diff --git a/backends/vulkan/runtime/vk_api/Runtime.cpp b/backends/vulkan/runtime/vk_api/Runtime.cpp index 9b30aaacda8..2073a7364ba 100644 --- a/backends/vulkan/runtime/vk_api/Runtime.cpp +++ b/backends/vulkan/runtime/vk_api/Runtime.cpp @@ -258,7 +258,8 @@ uint32_t select_first(const std::vector& devices) { // Global runtime initialization // -std::unique_ptr init_global_vulkan_runtime() { +std::unique_ptr init_global_vulkan_runtime( + const std::string& cache_data_path) { // Load Vulkan drivers #if defined(USE_VULKAN_VOLK) if (VK_SUCCESS != volkInitialize()) { @@ -278,7 +279,6 @@ std::unique_ptr init_global_vulkan_runtime() { #endif /* VULKAN_DEBUG */ const bool init_default_device = true; const uint32_t num_requested_queues = 1; // TODO: raise this value - const std::string cache_data_path = ""; // TODO: expose to client const RuntimeConfig default_config{ enable_validation_messages, @@ -377,13 +377,24 @@ uint32_t Runtime::create_adapter(const Selector& selector) { return adapter_i; } +std::string& set_and_get_pipeline_cache_data_path( + const std::string& file_path) { + // The global cache data path is declared as a static local variable for the + // same reasons as the global runtime below. + static std::string global_cache_data_path; + if (file_path.size() > 0) { + global_cache_data_path = file_path; + } + return global_cache_data_path; +} + Runtime* runtime() { // The global vulkan runtime is declared as a static local variable within a // non-static function to ensure it has external linkage. If it were a global // static variable there would be one copy per translation unit that includes // Runtime.h as it would have internal linkage. static const std::unique_ptr p_runtime = - init_global_vulkan_runtime(); + init_global_vulkan_runtime(set_and_get_pipeline_cache_data_path("")); VK_CHECK_COND( p_runtime, diff --git a/backends/vulkan/runtime/vk_api/Runtime.h b/backends/vulkan/runtime/vk_api/Runtime.h index 16f1400021c..c1b67c0dbdc 100644 --- a/backends/vulkan/runtime/vk_api/Runtime.h +++ b/backends/vulkan/runtime/vk_api/Runtime.h @@ -100,6 +100,8 @@ class Runtime final { uint32_t create_adapter(const Selector&); }; +std::string& set_and_get_pipeline_cache_data_path(const std::string& file_path); + // The global runtime is retrieved using this function, where it is declared as // a static local variable. Runtime* runtime();