nir: add bit_size parameter to system values with multiple allowed bit sizes
authorKarol Herbst <kherbst@redhat.com>
Tue, 4 Dec 2018 15:40:30 +0000 (16:40 +0100)
committerKarol Herbst <kherbst@redhat.com>
Sun, 20 Jan 2019 23:17:18 +0000 (00:17 +0100)
v2: add assert to verify we have at least one valid bit_size
v3: fix use of load_front_face in nir_lower_two_sided_color and tgsi_to_nir

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/compiler/nir/nir_builder_opcodes_h.py
src/compiler/nir/nir_lower_system_values.c
src/compiler/nir/nir_lower_two_sided_color.c
src/gallium/auxiliary/nir/tgsi_to_nir.c
src/gallium/drivers/vc4/vc4_nir_lower_blend.c

index 34b8c4371e1164deed1f5293e83a85b2eaf73c4d..53fb23ca2b351cba113854c3cf14d4973d811629 100644 (file)
@@ -44,13 +44,14 @@ 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)
+nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index,
+                      unsigned bit_size)
 {
    nir_intrinsic_instr *load = nir_intrinsic_instr_create(build->shader, op);
    load->num_components = nir_intrinsic_infos[op].dest_components;
    load->const_index[0] = index;
    nir_ssa_dest_init(&load->instr, &load->dest,
-                     nir_intrinsic_infos[op].dest_components, 32, NULL);
+                     nir_intrinsic_infos[op].dest_components, bit_size, NULL);
    nir_builder_instr_insert(build, &load->instr);
    return &load->dest.ssa;
 }
@@ -60,6 +61,8 @@ def sysval_decl_list(opcode):
    res = ''
    if opcode.indices:
       res += ', unsigned ' + opcode.indices[0].lower()
+   if len(opcode.bit_sizes) != 1:
+      res += ', unsigned bit_size'
    return res
 
 def sysval_arg_list(opcode):
@@ -68,10 +71,18 @@ def sysval_arg_list(opcode):
       args.append(opcode.indices[0].lower())
    else:
       args.append('0')
+
+   if len(opcode.bit_sizes) == 1:
+      bit_size = opcode.bit_sizes[0]
+      args.append(str(bit_size))
+   else:
+      args.append('bit_size')
+
    return ', '.join(args)
 %>
 
 % for name, opcode in filter(lambda v: v[1].sysval, sorted(INTR_OPCODES.items())):
+<% assert len(opcode.bit_sizes) > 0 %>
 static inline nir_ssa_def *
 nir_${name}(nir_builder *build${sysval_decl_list(opcode)})
 {
index 08a9e8be44a96a4d983b730a417fc1bfdcab38cc..68b0ea89c8d52b7fa7e212e18baab2df03251b68 100644 (file)
@@ -261,8 +261,8 @@ convert_block(nir_block *block, nir_builder *b)
       if (sysval == NULL) {
          nir_intrinsic_op sysval_op =
             nir_intrinsic_from_system_value(var->data.location);
-         sysval = nir_load_system_value(b, sysval_op, 0);
-         sysval->bit_size = load_deref->dest.ssa.bit_size;
+         sysval = nir_load_system_value(b, sysval_op, 0,
+                                        load_deref->dest.ssa.bit_size);
       }
 
       nir_ssa_def_rewrite_uses(&load_deref->dest.ssa, nir_src_for_ssa(sysval));
index 437dd5fb74518c614a5875c104add536c1ab9330..d1eb32a18876bd699c6e10405cb61952f7e7302e 100644 (file)
@@ -158,11 +158,10 @@ nir_lower_two_sided_color_block(nir_block *block,
        * bcsel(load_system_value(FACE), load_input(COLn), load_input(BFCn))
        */
       b->cursor = nir_before_instr(&intr->instr);
-      nir_ssa_def *face = nir_load_front_face(b);
       /* gl_FrontFace is a boolean but the intrinsic constructor creates
        * 32-bit value by default.
        */
-      face->bit_size = 1;
+      nir_ssa_def *face = nir_load_front_face(b, 1);
       nir_ssa_def *front = load_input(b, state->colors[idx].front);
       nir_ssa_def *back  = load_input(b, state->colors[idx].back);
       nir_ssa_def *color = nir_bcsel(b, face, front, back);
index 000109621d8642f6254e0b39a1329c4a113d5c17..10e24387849b090cafc3b610f602223f8baa64f6 100644 (file)
@@ -516,7 +516,7 @@ ttn_src_for_file_and_index(struct ttn_compile *c, unsigned file, unsigned index,
           c->scan->input_semantic_name[index] == TGSI_SEMANTIC_FACE) {
          nir_ssa_def *tgsi_frontface[4] = {
             nir_bcsel(&c->build,
-                      nir_load_front_face(&c->build),
+                      nir_load_front_face(&c->build, 1),
                       nir_imm_float(&c->build, 1.0),
                       nir_imm_float(&c->build, -1.0)),
             nir_imm_float(&c->build, 0.0),
index 67ae05d4f610d6a75ce937a18e010e8f7847af72..ff6268f478a3929e14657bab11a5686b2a19d2cd 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);
+                                             0, 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));
+                                                      0, 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));