mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Implement Culling and FrontFace
This patch implements Culling and FrontFace on backends, and add tests too. This test also verified that we couldn't invert FrontFace on Metal backend. Otherwise, the tests would fail on all HWs. But we do need to invert CCW/CW on OpenGL backend. Because Y axis is up in OpenGL while Y axis is down in WebGPU. Bug=dawn:43 Change-Id: I7dd0922477397a13c5f7208e104ff352a673a556 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8420 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
committed by
Commit Bot service account
parent
c6d2d8e8fb
commit
d2631f86e7
@@ -138,6 +138,19 @@ namespace dawn_native { namespace d3d12 {
|
||||
}
|
||||
}
|
||||
|
||||
D3D12_CULL_MODE D3D12CullMode(dawn::CullMode mode) {
|
||||
switch (mode) {
|
||||
case dawn::CullMode::None:
|
||||
return D3D12_CULL_MODE_NONE;
|
||||
case dawn::CullMode::Front:
|
||||
return D3D12_CULL_MODE_FRONT;
|
||||
case dawn::CullMode::Back:
|
||||
return D3D12_CULL_MODE_BACK;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
D3D12_BLEND D3D12Blend(dawn::BlendFactor factor) {
|
||||
switch (factor) {
|
||||
case dawn::BlendFactor::Zero:
|
||||
@@ -343,8 +356,9 @@ namespace dawn_native { namespace d3d12 {
|
||||
}
|
||||
|
||||
descriptorD3D12.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
|
||||
descriptorD3D12.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
|
||||
descriptorD3D12.RasterizerState.FrontCounterClockwise = FALSE;
|
||||
descriptorD3D12.RasterizerState.CullMode = D3D12CullMode(GetCullMode());
|
||||
descriptorD3D12.RasterizerState.FrontCounterClockwise =
|
||||
(GetFrontFace() == dawn::FrontFace::CCW) ? TRUE : FALSE;
|
||||
descriptorD3D12.RasterizerState.DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
|
||||
descriptorD3D12.RasterizerState.DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
|
||||
descriptorD3D12.RasterizerState.SlopeScaledDepthBias =
|
||||
|
||||
@@ -283,12 +283,11 @@ namespace dawn_native { namespace metal {
|
||||
}
|
||||
|
||||
MTLWinding MTLFrontFace(dawn::FrontFace face) {
|
||||
// Note that these are inverted because we flip the Y coordinate in the vertex shader
|
||||
switch (face) {
|
||||
case dawn::FrontFace::CW:
|
||||
return MTLWindingCounterClockwise;
|
||||
case dawn::FrontFace::CCW:
|
||||
return MTLWindingClockwise;
|
||||
case dawn::FrontFace::CCW:
|
||||
return MTLWindingCounterClockwise;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,23 @@ namespace dawn_native { namespace opengl {
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyFrontFaceAndCulling(const OpenGLFunctions& gl,
|
||||
dawn::FrontFace face,
|
||||
dawn::CullMode mode) {
|
||||
if (mode == dawn::CullMode::None) {
|
||||
gl.Disable(GL_CULL_FACE);
|
||||
} else {
|
||||
gl.Enable(GL_CULL_FACE);
|
||||
// Note that we invert winding direction in OpenGL. Because Y axis is up in OpenGL,
|
||||
// which is different from WebGPU and other backends (Y axis is down).
|
||||
GLenum direction = (face == dawn::FrontFace::CCW) ? GL_CW : GL_CCW;
|
||||
gl.FrontFace(direction);
|
||||
|
||||
GLenum cullMode = (mode == dawn::CullMode::Front) ? GL_FRONT : GL_BACK;
|
||||
gl.CullFace(cullMode);
|
||||
}
|
||||
}
|
||||
|
||||
GLenum GLBlendFactor(dawn::BlendFactor factor, bool alpha) {
|
||||
switch (factor) {
|
||||
case dawn::BlendFactor::Zero:
|
||||
@@ -236,6 +253,8 @@ namespace dawn_native { namespace opengl {
|
||||
ASSERT(mVertexArrayObject);
|
||||
gl.BindVertexArray(mVertexArrayObject);
|
||||
|
||||
ApplyFrontFaceAndCulling(gl, GetFrontFace(), GetCullMode());
|
||||
|
||||
ApplyDepthStencilState(gl, GetDepthStencilStateDescriptor(), &persistentPipelineState);
|
||||
|
||||
for (uint32_t attachmentSlot : IterateBitSet(GetColorAttachmentsMask())) {
|
||||
|
||||
@@ -137,6 +137,26 @@ namespace dawn_native { namespace vulkan {
|
||||
}
|
||||
}
|
||||
|
||||
VkFrontFace VulkanFrontFace(dawn::FrontFace face) {
|
||||
switch (face) {
|
||||
case dawn::FrontFace::CCW:
|
||||
return VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
case dawn::FrontFace::CW:
|
||||
return VK_FRONT_FACE_CLOCKWISE;
|
||||
}
|
||||
}
|
||||
|
||||
VkCullModeFlagBits VulkanCullMode(dawn::CullMode mode) {
|
||||
switch (mode) {
|
||||
case dawn::CullMode::None:
|
||||
return VK_CULL_MODE_NONE;
|
||||
case dawn::CullMode::Front:
|
||||
return VK_CULL_MODE_FRONT_BIT;
|
||||
case dawn::CullMode::Back:
|
||||
return VK_CULL_MODE_BACK_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
VkBlendFactor VulkanBlendFactor(dawn::BlendFactor factor) {
|
||||
switch (factor) {
|
||||
case dawn::BlendFactor::Zero:
|
||||
@@ -355,8 +375,8 @@ namespace dawn_native { namespace vulkan {
|
||||
rasterization.depthClampEnable = VK_FALSE;
|
||||
rasterization.rasterizerDiscardEnable = VK_FALSE;
|
||||
rasterization.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
rasterization.cullMode = VK_CULL_MODE_NONE;
|
||||
rasterization.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
rasterization.cullMode = VulkanCullMode(GetCullMode());
|
||||
rasterization.frontFace = VulkanFrontFace(GetFrontFace());
|
||||
rasterization.depthBiasEnable = VK_FALSE;
|
||||
rasterization.depthBiasConstantFactor = 0.0f;
|
||||
rasterization.depthBiasClamp = 0.0f;
|
||||
|
||||
Reference in New Issue
Block a user