Home

Resume

Blog

Teikitu


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

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

/* ---- tgKN_GPU_PM_Module_Init ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_PM_Module_Init( TgVOID )
{
    g_tiCVAR_KN_GPU_PM_Adapter = KTgCN_VAR_ID__INVALID;
    g_tiCVAR_KN_GPU_PM_Output = KTgCN_VAR_ID__INVALID;
    g_tiCVAR_KN_GPU_PM_Width = KTgCN_VAR_ID__INVALID;
    g_tiCVAR_KN_GPU_PM_Height = KTgCN_VAR_ID__INVALID;
    g_tiCVAR_KN_GPU_PM_Refresh_Rate = KTgCN_VAR_ID__INVALID;
    g_tiCVAR_KN_GPU_PM_ScanOut_HDR = KTgCN_VAR_ID__INVALID;

    g_szKN_GPU_PM_Adapter[0] = 0;
    g_szKN_GPU_PM_Output[0] = 0;
    g_uiKN_GPU_PM_Width = 0;
    g_uiKN_GPU_PM_Height = 0;
    g_uiKN_GPU_PM_Refresh_Rate = 60;
    g_bKN_GPU_PM_ScanOut_HDR = TgFALSE;


    g_hDLL_DXGI = nullptr;
    g_hDLL_DXGI_DEBUG = nullptr;
    g_hDLL_D3D12 = nullptr;

    g_pfnCreateDXGIFactory = nullptr;
    g_pfnD3D12CreateDevice = nullptr;
    g_pfnD3D12GetDebugInterface = nullptr;

    g_pDXGIFactory_5 = nullptr;

    if (TgFAILED( tgKN_PM_GPU_PM_Module_Init() ))
    {
        return (KTgE_FAIL);
    };

    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Module_Boot ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_PM_Module_Boot( TgVOID )
{
    if (TgFAILED(tgKN_PM_GPU_PM_Module_Boot()))
    {
        return (KTgE_FAIL);
    };

    TgERROR( nullptr != g_pDXGIFactory_5 );

    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Module_Stop ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_GPU_PM_Module_Stop( TgVOID )
{
    /* Free the enumeration lists */
    if (nullptr != g_pDXGIFactory_5)
    {
        TgVERIFY(0 == IDXGIFactory5_Release( g_pDXGIFactory_5 ));
        g_pDXGIFactory_5 = nullptr;
    };

    tgKN_PM_GPU_PM_Module_Stop();
}


/* ---- tgKN_GPU_PM_Module_Free ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_GPU_PM_Module_Free( TgVOID )
{
    tgKN_PM_GPU_PM_Module_Free();
}


/* ---- tgKN_GPU_PM_Module_Update --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_PM_Module_Update( C_TgFLOAT32 UNUSED_PARAM fdT )
{
    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Load_Config ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_PM_Load_Config( TgVOID )
{
    TgUINTXX                            uiKN;
    CP_TgCHAR                           pszVal;
    TgSIZE                              nuiVal;
    TgUINT32                            uiVal;

    uiKN = tgSZ_Hash( TgT("KERNEL") );
    g_szKN_GPU_PM_Adapter[0] = 0;
    if (TgSUCCEEDED( tgCM_Config_Query_String( &pszVal, &nuiVal, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Adapter") ) ) ))
        tgSZ_Copy( g_szKN_GPU_PM_Adapter, TgARRAY_COUNT( g_szKN_GPU_PM_Adapter ), pszVal );
    g_tiCVAR_KN_GPU_PM_Adapter = tgCN_Var_Init_String( TgT("KN_GPU_PM_Adapter"), TgT(""), KTgCN_VAR_INIT, 0, g_szKN_GPU_PM_Adapter, TgARRAY_COUNT(g_szKN_GPU_PM_Adapter) );

    g_szKN_GPU_PM_Output[0] = 0;
    if (TgSUCCEEDED( tgCM_Config_Query_String( &pszVal, &nuiVal, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Output") ) ) ))
        tgSZ_Copy( g_szKN_GPU_PM_Output, TgARRAY_COUNT( g_szKN_GPU_PM_Output ), pszVal );
    g_tiCVAR_KN_GPU_PM_Output = tgCN_Var_Init_String( TgT("KN_GPU_PM_Output"), TgT(""), KTgCN_VAR_INIT, 0, g_szKN_GPU_PM_Output, TgARRAY_COUNT(g_szKN_GPU_PM_Output) );

    if (TgFAILED( tgCM_Config_Query_U32( &g_uiKN_GPU_PM_Width, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Width") ) ) ))
        g_uiKN_GPU_PM_Width = 320;
    if (TgFAILED( tgCM_Config_Query_U32( &g_uiKN_GPU_PM_Height, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Height") ) ) ))
        g_uiKN_GPU_PM_Height = 200;
    if (TgFAILED( tgCM_Config_Query_U32( &g_uiKN_GPU_PM_Refresh_Rate, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Refresh_Rate") ) ) ))
        g_uiKN_GPU_PM_Refresh_Rate = 60;

    g_bKN_GPU_PM_ScanOut_HDR = TgFALSE;
    if (TgSUCCEEDED( tgCM_Config_Query_U32( &uiVal, uiKN, tgSZ_Hash( TgT( "KN_GPU_DX12_ScanOut_HDR" ) ) ) ))
        g_bKN_GPU_PM_ScanOut_HDR = 0 != uiVal ? TgTRUE : TgFALSE;

    g_tiCVAR_KN_GPU_PM_Width = tgCN_Var_Init_U32( TgT("KN_GPU_PM_Width"), TgT(""), KTgCN_VAR_INIT, g_uiKN_GPU_PM_Width, 320, 99999 );
    g_tiCVAR_KN_GPU_PM_Height = tgCN_Var_Init_U32( TgT("KN_GPU_PM_Height"), TgT(""), KTgCN_VAR_INIT, g_uiKN_GPU_PM_Height, 200, 99999 );
    g_tiCVAR_KN_GPU_PM_Refresh_Rate = tgCN_Var_Init_U32( TgT("KN_GPU_PM_Refresh_Rate"), TgT(""), KTgCN_VAR_INIT, g_uiKN_GPU_PM_Refresh_Rate, 0, 240 );
    g_tiCVAR_KN_GPU_PM_ScanOut_HDR = tgCN_Var_Init_Bool( TgT("KN_GPU_PM_ScanOut_HDR"), TgT(""), KTgCN_VAR_INIT, g_bKN_GPU_PM_ScanOut_HDR );

    return (KTgS_OK);
}


/* ---- tgKN_GPU_PM_Save_Config ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_PM_Save_Config( TgVOID )
{
    TgUINTXX                            uiKN;
    CP_TgCHAR                           pszVal;
    TgUINT32                            uiVal;

    uiKN = tgSZ_Hash( TgT("KERNEL") );
    if (TgFALSE != tgCN_VAR_ID_Is_Valid( g_tiCVAR_KN_GPU_PM_Adapter ) && TgTRUE == tgCN_Var_Query_String( &pszVal, g_tiCVAR_KN_GPU_PM_Adapter ))
        tgSZ_Copy( g_szKN_GPU_PM_Adapter, TgARRAY_COUNT( g_szKN_GPU_PM_Adapter ), pszVal );
    tgCM_Config_Set_String( g_szKN_GPU_PM_Adapter, TgARRAY_COUNT( g_szKN_GPU_PM_Adapter ), uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Adapter") ) );

    if (TgFALSE != tgCN_VAR_ID_Is_Valid( g_tiCVAR_KN_GPU_PM_Output ) && TgTRUE == tgCN_Var_Query_String( &pszVal, g_tiCVAR_KN_GPU_PM_Output ))
        tgSZ_Copy( g_szKN_GPU_PM_Output, TgARRAY_COUNT( g_szKN_GPU_PM_Output ), pszVal );
    tgCM_Config_Set_String( g_szKN_GPU_PM_Output, TgARRAY_COUNT( g_szKN_GPU_PM_Output ), uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Output") ) );

    if (TgFALSE != tgCN_VAR_ID_Is_Valid( g_tiCVAR_KN_GPU_PM_Width ) && TgTRUE == tgCN_Var_Query_U32( &uiVal, g_tiCVAR_KN_GPU_PM_Width ))
        g_uiKN_GPU_PM_Width = uiVal;
    tgCM_Config_Set_U32( g_uiKN_GPU_PM_Width, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Width") ) );

    if (TgFALSE == tgCN_VAR_ID_Is_Valid( g_tiCVAR_KN_GPU_PM_Height ) && TgTRUE == tgCN_Var_Query_U32( &uiVal, g_tiCVAR_KN_GPU_PM_Height ))
        g_uiKN_GPU_PM_Height = uiVal;
    tgCM_Config_Set_U32( g_uiKN_GPU_PM_Height, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Height") ) );

    if (TgFALSE == tgCN_VAR_ID_Is_Valid( g_tiCVAR_KN_GPU_PM_Refresh_Rate ) && TgTRUE == tgCN_Var_Query_U32( &uiVal, g_tiCVAR_KN_GPU_PM_Refresh_Rate ))
        g_uiKN_GPU_PM_Refresh_Rate = uiVal;
    tgCM_Config_Set_U32( g_uiKN_GPU_PM_Refresh_Rate, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_Refresh_Rate") ) );

    if (TgFALSE != tgCN_VAR_ID_Is_Valid( g_tiCVAR_KN_GPU_PM_ScanOut_HDR ) && TgTRUE == tgCN_Var_Query_U32( &uiVal, g_tiCVAR_KN_GPU_PM_ScanOut_HDR ))
        g_bKN_GPU_PM_ScanOut_HDR = 0 != uiVal ? TgTRUE : TgFALSE;
    tgCM_Config_Set_U32( (TgUINT32)g_bKN_GPU_PM_ScanOut_HDR, uiKN, tgSZ_Hash( TgT("KN_GPU_DX12_ScanOut_HDR") ) );

    return (KTgS_OK);
}