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;
|
||||
}
|
||||
|
||||
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 {
|
||||
ASSERT(!IsError());
|
||||
return mColorAttachmentsSet;
|
||||
|
|
|
@ -53,6 +53,8 @@ namespace dawn_native {
|
|||
const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot);
|
||||
const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor();
|
||||
dawn::PrimitiveTopology GetPrimitiveTopology() const;
|
||||
dawn::CullMode GetCullMode() const;
|
||||
dawn::FrontFace GetFrontFace() const;
|
||||
|
||||
std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const;
|
||||
bool HasDepthStencilAttachment() const;
|
||||
|
|
|
@ -684,6 +684,8 @@ namespace dawn_native { namespace metal {
|
|||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||
|
||||
[encoder setDepthStencilState:lastPipeline->GetMTLDepthStencilState()];
|
||||
[encoder setFrontFacingWinding:lastPipeline->GetMTLFrontFace()];
|
||||
[encoder setCullMode:lastPipeline->GetMTLCullMode()];
|
||||
lastPipeline->Encode(encoder);
|
||||
} break;
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
MTLIndexType GetMTLIndexType() const;
|
||||
MTLPrimitiveType GetMTLPrimitiveTopology() const;
|
||||
MTLWinding GetMTLFrontFace() const;
|
||||
MTLCullMode GetMTLCullMode() const;
|
||||
|
||||
void Encode(id<MTLRenderCommandEncoder> encoder);
|
||||
|
||||
|
@ -40,6 +42,8 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
MTLIndexType mMtlIndexType;
|
||||
MTLPrimitiveType mMtlPrimitiveTopology;
|
||||
MTLWinding mMtlFrontFace;
|
||||
MTLCullMode mMtlCullMode;
|
||||
id<MTLRenderPipelineState> mMtlRenderPipelineState = nil;
|
||||
id<MTLDepthStencilState> mMtlDepthStencilState = nil;
|
||||
};
|
||||
|
|
|
@ -282,12 +282,34 @@ namespace dawn_native { namespace metal {
|
|||
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
|
||||
|
||||
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
|
||||
: RenderPipelineBase(device, descriptor),
|
||||
mMtlIndexType(MTLIndexFormat(GetInputStateDescriptor()->indexFormat)),
|
||||
mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) {
|
||||
mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())),
|
||||
mMtlFrontFace(MTLFrontFace(GetFrontFace())),
|
||||
mMtlCullMode(ToMTLCullMode(GetCullMode())) {
|
||||
auto mtlDevice = device->GetMTLDevice();
|
||||
|
||||
MTLRenderPipelineDescriptor* descriptorMTL = [MTLRenderPipelineDescriptor new];
|
||||
|
@ -362,6 +384,14 @@ namespace dawn_native { namespace metal {
|
|||
return mMtlPrimitiveTopology;
|
||||
}
|
||||
|
||||
MTLWinding RenderPipeline::GetMTLFrontFace() const {
|
||||
return mMtlFrontFace;
|
||||
}
|
||||
|
||||
MTLCullMode RenderPipeline::GetMTLCullMode() const {
|
||||
return mMtlCullMode;
|
||||
}
|
||||
|
||||
void RenderPipeline::Encode(id<MTLRenderCommandEncoder> encoder) {
|
||||
[encoder setRenderPipelineState:mMtlRenderPipelineState];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue