diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 5a88a718b0..c7985e82fa 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -139,7 +139,22 @@ TextureCacheCommon::~TextureCacheCommon() { } void TextureCacheCommon::StartFrame() { + ForgetLastTexture(); textureShaderCache_->Decimate(); + timesInvalidatedAllThisFrame_ = 0; + replacementTimeThisFrame_ = 0.0; + + if (texelsScaledThisFrame_) { + VERBOSE_LOG(G3D, "Scaled %d texels", texelsScaledThisFrame_); + } + texelsScaledThisFrame_ = 0; + + if (clearCacheNextFrame_) { + Clear(true); + clearCacheNextFrame_ = false; + } else { + Decimate(false); + } } // Produces a signed 1.23.8 value. diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index c8d6b9194a..047a3504f9 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -185,25 +185,6 @@ void TextureCacheD3D11::ForgetLastTexture() { context_->PSSetShaderResources(0, 4, nullTex); } -void TextureCacheD3D11::StartFrame() { - TextureCacheCommon::StartFrame(); - - lastBoundTexture = INVALID_TEX; - timesInvalidatedAllThisFrame_ = 0; - replacementTimeThisFrame_ = 0.0; - - if (texelsScaledThisFrame_) { - // INFO_LOG(G3D, "Scaled %i texels", texelsScaledThisFrame_); - } - texelsScaledThisFrame_ = 0; - if (clearCacheNextFrame_) { - Clear(true); - clearCacheNextFrame_ = false; - } else { - Decimate(); - } -} - void TextureCacheD3D11::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) { const u32 clutBaseBytes = clutBase * (clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16)); // Technically, these extra bytes weren't loaded, but hopefully it was loaded earlier. diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 8c2ff77f62..35f14d5a6f 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -46,8 +46,6 @@ public: TextureCacheD3D11(Draw::DrawContext *draw, Draw2D *draw2D); ~TextureCacheD3D11(); - void StartFrame() override; - void SetFramebufferManager(FramebufferManagerD3D11 *fbManager); void ForgetLastTexture() override; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index d615c4e330..4e349fbe73 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -154,22 +154,8 @@ void TextureCacheDX9::ApplySamplingParams(const SamplerCacheKey &key) { void TextureCacheDX9::StartFrame() { TextureCacheCommon::StartFrame(); - lastBoundTexture = nullptr; - timesInvalidatedAllThisFrame_ = 0; - replacementTimeThisFrame_ = 0.0; - - if (texelsScaledThisFrame_) { - VERBOSE_LOG(G3D, "Scaled %i texels", texelsScaledThisFrame_); - } - texelsScaledThisFrame_ = 0; - if (clearCacheNextFrame_) { - Clear(true); - clearCacheNextFrame_ = false; - } else { - Decimate(); - } - if (gstate_c.Use(GPU_USE_ANISOTROPY)) { + // Just take the opportunity to set the global aniso level here, once per frame. DWORD aniso = 1 << g_Config.iAnisotropyLevel; DWORD anisotropyLevel = aniso > maxAnisotropyLevel ? maxAnisotropyLevel : aniso; device_->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, anisotropyLevel); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index c4ed59221d..aacba8e3d6 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -143,10 +143,6 @@ static void ConvertColors(void *dstBuf, const void *srcBuf, Draw::DataFormat dst void TextureCacheGLES::StartFrame() { TextureCacheCommon::StartFrame(); - ForgetLastTexture(); - timesInvalidatedAllThisFrame_ = 0; - replacementTimeThisFrame_ = 0.0; - GLRenderManager *renderManager = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); if (!lowMemoryMode_ && renderManager->SawOutOfMemory()) { lowMemoryMode_ = true; @@ -159,17 +155,6 @@ void TextureCacheGLES::StartFrame() { host->NotifyUserMessage(err->T("Warning: Video memory FULL, switching to slow caching mode"), 2.0f); } } - - if (texelsScaledThisFrame_) { - VERBOSE_LOG(G3D, "Scaled %i texels", texelsScaledThisFrame_); - } - texelsScaledThisFrame_ = 0; - if (clearCacheNextFrame_) { - Clear(true); - clearCacheNextFrame_ = false; - } else { - Decimate(); - } } void TextureCacheGLES::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) { diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index d47ed1ee2d..1444c6abca 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -327,27 +327,8 @@ static const VkFilter MagFiltVK[2] = { void TextureCacheVulkan::StartFrame() { TextureCacheCommon::StartFrame(); - - textureShaderCache_->Decimate(); - - timesInvalidatedAllThisFrame_ = 0; - texelsScaledThisFrame_ = 0; - replacementTimeThisFrame_ = 0.0; - - if (clearCacheNextFrame_) { - Clear(true); - clearCacheNextFrame_ = false; - } else { - int slabPressureLimit = TEXCACHE_SLAB_PRESSURE; - if (g_Config.iTexScalingLevel > 1) { - // Since textures are 2D maybe we should square this, but might get too non-aggressive. - slabPressureLimit *= g_Config.iTexScalingLevel; - } - // TODO: Use some indication from VMA. - // Maybe see https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/staying_within_budget.html#staying_within_budget_querying_for_budget . - Decimate(false); - } - + // TODO: For low memory detection, maybe use some indication from VMA. + // Maybe see https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/staying_within_budget.html#staying_within_budget_querying_for_budget . computeShaderManager_.BeginFrame(); } diff --git a/GPU/Vulkan/VulkanUtil.cpp b/GPU/Vulkan/VulkanUtil.cpp index 0d87ebc153..d10749b187 100644 --- a/GPU/Vulkan/VulkanUtil.cpp +++ b/GPU/Vulkan/VulkanUtil.cpp @@ -52,8 +52,7 @@ VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits } } -VulkanComputeShaderManager::VulkanComputeShaderManager(VulkanContext *vulkan) : vulkan_(vulkan), pipelines_(8) { -} +VulkanComputeShaderManager::VulkanComputeShaderManager(VulkanContext *vulkan) : vulkan_(vulkan), pipelines_(8) {} VulkanComputeShaderManager::~VulkanComputeShaderManager() {} void VulkanComputeShaderManager::InitDeviceObjects(Draw::DrawContext *draw) { @@ -96,6 +95,7 @@ void VulkanComputeShaderManager::InitDeviceObjects(Draw::DrawContext *draw) { for (int i = 0; i < ARRAY_SIZE(frameData_); i++) { frameData_[i].descPool.Create(vulkan_, dp, dpTypes); + frameData_[i].descPoolUsed = false; } VkPushConstantRange push = {}; @@ -137,6 +137,7 @@ void VulkanComputeShaderManager::DestroyDeviceObjects() { VkDescriptorSet VulkanComputeShaderManager::GetDescriptorSet(VkImageView image, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range, VkBuffer buffer2, VkDeviceSize offset2, VkDeviceSize range2) { int curFrame = vulkan_->GetCurFrame(); FrameData &frameData = frameData_[curFrame]; + frameData.descPoolUsed = true; VkDescriptorSet desc = frameData.descPool.Allocate(1, &descriptorSetLayout_, "compute_descset"); _assert_(desc != VK_NULL_HANDLE); @@ -206,5 +207,8 @@ VkPipeline VulkanComputeShaderManager::GetPipeline(VkShaderModule cs) { void VulkanComputeShaderManager::BeginFrame() { int curFrame = vulkan_->GetCurFrame(); FrameData &frame = frameData_[curFrame]; - frame.descPool.Reset(); + if (frame.descPoolUsed) { + frame.descPool.Reset(); + frame.descPoolUsed = false; + } } diff --git a/GPU/Vulkan/VulkanUtil.h b/GPU/Vulkan/VulkanUtil.h index 2046f6201f..75ed153ad3 100644 --- a/GPU/Vulkan/VulkanUtil.h +++ b/GPU/Vulkan/VulkanUtil.h @@ -77,6 +77,7 @@ private: } VulkanDescSetPool descPool; + bool descPoolUsed = false; }; FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES];