Use blend descriptor to replace a blend struct.

Bug=dawn:32

Change-Id: I74db6c1e9cf57a168967131ea2c9e1d802853ab4
Reviewed-on: https://dawn-review.googlesource.com/c/2020
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Yunchao He 2018-10-29 09:06:55 +00:00 committed by Commit Bot service account
parent 3f06587542
commit c35103dc19
6 changed files with 113 additions and 54 deletions

View File

@ -96,6 +96,15 @@
{"value": 3, "name": "storage buffer"} {"value": 3, "name": "storage buffer"}
] ]
}, },
"blend descriptor": {
"category": "structure",
"extensible": false,
"members": [
{"name": "operation", "type": "blend operation"},
{"name": "src factor", "type": "blend factor"},
{"name": "dst factor", "type": "blend factor"}
]
},
"blend factor": { "blend factor": {
"category": "enum", "category": "enum",
"values": [ "values": [
@ -143,17 +152,13 @@
{ {
"name": "set alpha blend", "name": "set alpha blend",
"args": [ "args": [
{"name": "blend operation", "type": "blend operation"}, {"name": "alpha blend", "type": "blend descriptor", "annotation": "const*"}
{"name": "src factor", "type": "blend factor"},
{"name": "dst factor", "type": "blend factor"}
] ]
}, },
{ {
"name": "set color blend", "name": "set color blend",
"args": [ "args": [
{"name": "blend operation", "type": "blend operation"}, {"name": "color blend", "type": "blend descriptor", "annotation": "const*"}
{"name": "src factor", "type": "blend factor"},
{"name": "dst factor", "type": "blend factor"}
] ]
}, },
{ {

View File

@ -55,9 +55,7 @@ namespace dawn_native {
mBlendInfo.blendEnabled = blendEnabled; mBlendInfo.blendEnabled = blendEnabled;
} }
void BlendStateBuilder::SetAlphaBlend(dawn::BlendOperation blendOperation, void BlendStateBuilder::SetAlphaBlend(const BlendDescriptor* alphaBlend) {
dawn::BlendFactor srcFactor,
dawn::BlendFactor dstFactor) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) { if ((mPropertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) {
HandleError("Alpha blend property set multiple times"); HandleError("Alpha blend property set multiple times");
return; return;
@ -65,12 +63,14 @@ namespace dawn_native {
mPropertiesSet |= BLEND_STATE_PROPERTY_ALPHA_BLEND; mPropertiesSet |= BLEND_STATE_PROPERTY_ALPHA_BLEND;
mBlendInfo.alphaBlend = {blendOperation, srcFactor, dstFactor}; // TODO(yunchao.he@intel.com): validate the enum values in
// ValidateBlendStateDescriptor when it is added.
mBlendInfo.alphaBlend.operation = alphaBlend->operation;
mBlendInfo.alphaBlend.srcFactor = alphaBlend->srcFactor;
mBlendInfo.alphaBlend.dstFactor = alphaBlend->dstFactor;
} }
void BlendStateBuilder::SetColorBlend(dawn::BlendOperation blendOperation, void BlendStateBuilder::SetColorBlend(const BlendDescriptor* colorBlend) {
dawn::BlendFactor srcFactor,
dawn::BlendFactor dstFactor) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) { if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) {
HandleError("Color blend property set multiple times"); HandleError("Color blend property set multiple times");
return; return;
@ -78,7 +78,11 @@ namespace dawn_native {
mPropertiesSet |= BLEND_STATE_PROPERTY_COLOR_BLEND; mPropertiesSet |= BLEND_STATE_PROPERTY_COLOR_BLEND;
mBlendInfo.colorBlend = {blendOperation, srcFactor, dstFactor}; // TODO(yunchao.he@intel.com): validate the enum values in
// ValidateBlendStateDescriptor when it is added.
mBlendInfo.colorBlend.operation = colorBlend->operation;
mBlendInfo.colorBlend.srcFactor = colorBlend->srcFactor;
mBlendInfo.colorBlend.dstFactor = colorBlend->dstFactor;
} }
void BlendStateBuilder::SetColorWriteMask(dawn::ColorWriteMask colorWriteMask) { void BlendStateBuilder::SetColorWriteMask(dawn::ColorWriteMask colorWriteMask) {

View File

@ -28,15 +28,9 @@ namespace dawn_native {
BlendStateBase(BlendStateBuilder* builder); BlendStateBase(BlendStateBuilder* builder);
struct BlendInfo { struct BlendInfo {
struct BlendOpFactor {
dawn::BlendOperation operation = dawn::BlendOperation::Add;
dawn::BlendFactor srcFactor = dawn::BlendFactor::One;
dawn::BlendFactor dstFactor = dawn::BlendFactor::Zero;
};
bool blendEnabled = false; bool blendEnabled = false;
BlendOpFactor alphaBlend; BlendDescriptor alphaBlend;
BlendOpFactor colorBlend; BlendDescriptor colorBlend;
dawn::ColorWriteMask colorWriteMask = dawn::ColorWriteMask::All; dawn::ColorWriteMask colorWriteMask = dawn::ColorWriteMask::All;
}; };
@ -52,12 +46,8 @@ namespace dawn_native {
// Dawn API // Dawn API
void SetBlendEnabled(bool blendEnabled); void SetBlendEnabled(bool blendEnabled);
void SetAlphaBlend(dawn::BlendOperation blendOperation, void SetAlphaBlend(const BlendDescriptor* alphaBlend);
dawn::BlendFactor srcFactor, void SetColorBlend(const BlendDescriptor* colorBlend);
dawn::BlendFactor dstFactor);
void SetColorBlend(dawn::BlendOperation blendOperation,
dawn::BlendFactor srcFactor,
dawn::BlendFactor dstFactor);
void SetColorWriteMask(dawn::ColorWriteMask colorWriteMask); void SetColorWriteMask(dawn::ColorWriteMask colorWriteMask);
private: private:

View File

@ -133,10 +133,15 @@ class BlendStateTest : public DawnTest {
// Given a vector of tests where each element is <testColor, expectedColor>, check that all expectations are true for the given blend operation // Given a vector of tests where each element is <testColor, expectedColor>, check that all expectations are true for the given blend operation
void CheckBlendOperation(RGBA8 base, dawn::BlendOperation operation, std::vector<std::pair<RGBA8, RGBA8>> tests) { void CheckBlendOperation(RGBA8 base, dawn::BlendOperation operation, std::vector<std::pair<RGBA8, RGBA8>> tests) {
dawn::BlendDescriptor blend;
blend.operation = operation;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendState blendState = device.CreateBlendStateBuilder() dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(operation, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend)
.SetAlphaBlend(operation, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend)
.GetResult(); .GetResult();
SetupSingleSourcePipelines(blendState); SetupSingleSourcePipelines(blendState);
@ -148,10 +153,20 @@ class BlendStateTest : public DawnTest {
// Given a vector of tests where each element is <testSpec, expectedColor>, check that all expectations are true for the given blend factors // Given a vector of tests where each element is <testSpec, expectedColor>, check that all expectations are true for the given blend factors
void CheckBlendFactor(RGBA8 base, dawn::BlendFactor colorSrcFactor, dawn::BlendFactor colorDstFactor, dawn::BlendFactor alphaSrcFactor, dawn::BlendFactor alphaDstFactor, std::vector<std::pair<TriangleSpec, RGBA8>> tests) { void CheckBlendFactor(RGBA8 base, dawn::BlendFactor colorSrcFactor, dawn::BlendFactor colorDstFactor, dawn::BlendFactor alphaSrcFactor, dawn::BlendFactor alphaDstFactor, std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
dawn::BlendDescriptor colorBlend;
colorBlend.operation = dawn::BlendOperation::Add;
colorBlend.srcFactor = colorSrcFactor;
colorBlend.dstFactor = colorDstFactor;
dawn::BlendDescriptor alphaBlend;
alphaBlend.operation = dawn::BlendOperation::Add;
alphaBlend.srcFactor = alphaSrcFactor;
alphaBlend.dstFactor = alphaDstFactor;
dawn::BlendState blendState = device.CreateBlendStateBuilder() dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, colorSrcFactor, colorDstFactor) .SetColorBlend(&colorBlend)
.SetAlphaBlend(dawn::BlendOperation::Add, alphaSrcFactor, alphaDstFactor) .SetAlphaBlend(&alphaBlend)
.GetResult(); .GetResult();
SetupSingleSourcePipelines(blendState); SetupSingleSourcePipelines(blendState);
@ -610,12 +625,17 @@ TEST_P(BlendStateTest, DstBlendFactorOneMinusBlendColor) {
// Check that the color write mask works // Check that the color write mask works
TEST_P(BlendStateTest, ColorWriteMask) { TEST_P(BlendStateTest, ColorWriteMask) {
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
{ {
// Test single channel color write // Test single channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder() dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Red) .SetColorWriteMask(dawn::ColorWriteMask::Red)
.GetResult(); .GetResult();
SetupSingleSourcePipelines(blendState); SetupSingleSourcePipelines(blendState);
@ -631,8 +651,8 @@ TEST_P(BlendStateTest, ColorWriteMask) {
// Test multi channel color write // Test multi channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder() dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Green | dawn::ColorWriteMask::Alpha) .SetColorWriteMask(dawn::ColorWriteMask::Green | dawn::ColorWriteMask::Alpha)
.GetResult(); .GetResult();
SetupSingleSourcePipelines(blendState); SetupSingleSourcePipelines(blendState);
@ -648,8 +668,8 @@ TEST_P(BlendStateTest, ColorWriteMask) {
// Test no channel color write // Test no channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder() dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::None) .SetColorWriteMask(dawn::ColorWriteMask::None)
.GetResult(); .GetResult();
SetupSingleSourcePipelines(blendState); SetupSingleSourcePipelines(blendState);
@ -739,21 +759,36 @@ 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, 3> blendStates = { { std::array<dawn::BlendState, 3> blendStates = { {
device.CreateBlendStateBuilder() device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend1)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend1)
.GetResult(), .GetResult(),
device.CreateBlendStateBuilder() device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Subtract, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend2)
.SetAlphaBlend(dawn::BlendOperation::Subtract, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend2)
.GetResult(), .GetResult(),
device.CreateBlendStateBuilder() device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Min, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend3)
.SetAlphaBlend(dawn::BlendOperation::Min, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend3)
.GetResult(), .GetResult(),
} }; } };
@ -819,10 +854,15 @@ TEST_P(BlendStateTest, IndependentBlendState) {
// Test that the default blend color is correctly set at the beginning of every subpass // Test that the default blend color is correctly set at the beginning of every subpass
TEST_P(BlendStateTest, DefaultBlendColor) { 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() dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::BlendColor, dawn::BlendFactor::One) .SetColorBlend(&blend)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::BlendColor, dawn::BlendFactor::One) .SetAlphaBlend(&blend)
.GetResult(); .GetResult();
dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"( dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(

View File

@ -182,10 +182,15 @@ class PushConstantTest: public DawnTest {
})").c_str() })").c_str()
); );
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendState blendState = device.CreateBlendStateBuilder() dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend)
.GetResult(); .GetResult();
return device.CreateRenderPipelineBuilder() return device.CreateRenderPipelineBuilder()

View File

@ -21,10 +21,15 @@ class BlendStateValidationTest : public ValidationTest {
TEST_F(BlendStateValidationTest, CreationSuccess) { TEST_F(BlendStateValidationTest, CreationSuccess) {
// Success for setting all properties // 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()) dawn::BlendState state = AssertWillBeSuccess(device.CreateBlendStateBuilder())
.SetBlendEnabled(true) .SetBlendEnabled(true)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Red) .SetColorWriteMask(dawn::ColorWriteMask::Red)
.GetResult(); .GetResult();
} }
@ -46,19 +51,29 @@ TEST_F(BlendStateValidationTest, CreationDuplicates) {
.GetResult(); .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 // Test failure when specifying alpha blend multiple times
{ {
dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder()) dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder())
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetAlphaBlend(&blend1)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::Zero, dawn::BlendFactor::Zero) .SetAlphaBlend(&blend2)
.GetResult(); .GetResult();
} }
// Test failure when specifying color blend multiple times // Test failure when specifying color blend multiple times
{ {
dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder()) dawn::BlendState state = AssertWillBeError(device.CreateBlendStateBuilder())
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One) .SetColorBlend(&blend1)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::Zero, dawn::BlendFactor::Zero) .SetColorBlend(&blend2)
.GetResult(); .GetResult();
} }