code refactoring: const color values

BUG=
Change-Id: I6f394fd8ae45d30e1e3846b9a7a03f51efb8a475
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13660
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:
Yunchao He 2019-11-18 03:27:44 +00:00 committed by Commit Bot service account
parent a930e599e1
commit e0eeef4b34
15 changed files with 58 additions and 67 deletions

View File

@ -77,6 +77,13 @@ struct RGBA8 {
};
std::ostream& operator<<(std::ostream& stream, const RGBA8& color);
constexpr RGBA8 kZero(0, 0, 0, 0);
constexpr RGBA8 kBlack(0, 0, 0, 255);
constexpr RGBA8 kRed(255, 0, 0, 255);
constexpr RGBA8 kGreen(0, 255, 0, 255);
constexpr RGBA8 kBlue(0, 0, 255, 255);
constexpr RGBA8 kWhite(255, 255, 255, 255);
struct DawnTestParam {
explicit DawnTestParam(dawn_native::BackendType backendType) : backendType(backendType) {
}

View File

@ -95,8 +95,8 @@ TEST_P(ClipSpaceTest, ClipSpace) {
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 0, 0, 255), colorTexture, kSize - 1, kSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), colorTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(kRed, colorTexture, kSize - 1, kSize - 1);
EXPECT_PIXEL_RGBA8_EQ(kGreen, colorTexture, 0, 0);
}
DAWN_INSTANTIATE_TEST(ClipSpaceTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

@ -356,9 +356,6 @@ class CompressedTextureBCFormatTest : public DawnTest {
// RGBA8 formats.
static std::vector<RGBA8> GetExpectedData(wgpu::TextureFormat bcFormat,
const wgpu::Extent3D& testRegion) {
constexpr RGBA8 kRed(255, 0, 0, 255);
constexpr RGBA8 kGreen(0, 255, 0, 255);
constexpr RGBA8 kBlack(0, 0, 0, 255);
constexpr RGBA8 kDarkRed(198, 0, 0, 255);
constexpr RGBA8 kDarkGreen(0, 207, 0, 255);
constexpr RGBA8 kDarkRedSRGB(144, 0, 0, 255);

View File

@ -90,9 +90,9 @@ class CullingTest : public DawnTest {
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
constexpr RGBA8 kTopLeftColor = RGBA8(0, 0, 0, 255);
constexpr RGBA8 kTopLeftColor = kBlack;
constexpr RGBA8 kBottomRightColor = RGBA8(3, 3, 0, 255);
constexpr RGBA8 kBackgroundColor = RGBA8(0, 0, 255, 255);
constexpr RGBA8 kBackgroundColor = kBlue;
RGBA8 kCCWTriangleTopLeftColor = isCCWTriangleCulled ? kBackgroundColor : kTopLeftColor;
EXPECT_PIXEL_RGBA8_EQ(kCCWTriangleTopLeftColor, colorTexture, 0, 0);

View File

@ -87,7 +87,7 @@ TEST_P(IndexFormatTest, Uint32) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 100, 300);
}
// Test that the Uint16 index format is correctly interpreted
@ -114,7 +114,7 @@ TEST_P(IndexFormatTest, Uint16) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 100, 300);
}
// Test for primitive restart use vertices like in the drawing and draw the following
@ -164,9 +164,9 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, 210, 190); // C
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, 210, 190); // C
}
// Test use of primitive restart with an Uint16 index format
@ -206,9 +206,9 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, 210, 190); // C
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, 210, 190); // C
}
// Test that the index format used is the format of the last set pipeline. This is to
@ -242,7 +242,7 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 100, 300);
}
// Test that setting the index buffer before the pipeline works, this is important

View File

@ -210,7 +210,7 @@ class PrimitiveTopologyTest : public DawnTest {
for (auto& locationSpec : locationSpecs) {
for (size_t i = 0; i < locationSpec.count; ++i) {
// If this pixel is included, check that it is green. Otherwise, check that it is black
RGBA8 color = locationSpec.include ? RGBA8(0, 255, 0, 255) : RGBA8(0, 0, 0, 0);
RGBA8 color = locationSpec.include ? kGreen : kZero;
EXPECT_PIXEL_RGBA8_EQ(color, renderPass.color, locationSpec.locations[i].x, locationSpec.locations[i].y)
<< "Expected (" << locationSpec.locations[i].x << ", " << locationSpec.locations[i].y << ") to be " << color;
}

View File

@ -19,7 +19,7 @@
#include "utils/WGPUHelpers.h"
constexpr uint32_t kRTSize = 4;
constexpr RGBA8 kColors[2] = {RGBA8(0, 255, 0, 255), RGBA8(0, 0, 255, 255)};
constexpr RGBA8 kColors[2] = {kGreen, kBlue};
// RenderBundleTest tests simple usage of RenderBundles to draw. The implementaiton
// of RenderBundle is shared significantly with render pass execution which is

View File

@ -71,14 +71,11 @@ class RenderPassLoadOpTests : public DawnTest {
renderTargetView = renderTarget.CreateView();
RGBA8 zero(0, 0, 0, 0);
std::fill(expectZero.begin(), expectZero.end(), zero);
std::fill(expectZero.begin(), expectZero.end(), kZero);
RGBA8 green(0, 255, 0, 255);
std::fill(expectGreen.begin(), expectGreen.end(), green);
std::fill(expectGreen.begin(), expectGreen.end(), kGreen);
RGBA8 blue(0, 0, 255, 255);
std::fill(expectBlue.begin(), expectBlue.end(), blue);
std::fill(expectBlue.begin(), expectBlue.end(), kBlue);
// draws a blue quad on the right half of the screen
const char* vsSource = R"(

View File

@ -76,10 +76,6 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
// This test is consistently failing on OpenGL and flaky on Metal.
return;
}
constexpr RGBA8 kRed(255, 0, 0, 255);
constexpr RGBA8 kGreen(0, 255, 0, 255);
constexpr RGBA8 kBlue(0, 0, 255, 255);
wgpu::Texture renderTarget1 = CreateDefault2DTexture();
wgpu::Texture renderTarget2 = CreateDefault2DTexture();
@ -165,8 +161,6 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
constexpr RGBA8 kRed(255, 0, 0, 255);
constexpr RGBA8 kBlue(0, 0, 255, 255);
EXPECT_PIXEL_RGBA8_EQ(kBlue, renderTarget, 2, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(kRed, renderTarget, kRTSize - 1, 1);
}

View File

@ -108,10 +108,8 @@ protected:
// Create a 2x2 checkerboard texture, with black in the top left and bottom right corners.
const uint32_t rowPixels = kTextureRowPitchAlignment / sizeof(RGBA8);
RGBA8 data[rowPixels * 2];
RGBA8 black(0, 0, 0, 255);
RGBA8 white(255, 255, 255, 255);
data[0] = data[rowPixels + 1] = black;
data[1] = data[rowPixels] = white;
data[0] = data[rowPixels + 1] = kBlack;
data[1] = data[rowPixels] = kWhite;
wgpu::Buffer stagingBuffer =
utils::CreateBufferFromData(device, data, sizeof(data), wgpu::BufferUsage::CopySrc);
@ -164,12 +162,10 @@ protected:
RGBA8 expectedU3(u.mExpected3, u.mExpected3, u.mExpected3, 255);
RGBA8 expectedV2(v.mExpected2, v.mExpected2, v.mExpected2, 255);
RGBA8 expectedV3(v.mExpected3, v.mExpected3, v.mExpected3, 255);
RGBA8 black(0, 0, 0, 255);
RGBA8 white(255, 255, 255, 255);
EXPECT_PIXEL_RGBA8_EQ(black, mRenderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(white, mRenderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(white, mRenderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(black, mRenderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(kBlack, mRenderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(kWhite, mRenderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(kWhite, mRenderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(kBlack, mRenderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(expectedU2, mRenderPass.color, 2, 0);
EXPECT_PIXEL_RGBA8_EQ(expectedU3, mRenderPass.color, 3, 0);
EXPECT_PIXEL_RGBA8_EQ(expectedV2, mRenderPass.color, 0, 2);

View File

@ -64,10 +64,10 @@ TEST_P(ScissorTest, DefaultsToWholeRenderTarget) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 99, 99);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 99, 99);
}
// Test setting the scissor to something larger than the attachments.
@ -87,10 +87,10 @@ TEST_P(ScissorTest, LargerThanAttachment) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 99, 99);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 99, 99);
}
// Test setting a partial scissor (not empty, not full attachment)
@ -116,11 +116,11 @@ TEST_P(ScissorTest, PartialRect) {
queue.Submit(1, &commands);
// Test the two opposite corners of the scissor box. With one pixel inside and on outside
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kX - 1, kY - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, kX, kY);
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, kX - 1, kY - 1);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, kX, kY);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kX + kW, kY + kH);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, kX + kW - 1, kY + kH - 1);
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, kX + kW, kY + kH);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, kX + kW - 1, kY + kH - 1);
}
// Test that the scissor setting doesn't get inherited between renderpasses
@ -146,10 +146,10 @@ TEST_P(ScissorTest, NoInheritanceBetweenRenderPass) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 99, 99);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 99, 99);
}
DAWN_INSTANTIATE_TEST(ScissorTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

@ -390,7 +390,7 @@ class VertexFormatTest : public DawnTest {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 0);
}
};

View File

@ -221,9 +221,9 @@ class VertexStateTest : public DawnTest {
unsigned int x = kRTCellOffset + kRTCellSize * triangle;
unsigned int y = kRTCellOffset + kRTCellSize * instance;
if (triangle < triangles && instance < instances) {
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, x, y);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, x, y);
} else {
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, x, y);
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, x, y);
}
}
}
@ -572,7 +572,7 @@ TEST_P(OptionalVertexStateTest, Basic) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 1, 1);
}
DAWN_INSTANTIATE_TEST(OptionalVertexStateTest,

View File

@ -58,10 +58,10 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, 1, 1);
}
DAWN_INSTANTIATE_TEST(ViewportOrientationTests, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

@ -156,9 +156,9 @@ class ViewportTest : public DawnTest {
queue.Submit(1, &commandBuffer);
constexpr RGBA8 kColor[ColorTypeCount] = {
RGBA8(255, 0, 0, 255), // top-left triangle is red
RGBA8(0, 255, 0, 255), // bottom-right triangle is green
RGBA8(0, 0, 255, 255), // background is blue
kRed, // top-left triangle is red
kGreen, // bottom-right triangle is green
kBlue, // background is blue
};
EXPECT_PIXEL_RGBA8_EQ(kColor[info.topLeftPoint], colorTexture1, 0, 0);