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"}
]
},
"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": {
"category": "enum",
"values": [
@ -143,17 +152,13 @@
{
"name": "set alpha blend",
"args": [
{"name": "blend operation", "type": "blend operation"},
{"name": "src factor", "type": "blend factor"},
{"name": "dst factor", "type": "blend factor"}
{"name": "alpha blend", "type": "blend descriptor", "annotation": "const*"}
]
},
{
"name": "set color blend",
"args": [
{"name": "blend operation", "type": "blend operation"},
{"name": "src factor", "type": "blend factor"},
{"name": "dst factor", "type": "blend factor"}
{"name": "color blend", "type": "blend descriptor", "annotation": "const*"}
]
},
{

View File

@ -55,9 +55,7 @@ namespace dawn_native {
mBlendInfo.blendEnabled = blendEnabled;
}
void BlendStateBuilder::SetAlphaBlend(dawn::BlendOperation blendOperation,
dawn::BlendFactor srcFactor,
dawn::BlendFactor dstFactor) {
void BlendStateBuilder::SetAlphaBlend(const BlendDescriptor* alphaBlend) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) {
HandleError("Alpha blend property set multiple times");
return;
@ -65,12 +63,14 @@ namespace dawn_native {
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,
dawn::BlendFactor srcFactor,
dawn::BlendFactor dstFactor) {
void BlendStateBuilder::SetColorBlend(const BlendDescriptor* colorBlend) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) {
HandleError("Color blend property set multiple times");
return;
@ -78,7 +78,11 @@ namespace dawn_native {
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) {

View File

@ -28,15 +28,9 @@ namespace dawn_native {
BlendStateBase(BlendStateBuilder* builder);
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;
BlendOpFactor alphaBlend;
BlendOpFactor colorBlend;
BlendDescriptor alphaBlend;
BlendDescriptor colorBlend;
dawn::ColorWriteMask colorWriteMask = dawn::ColorWriteMask::All;
};
@ -52,12 +46,8 @@ namespace dawn_native {
// Dawn API
void SetBlendEnabled(bool blendEnabled);
void SetAlphaBlend(dawn::BlendOperation blendOperation,
dawn::BlendFactor srcFactor,
dawn::BlendFactor dstFactor);
void SetColorBlend(dawn::BlendOperation blendOperation,
dawn::BlendFactor srcFactor,
dawn::BlendFactor dstFactor);
void SetAlphaBlend(const BlendDescriptor* alphaBlend);
void SetColorBlend(const BlendDescriptor* colorBlend);
void SetColorWriteMask(dawn::ColorWriteMask colorWriteMask);
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
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()
.SetBlendEnabled(true)
.SetColorBlend(operation, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(operation, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
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
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()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, colorSrcFactor, colorDstFactor)
.SetAlphaBlend(dawn::BlendOperation::Add, alphaSrcFactor, alphaDstFactor)
.SetColorBlend(&colorBlend)
.SetAlphaBlend(&alphaBlend)
.GetResult();
SetupSingleSourcePipelines(blendState);
@ -610,12 +625,17 @@ TEST_P(BlendStateTest, DstBlendFactorOneMinusBlendColor) {
// Check that the color write mask works
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
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Red)
.GetResult();
SetupSingleSourcePipelines(blendState);
@ -631,8 +651,8 @@ TEST_P(BlendStateTest, ColorWriteMask) {
// Test multi channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::Green | dawn::ColorWriteMask::Alpha)
.GetResult();
SetupSingleSourcePipelines(blendState);
@ -648,8 +668,8 @@ TEST_P(BlendStateTest, ColorWriteMask) {
// Test no channel color write
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.SetColorWriteMask(dawn::ColorWriteMask::None)
.GetResult();
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 = { {
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend1)
.SetAlphaBlend(&blend1)
.GetResult(),
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Subtract, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Subtract, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend2)
.SetAlphaBlend(&blend2)
.GetResult(),
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Min, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Min, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend3)
.SetAlphaBlend(&blend3)
.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_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(dawn::BlendOperation::Add, dawn::BlendFactor::BlendColor, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::BlendColor, dawn::BlendFactor::One)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(

View File

@ -182,10 +182,15 @@ class PushConstantTest: public DawnTest {
})").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()
.SetBlendEnabled(true)
.SetColorBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetAlphaBlend(dawn::BlendOperation::Add, dawn::BlendFactor::One, dawn::BlendFactor::One)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
return device.CreateRenderPipelineBuilder()

View File

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