Compute relative fragment coordinates just once
`yyyy` was computed both in QuadRasterizer and PixelRoutine.
This change also addresses an issue where the fragment coordinates were
adjusted for per-sample shading but interpolation of ClipDistance and
CullDistance were inconsistently using the adjusted x coordinate in
combination with the unadjusted y coordinate through the DclipDistance
and DcullDistance values.
Bug: b/237494823
Change-Id: I71df337fdb97eefd3e46b6ca00d150f134e11d85
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/67529
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Sean Risser <srisser@google.com>
diff --git a/src/Device/QuadRasterizer.cpp b/src/Device/QuadRasterizer.cpp
index b69945e..778454e 100644
--- a/src/Device/QuadRasterizer.cpp
+++ b/src/Device/QuadRasterizer.cpp
@@ -122,7 +122,7 @@
x1 = Max(x1, Max(x1a, x1b));
}
- SIMD::Float yyyy = SIMD::Float(Float(y)) + SIMD::Float(*Pointer<Float4>(primitive + OFFSET(Primitive, yQuad), 16));
+ yyyy = SIMD::Float(Float(y)) + SIMD::Float(*Pointer<Float4>(primitive + OFFSET(Primitive, yQuad), 16));
if(interpolateZ())
{
diff --git a/src/Device/QuadRasterizer.hpp b/src/Device/QuadRasterizer.hpp
index 9ef2ee1..8ae7df9 100644
--- a/src/Device/QuadRasterizer.hpp
+++ b/src/Device/QuadRasterizer.hpp
@@ -33,6 +33,11 @@
protected:
Pointer<Byte> constants;
+ // Fragment coordinates relative to the polygon's origin
+ SIMD::Float xxxx;
+ SIMD::Float yyyy;
+
+ // B * y + C term of interpolants plane equations
SIMD::Float Dz[4];
SIMD::Float Dw;
SIMD::Float Dv[MAX_INTERFACE_COMPONENTS];
diff --git a/src/Pipeline/PixelRoutine.cpp b/src/Pipeline/PixelRoutine.cpp
index 4e1e827..14aa0c3 100644
--- a/src/Pipeline/PixelRoutine.cpp
+++ b/src/Pipeline/PixelRoutine.cpp
@@ -94,7 +94,7 @@
SIMD::Float rhwCentroid;
- SIMD::Float xxxx = Float4(Float(x)) + *Pointer<Float4>(primitive + OFFSET(Primitive, xQuad), 16);
+ xxxx = Float4(Float(x)) + *Pointer<Float4>(primitive + OFFSET(Primitive, xQuad), 16);
if(interpolateZ())
{
@@ -140,9 +140,6 @@
occlusionSampleCount(zMask, sMask, samples);
}
- ASSERT(SIMD::Width == 4);
- SIMD::Float yyyy = SIMD::Float(Float(y)) + SIMD::Float(*Pointer<Float4>(primitive + OFFSET(Primitive, yQuad), 16));
-
// Centroid locations
SIMD::Float XXXX = 0.0f;
SIMD::Float YYYY = 0.0f;
@@ -193,10 +190,13 @@
routine.interpolationData.rhwCentroid = rhwCentroid;
}
+ SIMD::Float xSample = xxxx;
+ SIMD::Float ySample = yyyy;
+
if(perSampleShading && (state.multiSampleCount > 1))
{
- xxxx += SampleLocationsX[samples[0]];
- yyyy += SampleLocationsY[samples[0]];
+ xSample += SampleLocationsX[samples[0]];
+ ySample += SampleLocationsY[samples[0]];
}
int packedInterpolant = 0;
@@ -216,7 +216,7 @@
else if(perSampleShading)
{
routine.inputs[interfaceInterpolant] =
- SpirvRoutine::interpolateAtXY(xxxx, yyyy, rhw,
+ SpirvRoutine::interpolateAtXY(xSample, ySample, rhw,
primitive + OFFSET(Primitive, V[packedInterpolant]),
routine.inputsInterpolation[packedInterpolant]);
}