From 3aaf2cc63956dc83b6e338928113bc77bfb86416 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 25 Feb 2025 02:15:15 +0100 Subject: [PATCH] Add SPIRV cache to VkShaderCache --- .../rendering/vulkan/shaders/vk_shader.cpp | 101 +++++-------- .../rendering/vulkan/shaders/vk_shader.h | 7 +- .../vulkan/shaders/vk_shadercache.cpp | 136 +++++++++++++++--- .../rendering/vulkan/shaders/vk_shadercache.h | 85 +++++++++-- .../rendering/vulkan/vk_renderdevice.cpp | 3 + src/common/rendering/vulkan/vk_renderdevice.h | 3 + 6 files changed, 235 insertions(+), 100 deletions(-) diff --git a/src/common/rendering/vulkan/shaders/vk_shader.cpp b/src/common/rendering/vulkan/shaders/vk_shader.cpp index e1678629c..1a6d0b6f4 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/common/rendering/vulkan/shaders/vk_shader.cpp @@ -34,51 +34,49 @@ VkShaderManager::VkShaderManager(VulkanRenderDevice* fb) : fb(fb) { - ShaderCache = std::make_unique(fb); - ZMinMax.vert = ShaderBuilder() - .Code(GLSLCompiler() + .Code(CachedGLSLCompiler() .Type(ShaderType::Vertex) .AddSource("VersionBlock", GetVersionBlock().GetChars()) .AddSource("shaders/scene/vert_zminmax.glsl", LoadPrivateShaderLump("shaders/scene/vert_zminmax.glsl").GetChars()) - .Compile(fb->GetDevice())) + .Compile(fb)) .DebugName("ZMinMax.vert") .Create("ZMinMax.vert", fb->GetDevice()); ZMinMax.frag[0] = ShaderBuilder() - .Code(GLSLCompiler() + .Code(CachedGLSLCompiler() .Type(ShaderType::Fragment) .AddSource("VersionBlock", GetVersionBlock().GetChars()) .AddSource("shaders/scene/frag_zminmax0.glsl", LoadPrivateShaderLump("shaders/scene/frag_zminmax0.glsl").GetChars()) - .Compile(fb->GetDevice())) + .Compile(fb)) .DebugName("ZMinMax0.frag") .Create("ZMinMax0.frag", fb->GetDevice()); ZMinMax.frag[1] = ShaderBuilder() - .Code(GLSLCompiler() + .Code(CachedGLSLCompiler() .Type(ShaderType::Fragment) .AddSource("VersionBlock", GetVersionBlock().GetChars()) .AddSource("DefinesBlock", "#define MULTISAMPLE\n") .AddSource("shaders/scene/frag_zminmax0.glsl", LoadPrivateShaderLump("shaders/scene/frag_zminmax0.glsl").GetChars()) - .Compile(fb->GetDevice())) + .Compile(fb)) .DebugName("ZMinMax0.frag") .Create("ZMinMax0.frag", fb->GetDevice()); ZMinMax.frag[2] = ShaderBuilder() - .Code(GLSLCompiler() + .Code(CachedGLSLCompiler() .Type(ShaderType::Fragment) .AddSource("VersionBlock", GetVersionBlock().GetChars()) .AddSource("shaders/scene/frag_zminmax1.glsl", LoadPrivateShaderLump("shaders/scene/frag_zminmax1.glsl").GetChars()) - .Compile(fb->GetDevice())) + .Compile(fb)) .DebugName("ZMinMax1.frag") .Create("ZMinMax1.frag", fb->GetDevice()); LightTiles = ShaderBuilder() - .Code(GLSLCompiler() + .Code(CachedGLSLCompiler() .Type(ShaderType::Compute) .AddSource("VersionBlock", GetVersionBlock().GetChars()) .AddSource("shaders/scene/comp_lighttiles.glsl", LoadPrivateShaderLump("shaders/scene/comp_lighttiles.glsl").GetChars()) - .Compile(fb->GetDevice())) + .Compile(fb)) .DebugName("LightTiles.comp") .Create("LightTiles.comp", fb->GetDevice()); } @@ -383,7 +381,7 @@ void VkShaderManager::BuildDefinesBlock(FString &definesBlock, const char *defin { //ugh EffectState also controls layout, because specular/pbr/etc defines switch texture indices around for normal/specular/etc - definesBlock << LoadPrivateShaderLump("shaders/shaderkey.glsl").GetChars() << "\n"; + definesBlock << SubstituteDefines(LoadPrivateShaderLump("shaders/shaderkey.glsl")).GetChars() << "\n"; definesBlock << "#define UBERSHADERS\n"; @@ -570,28 +568,27 @@ std::unique_ptr VkShaderManager::LoadVertShader(FString shadername BuildLayoutBlock(layoutBlock, false, key, shader); FString codeBlock; - codeBlock << LoadPrivateShaderLump(vert_lump).GetChars() << "\n"; + codeBlock << SubstituteDefines(LoadPrivateShaderLump(vert_lump)).GetChars() << "\n"; if(vert_lump_custom) { codeBlock << "\n#line 1\n"; - codeBlock << LoadPublicShaderLump(vert_lump_custom).GetChars() << "\n"; + codeBlock << SubstituteDefines(LoadPublicShaderLump(vert_lump_custom)).GetChars() << "\n"; } else { - codeBlock << LoadPrivateShaderLump("shaders/scene/vert_nocustom.glsl").GetChars() << "\n"; + codeBlock << SubstituteDefines(LoadPrivateShaderLump("shaders/scene/vert_nocustom.glsl")).GetChars() << "\n"; } return ShaderBuilder() - .Code(GLSLCompiler() + .Code(CachedGLSLCompiler() .Type(ShaderType::Vertex) .AddSource("VersionBlock", GetVersionBlock().GetChars()) .AddSource("DefinesBlock", definesBlock.GetChars()) .AddSource("LayoutBlock", layoutBlock.GetChars()) - .AddSource("shaders/scene/layout_shared.glsl", LoadPrivateShaderLump("shaders/scene/layout_shared.glsl").GetChars()) + .AddSource("shaders/scene/layout_shared.glsl", SubstituteDefines(LoadPrivateShaderLump("shaders/scene/layout_shared.glsl")).GetChars()) .AddSource(vert_lump_custom ? vert_lump_custom : vert_lump, codeBlock.GetChars()) - .OnIncludeLocal([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, false); }) - .OnIncludeSystem([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, true); }) - .Compile(fb->GetDevice())) + .IncludeFilter([](FString s) { return SubstituteDefines(std::move(s), false); }) + .Compile(fb)) .DebugName(shadername.GetChars()) .Create(shadername.GetChars(), fb->GetDevice()); } @@ -605,7 +602,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername BuildLayoutBlock(layoutBlock, true, key, shader); FString codeBlock; - codeBlock << LoadPrivateShaderLump(frag_lump).GetChars() << "\n"; + codeBlock << SubstituteDefines(LoadPrivateShaderLump(frag_lump)).GetChars() << "\n"; FString materialname = "MaterialBlock"; FString materialBlock; @@ -617,7 +614,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername if (material_lump) { materialname = material_lump; - materialBlock = LoadPublicShaderLump(material_lump); + materialBlock = SubstituteDefines(LoadPublicShaderLump(material_lump)); // Attempt to fix old custom shaders: @@ -636,15 +633,15 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername FString code; if (materialBlock.IndexOf("ProcessTexel") >= 0) { - code = LoadPrivateShaderLump("shaders/scene/material_legacy_ptexel.glsl"); + code = SubstituteDefines(LoadPrivateShaderLump("shaders/scene/material_legacy_ptexel.glsl")); } else if (materialBlock.IndexOf("Process") >= 0) { - code = LoadPrivateShaderLump("shaders/scene/material_legacy_process.glsl"); + code = SubstituteDefines(LoadPrivateShaderLump("shaders/scene/material_legacy_process.glsl")); } else { - code = LoadPrivateShaderLump("shaders/scene/material_default.glsl"); + code = SubstituteDefines(LoadPrivateShaderLump("shaders/scene/material_default.glsl")); } code << "\n#line 1\n"; @@ -656,7 +653,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername definesBlock << "#define LEGACY_USER_SHADER\n"; - FString code = LoadPrivateShaderLump("shaders/scene/material_legacy_pmaterial.glsl"); + FString code = SubstituteDefines(LoadPrivateShaderLump("shaders/scene/material_legacy_pmaterial.glsl")); code << "\n#line 1\n"; materialBlock = code + materialBlock; @@ -669,34 +666,33 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername if(light_lump_shared) { - lightBlock << LoadPrivateShaderLump(light_lump_shared).GetChars(); + lightBlock << SubstituteDefines(LoadPrivateShaderLump(light_lump_shared)).GetChars(); } - lightBlock << LoadPrivateShaderLump(light_lump).GetChars(); + lightBlock << SubstituteDefines(LoadPrivateShaderLump(light_lump)).GetChars(); } if (mateffect_lump && mateffectBlock.IsEmpty()) { mateffectname = mateffect_lump; - mateffectBlock << LoadPrivateShaderLump(mateffect_lump).GetChars(); + mateffectBlock << SubstituteDefines(LoadPrivateShaderLump(mateffect_lump)).GetChars(); } return ShaderBuilder() - .Code(GLSLCompiler() + .Code(CachedGLSLCompiler() .Type(ShaderType::Fragment) .AddSource("VersionBlock", GetVersionBlock().GetChars()) .AddSource("DefinesBlock", definesBlock.GetChars()) .AddSource("LayoutBlock", layoutBlock.GetChars()) - .AddSource("shaders/scene/layout_shared.glsl", LoadPrivateShaderLump("shaders/scene/layout_shared.glsl").GetChars()) - .AddSource("shaders/scene/includes.glsl", LoadPrivateShaderLump("shaders/scene/includes.glsl").GetChars()) + .AddSource("shaders/scene/layout_shared.glsl", SubstituteDefines(LoadPrivateShaderLump("shaders/scene/layout_shared.glsl")).GetChars()) + .AddSource("shaders/scene/includes.glsl", SubstituteDefines(LoadPrivateShaderLump("shaders/scene/includes.glsl")).GetChars()) .AddSource(mateffectname.GetChars(), mateffectBlock.GetChars()) .AddSource(materialname.GetChars(), materialBlock.GetChars()) .AddSource(lightname.GetChars(), lightBlock.GetChars()) .AddSource(frag_lump, codeBlock.GetChars()) - .OnIncludeLocal([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, false); }) - .OnIncludeSystem([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, true); }) - .Compile(fb->GetDevice())) + .IncludeFilter([](FString s) { return SubstituteDefines(std::move(s), false); }) + .Compile(fb)) .DebugName(shadername.GetChars()) .Create(shadername.GetChars(), fb->GetDevice()); } @@ -725,43 +721,14 @@ FString VkShaderManager::GetVersionBlock() return versionBlock; } -ShaderIncludeResult VkShaderManager::OnInclude(FString headerName, FString includerName, size_t depth, bool system) -{ - if (depth > 8) - I_Error("Too much include recursion!"); - - FString includeguardname; - includeguardname << "_HEADERGUARD_" << headerName.GetChars(); - includeguardname.ReplaceChars("/\\.", '_'); - - FString code; - code << "#ifndef " << includeguardname.GetChars() << "\n"; - code << "#define " << includeguardname.GetChars() << "\n"; - code << "#line 1\n"; - - if (system) - code << LoadPrivateShaderLump(headerName.GetChars()).GetChars() << "\n"; - else - code << LoadPublicShaderLump(headerName.GetChars()).GetChars() << "\n"; - - code << "#endif\n"; - - return ShaderIncludeResult(headerName.GetChars(), code.GetChars()); -} - FString VkShaderManager::LoadPublicShaderLump(const char* lumpname) { - int lump = fileSystem.CheckNumForFullName(lumpname, 0); - if (lump == -1) lump = fileSystem.CheckNumForFullName(lumpname); - if (lump == -1) I_Error("Unable to load '%s'", lumpname); - return GetStringFromLump(lump); + return fb->GetShaderCache()->GetPublicFile(lumpname).Code; } FString VkShaderManager::LoadPrivateShaderLump(const char* lumpname) { - int lump = fileSystem.CheckNumForFullName(lumpname, 0); - if (lump == -1) I_Error("Unable to load '%s'", lumpname); - return GetStringFromLump(lump); + return fb->GetShaderCache()->GetPrivateFile(lumpname).Code; } FString VkShaderManager::SubstituteDefines(FString str, bool isUberShader) diff --git a/src/common/rendering/vulkan/shaders/vk_shader.h b/src/common/rendering/vulkan/shaders/vk_shader.h index d9fe61aea..43d3af2c5 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.h +++ b/src/common/rendering/vulkan/shaders/vk_shader.h @@ -15,7 +15,6 @@ class ShaderIncludeResult; class VulkanRenderDevice; class VulkanDevice; class VulkanShader; -class VkShaderCache; class VkPPShader; class PPShader; @@ -162,21 +161,17 @@ private: std::unique_ptr LoadVertShader(FString shadername, const char *vert_lump, const char *vert_lump_custom, const char *defines, const VkShaderKey& key, const UserShaderDesc *shader); std::unique_ptr LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char* mateffect_lump, const char *light_lump_shared, const char *lightmodel_lump, const char *defines, const VkShaderKey& key, const UserShaderDesc *shader); - ShaderIncludeResult OnInclude(FString headerName, FString includerName, size_t depth, bool system); - FString GetVersionBlock(); FString LoadPublicShaderLump(const char *lumpname); FString LoadPrivateShaderLump(const char *lumpname); - static FString SubstituteDefines(FString code, bool isUberShader); + static FString SubstituteDefines(FString code, bool isUberShader = false); void BuildLayoutBlock(FString &definesBlock, bool isFrag, const VkShaderKey& key, const UserShaderDesc *shader, bool isUberShader = false); void BuildDefinesBlock(FString &definesBlock, const char *defines, bool isFrag, const VkShaderKey& key, const UserShaderDesc *shader, bool isUberShader = false); VulkanRenderDevice* fb = nullptr; - std::unique_ptr ShaderCache; - std::map programs; std::list PPShaders; diff --git a/src/common/rendering/vulkan/shaders/vk_shadercache.cpp b/src/common/rendering/vulkan/shaders/vk_shadercache.cpp index eef1c6f0e..047b464e9 100644 --- a/src/common/rendering/vulkan/shaders/vk_shadercache.cpp +++ b/src/common/rendering/vulkan/shaders/vk_shadercache.cpp @@ -1,5 +1,6 @@ #include "vk_shadercache.h" +#include "vulkan/vk_renderdevice.h" #include "sha1.h" #include "filesystem.h" #include "engineerrors.h" @@ -10,34 +11,133 @@ VkShaderCache::VkShaderCache(VulkanRenderDevice* fb) : fb(fb) { } -const VkShaderSourceFile& VkShaderCache::GetPublicFile(const FString& lumpname) +std::vector VkShaderCache::Compile(ShaderType type, const TArrayView& sources, const std::function& includeFilter) +{ + // Is this something we already compiled before? + + FString checksum = CalcSha1(type, sources); + auto it = CodeCache.find(checksum); + if (it != CodeCache.end()) + { + // OK we found a match. Did any of the include files change? + + try + { + const VkCachedCompile& cacheinfo = it->second; + + bool foundChanges = false; + for (const VkCachedInclude& includeinfo : cacheinfo.Includes) + { + const VkCachedShaderLump& lumpinfo = includeinfo.PrivateLump ? GetPrivateFile(includeinfo.LumpName) : GetPublicFile(includeinfo.LumpName); + if (lumpinfo.Checksum != includeinfo.Checksum) + { + foundChanges = true; + break; + } + } + + if (!foundChanges) + return cacheinfo.Code; + } + catch (...) + { + // If GetPrivateFile or GetPublicFile is unable to find the file anymore it must be out of date. + } + } + + // No match or out of date + // Compile it and store the dependencies: + + auto noFilter = [](FString s) { return s; }; + + VkCachedCompile cachedCompile; + GLSLCompiler compiler; + compiler.Type(type); + compiler.OnIncludeLocal([&](std::string headerName, std::string includerName, size_t depth) { return OnInclude(cachedCompile, headerName.c_str(), includerName.c_str(), depth, false, includeFilter ? includeFilter : noFilter); }); + compiler.OnIncludeSystem([&](std::string headerName, std::string includerName, size_t depth) { return OnInclude(cachedCompile, headerName.c_str(), includerName.c_str(), depth, true, includeFilter ? includeFilter : noFilter); }); + for (const VkShaderSource& source : sources) + compiler.AddSource(source.Name, source.Code); + cachedCompile.Code = compiler.Compile(fb->GetDevice()); + + auto& c = CodeCache[checksum]; + c = std::move(cachedCompile); + return c.Code; +} + +ShaderIncludeResult VkShaderCache::OnInclude(VkCachedCompile& cachedCompile, FString headerName, FString includerName, size_t depth, bool system, const std::function& includeFilter) +{ + if (depth > 8) + I_Error("Too much include recursion!"); + + const VkCachedShaderLump& file = system ? GetPrivateFile(headerName) : GetPublicFile(headerName); + + VkCachedInclude cacheinfo; + cacheinfo.LumpName = headerName; + cacheinfo.PrivateLump = system; + cacheinfo.Checksum = file.Checksum; + cachedCompile.Includes.push_back(std::move(cacheinfo)); + + FString includeguardname; + includeguardname << "_HEADERGUARD_" << headerName.GetChars(); + includeguardname.ReplaceChars("/\\.", '_'); + + FString code; + code << "#ifndef " << includeguardname.GetChars() << "\n"; + code << "#define " << includeguardname.GetChars() << "\n"; + code << "#line 1\n"; + code << includeFilter(file.Code.GetChars()) << "\n"; + code << "#endif\n"; + + return ShaderIncludeResult(headerName.GetChars(), code.GetChars()); +} + +FString VkShaderCache::CalcSha1(ShaderType type, const TArrayView& sources) +{ + size_t totalSize = 0; + SHA1 sha1; + for (const VkShaderSource& source : sources) + { + totalSize = source.Code.size(); + sha1.update(source.Code); + } + return std::to_string((int)type) + "-" + sha1.final() + "-" + std::to_string(totalSize); +} + +FString VkShaderCache::CalcSha1(const FString& str) +{ + SHA1 sha1; + sha1.update(str.GetChars()); + return sha1.final(); +} + +const VkCachedShaderLump& VkShaderCache::GetPublicFile(const FString& lumpname) { auto it = PublicFiles.find(lumpname); if (it != PublicFiles.end()) return it->second; - FString code = LoadPublicShaderLump(lumpname.GetChars()); - FString sha1 = CalcSha1(code); + VkCachedShaderLump cacheinfo; + cacheinfo.Code = LoadPublicShaderLump(lumpname.GetChars()); + cacheinfo.Checksum = CalcSha1(cacheinfo.Code); - VkShaderSourceFile& file = PublicFiles[lumpname]; - file.Sourcecode = std::move(code); - file.Sha1 = std::move(sha1); - return file; + auto& result = PublicFiles[lumpname]; + result = std::move(cacheinfo); + return result; } -const VkShaderSourceFile& VkShaderCache::GetPrivateFile(const FString& lumpname) +const VkCachedShaderLump& VkShaderCache::GetPrivateFile(const FString& lumpname) { auto it = PrivateFiles.find(lumpname); if (it != PrivateFiles.end()) return it->second; - FString code = LoadPrivateShaderLump(lumpname.GetChars()); - FString sha1 = CalcSha1(code); + VkCachedShaderLump cacheinfo; + cacheinfo.Code = LoadPrivateShaderLump(lumpname.GetChars()); + cacheinfo.Checksum = CalcSha1(cacheinfo.Code); - VkShaderSourceFile& file = PrivateFiles[lumpname]; - file.Sourcecode = std::move(code); - file.Sha1 = std::move(sha1); - return file; + auto& result = PrivateFiles[lumpname]; + result = std::move(cacheinfo); + return result; } FString VkShaderCache::LoadPublicShaderLump(const char* lumpname) @@ -55,9 +155,9 @@ FString VkShaderCache::LoadPrivateShaderLump(const char* lumpname) return GetStringFromLump(lump); } -FString VkShaderCache::CalcSha1(const FString& str) +///////////////////////////////////////////////////////////////////////////// + +std::vector CachedGLSLCompiler::Compile(VulkanRenderDevice* fb) { - SHA1 sha1; - sha1.update(str.GetChars()); - return sha1.final(); + return fb->GetShaderCache()->Compile(shaderType, TArrayView(sources.Data(), sources.Size()), includeFilter); } diff --git a/src/common/rendering/vulkan/shaders/vk_shadercache.h b/src/common/rendering/vulkan/shaders/vk_shadercache.h index 50f7acfaf..2be785424 100644 --- a/src/common/rendering/vulkan/shaders/vk_shadercache.h +++ b/src/common/rendering/vulkan/shaders/vk_shadercache.h @@ -1,16 +1,44 @@ #pragma once #include "common/utility/zstring.h" +#include "common/utility/templates.h" #include +#include #include +#include +#include class VulkanRenderDevice; +enum class ShaderType; +class ShaderIncludeResult; -class VkShaderSourceFile +class VkShaderSource { public: - FString Sha1; - FString Sourcecode; + std::string Name; + std::string Code; +}; + +class VkCachedShaderLump +{ +public: + FString Checksum; + FString Code; +}; + +class VkCachedInclude +{ +public: + FString LumpName; + bool PrivateLump = false; + FString Checksum; +}; + +class VkCachedCompile +{ +public: + std::vector Code; + std::vector Includes; }; class VkShaderCache @@ -18,16 +46,55 @@ class VkShaderCache public: VkShaderCache(VulkanRenderDevice* fb); + std::vector Compile(ShaderType type, const TArrayView& sources, const std::function& includeFilter = {}); + + const VkCachedShaderLump& GetPublicFile(const FString& lumpname); + const VkCachedShaderLump& GetPrivateFile(const FString& lumpname); + private: - const VkShaderSourceFile& GetPublicFile(const FString& lumpname); - const VkShaderSourceFile& GetPrivateFile(const FString& lumpname); + FString CalcSha1(ShaderType type, const TArrayView& sources); + FString CalcSha1(const FString& str); + + ShaderIncludeResult OnInclude(VkCachedCompile& cachedCompile, FString headerName, FString includerName, size_t depth, bool system, const std::function& includeFilter); static FString LoadPublicShaderLump(const char* lumpname); static FString LoadPrivateShaderLump(const char* lumpname); - static FString CalcSha1(const FString& str); - VulkanRenderDevice* fb; + VulkanRenderDevice* fb = nullptr; - std::map PublicFiles; - std::map PrivateFiles; + std::map PublicFiles; + std::map PrivateFiles; + std::map CodeCache; +}; + +class CachedGLSLCompiler +{ +public: + CachedGLSLCompiler& Type(ShaderType type) + { + shaderType = type; + return *this; + } + + CachedGLSLCompiler& AddSource(std::string name, std::string code) + { + VkShaderSource source; + source.Name = std::move(name); + source.Code = std::move(code); + sources.Push(std::move(source)); + return *this; + } + + CachedGLSLCompiler& IncludeFilter(std::function filter) + { + includeFilter = std::move(filter); + return *this; + } + + std::vector Compile(VulkanRenderDevice* fb); + +private: + ShaderType shaderType = {}; + TArray sources; + std::function includeFilter; }; diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index 630ed8748..d1296486c 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -49,6 +49,7 @@ #include "vulkan/pipelines/vk_renderpass.h" #include "vulkan/descriptorsets/vk_descriptorset.h" #include "vulkan/shaders/vk_shader.h" +#include "vulkan/shaders/vk_shadercache.h" #include "vulkan/samplers/vk_samplers.h" #include "vulkan/textures/vk_renderbuffers.h" #include "vulkan/textures/vk_hwtexture.h" @@ -185,6 +186,8 @@ VulkanRenderDevice::VulkanRenderDevice(void *hMonitor, bool fullscreen, std::sha } mUseRayQuery = vk_rayquery && mDevice->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME) && mDevice->PhysicalDevice.Features.RayQuery.rayQuery; + + mShaderCache = std::make_unique(this); } VulkanRenderDevice::~VulkanRenderDevice() diff --git a/src/common/rendering/vulkan/vk_renderdevice.h b/src/common/rendering/vulkan/vk_renderdevice.h index 4c21bb222..99f5846a5 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.h +++ b/src/common/rendering/vulkan/vk_renderdevice.h @@ -25,6 +25,7 @@ class VkRenderBuffers; class VkPostprocess; class VkPipelineKey; class VkRenderPassSetup; +class VkShaderCache; class VulkanRenderDevice : public SystemBaseFrameBuffer { @@ -33,6 +34,7 @@ public: ~VulkanRenderDevice(); VulkanDevice* GetDevice() { return mDevice.get(); } + VkShaderCache* GetShaderCache() { return mShaderCache.get(); } VkCommandBufferManager* GetCommands() { return mCommands.get(); } VkShaderManager *GetShaderManager() { return mShaderManager.get(); } VkSamplerManager *GetSamplerManager() { return mSamplerManager.get(); } @@ -112,6 +114,7 @@ private: bool HasSurface = false; std::shared_ptr mDevice; + std::unique_ptr mShaderCache; std::unique_ptr mCommands; std::unique_ptr mBufferManager; std::unique_ptr mSamplerManager;