From 813fe64c0cedbcd0669d2be65dd3f79c937afb40 Mon Sep 17 00:00:00 2001 From: Collecting Date: Thu, 12 Feb 2026 05:38:28 +0100 Subject: [PATCH] revert df6ee98a51b785b247dc95b280138f1e474f19d6 revert Merge pull request 'vk_pipeline_cache: Fix unbounded memory growth during shader compilation' (#134) from fix-unbounded-memory into main Reviewed-on: https://git.citron-emu.org/Citron/Emulator/pulls/134 Needs proper testing, will crash games instead of properly clean --- .../renderer_vulkan/vk_pipeline_cache.cpp | 29 +++++-------------- .../renderer_vulkan/vk_pipeline_cache.h | 3 +- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 772e7634c..520375840 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -411,12 +411,9 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_, dynamic_features = DynamicFeatures{ .has_extended_dynamic_state = allow_eds1 && device.IsExtExtendedDynamicStateSupported(), .has_extended_dynamic_state_2 = allow_eds2 && device.IsExtExtendedDynamicState2Supported(), - .has_extended_dynamic_state_2_extra = - allow_eds2 && device.IsExtExtendedDynamicState2ExtrasSupported(), - .has_extended_dynamic_state_3_blend = - allow_eds3 && device.IsExtExtendedDynamicState3BlendingSupported(), - .has_extended_dynamic_state_3_enables = - allow_eds3 && device.IsExtExtendedDynamicState3EnablesSupported(), + .has_extended_dynamic_state_2_extra = allow_eds2 && device.IsExtExtendedDynamicState2ExtrasSupported(), + .has_extended_dynamic_state_3_blend = allow_eds3 && device.IsExtExtendedDynamicState3BlendingSupported(), + .has_extended_dynamic_state_3_enables = allow_eds3 && device.IsExtExtendedDynamicState3EnablesSupported(), .has_dynamic_vertex_input = allow_eds3 && device.IsExtVertexInputDynamicStateSupported(), }; } @@ -430,19 +427,15 @@ PipelineCache::~PipelineCache() { void PipelineCache::EvictOldPipelines() { constexpr u64 FRAMES_TO_KEEP = 2000; - constexpr u64 AGGRESSIVE_FRAMES_TO_KEEP = 60; const u64 current_frame = scheduler.CurrentTick(); - const bool aggressive = (graphics_cache.size() + compute_cache.size()) > MAX_PIPELINES_IN_RAM; - if (!aggressive && current_frame - last_memory_pressure_frame < MEMORY_PRESSURE_COOLDOWN) { + if (current_frame - last_memory_pressure_frame < MEMORY_PRESSURE_COOLDOWN) { return; } last_memory_pressure_frame = current_frame; - const u64 frames_to_keep = aggressive ? AGGRESSIVE_FRAMES_TO_KEEP : FRAMES_TO_KEEP; - const u64 evict_before_frame = - current_frame > frames_to_keep ? current_frame - frames_to_keep : 0; + const u64 evict_before_frame = current_frame > FRAMES_TO_KEEP ? current_frame - FRAMES_TO_KEEP : 0; size_t evicted_graphics = 0; size_t evicted_compute = 0; @@ -689,9 +682,6 @@ std::unique_ptr PipelineCache::CreateGraphicsPipeline( ShaderPools& pools, const GraphicsPipelineCacheKey& key, std::span envs, PipelineStatistics* statistics, bool build_in_parallel) try { - if (graphics_cache.size() + compute_cache.size() >= MAX_PIPELINES_IN_RAM) { - EvictOldPipelines(); - } auto hash = key.Hash(); LOG_INFO(Render_Vulkan, "0x{:016x}", hash); size_t env_index{0}; @@ -776,8 +766,7 @@ std::unique_ptr PipelineCache::CreateGraphicsPipeline( } catch (const vk::Exception& exception) { if (exception.GetResult() == VK_ERROR_OUT_OF_DEVICE_MEMORY) { - LOG_ERROR(Render_Vulkan, - "Out of device memory during graphics pipeline creation, attempting recovery"); + LOG_ERROR(Render_Vulkan, "Out of device memory during graphics pipeline creation, attempting recovery"); EvictOldPipelines(); return nullptr; } @@ -845,9 +834,6 @@ std::unique_ptr PipelineCache::CreateComputePipeline( std::unique_ptr PipelineCache::CreateComputePipeline( ShaderPools& pools, const ComputePipelineCacheKey& key, Shader::Environment& env, PipelineStatistics* statistics, bool build_in_parallel) try { - if (graphics_cache.size() + compute_cache.size() >= MAX_PIPELINES_IN_RAM) { - EvictOldPipelines(); - } auto hash = key.Hash(); if (device.HasBrokenCompute()) { LOG_ERROR(Render_Vulkan, "Skipping 0x{:016x}", hash); @@ -880,8 +866,7 @@ std::unique_ptr PipelineCache::CreateComputePipeline( } catch (const vk::Exception& exception) { if (exception.GetResult() == VK_ERROR_OUT_OF_DEVICE_MEMORY) { - LOG_ERROR(Render_Vulkan, - "Out of device memory during compute pipeline creation, attempting recovery"); + LOG_ERROR(Render_Vulkan, "Out of device memory during compute pipeline creation, attempting recovery"); EvictOldPipelines(); return nullptr; } diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.h b/src/video_core/renderer_vulkan/vk_pipeline_cache.h index 8846a8337..6fb1d1e12 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.h +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.h @@ -144,8 +144,6 @@ private: /// Evicts old unused pipelines to free memory when under pressure void EvictOldPipelines(); - static constexpr size_t MAX_PIPELINES_IN_RAM = 4096; - public: /// Public interface to evict old pipelines (for memory pressure handling) void TriggerPipelineEviction() { @@ -188,6 +186,7 @@ public: Common::ThreadWorker workers; Common::ThreadWorker serialization_thread; DynamicFeatures dynamic_features; + }; } // namespace Vulkan