[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 <jmadill@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Sergey Ulanov 2021-11-19 00:57:29 +00:00 коммит произвёл Angle LUCI CQ
Родитель f2bf9954b3
Коммит 6e2e36cc8b
4 изменённых файлов: 21 добавлений и 17 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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" ]

Просмотреть файл

@ -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"))
{