Commit b8bbbf9e by Jamie Madill Committed by Commit Bot

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/671490Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent abd31359
#!/usr/bin/python
#
# Copyright 2016 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# generate_vulkan_header.py:
# Workaround problems with Windows and GYP and the Vulkan loader paths.
import os, sys
if len(sys.argv) < 4:
print("Usage: " + sys.argv[0] + " <json_source_path> <output_file> <product_dir>")
sys.exit(1)
layers_source_path = sys.argv[1]
output_file = sys.argv[2]
product_dir = sys.argv[3].rstrip("\"")
def fixpath(inpath):
return os.path.relpath(inpath, product_dir).replace('\\', '/')
with open(output_file, "w") as outfile:
outfile.write("#define LAYERS_SOURCE_PATH \"" + fixpath(layers_source_path) + "\"\n")
outfile.write("#define DEFAULT_VK_LAYERS_PATH \"" + fixpath(product_dir) + "\"\n")
...@@ -20,6 +20,7 @@ const char *GetExecutableDirectory(); ...@@ -20,6 +20,7 @@ const char *GetExecutableDirectory();
const char *GetSharedLibraryExtension(); const char *GetSharedLibraryExtension();
Optional<std::string> GetCWD(); Optional<std::string> GetCWD();
bool SetCWD(const char *dirName); bool SetCWD(const char *dirName);
bool SetEnvironmentVar(const char *variableName, const char *value);
} // namespace angle } // namespace angle
......
...@@ -81,4 +81,9 @@ bool SetCWD(const char *dirName) ...@@ -81,4 +81,9 @@ bool SetCWD(const char *dirName)
return (chdir(dirName) == 0); return (chdir(dirName) == 0);
} }
bool SetEnvironmentVar(const char *variableName, const char *value)
{
return (setenv(variableName, value, 1) == 0);
}
} // namespace angle } // namespace angle
...@@ -86,4 +86,9 @@ bool SetCWD(const char *dirName) ...@@ -86,4 +86,9 @@ bool SetCWD(const char *dirName)
return (chdir(dirName) == 0); return (chdir(dirName) == 0);
} }
bool SetEnvironmentVar(const char *variableName, const char *value)
{
return (setenv(variableName, value, 1) == 0);
}
} // namespace angle } // namespace angle
...@@ -71,4 +71,9 @@ bool SetCWD(const char *dirName) ...@@ -71,4 +71,9 @@ bool SetCWD(const char *dirName)
return (SetCurrentDirectoryA(dirName) == TRUE); return (SetCurrentDirectoryA(dirName) == TRUE);
} }
bool SetEnvironmentVar(const char *variableName, const char *value)
{
return (SetEnvironmentVariableA(variableName, value) == TRUE);
}
} // namespace angle } // namespace angle
...@@ -172,9 +172,23 @@ vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *w ...@@ -172,9 +172,23 @@ vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *w
else else
{ {
previousCWD = cwd.value(); previousCWD = cwd.value();
const char *exeDir = angle::GetExecutableDirectory();
if (!angle::SetCWD(exeDir))
{
ERR() << "Error setting CWD for Vulkan layers init.";
mEnableValidationLayers = false;
}
}
}
// 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;
} }
const char *exeDir = angle::GetExecutableDirectory();
angle::SetCWD(exeDir);
} }
// Gather global layer properties. // Gather global layer properties.
......
...@@ -74,6 +74,7 @@ VkAccessFlags GetBasicLayoutAccessFlags(VkImageLayout layout) ...@@ -74,6 +74,7 @@ VkAccessFlags GetBasicLayoutAccessFlags(VkImageLayout layout)
// Mirrors std_validation_str in loader.h // Mirrors std_validation_str in loader.h
// TODO(jmadill): Possibly wrap the loader into a safe source file. Can't be included trivially. // 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_VkStdValidationLayerName = "VK_LAYER_LUNARG_standard_validation";
const char *g_VkLoaderLayersPathEnv = "VK_LAYER_PATH";
const char *VulkanResultString(VkResult result) const char *VulkanResultString(VkResult result)
{ {
......
...@@ -33,6 +33,7 @@ const char *VulkanResultString(VkResult result); ...@@ -33,6 +33,7 @@ const char *VulkanResultString(VkResult result);
bool HasStandardValidationLayer(const std::vector<VkLayerProperties> &layerProps); bool HasStandardValidationLayer(const std::vector<VkLayerProperties> &layerProps);
extern const char *g_VkStdValidationLayerName; extern const char *g_VkStdValidationLayerName;
extern const char *g_VkLoaderLayersPathEnv;
enum class TextureDimension enum class TextureDimension
{ {
......
...@@ -195,8 +195,7 @@ config("vulkan_loader_config") { ...@@ -195,8 +195,7 @@ config("vulkan_loader_config") {
include_dirs = rebase_path(vulkan_gypi.vulkan_loader_include_dirs, ".", "src") include_dirs = rebase_path(vulkan_gypi.vulkan_loader_include_dirs, ".", "src")
include_dirs += [ vulkan_gen_dir ] include_dirs += [ vulkan_gen_dir ]
defines = [ defines = [
"LAYERS_SOURCE_PATH=\"$data_dir\"", "ANGLE_VK_LAYERS_DIR=\"$data_dir\"",
"DEFAULT_VK_LAYERS_PATH=\".\"",
"API_NAME=\"Vulkan\"", "API_NAME=\"Vulkan\"",
] ]
......
...@@ -916,9 +916,7 @@ ...@@ -916,9 +916,7 @@
{ {
'AdditionalOptions': 'AdditionalOptions':
[ [
# TODO(jmadill): Force include header on other platforms.
'<@(vulkan_loader_cflags_win)', '<@(vulkan_loader_cflags_win)',
'/FIangle_loader.h'
], ],
}, },
'VCLinkerTool': 'VCLinkerTool':
...@@ -945,6 +943,10 @@ ...@@ -945,6 +943,10 @@
], ],
}, },
}, },
'defines':
[
'ANGLE_VK_LAYERS_DIR="<(vulkan_json)"',
],
'conditions': 'conditions':
[ [
['OS=="win"', ['OS=="win"',
...@@ -971,7 +973,6 @@ ...@@ -971,7 +973,6 @@
{ {
'sources': 'sources':
[ [
'<(angle_gen_path)/vulkan/angle_loader.h',
'<@(vulkan_loader_win_sources)', '<@(vulkan_loader_win_sources)',
], ],
'defines': 'defines':
...@@ -984,51 +985,12 @@ ...@@ -984,51 +985,12 @@
{ {
'defines': 'defines':
[ [
'DEFAULT_VK_LAYERS_PATH="."',
'HAVE_SECURE_GETENV', 'HAVE_SECURE_GETENV',
'LAYERS_SOURCE_PATH="<(vulkan_json)"',
'VK_USE_PLATFORM_XCB_KHR', 'VK_USE_PLATFORM_XCB_KHR',
'VK_USE_PLATFORM_XCB_KHX', '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',
]
},
],
}, },
{ {
......
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