Home

Resume

Blog

Teikitu


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

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

/* ---- tgKN_GPU_DXGI_Select_Min_Mode ----------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_DXGI_Select_Min_Mode( PC_STg2_KN_GPU_Mode psSelect, PCU_STg2_KN_GPU_DXGI_Output psOutput_Info, CPC_STg2_KN_GPU_Mode psRequest )
{
    C_TgUINT32                          nuiModes = (TgUINT32)psOutput_Info->m_niMode;
    TgUINT32                            uiWidth = psRequest->m_uiWidth;
    TgUINT32                            uiHeight = psRequest->m_uiHeight;
    TgUINT32                            uiIndex=0;
    DXGI_FORMAT                         enDXGI_Format;

    TgPARAM_CHECK(nullptr != psOutput_Info);

    if (psOutput_Info->m_psMode[uiIndex].Width < uiWidth)
    {
        for (++uiIndex; uiIndex < nuiModes; ++uiIndex)
        {
            if (psOutput_Info->m_psMode[uiIndex].Width > uiWidth)
            {
                break;
            };
        };
        --uiIndex;
    };

    uiWidth = psOutput_Info->m_psMode[uiIndex].Width;
    if (0 == uiIndex)
    {
        for (++uiIndex; uiIndex < nuiModes; ++uiIndex)
        {
            if (psOutput_Info->m_psMode[uiIndex].Width > uiWidth)
            {
                break;
            };
        };
        --uiIndex;
    };

    if (psOutput_Info->m_psMode[uiIndex].Height > uiHeight)
    {
        for (; uiIndex > 0; --uiIndex)
        {
            if (psOutput_Info->m_psMode[uiIndex].Height < uiHeight || psOutput_Info->m_psMode[uiIndex-1].Width != uiWidth)
            {
                break;
            };
        };
    };

    uiHeight = psOutput_Info->m_psMode[uiIndex].Height;
    if (0 == uiIndex || psOutput_Info->m_psMode[uiIndex-1].Width != uiWidth)
    {
        for (++uiIndex; uiIndex < nuiModes && psOutput_Info->m_psMode[uiIndex].Width == uiWidth && psOutput_Info->m_psMode[uiIndex].Height == uiHeight; ++uiIndex);
        --uiIndex;
    };

    enDXGI_Format = KTgKN_DX_TARGET_LIST[psRequest->m_enFormat];
    if (psOutput_Info->m_psMode[uiIndex].Format != enDXGI_Format)
    {
        for (; uiIndex > 0; --uiIndex)
        {
            if (psOutput_Info->m_psMode[uiIndex].Format == enDXGI_Format)
            {
                break;
            };

            if (psOutput_Info->m_psMode[uiIndex-1].Width != uiWidth || psOutput_Info->m_psMode[uiIndex-1].Height != uiHeight)
            {
                break;
            };
        };
    };

    if (psOutput_Info->m_psMode[uiIndex].Format != enDXGI_Format)
    {
        return (KTgE_FAIL);
    };

    if (psOutput_Info->m_psMode[uiIndex].RefreshRate.Denominator > psRequest->m_uiRefresh_Rate*psOutput_Info->m_psMode[uiIndex].RefreshRate.Numerator)
    {
        for (; uiIndex > 0; --uiIndex)
        {
            if(
                psOutput_Info->m_psMode[uiIndex-1].Format != enDXGI_Format ||
                psOutput_Info->m_psMode[uiIndex-1].Width != uiWidth ||
                psOutput_Info->m_psMode[uiIndex-1].Height != uiHeight )
            {
                break;
            };

            if (psOutput_Info->m_psMode[uiIndex].RefreshRate.Denominator < psRequest->m_uiRefresh_Rate*psOutput_Info->m_psMode[uiIndex].RefreshRate.Numerator)
            {
                break;
            };
        };
    };

    psSelect->m_uiWidth = psOutput_Info->m_psMode[uiIndex].Width;
    psSelect->m_uiHeight = psOutput_Info->m_psMode[uiIndex].Height;
    psSelect->m_uiRefresh_Rate  = psOutput_Info->m_psMode[uiIndex].RefreshRate.Denominator;
    psSelect->m_uiRefresh_Rate /= psOutput_Info->m_psMode[uiIndex].RefreshRate.Numerator;
    psSelect->m_enFormat = psRequest->m_enFormat;

    return (KTgS_OK);
}


/* ---- tgKN_GPU_DXGI_Select_Max_Mode ----------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgKN_GPU_DXGI_Select_Max_Mode( PC_STg2_KN_GPU_Mode psSelect, PCU_STg2_KN_GPU_DXGI_Output psOutput_Info, CPC_STg2_KN_GPU_Mode psRequest )
{
    C_TgUINT32                          nuiModes = (TgUINT32)psOutput_Info->m_niMode;
    TgUINT32                            uiWidth = psRequest->m_uiWidth;
    TgUINT32                            uiHeight = psRequest->m_uiHeight;
    TgUINT32                            uiIndex=0;
    DXGI_FORMAT                         enDXGI_Format;

    TgPARAM_CHECK(nullptr != psOutput_Info);

    if (psOutput_Info->m_psMode[uiIndex].Width < uiWidth)
    {
        for (; uiIndex < nuiModes; ++uiIndex)
        {
            if (psOutput_Info->m_psMode[uiIndex].Width >= uiWidth)
            {
                break;
            };
        };
    };

    if (uiIndex == nuiModes)
    {
        uiWidth = psOutput_Info->m_psMode[--uiIndex].Width;
        for (; uiIndex > 0; --uiIndex)
        {
            if (psOutput_Info->m_psMode[uiIndex-1].Width != uiWidth)
            {
                break;
            };
        };
    }
    else
    {
        uiWidth = psOutput_Info->m_psMode[uiIndex].Width;
    };

    if (psOutput_Info->m_psMode[uiIndex].Height < uiHeight)
    {
        for (;; ++uiIndex)
        {
            if (uiIndex == nuiModes || uiWidth != psOutput_Info->m_psMode[uiIndex].Width)
            {
                uiHeight = psOutput_Info->m_psMode[--uiIndex].Height;
                for (; uiIndex > 0; --uiIndex)
                {
                    if (psOutput_Info->m_psMode[uiIndex-1].Height != uiHeight || psOutput_Info->m_psMode[uiIndex-1].Width != uiWidth)
                    {
                        break;
                    };
                };
                break;
            };

            if( psOutput_Info->m_psMode[uiIndex].Height >= uiHeight )
            {
                break;
            };
        };
    };

    uiHeight = psOutput_Info->m_psMode[uiIndex].Height;

    enDXGI_Format = KTgKN_DX_TARGET_LIST[psRequest->m_enFormat];
    if (psOutput_Info->m_psMode[uiIndex].Format != enDXGI_Format)
    {
        for (;; ++uiIndex)
        {
            if (   uiIndex == nuiModes
                || psOutput_Info->m_psMode[uiIndex].Width != uiWidth
                || psOutput_Info->m_psMode[uiIndex].Height != uiHeight
                || psOutput_Info->m_psMode[uiIndex].Format == enDXGI_Format)
            {
                break;
            };
        };
    };

    if (   uiIndex == nuiModes
        || psOutput_Info->m_psMode[uiIndex].Width != uiWidth
        || psOutput_Info->m_psMode[uiIndex].Height != uiHeight
        || psOutput_Info->m_psMode[uiIndex].Format != enDXGI_Format
    ) {
            return (KTgE_FAIL);
    };

    if (psOutput_Info->m_psMode[uiIndex].RefreshRate.Denominator <
        psRequest->m_uiRefresh_Rate*psOutput_Info->m_psMode[uiIndex].RefreshRate.Numerator)
    {
        for( ;; ++uiIndex )
        {
            if (   uiIndex == nuiModes
                || psOutput_Info->m_psMode[uiIndex].Width != uiWidth
                || psOutput_Info->m_psMode[uiIndex].Height != uiHeight
                || psOutput_Info->m_psMode[uiIndex].Format != enDXGI_Format)
            {
                --uiIndex;
                break;
            };

            if (psOutput_Info->m_psMode[uiIndex].RefreshRate.Denominator >=
                psRequest->m_uiRefresh_Rate*psOutput_Info->m_psMode[uiIndex].RefreshRate.Numerator)
            {
                break;
            };
        };
    };

    psSelect->m_uiWidth = psOutput_Info->m_psMode[uiIndex].Width;
    psSelect->m_uiHeight = psOutput_Info->m_psMode[uiIndex].Height;
    psSelect->m_uiRefresh_Rate  = psOutput_Info->m_psMode[uiIndex].RefreshRate.Denominator;
    psSelect->m_uiRefresh_Rate /= psOutput_Info->m_psMode[uiIndex].RefreshRate.Numerator;
    psSelect->m_enFormat = psRequest->m_enFormat;

    return (KTgS_OK);
}