vc4: Add support for loading immediate values in QIR.

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).
This commit is contained in:
Eric Anholt 2016-05-05 18:04:14 -07:00
parent 890dc19eeb
commit a1f698881e
4 changed files with 32 additions and 0 deletions

View 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);

View 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 */

View 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:

View 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],