mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-05 22:41:18 +12:00
refactor fbos
This commit is contained in:
parent
6b47d4f61e
commit
cd21d957b3
9 changed files with 143 additions and 75 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "Cafe/HW/Latte/Renderer/Metal/MetalCommon.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/MetalLayerHandle.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Renderer.h"
|
||||
#include "HW/Latte/Renderer/Metal/MetalAttachmentsInfo.h"
|
||||
#include "config/CemuConfig.h"
|
||||
|
||||
#define IMGUI_IMPL_METAL_CPP
|
||||
|
@ -511,13 +512,13 @@ LatteCachedFBO* MetalRenderer::rendertarget_createCachedFBO(uint64 key)
|
|||
|
||||
void MetalRenderer::rendertarget_deleteCachedFBO(LatteCachedFBO* cfbo)
|
||||
{
|
||||
if (cfbo == (LatteCachedFBO*)m_state.m_activeFBO)
|
||||
m_state.m_activeFBO = nullptr;
|
||||
if (cfbo == (LatteCachedFBO*)m_state.m_activeFBO.m_fbo)
|
||||
m_state.m_activeFBO = {nullptr};
|
||||
}
|
||||
|
||||
void MetalRenderer::rendertarget_bindFramebufferObject(LatteCachedFBO* cfbo)
|
||||
{
|
||||
m_state.m_activeFBO = (CachedFBOMtl*)cfbo;
|
||||
m_state.m_activeFBO = {(CachedFBOMtl*)cfbo, MetalAttachmentsInfo((CachedFBOMtl*)cfbo)};
|
||||
}
|
||||
|
||||
void* MetalRenderer::texture_acquireTextureUploadBuffer(uint32 size)
|
||||
|
@ -1008,7 +1009,7 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
|
|||
// Disable depth write when there is no depth attachment
|
||||
auto& depthControl = LatteGPUState.contextNew.DB_DEPTH_CONTROL;
|
||||
bool depthWriteEnable = depthControl.get_Z_WRITE_ENABLE();
|
||||
if (!m_state.m_activeFBO->depthBuffer.texture)
|
||||
if (!m_state.m_activeFBO.m_fbo->depthBuffer.texture)
|
||||
depthControl.set_Z_WRITE_ENABLE(false);
|
||||
|
||||
MTL::DepthStencilState* depthStencilState = m_depthStencilCache->GetDepthStencilState(LatteGPUState.contextNew);
|
||||
|
@ -1222,7 +1223,7 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
|
|||
//}
|
||||
|
||||
// Render pipeline state
|
||||
MTL::RenderPipelineState* renderPipelineState = m_pipelineCache->GetRenderPipelineState(fetchShader, vertexShader, geometryShader, pixelShader, m_state.m_lastUsedFBO, m_state.m_activeFBO, LatteGPUState.contextNew);
|
||||
MTL::RenderPipelineState* renderPipelineState = m_pipelineCache->GetRenderPipelineState(fetchShader, vertexShader, geometryShader, pixelShader, m_state.m_lastUsedFBO.m_attachmentsInfo, m_state.m_activeFBO.m_attachmentsInfo, LatteGPUState.contextNew);
|
||||
if (!renderPipelineState)
|
||||
return;
|
||||
|
||||
|
@ -1524,12 +1525,12 @@ MTL::RenderCommandEncoder* MetalRenderer::GetRenderCommandEncoder(bool forceRecr
|
|||
{
|
||||
if (m_encoderType == MetalEncoderType::Render)
|
||||
{
|
||||
bool needsNewRenderPass = (m_state.m_lastUsedFBO == nullptr);
|
||||
bool needsNewRenderPass = (m_state.m_lastUsedFBO.m_fbo == nullptr);
|
||||
if (!needsNewRenderPass)
|
||||
{
|
||||
for (uint8 i = 0; i < 8; i++)
|
||||
{
|
||||
if (m_state.m_activeFBO->colorBuffer[i].texture && m_state.m_activeFBO->colorBuffer[i].texture != m_state.m_lastUsedFBO->colorBuffer[i].texture)
|
||||
if (m_state.m_activeFBO.m_fbo->colorBuffer[i].texture && m_state.m_activeFBO.m_fbo->colorBuffer[i].texture != m_state.m_lastUsedFBO.m_fbo->colorBuffer[i].texture)
|
||||
{
|
||||
needsNewRenderPass = true;
|
||||
break;
|
||||
|
@ -1539,7 +1540,7 @@ MTL::RenderCommandEncoder* MetalRenderer::GetRenderCommandEncoder(bool forceRecr
|
|||
|
||||
if (!needsNewRenderPass)
|
||||
{
|
||||
if (m_state.m_activeFBO->depthBuffer.texture && (m_state.m_activeFBO->depthBuffer.texture != m_state.m_lastUsedFBO->depthBuffer.texture || ( m_state.m_activeFBO->depthBuffer.hasStencil && !m_state.m_lastUsedFBO->depthBuffer.hasStencil)))
|
||||
if (m_state.m_activeFBO.m_fbo->depthBuffer.texture && (m_state.m_activeFBO.m_fbo->depthBuffer.texture != m_state.m_lastUsedFBO.m_fbo->depthBuffer.texture || ( m_state.m_activeFBO.m_fbo->depthBuffer.hasStencil && !m_state.m_lastUsedFBO.m_fbo->depthBuffer.hasStencil)))
|
||||
{
|
||||
needsNewRenderPass = true;
|
||||
}
|
||||
|
@ -1557,7 +1558,7 @@ MTL::RenderCommandEncoder* MetalRenderer::GetRenderCommandEncoder(bool forceRecr
|
|||
|
||||
auto commandBuffer = GetCommandBuffer();
|
||||
|
||||
auto renderCommandEncoder = commandBuffer->renderCommandEncoder(m_state.m_activeFBO->GetRenderPassDescriptor());
|
||||
auto renderCommandEncoder = commandBuffer->renderCommandEncoder(m_state.m_activeFBO.m_fbo->GetRenderPassDescriptor());
|
||||
#ifdef CEMU_DEBUG_ASSERT
|
||||
renderCommandEncoder->setLabel(GetLabel("Render command encoder", renderCommandEncoder));
|
||||
#endif
|
||||
|
@ -1716,7 +1717,7 @@ bool MetalRenderer::CheckIfRenderPassNeedsFlush(LatteDecompilerShader* shader)
|
|||
// 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->colorBuffer[i].texture;
|
||||
auto colorTarget = m_state.m_activeFBO.m_fbo->colorBuffer[i].texture;
|
||||
if (colorTarget && colorTarget->baseTexture == baseTexture)
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue