9 #include "flutter/fml/build_config.h"
10 #include "flutter/fml/file.h"
11 #include "flutter/fml/logging.h"
12 #include "flutter/fml/paths.h"
21 static constexpr
const char* kSwiftShaderICDJSON =
"vk_swiftshader_icd.json";
22 static constexpr
const char* kVulkanICDFileNamesEnvVariableKey =
24 const auto executable_directory_path =
25 fml::paths::GetExecutableDirectoryPath();
26 FML_CHECK(executable_directory_path.first);
27 const auto executable_directory =
28 fml::OpenDirectory(executable_directory_path.second.c_str(),
false,
29 fml::FilePermission::kRead);
30 FML_CHECK(executable_directory.is_valid());
31 if (fml::FileExists(executable_directory, kSwiftShaderICDJSON)) {
32 const auto icd_path = fml::paths::JoinPaths(
33 {executable_directory_path.second, kSwiftShaderICDJSON});
36 ::SetEnvironmentVariableA(kVulkanICDFileNamesEnvVariableKey,
40 const auto success = ::setenv(kVulkanICDFileNamesEnvVariableKey,
46 <<
"Could not set the environment variable to use SwiftShader.";
49 <<
"Was asked to use SwiftShader but could not find the installable "
50 "client driver (ICD) for the locally built SwiftShader.";
55 static bool swiftshader_preference =
false;
56 static std::once_flag sOnceInitializer;
57 std::call_once(sOnceInitializer, [use_swiftshader]() {
58 if (use_swiftshader) {
60 swiftshader_preference = use_swiftshader;
63 FML_CHECK(swiftshader_preference == use_swiftshader)
64 <<
"The option to use SwiftShader in a process can only be set once and "
65 "may not be changed later.";
static void FindSwiftShaderICDAtKnownPaths()
void SetupSwiftshaderOnce(bool use_swiftshader)
Find and setup the installable client driver for a locally built SwiftShader at known paths....