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: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index 25eed51..08b7139 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -29,20 +29,6 @@
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 @@
stencilBuffer = nullptr;
stencilEnable = false;
- twoSidedStencil = false;
frontStencil = {};
backStencil = {};
@@ -133,8 +118,8 @@
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 @@
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;
diff --git a/src/Device/Context.hpp b/src/Device/Context.hpp
index 0ecd28f..0957aeb 100644
--- a/src/Device/Context.hpp
+++ b/src/Device/Context.hpp
@@ -23,7 +23,6 @@
namespace vk
{
- class DescriptorSet;
class ImageView;
class PipelineLayout;
}
@@ -32,43 +31,6 @@
{
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 @@
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 @@
VkPrimitiveTopology topology;
bool stencilEnable;
- bool twoSidedStencil;
VkStencilOpState frontStencil;
VkStencilOpState backStencil;
// Pixel processor states
VkCullModeFlags cullMode;
- bool frontFacingCCW;
+ VkFrontFace frontFace;
float depthBias;
float slopeDepthBias;
diff --git a/src/Device/PixelProcessor.cpp b/src/Device/PixelProcessor.cpp
index f3ad420..898da83 100644
--- a/src/Device/PixelProcessor.cpp
+++ b/src/Device/PixelProcessor.cpp
@@ -180,7 +180,6 @@
if(context->stencilActive())
{
state.stencilActive = true;
- state.twoSidedStencil = context->twoSidedStencil;
state.frontStencil = context->frontStencil;
state.backStencil = context->backStencil;
}
@@ -221,7 +220,7 @@
state.centroid = context->pixelShader->getModes().NeedsCentroid;
}
- state.frontFaceCCW = context->frontFacingCCW;
+ state.frontFace = context->frontFace;
state.hash = state.computeHash();
diff --git a/src/Device/PixelProcessor.hpp b/src/Device/PixelProcessor.hpp
index b16515d..e48f677 100644
--- a/src/Device/PixelProcessor.hpp
+++ b/src/Device/PixelProcessor.hpp
@@ -43,7 +43,6 @@
bool quadLayoutDepthBuffer;
bool stencilActive;
- bool twoSidedStencil;
VkStencilOpState frontStencil;
VkStencilOpState backStencil;
@@ -66,7 +65,7 @@
unsigned int multiSampleMask;
bool alphaToCoverage;
bool centroid;
- bool frontFaceCCW;
+ VkFrontFace frontFace;
VkFormat depthFormat;
};
diff --git a/src/Device/SetupProcessor.cpp b/src/Device/SetupProcessor.cpp
index c3e2f89..8294514 100644
--- a/src/Device/SetupProcessor.cpp
+++ b/src/Device/SetupProcessor.cpp
@@ -74,9 +74,8 @@
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;
diff --git a/src/Device/SetupProcessor.hpp b/src/Device/SetupProcessor.hpp
index f5adc42..c82b8b5 100644
--- a/src/Device/SetupProcessor.hpp
+++ b/src/Device/SetupProcessor.hpp
@@ -43,9 +43,8 @@
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;
diff --git a/src/Pipeline/PixelRoutine.cpp b/src/Pipeline/PixelRoutine.cpp
index 5438b52..a231b62 100644
--- a/src/Pipeline/PixelRoutine.cpp
+++ b/src/Pipeline/PixelRoutine.cpp
@@ -265,20 +265,17 @@
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));
- }
-
- stencilTest(valueBack, state.backStencil.compareOp, true);
-
- value &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
- valueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
- value |= valueBack;
+ valueBack &= *Pointer<Byte8>(data + OFFSET(DrawData,stencil[1].testMaskQ));
}
+ stencilTest(valueBack, state.backStencil.compareOp, true);
+
+ value &= *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask));
+ valueBack &= *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask));
+ value |= valueBack;
+
sMask = SignMask(value) & cMask;
}
@@ -697,13 +694,13 @@
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 @@
newValue |= maskedValue;
}
- if(state.twoSidedStencil)
+ Byte8 newValueBack;
+
+ stencilOperation(newValueBack, bufferValue, state.backStencil, true, zMask, sMask);
+
+ if(state.backStencil.writeMask != 0)
{
- Byte8 newValueBack;
-
- 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;
+ 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;
diff --git a/src/Pipeline/SetupRoutine.cpp b/src/Pipeline/SetupRoutine.cpp
index fd1702e..a87aac6 100644
--- a/src/Pipeline/SetupRoutine.cpp
+++ b/src/Pipeline/SetupRoutine.cpp
@@ -92,7 +92,7 @@
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)
{
diff --git a/src/Vulkan/VkPipeline.cpp b/src/Vulkan/VkPipeline.cpp
index 4a8ba05..cf4764b 100644
--- a/src/Vulkan/VkPipeline.cpp
+++ b/src/Vulkan/VkPipeline.cpp
@@ -367,7 +367,7 @@
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 @@
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 @@
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)