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
91 struct nv50_program
*p
;
94 struct nv50_reg
*r_temp
[NV50_SU_MAX_TEMP
];
97 struct nv50_reg
*temp
;
99 struct nv50_reg
*attr
;
101 struct nv50_reg
*result
;
103 struct nv50_reg
*param
;
105 struct nv50_reg
*immd
;
109 struct nv50_reg
*temp_temp
[16];
110 unsigned temp_temp_nr
;
114 alloc_reg(struct nv50_pc
*pc
, struct nv50_reg
*reg
)
118 if (reg
->type
== P_RESULT
) {
119 if (pc
->p
->cfg
.high_result
< (reg
->hw
+ 1))
120 pc
->p
->cfg
.high_result
= reg
->hw
+ 1;
123 if (reg
->type
!= P_TEMP
)
127 /*XXX: do this here too to catch FP temp-as-attr usage..
128 * not clean, but works */
129 if (pc
->p
->cfg
.high_temp
< (reg
->hw
+ 1))
130 pc
->p
->cfg
.high_temp
= reg
->hw
+ 1;
134 for (i
= 0; i
< NV50_SU_MAX_TEMP
; i
++) {
135 if (!(pc
->r_temp
[i
])) {
138 if (pc
->p
->cfg
.high_temp
< (i
+ 1))
139 pc
->p
->cfg
.high_temp
= i
+ 1;
147 static struct nv50_reg
*
148 alloc_temp(struct nv50_pc
*pc
, struct nv50_reg
*dst
)
153 if (dst
&& dst
->type
== P_TEMP
&& dst
->hw
== -1)
156 for (i
= 0; i
< NV50_SU_MAX_TEMP
; i
++) {
157 if (!pc
->r_temp
[i
]) {
158 r
= CALLOC_STRUCT(nv50_reg
);
172 free_temp(struct nv50_pc
*pc
, struct nv50_reg
*r
)
174 if (r
->index
== -1) {
177 FREE(pc
->r_temp
[hw
]);
178 pc
->r_temp
[hw
] = NULL
;
183 alloc_temp4(struct nv50_pc
*pc
, struct nv50_reg
*dst
[4], int idx
)
187 if ((idx
+ 4) >= NV50_SU_MAX_TEMP
)
190 if (pc
->r_temp
[idx
] || pc
->r_temp
[idx
+ 1] ||
191 pc
->r_temp
[idx
+ 2] || pc
->r_temp
[idx
+ 3])
192 return alloc_temp4(pc
, dst
, idx
+ 1);
194 for (i
= 0; i
< 4; i
++) {
195 dst
[i
] = CALLOC_STRUCT(nv50_reg
);
196 dst
[i
]->type
= P_TEMP
;
198 dst
[i
]->hw
= idx
+ i
;
199 pc
->r_temp
[idx
+ i
] = dst
[i
];
206 free_temp4(struct nv50_pc
*pc
, struct nv50_reg
*reg
[4])
210 for (i
= 0; i
< 4; i
++)
211 free_temp(pc
, reg
[i
]);
214 static struct nv50_reg
*
215 temp_temp(struct nv50_pc
*pc
)
217 if (pc
->temp_temp_nr
>= 16)
220 pc
->temp_temp
[pc
->temp_temp_nr
] = alloc_temp(pc
, NULL
);
221 return pc
->temp_temp
[pc
->temp_temp_nr
++];
225 kill_temp_temp(struct nv50_pc
*pc
)
229 for (i
= 0; i
< pc
->temp_temp_nr
; i
++)
230 free_temp(pc
, pc
->temp_temp
[i
]);
231 pc
->temp_temp_nr
= 0;
235 ctor_immd(struct nv50_pc
*pc
, float x
, float y
, float z
, float w
)
237 pc
->immd_buf
= REALLOC(pc
->immd_buf
, (pc
->immd_nr
* r
* sizeof(float)),
238 (pc
->immd_nr
+ 1) * 4 * sizeof(float));
239 pc
->immd_buf
[(pc
->immd_nr
* 4) + 0] = x
;
240 pc
->immd_buf
[(pc
->immd_nr
* 4) + 1] = y
;
241 pc
->immd_buf
[(pc
->immd_nr
* 4) + 2] = z
;
242 pc
->immd_buf
[(pc
->immd_nr
* 4) + 3] = w
;
244 return pc
->immd_nr
++;
247 static struct nv50_reg
*
248 alloc_immd(struct nv50_pc
*pc
, float f
)
250 struct nv50_reg
*r
= CALLOC_STRUCT(nv50_reg
);
253 hw
= ctor_immd(pc
, f
, 0, 0, 0) * 4;
260 static struct nv50_program_exec
*
261 exec(struct nv50_pc
*pc
)
263 struct nv50_program_exec
*e
= CALLOC_STRUCT(nv50_program_exec
);
270 emit(struct nv50_pc
*pc
, struct nv50_program_exec
*e
)
272 struct nv50_program
*p
= pc
->p
;
275 p
->exec_tail
->next
= e
;
279 p
->exec_size
+= (e
->inst
[0] & 1) ? 2 : 1;
282 static INLINE
void set_long(struct nv50_pc
*, struct nv50_program_exec
*);
285 is_long(struct nv50_program_exec
*e
)
293 is_immd(struct nv50_program_exec
*e
)
295 if (is_long(e
) && (e
->inst
[1] & 3) == 3)
301 set_pred(struct nv50_pc
*pc
, unsigned pred
, unsigned idx
,
302 struct nv50_program_exec
*e
)
305 e
->inst
[1] &= ~((0x1f << 7) | (0x3 << 12));
306 e
->inst
[1] |= (pred
<< 7) | (idx
<< 12);
310 set_pred_wr(struct nv50_pc
*pc
, unsigned on
, unsigned idx
,
311 struct nv50_program_exec
*e
)
314 e
->inst
[1] &= ~((0x3 << 4) | (1 << 6));
315 e
->inst
[1] |= (idx
<< 4) | (on
<< 6);
319 set_long(struct nv50_pc
*pc
, struct nv50_program_exec
*e
)
325 set_pred(pc
, 0xf, 0, e
);
326 set_pred_wr(pc
, 0, 0, e
);
330 set_dst(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_program_exec
*e
)
332 if (dst
->type
== P_RESULT
) {
334 e
->inst
[1] |= 0x00000008;
338 e
->inst
[0] |= (dst
->hw
<< 2);
342 set_immd(struct nv50_pc
*pc
, struct nv50_reg
*imm
, struct nv50_program_exec
*e
)
344 unsigned val
= fui(pc
->immd_buf
[imm
->hw
]); /* XXX */
347 /*XXX: can't be predicated - bits overlap.. catch cases where both
348 * are required and avoid them. */
349 set_pred(pc
, 0, 0, e
);
350 set_pred_wr(pc
, 0, 0, e
);
352 e
->inst
[1] |= 0x00000002 | 0x00000001;
353 e
->inst
[0] |= (val
& 0x3f) << 16;
354 e
->inst
[1] |= (val
>> 6) << 2;
358 emit_interp(struct nv50_pc
*pc
, struct nv50_reg
*dst
,
359 struct nv50_reg
*src
, struct nv50_reg
*iv
)
361 struct nv50_program_exec
*e
= exec(pc
);
363 e
->inst
[0] |= 0x80000000;
366 e
->inst
[0] |= (src
->hw
<< 16);
368 e
->inst
[0] |= (1 << 25);
370 e
->inst
[0] |= (iv
->hw
<< 9);
377 set_data(struct nv50_pc
*pc
, struct nv50_reg
*src
, unsigned m
, unsigned s
,
378 struct nv50_program_exec
*e
)
382 e
->inst
[1] |= (1 << 22);
384 if (src
->type
== P_IMMD
) {
385 e
->inst
[1] |= (NV50_CB_PMISC
<< 22);
387 if (pc
->p
->type
== PIPE_SHADER_VERTEX
)
388 e
->inst
[1] |= (NV50_CB_PVP
<< 22);
390 e
->inst
[1] |= (NV50_CB_PFP
<< 22);
394 e
->param
.index
= src
->hw
;
396 e
->param
.mask
= m
<< (s
% 32);
400 emit_mov(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
402 struct nv50_program_exec
*e
= exec(pc
);
404 e
->inst
[0] |= 0x10000000;
408 if (0 && dst
->type
!= P_RESULT
&& src
->type
== P_IMMD
) {
409 set_immd(pc
, src
, e
);
410 /*XXX: 32-bit, but steals part of "half" reg space - need to
411 * catch and handle this case if/when we do half-regs
413 e
->inst
[0] |= 0x00008000;
415 if (src
->type
== P_IMMD
|| src
->type
== P_CONST
) {
417 set_data(pc
, src
, 0x7f, 9, e
);
418 e
->inst
[1] |= 0x20000000; /* src0 const? */
420 if (src
->type
== P_ATTR
) {
422 e
->inst
[1] |= 0x00200000;
426 e
->inst
[0] |= (src
->hw
<< 9);
429 /* We really should support "half" instructions here at some point,
430 * but I don't feel confident enough about them yet.
433 if (is_long(e
) && !is_immd(e
)) {
434 e
->inst
[1] |= 0x04000000; /* 32-bit */
435 e
->inst
[1] |= 0x0003c000; /* "subsubop" 0xf == mov */
442 check_swap_src_0_1(struct nv50_pc
*pc
,
443 struct nv50_reg
**s0
, struct nv50_reg
**s1
)
445 struct nv50_reg
*src0
= *s0
, *src1
= *s1
;
447 if (src0
->type
== P_CONST
) {
448 if (src1
->type
!= P_CONST
) {
454 if (src1
->type
== P_ATTR
) {
455 if (src0
->type
!= P_ATTR
) {
466 set_src_0(struct nv50_pc
*pc
, struct nv50_reg
*src
, struct nv50_program_exec
*e
)
468 if (src
->type
== P_ATTR
) {
470 e
->inst
[1] |= 0x00200000;
472 if (src
->type
== P_CONST
|| src
->type
== P_IMMD
) {
473 struct nv50_reg
*temp
= temp_temp(pc
);
475 emit_mov(pc
, temp
, src
);
480 e
->inst
[0] |= (src
->hw
<< 9);
484 set_src_1(struct nv50_pc
*pc
, struct nv50_reg
*src
, struct nv50_program_exec
*e
)
486 if (src
->type
== P_ATTR
) {
487 struct nv50_reg
*temp
= temp_temp(pc
);
489 emit_mov(pc
, temp
, src
);
492 if (src
->type
== P_CONST
|| src
->type
== P_IMMD
) {
493 assert(!(e
->inst
[0] & 0x00800000));
494 if (e
->inst
[0] & 0x01000000) {
495 struct nv50_reg
*temp
= temp_temp(pc
);
497 emit_mov(pc
, temp
, src
);
500 set_data(pc
, src
, 0x7f, 16, e
);
501 e
->inst
[0] |= 0x00800000;
506 e
->inst
[0] |= (src
->hw
<< 16);
510 set_src_2(struct nv50_pc
*pc
, struct nv50_reg
*src
, struct nv50_program_exec
*e
)
514 if (src
->type
== P_ATTR
) {
515 struct nv50_reg
*temp
= temp_temp(pc
);
517 emit_mov(pc
, temp
, src
);
520 if (src
->type
== P_CONST
|| src
->type
== P_IMMD
) {
521 assert(!(e
->inst
[0] & 0x01000000));
522 if (e
->inst
[0] & 0x00800000) {
523 struct nv50_reg
*temp
= temp_temp(pc
);
525 emit_mov(pc
, temp
, src
);
528 set_data(pc
, src
, 0x7f, 32+14, e
);
529 e
->inst
[0] |= 0x01000000;
534 e
->inst
[1] |= (src
->hw
<< 14);
538 emit_mul(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
539 struct nv50_reg
*src1
)
541 struct nv50_program_exec
*e
= exec(pc
);
543 e
->inst
[0] |= 0xc0000000;
546 check_swap_src_0_1(pc
, &src0
, &src1
);
548 set_src_0(pc
, src0
, e
);
549 set_src_1(pc
, src1
, e
);
555 emit_add(struct nv50_pc
*pc
, struct nv50_reg
*dst
,
556 struct nv50_reg
*src0
, struct nv50_reg
*src1
)
558 struct nv50_program_exec
*e
= exec(pc
);
560 e
->inst
[0] |= 0xb0000000;
562 check_swap_src_0_1(pc
, &src0
, &src1
);
564 set_src_0(pc
, src0
, e
);
566 set_src_2(pc
, src1
, e
);
568 set_src_1(pc
, src1
, e
);
574 emit_minmax(struct nv50_pc
*pc
, unsigned sub
, struct nv50_reg
*dst
,
575 struct nv50_reg
*src0
, struct nv50_reg
*src1
)
577 struct nv50_program_exec
*e
= exec(pc
);
580 e
->inst
[0] |= 0xb0000000;
581 e
->inst
[1] |= (sub
<< 29);
583 check_swap_src_0_1(pc
, &src0
, &src1
);
585 set_src_0(pc
, src0
, e
);
586 set_src_1(pc
, src1
, e
);
592 emit_sub(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
593 struct nv50_reg
*src1
)
595 struct nv50_program_exec
*e
= exec(pc
);
597 e
->inst
[0] |= 0xb0000000;
600 if (check_swap_src_0_1(pc
, &src0
, &src1
))
601 e
->inst
[1] |= 0x04000000;
603 e
->inst
[1] |= 0x08000000;
606 set_src_0(pc
, src0
, e
);
607 set_src_2(pc
, src1
, e
);
613 emit_mad(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
614 struct nv50_reg
*src1
, struct nv50_reg
*src2
)
616 struct nv50_program_exec
*e
= exec(pc
);
618 e
->inst
[0] |= 0xe0000000;
620 check_swap_src_0_1(pc
, &src0
, &src1
);
622 set_src_0(pc
, src0
, e
);
623 set_src_1(pc
, src1
, e
);
624 set_src_2(pc
, src2
, e
);
630 emit_msb(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src0
,
631 struct nv50_reg
*src1
, struct nv50_reg
*src2
)
633 struct nv50_program_exec
*e
= exec(pc
);
635 e
->inst
[0] |= 0xe0000000;
637 e
->inst
[1] |= 0x08000000; /* src0 * src1 - src2 */
639 check_swap_src_0_1(pc
, &src0
, &src1
);
641 set_src_0(pc
, src0
, e
);
642 set_src_1(pc
, src1
, e
);
643 set_src_2(pc
, src2
, e
);
649 emit_flop(struct nv50_pc
*pc
, unsigned sub
,
650 struct nv50_reg
*dst
, struct nv50_reg
*src
)
652 struct nv50_program_exec
*e
= exec(pc
);
654 e
->inst
[0] |= 0x90000000;
657 e
->inst
[1] |= (sub
<< 29);
661 set_src_0(pc
, src
, e
);
667 emit_preex2(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
669 struct nv50_program_exec
*e
= exec(pc
);
671 e
->inst
[0] |= 0xb0000000;
674 set_src_0(pc
, src
, e
);
676 e
->inst
[1] |= (6 << 29) | 0x00004000;
682 emit_precossin(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
684 struct nv50_program_exec
*e
= exec(pc
);
686 e
->inst
[0] |= 0xb0000000;
689 set_src_0(pc
, src
, e
);
691 e
->inst
[1] |= (6 << 29);
697 emit_set(struct nv50_pc
*pc
, unsigned c_op
, struct nv50_reg
*dst
,
698 struct nv50_reg
*src0
, struct nv50_reg
*src1
)
700 struct nv50_program_exec
*e
= exec(pc
);
701 unsigned inv_cop
[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
702 struct nv50_reg
*rdst
;
705 if (check_swap_src_0_1(pc
, &src0
, &src1
))
706 c_op
= inv_cop
[c_op
];
709 if (dst
->type
!= P_TEMP
)
710 dst
= alloc_temp(pc
, NULL
);
714 e
->inst
[0] |= 0xb0000000;
715 e
->inst
[1] |= (3 << 29);
716 e
->inst
[1] |= (c_op
<< 14);
717 /*XXX: breaks things, .u32 by default?
718 * decuda will disasm as .u16 and use .lo/.hi regs, but this
719 * doesn't seem to match what the hw actually does.
720 inst[1] |= 0x04000000; << breaks things.. .u32 by default?
723 set_src_0(pc
, src0
, e
);
724 set_src_1(pc
, src1
, e
);
729 e
->inst
[0] = 0xa0000001;
730 e
->inst
[1] = 0x64014780;
731 set_dst(pc
, rdst
, e
);
732 set_src_0(pc
, dst
, e
);
740 emit_flr(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
742 struct nv50_program_exec
*e
= exec(pc
);
744 e
->inst
[0] = 0xa0000000; /* cvt */
746 e
->inst
[1] |= (6 << 29); /* cvt */
747 e
->inst
[1] |= 0x08000000; /* integer mode */
748 e
->inst
[1] |= 0x04000000; /* 32 bit */
749 e
->inst
[1] |= ((0x1 << 3)) << 14; /* .rn */
750 e
->inst
[1] |= (1 << 14); /* src .f32 */
752 set_src_0(pc
, src
, e
);
758 emit_pow(struct nv50_pc
*pc
, struct nv50_reg
*dst
,
759 struct nv50_reg
*v
, struct nv50_reg
*e
)
761 struct nv50_reg
*temp
= alloc_temp(pc
, NULL
);
763 emit_flop(pc
, 3, temp
, v
);
764 emit_mul(pc
, temp
, temp
, e
);
765 emit_preex2(pc
, temp
, temp
);
766 emit_flop(pc
, 6, dst
, temp
);
772 emit_abs(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
774 struct nv50_program_exec
*e
= exec(pc
);
776 e
->inst
[0] = 0xa0000000; /* cvt */
778 e
->inst
[1] |= (6 << 29); /* cvt */
779 e
->inst
[1] |= 0x04000000; /* 32 bit */
780 e
->inst
[1] |= (1 << 14); /* src .f32 */
781 e
->inst
[1] |= ((1 << 6) << 14); /* .abs */
783 set_src_0(pc
, src
, e
);
789 emit_lit(struct nv50_pc
*pc
, struct nv50_reg
**dst
, unsigned mask
,
790 struct nv50_reg
**src
)
792 struct nv50_reg
*one
= alloc_immd(pc
, 1.0);
793 struct nv50_reg
*zero
= alloc_immd(pc
, 0.0);
794 struct nv50_reg
*neg128
= alloc_immd(pc
, -127.999999);
795 struct nv50_reg
*pos128
= alloc_immd(pc
, 127.999999);
796 struct nv50_reg
*tmp
[4];
799 emit_mov(pc
, dst
[0], one
);
802 emit_mov(pc
, dst
[3], one
);
804 if (mask
& (3 << 1)) {
808 tmp
[0] = temp_temp(pc
);
809 emit_minmax(pc
, 4, tmp
[0], src
[0], zero
);
812 if (mask
& (1 << 2)) {
813 set_pred_wr(pc
, 1, 0, pc
->p
->exec_tail
);
815 tmp
[1] = temp_temp(pc
);
816 emit_minmax(pc
, 4, tmp
[1], src
[1], zero
);
818 tmp
[3] = temp_temp(pc
);
819 emit_minmax(pc
, 4, tmp
[3], src
[3], neg128
);
820 emit_minmax(pc
, 5, tmp
[3], tmp
[3], pos128
);
822 emit_pow(pc
, dst
[2], tmp
[1], tmp
[3]);
823 emit_mov(pc
, dst
[2], zero
);
824 set_pred(pc
, 3, 0, pc
->p
->exec_tail
);
829 emit_neg(struct nv50_pc
*pc
, struct nv50_reg
*dst
, struct nv50_reg
*src
)
831 struct nv50_program_exec
*e
= exec(pc
);
834 e
->inst
[0] |= 0xa0000000; /* delta */
835 e
->inst
[1] |= (7 << 29); /* delta */
836 e
->inst
[1] |= 0x04000000; /* negate arg0? probably not */
837 e
->inst
[1] |= (1 << 14); /* src .f32 */
839 set_src_0(pc
, src
, e
);
845 emit_kil(struct nv50_pc
*pc
, struct nv50_reg
*src
)
847 struct nv50_program_exec
*e
;
848 const int r_pred
= 1;
850 /* Sets predicate reg ? */
852 e
->inst
[0] = 0xa00001fd;
853 e
->inst
[1] = 0xc4014788;
854 set_src_0(pc
, src
, e
);
855 set_pred_wr(pc
, 1, r_pred
, e
);
858 /* This is probably KILP */
860 e
->inst
[0] = 0x000001fe;
862 set_pred(pc
, 1 /* LT? */, r_pred
, e
);
866 static struct nv50_reg
*
867 tgsi_dst(struct nv50_pc
*pc
, int c
, const struct tgsi_full_dst_register
*dst
)
869 switch (dst
->DstRegister
.File
) {
870 case TGSI_FILE_TEMPORARY
:
871 return &pc
->temp
[dst
->DstRegister
.Index
* 4 + c
];
872 case TGSI_FILE_OUTPUT
:
873 return &pc
->result
[dst
->DstRegister
.Index
* 4 + c
];
883 static struct nv50_reg
*
884 tgsi_src(struct nv50_pc
*pc
, int chan
, const struct tgsi_full_src_register
*src
)
886 struct nv50_reg
*r
= NULL
;
887 struct nv50_reg
*temp
;
890 c
= tgsi_util_get_full_src_register_extswizzle(src
, chan
);
892 case TGSI_EXTSWIZZLE_X
:
893 case TGSI_EXTSWIZZLE_Y
:
894 case TGSI_EXTSWIZZLE_Z
:
895 case TGSI_EXTSWIZZLE_W
:
896 switch (src
->SrcRegister
.File
) {
897 case TGSI_FILE_INPUT
:
898 r
= &pc
->attr
[src
->SrcRegister
.Index
* 4 + c
];
900 case TGSI_FILE_TEMPORARY
:
901 r
= &pc
->temp
[src
->SrcRegister
.Index
* 4 + c
];
903 case TGSI_FILE_CONSTANT
:
904 r
= &pc
->param
[src
->SrcRegister
.Index
* 4 + c
];
906 case TGSI_FILE_IMMEDIATE
:
907 r
= &pc
->immd
[src
->SrcRegister
.Index
* 4 + c
];
909 case TGSI_FILE_SAMPLER
:
916 case TGSI_EXTSWIZZLE_ZERO
:
917 r
= alloc_immd(pc
, 0.0);
919 case TGSI_EXTSWIZZLE_ONE
:
920 r
= alloc_immd(pc
, 1.0);
927 switch (tgsi_util_get_full_src_register_sign_mode(src
, chan
)) {
928 case TGSI_UTIL_SIGN_KEEP
:
930 case TGSI_UTIL_SIGN_CLEAR
:
931 temp
= temp_temp(pc
);
932 emit_abs(pc
, temp
, r
);
935 case TGSI_UTIL_SIGN_TOGGLE
:
936 temp
= temp_temp(pc
);
937 emit_neg(pc
, temp
, r
);
940 case TGSI_UTIL_SIGN_SET
:
941 temp
= temp_temp(pc
);
942 emit_abs(pc
, temp
, r
);
943 emit_neg(pc
, temp
, r
);
955 nv50_program_tx_insn(struct nv50_pc
*pc
, const union tgsi_full_token
*tok
)
957 const struct tgsi_full_instruction
*inst
= &tok
->FullInstruction
;
958 struct nv50_reg
*rdst
[4], *dst
[4], *src
[3][4], *temp
;
959 unsigned mask
, sat
, unit
;
962 mask
= inst
->FullDstRegisters
[0].DstRegister
.WriteMask
;
963 sat
= inst
->Instruction
.Saturate
== TGSI_SAT_ZERO_ONE
;
965 for (c
= 0; c
< 4; c
++) {
967 dst
[c
] = tgsi_dst(pc
, c
, &inst
->FullDstRegisters
[0]);
972 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
973 struct tgsi_full_src_register
*fs
= &inst
->FullSrcRegisters
[i
];
975 if (fs
->SrcRegister
.File
== TGSI_FILE_SAMPLER
)
976 unit
= fs
->SrcRegister
.Index
;
978 for (c
= 0; c
< 4; c
++)
979 src
[i
][c
] = tgsi_src(pc
, c
, fs
);
983 for (c
= 0; c
< 4; c
++) {
985 dst
[c
] = temp_temp(pc
);
989 switch (inst
->Instruction
.Opcode
) {
990 case TGSI_OPCODE_ABS
:
991 for (c
= 0; c
< 4; c
++) {
992 if (!(mask
& (1 << c
)))
994 emit_abs(pc
, dst
[c
], src
[0][c
]);
997 case TGSI_OPCODE_ADD
:
998 for (c
= 0; c
< 4; c
++) {
999 if (!(mask
& (1 << c
)))
1001 emit_add(pc
, dst
[c
], src
[0][c
], src
[1][c
]);
1004 case TGSI_OPCODE_COS
:
1005 temp
= alloc_temp(pc
, NULL
);
1006 emit_precossin(pc
, temp
, src
[0][0]);
1007 emit_flop(pc
, 5, temp
, temp
);
1008 for (c
= 0; c
< 4; c
++) {
1009 if (!(mask
& (1 << c
)))
1011 emit_mov(pc
, dst
[c
], temp
);
1014 case TGSI_OPCODE_DP3
:
1015 temp
= alloc_temp(pc
, NULL
);
1016 emit_mul(pc
, temp
, src
[0][0], src
[1][0]);
1017 emit_mad(pc
, temp
, src
[0][1], src
[1][1], temp
);
1018 emit_mad(pc
, temp
, src
[0][2], src
[1][2], temp
);
1019 for (c
= 0; c
< 4; c
++) {
1020 if (!(mask
& (1 << c
)))
1022 emit_mov(pc
, dst
[c
], temp
);
1024 free_temp(pc
, temp
);
1026 case TGSI_OPCODE_DP4
:
1027 temp
= alloc_temp(pc
, NULL
);
1028 emit_mul(pc
, temp
, src
[0][0], src
[1][0]);
1029 emit_mad(pc
, temp
, src
[0][1], src
[1][1], temp
);
1030 emit_mad(pc
, temp
, src
[0][2], src
[1][2], temp
);
1031 emit_mad(pc
, temp
, src
[0][3], src
[1][3], temp
);
1032 for (c
= 0; c
< 4; c
++) {
1033 if (!(mask
& (1 << c
)))
1035 emit_mov(pc
, dst
[c
], temp
);
1037 free_temp(pc
, temp
);
1039 case TGSI_OPCODE_DPH
:
1040 temp
= alloc_temp(pc
, NULL
);
1041 emit_mul(pc
, temp
, src
[0][0], src
[1][0]);
1042 emit_mad(pc
, temp
, src
[0][1], src
[1][1], temp
);
1043 emit_mad(pc
, temp
, src
[0][2], src
[1][2], temp
);
1044 emit_add(pc
, temp
, src
[1][3], temp
);
1045 for (c
= 0; c
< 4; c
++) {
1046 if (!(mask
& (1 << c
)))
1048 emit_mov(pc
, dst
[c
], temp
);
1050 free_temp(pc
, temp
);
1052 case TGSI_OPCODE_DST
:
1054 struct nv50_reg
*one
= alloc_immd(pc
, 1.0);
1055 if (mask
& (1 << 0))
1056 emit_mov(pc
, dst
[0], one
);
1057 if (mask
& (1 << 1))
1058 emit_mul(pc
, dst
[1], src
[0][1], src
[1][1]);
1059 if (mask
& (1 << 2))
1060 emit_mov(pc
, dst
[2], src
[0][2]);
1061 if (mask
& (1 << 3))
1062 emit_mov(pc
, dst
[3], src
[1][3]);
1066 case TGSI_OPCODE_EX2
:
1067 temp
= alloc_temp(pc
, NULL
);
1068 emit_preex2(pc
, temp
, src
[0][0]);
1069 emit_flop(pc
, 6, temp
, temp
);
1070 for (c
= 0; c
< 4; c
++) {
1071 if (!(mask
& (1 << c
)))
1073 emit_mov(pc
, dst
[c
], temp
);
1075 free_temp(pc
, temp
);
1077 case TGSI_OPCODE_FLR
:
1078 for (c
= 0; c
< 4; c
++) {
1079 if (!(mask
& (1 << c
)))
1081 emit_flr(pc
, dst
[c
], src
[0][c
]);
1084 case TGSI_OPCODE_FRC
:
1085 temp
= alloc_temp(pc
, NULL
);
1086 for (c
= 0; c
< 4; c
++) {
1087 if (!(mask
& (1 << c
)))
1089 emit_flr(pc
, temp
, src
[0][c
]);
1090 emit_sub(pc
, dst
[c
], src
[0][c
], temp
);
1092 free_temp(pc
, temp
);
1094 case TGSI_OPCODE_KIL
:
1095 emit_kil(pc
, src
[0][0]);
1096 emit_kil(pc
, src
[0][1]);
1097 emit_kil(pc
, src
[0][2]);
1098 emit_kil(pc
, src
[0][3]);
1100 case TGSI_OPCODE_LIT
:
1101 emit_lit(pc
, &dst
[0], mask
, &src
[0][0]);
1103 case TGSI_OPCODE_LG2
:
1104 temp
= alloc_temp(pc
, NULL
);
1105 emit_flop(pc
, 3, temp
, src
[0][0]);
1106 for (c
= 0; c
< 4; c
++) {
1107 if (!(mask
& (1 << c
)))
1109 emit_mov(pc
, dst
[c
], temp
);
1112 case TGSI_OPCODE_LRP
:
1113 for (c
= 0; c
< 4; c
++) {
1114 if (!(mask
& (1 << c
)))
1116 /*XXX: we can do better than this */
1117 temp
= alloc_temp(pc
, NULL
);
1118 emit_neg(pc
, temp
, src
[0][c
]);
1119 emit_mad(pc
, temp
, temp
, src
[2][c
], src
[2][c
]);
1120 emit_mad(pc
, dst
[c
], src
[0][c
], src
[1][c
], temp
);
1121 free_temp(pc
, temp
);
1124 case TGSI_OPCODE_MAD
:
1125 for (c
= 0; c
< 4; c
++) {
1126 if (!(mask
& (1 << c
)))
1128 emit_mad(pc
, dst
[c
], src
[0][c
], src
[1][c
], src
[2][c
]);
1131 case TGSI_OPCODE_MAX
:
1132 for (c
= 0; c
< 4; c
++) {
1133 if (!(mask
& (1 << c
)))
1135 emit_minmax(pc
, 4, dst
[c
], src
[0][c
], src
[1][c
]);
1138 case TGSI_OPCODE_MIN
:
1139 for (c
= 0; c
< 4; c
++) {
1140 if (!(mask
& (1 << c
)))
1142 emit_minmax(pc
, 5, dst
[c
], src
[0][c
], src
[1][c
]);
1145 case TGSI_OPCODE_MOV
:
1146 for (c
= 0; c
< 4; c
++) {
1147 if (!(mask
& (1 << c
)))
1149 emit_mov(pc
, dst
[c
], src
[0][c
]);
1152 case TGSI_OPCODE_MUL
:
1153 for (c
= 0; c
< 4; c
++) {
1154 if (!(mask
& (1 << c
)))
1156 emit_mul(pc
, dst
[c
], src
[0][c
], src
[1][c
]);
1159 case TGSI_OPCODE_POW
:
1160 temp
= alloc_temp(pc
, NULL
);
1161 emit_pow(pc
, temp
, src
[0][0], src
[1][0]);
1162 for (c
= 0; c
< 4; c
++) {
1163 if (!(mask
& (1 << c
)))
1165 emit_mov(pc
, dst
[c
], temp
);
1167 free_temp(pc
, temp
);
1169 case TGSI_OPCODE_RCP
:
1170 for (c
= 0; c
< 4; c
++) {
1171 if (!(mask
& (1 << c
)))
1173 emit_flop(pc
, 0, dst
[c
], src
[0][0]);
1176 case TGSI_OPCODE_RSQ
:
1177 for (c
= 0; c
< 4; c
++) {
1178 if (!(mask
& (1 << c
)))
1180 emit_flop(pc
, 2, dst
[c
], src
[0][0]);
1183 case TGSI_OPCODE_SCS
:
1184 temp
= alloc_temp(pc
, NULL
);
1185 emit_precossin(pc
, temp
, src
[0][0]);
1186 if (mask
& (1 << 0))
1187 emit_flop(pc
, 5, dst
[0], temp
);
1188 if (mask
& (1 << 1))
1189 emit_flop(pc
, 4, dst
[1], temp
);
1191 case TGSI_OPCODE_SGE
:
1192 for (c
= 0; c
< 4; c
++) {
1193 if (!(mask
& (1 << c
)))
1195 emit_set(pc
, 6, dst
[c
], src
[0][c
], src
[1][c
]);
1198 case TGSI_OPCODE_SIN
:
1199 temp
= alloc_temp(pc
, NULL
);
1200 emit_precossin(pc
, temp
, src
[0][0]);
1201 emit_flop(pc
, 4, temp
, temp
);
1202 for (c
= 0; c
< 4; c
++) {
1203 if (!(mask
& (1 << c
)))
1205 emit_mov(pc
, dst
[c
], temp
);
1208 case TGSI_OPCODE_SLT
:
1209 for (c
= 0; c
< 4; c
++) {
1210 if (!(mask
& (1 << c
)))
1212 emit_set(pc
, 1, dst
[c
], src
[0][c
], src
[1][c
]);
1215 case TGSI_OPCODE_SUB
:
1216 for (c
= 0; c
< 4; c
++) {
1217 if (!(mask
& (1 << c
)))
1219 emit_sub(pc
, dst
[c
], src
[0][c
], src
[1][c
]);
1222 case TGSI_OPCODE_TEX
:
1223 case TGSI_OPCODE_TXP
:
1225 struct nv50_reg
*t
[4];
1226 struct nv50_program_exec
*e
;
1228 alloc_temp4(pc
, t
, 0);
1229 emit_mov(pc
, t
[0], src
[0][0]);
1230 emit_mov(pc
, t
[1], src
[0][1]);
1233 e
->inst
[0] = 0xf6400000;
1234 e
->inst
[0] |= (unit
<< 9);
1236 e
->inst
[1] |= 0x0000c004;
1237 set_dst(pc
, t
[0], e
);
1240 if (mask
& (1 << 0)) emit_mov(pc
, dst
[0], t
[0]);
1241 if (mask
& (1 << 1)) emit_mov(pc
, dst
[1], t
[1]);
1242 if (mask
& (1 << 2)) emit_mov(pc
, dst
[2], t
[2]);
1243 if (mask
& (1 << 3)) emit_mov(pc
, dst
[3], t
[3]);
1248 case TGSI_OPCODE_XPD
:
1249 temp
= alloc_temp(pc
, NULL
);
1250 if (mask
& (1 << 0)) {
1251 emit_mul(pc
, temp
, src
[0][2], src
[1][1]);
1252 emit_msb(pc
, dst
[0], src
[0][1], src
[1][2], temp
);
1254 if (mask
& (1 << 1)) {
1255 emit_mul(pc
, temp
, src
[0][0], src
[1][2]);
1256 emit_msb(pc
, dst
[1], src
[0][2], src
[1][0], temp
);
1258 if (mask
& (1 << 2)) {
1259 emit_mul(pc
, temp
, src
[0][1], src
[1][0]);
1260 emit_msb(pc
, dst
[2], src
[0][0], src
[1][1], temp
);
1262 free_temp(pc
, temp
);
1264 case TGSI_OPCODE_END
:
1267 NOUVEAU_ERR("invalid opcode %d\n", inst
->Instruction
.Opcode
);
1272 for (c
= 0; c
< 4; c
++) {
1273 struct nv50_program_exec
*e
;
1275 if (!(mask
& (1 << c
)))
1279 e
->inst
[0] = 0xa0000000; /* cvt */
1281 e
->inst
[1] |= (6 << 29); /* cvt */
1282 e
->inst
[1] |= 0x04000000; /* 32 bit */
1283 e
->inst
[1] |= (1 << 14); /* src .f32 */
1284 e
->inst
[1] |= ((1 << 5) << 14); /* .sat */
1285 set_dst(pc
, rdst
[c
], e
);
1286 set_src_0(pc
, dst
[c
], e
);
1296 nv50_program_tx_prep(struct nv50_pc
*pc
)
1298 struct tgsi_parse_context p
;
1299 boolean ret
= FALSE
;
1302 tgsi_parse_init(&p
, pc
->p
->pipe
.tokens
);
1303 while (!tgsi_parse_end_of_tokens(&p
)) {
1304 const union tgsi_full_token
*tok
= &p
.FullToken
;
1306 tgsi_parse_token(&p
);
1307 switch (tok
->Token
.Type
) {
1308 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1310 const struct tgsi_full_immediate
*imm
=
1311 &p
.FullToken
.FullImmediate
;
1313 ctor_immd(pc
, imm
->u
.ImmediateFloat32
[0].Float
,
1314 imm
->u
.ImmediateFloat32
[1].Float
,
1315 imm
->u
.ImmediateFloat32
[2].Float
,
1316 imm
->u
.ImmediateFloat32
[3].Float
);
1319 case TGSI_TOKEN_TYPE_DECLARATION
:
1321 const struct tgsi_full_declaration
*d
;
1324 d
= &p
.FullToken
.FullDeclaration
;
1325 last
= d
->DeclarationRange
.Last
;
1327 switch (d
->Declaration
.File
) {
1328 case TGSI_FILE_TEMPORARY
:
1329 if (pc
->temp_nr
< (last
+ 1))
1330 pc
->temp_nr
= last
+ 1;
1332 case TGSI_FILE_OUTPUT
:
1333 if (pc
->result_nr
< (last
+ 1))
1334 pc
->result_nr
= last
+ 1;
1336 case TGSI_FILE_INPUT
:
1337 if (pc
->attr_nr
< (last
+ 1))
1338 pc
->attr_nr
= last
+ 1;
1340 case TGSI_FILE_CONSTANT
:
1341 if (pc
->param_nr
< (last
+ 1))
1342 pc
->param_nr
= last
+ 1;
1344 case TGSI_FILE_SAMPLER
:
1347 NOUVEAU_ERR("bad decl file %d\n",
1348 d
->Declaration
.File
);
1353 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1361 pc
->temp
= CALLOC(pc
->temp_nr
* 4, sizeof(struct nv50_reg
));
1365 for (i
= 0; i
< pc
->temp_nr
; i
++) {
1366 for (c
= 0; c
< 4; c
++) {
1367 pc
->temp
[i
*4+c
].type
= P_TEMP
;
1368 pc
->temp
[i
*4+c
].hw
= -1;
1369 pc
->temp
[i
*4+c
].index
= i
;
1375 struct nv50_reg
*iv
= NULL
;
1378 pc
->attr
= CALLOC(pc
->attr_nr
* 4, sizeof(struct nv50_reg
));
1382 if (pc
->p
->type
== PIPE_SHADER_FRAGMENT
) {
1383 iv
= alloc_temp(pc
, NULL
);
1384 emit_interp(pc
, iv
, iv
, NULL
);
1385 emit_flop(pc
, 0, iv
, iv
);
1389 for (i
= 0; i
< pc
->attr_nr
; i
++) {
1390 struct nv50_reg
*a
= &pc
->attr
[i
*4];
1392 for (c
= 0; c
< 4; c
++) {
1393 if (pc
->p
->type
== PIPE_SHADER_FRAGMENT
) {
1394 struct nv50_reg
*at
=
1395 alloc_temp(pc
, NULL
);
1396 pc
->attr
[i
*4+c
].type
= at
->type
;
1397 pc
->attr
[i
*4+c
].hw
= at
->hw
;
1398 pc
->attr
[i
*4+c
].index
= at
->index
;
1400 pc
->p
->cfg
.vp
.attr
[aid
/32] |=
1402 pc
->attr
[i
*4+c
].type
= P_ATTR
;
1403 pc
->attr
[i
*4+c
].hw
= aid
++;
1404 pc
->attr
[i
*4+c
].index
= i
;
1408 if (pc
->p
->type
!= PIPE_SHADER_FRAGMENT
)
1411 emit_interp(pc
, &a
[0], &a
[0], iv
);
1412 emit_interp(pc
, &a
[1], &a
[1], iv
);
1413 emit_interp(pc
, &a
[2], &a
[2], iv
);
1414 emit_interp(pc
, &a
[3], &a
[3], iv
);
1421 if (pc
->result_nr
) {
1424 pc
->result
= CALLOC(pc
->result_nr
* 4, sizeof(struct nv50_reg
));
1428 for (i
= 0; i
< pc
->result_nr
; i
++) {
1429 for (c
= 0; c
< 4; c
++) {
1430 if (pc
->p
->type
== PIPE_SHADER_FRAGMENT
) {
1431 pc
->result
[i
*4+c
].type
= P_TEMP
;
1432 pc
->result
[i
*4+c
].hw
= -1;
1434 pc
->result
[i
*4+c
].type
= P_RESULT
;
1435 pc
->result
[i
*4+c
].hw
= rid
++;
1437 pc
->result
[i
*4+c
].index
= i
;
1445 pc
->param
= CALLOC(pc
->param_nr
* 4, sizeof(struct nv50_reg
));
1449 for (i
= 0; i
< pc
->param_nr
; i
++) {
1450 for (c
= 0; c
< 4; c
++) {
1451 pc
->param
[i
*4+c
].type
= P_CONST
;
1452 pc
->param
[i
*4+c
].hw
= rid
++;
1453 pc
->param
[i
*4+c
].index
= i
;
1459 int rid
= pc
->param_nr
* 4;
1461 pc
->immd
= CALLOC(pc
->immd_nr
* 4, sizeof(struct nv50_reg
));
1465 for (i
= 0; i
< pc
->immd_nr
; i
++) {
1466 for (c
= 0; c
< 4; c
++) {
1467 pc
->immd
[i
*4+c
].type
= P_IMMD
;
1468 pc
->immd
[i
*4+c
].hw
= rid
++;
1469 pc
->immd
[i
*4+c
].index
= i
;
1476 tgsi_parse_free(&p
);
1481 nv50_program_tx(struct nv50_program
*p
)
1483 struct tgsi_parse_context parse
;
1487 pc
= CALLOC_STRUCT(nv50_pc
);
1491 pc
->p
->cfg
.high_temp
= 4;
1493 ret
= nv50_program_tx_prep(pc
);
1497 tgsi_parse_init(&parse
, pc
->p
->pipe
.tokens
);
1498 while (!tgsi_parse_end_of_tokens(&parse
)) {
1499 const union tgsi_full_token
*tok
= &parse
.FullToken
;
1501 tgsi_parse_token(&parse
);
1503 switch (tok
->Token
.Type
) {
1504 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1505 ret
= nv50_program_tx_insn(pc
, tok
);
1514 if (p
->type
== PIPE_SHADER_FRAGMENT
) {
1515 struct nv50_reg out
;
1518 for (out
.hw
= 0; out
.hw
< pc
->result_nr
* 4; out
.hw
++)
1519 emit_mov(pc
, &out
, &pc
->result
[out
.hw
]);
1522 assert(is_long(pc
->p
->exec_tail
) && !is_immd(pc
->p
->exec_head
));
1523 pc
->p
->exec_tail
->inst
[1] |= 0x00000001;
1525 p
->param_nr
= pc
->param_nr
* 4;
1526 p
->immd_nr
= pc
->immd_nr
* 4;
1527 p
->immd
= pc
->immd_buf
;
1530 tgsi_parse_free(&parse
);
1537 nv50_program_validate(struct nv50_context
*nv50
, struct nv50_program
*p
)
1539 if (nv50_program_tx(p
) == FALSE
)
1541 p
->translated
= TRUE
;
1545 nv50_program_upload_data(struct nv50_context
*nv50
, float *map
,
1546 unsigned start
, unsigned count
)
1549 unsigned nr
= count
> 2047 ? 2047 : count
;
1551 BEGIN_RING(tesla
, 0x00000f00, 1);
1552 OUT_RING ((NV50_CB_PMISC
<< 0) | (start
<< 8));
1553 BEGIN_RING(tesla
, 0x40000f04, nr
);
1554 OUT_RINGp (map
, nr
);
1563 nv50_program_validate_data(struct nv50_context
*nv50
, struct nv50_program
*p
)
1565 struct nouveau_winsys
*nvws
= nv50
->screen
->nvws
;
1566 struct pipe_winsys
*ws
= nv50
->pipe
.winsys
;
1567 unsigned nr
= p
->param_nr
+ p
->immd_nr
;
1569 if (!p
->data
&& nr
) {
1570 struct nouveau_resource
*heap
= nv50
->screen
->vp_data_heap
;
1572 if (nvws
->res_alloc(heap
, nr
, p
, &p
->data
)) {
1573 while (heap
->next
&& heap
->size
< nr
) {
1574 struct nv50_program
*evict
= heap
->next
->priv
;
1575 nvws
->res_free(&evict
->data
);
1578 if (nvws
->res_alloc(heap
, nr
, p
, &p
->data
))
1584 float *map
= ws
->buffer_map(ws
, nv50
->constbuf
[p
->type
],
1585 PIPE_BUFFER_USAGE_CPU_READ
);
1586 nv50_program_upload_data(nv50
, map
, p
->data
->start
,
1588 ws
->buffer_unmap(ws
, nv50
->constbuf
[p
->type
]);
1592 nv50_program_upload_data(nv50
, p
->immd
,
1593 p
->data
->start
+ p
->param_nr
,
1599 nv50_program_validate_code(struct nv50_context
*nv50
, struct nv50_program
*p
)
1601 struct pipe_winsys
*ws
= nv50
->pipe
.winsys
;
1602 struct nv50_program_exec
*e
;
1603 struct nouveau_stateobj
*so
;
1604 const unsigned flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_WR
;
1605 unsigned start
, count
, *up
, *ptr
;
1606 boolean upload
= FALSE
;
1609 p
->buffer
= ws
->buffer_create(ws
, 0x100, 0, p
->exec_size
* 4);
1613 if (p
->data
&& p
->data
->start
!= p
->data_start
) {
1614 for (e
= p
->exec_head
; e
; e
= e
->next
) {
1617 if (e
->param
.index
< 0)
1619 ei
= e
->param
.shift
>> 5;
1620 ci
= e
->param
.index
+ p
->data
->start
;
1622 e
->inst
[ei
] &= ~e
->param
.mask
;
1623 e
->inst
[ei
] |= (ci
<< e
->param
.shift
);
1626 p
->data_start
= p
->data
->start
;
1633 #ifdef NV50_PROGRAM_DUMP
1634 NOUVEAU_ERR("-------\n");
1635 up
= ptr
= MALLOC(p
->exec_size
* 4);
1636 for (e
= p
->exec_head
; e
; e
= e
->next
) {
1637 NOUVEAU_ERR("0x%08x\n", e
->inst
[0]);
1639 NOUVEAU_ERR("0x%08x\n", e
->inst
[1]);
1644 up
= ptr
= MALLOC(p
->exec_size
* 4);
1645 for (e
= p
->exec_head
; e
; e
= e
->next
) {
1646 *(ptr
++) = e
->inst
[0];
1648 *(ptr
++) = e
->inst
[1];
1652 so_method(so
, nv50
->screen
->tesla
, 0x1280, 3);
1653 so_reloc (so
, p
->buffer
, 0, flags
| NOUVEAU_BO_HIGH
, 0, 0);
1654 so_reloc (so
, p
->buffer
, 0, flags
| NOUVEAU_BO_LOW
, 0, 0);
1655 so_data (so
, (NV50_CB_PUPLOAD
<< 16) | 0x0800); //(p->exec_size * 4));
1657 start
= 0; count
= p
->exec_size
;
1659 struct nouveau_winsys
*nvws
= nv50
->screen
->nvws
;
1664 nr
= MIN2(count
, 2047);
1665 nr
= MIN2(nvws
->channel
->pushbuf
->remaining
, nr
);
1666 if (nvws
->channel
->pushbuf
->remaining
< (nr
+ 3)) {
1671 BEGIN_RING(tesla
, 0x0f00, 1);
1672 OUT_RING ((start
<< 8) | NV50_CB_PUPLOAD
);
1673 BEGIN_RING(tesla
, 0x40000f04, nr
);
1674 OUT_RINGp (up
+ start
, nr
);
1685 nv50_vertprog_validate(struct nv50_context
*nv50
)
1687 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
1688 struct nv50_program
*p
= nv50
->vertprog
;
1689 struct nouveau_stateobj
*so
;
1691 if (!p
->translated
) {
1692 nv50_program_validate(nv50
, p
);
1697 nv50_program_validate_data(nv50
, p
);
1698 nv50_program_validate_code(nv50
, p
);
1701 so_method(so
, tesla
, NV50TCL_VP_ADDRESS_HIGH
, 2);
1702 so_reloc (so
, p
->buffer
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
1703 NOUVEAU_BO_HIGH
, 0, 0);
1704 so_reloc (so
, p
->buffer
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
1705 NOUVEAU_BO_LOW
, 0, 0);
1706 so_method(so
, tesla
, 0x1650, 2);
1707 so_data (so
, p
->cfg
.vp
.attr
[0]);
1708 so_data (so
, p
->cfg
.vp
.attr
[1]);
1709 so_method(so
, tesla
, 0x16b8, 1);
1710 so_data (so
, p
->cfg
.high_result
);
1711 so_method(so
, tesla
, 0x16ac, 2);
1712 so_data (so
, p
->cfg
.high_result
); //8);
1713 so_data (so
, p
->cfg
.high_temp
);
1714 so_method(so
, tesla
, 0x140c, 1);
1715 so_data (so
, 0); /* program start offset */
1716 so_ref(so
, &nv50
->state
.vertprog
);
1720 nv50_fragprog_validate(struct nv50_context
*nv50
)
1722 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
1723 struct nv50_program
*p
= nv50
->fragprog
;
1724 struct nouveau_stateobj
*so
;
1726 if (!p
->translated
) {
1727 nv50_program_validate(nv50
, p
);
1732 nv50_program_validate_data(nv50
, p
);
1733 nv50_program_validate_code(nv50
, p
);
1736 so_method(so
, tesla
, NV50TCL_FP_ADDRESS_HIGH
, 2);
1737 so_reloc (so
, p
->buffer
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
1738 NOUVEAU_BO_HIGH
, 0, 0);
1739 so_reloc (so
, p
->buffer
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
1740 NOUVEAU_BO_LOW
, 0, 0);
1741 so_method(so
, tesla
, 0x1904, 4);
1742 so_data (so
, 0x00040404); /* p: 0x01000404 */
1743 so_data (so
, 0x00000004);
1744 so_data (so
, 0x00000000);
1745 so_data (so
, 0x00000000);
1746 so_method(so
, tesla
, 0x16bc, 3); /*XXX: fixme */
1747 so_data (so
, 0x03020100);
1748 so_data (so
, 0x07060504);
1749 so_data (so
, 0x0b0a0908);
1750 so_method(so
, tesla
, 0x1988, 2);
1751 so_data (so
, 0x08080408); //0x08040404); /* p: 0x0f000401 */
1752 so_data (so
, p
->cfg
.high_temp
);
1753 so_method(so
, tesla
, 0x1414, 1);
1754 so_data (so
, 0); /* program start offset */
1755 so_ref(so
, &nv50
->state
.fragprog
);
1759 nv50_program_destroy(struct nv50_context
*nv50
, struct nv50_program
*p
)
1761 struct pipe_screen
*pscreen
= nv50
->pipe
.screen
;
1763 while (p
->exec_head
) {
1764 struct nv50_program_exec
*e
= p
->exec_head
;
1766 p
->exec_head
= e
->next
;
1769 p
->exec_tail
= NULL
;
1773 pipe_buffer_reference(pscreen
, &p
->buffer
, NULL
);
1775 nv50
->screen
->nvws
->res_free(&p
->data
);