Squashed commit of the following:
[mesa.git] / src / gallium / drivers / nvfx / nvfx_vertprog.c
index 3d0e8c23a1522143d7ddca013805b4d2ba299922..3547cad6aebbb5330c8114990f210a5734ab9aa5 100644 (file)
  *  4. bugs
  */
 
-#define SWZ_X 0
-#define SWZ_Y 1
-#define SWZ_Z 2
-#define SWZ_W 3
-#define MASK_X 8
-#define MASK_Y 4
-#define MASK_Z 2
-#define MASK_W 1
-#define MASK_ALL (MASK_X|MASK_Y|MASK_Z|MASK_W)
-#define DEF_SCALE 0
-#define DEF_CTEST 0
 #include "nv30_vertprog.h"
 #include "nv40_vertprog.h"
 
-#define swz(s,x,y,z,w) nvfx_sr_swz((s), SWZ_##x, SWZ_##y, SWZ_##z, SWZ_##w)
-#define neg(s) nvfx_sr_neg((s))
-#define abs(s) nvfx_sr_abs((s))
-
 #define NVFX_VP_INST_DEST_CLIP(n) ((~0 - 6) + (n))
 
 struct nvfx_vpc {
@@ -307,7 +292,7 @@ nvfx_vp_arith(struct nvfx_context* nvfx, struct nvfx_vpc *vpc, int slot, int op,
 
        hw = vpc->vpi->data;
 
-       hw[0] |= (NVFX_VP_INST_COND_TR << NVFX_VP(INST_COND_SHIFT));
+       hw[0] |= (NVFX_COND_TR << NVFX_VP(INST_COND_SHIFT));
        hw[0] |= ((0 << NVFX_VP(INST_COND_SWZ_X_SHIFT)) |
                  (1 << NVFX_VP(INST_COND_SWZ_Y_SHIFT)) |
                  (2 << NVFX_VP(INST_COND_SWZ_Z_SHIFT)) |
@@ -405,46 +390,13 @@ tgsi_mask(uint tgsi)
 {
        int mask = 0;
 
-       if (tgsi & TGSI_WRITEMASK_X) mask |= MASK_X;
-       if (tgsi & TGSI_WRITEMASK_Y) mask |= MASK_Y;
-       if (tgsi & TGSI_WRITEMASK_Z) mask |= MASK_Z;
-       if (tgsi & TGSI_WRITEMASK_W) mask |= MASK_W;
+       if (tgsi & TGSI_WRITEMASK_X) mask |= NVFX_VP_MASK_X;
+       if (tgsi & TGSI_WRITEMASK_Y) mask |= NVFX_VP_MASK_Y;
+       if (tgsi & TGSI_WRITEMASK_Z) mask |= NVFX_VP_MASK_Z;
+       if (tgsi & TGSI_WRITEMASK_W) mask |= NVFX_VP_MASK_W;
        return mask;
 }
 
-static boolean
-src_native_swz(struct nvfx_context* nvfx, struct nvfx_vpc *vpc, const struct tgsi_full_src_register *fsrc,
-              struct nvfx_sreg *src)
-{
-       const struct nvfx_sreg none = nvfx_sr(NVFXSR_NONE, 0);
-       struct nvfx_sreg tgsi = tgsi_src(vpc, fsrc);
-       uint mask = 0;
-       uint c;
-
-       for (c = 0; c < 4; c++) {
-               switch (tgsi_util_get_full_src_register_swizzle(fsrc, c)) {
-               case TGSI_SWIZZLE_X:
-               case TGSI_SWIZZLE_Y:
-               case TGSI_SWIZZLE_Z:
-               case TGSI_SWIZZLE_W:
-                       mask |= tgsi_mask(1 << c);
-                       break;
-               default:
-                       assert(0);
-               }
-       }
-
-       if (mask == MASK_ALL)
-               return TRUE;
-
-       *src = temp(vpc);
-
-       if (mask)
-               arith(vpc, VEC, MOV, *src, mask, tgsi, none, none);
-
-       return FALSE;
-}
-
 static boolean
 nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc,
                                const struct tgsi_full_instruction *finst)
@@ -472,17 +424,6 @@ nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc,
 
                fsrc = &finst->Src[i];
 
-               switch (fsrc->Register.File) {
-               case TGSI_FILE_INPUT:
-               case TGSI_FILE_CONSTANT:
-               case TGSI_FILE_TEMPORARY:
-                       if (!src_native_swz(nvfx, vpc, fsrc, &src[i]))
-                               continue;
-                       break;
-               default:
-                       break;
-               }
-
                switch (fsrc->Register.File) {
                case TGSI_FILE_INPUT:
                        if (ai == -1 || ai == fsrc->Register.Index) {
@@ -490,7 +431,7 @@ nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc,
                                src[i] = tgsi_src(vpc, fsrc);
                        } else {
                                src[i] = temp(vpc);
-                               arith(vpc, VEC, MOV, src[i], MASK_ALL,
+                               arith(vpc, VEC, MOV, src[i], NVFX_VP_MASK_ALL,
                                      tgsi_src(vpc, fsrc), none, none);
                        }
                        break;
@@ -501,7 +442,7 @@ nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc,
                                src[i] = tgsi_src(vpc, fsrc);
                        } else {
                                src[i] = temp(vpc);
-                               arith(vpc, VEC, MOV, src[i], MASK_ALL,
+                               arith(vpc, VEC, MOV, src[i], NVFX_VP_MASK_ALL,
                                      tgsi_src(vpc, fsrc), none, none);
                        }
                        break;
@@ -512,7 +453,7 @@ nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc,
                                src[i] = tgsi_src(vpc, fsrc);
                        } else {
                                src[i] = temp(vpc);
-                               arith(vpc, VEC, MOV, src[i], MASK_ALL,
+                               arith(vpc, VEC, MOV, src[i], NVFX_VP_MASK_ALL,
                                      tgsi_src(vpc, fsrc), none, none);
                        }
                        break;
@@ -588,9 +529,9 @@ nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc,
                break;
        case TGSI_OPCODE_POW:
                tmp = temp(vpc);
-               arith(vpc, SCA, LG2, tmp, MASK_X, none, none,
+               arith(vpc, SCA, LG2, tmp, NVFX_VP_MASK_X, none, none,
                      swz(src[0], X, X, X, X));
-               arith(vpc, VEC, MUL, tmp, MASK_X, swz(tmp, X, X, X, X),
+               arith(vpc, VEC, MUL, tmp, NVFX_VP_MASK_X, swz(tmp, X, X, X, X),
                      swz(src[1], X, X, X, X), none);
                arith(vpc, SCA, EX2, dst, mask, none, none,
                      swz(tmp, X, X, X, X));
@@ -619,7 +560,7 @@ nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc,
                tmp = temp(vpc);
                arith(vpc, VEC, MUL, tmp, mask,
                      swz(src[0], Z, X, Y, Y), swz(src[1], Y, Z, X, X), none);
-               arith(vpc, VEC, MAD, dst, (mask & ~MASK_W),
+               arith(vpc, VEC, MAD, dst, (mask & ~NVFX_VP_MASK_W),
                      swz(src[0], Y, Z, X, X), swz(src[1], Z, X, Y, Y),
                      neg(tmp));
                break;
@@ -849,7 +790,7 @@ nvfx_vertprog_translate(struct nvfx_context *nvfx,
                                                NVFX_VP(INST_DEST_POS));
                struct nvfx_sreg htmp = vpc->r_result[vpc->hpos_idx];
 
-               arith(vpc, VEC, MOV, hpos, MASK_ALL, htmp, none, none);
+               arith(vpc, VEC, MOV, hpos, NVFX_VP_MASK_ALL, htmp, none, none);
        }
 
        /* Insert code to handle user clip planes */
@@ -865,9 +806,9 @@ nvfx_vertprog_translate(struct nvfx_context *nvfx,
                unsigned mask;
 
                switch (i) {
-               case 0: case 3: mask = MASK_Y; break;
-               case 1: case 4: mask = MASK_Z; break;
-               case 2: case 5: mask = MASK_W; break;
+               case 0: case 3: mask = NVFX_VP_MASK_Y; break;
+               case 1: case 4: mask = NVFX_VP_MASK_Z; break;
+               case 2: case 5: mask = NVFX_VP_MASK_W; break;
                default:
                        NOUVEAU_ERR("invalid clip dist #%d\n", i);
                        goto out_err;
@@ -892,12 +833,13 @@ out_err:
 static boolean
 nvfx_vertprog_validate(struct nvfx_context *nvfx)
 {
-       struct pipe_screen *pscreen = nvfx->pipe.screen;
+       struct pipe_context *pipe = &nvfx->pipe;
        struct nvfx_screen *screen = nvfx->screen;
        struct nouveau_channel *chan = screen->base.channel;
        struct nouveau_grobj *eng3d = screen->eng3d;
        struct nvfx_vertex_program *vp;
-       struct pipe_buffer *constbuf;
+       struct pipe_resource *constbuf;
+       struct pipe_transfer *transfer;
        boolean upload_code = FALSE, upload_data = FALSE;
        int i;
 
@@ -1021,8 +963,9 @@ check_gpu_resources:
                float *map = NULL;
 
                if (constbuf) {
-                       map = pipe_buffer_map(pscreen, constbuf,
-                                             PIPE_BUFFER_USAGE_CPU_READ);
+                       map = pipe_buffer_map(pipe, constbuf,
+                                             PIPE_TRANSFER_READ,
+                                             &transfer);
                }
 
                for (i = 0; i < vp->nr_consts; i++) {
@@ -1043,7 +986,7 @@ check_gpu_resources:
                }
 
                if (constbuf)
-                       pipe_buffer_unmap(pscreen, constbuf);
+                       pipe_buffer_unmap(pipe, constbuf, transfer);
        }
 
        /* Upload vtxprog */