26 static std::optional<std::string>
result = []() -> std::optional<std::string> {
27 static char tmp_dir_buffer[
FILE_MAX];
33 std::string cache_dir = std::string(tmp_dir_buffer) +
"vk-spirv-cache" +
SEP_STR;
72 fstream sidecar_file(sidecar_path, std::ios::binary | std::ios::in | std::ios::ate);
73 std::streamsize sidecar_size_on_disk = sidecar_file.tellg();
75 if (sidecar_size_on_disk !=
sizeof(sidecar)) {
78 sidecar_file.seekg(0, std::ios::beg);
79 sidecar_file.read(
reinterpret_cast<char *
>(&sidecar),
sizeof(sidecar));
82 fstream spirv_file(spirv_path, std::ios::binary | std::ios::in | std::ios::ate);
83 std::streamsize
size = spirv_file.tellg();
87 spirv_file.seekg(0, std::ios::beg);
107 fstream spirv_file(spirv_path, std::ios::binary | std::ios::out);
114 fstream sidecar_file(sidecar_path, std::ios::binary | std::ios::out);
115 sidecar_file.write(
reinterpret_cast<const char *
>(&sidecar),
sizeof(
SPIRVSidecar));
131 const time_t ts_now = time(
nullptr);
132 const time_t delete_threshold = 60 * 60 * 24 * 30 ;
133 if (entry.
s.st_mtime + delete_threshold < ts_now) {
149 case shaderc_vertex_shader:
151 case shaderc_geometry_shader:
153 case shaderc_fragment_shader:
155 case shaderc_compute_shader:
159 BLI_assert_msg(
false,
"Do not know how to convert shaderc_shader_kind to stage name.");
162 return "unknown stage";
168 size_t start_pos = 0;
169 while ((start_pos = source.find(
"#line ", start_pos)) != std::string::npos) {
170 source[start_pos] =
'/';
171 source[start_pos + 1] =
'/';
178 shaderc_shader_kind stage,
185 shaderc::CompileOptions
options;
186 bool do_optimize =
true;
187 options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_2);
202 constexpr int64_t optimization_source_size_limit = 512 * 1024;
203 if (shader_module.
combined_sources.size() > optimization_source_size_limit) {
206 options.SetOptimizationLevel(do_optimize ? shaderc_optimization_level_performance :
207 shaderc_optimization_level_zero);
212 options.SetGenerateDebugInfo();
220 sources, stage, full_name.c_str(),
options);
221 bool compilation_succeeded = shader_module.
compilation_result.GetCompilationStatus() ==
222 shaderc_compilation_status_success;
223 if (compilation_succeeded) {
226 return compilation_succeeded;
230 shaderc_shader_kind stage,
233 shaderc::Compiler compiler;
bool BKE_appdir_folder_caches(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
@ G_DEBUG_GPU_SHADER_DEBUG_INFO
#define BLI_assert_msg(a, msg)
bool BLI_file_touch(const char *filepath) ATTR_NONNULL(1)
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
unsigned int BLI_filelist_dir_contents(const char *dirname, struct direntry **r_filelist)
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries)
File and directory operations.
Platform independent time functions.
Compatibility-like things for windows.
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void resize(const int64_t new_size)
static bool compile_module(VKShader &shader, shaderc_shader_kind stage, VKShaderModule &shader_module)
static void cache_dir_clear_old()
shaderc::SpvCompilationResult compilation_result
std::string combined_sources
void build_sources_hash()
Vector< uint32_t > spirv_binary
CCL_NAMESPACE_BEGIN struct Options options
static bool compile_ex(shaderc::Compiler &compiler, VKShader &shader, shaderc_shader_kind stage, VKShaderModule &shader_module)
static void write_spirv_to_disk(VKShaderModule &shader_module)
static std::optional< std::string > cache_dir_get()
static bool read_spirv_from_disk(VKShaderModule &shader_module)
static StringRef to_stage_name(shaderc_shader_kind stage)
static std::string patch_line_directives(std::string source)