code refactoring: prefix const color values with RGBA8

BUG=
Change-Id: I820180adc19b1d1c226ca92084c64e441173c27b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13760
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
Yunchao He 2019-11-19 17:57:30 +00:00 committed by Commit Bot service account
parent 083a1ce2bf
commit 0c02f54edf
17 changed files with 79 additions and 70 deletions

View File

@ -80,6 +80,14 @@ namespace {
} // namespace
const RGBA8 RGBA8::kZero = RGBA8(0, 0, 0, 0);
const RGBA8 RGBA8::kBlack = RGBA8(0, 0, 0, 255);
const RGBA8 RGBA8::kRed = RGBA8(255, 0, 0, 255);
const RGBA8 RGBA8::kGreen = RGBA8(0, 255, 0, 255);
const RGBA8 RGBA8::kBlue = RGBA8(0, 0, 255, 255);
const RGBA8 RGBA8::kYellow = RGBA8(255, 255, 0, 255);
const RGBA8 RGBA8::kWhite = RGBA8(255, 255, 255, 255);
const DawnTestParam D3D12Backend(dawn_native::BackendType::D3D12);
const DawnTestParam MetalBackend(dawn_native::BackendType::Metal);
const DawnTestParam OpenGLBackend(dawn_native::BackendType::OpenGL);

View File

@ -74,16 +74,17 @@ struct RGBA8 {
bool operator!=(const RGBA8& other) const;
uint8_t r, g, b, a;
static const RGBA8 kZero;
static const RGBA8 kBlack;
static const RGBA8 kRed;
static const RGBA8 kGreen;
static const RGBA8 kBlue;
static const RGBA8 kYellow;
static const RGBA8 kWhite;
};
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(kRed, colorTexture, kSize - 1, kSize - 1);
EXPECT_PIXEL_RGBA8_EQ(kGreen, colorTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, colorTexture, kSize - 1, kSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, colorTexture, 0, 0);
}
DAWN_INSTANTIATE_TEST(ClipSpaceTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

@ -389,13 +389,13 @@ class CompressedTextureBCFormatTest : public DawnTest {
case wgpu::TextureFormat::BC4RSnorm:
case wgpu::TextureFormat::BC4RUnorm:
return FillExpectedData(testRegion, kRed, kBlack);
return FillExpectedData(testRegion, RGBA8::kRed, RGBA8::kBlack);
case wgpu::TextureFormat::BC5RGSnorm:
case wgpu::TextureFormat::BC5RGUnorm:
case wgpu::TextureFormat::BC6HRGBSfloat:
case wgpu::TextureFormat::BC6HRGBUfloat:
return FillExpectedData(testRegion, kRed, kGreen);
return FillExpectedData(testRegion, RGBA8::kRed, RGBA8::kGreen);
default:
UNREACHABLE();

View File

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

View File

@ -132,7 +132,7 @@ TEST_P(StorageToUniformSyncTests, ReadAfterWriteWithSameCommandBuffer) {
queue.Submit(1, &commands);
// Verify the rendering result.
EXPECT_PIXEL_RGBA8_EQ(kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
}
// Write into a storage buffer in compute pass in a command buffer. Then read that data in a render
@ -171,7 +171,7 @@ TEST_P(StorageToUniformSyncTests, ReadAfterWriteWithDifferentCommandBuffers) {
queue.Submit(2, cb);
// Verify the rendering result.
EXPECT_PIXEL_RGBA8_EQ(kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
}
// Write into a storage buffer in compute pass in a command buffer. Then read that data in a render
@ -211,7 +211,7 @@ TEST_P(StorageToUniformSyncTests, ReadAfterWriteWithDifferentQueueSubmits) {
queue.Submit(1, &cb[1]);
// Verify the rendering result.
EXPECT_PIXEL_RGBA8_EQ(kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
}
DAWN_INSTANTIATE_TEST(StorageToUniformSyncTests,

View File

@ -87,7 +87,7 @@ TEST_P(IndexFormatTest, Uint32) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(kGreen, renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(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
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(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
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(kGreen, renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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 ? kGreen : kZero;
RGBA8 color = locationSpec.include ? RGBA8::kGreen : RGBA8::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] = {kGreen, kBlue};
const RGBA8 kColors[2] = {RGBA8::kGreen, RGBA8::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,11 +71,11 @@ class RenderPassLoadOpTests : public DawnTest {
renderTargetView = renderTarget.CreateView();
std::fill(expectZero.begin(), expectZero.end(), kZero);
std::fill(expectZero.begin(), expectZero.end(), RGBA8::kZero);
std::fill(expectGreen.begin(), expectGreen.end(), kGreen);
std::fill(expectGreen.begin(), expectGreen.end(), RGBA8::kGreen);
std::fill(expectBlue.begin(), expectBlue.end(), kBlue);
std::fill(expectBlue.begin(), expectBlue.end(), RGBA8::kBlue);
// draws a blue quad on the right half of the screen
const char* vsSource = R"(

View File

@ -108,11 +108,11 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(kBlue, renderTarget1, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(kRed, renderTarget1, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlue, renderTarget1, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderTarget1, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(kBlue, renderTarget2, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderTarget2, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlue, renderTarget2, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderTarget2, kRTSize - 1, 1);
}
// Verify that the content in the color attachment will not be changed if there is no corresponding
@ -161,8 +161,8 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(kBlue, renderTarget, 2, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(kRed, renderTarget, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlue, renderTarget, 2, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderTarget, kRTSize - 1, 1);
}
DAWN_INSTANTIATE_TEST(RenderPassTest,

View File

@ -108,8 +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];
data[0] = data[rowPixels + 1] = kBlack;
data[1] = data[rowPixels] = kWhite;
data[0] = data[rowPixels + 1] = RGBA8::kBlack;
data[1] = data[rowPixels] = RGBA8::kWhite;
wgpu::Buffer stagingBuffer =
utils::CreateBufferFromData(device, data, sizeof(data), wgpu::BufferUsage::CopySrc);
@ -162,10 +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);
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(RGBA8::kBlack, mRenderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kWhite, mRenderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kWhite, mRenderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(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);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(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);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(kZero, renderPass.color, kX - 1, kY - 1);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, kX, kY);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, kX - 1, kY - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, kX, kY);
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, kX + kW, kY + kH);
EXPECT_PIXEL_RGBA8_EQ(kGreen, renderPass.color, kX + kW - 1, kY + kH - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, kX + kW, kY + kH);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(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);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(kGreen, renderPass.color, x, y);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, x, y);
} else {
EXPECT_PIXEL_RGBA8_EQ(kZero, renderPass.color, x, y);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(kGreen, renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::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(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);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 1, 1);
}
DAWN_INSTANTIATE_TEST(ViewportOrientationTests, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

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