Commit be800bd2 by Alexis Hetu Committed by Alexis Hétu

Move required interpolation logic to SpirvShader

Some of the interpolation logic is required to properly implement the GLSLstd450Interpolate* operations. In order to prevent code duplication and to make sure the logic is always identical between the regular fragment input interpolation and the one performed by the GLSLstd450Interpolate* operations, the interpolateCentroid() function was moved to SpirvShader and renamed with a more generic name, interpolateXY(), as it will be used to interpolate all modes (centroid, sample and offset). Bug: b/171415086 Change-Id: Ifbffa2b395a0b8c22fa120b36643db05f867a306 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/51731Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 8be55746
...@@ -147,7 +147,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -147,7 +147,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
if(state.centroid) if(state.centroid)
{ {
rhwCentroid = reciprocal(interpolateCentroid(XXXX, YYYY, rhwCentroid, primitive + OFFSET(Primitive, w), false, false)); rhwCentroid = reciprocal(SpirvRoutine::interpolateAtXY(XXXX, YYYY, rhwCentroid, primitive + OFFSET(Primitive, w), false, false));
} }
} }
...@@ -161,9 +161,9 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -161,9 +161,9 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
if(input.Centroid && state.enableMultiSampling) if(input.Centroid && state.enableMultiSampling)
{ {
routine.inputs[interpolant] = routine.inputs[interpolant] =
interpolateCentroid(XXXX, YYYY, rhwCentroid, SpirvRoutine::interpolateAtXY(XXXX, YYYY, rhwCentroid,
primitive + OFFSET(Primitive, V[interpolant]), primitive + OFFSET(Primitive, V[interpolant]),
input.Flat, !input.NoPerspective); input.Flat, !input.NoPerspective);
} }
else else
{ {
...@@ -282,24 +282,6 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -282,24 +282,6 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
} }
} }
Float4 PixelRoutine::interpolateCentroid(const Float4 &x, const Float4 &y, const Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective)
{
Float4 interpolant = *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation, C), 16);
if(!flat)
{
interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation, A), 16) +
y * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation, B), 16);
if(perspective)
{
interpolant *= rhw;
}
}
return interpolant;
}
void PixelRoutine::stencilTest(const Pointer<Byte> &sBuffer, int q, const Int &x, Int &sMask, const Int &cMask) void PixelRoutine::stencilTest(const Pointer<Byte> &sBuffer, int q, const Int &x, Int &sMask, const Int &cMask)
{ {
if(!state.stencilActive) if(!state.stencilActive)
......
...@@ -66,7 +66,6 @@ protected: ...@@ -66,7 +66,6 @@ protected:
void linearToSRGB12_16(Vector4s &c); void linearToSRGB12_16(Vector4s &c);
private: private:
Float4 interpolateCentroid(const Float4 &x, const Float4 &y, const Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective);
Byte8 stencilReplaceRef(bool isBack); Byte8 stencilReplaceRef(bool isBack);
void stencilTest(const Pointer<Byte> &sBuffer, int q, const Int &x, Int &sMask, const Int &cMask); void stencilTest(const Pointer<Byte> &sBuffer, int q, const Int &x, Int &sMask, const Int &cMask);
void stencilTest(Byte8 &value, VkCompareOp stencilCompareMode, bool isBack); void stencilTest(Byte8 &value, VkCompareOp stencilCompareMode, bool isBack);
......
...@@ -1406,6 +1406,8 @@ public: ...@@ -1406,6 +1406,8 @@ public:
// common for all shader types. // common for all shader types.
void setImmutableInputBuiltins(SpirvShader const *shader); void setImmutableInputBuiltins(SpirvShader const *shader);
static SIMD::Float interpolateAtXY(const SIMD::Float &x, const SIMD::Float &y, const SIMD::Float &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective);
// setInputBuiltin() calls f() with the builtin and value if the shader // setInputBuiltin() calls f() with the builtin and value if the shader
// uses the input builtin, otherwise the call is a no-op. // uses the input builtin, otherwise the call is a no-op.
// F is a function with the signature: // F is a function with the signature:
......
...@@ -15,14 +15,35 @@ ...@@ -15,14 +15,35 @@
#include "SpirvShader.hpp" #include "SpirvShader.hpp"
#include "ShaderCore.hpp" #include "ShaderCore.hpp"
#include "Device/Primitive.hpp"
#include <spirv/unified1/GLSL.std.450.h> #include <spirv/unified1/GLSL.std.450.h>
#include <spirv/unified1/spirv.hpp> #include <spirv/unified1/spirv.hpp>
namespace { namespace {
constexpr float PI = 3.141592653589793f; constexpr float PI = 3.141592653589793f;
sw::SIMD::Float Interpolate(const sw::SIMD::Float &x, const sw::SIMD::Float &y, const sw::SIMD::Float &rhw,
const sw::SIMD::Float &A, const sw::SIMD::Float &B, const sw::SIMD::Float &C,
bool flat, bool perspective)
{
sw::SIMD::Float interpolant = C;
if(!flat)
{
interpolant += x * A + y * B;
if(perspective)
{
interpolant *= rhw;
}
}
return interpolant;
} }
} // namespace
namespace sw { namespace sw {
SpirvShader::EmitResult SpirvShader::EmitExtGLSLstd450(InsnIterator insn, EmitState *state) const SpirvShader::EmitResult SpirvShader::EmitExtGLSLstd450(InsnIterator insn, EmitState *state) const
...@@ -932,4 +953,19 @@ SpirvShader::EmitResult SpirvShader::EmitExtGLSLstd450(InsnIterator insn, EmitSt ...@@ -932,4 +953,19 @@ SpirvShader::EmitResult SpirvShader::EmitExtGLSLstd450(InsnIterator insn, EmitSt
return EmitResult::Continue; return EmitResult::Continue;
} }
SIMD::Float SpirvRoutine::interpolateAtXY(const SIMD::Float &x, const SIMD::Float &y, const SIMD::Float &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective)
{
SIMD::Float A;
SIMD::Float B;
SIMD::Float C = *Pointer<SIMD::Float>(planeEquation + OFFSET(PlaneEquation, C), 16);
if(!flat)
{
A = *Pointer<SIMD::Float>(planeEquation + OFFSET(PlaneEquation, A), 16);
B = *Pointer<SIMD::Float>(planeEquation + OFFSET(PlaneEquation, B), 16);
}
return ::Interpolate(x, y, rhw, A, B, C, flat, perspective);
}
} // namespace sw } // namespace sw
\ No newline at end of file
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