Mesa (main): glsl: Add ir_assignment constructor that takes just a write mask

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Feb 11 17:59:12 UTC 2022


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Jan 14 17:38:05 2022 -0800

glsl: Add ir_assignment constructor that takes just a write mask

The other constructor that takes a write mask and a condition will be
removed shortly.

Reviewed-by: Matt Turner <mattst88 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14573>

---

 src/compiler/glsl/ast_function.cpp        | 15 +++++++--------
 src/compiler/glsl/ir.cpp                  | 14 ++++++++++++++
 src/compiler/glsl/ir.h                    |  2 ++
 src/compiler/glsl/ir_builder.cpp          |  1 -
 src/compiler/glsl/lower_mat_op_to_vec.cpp |  2 +-
 src/compiler/glsl/lower_vector.cpp        |  4 ++--
 6 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp
index 01ad88417ed..f1c9ee99d85 100644
--- a/src/compiler/glsl/ast_function.cpp
+++ b/src/compiler/glsl/ast_function.cpp
@@ -1265,8 +1265,7 @@ process_vec_mat_constructor(exec_list *instructions,
          assert(var->type->is_vector());
          assert(i < 4);
          ir_dereference *lhs = new(ctx) ir_dereference_variable(var);
-         assignment = new(ctx) ir_assignment(lhs, rhs, NULL,
-                                             (unsigned)(1 << i));
+         assignment = new(ctx) ir_assignment(lhs, rhs, 1u << i);
       }
 
       instructions->push_tail(assignment);
@@ -1463,7 +1462,7 @@ emit_inline_vector_constructor(const glsl_type *type,
 
       assert(rhs->type == lhs->type);
 
-      ir_instruction *inst = new(ctx) ir_assignment(lhs, rhs, NULL, mask);
+      ir_instruction *inst = new(ctx) ir_assignment(lhs, rhs, mask);
       instructions->push_tail(inst);
    } else {
       unsigned base_component = 0;
@@ -1533,7 +1532,7 @@ emit_inline_vector_constructor(const glsl_type *type,
          ir_rvalue *rhs = new(ctx) ir_constant(rhs_type, &data);
 
          ir_instruction *inst =
-            new(ctx) ir_assignment(lhs, rhs, NULL, constant_mask);
+            new(ctx) ir_assignment(lhs, rhs, constant_mask);
          instructions->push_tail(inst);
       }
 
@@ -1567,7 +1566,7 @@ emit_inline_vector_constructor(const glsl_type *type,
                new(ctx) ir_swizzle(param, 0, 1, 2, 3, rhs_components);
 
             ir_instruction *inst =
-               new(ctx) ir_assignment(lhs, rhs, NULL, write_mask);
+               new(ctx) ir_assignment(lhs, rhs, write_mask);
             instructions->push_tail(inst);
          }
 
@@ -1618,7 +1617,7 @@ assign_to_matrix_column(ir_variable *var, unsigned column, unsigned row_base,
    /* Mask of fields to be written in the assignment. */
    const unsigned write_mask = ((1U << count) - 1) << row_base;
 
-   return new(mem_ctx) ir_assignment(column_ref, src, NULL, write_mask);
+   return new(mem_ctx) ir_assignment(column_ref, src, write_mask);
 }
 
 
@@ -1686,7 +1685,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
       ir_dereference *const rhs_ref =
          new(ctx) ir_dereference_variable(rhs_var);
 
-      inst = new(ctx) ir_assignment(rhs_ref, first_param, NULL, 0x01);
+      inst = new(ctx) ir_assignment(rhs_ref, first_param, 0x01);
       instructions->push_tail(inst);
 
       /* Assign the temporary vector to each column of the destination matrix
@@ -1835,7 +1834,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
          }
 
          ir_instruction *inst =
-            new(ctx) ir_assignment(lhs, rhs, NULL, write_mask);
+            new(ctx) ir_assignment(lhs, rhs, write_mask);
          instructions->push_tail(inst);
       }
    } else {
diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 2035aef1e59..8eda95eaf53 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -23,6 +23,7 @@
 #include <string.h>
 #include "ir.h"
 #include "util/half_float.h"
+#include "util/bitscan.h"
 #include "compiler/glsl_types.h"
 #include "glsl_parser_extras.h"
 
@@ -168,6 +169,19 @@ ir_assignment::ir_assignment(ir_dereference *lhs, ir_rvalue *rhs,
    }
 }
 
+ir_assignment::ir_assignment(ir_dereference *lhs, ir_rvalue *rhs,
+                             unsigned write_mask)
+   : ir_instruction(ir_type_assignment)
+{
+   this->condition = NULL;
+   this->rhs = rhs;
+   this->lhs = lhs;
+   this->write_mask = write_mask;
+
+   if (lhs->type->is_scalar() || lhs->type->is_vector())
+      assert(util_bitcount(write_mask) == this->rhs->type->vector_elements);
+}
+
 ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
 			     ir_rvalue *condition)
    : ir_instruction(ir_type_assignment)
diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index e8097728cb2..b53f216ee9e 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -1475,6 +1475,8 @@ public:
    ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, ir_rvalue *condition,
 		 unsigned write_mask);
 
+   ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, unsigned write_mask);
+
    virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const;
 
    virtual ir_constant *constant_expression_value(void *mem_ctx,
diff --git a/src/compiler/glsl/ir_builder.cpp b/src/compiler/glsl/ir_builder.cpp
index 998fea1e464..770ba692efd 100644
--- a/src/compiler/glsl/ir_builder.cpp
+++ b/src/compiler/glsl/ir_builder.cpp
@@ -58,7 +58,6 @@ assign(deref lhs, operand rhs, int writemask)
 
    ir_assignment *assign = new(mem_ctx) ir_assignment(lhs.val,
                                                       rhs.val,
-                                                      NULL,
                                                       writemask);
 
    return assign;
diff --git a/src/compiler/glsl/lower_mat_op_to_vec.cpp b/src/compiler/glsl/lower_mat_op_to_vec.cpp
index 13d3ccbaddb..10e006c8381 100644
--- a/src/compiler/glsl/lower_mat_op_to_vec.cpp
+++ b/src/compiler/glsl/lower_mat_op_to_vec.cpp
@@ -271,7 +271,7 @@ ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_dereference *result,
 	 new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
 
       ir_assignment *const assign =
-	 new(this->mem_ctx) ir_assignment(lhs, cmp, NULL, (1U << i));
+         new(this->mem_ctx) ir_assignment(lhs, cmp, 1U << i);
 
       this->base_ir->insert_before(assign);
    }
diff --git a/src/compiler/glsl/lower_vector.cpp b/src/compiler/glsl/lower_vector.cpp
index 4024644b062..fc5a6f2aa72 100644
--- a/src/compiler/glsl/lower_vector.cpp
+++ b/src/compiler/glsl/lower_vector.cpp
@@ -191,7 +191,7 @@ lower_vector_visitor::handle_rvalue(ir_rvalue **rvalue)
 				  &d);
       ir_dereference *const lhs = new(mem_ctx) ir_dereference_variable(temp);
       ir_assignment *const assign =
-	 new(mem_ctx) ir_assignment(lhs, c, NULL, write_mask);
+	 new(mem_ctx) ir_assignment(lhs, c, write_mask);
 
       this->base_ir->insert_before(assign);
    }
@@ -204,7 +204,7 @@ lower_vector_visitor::handle_rvalue(ir_rvalue **rvalue)
 
       ir_dereference *const lhs = new(mem_ctx) ir_dereference_variable(temp);
       ir_assignment *const assign =
-	 new(mem_ctx) ir_assignment(lhs, expr->operands[i], NULL, (1U << i));
+	 new(mem_ctx) ir_assignment(lhs, expr->operands[i], 1U << i);
 
       this->base_ir->insert_before(assign);
       assigned++;



More information about the mesa-commit mailing list