nv50: support TXB and TXL
[mesa.git] / src / gallium / drivers / nv50 / nv50_program.c
index 9ccc4f5a161701b956af0fc943940913d05aae1f..ddb049f391057ed70815e7865229a4e738d5b74e 100644 (file)
@@ -88,12 +88,16 @@ struct nv50_reg {
        int index;
 
        int hw;
-       int neg;
+       int mod;
 
        int rhw; /* result hw for FP outputs, or interpolant index */
        int acc; /* instruction where this reg is last read (first insn == 1) */
 };
 
+#define NV50_MOD_NEG 1
+#define NV50_MOD_ABS 2
+#define NV50_MOD_SAT 4
+
 /* arbitrary limits */
 #define MAX_IF_DEPTH 4
 #define MAX_LOOP_DEPTH 4
@@ -127,6 +131,9 @@ struct nv50_pc {
        struct nv50_reg *r_brdc;
        struct nv50_reg *r_dst[4];
 
+       struct nv50_reg reg_instances[16];
+       unsigned reg_instance_nr;
+
        unsigned interp_mode[32];
        /* perspective interpolation registers */
        struct nv50_reg *iv_p;
@@ -146,13 +153,26 @@ struct nv50_pc {
        boolean allow32;
 };
 
+static INLINE struct nv50_reg *
+reg_instance(struct nv50_pc *pc, struct nv50_reg *reg)
+{
+       struct nv50_reg *dup = NULL;
+       if (reg) {
+               assert(pc->reg_instance_nr < 16);
+               dup = &pc->reg_instances[pc->reg_instance_nr++];
+               *dup = *reg;
+               reg->mod = 0;
+       }
+       return dup;
+}
+
 static INLINE void
 ctor_reg(struct nv50_reg *reg, unsigned type, int index, int hw)
 {
        reg->type = type;
        reg->index = index;
        reg->hw = hw;
-       reg->neg = 0;
+       reg->mod = 0;
        reg->rhw = -1;
        reg->acc = 0;
 }
@@ -460,8 +480,12 @@ set_dst(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_program_exec *e)
 static INLINE void
 set_immd(struct nv50_pc *pc, struct nv50_reg *imm, struct nv50_program_exec *e)
 {
+       unsigned val;
        float f = pc->immd_buf[imm->hw];
-       unsigned val = fui(imm->neg ? -f : f);
+
+       if (imm->mod & NV50_MOD_ABS)
+               f = fabsf(f);
+       val = fui((imm->mod & NV50_MOD_NEG) ? -f : f);
 
        set_long(pc, e);
        /*XXX: can't be predicated - bits overlap.. catch cases where both
@@ -801,12 +825,12 @@ emit_mul(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0,
        set_dst(pc, dst, e);
        set_src_0(pc, src0, e);
        if (src1->type == P_IMMD && !is_long(e)) {
-               if (src0->neg)
+               if (src0->mod & NV50_MOD_NEG)
                        e->inst[0] |= 0x00008000;
                set_immd(pc, src1, e);
        } else {
                set_src_1(pc, src1, e);
-               if (src0->neg ^ src1->neg) {
+               if ((src0->mod ^ src1->mod) & NV50_MOD_NEG) {
                        if (is_long(e))
                                e->inst[1] |= 0x08000000;
                        else
@@ -828,9 +852,10 @@ emit_add(struct nv50_pc *pc, struct nv50_reg *dst,
        alloc_reg(pc, src1);
        check_swap_src_0_1(pc, &src0, &src1);
 
-       if (!pc->allow32 || (src0->neg | src1->neg) || src1->hw > 63) {
+       if (!pc->allow32 || (src0->mod | src1->mod) || src1->hw > 63) {
                set_long(pc, e);
-               e->inst[1] |= (src0->neg << 26) | (src1->neg << 27);
+               e->inst[1] |= ((src0->mod & NV50_MOD_NEG) << 26) |
+                             ((src1->mod & NV50_MOD_NEG) << 27);
        }
 
        set_dst(pc, dst, e);
@@ -877,6 +902,11 @@ emit_minmax(struct nv50_pc *pc, unsigned sub, struct nv50_reg *dst,
        set_src_0(pc, src0, e);
        set_src_1(pc, src1, e);
 
+       if (src0->mod & NV50_MOD_ABS)
+               e->inst[1] |= 0x00100000;
+       if (src1->mod & NV50_MOD_ABS)
+               e->inst[1] |= 0x00080000;
+
        emit(pc, e);
 }
 
@@ -884,10 +914,46 @@ static INLINE void
 emit_sub(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0,
         struct nv50_reg *src1)
 {
-       assert(src0 != src1);
-       src1->neg ^= 1;
+       src1->mod ^= NV50_MOD_NEG;
        emit_add(pc, dst, src0, src1);
-       src1->neg ^= 1;
+       src1->mod ^= NV50_MOD_NEG;
+}
+
+static void
+emit_bitop2(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0,
+           struct nv50_reg *src1, unsigned op)
+{
+       struct nv50_program_exec *e = exec(pc);
+
+       e->inst[0] = 0xd0000000;
+       set_long(pc, e);
+
+       check_swap_src_0_1(pc, &src0, &src1);
+       set_dst(pc, dst, e);
+       set_src_0(pc, src0, e);
+
+       if (op != TGSI_OPCODE_AND && op != TGSI_OPCODE_OR &&
+           op != TGSI_OPCODE_XOR)
+               assert(!"invalid bit op");
+
+       if (src1->type == P_IMMD && src0->type == P_TEMP && pc->allow32) {
+               set_immd(pc, src1, e);
+               if (op == TGSI_OPCODE_OR)
+                       e->inst[0] |= 0x0100;
+               else
+               if (op == TGSI_OPCODE_XOR)
+                       e->inst[0] |= 0x8000;
+       } else {
+               set_src_1(pc, src1, e);
+               e->inst[1] |= 0x04000000; /* 32 bit */
+               if (op == TGSI_OPCODE_OR)
+                       e->inst[1] |= 0x4000;
+               else
+               if (op == TGSI_OPCODE_XOR)
+                       e->inst[1] |= 0x8000;
+       }
+
+       emit(pc, e);
 }
 
 static void
@@ -904,9 +970,9 @@ emit_mad(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0,
        set_src_1(pc, src1, e);
        set_src_2(pc, src2, e);
 
-       if (src0->neg ^ src1->neg)
+       if ((src0->mod ^ src1->mod) & NV50_MOD_NEG)
                e->inst[1] |= 0x04000000;
-       if (src2->neg)
+       if (src2->mod & NV50_MOD_NEG)
                e->inst[1] |= 0x08000000;
 
        emit(pc, e);
@@ -916,10 +982,9 @@ static INLINE void
 emit_msb(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0,
         struct nv50_reg *src1, struct nv50_reg *src2)
 {
-       assert(src2 != src0 && src2 != src1);
-       src2->neg ^= 1;
+       src2->mod ^= NV50_MOD_NEG;
        emit_mad(pc, dst, src0, src1, src2);
-       src2->neg ^= 1;
+       src2->mod ^= NV50_MOD_NEG;
 }
 
 static void
@@ -1193,7 +1258,7 @@ emit_kil(struct nv50_pc *pc, struct nv50_reg *src)
        const int r_pred = 1;
        unsigned cvn = CVT_F32_F32;
 
-       if (src->neg)
+       if (src->mod & NV50_MOD_NEG)
                cvn |= CVT_NEG;
        /* write predicate reg */
        emit_cvt(pc, NULL, src, r_pred, CVTOP_RN, cvn);
@@ -1207,93 +1272,149 @@ emit_kil(struct nv50_pc *pc, struct nv50_reg *src)
 }
 
 static void
-emit_tex(struct nv50_pc *pc, struct nv50_reg **dst, unsigned mask,
-        struct nv50_reg **src, unsigned unit, unsigned type, boolean proj)
+load_cube_tex_coords(struct nv50_pc *pc, struct nv50_reg *t[4],
+                    struct nv50_reg **src, unsigned arg, boolean proj)
 {
-       struct nv50_reg *temp, *t[4];
-       struct nv50_program_exec *e;
+       int mod[3] = { src[0]->mod, src[1]->mod, src[2]->mod };
+
+       src[0]->mod |= NV50_MOD_ABS;
+       src[1]->mod |= NV50_MOD_ABS;
+       src[2]->mod |= NV50_MOD_ABS;
+
+       emit_minmax(pc, 4, t[2], src[0], src[1]);
+       emit_minmax(pc, 4, t[2], src[2], t[2]);
+
+       src[0]->mod = mod[0];
+       src[1]->mod = mod[1];
+       src[2]->mod = mod[2];
+
+       if (proj && 0 /* looks more correct without this */)
+               emit_mul(pc, t[2], t[2], src[3]);
+       else
+       if (arg == 4) /* there is no textureProj(samplerCubeShadow) */
+               emit_mov(pc, t[3], src[3]);
+
+       emit_flop(pc, 0, t[2], t[2]);
+
+       emit_mul(pc, t[0], src[0], t[2]);
+       emit_mul(pc, t[1], src[1], t[2]);
+       emit_mul(pc, t[2], src[2], t[2]);
+}
+
+static void
+load_proj_tex_coords(struct nv50_pc *pc, struct nv50_reg *t[4],
+                    struct nv50_reg **src, unsigned dim, unsigned arg)
+{
+       unsigned c, mode;
+
+       if (src[0]->type == P_TEMP && src[0]->rhw != -1) {
+               mode = pc->interp_mode[src[0]->index] | INTERP_PERSPECTIVE;
+
+               t[3]->rhw = src[3]->rhw;
+               emit_interp(pc, t[3], NULL, (mode & INTERP_CENTROID));
+               emit_flop(pc, 0, t[3], t[3]);
 
-       unsigned c, mode, dim;
+               for (c = 0; c < dim; ++c) {
+                       t[c]->rhw = src[c]->rhw;
+                       emit_interp(pc, t[c], t[3], mode);
+               }
+               if (arg != dim) { /* depth reference value */
+                       t[dim]->rhw = src[2]->rhw;
+                       emit_interp(pc, t[dim], t[3], mode);
+               }
+       } else {
+               /* XXX: for some reason the blob sometimes uses MAD
+                * (mad f32 $rX $rY $rZ neg $r63)
+                */
+               emit_flop(pc, 0, t[3], src[3]);
+               for (c = 0; c < dim; ++c)
+                       emit_mul(pc, t[c], src[c], t[3]);
+               if (arg != dim) /* depth reference value */
+                       emit_mul(pc, t[dim], src[2], t[3]);
+       }
+}
 
+static INLINE void
+get_tex_dim(unsigned type, unsigned *dim, unsigned *arg)
+{
        switch (type) {
        case TGSI_TEXTURE_1D:
-               dim = 1;
+               *arg = *dim = 1;
+               break;
+       case TGSI_TEXTURE_SHADOW1D:
+               *dim = 1;
+               *arg = 2;
                break;
        case TGSI_TEXTURE_UNKNOWN:
        case TGSI_TEXTURE_2D:
-       case TGSI_TEXTURE_SHADOW1D: /* XXX: x, z */
        case TGSI_TEXTURE_RECT:
-               dim = 2;
+               *arg = *dim = 2;
+               break;
+       case TGSI_TEXTURE_SHADOW2D:
+       case TGSI_TEXTURE_SHADOWRECT:
+               *dim = 2;
+               *arg = 3;
                break;
        case TGSI_TEXTURE_3D:
        case TGSI_TEXTURE_CUBE:
-       case TGSI_TEXTURE_SHADOW2D:
-       case TGSI_TEXTURE_SHADOWRECT: /* XXX */
-               dim = 3;
+               *dim = *arg = 3;
                break;
        default:
                assert(0);
                break;
        }
+}
+
+static void
+emit_tex(struct nv50_pc *pc, struct nv50_reg **dst, unsigned mask,
+        struct nv50_reg **src, unsigned unit, unsigned type,
+        boolean proj, int bias_lod)
+{
+       struct nv50_reg *t[4];
+       struct nv50_program_exec *e;
+       unsigned c, dim, arg;
 
-       /* some cards need t[0]'s hw index to be a multiple of 4 */
+       /* t[i] must be within a single 128 bit super-reg */
        alloc_temp4(pc, t, 0);
 
-       if (proj) {
-               if (src[0]->type == P_TEMP && src[0]->rhw != -1) {
-                       mode = pc->interp_mode[src[0]->index];
+       e = exec(pc);
+       e->inst[0] = 0xf0000000;
+       set_long(pc, e);
+       set_dst(pc, t[0], e);
 
-                       t[3]->rhw = src[3]->rhw;
-                       emit_interp(pc, t[3], NULL, (mode & INTERP_CENTROID));
-                       emit_flop(pc, 0, t[3], t[3]);
+       /* TIC and TSC binding indices (TSC is ignored as TSC_LINKED = TRUE): */
+       e->inst[0] |= (unit << 9) /* | (unit << 17) */;
 
-                       for (c = 0; c < dim; c++) {
-                               t[c]->rhw = src[c]->rhw;
-                               emit_interp(pc, t[c], t[3],
-                                           (mode | INTERP_PERSPECTIVE));
-                       }
-               } else {
-                       emit_flop(pc, 0, t[3], src[3]);
-                       for (c = 0; c < dim; c++)
-                               emit_mul(pc, t[c], src[c], t[3]);
+       /* live flag (don't set if TEX results affect input to another TEX): */
+       /* e->inst[0] |= 0x00000004; */
 
-                       /* XXX: for some reason the blob sometimes uses MAD:
-                        * emit_mad(pc, t[c], src[0][c], t[3], t[3])
-                        * pc->p->exec_tail->inst[1] |= 0x080fc000;
-                        */
-               }
-       } else {
-               if (type == TGSI_TEXTURE_CUBE) {
-                       temp = temp_temp(pc);
-                       emit_minmax(pc, 4, temp, src[0], src[1]);
-                       emit_minmax(pc, 4, temp, temp, src[2]);
-                       emit_flop(pc, 0, temp, temp);
-                       for (c = 0; c < 3; c++)
-                               emit_mul(pc, t[c], src[c], temp);
-               } else {
-                       for (c = 0; c < dim; c++)
-                               emit_mov(pc, t[c], src[c]);
-               }
+       get_tex_dim(type, &dim, &arg);
+
+       if (type == TGSI_TEXTURE_CUBE) {
+               e->inst[0] |= 0x08000000;
+               load_cube_tex_coords(pc, t, src, arg, proj);
+       } else
+       if (proj)
+               load_proj_tex_coords(pc, t, src, dim, arg);
+       else {
+               for (c = 0; c < dim; c++)
+                       emit_mov(pc, t[c], src[c]);
+               if (arg != dim) /* depth reference value (always src.z here) */
+                       emit_mov(pc, t[dim], src[2]);
        }
 
-       e = exec(pc);
-       set_long(pc, e);
-       e->inst[0] |= 0xf0000000;
-       e->inst[1] |= 0x00000004;
-       set_dst(pc, t[0], e);
-       e->inst[0] |= (unit << 9);
+       if (bias_lod) {
+               assert(arg < 4);
+               emit_mov(pc, t[arg++], src[3]);
+               e->inst[1] |= (bias_lod < 0) ? 0x20000000 : 0x40000000;
+       }
 
-       if (dim == 2)
-               e->inst[0] |= 0x00400000;
-       else
-       if (dim == 3)
-               e->inst[0] |= 0x00800000;
+       e->inst[0] |= (arg - 1) << 22;
 
        e->inst[0] |= (mask & 0x3) << 25;
        e->inst[1] |= (mask & 0xc) << 12;
 
        emit(pc, e);
-
 #if 1
        c = 0;
        if (mask & 1) emit_mov(pc, dst[0], t[c++]);
@@ -1367,19 +1488,25 @@ emit_ddx(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src)
 static void
 emit_ddy(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src)
 {
+       struct nv50_reg *r = src;
        struct nv50_program_exec *e = exec(pc);
 
        assert(src->type == P_TEMP);
 
-       if (!src->neg) /* ! double negation */
-               emit_neg(pc, src, src);
+       if (!(src->mod & NV50_MOD_NEG)) { /* ! double negation */
+               r = alloc_temp(pc, NULL);
+               emit_neg(pc, r, src);
+       }
 
        e->inst[0] = 0xc0150000;
        e->inst[1] = 0x8a400000;
        set_long(pc, e);
        set_dst(pc, dst, e);
-       set_src_0(pc, src, e);
-       set_src_2(pc, src, e);
+       set_src_0(pc, r, e);
+       set_src_2(pc, r, e);
+
+       if (r != src)
+               free_temp(pc, r);
 
        emit(pc, e);
 }
@@ -1436,8 +1563,6 @@ convert_to_long(struct nv50_pc *pc, struct nv50_program_exec *e)
 static boolean
 negate_supported(const struct tgsi_full_instruction *insn, int i)
 {
-       int s;
-
        switch (insn->Instruction.Opcode) {
        case TGSI_OPCODE_DDY:
        case TGSI_OPCODE_DP3:
@@ -1447,36 +1572,21 @@ negate_supported(const struct tgsi_full_instruction *insn, int i)
        case TGSI_OPCODE_ADD:
        case TGSI_OPCODE_SUB:
        case TGSI_OPCODE_MAD:
-               break;
+               return TRUE;
        case TGSI_OPCODE_POW:
                if (i == 1)
-                       break;
+                       return TRUE;
                return FALSE;
        default:
                return FALSE;
        }
-
-       /* Watch out for possible multiple uses of an nv50_reg, we
-        * can't use nv50_reg::neg in these cases.
-        */
-       for (s = 0; s < insn->Instruction.NumSrcRegs; ++s) {
-               if (s == i)
-                       continue;
-               if ((insn->FullSrcRegisters[s].SrcRegister.Index ==
-                    insn->FullSrcRegisters[i].SrcRegister.Index) &&
-                   (insn->FullSrcRegisters[s].SrcRegister.File ==
-                    insn->FullSrcRegisters[i].SrcRegister.File))
-                       return FALSE;
-       }
-
-       return TRUE;
 }
 
 /* Return a read mask for source registers deduced from opcode & write mask. */
 static unsigned
 nv50_tgsi_src_mask(const struct tgsi_full_instruction *insn, int c)
 {
-       unsigned x, mask = insn->FullDstRegisters[0].DstRegister.WriteMask;
+       unsigned x, mask = insn->Dst[0].Register.WriteMask;
 
        switch (insn->Instruction.Opcode) {
        case TGSI_OPCODE_COS:
@@ -1497,24 +1607,32 @@ nv50_tgsi_src_mask(const struct tgsi_full_instruction *insn, int c)
        case TGSI_OPCODE_RSQ:
        case TGSI_OPCODE_SCS:
                return 0x1;
+       case TGSI_OPCODE_IF:
+               return 0x1;
        case TGSI_OPCODE_LIT:
                return 0xb;
        case TGSI_OPCODE_TEX:
+       case TGSI_OPCODE_TXB:
+       case TGSI_OPCODE_TXL:
        case TGSI_OPCODE_TXP:
        {
-               const struct tgsi_instruction_ext_texture *tex;
+               const struct tgsi_instruction_texture *tex;
 
-               assert(insn->Instruction.Extended);
-               tex = &insn->InstructionExtTexture;
+               assert(insn->Instruction.Texture);
+               tex = &insn->Texture;
 
                mask = 0x7;
-               if (insn->Instruction.Opcode == TGSI_OPCODE_TXP)
-                       mask |= 0x8;
+               if (insn->Instruction.Opcode != TGSI_OPCODE_TEX &&
+                   insn->Instruction.Opcode != TGSI_OPCODE_TXD)
+                       mask |= 0x8; /* bias, lod or proj */
 
                switch (tex->Texture) {
                case TGSI_TEXTURE_1D:
                        mask &= 0x9;
                        break;
+               case TGSI_TEXTURE_SHADOW1D:
+                       mask &= 0x5;
+                       break;
                case TGSI_TEXTURE_2D:
                        mask &= 0xb;
                        break;
@@ -1539,17 +1657,17 @@ nv50_tgsi_src_mask(const struct tgsi_full_instruction *insn, int c)
 static struct nv50_reg *
 tgsi_dst(struct nv50_pc *pc, int c, const struct tgsi_full_dst_register *dst)
 {
-       switch (dst->DstRegister.File) {
+       switch (dst->Register.File) {
        case TGSI_FILE_TEMPORARY:
-               return &pc->temp[dst->DstRegister.Index * 4 + c];
+               return &pc->temp[dst->Register.Index * 4 + c];
        case TGSI_FILE_OUTPUT:
-               return &pc->result[dst->DstRegister.Index * 4 + c];
+               return &pc->result[dst->Register.Index * 4 + c];
        case TGSI_FILE_ADDRESS:
        {
-               struct nv50_reg *r = pc->addr[dst->DstRegister.Index * 4 + c];
+               struct nv50_reg *r = pc->addr[dst->Register.Index * 4 + c];
                if (!r) {
                        r = alloc_addr(pc, NULL);
-                       pc->addr[dst->DstRegister.Index * 4 + c] = r;
+                       pc->addr[dst->Register.Index * 4 + c] = r;
                }
                assert(r);
                return r;
@@ -1571,8 +1689,8 @@ tgsi_src(struct nv50_pc *pc, int chan, const struct tgsi_full_src_register *src,
        struct nv50_reg *temp;
        unsigned sgn, c, swz;
 
-       if (src->SrcRegister.File != TGSI_FILE_CONSTANT)
-               assert(!src->SrcRegister.Indirect);
+       if (src->Register.File != TGSI_FILE_CONSTANT)
+               assert(!src->Register.Indirect);
 
        sgn = tgsi_util_get_full_src_register_sign_mode(src, chan);
 
@@ -1582,16 +1700,16 @@ tgsi_src(struct nv50_pc *pc, int chan, const struct tgsi_full_src_register *src,
        case TGSI_SWIZZLE_Y:
        case TGSI_SWIZZLE_Z:
        case TGSI_SWIZZLE_W:
-               switch (src->SrcRegister.File) {
+               switch (src->Register.File) {
                case TGSI_FILE_INPUT:
-                       r = &pc->attr[src->SrcRegister.Index * 4 + c];
+                       r = &pc->attr[src->Register.Index * 4 + c];
                        break;
                case TGSI_FILE_TEMPORARY:
-                       r = &pc->temp[src->SrcRegister.Index * 4 + c];
+                       r = &pc->temp[src->Register.Index * 4 + c];
                        break;
                case TGSI_FILE_CONSTANT:
-                       if (!src->SrcRegister.Indirect) {
-                               r = &pc->param[src->SrcRegister.Index * 4 + c];
+                       if (!src->Register.Indirect) {
+                               r = &pc->param[src->Register.Index * 4 + c];
                                break;
                        }
                        /* Indicate indirection by setting r->acc < 0 and
@@ -1599,19 +1717,19 @@ tgsi_src(struct nv50_pc *pc, int chan, const struct tgsi_full_src_register *src,
                         */
                        r = MALLOC_STRUCT(nv50_reg);
                        swz = tgsi_util_get_src_register_swizzle(
-                                                &src->SrcRegisterInd, 0);
+                                                &src->Indirect, 0);
                        ctor_reg(r, P_CONST,
-                                src->SrcRegisterInd.Index * 4 + swz,
-                                src->SrcRegister.Index * 4 + c);
+                                src->Indirect.Index * 4 + swz,
+                                src->Register.Index * 4 + c);
                        r->acc = -1;
                        break;
                case TGSI_FILE_IMMEDIATE:
-                       r = &pc->immd[src->SrcRegister.Index * 4 + c];
+                       r = &pc->immd[src->Register.Index * 4 + c];
                        break;
                case TGSI_FILE_SAMPLER:
                        break;
                case TGSI_FILE_ADDRESS:
-                       r = pc->addr[src->SrcRegister.Index * 4 + c];
+                       r = pc->addr[src->Register.Index * 4 + c];
                        assert(r);
                        break;
                default:
@@ -1634,7 +1752,7 @@ tgsi_src(struct nv50_pc *pc, int chan, const struct tgsi_full_src_register *src,
                break;
        case TGSI_UTIL_SIGN_TOGGLE:
                if (neg)
-                       r->neg = 1;
+                       r->mod = NV50_MOD_NEG;
                else {
                        temp = temp_temp(pc);
                        emit_neg(pc, temp, r);
@@ -1706,6 +1824,8 @@ nv50_tgsi_dst_revdep(unsigned op, int s, int c)
        case TGSI_OPCODE_LIT:
        case TGSI_OPCODE_SCS:
        case TGSI_OPCODE_TEX:
+       case TGSI_OPCODE_TXB:
+       case TGSI_OPCODE_TXL:
        case TGSI_OPCODE_TXP:
                /* these take care of dangerous swizzles themselves */
                return 0x0;
@@ -1777,33 +1897,34 @@ nv50_program_tx_insn(struct nv50_pc *pc,
        unsigned mask, sat, unit;
        int i, c;
 
-       mask = inst->FullDstRegisters[0].DstRegister.WriteMask;
+       mask = inst->Dst[0].Register.WriteMask;
        sat = inst->Instruction.Saturate == TGSI_SAT_ZERO_ONE;
 
        memset(src, 0, sizeof(src));
 
        for (c = 0; c < 4; c++) {
                if ((mask & (1 << c)) && !pc->r_dst[c])
-                       dst[c] = tgsi_dst(pc, c, &inst->FullDstRegisters[0]);
+                       dst[c] = tgsi_dst(pc, c, &inst->Dst[0]);
                else
                        dst[c] = pc->r_dst[c];
                rdst[c] = dst[c];
        }
 
        for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
-               const struct tgsi_full_src_register *fs = &inst->FullSrcRegisters[i];
+               const struct tgsi_full_src_register *fs = &inst->Src[i];
                unsigned src_mask;
                boolean neg_supp;
 
                src_mask = nv50_tgsi_src_mask(inst, i);
                neg_supp = negate_supported(inst, i);
 
-               if (fs->SrcRegister.File == TGSI_FILE_SAMPLER)
-                       unit = fs->SrcRegister.Index;
+               if (fs->Register.File == TGSI_FILE_SAMPLER)
+                       unit = fs->Register.Index;
 
                for (c = 0; c < 4; c++)
                        if (src_mask & (1 << c))
-                               src[i][c] = tgsi_src(pc, c, fs, neg_supp);
+                               src[i][c] = reg_instance(pc,
+                                       tgsi_src(pc, c, fs, neg_supp));
        }
 
        brdc = temp = pc->r_brdc;
@@ -1838,6 +1959,16 @@ nv50_program_tx_insn(struct nv50_pc *pc,
                        emit_add(pc, dst[c], src[0][c], src[1][c]);
                }
                break;
+       case TGSI_OPCODE_AND:
+       case TGSI_OPCODE_XOR:
+       case TGSI_OPCODE_OR:
+               for (c = 0; c < 4; c++) {
+                       if (!(mask & (1 << c)))
+                               continue;
+                       emit_bitop2(pc, dst[c], src[0][c], src[1][c],
+                                   inst->Instruction.Opcode);
+               }
+               break;
        case TGSI_OPCODE_ARL:
                assert(src[0][0]);
                temp = temp_temp(pc);
@@ -1979,7 +2110,9 @@ nv50_program_tx_insn(struct nv50_pc *pc,
        case TGSI_OPCODE_IF:
                /* emitting a join_at may not be necessary */
                assert(pc->if_lvl < MAX_IF_DEPTH);
-               set_pred_wr(pc, 1, 0, pc->if_cond);
+               /* set_pred_wr(pc, 1, 0, pc->if_cond); */
+               emit_cvt(pc, NULL, src[0][0], 0, CVTOP_ABS | CVTOP_RN,
+                        CVT_F32_F32);
                emit_branch(pc, 0, 2, &pc->br_join[pc->if_lvl]);
                pc->if_insn[pc->if_lvl++] = pc->p->exec_tail;
                terminate_mbb(pc);
@@ -2096,11 +2229,19 @@ nv50_program_tx_insn(struct nv50_pc *pc,
                break;
        case TGSI_OPCODE_TEX:
                emit_tex(pc, dst, mask, src[0], unit,
-                        inst->InstructionExtTexture.Texture, FALSE);
+                        inst->Texture.Texture, FALSE, 0);
+               break;
+       case TGSI_OPCODE_TXB:
+               emit_tex(pc, dst, mask, src[0], unit,
+                        inst->Texture.Texture, FALSE, -1);
+               break;
+       case TGSI_OPCODE_TXL:
+               emit_tex(pc, dst, mask, src[0], unit,
+                        inst->Texture.Texture, FALSE, 1);
                break;
        case TGSI_OPCODE_TXP:
                emit_tex(pc, dst, mask, src[0], unit,
-                        inst->InstructionExtTexture.Texture, TRUE);
+                        inst->Texture.Texture, TRUE, 0);
                break;
        case TGSI_OPCODE_TRUNC:
                for (c = 0; c < 4; c++) {
@@ -2158,16 +2299,14 @@ nv50_program_tx_insn(struct nv50_pc *pc,
                for (c = 0; c < 4; c++) {
                        if (!src[i][c])
                                continue;
-                       src[i][c]->neg = 0;
-                       if (src[i][c]->index == -1 && src[i][c]->type == P_IMMD)
-                               FREE(src[i][c]);
-                       else
                        if (src[i][c]->acc < 0 && src[i][c]->type == P_CONST)
                                FREE(src[i][c]); /* indirect constant */
                }
        }
 
        kill_temp_temp(pc);
+       pc->reg_instance_nr = 0;
+
        return TRUE;
 }
 
@@ -2179,7 +2318,7 @@ prep_inspect_insn(struct nv50_pc *pc, const struct tgsi_full_instruction *insn)
        const struct tgsi_dst_register *dst;
        unsigned i, c, k, mask;
 
-       dst = &insn->FullDstRegisters[0].DstRegister;
+       dst = &insn->Dst[0].Register;
        mask = dst->WriteMask;
 
         if (dst->File == TGSI_FILE_TEMPORARY)
@@ -2197,12 +2336,12 @@ prep_inspect_insn(struct nv50_pc *pc, const struct tgsi_full_instruction *insn)
        }
 
        for (i = 0; i < insn->Instruction.NumSrcRegs; i++) {
-               src = &insn->FullSrcRegisters[i];
+               src = &insn->Src[i];
 
-               if (src->SrcRegister.File == TGSI_FILE_TEMPORARY)
+               if (src->Register.File == TGSI_FILE_TEMPORARY)
                        reg = pc->temp;
                else
-               if (src->SrcRegister.File == TGSI_FILE_INPUT)
+               if (src->Register.File == TGSI_FILE_INPUT)
                        reg = pc->attr;
                else
                        continue;
@@ -2214,7 +2353,7 @@ prep_inspect_insn(struct nv50_pc *pc, const struct tgsi_full_instruction *insn)
                                continue;
                        k = tgsi_util_get_full_src_register_swizzle(src, c);
 
-                       reg[src->SrcRegister.Index * 4 + k].acc = pc->insn_nr;
+                       reg[src->Register.Index * 4 + k].acc = pc->insn_nr;
                }
        }
 }
@@ -2274,13 +2413,13 @@ static struct nv50_reg *
 tgsi_broadcast_dst(struct nv50_pc *pc,
                   const struct tgsi_full_dst_register *fd, unsigned mask)
 {
-       if (fd->DstRegister.File == TGSI_FILE_TEMPORARY) {
-               int c = ffs(~mask & fd->DstRegister.WriteMask);
+       if (fd->Register.File == TGSI_FILE_TEMPORARY) {
+               int c = ffs(~mask & fd->Register.WriteMask);
                if (c)
                        return tgsi_dst(pc, c - 1, fd);
        } else {
-               int c = ffs(fd->DstRegister.WriteMask) - 1;
-               if ((1 << c) == fd->DstRegister.WriteMask)
+               int c = ffs(fd->Register.WriteMask) - 1;
+               if ((1 << c) == fd->Register.WriteMask)
                        return tgsi_dst(pc, c, fd);
        }
 
@@ -2294,7 +2433,7 @@ static unsigned
 nv50_tgsi_scan_swizzle(const struct tgsi_full_instruction *insn,
                       unsigned rdep[4])
 {
-       const struct tgsi_full_dst_register *fd = &insn->FullDstRegisters[0];
+       const struct tgsi_full_dst_register *fd = &insn->Dst[0];
        const struct tgsi_full_src_register *fs;
        unsigned i, deqs = 0;
 
@@ -2305,9 +2444,9 @@ nv50_tgsi_scan_swizzle(const struct tgsi_full_instruction *insn,
                unsigned chn, mask = nv50_tgsi_src_mask(insn, i);
                boolean neg_supp = negate_supported(insn, i);
 
-               fs = &insn->FullSrcRegisters[i];
-               if (fs->SrcRegister.File != fd->DstRegister.File ||
-                   fs->SrcRegister.Index != fd->DstRegister.Index)
+               fs = &insn->Src[i];
+               if (fs->Register.File != fd->Register.File ||
+                   fs->Register.Index != fd->Register.Index)
                        continue;
 
                for (chn = 0; chn < 4; ++chn) {
@@ -2318,7 +2457,7 @@ nv50_tgsi_scan_swizzle(const struct tgsi_full_instruction *insn,
                        c = tgsi_util_get_full_src_register_swizzle(fs, chn);
                        s = tgsi_util_get_full_src_register_sign_mode(fs, chn);
 
-                       if (!(fd->DstRegister.WriteMask & (1 << c)))
+                       if (!(fd->Register.WriteMask & (1 << c)))
                                continue;
 
                        /* no danger if src is copied to TEMP first */
@@ -2342,7 +2481,7 @@ nv50_tgsi_insn(struct nv50_pc *pc, const union tgsi_full_token *tok)
        const struct tgsi_full_dst_register *fd;
        unsigned i, deqs, rdep[4], m[4];
 
-       fd = &tok->FullInstruction.FullDstRegisters[0];
+       fd = &tok->FullInstruction.Dst[0];
        deqs = nv50_tgsi_scan_swizzle(&insn, rdep);
 
        if (is_scalar_op(insn.Instruction.Opcode)) {
@@ -2361,10 +2500,10 @@ nv50_tgsi_insn(struct nv50_pc *pc, const union tgsi_full_token *tok)
        for (i = 0; i < 4; ++i) {
                assert(pc->r_dst[m[i]] == NULL);
 
-               insn.FullDstRegisters[0].DstRegister.WriteMask =
-                       fd->DstRegister.WriteMask & (1 << m[i]);
+               insn.Dst[0].Register.WriteMask =
+                       fd->Register.WriteMask & (1 << m[i]);
 
-               if (!insn.FullDstRegisters[0].DstRegister.WriteMask)
+               if (!insn.Dst[0].Register.WriteMask)
                        continue;
 
                if (deqs & (1 << i))
@@ -2414,6 +2553,23 @@ load_interpolant(struct nv50_pc *pc, struct nv50_reg *reg)
        emit_interp(pc, reg, iv, mode);
 }
 
+/* The face input is always at v[255] (varying space), with a
+ * value of 0 for back-facing, and 0xffffffff for front-facing.
+ */
+static void
+load_frontfacing(struct nv50_pc *pc, struct nv50_reg *a)
+{
+       struct nv50_reg *one = alloc_immd(pc, 1.0f);
+
+       assert(a->rhw == -1);
+       alloc_reg(pc, a); /* do this before rhw is set */
+       a->rhw = 255;
+       load_interpolant(pc, a);
+       emit_bitop2(pc, a, a, one, TGSI_OPCODE_AND);
+
+       FREE(one);
+}
+
 static boolean
 nv50_program_tx_prep(struct nv50_pc *pc)
 {
@@ -2445,8 +2601,8 @@ nv50_program_tx_prep(struct nv50_pc *pc)
                        unsigned si, last, first, mode;
 
                        d = &tp.FullToken.FullDeclaration;
-                       first = d->DeclarationRange.First;
-                       last = d->DeclarationRange.Last;
+                       first = d->Range.First;
+                       last = d->Range.Last;
 
                        switch (d->Declaration.File) {
                        case TGSI_FILE_TEMPORARY:
@@ -2456,8 +2612,8 @@ nv50_program_tx_prep(struct nv50_pc *pc)
                                    p->type == PIPE_SHADER_FRAGMENT)
                                        break;
 
-                               si = d->Semantic.SemanticIndex;
-                               switch (d->Semantic.SemanticName) {
+                               si = d->Semantic.Index;
+                               switch (d->Semantic.Name) {
                                case TGSI_SEMANTIC_BCOLOR:
                                        p->cfg.two_side[si].hw = first;
                                        if (p->cfg.io_nr > first)
@@ -2535,7 +2691,7 @@ nv50_program_tx_prep(struct nv50_pc *pc)
 
                for (i = 0, rid = 0; i < pc->result_nr; ++i) {
                        p->cfg.io[i].hw = rid;
-                       p->cfg.io[i].id_vp = i;
+                       p->cfg.io[i].id = i;
 
                        for (c = 0; c < 4; ++c) {
                                int n = i * 4 + c;
@@ -2558,6 +2714,8 @@ nv50_program_tx_prep(struct nv50_pc *pc)
                int rid, aid;
                unsigned n = 0, m = pc->attr_nr - flat_nr;
 
+               pc->allow32 = TRUE;
+
                int base = (TGSI_SEMANTIC_POSITION ==
                            p->info.input_semantic_name[0]) ? 0 : 1;
 
@@ -2565,14 +2723,12 @@ nv50_program_tx_prep(struct nv50_pc *pc)
                 * the lower hardware IDs, so sort them:
                 */
                for (i = 0; i < pc->attr_nr; i++) {
-                       if (pc->interp_mode[i] == INTERP_FLAT) {
-                               p->cfg.io[m].id_vp = i + base;
-                               p->cfg.io[m++].id_fp = i;
-                       } else {
+                       if (pc->interp_mode[i] == INTERP_FLAT)
+                               p->cfg.io[m++].id = i;
+                       else {
                                if (!(pc->interp_mode[i] & INTERP_PERSPECTIVE))
                                        p->cfg.io[n].linear = TRUE;
-                               p->cfg.io[n].id_vp = i + base;
-                               p->cfg.io[n++].id_fp = i;
+                               p->cfg.io[n++].id = i;
                        }
                }
 
@@ -2584,7 +2740,13 @@ nv50_program_tx_prep(struct nv50_pc *pc)
 
                for (n = 0; n < pc->attr_nr; ++n) {
                        p->cfg.io[n].hw = rid = aid;
-                       i = p->cfg.io[n].id_fp;
+                       i = p->cfg.io[n].id;
+
+                       if (p->info.input_semantic_name[n] ==
+                           TGSI_SEMANTIC_FACE) {
+                               load_frontfacing(pc, &pc->attr[i * 4]);
+                               continue;
+                       }
 
                        for (c = 0; c < 4; ++c) {
                                if (!pc->attr[i * 4 + c].acc)
@@ -2618,8 +2780,8 @@ nv50_program_tx_prep(struct nv50_pc *pc)
                for (i = 0; i < pc->attr_nr; i++) {
                        ubyte si, sn;
 
-                       sn = p->info.input_semantic_name[p->cfg.io[i].id_fp];
-                       si = p->info.input_semantic_index[p->cfg.io[i].id_fp];
+                       sn = p->info.input_semantic_name[p->cfg.io[i].id];
+                       si = p->info.input_semantic_index[p->cfg.io[i].id];
 
                        if (sn == TGSI_SEMANTIC_COLOR) {
                                p->cfg.two_side[si] = p->cfg.io[i];
@@ -2644,6 +2806,10 @@ nv50_program_tx_prep(struct nv50_pc *pc)
                        pc->result[2].rhw = rid;
 
                p->cfg.high_result = rid;
+
+               /* separate/different colour results for MRTs ? */
+               if (pc->result_nr - (p->info.writes_z ? 1 : 0) > 1)
+                       p->cfg.regs[2] |= 1;
        }
 
        if (pc->immd_nr) {
@@ -2800,7 +2966,7 @@ nv50_fp_move_results(struct nv50_pc *pc)
 static void
 nv50_program_fixup_insns(struct nv50_pc *pc)
 {
-       struct nv50_program_exec *e, *prev = NULL, **bra_list;
+       struct nv50_program_exec *e, **bra_list;
        unsigned i, n, pos;
 
        bra_list = CALLOC(pc->p->exec_size, sizeof(struct nv50_program_exec *));
@@ -2812,6 +2978,16 @@ nv50_program_fixup_insns(struct nv50_pc *pc)
                if (e->param.index >= 0 && !e->param.mask)
                        bra_list[n++] = e;
 
+       /* last instruction must be long so it can have the exit bit set */
+       if (!is_long(pc->p->exec_tail))
+               convert_to_long(pc, pc->p->exec_tail);
+       /* set exit bit */
+       pc->p->exec_tail->inst[1] |= 1;
+
+       /* !immd on exit insn simultaneously means !join */
+       assert(!is_immd(pc->p->exec_head));
+       assert(!is_immd(pc->p->exec_tail));
+
        /* Make sure we don't have any single 32 bit instructions. */
        for (e = pc->p->exec_head, pos = 0; e; e = e->next) {
                pos += is_long(e) ? 2 : 1;
@@ -2823,22 +2999,7 @@ nv50_program_fixup_insns(struct nv50_pc *pc)
                        convert_to_long(pc, e);
                        ++pos;
                }
-               if (e->next)
-                       prev = e;
-       }
-
-       assert(!is_immd(pc->p->exec_head));
-       assert(!is_immd(pc->p->exec_tail));
-
-       /* last instruction must be long so it can have the end bit set */
-       if (!is_long(pc->p->exec_tail)) {
-               convert_to_long(pc, pc->p->exec_tail);
-               if (prev)
-                       convert_to_long(pc, prev);
        }
-       assert(!(pc->p->exec_tail->inst[1] & 2));
-       /* set the end-bit */
-       pc->p->exec_tail->inst[1] |= 1;
 
        FREE(bra_list);
 }
@@ -2976,11 +3137,8 @@ static void
 nv50_program_validate_code(struct nv50_context *nv50, struct nv50_program *p)
 {
        struct nouveau_channel *chan = nv50->screen->base.channel;
-       struct nouveau_grobj *tesla = nv50->screen->tesla;
        struct nv50_program_exec *e;
-       struct nouveau_stateobj *so;
-       const unsigned flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_WR;
-       unsigned start, count, *up, *ptr;
+       uint32_t *up, i;
        boolean upload = FALSE;
 
        if (!p->bo) {
@@ -2995,32 +3153,37 @@ nv50_program_validate_code(struct nv50_context *nv50, struct nv50_program *p)
        if (!upload)
                return;
 
-       for (e = p->exec_head; e; e = e->next) {
+       up = MALLOC(p->exec_size * 4);
+
+       for (i = 0, e = p->exec_head; e; e = e->next) {
                unsigned ei, ci, bs;
 
-               if (e->param.index < 0)
-                       continue;
+               if (e->param.index >= 0 && e->param.mask) {
+                       bs = (e->inst[1] >> 22) & 0x07;
+                       assert(bs < 2);
+                       ei = e->param.shift >> 5;
+                       ci = e->param.index;
+                       if (bs == 0)
+                               ci += p->data[bs]->start;
 
-               if (e->param.mask == 0) {
+                       e->inst[ei] &= ~e->param.mask;
+                       e->inst[ei] |= (ci << e->param.shift);
+               } else
+               if (e->param.index >= 0) {
+                       /* zero mask means param is a jump/branch offset */
                        assert(!(e->param.index & 1));
                        /* seem to be 8 byte steps */
                        ei = (e->param.index >> 1) + 0 /* START_ID */;
 
                        e->inst[0] &= 0xf0000fff;
                        e->inst[0] |= ei << 12;
-                       continue;
                }
 
-               bs = (e->inst[1] >> 22) & 0x07;
-               assert(bs < 2);
-               ei = e->param.shift >> 5;
-               ci = e->param.index;
-               if (bs == 0)
-                       ci += p->data[bs]->start;
-
-               e->inst[ei] &= ~e->param.mask;
-               e->inst[ei] |= (ci << e->param.shift);
+               up[i++] = e->inst[0];
+               if (is_long(e))
+                       up[i++] = e->inst[1];
        }
+       assert(i == p->exec_size);
 
        if (p->data[0])
                p->data_start[0] = p->data[0]->start;
@@ -3033,45 +3196,12 @@ nv50_program_validate_code(struct nv50_context *nv50, struct nv50_program *p)
                        NOUVEAU_ERR("0x%08x\n", e->inst[1]);
        }
 #endif
-
-       up = ptr = MALLOC(p->exec_size * 4);
-       for (e = p->exec_head; e; e = e->next) {
-               *(ptr++) = e->inst[0];
-               if (is_long(e))
-                       *(ptr++) = e->inst[1];
-       }
-
-       so = so_new(4,2);
-       so_method(so, nv50->screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3);
-       so_reloc (so, p->bo, 0, flags | NOUVEAU_BO_HIGH, 0, 0);
-       so_reloc (so, p->bo, 0, flags | NOUVEAU_BO_LOW, 0, 0);
-       so_data  (so, (NV50_CB_PUPLOAD << 16) | 0x0800); //(p->exec_size * 4));
-
-       start = 0; count = p->exec_size;
-       while (count) {
-               struct nouveau_channel *chan = nv50->screen->base.channel;
-               unsigned nr;
-
-               so_emit(chan, so);
-
-               nr = MIN2(count, 2047);
-               nr = MIN2(chan->pushbuf->remaining, nr);
-               if (chan->pushbuf->remaining < (nr + 3)) {
-                       FIRE_RING(chan);
-                       continue;
-               }
-
-               BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 1);
-               OUT_RING  (chan, (start << 8) | NV50_CB_PUPLOAD);
-               BEGIN_RING(chan, tesla, NV50TCL_CB_DATA(0) | 0x40000000, nr);
-               OUT_RINGp (chan, up + start, nr);
-
-               start += nr;
-               count -= nr;
-       }
+       nv50_upload_sifc(nv50, p->bo, 0, NOUVEAU_BO_VRAM,
+                        NV50_2D_DST_FORMAT_R8_UNORM, 65536, 1, 262144,
+                        up, NV50_2D_SIFC_FORMAT_R8_UNORM, 0,
+                        0, 0, p->exec_size * 4, 1, 1);
 
        FREE(up);
-       so_ref(NULL, &so);
 }
 
 void
@@ -3153,15 +3283,15 @@ nv50_pntc_replace(struct nv50_context *nv50, uint32_t pntc[8], unsigned base)
        struct nv50_program *vp = nv50->vertprog;
        unsigned i, c, m = base;
 
-       /* XXX: This can't work correctly in all cases yet, we either
-        * have to create TGSI_SEMANTIC_PNTC or sprite_coord_mode has
-        * to be per FP input instead of per VP output
+       /* XXX: this might not work correctly in all cases yet - we'll
+        * just assume that an FP generic input that is not written in
+        * the VP is PointCoord.
         */
        memset(pntc, 0, 8 * sizeof(uint32_t));
 
        for (i = 0; i < fp->cfg.io_nr; i++) {
                uint8_t sn, si;
-               uint8_t j = fp->cfg.io[i].id_vp, k = fp->cfg.io[i].id_fp;
+               uint8_t j, k = fp->cfg.io[i].id;
                unsigned n = popcnt4(fp->cfg.io[i].mask);
 
                if (fp->info.input_semantic_name[k] != TGSI_SEMANTIC_GENERIC) {
@@ -3169,10 +3299,16 @@ nv50_pntc_replace(struct nv50_context *nv50, uint32_t pntc[8], unsigned base)
                        continue;
                }
 
-               sn = vp->info.input_semantic_name[j];
-               si = vp->info.input_semantic_index[j];
+               for (j = 0; j < vp->info.num_outputs; ++j) {
+                       sn = vp->info.output_semantic_name[j];
+                       si = vp->info.output_semantic_index[j];
 
-               if (j < fp->cfg.io_nr && sn == TGSI_SEMANTIC_GENERIC) {
+                       if (sn == fp->info.input_semantic_name[k] &&
+                           si == fp->info.input_semantic_index[k])
+                               break;
+               }
+
+               if (j < vp->info.num_outputs) {
                        ubyte mode =
                                nv50->rasterizer->pipe.sprite_coord_mode[si];
 
@@ -3260,20 +3396,24 @@ nv50_linkage_validate(struct nv50_context *nv50)
        reg[0] += m - 4; /* adjust FFC0 id */
        reg[4] |= m << 8; /* set mid where 'normal' FP inputs start */
 
-       i = 0;
-       if (fp->info.input_semantic_name[0] == TGSI_SEMANTIC_POSITION)
-               i = 1;
-       for (; i < fp->cfg.io_nr; i++) {
-               ubyte sn = fp->info.input_semantic_name[fp->cfg.io[i].id_fp];
-               ubyte si = fp->info.input_semantic_index[fp->cfg.io[i].id_fp];
-
-               n = fp->cfg.io[i].id_vp;
-               if (n >= vp->cfg.io_nr ||
-                   vp->info.output_semantic_name[n] != sn ||
-                   vp->info.output_semantic_index[n] != si)
-                       vpo = &dummy;
-               else
-                       vpo = &vp->cfg.io[n];
+       for (i = 0; i < fp->cfg.io_nr; i++) {
+               ubyte sn = fp->info.input_semantic_name[fp->cfg.io[i].id];
+               ubyte si = fp->info.input_semantic_index[fp->cfg.io[i].id];
+
+               /* position must be mapped first */
+               assert(i == 0 || sn != TGSI_SEMANTIC_POSITION);
+
+               /* maybe even remove these from cfg.io */
+               if (sn == TGSI_SEMANTIC_POSITION || sn == TGSI_SEMANTIC_FACE)
+                       continue;
+
+               /* VP outputs and vp->cfg.io are in the same order */
+               for (n = 0; n < vp->info.num_outputs; ++n) {
+                       if (vp->info.output_semantic_name[n] == sn &&
+                           vp->info.output_semantic_index[n] == si)
+                               break;
+               }
+               vpo = (n < vp->info.num_outputs) ? &vp->cfg.io[n] : &dummy;
 
                m = nv50_sreg4_map(map, m, lin, &fp->cfg.io[i], vpo);
        }