23void FindSwiftShaderICDAtKnownPaths() {
24 static constexpr const char* kSwiftShaderICDJSON =
"vk_swiftshader_icd.json";
25 static constexpr const char* kVulkanICDFileNamesEnvVariableKey =
27 const auto executable_directory_path =
29 FML_CHECK(executable_directory_path.first);
30 auto icd_directory = executable_directory_path.second;
31 if (icd_directory.ends_with(
"exe.unstripped")) {
42 ::SetEnvironmentVariableA(kVulkanICDFileNamesEnvVariableKey,
46 const auto success = ::setenv(kVulkanICDFileNamesEnvVariableKey,
52 <<
"Could not set the environment variable to use SwiftShader.";
55 <<
"Was asked to use SwiftShader but could not find the installable "
56 "client driver (ICD) for the locally built SwiftShader.";
63 static bool swiftshader_preference =
false;
64 static std::once_flag sOnceInitializer;
65 std::call_once(sOnceInitializer, [use_swiftshader]() {
66 if (use_swiftshader) {
67 FindSwiftShaderICDAtKnownPaths();
68 swiftshader_preference = use_swiftshader;
71 FML_CHECK(swiftshader_preference == use_swiftshader)
72 <<
"The option to use SwiftShader in a process can only be set once and "
73 "may not be changed later.";
#define FML_CHECK(condition)
void SetupSwiftshaderOnce(bool use_swiftshader)
Find and setup the installable client driver for a locally built SwiftShader at known paths....
std::string JoinPaths(std::initializer_list< std::string > components)
std::pair< bool, std::string > GetExecutableDirectoryPath()
std::string GetDirectoryName(const std::string &path)
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
bool FileExists(const fml::UniqueFD &base_directory, const char *path)