2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_opcodes.h"
25 #include "r600_formats.h"
26 #include "r600_shader.h"
31 #include "util/u_memory.h"
32 #include "pipe/p_shader_tokens.h"
34 #define NUM_OF_CYCLES 3
35 #define NUM_OF_COMPONENTS 4
37 static inline unsigned int r600_bytecode_get_num_operands(
38 struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
40 return r600_isa_alu(alu
->op
)->src_count
;
43 int r700_bytecode_alu_build(struct r600_bytecode
*bc
,
44 struct r600_bytecode_alu
*alu
, unsigned id
);
46 static struct r600_bytecode_cf
*r600_bytecode_cf(void)
48 struct r600_bytecode_cf
*cf
= CALLOC_STRUCT(r600_bytecode_cf
);
52 LIST_INITHEAD(&cf
->list
);
53 LIST_INITHEAD(&cf
->alu
);
54 LIST_INITHEAD(&cf
->vtx
);
55 LIST_INITHEAD(&cf
->tex
);
59 static struct r600_bytecode_alu
*r600_bytecode_alu(void)
61 struct r600_bytecode_alu
*alu
= CALLOC_STRUCT(r600_bytecode_alu
);
65 LIST_INITHEAD(&alu
->list
);
69 static struct r600_bytecode_vtx
*r600_bytecode_vtx(void)
71 struct r600_bytecode_vtx
*vtx
= CALLOC_STRUCT(r600_bytecode_vtx
);
75 LIST_INITHEAD(&vtx
->list
);
79 static struct r600_bytecode_tex
*r600_bytecode_tex(void)
81 struct r600_bytecode_tex
*tex
= CALLOC_STRUCT(r600_bytecode_tex
);
85 LIST_INITHEAD(&tex
->list
);
89 void r600_bytecode_init(struct r600_bytecode
*bc
,
90 enum chip_class chip_class
,
91 enum radeon_family family
,
92 enum r600_msaa_texture_mode msaa_texture_mode
)
94 if ((chip_class
== R600
) &&
95 (family
!= CHIP_RV670
&& family
!= CHIP_RS780
&& family
!= CHIP_RS880
)) {
96 bc
->ar_handling
= AR_HANDLE_RV6XX
;
97 bc
->r6xx_nop_after_rel_dst
= 1;
99 bc
->ar_handling
= AR_HANDLE_NORMAL
;
100 bc
->r6xx_nop_after_rel_dst
= 0;
103 LIST_INITHEAD(&bc
->cf
);
104 bc
->chip_class
= chip_class
;
105 bc
->msaa_texture_mode
= msaa_texture_mode
;
108 static int r600_bytecode_add_cf(struct r600_bytecode
*bc
)
110 struct r600_bytecode_cf
*cf
= r600_bytecode_cf();
114 LIST_ADDTAIL(&cf
->list
, &bc
->cf
);
116 cf
->id
= bc
->cf_last
->id
+ 2;
117 if (bc
->cf_last
->eg_alu_extended
) {
118 /* take into account extended alu size */
126 bc
->force_add_cf
= 0;
131 int r600_bytecode_add_output(struct r600_bytecode
*bc
,
132 const struct r600_bytecode_output
*output
)
136 if (output
->gpr
>= bc
->ngpr
)
137 bc
->ngpr
= output
->gpr
+ 1;
139 if (bc
->cf_last
&& (bc
->cf_last
->op
== output
->op
||
140 (bc
->cf_last
->op
== CF_OP_EXPORT
&&
141 output
->op
== CF_OP_EXPORT_DONE
)) &&
142 output
->type
== bc
->cf_last
->output
.type
&&
143 output
->elem_size
== bc
->cf_last
->output
.elem_size
&&
144 output
->swizzle_x
== bc
->cf_last
->output
.swizzle_x
&&
145 output
->swizzle_y
== bc
->cf_last
->output
.swizzle_y
&&
146 output
->swizzle_z
== bc
->cf_last
->output
.swizzle_z
&&
147 output
->swizzle_w
== bc
->cf_last
->output
.swizzle_w
&&
148 (output
->burst_count
+ bc
->cf_last
->output
.burst_count
) <= 16) {
150 if ((output
->gpr
+ output
->burst_count
) == bc
->cf_last
->output
.gpr
&&
151 (output
->array_base
+ output
->burst_count
) == bc
->cf_last
->output
.array_base
) {
153 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
154 bc
->cf_last
->op
= bc
->cf_last
->output
.op
= output
->op
;
155 bc
->cf_last
->output
.gpr
= output
->gpr
;
156 bc
->cf_last
->output
.array_base
= output
->array_base
;
157 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
160 } else if (output
->gpr
== (bc
->cf_last
->output
.gpr
+ bc
->cf_last
->output
.burst_count
) &&
161 output
->array_base
== (bc
->cf_last
->output
.array_base
+ bc
->cf_last
->output
.burst_count
)) {
163 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
164 bc
->cf_last
->op
= bc
->cf_last
->output
.op
= output
->op
;
165 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
170 r
= r600_bytecode_add_cf(bc
);
173 bc
->cf_last
->op
= output
->op
;
174 memcpy(&bc
->cf_last
->output
, output
, sizeof(struct r600_bytecode_output
));
178 /* alu instructions that can ony exits once per group */
179 static int is_alu_once_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
181 return r600_isa_alu(alu
->op
)->flags
& (AF_KILL
| AF_PRED
);
184 static int is_alu_reduction_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
186 return (r600_isa_alu(alu
->op
)->flags
& AF_REPL
) &&
187 (r600_isa_alu_slots(bc
->isa
->hw_class
, alu
->op
) == AF_4V
);
190 static int is_alu_mova_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
192 return r600_isa_alu(alu
->op
)->flags
& AF_MOVA
;
195 static int alu_uses_rel(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
197 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
204 for (src
= 0; src
< num_src
; ++src
) {
205 if (alu
->src
[src
].rel
) {
212 static int is_alu_vec_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
214 unsigned slots
= r600_isa_alu_slots(bc
->isa
->hw_class
, alu
->op
);
215 return !(slots
& AF_S
);
218 static int is_alu_trans_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
220 unsigned slots
= r600_isa_alu_slots(bc
->isa
->hw_class
, alu
->op
);
221 return !(slots
& AF_V
);
224 /* alu instructions that can execute on any unit */
225 static int is_alu_any_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
227 unsigned slots
= r600_isa_alu_slots(bc
->isa
->hw_class
, alu
->op
);
228 return slots
== AF_VS
;
231 static int is_nop_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
233 return alu
->op
== ALU_OP0_NOP
;
236 static int assign_alu_units(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu_first
,
237 struct r600_bytecode_alu
*assignment
[5])
239 struct r600_bytecode_alu
*alu
;
240 unsigned i
, chan
, trans
;
241 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
243 for (i
= 0; i
< max_slots
; i
++)
244 assignment
[i
] = NULL
;
246 for (alu
= alu_first
; alu
; alu
= LIST_ENTRY(struct r600_bytecode_alu
, alu
->list
.next
, list
)) {
247 chan
= alu
->dst
.chan
;
250 else if (is_alu_trans_unit_inst(bc
, alu
))
252 else if (is_alu_vec_unit_inst(bc
, alu
))
254 else if (assignment
[chan
])
255 trans
= 1; /* Assume ALU_INST_PREFER_VECTOR. */
261 assert(0); /* ALU.Trans has already been allocated. */
266 if (assignment
[chan
]) {
267 assert(0); /* ALU.chan has already been allocated. */
270 assignment
[chan
] = alu
;
279 struct alu_bank_swizzle
{
280 int hw_gpr
[NUM_OF_CYCLES
][NUM_OF_COMPONENTS
];
281 int hw_cfile_addr
[4];
282 int hw_cfile_elem
[4];
285 static const unsigned cycle_for_bank_swizzle_vec
[][3] = {
286 [SQ_ALU_VEC_012
] = { 0, 1, 2 },
287 [SQ_ALU_VEC_021
] = { 0, 2, 1 },
288 [SQ_ALU_VEC_120
] = { 1, 2, 0 },
289 [SQ_ALU_VEC_102
] = { 1, 0, 2 },
290 [SQ_ALU_VEC_201
] = { 2, 0, 1 },
291 [SQ_ALU_VEC_210
] = { 2, 1, 0 }
294 static const unsigned cycle_for_bank_swizzle_scl
[][3] = {
295 [SQ_ALU_SCL_210
] = { 2, 1, 0 },
296 [SQ_ALU_SCL_122
] = { 1, 2, 2 },
297 [SQ_ALU_SCL_212
] = { 2, 1, 2 },
298 [SQ_ALU_SCL_221
] = { 2, 2, 1 }
301 static void init_bank_swizzle(struct alu_bank_swizzle
*bs
)
303 int i
, cycle
, component
;
305 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
306 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
307 bs
->hw_gpr
[cycle
][component
] = -1;
308 for (i
= 0; i
< 4; i
++)
309 bs
->hw_cfile_addr
[i
] = -1;
310 for (i
= 0; i
< 4; i
++)
311 bs
->hw_cfile_elem
[i
] = -1;
314 static int reserve_gpr(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
, unsigned cycle
)
316 if (bs
->hw_gpr
[cycle
][chan
] == -1)
317 bs
->hw_gpr
[cycle
][chan
] = sel
;
318 else if (bs
->hw_gpr
[cycle
][chan
] != (int)sel
) {
319 /* Another scalar operation has already used the GPR read port for the channel. */
325 static int reserve_cfile(struct r600_bytecode
*bc
, struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
)
327 int res
, num_res
= 4;
328 if (bc
->chip_class
>= R700
) {
332 for (res
= 0; res
< num_res
; ++res
) {
333 if (bs
->hw_cfile_addr
[res
] == -1) {
334 bs
->hw_cfile_addr
[res
] = sel
;
335 bs
->hw_cfile_elem
[res
] = chan
;
337 } else if (bs
->hw_cfile_addr
[res
] == sel
&&
338 bs
->hw_cfile_elem
[res
] == chan
)
339 return 0; /* Read for this scalar element already reserved, nothing to do here. */
341 /* All cfile read ports are used, cannot reference vector element. */
345 static int is_gpr(unsigned sel
)
347 return (sel
>= 0 && sel
<= 127);
350 /* CB constants start at 512, and get translated to a kcache index when ALU
351 * clauses are constructed. Note that we handle kcache constants the same way
352 * as (the now gone) cfile constants, is that really required? */
353 static int is_cfile(unsigned sel
)
355 return (sel
> 255 && sel
< 512) ||
356 (sel
> 511 && sel
< 4607) || /* Kcache before translation. */
357 (sel
> 127 && sel
< 192); /* Kcache after translation. */
360 static int is_const(int sel
)
362 return is_cfile(sel
) ||
363 (sel
>= V_SQ_ALU_SRC_0
&&
364 sel
<= V_SQ_ALU_SRC_LITERAL
);
367 static int check_vector(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
368 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
370 int r
, src
, num_src
, sel
, elem
, cycle
;
372 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
373 for (src
= 0; src
< num_src
; src
++) {
374 sel
= alu
->src
[src
].sel
;
375 elem
= alu
->src
[src
].chan
;
377 cycle
= cycle_for_bank_swizzle_vec
[bank_swizzle
][src
];
378 if (src
== 1 && sel
== alu
->src
[0].sel
&& elem
== alu
->src
[0].chan
)
379 /* Nothing to do; special-case optimization,
380 * second source uses first source’s reservation. */
383 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
387 } else if (is_cfile(sel
)) {
388 r
= reserve_cfile(bc
, bs
, (alu
->src
[src
].kc_bank
<<16) + sel
, elem
);
392 /* No restrictions on PV, PS, literal or special constants. */
397 static int check_scalar(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
398 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
400 int r
, src
, num_src
, const_count
, sel
, elem
, cycle
;
402 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
403 for (const_count
= 0, src
= 0; src
< num_src
; ++src
) {
404 sel
= alu
->src
[src
].sel
;
405 elem
= alu
->src
[src
].chan
;
406 if (is_const(sel
)) { /* Any constant, including literal and inline constants. */
407 if (const_count
>= 2)
408 /* More than two references to a constant in
409 * transcendental operation. */
415 r
= reserve_cfile(bc
, bs
, (alu
->src
[src
].kc_bank
<<16) + sel
, elem
);
420 for (src
= 0; src
< num_src
; ++src
) {
421 sel
= alu
->src
[src
].sel
;
422 elem
= alu
->src
[src
].chan
;
424 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
425 if (cycle
< const_count
)
426 /* Cycle for GPR load conflicts with
427 * constant load in transcendental operation. */
429 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
433 /* PV PS restrictions */
434 if (const_count
&& (sel
== 254 || sel
== 255)) {
435 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
436 if (cycle
< const_count
)
443 static int check_and_set_bank_swizzle(struct r600_bytecode
*bc
,
444 struct r600_bytecode_alu
*slots
[5])
446 struct alu_bank_swizzle bs
;
448 int i
, r
= 0, forced
= 1;
449 boolean scalar_only
= bc
->chip_class
== CAYMAN
? false : true;
450 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
452 for (i
= 0; i
< max_slots
; i
++) {
454 if (slots
[i
]->bank_swizzle_force
) {
455 slots
[i
]->bank_swizzle
= slots
[i
]->bank_swizzle_force
;
461 if (i
< 4 && slots
[i
])
467 /* Just check every possible combination of bank swizzle.
468 * Not very efficent, but works on the first try in most of the cases. */
469 for (i
= 0; i
< 4; i
++)
470 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
)
471 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
473 bank_swizzle
[i
] = slots
[i
]->bank_swizzle
;
475 bank_swizzle
[4] = SQ_ALU_SCL_210
;
476 while(bank_swizzle
[4] <= SQ_ALU_SCL_221
) {
478 if (max_slots
== 4) {
479 for (i
= 0; i
< max_slots
; i
++) {
480 if (bank_swizzle
[i
] == SQ_ALU_VEC_210
)
484 init_bank_swizzle(&bs
);
485 if (scalar_only
== false) {
486 for (i
= 0; i
< 4; i
++) {
488 r
= check_vector(bc
, slots
[i
], &bs
, bank_swizzle
[i
]);
496 if (!r
&& slots
[4] && max_slots
== 5) {
497 r
= check_scalar(bc
, slots
[4], &bs
, bank_swizzle
[4]);
500 for (i
= 0; i
< max_slots
; i
++) {
502 slots
[i
]->bank_swizzle
= bank_swizzle
[i
];
510 for (i
= 0; i
< max_slots
; i
++) {
511 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
) {
513 if (bank_swizzle
[i
] <= SQ_ALU_VEC_210
)
516 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
522 /* Couldn't find a working swizzle. */
526 static int replace_gpr_with_pv_ps(struct r600_bytecode
*bc
,
527 struct r600_bytecode_alu
*slots
[5], struct r600_bytecode_alu
*alu_prev
)
529 struct r600_bytecode_alu
*prev
[5];
531 int i
, j
, r
, src
, num_src
;
532 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
534 r
= assign_alu_units(bc
, alu_prev
, prev
);
538 for (i
= 0; i
< max_slots
; ++i
) {
539 if (prev
[i
] && (prev
[i
]->dst
.write
|| prev
[i
]->is_op3
) && !prev
[i
]->dst
.rel
) {
540 gpr
[i
] = prev
[i
]->dst
.sel
;
541 /* cube writes more than PV.X */
542 if (is_alu_reduction_inst(bc
, prev
[i
]))
545 chan
[i
] = prev
[i
]->dst
.chan
;
550 for (i
= 0; i
< max_slots
; ++i
) {
551 struct r600_bytecode_alu
*alu
= slots
[i
];
555 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
556 for (src
= 0; src
< num_src
; ++src
) {
557 if (!is_gpr(alu
->src
[src
].sel
) || alu
->src
[src
].rel
)
560 if (bc
->chip_class
< CAYMAN
) {
561 if (alu
->src
[src
].sel
== gpr
[4] &&
562 alu
->src
[src
].chan
== chan
[4] &&
563 alu_prev
->pred_sel
== alu
->pred_sel
) {
564 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PS
;
565 alu
->src
[src
].chan
= 0;
570 for (j
= 0; j
< 4; ++j
) {
571 if (alu
->src
[src
].sel
== gpr
[j
] &&
572 alu
->src
[src
].chan
== j
&&
573 alu_prev
->pred_sel
== alu
->pred_sel
) {
574 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PV
;
575 alu
->src
[src
].chan
= chan
[j
];
585 void r600_bytecode_special_constants(uint32_t value
, unsigned *sel
, unsigned *neg
)
589 *sel
= V_SQ_ALU_SRC_0
;
592 *sel
= V_SQ_ALU_SRC_1_INT
;
595 *sel
= V_SQ_ALU_SRC_M_1_INT
;
597 case 0x3F800000: /* 1.0f */
598 *sel
= V_SQ_ALU_SRC_1
;
600 case 0x3F000000: /* 0.5f */
601 *sel
= V_SQ_ALU_SRC_0_5
;
603 case 0xBF800000: /* -1.0f */
604 *sel
= V_SQ_ALU_SRC_1
;
607 case 0xBF000000: /* -0.5f */
608 *sel
= V_SQ_ALU_SRC_0_5
;
612 *sel
= V_SQ_ALU_SRC_LITERAL
;
617 /* compute how many literal are needed */
618 static int r600_bytecode_alu_nliterals(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
619 uint32_t literal
[4], unsigned *nliteral
)
621 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
624 for (i
= 0; i
< num_src
; ++i
) {
625 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
626 uint32_t value
= alu
->src
[i
].value
;
628 for (j
= 0; j
< *nliteral
; ++j
) {
629 if (literal
[j
] == value
) {
637 literal
[(*nliteral
)++] = value
;
644 static void r600_bytecode_alu_adjust_literals(struct r600_bytecode
*bc
,
645 struct r600_bytecode_alu
*alu
,
646 uint32_t literal
[4], unsigned nliteral
)
648 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
651 for (i
= 0; i
< num_src
; ++i
) {
652 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
653 uint32_t value
= alu
->src
[i
].value
;
654 for (j
= 0; j
< nliteral
; ++j
) {
655 if (literal
[j
] == value
) {
656 alu
->src
[i
].chan
= j
;
664 static int merge_inst_groups(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*slots
[5],
665 struct r600_bytecode_alu
*alu_prev
)
667 struct r600_bytecode_alu
*prev
[5];
668 struct r600_bytecode_alu
*result
[5] = { NULL
};
670 uint32_t literal
[4], prev_literal
[4];
671 unsigned nliteral
= 0, prev_nliteral
= 0;
673 int i
, j
, r
, src
, num_src
;
674 int num_once_inst
= 0;
675 int have_mova
= 0, have_rel
= 0;
676 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
678 r
= assign_alu_units(bc
, alu_prev
, prev
);
682 for (i
= 0; i
< max_slots
; ++i
) {
684 if (prev
[i
]->pred_sel
)
686 if (is_alu_once_inst(bc
, prev
[i
]))
690 if (slots
[i
]->pred_sel
)
692 if (is_alu_once_inst(bc
, slots
[i
]))
697 for (i
= 0; i
< max_slots
; ++i
) {
698 struct r600_bytecode_alu
*alu
;
700 if (num_once_inst
> 0)
703 /* check number of literals */
705 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], literal
, &nliteral
))
707 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], prev_literal
, &prev_nliteral
))
709 if (is_alu_mova_inst(bc
, prev
[i
])) {
715 if (alu_uses_rel(bc
, prev
[i
])) {
722 num_once_inst
+= is_alu_once_inst(bc
, prev
[i
]);
724 if (slots
[i
] && r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
))
727 /* Let's check used slots. */
728 if (prev
[i
] && !slots
[i
]) {
731 } else if (prev
[i
] && slots
[i
]) {
732 if (max_slots
== 5 && result
[4] == NULL
&& prev
[4] == NULL
&& slots
[4] == NULL
) {
733 /* Trans unit is still free try to use it. */
734 if (is_alu_any_unit_inst(bc
, slots
[i
])) {
736 result
[4] = slots
[i
];
737 } else if (is_alu_any_unit_inst(bc
, prev
[i
])) {
738 if (slots
[i
]->dst
.sel
== prev
[i
]->dst
.sel
&&
739 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
740 (prev
[i
]->dst
.write
== 1 || prev
[i
]->is_op3
))
743 result
[i
] = slots
[i
];
749 } else if(!slots
[i
]) {
752 if (max_slots
== 5 && slots
[i
] && prev
[4] &&
753 slots
[i
]->dst
.sel
== prev
[4]->dst
.sel
&&
754 slots
[i
]->dst
.chan
== prev
[4]->dst
.chan
&&
755 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
756 (prev
[4]->dst
.write
== 1 || prev
[4]->is_op3
))
759 result
[i
] = slots
[i
];
763 num_once_inst
+= is_alu_once_inst(bc
, alu
);
765 /* don't reschedule NOPs */
766 if (is_nop_inst(bc
, alu
))
769 if (is_alu_mova_inst(bc
, alu
)) {
776 if (alu_uses_rel(bc
, alu
)) {
783 /* Let's check source gprs */
784 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
785 for (src
= 0; src
< num_src
; ++src
) {
787 /* Constants don't matter. */
788 if (!is_gpr(alu
->src
[src
].sel
))
791 for (j
= 0; j
< max_slots
; ++j
) {
792 if (!prev
[j
] || !(prev
[j
]->dst
.write
|| prev
[j
]->is_op3
))
795 /* If it's relative then we can't determin which gpr is really used. */
796 if (prev
[j
]->dst
.chan
== alu
->src
[src
].chan
&&
797 (prev
[j
]->dst
.sel
== alu
->src
[src
].sel
||
798 prev
[j
]->dst
.rel
|| alu
->src
[src
].rel
))
804 /* more than one PRED_ or KILL_ ? */
805 if (num_once_inst
> 1)
808 /* check if the result can still be swizzlet */
809 r
= check_and_set_bank_swizzle(bc
, result
);
813 /* looks like everything worked out right, apply the changes */
815 /* undo adding previus literals */
816 bc
->cf_last
->ndw
-= align(prev_nliteral
, 2);
818 /* sort instructions */
819 for (i
= 0; i
< max_slots
; ++i
) {
820 slots
[i
] = result
[i
];
822 LIST_DEL(&result
[i
]->list
);
824 LIST_ADDTAIL(&result
[i
]->list
, &bc
->cf_last
->alu
);
828 /* determine new last instruction */
829 LIST_ENTRY(struct r600_bytecode_alu
, bc
->cf_last
->alu
.prev
, list
)->last
= 1;
831 /* determine new first instruction */
832 for (i
= 0; i
< max_slots
; ++i
) {
834 bc
->cf_last
->curr_bs_head
= result
[i
];
839 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->prev2_bs_head
;
840 bc
->cf_last
->prev2_bs_head
= NULL
;
845 /* we'll keep kcache sets sorted by bank & addr */
846 static int r600_bytecode_alloc_kcache_line(struct r600_bytecode
*bc
,
847 struct r600_bytecode_kcache
*kcache
,
848 unsigned bank
, unsigned line
)
850 int i
, kcache_banks
= bc
->chip_class
>= EVERGREEN
? 4 : 2;
852 for (i
= 0; i
< kcache_banks
; i
++) {
853 if (kcache
[i
].mode
) {
856 if (kcache
[i
].bank
< bank
)
859 if ((kcache
[i
].bank
== bank
&& kcache
[i
].addr
> line
+1) ||
860 kcache
[i
].bank
> bank
) {
861 /* try to insert new line */
862 if (kcache
[kcache_banks
-1].mode
) {
863 /* all sets are in use */
867 memmove(&kcache
[i
+1],&kcache
[i
], (kcache_banks
-i
-1)*sizeof(struct r600_bytecode_kcache
));
868 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_1
;
869 kcache
[i
].bank
= bank
;
870 kcache
[i
].addr
= line
;
874 d
= line
- kcache
[i
].addr
;
878 if (kcache
[i
].mode
== V_SQ_CF_KCACHE_LOCK_2
) {
879 /* we are prepending the line to the current set,
880 * discarding the existing second line,
881 * so we'll have to insert line+2 after it */
884 } else if (kcache
[i
].mode
== V_SQ_CF_KCACHE_LOCK_1
) {
885 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
888 /* V_SQ_CF_KCACHE_LOCK_LOOP_INDEX is not supported */
892 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
896 } else { /* free kcache set - use it */
897 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_1
;
898 kcache
[i
].bank
= bank
;
899 kcache
[i
].addr
= line
;
906 static int r600_bytecode_alloc_inst_kcache_lines(struct r600_bytecode
*bc
,
907 struct r600_bytecode_kcache
*kcache
,
908 struct r600_bytecode_alu
*alu
)
912 for (i
= 0; i
< 3; i
++) {
913 unsigned bank
, line
, sel
= alu
->src
[i
].sel
;
918 bank
= alu
->src
[i
].kc_bank
;
921 if ((r
= r600_bytecode_alloc_kcache_line(bc
, kcache
, bank
, line
)))
927 static int r600_bytecode_assign_kcache_banks(struct r600_bytecode
*bc
,
928 struct r600_bytecode_alu
*alu
,
929 struct r600_bytecode_kcache
* kcache
)
933 /* Alter the src operands to refer to the kcache. */
934 for (i
= 0; i
< 3; ++i
) {
935 static const unsigned int base
[] = {128, 160, 256, 288};
936 unsigned int line
, sel
= alu
->src
[i
].sel
, found
= 0;
944 for (j
= 0; j
< 4 && !found
; ++j
) {
945 switch (kcache
[j
].mode
) {
946 case V_SQ_CF_KCACHE_NOP
:
947 case V_SQ_CF_KCACHE_LOCK_LOOP_INDEX
:
948 R600_ERR("unexpected kcache line mode\n");
951 if (kcache
[j
].bank
== alu
->src
[i
].kc_bank
&&
952 kcache
[j
].addr
<= line
&&
953 line
< kcache
[j
].addr
+ kcache
[j
].mode
) {
954 alu
->src
[i
].sel
= sel
- (kcache
[j
].addr
<<4);
955 alu
->src
[i
].sel
+= base
[j
];
964 static int r600_bytecode_alloc_kcache_lines(struct r600_bytecode
*bc
,
965 struct r600_bytecode_alu
*alu
,
968 struct r600_bytecode_kcache kcache_sets
[4];
969 struct r600_bytecode_kcache
*kcache
= kcache_sets
;
972 memcpy(kcache
, bc
->cf_last
->kcache
, 4 * sizeof(struct r600_bytecode_kcache
));
974 if ((r
= r600_bytecode_alloc_inst_kcache_lines(bc
, kcache
, alu
))) {
975 /* can't alloc, need to start new clause */
976 if ((r
= r600_bytecode_add_cf(bc
))) {
979 bc
->cf_last
->op
= type
;
981 /* retry with the new clause */
982 kcache
= bc
->cf_last
->kcache
;
983 if ((r
= r600_bytecode_alloc_inst_kcache_lines(bc
, kcache
, alu
))) {
984 /* can't alloc again- should never happen */
988 /* update kcache sets */
989 memcpy(bc
->cf_last
->kcache
, kcache
, 4 * sizeof(struct r600_bytecode_kcache
));
992 /* if we actually used more than 2 kcache sets - use ALU_EXTENDED on eg+ */
993 if (kcache
[2].mode
!= V_SQ_CF_KCACHE_NOP
) {
994 if (bc
->chip_class
< EVERGREEN
)
996 bc
->cf_last
->eg_alu_extended
= 1;
1002 static int insert_nop_r6xx(struct r600_bytecode
*bc
)
1004 struct r600_bytecode_alu alu
;
1007 for (i
= 0; i
< 4; i
++) {
1008 memset(&alu
, 0, sizeof(alu
));
1009 alu
.op
= ALU_OP0_NOP
;
1010 alu
.src
[0].chan
= i
;
1012 alu
.last
= (i
== 3);
1013 r
= r600_bytecode_add_alu(bc
, &alu
);
1020 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
1021 static int load_ar_r6xx(struct r600_bytecode
*bc
)
1023 struct r600_bytecode_alu alu
;
1029 /* hack to avoid making MOVA the last instruction in the clause */
1030 if ((bc
->cf_last
->ndw
>>1) >= 110)
1031 bc
->force_add_cf
= 1;
1033 memset(&alu
, 0, sizeof(alu
));
1034 alu
.op
= ALU_OP1_MOVA_GPR_INT
;
1035 alu
.src
[0].sel
= bc
->ar_reg
;
1036 alu
.src
[0].chan
= bc
->ar_chan
;
1038 alu
.index_mode
= INDEX_MODE_LOOP
;
1039 r
= r600_bytecode_add_alu(bc
, &alu
);
1043 /* no requirement to set uses waterfall on MOVA_GPR_INT */
1048 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
1049 static int load_ar(struct r600_bytecode
*bc
)
1051 struct r600_bytecode_alu alu
;
1054 if (bc
->ar_handling
)
1055 return load_ar_r6xx(bc
);
1060 /* hack to avoid making MOVA the last instruction in the clause */
1061 if ((bc
->cf_last
->ndw
>>1) >= 110)
1062 bc
->force_add_cf
= 1;
1064 memset(&alu
, 0, sizeof(alu
));
1065 alu
.op
= ALU_OP1_MOVA_INT
;
1066 alu
.src
[0].sel
= bc
->ar_reg
;
1067 alu
.src
[0].chan
= bc
->ar_chan
;
1069 r
= r600_bytecode_add_alu(bc
, &alu
);
1073 bc
->cf_last
->r6xx_uses_waterfall
= 1;
1078 int r600_bytecode_add_alu_type(struct r600_bytecode
*bc
,
1079 const struct r600_bytecode_alu
*alu
, unsigned type
)
1081 struct r600_bytecode_alu
*nalu
= r600_bytecode_alu();
1082 struct r600_bytecode_alu
*lalu
;
1087 memcpy(nalu
, alu
, sizeof(struct r600_bytecode_alu
));
1089 if (bc
->cf_last
!= NULL
&& bc
->cf_last
->op
!= type
) {
1090 /* check if we could add it anyway */
1091 if (bc
->cf_last
->op
== CF_OP_ALU
&&
1092 type
== CF_OP_ALU_PUSH_BEFORE
) {
1093 LIST_FOR_EACH_ENTRY(lalu
, &bc
->cf_last
->alu
, list
) {
1094 if (lalu
->execute_mask
) {
1095 bc
->force_add_cf
= 1;
1100 bc
->force_add_cf
= 1;
1103 /* cf can contains only alu or only vtx or only tex */
1104 if (bc
->cf_last
== NULL
|| bc
->force_add_cf
) {
1105 r
= r600_bytecode_add_cf(bc
);
1111 bc
->cf_last
->op
= type
;
1113 /* Check AR usage and load it if required */
1114 for (i
= 0; i
< 3; i
++)
1115 if (nalu
->src
[i
].rel
&& !bc
->ar_loaded
)
1118 if (nalu
->dst
.rel
&& !bc
->ar_loaded
)
1121 /* Setup the kcache for this ALU instruction. This will start a new
1122 * ALU clause if needed. */
1123 if ((r
= r600_bytecode_alloc_kcache_lines(bc
, nalu
, type
))) {
1128 if (!bc
->cf_last
->curr_bs_head
) {
1129 bc
->cf_last
->curr_bs_head
= nalu
;
1131 /* number of gpr == the last gpr used in any alu */
1132 for (i
= 0; i
< 3; i
++) {
1133 if (nalu
->src
[i
].sel
>= bc
->ngpr
&& nalu
->src
[i
].sel
< 128) {
1134 bc
->ngpr
= nalu
->src
[i
].sel
+ 1;
1136 if (nalu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
)
1137 r600_bytecode_special_constants(nalu
->src
[i
].value
,
1138 &nalu
->src
[i
].sel
, &nalu
->src
[i
].neg
);
1140 if (nalu
->dst
.sel
>= bc
->ngpr
) {
1141 bc
->ngpr
= nalu
->dst
.sel
+ 1;
1143 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
1144 /* each alu use 2 dwords */
1145 bc
->cf_last
->ndw
+= 2;
1148 /* process cur ALU instructions for bank swizzle */
1150 uint32_t literal
[4];
1152 struct r600_bytecode_alu
*slots
[5];
1153 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
1154 r
= assign_alu_units(bc
, bc
->cf_last
->curr_bs_head
, slots
);
1158 if (bc
->cf_last
->prev_bs_head
) {
1159 r
= merge_inst_groups(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1164 if (bc
->cf_last
->prev_bs_head
) {
1165 r
= replace_gpr_with_pv_ps(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1170 r
= check_and_set_bank_swizzle(bc
, slots
);
1174 for (i
= 0, nliteral
= 0; i
< max_slots
; i
++) {
1176 r
= r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
);
1181 bc
->cf_last
->ndw
+= align(nliteral
, 2);
1183 /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots)
1185 if ((bc
->cf_last
->ndw
>> 1) >= 120) {
1186 bc
->force_add_cf
= 1;
1189 bc
->cf_last
->prev2_bs_head
= bc
->cf_last
->prev_bs_head
;
1190 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->curr_bs_head
;
1191 bc
->cf_last
->curr_bs_head
= NULL
;
1194 if (nalu
->dst
.rel
&& bc
->r6xx_nop_after_rel_dst
)
1195 insert_nop_r6xx(bc
);
1200 int r600_bytecode_add_alu(struct r600_bytecode
*bc
, const struct r600_bytecode_alu
*alu
)
1202 return r600_bytecode_add_alu_type(bc
, alu
, CF_OP_ALU
);
1205 static unsigned r600_bytecode_num_tex_and_vtx_instructions(const struct r600_bytecode
*bc
)
1207 switch (bc
->chip_class
) {
1217 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1222 static inline boolean
last_inst_was_not_vtx_fetch(struct r600_bytecode
*bc
)
1224 return !((r600_isa_cf(bc
->cf_last
->op
)->flags
& CF_FETCH
) &&
1225 (bc
->chip_class
== CAYMAN
||
1226 bc
->cf_last
->op
!= CF_OP_TEX
));
1229 int r600_bytecode_add_vtx(struct r600_bytecode
*bc
, const struct r600_bytecode_vtx
*vtx
)
1231 struct r600_bytecode_vtx
*nvtx
= r600_bytecode_vtx();
1236 memcpy(nvtx
, vtx
, sizeof(struct r600_bytecode_vtx
));
1238 /* cf can contains only alu or only vtx or only tex */
1239 if (bc
->cf_last
== NULL
||
1240 last_inst_was_not_vtx_fetch(bc
) ||
1242 r
= r600_bytecode_add_cf(bc
);
1247 switch (bc
->chip_class
) {
1251 bc
->cf_last
->op
= CF_OP_VTX
;
1254 bc
->cf_last
->op
= CF_OP_TEX
;
1257 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1262 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
1263 /* each fetch use 4 dwords */
1264 bc
->cf_last
->ndw
+= 4;
1266 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1267 bc
->force_add_cf
= 1;
1269 bc
->ngpr
= MAX2(bc
->ngpr
, vtx
->src_gpr
+ 1);
1270 bc
->ngpr
= MAX2(bc
->ngpr
, vtx
->dst_gpr
+ 1);
1275 int r600_bytecode_add_tex(struct r600_bytecode
*bc
, const struct r600_bytecode_tex
*tex
)
1277 struct r600_bytecode_tex
*ntex
= r600_bytecode_tex();
1282 memcpy(ntex
, tex
, sizeof(struct r600_bytecode_tex
));
1284 /* we can't fetch data und use it as texture lookup address in the same TEX clause */
1285 if (bc
->cf_last
!= NULL
&&
1286 bc
->cf_last
->op
== CF_OP_TEX
) {
1287 struct r600_bytecode_tex
*ttex
;
1288 LIST_FOR_EACH_ENTRY(ttex
, &bc
->cf_last
->tex
, list
) {
1289 if (ttex
->dst_gpr
== ntex
->src_gpr
) {
1290 bc
->force_add_cf
= 1;
1294 /* slight hack to make gradients always go into same cf */
1295 if (ntex
->op
== FETCH_OP_SET_GRADIENTS_H
)
1296 bc
->force_add_cf
= 1;
1299 /* cf can contains only alu or only vtx or only tex */
1300 if (bc
->cf_last
== NULL
||
1301 bc
->cf_last
->op
!= CF_OP_TEX
||
1303 r
= r600_bytecode_add_cf(bc
);
1308 bc
->cf_last
->op
= CF_OP_TEX
;
1310 if (ntex
->src_gpr
>= bc
->ngpr
) {
1311 bc
->ngpr
= ntex
->src_gpr
+ 1;
1313 if (ntex
->dst_gpr
>= bc
->ngpr
) {
1314 bc
->ngpr
= ntex
->dst_gpr
+ 1;
1316 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
1317 /* each texture fetch use 4 dwords */
1318 bc
->cf_last
->ndw
+= 4;
1320 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1321 bc
->force_add_cf
= 1;
1325 int r600_bytecode_add_cfinst(struct r600_bytecode
*bc
, unsigned op
)
1328 r
= r600_bytecode_add_cf(bc
);
1332 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
1333 bc
->cf_last
->op
= op
;
1337 int cm_bytecode_add_cf_end(struct r600_bytecode
*bc
)
1339 return r600_bytecode_add_cfinst(bc
, CF_OP_CF_END
);
1342 /* common to all 3 families */
1343 static int r600_bytecode_vtx_build(struct r600_bytecode
*bc
, struct r600_bytecode_vtx
*vtx
, unsigned id
)
1345 bc
->bytecode
[id
] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
) |
1346 S_SQ_VTX_WORD0_FETCH_TYPE(vtx
->fetch_type
) |
1347 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
1348 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
);
1349 if (bc
->chip_class
< CAYMAN
)
1350 bc
->bytecode
[id
] |= S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
1352 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
1353 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
1354 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
1355 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
1356 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
1357 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
1358 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
1359 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
1360 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
1361 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
1362 bc
->bytecode
[id
] = S_SQ_VTX_WORD2_OFFSET(vtx
->offset
)|
1363 S_SQ_VTX_WORD2_ENDIAN_SWAP(vtx
->endian
);
1364 if (bc
->chip_class
< CAYMAN
)
1365 bc
->bytecode
[id
] |= S_SQ_VTX_WORD2_MEGA_FETCH(1);
1367 bc
->bytecode
[id
++] = 0;
1371 /* common to all 3 families */
1372 static int r600_bytecode_tex_build(struct r600_bytecode
*bc
, struct r600_bytecode_tex
*tex
, unsigned id
)
1374 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(
1375 r600_isa_fetch_opcode(bc
->isa
->hw_class
, tex
->op
)) |
1376 EG_S_SQ_TEX_WORD0_INST_MOD(tex
->inst_mod
) |
1377 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
1378 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
1379 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
1380 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
1381 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
1382 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
1383 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
1384 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
1385 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
1386 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
1387 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
1388 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
1389 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
1390 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
1391 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
1392 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
1393 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
1394 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
1395 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
1396 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
1397 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
1398 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
1399 bc
->bytecode
[id
++] = 0;
1403 /* r600 only, r700/eg bits in r700_asm.c */
1404 static int r600_bytecode_alu_build(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, unsigned id
)
1406 unsigned opcode
= r600_isa_alu_opcode(bc
->isa
->hw_class
, alu
->op
);
1408 /* don't replace gpr by pv or ps for destination register */
1409 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
1410 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
1411 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
1412 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
1413 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
1414 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
1415 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
1416 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
1417 S_SQ_ALU_WORD0_INDEX_MODE(alu
->index_mode
) |
1418 S_SQ_ALU_WORD0_PRED_SEL(alu
->pred_sel
) |
1419 S_SQ_ALU_WORD0_LAST(alu
->last
);
1422 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1423 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1424 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1425 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1426 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
1427 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
1428 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
1429 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
1430 S_SQ_ALU_WORD1_OP3_ALU_INST(opcode
) |
1431 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
1433 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1434 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1435 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1436 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1437 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
1438 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
1439 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
1440 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
1441 S_SQ_ALU_WORD1_OP2_ALU_INST(opcode
) |
1442 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
1443 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->execute_mask
) |
1444 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->update_pred
);
1449 static void r600_bytecode_cf_vtx_build(uint32_t *bytecode
, const struct r600_bytecode_cf
*cf
)
1451 *bytecode
++ = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
1452 *bytecode
++ = S_SQ_CF_WORD1_CF_INST(r600_isa_cf_opcode(ISA_CC_R600
, cf
->op
)) |
1453 S_SQ_CF_WORD1_BARRIER(1) |
1454 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
1457 /* common for r600/r700 - eg in eg_asm.c */
1458 static int r600_bytecode_cf_build(struct r600_bytecode
*bc
, struct r600_bytecode_cf
*cf
)
1460 unsigned id
= cf
->id
;
1461 const struct cf_op_info
*cfop
= r600_isa_cf(cf
->op
);
1462 unsigned opcode
= r600_isa_cf_opcode(bc
->isa
->hw_class
, cf
->op
);
1464 if (cfop
->flags
& CF_ALU
) {
1465 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
1466 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache
[0].mode
) |
1467 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache
[0].bank
) |
1468 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache
[1].bank
);
1470 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD1_CF_INST(opcode
) |
1471 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache
[1].mode
) |
1472 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache
[0].addr
) |
1473 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache
[1].addr
) |
1474 S_SQ_CF_ALU_WORD1_BARRIER(1) |
1475 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chip_class
== R600
? cf
->r6xx_uses_waterfall
: 0) |
1476 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
1477 } else if (cfop
->flags
& CF_FETCH
) {
1478 if (bc
->chip_class
== R700
)
1479 r700_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1481 r600_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1482 } else if (cfop
->flags
& CF_EXP
) {
1483 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1484 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1485 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1486 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1487 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1488 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
1489 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
1490 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
1491 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
1492 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1493 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(opcode
) |
1494 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
1495 } else if (cfop
->flags
& CF_STRM
) {
1496 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1497 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1498 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1499 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1500 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1501 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1502 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(opcode
) |
1503 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
) |
1504 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(cf
->output
.array_size
) |
1505 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(cf
->output
.comp_mask
);
1507 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
1508 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(opcode
) |
1509 S_SQ_CF_WORD1_BARRIER(1) |
1510 S_SQ_CF_WORD1_COND(cf
->cond
) |
1511 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
1516 int r600_bytecode_build(struct r600_bytecode
*bc
)
1518 struct r600_bytecode_cf
*cf
;
1519 struct r600_bytecode_alu
*alu
;
1520 struct r600_bytecode_vtx
*vtx
;
1521 struct r600_bytecode_tex
*tex
;
1522 uint32_t literal
[4];
1527 if (bc
->callstack
[0].max
> 0)
1528 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
1529 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
1533 /* first path compute addr of each CF block */
1534 /* addr start after all the CF instructions */
1535 addr
= bc
->cf_last
->id
+ 2;
1536 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1537 if (r600_isa_cf(cf
->op
)->flags
& CF_FETCH
) {
1539 addr
&= 0xFFFFFFFCUL
;
1543 bc
->ndw
= cf
->addr
+ cf
->ndw
;
1546 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
1547 if (bc
->bytecode
== NULL
)
1549 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1550 const struct cf_op_info
*cfop
= r600_isa_cf(cf
->op
);
1552 if (bc
->chip_class
>= EVERGREEN
)
1553 r
= eg_bytecode_cf_build(bc
, cf
);
1555 r
= r600_bytecode_cf_build(bc
, cf
);
1558 if (cfop
->flags
& CF_ALU
) {
1560 memset(literal
, 0, sizeof(literal
));
1561 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1562 r
= r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1565 r600_bytecode_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
1566 r600_bytecode_assign_kcache_banks(bc
, alu
, cf
->kcache
);
1568 switch(bc
->chip_class
) {
1570 r
= r600_bytecode_alu_build(bc
, alu
, addr
);
1573 case EVERGREEN
: /* eg alu is same encoding as r700 */
1575 r
= r700_bytecode_alu_build(bc
, alu
, addr
);
1578 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
1585 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
1586 bc
->bytecode
[addr
++] = literal
[i
];
1589 memset(literal
, 0, sizeof(literal
));
1592 } else if (cf
->op
== CF_OP_VTX
) {
1593 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1594 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
1599 } else if (cf
->op
== CF_OP_TEX
) {
1600 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1601 assert(bc
->chip_class
>= EVERGREEN
);
1602 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
1607 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1608 r
= r600_bytecode_tex_build(bc
, tex
, addr
);
1618 void r600_bytecode_clear(struct r600_bytecode
*bc
)
1620 struct r600_bytecode_cf
*cf
= NULL
, *next_cf
;
1623 bc
->bytecode
= NULL
;
1625 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
1626 struct r600_bytecode_alu
*alu
= NULL
, *next_alu
;
1627 struct r600_bytecode_tex
*tex
= NULL
, *next_tex
;
1628 struct r600_bytecode_tex
*vtx
= NULL
, *next_vtx
;
1630 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
1634 LIST_INITHEAD(&cf
->alu
);
1636 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
1640 LIST_INITHEAD(&cf
->tex
);
1642 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
1646 LIST_INITHEAD(&cf
->vtx
);
1651 LIST_INITHEAD(&cf
->list
);
1654 void r600_bytecode_dump(struct r600_bytecode
*bc
)
1656 struct r600_bytecode_cf
*cf
= NULL
;
1657 struct r600_bytecode_alu
*alu
= NULL
;
1658 struct r600_bytecode_vtx
*vtx
= NULL
;
1659 struct r600_bytecode_tex
*tex
= NULL
;
1662 uint32_t literal
[4];
1666 switch (bc
->chip_class
) {
1681 fprintf(stderr
, "bytecode %d dw -- %d gprs ---------------------\n", bc
->ndw
, bc
->ngpr
);
1682 fprintf(stderr
, " %c\n", chip
);
1684 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1686 if (cf
->op
== CF_NATIVE
) {
1687 fprintf(stderr
, "%04d %08X CF NATIVE\n", id
, bc
->bytecode
[id
]);
1688 fprintf(stderr
, "%04d %08X CF NATIVE\n", id
+ 1, bc
->bytecode
[id
+ 1]);
1690 const struct cf_op_info
*cfop
= r600_isa_cf(cf
->op
);
1691 if (cfop
->flags
& CF_ALU
) {
1692 if (cf
->eg_alu_extended
) {
1693 fprintf(stderr
, "%04d %08X ALU_EXT0 ", id
, bc
->bytecode
[id
]);
1694 fprintf(stderr
, "KCACHE_BANK2:%X ", cf
->kcache
[2].bank
);
1695 fprintf(stderr
, "KCACHE_BANK3:%X ", cf
->kcache
[3].bank
);
1696 fprintf(stderr
, "KCACHE_MODE2:%X\n", cf
->kcache
[2].mode
);
1698 fprintf(stderr
, "%04d %08X ALU_EXT1 ", id
, bc
->bytecode
[id
]);
1699 fprintf(stderr
, "KCACHE_MODE3:%X ", cf
->kcache
[3].mode
);
1700 fprintf(stderr
, "KCACHE_ADDR2:%X ", cf
->kcache
[2].addr
);
1701 fprintf(stderr
, "KCACHE_ADDR3:%X\n", cf
->kcache
[3].addr
);
1705 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1706 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
1707 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
1708 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
1709 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
1711 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1712 fprintf(stderr
, "INST: %s ", cfop
->name
);
1713 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
1714 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
1715 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
1716 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
1717 } else if (cfop
->flags
& CF_FETCH
) {
1718 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1719 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
1721 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1722 fprintf(stderr
, "INST: %s ", cfop
->name
);
1723 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
1724 } else if (cfop
->flags
& CF_EXP
) {
1725 fprintf(stderr
, "%04d %08X %s ", id
, bc
->bytecode
[id
],
1727 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
1728 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
1729 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
1730 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
1732 fprintf(stderr
, "%04d %08X %s ", id
, bc
->bytecode
[id
],
1734 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
1735 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
1736 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
1737 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
1738 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
1739 fprintf(stderr
, "INST: %s ", r600_isa_cf(cf
->op
)->name
);
1740 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
1741 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
1742 } else if (cfop
->flags
& CF_STRM
) {
1743 fprintf(stderr
, "%04d %08X EXPORT %s ", id
, bc
->bytecode
[id
],
1745 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
1746 fprintf(stderr
, "ELEM_SIZE:%i ", cf
->output
.elem_size
);
1747 fprintf(stderr
, "ARRAY_BASE:%i ", cf
->output
.array_base
);
1748 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
1750 fprintf(stderr
, "%04d %08X EXPORT %s ", id
, bc
->bytecode
[id
],
1752 fprintf(stderr
, "ARRAY_SIZE:%i ", cf
->output
.array_size
);
1753 fprintf(stderr
, "COMP_MASK:%X ", cf
->output
.comp_mask
);
1754 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
1755 fprintf(stderr
, "INST: %s ", cfop
->name
);
1756 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
1757 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
1760 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1761 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
1763 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1764 fprintf(stderr
, "INST: %s ", cfop
->name
);
1765 fprintf(stderr
, "COND:%X ", cf
->cond
);
1766 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
1772 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1773 r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1775 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1776 fprintf(stderr
, " SRC0(SEL:%d ", alu
->src
[0].sel
);
1777 fprintf(stderr
, "REL:%d ", alu
->src
[0].rel
);
1778 fprintf(stderr
, "CHAN:%d ", alu
->src
[0].chan
);
1779 fprintf(stderr
, "NEG:%d) ", alu
->src
[0].neg
);
1780 fprintf(stderr
, "SRC1(SEL:%d ", alu
->src
[1].sel
);
1781 fprintf(stderr
, "REL:%d ", alu
->src
[1].rel
);
1782 fprintf(stderr
, "CHAN:%d ", alu
->src
[1].chan
);
1783 fprintf(stderr
, "NEG:%d ", alu
->src
[1].neg
);
1784 fprintf(stderr
, "IM:%d) ", alu
->index_mode
);
1785 fprintf(stderr
, "PRED_SEL:%d ", alu
->pred_sel
);
1786 fprintf(stderr
, "LAST:%d)\n", alu
->last
);
1788 fprintf(stderr
, "%04d %08X %c ", id
, bc
->bytecode
[id
], alu
->last
? '*' : ' ');
1789 fprintf(stderr
, "INST: %s ", r600_isa_alu(alu
->op
)->name
);
1790 fprintf(stderr
, "DST(SEL:%d ", alu
->dst
.sel
);
1791 fprintf(stderr
, "CHAN:%d ", alu
->dst
.chan
);
1792 fprintf(stderr
, "REL:%d ", alu
->dst
.rel
);
1793 fprintf(stderr
, "CLAMP:%d) ", alu
->dst
.clamp
);
1794 fprintf(stderr
, "BANK_SWIZZLE:%d ", alu
->bank_swizzle
);
1796 fprintf(stderr
, "SRC2(SEL:%d ", alu
->src
[2].sel
);
1797 fprintf(stderr
, "REL:%d ", alu
->src
[2].rel
);
1798 fprintf(stderr
, "CHAN:%d ", alu
->src
[2].chan
);
1799 fprintf(stderr
, "NEG:%d)\n", alu
->src
[2].neg
);
1801 fprintf(stderr
, "SRC0_ABS:%d ", alu
->src
[0].abs
);
1802 fprintf(stderr
, "SRC1_ABS:%d ", alu
->src
[1].abs
);
1803 fprintf(stderr
, "WRITE_MASK:%d ", alu
->dst
.write
);
1804 fprintf(stderr
, "OMOD:%d ", alu
->omod
);
1805 fprintf(stderr
, "EXECUTE_MASK:%d ", alu
->execute_mask
);
1806 fprintf(stderr
, "UPDATE_PRED:%d\n", alu
->update_pred
);
1811 for (i
= 0; i
< nliteral
; i
++, id
++) {
1812 float *f
= (float*)(bc
->bytecode
+ id
);
1813 fprintf(stderr
, "%04d %08X\t%f (%d)\n", id
, bc
->bytecode
[id
], *f
,
1814 *(bc
->bytecode
+ id
));
1821 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1822 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1823 fprintf(stderr
, "INST: %s ", r600_isa_fetch(tex
->op
)->name
);
1824 fprintf(stderr
, "RESOURCE_ID:%d ", tex
->resource_id
);
1825 fprintf(stderr
, "SRC(GPR:%d ", tex
->src_gpr
);
1826 fprintf(stderr
, "REL:%d)\n", tex
->src_rel
);
1828 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1829 fprintf(stderr
, "DST(GPR:%d ", tex
->dst_gpr
);
1830 fprintf(stderr
, "REL:%d ", tex
->dst_rel
);
1831 fprintf(stderr
, "SEL_X:%d ", tex
->dst_sel_x
);
1832 fprintf(stderr
, "SEL_Y:%d ", tex
->dst_sel_y
);
1833 fprintf(stderr
, "SEL_Z:%d ", tex
->dst_sel_z
);
1834 fprintf(stderr
, "SEL_W:%d) ", tex
->dst_sel_w
);
1835 fprintf(stderr
, "LOD_BIAS:%d ", tex
->lod_bias
);
1836 fprintf(stderr
, "COORD_TYPE_X:%d ", tex
->coord_type_x
);
1837 fprintf(stderr
, "COORD_TYPE_Y:%d ", tex
->coord_type_y
);
1838 fprintf(stderr
, "COORD_TYPE_Z:%d ", tex
->coord_type_z
);
1839 fprintf(stderr
, "COORD_TYPE_W:%d\n", tex
->coord_type_w
);
1841 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1842 fprintf(stderr
, "OFFSET_X:%d ", tex
->offset_x
);
1843 fprintf(stderr
, "OFFSET_Y:%d ", tex
->offset_y
);
1844 fprintf(stderr
, "OFFSET_Z:%d ", tex
->offset_z
);
1845 fprintf(stderr
, "SAMPLER_ID:%d ", tex
->sampler_id
);
1846 fprintf(stderr
, "SRC(SEL_X:%d ", tex
->src_sel_x
);
1847 fprintf(stderr
, "SEL_Y:%d ", tex
->src_sel_y
);
1848 fprintf(stderr
, "SEL_Z:%d ", tex
->src_sel_z
);
1849 fprintf(stderr
, "SEL_W:%d)\n", tex
->src_sel_w
);
1851 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
1855 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1856 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1857 fprintf(stderr
, "INST: %s ", r600_isa_fetch(vtx
->op
)->name
);
1858 fprintf(stderr
, "FETCH_TYPE:%d ", vtx
->fetch_type
);
1859 fprintf(stderr
, "BUFFER_ID:%d\n", vtx
->buffer_id
);
1861 /* This assumes that no semantic fetches exist */
1862 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1863 fprintf(stderr
, "SRC(GPR:%d ", vtx
->src_gpr
);
1864 fprintf(stderr
, "SEL_X:%d) ", vtx
->src_sel_x
);
1865 if (bc
->chip_class
< CAYMAN
)
1866 fprintf(stderr
, "MEGA_FETCH_COUNT:%d ", vtx
->mega_fetch_count
);
1868 fprintf(stderr
, "SEL_Y:%d) ", 0);
1869 fprintf(stderr
, "DST(GPR:%d ", vtx
->dst_gpr
);
1870 fprintf(stderr
, "SEL_X:%d ", vtx
->dst_sel_x
);
1871 fprintf(stderr
, "SEL_Y:%d ", vtx
->dst_sel_y
);
1872 fprintf(stderr
, "SEL_Z:%d ", vtx
->dst_sel_z
);
1873 fprintf(stderr
, "SEL_W:%d) ", vtx
->dst_sel_w
);
1874 fprintf(stderr
, "USE_CONST_FIELDS:%d ", vtx
->use_const_fields
);
1875 fprintf(stderr
, "FORMAT(DATA:%d ", vtx
->data_format
);
1876 fprintf(stderr
, "NUM:%d ", vtx
->num_format_all
);
1877 fprintf(stderr
, "COMP:%d ", vtx
->format_comp_all
);
1878 fprintf(stderr
, "MODE:%d)\n", vtx
->srf_mode_all
);
1880 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1881 fprintf(stderr
, "ENDIAN:%d ", vtx
->endian
);
1882 fprintf(stderr
, "OFFSET:%d\n", vtx
->offset
);
1885 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
1890 fprintf(stderr
, "--------------------------------------\n");
1893 void r600_vertex_data_type(enum pipe_format pformat
,
1895 unsigned *num_format
, unsigned *format_comp
, unsigned *endian
)
1897 const struct util_format_description
*desc
;
1903 *endian
= ENDIAN_NONE
;
1905 desc
= util_format_description(pformat
);
1906 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
1910 /* Find the first non-VOID channel. */
1911 for (i
= 0; i
< 4; i
++) {
1912 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
1917 *endian
= r600_endian_swap(desc
->channel
[i
].size
);
1919 switch (desc
->channel
[i
].type
) {
1920 /* Half-floats, floats, ints */
1921 case UTIL_FORMAT_TYPE_FLOAT
:
1922 switch (desc
->channel
[i
].size
) {
1924 switch (desc
->nr_channels
) {
1926 *format
= FMT_16_FLOAT
;
1929 *format
= FMT_16_16_FLOAT
;
1933 *format
= FMT_16_16_16_16_FLOAT
;
1938 switch (desc
->nr_channels
) {
1940 *format
= FMT_32_FLOAT
;
1943 *format
= FMT_32_32_FLOAT
;
1946 *format
= FMT_32_32_32_FLOAT
;
1949 *format
= FMT_32_32_32_32_FLOAT
;
1958 case UTIL_FORMAT_TYPE_UNSIGNED
:
1960 case UTIL_FORMAT_TYPE_SIGNED
:
1961 switch (desc
->channel
[i
].size
) {
1963 switch (desc
->nr_channels
) {
1972 *format
= FMT_8_8_8_8
;
1977 if (desc
->nr_channels
!= 4)
1980 *format
= FMT_2_10_10_10
;
1983 switch (desc
->nr_channels
) {
1988 *format
= FMT_16_16
;
1992 *format
= FMT_16_16_16_16
;
1997 switch (desc
->nr_channels
) {
2002 *format
= FMT_32_32
;
2005 *format
= FMT_32_32_32
;
2008 *format
= FMT_32_32_32_32
;
2020 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2025 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
||
2026 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2027 if (!desc
->channel
[i
].normalized
) {
2028 if (desc
->channel
[i
].pure_integer
)
2036 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
2039 void *r600_create_vertex_fetch_shader(struct pipe_context
*ctx
,
2041 const struct pipe_vertex_element
*elements
)
2043 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2044 static int dump_shaders
= -1;
2045 struct r600_bytecode bc
;
2046 struct r600_bytecode_vtx vtx
;
2047 const struct util_format_description
*desc
;
2048 unsigned fetch_resource_start
= rctx
->chip_class
>= EVERGREEN
? 0 : 160;
2049 unsigned format
, num_format
, format_comp
, endian
;
2051 int i
, j
, r
, fs_size
;
2052 struct r600_fetch_shader
*shader
;
2056 memset(&bc
, 0, sizeof(bc
));
2057 r600_bytecode_init(&bc
, rctx
->chip_class
, rctx
->family
,
2058 rctx
->screen
->msaa_texture_support
);
2062 for (i
= 0; i
< count
; i
++) {
2063 if (elements
[i
].instance_divisor
> 1) {
2064 if (rctx
->chip_class
== CAYMAN
) {
2065 for (j
= 0; j
< 4; j
++) {
2066 struct r600_bytecode_alu alu
;
2067 memset(&alu
, 0, sizeof(alu
));
2068 alu
.op
= ALU_OP2_MULHI_UINT
;
2070 alu
.src
[0].chan
= 3;
2071 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2072 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2073 alu
.dst
.sel
= i
+ 1;
2075 alu
.dst
.write
= j
== 3;
2077 if ((r
= r600_bytecode_add_alu(&bc
, &alu
))) {
2078 r600_bytecode_clear(&bc
);
2083 struct r600_bytecode_alu alu
;
2084 memset(&alu
, 0, sizeof(alu
));
2085 alu
.op
= ALU_OP2_MULHI_UINT
;
2087 alu
.src
[0].chan
= 3;
2088 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2089 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2090 alu
.dst
.sel
= i
+ 1;
2094 if ((r
= r600_bytecode_add_alu(&bc
, &alu
))) {
2095 r600_bytecode_clear(&bc
);
2102 for (i
= 0; i
< count
; i
++) {
2103 r600_vertex_data_type(elements
[i
].src_format
,
2104 &format
, &num_format
, &format_comp
, &endian
);
2106 desc
= util_format_description(elements
[i
].src_format
);
2108 r600_bytecode_clear(&bc
);
2109 R600_ERR("unknown format %d\n", elements
[i
].src_format
);
2113 if (elements
[i
].src_offset
> 65535) {
2114 r600_bytecode_clear(&bc
);
2115 R600_ERR("too big src_offset: %u\n", elements
[i
].src_offset
);
2119 memset(&vtx
, 0, sizeof(vtx
));
2120 vtx
.buffer_id
= elements
[i
].vertex_buffer_index
+ fetch_resource_start
;
2121 vtx
.fetch_type
= elements
[i
].instance_divisor
? 1 : 0;
2122 vtx
.src_gpr
= elements
[i
].instance_divisor
> 1 ? i
+ 1 : 0;
2123 vtx
.src_sel_x
= elements
[i
].instance_divisor
? 3 : 0;
2124 vtx
.mega_fetch_count
= 0x1F;
2125 vtx
.dst_gpr
= i
+ 1;
2126 vtx
.dst_sel_x
= desc
->swizzle
[0];
2127 vtx
.dst_sel_y
= desc
->swizzle
[1];
2128 vtx
.dst_sel_z
= desc
->swizzle
[2];
2129 vtx
.dst_sel_w
= desc
->swizzle
[3];
2130 vtx
.data_format
= format
;
2131 vtx
.num_format_all
= num_format
;
2132 vtx
.format_comp_all
= format_comp
;
2133 vtx
.srf_mode_all
= 1;
2134 vtx
.offset
= elements
[i
].src_offset
;
2135 vtx
.endian
= endian
;
2137 if ((r
= r600_bytecode_add_vtx(&bc
, &vtx
))) {
2138 r600_bytecode_clear(&bc
);
2143 r600_bytecode_add_cfinst(&bc
, CF_OP_RET
);
2145 if ((r
= r600_bytecode_build(&bc
))) {
2146 r600_bytecode_clear(&bc
);
2150 if (dump_shaders
== -1)
2151 dump_shaders
= debug_get_bool_option("R600_DUMP_SHADERS", FALSE
);
2154 fprintf(stderr
, "--------------------------------------------------------------\n");
2155 r600_bytecode_dump(&bc
);
2156 fprintf(stderr
, "______________________________________________________________\n");
2161 /* Allocate the CSO. */
2162 shader
= CALLOC_STRUCT(r600_fetch_shader
);
2164 r600_bytecode_clear(&bc
);
2168 u_suballocator_alloc(rctx
->allocator_fetch_shader
, fs_size
, &shader
->offset
,
2169 (struct pipe_resource
**)&shader
->buffer
);
2170 if (!shader
->buffer
) {
2171 r600_bytecode_clear(&bc
);
2176 bytecode
= r600_buffer_mmap_sync_with_rings(rctx
, shader
->buffer
, PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_UNSYNCHRONIZED
);
2177 bytecode
+= shader
->offset
/ 4;
2179 if (R600_BIG_ENDIAN
) {
2180 for (i
= 0; i
< fs_size
/ 4; ++i
) {
2181 bytecode
[i
] = bswap_32(bc
.bytecode
[i
]);
2184 memcpy(bytecode
, bc
.bytecode
, fs_size
);
2186 rctx
->ws
->buffer_unmap(shader
->buffer
->cs_buf
);
2188 r600_bytecode_clear(&bc
);
2192 void r600_bytecode_alu_read(struct r600_bytecode
*bc
,
2193 struct r600_bytecode_alu
*alu
, uint32_t word0
, uint32_t word1
)
2196 alu
->src
[0].sel
= G_SQ_ALU_WORD0_SRC0_SEL(word0
);
2197 alu
->src
[0].rel
= G_SQ_ALU_WORD0_SRC0_REL(word0
);
2198 alu
->src
[0].chan
= G_SQ_ALU_WORD0_SRC0_CHAN(word0
);
2199 alu
->src
[0].neg
= G_SQ_ALU_WORD0_SRC0_NEG(word0
);
2200 alu
->src
[1].sel
= G_SQ_ALU_WORD0_SRC1_SEL(word0
);
2201 alu
->src
[1].rel
= G_SQ_ALU_WORD0_SRC1_REL(word0
);
2202 alu
->src
[1].chan
= G_SQ_ALU_WORD0_SRC1_CHAN(word0
);
2203 alu
->src
[1].neg
= G_SQ_ALU_WORD0_SRC1_NEG(word0
);
2204 alu
->index_mode
= G_SQ_ALU_WORD0_INDEX_MODE(word0
);
2205 alu
->pred_sel
= G_SQ_ALU_WORD0_PRED_SEL(word0
);
2206 alu
->last
= G_SQ_ALU_WORD0_LAST(word0
);
2209 alu
->bank_swizzle
= G_SQ_ALU_WORD1_BANK_SWIZZLE(word1
);
2210 if (alu
->bank_swizzle
)
2211 alu
->bank_swizzle_force
= alu
->bank_swizzle
;
2212 alu
->dst
.sel
= G_SQ_ALU_WORD1_DST_GPR(word1
);
2213 alu
->dst
.rel
= G_SQ_ALU_WORD1_DST_REL(word1
);
2214 alu
->dst
.chan
= G_SQ_ALU_WORD1_DST_CHAN(word1
);
2215 alu
->dst
.clamp
= G_SQ_ALU_WORD1_CLAMP(word1
);
2216 if (G_SQ_ALU_WORD1_ENCODING(word1
)) /*ALU_DWORD1_OP3*/
2219 alu
->src
[2].sel
= G_SQ_ALU_WORD1_OP3_SRC2_SEL(word1
);
2220 alu
->src
[2].rel
= G_SQ_ALU_WORD1_OP3_SRC2_REL(word1
);
2221 alu
->src
[2].chan
= G_SQ_ALU_WORD1_OP3_SRC2_CHAN(word1
);
2222 alu
->src
[2].neg
= G_SQ_ALU_WORD1_OP3_SRC2_NEG(word1
);
2223 alu
->op
= r600_isa_alu_by_opcode(bc
->isa
,
2224 G_SQ_ALU_WORD1_OP3_ALU_INST(word1
), /* is_op3 = */ 1);
2227 else /*ALU_DWORD1_OP2*/
2229 alu
->src
[0].abs
= G_SQ_ALU_WORD1_OP2_SRC0_ABS(word1
);
2230 alu
->src
[1].abs
= G_SQ_ALU_WORD1_OP2_SRC1_ABS(word1
);
2231 alu
->op
= r600_isa_alu_by_opcode(bc
->isa
,
2232 G_SQ_ALU_WORD1_OP2_ALU_INST(word1
), /* is_op3 = */ 0);
2233 alu
->omod
= G_SQ_ALU_WORD1_OP2_OMOD(word1
);
2234 alu
->dst
.write
= G_SQ_ALU_WORD1_OP2_WRITE_MASK(word1
);
2235 alu
->update_pred
= G_SQ_ALU_WORD1_OP2_UPDATE_PRED(word1
);
2237 G_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(word1
);
2241 void r600_bytecode_export_read(struct r600_bytecode
*bc
,
2242 struct r600_bytecode_output
*output
, uint32_t word0
, uint32_t word1
)
2244 output
->array_base
= G_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(word0
);
2245 output
->type
= G_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(word0
);
2246 output
->gpr
= G_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(word0
);
2247 output
->elem_size
= G_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(word0
);
2249 output
->swizzle_x
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(word1
);
2250 output
->swizzle_y
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(word1
);
2251 output
->swizzle_z
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(word1
);
2252 output
->swizzle_w
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(word1
);
2253 output
->burst_count
= G_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(word1
);
2254 output
->end_of_program
= G_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(word1
);
2255 output
->op
= r600_isa_cf_by_opcode(bc
->isa
,
2256 G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(word1
), 0);
2257 output
->barrier
= G_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(word1
);
2258 output
->array_size
= G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(word1
);
2259 output
->comp_mask
= G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(word1
);