2 * Copyright 2008 Ben Skeggs
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "pipe/p_context.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/p_state.h"
26 #include "pipe/p_inlines.h"
28 #include "pipe/p_shader_tokens.h"
29 #include "tgsi/tgsi_parse.h"
30 #include "tgsi/tgsi_util.h"
32 #include "nv50_context.h"
34 #define NV50_SU_MAX_TEMP 64
35 //#define NV50_PROGRAM_DUMP
37 /* ARL - gallium craps itself on progs/vp/arl.txt
39 * MSB - Like MAD, but MUL+SUB
40 * - Fuck it off, introduce a way to negate args for ops that
43 * Look into inlining IMMD for ops other than MOV (make it general?)
44 * - Maybe even relax restrictions a bit, can't do P_RESULT + P_IMMD,
45 * but can emit to P_TEMP first - then MOV later. NVIDIA does this
47 * In ops such as ADD it's possible to construct a bad opcode in the !is_long()
48 * case, if the emit_src() causes the inst to suddenly become long.
50 * Verify half-insns work where expected - and force disable them where they
51 * don't work - MUL has it forcibly disabled atm as it fixes POW..
53 * FUCK! watch dst==src vectors, can overwrite components that are needed.
54 * ie. SUB R0, R0.yzxw, R0
56 * Things to check with renouveau:
57 * FP attr/result assignment - how?
59 * - 0x16bc maps vp output onto fp hpos
60 * - 0x16c0 maps vp output onto fp col0
64 * 0x16bc->0x16e8 --> some binding between vp/fp regs
65 * 0x16b8 --> VP output count
67 * 0x1298 --> "MOV rcol.x, fcol.y" "MOV depr, fcol.y" = 0x00000005
68 * "MOV rcol.x, fcol.y" = 0x00000004
69 * 0x19a8 --> as above but 0x00000100 and 0x00000000
70 * - 0x00100000 used when KIL used
71 * 0x196c --> as above but 0x00000011 and 0x00000000
73 * 0x1988 --> 0xXXNNNNNN
74 * - XX == FP high something
89 int rhw
; /* result hw for FP outputs, or interpolant index */
90 int acc
; /* instruction where this reg is last read (first insn == 1) */
93 /* arbitrary limits */
94 #define MAX_IF_DEPTH 4
95 #define MAX_LOOP_DEPTH 4
98 struct nv50_program
*p
;
101 struct nv50_reg
*r_temp
[NV50_SU_MAX_TEMP
];
104 struct nv50_reg
*temp
;
106 struct nv50_reg
*attr
;
108 struct nv50_reg
*result
;
110 struct nv50_reg
*param
;
112 struct nv50_reg
*immd
;
116 struct nv50_reg
*temp_temp
[16];
117 unsigned temp_temp_nr
;
119 /* broadcast and destination replacement regs */
120 struct nv50_reg
*r_brdc
;
121 struct nv50_reg
*r_dst
[4];
123 unsigned interp_mode
[32];
124 /* perspective interpolation registers */
125 struct nv50_reg
*iv_p
;
126 struct nv50_reg
*iv_c
;
128 struct nv50_program_exec
*if_cond
;
129 struct nv50_program_exec
*if_insn
[MAX_IF_DEPTH
];
130 struct nv50_program_exec
*br_join
[MAX_IF_DEPTH
];
131 struct nv50_program_exec
*br_loop
[MAX_LOOP_DEPTH
]; /* for BRK branch */
132 int if_lvl
, loop_lvl
;
133 unsigned loop_pos
[MAX_LOOP_DEPTH
];
135 /* current instruction and total number of insns */
143 ctor_reg(struct nv50_reg
*reg
, unsigned type
, int index
, int hw
)
153 static INLINE
unsigned
154 popcnt4(uint32_t val
)
156 static const unsigned cnt
[16]
157 = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
158 return cnt
[val
& 0xf];
162 alloc_reg(struct nv50_pc
*pc
, struct nv50_reg
*reg
)
166 if (reg
->type
== P_RESULT
) {
167 if (pc
->p
->cfg
.high_result
< (reg
->hw
+ 1))
168 pc
->p
->cfg
.high_result
= reg
->hw
+ 1;
171 if (reg
->type
!= P_TEMP
)
175 /*XXX: do this here too to catch FP temp-as-attr usage..
176 * not clean, but works */
177 if (pc
->p
->cfg
.high_temp
< (reg
->hw
+ 1))
178 pc
->p
->cfg
.high_temp
= reg
->hw
+ 1;
182 if (reg
->rhw
!= -1) {
183 /* try to allocate temporary with index rhw first */
184 if (!(pc
->r_temp
[reg
->rhw
])) {
185 pc
->r_temp
[reg
->rhw
] = reg
;
187 if (pc
->p
->cfg
.high_temp
< (reg
->rhw
+ 1))
188 pc
->p
->cfg
.high_temp
= reg
->rhw
+ 1;
191 /* make sure we don't get things like $r0 needs to go
192 * in $r1 and $r1 in $r0
194 i
= pc
->result_nr
* 4;
197 for (; i
< NV50_SU_MAX_TEMP
; i
++) {
198 if (!(pc
->r_temp
[i
])) {
201 if (pc
->p
->cfg
.high_temp
< (i
+ 1))
202 pc
->p
->cfg
.high_temp
= i
+ 1;
210 /* XXX: For shaders that aren't executed linearly (e.g. shaders that
211 * contain loops), we need to assign all hw regs to TGSI TEMPs early,
212 * lest we risk temp_temps overwriting regs alloc'd "later".
214 static struct nv50_reg
*
215 alloc_temp(struct nv50_pc
*pc
, struct nv50_reg
*dst
)
220 if (dst
&& dst
->type
== P_TEMP
&& dst
->hw
== -1)
223 for (i
= 0; i
< NV50_SU_MAX_TEMP
; i
++) {
224 if (!pc
->r_temp
[i
]) {
225 r
= MALLOC_STRUCT(nv50_reg
);
226 ctor_reg(r
, P_TEMP
, -1, i
);
236 /* Assign the hw of the discarded temporary register src
237 * to the tgsi register dst and free src.
240 assimilate_temp(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
242 assert(src
->index
== -1 && src
->hw
!= -1);
245 pc
->r_temp
[dst
->hw
] = NULL
;
246 pc
->r_temp
[src
->hw
] = dst
;
252 /* release the hardware resource held by r */
254 release_hw(struct nv50_pc
*pc
, struct nv50_reg
*r
)
256 assert(r
->type
== P_TEMP
);
260 assert(pc
->r_temp
[r
->hw
] == r
);
261 pc
->r_temp
[r
->hw
] = NULL
;
269 free_temp(struct nv50_pc
*pc
, struct nv50_reg
*r
)
271 if (r
->index
== -1) {
274 FREE(pc
->r_temp
[hw
]);
275 pc
->r_temp
[hw
] = NULL
;
280 alloc_temp4(struct nv50_pc
*pc
, struct nv50_reg
*dst
[4], int idx
)
284 if ((idx
+ 4) >= NV50_SU_MAX_TEMP
)
287 if (pc
->r_temp
[idx
] || pc
->r_temp
[idx
+ 1] ||
288 pc
->r_temp
[idx
+ 2] || pc
->r_temp
[idx
+ 3])
289 return alloc_temp4(pc
, dst
, idx
+ 4);
291 for (i
= 0; i
< 4; i
++) {
292 dst
[i
] = MALLOC_STRUCT(nv50_reg
);
293 ctor_reg(dst
[i
], P_TEMP
, -1, idx
+ i
);
294 pc
->r_temp
[idx
+ i
] = dst
[i
];
301 free_temp4(struct nv50_pc
*pc
, struct nv50_reg
*reg
[4])
305 for (i
= 0; i
< 4; i
++)
306 free_temp(pc
, reg
[i
]);
309 static struct nv50_reg
*
310 temp_temp(struct nv50_pc
*pc
)
312 if (pc
->temp_temp_nr
>= 16)
315 pc
->temp_temp
[pc
->temp_temp_nr
] = alloc_temp(pc
, NULL
);
316 return pc
->temp_temp
[pc
->temp_temp_nr
++];
320 kill_temp_temp(struct nv50_pc
*pc
)
324 for (i
= 0; i
< pc
->temp_temp_nr
; i
++)
325 free_temp(pc
, pc
->temp_temp
[i
]);
326 pc
->temp_temp_nr
= 0;
330 ctor_immd(struct nv50_pc
*pc
, float x
, float y
, float z
, float w
)
332 pc
->immd_buf
= REALLOC(pc
->immd_buf
, (pc
->immd_nr
* 4 * sizeof(float)),
333 (pc
->immd_nr
+ 1) * 4 * sizeof(float));
334 pc
->immd_buf
[(pc
->immd_nr
* 4) + 0] = x
;
335 pc
->immd_buf
[(pc
->immd_nr
* 4) + 1] = y
;
336 pc
->immd_buf
[(pc
->immd_nr
* 4) + 2] = z
;
337 pc
->immd_buf
[(pc
->immd_nr
* 4) + 3] = w
;
339 return pc
->immd_nr
++;
342 static struct nv50_reg
*
343 alloc_immd(struct nv50_pc
*pc
, float f
)
345 struct nv50_reg
*r
= MALLOC_STRUCT(nv50_reg
);
348 for (hw
= 0; hw
< pc
->immd_nr
* 4; hw
++)
349 if (pc
->immd_buf
[hw
] == f
)
352 if (hw
== pc
->immd_nr
* 4)
353 hw
= ctor_immd(pc
, f
, -f
, 0.5 * f
, 0) * 4;
355 ctor_reg(r
, P_IMMD
, -1, hw
);
359 static struct nv50_program_exec
*
360 exec(struct nv50_pc
*pc
)
362 struct nv50_program_exec
*e
= CALLOC_STRUCT(nv50_program_exec
);
369 emit(struct nv50_pc
*pc
, struct nv50_program_exec
*e
)
371 struct nv50_program
*p
= pc
->p
;
374 p
->exec_tail
->next
= e
;
378 p
->exec_size
+= (e
->inst
[0] & 1) ? 2 : 1;
381 static INLINE
void set_long(struct nv50_pc
*, struct nv50_program_exec
*);
384 is_long(struct nv50_program_exec
*e
)
392 is_immd(struct nv50_program_exec
*e
)
394 if (is_long(e
) && (e
->inst
[1] & 3) == 3)
400 set_pred(struct nv50_pc
*pc
, unsigned pred
, unsigned idx
,
401 struct nv50_program_exec
*e
)
404 e
->inst
[1] &= ~((0x1f << 7) | (0x3 << 12));
405 e
->inst
[1] |= (pred
<< 7) | (idx
<< 12);
409 set_pred_wr(struct nv50_pc
*pc
, unsigned on
, unsigned idx
,
410 struct nv50_program_exec
*e
)
413 e
->inst
[1] &= ~((0x3 << 4) | (1 << 6));
414 e
->inst
[1] |= (idx
<< 4) | (on
<< 6);
418 set_long(struct nv50_pc
*pc
, struct nv50_program_exec
*e
)
424 set_pred(pc
, 0xf, 0, e
);
425 set_pred_wr(pc
, 0, 0, e
);
429 set_dst(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_program_exec
*e
)
431 if (dst
->type
== P_RESULT
) {
433 e
->inst
[1] |= 0x00000008;
437 e
->inst
[0] |= (dst
->hw
<< 2);
441 set_immd(struct nv50_pc
*pc
, struct nv50_reg
*imm
, struct nv50_program_exec
*e
)
443 float f
= pc
->immd_buf
[imm
->hw
];
444 unsigned val
= fui(imm
->neg
? -f
: f
);
447 /*XXX: can't be predicated - bits overlap.. catch cases where both
448 * are required and avoid them. */
449 set_pred(pc
, 0, 0, e
);
450 set_pred_wr(pc
, 0, 0, e
);
452 e
->inst
[1] |= 0x00000002 | 0x00000001;
453 e
->inst
[0] |= (val
& 0x3f) << 16;
454 e
->inst
[1] |= (val
>> 6) << 2;
458 #define INTERP_LINEAR 0
459 #define INTERP_FLAT 1
460 #define INTERP_PERSPECTIVE 2
461 #define INTERP_CENTROID 4
463 /* interpolant index has been stored in dst->rhw */
465 emit_interp(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*iv
,
468 assert(dst
->rhw
!= -1);
469 struct nv50_program_exec
*e
= exec(pc
);
471 e
->inst
[0] |= 0x80000000;
473 e
->inst
[0] |= (dst
->rhw
<< 16);
475 if (mode
& INTERP_FLAT
) {
476 e
->inst
[0] |= (1 << 8);
478 if (mode
& INTERP_PERSPECTIVE
) {
479 e
->inst
[0] |= (1 << 25);
481 e
->inst
[0] |= (iv
->hw
<< 9);
484 if (mode
& INTERP_CENTROID
)
485 e
->inst
[0] |= (1 << 24);
492 set_data(struct nv50_pc
*pc
, struct nv50_reg
*src
, unsigned m
, unsigned s
,
493 struct nv50_program_exec
*e
)
497 e
->param
.index
= src
->hw
;
499 e
->param
.mask
= m
<< (s
% 32);
501 e
->inst
[1] |= (((src
->type
== P_IMMD
) ? 0 : 1) << 22);
505 emit_mov(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
507 struct nv50_program_exec
*e
= exec(pc
);
509 e
->inst
[0] = 0x10000000;
515 if (!is_long(e
) && src
->type
== P_IMMD
) {
516 set_immd(pc
, src
, e
);
517 /*XXX: 32-bit, but steals part of "half" reg space - need to
518 * catch and handle this case if/when we do half-regs
521 if (src
->type
== P_IMMD
|| src
->type
== P_CONST
) {
523 set_data(pc
, src
, 0x7f, 9, e
);
524 e
->inst
[1] |= 0x20000000; /* src0 const? */
526 if (src
->type
== P_ATTR
) {
528 e
->inst
[1] |= 0x00200000;
532 e
->inst
[0] |= (src
->hw
<< 9);
535 if (is_long(e
) && !is_immd(e
)) {
536 e
->inst
[1] |= 0x04000000; /* 32-bit */
537 e
->inst
[1] |= 0x0000c000; /* "subsubop" 0x3 */
538 if (!(e
->inst
[1] & 0x20000000))
539 e
->inst
[1] |= 0x00030000; /* "subsubop" 0xf */
541 e
->inst
[0] |= 0x00008000;
547 emit_mov_immdval(struct nv50_pc
*pc
, struct nv50_reg
*dst
, float f
)
549 struct nv50_reg
*imm
= alloc_immd(pc
, f
);
550 emit_mov(pc
, dst
, imm
);
555 check_swap_src_0_1(struct nv50_pc
*pc
,
556 struct nv50_reg
**s0
, struct nv50_reg
**s1
)
558 struct nv50_reg
*src0
= *s0
, *src1
= *s1
;
560 if (src0
->type
== P_CONST
) {
561 if (src1
->type
!= P_CONST
) {
567 if (src1
->type
== P_ATTR
) {
568 if (src0
->type
!= P_ATTR
) {
579 set_src_0_restricted(struct nv50_pc
*pc
, struct nv50_reg
*src
,
580 struct nv50_program_exec
*e
)
582 struct nv50_reg
*temp
;
584 if (src
->type
!= P_TEMP
) {
585 temp
= temp_temp(pc
);
586 emit_mov(pc
, temp
, src
);
591 e
->inst
[0] |= (src
->hw
<< 9);
595 set_src_0(struct nv50_pc
*pc
, struct nv50_reg
*src
, struct nv50_program_exec
*e
)
597 if (src
->type
== P_ATTR
) {
599 e
->inst
[1] |= 0x00200000;
601 if (src
->type
== P_CONST
|| src
->type
== P_IMMD
) {
602 struct nv50_reg
*temp
= temp_temp(pc
);
604 emit_mov(pc
, temp
, src
);
609 e
->inst
[0] |= (src
->hw
<< 9);
613 set_src_1(struct nv50_pc
*pc
, struct nv50_reg
*src
, struct nv50_program_exec
*e
)
615 if (src
->type
== P_ATTR
) {
616 struct nv50_reg
*temp
= temp_temp(pc
);
618 emit_mov(pc
, temp
, src
);
621 if (src
->type
== P_CONST
|| src
->type
== P_IMMD
) {
622 assert(!(e
->inst
[0] & 0x00800000));
623 if (e
->inst
[0] & 0x01000000) {
624 struct nv50_reg
*temp
= temp_temp(pc
);
626 emit_mov(pc
, temp
, src
);
629 set_data(pc
, src
, 0x7f, 16, e
);
630 e
->inst
[0] |= 0x00800000;
635 e
->inst
[0] |= (src
->hw
<< 16);
639 set_src_2(struct nv50_pc
*pc
, struct nv50_reg
*src
, struct nv50_program_exec
*e
)
643 if (src
->type
== P_ATTR
) {
644 struct nv50_reg
*temp
= temp_temp(pc
);
646 emit_mov(pc
, temp
, src
);
649 if (src
->type
== P_CONST
|| src
->type
== P_IMMD
) {
650 assert(!(e
->inst
[0] & 0x01000000));
651 if (e
->inst
[0] & 0x00800000) {
652 struct nv50_reg
*temp
= temp_temp(pc
);
654 emit_mov(pc
, temp
, src
);
657 set_data(pc
, src
, 0x7f, 32+14, e
);
658 e
->inst
[0] |= 0x01000000;
663 e
->inst
[1] |= (src
->hw
<< 14);
667 emit_mul(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
668 struct nv50_reg
*src1
)
670 struct nv50_program_exec
*e
= exec(pc
);
672 e
->inst
[0] |= 0xc0000000;
677 check_swap_src_0_1(pc
, &src0
, &src1
);
679 set_src_0(pc
, src0
, e
);
680 if (src1
->type
== P_IMMD
&& !is_long(e
)) {
682 e
->inst
[0] |= 0x00008000;
683 set_immd(pc
, src1
, e
);
685 set_src_1(pc
, src1
, e
);
686 if (src0
->neg
^ src1
->neg
) {
688 e
->inst
[1] |= 0x08000000;
690 e
->inst
[0] |= 0x00008000;
698 emit_add(struct nv50_pc
*pc
, struct nv50_reg
*dst
,
699 struct nv50_reg
*src0
, struct nv50_reg
*src1
)
701 struct nv50_program_exec
*e
= exec(pc
);
703 e
->inst
[0] |= 0xb0000000;
705 check_swap_src_0_1(pc
, &src0
, &src1
);
707 if (!pc
->allow32
|| src0
->neg
|| src1
->neg
) {
709 e
->inst
[1] |= (src0
->neg
<< 26) | (src1
->neg
<< 27);
713 set_src_0(pc
, src0
, e
);
714 if (src1
->type
== P_CONST
|| src1
->type
== P_ATTR
|| is_long(e
))
715 set_src_2(pc
, src1
, e
);
717 if (src1
->type
== P_IMMD
)
718 set_immd(pc
, src1
, e
);
720 set_src_1(pc
, src1
, e
);
726 emit_minmax(struct nv50_pc
*pc
, unsigned sub
, struct nv50_reg
*dst
,
727 struct nv50_reg
*src0
, struct nv50_reg
*src1
)
729 struct nv50_program_exec
*e
= exec(pc
);
732 e
->inst
[0] |= 0xb0000000;
733 e
->inst
[1] |= (sub
<< 29);
735 check_swap_src_0_1(pc
, &src0
, &src1
);
737 set_src_0(pc
, src0
, e
);
738 set_src_1(pc
, src1
, e
);
744 emit_sub(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
745 struct nv50_reg
*src1
)
748 emit_add(pc
, dst
, src0
, src1
);
753 emit_mad(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
754 struct nv50_reg
*src1
, struct nv50_reg
*src2
)
756 struct nv50_program_exec
*e
= exec(pc
);
758 e
->inst
[0] |= 0xe0000000;
760 check_swap_src_0_1(pc
, &src0
, &src1
);
762 set_src_0(pc
, src0
, e
);
763 set_src_1(pc
, src1
, e
);
764 set_src_2(pc
, src2
, e
);
766 if (src0
->neg
^ src1
->neg
)
767 e
->inst
[1] |= 0x04000000;
769 e
->inst
[1] |= 0x08000000;
775 emit_msb(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
776 struct nv50_reg
*src1
, struct nv50_reg
*src2
)
779 emit_mad(pc
, dst
, src0
, src1
, src2
);
784 emit_flop(struct nv50_pc
*pc
, unsigned sub
,
785 struct nv50_reg
*dst
, struct nv50_reg
*src
)
787 struct nv50_program_exec
*e
= exec(pc
);
789 e
->inst
[0] |= 0x90000000;
792 e
->inst
[1] |= (sub
<< 29);
797 if (sub
== 0 || sub
== 2)
798 set_src_0_restricted(pc
, src
, e
);
800 set_src_0(pc
, src
, e
);
806 emit_preex2(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
808 struct nv50_program_exec
*e
= exec(pc
);
810 e
->inst
[0] |= 0xb0000000;
813 set_src_0(pc
, src
, e
);
815 e
->inst
[1] |= (6 << 29) | 0x00004000;
821 emit_precossin(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
823 struct nv50_program_exec
*e
= exec(pc
);
825 e
->inst
[0] |= 0xb0000000;
828 set_src_0(pc
, src
, e
);
830 e
->inst
[1] |= (6 << 29);
835 #define CVTOP_RN 0x01
836 #define CVTOP_FLOOR 0x03
837 #define CVTOP_CEIL 0x05
838 #define CVTOP_TRUNC 0x07
839 #define CVTOP_SAT 0x08
840 #define CVTOP_ABS 0x10
842 /* 0x04 == 32 bit dst */
843 /* 0x40 == dst is float */
844 /* 0x80 == src is float */
845 #define CVT_F32_F32 0xc4
846 #define CVT_F32_S32 0x44
847 #define CVT_F32_U32 0x64
848 #define CVT_S32_F32 0x8c
849 #define CVT_S32_S32 0x0c
854 emit_cvt(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
,
855 int wp
, unsigned cvn
, unsigned fmt
)
857 struct nv50_program_exec
*e
;
862 e
->inst
[0] |= 0xa0000000;
863 e
->inst
[1] |= 0x00004000; /* 32 bit src */
864 e
->inst
[1] |= (cvn
<< 16);
865 e
->inst
[1] |= (fmt
<< 24);
866 set_src_0(pc
, src
, e
);
869 set_pred_wr(pc
, 1, wp
, e
);
874 e
->inst
[0] |= 0x000001fc;
875 e
->inst
[1] |= 0x00000008;
881 /* nv50 Condition codes:
888 * 0x7 = set condition code ? (used before bra.lt/le/gt/ge)
889 * 0x8 = unordered bit (allows NaN)
892 emit_set(struct nv50_pc
*pc
, unsigned ccode
, struct nv50_reg
*dst
, int wp
,
893 struct nv50_reg
*src0
, struct nv50_reg
*src1
)
895 static const unsigned cc_swapped
[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
897 struct nv50_program_exec
*e
= exec(pc
);
898 struct nv50_reg
*rdst
;
901 if (check_swap_src_0_1(pc
, &src0
, &src1
))
902 ccode
= cc_swapped
[ccode
& 7] | (ccode
& 8);
905 if (dst
&& dst
->type
!= P_TEMP
)
906 dst
= alloc_temp(pc
, NULL
);
910 e
->inst
[0] |= 0xb0000000;
911 e
->inst
[1] |= 0x60000000 | (ccode
<< 14);
913 /* XXX: decuda will disasm as .u16 and use .lo/.hi regs, but
914 * that doesn't seem to match what the hw actually does
915 e->inst[1] |= 0x04000000; << breaks things, u32 by default ?
919 set_pred_wr(pc
, 1, wp
, e
);
923 e
->inst
[0] |= 0x000001fc;
924 e
->inst
[1] |= 0x00000008;
927 set_src_0(pc
, src0
, e
);
928 set_src_1(pc
, src1
, e
);
931 pc
->if_cond
= pc
->p
->exec_tail
; /* record for OPCODE_IF */
933 /* cvt.f32.u32/s32 (?) if we didn't only write the predicate */
935 emit_cvt(pc
, rdst
, dst
, -1, CVTOP_ABS
| CVTOP_RN
, CVT_F32_S32
);
936 if (rdst
&& rdst
!= dst
)
940 static INLINE
unsigned
941 map_tgsi_setop_cc(unsigned op
)
944 case TGSI_OPCODE_SLT
: return 0x1;
945 case TGSI_OPCODE_SGE
: return 0x6;
946 case TGSI_OPCODE_SEQ
: return 0x2;
947 case TGSI_OPCODE_SGT
: return 0x4;
948 case TGSI_OPCODE_SLE
: return 0x3;
949 case TGSI_OPCODE_SNE
: return 0xd;
957 emit_flr(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
959 emit_cvt(pc
, dst
, src
, -1, CVTOP_FLOOR
, CVT_F32_F32
| CVT_RI
);
963 emit_pow(struct nv50_pc
*pc
, struct nv50_reg
*dst
,
964 struct nv50_reg
*v
, struct nv50_reg
*e
)
966 struct nv50_reg
*temp
= alloc_temp(pc
, NULL
);
968 emit_flop(pc
, 3, temp
, v
);
969 emit_mul(pc
, temp
, temp
, e
);
970 emit_preex2(pc
, temp
, temp
);
971 emit_flop(pc
, 6, dst
, temp
);
977 emit_abs(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
979 emit_cvt(pc
, dst
, src
, -1, CVTOP_ABS
, CVT_F32_F32
);
983 emit_sat(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
985 emit_cvt(pc
, dst
, src
, -1, CVTOP_SAT
, CVT_F32_F32
);
989 emit_lit(struct nv50_pc
*pc
, struct nv50_reg
**dst
, unsigned mask
,
990 struct nv50_reg
**src
)
992 struct nv50_reg
*one
= alloc_immd(pc
, 1.0);
993 struct nv50_reg
*zero
= alloc_immd(pc
, 0.0);
994 struct nv50_reg
*neg128
= alloc_immd(pc
, -127.999999);
995 struct nv50_reg
*pos128
= alloc_immd(pc
, 127.999999);
996 struct nv50_reg
*tmp
[4];
997 boolean allow32
= pc
->allow32
;
1001 if (mask
& (3 << 1)) {
1002 tmp
[0] = alloc_temp(pc
, NULL
);
1003 emit_minmax(pc
, 4, tmp
[0], src
[0], zero
);
1006 if (mask
& (1 << 2)) {
1007 set_pred_wr(pc
, 1, 0, pc
->p
->exec_tail
);
1009 tmp
[1] = temp_temp(pc
);
1010 emit_minmax(pc
, 4, tmp
[1], src
[1], zero
);
1012 tmp
[3] = temp_temp(pc
);
1013 emit_minmax(pc
, 4, tmp
[3], src
[3], neg128
);
1014 emit_minmax(pc
, 5, tmp
[3], tmp
[3], pos128
);
1016 emit_pow(pc
, dst
[2], tmp
[1], tmp
[3]);
1017 emit_mov(pc
, dst
[2], zero
);
1018 set_pred(pc
, 3, 0, pc
->p
->exec_tail
);
1021 if (mask
& (1 << 1))
1022 assimilate_temp(pc
, dst
[1], tmp
[0]);
1024 if (mask
& (1 << 2))
1025 free_temp(pc
, tmp
[0]);
1027 pc
->allow32
= allow32
;
1029 /* do this last, in case src[i,j] == dst[0,3] */
1030 if (mask
& (1 << 0))
1031 emit_mov(pc
, dst
[0], one
);
1033 if (mask
& (1 << 3))
1034 emit_mov(pc
, dst
[3], one
);
1043 emit_neg(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
1045 emit_cvt(pc
, dst
, src
, -1, CVTOP_RN
, CVT_F32_F32
| CVT_NEG
);
1049 emit_kil(struct nv50_pc
*pc
, struct nv50_reg
*src
)
1051 struct nv50_program_exec
*e
;
1052 const int r_pred
= 1;
1053 unsigned cvn
= CVT_F32_F32
;
1057 /* write predicate reg */
1058 emit_cvt(pc
, NULL
, src
, r_pred
, CVTOP_RN
, cvn
);
1060 /* conditional discard */
1062 e
->inst
[0] = 0x00000002;
1064 set_pred(pc
, 0x1 /* LT */, r_pred
, e
);
1069 emit_tex(struct nv50_pc
*pc
, struct nv50_reg
**dst
, unsigned mask
,
1070 struct nv50_reg
**src
, unsigned unit
, unsigned type
, boolean proj
)
1072 struct nv50_reg
*temp
, *t
[4];
1073 struct nv50_program_exec
*e
;
1075 unsigned c
, mode
, dim
;
1078 case TGSI_TEXTURE_1D
:
1081 case TGSI_TEXTURE_UNKNOWN
:
1082 case TGSI_TEXTURE_2D
:
1083 case TGSI_TEXTURE_SHADOW1D
: /* XXX: x, z */
1084 case TGSI_TEXTURE_RECT
:
1087 case TGSI_TEXTURE_3D
:
1088 case TGSI_TEXTURE_CUBE
:
1089 case TGSI_TEXTURE_SHADOW2D
:
1090 case TGSI_TEXTURE_SHADOWRECT
: /* XXX */
1098 /* some cards need t[0]'s hw index to be a multiple of 4 */
1099 alloc_temp4(pc
, t
, 0);
1102 if (src
[0]->type
== P_TEMP
&& src
[0]->rhw
!= -1) {
1103 mode
= pc
->interp_mode
[src
[0]->index
];
1105 t
[3]->rhw
= src
[3]->rhw
;
1106 emit_interp(pc
, t
[3], NULL
, (mode
& INTERP_CENTROID
));
1107 emit_flop(pc
, 0, t
[3], t
[3]);
1109 for (c
= 0; c
< dim
; c
++) {
1110 t
[c
]->rhw
= src
[c
]->rhw
;
1111 emit_interp(pc
, t
[c
], t
[3],
1112 (mode
| INTERP_PERSPECTIVE
));
1115 emit_flop(pc
, 0, t
[3], src
[3]);
1116 for (c
= 0; c
< dim
; c
++)
1117 emit_mul(pc
, t
[c
], src
[c
], t
[3]);
1119 /* XXX: for some reason the blob sometimes uses MAD:
1120 * emit_mad(pc, t[c], src[0][c], t[3], t[3])
1121 * pc->p->exec_tail->inst[1] |= 0x080fc000;
1125 if (type
== TGSI_TEXTURE_CUBE
) {
1126 temp
= temp_temp(pc
);
1127 emit_minmax(pc
, 4, temp
, src
[0], src
[1]);
1128 emit_minmax(pc
, 4, temp
, temp
, src
[2]);
1129 emit_flop(pc
, 0, temp
, temp
);
1130 for (c
= 0; c
< 3; c
++)
1131 emit_mul(pc
, t
[c
], src
[c
], temp
);
1133 for (c
= 0; c
< dim
; c
++)
1134 emit_mov(pc
, t
[c
], src
[c
]);
1140 e
->inst
[0] |= 0xf0000000;
1141 e
->inst
[1] |= 0x00000004;
1142 set_dst(pc
, t
[0], e
);
1143 e
->inst
[0] |= (unit
<< 9);
1146 e
->inst
[0] |= 0x00400000;
1149 e
->inst
[0] |= 0x00800000;
1151 e
->inst
[0] |= (mask
& 0x3) << 25;
1152 e
->inst
[1] |= (mask
& 0xc) << 12;
1158 if (mask
& 1) emit_mov(pc
, dst
[0], t
[c
++]);
1159 if (mask
& 2) emit_mov(pc
, dst
[1], t
[c
++]);
1160 if (mask
& 4) emit_mov(pc
, dst
[2], t
[c
++]);
1161 if (mask
& 8) emit_mov(pc
, dst
[3], t
[c
]);
1165 /* XXX: if p.e. MUL is used directly after TEX, it would still use
1166 * the texture coordinates, not the fetched values: latency ? */
1168 for (c
= 0; c
< 4; c
++) {
1169 if (mask
& (1 << c
))
1170 assimilate_temp(pc
, dst
[c
], t
[c
]);
1172 free_temp(pc
, t
[c
]);
1178 emit_branch(struct nv50_pc
*pc
, int pred
, unsigned cc
,
1179 struct nv50_program_exec
**join
)
1181 struct nv50_program_exec
*e
= exec(pc
);
1185 e
->inst
[0] |= 0xa0000002;
1192 e
->inst
[0] |= 0x10000002;
1194 set_pred(pc
, cc
, pred
, e
);
1199 emit_nop(struct nv50_pc
*pc
)
1201 struct nv50_program_exec
*e
= exec(pc
);
1203 e
->inst
[0] = 0xf0000000;
1205 e
->inst
[1] = 0xe0000000;
1210 emit_ddx(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
1212 struct nv50_program_exec
*e
= exec(pc
);
1214 assert(src
->type
== P_TEMP
);
1216 e
->inst
[0] = 0xc0140000;
1217 e
->inst
[1] = 0x89800000;
1219 set_dst(pc
, dst
, e
);
1220 set_src_0(pc
, src
, e
);
1221 set_src_2(pc
, src
, e
);
1227 emit_ddy(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
1229 struct nv50_program_exec
*e
= exec(pc
);
1231 assert(src
->type
== P_TEMP
);
1233 if (!src
->neg
) /* ! double negation */
1234 emit_neg(pc
, src
, src
);
1236 e
->inst
[0] = 0xc0150000;
1237 e
->inst
[1] = 0x8a400000;
1239 set_dst(pc
, dst
, e
);
1240 set_src_0(pc
, src
, e
);
1241 set_src_2(pc
, src
, e
);
1247 convert_to_long(struct nv50_pc
*pc
, struct nv50_program_exec
*e
)
1249 unsigned q
= 0, m
= ~0;
1251 assert(!is_long(e
));
1253 switch (e
->inst
[0] >> 28) {
1260 /* INTERP (move centroid, perspective and flat bits) */
1262 q
= (e
->inst
[0] & (3 << 24)) >> (24 - 16);
1263 q
|= (e
->inst
[0] & (1 << 8)) << (18 - 8);
1271 q
= ((e
->inst
[0] & (~m
)) >> 2);
1276 q
= ((e
->inst
[0] & (~m
)) << 12);
1279 /* MAD (if src2 == dst) */
1280 q
= ((e
->inst
[0] & 0x1fc) << 12);
1294 /* Some operations support an optional negation flag. */
1296 negate_supported(const struct tgsi_full_instruction
*insn
, int i
)
1300 switch (insn
->Instruction
.Opcode
) {
1301 case TGSI_OPCODE_DDY
:
1302 case TGSI_OPCODE_DP3
:
1303 case TGSI_OPCODE_DP4
:
1304 case TGSI_OPCODE_MUL
:
1305 case TGSI_OPCODE_KIL
:
1306 case TGSI_OPCODE_ADD
:
1307 case TGSI_OPCODE_SUB
:
1308 case TGSI_OPCODE_MAD
:
1310 case TGSI_OPCODE_POW
:
1318 /* Watch out for possible multiple uses of an nv50_reg, we
1319 * can't use nv50_reg::neg in these cases.
1321 for (s
= 0; s
< insn
->Instruction
.NumSrcRegs
; ++s
) {
1324 if ((insn
->FullSrcRegisters
[s
].SrcRegister
.Index
==
1325 insn
->FullSrcRegisters
[i
].SrcRegister
.Index
) &&
1326 (insn
->FullSrcRegisters
[s
].SrcRegister
.File
==
1327 insn
->FullSrcRegisters
[i
].SrcRegister
.File
))
1334 /* Return a read mask for source registers deduced from opcode & write mask. */
1336 nv50_tgsi_src_mask(const struct tgsi_full_instruction
*insn
, int c
)
1338 unsigned x
, mask
= insn
->FullDstRegisters
[0].DstRegister
.WriteMask
;
1340 switch (insn
->Instruction
.Opcode
) {
1341 case TGSI_OPCODE_COS
:
1342 case TGSI_OPCODE_SIN
:
1343 return (mask
& 0x8) | ((mask
& 0x7) ? 0x1 : 0x0);
1344 case TGSI_OPCODE_DP3
:
1346 case TGSI_OPCODE_DP4
:
1347 case TGSI_OPCODE_DPH
:
1348 case TGSI_OPCODE_KIL
: /* WriteMask ignored */
1350 case TGSI_OPCODE_DST
:
1351 return mask
& (c
? 0xa : 0x6);
1352 case TGSI_OPCODE_EX2
:
1353 case TGSI_OPCODE_LG2
:
1354 case TGSI_OPCODE_POW
:
1355 case TGSI_OPCODE_RCP
:
1356 case TGSI_OPCODE_RSQ
:
1357 case TGSI_OPCODE_SCS
:
1359 case TGSI_OPCODE_LIT
:
1361 case TGSI_OPCODE_TEX
:
1362 case TGSI_OPCODE_TXP
:
1364 const struct tgsi_instruction_ext_texture
*tex
;
1366 assert(insn
->Instruction
.Extended
);
1367 tex
= &insn
->InstructionExtTexture
;
1370 if (insn
->Instruction
.Opcode
== TGSI_OPCODE_TXP
)
1373 switch (tex
->Texture
) {
1374 case TGSI_TEXTURE_1D
:
1377 case TGSI_TEXTURE_2D
:
1385 case TGSI_OPCODE_XPD
:
1387 if (mask
& 1) x
|= 0x6;
1388 if (mask
& 2) x
|= 0x5;
1389 if (mask
& 4) x
|= 0x3;
1398 static struct nv50_reg
*
1399 tgsi_dst(struct nv50_pc
*pc
, int c
, const struct tgsi_full_dst_register
*dst
)
1401 switch (dst
->DstRegister
.File
) {
1402 case TGSI_FILE_TEMPORARY
:
1403 return &pc
->temp
[dst
->DstRegister
.Index
* 4 + c
];
1404 case TGSI_FILE_OUTPUT
:
1405 return &pc
->result
[dst
->DstRegister
.Index
* 4 + c
];
1406 case TGSI_FILE_NULL
:
1415 static struct nv50_reg
*
1416 tgsi_src(struct nv50_pc
*pc
, int chan
, const struct tgsi_full_src_register
*src
,
1419 struct nv50_reg
*r
= NULL
;
1420 struct nv50_reg
*temp
;
1423 sgn
= tgsi_util_get_full_src_register_sign_mode(src
, chan
);
1425 c
= tgsi_util_get_full_src_register_extswizzle(src
, chan
);
1427 case TGSI_EXTSWIZZLE_X
:
1428 case TGSI_EXTSWIZZLE_Y
:
1429 case TGSI_EXTSWIZZLE_Z
:
1430 case TGSI_EXTSWIZZLE_W
:
1431 switch (src
->SrcRegister
.File
) {
1432 case TGSI_FILE_INPUT
:
1433 r
= &pc
->attr
[src
->SrcRegister
.Index
* 4 + c
];
1435 case TGSI_FILE_TEMPORARY
:
1436 r
= &pc
->temp
[src
->SrcRegister
.Index
* 4 + c
];
1438 case TGSI_FILE_CONSTANT
:
1439 r
= &pc
->param
[src
->SrcRegister
.Index
* 4 + c
];
1441 case TGSI_FILE_IMMEDIATE
:
1442 r
= &pc
->immd
[src
->SrcRegister
.Index
* 4 + c
];
1444 case TGSI_FILE_SAMPLER
:
1451 case TGSI_EXTSWIZZLE_ZERO
:
1452 r
= alloc_immd(pc
, 0.0);
1454 case TGSI_EXTSWIZZLE_ONE
:
1455 if (sgn
== TGSI_UTIL_SIGN_TOGGLE
|| sgn
== TGSI_UTIL_SIGN_SET
)
1456 return alloc_immd(pc
, -1.0);
1457 return alloc_immd(pc
, 1.0);
1464 case TGSI_UTIL_SIGN_KEEP
:
1466 case TGSI_UTIL_SIGN_CLEAR
:
1467 temp
= temp_temp(pc
);
1468 emit_abs(pc
, temp
, r
);
1471 case TGSI_UTIL_SIGN_TOGGLE
:
1475 temp
= temp_temp(pc
);
1476 emit_neg(pc
, temp
, r
);
1480 case TGSI_UTIL_SIGN_SET
:
1481 temp
= temp_temp(pc
);
1482 emit_abs(pc
, temp
, r
);
1486 emit_neg(pc
, temp
, temp
);
1497 /* return TRUE for ops that produce only a single result */
1499 is_scalar_op(unsigned op
)
1502 case TGSI_OPCODE_COS
:
1503 case TGSI_OPCODE_DP2
:
1504 case TGSI_OPCODE_DP3
:
1505 case TGSI_OPCODE_DP4
:
1506 case TGSI_OPCODE_DPH
:
1507 case TGSI_OPCODE_EX2
:
1508 case TGSI_OPCODE_LG2
:
1509 case TGSI_OPCODE_POW
:
1510 case TGSI_OPCODE_RCP
:
1511 case TGSI_OPCODE_RSQ
:
1512 case TGSI_OPCODE_SIN
:
1514 case TGSI_OPCODE_KIL:
1515 case TGSI_OPCODE_LIT:
1516 case TGSI_OPCODE_SCS:
1524 /* Returns a bitmask indicating which dst components depend
1525 * on source s, component c (reverse of nv50_tgsi_src_mask).
1528 nv50_tgsi_dst_revdep(unsigned op
, int s
, int c
)
1530 if (is_scalar_op(op
))
1534 case TGSI_OPCODE_DST
:
1535 return (1 << c
) & (s
? 0xa : 0x6);
1536 case TGSI_OPCODE_XPD
:
1546 case TGSI_OPCODE_LIT
:
1547 case TGSI_OPCODE_SCS
:
1548 case TGSI_OPCODE_TEX
:
1549 case TGSI_OPCODE_TXP
:
1550 /* these take care of dangerous swizzles themselves */
1552 case TGSI_OPCODE_IF
:
1553 case TGSI_OPCODE_KIL
:
1554 /* don't call this function for these ops */
1558 /* linear vector instruction */
1563 static INLINE boolean
1564 has_pred(struct nv50_program_exec
*e
, unsigned cc
)
1566 if (!is_long(e
) || is_immd(e
))
1568 return ((e
->inst
[1] & 0x780) == (cc
<< 7));
1571 /* on ENDIF see if we can do "@p0.neu single_op" instead of:
1578 nv50_kill_branch(struct nv50_pc
*pc
)
1580 int lvl
= pc
->if_lvl
;
1582 if (pc
->if_insn
[lvl
]->next
!= pc
->p
->exec_tail
)
1585 /* if ccode == 'true', the BRA is from an ELSE and the predicate
1586 * reg may no longer be valid, since we currently always use $p0
1588 if (has_pred(pc
->if_insn
[lvl
], 0xf))
1590 assert(pc
->if_insn
[lvl
] && pc
->br_join
[lvl
]);
1592 /* We'll use the exec allocated for JOIN_AT (as we can't easily
1593 * update prev's next); if exec_tail is BRK, update the pointer.
1595 if (pc
->loop_lvl
&& pc
->br_loop
[pc
->loop_lvl
- 1] == pc
->p
->exec_tail
)
1596 pc
->br_loop
[pc
->loop_lvl
- 1] = pc
->br_join
[lvl
];
1598 pc
->p
->exec_size
-= 4; /* remove JOIN_AT and BRA */
1600 *pc
->br_join
[lvl
] = *pc
->p
->exec_tail
;
1602 FREE(pc
->if_insn
[lvl
]);
1603 FREE(pc
->p
->exec_tail
);
1605 pc
->p
->exec_tail
= pc
->br_join
[lvl
];
1606 pc
->p
->exec_tail
->next
= NULL
;
1607 set_pred(pc
, 0xd, 0, pc
->p
->exec_tail
);
1613 nv50_program_tx_insn(struct nv50_pc
*pc
,
1614 const struct tgsi_full_instruction
*inst
)
1616 struct nv50_reg
*rdst
[4], *dst
[4], *brdc
, *src
[3][4], *temp
;
1617 unsigned mask
, sat
, unit
;
1620 mask
= inst
->FullDstRegisters
[0].DstRegister
.WriteMask
;
1621 sat
= inst
->Instruction
.Saturate
== TGSI_SAT_ZERO_ONE
;
1623 memset(src
, 0, sizeof(src
));
1625 for (c
= 0; c
< 4; c
++) {
1626 if ((mask
& (1 << c
)) && !pc
->r_dst
[c
])
1627 dst
[c
] = tgsi_dst(pc
, c
, &inst
->FullDstRegisters
[0]);
1629 dst
[c
] = pc
->r_dst
[c
];
1633 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1634 const struct tgsi_full_src_register
*fs
= &inst
->FullSrcRegisters
[i
];
1638 src_mask
= nv50_tgsi_src_mask(inst
, i
);
1639 neg_supp
= negate_supported(inst
, i
);
1641 if (fs
->SrcRegister
.File
== TGSI_FILE_SAMPLER
)
1642 unit
= fs
->SrcRegister
.Index
;
1644 for (c
= 0; c
< 4; c
++)
1645 if (src_mask
& (1 << c
))
1646 src
[i
][c
] = tgsi_src(pc
, c
, fs
, neg_supp
);
1649 brdc
= temp
= pc
->r_brdc
;
1650 if (brdc
&& brdc
->type
!= P_TEMP
) {
1651 temp
= temp_temp(pc
);
1656 for (c
= 0; c
< 4; c
++) {
1657 if (!(mask
& (1 << c
)) || dst
[c
]->type
== P_TEMP
)
1660 dst
[c
] = temp_temp(pc
);
1664 assert(brdc
|| !is_scalar_op(inst
->Instruction
.Opcode
));
1666 switch (inst
->Instruction
.Opcode
) {
1667 case TGSI_OPCODE_ABS
:
1668 for (c
= 0; c
< 4; c
++) {
1669 if (!(mask
& (1 << c
)))
1671 emit_abs(pc
, dst
[c
], src
[0][c
]);
1674 case TGSI_OPCODE_ADD
:
1675 for (c
= 0; c
< 4; c
++) {
1676 if (!(mask
& (1 << c
)))
1678 emit_add(pc
, dst
[c
], src
[0][c
], src
[1][c
]);
1681 case TGSI_OPCODE_BGNLOOP
:
1682 pc
->loop_pos
[pc
->loop_lvl
++] = pc
->p
->exec_size
;
1684 case TGSI_OPCODE_BRK
:
1685 emit_branch(pc
, -1, 0, NULL
);
1686 assert(pc
->loop_lvl
> 0);
1687 pc
->br_loop
[pc
->loop_lvl
- 1] = pc
->p
->exec_tail
;
1689 case TGSI_OPCODE_CEIL
:
1690 for (c
= 0; c
< 4; c
++) {
1691 if (!(mask
& (1 << c
)))
1693 emit_cvt(pc
, dst
[c
], src
[0][c
], -1,
1694 CVTOP_CEIL
, CVT_F32_F32
| CVT_RI
);
1697 case TGSI_OPCODE_CMP
:
1698 pc
->allow32
= FALSE
;
1699 for (c
= 0; c
< 4; c
++) {
1700 if (!(mask
& (1 << c
)))
1702 emit_cvt(pc
, NULL
, src
[0][c
], 1, CVTOP_RN
, CVT_F32_F32
);
1703 emit_mov(pc
, dst
[c
], src
[1][c
]);
1704 set_pred(pc
, 0x1, 1, pc
->p
->exec_tail
); /* @SF */
1705 emit_mov(pc
, dst
[c
], src
[2][c
]);
1706 set_pred(pc
, 0x6, 1, pc
->p
->exec_tail
); /* @NSF */
1709 case TGSI_OPCODE_COS
:
1711 emit_precossin(pc
, temp
, src
[0][3]);
1712 emit_flop(pc
, 5, dst
[3], temp
);
1716 temp
= brdc
= temp_temp(pc
);
1718 emit_precossin(pc
, temp
, src
[0][0]);
1719 emit_flop(pc
, 5, brdc
, temp
);
1721 case TGSI_OPCODE_DDX
:
1722 for (c
= 0; c
< 4; c
++) {
1723 if (!(mask
& (1 << c
)))
1725 emit_ddx(pc
, dst
[c
], src
[0][c
]);
1728 case TGSI_OPCODE_DDY
:
1729 for (c
= 0; c
< 4; c
++) {
1730 if (!(mask
& (1 << c
)))
1732 emit_ddy(pc
, dst
[c
], src
[0][c
]);
1735 case TGSI_OPCODE_DP3
:
1736 emit_mul(pc
, temp
, src
[0][0], src
[1][0]);
1737 emit_mad(pc
, temp
, src
[0][1], src
[1][1], temp
);
1738 emit_mad(pc
, brdc
, src
[0][2], src
[1][2], temp
);
1740 case TGSI_OPCODE_DP4
:
1741 emit_mul(pc
, temp
, src
[0][0], src
[1][0]);
1742 emit_mad(pc
, temp
, src
[0][1], src
[1][1], temp
);
1743 emit_mad(pc
, temp
, src
[0][2], src
[1][2], temp
);
1744 emit_mad(pc
, brdc
, src
[0][3], src
[1][3], temp
);
1746 case TGSI_OPCODE_DPH
:
1747 emit_mul(pc
, temp
, src
[0][0], src
[1][0]);
1748 emit_mad(pc
, temp
, src
[0][1], src
[1][1], temp
);
1749 emit_mad(pc
, temp
, src
[0][2], src
[1][2], temp
);
1750 emit_add(pc
, brdc
, src
[1][3], temp
);
1752 case TGSI_OPCODE_DST
:
1753 if (mask
& (1 << 1))
1754 emit_mul(pc
, dst
[1], src
[0][1], src
[1][1]);
1755 if (mask
& (1 << 2))
1756 emit_mov(pc
, dst
[2], src
[0][2]);
1757 if (mask
& (1 << 3))
1758 emit_mov(pc
, dst
[3], src
[1][3]);
1759 if (mask
& (1 << 0))
1760 emit_mov_immdval(pc
, dst
[0], 1.0f
);
1762 case TGSI_OPCODE_ELSE
:
1763 emit_branch(pc
, -1, 0, NULL
);
1764 pc
->if_insn
[--pc
->if_lvl
]->param
.index
= pc
->p
->exec_size
;
1765 pc
->if_insn
[pc
->if_lvl
++] = pc
->p
->exec_tail
;
1767 case TGSI_OPCODE_ENDIF
:
1768 pc
->if_insn
[--pc
->if_lvl
]->param
.index
= pc
->p
->exec_size
;
1770 /* try to replace branch over 1 insn with a predicated insn */
1771 if (nv50_kill_branch(pc
) == TRUE
)
1774 if (pc
->br_join
[pc
->if_lvl
]) {
1775 pc
->br_join
[pc
->if_lvl
]->param
.index
= pc
->p
->exec_size
;
1776 pc
->br_join
[pc
->if_lvl
] = NULL
;
1778 /* emit a NOP as join point, we could set it on the next
1779 * one, but would have to make sure it is long and !immd
1782 pc
->p
->exec_tail
->inst
[1] |= 2;
1784 case TGSI_OPCODE_ENDLOOP
:
1785 emit_branch(pc
, -1, 0, NULL
);
1786 pc
->p
->exec_tail
->param
.index
= pc
->loop_pos
[--pc
->loop_lvl
];
1787 pc
->br_loop
[pc
->loop_lvl
]->param
.index
= pc
->p
->exec_size
;
1789 case TGSI_OPCODE_EX2
:
1790 emit_preex2(pc
, temp
, src
[0][0]);
1791 emit_flop(pc
, 6, brdc
, temp
);
1793 case TGSI_OPCODE_FLR
:
1794 for (c
= 0; c
< 4; c
++) {
1795 if (!(mask
& (1 << c
)))
1797 emit_flr(pc
, dst
[c
], src
[0][c
]);
1800 case TGSI_OPCODE_FRC
:
1801 temp
= temp_temp(pc
);
1802 for (c
= 0; c
< 4; c
++) {
1803 if (!(mask
& (1 << c
)))
1805 emit_flr(pc
, temp
, src
[0][c
]);
1806 emit_sub(pc
, dst
[c
], src
[0][c
], temp
);
1809 case TGSI_OPCODE_IF
:
1810 /* emitting a join_at may not be necessary */
1811 assert(pc
->if_lvl
< MAX_IF_DEPTH
);
1812 set_pred_wr(pc
, 1, 0, pc
->if_cond
);
1813 emit_branch(pc
, 0, 2, &pc
->br_join
[pc
->if_lvl
]);
1814 pc
->if_insn
[pc
->if_lvl
++] = pc
->p
->exec_tail
;
1816 case TGSI_OPCODE_KIL
:
1817 emit_kil(pc
, src
[0][0]);
1818 emit_kil(pc
, src
[0][1]);
1819 emit_kil(pc
, src
[0][2]);
1820 emit_kil(pc
, src
[0][3]);
1822 case TGSI_OPCODE_LIT
:
1823 emit_lit(pc
, &dst
[0], mask
, &src
[0][0]);
1825 case TGSI_OPCODE_LG2
:
1826 emit_flop(pc
, 3, brdc
, src
[0][0]);
1828 case TGSI_OPCODE_LRP
:
1829 temp
= temp_temp(pc
);
1830 for (c
= 0; c
< 4; c
++) {
1831 if (!(mask
& (1 << c
)))
1833 emit_sub(pc
, temp
, src
[1][c
], src
[2][c
]);
1834 emit_mad(pc
, dst
[c
], temp
, src
[0][c
], src
[2][c
]);
1837 case TGSI_OPCODE_MAD
:
1838 for (c
= 0; c
< 4; c
++) {
1839 if (!(mask
& (1 << c
)))
1841 emit_mad(pc
, dst
[c
], src
[0][c
], src
[1][c
], src
[2][c
]);
1844 case TGSI_OPCODE_MAX
:
1845 for (c
= 0; c
< 4; c
++) {
1846 if (!(mask
& (1 << c
)))
1848 emit_minmax(pc
, 4, dst
[c
], src
[0][c
], src
[1][c
]);
1851 case TGSI_OPCODE_MIN
:
1852 for (c
= 0; c
< 4; c
++) {
1853 if (!(mask
& (1 << c
)))
1855 emit_minmax(pc
, 5, dst
[c
], src
[0][c
], src
[1][c
]);
1858 case TGSI_OPCODE_MOV
:
1859 case TGSI_OPCODE_SWZ
:
1860 for (c
= 0; c
< 4; c
++) {
1861 if (!(mask
& (1 << c
)))
1863 emit_mov(pc
, dst
[c
], src
[0][c
]);
1866 case TGSI_OPCODE_MUL
:
1867 for (c
= 0; c
< 4; c
++) {
1868 if (!(mask
& (1 << c
)))
1870 emit_mul(pc
, dst
[c
], src
[0][c
], src
[1][c
]);
1873 case TGSI_OPCODE_POW
:
1874 emit_pow(pc
, brdc
, src
[0][0], src
[1][0]);
1876 case TGSI_OPCODE_RCP
:
1877 emit_flop(pc
, 0, brdc
, src
[0][0]);
1879 case TGSI_OPCODE_RSQ
:
1880 emit_flop(pc
, 2, brdc
, src
[0][0]);
1882 case TGSI_OPCODE_SCS
:
1883 temp
= temp_temp(pc
);
1885 emit_precossin(pc
, temp
, src
[0][0]);
1886 if (mask
& (1 << 0))
1887 emit_flop(pc
, 5, dst
[0], temp
);
1888 if (mask
& (1 << 1))
1889 emit_flop(pc
, 4, dst
[1], temp
);
1890 if (mask
& (1 << 2))
1891 emit_mov_immdval(pc
, dst
[2], 0.0);
1892 if (mask
& (1 << 3))
1893 emit_mov_immdval(pc
, dst
[3], 1.0);
1895 case TGSI_OPCODE_SIN
:
1897 emit_precossin(pc
, temp
, src
[0][3]);
1898 emit_flop(pc
, 4, dst
[3], temp
);
1902 temp
= brdc
= temp_temp(pc
);
1904 emit_precossin(pc
, temp
, src
[0][0]);
1905 emit_flop(pc
, 4, brdc
, temp
);
1907 case TGSI_OPCODE_SLT
:
1908 case TGSI_OPCODE_SGE
:
1909 case TGSI_OPCODE_SEQ
:
1910 case TGSI_OPCODE_SGT
:
1911 case TGSI_OPCODE_SLE
:
1912 case TGSI_OPCODE_SNE
:
1913 i
= map_tgsi_setop_cc(inst
->Instruction
.Opcode
);
1914 for (c
= 0; c
< 4; c
++) {
1915 if (!(mask
& (1 << c
)))
1917 emit_set(pc
, i
, dst
[c
], -1, src
[0][c
], src
[1][c
]);
1920 case TGSI_OPCODE_SUB
:
1921 for (c
= 0; c
< 4; c
++) {
1922 if (!(mask
& (1 << c
)))
1924 emit_sub(pc
, dst
[c
], src
[0][c
], src
[1][c
]);
1927 case TGSI_OPCODE_TEX
:
1928 emit_tex(pc
, dst
, mask
, src
[0], unit
,
1929 inst
->InstructionExtTexture
.Texture
, FALSE
);
1931 case TGSI_OPCODE_TXP
:
1932 emit_tex(pc
, dst
, mask
, src
[0], unit
,
1933 inst
->InstructionExtTexture
.Texture
, TRUE
);
1935 case TGSI_OPCODE_TRUNC
:
1936 for (c
= 0; c
< 4; c
++) {
1937 if (!(mask
& (1 << c
)))
1939 emit_cvt(pc
, dst
[c
], src
[0][c
], -1,
1940 CVTOP_TRUNC
, CVT_F32_F32
| CVT_RI
);
1943 case TGSI_OPCODE_XPD
:
1944 temp
= temp_temp(pc
);
1945 if (mask
& (1 << 0)) {
1946 emit_mul(pc
, temp
, src
[0][2], src
[1][1]);
1947 emit_msb(pc
, dst
[0], src
[0][1], src
[1][2], temp
);
1949 if (mask
& (1 << 1)) {
1950 emit_mul(pc
, temp
, src
[0][0], src
[1][2]);
1951 emit_msb(pc
, dst
[1], src
[0][2], src
[1][0], temp
);
1953 if (mask
& (1 << 2)) {
1954 emit_mul(pc
, temp
, src
[0][1], src
[1][0]);
1955 emit_msb(pc
, dst
[2], src
[0][0], src
[1][1], temp
);
1957 if (mask
& (1 << 3))
1958 emit_mov_immdval(pc
, dst
[3], 1.0);
1960 case TGSI_OPCODE_END
:
1963 NOUVEAU_ERR("invalid opcode %d\n", inst
->Instruction
.Opcode
);
1969 emit_sat(pc
, brdc
, brdc
);
1970 for (c
= 0; c
< 4; c
++)
1971 if ((mask
& (1 << c
)) && dst
[c
] != brdc
)
1972 emit_mov(pc
, dst
[c
], brdc
);
1975 for (c
= 0; c
< 4; c
++) {
1976 if (!(mask
& (1 << c
)))
1978 /* in this case we saturate later */
1979 if (dst
[c
]->type
== P_TEMP
&& dst
[c
]->index
< 0)
1981 emit_sat(pc
, rdst
[c
], dst
[c
]);
1985 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1986 for (c
= 0; c
< 4; c
++) {
1990 if (src
[i
][c
]->index
== -1 && src
[i
][c
]->type
== P_IMMD
)
2000 prep_inspect_insn(struct nv50_pc
*pc
, const struct tgsi_full_instruction
*insn
)
2002 struct nv50_reg
*reg
= NULL
;
2003 const struct tgsi_full_src_register
*src
;
2004 const struct tgsi_dst_register
*dst
;
2005 unsigned i
, c
, k
, mask
;
2007 dst
= &insn
->FullDstRegisters
[0].DstRegister
;
2008 mask
= dst
->WriteMask
;
2010 if (dst
->File
== TGSI_FILE_TEMPORARY
)
2013 if (dst
->File
== TGSI_FILE_OUTPUT
)
2017 for (c
= 0; c
< 4; c
++) {
2018 if (!(mask
& (1 << c
)))
2020 reg
[dst
->Index
* 4 + c
].acc
= pc
->insn_nr
;
2024 for (i
= 0; i
< insn
->Instruction
.NumSrcRegs
; i
++) {
2025 src
= &insn
->FullSrcRegisters
[i
];
2027 if (src
->SrcRegister
.File
== TGSI_FILE_TEMPORARY
)
2030 if (src
->SrcRegister
.File
== TGSI_FILE_INPUT
)
2035 mask
= nv50_tgsi_src_mask(insn
, i
);
2037 for (c
= 0; c
< 4; c
++) {
2038 if (!(mask
& (1 << c
)))
2040 k
= tgsi_util_get_full_src_register_extswizzle(src
, c
);
2042 if (k
> TGSI_EXTSWIZZLE_W
)
2045 reg
[src
->SrcRegister
.Index
* 4 + k
].acc
= pc
->insn_nr
;
2050 /* Returns a bitmask indicating which dst components need to be
2051 * written to temporaries first to avoid 'corrupting' sources.
2053 * m[i] (out) indicate component to write in the i-th position
2054 * rdep[c] (in) bitmasks of dst[i] that require dst[c] as source
2057 nv50_revdep_reorder(unsigned m
[4], unsigned rdep
[4])
2059 unsigned i
, c
, x
, unsafe
;
2061 for (c
= 0; c
< 4; c
++)
2064 /* Swap as long as a dst component written earlier is depended on
2065 * by one written later, but the next one isn't depended on by it.
2067 for (c
= 0; c
< 3; c
++) {
2068 if (rdep
[m
[c
+ 1]] & (1 << m
[c
]))
2069 continue; /* if next one is depended on by us */
2070 for (i
= c
+ 1; i
< 4; i
++)
2071 /* if we are depended on by a later one */
2072 if (rdep
[m
[c
]] & (1 << m
[i
]))
2085 /* mark dependencies that could not be resolved by reordering */
2086 for (i
= 0; i
< 3; ++i
)
2087 for (c
= i
+ 1; c
< 4; ++c
)
2088 if (rdep
[m
[i
]] & (1 << m
[c
]))
2091 /* NOTE: $unsafe is with respect to order, not component */
2095 /* Select a suitable dst register for broadcasting scalar results,
2096 * or return NULL if we have to allocate an extra TEMP.
2098 * If e.g. only 1 component is written, we may also emit the final
2099 * result to a write-only register.
2101 static struct nv50_reg
*
2102 tgsi_broadcast_dst(struct nv50_pc
*pc
,
2103 const struct tgsi_full_dst_register
*fd
, unsigned mask
)
2105 if (fd
->DstRegister
.File
== TGSI_FILE_TEMPORARY
) {
2106 int c
= ffs(~mask
& fd
->DstRegister
.WriteMask
);
2108 return tgsi_dst(pc
, c
- 1, fd
);
2110 int c
= ffs(fd
->DstRegister
.WriteMask
) - 1;
2111 if ((1 << c
) == fd
->DstRegister
.WriteMask
)
2112 return tgsi_dst(pc
, c
, fd
);
2118 /* Scan source swizzles and return a bitmask indicating dst regs that
2119 * also occur among the src regs, and fill rdep for nv50_revdep_reoder.
2122 nv50_tgsi_scan_swizzle(const struct tgsi_full_instruction
*insn
,
2125 const struct tgsi_full_dst_register
*fd
= &insn
->FullDstRegisters
[0];
2126 const struct tgsi_full_src_register
*fs
;
2127 unsigned i
, deqs
= 0;
2129 for (i
= 0; i
< 4; ++i
)
2132 for (i
= 0; i
< insn
->Instruction
.NumSrcRegs
; i
++) {
2133 unsigned chn
, mask
= nv50_tgsi_src_mask(insn
, i
);
2134 boolean neg_supp
= negate_supported(insn
, i
);
2136 fs
= &insn
->FullSrcRegisters
[i
];
2137 if (fs
->SrcRegister
.File
!= fd
->DstRegister
.File
||
2138 fs
->SrcRegister
.Index
!= fd
->DstRegister
.Index
)
2141 for (chn
= 0; chn
< 4; ++chn
) {
2144 if (!(mask
& (1 << chn
))) /* src is not read */
2146 c
= tgsi_util_get_full_src_register_extswizzle(fs
, chn
);
2147 s
= tgsi_util_get_full_src_register_sign_mode(fs
, chn
);
2149 if (c
> TGSI_EXTSWIZZLE_W
||
2150 !(fd
->DstRegister
.WriteMask
& (1 << c
)))
2153 /* no danger if src is copied to TEMP first */
2154 if ((s
!= TGSI_UTIL_SIGN_KEEP
) &&
2155 (s
!= TGSI_UTIL_SIGN_TOGGLE
|| !neg_supp
))
2158 rdep
[c
] |= nv50_tgsi_dst_revdep(
2159 insn
->Instruction
.Opcode
, i
, chn
);
2168 nv50_tgsi_insn(struct nv50_pc
*pc
, const union tgsi_full_token
*tok
)
2170 struct tgsi_full_instruction insn
= tok
->FullInstruction
;
2171 const struct tgsi_full_dst_register
*fd
;
2172 unsigned i
, deqs
, rdep
[4], m
[4];
2174 fd
= &tok
->FullInstruction
.FullDstRegisters
[0];
2175 deqs
= nv50_tgsi_scan_swizzle(&insn
, rdep
);
2177 if (is_scalar_op(insn
.Instruction
.Opcode
)) {
2178 pc
->r_brdc
= tgsi_broadcast_dst(pc
, fd
, deqs
);
2180 pc
->r_brdc
= temp_temp(pc
);
2181 return nv50_program_tx_insn(pc
, &insn
);
2186 return nv50_program_tx_insn(pc
, &insn
);
2188 deqs
= nv50_revdep_reorder(m
, rdep
);
2190 for (i
= 0; i
< 4; ++i
) {
2191 assert(pc
->r_dst
[m
[i
]] == NULL
);
2193 insn
.FullDstRegisters
[0].DstRegister
.WriteMask
=
2194 fd
->DstRegister
.WriteMask
& (1 << m
[i
]);
2196 if (!insn
.FullDstRegisters
[0].DstRegister
.WriteMask
)
2199 if (deqs
& (1 << i
))
2200 pc
->r_dst
[m
[i
]] = alloc_temp(pc
, NULL
);
2202 if (!nv50_program_tx_insn(pc
, &insn
))
2206 for (i
= 0; i
< 4; i
++) {
2207 struct nv50_reg
*reg
= pc
->r_dst
[i
];
2210 pc
->r_dst
[i
] = NULL
;
2212 if (insn
.Instruction
.Saturate
== TGSI_SAT_ZERO_ONE
)
2213 emit_sat(pc
, tgsi_dst(pc
, i
, fd
), reg
);
2215 emit_mov(pc
, tgsi_dst(pc
, i
, fd
), reg
);
2223 load_interpolant(struct nv50_pc
*pc
, struct nv50_reg
*reg
)
2225 struct nv50_reg
*iv
, **ppiv
;
2226 unsigned mode
= pc
->interp_mode
[reg
->index
];
2228 ppiv
= (mode
& INTERP_CENTROID
) ? &pc
->iv_c
: &pc
->iv_p
;
2231 if ((mode
& INTERP_PERSPECTIVE
) && !iv
) {
2232 iv
= *ppiv
= alloc_temp(pc
, NULL
);
2233 iv
->rhw
= popcnt4(pc
->p
->cfg
.regs
[1] >> 24) - 1;
2235 emit_interp(pc
, iv
, NULL
, mode
& INTERP_CENTROID
);
2236 emit_flop(pc
, 0, iv
, iv
);
2238 /* XXX: when loading interpolants dynamically, move these
2239 * to the program head, or make sure it can't be skipped.
2243 emit_interp(pc
, reg
, iv
, mode
);
2247 nv50_program_tx_prep(struct nv50_pc
*pc
)
2249 struct tgsi_parse_context tp
;
2250 struct nv50_program
*p
= pc
->p
;
2251 boolean ret
= FALSE
;
2252 unsigned i
, c
, flat_nr
= 0;
2254 tgsi_parse_init(&tp
, pc
->p
->pipe
.tokens
);
2255 while (!tgsi_parse_end_of_tokens(&tp
)) {
2256 const union tgsi_full_token
*tok
= &tp
.FullToken
;
2258 tgsi_parse_token(&tp
);
2259 switch (tok
->Token
.Type
) {
2260 case TGSI_TOKEN_TYPE_IMMEDIATE
:
2262 const struct tgsi_full_immediate
*imm
=
2263 &tp
.FullToken
.FullImmediate
;
2265 ctor_immd(pc
, imm
->u
[0].Float
,
2271 case TGSI_TOKEN_TYPE_DECLARATION
:
2273 const struct tgsi_full_declaration
*d
;
2274 unsigned si
, last
, first
, mode
;
2276 d
= &tp
.FullToken
.FullDeclaration
;
2277 first
= d
->DeclarationRange
.First
;
2278 last
= d
->DeclarationRange
.Last
;
2280 switch (d
->Declaration
.File
) {
2281 case TGSI_FILE_TEMPORARY
:
2283 case TGSI_FILE_OUTPUT
:
2284 if (!d
->Declaration
.Semantic
||
2285 p
->type
== PIPE_SHADER_FRAGMENT
)
2288 si
= d
->Semantic
.SemanticIndex
;
2289 switch (d
->Semantic
.SemanticName
) {
2290 case TGSI_SEMANTIC_BCOLOR
:
2291 p
->cfg
.two_side
[si
].hw
= first
;
2292 if (p
->cfg
.io_nr
> first
)
2293 p
->cfg
.io_nr
= first
;
2295 case TGSI_SEMANTIC_PSIZE
:
2296 p
->cfg
.psiz
= first
;
2297 if (p
->cfg
.io_nr
> first
)
2298 p
->cfg
.io_nr
= first
;
2301 case TGSI_SEMANTIC_CLIP_DISTANCE:
2302 p->cfg.clpd = MIN2(p->cfg.clpd, first);
2309 case TGSI_FILE_INPUT
:
2311 if (p
->type
!= PIPE_SHADER_FRAGMENT
)
2314 switch (d
->Declaration
.Interpolate
) {
2315 case TGSI_INTERPOLATE_CONSTANT
:
2319 case TGSI_INTERPOLATE_PERSPECTIVE
:
2320 mode
= INTERP_PERSPECTIVE
;
2321 p
->cfg
.regs
[1] |= 0x08 << 24;
2324 mode
= INTERP_LINEAR
;
2327 if (d
->Declaration
.Centroid
)
2328 mode
|= INTERP_CENTROID
;
2331 for (i
= first
; i
<= last
; i
++)
2332 pc
->interp_mode
[i
] = mode
;
2335 case TGSI_FILE_CONSTANT
:
2337 case TGSI_FILE_SAMPLER
:
2340 NOUVEAU_ERR("bad decl file %d\n",
2341 d
->Declaration
.File
);
2346 case TGSI_TOKEN_TYPE_INSTRUCTION
:
2348 prep_inspect_insn(pc
, &tok
->FullInstruction
);
2355 if (p
->type
== PIPE_SHADER_VERTEX
) {
2358 for (i
= 0; i
< pc
->attr_nr
* 4; ++i
) {
2359 if (pc
->attr
[i
].acc
) {
2360 pc
->attr
[i
].hw
= rid
++;
2361 p
->cfg
.attr
[i
/ 32] |= 1 << (i
% 32);
2365 for (i
= 0, rid
= 0; i
< pc
->result_nr
; ++i
) {
2366 p
->cfg
.io
[i
].hw
= rid
;
2367 p
->cfg
.io
[i
].id_vp
= i
;
2369 for (c
= 0; c
< 4; ++c
) {
2371 if (!pc
->result
[n
].acc
)
2373 pc
->result
[n
].hw
= rid
++;
2374 p
->cfg
.io
[i
].mask
|= 1 << c
;
2378 for (c
= 0; c
< 2; ++c
)
2379 if (p
->cfg
.two_side
[c
].hw
< 0x40)
2380 p
->cfg
.two_side
[c
] = p
->cfg
.io
[
2381 p
->cfg
.two_side
[c
].hw
];
2383 if (p
->cfg
.psiz
< 0x40)
2384 p
->cfg
.psiz
= p
->cfg
.io
[p
->cfg
.psiz
].hw
;
2386 if (p
->type
== PIPE_SHADER_FRAGMENT
) {
2388 unsigned n
= 0, m
= pc
->attr_nr
- flat_nr
;
2390 int base
= (TGSI_SEMANTIC_POSITION
==
2391 p
->info
.input_semantic_name
[0]) ? 0 : 1;
2393 /* non-flat interpolants have to be mapped to
2394 * the lower hardware IDs, so sort them:
2396 for (i
= 0; i
< pc
->attr_nr
; i
++) {
2397 if (pc
->interp_mode
[i
] == INTERP_FLAT
) {
2398 p
->cfg
.io
[m
].id_vp
= i
+ base
;
2399 p
->cfg
.io
[m
++].id_fp
= i
;
2401 if (!(pc
->interp_mode
[i
] & INTERP_PERSPECTIVE
))
2402 p
->cfg
.io
[n
].linear
= TRUE
;
2403 p
->cfg
.io
[n
].id_vp
= i
+ base
;
2404 p
->cfg
.io
[n
++].id_fp
= i
;
2408 if (!base
) /* set w-coordinate mask from perspective interp */
2409 p
->cfg
.io
[0].mask
|= p
->cfg
.regs
[1] >> 24;
2411 aid
= popcnt4( /* if fcrd isn't contained in cfg.io */
2412 base
? (p
->cfg
.regs
[1] >> 24) : p
->cfg
.io
[0].mask
);
2414 for (n
= 0; n
< pc
->attr_nr
; ++n
) {
2415 p
->cfg
.io
[n
].hw
= rid
= aid
;
2416 i
= p
->cfg
.io
[n
].id_fp
;
2418 for (c
= 0; c
< 4; ++c
) {
2419 if (!pc
->attr
[i
* 4 + c
].acc
)
2421 pc
->attr
[i
* 4 + c
].rhw
= rid
++;
2422 p
->cfg
.io
[n
].mask
|= 1 << c
;
2424 load_interpolant(pc
, &pc
->attr
[i
* 4 + c
]);
2426 aid
+= popcnt4(p
->cfg
.io
[n
].mask
);
2430 p
->cfg
.regs
[1] |= p
->cfg
.io
[0].mask
<< 24;
2432 m
= popcnt4(p
->cfg
.regs
[1] >> 24);
2434 /* set count of non-position inputs and of non-flat
2435 * non-position inputs for FP_INTERPOLANT_CTRL
2437 p
->cfg
.regs
[1] |= aid
- m
;
2440 i
= p
->cfg
.io
[pc
->attr_nr
- flat_nr
].hw
;
2441 p
->cfg
.regs
[1] |= (i
- m
) << 16;
2443 p
->cfg
.regs
[1] |= p
->cfg
.regs
[1] << 16;
2445 /* mark color semantic for light-twoside */
2447 for (i
= 0; i
< pc
->attr_nr
; i
++) {
2450 sn
= p
->info
.input_semantic_name
[p
->cfg
.io
[i
].id_fp
];
2451 si
= p
->info
.input_semantic_index
[p
->cfg
.io
[i
].id_fp
];
2453 if (sn
== TGSI_SEMANTIC_COLOR
) {
2454 p
->cfg
.two_side
[si
] = p
->cfg
.io
[i
];
2456 /* increase colour count */
2457 p
->cfg
.regs
[0] += popcnt4(
2458 p
->cfg
.two_side
[si
].mask
) << 16;
2460 n
= MIN2(n
, p
->cfg
.io
[i
].hw
- m
);
2464 p
->cfg
.regs
[0] += n
;
2466 /* Initialize FP results:
2467 * FragDepth is always first TGSI and last hw output
2469 i
= p
->info
.writes_z
? 4 : 0;
2470 for (rid
= 0; i
< pc
->result_nr
* 4; i
++)
2471 pc
->result
[i
].rhw
= rid
++;
2472 if (p
->info
.writes_z
)
2473 pc
->result
[2].rhw
= rid
;
2475 p
->cfg
.high_result
= rid
;
2481 pc
->immd
= MALLOC(pc
->immd_nr
* 4 * sizeof(struct nv50_reg
));
2485 for (i
= 0; i
< pc
->immd_nr
; i
++) {
2486 for (c
= 0; c
< 4; c
++, rid
++)
2487 ctor_reg(&pc
->immd
[rid
], P_IMMD
, i
, rid
);
2494 free_temp(pc
, pc
->iv_p
);
2496 free_temp(pc
, pc
->iv_c
);
2498 tgsi_parse_free(&tp
);
2503 free_nv50_pc(struct nv50_pc
*pc
)
2520 ctor_nv50_pc(struct nv50_pc
*pc
, struct nv50_program
*p
)
2523 unsigned rtype
[2] = { P_ATTR
, P_RESULT
};
2526 pc
->temp_nr
= p
->info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
2527 pc
->attr_nr
= p
->info
.file_max
[TGSI_FILE_INPUT
] + 1;
2528 pc
->result_nr
= p
->info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
2529 pc
->param_nr
= p
->info
.file_max
[TGSI_FILE_CONSTANT
] + 1;
2531 p
->cfg
.high_temp
= 4;
2533 p
->cfg
.two_side
[0].hw
= 0x40;
2534 p
->cfg
.two_side
[1].hw
= 0x40;
2537 case PIPE_SHADER_VERTEX
:
2540 p
->cfg
.io_nr
= pc
->result_nr
;
2542 case PIPE_SHADER_FRAGMENT
:
2543 rtype
[0] = rtype
[1] = P_TEMP
;
2545 p
->cfg
.regs
[0] = 0x01000004;
2546 p
->cfg
.io_nr
= pc
->attr_nr
;
2548 if (p
->info
.writes_z
) {
2549 p
->cfg
.regs
[2] |= 0x00000100;
2550 p
->cfg
.regs
[3] |= 0x00000011;
2552 if (p
->info
.uses_kill
)
2553 p
->cfg
.regs
[2] |= 0x00100000;
2558 pc
->temp
= MALLOC(pc
->temp_nr
* 4 * sizeof(struct nv50_reg
));
2562 for (i
= 0; i
< pc
->temp_nr
* 4; ++i
)
2563 ctor_reg(&pc
->temp
[i
], P_TEMP
, i
/ 4, -1);
2567 pc
->attr
= MALLOC(pc
->attr_nr
* 4 * sizeof(struct nv50_reg
));
2571 for (i
= 0; i
< pc
->attr_nr
* 4; ++i
)
2572 ctor_reg(&pc
->attr
[i
], rtype
[0], i
/ 4, -1);
2575 if (pc
->result_nr
) {
2576 unsigned nr
= pc
->result_nr
* 4;
2578 pc
->result
= MALLOC(nr
* sizeof(struct nv50_reg
));
2582 for (i
= 0; i
< nr
; ++i
)
2583 ctor_reg(&pc
->result
[i
], rtype
[1], i
/ 4, -1);
2589 pc
->param
= MALLOC(pc
->param_nr
* 4 * sizeof(struct nv50_reg
));
2593 for (i
= 0; i
< pc
->param_nr
; ++i
)
2594 for (c
= 0; c
< 4; ++c
, ++rid
)
2595 ctor_reg(&pc
->param
[rid
], P_CONST
, i
, rid
);
2602 nv50_fp_move_results(struct nv50_pc
*pc
)
2604 struct nv50_reg reg
;
2607 ctor_reg(®
, P_TEMP
, -1, -1);
2609 for (i
= 0; i
< pc
->result_nr
* 4; ++i
) {
2610 if (pc
->result
[i
].rhw
< 0 || pc
->result
[i
].hw
< 0)
2612 if (pc
->result
[i
].rhw
!= pc
->result
[i
].hw
) {
2613 reg
.hw
= pc
->result
[i
].rhw
;
2614 emit_mov(pc
, ®
, &pc
->result
[i
]);
2620 nv50_program_fixup_insns(struct nv50_pc
*pc
)
2622 struct nv50_program_exec
*e
, *prev
= NULL
, **bra_list
;
2625 bra_list
= CALLOC(pc
->p
->exec_size
, sizeof(struct nv50_program_exec
*));
2627 /* Collect branch instructions, we need to adjust their offsets
2628 * when converting 32 bit instructions to 64 bit ones
2630 for (n
= 0, e
= pc
->p
->exec_head
; e
; e
= e
->next
)
2631 if (e
->param
.index
>= 0 && !e
->param
.mask
)
2634 /* Make sure we don't have any single 32 bit instructions. */
2635 for (e
= pc
->p
->exec_head
, pos
= 0; e
; e
= e
->next
) {
2636 pos
+= is_long(e
) ? 2 : 1;
2638 if ((pos
& 1) && (!e
->next
|| is_long(e
->next
))) {
2639 for (i
= 0; i
< n
; ++i
)
2640 if (bra_list
[i
]->param
.index
>= pos
)
2641 bra_list
[i
]->param
.index
+= 1;
2642 convert_to_long(pc
, e
);
2649 assert(!is_immd(pc
->p
->exec_head
));
2650 assert(!is_immd(pc
->p
->exec_tail
));
2652 /* last instruction must be long so it can have the end bit set */
2653 if (!is_long(pc
->p
->exec_tail
)) {
2654 convert_to_long(pc
, pc
->p
->exec_tail
);
2656 convert_to_long(pc
, prev
);
2658 assert(!(pc
->p
->exec_tail
->inst
[1] & 2));
2659 /* set the end-bit */
2660 pc
->p
->exec_tail
->inst
[1] |= 1;
2666 nv50_program_tx(struct nv50_program
*p
)
2668 struct tgsi_parse_context parse
;
2672 pc
= CALLOC_STRUCT(nv50_pc
);
2676 ret
= ctor_nv50_pc(pc
, p
);
2680 ret
= nv50_program_tx_prep(pc
);
2684 tgsi_parse_init(&parse
, pc
->p
->pipe
.tokens
);
2685 while (!tgsi_parse_end_of_tokens(&parse
)) {
2686 const union tgsi_full_token
*tok
= &parse
.FullToken
;
2688 /* don't allow half insn/immd on first and last instruction */
2690 if (pc
->insn_cur
== 0 || pc
->insn_cur
+ 2 == pc
->insn_nr
)
2691 pc
->allow32
= FALSE
;
2693 tgsi_parse_token(&parse
);
2695 switch (tok
->Token
.Type
) {
2696 case TGSI_TOKEN_TYPE_INSTRUCTION
:
2698 ret
= nv50_tgsi_insn(pc
, tok
);
2707 if (pc
->p
->type
== PIPE_SHADER_FRAGMENT
)
2708 nv50_fp_move_results(pc
);
2710 nv50_program_fixup_insns(pc
);
2712 p
->param_nr
= pc
->param_nr
* 4;
2713 p
->immd_nr
= pc
->immd_nr
* 4;
2714 p
->immd
= pc
->immd_buf
;
2717 tgsi_parse_free(&parse
);
2725 nv50_program_validate(struct nv50_context
*nv50
, struct nv50_program
*p
)
2727 if (nv50_program_tx(p
) == FALSE
)
2729 p
->translated
= TRUE
;
2733 nv50_program_upload_data(struct nv50_context
*nv50
, float *map
,
2734 unsigned start
, unsigned count
, unsigned cbuf
)
2736 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
2737 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
2740 unsigned nr
= count
> 2047 ? 2047 : count
;
2742 BEGIN_RING(chan
, tesla
, NV50TCL_CB_ADDR
, 1);
2743 OUT_RING (chan
, (cbuf
<< 0) | (start
<< 8));
2744 BEGIN_RING(chan
, tesla
, NV50TCL_CB_DATA(0) | 0x40000000, nr
);
2745 OUT_RINGp (chan
, map
, nr
);
2754 nv50_program_validate_data(struct nv50_context
*nv50
, struct nv50_program
*p
)
2756 struct pipe_screen
*pscreen
= nv50
->pipe
.screen
;
2758 if (!p
->data
[0] && p
->immd_nr
) {
2759 struct nouveau_resource
*heap
= nv50
->screen
->immd_heap
[0];
2761 if (nouveau_resource_alloc(heap
, p
->immd_nr
, p
, &p
->data
[0])) {
2762 while (heap
->next
&& heap
->size
< p
->immd_nr
) {
2763 struct nv50_program
*evict
= heap
->next
->priv
;
2764 nouveau_resource_free(&evict
->data
[0]);
2767 if (nouveau_resource_alloc(heap
, p
->immd_nr
, p
,
2772 /* immediates only need to be uploaded again when freed */
2773 nv50_program_upload_data(nv50
, p
->immd
, p
->data
[0]->start
,
2774 p
->immd_nr
, NV50_CB_PMISC
);
2777 assert(p
->param_nr
<= 128);
2781 float *map
= pipe_buffer_map(pscreen
, nv50
->constbuf
[p
->type
],
2782 PIPE_BUFFER_USAGE_CPU_READ
);
2784 if (p
->type
== PIPE_SHADER_VERTEX
)
2789 nv50_program_upload_data(nv50
, map
, 0, p
->param_nr
, cb
);
2790 pipe_buffer_unmap(pscreen
, nv50
->constbuf
[p
->type
]);
2795 nv50_program_validate_code(struct nv50_context
*nv50
, struct nv50_program
*p
)
2797 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
2798 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
2799 struct nv50_program_exec
*e
;
2800 struct nouveau_stateobj
*so
;
2801 const unsigned flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_WR
;
2802 unsigned start
, count
, *up
, *ptr
;
2803 boolean upload
= FALSE
;
2806 nouveau_bo_new(chan
->device
, NOUVEAU_BO_VRAM
, 0x100,
2807 p
->exec_size
* 4, &p
->bo
);
2811 if (p
->data
[0] && p
->data
[0]->start
!= p
->data_start
[0])
2817 for (e
= p
->exec_head
; e
; e
= e
->next
) {
2818 unsigned ei
, ci
, bs
;
2820 if (e
->param
.index
< 0)
2823 if (e
->param
.mask
== 0) {
2824 assert(!(e
->param
.index
& 1));
2825 /* seem to be 8 byte steps */
2826 ei
= (e
->param
.index
>> 1) + 0 /* START_ID */;
2828 e
->inst
[0] &= 0xf0000fff;
2829 e
->inst
[0] |= ei
<< 12;
2833 bs
= (e
->inst
[1] >> 22) & 0x07;
2835 ei
= e
->param
.shift
>> 5;
2836 ci
= e
->param
.index
;
2838 ci
+= p
->data
[bs
]->start
;
2840 e
->inst
[ei
] &= ~e
->param
.mask
;
2841 e
->inst
[ei
] |= (ci
<< e
->param
.shift
);
2845 p
->data_start
[0] = p
->data
[0]->start
;
2847 #ifdef NV50_PROGRAM_DUMP
2848 NOUVEAU_ERR("-------\n");
2849 for (e
= p
->exec_head
; e
; e
= e
->next
) {
2850 NOUVEAU_ERR("0x%08x\n", e
->inst
[0]);
2852 NOUVEAU_ERR("0x%08x\n", e
->inst
[1]);
2856 up
= ptr
= MALLOC(p
->exec_size
* 4);
2857 for (e
= p
->exec_head
; e
; e
= e
->next
) {
2858 *(ptr
++) = e
->inst
[0];
2860 *(ptr
++) = e
->inst
[1];
2864 so_method(so
, nv50
->screen
->tesla
, NV50TCL_CB_DEF_ADDRESS_HIGH
, 3);
2865 so_reloc (so
, p
->bo
, 0, flags
| NOUVEAU_BO_HIGH
, 0, 0);
2866 so_reloc (so
, p
->bo
, 0, flags
| NOUVEAU_BO_LOW
, 0, 0);
2867 so_data (so
, (NV50_CB_PUPLOAD
<< 16) | 0x0800); //(p->exec_size * 4));
2869 start
= 0; count
= p
->exec_size
;
2871 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
2876 nr
= MIN2(count
, 2047);
2877 nr
= MIN2(chan
->pushbuf
->remaining
, nr
);
2878 if (chan
->pushbuf
->remaining
< (nr
+ 3)) {
2883 BEGIN_RING(chan
, tesla
, NV50TCL_CB_ADDR
, 1);
2884 OUT_RING (chan
, (start
<< 8) | NV50_CB_PUPLOAD
);
2885 BEGIN_RING(chan
, tesla
, NV50TCL_CB_DATA(0) | 0x40000000, nr
);
2886 OUT_RINGp (chan
, up
+ start
, nr
);
2897 nv50_vertprog_validate(struct nv50_context
*nv50
)
2899 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
2900 struct nv50_program
*p
= nv50
->vertprog
;
2901 struct nouveau_stateobj
*so
;
2903 if (!p
->translated
) {
2904 nv50_program_validate(nv50
, p
);
2909 nv50_program_validate_data(nv50
, p
);
2910 nv50_program_validate_code(nv50
, p
);
2913 so_method(so
, tesla
, NV50TCL_VP_ADDRESS_HIGH
, 2);
2914 so_reloc (so
, p
->bo
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
2915 NOUVEAU_BO_HIGH
, 0, 0);
2916 so_reloc (so
, p
->bo
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
2917 NOUVEAU_BO_LOW
, 0, 0);
2918 so_method(so
, tesla
, NV50TCL_VP_ATTR_EN_0
, 2);
2919 so_data (so
, p
->cfg
.attr
[0]);
2920 so_data (so
, p
->cfg
.attr
[1]);
2921 so_method(so
, tesla
, NV50TCL_VP_REG_ALLOC_RESULT
, 1);
2922 so_data (so
, p
->cfg
.high_result
);
2923 so_method(so
, tesla
, NV50TCL_VP_RESULT_MAP_SIZE
, 2);
2924 so_data (so
, p
->cfg
.high_result
); //8);
2925 so_data (so
, p
->cfg
.high_temp
);
2926 so_method(so
, tesla
, NV50TCL_VP_START_ID
, 1);
2927 so_data (so
, 0); /* program start offset */
2928 so_ref(so
, &nv50
->state
.vertprog
);
2933 nv50_fragprog_validate(struct nv50_context
*nv50
)
2935 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
2936 struct nv50_program
*p
= nv50
->fragprog
;
2937 struct nouveau_stateobj
*so
;
2939 if (!p
->translated
) {
2940 nv50_program_validate(nv50
, p
);
2945 nv50_program_validate_data(nv50
, p
);
2946 nv50_program_validate_code(nv50
, p
);
2949 so_method(so
, tesla
, NV50TCL_FP_ADDRESS_HIGH
, 2);
2950 so_reloc (so
, p
->bo
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
2951 NOUVEAU_BO_HIGH
, 0, 0);
2952 so_reloc (so
, p
->bo
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
2953 NOUVEAU_BO_LOW
, 0, 0);
2954 so_method(so
, tesla
, NV50TCL_FP_REG_ALLOC_TEMP
, 1);
2955 so_data (so
, p
->cfg
.high_temp
);
2956 so_method(so
, tesla
, NV50TCL_FP_RESULT_COUNT
, 1);
2957 so_data (so
, p
->cfg
.high_result
);
2958 so_method(so
, tesla
, NV50TCL_FP_CTRL_UNK19A8
, 1);
2959 so_data (so
, p
->cfg
.regs
[2]);
2960 so_method(so
, tesla
, NV50TCL_FP_CTRL_UNK196C
, 1);
2961 so_data (so
, p
->cfg
.regs
[3]);
2962 so_method(so
, tesla
, NV50TCL_FP_START_ID
, 1);
2963 so_data (so
, 0); /* program start offset */
2964 so_ref(so
, &nv50
->state
.fragprog
);
2969 nv50_pntc_replace(struct nv50_context
*nv50
, uint32_t pntc
[8], unsigned base
)
2971 struct nv50_program
*fp
= nv50
->fragprog
;
2972 struct nv50_program
*vp
= nv50
->vertprog
;
2973 unsigned i
, c
, m
= base
;
2975 /* XXX: This can't work correctly in all cases yet, we either
2976 * have to create TGSI_SEMANTIC_PNTC or sprite_coord_mode has
2977 * to be per FP input instead of per VP output
2979 memset(pntc
, 0, 8 * sizeof(uint32_t));
2981 for (i
= 0; i
< fp
->cfg
.io_nr
; i
++) {
2983 uint8_t j
= fp
->cfg
.io
[i
].id_vp
, k
= fp
->cfg
.io
[i
].id_fp
;
2984 unsigned n
= popcnt4(fp
->cfg
.io
[i
].mask
);
2986 if (fp
->info
.input_semantic_name
[k
] != TGSI_SEMANTIC_GENERIC
) {
2991 sn
= vp
->info
.input_semantic_name
[j
];
2992 si
= vp
->info
.input_semantic_index
[j
];
2994 if (j
< fp
->cfg
.io_nr
&& sn
== TGSI_SEMANTIC_GENERIC
) {
2996 nv50
->rasterizer
->pipe
.sprite_coord_mode
[si
];
2998 if (mode
== PIPE_SPRITE_COORD_NONE
) {
3004 /* this is either PointCoord or replaced by sprite coords */
3005 for (c
= 0; c
< 4; c
++) {
3006 if (!(fp
->cfg
.io
[i
].mask
& (1 << c
)))
3008 pntc
[m
/ 8] |= (c
+ 1) << ((m
% 8) * 4);
3015 nv50_sreg4_map(uint32_t *p_map
, int mid
, uint32_t lin
[4],
3016 struct nv50_sreg4
*fpi
, struct nv50_sreg4
*vpo
)
3019 uint8_t mv
= vpo
->mask
, mf
= fpi
->mask
, oid
= vpo
->hw
;
3020 uint8_t *map
= (uint8_t *)p_map
;
3022 for (c
= 0; c
< 4; ++c
) {
3024 if (fpi
->linear
== TRUE
)
3025 lin
[mid
/ 32] |= 1 << (mid
% 32);
3026 map
[mid
++] = (mv
& 1) ? oid
: ((c
== 3) ? 0x41 : 0x40);
3038 nv50_linkage_validate(struct nv50_context
*nv50
)
3040 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
3041 struct nv50_program
*vp
= nv50
->vertprog
;
3042 struct nv50_program
*fp
= nv50
->fragprog
;
3043 struct nouveau_stateobj
*so
;
3044 struct nv50_sreg4 dummy
, *vpo
;
3046 uint32_t map
[16], lin
[4], reg
[5], pcrd
[8];
3048 memset(map
, 0, sizeof(map
));
3049 memset(lin
, 0, sizeof(lin
));
3051 reg
[1] = 0x00000004; /* low and high clip distance map ids */
3052 reg
[2] = 0x00000000; /* layer index map id (disabled, GP only) */
3053 reg
[3] = 0x00000000; /* point size map id & enable */
3054 reg
[0] = fp
->cfg
.regs
[0]; /* colour semantic reg */
3055 reg
[4] = fp
->cfg
.regs
[1]; /* interpolant info */
3057 dummy
.linear
= FALSE
;
3058 dummy
.mask
= 0xf; /* map all components of HPOS */
3059 m
= nv50_sreg4_map(map
, m
, lin
, &dummy
, &vp
->cfg
.io
[0]);
3063 if (vp
->cfg
.clpd
< 0x40) {
3064 for (c
= 0; c
< vp
->cfg
.clpd_nr
; ++c
)
3065 map
[m
++] = vp
->cfg
.clpd
+ c
;
3069 reg
[0] |= m
<< 8; /* adjust BFC0 id */
3071 /* if light_twoside is active, it seems FFC0_ID == BFC0_ID is bad */
3072 if (nv50
->rasterizer
->pipe
.light_twoside
) {
3073 vpo
= &vp
->cfg
.two_side
[0];
3075 m
= nv50_sreg4_map(map
, m
, lin
, &fp
->cfg
.two_side
[0], &vpo
[0]);
3076 m
= nv50_sreg4_map(map
, m
, lin
, &fp
->cfg
.two_side
[1], &vpo
[1]);
3079 reg
[0] += m
- 4; /* adjust FFC0 id */
3080 reg
[4] |= m
<< 8; /* set mid where 'normal' FP inputs start */
3083 if (fp
->info
.input_semantic_name
[0] == TGSI_SEMANTIC_POSITION
)
3085 for (; i
< fp
->cfg
.io_nr
; i
++) {
3086 ubyte sn
= fp
->info
.input_semantic_name
[fp
->cfg
.io
[i
].id_fp
];
3087 ubyte si
= fp
->info
.input_semantic_index
[fp
->cfg
.io
[i
].id_fp
];
3089 n
= fp
->cfg
.io
[i
].id_vp
;
3090 if (n
>= vp
->cfg
.io_nr
||
3091 vp
->info
.output_semantic_name
[n
] != sn
||
3092 vp
->info
.output_semantic_index
[n
] != si
)
3095 vpo
= &vp
->cfg
.io
[n
];
3097 m
= nv50_sreg4_map(map
, m
, lin
, &fp
->cfg
.io
[i
], vpo
);
3100 if (nv50
->rasterizer
->pipe
.point_size_per_vertex
) {
3101 map
[m
/ 4] |= vp
->cfg
.psiz
<< ((m
% 4) * 8);
3102 reg
[3] = (m
++ << 4) | 1;
3105 /* now fill the stateobj */
3109 so_method(so
, tesla
, NV50TCL_VP_RESULT_MAP_SIZE
, 1);
3111 so_method(so
, tesla
, NV50TCL_VP_RESULT_MAP(0), n
);
3112 so_datap (so
, map
, n
);
3114 so_method(so
, tesla
, NV50TCL_MAP_SEMANTIC_0
, 4);
3115 so_datap (so
, reg
, 4);
3117 so_method(so
, tesla
, NV50TCL_FP_INTERPOLANT_CTRL
, 1);
3118 so_data (so
, reg
[4]);
3120 so_method(so
, tesla
, 0x1540, 4);
3121 so_datap (so
, lin
, 4);
3123 if (nv50
->rasterizer
->pipe
.point_sprite
) {
3124 nv50_pntc_replace(nv50
, pcrd
, (reg
[4] >> 8) & 0xff);
3126 so_method(so
, tesla
, NV50TCL_POINT_COORD_REPLACE_MAP(0), 8);
3127 so_datap (so
, pcrd
, 8);
3130 so_ref(so
, &nv50
->state
.programs
);
3135 nv50_program_destroy(struct nv50_context
*nv50
, struct nv50_program
*p
)
3137 while (p
->exec_head
) {
3138 struct nv50_program_exec
*e
= p
->exec_head
;
3140 p
->exec_head
= e
->next
;
3143 p
->exec_tail
= NULL
;
3146 nouveau_bo_ref(NULL
, &p
->bo
);
3148 nouveau_resource_free(&p
->data
[0]);