From 5030a2e84acedb1bb65b077da4e6a79a1ebc7c2a Mon Sep 17 00:00:00 2001 From: Samuliak Date: Sun, 4 Aug 2024 15:09:49 +0200 Subject: [PATCH] implement color buffer clear --- .../HW/Latte/Renderer/Metal/MetalRenderer.cpp | 36 +++++++++++-------- .../HW/Latte/Renderer/Metal/MetalRenderer.h | 2 ++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index 67e1cb46..ad1ce126 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -126,7 +126,10 @@ bool MetalRenderer::GetVRAMInfo(int& usageInMB, int& totalInMB) const void MetalRenderer::ClearColorbuffer(bool padView) { - debug_printf("MetalRenderer::ClearColorbuffer not implemented\n"); + if (!AcquireNextDrawable()) + return; + + ClearColorTextureInternal(m_drawable->texture(), 0, 0, 0.0f, 0.0f, 0.0f, 0.0f); } void MetalRenderer::DrawEmptyFrame(bool mainWindow) @@ -283,19 +286,7 @@ void MetalRenderer::texture_clearColorSlice(LatteTexture* hostTexture, sint32 sl { auto mtlTexture = static_cast(hostTexture)->GetTexture(); - MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init(); - auto colorAttachment = renderPassDescriptor->colorAttachments()->object(0); - colorAttachment->setTexture(mtlTexture); - colorAttachment->setClearColor(MTL::ClearColor(r, g, b, a)); - colorAttachment->setLoadAction(MTL::LoadActionClear); - colorAttachment->setStoreAction(MTL::StoreActionStore); - colorAttachment->setSlice(sliceIndex); - colorAttachment->setLevel(mipIndex); - - MTL::Texture* colorRenderTargets[8] = {nullptr}; - colorRenderTargets[0] = mtlTexture; - GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, nullptr, true); - renderPassDescriptor->release(); + ClearColorTextureInternal(mtlTexture, sliceIndex, mipIndex, r, g, b, a); } void MetalRenderer::texture_clearDepthSlice(LatteTexture* hostTexture, uint32 sliceIndex, sint32 mipIndex, bool clearDepth, bool clearStencil, float depthValue, uint32 stencilValue) @@ -1162,3 +1153,20 @@ void MetalRenderer::RebindRenderState(MTL::RenderCommandEncoder* renderCommandEn } } } + +void MetalRenderer::ClearColorTextureInternal(MTL::Texture* mtlTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a) +{ + MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init(); + auto colorAttachment = renderPassDescriptor->colorAttachments()->object(0); + colorAttachment->setTexture(mtlTexture); + colorAttachment->setClearColor(MTL::ClearColor(r, g, b, a)); + colorAttachment->setLoadAction(MTL::LoadActionClear); + colorAttachment->setStoreAction(MTL::StoreActionStore); + colorAttachment->setSlice(sliceIndex); + colorAttachment->setLevel(mipIndex); + + MTL::Texture* colorRenderTargets[8] = {nullptr}; + colorRenderTargets[0] = mtlTexture; + GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, nullptr, true); + renderPassDescriptor->release(); +} diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h index f5064d54..b6fb30ad 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h @@ -229,4 +229,6 @@ private: void BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader); void RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder); + + void ClearColorTextureInternal(MTL::Texture* mtlTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a); };