Fix clamping cube face coordinates to [0.0, 1.0) range
While cube face coordinates are nominally already in the [0.0, 1.0]
range due to the projection of the sampling coordinates onto the cube
face, the projection doesn't result in such normalized cube face
coordinates for Inf and NaN values in the sampling coordinates.
This change causes us to always clamp, matching the legacy OpenGL ES
code now.
Bug: b/132981873
Change-Id: Ib89d032ed4c5945f115269a4e8989aa03e52a6b5
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/48788
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Pipeline/SamplerCore.cpp b/src/Pipeline/SamplerCore.cpp
index ee59c1e..35f38c1 100644
--- a/src/Pipeline/SamplerCore.cpp
+++ b/src/Pipeline/SamplerCore.cpp
@@ -2293,10 +2293,6 @@
const int oneBits = 0x3F7FFFFF; // Value just under 1.0f
const int twoBits = 0x3FFFFFFF; // Value just under 2.0f
- bool pointFilter = state.textureFilter == FILTER_POINT ||
- state.textureFilter == FILTER_MIN_POINT_MAG_LINEAR ||
- state.textureFilter == FILTER_MIN_LINEAR_MAG_POINT;
-
Float4 coord = uvw;
if(state.unnormalizedCoordinates)
@@ -2348,9 +2344,10 @@
{
case ADDRESSING_CLAMP:
case ADDRESSING_SEAMLESS:
- // Linear filtering of cube doesn't require clamping because the coordinates
- // are already in [0, 1] range and numerical imprecision is tolerated.
- if(addressingMode != ADDRESSING_SEAMLESS || pointFilter)
+ // While cube face coordinates are nominally already in the [0.0, 1.0] range
+ // due to the projection, and numerical imprecision is tolerated due to the
+ // border of pixels for seamless filtering, the projection doesn't cause
+ // range normalization for Inf and NaN values. So we always clamp.
{
Float4 one = As<Float4>(Int4(oneBits));
coord = Min(Max(coord, Float4(0.0f)), one);