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/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());

View File

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

View File

@ -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