From de3c2783f400157b67ee2a07bc25e2ced042dc6c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 13 Dec 2022 22:00:51 -0800 Subject: [PATCH] Vulkan: Reload shaders if use flags change. --- GPU/GPUState.h | 3 ++- GPU/Vulkan/GPU_Vulkan.cpp | 11 +++++++++++ GPU/Vulkan/ShaderManagerVulkan.cpp | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/GPU/GPUState.h b/GPU/GPUState.h index e95c13558b..18b3cdcf4d 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -581,7 +581,7 @@ struct GPUStateCache { void SetUseFlags(u32 newFlags) { if (newFlags != useFlags_) { useFlags_ = newFlags; - // Recompile shaders and stuff? + useFlagsChanged = true; } } @@ -612,6 +612,7 @@ public: bool bgraTexture; bool needShaderTexClamp; bool arrayTexture; + bool useFlagsChanged; float morphWeights[8]; u32 deferredVertTypeDirty; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index c5152198c4..6f282f2dfe 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -135,6 +135,9 @@ void GPU_Vulkan::LoadCache(const Path &filename) { } if (result) { // Reload use flags in case LoadCacheFlags() changed them. + if (drawEngineCommon_->EverUsedExactEqualDepth()) { + sawExactEqualDepth_ = true; + } gstate_c.SetUseFlags(CheckGPUFeatures()); result = shaderManagerVulkan_->LoadCache(f); if (!result) { @@ -304,6 +307,14 @@ void GPU_Vulkan::BeginHostFrame() { shaderManagerVulkan_->DirtyShader(); gstate_c.Dirty(DIRTY_ALL); + if (gstate_c.useFlagsChanged) { + // TODO: It'd be better to recompile them in the background, probably? + // This most likely means that saw equal depth changed. + WARN_LOG(G3D, "Shader use flags changed, clearing all shaders"); + shaderManagerVulkan_->ClearShaders(); + gstate_c.useFlagsChanged = false; + } + if (dumpNextFrame_) { NOTICE_LOG(G3D, "DUMPING THIS FRAME"); dumpThisFrame_ = true; diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index 4eeafc3321..549b760503 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -565,6 +565,9 @@ bool ShaderManagerVulkan::LoadCache(FILE *f) { // This can simply be a result of sawExactEqualDepth_ having been flipped to true in the previous run. // Let's just keep going. WARN_LOG(G3D, "Shader cache useFlags mismatch, %08x, expected %08x", header.useFlags, gstate_c.GetUseFlags()); + } else { + // We're compiling shaders now, so they haven't changed anymore. + gstate_c.useFlagsChanged = false; } int failCount = 0;