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 ...@@ -29,20 +29,6 @@ namespace sw
init(); 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 bool Context::isDrawPoint() const
{ {
switch(topology) switch(topology)
...@@ -113,7 +99,6 @@ namespace sw ...@@ -113,7 +99,6 @@ namespace sw
stencilBuffer = nullptr; stencilBuffer = nullptr;
stencilEnable = false; stencilEnable = false;
twoSidedStencil = false;
frontStencil = {}; frontStencil = {};
backStencil = {}; backStencil = {};
...@@ -133,8 +118,8 @@ namespace sw ...@@ -133,8 +118,8 @@ namespace sw
destBlendFactorStateAlpha = VK_BLEND_FACTOR_ZERO; destBlendFactorStateAlpha = VK_BLEND_FACTOR_ZERO;
blendOperationStateAlpha = VK_BLEND_OP_ADD; blendOperationStateAlpha = VK_BLEND_OP_ADD;
cullMode = CULL_CLOCKWISE; cullMode = VK_CULL_MODE_FRONT_BIT;
frontFacingCCW = true; frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
depthBias = 0.0f; depthBias = 0.0f;
slopeDepthBias = 0.0f; slopeDepthBias = 0.0f;
...@@ -159,27 +144,6 @@ namespace sw ...@@ -159,27 +144,6 @@ namespace sw
alphaToCoverage = false; 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 bool Context::depthWriteActive() const
{ {
if(!depthBufferActive()) return false; if(!depthBufferActive()) return false;
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
namespace vk namespace vk
{ {
class DescriptorSet;
class ImageView; class ImageView;
class PipelineLayout; class PipelineLayout;
} }
...@@ -32,43 +31,6 @@ namespace sw ...@@ -32,43 +31,6 @@ namespace sw
{ {
class SpirvShader; 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 struct PushConstantStorage
{ {
unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE]; unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE];
...@@ -79,23 +41,12 @@ namespace sw ...@@ -79,23 +41,12 @@ namespace sw
public: public:
Context(); Context();
~Context();
void *operator new(size_t bytes);
void operator delete(void *pointer, size_t bytes);
void init(); void init();
bool isDrawPoint() const; bool isDrawPoint() const;
bool isDrawLine() const; bool isDrawLine() const;
bool isDrawTriangle() 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 depthWriteActive() const;
bool depthBufferActive() const; bool depthBufferActive() const;
bool stencilActive() const; bool stencilActive() const;
...@@ -113,13 +64,12 @@ namespace sw ...@@ -113,13 +64,12 @@ namespace sw
VkPrimitiveTopology topology; VkPrimitiveTopology topology;
bool stencilEnable; bool stencilEnable;
bool twoSidedStencil;
VkStencilOpState frontStencil; VkStencilOpState frontStencil;
VkStencilOpState backStencil; VkStencilOpState backStencil;
// Pixel processor states // Pixel processor states
VkCullModeFlags cullMode; VkCullModeFlags cullMode;
bool frontFacingCCW; VkFrontFace frontFace;
float depthBias; float depthBias;
float slopeDepthBias; float slopeDepthBias;
......
...@@ -180,7 +180,6 @@ namespace sw ...@@ -180,7 +180,6 @@ namespace sw
if(context->stencilActive()) if(context->stencilActive())
{ {
state.stencilActive = true; state.stencilActive = true;
state.twoSidedStencil = context->twoSidedStencil;
state.frontStencil = context->frontStencil; state.frontStencil = context->frontStencil;
state.backStencil = context->backStencil; state.backStencil = context->backStencil;
} }
...@@ -221,7 +220,7 @@ namespace sw ...@@ -221,7 +220,7 @@ namespace sw
state.centroid = context->pixelShader->getModes().NeedsCentroid; state.centroid = context->pixelShader->getModes().NeedsCentroid;
} }
state.frontFaceCCW = context->frontFacingCCW; state.frontFace = context->frontFace;
state.hash = state.computeHash(); state.hash = state.computeHash();
......
...@@ -43,7 +43,6 @@ namespace sw ...@@ -43,7 +43,6 @@ namespace sw
bool quadLayoutDepthBuffer; bool quadLayoutDepthBuffer;
bool stencilActive; bool stencilActive;
bool twoSidedStencil;
VkStencilOpState frontStencil; VkStencilOpState frontStencil;
VkStencilOpState backStencil; VkStencilOpState backStencil;
...@@ -66,7 +65,7 @@ namespace sw ...@@ -66,7 +65,7 @@ namespace sw
unsigned int multiSampleMask; unsigned int multiSampleMask;
bool alphaToCoverage; bool alphaToCoverage;
bool centroid; bool centroid;
bool frontFaceCCW; VkFrontFace frontFace;
VkFormat depthFormat; VkFormat depthFormat;
}; };
......
...@@ -74,9 +74,8 @@ namespace sw ...@@ -74,9 +74,8 @@ namespace sw
state.isDrawTriangle = context->isDrawTriangle(); state.isDrawTriangle = context->isDrawTriangle();
state.interpolateZ = context->depthBufferActive() || vPosZW; state.interpolateZ = context->depthBufferActive() || vPosZW;
state.interpolateW = context->pixelShader != nullptr; state.interpolateW = context->pixelShader != nullptr;
state.frontFacingCCW = context->frontFacingCCW; state.frontFace = context->frontFace;
state.cullMode = context->cullMode; state.cullMode = context->cullMode;
state.twoSidedStencil = context->stencilActive() && context->twoSidedStencil;
state.slopeDepthBias = context->slopeDepthBias != 0.0f; state.slopeDepthBias = context->slopeDepthBias != 0.0f;
state.multiSample = context->sampleCount; state.multiSample = context->sampleCount;
......
...@@ -43,9 +43,8 @@ namespace sw ...@@ -43,9 +43,8 @@ namespace sw
bool isDrawTriangle : 1; bool isDrawTriangle : 1;
bool interpolateZ : 1; bool interpolateZ : 1;
bool interpolateW : 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); VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM);
bool twoSidedStencil : 1;
bool slopeDepthBias : 1; bool slopeDepthBias : 1;
unsigned int multiSample : 3; // 1, 2 or 4 unsigned int multiSample : 3; // 1, 2 or 4
bool rasterizerDiscard : 1; bool rasterizerDiscard : 1;
......
...@@ -265,19 +265,16 @@ namespace sw ...@@ -265,19 +265,16 @@ namespace sw
stencilTest(value, state.frontStencil.compareOp, false); 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)); value &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
valueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask)); valueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
value |= valueBack; value |= valueBack;
}
sMask = SignMask(value) & cMask; sMask = SignMask(value) & cMask;
} }
...@@ -697,13 +694,13 @@ namespace sw ...@@ -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.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; return;
} }
} }
if((state.frontStencil.writeMask == 0) && (!state.twoSidedStencil || (state.backStencil.writeMask == 0))) if((state.frontStencil.writeMask == 0) && (state.backStencil.writeMask == 0))
{ {
return; return;
} }
...@@ -728,25 +725,22 @@ namespace sw ...@@ -728,25 +725,22 @@ namespace sw
newValue |= maskedValue; 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) if(state.backStencil.writeMask != 0)
{ {
Byte8 maskedValue = bufferValue; Byte8 maskedValue = bufferValue;
newValueBack &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].writeMaskQ)); newValueBack &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].writeMaskQ));
maskedValue &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].invWriteMaskQ)); maskedValue &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].invWriteMaskQ));
newValueBack |= maskedValue; newValueBack |= maskedValue;
}
newValue &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
newValueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
newValue |= newValueBack;
} }
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); newValue &= *Pointer<Byte8>(constants + OFFSET(Constants,maskB4Q) + 8 * cMask);
bufferValue &= *Pointer<Byte8>(constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask); bufferValue &= *Pointer<Byte8>(constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask);
newValue |= bufferValue; newValue |= bufferValue;
......
...@@ -92,7 +92,7 @@ namespace sw ...@@ -92,7 +92,7 @@ namespace sw
A = IfThenElse(w0w1w2 < 0, -A, A); 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) if(state.cullMode & VK_CULL_MODE_FRONT_BIT)
{ {
......
...@@ -367,7 +367,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -367,7 +367,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
context.rasterizerDiscard = (rasterizationState->rasterizerDiscardEnable == VK_TRUE); context.rasterizerDiscard = (rasterizationState->rasterizerDiscardEnable == VK_TRUE);
context.cullMode = rasterizationState->cullMode; 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.depthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasConstantFactor : 0.0f;
context.slopeDepthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasSlopeFactor : 0.0f; context.slopeDepthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasSlopeFactor : 0.0f;
...@@ -416,7 +416,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -416,7 +416,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
context.depthWriteEnable = (depthStencilState->depthWriteEnable == VK_TRUE); context.depthWriteEnable = (depthStencilState->depthWriteEnable == VK_TRUE);
context.depthCompareMode = depthStencilState->depthCompareOp; context.depthCompareMode = depthStencilState->depthCompareOp;
context.stencilEnable = context.twoSidedStencil = (depthStencilState->stencilTestEnable == VK_TRUE); context.stencilEnable = (depthStencilState->stencilTestEnable == VK_TRUE);
if(context.stencilEnable) if(context.stencilEnable)
{ {
context.frontStencil = depthStencilState->front; context.frontStencil = depthStencilState->front;
...@@ -444,7 +444,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -444,7 +444,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
for (auto i = 0u; i < colorBlendState->attachmentCount; i++) for (auto i = 0u; i < colorBlendState->attachmentCount; i++)
{ {
const VkPipelineColorBlendAttachmentState& attachment = colorBlendState->pAttachments[i]; const VkPipelineColorBlendAttachmentState& attachment = colorBlendState->pAttachments[i];
context.setColorWriteMask(i, attachment.colorWriteMask); context.colorWriteMask[i] = attachment.colorWriteMask;
} }
if(colorBlendState->attachmentCount > 0) 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