Improve ScopedEnvironmentVar to distinguish between null and empty

Found while investigating Swiftshader support. Some Vulkan loaders
fail to create an instance if VK_ICD_FILENAMES is empty string
rather than entirely absent. It was set to empty string because
Dawn did not distinguish between nonexistent environment variables
and the empty string. This CL adds distinguishing between the two,
including tests for the behavior.

Bug: chromium:1266550
Change-Id: I1680a281f62e6b340009e01da65db9d485e2975e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/69520
Auto-Submit: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng
2021-11-16 23:37:15 +00:00
committed by Dawn LUCI CQ
parent 970739e4e3
commit 09c308cfcf
5 changed files with 85 additions and 37 deletions

View File

@@ -92,8 +92,9 @@ static utils::TerribleCommandBuffer* c2sBuf = nullptr;
static utils::TerribleCommandBuffer* s2cBuf = nullptr;
wgpu::Device CreateCppDawnDevice() {
if (GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM").empty()) {
SetEnvironmentVar("ANGLE_DEFAULT_PLATFORM", "swiftshader");
ScopedEnvironmentVar angleDefaultPlatform;
if (GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM").first.empty()) {
angleDefaultPlatform.Set("ANGLE_DEFAULT_PLATFORM", "swiftshader");
}
glfwSetErrorCallback(PrintGLFWError);