VideoBackends:Metal: Multi render target support

This commit is contained in:
TellowKrinkle
2023-06-27 23:50:16 -05:00
parent 78f4a9189d
commit fc4036af80
6 changed files with 82 additions and 48 deletions

View File

@ -189,13 +189,56 @@ void Metal::StagingTexture::Flush()
m_wait_buffer = nullptr;
}
Metal::Framebuffer::Framebuffer(AbstractTexture* color, AbstractTexture* depth, //
static void InitDesc(id desc, AbstractTexture* tex)
{
[desc setTexture:static_cast<Metal::Texture*>(tex)->GetMTLTexture()];
[desc setLoadAction:MTLLoadActionLoad];
[desc setStoreAction:MTLStoreActionStore];
}
static void InitStencilDesc(MTLRenderPassStencilAttachmentDescriptor* desc, AbstractTexture* tex)
{
InitDesc(desc, tex);
[desc setClearStencil:0];
}
Metal::Framebuffer::Framebuffer(AbstractTexture* color, AbstractTexture* depth,
std::vector<AbstractTexture*> additonal_color_textures, //
u32 width, u32 height, u32 layers, u32 samples)
: AbstractFramebuffer(color, depth, {},
color ? color->GetFormat() : AbstractTextureFormat::Undefined, //
depth ? depth->GetFormat() : AbstractTextureFormat::Undefined, //
width, height, layers, samples)
width, height, layers, samples),
m_additional_color_textures(std::move(additonal_color_textures))
{
m_pass_descriptor = MRCTransfer([MTLRenderPassDescriptor new]);
MTLRenderPassDescriptor* desc = m_pass_descriptor;
if (color)
InitDesc(desc.colorAttachments[0], color);
if (depth)
{
InitDesc(desc.depthAttachment, depth);
if (Util::HasStencil(depth->GetFormat()))
InitStencilDesc(desc.stencilAttachment, depth);
}
for (size_t i = 0; i < m_additional_color_textures.size(); i++)
InitDesc(desc.colorAttachments[i + 1], m_additional_color_textures[i]);
}
Metal::Framebuffer::~Framebuffer() = default;
void Metal::Framebuffer::ActualSetLoadAction(MTLLoadAction action)
{
m_current_load_action = action;
AbstractTextureFormat depth_fmt = GetDepthFormat();
MTLRenderPassDescriptor* desc = m_pass_descriptor;
desc.colorAttachments[0].loadAction = action;
if (depth_fmt != AbstractTextureFormat::Undefined)
{
desc.depthAttachment.loadAction = action;
if (Util::HasStencil(depth_fmt))
desc.stencilAttachment.loadAction = action;
}
for (size_t i = 0; i < NumAdditionalColorTextures(); i++)
desc.colorAttachments[i + 1].loadAction = action;
}