Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS (DX12) Kernel - System.c
    »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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

#include "TgS (DX12) Kernel - Internal - D3DX.inl"


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

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

static TgRESULT                             tgKN_GPU_PM_Context__Init_Contexts( C_TgKN_GPU_CXT_ID, CPCU_STg2_KN_GPU_Select );
static TgRESULT                             tgKN_GPU_PM_Context__Init_Device( C_TgKN_GPU_CXT_DEVC_ID, C_TgSINT32 );
static TgVOID                               tgKN_GPU_PM_Context__Free_Device( C_TgKN_GPU_CXT_DEVC_ID );
static TgRESULT                             tgKN_GPU_PM_Context__Init_Output( C_TgKN_GPU_CXT_SWAP_ID, C_TgKN_GPU_CXT_DEVC_ID, CPCU_STg2_KN_GPU_Select );
static TgVOID                               tgKN_GPU_PM_Context__Free_Output( C_TgKN_GPU_CXT_SWAP_ID, C_TgBOOL );
static TgRESULT                             tgKN_GPU_PM_Context__Init_Resource( C_TgKN_GPU_CXT_DATA_ID );
static TgRESULT                             tgKN_GPU_PM_Context__Init_External( C_TgKN_GPU_CXT_EXTN_ID );




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

/* ---- tgKN_GPU_DXGI_Device__Create ------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
P_D3D12_DEVICE1 tgKN_GPU_DXGI_Device__Create( P_D3D_FEATURE_LEVEL penFeature_Level, P_STg2_KN_GPU_DXGI_Adapter psAdapter )
{
    P_D3D12_DEVICE                      pdxDevice;
    P_D3D12_DEVICE1                     psDevice1;
    D3D_FEATURE_LEVEL                   enFeature_Level;
    HRESULT                             iRet;

    /* Attempt to acquire a 12.1 feature level first (if not installed we get an INVALIDARG fail immediately) */
    pdxDevice = nullptr;
    enFeature_Level = D3D_FEATURE_LEVEL_12_1;
    iRet = g_pfnD3D12CreateDevice( psAdapter->m_pDXGI_Adapter_3, enFeature_Level, &IID_ID3D12Device, (PP_TgVOID)&pdxDevice );

    if (FAILED( iRet ))
    {
        /* On failure to acquire 12.1 attempt 12.0.  There is no support for non DX12 feature levels.  Tough shit. */
        enFeature_Level = D3D_FEATURE_LEVEL_12_0;
        iRet = g_pfnD3D12CreateDevice( psAdapter->m_pDXGI_Adapter_3, enFeature_Level, &IID_ID3D12Device, (PP_TgVOID)&pdxDevice );
        if (FAILED( iRet ))
        {
            return (nullptr);
        };
    };

    if (FAILED(ID3D12Device_QueryInterface( pdxDevice, &IID_ID3D12Device1, (PP_TgVOID)&psDevice1 )))
    {
        ID3D12Device_Release( pdxDevice );
        return (nullptr);
    };

    *penFeature_Level = enFeature_Level;
    return (psDevice1);
}


/* ---- tgKN_GPU_DXGI_Free_Adapter -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_GPU_DXGI_Free_Adapter( P_STg2_KN_GPU_DXGI_Adapter psAdapter )
{
    TgSINT32                            iOutput;

    for (iOutput = 0; iOutput < psAdapter->m_niOutput; ++iOutput)
    {
        tgKN_GPU_DXGI_Free_Output( psAdapter->m_asOutput + iOutput );
    };

    if (nullptr != psAdapter->m_psDevice1)
    {
        TgVERIFY( 0 == ID3D12Device1_Release( psAdapter->m_psDevice1 ) );
        psAdapter->m_psDevice1 = nullptr;
    };
    TgVERIFY( 0 == IDXGIAdapter3_Release( psAdapter->m_pDXGI_Adapter_3 ) );
}


/* ---- tgKN_GPU_DXGI_Free_Output --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_GPU_DXGI_Free_Output( P_STg2_KN_GPU_DXGI_Output psOutput )
{
    TgVERIFY(0 == IDXGIOutput5_Release( psOutput->m_pDXGI_Output_5 ));
    TgFREE_POOL( psOutput->m_psMode );
}


/* ---- tgKN_GPU_PM_Context__Init --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_PM_Context__Init( C_TgKN_GPU_CXT_ID tiCXT, CPCU_STg2_KN_GPU_Select psSelect )
{
    P_STg2_KN_GPU_Context               psCXT;

    tgCN_PrintF( KTgCN_CHANEL_LOG | KTgCN_CHANEL_MESSAGE | KTgCN_SEVERITY_5, TgT( "" ) );

    if (psSelect->m_iAdapter < 0 || psSelect->m_iAdapter >= g_niKN_GPU_Adapter)
    {
        return (KTgE_FAIL);
    };

    if (psSelect->m_iOutput < 0 || psSelect->m_iOutput >= g_asKN_GPU_Adapter[psSelect->m_iAdapter].m_niOutput)
    {
        return (KTgE_FAIL);
    };

    psCXT = g_asKN_GPU_Context + tiCXT.m.iI;

    if (TgFAILED(tgKN_GPU_PM_Context__Init_Contexts( tiCXT, psSelect )))
    {
        return (KTgE_FAIL);
    };

    if (TgFAILED(tgKN_GPU_PM_Context__Init_Device( psCXT->m_tiCXT_DEVC, psSelect->m_iAdapter )))
    {
        tgKN_GPU_PM_Context__Free( tiCXT );
        return (KTgE_FAIL);
    };

    if (TgFAILED(tgKN_GPU_PM_Context__Init_Output( psCXT->m_tiCXT_SWAP, psCXT->m_tiCXT_DEVC, psSelect )))
    {
        tgKN_GPU_PM_Context__Free( tiCXT );
        return (KTgE_FAIL);
    };

    if (TgFAILED(tgKN_GPU_PM_Context__Init_Resource( psCXT->m_tiCXT_DATA )))
    {
        tgKN_GPU_PM_Context__Free( tiCXT );
        return (KTgE_FAIL);
    };

    if (TgFAILED(tgKN_GPU_PM_Context__Init_External( psCXT->m_tiCXT_EXTN )))
    {
        tgKN_GPU_PM_Context__Free( tiCXT );
        return (KTgE_FAIL);
    };

    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Context__Free --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_GPU_PM_Context__Free( C_TgKN_GPU_CXT_ID tiCXT )
{
    P_STg2_KN_GPU_Context               psCXT;

    psCXT = g_asKN_GPU_Context + tiCXT.m.iI;

    if (TgFALSE != tgKN_GPU_CXT_SWAP_ID_Is_Valid( psCXT->m_tiCXT_SWAP ))
    {
        tgKN_GPU_PM_Context__Free_Output( psCXT->m_tiCXT_SWAP, TgTRUE );
    };

    if (TgFALSE != tgKN_GPU_CXT_DEVC_ID_Is_Valid( psCXT->m_tiCXT_DEVC ))
    {
        tgKN_GPU_PM_Context__Free_Device( psCXT->m_tiCXT_DEVC );
    };
}


/* ---- tgKN_GPU_PM_Render_Context__Flush ------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_GPU_PM_Render_Context__Flush( C_TgKN_GPU_CXT_DEVC_ID tiCXT_DEVC, C_TgKN_GPU_CXT_SWAP_ID tiCXT_SWAP )
{
    P_STg2_KN_GPU_DX12_Context__Device  psCXT_DEVC;
    P_STg2_KN_GPU_DX12_Context__Output  psCXT_SWAP;

    psCXT_DEVC = g_asKN_GPU_DX12_Context_Device + tiCXT_DEVC.m.iI;
    psCXT_SWAP = g_asKN_GPU_DX12_Context_Output + tiCXT_SWAP.m.iI;

    TgVERIFY(SUCCEEDED(ID3D12CommandQueue_Signal( psCXT_DEVC->m_psCmd_Queue__Direct, psCXT_SWAP->m_psFence, psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index] )));
    TgVERIFY(SUCCEEDED(ID3D12Fence_SetEventOnCompletion( psCXT_SWAP->m_psFence, psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index], psCXT_SWAP->m_psFenceEvent )));
    g_pfnWaitForSingleObjectEx( psCXT_SWAP->m_psFenceEvent, INFINITE, FALSE );

    ++psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index];
}


/* ---- tgKN_GPU_PM_Render_Context__Swap_Acquire ------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_GPU_PM_Render_Context__Swap_Acquire( C_TgKN_GPU_CXT_ID tiCXT )
{
    P_STg2_KN_GPU_Context               psCXT;
    P_STg2_KN_GPU_DX12_Context__Device  psCXT_DEVC;
    P_STg2_KN_GPU_DX12_Context__Output  psCXT_SWAP;
    D3D12_RESOURCE_BARRIER              sBarrier;

    psCXT = g_asKN_GPU_Context + tiCXT.m.iI;
    psCXT_DEVC = g_asKN_GPU_DX12_Context_Device + psCXT->m_tiCXT_DEVC.m.iI;
    psCXT_SWAP = g_asKN_GPU_DX12_Context_Output + psCXT->m_tiCXT_SWAP.m.iI;

    /* Acquire and Reset all Swap related resources - command allocator, list, transition the buffer */
    ID3D12GraphicsCommandList_Reset( psCXT_DEVC->m_psCmd_Graphics_List__Swap, psCXT_DEVC->m_psCmd_Allocator__Direct[psCXT_SWAP->m_uiSwap_Index], nullptr );

    __CD3DX12_RESOURCE_BARRIER_Transition( &sBarrier, psCXT_SWAP->m_apsRTV[psCXT_SWAP->m_uiSwap_Index], D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET,
                                           D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_BARRIER_FLAG_NONE );
    ID3D12GraphicsCommandList_ResourceBarrier( psCXT_DEVC->m_psCmd_Graphics_List__Swap, 1, &sBarrier );
}


/* ---- tgKN_GPU_PM_Render_Context__Swap -------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_PM_Render_Context__Swap( C_TgKN_GPU_CXT_ID tiCXT )
{
    P_STg2_KN_GPU_Context               psCXT;
    P_STg2_KN_GPU_DX12_Context__Device  psCXT_DEVC;
    P_STg2_KN_GPU_DX12_Context__Output  psCXT_SWAP;
    D3D12_RESOURCE_BARRIER              sBarrier;
    HRESULT                             iRet;
    TgUINT64                            uiCurrent_Swap_Index;

    psCXT = g_asKN_GPU_Context + tiCXT.m.iI;
    psCXT_DEVC = g_asKN_GPU_DX12_Context_Device + psCXT->m_tiCXT_DEVC.m.iI;
    psCXT_SWAP = g_asKN_GPU_DX12_Context_Output + psCXT->m_tiCXT_SWAP.m.iI;

    __CD3DX12_RESOURCE_BARRIER_Transition( &sBarrier, psCXT_SWAP->m_apsRTV[psCXT_SWAP->m_uiSwap_Index], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT,
                                           D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_BARRIER_FLAG_NONE );
    ID3D12GraphicsCommandList_ResourceBarrier( psCXT_DEVC->m_psCmd_Graphics_List__Swap, 1, &sBarrier );

    /* Close and execute the swap command list */
    TgVERIFY(SUCCEEDED(ID3D12GraphicsCommandList_Close( psCXT_DEVC->m_psCmd_Graphics_List__Swap )));
    ID3D12CommandQueue_ExecuteCommandLists( psCXT_DEVC->m_psCmd_Queue__Direct, 1, (PP_D3D12_COMMAND_LIST)&psCXT_DEVC->m_psCmd_Graphics_List__Swap );

    psCXT_SWAP->m_uiVSync = 1;
    iRet = IDXGISwapChain4_Present( psCXT_SWAP->m_psSwapChain4, psCXT_SWAP->m_uiVSync, 0 );
    if ((DXGI_ERROR_DEVICE_REMOVED == iRet) || (DXGI_ERROR_DEVICE_RESET == iRet))
    {
        psCXT_DEVC->m_uiIsReset = 1;
        return (KTgE_FAIL);
    };

    /* Schedule a Signal command in the queue */
    uiCurrent_Swap_Index = psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index];
    TgVERIFY(SUCCEEDED(ID3D12CommandQueue_Signal( psCXT_DEVC->m_psCmd_Queue__Direct, psCXT_SWAP->m_psFence, uiCurrent_Swap_Index )));

    psCXT_SWAP->m_uiSwap_Index = IDXGISwapChain4_GetCurrentBackBufferIndex( psCXT_SWAP->m_psSwapChain4 );

    /* Check to see if the next frame is ready to start. */
    if (ID3D12Fence_GetCompletedValue( psCXT_SWAP->m_psFence ) < psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index])
    {
        TgVERIFY(SUCCEEDED(ID3D12Fence_SetEventOnCompletion( psCXT_SWAP->m_psFence, psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index], psCXT_SWAP->m_psFenceEvent )));
        g_pfnWaitForSingleObjectEx( psCXT_SWAP->m_psFenceEvent, INFINITE, FALSE );
    }

    psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index] = uiCurrent_Swap_Index + 1;

    ID3D12CommandAllocator_Reset( psCXT_DEVC->m_psCmd_Allocator__Direct[psCXT_SWAP->m_uiSwap_Index] );
    ID3D12CommandAllocator_Reset( psCXT_DEVC->m_psCmd_Allocator__Bundle[psCXT_SWAP->m_uiSwap_Index] );

    return (KTgS_OK);
}




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

/* ---- tgKN_GPU_PM_Context__Init_Contexts ------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgRESULT tgKN_GPU_PM_Context__Init_Contexts( C_TgKN_GPU_CXT_ID tiCXT, CPCU_STg2_KN_GPU_Select psSelect )
{
    P_STg2_KN_GPU_Context               psCXT;

    psCXT = g_asKN_GPU_Context + tiCXT.m.iI;

    if (TgTRUE != tgKN_GPU_CXT_DEVC_ID_Is_Valid( psSelect->m_tiCXT_DEVC ))
        memset( g_asKN_GPU_DX12_Context_Device + psCXT->m_tiCXT_DEVC.m.iI, 0, sizeof( STg2_KN_GPU_DX12_Context__Device ) );
    if (TgTRUE != tgKN_GPU_CXT_DATA_ID_Is_Valid( psSelect->m_tiCXT_DATA ))
        memset( g_asKN_GPU_DX12_Context_Data + psCXT->m_tiCXT_DATA.m.iI, 0, sizeof( STg2_KN_GPU_DX12_Context__Data ) );
    if (TgTRUE != tgKN_GPU_CXT_EXTN_ID_Is_Valid( psSelect->m_tiCXT_EXTN ))
        memset( g_asKN_GPU_DX12_Context_External + psCXT->m_tiCXT_EXTN.m.iI, 0, sizeof( STg2_KN_GPU_DX12_Context__External ) );

    memset( g_asKN_GPU_DX12_Context_Output + psCXT->m_tiCXT_SWAP.m.iI, 0, sizeof( STg2_KN_GPU_DX12_Context__Output ) );
    memset( g_asKN_GPU_DX12_Context + tiCXT.m.iI, 0, sizeof( STg2_KN_GPU_DX12_Context ) );

    g_asKN_GPU_DX12_Context_Device[psCXT->m_tiCXT_DEVC.m.iI].m_tiID = psCXT->m_tiCXT_DEVC;
    g_asKN_GPU_DX12_Context_Output[psCXT->m_tiCXT_SWAP.m.iI].m_tiID = psCXT->m_tiCXT_SWAP;
    g_asKN_GPU_DX12_Context_Data[psCXT->m_tiCXT_DATA.m.iI].m_tiID = psCXT->m_tiCXT_DATA;
    g_asKN_GPU_DX12_Context_External[psCXT->m_tiCXT_EXTN.m.iI].m_tiID = psCXT->m_tiCXT_EXTN;
    g_asKN_GPU_DX12_Context[tiCXT.m.iI].m_tiID = tiCXT;

    g_asKN_GPU_DX12_Context_Output[psCXT->m_tiCXT_SWAP.m.iI].m_enFormat_DS = KTgKN_DX_FORMAT_LIST[psSelect->m_enFormat_DS];

    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Context__Init_Device -------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgRESULT tgKN_GPU_PM_Context__Init_Device( C_TgKN_GPU_CXT_DEVC_ID tiCXT_DEVC, C_TgSINT32 iAdapter )
{
    P_STg2_KN_GPU_DX12_Context__Device  psCXT_DEVC;
    P_D3D12_DEVICE1                     psDevice1;
    TgSINT32                            iIndex;
    PP_D3D12_COMMAND_ALLOCATOR          ppDXGI_Allocator;
    P_D3D12_INFO_QUEUE                  pdxInfo;
    D3D12_COMMAND_QUEUE_DESC            sQueueDesc;
    D3D12_DESCRIPTOR_HEAP_DESC          sHeapDesc;

    /* Create the standard DXGI and D3D12 resources needed for working with the GPU */
    psCXT_DEVC = g_asKN_GPU_DX12_Context_Device + tiCXT_DEVC.m.iI;
    psDevice1 = g_asKN_GPU_DXGI_Adapter[iAdapter].m_psDevice1;
    TgERROR( tgEQ_KN_GPU_CXT_DEVC_ID( tiCXT_DEVC, psCXT_DEVC->m_tiID ) );

    psCXT_DEVC->m_iAdapter = iAdapter;


    /* Allocate the allocators */

    TgCOMPILER_ASSERT( KTgKN_GPU_DX12_MAX_GRAPHICS_ALLOCATOR == TgARRAY_COUNT( psCXT_DEVC->m_psCmd_Allocator__Direct ), 1 );
    TgCOMPILER_ASSERT( KTgKN_GPU_DX12_MAX_GRAPHICS_ALLOCATOR == TgARRAY_COUNT( psCXT_DEVC->m_psCmd_Allocator__Bundle ), 1 );
    for (iIndex = 0; iIndex < KTgKN_GPU_DX12_MAX_GRAPHICS_ALLOCATOR; ++iIndex)
    {
        ppDXGI_Allocator = psCXT_DEVC->m_psCmd_Allocator__Direct;
        if (FAILED(ID3D12Device1_CreateCommandAllocator( psDevice1, D3D12_COMMAND_LIST_TYPE_DIRECT, &IID_ID3D12CommandAllocator, (PP_TgVOID)(ppDXGI_Allocator + iIndex) )))
            return (KTgE_FAIL);
        ppDXGI_Allocator = psCXT_DEVC->m_psCmd_Allocator__Bundle;
        if (FAILED(ID3D12Device1_CreateCommandAllocator( psDevice1, D3D12_COMMAND_LIST_TYPE_BUNDLE, &IID_ID3D12CommandAllocator, (PP_TgVOID)(ppDXGI_Allocator + iIndex) )))
            return (KTgE_FAIL);
    };


    /* Allocate the command queues */

    memset( &sQueueDesc, 0, sizeof( sQueueDesc ) );
    sQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
    sQueueDesc.NodeMask = psCXT_DEVC->m_uiNodeMask;

    sQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
    if (FAILED(ID3D12Device1_CreateCommandQueue( psDevice1, &sQueueDesc, &IID_ID3D12CommandQueue, (PP_TgVOID)&psCXT_DEVC->m_psCmd_Queue__Direct )))
        return (KTgE_FAIL);
    sQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE;
    if (FAILED( ID3D12Device1_CreateCommandQueue( psDevice1, &sQueueDesc, &IID_ID3D12CommandQueue, (PP_TgVOID)&psCXT_DEVC->m_psCmd_Queue__Compute ) ))
        return (KTgE_FAIL);
    sQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_COPY;
    if (FAILED( ID3D12Device1_CreateCommandQueue( psDevice1, &sQueueDesc, &IID_ID3D12CommandQueue, (PP_TgVOID)&psCXT_DEVC->m_psCmd_Queue__Copy ) ))
        return (KTgE_FAIL);


    /* Allocate the command lists */

    if (FAILED(ID3D12Device1_CreateCommandList( psDevice1, psCXT_DEVC->m_uiNodeMask, D3D12_COMMAND_LIST_TYPE_DIRECT, psCXT_DEVC->m_psCmd_Allocator__Direct[0],
                                                nullptr, &IID_ID3D12GraphicsCommandList, (PP_TgVOID)&psCXT_DEVC->m_psCmd_Graphics_List__Init )))
        return (KTgE_FAIL);

    TgVERIFY(SUCCEEDED(ID3D12GraphicsCommandList_Close( psCXT_DEVC->m_psCmd_Graphics_List__Init )));

    if (FAILED(ID3D12Device1_CreateCommandList( psDevice1, psCXT_DEVC->m_uiNodeMask, D3D12_COMMAND_LIST_TYPE_DIRECT, psCXT_DEVC->m_psCmd_Allocator__Direct[0],
                                                nullptr, &IID_ID3D12GraphicsCommandList, (PP_TgVOID)&psCXT_DEVC->m_psCmd_Graphics_List__Swap )))
        return (KTgE_FAIL);

    TgVERIFY(SUCCEEDED(ID3D12GraphicsCommandList_Close( psCXT_DEVC->m_psCmd_Graphics_List__Swap )));


    /* Create descriptor heaps for render target views and depth stencil views. */

    memset( &sHeapDesc, 0, sizeof( sHeapDesc ) );
    sHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
    sHeapDesc.NodeMask = psCXT_DEVC->m_uiNodeMask;

    sHeapDesc.NumDescriptors = KTgKN_GPU_DX12_BUFFER_COUNT;
    sHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
    if(FAILED(ID3D12Device1_CreateDescriptorHeap( psDevice1, &sHeapDesc, &IID_ID3D12DescriptorHeap, (PP_TgVOID)&psCXT_DEVC->m_psHeap_RTV )))
        return (KTgE_FAIL);

    psCXT_DEVC->m_uiDescriptor_Size_RTV = ID3D12Device1_GetDescriptorHandleIncrementSize( psDevice1, D3D12_DESCRIPTOR_HEAP_TYPE_RTV );

    sHeapDesc.NumDescriptors = 1;
    sHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
    if (FAILED( ID3D12Device1_CreateDescriptorHeap( psDevice1, &sHeapDesc, &IID_ID3D12DescriptorHeap, (PP_TgVOID)&psCXT_DEVC->m_psHeap_DSV ) ))
        return (KTgE_FAIL);


    /* Clear all filters on the debug output */

    if (SUCCEEDED(ID3D12Device1_QueryInterface( psDevice1, &IID_ID3D12InfoQueue, (PP_TgVOID)&pdxInfo )))
    {
        ID3D12InfoQueue_PushEmptyStorageFilter( pdxInfo );
        ID3D12InfoQueue_PushEmptyRetrievalFilter( pdxInfo );
        ID3D12InfoQueue_Release( pdxInfo );
    };


    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Context__Free_Device -------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgKN_GPU_PM_Context__Free_Device( C_TgKN_GPU_CXT_DEVC_ID tiCXT_DEVC )
{
    P_STg2_KN_GPU_DX12_Context__Device  psCXT_DEVC;
    TgSINT32                            iIndex;

    TgPARAM_CHECK(TgTRUE != tgKN_GPU_CXT_DEVC_ID_Is_Valid( tiCXT_DEVC ));

    psCXT_DEVC = g_asKN_GPU_DX12_Context_Device + tiCXT_DEVC.m.iI;
    TgERROR( nullptr != psCXT_DEVC );

    if (nullptr != psCXT_DEVC->m_psHeap_DSV)
    {
        TgVERIFY(0 == ID3D12DescriptorHeap_Release( psCXT_DEVC->m_psHeap_DSV ));
    };
    if (nullptr != psCXT_DEVC->m_psHeap_RTV)
    {
        TgVERIFY( 0 == ID3D12DescriptorHeap_Release( psCXT_DEVC->m_psHeap_RTV ) );
    };
    if (nullptr != psCXT_DEVC->m_psCmd_Graphics_List__Init)
    {
        TgVERIFY( 0 == ID3D12GraphicsCommandList_Release( psCXT_DEVC->m_psCmd_Graphics_List__Init ) );
    };
    if (nullptr != psCXT_DEVC->m_psCmd_Graphics_List__Swap)
    {
        TgVERIFY( 0 == ID3D12GraphicsCommandList_Release( psCXT_DEVC->m_psCmd_Graphics_List__Swap ) );
    };
    if (nullptr != psCXT_DEVC->m_psCmd_Queue__Copy)
    {
        TgVERIFY( 0 == ID3D12CommandQueue_Release( psCXT_DEVC->m_psCmd_Queue__Copy ) );
    };
    if (nullptr != psCXT_DEVC->m_psCmd_Queue__Compute)
    {
        TgVERIFY( 0 == ID3D12CommandQueue_Release( psCXT_DEVC->m_psCmd_Queue__Compute ) );
    };
    if (nullptr != psCXT_DEVC->m_psCmd_Queue__Direct)
    {
        TgVERIFY( 0 == ID3D12CommandQueue_Release( psCXT_DEVC->m_psCmd_Queue__Direct ) );
    };

    for (iIndex = 0; iIndex < KTgKN_GPU_DX12_MAX_GRAPHICS_ALLOCATOR; ++iIndex)
    {
        if (nullptr != psCXT_DEVC->m_psCmd_Allocator__Bundle[iIndex])
        {
            TgVERIFY( 0 == ID3D12CommandAllocator_Release( psCXT_DEVC->m_psCmd_Allocator__Bundle[iIndex] ) );
        };
        if (nullptr != psCXT_DEVC->m_psCmd_Allocator__Direct[iIndex])
        {
            TgVERIFY( 0 == ID3D12CommandAllocator_Release( psCXT_DEVC->m_psCmd_Allocator__Direct[iIndex] ) );
        };
    };

    memset( psCXT_DEVC, 0, sizeof( STg2_KN_GPU_DX12_Context__Device ) );
    psCXT_DEVC->m_tiID = KTgKN_GPU_CXT_DEVC_ID__INVALID;
}


/* ---- tgKN_GPU_PM_Context__Init_Output -------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgRESULT tgKN_GPU_PM_Context__Init_Output( C_TgKN_GPU_CXT_SWAP_ID tiCXT_SWAP, C_TgKN_GPU_CXT_DEVC_ID tiCXT_DEVC, CPCU_STg2_KN_GPU_Select psSelect )
{
    P_STg2_KN_GPU_DX12_Context__Output  psCXT_SWAP;
    P_STg2_KN_GPU_DX12_Context__Device  psCXT_DEVC;
    P_D3D12_DEVICE1                     psDevice1;
    DXGI_FORMAT                         enDXGI_Format;
    TgSINT32                            iMode;
    TgSINT32                            iIndex;
    TgUINT32                            uiFlags;
    TgUINT32                            uiSwap_Index;
    D3D12_CPU_DESCRIPTOR_HANDLE         sCPU_RTV;
    TgSINT32                            iRTV;
    HRESULT                             iRet;
    D3D12_HEAP_PROPERTIES depthHeapProperties;
    D3D12_RESOURCE_DESC depthResourceDesc;
    D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc;
    D3D12_CLEAR_VALUE depthOptimizedClearValue;

    TgERROR(nullptr != g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_pDXGI_Adapter_3);
    TgERROR(nullptr != g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_psDevice1);

    psCXT_DEVC = g_asKN_GPU_DX12_Context_Device + tiCXT_DEVC.m.iI;
    psCXT_SWAP = g_asKN_GPU_DX12_Context_Output + tiCXT_SWAP.m.iI;
    psDevice1 = g_asKN_GPU_DXGI_Adapter[psCXT_DEVC->m_iAdapter].m_psDevice1;

    psCXT_SWAP->m_iOutput = psSelect->m_iOutput;

    enDXGI_Format = KTgKN_DX_TARGET_LIST[psSelect->m_sMode.m_enFormat];


    /* Search for the exact DXGI mode match */

    for (iMode = 0; iMode < g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_niMode; ++iMode)
    {
        TgUINT32                            uiRefresh_Rate;

        if (enDXGI_Format != g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_psMode[iMode].Format)
            continue;

        if (psSelect->m_sMode.m_uiWidth != g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_psMode[iMode].Width)
            continue;
        if (psSelect->m_sMode.m_uiHeight != g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_psMode[iMode].Height)
            continue;

        uiRefresh_Rate = g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_psMode[iMode].RefreshRate.Numerator;
        uiRefresh_Rate /= g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_psMode[iMode].RefreshRate.Denominator;
        if (psSelect->m_sMode.m_uiRefresh_Rate != uiRefresh_Rate)
            continue;

        break;
    };

    if (iMode >= g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_niMode)
    {
        return (KTgE_FAIL);
    };
    psCXT_SWAP->m_sMode = g_asKN_GPU_DXGI_Adapter[psSelect->m_iAdapter].m_asOutput->m_psMode[iMode];
    psCXT_SWAP->m_iSample = psSelect->m_niSample;


    /* Create or Resize the Swap Chain */

    uiFlags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH | DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
    if (nullptr != psCXT_SWAP->m_psSwapChain4)
    {
        tgKN_GPU_PM_Render_Context__Flush( tiCXT_DEVC, tiCXT_SWAP );
        tgKN_GPU_PM_Context__Free_Output( tiCXT_SWAP, TgFALSE );

        for (iIndex = 0; iIndex < KTgKN_GPU_DX12_BUFFER_COUNT; ++iIndex)
        {
            psCXT_SWAP->m_uiFenceValues[iIndex] = psCXT_SWAP->m_uiFenceValues[psCXT_SWAP->m_uiSwap_Index];
        };

        iRet = IDXGISwapChain4_ResizeBuffers( psCXT_SWAP->m_psSwapChain4, KTgKN_GPU_DX12_BUFFER_COUNT, psCXT_SWAP->m_sMode.Width, psCXT_SWAP->m_sMode.Height,
                                              psCXT_SWAP->m_sMode.Format, uiFlags );

        if (iRet == DXGI_ERROR_DEVICE_REMOVED || iRet == DXGI_ERROR_DEVICE_RESET)
        {
            psCXT_DEVC->m_uiIsReset = 1;
            return (KTgE_FAIL);
        };
        TgVERIFY(SUCCEEDED(iRet));
    }
    else
    {
        DXGI_SWAP_CHAIN_DESC1               sSwapChain1;
        DXGI_SWAP_CHAIN_FULLSCREEN_DESC     sSwapChainFS;
        P_IUNKNOWN                          pUnknown;
        P_DXGI_SWAP_CHAIN1                  pSwapChain1;

        memset( &sSwapChain1, 0, sizeof( sSwapChain1 ) );
        sSwapChain1.Width = psCXT_SWAP->m_sMode.Width;
        sSwapChain1.Height = psCXT_SWAP->m_sMode.Height;
        sSwapChain1.Format = psCXT_SWAP->m_sMode.Format;
        sSwapChain1.Stereo = psCXT_SWAP->m_sMode.Stereo;
        sSwapChain1.SampleDesc.Quality = 0;
        sSwapChain1.SampleDesc.Count = (UINT)psSelect->m_niSample;
        sSwapChain1.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
        sSwapChain1.BufferCount = KTgKN_GPU_DX12_BUFFER_COUNT;
        sSwapChain1.Scaling = DXGI_SCALING_NONE;
    #if !defined(TgCOMPILE_PLATFORM_UWP)
        sSwapChain1.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
    #else
        sSwapChain.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
    #endif
        sSwapChain1.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
        sSwapChain1.Flags = uiFlags;

        sSwapChainFS.RefreshRate = psCXT_SWAP->m_sMode.RefreshRate;
        sSwapChainFS.ScanlineOrdering = psCXT_SWAP->m_sMode.ScanlineOrdering;
        sSwapChainFS.Scaling = psCXT_SWAP->m_sMode.Scaling;
        sSwapChainFS.Windowed = TRUE;

        pUnknown = (IUnknown*)psCXT_DEVC->m_psCmd_Queue__Direct;
    #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
        iRet = IDXGIFactory5_CreateSwapChainForHwnd( g_pDXGIFactory_5, pUnknown, g_hWnd, &sSwapChain1, &sSwapChainFS, nullptr, &pSwapChain1 );
    #else
        TgVERIFY( SUCCEEDED( IDXGIFactory5_CreateSwapChainForCoreWindow( g_pDXGIFactory_5, pUnknown, (IUnknown*)[CoreWindow Crap], &sSwapChain, nullptr, &pSwapChain1 ) ) );
    #endif
        if (FAILED( iRet ))
        {
            return (KTgE_FAIL);
        };
        iRet = IDXGISwapChain1_QueryInterface( pSwapChain1, &IID_IDXGISwapChain4, (PP_TgVOID)&psCXT_SWAP->m_psSwapChain4 );
        IDXGISwapChain1_Release( pSwapChain1 );
        if (FAILED( iRet ))
        {
            return (KTgE_FAIL);
        };

        TgVERIFY( SUCCEEDED( IDXGIFactory5_MakeWindowAssociation( g_pDXGIFactory_5, g_hWnd, DXGI_MWA_NO_ALT_ENTER ) ) );
    };


    /* Create resource views */

    uiSwap_Index = IDXGISwapChain4_GetCurrentBackBufferIndex( psCXT_SWAP->m_psSwapChain4 );
    psCXT_SWAP->m_uiSwap_Index = uiSwap_Index;
    sCPU_RTV = __ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart( psCXT_DEVC->m_psHeap_RTV );
    for (iRTV = 0; iRTV < KTgKN_GPU_DX12_BUFFER_COUNT; ++iRTV)
    {
        IDXGISwapChain4_GetBuffer( psCXT_SWAP->m_psSwapChain4, iRTV, &IID_ID3D12Resource, (PP_TgVOID)(psCXT_SWAP->m_apsRTV + iRTV) );
        ID3D12Device1_CreateRenderTargetView( psDevice1, psCXT_SWAP->m_apsRTV[iRTV], nullptr, sCPU_RTV );
        sCPU_RTV.ptr += psCXT_DEVC->m_uiDescriptor_Size_RTV;
    }

    depthHeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
    depthHeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
    depthHeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
    depthHeapProperties.CreationNodeMask = 1;
    depthHeapProperties.VisibleNodeMask = 1;

    __CD3DX12_RESOURCE_DESC_Tex2D( &depthResourceDesc, psCXT_SWAP->m_enFormat_DS, psCXT_SWAP->m_sMode.Width, psCXT_SWAP->m_sMode.Height );
    depthResourceDesc.MipLevels = 1;
    depthResourceDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;


    depthOptimizedClearValue.Format = psCXT_SWAP->m_enFormat_DS;
    depthOptimizedClearValue.DepthStencil.Depth = 1.0F;
    depthOptimizedClearValue.DepthStencil.Stencil = 0;

    TgVERIFY(SUCCEEDED(ID3D12Device1_CreateCommittedResource( psDevice1, &depthHeapProperties, D3D12_HEAP_FLAG_NONE, &depthResourceDesc, D3D12_RESOURCE_STATE_DEPTH_WRITE,
                                                              &depthOptimizedClearValue, &IID_ID3D12Resource, (PP_TgVOID)&psCXT_SWAP->m_psDepth_Stencil ) ) );

    memset( &dsvDesc, 0, sizeof( dsvDesc ) );
    dsvDesc.Format = psCXT_SWAP->m_enFormat_DS;
    dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
    dsvDesc.Flags = D3D12_DSV_FLAG_NONE;

    sCPU_RTV = __ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart( psCXT_DEVC->m_psHeap_DSV );
    ID3D12Device1_CreateDepthStencilView( psDevice1, psCXT_SWAP->m_psDepth_Stencil, &dsvDesc, sCPU_RTV );


    /* Initialize the Viewport */

    psCXT_SWAP->m_sViewPort.TopLeftX = 0.0F;
    psCXT_SWAP->m_sViewPort.TopLeftY = 0.0F;
    psCXT_SWAP->m_sViewPort.Width = (TgFLOAT32)psCXT_SWAP->m_sMode.Width;
    psCXT_SWAP->m_sViewPort.Height = (TgFLOAT32)psCXT_SWAP->m_sMode.Height;
    psCXT_SWAP->m_sViewPort.MinDepth = 0.0F;
    psCXT_SWAP->m_sViewPort.MaxDepth = 1.0F;
    psCXT_SWAP->m_sScissorRect.left = 0;
    psCXT_SWAP->m_sScissorRect.top = 0;
    psCXT_SWAP->m_sScissorRect.right = (LONG)psCXT_SWAP->m_sMode.Width;
    psCXT_SWAP->m_sScissorRect.bottom = (LONG)psCXT_SWAP->m_sMode.Height;

    /* Create synchronization objects */
    TgVERIFY(SUCCEEDED(ID3D12Device1_CreateFence( psDevice1, psCXT_SWAP->m_uiFenceValues[uiSwap_Index], D3D12_FENCE_FLAG_NONE, &IID_ID3D12Fence,
                                                  (PP_TgVOID)&psCXT_SWAP->m_psFence )));
    ++psCXT_SWAP->m_uiFenceValues[uiSwap_Index];
    psCXT_SWAP->m_psFenceEvent = g_pfnCreateEventEx( nullptr, FALSE, FALSE, EVENT_ALL_ACCESS );

    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Context__Free_Output -------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgKN_GPU_PM_Context__Free_Output( C_TgKN_GPU_CXT_SWAP_ID tiCXT_SWAP, C_TgBOOL bFreeSwap )
{
    P_STg2_KN_GPU_DX12_Context__Output  psCXT_SWAP;
    TgSINT32                            iIndex;

    TgPARAM_CHECK(TgTRUE != tgKN_GPU_CXT_SWAP_ID_Is_Valid( tiCXT_SWAP ));

    psCXT_SWAP = g_asKN_GPU_DX12_Context_Output + tiCXT_SWAP.m.iI;
    TgERROR( nullptr != psCXT_SWAP );

    if (TgTRUE == bFreeSwap)
    {
        if (nullptr != psCXT_SWAP->m_psSwapChain4)
        {
            TgVERIFY( 0 == IDXGISwapChain4_Release( psCXT_SWAP->m_psSwapChain4 ) );
            psCXT_SWAP->m_psSwapChain4 = nullptr;
        };
    };
    for (iIndex = 0; iIndex < (TgSINT32)TgARRAY_COUNT( psCXT_SWAP->m_apsRTV ); ++iIndex)
    {
        if (nullptr != psCXT_SWAP->m_apsRTV[iIndex])
        {
            TgVERIFY( 0 == ID3D12Resource_Release( psCXT_SWAP->m_apsRTV[iIndex] ) );
            psCXT_SWAP->m_apsRTV[iIndex] = nullptr;
        };
    };
    if (nullptr != psCXT_SWAP->m_psDepth_Stencil)
    {
        TgVERIFY( 0 == ID3D12Resource_Release( psCXT_SWAP->m_psDepth_Stencil ) );
    };
    if (nullptr != psCXT_SWAP->m_psFence)
    {
        TgVERIFY( 0 == ID3D12Fence_Release( psCXT_SWAP->m_psFence ) );
    };
    if (nullptr != psCXT_SWAP->m_psFenceEvent)
    {
        g_pfnCloseHandle( psCXT_SWAP->m_psFenceEvent );
        psCXT_SWAP->m_psFenceEvent = nullptr;
    };

    memset( psCXT_SWAP, 0, sizeof( STg2_KN_GPU_DX12_Context__Output ) );
    psCXT_SWAP->m_tiID = KTgKN_GPU_CXT_SWAP_ID__INVALID;
}


/* ---- tgKN_GPU_PM_Context__Init_Resource ------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgRESULT tgKN_GPU_PM_Context__Init_Resource( C_TgKN_GPU_CXT_DATA_ID tiCXT_DATA )
{
    tgKN_GPU_CXT_DATA__Init( tiCXT_DATA );
    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Context__Init_External ------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgRESULT tgKN_GPU_PM_Context__Init_External( C_TgKN_GPU_CXT_EXTN_ID UNUSED_PARAM tiCXT_EXEC )
{
    return (KTgS_OK);
}