Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Kernel - Resource [GPU].c_inc
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if defined(TgCOMPILE_GPU_SUPPORT)

/* == Kernel ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Parent File Local Functions                                                                                                                                           */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

static TgUINTXX                             T(tgKN_GPU_,__Load_BIN_Internal)(
                                                C_TgKN_FILE_ID, C_TgSIZE, C_ETgKN_GPU_ALLOCATOR, PCU_STg2_KN_GPU_RS_LIB_DESC, C_TgUINTXX, C_TgSIZE );




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions and Data                                                                                                                                         */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

CLANG_WARN_SUPPRESS(unused-function)

static TgVOID                               T(tgKN_GPU_,__Free_Internal)( PCU_STg2_KN_GPU_RS_LIB_DESC, C_TgSIZE );
static TgVOID                               T(tgKN_GPU_,_Inst__Init_Internal)( PCU_STg2_KN_GPU_RSI_LIB_DESC, C_TgKN_GPU_RSI_ID );
static TgVOID                               T(tgKN_GPU_,_Inst__Free_Internal)( PCU_STg2_KN_GPU_RSI_LIB_DESC, C_TgKN_GPU_RSI_ID );

#if TgS_DEBUG_KERNEL
#define RESOURCE_NAME(index) T(g_szKN_GPU_,)[index]
/*# TgS_DEBUG_KERNEL */
#else
#define RESOURCE_NAME(index) TgT("")
/*# TgS_DEBUG_KERNEL */
#endif




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- T(tgKN_GPU_,__File_Load) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(TgS_FINAL)
TgKN_GPU_RS_ID T(tgKN_GPU_,__File_Load)( C_TgKN_FS_MOUNT_ID tiFS_Mount, CPC_TgCHAR pszPath, CPC_TgCHAR pszFile, C_ETgKN_GPU_ALLOCATOR enAllocator )
{
    TgKN_GPU_RS_ID                      tiRet;

    tiRet = tgKN_GPU_RS__File_Load_BIN( tiFS_Mount, pszPath, pszFile, enAllocator, &T(g_sKN_Lib_,_DESC) );

    if (TgTRUE != tgKN_GPU_RS_ID_Is_Valid( tiRet ))
    {
        tgCN_PrintF( KTgCN_CHANEL_ERROR, TgT( "%-16.16s(%-32.32s): [Fail] %-57.57s\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX__File_Load"), pszFile ? pszFile : TgT("") );
        return (KTgKN_GPU_RS_ID__INVALID);
    };

    TgERROR(TgTRUE == tgEQ_KN_GPU_RS_ID( T(g_sKN_Lib_,_DESC).m_ptiRS[tiRet.m.iI], tiRet ));

    return (tiRet);
}

/*# TgS_FINAL */
#endif


/* ---- T(tgKN_GPU_,__Load) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgKN_GPU_RS_ID T(tgKN_GPU_,__Load)( C_TgKN_FILE_ID tiFile, C_TgSIZE uiFile_Offset, C_ETgKN_GPU_ALLOCATOR enAllocator, C_TgUINTXX uiHash_RS )
{
    TgKN_GPU_RS_ID                      tiRet;

    tiRet = tgKN_GPU_RS__Load_BIN( tiFile, uiFile_Offset, enAllocator, uiHash_RS, &T(g_sKN_Lib_,_DESC) );

    if (TgTRUE != tgKN_GPU_RS_ID_Is_Valid( tiRet ))
    {
        tgCN_PrintF( KTgCN_CHANEL_ERROR, TgT( "%-16.16s(%-32.32s): [Fail] %-57.57s\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX__Load"), TgT("") );
        return (KTgKN_GPU_RS_ID__INVALID);
    };

    TgERROR(TgTRUE == tgEQ_KN_GPU_RS_ID( T(g_sKN_Lib_,_DESC).m_ptiRS[tiRet.m.iI], tiRet ));

    return (tiRet);
}


/* ---- T(tgKN_GPU_,_Inst__Init) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
TgKN_GPU_RSI_ID T(tgKN_GPU_,_Inst__Init)( C_TgKN_GPU_CXT_DATA_ID tiCT, C_TgKN_GPU_RS_ID tiRS )
{
    TgPARAM_CHECK_INDEX( tiCT.m.iI, g_asKN_GPU_Context_Resource);
    return (tgKN_GPU_RSI__Init( &g_asKN_GPU_Context_Resource[tiCT.m.iI].T(m_s,_Inst_LIB_DESC), (TgUINT32)tiCT.m.iI, tiRS ));
}
/*# !defined(T_NO_INSTANCE) */
#endif


/* ---- T(tgKN_GPU_,_Inst__IncRef) -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
TgKN_GPU_RSI_ID T(tgKN_GPU_, _Inst__IncRef)( C_TgKN_GPU_RSI_ID tiRSI )
{
    TgPARAM_CHECK_INDEX((tiRSI.m.iK >> 16), g_asKN_GPU_Context_Resource);
    return (tgKN_GPU_RSI__IncRef( &g_asKN_GPU_Context_Resource[(tiRSI.m.iK >> 16)].T(m_s,_Inst_LIB_DESC), tiRSI ));
}
/*# !defined(T_NO_INSTANCE) */
#endif


/* ---- T(tgKN_GPU_,_Inst__Hash_Find_And_IncRef) ------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
TgKN_GPU_RSI_ID T(tgKN_GPU_, _Inst__Hash_Find_And_IncRef)( C_TgKN_GPU_CXT_DATA_ID tiCT, C_TgUINTXX uiHash )
{
    TgPARAM_CHECK_INDEX(tiCT.m.iI, g_asKN_GPU_Context_Resource);
    return (tgKN_GPU_RSI__Hash_Find_And_IncRef( &g_asKN_GPU_Context_Resource[tiCT.m.iI].T(m_s,_Inst_LIB_DESC), (TgUINT32)tiCT.m.iI, uiHash ));
}
/*# !defined(T_NO_INSTANCE) */
#endif


/* ---- T(tgKN_GPU_,_Inst_Release) -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
TgSINT32 T(tgKN_GPU_, _Inst__Release)( C_TgKN_GPU_RSI_ID tiRSI )
{
    TgPARAM_CHECK_INDEX((tiRSI.m.iK >> 16), g_asKN_GPU_Context_Resource);
    return (tgKN_GPU_RSI__Release( &g_asKN_GPU_Context_Resource[(tiRSI.m.iK >> 16)].T(m_s,_Inst_LIB_DESC), tiRSI ));
}
/*# !defined(T_NO_INSTANCE) */
#endif




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Private Functions                                                                                                                                                     */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- T(tgKN_GPU_,__Release) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSINT32 T(tgKN_GPU_,__Release)( C_TgKN_GPU_RS_ID tiRS )
{
    return (tgKN_GPU_RS__Release( tiRS, &T(g_sKN_Lib_,_DESC) ));
}


/* ---- T(tgKN_GPU_,_LIB__Init) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID T(tgKN_GPU_,_LIB__Init)( TgVOID )
{
    TgSINT32                            iIndex;
    union
    {
        P_TgVOID                            p;
        TgSINT32 volatile *                 pi;
    }                                   sVoid;

    tgCM_UTM_AM_ST_Init_PreLoad( &T(g_sKN_Lib_,).m_sStack, (P_TgVOID)T(g_asKN_Lib_,_Data), sizeof( T(g_asKN_Lib_,_Data)[0] ), T(KTgKN_GPU_MAX_,) );
    tgCM_UTM_SN_Init( &T(g_sKN_Lib_,_Lock).m_sLock );

    T(g_sKN_Lib_,_DESC).m_puiHash = T(g_asKN_Lib_,_Hash);
    T(g_sKN_Lib_,_DESC).m_ptiRS = T(g_atiKN_Lib_,_RS);
    T(g_sKN_Lib_,_DESC).m_piRef = T(g_aiKN_Lib_,_Ref);
    T(g_sKN_Lib_,_DESC).m_psLock = &T(g_sKN_Lib_,_Lock).m_sLock;
    T(g_sKN_Lib_,_DESC).m_psList = &T(g_sKN_Lib_,).m_sStack;
    T(g_sKN_Lib_,_DESC).m_puiData = (P_TgUINT08)T(g_asKN_Lib_,_Data);
    T(g_sKN_Lib_,_DESC).m_uiStride = sizeof( T(g_asKN_Lib_,_Data)[0] );
    T(g_sKN_Lib_,_DESC).m_pfnLoad = T(tgKN_GPU_,__Load_BIN_Internal);
    T(g_sKN_Lib_,_DESC).m_pfnFree = T(tgKN_GPU_,__Free_Internal);
    T(g_sKN_Lib_,_DESC).m_iMaxList = T(KTgKN_GPU_MAX_,);
    T(g_sKN_Lib_,_DESC).m_uiSize = 0;
    TgCOMPILER_ASSERT( sizeof( T(STg2_KN_GPU_,_DATA) ) >= sizeof( STg2_UTM_AM_ST ), 1 );

    sVoid.pi = T(g_aiKN_Lib_,_Ref);
    memset( sVoid.p, 0, sizeof( T(g_aiKN_Lib_,_Ref) ) );
    for (iIndex = 0; iIndex < T(KTgKN_GPU_MAX_,); ++iIndex)
    {
        T(g_asKN_Lib_,_Hash)[iIndex] = KTgEMPTY_HASH;
        T(g_atiKN_Lib_,_RS)[iIndex] = KTgKN_GPU_RS_ID__INVALID;
    };
}


/* ---- T(tgKN_GPU_,_LIB__Stop) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID T(tgKN_GPU_,_LIB__Stop)( TgVOID )
{
    TgSIZE                              uiIndex;
    TgBOOL                              bNoSpam;

    /* Locking down the system forever - no threads should be waiting on these locks to be down in higher order logic */
    tgCM_UTM_SN_Lock_Spin( &T(g_sKN_Lib_,_Lock).m_sLock );

    /* Just in case, unload any textures currently in the system */
    bNoSpam = TgFALSE;
    for (uiIndex = 0; uiIndex < T(KTgKN_GPU_MAX_,); ++uiIndex)
    {
        if (TgFALSE != tgKN_GPU_RS_ID_Is_Valid( T(g_atiKN_Lib_,_RS)[uiIndex] ))
        {
        #if TgS_DEBUG_KERNEL
        #if !defined(TGS_FINAL)
            tgCN_PrintF( KTgCN_CHANEL_WARNING, TgT( "%-16.16s(%-32.32s): %-35.35s not unloaded\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX_LIB__Stop"),
                         T(g_szKN_GPU_,)[uiIndex] );
        #else
            if (TgFALSE == bNoSpam)
            {
                tgCN_PrintF( KTgCN_CHANEL_WARNING, TgT( "%-16.16s(%-32.32s): %-48.48s\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX_LIB__Stop"),
                             TgT("Texture resident in render during stop.") );
                bNoSpam = TgTRUE;
            };
        #endif
        #endif

            T(g_aiKN_Lib_,_Ref)[uiIndex] = 1;
            tgKN_GPU_TX_IMG__Release( T(g_atiKN_Lib_,_RS)[uiIndex] );
        };
    };
}


/* ---- T(tgKN_GPU_,_LIB__Free) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID T(tgKN_GPU_,_LIB__Free)( TgVOID )
{
    tgCM_UTM_AM_ST_Free( &T(g_sKN_Lib_,).m_sStack );
    tgCM_UTM_SN_Free( &T(g_sKN_Lib_,_Lock).m_sLock );

    T(g_sKN_Lib_,_DESC).m_puiHash = nullptr;
    T(g_sKN_Lib_,_DESC).m_ptiRS = nullptr;
    T(g_sKN_Lib_,_DESC).m_piRef = nullptr;
    T(g_sKN_Lib_,_DESC).m_psLock = nullptr;
    T(g_sKN_Lib_,_DESC).m_psList = nullptr;
    T(g_sKN_Lib_,_DESC).m_puiData = nullptr;
    T(g_sKN_Lib_,_DESC).m_uiStride = 0;
    T(g_sKN_Lib_,_DESC).m_pfnLoad = nullptr;
    T(g_sKN_Lib_,_DESC).m_pfnFree = nullptr;
    T(g_sKN_Lib_,_DESC).m_iMaxList = 0;
    T(g_sKN_Lib_,_DESC).m_uiSize = 0;

#if TgCOMPILE_MEM_FREE_CLEAR
    {
        TgSINT32                            iIndex;
        union
        {
            P_TgVOID                            p;
            TgSINT32 volatile *                 pi;
        }                                   sVoid;

        for (iIndex = 0; iIndex < T(KTgKN_GPU_MAX_,); ++iIndex)
        {
            T(g_asKN_Lib_,_Hash)[iIndex] = KTgEMPTY_HASH;
            T(g_atiKN_Lib_,_RS)[iIndex] = KTgKN_GPU_RS_ID__INVALID;
        };

        sVoid.pi = T(g_aiKN_Lib_,_Ref);
        memset( sVoid.p, 0, sizeof( T(g_aiKN_Lib_,_Ref) ) );
    };
/*# TgCOMPILE_MEM_FREE_CLEAR */
#endif
}


/* ---- T(tgKN_GPU_,_Inst_LIB__Init) ------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
TgVOID T(tgKN_GPU_,_Inst_LIB__Init)(C_TgSINT32 iCT)
{
    TgSINT32                            iIndex;
    union
    {
        P_TgVOID                            p;
        TgSINT32 volatile *                 pi;
    }                                   sVoid;

    tgCM_UTM_SN_Init( &T(g_sCXT_,_Inst_Lock)[iCT].m_sLock );
    tgCM_UTM_AM_ST_Init_PreLoad( &T(g_sCXT_,_Inst)[iCT].m_sStack, (P_TgVOID)T(g_atiCXT_,)[iCT], sizeof( T(g_atiCXT_,)[iCT][0] ), T(KTgKN_GPU_MAX_,) );

    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_ptiRSI = T(g_atiCXT_,_Inst)[iCT];
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_ptiRS = T(g_atiCXT_,)[iCT];
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_piRef = T(g_aiCXT_,_Inst_Ref)[iCT];
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_psLock = &T(g_sCXT_,_Inst_Lock)[iCT].m_sLock;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_psList = &T(g_sCXT_,_Inst)[iCT].m_sStack;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_puiData = (P_TgVOID)T(g_atiCXT_,)[iCT];
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_uiStride = sizeof( T(g_atiCXT_,)[iCT][0] );
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_pLibRS = &T(g_sKN_Lib_,_DESC);
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_pfnInst = T(tgKN_GPU_,_Inst__Init_Internal);
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_pfnFree = T(tgKN_GPU_,_Inst__Free_Internal);
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_uiSize = 0;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_iMaxList = T(KTgKN_GPU_MAX_,);
    TgCOMPILER_ASSERT( sizeof( T( g_atiCXT_, )[0][0] ) >= sizeof( STg2_UTM_Node ), 1 );

    sVoid.pi = T(g_aiCXT_,_Inst_Ref)[iCT];
    memset( sVoid.p, 0, sizeof( T(g_aiCXT_,_Inst_Ref)[iCT] ) );
    for (iIndex = 0; iIndex < T(KTgKN_GPU_MAX_,); ++iIndex)
    {
        T(g_atiCXT_,_Inst)[iCT][iIndex] = KTgKN_GPU_RSI_ID__INVALID;
    };
}
/*# !defined(T_NO_INSTANCE) */
#endif


/* ---- T(tgKN_GPU_,_Inst_LIB__Free) ------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
TgVOID T(tgKN_GPU_,_Inst_LIB__Free)(C_TgSINT32 iCT)
{
    tgCM_UTM_AM_ST_Free( &T(g_sCXT_,_Inst)[iCT].m_sStack );
    tgCM_UTM_SN_Free( &T(g_sCXT_, _Inst_Lock)[iCT].m_sLock );

    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_ptiRSI = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_ptiRS = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_piRef = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_psList = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_psLock = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_pLibRS = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_pfnInst = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_pfnFree = nullptr;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_iMaxList = 0;
    g_asKN_GPU_Context_Resource[iCT].T(m_s,_Inst_LIB_DESC).m_uiSize = 0;

#if TgCOMPILE_MEM_FREE_CLEAR
    {
        TgSINT32                            iIndex;
        union
        {
            P_TgVOID                            p;
            TgSINT32 volatile *                 pi;
        }                                   sVoid;

        for (iIndex = 0; iIndex < T(KTgKN_GPU_MAX_,); ++iIndex)
        {
            T(g_atiCXT_,_Inst)[iCT][iIndex] = KTgKN_GPU_RSI_ID__INVALID;
            T(g_atiCXT_,)[iCT][iIndex] = KTgKN_GPU_RS_ID__INVALID;
        };

        sVoid.pi = T(g_aiCXT_,_Inst_Ref)[iCT];
        memset( sVoid.p, 0, sizeof( T(g_aiCXT_,_Inst_Ref)[iCT] ) );
    };
/*# TgCOMPILE_MEM_FREE_CLEAR */
#endif
}
/*# !defined(T_NO_INSTANCE) */
#endif




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions                                                                                                                                                  */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- T(tgKN_GPU_,__Free_Internal) ------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID T(tgKN_GPU_,__Free_Internal)( PCU_STg2_KN_GPU_RS_LIB_DESC pLibRS, C_TgSIZE uiIndex )
{
    /*TgERROR( 0u == (ETgKN_GPU_ALLOCATOR_IGNORE_REF_COUNT & g_asKN_Lib_CS_Data[uiIndex].m_sSH.m_enAllocator) ); */

#if TgS_DEBUG_KERNEL
    tgCN_PrintF( KTgCN_CHANEL_LOADING, TgT( "%-16.16s(%-32.32s): [Free] %-57.57s | id(% 4d) | % -9d BY\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX__Free_Internal"),
                 RESOURCE_NAME( uiIndex ), uiIndex, T(g_uiKN_Size_GPU_,)[uiIndex] );
/*# TgS_DEBUG_KERNEL */
#endif

#if TgS_STAT_KERNEL || TgS_DEBUG_KERNEL
    pLibRS->m_uiSize -= T(g_uiKN_Size_GPU_,)[uiIndex];
/*# TgS_STAT_KERNEL || TgS_DEBUG_KERNEL */
#endif

    T(tgKN_GPU_PM_,__Free)( pLibRS, uiIndex );
}


/* ---- T(tgKN_GPU_,_Inst__Init_Internal) ------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
static TgVOID T(tgKN_GPU_, _Inst__Init_Internal )(PCU_STg2_KN_GPU_RSI_LIB_DESC pLibRSI, C_TgKN_GPU_RSI_ID tiRSI)
{
    T(tgKN_GPU_PM_,_Inst__Init)( pLibRSI, tiRSI );

    if (TgTRUE != tgKN_GPU_RSI_ID_Is_Valid( pLibRSI->m_ptiRSI[tiRSI.m.iI] ))
    {
        tgCN_PrintF( KTgCN_CHANEL_WARNING, TgT( "%-16.16s(%-32.32s): [Warn] %-57.57s\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX__Init_Internal"),
                     TgT("Failed to allocate a shader instance entry in context") );
        tgCN_PrintF( KTgCN_CHANEL_WARNING, TgT( "%-16.16s(%-32.32s): [Warn] %-57.57s\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX__Init_Internal"),
                     RESOURCE_NAME(pLibRSI->m_ptiRS[tiRSI.m.iI].m.iI) );
        return;
    };

#if TgS_DEBUG_KERNEL
    tgCN_PrintF( KTgCN_CHANEL_LOADING, TgT( "%-16.16s(%-32.32s): [Inst] %-57.57s | id(% 4d) | % -9d BY\n" ), TgT("Kernel"), TgT("tgKN_GPU_XXX__Init_Internal"),
                 RESOURCE_NAME(pLibRSI->m_ptiRS[tiRSI.m.iI].m.iI), pLibRSI->m_ptiRS[tiRSI.m.iI].m.iI, T(g_uiKN_Size_GPU_,)[pLibRSI->m_ptiRS[tiRSI.m.iI].m.iI] );
/*# TgS_DEBUG_KERNEL */
#endif

#if TgS_STAT_KERNEL || TgS_DEBUG_KERNEL
    pLibRSI->m_uiSize += T(g_uiKN_Size_GPU_,)[pLibRSI->m_ptiRS[tiRSI.m.iI].m.iI];
/*# TgS_STAT_KERNEL || TgS_DEBUG_KERNEL */
#endif
}
/*# !defined(T_NO_INSTANCE) */
#endif


/* ---- T(tgKN_GPU_,_Inst__Free_Internal) ------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#if !defined(T_NO_INSTANCE)
static TgVOID T(tgKN_GPU_, _Inst__Free_Internal )(PCU_STg2_KN_GPU_RSI_LIB_DESC pLibRSI, C_TgKN_GPU_RSI_ID tiRSI)
{
#if TgS_STAT_KERNEL || TgS_DEBUG_KERNEL
    pLibRSI->m_uiSize -= T(g_uiKN_Size_GPU_,)[pLibRSI->m_ptiRS[tiRSI.m.iI].m.iI];
/*# TgS_STAT_KERNEL || TgS_DEBUG_KERNEL */
#endif

    T(tgKN_GPU_PM_,_Inst__Free)( pLibRSI, tiRSI );
    pLibRSI->m_ptiRS[tiRSI.m.iI] = KTgKN_GPU_RS_ID__INVALID;
}
/*# !defined(T_NO_INSTANCE) */
#endif


/*# defined(TgCOMPILE_GPU_SUPPORT) */
#endif