From 6d6666819a449ffe4bcbecebcdab0b70e635ed37 Mon Sep 17 00:00:00 2001 From: nmzik Date: Tue, 29 Sep 2026 03:53:10 +0400 Subject: [PATCH] graphics: serialize pipeline cache through its renderer owner --- src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp | 7 +------ src/graphics/host_gpu/renderer/pipeline/pipelineCache.h | 3 +-- src/graphics/presentation/window/window.cpp | 1 + 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp b/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp index 42cc0f6f5..dcd1c94a3 100644 --- a/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp +++ b/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp @@ -5,6 +5,7 @@ #include "common/file.h" #include "common/logging/log.h" #include "common/profiler.h" +#include "common/threads.h" #include "graphics/guest_gpu/hardwareContext.h" #include "graphics/host_gpu/renderer/colorRenderTarget.h" #include "graphics/host_gpu/renderer/debug.h" @@ -518,7 +519,6 @@ void PipelineCache::InitializeDriverCache() { } void PipelineCache::Save() { - Common::LockGuard lock(m_mutex); if (m_driver_cache == nullptr) { return; } @@ -640,7 +640,6 @@ PipelineCache::GraphicsPrograms PipelineCache::GetGraphicsPrograms( static_cast(std::min(limits.maxViewportDimensions[1], 16384u)) * 0.5f; clip.enabled = true; } - Common::LockGuard lock(m_mutex); uint32_t push_data_cursor = mesh_active ? ShaderRecompiler::IR::PushData::MeshDrawDwordCount : 0; GraphicsPrograms result; @@ -658,7 +657,6 @@ ShaderProgram PipelineCache::GetComputeProgram(const HW::ComputeShaderInfo& regs ShaderComputeInputInfo& input_info) { input_info.host_subgroup_size = m_graphics.SupportsComputeWave64() ? 64u : 32u; const auto params = PrepareProgram(regs, sh, input_info); - Common::LockGuard lock(m_mutex); uint32_t push_data_cursor = 0; return m_program_cache->Get(params, input_info, push_data_cursor); } @@ -683,7 +681,6 @@ PipelineCache::Pipeline& PipelineCache::GetGraphicsPipeline( EXIT_IF(ps_active && !pixel_program); const auto color_count = static_cast(colors.size()); - Common::LockGuard lock(m_mutex); auto& ctx = command.GetRegisters(); const HW::ModeControl& mc = ctx.GetModeControl(); @@ -839,8 +836,6 @@ PipelineCache::GetComputePipeline(const ShaderComputeInputInfo& input_info, EXIT_IF(!compute_program); - Common::LockGuard lock(m_mutex); - if (auto iter = m_compute_pipelines.find(compute_program.id); iter != m_compute_pipelines.end()) { return *iter->second; diff --git a/src/graphics/host_gpu/renderer/pipeline/pipelineCache.h b/src/graphics/host_gpu/renderer/pipeline/pipelineCache.h index 05ace5277..4be29854d 100644 --- a/src/graphics/host_gpu/renderer/pipeline/pipelineCache.h +++ b/src/graphics/host_gpu/renderer/pipeline/pipelineCache.h @@ -4,7 +4,6 @@ #include "common/abi.h" #include "common/assert.h" #include "common/common.h" -#include "common/threads.h" #include "graphics/host_gpu/renderer/renderTarget.h" #include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/shader.h" @@ -103,6 +102,7 @@ struct ShaderProgram { explicit operator bool() const { return id != 0 && module != nullptr; } }; +// The owning renderer serializes access, including saves while the GPU is running. class PipelineCache { public: explicit PipelineCache(GraphicContext& graphics); @@ -179,7 +179,6 @@ private: std::unordered_map, GraphicsPipelineKeyHash> m_graphics_pipelines; std::unordered_map> m_compute_pipelines; - Common::Mutex m_mutex; void InitializeDriverCache(); }; diff --git a/src/graphics/presentation/window/window.cpp b/src/graphics/presentation/window/window.cpp index e223eca45..5494ff0f4 100644 --- a/src/graphics/presentation/window/window.cpp +++ b/src/graphics/presentation/window/window.cpp @@ -817,6 +817,7 @@ void WindowRun() { EXIT_IF(g_window == nullptr); g_window->Run(); + Common::LockGuard lock(g_window->render_context->GetMutex()); g_window->render_context->GetPipelineCache().Save(); }