Metal: Apply BlendState to RenderPipeline

This commit is contained in:
Austin Eng 2017-08-03 12:17:14 -04:00 committed by Austin Eng
parent 4820dbd7ee
commit 476e5cbe30
3 changed files with 29 additions and 11 deletions

View File

@ -14,11 +14,13 @@
#include "backend/metal/RenderPipelineMTL.h" #include "backend/metal/RenderPipelineMTL.h"
#include "backend/metal/BlendStateMTL.h"
#include "backend/metal/DepthStencilStateMTL.h" #include "backend/metal/DepthStencilStateMTL.h"
#include "backend/metal/InputStateMTL.h" #include "backend/metal/InputStateMTL.h"
#include "backend/metal/MetalBackend.h" #include "backend/metal/MetalBackend.h"
#include "backend/metal/PipelineLayoutMTL.h" #include "backend/metal/PipelineLayoutMTL.h"
#include "backend/metal/ShaderModuleMTL.h" #include "backend/metal/ShaderModuleMTL.h"
#include "backend/metal/TextureMTL.h"
namespace backend { namespace backend {
namespace metal { namespace metal {
@ -78,9 +80,23 @@ namespace metal {
} }
} }
// TODO(cwallez@chromium.org): get the attachment formats from the subpass RenderPass* renderPass = ToBackend(GetRenderPass());
descriptor.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA8Unorm; auto& subpassInfo = renderPass->GetSubpassInfo(GetSubPass());
descriptor.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float;
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()); descriptor.inputPrimitiveTopology = MTLInputPrimitiveTopology(GetPrimitiveTopology());
InputState* inputState = ToBackend(GetInputState()); InputState* inputState = ToBackend(GetInputState());

View File

@ -22,6 +22,8 @@
namespace backend { namespace backend {
namespace metal { namespace metal {
MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format);
class Texture : public TextureBase { class Texture : public TextureBase {
public: public:
Texture(TextureBuilder* builder); Texture(TextureBuilder* builder);

View File

@ -19,16 +19,16 @@
namespace backend { namespace backend {
namespace metal { namespace metal {
namespace { MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format) {
MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format) { switch (format) {
switch (format) { case nxt::TextureFormat::R8G8B8A8Unorm:
case nxt::TextureFormat::R8G8B8A8Unorm: return MTLPixelFormatRGBA8Unorm;
return MTLPixelFormatRGBA8Unorm; case nxt::TextureFormat::D32FloatS8Uint:
case nxt::TextureFormat::D32FloatS8Uint: return MTLPixelFormatDepth32Float_Stencil8;
return MTLPixelFormatDepth32Float_Stencil8;
}
} }
}
namespace {
MTLTextureUsage MetalTextureUsage(nxt::TextureUsageBit usage) { MTLTextureUsage MetalTextureUsage(nxt::TextureUsageBit usage) {
MTLTextureUsage result = MTLTextureUsageUnknown; // This is 0 MTLTextureUsage result = MTLTextureUsageUnknown; // This is 0