nir: Allow for system values with variable numbers of destination components
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 14 Jul 2020 18:27:53 +0000 (13:27 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 22 Jul 2020 23:43:35 +0000 (23:43 +0000)
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5927>

src/compiler/nir/nir_builder_opcodes_h.py
src/compiler/nir/nir_lower_system_values.c
src/gallium/drivers/vc4/vc4_nir_lower_blend.c

index ec212f4e30957dc1f3cef45a790324b1b3d632d7..2c37be7c20ee7f5e65ea8528f09b18a7468fb6aa 100644 (file)
@@ -53,12 +53,17 @@ nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
 /* Generic builder for system values. */
 static inline nir_ssa_def *
 nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index,
-                      unsigned bit_size)
+                      unsigned num_components, unsigned bit_size)
 {
    nir_intrinsic_instr *load = nir_intrinsic_instr_create(build->shader, op);
+   if (nir_intrinsic_infos[op].dest_components > 0)
+      assert(num_components == nir_intrinsic_infos[op].dest_components);
+   else
+      load->num_components = num_components;
    load->const_index[0] = index;
+
    nir_ssa_dest_init(&load->instr, &load->dest,
-                     nir_intrinsic_infos[op].dest_components, bit_size, NULL);
+                     num_components, bit_size, NULL);
    nir_builder_instr_insert(build, &load->instr);
    return &load->dest.ssa;
 }
@@ -68,6 +73,8 @@ def sysval_decl_list(opcode):
    res = ''
    if opcode.indices:
       res += ', unsigned ' + opcode.indices[0].lower()
+   if opcode.dest_components == 0:
+      res += ', unsigned num_components'
    if len(opcode.bit_sizes) != 1:
       res += ', unsigned bit_size'
    return res
@@ -79,6 +86,11 @@ def sysval_arg_list(opcode):
    else:
       args.append('0')
 
+   if opcode.dest_components == 0:
+      args.append('num_components')
+   else:
+      args.append(str(opcode.dest_components))
+
    if len(opcode.bit_sizes) == 1:
       bit_size = opcode.bit_sizes[0]
       args.append(str(bit_size))
index bc9d23cf52d4e7f06864b7764b001cd38dac0a6a..bdc337aecfc912ed9ae3b088426a9e6d86f883d1 100644 (file)
@@ -305,6 +305,7 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state)
       nir_intrinsic_op sysval_op =
          nir_intrinsic_from_system_value(var->data.location);
       return nir_load_system_value(b, sysval_op, 0,
+                                      intrin->dest.ssa.num_components,
                                       intrin->dest.ssa.bit_size);
    }
 
index c915b8c5089bfae7474d2221c5f24c0436179a9c..192abe99291a741fbd5b87eaa187a01b7d68b1e3 100644 (file)
@@ -100,7 +100,7 @@ vc4_blend_channel_f(nir_builder *b,
                 return nir_load_system_value(b,
                                              nir_intrinsic_load_blend_const_color_r_float +
                                              channel,
-                                             0, 32);
+                                             0, 1, 32);
         case PIPE_BLENDFACTOR_CONST_ALPHA:
                 return nir_load_blend_const_color_a_float(b);
         case PIPE_BLENDFACTOR_ZERO:
@@ -118,7 +118,7 @@ vc4_blend_channel_f(nir_builder *b,
                                 nir_load_system_value(b,
                                                       nir_intrinsic_load_blend_const_color_r_float +
                                                       channel,
-                                                      0, 32));
+                                                      0, 1, 32));
         case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
                 return nir_fsub(b, nir_imm_float(b, 1.0),
                                 nir_load_blend_const_color_a_float(b));