From 413dcf8a40df9db9cf51ec828c1e0331251ef0d7 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Thu, 15 Apr 2021 19:33:58 +0000 Subject: [PATCH] Rename setBlendColor->setBlendConstant Matches most recent spec changes. setBlendColor has been marked as deprecated. Bug: chromium:1199057 Change-Id: I4584ce789bd7d14401244509d5ada62a46236a5d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/47901 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Brandon Jones --- dawn.json | 6 ++++++ src/dawn_native/Commands.cpp | 10 +++++----- src/dawn_native/Commands.h | 4 ++-- src/dawn_native/RenderPassEncoder.cpp | 11 +++++++++-- src/dawn_native/RenderPassEncoder.h | 3 ++- src/dawn_native/d3d12/CommandBufferD3D12.cpp | 4 ++-- src/dawn_native/metal/CommandBufferMTL.mm | 4 ++-- src/dawn_native/opengl/CommandBufferGL.cpp | 4 ++-- src/dawn_native/vulkan/CommandBufferVk.cpp | 4 ++-- src/tests/end2end/ColorStateTests.cpp | 10 +++++----- src/tests/end2end/DeprecatedAPITests.cpp | 12 ++++++++++++ .../DynamicStateCommandValidationTests.cpp | 14 +++++++------- 12 files changed, 56 insertions(+), 30 deletions(-) diff --git a/dawn.json b/dawn.json index cf5356f78d..5b7d2c94f8 100644 --- a/dawn.json +++ b/dawn.json @@ -1546,6 +1546,12 @@ {"name": "color", "type": "color", "annotation": "const*"} ] }, + { + "name": "set blend constant", + "args": [ + {"name": "color", "type": "color", "annotation": "const*"} + ] + }, { "name": "set viewport", "args": [ diff --git a/src/dawn_native/Commands.cpp b/src/dawn_native/Commands.cpp index eba44c6989..e3f852e2a3 100644 --- a/src/dawn_native/Commands.cpp +++ b/src/dawn_native/Commands.cpp @@ -168,9 +168,9 @@ namespace dawn_native { cmd->~SetScissorRectCmd(); break; } - case Command::SetBlendColor: { - SetBlendColorCmd* cmd = commands->NextCommand(); - cmd->~SetBlendColorCmd(); + case Command::SetBlendConstant: { + SetBlendConstantCmd* cmd = commands->NextCommand(); + cmd->~SetBlendConstantCmd(); break; } case Command::SetBindGroup: { @@ -315,8 +315,8 @@ namespace dawn_native { commands->NextCommand(); break; - case Command::SetBlendColor: - commands->NextCommand(); + case Command::SetBlendConstant: + commands->NextCommand(); break; case Command::SetBindGroup: { diff --git a/src/dawn_native/Commands.h b/src/dawn_native/Commands.h index aa93c835c7..3c958fa03a 100644 --- a/src/dawn_native/Commands.h +++ b/src/dawn_native/Commands.h @@ -59,7 +59,7 @@ namespace dawn_native { SetStencilReference, SetViewport, SetScissorRect, - SetBlendColor, + SetBlendConstant, SetBindGroup, SetIndexBuffer, SetVertexBuffer, @@ -231,7 +231,7 @@ namespace dawn_native { uint32_t x, y, width, height; }; - struct SetBlendColorCmd { + struct SetBlendConstantCmd { Color color; }; diff --git a/src/dawn_native/RenderPassEncoder.cpp b/src/dawn_native/RenderPassEncoder.cpp index 4c48bb43e8..1ab90237d2 100644 --- a/src/dawn_native/RenderPassEncoder.cpp +++ b/src/dawn_native/RenderPassEncoder.cpp @@ -115,15 +115,22 @@ namespace dawn_native { }); } - void RenderPassEncoder::APISetBlendColor(const Color* color) { + void RenderPassEncoder::APISetBlendConstant(const Color* color) { mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { - SetBlendColorCmd* cmd = allocator->Allocate(Command::SetBlendColor); + SetBlendConstantCmd* cmd = + allocator->Allocate(Command::SetBlendConstant); cmd->color = *color; return {}; }); } + void RenderPassEncoder::APISetBlendColor(const Color* color) { + GetDevice()->EmitDeprecationWarning( + "SetBlendColor has been deprecated in favor of SetBlendConstant."); + APISetBlendConstant(color); + } + void RenderPassEncoder::APISetViewport(float x, float y, float width, diff --git a/src/dawn_native/RenderPassEncoder.h b/src/dawn_native/RenderPassEncoder.h index a8bf460548..dc22bf1e6e 100644 --- a/src/dawn_native/RenderPassEncoder.h +++ b/src/dawn_native/RenderPassEncoder.h @@ -40,7 +40,8 @@ namespace dawn_native { void APIEndPass(); void APISetStencilReference(uint32_t reference); - void APISetBlendColor(const Color* color); + void APISetBlendConstant(const Color* color); + void APISetBlendColor(const Color* color); // Deprecated void APISetViewport(float x, float y, float width, diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index 7fb5e22168..08b181cc86 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -1450,8 +1450,8 @@ namespace dawn_native { namespace d3d12 { break; } - case Command::SetBlendColor: { - SetBlendColorCmd* cmd = mCommands.NextCommand(); + case Command::SetBlendConstant: { + SetBlendConstantCmd* cmd = mCommands.NextCommand(); const std::array color = ConvertToFloatColor(cmd->color); commandList->OMSetBlendFactor(color.data()); break; diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index 71f0d0f128..f93737d748 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -1281,8 +1281,8 @@ namespace dawn_native { namespace metal { break; } - case Command::SetBlendColor: { - SetBlendColorCmd* cmd = mCommands.NextCommand(); + case Command::SetBlendConstant: { + SetBlendConstantCmd* cmd = mCommands.NextCommand(); [encoder setBlendColorRed:cmd->color.r green:cmd->color.g blue:cmd->color.b diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index 478bdaff02..afb15a2ecb 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -1218,8 +1218,8 @@ namespace dawn_native { namespace opengl { break; } - case Command::SetBlendColor: { - SetBlendColorCmd* cmd = mCommands.NextCommand(); + case Command::SetBlendConstant: { + SetBlendConstantCmd* cmd = mCommands.NextCommand(); const std::array blendColor = ConvertToFloatColor(cmd->color); gl.BlendColor(blendColor[0], blendColor[1], blendColor[2], blendColor[3]); break; diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp index 47fac441a5..16d81005b0 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.cpp +++ b/src/dawn_native/vulkan/CommandBufferVk.cpp @@ -1209,8 +1209,8 @@ namespace dawn_native { namespace vulkan { return {}; } - case Command::SetBlendColor: { - SetBlendColorCmd* cmd = mCommands.NextCommand(); + case Command::SetBlendConstant: { + SetBlendConstantCmd* cmd = mCommands.NextCommand(); const std::array blendConstants = ConvertToFloatColor(cmd->color); device->fn.CmdSetBlendConstants(commands, blendConstants.data()); break; diff --git a/src/tests/end2end/ColorStateTests.cpp b/src/tests/end2end/ColorStateTests.cpp index 1e914320f8..5a4266c18a 100644 --- a/src/tests/end2end/ColorStateTests.cpp +++ b/src/tests/end2end/ColorStateTests.cpp @@ -106,8 +106,8 @@ class ColorStateTest : public DawnTest { // Test that after drawing a triangle with the base color, and then the given triangle spec, the // color is as expected void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) { - wgpu::Color blendColor{triangle.blendFactor[0], triangle.blendFactor[1], - triangle.blendFactor[2], triangle.blendFactor[3]}; + wgpu::Color blendConstant{triangle.blendFactor[0], triangle.blendFactor[1], + triangle.blendFactor[2], triangle.blendFactor[3]}; wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); { @@ -120,7 +120,7 @@ class ColorStateTest : public DawnTest { // Then use the test pipeline to draw the test triangle with blending pass.SetPipeline(testPipeline); pass.SetBindGroup(0, MakeBindGroupForColors(std::array({{triangle.color}}))); - pass.SetBlendColor(&blendColor); + pass.SetBlendConstant(&blendConstant); pass.Draw(3); pass.EndPass(); } @@ -975,7 +975,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) { MakeBindGroupForColors(std::array({{RGBA8(0, 0, 0, 0)}}))); pass.Draw(3); pass.SetPipeline(testPipeline); - pass.SetBlendColor(&kWhite); + pass.SetBlendConstant(&kWhite); pass.SetBindGroup( 0, MakeBindGroupForColors(std::array({{RGBA8(255, 255, 255, 255)}}))); pass.Draw(3); @@ -999,7 +999,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) { MakeBindGroupForColors(std::array({{RGBA8(0, 0, 0, 0)}}))); pass.Draw(3); pass.SetPipeline(testPipeline); - pass.SetBlendColor(&kWhite); + pass.SetBlendConstant(&kWhite); pass.SetBindGroup( 0, MakeBindGroupForColors(std::array({{RGBA8(255, 255, 255, 255)}}))); pass.Draw(3); diff --git a/src/tests/end2end/DeprecatedAPITests.cpp b/src/tests/end2end/DeprecatedAPITests.cpp index aaadf5e295..40d8d381bc 100644 --- a/src/tests/end2end/DeprecatedAPITests.cpp +++ b/src/tests/end2end/DeprecatedAPITests.cpp @@ -51,6 +51,18 @@ TEST_P(DeprecationTests, SetIndexBufferWithFormat) { pass.EndPass(); } +// Test that SetBlendColor is deprecated. +TEST_P(DeprecationTests, SetSetBlendColor) { + wgpu::Color blendColor{1.0, 0.0, 0.0, 1.0}; + + utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 1, 1); + + wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); + wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); + EXPECT_DEPRECATION_WARNING(pass.SetBlendColor(&blendColor)); + pass.EndPass(); +} + // Test that BindGroupLayoutEntry cannot have a type if buffer, sampler, texture, or storageTexture // are defined. TEST_P(DeprecationTests, BindGroupLayoutEntryTypeConflict) { diff --git a/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp b/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp index d66a5290b2..458d277e82 100644 --- a/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp +++ b/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp @@ -203,31 +203,31 @@ TEST_F(SetScissorTest, ScissorLargerThanFramebuffer) { TestScissorCall(false, 0, std::numeric_limits::max(), kWidth, kHeight); } -class SetBlendColorTest : public ValidationTest {}; +class SetBlendConstantTest : public ValidationTest {}; -// Test to check basic use of SetBlendColor -TEST_F(SetBlendColorTest, Success) { +// Test to check basic use of SetBlendConstantTest +TEST_F(SetBlendConstantTest, Success) { DummyRenderPass renderPass(device); wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); { wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); constexpr wgpu::Color kTransparentBlack{0.0f, 0.0f, 0.0f, 0.0f}; - pass.SetBlendColor(&kTransparentBlack); + pass.SetBlendConstant(&kTransparentBlack); pass.EndPass(); } encoder.Finish(); } -// Test that SetBlendColor allows any value, large, small or negative -TEST_F(SetBlendColorTest, AnyValueAllowed) { +// Test that SetBlendConstant allows any value, large, small or negative +TEST_F(SetBlendConstantTest, AnyValueAllowed) { DummyRenderPass renderPass(device); wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); { wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); constexpr wgpu::Color kAnyColorValue{-1.0f, 42.0f, -0.0f, 0.0f}; - pass.SetBlendColor(&kAnyColorValue); + pass.SetBlendConstant(&kAnyColorValue); pass.EndPass(); } encoder.Finish();