From 8e38e14ea9c87a6c8c02bcd02cf3ce7e2862f88b Mon Sep 17 00:00:00 2001 From: BearOso Date: Mon, 20 Feb 2023 16:04:55 -0600 Subject: [PATCH] Vulkan/Slang: Load shader files asynchronously. --- vulkan/slang_preset.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/vulkan/slang_preset.cpp b/vulkan/slang_preset.cpp index 2bd45372..42f3ee6f 100644 --- a/vulkan/slang_preset.cpp +++ b/vulkan/slang_preset.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "../external/SPIRV-Cross/spirv_cross.hpp" #include "../external/SPIRV-Cross/spirv_glsl.hpp" #include "slang_shader.hpp" @@ -109,12 +110,19 @@ bool SlangPreset::load_preset_file(string filename) } } - for (auto &shader : passes) + std::vector> futures; + for (size_t i = 0; i < passes.size(); i++) { - if (!shader.load_file()) - return false; + futures.push_back(std::async(std::launch::async, [&, i]() -> bool { + return passes[i].load_file(); + })); } - + bool success = true; + for (auto &f : futures) + success &= f.get(); + if (!success) + return false; + gather_parameters(); for (auto &p : parameters)