Add support for BuiltInFrontFacing - Remove Primitive::area, it is unused - Always set front/back masks - Initialize frontfacing based on front/back mask Bug: b/118386749 Test: dEQP-VK.glsl.builtin_var.* Change-Id: I8ccb5a2deb64df2dc4774a3511a5d30c09c30e5f Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29208 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: Chris Forbes <chrisforbes@google.com> Presubmit-Ready: Chris Forbes <chrisforbes@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Device/Primitive.hpp b/src/Device/Primitive.hpp index 1e085f7..f72fe32 100644 --- a/src/Device/Primitive.hpp +++ b/src/Device/Primitive.hpp
@@ -50,8 +50,6 @@ PlaneEquation V[MAX_INTERFACE_COMPONENTS]; }; - float area; - // Masks for two-sided stencil int64_t clockwiseMask; int64_t invClockwiseMask;
diff --git a/src/Pipeline/PixelProgram.cpp b/src/Pipeline/PixelProgram.cpp index 9eb0ab4..127a148 100644 --- a/src/Pipeline/PixelProgram.cpp +++ b/src/Pipeline/PixelProgram.cpp
@@ -33,6 +33,14 @@ routine.descriptorDynamicOffsets = data + OFFSET(DrawData, descriptorDynamicOffsets); routine.pushConstants = data + OFFSET(DrawData, pushConstants); + auto it = spirvShader->inputBuiltins.find(spv::BuiltInFrontFacing); + if (it != spirvShader->inputBuiltins.end()) + { + ASSERT(it->second.SizeInComponents == 1); + auto frontFacing = Int4(*Pointer<Int>(primitive + OFFSET(Primitive, clockwiseMask))); + routine.getVariable(it->second.Id)[it->second.FirstComponent] = As<Float4>(frontFacing); + } + auto activeLaneMask = SIMD::Int(0xFFFFFFFF); // TODO: Control this. spirvShader->emit(&routine, activeLaneMask, descriptorSets); spirvShader->emitEpilog(&routine);
diff --git a/src/Pipeline/SetupRoutine.cpp b/src/Pipeline/SetupRoutine.cpp index d090d3d..5e9b714 100644 --- a/src/Pipeline/SetupRoutine.cpp +++ b/src/Pipeline/SetupRoutine.cpp
@@ -107,32 +107,21 @@ d = IfThenElse(A > 0.0f, d, Int(0)); - if(state.twoSidedStencil) - { - If(frontFacing) - { - *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask)) = Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); - *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask)) = Byte8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - } - Else - { - *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask)) = Byte8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask)) = Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); - } - } - - if(state.vFace) - { - *Pointer<Float>(primitive + OFFSET(Primitive,area)) = 0.5f * A; - } - } - else - { - if(state.twoSidedStencil) + If(frontFacing) { *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask)) = Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask)) = Byte8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); } + Else + { + *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask)) = Byte8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask)) = Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); + } + } + else + { + *Pointer<Byte8>(primitive + OFFSET(Primitive,clockwiseMask)) = Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); + *Pointer<Byte8>(primitive + OFFSET(Primitive,invClockwiseMask)) = Byte8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); } Int n = *Pointer<Int>(polygon + OFFSET(Polygon,n));