Commit 72d81048 by Alexis Hetu Committed by Alexis Hétu

Context cleanup

- Removed twoSidedStencil, which was always true when stencil is enabled - Removed unused enums and functions - Removed custom new/delete operators - Used VkFrontFace type for frontFace Bug b/132280877 Change-Id: I440d5e910e50de0ac8049d3a56848fa8d2de3493 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33531 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 463fab94
......@@ -29,20 +29,6 @@ namespace sw
init();
}
Context::~Context()
{
}
void *Context::operator new(size_t bytes)
{
return allocate((unsigned int)bytes);
}
void Context::operator delete(void *pointer, size_t bytes)
{
deallocate(pointer);
}
bool Context::isDrawPoint() const
{
switch(topology)
......@@ -113,7 +99,6 @@ namespace sw
stencilBuffer = nullptr;
stencilEnable = false;
twoSidedStencil = false;
frontStencil = {};
backStencil = {};
......@@ -133,8 +118,8 @@ namespace sw
destBlendFactorStateAlpha = VK_BLEND_FACTOR_ZERO;
blendOperationStateAlpha = VK_BLEND_OP_ADD;
cullMode = CULL_CLOCKWISE;
frontFacingCCW = true;
cullMode = VK_CULL_MODE_FRONT_BIT;
frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
depthBias = 0.0f;
slopeDepthBias = 0.0f;
......@@ -159,27 +144,6 @@ namespace sw
alphaToCoverage = false;
}
bool Context::setDepthBufferEnable(bool depthBufferEnable)
{
bool modified = (Context::depthBufferEnable != depthBufferEnable);
Context::depthBufferEnable = depthBufferEnable;
return modified;
}
bool Context::setAlphaBlendEnable(bool alphaBlendEnable)
{
bool modified = (Context::alphaBlendEnable != alphaBlendEnable);
Context::alphaBlendEnable = alphaBlendEnable;
return modified;
}
bool Context::setColorWriteMask(int index, int colorWriteMask)
{
bool modified = (Context::colorWriteMask[index] != colorWriteMask);
Context::colorWriteMask[index] = colorWriteMask;
return modified;
}
bool Context::depthWriteActive() const
{
if(!depthBufferActive()) return false;
......
......@@ -23,7 +23,6 @@
namespace vk
{
class DescriptorSet;
class ImageView;
class PipelineLayout;
}
......@@ -32,43 +31,6 @@ namespace sw
{
class SpirvShader;
enum In // Default input stream semantic
{
Position = 0,
BlendWeight = 1,
BlendIndices = 2,
Normal = 3,
PointSize = 4,
Color0 = 5,
Color1 = 6,
TexCoord0 = 7,
TexCoord1 = 8,
TexCoord2 = 9,
TexCoord3 = 10,
TexCoord4 = 11,
TexCoord5 = 12,
TexCoord6 = 13,
TexCoord7 = 14,
PositionT = 15
};
enum CullMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
CULL_NONE,
CULL_CLOCKWISE,
CULL_COUNTERCLOCKWISE,
CULL_LAST = CULL_COUNTERCLOCKWISE
};
enum TransparencyAntialiasing ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
TRANSPARENCY_NONE,
TRANSPARENCY_ALPHA_TO_COVERAGE,
TRANSPARENCY_LAST = TRANSPARENCY_ALPHA_TO_COVERAGE
};
struct PushConstantStorage
{
unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE];
......@@ -79,23 +41,12 @@ namespace sw
public:
Context();
~Context();
void *operator new(size_t bytes);
void operator delete(void *pointer, size_t bytes);
void init();
bool isDrawPoint() const;
bool isDrawLine() const;
bool isDrawTriangle() const;
bool setDepthBufferEnable(bool depthBufferEnable);
bool setAlphaBlendEnable(bool alphaBlendEnable);
bool setColorWriteMask(int index, int colorWriteMask);
bool setWriteSRGB(bool sRGB);
bool depthWriteActive() const;
bool depthBufferActive() const;
bool stencilActive() const;
......@@ -113,13 +64,12 @@ namespace sw
VkPrimitiveTopology topology;
bool stencilEnable;
bool twoSidedStencil;
VkStencilOpState frontStencil;
VkStencilOpState backStencil;
// Pixel processor states
VkCullModeFlags cullMode;
bool frontFacingCCW;
VkFrontFace frontFace;
float depthBias;
float slopeDepthBias;
......
......@@ -180,7 +180,6 @@ namespace sw
if(context->stencilActive())
{
state.stencilActive = true;
state.twoSidedStencil = context->twoSidedStencil;
state.frontStencil = context->frontStencil;
state.backStencil = context->backStencil;
}
......@@ -221,7 +220,7 @@ namespace sw
state.centroid = context->pixelShader->getModes().NeedsCentroid;
}
state.frontFaceCCW = context->frontFacingCCW;
state.frontFace = context->frontFace;
state.hash = state.computeHash();
......
......@@ -43,7 +43,6 @@ namespace sw
bool quadLayoutDepthBuffer;
bool stencilActive;
bool twoSidedStencil;
VkStencilOpState frontStencil;
VkStencilOpState backStencil;
......@@ -66,7 +65,7 @@ namespace sw
unsigned int multiSampleMask;
bool alphaToCoverage;
bool centroid;
bool frontFaceCCW;
VkFrontFace frontFace;
VkFormat depthFormat;
};
......
......@@ -74,9 +74,8 @@ namespace sw
state.isDrawTriangle = context->isDrawTriangle();
state.interpolateZ = context->depthBufferActive() || vPosZW;
state.interpolateW = context->pixelShader != nullptr;
state.frontFacingCCW = context->frontFacingCCW;
state.frontFace = context->frontFace;
state.cullMode = context->cullMode;
state.twoSidedStencil = context->stencilActive() && context->twoSidedStencil;
state.slopeDepthBias = context->slopeDepthBias != 0.0f;
state.multiSample = context->sampleCount;
......
......@@ -43,9 +43,8 @@ namespace sw
bool isDrawTriangle : 1;
bool interpolateZ : 1;
bool interpolateW : 1;
bool frontFacingCCW : 1;
VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM);
VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM);
bool twoSidedStencil : 1;
bool slopeDepthBias : 1;
unsigned int multiSample : 3; // 1, 2 or 4
bool rasterizerDiscard : 1;
......
......@@ -265,19 +265,16 @@ namespace sw
stencilTest(value, state.frontStencil.compareOp, false);
if(state.twoSidedStencil)
if(state.backStencil.compareMask != 0xff)
{
if(state.backStencil.compareMask != 0xff)
{
valueBack &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].testMaskQ));
}
valueBack &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].testMaskQ));
}
stencilTest(valueBack, state.backStencil.compareOp, true);
stencilTest(valueBack, state.backStencil.compareOp, true);
value &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
valueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
value |= valueBack;
}
value &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
valueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
value |= valueBack;
sMask = SignMask(value) & cMask;
}
......@@ -697,13 +694,13 @@ namespace sw
if(state.frontStencil.passOp == VK_STENCIL_OP_KEEP && state.frontStencil.depthFailOp == VK_STENCIL_OP_KEEP && state.frontStencil.failOp == VK_STENCIL_OP_KEEP)
{
if(!state.twoSidedStencil || (state.backStencil.passOp == VK_STENCIL_OP_KEEP && state.backStencil.depthFailOp == VK_STENCIL_OP_KEEP && state.backStencil.failOp == VK_STENCIL_OP_KEEP))
if(state.backStencil.passOp == VK_STENCIL_OP_KEEP && state.backStencil.depthFailOp == VK_STENCIL_OP_KEEP && state.backStencil.failOp == VK_STENCIL_OP_KEEP)
{
return;
}
}
if((state.frontStencil.writeMask == 0) && (!state.twoSidedStencil || (state.backStencil.writeMask == 0)))
if((state.frontStencil.writeMask == 0) && (state.backStencil.writeMask == 0))
{
return;
}
......@@ -728,25 +725,22 @@ namespace sw
newValue |= maskedValue;
}
if(state.twoSidedStencil)
{
Byte8 newValueBack;
Byte8 newValueBack;
stencilOperation(newValueBack, bufferValue, state.backStencil, true, zMask, sMask);
stencilOperation(newValueBack, bufferValue, state.backStencil, true, zMask, sMask);
if(state.backStencil.writeMask != 0)
{
Byte8 maskedValue = bufferValue;
newValueBack &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].writeMaskQ));
maskedValue &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].invWriteMaskQ));
newValueBack |= maskedValue;
}
newValue &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
newValueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
newValue |= newValueBack;
if(state.backStencil.writeMask != 0)
{
Byte8 maskedValue = bufferValue;
newValueBack &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].writeMaskQ));
maskedValue &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].invWriteMaskQ));
newValueBack |= maskedValue;
}
newValue &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
newValueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
newValue |= newValueBack;
newValue &= *Pointer<Byte8>(constants + OFFSET(Constants,maskB4Q) + 8 * cMask);
bufferValue &= *Pointer<Byte8>(constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask);
newValue |= bufferValue;
......
......@@ -92,7 +92,7 @@ namespace sw
A = IfThenElse(w0w1w2 < 0, -A, A);
Bool frontFacing = state.frontFacingCCW ? A > 0.0f : A < 0.0f;
Bool frontFacing = (state.frontFace == VK_FRONT_FACE_COUNTER_CLOCKWISE) ? A > 0.0f : A < 0.0f;
if(state.cullMode & VK_CULL_MODE_FRONT_BIT)
{
......
......@@ -367,7 +367,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
context.rasterizerDiscard = (rasterizationState->rasterizerDiscardEnable == VK_TRUE);
context.cullMode = rasterizationState->cullMode;
context.frontFacingCCW = rasterizationState->frontFace == VK_FRONT_FACE_COUNTER_CLOCKWISE;
context.frontFace = rasterizationState->frontFace;
context.depthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasConstantFactor : 0.0f;
context.slopeDepthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasSlopeFactor : 0.0f;
......@@ -416,7 +416,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
context.depthWriteEnable = (depthStencilState->depthWriteEnable == VK_TRUE);
context.depthCompareMode = depthStencilState->depthCompareOp;
context.stencilEnable = context.twoSidedStencil = (depthStencilState->stencilTestEnable == VK_TRUE);
context.stencilEnable = (depthStencilState->stencilTestEnable == VK_TRUE);
if(context.stencilEnable)
{
context.frontStencil = depthStencilState->front;
......@@ -444,7 +444,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
for (auto i = 0u; i < colorBlendState->attachmentCount; i++)
{
const VkPipelineColorBlendAttachmentState& attachment = colorBlendState->pAttachments[i];
context.setColorWriteMask(i, attachment.colorWriteMask);
context.colorWriteMask[i] = attachment.colorWriteMask;
}
if(colorBlendState->attachmentCount > 0)
......
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