vc4: Add support for loading immediate values in QIR.
authorEric Anholt <eric@anholt.net>
Fri, 6 May 2016 01:04:14 +0000 (18:04 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 6 May 2016 17:25:55 +0000 (10:25 -0700)
This will be used for resetting the uniform stream in the presence of
branching, but may also be useful as an optimization to reduce how many
uniforms we have to copy out per draw call (in exchange for increasing
icache pressure).

src/gallium/drivers/vc4/vc4_qir.c
src/gallium/drivers/vc4/vc4_qir.h
src/gallium/drivers/vc4/vc4_qir_validate.c
src/gallium/drivers/vc4/vc4_qpu_emit.c

index 86a7ae023c1d86f44d7962330e6d5a99495654f5..b9676adb3afe86e8a0ded335b4ba44df8ff1c904 100644 (file)
@@ -81,6 +81,8 @@ static const struct qir_op_info qir_op_info[] = {
         [QOP_TEX_B] = { "tex_b", 0, 2 },
         [QOP_TEX_DIRECT] = { "tex_direct", 0, 2 },
         [QOP_TEX_RESULT] = { "tex_result", 1, 0, true },
+
+        [QOP_LOAD_IMM] = { "load_imm", 0, 1 },
 };
 
 static const char *
@@ -244,6 +246,10 @@ qir_print_reg(struct vc4_compile *c, struct qreg reg, bool write)
                 fprintf(stderr, "null");
                 break;
 
+        case QFILE_LOAD_IMM:
+                fprintf(stderr, "0x%08x (%f)", reg.index, uif(reg.index));
+                break;
+
         case QFILE_SMALL_IMM:
                 if ((int)reg.index >= -16 && (int)reg.index <= 15)
                         fprintf(stderr, "%d", reg.index);
index d1263b64362f51be80c7414d7e4f723f4c1da2b5..f541c754c8858ed5f512b6064f5210de7c3ceed3 100644 (file)
@@ -61,6 +61,12 @@ enum qfile {
         QFILE_FRAG_Y,
         QFILE_FRAG_REV_FLAG,
 
+        /**
+         * Stores an immediate value in the index field that will be used
+         * directly by qpu_load_imm().
+         */
+        QFILE_LOAD_IMM,
+
         /**
          * Stores an immediate value in the index field that can be turned
          * into a small immediate field by qpu_encode_small_immediate().
@@ -147,6 +153,8 @@ enum qop {
          * the destination
          */
         QOP_TEX_RESULT,
+
+        QOP_LOAD_IMM,
 };
 
 struct queued_qpu_inst {
@@ -721,4 +729,13 @@ qir_VPM_WRITE(struct vc4_compile *c, struct qreg val)
         qir_MOV_dest(c, qir_reg(QFILE_VPM, 0), val);
 }
 
+static inline struct qreg
+qir_LOAD_IMM(struct vc4_compile *c, uint32_t val)
+{
+        struct qreg t = qir_get_temp(c);
+        qir_emit(c, qir_inst(QOP_LOAD_IMM, t,
+                             qir_reg(QFILE_LOAD_IMM, val), c->undef));
+        return t;
+}
+
 #endif /* VC4_QIR_H */
index f41cd634027a1eb748987620b4f0e191397df50a..af2e3baf8156d3b3669e31cb6b87ee249788da1f 100644 (file)
@@ -80,6 +80,7 @@ void qir_validate(struct vc4_compile *c)
                 case QFILE_FRAG_Y:
                 case QFILE_FRAG_REV_FLAG:
                 case QFILE_SMALL_IMM:
+                case QFILE_LOAD_IMM:
                         fail_instr(inst, "Bad dest file");
                         break;
                 }
@@ -96,6 +97,7 @@ void qir_validate(struct vc4_compile *c)
                         case QFILE_VARY:
                         case QFILE_UNIF:
                         case QFILE_VPM:
+                        case QFILE_LOAD_IMM:
                                 break;
 
                         case QFILE_SMALL_IMM:
index ecb70948ece5b3b157cd37f8ba51ed415d3334ec..794757e6d189e46a3e59dd6f22cc13e2dd65930a 100644 (file)
@@ -267,6 +267,7 @@ vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c)
                         int index = qinst->src[i].index;
                         switch (qinst->src[i].file) {
                         case QFILE_NULL:
+                        case QFILE_LOAD_IMM:
                                 src[i] = qpu_rn(0);
                                 break;
                         case QFILE_TEMP:
@@ -351,6 +352,7 @@ vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c)
                 case QFILE_VARY:
                 case QFILE_UNIF:
                 case QFILE_SMALL_IMM:
+                case QFILE_LOAD_IMM:
                 case QFILE_FRAG_X:
                 case QFILE_FRAG_Y:
                 case QFILE_FRAG_REV_FLAG:
@@ -390,6 +392,11 @@ vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c)
 
                         break;
 
+                case QOP_LOAD_IMM:
+                        assert(qinst->src[0].file == QFILE_LOAD_IMM);
+                        queue(c, qpu_load_imm_ui(dst, qinst->src[0].index));
+                        break;
+
                 case QOP_MS_MASK:
                         src[1] = qpu_ra(QPU_R_MS_REV_FLAGS);
                         fixup_raddr_conflict(c, dst, &src[0], &src[1],