mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-06 23:11:18 +12:00
support arbitrary pixel formats for state 5
This commit is contained in:
parent
66ad59db92
commit
00857b233b
2 changed files with 29 additions and 19 deletions
|
@ -134,22 +134,12 @@ MetalRenderer::MetalRenderer()
|
||||||
MTL::Function* vertexFullscreenFunction = utilityLibrary->newFunction(ToNSString("vertexFullscreen"));
|
MTL::Function* vertexFullscreenFunction = utilityLibrary->newFunction(ToNSString("vertexFullscreen"));
|
||||||
MTL::Function* fragmentCopyDepthToColorFunction = utilityLibrary->newFunction(ToNSString("fragmentCopyDepthToColor"));
|
MTL::Function* fragmentCopyDepthToColorFunction = utilityLibrary->newFunction(ToNSString("fragmentCopyDepthToColor"));
|
||||||
|
|
||||||
MTL::RenderPipelineDescriptor* rpd = MTL::RenderPipelineDescriptor::alloc()->init();
|
m_copyDepthToColorDesc = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||||
rpd->setVertexFunction(vertexFullscreenFunction);
|
m_copyDepthToColorDesc->setVertexFunction(vertexFullscreenFunction);
|
||||||
rpd->setFragmentFunction(fragmentCopyDepthToColorFunction);
|
m_copyDepthToColorDesc->setFragmentFunction(fragmentCopyDepthToColorFunction);
|
||||||
// TODO: don't hardcode the format
|
|
||||||
rpd->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatR16Unorm);
|
|
||||||
|
|
||||||
vertexFullscreenFunction->release();
|
vertexFullscreenFunction->release();
|
||||||
fragmentCopyDepthToColorFunction->release();
|
fragmentCopyDepthToColorFunction->release();
|
||||||
|
|
||||||
error = nullptr;
|
|
||||||
m_copyDepthToColorPipeline = m_device->newRenderPipelineState(rpd, &error);
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
cemuLog_log(LogType::Force, "failed to create copy depth to color pipeline (error: {})", error->localizedDescription()->utf8String());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Void vertex pipelines
|
// Void vertex pipelines
|
||||||
if (m_isAppleGPU)
|
if (m_isAppleGPU)
|
||||||
m_copyBufferToBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyBufferToBuffer");
|
m_copyBufferToBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyBufferToBuffer");
|
||||||
|
@ -164,7 +154,9 @@ MetalRenderer::~MetalRenderer()
|
||||||
//delete m_copyTextureToTexturePipeline;
|
//delete m_copyTextureToTexturePipeline;
|
||||||
//delete m_restrideBufferPipeline;
|
//delete m_restrideBufferPipeline;
|
||||||
|
|
||||||
m_copyDepthToColorPipeline->release();
|
m_copyDepthToColorDesc->release();
|
||||||
|
for (const auto [pixelFormat, pipeline] : m_copyDepthToColorPipelines)
|
||||||
|
pipeline->release();
|
||||||
|
|
||||||
delete m_outputShaderCache;
|
delete m_outputShaderCache;
|
||||||
delete m_pipelineCache;
|
delete m_pipelineCache;
|
||||||
|
@ -1369,22 +1361,39 @@ void MetalRenderer::draw_handleSpecialState5()
|
||||||
|
|
||||||
LatteTextureView* colorBuffer = LatteMRT::GetColorAttachment(0);
|
LatteTextureView* colorBuffer = LatteMRT::GetColorAttachment(0);
|
||||||
LatteTextureView* depthBuffer = LatteMRT::GetDepthAttachment();
|
LatteTextureView* depthBuffer = LatteMRT::GetDepthAttachment();
|
||||||
auto mtlDepthTexture = static_cast<LatteTextureViewMtl*>(depthBuffer)->GetRGBAView();
|
auto colorTextureMtl = static_cast<LatteTextureViewMtl*>(colorBuffer);
|
||||||
|
auto depthTextureMtl = static_cast<LatteTextureViewMtl*>(depthBuffer);
|
||||||
|
|
||||||
sint32 vpWidth, vpHeight;
|
sint32 vpWidth, vpHeight;
|
||||||
LatteMRT::GetVirtualViewportDimensions(vpWidth, vpHeight);
|
LatteMRT::GetVirtualViewportDimensions(vpWidth, vpHeight);
|
||||||
|
|
||||||
|
// Get the pipeline
|
||||||
|
MTL::PixelFormat colorPixelFormat = colorTextureMtl->GetRGBAView()->pixelFormat();
|
||||||
|
auto& pipeline = m_copyDepthToColorPipelines[colorPixelFormat];
|
||||||
|
if (!pipeline)
|
||||||
|
{
|
||||||
|
m_copyDepthToColorDesc->colorAttachments()->object(0)->setPixelFormat(colorPixelFormat);
|
||||||
|
|
||||||
|
NS::Error* error = nullptr;
|
||||||
|
pipeline = m_device->newRenderPipelineState(m_copyDepthToColorDesc, &error);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
cemuLog_log(LogType::Force, "failed to create copy depth to color pipeline (error: {})", error->localizedDescription()->utf8String());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sadly, we need to end encoding to ensure that the depth data is up-to-date
|
// Sadly, we need to end encoding to ensure that the depth data is up-to-date
|
||||||
|
EndEncoding();
|
||||||
|
|
||||||
// Copy depth to color
|
// Copy depth to color
|
||||||
auto renderCommandEncoder = GetRenderCommandEncoder();
|
auto renderCommandEncoder = GetRenderCommandEncoder();
|
||||||
|
|
||||||
auto& encoderState = m_state.m_encoderState;
|
auto& encoderState = m_state.m_encoderState;
|
||||||
|
|
||||||
renderCommandEncoder->setRenderPipelineState(m_copyDepthToColorPipeline);
|
renderCommandEncoder->setRenderPipelineState(pipeline);
|
||||||
// TODO: make a helper function for this
|
// TODO: make a helper function for this
|
||||||
encoderState.m_renderPipelineState = m_copyDepthToColorPipeline;
|
encoderState.m_renderPipelineState = pipeline;
|
||||||
SetTexture(renderCommandEncoder, METAL_SHADER_TYPE_FRAGMENT, mtlDepthTexture, GET_HELPER_TEXTURE_BINDING(0));
|
SetTexture(renderCommandEncoder, METAL_SHADER_TYPE_FRAGMENT, depthTextureMtl->GetRGBAView(), GET_HELPER_TEXTURE_BINDING(0));
|
||||||
// TODO: make a helper function for this
|
// TODO: make a helper function for this
|
||||||
renderCommandEncoder->setFragmentBytes(&vpWidth, sizeof(sint32), GET_HELPER_BUFFER_BINDING(0));
|
renderCommandEncoder->setFragmentBytes(&vpWidth, sizeof(sint32), GET_HELPER_BUFFER_BINDING(0));
|
||||||
encoderState.m_buffers[METAL_SHADER_TYPE_FRAGMENT][GET_HELPER_BUFFER_BINDING(0)] = {nullptr};
|
encoderState.m_buffers[METAL_SHADER_TYPE_FRAGMENT][GET_HELPER_BUFFER_BINDING(0)] = {nullptr};
|
||||||
|
|
|
@ -473,7 +473,8 @@ private:
|
||||||
class MetalSamplerCache* m_samplerCache;
|
class MetalSamplerCache* m_samplerCache;
|
||||||
|
|
||||||
// Pipelines
|
// Pipelines
|
||||||
MTL::RenderPipelineState* m_copyDepthToColorPipeline;
|
MTL::RenderPipelineDescriptor* m_copyDepthToColorDesc;
|
||||||
|
std::map<MTL::PixelFormat, MTL::RenderPipelineState*> m_copyDepthToColorPipelines;
|
||||||
|
|
||||||
// Void vertex pipelines
|
// Void vertex pipelines
|
||||||
class MetalVoidVertexPipeline* m_copyBufferToBufferPipeline;
|
class MetalVoidVertexPipeline* m_copyBufferToBufferPipeline;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue