1 #include "pipe/p_context.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_state.h"
4 #include "util/u_linkage.h"
5 #include "util/u_debug.h"
7 #include "pipe/p_shader_tokens.h"
8 #include "tgsi/tgsi_parse.h"
9 #include "tgsi/tgsi_dump.h"
10 #include "tgsi/tgsi_util.h"
12 #include "nvfx_context.h"
13 #include "nvfx_state.h"
14 #include "nvfx_resource.h"
16 /* TODO (at least...):
17 * 1. Indexed consts + ARL
18 * 3. NV_vp11, NV_vp2, NV_vp3 features
19 * - extra arith opcodes
27 #include "nv30_vertprog.h"
28 #include "nv40_vertprog.h"
30 #define NVFX_VP_INST_DEST_CLIP(n) ((~0 - 6) + (n))
32 struct nvfx_loop_entry
39 struct nvfx_context
* nvfx
;
40 struct nvfx_vertex_program
*vp
;
42 struct nvfx_vertex_program_exec
*vpi
;
45 unsigned r_temps_discard
;
46 struct nvfx_reg r_result
[PIPE_MAX_SHADER_OUTPUTS
];
47 struct nvfx_reg
*r_address
;
48 struct nvfx_reg
*r_temp
;
55 struct util_dynarray label_relocs
;
56 struct util_dynarray loop_stack
;
59 static struct nvfx_reg
60 temp(struct nvfx_vpc
*vpc
)
62 int idx
= ffs(~vpc
->r_temps
) - 1;
65 NOUVEAU_ERR("out of temps!!\n");
67 return nvfx_reg(NVFXSR_TEMP
, 0);
70 vpc
->r_temps
|= (1 << idx
);
71 vpc
->r_temps_discard
|= (1 << idx
);
72 return nvfx_reg(NVFXSR_TEMP
, idx
);
76 release_temps(struct nvfx_vpc
*vpc
)
78 vpc
->r_temps
&= ~vpc
->r_temps_discard
;
79 vpc
->r_temps_discard
= 0;
82 static struct nvfx_reg
83 constant(struct nvfx_vpc
*vpc
, int pipe
, float x
, float y
, float z
, float w
)
85 struct nvfx_vertex_program
*vp
= vpc
->vp
;
86 struct nvfx_vertex_program_data
*vpd
;
90 for (idx
= 0; idx
< vp
->nr_consts
; idx
++) {
91 if (vp
->consts
[idx
].index
== pipe
)
92 return nvfx_reg(NVFXSR_CONST
, idx
);
96 idx
= vp
->nr_consts
++;
97 vp
->consts
= realloc(vp
->consts
, sizeof(*vpd
) * vp
->nr_consts
);
98 vpd
= &vp
->consts
[idx
];
105 return nvfx_reg(NVFXSR_CONST
, idx
);
108 #define arith(s,o,d,m,s0,s1,s2) \
109 nvfx_insn(0, (NVFX_VP_INST_SLOT_##s << 7) | NVFX_VP_INST_##s##_OP_##o, -1, (d), (m), (s0), (s1), (s2))
112 emit_src(struct nvfx_context
* nvfx
, struct nvfx_vpc
*vpc
, uint32_t *hw
, int pos
, struct nvfx_src src
)
114 struct nvfx_vertex_program
*vp
= vpc
->vp
;
116 struct nvfx_relocation reloc
;
118 switch (src
.reg
.type
) {
120 sr
|= (NVFX_VP(SRC_REG_TYPE_TEMP
) << NVFX_VP(SRC_REG_TYPE_SHIFT
));
121 sr
|= (src
.reg
.index
<< NVFX_VP(SRC_TEMP_SRC_SHIFT
));
124 sr
|= (NVFX_VP(SRC_REG_TYPE_INPUT
) <<
125 NVFX_VP(SRC_REG_TYPE_SHIFT
));
126 vp
->ir
|= (1 << src
.reg
.index
);
127 hw
[1] |= (src
.reg
.index
<< NVFX_VP(INST_INPUT_SRC_SHIFT
));
130 sr
|= (NVFX_VP(SRC_REG_TYPE_CONST
) <<
131 NVFX_VP(SRC_REG_TYPE_SHIFT
));
132 reloc
.location
= vp
->nr_insns
- 1;
133 reloc
.target
= src
.reg
.index
;
134 util_dynarray_append(&vp
->const_relocs
, struct nvfx_relocation
, reloc
);
137 sr
|= (NVFX_VP(SRC_REG_TYPE_INPUT
) <<
138 NVFX_VP(SRC_REG_TYPE_SHIFT
));
145 sr
|= NVFX_VP(SRC_NEGATE
);
148 hw
[0] |= (1 << (21 + pos
));
150 sr
|= ((src
.swz
[0] << NVFX_VP(SRC_SWZ_X_SHIFT
)) |
151 (src
.swz
[1] << NVFX_VP(SRC_SWZ_Y_SHIFT
)) |
152 (src
.swz
[2] << NVFX_VP(SRC_SWZ_Z_SHIFT
)) |
153 (src
.swz
[3] << NVFX_VP(SRC_SWZ_W_SHIFT
)));
157 hw
[1] |= ((sr
& NVFX_VP(SRC0_HIGH_MASK
)) >>
158 NVFX_VP(SRC0_HIGH_SHIFT
)) << NVFX_VP(INST_SRC0H_SHIFT
);
159 hw
[2] |= (sr
& NVFX_VP(SRC0_LOW_MASK
)) <<
160 NVFX_VP(INST_SRC0L_SHIFT
);
163 hw
[2] |= sr
<< NVFX_VP(INST_SRC1_SHIFT
);
166 hw
[2] |= ((sr
& NVFX_VP(SRC2_HIGH_MASK
)) >>
167 NVFX_VP(SRC2_HIGH_SHIFT
)) << NVFX_VP(INST_SRC2H_SHIFT
);
168 hw
[3] |= (sr
& NVFX_VP(SRC2_LOW_MASK
)) <<
169 NVFX_VP(INST_SRC2L_SHIFT
);
177 emit_dst(struct nvfx_context
* nvfx
, struct nvfx_vpc
*vpc
, uint32_t *hw
, int slot
, struct nvfx_reg dst
)
179 struct nvfx_vertex_program
*vp
= vpc
->vp
;
184 hw
[0] |= NV30_VP_INST_DEST_TEMP_ID_MASK
;
186 hw
[3] |= NV40_VP_INST_DEST_MASK
;
188 hw
[0] |= NV40_VP_INST_VEC_DEST_TEMP_MASK
;
190 hw
[3] |= NV40_VP_INST_SCA_DEST_TEMP_MASK
;
195 hw
[0] |= (dst
.index
<< NV30_VP_INST_DEST_TEMP_ID_SHIFT
);
197 hw
[3] |= NV40_VP_INST_DEST_MASK
;
199 hw
[0] |= (dst
.index
<< NV40_VP_INST_VEC_DEST_TEMP_SHIFT
);
201 hw
[3] |= (dst
.index
<< NV40_VP_INST_SCA_DEST_TEMP_SHIFT
);
205 /* TODO: this may be wrong because on nv30 COL0 and BFC0 are swapped */
207 case NVFX_VP_INST_DEST_CLIP(0):
209 vp
->clip_ctrl
|= NV34TCL_VP_CLIP_PLANES_ENABLE_PLANE0
;
210 dst
.index
= NVFX_VP(INST_DEST_FOGC
);
212 case NVFX_VP_INST_DEST_CLIP(1):
214 vp
->clip_ctrl
|= NV34TCL_VP_CLIP_PLANES_ENABLE_PLANE1
;
215 dst
.index
= NVFX_VP(INST_DEST_FOGC
);
217 case NVFX_VP_INST_DEST_CLIP(2):
219 vp
->clip_ctrl
|= NV34TCL_VP_CLIP_PLANES_ENABLE_PLANE2
;
220 dst
.index
= NVFX_VP(INST_DEST_FOGC
);
222 case NVFX_VP_INST_DEST_CLIP(3):
224 vp
->clip_ctrl
|= NV34TCL_VP_CLIP_PLANES_ENABLE_PLANE3
;
225 dst
.index
= NVFX_VP(INST_DEST_PSZ
);
227 case NVFX_VP_INST_DEST_CLIP(4):
229 vp
->clip_ctrl
|= NV34TCL_VP_CLIP_PLANES_ENABLE_PLANE4
;
230 dst
.index
= NVFX_VP(INST_DEST_PSZ
);
232 case NVFX_VP_INST_DEST_CLIP(5):
234 vp
->clip_ctrl
|= NV34TCL_VP_CLIP_PLANES_ENABLE_PLANE5
;
235 dst
.index
= NVFX_VP(INST_DEST_PSZ
);
239 /* we don't need vp->or on nv3x
240 * texcoords are handled by fragment program
243 case NV40_VP_INST_DEST_COL0
: vp
->or |= (1 << 0); break;
244 case NV40_VP_INST_DEST_COL1
: vp
->or |= (1 << 1); break;
245 case NV40_VP_INST_DEST_BFC0
: vp
->or |= (1 << 2); break;
246 case NV40_VP_INST_DEST_BFC1
: vp
->or |= (1 << 3); break;
247 case NV40_VP_INST_DEST_FOGC
: vp
->or |= (1 << 4); break;
248 case NV40_VP_INST_DEST_PSZ
: vp
->or |= (1 << 5); break;
255 hw
[3] |= (dst
.index
<< NV30_VP_INST_DEST_SHIFT
);
256 hw
[0] |= NV30_VP_INST_VEC_DEST_TEMP_MASK
;
258 /*XXX: no way this is entirely correct, someone needs to
259 * figure out what exactly it is.
263 hw
[3] |= (dst
.index
<< NV40_VP_INST_DEST_SHIFT
);
265 hw
[0] |= NV40_VP_INST_VEC_RESULT
;
266 hw
[0] |= NV40_VP_INST_VEC_DEST_TEMP_MASK
;
268 hw
[3] |= NV40_VP_INST_SCA_RESULT
;
269 hw
[3] |= NV40_VP_INST_SCA_DEST_TEMP_MASK
;
279 nvfx_vp_emit(struct nvfx_vpc
*vpc
, struct nvfx_insn insn
)
281 struct nvfx_context
* nvfx
= vpc
->nvfx
;
282 struct nvfx_vertex_program
*vp
= vpc
->vp
;
283 unsigned slot
= insn
.op
>> 7;
284 unsigned op
= insn
.op
& 0x7f;
287 vp
->insns
= realloc(vp
->insns
, ++vp
->nr_insns
* sizeof(*vpc
->vpi
));
288 vpc
->vpi
= &vp
->insns
[vp
->nr_insns
- 1];
289 memset(vpc
->vpi
, 0, sizeof(*vpc
->vpi
));
293 hw
[0] |= (insn
.cc_test
<< NVFX_VP(INST_COND_SHIFT
));
294 hw
[0] |= ((insn
.cc_swz
[0] << NVFX_VP(INST_COND_SWZ_X_SHIFT
)) |
295 (insn
.cc_swz
[1] << NVFX_VP(INST_COND_SWZ_Y_SHIFT
)) |
296 (insn
.cc_swz
[2] << NVFX_VP(INST_COND_SWZ_Z_SHIFT
)) |
297 (insn
.cc_swz
[3] << NVFX_VP(INST_COND_SWZ_W_SHIFT
)));
299 hw
[0] |= NVFX_VP(INST_COND_UPDATE_ENABLE
);
303 hw
[1] |= (op
<< NV30_VP_INST_VEC_OPCODE_SHIFT
);
306 hw
[0] |= ((op
>> 4) << NV30_VP_INST_SCA_OPCODEH_SHIFT
);
307 hw
[1] |= ((op
& 0xf) << NV30_VP_INST_SCA_OPCODEL_SHIFT
);
309 // hw[3] |= NVFX_VP(INST_SCA_DEST_TEMP_MASK);
310 // hw[3] |= (mask << NVFX_VP(INST_VEC_WRITEMASK_SHIFT));
312 if (insn
.dst
.type
== NVFXSR_OUTPUT
) {
314 hw
[3] |= (insn
.mask
<< NV30_VP_INST_SDEST_WRITEMASK_SHIFT
);
316 hw
[3] |= (insn
.mask
<< NV30_VP_INST_VDEST_WRITEMASK_SHIFT
);
319 hw
[3] |= (insn
.mask
<< NV30_VP_INST_STEMP_WRITEMASK_SHIFT
);
321 hw
[3] |= (insn
.mask
<< NV30_VP_INST_VTEMP_WRITEMASK_SHIFT
);
325 hw
[1] |= (op
<< NV40_VP_INST_VEC_OPCODE_SHIFT
);
326 hw
[3] |= NV40_VP_INST_SCA_DEST_TEMP_MASK
;
327 hw
[3] |= (insn
.mask
<< NV40_VP_INST_VEC_WRITEMASK_SHIFT
);
329 hw
[1] |= (op
<< NV40_VP_INST_SCA_OPCODE_SHIFT
);
330 hw
[0] |= NV40_VP_INST_VEC_DEST_TEMP_MASK
;
331 hw
[3] |= (insn
.mask
<< NV40_VP_INST_SCA_WRITEMASK_SHIFT
);
335 emit_dst(nvfx
, vpc
, hw
, slot
, insn
.dst
);
336 emit_src(nvfx
, vpc
, hw
, 0, insn
.src
[0]);
337 emit_src(nvfx
, vpc
, hw
, 1, insn
.src
[1]);
338 emit_src(nvfx
, vpc
, hw
, 2, insn
.src
[2]);
341 static inline struct nvfx_src
342 tgsi_src(struct nvfx_vpc
*vpc
, const struct tgsi_full_src_register
*fsrc
) {
345 switch (fsrc
->Register
.File
) {
346 case TGSI_FILE_INPUT
:
347 src
.reg
= nvfx_reg(NVFXSR_INPUT
, fsrc
->Register
.Index
);
349 case TGSI_FILE_CONSTANT
:
350 src
.reg
= constant(vpc
, fsrc
->Register
.Index
, 0, 0, 0, 0);
352 case TGSI_FILE_IMMEDIATE
:
353 src
.reg
= vpc
->imm
[fsrc
->Register
.Index
];
355 case TGSI_FILE_TEMPORARY
:
356 src
.reg
= vpc
->r_temp
[fsrc
->Register
.Index
];
359 NOUVEAU_ERR("bad src file\n");
365 src
.abs
= fsrc
->Register
.Absolute
;
366 src
.negate
= fsrc
->Register
.Negate
;
367 src
.swz
[0] = fsrc
->Register
.SwizzleX
;
368 src
.swz
[1] = fsrc
->Register
.SwizzleY
;
369 src
.swz
[2] = fsrc
->Register
.SwizzleZ
;
370 src
.swz
[3] = fsrc
->Register
.SwizzleW
;
374 static INLINE
struct nvfx_reg
375 tgsi_dst(struct nvfx_vpc
*vpc
, const struct tgsi_full_dst_register
*fdst
) {
378 switch (fdst
->Register
.File
) {
380 dst
= nvfx_reg(NVFXSR_NONE
, 0);
382 case TGSI_FILE_OUTPUT
:
383 dst
= vpc
->r_result
[fdst
->Register
.Index
];
385 case TGSI_FILE_TEMPORARY
:
386 dst
= vpc
->r_temp
[fdst
->Register
.Index
];
388 case TGSI_FILE_ADDRESS
:
389 dst
= vpc
->r_address
[fdst
->Register
.Index
];
392 NOUVEAU_ERR("bad dst file %i\n", fdst
->Register
.File
);
406 if (tgsi
& TGSI_WRITEMASK_X
) mask
|= NVFX_VP_MASK_X
;
407 if (tgsi
& TGSI_WRITEMASK_Y
) mask
|= NVFX_VP_MASK_Y
;
408 if (tgsi
& TGSI_WRITEMASK_Z
) mask
|= NVFX_VP_MASK_Z
;
409 if (tgsi
& TGSI_WRITEMASK_W
) mask
|= NVFX_VP_MASK_W
;
414 nvfx_vertprog_parse_instruction(struct nvfx_context
* nvfx
, struct nvfx_vpc
*vpc
,
415 unsigned idx
, const struct tgsi_full_instruction
*finst
)
417 struct nvfx_src src
[3], tmp
;
419 struct nvfx_src none
= nvfx_src(nvfx_reg(NVFXSR_NONE
, 0));
420 struct nvfx_insn insn
;
421 struct nvfx_relocation reloc
;
422 struct nvfx_loop_entry loop
;
424 int ai
= -1, ci
= -1, ii
= -1;
427 if (finst
->Instruction
.Opcode
== TGSI_OPCODE_END
)
430 for (i
= 0; i
< finst
->Instruction
.NumSrcRegs
; i
++) {
431 const struct tgsi_full_src_register
*fsrc
;
433 fsrc
= &finst
->Src
[i
];
434 if (fsrc
->Register
.File
== TGSI_FILE_TEMPORARY
) {
435 src
[i
] = tgsi_src(vpc
, fsrc
);
439 for (i
= 0; i
< finst
->Instruction
.NumSrcRegs
; i
++) {
440 const struct tgsi_full_src_register
*fsrc
;
442 fsrc
= &finst
->Src
[i
];
444 switch (fsrc
->Register
.File
) {
445 case TGSI_FILE_INPUT
:
446 if (ai
== -1 || ai
== fsrc
->Register
.Index
) {
447 ai
= fsrc
->Register
.Index
;
448 src
[i
] = tgsi_src(vpc
, fsrc
);
450 src
[i
] = nvfx_src(temp(vpc
));
451 nvfx_vp_emit(vpc
, arith(VEC
, MOV
, src
[i
].reg
, NVFX_VP_MASK_ALL
, tgsi_src(vpc
, fsrc
), none
, none
));
454 case TGSI_FILE_CONSTANT
:
455 if ((ci
== -1 && ii
== -1) ||
456 ci
== fsrc
->Register
.Index
) {
457 ci
= fsrc
->Register
.Index
;
458 src
[i
] = tgsi_src(vpc
, fsrc
);
460 src
[i
] = nvfx_src(temp(vpc
));
461 nvfx_vp_emit(vpc
, arith(VEC
, MOV
, src
[i
].reg
, NVFX_VP_MASK_ALL
, tgsi_src(vpc
, fsrc
), none
, none
));
464 case TGSI_FILE_IMMEDIATE
:
465 if ((ci
== -1 && ii
== -1) ||
466 ii
== fsrc
->Register
.Index
) {
467 ii
= fsrc
->Register
.Index
;
468 src
[i
] = tgsi_src(vpc
, fsrc
);
470 src
[i
] = nvfx_src(temp(vpc
));
471 nvfx_vp_emit(vpc
, arith(VEC
, MOV
, src
[i
].reg
, NVFX_VP_MASK_ALL
, tgsi_src(vpc
, fsrc
), none
, none
));
474 case TGSI_FILE_TEMPORARY
:
478 NOUVEAU_ERR("bad src file\n");
483 dst
= tgsi_dst(vpc
, &finst
->Dst
[0]);
484 mask
= tgsi_mask(finst
->Dst
[0].Register
.WriteMask
);
486 switch (finst
->Instruction
.Opcode
) {
487 case TGSI_OPCODE_ABS
:
488 nvfx_vp_emit(vpc
, arith(VEC
, MOV
, dst
, mask
, abs(src
[0]), none
, none
));
490 case TGSI_OPCODE_ADD
:
491 nvfx_vp_emit(vpc
, arith(VEC
, ADD
, dst
, mask
, src
[0], none
, src
[1]));
493 case TGSI_OPCODE_ARL
:
494 nvfx_vp_emit(vpc
, arith(VEC
, ARL
, dst
, mask
, src
[0], none
, none
));
496 case TGSI_OPCODE_CMP
:
497 insn
= arith(VEC
, MOV
, none
.reg
, mask
, src
[0], none
, none
);
499 nvfx_vp_emit(vpc
, insn
);
501 insn
= arith(VEC
, MOV
, dst
, mask
, src
[2], none
, none
);
502 insn
.cc_test
= NVFX_COND_GE
;
503 nvfx_vp_emit(vpc
, insn
);
505 insn
= arith(VEC
, MOV
, dst
, mask
, src
[1], none
, none
);
506 insn
.cc_test
= NVFX_COND_LT
;
507 nvfx_vp_emit(vpc
, insn
);
509 case TGSI_OPCODE_COS
:
510 nvfx_vp_emit(vpc
, arith(SCA
, COS
, dst
, mask
, none
, none
, src
[0]));
512 case TGSI_OPCODE_DP2
:
513 tmp
= nvfx_src(temp(vpc
));
514 nvfx_vp_emit(vpc
, arith(VEC
, MUL
, tmp
.reg
, NVFX_VP_MASK_X
| NVFX_VP_MASK_Y
, src
[0], src
[1], none
));
515 nvfx_vp_emit(vpc
, arith(VEC
, ADD
, dst
, mask
, swz(tmp
, X
, X
, X
, X
), swz(tmp
, Y
, Y
, Y
, Y
), none
));
517 case TGSI_OPCODE_DP3
:
518 nvfx_vp_emit(vpc
, arith(VEC
, DP3
, dst
, mask
, src
[0], src
[1], none
));
520 case TGSI_OPCODE_DP4
:
521 nvfx_vp_emit(vpc
, arith(VEC
, DP4
, dst
, mask
, src
[0], src
[1], none
));
523 case TGSI_OPCODE_DPH
:
524 nvfx_vp_emit(vpc
, arith(VEC
, DPH
, dst
, mask
, src
[0], src
[1], none
));
526 case TGSI_OPCODE_DST
:
527 nvfx_vp_emit(vpc
, arith(VEC
, DST
, dst
, mask
, src
[0], src
[1], none
));
529 case TGSI_OPCODE_EX2
:
530 nvfx_vp_emit(vpc
, arith(SCA
, EX2
, dst
, mask
, none
, none
, src
[0]));
532 case TGSI_OPCODE_EXP
:
533 nvfx_vp_emit(vpc
, arith(SCA
, EXP
, dst
, mask
, none
, none
, src
[0]));
535 case TGSI_OPCODE_FLR
:
536 nvfx_vp_emit(vpc
, arith(VEC
, FLR
, dst
, mask
, src
[0], none
, none
));
538 case TGSI_OPCODE_FRC
:
539 nvfx_vp_emit(vpc
, arith(VEC
, FRC
, dst
, mask
, src
[0], none
, none
));
541 case TGSI_OPCODE_LG2
:
542 nvfx_vp_emit(vpc
, arith(SCA
, LG2
, dst
, mask
, none
, none
, src
[0]));
544 case TGSI_OPCODE_LIT
:
545 nvfx_vp_emit(vpc
, arith(SCA
, LIT
, dst
, mask
, none
, none
, src
[0]));
547 case TGSI_OPCODE_LOG
:
548 nvfx_vp_emit(vpc
, arith(SCA
, LOG
, dst
, mask
, none
, none
, src
[0]));
550 case TGSI_OPCODE_LRP
:
551 tmp
= nvfx_src(temp(vpc
));
552 nvfx_vp_emit(vpc
, arith(VEC
, MAD
, tmp
.reg
, mask
, neg(src
[0]), src
[2], src
[2]));
553 nvfx_vp_emit(vpc
, arith(VEC
, MAD
, dst
, mask
, src
[0], src
[1], tmp
));
555 case TGSI_OPCODE_MAD
:
556 nvfx_vp_emit(vpc
, arith(VEC
, MAD
, dst
, mask
, src
[0], src
[1], src
[2]));
558 case TGSI_OPCODE_MAX
:
559 nvfx_vp_emit(vpc
, arith(VEC
, MAX
, dst
, mask
, src
[0], src
[1], none
));
561 case TGSI_OPCODE_MIN
:
562 nvfx_vp_emit(vpc
, arith(VEC
, MIN
, dst
, mask
, src
[0], src
[1], none
));
564 case TGSI_OPCODE_MOV
:
565 nvfx_vp_emit(vpc
, arith(VEC
, MOV
, dst
, mask
, src
[0], none
, none
));
567 case TGSI_OPCODE_MUL
:
568 nvfx_vp_emit(vpc
, arith(VEC
, MUL
, dst
, mask
, src
[0], src
[1], none
));
570 case TGSI_OPCODE_NOP
:
572 case TGSI_OPCODE_POW
:
573 tmp
= nvfx_src(temp(vpc
));
574 nvfx_vp_emit(vpc
, arith(SCA
, LG2
, tmp
.reg
, NVFX_VP_MASK_X
, none
, none
, swz(src
[0], X
, X
, X
, X
)));
575 nvfx_vp_emit(vpc
, arith(VEC
, MUL
, tmp
.reg
, NVFX_VP_MASK_X
, swz(tmp
, X
, X
, X
, X
), swz(src
[1], X
, X
, X
, X
), none
));
576 nvfx_vp_emit(vpc
, arith(SCA
, EX2
, dst
, mask
, none
, none
, swz(tmp
, X
, X
, X
, X
)));
578 case TGSI_OPCODE_RCP
:
579 nvfx_vp_emit(vpc
, arith(SCA
, RCP
, dst
, mask
, none
, none
, src
[0]));
581 case TGSI_OPCODE_RSQ
:
582 nvfx_vp_emit(vpc
, arith(SCA
, RSQ
, dst
, mask
, none
, none
, abs(src
[0])));
584 case TGSI_OPCODE_SEQ
:
585 nvfx_vp_emit(vpc
, arith(VEC
, SEQ
, dst
, mask
, src
[0], src
[1], none
));
587 case TGSI_OPCODE_SFL
:
588 nvfx_vp_emit(vpc
, arith(VEC
, SFL
, dst
, mask
, src
[0], src
[1], none
));
590 case TGSI_OPCODE_SGE
:
591 nvfx_vp_emit(vpc
, arith(VEC
, SGE
, dst
, mask
, src
[0], src
[1], none
));
593 case TGSI_OPCODE_SGT
:
594 nvfx_vp_emit(vpc
, arith(VEC
, SGT
, dst
, mask
, src
[0], src
[1], none
));
596 case TGSI_OPCODE_SIN
:
597 nvfx_vp_emit(vpc
, arith(SCA
, SIN
, dst
, mask
, none
, none
, src
[0]));
599 case TGSI_OPCODE_SLE
:
600 nvfx_vp_emit(vpc
, arith(VEC
, SLE
, dst
, mask
, src
[0], src
[1], none
));
602 case TGSI_OPCODE_SLT
:
603 nvfx_vp_emit(vpc
, arith(VEC
, SLT
, dst
, mask
, src
[0], src
[1], none
));
605 case TGSI_OPCODE_SNE
:
606 nvfx_vp_emit(vpc
, arith(VEC
, SNE
, dst
, mask
, src
[0], src
[1], none
));
608 case TGSI_OPCODE_SSG
:
609 nvfx_vp_emit(vpc
, arith(VEC
, SSG
, dst
, mask
, src
[0], src
[1], none
));
611 case TGSI_OPCODE_STR
:
612 nvfx_vp_emit(vpc
, arith(VEC
, STR
, dst
, mask
, src
[0], src
[1], none
));
614 case TGSI_OPCODE_SUB
:
615 nvfx_vp_emit(vpc
, arith(VEC
, ADD
, dst
, mask
, src
[0], none
, neg(src
[1])));
617 case TGSI_OPCODE_TRUNC
:
618 tmp
= nvfx_src(temp(vpc
));
619 insn
= arith(VEC
, MOV
, none
.reg
, mask
, src
[0], none
, none
);
621 nvfx_vp_emit(vpc
, insn
);
623 nvfx_vp_emit(vpc
, arith(VEC
, FLR
, tmp
.reg
, mask
, abs(src
[0]), none
, none
));
624 nvfx_vp_emit(vpc
, arith(VEC
, MOV
, dst
, mask
, tmp
, none
, none
));
626 insn
= arith(VEC
, MOV
, dst
, mask
, neg(tmp
), none
, none
);
627 insn
.cc_test
= NVFX_COND_LT
;
628 nvfx_vp_emit(vpc
, insn
);
630 case TGSI_OPCODE_XPD
:
631 tmp
= nvfx_src(temp(vpc
));
632 nvfx_vp_emit(vpc
, arith(VEC
, MUL
, tmp
.reg
, mask
, swz(src
[0], Z
, X
, Y
, Y
), swz(src
[1], Y
, Z
, X
, X
), none
));
633 nvfx_vp_emit(vpc
, arith(VEC
, MAD
, dst
, (mask
& ~NVFX_VP_MASK_W
), swz(src
[0], Y
, Z
, X
, X
), swz(src
[1], Z
, X
, Y
, Y
), neg(tmp
)));
637 insn
= arith(VEC
, MOV
, none
.reg
, NVFX_VP_MASK_X
, src
[0], none
, none
);
639 nvfx_vp_emit(vpc
, insn
);
641 reloc
.location
= vpc
->vp
->nr_insns
;
642 reloc
.target
= finst
->Label
.Label
+ 1;
643 util_dynarray_append(&vpc
->label_relocs
, struct nvfx_relocation
, reloc
);
645 insn
= arith(SCA
, BRA
, none
.reg
, 0, none
, none
, none
);
646 insn
.cc_test
= NVFX_COND_EQ
;
647 insn
.cc_swz
[0] = insn
.cc_swz
[1] = insn
.cc_swz
[2] = insn
.cc_swz
[3] = 0;
648 nvfx_vp_emit(vpc
, insn
);
651 case TGSI_OPCODE_ELSE
:
652 case TGSI_OPCODE_BRA
:
653 case TGSI_OPCODE_CAL
:
654 reloc
.location
= vpc
->vp
->nr_insns
;
655 reloc
.target
= finst
->Label
.Label
;
656 util_dynarray_append(&vpc
->label_relocs
, struct nvfx_relocation
, reloc
);
658 if(finst
->Instruction
.Opcode
== TGSI_OPCODE_CAL
)
659 insn
= arith(SCA
, CAL
, none
.reg
, 0, none
, none
, none
);
661 insn
= arith(SCA
, BRA
, none
.reg
, 0, none
, none
, none
);
662 nvfx_vp_emit(vpc
, insn
);
665 case TGSI_OPCODE_RET
:
667 tmp
.swz
[0] = tmp
.swz
[1] = tmp
.swz
[2] = tmp
.swz
[3] = 0;
668 nvfx_vp_emit(vpc
, arith(SCA
, RET
, none
.reg
, 0, none
, none
, tmp
));
671 case TGSI_OPCODE_BGNSUB
:
672 case TGSI_OPCODE_ENDSUB
:
673 case TGSI_OPCODE_ENDIF
:
674 /* nothing to do here */
677 case TGSI_OPCODE_BGNLOOP
:
678 loop
.cont_target
= idx
;
679 loop
.brk_target
= finst
->Label
.Label
+ 1;
680 util_dynarray_append(&vpc
->loop_stack
, struct nvfx_loop_entry
, loop
);
683 case TGSI_OPCODE_ENDLOOP
:
684 loop
= util_dynarray_pop(&vpc
->loop_stack
, struct nvfx_loop_entry
);
686 reloc
.location
= vpc
->vp
->nr_insns
;
687 reloc
.target
= loop
.cont_target
;
688 util_dynarray_append(&vpc
->label_relocs
, struct nvfx_relocation
, reloc
);
690 nvfx_vp_emit(vpc
, arith(SCA
, BRA
, none
.reg
, 0, none
, none
, none
));
693 case TGSI_OPCODE_CONT
:
694 loop
= util_dynarray_top(&vpc
->loop_stack
, struct nvfx_loop_entry
);
696 reloc
.location
= vpc
->vp
->nr_insns
;
697 reloc
.target
= loop
.cont_target
;
698 util_dynarray_append(&vpc
->label_relocs
, struct nvfx_relocation
, reloc
);
700 nvfx_vp_emit(vpc
, arith(SCA
, BRA
, none
.reg
, 0, none
, none
, none
));
703 case TGSI_OPCODE_BRK
:
704 loop
= util_dynarray_top(&vpc
->loop_stack
, struct nvfx_loop_entry
);
706 reloc
.location
= vpc
->vp
->nr_insns
;
707 reloc
.target
= loop
.brk_target
;
708 util_dynarray_append(&vpc
->label_relocs
, struct nvfx_relocation
, reloc
);
710 nvfx_vp_emit(vpc
, arith(SCA
, BRA
, none
.reg
, 0, none
, none
, none
));
714 NOUVEAU_ERR("invalid opcode %d\n", finst
->Instruction
.Opcode
);
723 nvfx_vertprog_parse_decl_output(struct nvfx_context
* nvfx
, struct nvfx_vpc
*vpc
,
724 const struct tgsi_full_declaration
*fdec
)
726 unsigned idx
= fdec
->Range
.First
;
729 switch (fdec
->Semantic
.Name
) {
730 case TGSI_SEMANTIC_POSITION
:
731 hw
= NVFX_VP(INST_DEST_POS
);
734 case TGSI_SEMANTIC_COLOR
:
735 if (fdec
->Semantic
.Index
== 0) {
736 hw
= NVFX_VP(INST_DEST_COL0
);
738 if (fdec
->Semantic
.Index
== 1) {
739 hw
= NVFX_VP(INST_DEST_COL1
);
741 NOUVEAU_ERR("bad colour semantic index\n");
745 case TGSI_SEMANTIC_BCOLOR
:
746 if (fdec
->Semantic
.Index
== 0) {
747 hw
= NVFX_VP(INST_DEST_BFC0
);
749 if (fdec
->Semantic
.Index
== 1) {
750 hw
= NVFX_VP(INST_DEST_BFC1
);
752 NOUVEAU_ERR("bad bcolour semantic index\n");
756 case TGSI_SEMANTIC_FOG
:
757 hw
= NVFX_VP(INST_DEST_FOGC
);
759 case TGSI_SEMANTIC_PSIZE
:
760 hw
= NVFX_VP(INST_DEST_PSZ
);
762 case TGSI_SEMANTIC_GENERIC
:
763 hw
= (vpc
->vp
->generic_to_fp_input
[fdec
->Semantic
.Index
] & 0xf)
764 + NVFX_VP(INST_DEST_TC(0)) - NVFX_FP_OP_INPUT_SRC_TC(0);
766 case TGSI_SEMANTIC_EDGEFLAG
:
767 /* not really an error just a fallback */
768 NOUVEAU_ERR("cannot handle edgeflag output\n");
771 NOUVEAU_ERR("bad output semantic\n");
775 vpc
->r_result
[idx
] = nvfx_reg(NVFXSR_OUTPUT
, hw
);
780 nvfx_vertprog_prepare(struct nvfx_context
* nvfx
, struct nvfx_vpc
*vpc
)
782 struct tgsi_parse_context p
;
783 int high_temp
= -1, high_addr
= -1, nr_imm
= 0, i
;
784 struct util_semantic_set set
;
785 unsigned char sem_layout
[8];
786 unsigned num_outputs
;
788 num_outputs
= util_semantic_set_from_program_file(&set
, vpc
->vp
->pipe
.tokens
, TGSI_FILE_OUTPUT
);
790 if(num_outputs
> 8) {
791 NOUVEAU_ERR("too many vertex program outputs: %i\n", num_outputs
);
794 util_semantic_layout_from_set(sem_layout
, &set
, 8, 8);
796 /* hope 0xf is (0, 0, 0, 1) initialized; otherwise, we are _probably_ not required to do this */
797 memset(vpc
->vp
->generic_to_fp_input
, 0x0f, sizeof(vpc
->vp
->generic_to_fp_input
));
798 for(int i
= 0; i
< 8; ++i
) {
799 if(sem_layout
[i
] == 0xff)
801 //printf("vp: GENERIC[%i] to fpreg %i\n", sem_layout[i], NVFX_FP_OP_INPUT_SRC_TC(0) + i);
802 vpc
->vp
->generic_to_fp_input
[sem_layout
[i
]] = 0xf0 | NVFX_FP_OP_INPUT_SRC_TC(i
);
805 vpc
->vp
->sprite_fp_input
= -1;
806 for(int i
= 0; i
< 8; ++i
)
808 if(sem_layout
[i
] == 0xff)
810 vpc
->vp
->sprite_fp_input
= NVFX_FP_OP_INPUT_SRC_TC(i
);
815 tgsi_parse_init(&p
, vpc
->vp
->pipe
.tokens
);
816 while (!tgsi_parse_end_of_tokens(&p
)) {
817 const union tgsi_full_token
*tok
= &p
.FullToken
;
819 tgsi_parse_token(&p
);
820 switch(tok
->Token
.Type
) {
821 case TGSI_TOKEN_TYPE_IMMEDIATE
:
824 case TGSI_TOKEN_TYPE_DECLARATION
:
826 const struct tgsi_full_declaration
*fdec
;
828 fdec
= &p
.FullToken
.FullDeclaration
;
829 switch (fdec
->Declaration
.File
) {
830 case TGSI_FILE_TEMPORARY
:
831 if (fdec
->Range
.Last
> high_temp
) {
836 #if 0 /* this would be nice.. except gallium doesn't track it */
837 case TGSI_FILE_ADDRESS
:
838 if (fdec
->Range
.Last
> high_addr
) {
844 case TGSI_FILE_OUTPUT
:
845 if (!nvfx_vertprog_parse_decl_output(nvfx
, vpc
, fdec
))
853 #if 1 /* yay, parse instructions looking for address regs instead */
854 case TGSI_TOKEN_TYPE_INSTRUCTION
:
856 const struct tgsi_full_instruction
*finst
;
857 const struct tgsi_full_dst_register
*fdst
;
859 finst
= &p
.FullToken
.FullInstruction
;
860 fdst
= &finst
->Dst
[0];
862 if (fdst
->Register
.File
== TGSI_FILE_ADDRESS
) {
863 if (fdst
->Register
.Index
> high_addr
)
864 high_addr
= fdst
->Register
.Index
;
877 vpc
->imm
= CALLOC(nr_imm
, sizeof(struct nvfx_reg
));
882 vpc
->r_temp
= CALLOC(high_temp
, sizeof(struct nvfx_reg
));
883 for (i
= 0; i
< high_temp
; i
++)
884 vpc
->r_temp
[i
] = temp(vpc
);
888 vpc
->r_address
= CALLOC(high_addr
, sizeof(struct nvfx_reg
));
889 for (i
= 0; i
< high_addr
; i
++)
890 vpc
->r_address
[i
] = temp(vpc
);
893 vpc
->r_temps_discard
= 0;
897 DEBUG_GET_ONCE_BOOL_OPTION(nvfx_dump_vp
, "NVFX_DUMP_VP", FALSE
)
900 nvfx_vertprog_translate(struct nvfx_context
*nvfx
,
901 struct nvfx_vertex_program
*vp
)
903 struct tgsi_parse_context parse
;
904 struct nvfx_vpc
*vpc
= NULL
;
905 struct nvfx_src none
= nvfx_src(nvfx_reg(NVFXSR_NONE
, 0));
906 struct util_dynarray insns
;
909 vpc
= CALLOC(1, sizeof(struct nvfx_vpc
));
915 if (!nvfx_vertprog_prepare(nvfx
, vpc
)) {
920 /* Redirect post-transform vertex position to a temp if user clip
921 * planes are enabled. We need to append code to the vtxprog
922 * to handle clip planes later.
925 vpc
->r_result
[vpc
->hpos_idx
] = temp(vpc
);
926 vpc
->r_temps_discard
= 0;
929 tgsi_parse_init(&parse
, vp
->pipe
.tokens
);
931 util_dynarray_init(&insns
);
932 while (!tgsi_parse_end_of_tokens(&parse
)) {
933 tgsi_parse_token(&parse
);
935 switch (parse
.FullToken
.Token
.Type
) {
936 case TGSI_TOKEN_TYPE_IMMEDIATE
:
938 const struct tgsi_full_immediate
*imm
;
940 imm
= &parse
.FullToken
.FullImmediate
;
941 assert(imm
->Immediate
.DataType
== TGSI_IMM_FLOAT32
);
942 assert(imm
->Immediate
.NrTokens
== 4 + 1);
943 vpc
->imm
[vpc
->nr_imm
++] =
951 case TGSI_TOKEN_TYPE_INSTRUCTION
:
953 const struct tgsi_full_instruction
*finst
;
954 unsigned idx
= insns
.size
>> 2;
955 util_dynarray_append(&insns
, unsigned, vp
->nr_insns
);
956 finst
= &parse
.FullToken
.FullInstruction
;
957 if (!nvfx_vertprog_parse_instruction(nvfx
, vpc
, idx
, finst
))
966 util_dynarray_append(&insns
, unsigned, vp
->nr_insns
);
968 for(unsigned i
= 0; i
< vpc
->label_relocs
.size
; i
+= sizeof(struct nvfx_relocation
))
970 struct nvfx_relocation
* label_reloc
= (struct nvfx_relocation
*)((char*)vpc
->label_relocs
.data
+ i
);
971 struct nvfx_relocation hw_reloc
;
973 hw_reloc
.location
= label_reloc
->location
;
974 hw_reloc
.target
= ((unsigned*)insns
.data
)[label_reloc
->target
];
976 //debug_printf("hw %u -> tgsi %u = hw %u\n", hw_reloc.location, label_reloc->target, hw_reloc.target);
978 util_dynarray_append(&vp
->branch_relocs
, struct nvfx_relocation
, hw_reloc
);
980 util_dynarray_fini(&insns
);
981 util_dynarray_trim(&vp
->branch_relocs
);
983 /* XXX: what if we add a RET before?! make sure we jump here...*/
985 /* Write out HPOS if it was redirected to a temp earlier */
986 if (vpc
->r_result
[vpc
->hpos_idx
].type
!= NVFXSR_OUTPUT
) {
987 struct nvfx_reg hpos
= nvfx_reg(NVFXSR_OUTPUT
,
988 NVFX_VP(INST_DEST_POS
));
989 struct nvfx_src htmp
= nvfx_src(vpc
->r_result
[vpc
->hpos_idx
]);
991 nvfx_vp_emit(vpc
, arith(VEC
, MOV
, hpos
, NVFX_VP_MASK_ALL
, htmp
, none
, none
));
994 /* Insert code to handle user clip planes */
995 for (i
= 0; i
< vp
->ucp
.nr
; i
++) {
996 struct nvfx_reg cdst
= nvfx_reg(NVFXSR_OUTPUT
,
997 NVFX_VP_INST_DEST_CLIP(i
));
998 struct nvfx_src ceqn
= nvfx_src(constant(vpc
, -1,
999 nvfx
->clip
.ucp
[i
][0],
1000 nvfx
->clip
.ucp
[i
][1],
1001 nvfx
->clip
.ucp
[i
][2],
1002 nvfx
->clip
.ucp
[i
][3]));
1003 struct nvfx_src htmp
= nvfx_src(vpc
->r_result
[vpc
->hpos_idx
]);
1007 case 0: case 3: mask
= NVFX_VP_MASK_Y
; break;
1008 case 1: case 4: mask
= NVFX_VP_MASK_Z
; break;
1009 case 2: case 5: mask
= NVFX_VP_MASK_W
; break;
1011 NOUVEAU_ERR("invalid clip dist #%d\n", i
);
1015 nvfx_vp_emit(vpc
, arith(VEC
, DP4
, cdst
, mask
, htmp
, ceqn
, none
));
1018 //vp->insns[vp->nr_insns - 1].data[3] |= NVFX_VP_INST_LAST;
1020 /* Append NOP + END instruction for branches to the end of the program */
1021 nvfx_vp_emit(vpc
, arith(VEC
, NOP
, none
.reg
, 0, none
, none
, none
));
1022 vp
->insns
[vp
->nr_insns
- 1].data
[3] |= NVFX_VP_INST_LAST
| 0x1000;
1024 if(debug_get_option_nvfx_dump_vp())
1027 tgsi_dump(vp
->pipe
.tokens
, 0);
1029 debug_printf("\n%s vertex program:\n", nvfx
->is_nv4x
? "nv4x" : "nv3x");
1030 for (i
= 0; i
< vp
->nr_insns
; i
++)
1031 debug_printf("%3u: %08x %08x %08x %08x\n", i
, vp
->insns
[i
].data
[0], vp
->insns
[i
].data
[1], vp
->insns
[i
].data
[2], vp
->insns
[i
].data
[3]);
1035 vp
->exec_start
= -1;
1036 vp
->translated
= TRUE
;
1038 tgsi_parse_free(&parse
);
1039 util_dynarray_fini(&vpc
->label_relocs
);
1040 util_dynarray_fini(&vpc
->loop_stack
);
1044 FREE(vpc
->r_address
);
1051 nvfx_vertprog_validate(struct nvfx_context
*nvfx
)
1053 struct nvfx_screen
*screen
= nvfx
->screen
;
1054 struct nouveau_channel
*chan
= screen
->base
.channel
;
1055 struct nouveau_grobj
*eng3d
= screen
->eng3d
;
1056 struct nvfx_vertex_program
*vp
;
1057 struct pipe_resource
*constbuf
;
1058 boolean upload_code
= FALSE
, upload_data
= FALSE
;
1061 if (nvfx
->render_mode
== HW
) {
1062 vp
= nvfx
->vertprog
;
1063 constbuf
= nvfx
->constbuf
[PIPE_SHADER_VERTEX
];
1065 // TODO: ouch! can't we just use constant slots for these?!
1066 if ((nvfx
->dirty
& NVFX_NEW_UCP
) ||
1067 memcmp(&nvfx
->clip
, &vp
->ucp
, sizeof(vp
->ucp
))) {
1068 nvfx_vertprog_destroy(nvfx
, vp
);
1069 memcpy(&vp
->ucp
, &nvfx
->clip
, sizeof(vp
->ucp
));
1072 vp
= nvfx
->swtnl
.vertprog
;
1076 /* Translate TGSI shader into hw bytecode */
1077 if (!vp
->translated
)
1079 nvfx
->fallback_swtnl
&= ~NVFX_NEW_VERTPROG
;
1080 nvfx_vertprog_translate(nvfx
, vp
);
1081 if (!vp
->translated
) {
1082 nvfx
->fallback_swtnl
|= NVFX_NEW_VERTPROG
;
1087 /* Allocate hw vtxprog exec slots */
1089 struct nouveau_resource
*heap
= nvfx
->screen
->vp_exec_heap
;
1090 uint vplen
= vp
->nr_insns
;
1092 if (nouveau_resource_alloc(heap
, vplen
, vp
, &vp
->exec
)) {
1093 while (heap
->next
&& heap
->size
< vplen
) {
1094 struct nvfx_vertex_program
*evict
;
1096 evict
= heap
->next
->priv
;
1097 nouveau_resource_free(&evict
->exec
);
1100 if (nouveau_resource_alloc(heap
, vplen
, vp
, &vp
->exec
))
1102 debug_printf("Vertex shader too long: %u instructions\n", vplen
);
1103 nvfx
->fallback_swtnl
|= NVFX_NEW_VERTPROG
;
1111 /* Allocate hw vtxprog const slots */
1112 if (vp
->nr_consts
&& !vp
->data
) {
1113 struct nouveau_resource
*heap
= nvfx
->screen
->vp_data_heap
;
1115 if (nouveau_resource_alloc(heap
, vp
->nr_consts
, vp
, &vp
->data
)) {
1116 while (heap
->next
&& heap
->size
< vp
->nr_consts
) {
1117 struct nvfx_vertex_program
*evict
;
1119 evict
= heap
->next
->priv
;
1120 nouveau_resource_free(&evict
->data
);
1123 if (nouveau_resource_alloc(heap
, vp
->nr_consts
, vp
, &vp
->data
))
1125 debug_printf("Vertex shader uses too many constants: %u constants\n", vp
->nr_consts
);
1126 nvfx
->fallback_swtnl
|= NVFX_NEW_VERTPROG
;
1131 /*XXX: handle this some day */
1132 assert(vp
->data
->start
>= vp
->data_start_min
);
1135 if (vp
->data_start
!= vp
->data
->start
)
1139 /* If exec or data segments moved we need to patch the program to
1140 * fixup offsets and register IDs.
1142 if (vp
->exec_start
!= vp
->exec
->start
) {
1143 //printf("vp_relocs %u -> %u\n", vp->exec_start, vp->exec->start);
1144 for(unsigned i
= 0; i
< vp
->branch_relocs
.size
; i
+= sizeof(struct nvfx_relocation
))
1146 struct nvfx_relocation
* reloc
= (struct nvfx_relocation
*)((char*)vp
->branch_relocs
.data
+ i
);
1147 uint32_t* hw
= vp
->insns
[reloc
->location
].data
;
1148 unsigned target
= vp
->exec
->start
+ reloc
->target
;
1150 //debug_printf("vp_reloc hw %u -> hw %u\n", reloc->location, target);
1154 hw
[2] &=~ NV30_VP_INST_IADDR_MASK
;
1155 hw
[2] |= (target
& 0x1ff) << NV30_VP_INST_IADDR_SHIFT
;
1159 hw
[3] &=~ NV40_VP_INST_IADDRL_MASK
;
1160 hw
[3] |= (target
& 7) << NV40_VP_INST_IADDRL_SHIFT
;
1162 hw
[2] &=~ NV40_VP_INST_IADDRH_MASK
;
1163 hw
[2] |= ((target
>> 3) & 0x3f) << NV40_VP_INST_IADDRH_SHIFT
;
1167 vp
->exec_start
= vp
->exec
->start
;
1170 if (vp
->nr_consts
&& vp
->data_start
!= vp
->data
->start
) {
1171 for(unsigned i
= 0; i
< vp
->const_relocs
.size
; i
+= sizeof(struct nvfx_relocation
))
1173 struct nvfx_relocation
* reloc
= (struct nvfx_relocation
*)((char*)vp
->const_relocs
.data
+ i
);
1174 struct nvfx_vertex_program_exec
*vpi
= &vp
->insns
[reloc
->location
];
1176 vpi
->data
[1] &= ~NVFX_VP(INST_CONST_SRC_MASK
);
1178 (reloc
->target
+ vp
->data
->start
) <<
1179 NVFX_VP(INST_CONST_SRC_SHIFT
);
1182 vp
->data_start
= vp
->data
->start
;
1185 /* Update + Upload constant values */
1186 if (vp
->nr_consts
) {
1190 map
= (float*)nvfx_buffer(constbuf
)->data
;
1192 for (i
= 0; i
< vp
->nr_consts
; i
++) {
1193 struct nvfx_vertex_program_data
*vpd
= &vp
->consts
[i
];
1195 if (vpd
->index
>= 0) {
1197 !memcmp(vpd
->value
, &map
[vpd
->index
* 4],
1200 memcpy(vpd
->value
, &map
[vpd
->index
* 4],
1204 BEGIN_RING(chan
, eng3d
, NV34TCL_VP_UPLOAD_CONST_ID
, 5);
1205 OUT_RING (chan
, i
+ vp
->data
->start
);
1206 OUT_RINGp (chan
, (uint32_t *)vpd
->value
, 4);
1210 /* Upload vtxprog */
1212 BEGIN_RING(chan
, eng3d
, NV34TCL_VP_UPLOAD_FROM_ID
, 1);
1213 OUT_RING (chan
, vp
->exec
->start
);
1214 for (i
= 0; i
< vp
->nr_insns
; i
++) {
1215 BEGIN_RING(chan
, eng3d
, NV34TCL_VP_UPLOAD_INST(0), 4);
1216 OUT_RINGp (chan
, vp
->insns
[i
].data
, 4);
1220 if(nvfx
->dirty
& (NVFX_NEW_VERTPROG
| NVFX_NEW_UCP
))
1223 OUT_RING(chan
, RING_3D(NV34TCL_VP_START_FROM_ID
, 1));
1224 OUT_RING(chan
, vp
->exec
->start
);
1226 OUT_RING(chan
, RING_3D(NV40TCL_VP_ATTRIB_EN
, 1));
1227 OUT_RING(chan
, vp
->ir
);
1229 OUT_RING(chan
, RING_3D(NV34TCL_VP_CLIP_PLANES_ENABLE
, 1));
1230 OUT_RING(chan
, vp
->clip_ctrl
);
1237 nvfx_vertprog_destroy(struct nvfx_context
*nvfx
, struct nvfx_vertex_program
*vp
)
1239 vp
->translated
= FALSE
;
1247 if (vp
->nr_consts
) {
1253 nouveau_resource_free(&vp
->exec
);
1255 nouveau_resource_free(&vp
->data
);
1257 vp
->data_start_min
= 0;
1259 vp
->ir
= vp
->or = vp
->clip_ctrl
= 0;
1260 util_dynarray_fini(&vp
->branch_relocs
);
1261 util_dynarray_fini(&vp
->const_relocs
);