From 27a31fedabf24d90b0c56b1fa770fe29ce729296 Mon Sep 17 00:00:00 2001 From: Samuliak Date: Wed, 8 Jan 2025 16:58:06 +0100 Subject: [PATCH] clean up accurate barriers --- .../HW/Latte/Renderer/Metal/MetalRenderer.cpp | 23 ++++++++++++------- .../HW/Latte/Renderer/Metal/MetalRenderer.h | 3 +-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index c5bdd335..d9850f07 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -1031,7 +1031,11 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32 endRenderPass = CheckIfRenderPassNeedsFlush(geometryShader); if (endRenderPass) + { EndEncoding(); + // TODO: only log in debug? + cemuLog_logOnce(LogType::Force, "Ending render pass due to render target self-dependency\n"); + } } // Primitive type @@ -1871,6 +1875,11 @@ bool MetalRenderer::CheckIfRenderPassNeedsFlush(LatteDecompilerShader* shader) const auto relative_textureUnit = shader->resourceMapping.getTextureUnitFromBindingPoint(i); auto hostTextureUnit = relative_textureUnit; auto textureDim = shader->textureUnitDim[relative_textureUnit]; + + // Texture is accessed as a framebuffer fetch, therefore there is no need to flush it + if (shader->textureRenderTargetIndex[relative_textureUnit] != 255) + continue; + auto texUnitRegIndex = hostTextureUnit * 7; switch (shader->shaderType) { @@ -1895,15 +1904,13 @@ bool MetalRenderer::CheckIfRenderPassNeedsFlush(LatteDecompilerShader* shader) continue; LatteTexture* baseTexture = textureView->baseTexture; - if (!m_state.m_isFirstDrawInRenderPass) + + // If the texture is also used in the current render pass, we need to end the render pass to "flush" the texture + for (uint8 i = 0; i < LATTE_NUM_COLOR_TARGET; i++) { - // If the texture is also used in the current render pass, we need to end the render pass to "flush" the texture - for (uint8 i = 0; i < LATTE_NUM_COLOR_TARGET; i++) - { - auto colorTarget = m_state.m_activeFBO.m_fbo->colorBuffer[i].texture; - if (colorTarget && colorTarget->baseTexture == baseTexture) - return true; - } + auto colorTarget = m_state.m_activeFBO.m_fbo->colorBuffer[i].texture; + if (colorTarget && colorTarget->baseTexture == baseTexture) + return true; } } diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h index 49aa40b1..c3898f3a 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h @@ -125,8 +125,7 @@ struct MetalState MetalActiveFBOState m_lastUsedFBO; size_t m_vertexBufferOffsets[MAX_MTL_VERTEX_BUFFERS]; - // TODO: find out what is the max number of bound textures on the Wii U - class LatteTextureViewMtl* m_textures[64] = {nullptr}; + class LatteTextureViewMtl* m_textures[LATTE_NUM_MAX_TEX_UNITS] = {nullptr}; size_t m_uniformBufferOffsets[METAL_GENERAL_SHADER_TYPE_TOTAL][MAX_MTL_BUFFERS]; MTL::Viewport m_viewport;