Vulkan: Use environment override to load layers.
Instead of using a compile-time define, use an OS call to override
the environment variable the loader uses to look for layers. This
should allow us to have a run-time override mechanism, so we can
more easily use ANGLE with RenderDoc and other tools that hook
into the layers for debugging and profiling purposes.
This should also allow the developer to install and use their own
layers with ANGLE if desired.
This patch removes the angle_loader.h generation since it is no
longer necessary.
It also fixes an unrelated loader warning that occured when releasing
the current pipeline object.
BUG=angleproject:1898
Change-Id: Ic4a5120a6b73745397451ef9e3897e157da1feda
Reviewed-on: https://chromium-review.googlesource.com/671490
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/common/system_utils.h b/src/common/system_utils.h
index cac24f7..d61faa5 100644
--- a/src/common/system_utils.h
+++ b/src/common/system_utils.h
@@ -20,6 +20,7 @@
const char *GetSharedLibraryExtension();
Optional<std::string> GetCWD();
bool SetCWD(const char *dirName);
+bool SetEnvironmentVar(const char *variableName, const char *value);
} // namespace angle
diff --git a/src/common/system_utils_linux.cpp b/src/common/system_utils_linux.cpp
index 8504c6a..98ab4cc 100644
--- a/src/common/system_utils_linux.cpp
+++ b/src/common/system_utils_linux.cpp
@@ -81,4 +81,9 @@
return (chdir(dirName) == 0);
}
+bool SetEnvironmentVar(const char *variableName, const char *value)
+{
+ return (setenv(variableName, value, 1) == 0);
+}
+
} // namespace angle
diff --git a/src/common/system_utils_mac.cpp b/src/common/system_utils_mac.cpp
index a73f1aa..03b9185 100644
--- a/src/common/system_utils_mac.cpp
+++ b/src/common/system_utils_mac.cpp
@@ -86,4 +86,9 @@
return (chdir(dirName) == 0);
}
+bool SetEnvironmentVar(const char *variableName, const char *value)
+{
+ return (setenv(variableName, value, 1) == 0);
+}
+
} // namespace angle
diff --git a/src/common/system_utils_win.cpp b/src/common/system_utils_win.cpp
index 8f765ff..6bb2bfb 100644
--- a/src/common/system_utils_win.cpp
+++ b/src/common/system_utils_win.cpp
@@ -71,4 +71,9 @@
return (SetCurrentDirectoryA(dirName) == TRUE);
}
+bool SetEnvironmentVar(const char *variableName, const char *value)
+{
+ return (SetEnvironmentVariableA(variableName, value) == TRUE);
+}
+
} // namespace angle
diff --git a/src/libANGLE/renderer/vulkan/RendererVk.cpp b/src/libANGLE/renderer/vulkan/RendererVk.cpp
index bc090b0..8ca9d65 100644
--- a/src/libANGLE/renderer/vulkan/RendererVk.cpp
+++ b/src/libANGLE/renderer/vulkan/RendererVk.cpp
@@ -172,9 +172,23 @@
else
{
previousCWD = cwd.value();
+ const char *exeDir = angle::GetExecutableDirectory();
+ if (!angle::SetCWD(exeDir))
+ {
+ ERR() << "Error setting CWD for Vulkan layers init.";
+ mEnableValidationLayers = false;
+ }
}
- const char *exeDir = angle::GetExecutableDirectory();
- angle::SetCWD(exeDir);
+ }
+
+ // Override environment variable to use the ANGLE layers.
+ if (mEnableValidationLayers)
+ {
+ if (!angle::SetEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_LAYERS_DIR))
+ {
+ ERR() << "Error setting environment for Vulkan layers init.";
+ mEnableValidationLayers = false;
+ }
}
// Gather global layer properties.
diff --git a/src/libANGLE/renderer/vulkan/renderervk_utils.cpp b/src/libANGLE/renderer/vulkan/renderervk_utils.cpp
index 900a8fe..f593064 100644
--- a/src/libANGLE/renderer/vulkan/renderervk_utils.cpp
+++ b/src/libANGLE/renderer/vulkan/renderervk_utils.cpp
@@ -74,6 +74,7 @@
// Mirrors std_validation_str in loader.h
// TODO(jmadill): Possibly wrap the loader into a safe source file. Can't be included trivially.
const char *g_VkStdValidationLayerName = "VK_LAYER_LUNARG_standard_validation";
+const char *g_VkLoaderLayersPathEnv = "VK_LAYER_PATH";
const char *VulkanResultString(VkResult result)
{
diff --git a/src/libANGLE/renderer/vulkan/renderervk_utils.h b/src/libANGLE/renderer/vulkan/renderervk_utils.h
index 22e6ad9..1dce00a 100644
--- a/src/libANGLE/renderer/vulkan/renderervk_utils.h
+++ b/src/libANGLE/renderer/vulkan/renderervk_utils.h
@@ -33,6 +33,7 @@
bool HasStandardValidationLayer(const std::vector<VkLayerProperties> &layerProps);
extern const char *g_VkStdValidationLayerName;
+extern const char *g_VkLoaderLayersPathEnv;
enum class TextureDimension
{
diff --git a/src/vulkan_support/BUILD.gn b/src/vulkan_support/BUILD.gn
index 230c0aa..b0bbe37 100644
--- a/src/vulkan_support/BUILD.gn
+++ b/src/vulkan_support/BUILD.gn
@@ -195,8 +195,7 @@
include_dirs = rebase_path(vulkan_gypi.vulkan_loader_include_dirs, ".", "src")
include_dirs += [ vulkan_gen_dir ]
defines = [
- "LAYERS_SOURCE_PATH=\"$data_dir\"",
- "DEFAULT_VK_LAYERS_PATH=\".\"",
+ "ANGLE_VK_LAYERS_DIR=\"$data_dir\"",
"API_NAME=\"Vulkan\"",
]
diff --git a/src/vulkan_support/vulkan.gypi b/src/vulkan_support/vulkan.gypi
index 58522e1..c76e2d8 100644
--- a/src/vulkan_support/vulkan.gypi
+++ b/src/vulkan_support/vulkan.gypi
@@ -916,9 +916,7 @@
{
'AdditionalOptions':
[
- # TODO(jmadill): Force include header on other platforms.
'<@(vulkan_loader_cflags_win)',
- '/FIangle_loader.h'
],
},
'VCLinkerTool':
@@ -945,6 +943,10 @@
],
},
},
+ 'defines':
+ [
+ 'ANGLE_VK_LAYERS_DIR="<(vulkan_json)"',
+ ],
'conditions':
[
['OS=="win"',
@@ -971,7 +973,6 @@
{
'sources':
[
- '<(angle_gen_path)/vulkan/angle_loader.h',
'<@(vulkan_loader_win_sources)',
],
'defines':
@@ -984,51 +985,12 @@
{
'defines':
[
- 'DEFAULT_VK_LAYERS_PATH="."',
'HAVE_SECURE_GETENV',
- 'LAYERS_SOURCE_PATH="<(vulkan_json)"',
'VK_USE_PLATFORM_XCB_KHR',
'VK_USE_PLATFORM_XCB_KHX',
],
}],
],
- 'actions':
- [
- {
- # The loader header is force included into the loader and layers. Because
- # of issues with GYP, we can't use a normal header file, we hav to force
- # inclue this using compiler-specific flags.
- 'action_name': 'vulkan_loader_gen_angle_header',
- 'message': 'generating Vulkan loader ANGLE header',
- 'msvs_cygwin_shell': 0,
- 'inputs':
- [
- '<(angle_path)/scripts/generate_vulkan_header.py',
- ],
- 'outputs':
- [
- '<(angle_gen_path)/vulkan/angle_loader.h',
- ],
- 'action':
- [
- # TODO(jmadill): Use correct platform path
- 'python', '<(angle_path)/scripts/generate_vulkan_header.py', '<(PRODUCT_DIR)/<(vulkan_json)',
- '<(angle_gen_path)/vulkan/angle_loader.h', '<(PRODUCT_DIR)',
- ],
- },
- {
- 'action_name': 'vulkan_loader_order_deps',
- 'message': 'stamping for vulkan_loader_order_deps',
- 'msvs_cygwin_shell': 0,
- 'inputs': [ '<@(vulkan_layer_generated_files)' ],
- 'outputs': [ '<(angle_gen_path)/vulkan/vulkan_loader_order_deps.stamp' ],
- 'action':
- [
- 'python', '<(angle_path)/gyp/touch_stamp.py',
- '<(angle_gen_path)/vulkan/vulkan_loader_order_deps.stamp',
- ]
- },
- ],
},
{