2 #include "pipe/p_context.h"
3 #include "pipe/p_defines.h"
4 #include "pipe/p_state.h"
5 #include "util/u_dynarray.h"
6 #include "util/u_inlines.h"
7 #include "util/u_debug.h"
8 #include "util/u_memory.h"
10 #include "pipe/p_shader_tokens.h"
11 #include "tgsi/tgsi_parse.h"
12 #include "tgsi/tgsi_util.h"
13 #include "tgsi/tgsi_dump.h"
14 #include "tgsi/tgsi_ureg.h"
16 #include "nouveau_debug.h"
17 #include "nv_object.xml.h"
18 #include "nv30/nv30-40_3d.xml.h"
19 #include "nv30/nvfx_shader.h"
20 #include "nv30/nv30_state.h"
23 struct nv30_fragprog
*fp
;
26 unsigned long long r_temps
;
27 unsigned long long r_temps_discard
;
28 struct nvfx_reg r_result
[PIPE_MAX_SHADER_OUTPUTS
];
29 struct nvfx_reg r_input
[PIPE_MAX_SHADER_INPUTS
];
30 struct nvfx_reg
*r_temp
;
38 struct util_dynarray imm_data
;
40 struct nvfx_reg
* r_imm
;
43 struct util_dynarray if_stack
;
44 //struct util_dynarray loop_stack;
45 struct util_dynarray label_relocs
;
48 static inline struct nvfx_reg
49 temp(struct nvfx_fpc
*fpc
)
51 int idx
= __builtin_ctzll(~fpc
->r_temps
);
53 if (idx
>= fpc
->max_temps
) {
54 NOUVEAU_ERR("out of temps!!\n");
55 return nvfx_reg(NVFXSR_TEMP
, 0);
58 fpc
->r_temps
|= (1ULL << idx
);
59 fpc
->r_temps_discard
|= (1ULL << idx
);
60 return nvfx_reg(NVFXSR_TEMP
, idx
);
64 release_temps(struct nvfx_fpc
*fpc
)
66 fpc
->r_temps
&= ~fpc
->r_temps_discard
;
67 fpc
->r_temps_discard
= 0ULL;
70 static inline struct nvfx_reg
71 nvfx_fp_imm(struct nvfx_fpc
*fpc
, float a
, float b
, float c
, float d
)
73 float v
[4] = {a
, b
, c
, d
};
74 int idx
= fpc
->imm_data
.size
>> 4;
76 memcpy(util_dynarray_grow(&fpc
->imm_data
, sizeof(float) * 4), v
, 4 * sizeof(float));
77 return nvfx_reg(NVFXSR_IMM
, idx
);
81 grow_insns(struct nvfx_fpc
*fpc
, int size
)
83 struct nv30_fragprog
*fp
= fpc
->fp
;
86 fp
->insn
= realloc(fp
->insn
, sizeof(uint32_t) * fp
->insn_len
);
90 emit_src(struct nvfx_fpc
*fpc
, int pos
, struct nvfx_src src
)
92 struct nv30_fragprog
*fp
= fpc
->fp
;
93 uint32_t *hw
= &fp
->insn
[fpc
->inst_offset
];
96 switch (src
.reg
.type
) {
98 sr
|= (NVFX_FP_REG_TYPE_INPUT
<< NVFX_FP_REG_TYPE_SHIFT
);
99 hw
[0] |= (src
.reg
.index
<< NVFX_FP_OP_INPUT_SRC_SHIFT
);
102 sr
|= NVFX_FP_REG_SRC_HALF
;
105 sr
|= (NVFX_FP_REG_TYPE_TEMP
<< NVFX_FP_REG_TYPE_SHIFT
);
106 sr
|= (src
.reg
.index
<< NVFX_FP_REG_SRC_SHIFT
);
109 if (!fpc
->have_const
) {
111 hw
= &fp
->insn
[fpc
->inst_offset
];
115 memcpy(&fp
->insn
[fpc
->inst_offset
+ 4],
116 (float*)fpc
->imm_data
.data
+ src
.reg
.index
* 4,
117 sizeof(uint32_t) * 4);
119 sr
|= (NVFX_FP_REG_TYPE_CONST
<< NVFX_FP_REG_TYPE_SHIFT
);
122 if (!fpc
->have_const
) {
124 hw
= &fp
->insn
[fpc
->inst_offset
];
129 struct nv30_fragprog_data
*fpd
;
131 fp
->consts
= realloc(fp
->consts
, ++fp
->nr_consts
*
133 fpd
= &fp
->consts
[fp
->nr_consts
- 1];
134 fpd
->offset
= fpc
->inst_offset
+ 4;
135 fpd
->index
= src
.reg
.index
;
136 memset(&fp
->insn
[fpd
->offset
], 0, sizeof(uint32_t) * 4);
139 sr
|= (NVFX_FP_REG_TYPE_CONST
<< NVFX_FP_REG_TYPE_SHIFT
);
142 sr
|= (NVFX_FP_REG_TYPE_INPUT
<< NVFX_FP_REG_TYPE_SHIFT
);
149 sr
|= NVFX_FP_REG_NEGATE
;
152 hw
[1] |= (1 << (29 + pos
));
154 sr
|= ((src
.swz
[0] << NVFX_FP_REG_SWZ_X_SHIFT
) |
155 (src
.swz
[1] << NVFX_FP_REG_SWZ_Y_SHIFT
) |
156 (src
.swz
[2] << NVFX_FP_REG_SWZ_Z_SHIFT
) |
157 (src
.swz
[3] << NVFX_FP_REG_SWZ_W_SHIFT
));
163 emit_dst(struct nvfx_fpc
*fpc
, struct nvfx_reg dst
)
165 struct nv30_fragprog
*fp
= fpc
->fp
;
166 uint32_t *hw
= &fp
->insn
[fpc
->inst_offset
];
171 fp
->fp_control
|= 0x0000000e;
173 hw
[0] |= NVFX_FP_OP_OUT_REG_HALF
;
178 if (fpc
->num_regs
< (dst
.index
+ 1))
179 fpc
->num_regs
= dst
.index
+ 1;
188 hw
[0] |= (dst
.index
<< NVFX_FP_OP_OUT_REG_SHIFT
);
192 nvfx_fp_emit(struct nvfx_fpc
*fpc
, struct nvfx_insn insn
)
194 struct nv30_fragprog
*fp
= fpc
->fp
;
197 fpc
->inst_offset
= fp
->insn_len
;
200 hw
= &fp
->insn
[fpc
->inst_offset
];
201 memset(hw
, 0, sizeof(uint32_t) * 4);
203 if (insn
.op
== NVFX_FP_OP_OPCODE_KIL
)
204 fp
->fp_control
|= NV30_3D_FP_CONTROL_USES_KIL
;
205 hw
[0] |= (insn
.op
<< NVFX_FP_OP_OPCODE_SHIFT
);
206 hw
[0] |= (insn
.mask
<< NVFX_FP_OP_OUTMASK_SHIFT
);
207 hw
[2] |= (insn
.scale
<< NVFX_FP_OP_DST_SCALE_SHIFT
);
210 hw
[0] |= NVFX_FP_OP_OUT_SAT
;
213 hw
[0] |= NVFX_FP_OP_COND_WRITE_ENABLE
;
214 hw
[1] |= (insn
.cc_test
<< NVFX_FP_OP_COND_SHIFT
);
215 hw
[1] |= ((insn
.cc_swz
[0] << NVFX_FP_OP_COND_SWZ_X_SHIFT
) |
216 (insn
.cc_swz
[1] << NVFX_FP_OP_COND_SWZ_Y_SHIFT
) |
217 (insn
.cc_swz
[2] << NVFX_FP_OP_COND_SWZ_Z_SHIFT
) |
218 (insn
.cc_swz
[3] << NVFX_FP_OP_COND_SWZ_W_SHIFT
));
222 hw
[0] |= (insn
.unit
<< NVFX_FP_OP_TEX_UNIT_SHIFT
);
225 emit_dst(fpc
, insn
.dst
);
226 emit_src(fpc
, 0, insn
.src
[0]);
227 emit_src(fpc
, 1, insn
.src
[1]);
228 emit_src(fpc
, 2, insn
.src
[2]);
231 #define arith(s,o,d,m,s0,s1,s2) \
232 nvfx_insn((s), NVFX_FP_OP_OPCODE_##o, -1, \
233 (d), (m), (s0), (s1), (s2))
235 #define tex(s,o,u,d,m,s0,s1,s2) \
236 nvfx_insn((s), NVFX_FP_OP_OPCODE_##o, (u), \
237 (d), (m), (s0), none, none)
239 /* IF src.x != 0, as TGSI specifies */
241 nv40_fp_if(struct nvfx_fpc
*fpc
, struct nvfx_src src
)
243 const struct nvfx_src none
= nvfx_src(nvfx_reg(NVFXSR_NONE
, 0));
244 struct nvfx_insn insn
= arith(0, MOV
, none
.reg
, NVFX_FP_MASK_X
, src
, none
, none
);
247 nvfx_fp_emit(fpc
, insn
);
249 fpc
->inst_offset
= fpc
->fp
->insn_len
;
251 hw
= &fpc
->fp
->insn
[fpc
->inst_offset
];
252 /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */
253 hw
[0] = (NV40_FP_OP_BRA_OPCODE_IF
<< NVFX_FP_OP_OPCODE_SHIFT
) |
254 NV40_FP_OP_OUT_NONE
|
255 (NVFX_FP_PRECISION_FP16
<< NVFX_FP_OP_PRECISION_SHIFT
);
256 /* Use .xxxx swizzle so that we check only src[0].x*/
257 hw
[1] = (0 << NVFX_FP_OP_COND_SWZ_X_SHIFT
) |
258 (0 << NVFX_FP_OP_COND_SWZ_Y_SHIFT
) |
259 (0 << NVFX_FP_OP_COND_SWZ_Z_SHIFT
) |
260 (0 << NVFX_FP_OP_COND_SWZ_W_SHIFT
) |
261 (NVFX_FP_OP_COND_NE
<< NVFX_FP_OP_COND_SHIFT
);
262 hw
[2] = 0; /* | NV40_FP_OP_OPCODE_IS_BRANCH | else_offset */
263 hw
[3] = 0; /* | endif_offset */
264 util_dynarray_append(&fpc
->if_stack
, unsigned, fpc
->inst_offset
);
267 /* IF src.x != 0, as TGSI specifies */
269 nv40_fp_cal(struct nvfx_fpc
*fpc
, unsigned target
)
271 struct nvfx_relocation reloc
;
273 fpc
->inst_offset
= fpc
->fp
->insn_len
;
275 hw
= &fpc
->fp
->insn
[fpc
->inst_offset
];
276 /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */
277 hw
[0] = (NV40_FP_OP_BRA_OPCODE_CAL
<< NVFX_FP_OP_OPCODE_SHIFT
);
278 /* Use .xxxx swizzle so that we check only src[0].x*/
279 hw
[1] = (NVFX_SWZ_IDENTITY
<< NVFX_FP_OP_COND_SWZ_ALL_SHIFT
) |
280 (NVFX_FP_OP_COND_TR
<< NVFX_FP_OP_COND_SHIFT
);
281 hw
[2] = NV40_FP_OP_OPCODE_IS_BRANCH
; /* | call_offset */
283 reloc
.target
= target
;
284 reloc
.location
= fpc
->inst_offset
+ 2;
285 util_dynarray_append(&fpc
->label_relocs
, struct nvfx_relocation
, reloc
);
289 nv40_fp_ret(struct nvfx_fpc
*fpc
)
292 fpc
->inst_offset
= fpc
->fp
->insn_len
;
294 hw
= &fpc
->fp
->insn
[fpc
->inst_offset
];
295 /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */
296 hw
[0] = (NV40_FP_OP_BRA_OPCODE_RET
<< NVFX_FP_OP_OPCODE_SHIFT
);
297 /* Use .xxxx swizzle so that we check only src[0].x*/
298 hw
[1] = (NVFX_SWZ_IDENTITY
<< NVFX_FP_OP_COND_SWZ_ALL_SHIFT
) |
299 (NVFX_FP_OP_COND_TR
<< NVFX_FP_OP_COND_SHIFT
);
300 hw
[2] = NV40_FP_OP_OPCODE_IS_BRANCH
; /* | call_offset */
305 nv40_fp_rep(struct nvfx_fpc
*fpc
, unsigned count
, unsigned target
)
307 struct nvfx_relocation reloc
;
309 fpc
->inst_offset
= fpc
->fp
->insn_len
;
311 hw
= &fpc
->fp
->insn
[fpc
->inst_offset
];
312 /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */
313 hw
[0] = (NV40_FP_OP_BRA_OPCODE_REP
<< NVFX_FP_OP_OPCODE_SHIFT
) |
314 NV40_FP_OP_OUT_NONE
|
315 (NVFX_FP_PRECISION_FP16
<< NVFX_FP_OP_PRECISION_SHIFT
);
316 /* Use .xxxx swizzle so that we check only src[0].x*/
317 hw
[1] = (NVFX_SWZ_IDENTITY
<< NVFX_FP_OP_COND_SWZ_ALL_SHIFT
) |
318 (NVFX_FP_OP_COND_TR
<< NVFX_FP_OP_COND_SHIFT
);
319 hw
[2] = NV40_FP_OP_OPCODE_IS_BRANCH
|
320 (count
<< NV40_FP_OP_REP_COUNT1_SHIFT
) |
321 (count
<< NV40_FP_OP_REP_COUNT2_SHIFT
) |
322 (count
<< NV40_FP_OP_REP_COUNT3_SHIFT
);
323 hw
[3] = 0; /* | end_offset */
324 reloc
.target
= target
;
325 reloc
.location
= fpc
->inst_offset
+ 3;
326 util_dynarray_append(&fpc
->label_relocs
, struct nvfx_relocation
, reloc
);
327 //util_dynarray_append(&fpc->loop_stack, unsigned, target);
331 /* documentation only */
332 /* warning: this only works forward, and probably only if not inside any IF */
334 nv40_fp_bra(struct nvfx_fpc
*fpc
, unsigned target
)
336 struct nvfx_relocation reloc
;
338 fpc
->inst_offset
= fpc
->fp
->insn_len
;
340 hw
= &fpc
->fp
->insn
[fpc
->inst_offset
];
341 /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */
342 hw
[0] = (NV40_FP_OP_BRA_OPCODE_IF
<< NVFX_FP_OP_OPCODE_SHIFT
) |
343 NV40_FP_OP_OUT_NONE
|
344 (NVFX_FP_PRECISION_FP16
<< NVFX_FP_OP_PRECISION_SHIFT
);
345 /* Use .xxxx swizzle so that we check only src[0].x*/
346 hw
[1] = (NVFX_SWZ_IDENTITY
<< NVFX_FP_OP_COND_SWZ_X_SHIFT
) |
347 (NVFX_FP_OP_COND_FL
<< NVFX_FP_OP_COND_SHIFT
);
348 hw
[2] = NV40_FP_OP_OPCODE_IS_BRANCH
; /* | else_offset */
349 hw
[3] = 0; /* | endif_offset */
350 reloc
.target
= target
;
351 reloc
.location
= fpc
->inst_offset
+ 2;
352 util_dynarray_append(&fpc
->label_relocs
, struct nvfx_relocation
, reloc
);
353 reloc
.target
= target
;
354 reloc
.location
= fpc
->inst_offset
+ 3;
355 util_dynarray_append(&fpc
->label_relocs
, struct nvfx_relocation
, reloc
);
360 nv40_fp_brk(struct nvfx_fpc
*fpc
)
363 fpc
->inst_offset
= fpc
->fp
->insn_len
;
365 hw
= &fpc
->fp
->insn
[fpc
->inst_offset
];
366 /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */
367 hw
[0] = (NV40_FP_OP_BRA_OPCODE_BRK
<< NVFX_FP_OP_OPCODE_SHIFT
) |
369 /* Use .xxxx swizzle so that we check only src[0].x*/
370 hw
[1] = (NVFX_SWZ_IDENTITY
<< NVFX_FP_OP_COND_SWZ_X_SHIFT
) |
371 (NVFX_FP_OP_COND_TR
<< NVFX_FP_OP_COND_SHIFT
);
372 hw
[2] = NV40_FP_OP_OPCODE_IS_BRANCH
;
376 static inline struct nvfx_src
377 tgsi_src(struct nvfx_fpc
*fpc
, const struct tgsi_full_src_register
*fsrc
)
381 switch (fsrc
->Register
.File
) {
382 case TGSI_FILE_INPUT
:
383 src
.reg
= fpc
->r_input
[fsrc
->Register
.Index
];
385 case TGSI_FILE_CONSTANT
:
386 src
.reg
= nvfx_reg(NVFXSR_CONST
, fsrc
->Register
.Index
);
388 case TGSI_FILE_IMMEDIATE
:
389 assert(fsrc
->Register
.Index
< fpc
->nr_imm
);
390 src
.reg
= fpc
->r_imm
[fsrc
->Register
.Index
];
392 case TGSI_FILE_TEMPORARY
:
393 src
.reg
= fpc
->r_temp
[fsrc
->Register
.Index
];
395 /* NV40 fragprog result regs are just temps, so this is simple */
396 case TGSI_FILE_OUTPUT
:
397 src
.reg
= fpc
->r_result
[fsrc
->Register
.Index
];
400 NOUVEAU_ERR("bad src file\n");
406 src
.abs
= fsrc
->Register
.Absolute
;
407 src
.negate
= fsrc
->Register
.Negate
;
408 src
.swz
[0] = fsrc
->Register
.SwizzleX
;
409 src
.swz
[1] = fsrc
->Register
.SwizzleY
;
410 src
.swz
[2] = fsrc
->Register
.SwizzleZ
;
411 src
.swz
[3] = fsrc
->Register
.SwizzleW
;
413 src
.indirect_reg
= 0;
414 src
.indirect_swz
= 0;
418 static inline struct nvfx_reg
419 tgsi_dst(struct nvfx_fpc
*fpc
, const struct tgsi_full_dst_register
*fdst
) {
420 switch (fdst
->Register
.File
) {
421 case TGSI_FILE_OUTPUT
:
422 return fpc
->r_result
[fdst
->Register
.Index
];
423 case TGSI_FILE_TEMPORARY
:
424 return fpc
->r_temp
[fdst
->Register
.Index
];
426 return nvfx_reg(NVFXSR_NONE
, 0);
428 NOUVEAU_ERR("bad dst file %d\n", fdst
->Register
.File
);
429 return nvfx_reg(NVFXSR_NONE
, 0);
438 if (tgsi
& TGSI_WRITEMASK_X
) mask
|= NVFX_FP_MASK_X
;
439 if (tgsi
& TGSI_WRITEMASK_Y
) mask
|= NVFX_FP_MASK_Y
;
440 if (tgsi
& TGSI_WRITEMASK_Z
) mask
|= NVFX_FP_MASK_Z
;
441 if (tgsi
& TGSI_WRITEMASK_W
) mask
|= NVFX_FP_MASK_W
;
446 nvfx_fragprog_parse_instruction(struct nvfx_fpc
*fpc
,
447 const struct tgsi_full_instruction
*finst
)
449 const struct nvfx_src none
= nvfx_src(nvfx_reg(NVFXSR_NONE
, 0));
450 struct nvfx_insn insn
;
451 struct nvfx_src src
[3], tmp
;
453 int mask
, sat
, unit
= 0;
454 int ai
= -1, ci
= -1, ii
= -1;
457 if (finst
->Instruction
.Opcode
== TGSI_OPCODE_END
)
460 for (i
= 0; i
< finst
->Instruction
.NumSrcRegs
; i
++) {
461 const struct tgsi_full_src_register
*fsrc
;
463 fsrc
= &finst
->Src
[i
];
464 if (fsrc
->Register
.File
== TGSI_FILE_TEMPORARY
) {
465 src
[i
] = tgsi_src(fpc
, fsrc
);
469 for (i
= 0; i
< finst
->Instruction
.NumSrcRegs
; i
++) {
470 const struct tgsi_full_src_register
*fsrc
;
472 fsrc
= &finst
->Src
[i
];
474 switch (fsrc
->Register
.File
) {
475 case TGSI_FILE_INPUT
:
476 if(fpc
->fp
->info
.input_semantic_name
[fsrc
->Register
.Index
] == TGSI_SEMANTIC_FOG
&& (0
477 || fsrc
->Register
.SwizzleX
== PIPE_SWIZZLE_W
478 || fsrc
->Register
.SwizzleY
== PIPE_SWIZZLE_W
479 || fsrc
->Register
.SwizzleZ
== PIPE_SWIZZLE_W
480 || fsrc
->Register
.SwizzleW
== PIPE_SWIZZLE_W
482 /* hardware puts 0 in fogcoord.w, but GL/Gallium want 1 there */
483 struct nvfx_src addend
= nvfx_src(nvfx_fp_imm(fpc
, 0, 0, 0, 1));
484 addend
.swz
[0] = fsrc
->Register
.SwizzleX
;
485 addend
.swz
[1] = fsrc
->Register
.SwizzleY
;
486 addend
.swz
[2] = fsrc
->Register
.SwizzleZ
;
487 addend
.swz
[3] = fsrc
->Register
.SwizzleW
;
488 src
[i
] = nvfx_src(temp(fpc
));
489 nvfx_fp_emit(fpc
, arith(0, ADD
, src
[i
].reg
, NVFX_FP_MASK_ALL
, tgsi_src(fpc
, fsrc
), addend
, none
));
490 } else if (ai
== -1 || ai
== fsrc
->Register
.Index
) {
491 ai
= fsrc
->Register
.Index
;
492 src
[i
] = tgsi_src(fpc
, fsrc
);
494 src
[i
] = nvfx_src(temp(fpc
));
495 nvfx_fp_emit(fpc
, arith(0, MOV
, src
[i
].reg
, NVFX_FP_MASK_ALL
, tgsi_src(fpc
, fsrc
), none
, none
));
498 case TGSI_FILE_CONSTANT
:
499 if ((ci
== -1 && ii
== -1) ||
500 ci
== fsrc
->Register
.Index
) {
501 ci
= fsrc
->Register
.Index
;
502 src
[i
] = tgsi_src(fpc
, fsrc
);
504 src
[i
] = nvfx_src(temp(fpc
));
505 nvfx_fp_emit(fpc
, arith(0, MOV
, src
[i
].reg
, NVFX_FP_MASK_ALL
, tgsi_src(fpc
, fsrc
), none
, none
));
508 case TGSI_FILE_IMMEDIATE
:
509 if ((ci
== -1 && ii
== -1) ||
510 ii
== fsrc
->Register
.Index
) {
511 ii
= fsrc
->Register
.Index
;
512 src
[i
] = tgsi_src(fpc
, fsrc
);
514 src
[i
] = nvfx_src(temp(fpc
));
515 nvfx_fp_emit(fpc
, arith(0, MOV
, src
[i
].reg
, NVFX_FP_MASK_ALL
, tgsi_src(fpc
, fsrc
), none
, none
));
518 case TGSI_FILE_TEMPORARY
:
521 case TGSI_FILE_SAMPLER
:
522 unit
= fsrc
->Register
.Index
;
524 case TGSI_FILE_OUTPUT
:
527 NOUVEAU_ERR("bad src file\n");
532 dst
= tgsi_dst(fpc
, &finst
->Dst
[0]);
533 mask
= tgsi_mask(finst
->Dst
[0].Register
.WriteMask
);
534 sat
= finst
->Instruction
.Saturate
;
536 switch (finst
->Instruction
.Opcode
) {
537 case TGSI_OPCODE_ADD
:
538 nvfx_fp_emit(fpc
, arith(sat
, ADD
, dst
, mask
, src
[0], src
[1], none
));
540 case TGSI_OPCODE_CEIL
:
541 tmp
= nvfx_src(temp(fpc
));
542 nvfx_fp_emit(fpc
, arith(0, FLR
, tmp
.reg
, mask
, neg(src
[0]), none
, none
));
543 nvfx_fp_emit(fpc
, arith(sat
, MOV
, dst
, mask
, neg(tmp
), none
, none
));
545 case TGSI_OPCODE_CMP
:
546 insn
= arith(0, MOV
, none
.reg
, mask
, src
[0], none
, none
);
548 nvfx_fp_emit(fpc
, insn
);
550 insn
= arith(sat
, MOV
, dst
, mask
, src
[2], none
, none
);
551 insn
.cc_test
= NVFX_COND_GE
;
552 nvfx_fp_emit(fpc
, insn
);
554 insn
= arith(sat
, MOV
, dst
, mask
, src
[1], none
, none
);
555 insn
.cc_test
= NVFX_COND_LT
;
556 nvfx_fp_emit(fpc
, insn
);
558 case TGSI_OPCODE_COS
:
559 nvfx_fp_emit(fpc
, arith(sat
, COS
, dst
, mask
, src
[0], none
, none
));
561 case TGSI_OPCODE_DDX
:
562 if (mask
& (NVFX_FP_MASK_Z
| NVFX_FP_MASK_W
)) {
563 tmp
= nvfx_src(temp(fpc
));
564 nvfx_fp_emit(fpc
, arith(sat
, DDX
, tmp
.reg
, NVFX_FP_MASK_X
| NVFX_FP_MASK_Y
, swz(src
[0], Z
, W
, Z
, W
), none
, none
));
565 nvfx_fp_emit(fpc
, arith(0, MOV
, tmp
.reg
, NVFX_FP_MASK_Z
| NVFX_FP_MASK_W
, swz(tmp
, X
, Y
, X
, Y
), none
, none
));
566 nvfx_fp_emit(fpc
, arith(sat
, DDX
, tmp
.reg
, NVFX_FP_MASK_X
| NVFX_FP_MASK_Y
, src
[0], none
, none
));
567 nvfx_fp_emit(fpc
, arith(0, MOV
, dst
, mask
, tmp
, none
, none
));
569 nvfx_fp_emit(fpc
, arith(sat
, DDX
, dst
, mask
, src
[0], none
, none
));
572 case TGSI_OPCODE_DDY
:
573 if (mask
& (NVFX_FP_MASK_Z
| NVFX_FP_MASK_W
)) {
574 tmp
= nvfx_src(temp(fpc
));
575 nvfx_fp_emit(fpc
, arith(sat
, DDY
, tmp
.reg
, NVFX_FP_MASK_X
| NVFX_FP_MASK_Y
, swz(src
[0], Z
, W
, Z
, W
), none
, none
));
576 nvfx_fp_emit(fpc
, arith(0, MOV
, tmp
.reg
, NVFX_FP_MASK_Z
| NVFX_FP_MASK_W
, swz(tmp
, X
, Y
, X
, Y
), none
, none
));
577 nvfx_fp_emit(fpc
, arith(sat
, DDY
, tmp
.reg
, NVFX_FP_MASK_X
| NVFX_FP_MASK_Y
, src
[0], none
, none
));
578 nvfx_fp_emit(fpc
, arith(0, MOV
, dst
, mask
, tmp
, none
, none
));
580 nvfx_fp_emit(fpc
, arith(sat
, DDY
, dst
, mask
, src
[0], none
, none
));
583 case TGSI_OPCODE_DP2
:
584 tmp
= nvfx_src(temp(fpc
));
585 nvfx_fp_emit(fpc
, arith(0, MUL
, tmp
.reg
, NVFX_FP_MASK_X
| NVFX_FP_MASK_Y
, src
[0], src
[1], none
));
586 nvfx_fp_emit(fpc
, arith(0, ADD
, dst
, mask
, swz(tmp
, X
, X
, X
, X
), swz(tmp
, Y
, Y
, Y
, Y
), none
));
588 case TGSI_OPCODE_DP3
:
589 nvfx_fp_emit(fpc
, arith(sat
, DP3
, dst
, mask
, src
[0], src
[1], none
));
591 case TGSI_OPCODE_DP4
:
592 nvfx_fp_emit(fpc
, arith(sat
, DP4
, dst
, mask
, src
[0], src
[1], none
));
594 case TGSI_OPCODE_DST
:
595 nvfx_fp_emit(fpc
, arith(sat
, DST
, dst
, mask
, src
[0], src
[1], none
));
597 case TGSI_OPCODE_EX2
:
598 nvfx_fp_emit(fpc
, arith(sat
, EX2
, dst
, mask
, src
[0], none
, none
));
600 case TGSI_OPCODE_FLR
:
601 nvfx_fp_emit(fpc
, arith(sat
, FLR
, dst
, mask
, src
[0], none
, none
));
603 case TGSI_OPCODE_FRC
:
604 nvfx_fp_emit(fpc
, arith(sat
, FRC
, dst
, mask
, src
[0], none
, none
));
606 case TGSI_OPCODE_KILL
:
607 nvfx_fp_emit(fpc
, arith(0, KIL
, none
.reg
, 0, none
, none
, none
));
609 case TGSI_OPCODE_KILL_IF
:
610 insn
= arith(0, MOV
, none
.reg
, NVFX_FP_MASK_ALL
, src
[0], none
, none
);
612 nvfx_fp_emit(fpc
, insn
);
614 insn
= arith(0, KIL
, none
.reg
, 0, none
, none
, none
);
615 insn
.cc_test
= NVFX_COND_LT
;
616 nvfx_fp_emit(fpc
, insn
);
618 case TGSI_OPCODE_LG2
:
619 nvfx_fp_emit(fpc
, arith(sat
, LG2
, dst
, mask
, src
[0], none
, none
));
621 case TGSI_OPCODE_LIT
:
623 nvfx_fp_emit(fpc
, arith(sat
, LIT_NV30
, dst
, mask
, src
[0], none
, none
));
625 /* we use FLT_MIN, so that log2 never gives -infinity, and thus multiplication by
626 * specular 0 always gives 0, so that ex2 gives 1, to satisfy the 0^0 = 1 requirement
628 * NOTE: if we start using half precision, we might need an fp16 FLT_MIN here instead
630 struct nvfx_src maxs
= nvfx_src(nvfx_fp_imm(fpc
, 0, FLT_MIN
, 0, 0));
631 tmp
= nvfx_src(temp(fpc
));
632 if (ci
>= 0 || ii
>= 0) {
633 nvfx_fp_emit(fpc
, arith(0, MOV
, tmp
.reg
, NVFX_FP_MASK_X
| NVFX_FP_MASK_Y
, maxs
, none
, none
));
636 nvfx_fp_emit(fpc
, arith(0, MAX
, tmp
.reg
, NVFX_FP_MASK_Y
| NVFX_FP_MASK_W
, swz(src
[0], X
, X
, X
, Y
), swz(maxs
, X
, X
, Y
, Y
), none
));
637 nvfx_fp_emit(fpc
, arith(0, LG2
, tmp
.reg
, NVFX_FP_MASK_W
, swz(tmp
, W
, W
, W
, W
), none
, none
));
638 nvfx_fp_emit(fpc
, arith(0, MUL
, tmp
.reg
, NVFX_FP_MASK_W
, swz(tmp
, W
, W
, W
, W
), swz(src
[0], W
, W
, W
, W
), none
));
639 nvfx_fp_emit(fpc
, arith(sat
, LITEX2_NV40
, dst
, mask
, swz(tmp
, Y
, Y
, W
, W
), none
, none
));
642 case TGSI_OPCODE_LRP
:
644 nvfx_fp_emit(fpc
, arith(sat
, LRP_NV30
, dst
, mask
, src
[0], src
[1], src
[2]));
646 tmp
= nvfx_src(temp(fpc
));
647 nvfx_fp_emit(fpc
, arith(0, MAD
, tmp
.reg
, mask
, neg(src
[0]), src
[2], src
[2]));
648 nvfx_fp_emit(fpc
, arith(sat
, MAD
, dst
, mask
, src
[0], src
[1], tmp
));
651 case TGSI_OPCODE_MAD
:
652 nvfx_fp_emit(fpc
, arith(sat
, MAD
, dst
, mask
, src
[0], src
[1], src
[2]));
654 case TGSI_OPCODE_MAX
:
655 nvfx_fp_emit(fpc
, arith(sat
, MAX
, dst
, mask
, src
[0], src
[1], none
));
657 case TGSI_OPCODE_MIN
:
658 nvfx_fp_emit(fpc
, arith(sat
, MIN
, dst
, mask
, src
[0], src
[1], none
));
660 case TGSI_OPCODE_MOV
:
661 nvfx_fp_emit(fpc
, arith(sat
, MOV
, dst
, mask
, src
[0], none
, none
));
663 case TGSI_OPCODE_MUL
:
664 nvfx_fp_emit(fpc
, arith(sat
, MUL
, dst
, mask
, src
[0], src
[1], none
));
666 case TGSI_OPCODE_NOP
:
668 case TGSI_OPCODE_POW
:
670 nvfx_fp_emit(fpc
, arith(sat
, POW_NV30
, dst
, mask
, src
[0], src
[1], none
));
672 tmp
= nvfx_src(temp(fpc
));
673 nvfx_fp_emit(fpc
, arith(0, LG2
, tmp
.reg
, NVFX_FP_MASK_X
, swz(src
[0], X
, X
, X
, X
), none
, none
));
674 nvfx_fp_emit(fpc
, arith(0, MUL
, tmp
.reg
, NVFX_FP_MASK_X
, swz(tmp
, X
, X
, X
, X
), swz(src
[1], X
, X
, X
, X
), none
));
675 nvfx_fp_emit(fpc
, arith(sat
, EX2
, dst
, mask
, swz(tmp
, X
, X
, X
, X
), none
, none
));
678 case TGSI_OPCODE_RCP
:
679 nvfx_fp_emit(fpc
, arith(sat
, RCP
, dst
, mask
, src
[0], none
, none
));
681 case TGSI_OPCODE_RSQ
:
683 nvfx_fp_emit(fpc
, arith(sat
, RSQ_NV30
, dst
, mask
, abs(swz(src
[0], X
, X
, X
, X
)), none
, none
));
685 tmp
= nvfx_src(temp(fpc
));
686 insn
= arith(0, LG2
, tmp
.reg
, NVFX_FP_MASK_X
, abs(swz(src
[0], X
, X
, X
, X
)), none
, none
);
687 insn
.scale
= NVFX_FP_OP_DST_SCALE_INV_2X
;
688 nvfx_fp_emit(fpc
, insn
);
689 nvfx_fp_emit(fpc
, arith(sat
, EX2
, dst
, mask
, neg(swz(tmp
, X
, X
, X
, X
)), none
, none
));
692 case TGSI_OPCODE_SCS
:
693 /* avoid overwriting the source */
694 if(src
[0].swz
[NVFX_SWZ_X
] != NVFX_SWZ_X
)
696 if (mask
& NVFX_FP_MASK_X
)
697 nvfx_fp_emit(fpc
, arith(sat
, COS
, dst
, NVFX_FP_MASK_X
, swz(src
[0], X
, X
, X
, X
), none
, none
));
698 if (mask
& NVFX_FP_MASK_Y
)
699 nvfx_fp_emit(fpc
, arith(sat
, SIN
, dst
, NVFX_FP_MASK_Y
, swz(src
[0], X
, X
, X
, X
), none
, none
));
703 if (mask
& NVFX_FP_MASK_Y
)
704 nvfx_fp_emit(fpc
, arith(sat
, SIN
, dst
, NVFX_FP_MASK_Y
, swz(src
[0], X
, X
, X
, X
), none
, none
));
705 if (mask
& NVFX_FP_MASK_X
)
706 nvfx_fp_emit(fpc
, arith(sat
, COS
, dst
, NVFX_FP_MASK_X
, swz(src
[0], X
, X
, X
, X
), none
, none
));
709 case TGSI_OPCODE_SEQ
:
710 nvfx_fp_emit(fpc
, arith(sat
, SEQ
, dst
, mask
, src
[0], src
[1], none
));
712 case TGSI_OPCODE_SGE
:
713 nvfx_fp_emit(fpc
, arith(sat
, SGE
, dst
, mask
, src
[0], src
[1], none
));
715 case TGSI_OPCODE_SGT
:
716 nvfx_fp_emit(fpc
, arith(sat
, SGT
, dst
, mask
, src
[0], src
[1], none
));
718 case TGSI_OPCODE_SIN
:
719 nvfx_fp_emit(fpc
, arith(sat
, SIN
, dst
, mask
, src
[0], none
, none
));
721 case TGSI_OPCODE_SLE
:
722 nvfx_fp_emit(fpc
, arith(sat
, SLE
, dst
, mask
, src
[0], src
[1], none
));
724 case TGSI_OPCODE_SLT
:
725 nvfx_fp_emit(fpc
, arith(sat
, SLT
, dst
, mask
, src
[0], src
[1], none
));
727 case TGSI_OPCODE_SNE
:
728 nvfx_fp_emit(fpc
, arith(sat
, SNE
, dst
, mask
, src
[0], src
[1], none
));
730 case TGSI_OPCODE_SSG
:
732 struct nvfx_src minones
= swz(nvfx_src(nvfx_fp_imm(fpc
, -1, -1, -1, -1)), X
, X
, X
, X
);
734 insn
= arith(sat
, MOV
, dst
, mask
, src
[0], none
, none
);
736 nvfx_fp_emit(fpc
, insn
);
738 insn
= arith(0, STR
, dst
, mask
, none
, none
, none
);
739 insn
.cc_test
= NVFX_COND_GT
;
740 nvfx_fp_emit(fpc
, insn
);
743 insn
= arith(0, MOV
, dst
, mask
, minones
, none
, none
);
744 insn
.cc_test
= NVFX_COND_LT
;
745 nvfx_fp_emit(fpc
, insn
);
749 case TGSI_OPCODE_TEX
:
750 nvfx_fp_emit(fpc
, tex(sat
, TEX
, unit
, dst
, mask
, src
[0], none
, none
));
752 case TGSI_OPCODE_TRUNC
:
753 tmp
= nvfx_src(temp(fpc
));
754 insn
= arith(0, MOV
, none
.reg
, mask
, src
[0], none
, none
);
756 nvfx_fp_emit(fpc
, insn
);
758 nvfx_fp_emit(fpc
, arith(0, FLR
, tmp
.reg
, mask
, abs(src
[0]), none
, none
));
759 nvfx_fp_emit(fpc
, arith(sat
, MOV
, dst
, mask
, tmp
, none
, none
));
761 insn
= arith(sat
, MOV
, dst
, mask
, neg(tmp
), none
, none
);
762 insn
.cc_test
= NVFX_COND_LT
;
763 nvfx_fp_emit(fpc
, insn
);
765 case TGSI_OPCODE_TXB
:
766 nvfx_fp_emit(fpc
, tex(sat
, TXB
, unit
, dst
, mask
, src
[0], none
, none
));
768 case TGSI_OPCODE_TXL
:
770 nvfx_fp_emit(fpc
, tex(sat
, TXL_NV40
, unit
, dst
, mask
, src
[0], none
, none
));
771 else /* unsupported on nv30, use TEX and hope they like it */
772 nvfx_fp_emit(fpc
, tex(sat
, TEX
, unit
, dst
, mask
, src
[0], none
, none
));
774 case TGSI_OPCODE_TXP
:
775 nvfx_fp_emit(fpc
, tex(sat
, TXP
, unit
, dst
, mask
, src
[0], none
, none
));
777 case TGSI_OPCODE_XPD
:
778 tmp
= nvfx_src(temp(fpc
));
779 nvfx_fp_emit(fpc
, arith(0, MUL
, tmp
.reg
, mask
, swz(src
[0], Z
, X
, Y
, Y
), swz(src
[1], Y
, Z
, X
, X
), none
));
780 nvfx_fp_emit(fpc
, arith(sat
, MAD
, dst
, (mask
& ~NVFX_FP_MASK_W
), swz(src
[0], Y
, Z
, X
, X
), swz(src
[1], Z
, X
, Y
, Y
), neg(tmp
)));
784 // MOVRC0 R31 (TR0.xyzw), R<src>:
785 // IF (NE.xxxx) ELSE <else> END <end>
788 nv40_fp_if(fpc
, src
[0]);
791 case TGSI_OPCODE_ELSE
:
796 assert(util_dynarray_contains(&fpc
->if_stack
, unsigned));
797 hw
= &fpc
->fp
->insn
[util_dynarray_top(&fpc
->if_stack
, unsigned)];
798 hw
[2] = NV40_FP_OP_OPCODE_IS_BRANCH
| fpc
->fp
->insn_len
;
802 case TGSI_OPCODE_ENDIF
:
807 assert(util_dynarray_contains(&fpc
->if_stack
, unsigned));
808 hw
= &fpc
->fp
->insn
[util_dynarray_pop(&fpc
->if_stack
, unsigned)];
810 hw
[2] = NV40_FP_OP_OPCODE_IS_BRANCH
| fpc
->fp
->insn_len
;
811 hw
[3] = fpc
->fp
->insn_len
;
815 case TGSI_OPCODE_BGNSUB
:
816 case TGSI_OPCODE_ENDSUB
:
817 /* nothing to do here */
820 case TGSI_OPCODE_CAL
:
823 nv40_fp_cal(fpc
, finst
->Label
.Label
);
826 case TGSI_OPCODE_RET
:
832 case TGSI_OPCODE_BGNLOOP
:
835 /* TODO: we should support using two nested REPs to allow a > 255 iteration count */
836 nv40_fp_rep(fpc
, 255, finst
->Label
.Label
);
839 case TGSI_OPCODE_ENDLOOP
:
842 case TGSI_OPCODE_BRK
:
848 case TGSI_OPCODE_CONT
:
850 static int warned
= 0;
852 NOUVEAU_ERR("Sorry, the continue keyword is not implemented: ignoring it.\n");
859 NOUVEAU_ERR("invalid opcode %d\n", finst
->Instruction
.Opcode
);
868 static int warned
= 0;
871 "Sorry, control flow instructions are not supported in hardware on nv3x: ignoring them\n"
872 "If rendering is incorrect, try to disable GLSL support in the application.\n");
880 nvfx_fragprog_parse_decl_input(struct nvfx_fpc
*fpc
,
881 const struct tgsi_full_declaration
*fdec
)
883 unsigned idx
= fdec
->Range
.First
;
886 switch (fdec
->Semantic
.Name
) {
887 case TGSI_SEMANTIC_POSITION
:
888 hw
= NVFX_FP_OP_INPUT_SRC_POSITION
;
890 case TGSI_SEMANTIC_COLOR
:
891 hw
= NVFX_FP_OP_INPUT_SRC_COL0
+ fdec
->Semantic
.Index
;
893 case TGSI_SEMANTIC_FOG
:
894 hw
= NVFX_FP_OP_INPUT_SRC_FOGC
;
896 case TGSI_SEMANTIC_FACE
:
897 hw
= NV40_FP_OP_INPUT_SRC_FACING
;
899 case TGSI_SEMANTIC_TEXCOORD
:
900 assert(fdec
->Semantic
.Index
< 8);
901 fpc
->fp
->texcoord
[fdec
->Semantic
.Index
] = fdec
->Semantic
.Index
;
902 fpc
->fp
->texcoords
|= (1 << fdec
->Semantic
.Index
);
903 fpc
->fp
->vp_or
|= (0x00004000 << fdec
->Semantic
.Index
);
904 hw
= NVFX_FP_OP_INPUT_SRC_TC(fdec
->Semantic
.Index
);
906 case TGSI_SEMANTIC_GENERIC
:
907 case TGSI_SEMANTIC_PCOORD
:
908 /* will be assigned to remaining TC slots later */
915 fpc
->r_input
[idx
] = nvfx_reg(NVFXSR_INPUT
, hw
);
920 nvfx_fragprog_assign_generic(struct nvfx_fpc
*fpc
,
921 const struct tgsi_full_declaration
*fdec
)
923 unsigned num_texcoords
= fpc
->is_nv4x
? 10 : 8;
924 unsigned idx
= fdec
->Range
.First
;
927 switch (fdec
->Semantic
.Name
) {
928 case TGSI_SEMANTIC_GENERIC
:
929 case TGSI_SEMANTIC_PCOORD
:
930 for (hw
= 0; hw
< num_texcoords
; hw
++) {
931 if (fpc
->fp
->texcoord
[hw
] == 0xffff) {
933 fpc
->fp
->texcoords
|= (0x1 << hw
);
934 fpc
->fp
->vp_or
|= (0x00004000 << hw
);
936 fpc
->fp
->vp_or
|= (0x00001000 << (hw
- 8));
938 if (fdec
->Semantic
.Name
== TGSI_SEMANTIC_PCOORD
) {
939 fpc
->fp
->texcoord
[hw
] = 0xfffe;
940 fpc
->fp
->point_sprite_control
|= (0x00000100 << hw
);
942 fpc
->fp
->texcoord
[hw
] = fdec
->Semantic
.Index
+ 8;
944 hw
= NVFX_FP_OP_INPUT_SRC_TC(hw
);
945 fpc
->r_input
[idx
] = nvfx_reg(NVFXSR_INPUT
, hw
);
956 nvfx_fragprog_parse_decl_output(struct nvfx_fpc
*fpc
,
957 const struct tgsi_full_declaration
*fdec
)
959 unsigned idx
= fdec
->Range
.First
;
962 switch (fdec
->Semantic
.Name
) {
963 case TGSI_SEMANTIC_POSITION
:
966 case TGSI_SEMANTIC_COLOR
:
968 switch (fdec
->Semantic
.Index
) {
969 case 0: hw
= 0; break;
970 case 1: hw
= 2; break;
971 case 2: hw
= 3; break;
972 case 3: hw
= 4; break;
974 if(hw
> ((fpc
->is_nv4x
) ? 4 : 2)) {
975 NOUVEAU_ERR("bad rcol index\n");
980 NOUVEAU_ERR("bad output semantic\n");
984 fpc
->r_result
[idx
] = nvfx_reg(NVFXSR_OUTPUT
, hw
);
985 fpc
->r_temps
|= (1ULL << hw
);
990 nvfx_fragprog_prepare(struct nvfx_fpc
*fpc
)
992 struct tgsi_parse_context p
;
993 int high_temp
= -1, i
;
995 fpc
->r_imm
= CALLOC(fpc
->fp
->info
.immediate_count
, sizeof(struct nvfx_reg
));
997 tgsi_parse_init(&p
, fpc
->fp
->pipe
.tokens
);
998 while (!tgsi_parse_end_of_tokens(&p
)) {
999 const union tgsi_full_token
*tok
= &p
.FullToken
;
1001 tgsi_parse_token(&p
);
1002 switch(tok
->Token
.Type
) {
1003 case TGSI_TOKEN_TYPE_DECLARATION
:
1005 const struct tgsi_full_declaration
*fdec
;
1006 fdec
= &p
.FullToken
.FullDeclaration
;
1007 switch (fdec
->Declaration
.File
) {
1008 case TGSI_FILE_INPUT
:
1009 if (!nvfx_fragprog_parse_decl_input(fpc
, fdec
))
1012 case TGSI_FILE_OUTPUT
:
1013 if (!nvfx_fragprog_parse_decl_output(fpc
, fdec
))
1016 case TGSI_FILE_TEMPORARY
:
1017 if (fdec
->Range
.Last
> high_temp
) {
1027 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1029 struct tgsi_full_immediate
*imm
;
1031 imm
= &p
.FullToken
.FullImmediate
;
1032 assert(imm
->Immediate
.DataType
== TGSI_IMM_FLOAT32
);
1033 assert(fpc
->nr_imm
< fpc
->fp
->info
.immediate_count
);
1035 fpc
->r_imm
[fpc
->nr_imm
++] = nvfx_fp_imm(fpc
, imm
->u
[0].Float
, imm
->u
[1].Float
, imm
->u
[2].Float
, imm
->u
[3].Float
);
1042 tgsi_parse_free(&p
);
1044 tgsi_parse_init(&p
, fpc
->fp
->pipe
.tokens
);
1045 while (!tgsi_parse_end_of_tokens(&p
)) {
1046 const struct tgsi_full_declaration
*fdec
;
1047 tgsi_parse_token(&p
);
1048 switch(p
.FullToken
.Token
.Type
) {
1049 case TGSI_TOKEN_TYPE_DECLARATION
:
1050 fdec
= &p
.FullToken
.FullDeclaration
;
1051 switch (fdec
->Declaration
.File
) {
1052 case TGSI_FILE_INPUT
:
1053 if (!nvfx_fragprog_assign_generic(fpc
, fdec
))
1064 tgsi_parse_free(&p
);
1067 fpc
->r_temp
= CALLOC(high_temp
, sizeof(struct nvfx_reg
));
1068 for (i
= 0; i
< high_temp
; i
++)
1069 fpc
->r_temp
[i
] = temp(fpc
);
1070 fpc
->r_temps_discard
= 0ULL;
1079 tgsi_parse_free(&p
);
1083 DEBUG_GET_ONCE_BOOL_OPTION(nvfx_dump_fp
, "NVFX_DUMP_FP", false)
1086 _nvfx_fragprog_translate(uint16_t oclass
, struct nv30_fragprog
*fp
)
1088 struct tgsi_parse_context parse
;
1089 struct nvfx_fpc
*fpc
= NULL
;
1090 struct util_dynarray insns
;
1092 fp
->translated
= false;
1093 fp
->point_sprite_control
= 0;
1096 fpc
= CALLOC_STRUCT(nvfx_fpc
);
1100 fpc
->is_nv4x
= (oclass
>= NV40_3D_CLASS
) ? ~0 : 0;
1101 fpc
->max_temps
= fpc
->is_nv4x
? 48 : 32;
1104 memset(fp
->texcoord
, 0xff, sizeof(fp
->texcoord
));
1106 if (fp
->info
.properties
[TGSI_PROPERTY_FS_COORD_ORIGIN
])
1107 fp
->coord_conventions
|= NV30_3D_COORD_CONVENTIONS_ORIGIN_INVERTED
;
1108 if (fp
->info
.properties
[TGSI_PROPERTY_FS_COORD_PIXEL_CENTER
])
1109 fp
->coord_conventions
|= NV30_3D_COORD_CONVENTIONS_CENTER_INTEGER
;
1110 if (fp
->info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
])
1111 fp
->rt_enable
|= NV30_3D_RT_ENABLE_MRT
;
1113 if (!nvfx_fragprog_prepare(fpc
))
1116 tgsi_parse_init(&parse
, fp
->pipe
.tokens
);
1117 util_dynarray_init(&insns
, NULL
);
1119 while (!tgsi_parse_end_of_tokens(&parse
)) {
1120 tgsi_parse_token(&parse
);
1122 switch (parse
.FullToken
.Token
.Type
) {
1123 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1125 const struct tgsi_full_instruction
*finst
;
1127 util_dynarray_append(&insns
, unsigned, fp
->insn_len
);
1128 finst
= &parse
.FullToken
.FullInstruction
;
1129 if (!nvfx_fragprog_parse_instruction(fpc
, finst
))
1137 util_dynarray_append(&insns
, unsigned, fp
->insn_len
);
1139 for(unsigned i
= 0; i
< fpc
->label_relocs
.size
; i
+= sizeof(struct nvfx_relocation
))
1141 struct nvfx_relocation
* label_reloc
= (struct nvfx_relocation
*)((char*)fpc
->label_relocs
.data
+ i
);
1142 fp
->insn
[label_reloc
->location
] |= ((unsigned*)insns
.data
)[label_reloc
->target
];
1144 util_dynarray_fini(&insns
);
1147 fp
->fp_control
|= (fpc
->num_regs
-1)/2;
1149 fp
->fp_control
|= fpc
->num_regs
<< NV40_3D_FP_CONTROL_TEMP_COUNT__SHIFT
;
1151 /* Terminate final instruction */
1153 fp
->insn
[fpc
->inst_offset
] |= 0x00000001;
1155 /* Append NOP + END instruction for branches to the end of the program */
1156 fpc
->inst_offset
= fp
->insn_len
;
1158 fp
->insn
[fpc
->inst_offset
+ 0] = 0x00000001;
1159 fp
->insn
[fpc
->inst_offset
+ 1] = 0x00000000;
1160 fp
->insn
[fpc
->inst_offset
+ 2] = 0x00000000;
1161 fp
->insn
[fpc
->inst_offset
+ 3] = 0x00000000;
1163 if(debug_get_option_nvfx_dump_fp())
1166 tgsi_dump(fp
->pipe
.tokens
, 0);
1168 debug_printf("\n%s fragment program:\n", fpc
->is_nv4x
? "nv4x" : "nv3x");
1169 for (unsigned i
= 0; i
< fp
->insn_len
; i
+= 4)
1170 debug_printf("%3u: %08x %08x %08x %08x\n", i
>> 2, fp
->insn
[i
], fp
->insn
[i
+ 1], fp
->insn
[i
+ 2], fp
->insn
[i
+ 3]);
1174 fp
->translated
= true;
1177 tgsi_parse_free(&parse
);
1182 util_dynarray_fini(&fpc
->if_stack
);
1183 util_dynarray_fini(&fpc
->label_relocs
);
1184 util_dynarray_fini(&fpc
->imm_data
);
1185 //util_dynarray_fini(&fpc->loop_stack);
1192 _debug_printf("Error: failed to compile this fragment program:\n");
1193 tgsi_dump(fp
->pipe
.tokens
, 0);