mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-05 06:03:34 +00:00
Culling and FrontFace: verify the framebuffer coordinate
This patch is to verify the framebuffer coordinate in Dawn (and WebGPU). It shows that gl_FragCoord(0, 0) is at the top left. BUG=dawn:43 TEST=dawn_end2end_tests Change-Id: Ifd16488169c986d0c2c85eb92283c69e70ad33ae Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8780 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
parent
002395300f
commit
110700304f
@ -39,11 +39,14 @@ class CullingTest : public DawnTest {
|
||||
pipelineDescriptor.cVertexStage.module =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, vs);
|
||||
|
||||
// gl_FragCoord of pixel(x, y) in framebuffer coordinate is (x + 0.5, y + 0.5). And we use
|
||||
// RGBA8 format for the back buffer. So (gl_FragCoord.xy - vec2(0.5)) / 255 in shader code
|
||||
// will make the pixel's R and G channels exactly equal to the pixel's x and y coordinates.
|
||||
const char* fs =
|
||||
"#version 450\n"
|
||||
"layout(location = 0) out vec4 fragColor;"
|
||||
"void main() {\n"
|
||||
" fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
|
||||
" fragColor = vec4((gl_FragCoord.xy - vec2(0.5)) / 255, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
pipelineDescriptor.cFragmentStage.module =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fs);
|
||||
@ -75,7 +78,7 @@ class CullingTest : public DawnTest {
|
||||
dawn::Texture colorTexture = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm);
|
||||
|
||||
utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateDefaultView()});
|
||||
renderPassDescriptor.cColorAttachmentsInfoPtr[0]->clearColor = {0.0, 1.0, 0.0, 1.0};
|
||||
renderPassDescriptor.cColorAttachmentsInfoPtr[0]->clearColor = {0.0, 0.0, 1.0, 1.0};
|
||||
renderPassDescriptor.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Clear;
|
||||
|
||||
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||
@ -87,14 +90,16 @@ class CullingTest : public DawnTest {
|
||||
dawn::Queue queue = device.CreateQueue();
|
||||
queue.Submit(1, &commandBuffer);
|
||||
|
||||
constexpr RGBA8 kDrawingColor = RGBA8(255, 0, 0, 255);
|
||||
constexpr RGBA8 kBackgroundColor = RGBA8(0, 255, 0, 255);
|
||||
constexpr RGBA8 kTopLeftColor = RGBA8(0, 0, 0, 255);
|
||||
constexpr RGBA8 kBottomRightColor = RGBA8(3, 3, 0, 255);
|
||||
constexpr RGBA8 kBackgroundColor = RGBA8(0, 0, 255, 255);
|
||||
|
||||
RGBA8 kCCWTriangleColor = isCCWTriangleCulled ? kBackgroundColor : kDrawingColor;
|
||||
EXPECT_PIXEL_RGBA8_EQ(kCCWTriangleColor, colorTexture, 0, 0);
|
||||
RGBA8 kCCWTriangleTopLeftColor = isCCWTriangleCulled ? kBackgroundColor : kTopLeftColor;
|
||||
EXPECT_PIXEL_RGBA8_EQ(kCCWTriangleTopLeftColor, colorTexture, 0, 0);
|
||||
|
||||
RGBA8 kCWTriangleColor = isCWTriangleCulled ? kBackgroundColor : kDrawingColor;
|
||||
EXPECT_PIXEL_RGBA8_EQ(kCWTriangleColor, colorTexture, kSize - 1, kSize - 1);
|
||||
RGBA8 kCWTriangleBottomRightColor =
|
||||
isCWTriangleCulled ? kBackgroundColor : kBottomRightColor;
|
||||
EXPECT_PIXEL_RGBA8_EQ(kCWTriangleBottomRightColor, colorTexture, kSize - 1, kSize - 1);
|
||||
}
|
||||
|
||||
static constexpr uint32_t kSize = 4;
|
||||
|
Loading…
x
Reference in New Issue
Block a user