context/llpcCompiler.cpp
ShaderEntryState Compiler::LookUpShaderCaches(
    IShaderCache*                    pAppPipelineCache, // [in]    App's pipeline cache
    MetroHash::Hash*                 pCacheHash,        // [in]    Hash code of the shader
    BinaryData*                      pElfBin,           // [inout] Pointer to shader data
    ShaderCache**                    ppShaderCache,     // [in]    Array of shader caches.
    CacheEntryHandle*                phEntry            // [in]    Array of handles of the shader caches entry
    )
{
    ShaderEntryState cacheEntryState  = ShaderEntryState::New;
    uint32_t         shaderCacheCount = 1;
    Result           result           = Result::Success;

    if (pAppPipelineCache != nullptr)
    {
        ppShaderCache[0] = static_cast<ShaderCache*>(pAppPipelineCache);
        ppShaderCache[1] = m_shaderCache.get();
        shaderCacheCount = 2;
    }
    else
    {
        ppShaderCache[0] = m_shaderCache.get();
        ppShaderCache[1] = nullptr;
    }

    if (cl::ShaderCacheMode == ShaderCacheForceInternalCacheOnDisk)
    {
        ppShaderCache[0] = m_shaderCache.get();
        ppShaderCache[1] = nullptr;
        shaderCacheCount = 1;
    }

    for (uint32_t i = 0; i < shaderCacheCount; i++)
    {
        cacheEntryState = ppShaderCache[i]->FindShader(*pCacheHash, true, &phEntry[i]);
        if (cacheEntryState == ShaderEntryState::Ready)
        {
            result = ppShaderCache[i]->RetrieveShader(phEntry[i], &pElfBin->pCode, &pElfBin->codeSize);
            // Re-try if shader cache return error unknown
            if (result == Result::ErrorUnknown)
            {
                result = Result::Success;
                phEntry[i] = nullptr;
                cacheEntryState = ShaderEntryState::Compiling;
            }
            else
            {
                if (i == 1)
                {
                    // App's pipeline cache misses while internal cache hits
                    if (phEntry[0] != nullptr)
                    {
                        LLPC_ASSERT(pElfBin->codeSize > 0);
                        ppShaderCache[0]->InsertShader(phEntry[0], pElfBin->pCode, pElfBin->codeSize);
                    }
                }
                break;
            }
        }
    }

    return cacheEntryState;
}
// =====================================================================================================================
// Lookup in the shader caches with the given pipeline hash code.
// It will try App's pipelince cache first if that's available.
// Then try on the internal shader cache next if it misses.
//
// NOTE: Only two items in the array of shader caches; one for App's pipeline cache and one for internal cache
Lookup in the shader caches with the given pipeline hash code.
It will try App's pipelince cache first if that's available.
Then try on the internal shader cache next if it misses.

Only two items in the array of shader caches; one for App's pipeline cache and one for internal cache
Lookup in the shader caches with the given pipeline hash code . It will try App ' s pipelince cache first if that ' s available . Then try on the internal shader cache next if it misses . Only two items in the array of shader caches ; one for App ' s pipeline cache and one for internal cache
ShaderEntryState Compiler::LookUpShaderCaches(
    IShaderCache*                    pAppPipelineCache, 
    MetroHash::Hash*                 pCacheHash,        
    BinaryData*                      pElfBin,           
    ShaderCache**                    ppShaderCache,     
    CacheEntryHandle*                phEntry            
    )
{
    ShaderEntryState cacheEntryState  = ShaderEntryState::New;
    uint32_t         shaderCacheCount = 1;
    Result           result           = Result::Success;
    if (pAppPipelineCache != nullptr)
    {
        ppShaderCache[0] = static_cast<ShaderCache*>(pAppPipelineCache);
        ppShaderCache[1] = m_shaderCache.get();
        shaderCacheCount = 2;
    }
    else
    {
        ppShaderCache[0] = m_shaderCache.get();
        ppShaderCache[1] = nullptr;
    }
    if (cl::ShaderCacheMode == ShaderCacheForceInternalCacheOnDisk)
    {
        ppShaderCache[0] = m_shaderCache.get();
        ppShaderCache[1] = nullptr;
        shaderCacheCount = 1;
    }
    for (uint32_t i = 0; i < shaderCacheCount; i++)
    {
        cacheEntryState = ppShaderCache[i]->FindShader(*pCacheHash, true, &phEntry[i]);
        if (cacheEntryState == ShaderEntryState::Ready)
        {
            result = ppShaderCache[i]->RetrieveShader(phEntry[i], &pElfBin->pCode, &pElfBin->codeSize);
            if (result == Result::ErrorUnknown)
            {
                result = Result::Success;
                phEntry[i] = nullptr;
                cacheEntryState = ShaderEntryState::Compiling;
            }
            else
            {
                if (i == 1)
                {
                    if (phEntry[0] != nullptr)
                    {
                        LLPC_ASSERT(pElfBin->codeSize > 0);
                        ppShaderCache[0]->InsertShader(phEntry[0], pElfBin->pCode, pElfBin->codeSize);
                    }
                }
                break;
            }
        }
    }
    return cacheEntryState;
}
ShaderEntryState Compiler :: LookUpShaderCaches ( IShaderCache * pAppPipelineCache , MetroHash :: Hash * pCacheHash , BinaryData * pElfBin , ShaderCache * * ppShaderCache , CacheEntryHandle * phEntry ) { ShaderEntryState cacheEntryState = ShaderEntryState :: New ; uint32_t shaderCacheCount = 1 ; Result result = Result :: Success ; if ( pAppPipelineCache != nullptr ) { ppShaderCache [ 0 ] = static_cast < ShaderCache * > ( pAppPipelineCache ) ; ppShaderCache [ 1 ] = m_shaderCache . get ( ) ; shaderCacheCount = 2 ; } else { ppShaderCache [ 0 ] = m_shaderCache . get ( ) ; ppShaderCache [ 1 ] = nullptr ; } if ( cl :: ShaderCacheMode == ShaderCacheForceInternalCacheOnDisk ) { ppShaderCache [ 0 ] = m_shaderCache . get ( ) ; ppShaderCache [ 1 ] = nullptr ; shaderCacheCount = 1 ; } for ( uint32_t i = 0 ; i < shaderCacheCount ; i ++ ) { cacheEntryState = ppShaderCache [ i ] -> FindShader ( * pCacheHash , true , & phEntry [ i ] ) ; if ( cacheEntryState == ShaderEntryState :: Ready ) { result = ppShaderCache [ i ] -> RetrieveShader ( phEntry [ i ] , & pElfBin -> pCode , & pElfBin -> codeSize ) ; if ( result == Result :: ErrorUnknown ) { result = Result :: Success ; phEntry [ i ] = nullptr ; cacheEntryState = ShaderEntryState :: Compiling ; } else { if ( i == 1 ) { if ( phEntry [ 0 ] != nullptr ) { LLPC_ASSERT ( pElfBin -> codeSize > 0 ) ; ppShaderCache [ 0 ] -> InsertShader ( phEntry [ 0 ] , pElfBin -> pCode , pElfBin -> codeSize ) ; } } break ; } } } return cacheEntryState ; }
Lookup in the shader caches with the given pipeline hash code.
Lookup in the shader caches with the given pipeline hash code .
// [in]    App's pipeline cache // [in]    Hash code of the shader // [inout] Pointer to shader data // [in]    Array of shader caches. // [in]    Array of handles of the shader caches entry // Re-try if shader cache return error unknown // App's pipeline cache misses while internal cache hits