only begin a new render pass when necessary

This commit is contained in:
Samuliak 2024-07-03 12:48:40 +02:00
parent 9ec116da18
commit ea56f45fc2
2 changed files with 59 additions and 40 deletions

View file

@ -52,6 +52,9 @@ class RendererMTL final : public Renderer {
// Active state
MTL::CommandBuffer* commandBuffer = nullptr;
MTL::RenderCommandEncoder* renderCommandEncoder = nullptr;
MTL::Texture* lastColorTexture = nullptr;
MTL::Texture* lastDepthTexture = nullptr;
void createCommandBufferIfNeeded() {
if (!commandBuffer) {
@ -59,6 +62,37 @@ class RendererMTL final : public Renderer {
}
}
void endRenderPass() {
if (renderCommandEncoder) {
renderCommandEncoder->endEncoding();
renderCommandEncoder = nullptr;
}
}
void beginRenderPassIfNeeded(MTL::RenderPassDescriptor* renderPassDescriptor, MTL::Texture* colorTexture, MTL::Texture* depthTexture) {
createCommandBufferIfNeeded();
if (!renderCommandEncoder || colorTexture != lastColorTexture || depthTexture != lastDepthTexture) {
endRenderPass();
renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor);
lastColorTexture = colorTexture;
lastDepthTexture = depthTexture;
}
}
void commitCommandBuffer() {
if (renderCommandEncoder) {
renderCommandEncoder->endEncoding();
renderCommandEncoder = nullptr;
}
if (commandBuffer) {
commandBuffer->commit();
commandBuffer = nullptr;
}
}
std::optional<Metal::ColorRenderTarget> getColorRenderTarget(u32 addr, PICA::ColorFmt format, u32 width, u32 height, bool createIfnotFound = true);
Metal::DepthStencilRenderTarget& getDepthRenderTarget();
MTL::Texture* getTexture(Metal::Texture& tex);