Commit e8ce1f83 by Nicolas Capens Committed by Nicolas Capens

Move interpolant clamping out of interpolate()

Vulkan never clamps interpolants, except for depth values (specifically for fixed-point formats, and for floating-point formats when the unrestricted depth extension is not enabled). This change moves the clamping operation out of interpolate(), which makes it easier to see depth clamping being performed when necessary, and will facilitate changes in applying depth bias. Bug: b/139341727 Change-Id: I8cef29d63fef00308ef2f813b4feb687c83baa86 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49148 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarSean Risser <srisser@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 51b03d58
...@@ -231,7 +231,7 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax) ...@@ -231,7 +231,7 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax)
Until(y >= yMax); Until(y >= yMax);
} }
Float4 QuadRasterizer::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective, bool clamp) Float4 QuadRasterizer::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective)
{ {
Float4 interpolant = D; Float4 interpolant = D;
...@@ -245,11 +245,6 @@ Float4 QuadRasterizer::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<By ...@@ -245,11 +245,6 @@ Float4 QuadRasterizer::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<By
} }
} }
if(clamp)
{
interpolant = Min(Max(interpolant, Float4(0.0f)), Float4(1.0f));
}
return interpolant; return interpolant;
} }
......
...@@ -46,7 +46,7 @@ protected: ...@@ -46,7 +46,7 @@ protected:
bool interpolateZ() const; bool interpolateZ() const;
bool interpolateW() const; bool interpolateW() const;
Float4 interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective, bool clamp); Float4 interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective);
const PixelProcessor::State &state; const PixelProcessor::State &state;
const SpirvShader *const spirvShader; const SpirvShader *const spirvShader;
......
...@@ -90,7 +90,12 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -90,7 +90,12 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
x -= *Pointer<Float4>(constants + OFFSET(Constants, X) + q * sizeof(float4)); x -= *Pointer<Float4>(constants + OFFSET(Constants, X) + q * sizeof(float4));
} }
z[q] = interpolate(x, Dz[q], z[q], primitive + OFFSET(Primitive, z), false, false, state.depthClamp); z[q] = interpolate(x, Dz[q], z[q], primitive + OFFSET(Primitive, z), false, false);
if(state.depthClamp)
{
z[q] = Min(Max(z[q], Float4(0.0f)), Float4(1.0f));
}
} }
} }
...@@ -133,7 +138,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -133,7 +138,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
if(interpolateW()) if(interpolateW())
{ {
w = interpolate(xxxx, Dw, rhw, primitive + OFFSET(Primitive, w), false, false, false); w = interpolate(xxxx, Dw, rhw, primitive + OFFSET(Primitive, w), false, false);
rhw = reciprocal(w, false, false, true); rhw = reciprocal(w, false, false, true);
if(state.centroid) if(state.centroid)
...@@ -161,7 +166,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -161,7 +166,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
routine.inputs[interpolant] = routine.inputs[interpolant] =
interpolate(xxxx, Dv[interpolant], rhw, interpolate(xxxx, Dv[interpolant], rhw,
primitive + OFFSET(Primitive, V[interpolant]), primitive + OFFSET(Primitive, V[interpolant]),
input.Flat, !input.NoPerspective, false); input.Flat, !input.NoPerspective);
} }
} }
} }
...@@ -172,7 +177,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -172,7 +177,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
{ {
auto distance = interpolate(xxxx, DclipDistance[i], rhw, auto distance = interpolate(xxxx, DclipDistance[i], rhw,
primitive + OFFSET(Primitive, clipDistance[i]), primitive + OFFSET(Primitive, clipDistance[i]),
false, true, false); false, true);
auto clipMask = SignMask(CmpGE(distance, SIMD::Float(0))); auto clipMask = SignMask(CmpGE(distance, SIMD::Float(0)));
for(auto ms = 0u; ms < state.multiSampleCount; ms++) for(auto ms = 0u; ms < state.multiSampleCount; ms++)
...@@ -208,7 +213,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -208,7 +213,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
routine.getVariable(it->second.Id)[it->second.FirstComponent + i] = routine.getVariable(it->second.Id)[it->second.FirstComponent + i] =
interpolate(xxxx, DcullDistance[i], rhw, interpolate(xxxx, DcullDistance[i], rhw,
primitive + OFFSET(Primitive, cullDistance[i]), primitive + OFFSET(Primitive, cullDistance[i]),
false, true, false); false, true);
} }
} }
} }
......
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