nir: rename nir_lower_tex_projector
authorRob Clark <robclark@freedesktop.org>
Thu, 17 Sep 2015 11:54:35 +0000 (07:54 -0400)
committerRob Clark <robclark@freedesktop.org>
Sat, 19 Sep 2015 01:07:49 +0000 (21:07 -0400)
Since the following patches will add additional tex-lowering related
functionality, which doesn't make sense to split out into a separate
pass (as they would require duplication of the projector lowering
logic), let's give this pass a more generic name.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/Makefile.sources
src/glsl/nir/nir.h
src/glsl/nir/nir_lower_tex.c [new file with mode: 0644]
src/glsl/nir/nir_lower_tex_projector.c [deleted file]
src/mesa/drivers/dri/i965/brw_nir.c

index 5134ab73800f882d1bbe42685b89786f756097b9..b539b45e432ca233f36113032f4d293964fc46cb 100644 (file)
@@ -45,7 +45,7 @@ NIR_FILES = \
        nir/nir_lower_phis_to_scalar.c \
        nir/nir_lower_samplers.cpp \
        nir/nir_lower_system_values.c \
-       nir/nir_lower_tex_projector.c \
+       nir/nir_lower_tex.c \
        nir/nir_lower_to_source_mods.c \
        nir/nir_lower_vars_to_ssa.c \
        nir/nir_lower_var_copies.c \
index 83e31533e8bf597601339769696d8a4a2f1a47eb..c484d8e81ce43db392901c6e1da0c9ccf65b703b 100644 (file)
@@ -1836,7 +1836,7 @@ void nir_lower_samplers(nir_shader *shader,
                         const struct gl_shader_program *shader_program);
 
 void nir_lower_system_values(nir_shader *shader);
-void nir_lower_tex_projector(nir_shader *shader);
+void nir_lower_tex(nir_shader *shader);
 void nir_lower_idiv(nir_shader *shader);
 
 void nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables);
diff --git a/src/glsl/nir/nir_lower_tex.c b/src/glsl/nir/nir_lower_tex.c
new file mode 100644 (file)
index 0000000..b5ac1b2
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2015 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/*
+ * This lowering pass converts the coordinate division for texture projection
+ * to be done in ALU instructions instead of asking the texture operation to
+ * do so.
+ */
+
+#include "nir.h"
+#include "nir_builder.h"
+
+static bool
+nir_lower_tex_block(nir_block *block, void *void_state)
+{
+   nir_builder *b = void_state;
+
+   nir_foreach_instr_safe(block, instr) {
+      if (instr->type != nir_instr_type_tex)
+         continue;
+
+      nir_tex_instr *tex = nir_instr_as_tex(instr);
+      b->cursor = nir_before_instr(&tex->instr);
+
+      /* Find the projector in the srcs list, if present. */
+      unsigned proj_index;
+      for (proj_index = 0; proj_index < tex->num_srcs; proj_index++) {
+         if (tex->src[proj_index].src_type == nir_tex_src_projector)
+            break;
+      }
+      if (proj_index == tex->num_srcs)
+         continue;
+      nir_ssa_def *inv_proj =
+         nir_frcp(b, nir_ssa_for_src(b, tex->src[proj_index].src, 1));
+
+      /* Walk through the sources projecting the arguments. */
+      for (unsigned i = 0; i < tex->num_srcs; i++) {
+         switch (tex->src[i].src_type) {
+         case nir_tex_src_coord:
+         case nir_tex_src_comparitor:
+            break;
+         default:
+            continue;
+         }
+         nir_ssa_def *unprojected =
+            nir_ssa_for_src(b, tex->src[i].src, nir_tex_instr_src_size(tex, i));
+         nir_ssa_def *projected = nir_fmul(b, unprojected, inv_proj);
+
+         /* Array indices don't get projected, so make an new vector with the
+          * coordinate's array index untouched.
+          */
+         if (tex->is_array && tex->src[i].src_type == nir_tex_src_coord) {
+            switch (tex->coord_components) {
+            case 4:
+               projected = nir_vec4(b,
+                                    nir_channel(b, projected, 0),
+                                    nir_channel(b, projected, 1),
+                                    nir_channel(b, projected, 2),
+                                    nir_channel(b, unprojected, 3));
+               break;
+            case 3:
+               projected = nir_vec3(b,
+                                    nir_channel(b, projected, 0),
+                                    nir_channel(b, projected, 1),
+                                    nir_channel(b, unprojected, 2));
+               break;
+            case 2:
+               projected = nir_vec2(b,
+                                    nir_channel(b, projected, 0),
+                                    nir_channel(b, unprojected, 1));
+               break;
+            default:
+               unreachable("bad texture coord count for array");
+               break;
+            }
+         }
+
+         nir_instr_rewrite_src(&tex->instr,
+                               &tex->src[i].src,
+                               nir_src_for_ssa(projected));
+      }
+
+      /* Now move the later tex sources down the array so that the projector
+       * disappears.
+       */
+      nir_instr_rewrite_src(&tex->instr, &tex->src[proj_index].src,
+                            NIR_SRC_INIT);
+      for (unsigned i = proj_index + 1; i < tex->num_srcs; i++) {
+         tex->src[i-1].src_type = tex->src[i].src_type;
+         nir_instr_move_src(&tex->instr, &tex->src[i-1].src, &tex->src[i].src);
+      }
+      tex->num_srcs--;
+   }
+
+   return true;
+}
+
+static void
+nir_lower_tex_impl(nir_function_impl *impl)
+{
+   nir_builder b;
+   nir_builder_init(&b, impl);
+
+   nir_foreach_block(impl, nir_lower_tex_block, &b);
+
+   nir_metadata_preserve(impl, nir_metadata_block_index |
+                               nir_metadata_dominance);
+}
+
+void
+nir_lower_tex(nir_shader *shader)
+{
+   nir_foreach_overload(shader, overload) {
+      if (overload->impl)
+         nir_lower_tex_impl(overload->impl);
+   }
+}
diff --git a/src/glsl/nir/nir_lower_tex_projector.c b/src/glsl/nir/nir_lower_tex_projector.c
deleted file mode 100644 (file)
index 9afa42f..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright © 2015 Broadcom
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-/*
- * This lowering pass converts the coordinate division for texture projection
- * to be done in ALU instructions instead of asking the texture operation to
- * do so.
- */
-
-#include "nir.h"
-#include "nir_builder.h"
-
-static bool
-nir_lower_tex_projector_block(nir_block *block, void *void_state)
-{
-   nir_builder *b = void_state;
-
-   nir_foreach_instr_safe(block, instr) {
-      if (instr->type != nir_instr_type_tex)
-         continue;
-
-      nir_tex_instr *tex = nir_instr_as_tex(instr);
-      b->cursor = nir_before_instr(&tex->instr);
-
-      /* Find the projector in the srcs list, if present. */
-      unsigned proj_index;
-      for (proj_index = 0; proj_index < tex->num_srcs; proj_index++) {
-         if (tex->src[proj_index].src_type == nir_tex_src_projector)
-            break;
-      }
-      if (proj_index == tex->num_srcs)
-         continue;
-      nir_ssa_def *inv_proj =
-         nir_frcp(b, nir_ssa_for_src(b, tex->src[proj_index].src, 1));
-
-      /* Walk through the sources projecting the arguments. */
-      for (unsigned i = 0; i < tex->num_srcs; i++) {
-         switch (tex->src[i].src_type) {
-         case nir_tex_src_coord:
-         case nir_tex_src_comparitor:
-            break;
-         default:
-            continue;
-         }
-         nir_ssa_def *unprojected =
-            nir_ssa_for_src(b, tex->src[i].src, nir_tex_instr_src_size(tex, i));
-         nir_ssa_def *projected = nir_fmul(b, unprojected, inv_proj);
-
-         /* Array indices don't get projected, so make an new vector with the
-          * coordinate's array index untouched.
-          */
-         if (tex->is_array && tex->src[i].src_type == nir_tex_src_coord) {
-            switch (tex->coord_components) {
-            case 4:
-               projected = nir_vec4(b,
-                                    nir_channel(b, projected, 0),
-                                    nir_channel(b, projected, 1),
-                                    nir_channel(b, projected, 2),
-                                    nir_channel(b, unprojected, 3));
-               break;
-            case 3:
-               projected = nir_vec3(b,
-                                    nir_channel(b, projected, 0),
-                                    nir_channel(b, projected, 1),
-                                    nir_channel(b, unprojected, 2));
-               break;
-            case 2:
-               projected = nir_vec2(b,
-                                    nir_channel(b, projected, 0),
-                                    nir_channel(b, unprojected, 1));
-               break;
-            default:
-               unreachable("bad texture coord count for array");
-               break;
-            }
-         }
-
-         nir_instr_rewrite_src(&tex->instr,
-                               &tex->src[i].src,
-                               nir_src_for_ssa(projected));
-      }
-
-      /* Now move the later tex sources down the array so that the projector
-       * disappears.
-       */
-      nir_instr_rewrite_src(&tex->instr, &tex->src[proj_index].src,
-                            NIR_SRC_INIT);
-      for (unsigned i = proj_index + 1; i < tex->num_srcs; i++) {
-         tex->src[i-1].src_type = tex->src[i].src_type;
-         nir_instr_move_src(&tex->instr, &tex->src[i-1].src, &tex->src[i].src);
-      }
-      tex->num_srcs--;
-   }
-
-   return true;
-}
-
-static void
-nir_lower_tex_projector_impl(nir_function_impl *impl)
-{
-   nir_builder b;
-   nir_builder_init(&b, impl);
-
-   nir_foreach_block(impl, nir_lower_tex_projector_block, &b);
-
-   nir_metadata_preserve(impl, nir_metadata_block_index |
-                               nir_metadata_dominance);
-}
-
-void
-nir_lower_tex_projector(nir_shader *shader)
-{
-   nir_foreach_overload(shader, overload) {
-      if (overload->impl)
-         nir_lower_tex_projector_impl(overload->impl);
-   }
-}
index 9a0bbb068478ef566eaa1bd9ab504bc37d5968db..0d5b6dd7291c2ad0de5eb66eb520806cbaefba89 100644 (file)
@@ -96,7 +96,7 @@ brw_create_nir(struct brw_context *brw,
    nir_lower_global_vars_to_local(nir);
    nir_validate_shader(nir);
 
-   nir_lower_tex_projector(nir);
+   nir_lower_tex(nir);
    nir_validate_shader(nir);
 
    nir_normalize_cubemap_coords(nir);