#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);
}
}
+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;
return tmp_src;
}
-/* same as get_internal_temp, but w/ src.xxxx (for instructions that
- * replicate their results)
- */
-static struct tgsi_src_register *
-get_internal_temp_repl(struct fd3_compile_context *ctx,
- struct tgsi_dst_register *tmp_dst)
-{
- struct tgsi_src_register *tmp_src =
- get_internal_temp(ctx, tmp_dst);
- tmp_src->SwizzleX = tmp_src->SwizzleY =
- tmp_src->SwizzleZ = tmp_src->SwizzleW = TGSI_SWIZZLE_X;
- return tmp_src;
-}
-
static inline bool
is_const(struct tgsi_src_register *src)
{
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);
}
/*
* native instructions:
*/
-/* LIT - Light Coefficients:
- * dst.x = 1.0
- * dst.y = max(src.x, 0.0)
- * dst.z = (src.x > 0.0) ? max(src.y, 0.0)^{clamp(src.w, -128.0, 128.0))} : 0.0
- * dst.w = 1.0
- *
- * max.f tmp.y, src.y, {0.0}
- * nop
- * max.f tmp.z, src.w, {-128.0}
- * cmps.f.ge tmp.w, (neg)src.x, {0.0}
- * max.f dst.y, src.x, {0.0}
- * nop
- * min.f tmp.x, tmp.z, {128.0}
- * add.s tmp.z, tmp.w, -1
- * log2 tmp.y, tmp.y
- * (rpt1)nop
- * (ss)mul.f tmp.x, tmp.x, tmp.y
- * mov.f16f16 dst.x, {1.0}
- * mov.f16f16 dst.w, {1.0}
- * (rpt3)nop
- * exp2 tmp.x, tmp.x
- * (ss)sel.f16 dst.z, {0.0}, tmp.z, tmp.x
- */
-static void
-trans_lit(const struct instr_translater *t,
- struct fd3_compile_context *ctx,
- struct tgsi_full_instruction *inst)
-{
- struct ir3_instruction *instr;
- struct ir3_register *r;
- struct tgsi_dst_register tmp_dst;
- struct tgsi_src_register *tmp_src;
- struct tgsi_src_register constval0, constval1, constval128;
- struct tgsi_src_register *src = &inst->Src[0].Register;
- struct tgsi_dst_register *dst = get_dst(ctx, inst);
-
- tmp_src = get_internal_temp_repl(ctx, &tmp_dst);
-
- if (is_const(src))
- src = get_unconst(ctx, src);
-
- get_immediate(ctx, &constval0, fui(0.0));
- get_immediate(ctx, &constval1, fui(1.0));
- get_immediate(ctx, &constval128, fui(128.0));
-
- /* max.f tmp.y, src.y, {0.0} */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MAX_F);
- add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_Y);
- add_src_reg(ctx, instr, src, TGSI_SWIZZLE_Y);
- add_src_reg(ctx, instr, &constval0, constval0.SwizzleX);
-
- /* nop */
- ir3_instr_create(ctx->ir, 0, OPC_NOP);
-
- /* max.f tmp.z, src.w, {-128.0} */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MAX_F);
- add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_Z);
- add_src_reg(ctx, instr, src, TGSI_SWIZZLE_W);
- add_src_reg(ctx, instr, &constval128,
- constval128.SwizzleX)->flags |= IR3_REG_NEGATE;
-
- /* cmps.f.ge tmp.w, (neg)src.x, {0.0} */
- instr = ir3_instr_create(ctx->ir, 2, OPC_CMPS_F);
- add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_W);
- add_src_reg(ctx, instr, src, TGSI_SWIZZLE_X)->flags |= IR3_REG_NEGATE;
- add_src_reg(ctx, instr, &constval0, constval0.SwizzleX);
- instr->cat2.condition = IR3_COND_GE;
-
- /* max.f dst.y, src.x, {0.0} */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MAX_F);
- add_dst_reg(ctx, instr, dst, TGSI_SWIZZLE_Y);
- add_src_reg(ctx, instr, src, TGSI_SWIZZLE_X);
- add_src_reg(ctx, instr, &constval0, constval0.SwizzleX);
-
- /* nop */
- ir3_instr_create(ctx->ir, 0, OPC_NOP);
-
- /* min.f tmp.x, tmp.z, {128.0} */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MIN_F);
- add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_X);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_Z);
- add_src_reg(ctx, instr, &constval128, constval128.SwizzleX);
-
- /* add.s tmp.z, tmp.w, -1 */
- instr = ir3_instr_create(ctx->ir, 2, OPC_ADD_S);
- add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_Z);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_W);
- ir3_reg_create(instr, 0, IR3_REG_IMMED)->iim_val = -1;
-
- /* log2 tmp.y, tmp.y */
- instr = ir3_instr_create(ctx->ir, 4, OPC_LOG2);
- r = add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_Y);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_Y);
- regmask_set(ctx->needs_ss, r, TGSI_WRITEMASK_Y);
-
- /* (rpt1)nop */
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 1;
-
- /* (ss)mul.f tmp.x, tmp.x, tmp.y */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MUL_F);
- add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_X);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_X);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_Y);
-
- /* mov.f16f16 dst.x, {1.0} */
- instr = ir3_instr_create(ctx->ir, 1, 0);
- instr->cat1.src_type = get_ftype(ctx);
- instr->cat1.dst_type = get_ftype(ctx);
- add_dst_reg(ctx, instr, dst, TGSI_SWIZZLE_X);
- add_src_reg(ctx, instr, &constval1, constval1.SwizzleX);
-
- /* mov.f16f16 dst.w, {1.0} */
- instr = ir3_instr_create(ctx->ir, 1, 0);
- instr->cat1.src_type = get_ftype(ctx);
- instr->cat1.dst_type = get_ftype(ctx);
- add_dst_reg(ctx, instr, dst, TGSI_SWIZZLE_W);
- add_src_reg(ctx, instr, &constval1, constval1.SwizzleX);
-
- /* (rpt3)nop */
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 3;
-
- /* exp2 tmp.x, tmp.x */
- instr = ir3_instr_create(ctx->ir, 4, OPC_EXP2);
- r = add_dst_reg(ctx, instr, &tmp_dst, TGSI_SWIZZLE_X);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_X);
- regmask_set(ctx->needs_ss, r, TGSI_WRITEMASK_X);
-
- /* (ss)sel.f16 dst.z, {0.0}, tmp.z, tmp.x */
- instr = ir3_instr_create(ctx->ir, 3,
- ctx->so->half_precision ? OPC_SEL_F16 : OPC_SEL_F32);
- add_dst_reg(ctx, instr, dst, TGSI_SWIZZLE_Z);
- add_src_reg(ctx, instr, &constval0, constval0.SwizzleX);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_Z);
- add_src_reg(ctx, instr, tmp_src, TGSI_SWIZZLE_X);
-
- put_dst(ctx, inst, dst);
-}
-
-static inline void
-get_swiz(unsigned *swiz, struct tgsi_src_register *src)
-{
- swiz[0] = src->SwizzleX;
- swiz[1] = src->SwizzleY;
- swiz[2] = src->SwizzleZ;
- swiz[3] = src->SwizzleW;
-}
-
-static void
-trans_dotp(const struct instr_translater *t,
- struct fd3_compile_context *ctx,
- struct tgsi_full_instruction *inst)
-{
- struct ir3_instruction *instr;
- struct tgsi_dst_register tmp_dst;
- struct tgsi_src_register *tmp_src;
- struct tgsi_dst_register *dst = &inst->Dst[0].Register;
- struct tgsi_src_register *src0 = &inst->Src[0].Register;
- struct tgsi_src_register *src1 = &inst->Src[1].Register;
- unsigned swiz0[4];
- unsigned swiz1[4];
- opc_t opc_mad = ctx->so->half_precision ? OPC_MAD_F16 : OPC_MAD_F32;
- unsigned n = t->arg; /* number of components */
- unsigned i, swapped = 0;
-
- tmp_src = get_internal_temp_repl(ctx, &tmp_dst);
-
- /* in particular, can't handle const for src1 for cat3/mad:
- */
- if (is_rel_or_const(src1)) {
- if (!is_rel_or_const(src0)) {
- struct tgsi_src_register *tmp;
- tmp = src0;
- src0 = src1;
- src1 = tmp;
- swapped = 1;
- } else {
- src0 = get_unconst(ctx, src0);
- }
- }
-
- get_swiz(swiz0, src0);
- get_swiz(swiz1, src1);
-
- instr = ir3_instr_create(ctx->ir, 2, OPC_MUL_F);
- add_dst_reg(ctx, instr, &tmp_dst, 0);
- add_src_reg(ctx, instr, src0, swiz0[0]);
- add_src_reg(ctx, instr, src1, swiz1[0]);
-
- for (i = 1; i < n; i++) {
- ir3_instr_create(ctx->ir, 0, OPC_NOP);
-
- instr = ir3_instr_create(ctx->ir, 3, opc_mad);
- add_dst_reg(ctx, instr, &tmp_dst, 0);
- add_src_reg(ctx, instr, src0, swiz0[i]);
- add_src_reg(ctx, instr, src1, swiz1[i]);
- add_src_reg(ctx, instr, tmp_src, 0);
- }
-
- /* DPH(a,b) = (a.x * b.x) + (a.y * b.y) + (a.z * b.z) + b.w */
- if (t->tgsi_opc == TGSI_OPCODE_DPH) {
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 1;
-
- instr = ir3_instr_create(ctx->ir, 2, OPC_ADD_F);
- add_dst_reg(ctx, instr, &tmp_dst, 0);
- if (swapped)
- add_src_reg(ctx, instr, src0, swiz0[i]);
- else
- add_src_reg(ctx, instr, src1, swiz1[i]);
- add_src_reg(ctx, instr, tmp_src, 0);
-
- n++;
- }
-
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 2;
-
- /* because of get_internal_temp_repl(), this will replicate
- * the results to all components of dst:
- */
- create_mov(ctx, dst, tmp_src);
-}
-
static void
trans_clamp(const struct instr_translater *t,
struct fd3_compile_context *ctx,
put_dst(ctx, inst, dst);
}
-/* LRP(a,b,c) = (a * b) + ((1 - a) * c) */
-static void
-trans_lrp(const struct instr_translater *t,
- struct fd3_compile_context *ctx,
- struct tgsi_full_instruction *inst)
-{
- struct ir3_instruction *instr;
- struct tgsi_dst_register tmp_dst1, tmp_dst2;
- struct tgsi_src_register *tmp_src1, *tmp_src2;
- struct tgsi_src_register tmp_const;
- struct tgsi_src_register *src0 = &inst->Src[0].Register;
- struct tgsi_src_register *src1 = &inst->Src[1].Register;
-
- if (is_const(src0) && is_const(src1))
- src0 = get_unconst(ctx, src0);
-
- tmp_src1 = get_internal_temp(ctx, &tmp_dst1);
- tmp_src2 = get_internal_temp(ctx, &tmp_dst2);
-
- get_immediate(ctx, &tmp_const, fui(1.0));
-
- /* tmp1 = (a * b) */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MUL_F);
- vectorize(ctx, instr, &tmp_dst1, 2, src0, 0, src1, 0);
-
- /* tmp2 = (1 - a) */
- instr = ir3_instr_create(ctx->ir, 2, OPC_ADD_F);
- vectorize(ctx, instr, &tmp_dst2, 2, &tmp_const, 0,
- src0, IR3_REG_NEGATE);
-
- /* tmp2 = tmp2 * c */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MUL_F);
- vectorize(ctx, instr, &tmp_dst2, 2,
- tmp_src2, 0,
- &inst->Src[2].Register, 0);
-
- /* dst = tmp1 + tmp2 */
- instr = ir3_instr_create(ctx->ir, 2, OPC_ADD_F);
- vectorize(ctx, instr, &inst->Dst[0].Register, 2,
- tmp_src1, 0,
- tmp_src2, 0);
-}
-
-/* FRC(x) = x - FLOOR(x) */
-static void
-trans_frac(const struct instr_translater *t,
- struct fd3_compile_context *ctx,
- struct tgsi_full_instruction *inst)
-{
- struct ir3_instruction *instr;
- struct tgsi_dst_register tmp_dst;
- struct tgsi_src_register *tmp_src;
-
- tmp_src = get_internal_temp(ctx, &tmp_dst);
-
- /* tmp = FLOOR(x) */
- instr = ir3_instr_create(ctx->ir, 2, OPC_FLOOR_F);
- vectorize(ctx, instr, &tmp_dst, 1,
- &inst->Src[0].Register, 0);
-
- /* dst = x - tmp */
- instr = ir3_instr_create(ctx->ir, 2, OPC_ADD_F);
- vectorize(ctx, instr, &inst->Dst[0].Register, 2,
- &inst->Src[0].Register, 0,
- tmp_src, IR3_REG_NEGATE);
-}
-
/* ARL(x) = x, but mova from hrN.x to a0.. */
static void
trans_arl(const struct instr_translater *t,
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;
-}
-
-/* POW(a,b) = EXP2(b * LOG2(a)) */
-static void
-trans_pow(const struct instr_translater *t,
- struct fd3_compile_context *ctx,
- struct tgsi_full_instruction *inst)
-{
- struct ir3_instruction *instr;
- struct ir3_register *r;
- struct tgsi_dst_register tmp_dst;
- struct tgsi_src_register *tmp_src;
- struct tgsi_dst_register *dst = &inst->Dst[0].Register;
- struct tgsi_src_register *src0 = &inst->Src[0].Register;
- struct tgsi_src_register *src1 = &inst->Src[1].Register;
-
- tmp_src = get_internal_temp_repl(ctx, &tmp_dst);
-
- /* log2 Rtmp, Rsrc0 */
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 5;
- instr = ir3_instr_create(ctx->ir, 4, OPC_LOG2);
- r = add_dst_reg(ctx, instr, &tmp_dst, 0);
- add_src_reg(ctx, instr, src0, src0->SwizzleX);
- regmask_set(ctx->needs_ss, r, TGSI_WRITEMASK_X);
-
- /* mul.f Rtmp, Rtmp, Rsrc1 */
- instr = ir3_instr_create(ctx->ir, 2, OPC_MUL_F);
- add_dst_reg(ctx, instr, &tmp_dst, 0);
- add_src_reg(ctx, instr, tmp_src, 0);
- add_src_reg(ctx, instr, src1, src1->SwizzleX);
-
- /* blob compiler seems to ensure there are at least 6 instructions
- * between a "simple" (non-cat4) instruction and a dependent cat4..
- * probably we need to handle this in some other places too.
- */
- ir3_instr_create(ctx->ir, 0, OPC_NOP)->repeat = 5;
-
- /* exp2 Rdst, Rtmp */
- instr = ir3_instr_create(ctx->ir, 4, OPC_EXP2);
- r = add_dst_reg(ctx, instr, &tmp_dst, 0);
- add_src_reg(ctx, instr, tmp_src, 0);
- regmask_set(ctx->needs_ss, r, TGSI_WRITEMASK_X);
-
- create_mov(ctx, dst, tmp_src);
+ 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);
}
[TGSI_OPCODE_ ## n] = { .fxn = (f), .tgsi_opc = TGSI_OPCODE_ ## n, ##__VA_ARGS__ }
INSTR(MOV, instr_cat1),
- INSTR(LIT, trans_lit),
INSTR(RCP, instr_cat4, .opc = OPC_RCP),
INSTR(RSQ, instr_cat4, .opc = OPC_RSQ),
INSTR(SQRT, instr_cat4, .opc = OPC_SQRT),
INSTR(MUL, instr_cat2, .opc = OPC_MUL_F),
INSTR(ADD, instr_cat2, .opc = OPC_ADD_F),
INSTR(SUB, instr_cat2, .opc = OPC_ADD_F),
- INSTR(DP2, trans_dotp, .arg = 2),
- INSTR(DP3, trans_dotp, .arg = 3),
- INSTR(DP4, trans_dotp, .arg = 4),
- INSTR(DPH, trans_dotp, .arg = 3), /* almost like DP3 */
INSTR(MIN, instr_cat2, .opc = OPC_MIN_F),
INSTR(MAX, instr_cat2, .opc = OPC_MAX_F),
INSTR(MAD, instr_cat3, .opc = OPC_MAD_F32, .hopc = OPC_MAD_F16),
INSTR(TRUNC, instr_cat2, .opc = OPC_TRUNC_F),
- INSTR(LRP, trans_lrp),
- INSTR(FRC, trans_frac),
INSTR(CLAMP, trans_clamp),
INSTR(FLR, instr_cat2, .opc = OPC_FLOOR_F),
INSTR(ROUND, instr_cat2, .opc = OPC_RNDNE_F),
INSTR(ARL, trans_arl),
INSTR(EX2, instr_cat4, .opc = OPC_EXP2),
INSTR(LG2, instr_cat4, .opc = OPC_LOG2),
- INSTR(POW, trans_pow),
INSTR(ABS, instr_cat2, .opc = OPC_ABSNEG_F),
INSTR(COS, instr_cat4, .opc = OPC_COS),
INSTR(SIN, instr_cat4, .opc = OPC_SIN),
/* for frag shaders, we need to generate the corresponding bary instr: */
if (ctx->type == TGSI_PROCESSOR_FRAGMENT) {
- struct ir3_instruction *instr;
+ unsigned j;
+
+ for (j = 0; j < ncomp; j++) {
+ struct ir3_instruction *instr;
+ struct ir3_register *dst;
- instr = ir3_instr_create(ctx->ir, 2, OPC_BARY_F);
- instr->repeat = ncomp - 1;
+ instr = ir3_instr_create(ctx->ir, 2, OPC_BARY_F);
- /* dst register: */
- ctx->last_input = ir3_reg_create(instr, r, flags);
+ /* dst register: */
+ dst = ir3_reg_create(instr, r + j, flags);
+ ctx->last_input = dst;
- /* input position: */
- ir3_reg_create(instr, 0, IR3_REG_IMMED | IR3_REG_R)->iim_val =
- so->inputs[n].inloc - 8;
+ /* input position: */
+ ir3_reg_create(instr, 0, IR3_REG_IMMED)->iim_val =
+ so->inputs[n].inloc + j - 8;
- /* input base (always r0.x): */
- ir3_reg_create(instr, regid(0,0), 0);
+ /* input base (always r0.xy): */
+ ir3_reg_create(instr, regid(0,0), 0)->wrmask = 0x3;
+ }
nop = 6;
}
{
struct fd3_shader_stateobj *so = ctx->so;
unsigned base = ctx->base_reg[TGSI_FILE_OUTPUT];
+ unsigned comp = 0;
unsigned name = decl->Semantic.Name;
unsigned i;
if (ctx->type == TGSI_PROCESSOR_VERTEX) {
switch (name) {
case TGSI_SEMANTIC_POSITION:
- so->pos_regid = regid(decl->Range.First + base, 0);
- break;
+ so->writes_pos = true;
+ /* fallthrough */
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_POSITION:
+ comp = 2; /* tgsi will write to .z component */
+ so->writes_pos = true;
+ /* fallthrough */
case TGSI_SEMANTIC_COLOR:
- so->color_regid = regid(decl->Range.First + base, 0);
break;
default:
compile_error(ctx, "unknown FS semantic name: %s\n",
for (i = decl->Range.First; i <= decl->Range.Last; i++) {
unsigned n = so->outputs_count++;
so->outputs[n].semantic = decl_semantic(&decl->Semantic);
- so->outputs[n].regid = regid(i + base, 0);
+ so->outputs[n].regid = regid(i + base, comp);
}
}
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;