[Mesa-dev] [PATCH 19/29] nir: fix up bit sizes for undefined alu sources

Samuel Iglesias Gonsálvez siglesias at igalia.com
Mon Mar 21 12:05:58 UTC 2016


From: Iago Toral Quiroga <itoral at igalia.com>

Undefined sources in alu operations don't have a valid bit size because
they are uninitialized. Simply ignoring undefined sources for bit size
validation is not enough since drivers can check and operate with the
bit-size and that can lead to issues later on. Instead, fix undefined
sources to always have a compatible bit size.

v2 (Sam):
- Use helper to get type size from nir_alu_type.
---
 src/compiler/nir/nir_validate.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 9f18d1c..645c15a 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -180,9 +180,11 @@ validate_alu_src(nir_alu_instr *instr, unsigned index, validate_state *state)
 
    unsigned num_components;
    unsigned src_bit_size;
+   bool is_undef = false;
    if (src->src.is_ssa) {
       src_bit_size = src->src.ssa->bit_size;
       num_components = src->src.ssa->num_components;
+      is_undef = src->src.ssa->parent_instr->type == nir_instr_type_ssa_undef;
    } else {
       src_bit_size = src->src.reg.reg->bit_size;
       if (src->src.reg.reg->is_packed)
@@ -205,12 +207,20 @@ validate_alu_src(nir_alu_instr *instr, unsigned index, validate_state *state)
 
    if (nir_alu_type_get_type_size(src_type)) {
       /* This source has an explicit bit size */
+      if (is_undef) {
+         src_bit_size = nir_alu_type_get_type_size(src_type);
+         src->src.ssa->bit_size = src_bit_size;
+      }
       assert(nir_alu_type_get_type_size(src_type) == src_bit_size);
    } else {
       if (!nir_alu_type_get_type_size(nir_op_infos[instr->op].output_type)) {
          unsigned dest_bit_size =
             instr->dest.dest.is_ssa ? instr->dest.dest.ssa.bit_size
                                     : instr->dest.dest.reg.reg->bit_size;
+         if (is_undef) {
+            src_bit_size = dest_bit_size;
+            src->src.ssa->bit_size = dest_bit_size;
+         }
          assert(dest_bit_size == src_bit_size);
       }
    }
-- 
2.5.0



More information about the mesa-dev mailing list