From 6e2e36cc8b4e2996f1b1d1d838b8d3e1d5924720 Mon Sep 17 00:00:00 2001 From: Sergey Ulanov Date: Fri, 19 Nov 2021 00:57:29 +0000 Subject: [PATCH] [Fuchsia] Fix SwiftShader ICD discovery ANGLE needs to set VK_ICD_FILENAMES for the Vulkan loader to discover SwiftShader's ICD. Enable this logic on Fuchsia. Also updated ConcatenatePath() to handle absolute paths correctly. Bug: chromium:1225002 Change-Id: Ib69be0d7dcaef09f1da9d411023e90a3b7b4fca2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3292347 Reviewed-by: Jamie Madill Reviewed-by: Shahbaz Youssefi Commit-Queue: Shahbaz Youssefi --- src/common/system_utils.cpp | 2 +- src/common/system_utils_unittest.cpp | 4 ++-- src/common/vulkan/BUILD.gn | 15 ++++++++++----- src/common/vulkan/vulkan_icd.cpp | 17 ++++++++--------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/common/system_utils.cpp b/src/common/system_utils.cpp index b71115ab2..7f7fb4ca4 100644 --- a/src/common/system_utils.cpp +++ b/src/common/system_utils.cpp @@ -122,7 +122,7 @@ std::string ConcatenatePath(std::string first, std::string second) } if (IsFullPath(second)) { - return first; + return second; } bool firstRedundantPathSeparator = first.find_last_of(GetPathSeparator()) == first.length() - 1; bool secondRedundantPathSeparator = second.find(GetPathSeparator()) == 0; diff --git a/src/common/system_utils_unittest.cpp b/src/common/system_utils_unittest.cpp index 317093c77..b59c75116 100644 --- a/src/common/system_utils_unittest.cpp +++ b/src/common/system_utils_unittest.cpp @@ -121,7 +121,7 @@ TEST(SystemUtils, ConcatenatePath2FullPath) { std::string path1 = "/this/is/path1"; std::string path2 = "/this/is/path2"; - std::string expected = "/this/is/path1"; + std::string expected = "/this/is/path2"; EXPECT_EQ(ConcatenatePath(path1, path2), expected); } @@ -169,7 +169,7 @@ TEST(SystemUtils, ConcatenatePath2FullPath) { std::string path1 = "C:\\this\\is\\path1"; std::string path2 = "C:\\this\\is\\path2"; - std::string expected = "C:\\this\\is\\path1"; + std::string expected = "C:\\this\\is\\path2"; EXPECT_EQ(ConcatenatePath(path1, path2), expected); } diff --git a/src/common/vulkan/BUILD.gn b/src/common/vulkan/BUILD.gn index 964c0625b..6385a33aa 100644 --- a/src/common/vulkan/BUILD.gn +++ b/src/common/vulkan/BUILD.gn @@ -50,10 +50,13 @@ if (angle_enable_vulkan || angle_build_vulkan_system_info) { "vulkan_icd.h", ] - defines = [ - "ANGLE_VK_LAYERS_DIR=\"$angle_data_dir\"", - "ANGLE_VK_MOCK_ICD_JSON=\"$angle_data_dir/VkICD_mock_icd.json\"", - ] + defines = + [ "ANGLE_VK_MOCK_ICD_JSON=\"$angle_data_dir/VkICD_mock_icd.json\"" ] + + # On Fuchsia use validation layer provided by the SDK. + if (!is_fuchsia) { + defines += [ "ANGLE_VK_LAYERS_DIR=\"$angle_data_dir\"" ] + } data_deps = [] @@ -62,6 +65,8 @@ if (angle_enable_vulkan || angle_build_vulkan_system_info) { _sws_icd = "./$swiftshader_icd_file_name" if (is_win) { _sws_icd = ".\\\\$swiftshader_icd_file_name" + } else if (is_fuchsia) { + _sws_icd = "/pkg/$swiftshader_icd_file_name" } defines += [ "ANGLE_VK_SWIFTSHADER_ICD_JSON=\"${_sws_icd}\"" ] @@ -126,7 +131,7 @@ if (angle_enable_vulkan) { group("vulkan_validation_layers") { data_deps = [] if (is_fuchsia) { - data_deps += [ "//third_party/fuchsia-sdk:vulkan_validation" ] + data_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/vulkan_layers:VkLayer_khronos_validation" ] } else { data_deps += [ "$angle_vulkan_validation_layers_dir:vulkan_validation_layers" ] diff --git a/src/common/vulkan/vulkan_icd.cpp b/src/common/vulkan/vulkan_icd.cpp index d9577ed95..b896a1f05 100644 --- a/src/common/vulkan/vulkan_icd.cpp +++ b/src/common/vulkan/vulkan_icd.cpp @@ -47,19 +47,15 @@ namespace vk namespace { -// This function is unused on Android/Fuschia/GGP -#if !defined(ANGLE_PLATFORM_ANDROID) && !defined(ANGLE_PLATFORM_FUCHSIA) && \ - !defined(ANGLE_PLATFORM_GGP) -const std::string WrapICDEnvironment(const char *icdEnvironment) +ANGLE_MAYBE_UNUSED const std::string WrapICDEnvironment(const char *icdEnvironment) { // The libraries are bundled into the module directory std::string ret = ConcatenatePath(angle::GetModuleDirectory(), icdEnvironment); return ret; } -constexpr char kLoaderLayersPathEnv[] = "VK_LAYER_PATH"; -constexpr char kLayerEnablesEnv[] = "VK_LAYER_ENABLES"; -#endif +ANGLE_MAYBE_UNUSED constexpr char kLoaderLayersPathEnv[] = "VK_LAYER_PATH"; +ANGLE_MAYBE_UNUSED constexpr char kLayerEnablesEnv[] = "VK_LAYER_ENABLES"; constexpr char kLoaderICDFilenamesEnv[] = "VK_ICD_FILENAMES"; constexpr char kANGLEPreferredDeviceEnv[] = "ANGLE_PREFERRED_DEVICE"; @@ -115,8 +111,7 @@ ScopedVkLoaderEnvironment::ScopedVkLoaderEnvironment(bool enableValidationLayers // 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. -#if !defined(ANGLE_PLATFORM_ANDROID) && !defined(ANGLE_PLATFORM_FUCHSIA) && \ - !defined(ANGLE_PLATFORM_GGP) +#if !defined(ANGLE_PLATFORM_ANDROID) && !defined(ANGLE_PLATFORM_GGP) if (icd == vk::ICD::Mock) { if (!setICDEnvironment(WrapICDEnvironment(ANGLE_VK_MOCK_ICD_JSON).c_str())) @@ -133,6 +128,7 @@ ScopedVkLoaderEnvironment::ScopedVkLoaderEnvironment(bool enableValidationLayers } } # endif // defined(ANGLE_VK_SWIFTSHADER_ICD_JSON) + if (mEnableValidationLayers || icd != vk::ICD::Default) { const auto &cwd = angle::GetCWD(); @@ -159,11 +155,14 @@ ScopedVkLoaderEnvironment::ScopedVkLoaderEnvironment(bool enableValidationLayers // Override environment variable to use the ANGLE layers. if (mEnableValidationLayers) { +# if defined(ANGLE_VK_LAYERS_DIR) if (!angle::PrependPathToEnvironmentVar(kLoaderLayersPathEnv, ANGLE_VK_LAYERS_DIR)) { ERR() << "Error setting environment for Vulkan layers init."; mEnableValidationLayers = false; } +# endif // defined(ANGLE_VK_LAYERS_DIR) + if (!angle::PrependPathToEnvironmentVar( kLayerEnablesEnv, "VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION")) {