nir: allow texture offsets with cube maps
authorIlia Mirkin <imirkin@alum.mit.edu>
Sun, 19 Nov 2017 17:27:12 +0000 (12:27 -0500)
committerIlia Mirkin <imirkin@alum.mit.edu>
Sat, 25 Nov 2017 21:56:30 +0000 (16:56 -0500)
GL doesn't have this, but some hardware supports it. This is convenient
for lowering tg4 to plain texture calls, which is necessary on Adreno
A4xx hardware.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Rob Clark <robdclark@gmail.com>
src/compiler/nir/nir.h

index f46f6147110acbffec5cbfe2b5cd12fa6d4604ba..cf200fdc665dd15c0177336fc4bd0e09dab80aad 100644 (file)
@@ -1364,8 +1364,7 @@ nir_tex_instr_src_size(const nir_tex_instr *instr, unsigned src)
    if (instr->src[src].src_type == nir_tex_src_ms_mcs)
       return 4;
 
-   if (instr->src[src].src_type == nir_tex_src_offset ||
-       instr->src[src].src_type == nir_tex_src_ddx ||
+   if (instr->src[src].src_type == nir_tex_src_ddx ||
        instr->src[src].src_type == nir_tex_src_ddy) {
       if (instr->is_array)
          return instr->coord_components - 1;
@@ -1373,6 +1372,18 @@ nir_tex_instr_src_size(const nir_tex_instr *instr, unsigned src)
          return instr->coord_components;
    }
 
+   /* Usual APIs don't allow cube + offset, but we allow it, with 2 coords for
+    * the offset, since a cube maps to a single face.
+    */
+   if (instr->src[src].src_type == nir_tex_src_offset) {
+      if (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE)
+         return 2;
+      else if (instr->is_array)
+         return instr->coord_components - 1;
+      else
+         return instr->coord_components;
+   }
+
    return 1;
 }