Commit 26c61b24 by Omar El Sheikh Committed by Commit Bot

Vulkan: Fix to unset NULL Driver after tests

Updated ScopedVkLoaderEnvironment destructor to delete an environment variable that gets set during initialization of the renderer to load the Mock/Null driver for tests that request it. Bug: angleproject:2698 Change-Id: Ibbac795b6315971b303d97a55d24565a403d056c Reviewed-on: https://chromium-review.googlesource.com/1120940Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTobin Ehlis <tobine@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent c56adf60
...@@ -44,6 +44,18 @@ namespace ...@@ -44,6 +44,18 @@ namespace
// one for the vertex shader. // one for the vertex shader.
constexpr size_t kUniformBufferDescriptorsPerDescriptorSet = 2; constexpr size_t kUniformBufferDescriptorsPerDescriptorSet = 2;
bool ShouldEnableMockICD(const egl::AttributeMap &attribs)
{
#if !defined(ANGLE_PLATFORM_ANDROID)
// Mock ICD does not currently run on Android
return (attribs.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE) ==
EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE);
#else
return false;
#endif // !defined(ANGLE_PLATFORM_ANDROID)
}
VkResult VerifyExtensionsPresent(const std::vector<VkExtensionProperties> &extensionProps, VkResult VerifyExtensionsPresent(const std::vector<VkExtensionProperties> &extensionProps,
const std::vector<const char *> &enabledExtensionNames) const std::vector<const char *> &enabledExtensionNames)
{ {
...@@ -101,13 +113,28 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(VkDebugReportFlagsEXT flags, ...@@ -101,13 +113,28 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(VkDebugReportFlagsEXT flags,
class ScopedVkLoaderEnvironment : angle::NonCopyable class ScopedVkLoaderEnvironment : angle::NonCopyable
{ {
public: public:
explicit ScopedVkLoaderEnvironment(bool enableValidationLayers) ScopedVkLoaderEnvironment(bool enableValidationLayers, bool enableMockICD)
: mEnableValidationLayers(enableValidationLayers), mChangedCWD(false) : mEnableValidationLayers(enableValidationLayers),
mEnableMockICD(enableMockICD),
mChangedCWD(false),
mChangedICDPath(false)
{ {
// Changing CWD and setting environment variables makes no sense on Android, // Changing CWD and setting environment variables makes no sense on Android,
// since this code is a part of Java application there. // since this code is a part of Java application there.
// Android Vulkan loader doesn't need this either. // Android Vulkan loader doesn't need this either.
#if !defined(ANGLE_PLATFORM_ANDROID) #if !defined(ANGLE_PLATFORM_ANDROID)
if (enableMockICD)
{
// Override environment variable to use built Mock ICD
// ANGLE_VK_ICD_JSON gets set to the built mock ICD in BUILD.gn
mPreviousICDPath = angle::GetEnvironmentVar(g_VkICDPathEnv);
mChangedICDPath = angle::SetEnvironmentVar(g_VkICDPathEnv, ANGLE_VK_ICD_JSON);
if (!mChangedICDPath)
{
ERR() << "Error setting Path for Mock/Null Driver.";
mEnableMockICD = false;
}
}
if (mEnableValidationLayers) if (mEnableValidationLayers)
{ {
const auto &cwd = angle::GetCWD(); const auto &cwd = angle::GetCWD();
...@@ -150,14 +177,23 @@ class ScopedVkLoaderEnvironment : angle::NonCopyable ...@@ -150,14 +177,23 @@ class ScopedVkLoaderEnvironment : angle::NonCopyable
angle::SetCWD(mPreviousCWD.value().c_str()); angle::SetCWD(mPreviousCWD.value().c_str());
#endif // !defined(ANGLE_PLATFORM_ANDROID) #endif // !defined(ANGLE_PLATFORM_ANDROID)
} }
if (mChangedICDPath)
{
angle::SetEnvironmentVar(g_VkICDPathEnv, mPreviousICDPath.value().c_str());
}
} }
bool canEnableValidationLayers() const { return mEnableValidationLayers; } bool canEnableValidationLayers() const { return mEnableValidationLayers; }
bool canEnableMockICD() const { return mEnableMockICD; }
private: private:
bool mEnableValidationLayers; bool mEnableValidationLayers;
bool mEnableMockICD;
bool mChangedCWD; bool mChangedCWD;
Optional<std::string> mPreviousCWD; Optional<std::string> mPreviousCWD;
bool mChangedICDPath;
Optional<std::string> mPreviousICDPath;
}; };
} // anonymous namespace } // anonymous namespace
...@@ -286,24 +322,11 @@ void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices, ...@@ -286,24 +322,11 @@ void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices,
vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *wsiName) vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *wsiName)
{ {
ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs)); ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs),
ShouldEnableMockICD(attribs));
mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers(); mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers();
bool enableMockICD = scopedEnvironment.canEnableMockICD();
#if !defined(ANGLE_PLATFORM_ANDROID)
// Mock ICD does not currently run on Android
bool enableNullDriver = (attribs.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE) ==
EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE);
if (enableNullDriver)
{
// Override environment variable to use built Mock ICD
// ANGLE_VK_ICD_JSON gets set to the built mock ICD in BUILD.gn
ANGLE_VK_CHECK(angle::SetEnvironmentVar(g_VkICDPathEnv, ANGLE_VK_ICD_JSON),
VK_ERROR_INITIALIZATION_FAILED);
}
#else
constexpr bool enableNullDriver = false;
#endif // !defined(ANGLE_PLATFORM_ANDROID)
// Gather global layer properties. // Gather global layer properties.
uint32_t instanceLayerCount = 0; uint32_t instanceLayerCount = 0;
ANGLE_VK_TRY(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr)); ANGLE_VK_TRY(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr));
...@@ -399,7 +422,7 @@ vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *w ...@@ -399,7 +422,7 @@ vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *w
std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount); std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount);
ANGLE_VK_TRY( ANGLE_VK_TRY(
vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, physicalDevices.data())); vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, physicalDevices.data()));
ChoosePhysicalDevice(physicalDevices, enableNullDriver, &mPhysicalDevice, ChoosePhysicalDevice(physicalDevices, enableMockICD, &mPhysicalDevice,
&mPhysicalDeviceProperties); &mPhysicalDeviceProperties);
// Ensure we can find a graphics queue family. // Ensure we can find a graphics queue family.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment