Replace BlendState builder via BlendState descriptor.

This change also removes BlendState object.

Bug=dawn:32

Change-Id: I8bf4ff7531e7504efb17b6bae3ca01f1f2b4131e
Reviewed-on: https://dawn-review.googlesource.com/c/3042
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
Yunchao He
2018-12-27 06:32:31 +00:00
committed by Commit Bot service account
parent cb71ba7b3a
commit 92700bfccd
43 changed files with 489 additions and 1043 deletions

View File

@@ -53,7 +53,7 @@ class BlendStateTest : public DawnTest {
};
// Set up basePipeline and testPipeline. testPipeline has the given blend state on the first attachment. basePipeline has no blending
void SetupSingleSourcePipelines(const dawn::BlendState &blendState) {
void SetupSingleSourcePipelines(const dawn::BlendStateDescriptor& blendStateDescriptor) {
dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
@@ -82,7 +82,7 @@ class BlendStateTest : public DawnTest {
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
testDescriptor.cBlendStates[0] = blendState;
testDescriptor.cBlendStates[0] = blendStateDescriptor;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
}
@@ -135,13 +135,14 @@ class BlendStateTest : public DawnTest {
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
dawn::BlendStateDescriptor descriptor;
descriptor.blendEnabled = true;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.nextInChain = nullptr;
descriptor.colorWriteMask = dawn::ColorWriteMask::All;
SetupSingleSourcePipelines(blendState);
SetupSingleSourcePipelines(descriptor);
for (const auto& test : tests) {
DoSingleSourceTest(base, { test.first }, test.second);
@@ -160,13 +161,14 @@ class BlendStateTest : public DawnTest {
alphaBlend.srcFactor = alphaSrcFactor;
alphaBlend.dstFactor = alphaDstFactor;
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&colorBlend)
.SetAlphaBlend(&alphaBlend)
.GetResult();
dawn::BlendStateDescriptor descriptor;
descriptor.blendEnabled = true;
descriptor.colorBlend = colorBlend;
descriptor.alphaBlend = alphaBlend;
descriptor.nextInChain = nullptr;
descriptor.colorWriteMask = dawn::ColorWriteMask::All;
SetupSingleSourcePipelines(blendState);
SetupSingleSourcePipelines(descriptor);
for (const auto& test : tests) {
DoSingleSourceTest(base, test.first, test.second);
@@ -276,8 +278,18 @@ namespace {
// Test compilation and usage of the fixture
TEST_P(BlendStateTest, Basic) {
dawn::BlendState blendState = device.CreateBlendStateBuilder().GetResult();
SetupSingleSourcePipelines(blendState);
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero;
dawn::BlendStateDescriptor descriptor;
descriptor.nextInChain = nullptr;
descriptor.blendEnabled = false;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.colorWriteMask = dawn::ColorWriteMask::All;
SetupSingleSourcePipelines(descriptor);
DoSingleSourceTest(RGBA8(0, 0, 0, 0), { RGBA8(255, 0, 0, 0) }, RGBA8(255, 0, 0, 0));
}
@@ -627,15 +639,15 @@ TEST_P(BlendStateTest, ColorWriteMask) {
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendStateDescriptor descriptor;
descriptor.nextInChain = nullptr;
descriptor.blendEnabled = true;
descriptor.colorBlend = blend;
descriptor.alphaBlend = blend;
{
// Test single channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Red)
.GetResult();
SetupSingleSourcePipelines(blendState);
descriptor.colorWriteMask = dawn::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
for (auto& color : kColors) {
@@ -646,13 +658,8 @@ TEST_P(BlendStateTest, ColorWriteMask) {
{
// Test multi channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Green | dawn::ColorWriteMask::Alpha)
.GetResult();
SetupSingleSourcePipelines(blendState);
descriptor.colorWriteMask = dawn::ColorWriteMask::Green | dawn::ColorWriteMask::Alpha;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
for (auto& color : kColors) {
@@ -663,13 +670,8 @@ TEST_P(BlendStateTest, ColorWriteMask) {
{
// Test no channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::None)
.GetResult();
SetupSingleSourcePipelines(blendState);
descriptor.colorWriteMask = dawn::ColorWriteMask::None;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
for (auto& color : kColors) {
@@ -681,11 +683,18 @@ TEST_P(BlendStateTest, ColorWriteMask) {
// Check that the color write mask works when blending is disabled
TEST_P(BlendStateTest, ColorWriteMaskBlendingDisabled) {
{
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(false)
.SetColorWriteMask(dawn::ColorWriteMask::Red)
.GetResult();
SetupSingleSourcePipelines(blendState);
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero;
dawn::BlendStateDescriptor descriptor;
descriptor.nextInChain = nullptr;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.blendEnabled = false;
descriptor.colorWriteMask = dawn::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
RGBA8 expected(32, 0, 0, 0);
@@ -763,40 +772,6 @@ TEST_P(BlendStateTest, IndependentBlendState) {
}
)");
dawn::BlendDescriptor blend1;
blend1.operation = dawn::BlendOperation::Add;
blend1.srcFactor = dawn::BlendFactor::One;
blend1.dstFactor = dawn::BlendFactor::One;
dawn::BlendDescriptor blend2;
blend2.operation = dawn::BlendOperation::Subtract;
blend2.srcFactor = dawn::BlendFactor::One;
blend2.dstFactor = dawn::BlendFactor::One;
dawn::BlendDescriptor blend3;
blend3.operation = dawn::BlendOperation::Min;
blend3.srcFactor = dawn::BlendFactor::One;
blend3.dstFactor = dawn::BlendFactor::One;
std::array<dawn::BlendState, 4> blendStates = { {
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend1)
.SetAlphaBlend(&blend1)
.GetResult(),
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend2)
.SetAlphaBlend(&blend2)
.GetResult(),
device.CreateBlendStateBuilder().GetResult(),
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend3)
.SetAlphaBlend(&blend3)
.GetResult(),
} };
utils::ComboRenderPipelineDescriptor baseDescriptor(device);
baseDescriptor.layout = pipelineLayout;
baseDescriptor.cVertexStage.module = vsModule;
@@ -812,7 +787,34 @@ TEST_P(BlendStateTest, IndependentBlendState) {
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cAttachmentsState.numColorAttachments = 4;
testDescriptor.numBlendStates = 4;
testDescriptor.blendStates = blendStates.data();
// set blend states
dawn::BlendDescriptor blend1;
blend1.operation = dawn::BlendOperation::Add;
blend1.srcFactor = dawn::BlendFactor::One;
blend1.dstFactor = dawn::BlendFactor::One;
dawn::BlendDescriptor blend2;
blend2.operation = dawn::BlendOperation::Subtract;
blend2.srcFactor = dawn::BlendFactor::One;
blend2.dstFactor = dawn::BlendFactor::One;
dawn::BlendDescriptor blend3;
blend3.operation = dawn::BlendOperation::Min;
blend3.srcFactor = dawn::BlendFactor::One;
blend3.dstFactor = dawn::BlendFactor::One;
testDescriptor.cBlendStates[0].blendEnabled = true;
testDescriptor.cBlendStates[0].colorBlend = blend1;
testDescriptor.cBlendStates[0].alphaBlend = blend1;
testDescriptor.cBlendStates[1].blendEnabled = true;
testDescriptor.cBlendStates[1].colorBlend = blend2;
testDescriptor.cBlendStates[1].alphaBlend = blend2;
testDescriptor.cBlendStates[3].blendEnabled = true;
testDescriptor.cBlendStates[3].colorBlend = blend3;
testDescriptor.cBlendStates[3].alphaBlend = blend3;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
@@ -853,17 +855,6 @@ TEST_P(BlendStateTest, IndependentBlendState) {
// Test that the default blend color is correctly set at the beginning of every subpass
TEST_P(BlendStateTest, DefaultBlendColor) {
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::BlendColor;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
@@ -892,7 +883,14 @@ TEST_P(BlendStateTest, DefaultBlendColor) {
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
testDescriptor.cBlendStates[0] = blendState;
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::BlendColor;
blend.dstFactor = dawn::BlendFactor::One;
testDescriptor.cBlendStates[0].blendEnabled = true;
testDescriptor.cBlendStates[0].colorBlend = blend;
testDescriptor.cBlendStates[0].alphaBlend = blend;
testPipeline = device.CreateRenderPipeline(&testDescriptor);

View File

@@ -185,21 +185,19 @@ class PushConstantTest: public DawnTest {
})").c_str()
);
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = layout;
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList;
descriptor.cBlendStates[0] = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
descriptor.cBlendStates[0].blendEnabled = true;
descriptor.cBlendStates[0].alphaBlend = blend;
descriptor.cBlendStates[0].colorBlend = blend;
return device.CreateRenderPipeline(&descriptor);
}

View File

@@ -326,16 +326,17 @@ TEST_F(WireTests, CStringArgument) {
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _))
.WillOnce(Return(apiVsModule));
// Create the blend state
dawnBlendStateBuilder blendStateBuilder = dawnDeviceCreateBlendStateBuilder(device);
dawnBlendStateBuilder apiBlendStateBuilder = api.GetNewBlendStateBuilder();
EXPECT_CALL(api, DeviceCreateBlendStateBuilder(apiDevice))
.WillOnce(Return(apiBlendStateBuilder));
dawnBlendState blendState = dawnBlendStateBuilderGetResult(blendStateBuilder);
dawnBlendState apiBlendState = api.GetNewBlendState();
EXPECT_CALL(api, BlendStateBuilderGetResult(apiBlendStateBuilder))
.WillOnce(Return(apiBlendState));
// Create the blend state descriptor
dawnBlendDescriptor blendDescriptor;
blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD;
blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE;
blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE;
dawnBlendStateDescriptor blendStateDescriptor;
blendStateDescriptor.nextInChain = nullptr;
blendStateDescriptor.blendEnabled = false;
blendStateDescriptor.alphaBlend = blendDescriptor;
blendStateDescriptor.colorBlend = blendDescriptor;
blendStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
// Create the input state
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
@@ -397,7 +398,7 @@ TEST_F(WireTests, CStringArgument) {
pipelineDescriptor.attachmentsState = &attachmentsState;
pipelineDescriptor.numBlendStates = 1;
pipelineDescriptor.blendStates = &blendState;
pipelineDescriptor.blendStates = &blendStateDescriptor;
pipelineDescriptor.sampleCount = 1;
pipelineDescriptor.layout = layout;

View File

@@ -1,88 +0,0 @@
// Copyright 2017 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "tests/unittests/validation/ValidationTest.h"
class BlendStateValidationTest : public ValidationTest {
};
// Test cases where creation should succeed
TEST_F(BlendStateValidationTest, CreationSuccess) {
// Success for setting all properties
{
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendState state = AssertWillBeSuccess(device.CreateBlendStateBuilder())
.SetBlendEnabled(true)
.SetAlphaBlend(&blend)
.SetColorBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Red)
.GetResult();
}
// Success for empty builder
{
dawn::BlendState state = AssertWillBeSuccess(device.CreateBlendStateBuilder())
.GetResult();
}
}
// Test creation failure when specifying properties multiple times
TEST_F(BlendStateValidationTest, CreationDuplicates) {
// Test failure when specifying blend enabled multiple times
{
dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder())
.SetBlendEnabled(true)
.SetBlendEnabled(false)
.GetResult();
}
dawn::BlendDescriptor blend1;
blend1.operation = dawn::BlendOperation::Add;
blend1.srcFactor = dawn::BlendFactor::One;
blend1.dstFactor = dawn::BlendFactor::One;
dawn::BlendDescriptor blend2;
blend2.operation = dawn::BlendOperation::Add;
blend2.srcFactor = dawn::BlendFactor::Zero;
blend2.dstFactor = dawn::BlendFactor::Zero;
// Test failure when specifying alpha blend multiple times
{
dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder())
.SetAlphaBlend(&blend1)
.SetAlphaBlend(&blend2)
.GetResult();
}
// Test failure when specifying color blend multiple times
{
dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder())
.SetColorBlend(&blend1)
.SetColorBlend(&blend2)
.GetResult();
}
// Test failure when specifying color write mask multiple times
{
dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder())
.SetColorWriteMask(dawn::ColorWriteMask::Red)
.SetColorWriteMask(dawn::ColorWriteMask::Green)
.GetResult();
}
}