Module: Mesa
Branch: main
Commit: a31c54720649a1c11db3fea5c8f89abd523b537b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a31c54720649a1c11db3fea5c8f89abd523b537b

Author: Timothy Arceri <[email protected]>
Date:   Mon Oct 17 15:28:26 2022 +1100

glsl: move rule inside lower_packing_builtins()

We only have a single user of this pass so lets tidy things up and
move all the rules in the pass itself.

Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19112>

---

 src/compiler/glsl/ir_optimization.h          | 30 +++---------------
 src/compiler/glsl/lower_packing_builtins.cpp | 47 ++++++++++++++++++++++++++--
 src/mesa/state_tracker/st_glsl_to_ir.cpp     | 23 ++------------
 3 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h 
b/src/compiler/glsl/ir_optimization.h
index 5cd96c9bf95..6ed0434cbba 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -53,31 +53,6 @@ struct gl_shader_program;
 #define DIV64                     (1U << 0)
 #define MOD64                     (1U << 1)
 
-/**
- * \see class lower_packing_builtins_visitor
- */
-enum lower_packing_builtins_op {
-   LOWER_PACK_UNPACK_NONE               = 0x0000,
-
-   LOWER_PACK_SNORM_2x16                = 0x0001,
-   LOWER_UNPACK_SNORM_2x16              = 0x0002,
-
-   LOWER_PACK_UNORM_2x16                = 0x0004,
-   LOWER_UNPACK_UNORM_2x16              = 0x0008,
-
-   LOWER_PACK_HALF_2x16                 = 0x0010,
-   LOWER_UNPACK_HALF_2x16               = 0x0020,
-
-   LOWER_PACK_SNORM_4x8                 = 0x0040,
-   LOWER_UNPACK_SNORM_4x8               = 0x0080,
-
-   LOWER_PACK_UNORM_4x8                 = 0x0100,
-   LOWER_UNPACK_UNORM_4x8               = 0x0200,
-
-   LOWER_PACK_USE_BFI                   = 0x0400,
-   LOWER_PACK_USE_BFE                   = 0x0800,
-};
-
 bool do_common_optimization(exec_list *ir, bool linked,
                             const struct gl_shader_compiler_options *options,
                             bool native_integers);
@@ -110,7 +85,10 @@ void lower_discard_flow(exec_list *instructions);
 bool lower_instructions(exec_list *instructions, unsigned what_to_lower);
 bool lower_clip_cull_distance(struct gl_shader_program *prog,
                               gl_linked_shader *shader);
-bool lower_packing_builtins(exec_list *instructions, int op_mask);
+bool lower_packing_builtins(exec_list *instructions,
+                            bool has_shading_language_packing,
+                            bool has_gpu_shader5,
+                            bool has_half_float_packing);
 bool lower_vector_insert(exec_list *instructions, bool 
lower_nonconstant_index);
 bool lower_vector_derefs(gl_linked_shader *shader);
 void lower_named_interface_blocks(void *mem_ctx, gl_linked_shader *shader);
diff --git a/src/compiler/glsl/lower_packing_builtins.cpp 
b/src/compiler/glsl/lower_packing_builtins.cpp
index a41627bd561..caa75e41c3d 100644
--- a/src/compiler/glsl/lower_packing_builtins.cpp
+++ b/src/compiler/glsl/lower_packing_builtins.cpp
@@ -26,6 +26,28 @@
 #include "ir_optimization.h"
 #include "ir_rvalue_visitor.h"
 
+enum lower_packing_builtins_op {
+   LOWER_PACK_UNPACK_NONE               = 0x0000,
+
+   LOWER_PACK_SNORM_2x16                = 0x0001,
+   LOWER_UNPACK_SNORM_2x16              = 0x0002,
+
+   LOWER_PACK_UNORM_2x16                = 0x0004,
+   LOWER_UNPACK_UNORM_2x16              = 0x0008,
+
+   LOWER_PACK_HALF_2x16                 = 0x0010,
+   LOWER_UNPACK_HALF_2x16               = 0x0020,
+
+   LOWER_PACK_SNORM_4x8                 = 0x0040,
+   LOWER_UNPACK_SNORM_4x8               = 0x0080,
+
+   LOWER_PACK_UNORM_4x8                 = 0x0100,
+   LOWER_UNPACK_UNORM_4x8               = 0x0200,
+
+   LOWER_PACK_USE_BFI                   = 0x0400,
+   LOWER_PACK_USE_BFE                   = 0x0800,
+};
+
 namespace {
 
 using namespace ir_builder;
@@ -1299,12 +1321,31 @@ private:
 
 /**
  * \brief Lower the builtin packing functions.
- *
- * \param op_mask is a bitmask of `enum lower_packing_builtins_op`.
  */
 bool
-lower_packing_builtins(exec_list *instructions, int op_mask)
+lower_packing_builtins(exec_list *instructions,
+                       bool has_shading_language_packing,
+                       bool has_gpu_shader5,
+                       bool has_half_float_packing)
 {
+   if (!has_shading_language_packing)
+      return false;
+
+   int op_mask = LOWER_PACK_SNORM_2x16 |
+                 LOWER_UNPACK_SNORM_2x16 |
+                 LOWER_PACK_UNORM_2x16 |
+                 LOWER_UNPACK_UNORM_2x16 |
+                 LOWER_PACK_SNORM_4x8 |
+                 LOWER_UNPACK_SNORM_4x8 |
+                 LOWER_UNPACK_UNORM_4x8 |
+                 LOWER_PACK_UNORM_4x8;
+
+   if (has_gpu_shader5)
+      op_mask |= LOWER_PACK_USE_BFI | LOWER_PACK_USE_BFE;
+
+   if (!has_half_float_packing)
+      op_mask |= LOWER_PACK_HALF_2x16 | LOWER_UNPACK_HALF_2x16;
+
    lower_packing_builtins_visitor v(op_mask);
    visit_list_elements(&v, instructions, true);
    return v.get_progress();
diff --git a/src/mesa/state_tracker/st_glsl_to_ir.cpp 
b/src/mesa/state_tracker/st_glsl_to_ir.cpp
index 006f5de568e..2d27c1f7417 100644
--- a/src/mesa/state_tracker/st_glsl_to_ir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_ir.cpp
@@ -74,26 +74,9 @@ link_shader(struct gl_context *ctx, struct gl_shader_program 
*prog)
       if (!pscreen->get_param(pscreen, PIPE_CAP_INT64_DIVMOD))
          lower_64bit_integer_instructions(ir, DIV64 | MOD64);
 
-      if (ctx->Extensions.ARB_shading_language_packing) {
-         unsigned lower_inst = LOWER_PACK_SNORM_2x16 |
-                               LOWER_UNPACK_SNORM_2x16 |
-                               LOWER_PACK_UNORM_2x16 |
-                               LOWER_UNPACK_UNORM_2x16 |
-                               LOWER_PACK_SNORM_4x8 |
-                               LOWER_UNPACK_SNORM_4x8 |
-                               LOWER_UNPACK_UNORM_4x8 |
-                               LOWER_PACK_UNORM_4x8;
-
-         if (ctx->Extensions.ARB_gpu_shader5)
-            lower_inst |= LOWER_PACK_USE_BFI |
-                          LOWER_PACK_USE_BFE;
-         if (!ctx->st->has_half_float_packing)
-            lower_inst |= LOWER_PACK_HALF_2x16 |
-                          LOWER_UNPACK_HALF_2x16;
-
-         lower_packing_builtins(ir, lower_inst);
-      }
-
+      lower_packing_builtins(ir, ctx->Extensions.ARB_shading_language_packing,
+                             ctx->Extensions.ARB_gpu_shader5,
+                             ctx->st->has_half_float_packing);
       do_mat_op_to_vec(ir);
 
       if (stage == MESA_SHADER_FRAGMENT && pscreen->get_param(pscreen, 
PIPE_CAP_FBFETCH))

Reply via email to