diff --git a/src/backend/metal/RenderPipelineMTL.mm b/src/backend/metal/RenderPipelineMTL.mm index b85105613b..01830485aa 100644 --- a/src/backend/metal/RenderPipelineMTL.mm +++ b/src/backend/metal/RenderPipelineMTL.mm @@ -14,11 +14,13 @@ #include "backend/metal/RenderPipelineMTL.h" +#include "backend/metal/BlendStateMTL.h" #include "backend/metal/DepthStencilStateMTL.h" #include "backend/metal/InputStateMTL.h" #include "backend/metal/MetalBackend.h" #include "backend/metal/PipelineLayoutMTL.h" #include "backend/metal/ShaderModuleMTL.h" +#include "backend/metal/TextureMTL.h" namespace backend { namespace metal { @@ -78,9 +80,23 @@ namespace metal { } } - // TODO(cwallez@chromium.org): get the attachment formats from the subpass - descriptor.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA8Unorm; - descriptor.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float; + RenderPass* renderPass = ToBackend(GetRenderPass()); + auto& subpassInfo = renderPass->GetSubpassInfo(GetSubPass()); + + if (subpassInfo.depthStencilAttachmentSet) { + const auto& attachmentInfo = renderPass->GetAttachmentInfo(subpassInfo.depthStencilAttachment); + descriptor.depthAttachmentPixelFormat = MetalPixelFormat(attachmentInfo.format); + descriptor.stencilAttachmentPixelFormat = MetalPixelFormat(attachmentInfo.format); + } + + for (unsigned int attachmentSlot : IterateBitSet(subpassInfo.colorAttachmentsSet)) { + uint32_t attachment = subpassInfo.colorAttachments[attachmentSlot]; + const auto& attachmentInfo = renderPass->GetAttachmentInfo(attachment); + + descriptor.colorAttachments[attachmentSlot].pixelFormat = MetalPixelFormat(attachmentInfo.format); + ToBackend(GetBlendState(attachmentSlot))->ApplyBlendState(descriptor.colorAttachments[attachmentSlot]); + } + descriptor.inputPrimitiveTopology = MTLInputPrimitiveTopology(GetPrimitiveTopology()); InputState* inputState = ToBackend(GetInputState()); diff --git a/src/backend/metal/TextureMTL.h b/src/backend/metal/TextureMTL.h index 645253bdfa..760431c9f1 100644 --- a/src/backend/metal/TextureMTL.h +++ b/src/backend/metal/TextureMTL.h @@ -22,6 +22,8 @@ namespace backend { namespace metal { + MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format); + class Texture : public TextureBase { public: Texture(TextureBuilder* builder); diff --git a/src/backend/metal/TextureMTL.mm b/src/backend/metal/TextureMTL.mm index 2ab193173a..65e3c2bf44 100644 --- a/src/backend/metal/TextureMTL.mm +++ b/src/backend/metal/TextureMTL.mm @@ -19,16 +19,16 @@ namespace backend { namespace metal { - namespace { - MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format) { - switch (format) { - case nxt::TextureFormat::R8G8B8A8Unorm: - return MTLPixelFormatRGBA8Unorm; - case nxt::TextureFormat::D32FloatS8Uint: - return MTLPixelFormatDepth32Float_Stencil8; - } + MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format) { + switch (format) { + case nxt::TextureFormat::R8G8B8A8Unorm: + return MTLPixelFormatRGBA8Unorm; + case nxt::TextureFormat::D32FloatS8Uint: + return MTLPixelFormatDepth32Float_Stencil8; } + } + namespace { MTLTextureUsage MetalTextureUsage(nxt::TextureUsageBit usage) { MTLTextureUsage result = MTLTextureUsageUnknown; // This is 0