From 6bb191212b28d38e5d84cb422bd9599b0993697c Mon Sep 17 00:00:00 2001 From: Samuliak Date: Fri, 23 Aug 2024 09:41:00 +0200 Subject: [PATCH] simplify texture readback --- .../Renderer/Metal/LatteTextureReadbackMtl.cpp | 2 -- src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp | 14 ++++++-------- src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h | 12 ------------ 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureReadbackMtl.cpp b/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureReadbackMtl.cpp index 491017c0..f2c03709 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureReadbackMtl.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureReadbackMtl.cpp @@ -25,8 +25,6 @@ void LatteTextureReadbackInfoMtl::StartTransfer() blitCommandEncoder->copyFromTexture(baseTexture->GetTexture(), 0, 0, MTL::Origin{0, 0, 0}, MTL::Size{(uint32)baseTexture->width, (uint32)baseTexture->height, 1}, m_mtlr->GetTextureReadbackBuffer(), m_bufferOffset, bytesPerRow, bytesPerImage); m_commandBuffer = m_mtlr->GetCurrentCommandBuffer(); - m_mtlr->RequestSoonCommit(); - m_mtlr->RequestCommitOnIdle(); } bool LatteTextureReadbackInfoMtl::IsFinished() diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index a348409d..0031b4e2 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -21,7 +21,7 @@ #include "HW/Latte/Renderer/Metal/MetalCommon.h" #include "gui/guiWrapper.h" -#define DEFAULT_COMMIT_TRESHOLD 256 +#define COMMIT_TRESHOLD 256 extern bool hasValidFramebufferAttached; @@ -297,7 +297,7 @@ bool MetalRenderer::BeginFrame(bool mainWindow) void MetalRenderer::Flush(bool waitIdle) { - if (m_commitOnIdle || m_recordedDrawcalls > 0) + if (m_recordedDrawcalls > 0) CommitCommandBuffer(); if (waitIdle) { @@ -308,8 +308,8 @@ void MetalRenderer::Flush(bool waitIdle) void MetalRenderer::NotifyLatteCommandProcessorIdle() { - if (m_commitOnIdle) - CommitCommandBuffer(); + //if (m_commitOnIdle) + // CommitCommandBuffer(); } void MetalRenderer::AppendOverlayDebugInfo() @@ -1055,7 +1055,7 @@ void MetalRenderer::draw_endSequence() bool hasReadback = LatteTextureReadback_Update(); m_recordedDrawcalls++; // The number of draw calls needs to twice as big, since we are interrupting the render pass - if (m_recordedDrawcalls >= m_commitTreshold * 2 || hasReadback) + if (m_recordedDrawcalls >= COMMIT_TRESHOLD * 2 || hasReadback) { CommitCommandBuffer(); @@ -1320,16 +1320,14 @@ void MetalRenderer::EndEncoding() m_encoderType = MetalEncoderType::None; // Commit the command buffer if enough draw calls have been recorded - if (m_recordedDrawcalls >= m_commitTreshold) + if (m_recordedDrawcalls >= COMMIT_TRESHOLD) CommitCommandBuffer(); } } void MetalRenderer::CommitCommandBuffer() { - m_commitTreshold = DEFAULT_COMMIT_TRESHOLD; m_recordedDrawcalls = 0; - m_commitOnIdle = false; if (m_commandBuffers.size() != 0) { diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h index 108901f3..4da66653 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h @@ -375,16 +375,6 @@ public: return m_state.m_encoderState; } - void RequestSoonCommit() - { - m_commitTreshold = m_recordedDrawcalls + 8; - } - - void RequestCommitOnIdle() - { - m_commitOnIdle = true; - } - void SetBuffer(MTL::RenderCommandEncoder* renderCommandEncoder, MetalShaderType shaderType, MTL::Buffer* buffer, size_t offset, uint32 index); void SetTexture(MTL::RenderCommandEncoder* renderCommandEncoder, MetalShaderType shaderType, MTL::Texture* texture, uint32 index); void SetSamplerState(MTL::RenderCommandEncoder* renderCommandEncoder, MetalShaderType shaderType, MTL::SamplerState* samplerState, uint32 index); @@ -485,9 +475,7 @@ private: MTL::CommandEncoder* m_commandEncoder = nullptr; CA::MetalDrawable* m_drawable = nullptr; - uint32 m_commitTreshold = 0; uint32 m_recordedDrawcalls = 0; - bool m_commitOnIdle = false; // State MetalState m_state;