Metal: Implement Culling and FrontFace
This is implementing the feature on a single backend and without tests so we can get it in the hands of people trying WebGPU quickly. BUG=dawn:43 Change-Id: I4d0611efd21dd1af053288957f137febc78a74e8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6721 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
22cee9ae36
commit
3826880f81
|
@ -435,6 +435,16 @@ namespace dawn_native {
|
||||||
return mPrimitiveTopology;
|
return mPrimitiveTopology;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dawn::CullMode RenderPipelineBase::GetCullMode() const {
|
||||||
|
ASSERT(!IsError());
|
||||||
|
return mRasterizationState.cullMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::FrontFace RenderPipelineBase::GetFrontFace() const {
|
||||||
|
ASSERT(!IsError());
|
||||||
|
return mRasterizationState.frontFace;
|
||||||
|
}
|
||||||
|
|
||||||
std::bitset<kMaxColorAttachments> RenderPipelineBase::GetColorAttachmentsMask() const {
|
std::bitset<kMaxColorAttachments> RenderPipelineBase::GetColorAttachmentsMask() const {
|
||||||
ASSERT(!IsError());
|
ASSERT(!IsError());
|
||||||
return mColorAttachmentsSet;
|
return mColorAttachmentsSet;
|
||||||
|
|
|
@ -53,6 +53,8 @@ namespace dawn_native {
|
||||||
const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot);
|
const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot);
|
||||||
const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor();
|
const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor();
|
||||||
dawn::PrimitiveTopology GetPrimitiveTopology() const;
|
dawn::PrimitiveTopology GetPrimitiveTopology() const;
|
||||||
|
dawn::CullMode GetCullMode() const;
|
||||||
|
dawn::FrontFace GetFrontFace() const;
|
||||||
|
|
||||||
std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const;
|
std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const;
|
||||||
bool HasDepthStencilAttachment() const;
|
bool HasDepthStencilAttachment() const;
|
||||||
|
|
|
@ -684,6 +684,8 @@ namespace dawn_native { namespace metal {
|
||||||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
|
|
||||||
[encoder setDepthStencilState:lastPipeline->GetMTLDepthStencilState()];
|
[encoder setDepthStencilState:lastPipeline->GetMTLDepthStencilState()];
|
||||||
|
[encoder setFrontFacingWinding:lastPipeline->GetMTLFrontFace()];
|
||||||
|
[encoder setCullMode:lastPipeline->GetMTLCullMode()];
|
||||||
lastPipeline->Encode(encoder);
|
lastPipeline->Encode(encoder);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
MTLIndexType GetMTLIndexType() const;
|
MTLIndexType GetMTLIndexType() const;
|
||||||
MTLPrimitiveType GetMTLPrimitiveTopology() const;
|
MTLPrimitiveType GetMTLPrimitiveTopology() const;
|
||||||
|
MTLWinding GetMTLFrontFace() const;
|
||||||
|
MTLCullMode GetMTLCullMode() const;
|
||||||
|
|
||||||
void Encode(id<MTLRenderCommandEncoder> encoder);
|
void Encode(id<MTLRenderCommandEncoder> encoder);
|
||||||
|
|
||||||
|
@ -40,6 +42,8 @@ namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
MTLIndexType mMtlIndexType;
|
MTLIndexType mMtlIndexType;
|
||||||
MTLPrimitiveType mMtlPrimitiveTopology;
|
MTLPrimitiveType mMtlPrimitiveTopology;
|
||||||
|
MTLWinding mMtlFrontFace;
|
||||||
|
MTLCullMode mMtlCullMode;
|
||||||
id<MTLRenderPipelineState> mMtlRenderPipelineState = nil;
|
id<MTLRenderPipelineState> mMtlRenderPipelineState = nil;
|
||||||
id<MTLDepthStencilState> mMtlDepthStencilState = nil;
|
id<MTLDepthStencilState> mMtlDepthStencilState = nil;
|
||||||
};
|
};
|
||||||
|
|
|
@ -282,12 +282,34 @@ namespace dawn_native { namespace metal {
|
||||||
return mtlDepthStencilDescriptor;
|
return mtlDepthStencilDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MTLWinding MTLFrontFace(dawn::FrontFace face) {
|
||||||
|
switch (face) {
|
||||||
|
case dawn::FrontFace::CCW:
|
||||||
|
return MTLWindingCounterClockwise;
|
||||||
|
case dawn::FrontFace::CW:
|
||||||
|
return MTLWindingClockwise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MTLCullMode ToMTLCullMode(dawn::CullMode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case dawn::CullMode::None:
|
||||||
|
return MTLCullModeNone;
|
||||||
|
case dawn::CullMode::Front:
|
||||||
|
return MTLCullModeFront;
|
||||||
|
case dawn::CullMode::Back:
|
||||||
|
return MTLCullModeBack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
|
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
|
||||||
: RenderPipelineBase(device, descriptor),
|
: RenderPipelineBase(device, descriptor),
|
||||||
mMtlIndexType(MTLIndexFormat(GetInputStateDescriptor()->indexFormat)),
|
mMtlIndexType(MTLIndexFormat(GetInputStateDescriptor()->indexFormat)),
|
||||||
mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) {
|
mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())),
|
||||||
|
mMtlFrontFace(MTLFrontFace(GetFrontFace())),
|
||||||
|
mMtlCullMode(ToMTLCullMode(GetCullMode())) {
|
||||||
auto mtlDevice = device->GetMTLDevice();
|
auto mtlDevice = device->GetMTLDevice();
|
||||||
|
|
||||||
MTLRenderPipelineDescriptor* descriptorMTL = [MTLRenderPipelineDescriptor new];
|
MTLRenderPipelineDescriptor* descriptorMTL = [MTLRenderPipelineDescriptor new];
|
||||||
|
@ -362,6 +384,14 @@ namespace dawn_native { namespace metal {
|
||||||
return mMtlPrimitiveTopology;
|
return mMtlPrimitiveTopology;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MTLWinding RenderPipeline::GetMTLFrontFace() const {
|
||||||
|
return mMtlFrontFace;
|
||||||
|
}
|
||||||
|
|
||||||
|
MTLCullMode RenderPipeline::GetMTLCullMode() const {
|
||||||
|
return mMtlCullMode;
|
||||||
|
}
|
||||||
|
|
||||||
void RenderPipeline::Encode(id<MTLRenderCommandEncoder> encoder) {
|
void RenderPipeline::Encode(id<MTLRenderCommandEncoder> encoder) {
|
||||||
[encoder setRenderPipelineState:mMtlRenderPipelineState];
|
[encoder setRenderPipelineState:mMtlRenderPipelineState];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue