src/third_party/angle/src/common/vulkan/vulkan_icd.cpp
// If we're loading the validation layers, we could be running from any random directory.
// Change to the executable directory so we can find the layers, then change back to the
// previous directory to be safe we don't disrupt the application.
If we're loading the validation layers, we could be running from any random directory.
Change to the executable directory so we can find the layers, then change back to the
previous directory to be safe we don't disrupt the application.
If we ' re loading the validation layers we could be running from any random directory . Change to the executable directory so we can find the layers then change back to the previous directory to be safe we don ' t disrupt the application .
ScopedVkLoaderEnvironment::ScopedVkLoaderEnvironment(bool enableValidationLayers, vk::ICD icd)
    : mEnableValidationLayers(enableValidationLayers),
      mICD(icd),
      mChangedCWD(false),
      mChangedICDEnv(false)
{
#if !defined(ANGLE_PLATFORM_ANDROID) && !defined(ANGLE_PLATFORM_FUCHSIA) && \
    !defined(ANGLE_PLATFORM_GGP)
    if (icd == vk::ICD::Mock)
    {
        if (!setICDEnvironment(WrapICDEnvironment(ANGLE_VK_MOCK_ICD_JSON).c_str()))
        {
            ERR() << "Error setting environment for Mock/Null Driver.";
        }
    }
#    if defined(ANGLE_VK_SWIFTSHADER_ICD_JSON)
    else if (icd == vk::ICD::SwiftShader)
    {
        if (!setICDEnvironment(WrapICDEnvironment(ANGLE_VK_SWIFTSHADER_ICD_JSON).c_str()))
        {
            ERR() << "Error setting environment for SwiftShader.";
        }
    }
#    endif  
    if (mEnableValidationLayers || icd != vk::ICD::Default)
    {
        const auto &cwd = angle::GetCWD();
        if (!cwd.valid())
        {
            ERR() << "Error getting CWD for Vulkan layers init.";
            mEnableValidationLayers = false;
            mICD                    = vk::ICD::Default;
        }
        else
        {
            mPreviousCWD       = cwd.value();
            std::string exeDir = angle::GetExecutableDirectory();
            mChangedCWD        = angle::SetCWD(exeDir.c_str());
            if (!mChangedCWD)
            {
                ERR() << "Error setting CWD for Vulkan layers init.";
                mEnableValidationLayers = false;
                mICD                    = vk::ICD::Default;
            }
        }
    }
    if (mEnableValidationLayers)
    {
        if (!angle::PrependPathToEnvironmentVar(kLoaderLayersPathEnv, ANGLE_VK_LAYERS_DIR))
        {
            ERR() << "Error setting environment for Vulkan layers init.";
            mEnableValidationLayers = false;
        }
        if (!setCustomExtensionsEnvironment())
        {
            ERR() << "Error setting custom list for custom extensions for Vulkan layers init.";
            mEnableValidationLayers = false;
        }
    }
#endif  
}
ScopedVkLoaderEnvironment :: ScopedVkLoaderEnvironment ( bool enableValidationLayers , vk :: ICD icd ) : mEnableValidationLayers ( enableValidationLayers ) , mICD ( icd ) , mChangedCWD ( false ) , mChangedICDEnv ( false ) { #if ! defined ( ANGLE_PLATFORM_ANDROID ) && ! defined ( ANGLE_PLATFORM_FUCHSIA ) && ! defined ( ANGLE_PLATFORM_GGP ) if ( icd == vk :: ICD :: Mock ) { if ( ! setICDEnvironment ( WrapICDEnvironment ( ANGLE_VK_MOCK_ICD_JSON ) . c_str ( ) ) ) { ERR ( ) << " " ; } } #    if defined ( ANGLE_VK_SWIFTSHADER_ICD_JSON ) else if ( icd == vk :: ICD :: SwiftShader ) { if ( ! setICDEnvironment ( WrapICDEnvironment ( ANGLE_VK_SWIFTSHADER_ICD_JSON ) . c_str ( ) ) ) { ERR ( ) << " " ; } } #    endif if ( mEnableValidationLayers || icd != vk :: ICD :: Default ) { const auto & cwd = angle :: GetCWD ( ) ; if ( ! cwd . valid ( ) ) { ERR ( ) << " " ; mEnableValidationLayers = false ; mICD = vk :: ICD :: Default ; } else { mPreviousCWD = cwd . value ( ) ; std :: string exeDir = angle :: GetExecutableDirectory ( ) ; mChangedCWD = angle :: SetCWD ( exeDir . c_str ( ) ) ; if ( ! mChangedCWD ) { ERR ( ) << " " ; mEnableValidationLayers = false ; mICD = vk :: ICD :: Default ; } } } if ( mEnableValidationLayers ) { if ( ! angle :: PrependPathToEnvironmentVar ( kLoaderLayersPathEnv , ANGLE_VK_LAYERS_DIR ) ) { ERR ( ) << " " ; mEnableValidationLayers = false ; } if ( ! setCustomExtensionsEnvironment ( ) ) { ERR ( ) << " " ; mEnableValidationLayers = false ; } } #endif }
If we're loading the validation layers, we could be running from any random directory.
If we ' re loading the validation layers we could be running from any random directory .
// Changing CWD and setting environment variables makes no sense on Android, // since this code is a part of Java application there. // Android Vulkan loader doesn't need this either. // defined(ANGLE_VK_SWIFTSHADER_ICD_JSON) // Override environment variable to use the ANGLE layers. // !defined(ANGLE_PLATFORM_ANDROID)