5#include "flutter/impeller/playground/backend/vulkan/swiftshader_utilities.h"
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 =
26 FML_CHECK(executable_directory_path.first);
27 const auto executable_directory =
30 FML_CHECK(executable_directory.is_valid());
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.";
#define FML_CHECK(condition)
std::string JoinPaths(std::initializer_list< std::string > components)
std::pair< bool, std::string > GetExecutableDirectoryPath()
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
bool FileExists(const fml::UniqueFD &base_directory, const char *path)
static void FindSwiftShaderICDAtKnownPaths()
void SetupSwiftshaderOnce(bool use_swiftshader)
Find and setup the installable client driver for a locally built SwiftShader at known paths....