D3D11: Use clamp wrap mode for Integer textures.

Until we can support all wrap modes for int textures, use a correct
clamping scheme. This fixes several dEQP GLES3 FBO tests.

This shuffles some of the tests in functional.texture.units since
it hard-codes a different behaviour for all wrap modes, ignoring
the sampler setting.

BUG=angleproject:1244
TEST=dEQP-GLES3.functional.texture.*

Change-Id: Ic7e89a111728dfb18821534996bf5b9a5ad172b6
Reviewed-on: https://chromium-review.googlesource.com/313997
Tryjob-Request: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 2c4ad33..a2309a9 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -1118,7 +1118,9 @@
             TString addressx = "";
             TString addressy = "";
             TString addressz = "";
-            TString close = "";
+            TString closex   = "";
+            TString closey   = "";
+            TString closez   = "";
 
             if (IsIntegerSampler(textureFunction->sampler) ||
                 textureFunction->method == TextureFunction::FETCH)
@@ -1133,23 +1135,23 @@
                 // Convert from normalized floating-point to integer
                 if (textureFunction->method != TextureFunction::FETCH)
                 {
-                    addressx = "int(floor(width * frac((";
-                    addressy = "int(floor(height * frac((";
+                    // We hard-code the clamp wrap mode for integer textures.
+                    // TODO(jmadill): Figure out how to integer texture wrap modes.
+                    addressx = "int(clamp(round((width *";
+                    addressy = "int(clamp(round((height * ";
+                    closex   = ") - 0.5f), 0.0f, width - 1.0f))";
+                    closey   = ") - 0.5f), 0.0f, height - 1.0f))";
 
                     if (IsSamplerArray(textureFunction->sampler))
                     {
                         addressz = "int(max(0, min(layers - 1, floor(0.5 + ";
+                        closez   = "))))";
                     }
-                    else if (IsSamplerCube(textureFunction->sampler))
+                    else if (IsSampler3D(textureFunction->sampler))
                     {
-                        addressz = "((((";
+                        addressz = "int(clamp(round((depth * ";
+                        closez   = ") - 0.5f), 0.0f, depth - 1.0f))";
                     }
-                    else
-                    {
-                        addressz = "int(floor(depth * frac((";
-                    }
-
-                    close = "))))";
                 }
             }
             else
@@ -1175,7 +1177,7 @@
                 }
             }
 
-            out << addressx + ("t.x" + proj) + close + ", " + addressy + ("t.y" + proj) + close;
+            out << addressx + ("t.x" + proj) + closex + ", " + addressy + ("t.y" + proj) + closey;
 
             if (mOutputType == SH_HLSL9_OUTPUT)
             {
@@ -1215,7 +1217,7 @@
                     }
                     else
                     {
-                        out << ", " + addressz + ("t.z" + proj) + close;
+                        out << ", " + addressz + ("t.z" + proj) + closez;
                     }
                 }