GLES: Fix for crashes when sampling certain textures.

There was an optimization that skipped a [0, 1] clamp for a particular sampling mode as it assumed
the input coordinates were always within these bounds.

However, if the texture sample coordinates were inf or NaN, this assumption broke, causing the
returned address to be outside the bounds of the image data.

Bug: b/123731195
Bug: b/124368982
Change-Id: I0af34ee4c2792b19081d9270fd0b1e0d0559287e
Reviewed-on: https://swiftshader-review.googlesource.com/c/24868
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Shader/SamplerCore.cpp b/src/Shader/SamplerCore.cpp
index 8a2aa39..72bc9f4 100644
--- a/src/Shader/SamplerCore.cpp
+++ b/src/Shader/SamplerCore.cpp
@@ -2380,14 +2380,16 @@
 				case ADDRESSING_CLAMP:
 				case ADDRESSING_BORDER:
 				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)
-					{
-						Float4 one = As<Float4>(Int4(oneBits));
-						coord = Min(Max(coord, Float4(0.0f)), one);
-					}
-					break;
+				{
+					// While cube face coordinates are nominally already in the
+					// [0, 1] range due to the projection, and numerical
+					// imprecision is tolerated due to the border of pixels for
+					// seamless filtering, this isn't true for inf and NaN
+					// values. So we always clamp.
+					Float4 one = As<Float4>(Int4(oneBits));
+					coord = Min(Max(coord, Float4(0.0f)), one);
+				}
+				break;
 				case ADDRESSING_MIRROR:
 				{
 					Float4 half = As<Float4>(Int4(halfBits));