#include "instr-a3xx.h"
#include "ir-a3xx.h"
-/* ************************************************************************* */
-/* split the out or find some helper to use.. like main/bitset.h.. */
-
-#define MAX_REG 256
-
-typedef uint8_t regmask_t[2 * MAX_REG / 8];
-
-static unsigned regmask_idx(struct ir3_register *reg)
-{
- unsigned num = reg->num;
- assert(num < MAX_REG);
- if (reg->flags & IR3_REG_HALF)
- num += MAX_REG;
- return num;
-}
-
-static void regmask_set(regmask_t regmask, struct ir3_register *reg,
- unsigned wrmask)
-{
- unsigned ridx = regmask_idx(reg) & ~0x3;
- unsigned i;
- for (i = 0; i < 4; i++) {
- if (wrmask & (1 << i)) {
- unsigned idx = ridx + i;
- regmask[idx / 8] |= 1 << (idx % 8);
- }
- }
-}
-
-static unsigned regmask_get(regmask_t regmask, struct ir3_register *reg)
-{
- unsigned idx = regmask_idx(reg);
- return regmask[idx / 8] & (1 << (idx % 8));
-}
-
-/* ************************************************************************* */
struct fd3_compile_context {
const struct tgsi_token *tokens;
/* last instruction with relative addressing: */
struct ir3_instruction *last_rel;
+ /* for calculating input/output positions/linkages: */
unsigned next_inloc;
+
unsigned num_internal_temps;
struct tgsi_src_register internal_temps[6];
const struct tgsi_token *tokens)
{
unsigned ret, base = 0;
+ struct tgsi_shader_info *info = &ctx->info;
ctx->tokens = tokens;
ctx->ir = so->ir;
ctx->num_internal_temps = 0;
ctx->branch_count = 0;
- memset(ctx->needs_ss, 0, sizeof(ctx->needs_ss));
- memset(ctx->needs_sy, 0, sizeof(ctx->needs_sy));
+ regmask_init(&ctx->needs_ss);
+ regmask_init(&ctx->needs_sy);
memset(ctx->base_reg, 0, sizeof(ctx->base_reg));
tgsi_scan_shader(tokens, &ctx->info);
/* Immediates go after constants: */
ctx->base_reg[TGSI_FILE_CONSTANT] = 0;
ctx->base_reg[TGSI_FILE_IMMEDIATE] =
- ctx->info.file_max[TGSI_FILE_CONSTANT] + 1;
+ info->file_max[TGSI_FILE_CONSTANT] + 1;
/* if full precision and fragment shader, don't clobber
* r0.x w/ bary fetch:
/* Temporaries after outputs after inputs: */
ctx->base_reg[TGSI_FILE_INPUT] = base;
ctx->base_reg[TGSI_FILE_OUTPUT] = base +
- ctx->info.file_max[TGSI_FILE_INPUT] + 1;
+ info->file_max[TGSI_FILE_INPUT] + 1;
ctx->base_reg[TGSI_FILE_TEMPORARY] = base +
- ctx->info.file_max[TGSI_FILE_INPUT] + 1 +
- ctx->info.file_max[TGSI_FILE_OUTPUT] + 1;
+ info->file_max[TGSI_FILE_INPUT] + 1 +
+ info->file_max[TGSI_FILE_OUTPUT] + 1;
so->first_immediate = ctx->base_reg[TGSI_FILE_IMMEDIATE];
- ctx->immediate_idx = 4 * (ctx->info.file_max[TGSI_FILE_IMMEDIATE] + 1);
+ ctx->immediate_idx = 4 * (info->file_max[TGSI_FILE_IMMEDIATE] + 1);
ret = tgsi_parse_init(&ctx->parser, tokens);
if (ret != TGSI_PARSE_OK)
}
}
+static void
+add_nop(struct fd3_compile_context *ctx, unsigned count)
+{
+ while (count-- > 0)
+ ir3_instr_create(ctx->ir, 0, OPC_NOP);
+}
+
static unsigned
src_flags(struct fd3_compile_context *ctx, struct ir3_register *reg)
{
if (reg->flags & (IR3_REG_CONST | IR3_REG_IMMED))
return flags;
- if (regmask_get(ctx->needs_ss, reg)) {
+ if (regmask_get(&ctx->needs_ss, reg)) {
flags |= IR3_INSTR_SS;
- memset(ctx->needs_ss, 0, sizeof(ctx->needs_ss));
+ regmask_init(&ctx->needs_ss);
}
- if (regmask_get(ctx->needs_sy, reg)) {
+ if (regmask_get(&ctx->needs_sy, reg)) {
flags |= IR3_INSTR_SY;
- memset(ctx->needs_sy, 0, sizeof(ctx->needs_sy));
+ regmask_init(&ctx->needs_sy);
}
return flags;
add_dst_reg(ctx, instr, dst, i);
add_src_reg(ctx, instr, src, src_swiz(src, i));
} else {
- ir3_instr_create(ctx->ir, 0, OPC_NOP);
+ add_nop(ctx, 1);
}
}
}
int i, j, n = 0;
bool indirect = dst->Indirect;
- add_dst_reg(ctx, instr, dst, 0);
+ add_dst_reg(ctx, instr, dst, TGSI_SWIZZLE_X);
va_start(ap, nsrcs);
for (j = 0; j < nsrcs; j++) {
struct tgsi_src_register *src =
va_arg(ap, struct tgsi_src_register *);
unsigned flags = va_arg(ap, unsigned);
- struct ir3_register *reg = add_src_reg(ctx, instr, src, 0);
+ struct ir3_register *reg;
+ if (flags & IR3_REG_IMMED) {
+ reg = ir3_reg_create(instr, 0, IR3_REG_IMMED);
+ /* this is an ugly cast.. should have put flags first! */
+ reg->iim_val = *(int *)&src;
+ } else {
+ reg = add_src_reg(ctx, instr, src, TGSI_SWIZZLE_X);
+ indirect |= src->Indirect;
+ }
reg->flags |= flags & ~IR3_REG_NEGATE;
if (flags & IR3_REG_NEGATE)
reg->flags ^= IR3_REG_NEGATE;
- indirect |= src->Indirect;
}
va_end(ap);
for (j = 0; j < nsrcs; j++) {
struct tgsi_src_register *src =
va_arg(ap, struct tgsi_src_register *);
- (void)va_arg(ap, unsigned);
- cur->regs[j+1]->num =
- regid(cur->regs[j+1]->num >> 2,
- src_swiz(src, i));
- cur->flags |= src_flags(ctx, cur->regs[j+1]);
+ unsigned flags = va_arg(ap, unsigned);
+ if (!(flags & IR3_REG_IMMED)) {
+ cur->regs[j+1]->num =
+ regid(cur->regs[j+1]->num >> 2,
+ src_swiz(src, i));
+ cur->flags |= src_flags(ctx, cur->regs[j+1]);
+ }
}
va_end(ap);
/* pad w/ nop's.. at least until we are clever enough to
* figure out if we really need to..
*/
- for (; n < 4; n++) {
- ir3_instr_create(instr->shader, 0, OPC_NOP);
- }
+ add_nop(ctx, 4 - n);
}
/*
add_dst_reg(ctx, instr, &tmp_dst, chan)->flags |= IR3_REG_HALF;
add_src_reg(ctx, instr, src, chan);
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 2;
+ add_nop(ctx, 3);
/* shl.b Rtmp, Rtmp, 2 */
instr = ir3_instr_create(ctx->ir, 2, OPC_SHL_B);
add_src_reg(ctx, instr, tmp_src, chan)->flags |= IR3_REG_HALF;
ir3_reg_create(instr, 0, IR3_REG_IMMED)->iim_val = 2;
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 2;
+ add_nop(ctx, 3);
/* mova a0, Rtmp */
instr = ir3_instr_create(ctx->ir, 1, 0);
add_src_reg(ctx, instr, tmp_src, chan)->flags |= IR3_REG_HALF;
/* need to ensure 5 instr slots before a0 is used: */
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 5;
+ add_nop(ctx, 6);
}
/* texture fetch/sample instructions: */
struct tgsi_src_register *samp = &inst->Src[1].Register;
unsigned tex = inst->Texture.Texture;
int8_t *order;
- unsigned i, flags = 0;
+ unsigned i, flags = 0, src_wrmask;
bool needs_mov = false;
switch (t->arg) {
case TGSI_OPCODE_TEX:
- order = (tex == TGSI_TEXTURE_2D) ?
- (int8_t[4]){ 0, 1, -1, -1 } : /* 2D */
- (int8_t[4]){ 0, 1, 2, -1 }; /* 3D */
+ if (tex == TGSI_TEXTURE_2D) {
+ order = (int8_t[4]){ 0, 1, -1, -1 };
+ src_wrmask = TGSI_WRITEMASK_XY;
+ } else {
+ order = (int8_t[4]){ 0, 1, 2, -1 };
+ src_wrmask = TGSI_WRITEMASK_XYZ;
+ }
break;
case TGSI_OPCODE_TXP:
- order = (tex == TGSI_TEXTURE_2D) ?
- (int8_t[4]){ 0, 1, 3, -1 } : /* 2D */
- (int8_t[4]){ 0, 1, 2, 3 }; /* 3D */
+ if (tex == TGSI_TEXTURE_2D) {
+ order = (int8_t[4]){ 0, 1, 3, -1 };
+ src_wrmask = TGSI_WRITEMASK_XYZ;
+ } else {
+ order = (int8_t[4]){ 0, 1, 2, 3 };
+ src_wrmask = TGSI_WRITEMASK_XYZW;
+ }
flags |= IR3_INSTR_P;
break;
default:
}
if ((tex == TGSI_TEXTURE_3D) || (tex == TGSI_TEXTURE_CUBE)) {
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 2; // XXX ???
+ add_nop(ctx, 3);
flags |= IR3_INSTR_3D;
}
coord = tmp_src;
- if (j < 4)
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 4 - j - 1;
-
+ add_nop(ctx, 4 - j);
}
instr = ir3_instr_create(ctx->ir, 5, t->opc);
r = add_dst_reg(ctx, instr, &inst->Dst[0].Register, 0);
r->wrmask = inst->Dst[0].Register.WriteMask;
- add_src_reg(ctx, instr, coord, coord->SwizzleX);
+ add_src_reg(ctx, instr, coord, coord->SwizzleX)->wrmask = src_wrmask;
- regmask_set(ctx->needs_sy, r, r->wrmask);
+ /* after add_src_reg() so we don't set (sy) on sam instr itself! */
+ regmask_set(&ctx->needs_sy, r);
}
/*
case TGSI_OPCODE_CMP:
/* add.s tmp, tmp, -1 */
instr = ir3_instr_create(ctx->ir, 2, OPC_ADD_S);
- instr->repeat = 3;
- add_dst_reg(ctx, instr, &tmp_dst, 0);
- add_src_reg(ctx, instr, tmp_src, 0)->flags |= IR3_REG_R;
- ir3_reg_create(instr, 0, IR3_REG_IMMED)->iim_val = -1;
+ vectorize(ctx, instr, &tmp_dst, 2, tmp_src, 0, -1, IR3_REG_IMMED);
if (t->tgsi_opc == TGSI_OPCODE_CMP) {
/* sel.{f32,f16} dst, src2, tmp, src1 */
src = get_unconst(ctx, src);
/* worst case: */
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 5;
+ add_nop(ctx, 6);
/* we need to replicate into each component: */
for (i = 0, n = 0; i < 4; i++) {
}
}
- regmask_set(ctx->needs_ss, instr->regs[0], dst->WriteMask);
+ regmask_set(&ctx->needs_ss, instr->regs[0]);
put_dst(ctx, inst, dst);
}
/* for frag shaders, we need to generate the corresponding bary instr: */
if (ctx->type == TGSI_PROCESSOR_FRAGMENT) {
- struct ir3_instruction *instr;
+ unsigned j;
- instr = ir3_instr_create(ctx->ir, 2, OPC_BARY_F);
- instr->repeat = ncomp - 1;
+ for (j = 0; j < ncomp; j++) {
+ struct ir3_instruction *instr;
+ struct ir3_register *dst;
- /* dst register: */
- ctx->last_input = ir3_reg_create(instr, r, flags);
+ instr = ir3_instr_create(ctx->ir, 2, OPC_BARY_F);
- /* input position: */
- ir3_reg_create(instr, 0, IR3_REG_IMMED | IR3_REG_R)->iim_val =
- so->inputs[n].inloc - 8;
+ /* dst register: */
+ dst = ir3_reg_create(instr, r + j, flags);
+ ctx->last_input = dst;
- /* input base (always r0.x): */
- ir3_reg_create(instr, regid(0,0), 0);
+ /* input position: */
+ ir3_reg_create(instr, 0, IR3_REG_IMMED)->iim_val =
+ so->inputs[n].inloc + j - 8;
+
+ /* input base (always r0.xy): */
+ ir3_reg_create(instr, regid(0,0), 0)->wrmask = 0x3;
+ }
nop = 6;
}
if (ctx->type == TGSI_PROCESSOR_VERTEX) {
switch (name) {
case TGSI_SEMANTIC_POSITION:
- so->pos_regid = regid(decl->Range.First + base, 0);
- break;
case TGSI_SEMANTIC_PSIZE:
- so->psize_regid = regid(decl->Range.First + base, 0);
- break;
case TGSI_SEMANTIC_COLOR:
case TGSI_SEMANTIC_GENERIC:
case TGSI_SEMANTIC_FOG:
} else {
switch (name) {
case TGSI_SEMANTIC_COLOR:
- so->color_regid = regid(decl->Range.First + base, 0);
break;
default:
compile_error(ctx, "unknown FS semantic name: %s\n",
unsigned opc = inst->Instruction.Opcode;
const struct instr_translater *t = &translaters[opc];
- if (nop) {
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = nop - 1;
- nop = 0;
- }
+ add_nop(ctx, nop);
+ nop = 0;
if (t->fxn) {
t->fxn(t, ctx, inst);
assert(so->ir);
- so->color_regid = regid(63,0);
- so->pos_regid = regid(63,0);
- so->psize_regid = regid(63,0);
-
if (compile_init(&ctx, so, tokens) != TGSI_PARSE_OK)
return -1;
return 0;
}
+static uint32_t
+find_regid(const struct fd3_shader_stateobj *so, fd3_semantic semantic)
+{
+ int j;
+ for (j = 0; j < so->outputs_count; j++)
+ if (so->outputs[j].semantic == semantic)
+ return so->outputs[j].regid;
+ return regid(63, 0);
+}
+
void
fd3_program_emit(struct fd_ringbuffer *ring,
struct fd_program_stateobj *prog, bool binning)
const struct fd3_shader_stateobj *fp = prog->fp;
const struct ir3_shader_info *vsi = &vp->info;
const struct ir3_shader_info *fsi = &fp->info;
+ uint32_t pos_regid, psize_regid, color_regid;
int i;
if (binning) {
fsi = &fp->info;
}
+ pos_regid = find_regid(vp,
+ fd3_semantic_name(TGSI_SEMANTIC_POSITION, 0));
+ psize_regid = find_regid(vp,
+ fd3_semantic_name(TGSI_SEMANTIC_PSIZE, 0));
+ color_regid = find_regid(fp,
+ fd3_semantic_name(TGSI_SEMANTIC_COLOR, 0));
+
/* we could probably divide this up into things that need to be
* emitted if frag-prog is dirty vs if vert-prog is dirty..
*/
OUT_RING(ring, A3XX_SP_VS_CTRL_REG1_CONSTLENGTH(vp->constlen) |
A3XX_SP_VS_CTRL_REG1_INITIALOUTSTANDING(vp->total_in) |
A3XX_SP_VS_CTRL_REG1_CONSTFOOTPRINT(MAX2(vsi->max_const, 0)));
- OUT_RING(ring, A3XX_SP_VS_PARAM_REG_POSREGID(vp->pos_regid) |
- A3XX_SP_VS_PARAM_REG_PSIZEREGID(vp->psize_regid) |
+ OUT_RING(ring, A3XX_SP_VS_PARAM_REG_POSREGID(pos_regid) |
+ A3XX_SP_VS_PARAM_REG_PSIZEREGID(psize_regid) |
A3XX_SP_VS_PARAM_REG_TOTALVSOUTVAR(fp->inputs_count));
for (i = 0; i < fp->inputs_count; ) {
OUT_RING(ring, 0x00000000); /* SP_FS_OUTPUT_REG */
OUT_PKT0(ring, REG_A3XX_SP_FS_MRT_REG(0), 4);
- OUT_RING(ring, A3XX_SP_FS_MRT_REG_REGID(fp->color_regid) |
+ OUT_RING(ring, A3XX_SP_FS_MRT_REG_REGID(color_regid) |
COND(fp->half_precision, A3XX_SP_FS_MRT_REG_HALF_PRECISION));
OUT_RING(ring, A3XX_SP_FS_MRT_REG_REGID(0));
OUT_RING(ring, A3XX_SP_FS_MRT_REG_REGID(0));
if (!so)
return NULL;
- so->color_regid = regid(0,0);
so->half_precision = true;
so->inputs_count = 1;
- so->inputs[0].semantic = fd3_semantic_name(TGSI_SEMANTIC_TEXCOORD, 0);
+ so->inputs[0].semantic =
+ fd3_semantic_name(TGSI_SEMANTIC_TEXCOORD, 0);
so->inputs[0].inloc = 8;
so->inputs[0].compmask = 0x3;
so->total_in = 2;
+ so->outputs_count = 1;
+ so->outputs[0].semantic =
+ fd3_semantic_name(TGSI_SEMANTIC_COLOR, 0);
+ so->outputs[0].regid = regid(0,0);
so->samplers_count = 1;
so->vpsrepl[0] = 0x99999999;
if (!so)
return NULL;
- so->pos_regid = regid(1,0);
- so->psize_regid = regid(63,0);
so->inputs_count = 2;
so->inputs[0].regid = regid(0,0);
so->inputs[0].compmask = 0xf;
so->inputs[1].regid = regid(1,0);
so->inputs[1].compmask = 0xf;
so->total_in = 8;
- so->outputs_count = 1;
- so->outputs[0].semantic = fd3_semantic_name(TGSI_SEMANTIC_TEXCOORD, 0);
+ so->outputs_count = 2;
+ so->outputs[0].semantic =
+ fd3_semantic_name(TGSI_SEMANTIC_TEXCOORD, 0);
so->outputs[0].regid = regid(0,0);
+ so->outputs[1].semantic =
+ fd3_semantic_name(TGSI_SEMANTIC_POSITION, 0);
+ so->outputs[1].regid = regid(1,0);
fixup_vp_regfootprint(so);
if (!so)
return NULL;
- so->color_regid = regid(0,0);
so->half_precision = true;
so->inputs_count = 0;
+ so->outputs_count = 1;
+ so->outputs[0].semantic =
+ fd3_semantic_name(TGSI_SEMANTIC_COLOR, 0);
+ so->outputs[0].regid = regid(0, 0);
so->total_in = 0;
return so;
if (!so)
return NULL;
- so->pos_regid = regid(0,0);
- so->psize_regid = regid(63,0);
so->inputs_count = 1;
so->inputs[0].regid = regid(0,0);
so->inputs[0].compmask = 0xf;
so->total_in = 4;
- so->outputs_count = 0;
+
+ so->outputs_count = 1;
+ so->outputs[0].semantic =
+ fd3_semantic_name(TGSI_SEMANTIC_POSITION, 0);
+ so->outputs[0].regid = regid(0,0);
fixup_vp_regfootprint(so);