Commit 51d51084 by Alexis Hetu Committed by Alexis Hétu

Support for independentBlend feature

A few blend related context members were changed from scalars to arrays in order to support independent blend. Bug b/140193782 Change-Id: I5ca1153e952fe0d3899f68dc6cd7cc5d8a244b72 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34113Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Presubmit-Ready: Alexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 793b6c3d
......@@ -36,6 +36,19 @@ namespace sw
unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE];
};
struct BlendState
{
void init();
bool alphaBlendEnable;
VkBlendFactor sourceBlendFactor;
VkBlendFactor destBlendFactor;
VkBlendOp blendOperation;
VkBlendFactor sourceBlendFactorAlpha;
VkBlendFactor destBlendFactorAlpha;
VkBlendOp blendOperationAlpha;
};
class Context
{
public:
......@@ -52,14 +65,9 @@ namespace sw
bool stencilActive() const;
bool allTargetsColorClamp() const;
bool alphaBlendActive() const;
VkBlendFactor sourceBlendFactor() const;
VkBlendFactor destBlendFactor() const;
VkBlendOp blendOperation() const;
VkBlendFactor sourceBlendFactorAlpha() const;
VkBlendFactor destBlendFactorAlpha() const;
VkBlendOp blendOperationAlpha() const;
void setBlendState(int index, BlendState state);
BlendState getBlendState(int index) const;
VkPrimitiveTopology topology;
......@@ -75,9 +83,7 @@ namespace sw
float slopeDepthBias;
VkFormat renderTargetInternalFormat(int index) const;
bool colorWriteActive() const;
int colorWriteActive(int index) const;
bool colorUsed() const;
vk::DescriptorSet::Bindings descriptorSets = {};
vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {};
......@@ -102,15 +108,6 @@ namespace sw
VkCompareOp depthCompareMode;
bool depthWriteEnable;
bool alphaBlendEnable;
VkBlendFactor sourceBlendFactorState;
VkBlendFactor destBlendFactorState;
VkBlendOp blendOperationState;
VkBlendFactor sourceBlendFactorStateAlpha;
VkBlendFactor destBlendFactorStateAlpha;
VkBlendOp blendOperationStateAlpha;
float lineWidth;
int colorWriteMask[RENDERTARGETS]; // RGBA
......@@ -118,6 +115,21 @@ namespace sw
unsigned int multiSampleMask;
int sampleCount;
bool alphaToCoverage;
private:
bool colorWriteActive() const;
bool colorUsed() const;
bool alphaBlendActive(int index) const;
VkBlendFactor sourceBlendFactor(int index) const;
VkBlendFactor destBlendFactor(int index) const;
VkBlendOp blendOperation(int index) const;
VkBlendFactor sourceBlendFactorAlpha(int index) const;
VkBlendFactor destBlendFactorAlpha(int index) const;
VkBlendOp blendOperationAlpha(int index) const;
BlendState blendState[RENDERTARGETS];
};
}
......
......@@ -195,21 +195,11 @@ namespace sw
state.occlusionEnabled = context->occlusionEnabled;
state.depthClamp = (context->depthBias != 0.0f) || (context->slopeDepthBias != 0.0f);
if(context->alphaBlendActive())
{
state.alphaBlendActive = true;
state.sourceBlendFactor = context->sourceBlendFactor();
state.destBlendFactor = context->destBlendFactor();
state.blendOperation = context->blendOperation();
state.sourceBlendFactorAlpha = context->sourceBlendFactorAlpha();
state.destBlendFactorAlpha = context->destBlendFactorAlpha();
state.blendOperationAlpha = context->blendOperationAlpha();
}
for(int i = 0; i < RENDERTARGETS; i++)
{
state.colorWriteMask |= context->colorWriteActive(i) << (4 * i);
state.targetFormat[i] = context->renderTargetInternalFormat(i);
state.blendState[i] = context->getBlendState(i);
}
state.multiSample = static_cast<unsigned int>(context->sampleCount);
......
......@@ -52,13 +52,7 @@ namespace sw
bool perspective;
bool depthClamp;
bool alphaBlendActive;
VkBlendFactor sourceBlendFactor;
VkBlendFactor destBlendFactor;
VkBlendOp blendOperation;
VkBlendFactor sourceBlendFactorAlpha;
VkBlendFactor destBlendFactorAlpha;
VkBlendOp blendOperationAlpha;
BlendState blendState[RENDERTARGETS];
unsigned int colorWriteMask;
VkFormat targetFormat[RENDERTARGETS];
......
......@@ -1064,7 +1064,7 @@ namespace sw
void PixelRoutine::alphaBlend(int index, Pointer<Byte> &cBuffer, Vector4s &current, Int &x)
{
if(!state.alphaBlendActive)
if(!state.blendState[index].alphaBlendEnable)
{
return;
}
......@@ -1076,24 +1076,24 @@ namespace sw
Vector4s sourceFactor;
Vector4s destFactor;
blendFactor(sourceFactor, current, pixel, state.sourceBlendFactor);
blendFactor(destFactor, current, pixel, state.destBlendFactor);
blendFactor(sourceFactor, current, pixel, state.blendState[index].sourceBlendFactor);
blendFactor(destFactor, current, pixel, state.blendState[index].destBlendFactor);
if(state.sourceBlendFactor != VK_BLEND_FACTOR_ONE && state.sourceBlendFactor != VK_BLEND_FACTOR_ZERO)
if(state.blendState[index].sourceBlendFactor != VK_BLEND_FACTOR_ONE && state.blendState[index].sourceBlendFactor != VK_BLEND_FACTOR_ZERO)
{
current.x = MulHigh(As<UShort4>(current.x), As<UShort4>(sourceFactor.x));
current.y = MulHigh(As<UShort4>(current.y), As<UShort4>(sourceFactor.y));
current.z = MulHigh(As<UShort4>(current.z), As<UShort4>(sourceFactor.z));
}
if(state.destBlendFactor != VK_BLEND_FACTOR_ONE && state.destBlendFactor != VK_BLEND_FACTOR_ZERO)
if(state.blendState[index].destBlendFactor != VK_BLEND_FACTOR_ONE && state.blendState[index].destBlendFactor != VK_BLEND_FACTOR_ZERO)
{
pixel.x = MulHigh(As<UShort4>(pixel.x), As<UShort4>(destFactor.x));
pixel.y = MulHigh(As<UShort4>(pixel.y), As<UShort4>(destFactor.y));
pixel.z = MulHigh(As<UShort4>(pixel.z), As<UShort4>(destFactor.z));
}
switch(state.blendOperation)
switch(state.blendState[index].blendOperation)
{
case VK_BLEND_OP_ADD:
current.x = AddSat(As<UShort4>(current.x), As<UShort4>(pixel.x));
......@@ -1134,23 +1134,23 @@ namespace sw
current.z = Short4(0x0000);
break;
default:
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendOperation));
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendState[index].blendOperation));
}
blendFactorAlpha(sourceFactor, current, pixel, state.sourceBlendFactorAlpha);
blendFactorAlpha(destFactor, current, pixel, state.destBlendFactorAlpha);
blendFactorAlpha(sourceFactor, current, pixel, state.blendState[index].sourceBlendFactorAlpha);
blendFactorAlpha(destFactor, current, pixel, state.blendState[index].destBlendFactorAlpha);
if(state.sourceBlendFactorAlpha != VK_BLEND_FACTOR_ONE && state.sourceBlendFactorAlpha != VK_BLEND_FACTOR_ZERO)
if(state.blendState[index].sourceBlendFactorAlpha != VK_BLEND_FACTOR_ONE && state.blendState[index].sourceBlendFactorAlpha != VK_BLEND_FACTOR_ZERO)
{
current.w = MulHigh(As<UShort4>(current.w), As<UShort4>(sourceFactor.w));
}
if(state.destBlendFactorAlpha != VK_BLEND_FACTOR_ONE && state.destBlendFactorAlpha != VK_BLEND_FACTOR_ZERO)
if(state.blendState[index].destBlendFactorAlpha != VK_BLEND_FACTOR_ONE && state.blendState[index].destBlendFactorAlpha != VK_BLEND_FACTOR_ZERO)
{
pixel.w = MulHigh(As<UShort4>(pixel.w), As<UShort4>(destFactor.w));
}
switch(state.blendOperationAlpha)
switch(state.blendState[index].blendOperationAlpha)
{
case VK_BLEND_OP_ADD:
current.w = AddSat(As<UShort4>(current.w), As<UShort4>(pixel.w));
......@@ -1177,7 +1177,7 @@ namespace sw
current.w = Short4(0x0000);
break;
default:
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendOperationAlpha));
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendState[index].blendOperationAlpha));
}
}
......@@ -1794,7 +1794,7 @@ namespace sw
void PixelRoutine::alphaBlend(int index, Pointer<Byte> &cBuffer, Vector4f &oC, Int &x)
{
if(!state.alphaBlendActive)
if(!state.blendState[index].alphaBlendEnable)
{
return;
}
......@@ -1911,8 +1911,8 @@ namespace sw
Vector4f sourceFactor;
Vector4f destFactor;
blendFactor(sourceFactor, oC, pixel, state.sourceBlendFactor);
blendFactor(destFactor, oC, pixel, state.destBlendFactor);
blendFactor(sourceFactor, oC, pixel, state.blendState[index].sourceBlendFactor);
blendFactor(destFactor, oC, pixel, state.blendState[index].destBlendFactor);
oC.x *= sourceFactor.x;
oC.y *= sourceFactor.y;
......@@ -1922,7 +1922,7 @@ namespace sw
pixel.y *= destFactor.y;
pixel.z *= destFactor.z;
switch(state.blendOperation)
switch(state.blendState[index].blendOperation)
{
case VK_BLEND_OP_ADD:
oC.x += pixel.x;
......@@ -1963,16 +1963,16 @@ namespace sw
oC.z = Float4(0.0f);
break;
default:
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendOperation));
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendState[index].blendOperation));
}
blendFactorAlpha(sourceFactor, oC, pixel, state.sourceBlendFactorAlpha);
blendFactorAlpha(destFactor, oC, pixel, state.destBlendFactorAlpha);
blendFactorAlpha(sourceFactor, oC, pixel, state.blendState[index].sourceBlendFactorAlpha);
blendFactorAlpha(destFactor, oC, pixel, state.blendState[index].destBlendFactorAlpha);
oC.w *= sourceFactor.w;
pixel.w *= destFactor.w;
switch(state.blendOperationAlpha)
switch(state.blendState[index].blendOperationAlpha)
{
case VK_BLEND_OP_ADD:
oC.w += pixel.w;
......@@ -2000,7 +2000,7 @@ namespace sw
oC.w = Float4(0.0f);
break;
default:
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendOperationAlpha));
UNIMPLEMENTED("VkBlendOp: %d", int(state.blendState[index].blendOperationAlpha));
}
}
......
......@@ -34,7 +34,7 @@ const VkPhysicalDeviceFeatures& PhysicalDevice::getFeatures() const
VK_TRUE, // robustBufferAccess
VK_FALSE, // fullDrawIndexUint32
VK_FALSE, // imageCubeArray
VK_FALSE, // independentBlend
VK_TRUE, // independentBlend
VK_FALSE, // geometryShader
VK_FALSE, // tessellationShader
VK_FALSE, // sampleRateShading
......
......@@ -468,18 +468,10 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
{
const VkPipelineColorBlendAttachmentState& attachment = colorBlendState->pAttachments[i];
context.colorWriteMask[i] = attachment.colorWriteMask;
}
if(colorBlendState->attachmentCount > 0)
{
const VkPipelineColorBlendAttachmentState& attachment = colorBlendState->pAttachments[0];
context.alphaBlendEnable = (attachment.blendEnable == VK_TRUE);
context.blendOperationStateAlpha = attachment.alphaBlendOp;
context.blendOperationState = attachment.colorBlendOp;
context.destBlendFactorStateAlpha = attachment.dstAlphaBlendFactor;
context.destBlendFactorState = attachment.dstColorBlendFactor;
context.sourceBlendFactorStateAlpha = attachment.srcAlphaBlendFactor;
context.sourceBlendFactorState = attachment.srcColorBlendFactor;
context.setBlendState(i, { (attachment.blendEnable == VK_TRUE),
attachment.srcColorBlendFactor, attachment.dstColorBlendFactor, attachment.colorBlendOp,
attachment.srcAlphaBlendFactor, attachment.dstAlphaBlendFactor, attachment.alphaBlendOp });
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment