[Mesa-dev] [PATCH v2 9/9] vc4/nir: Use the new unified io intrinsics

Jason Ekstrand jason at jlekstrand.net
Fri Dec 4 15:12:03 PST 2015


Cc: Eric Anholt <eric at anholt.net>
---
 src/gallium/drivers/vc4/vc4_nir_lower_io.c | 16 ++++++---------
 src/gallium/drivers/vc4/vc4_program.c      | 31 ++++++++++++++++--------------
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_nir_lower_io.c b/src/gallium/drivers/vc4/vc4_nir_lower_io.c
index e2581c8..ba05797 100644
--- a/src/gallium/drivers/vc4/vc4_nir_lower_io.c
+++ b/src/gallium/drivers/vc4/vc4_nir_lower_io.c
@@ -358,15 +358,12 @@ vc4_nir_lower_uniform(struct vc4_compile *c, nir_builder *b,
                 /* Convert the base offset to bytes and add the component */
                 intr_comp->const_index[0] = (intr->const_index[0] * 16 + i * 4);
 
-                if (intr->intrinsic == nir_intrinsic_load_uniform_indirect) {
-                        /* Convert the variable TGSI register index to a byte
-                         * offset.
-                         */
-                        intr_comp->src[0] =
-                                nir_src_for_ssa(nir_ishl(b,
-                                                         intr->src[0].ssa,
-                                                         nir_imm_int(b, 4)));
-                }
+                /* Convert the offset to bytes.  If it happens to be a
+                 * constant, constant-folding will clean up the shift for us.
+                 */
+                intr_comp->src[0] =
+                        nir_src_for_ssa(nir_ishl(b, intr->src[0].ssa,
+                                                 nir_imm_int(b, 4)));
 
                 dests[i] = &intr_comp->dest.ssa;
 
@@ -397,7 +394,6 @@ vc4_nir_lower_io_instr(struct vc4_compile *c, nir_builder *b,
                 break;
 
         case nir_intrinsic_load_uniform:
-        case nir_intrinsic_load_uniform_indirect:
         case nir_intrinsic_load_user_clip_plane:
                 vc4_nir_lower_uniform(c, b, intr);
                 break;
diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index 1a45bac..1423d6e 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -1433,7 +1433,7 @@ static void
 ntq_emit_intrinsic(struct vc4_compile *c, nir_intrinsic_instr *instr)
 {
         const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
-        int dword_offset;
+        nir_const_value *const_offset;
         struct qreg *dest = NULL;
 
         if (info->has_dest) {
@@ -1443,23 +1443,26 @@ ntq_emit_intrinsic(struct vc4_compile *c, nir_intrinsic_instr *instr)
         switch (instr->intrinsic) {
         case nir_intrinsic_load_uniform:
                 assert(instr->num_components == 1);
-                /* The offset is in bytes, but we need dwords */
-                assert(instr->const_index[0] % 4 == 0);
-                dword_offset = instr->const_index[0] / 4;
-                if (dword_offset < VC4_NIR_STATE_UNIFORM_OFFSET) {
-                        *dest = qir_uniform(c, QUNIFORM_UNIFORM, dword_offset);
+                const_offset = nir_src_as_const_value(instr->src[0]);
+                if (const_offset) {
+                        unsigned offset = const_offset->u[0] +
+                                          instr->const_index[0];
+                        assert(offset % 4 == 0);
+                        /* We need dwords */
+                        offset = offset / 4;
+                        if (offset < VC4_NIR_STATE_UNIFORM_OFFSET) {
+                                *dest = qir_uniform(c, QUNIFORM_UNIFORM,
+                                                    offset);
+                        } else {
+                                *dest = qir_uniform(c, offset -
+                                                    VC4_NIR_STATE_UNIFORM_OFFSET,
+                                                    0);
+                        }
                 } else {
-                        *dest = qir_uniform(c, dword_offset -
-                                            VC4_NIR_STATE_UNIFORM_OFFSET,
-                                            0);
+                        *dest = indirect_uniform_load(c, instr);
                 }
                 break;
 
-        case nir_intrinsic_load_uniform_indirect:
-                *dest = indirect_uniform_load(c, instr);
-
-                break;
-
         case nir_intrinsic_load_user_clip_plane:
                 *dest = qir_uniform(c, QUNIFORM_USER_CLIP_PLANE,
                                     instr->const_index[0]);
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list