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.
25 #include "util/u_format.h"
26 #include "util/u_memory.h"
27 #include "pipe/p_shader_tokens.h"
28 #include "r600_pipe.h"
30 #include "r600_opcodes.h"
32 #include "r600_formats.h"
35 #define NUM_OF_CYCLES 3
36 #define NUM_OF_COMPONENTS 4
38 static inline unsigned int r600_bc_get_num_operands(struct r600_bc_alu
*alu
)
44 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
46 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
47 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
48 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
49 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
50 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
51 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
52 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
53 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
54 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
55 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
56 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
57 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
58 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
59 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
60 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
61 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
62 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
63 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
64 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
67 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
68 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
:
69 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
70 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
71 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
72 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
73 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
74 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
75 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
76 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
77 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
78 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
79 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
82 "Need instruction operand number for 0x%x.\n", alu
->inst
);
88 int r700_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
);
90 static struct r600_bc_cf
*r600_bc_cf(void)
92 struct r600_bc_cf
*cf
= CALLOC_STRUCT(r600_bc_cf
);
96 LIST_INITHEAD(&cf
->list
);
97 LIST_INITHEAD(&cf
->alu
);
98 LIST_INITHEAD(&cf
->vtx
);
99 LIST_INITHEAD(&cf
->tex
);
103 static struct r600_bc_alu
*r600_bc_alu(void)
105 struct r600_bc_alu
*alu
= CALLOC_STRUCT(r600_bc_alu
);
109 LIST_INITHEAD(&alu
->list
);
113 static struct r600_bc_vtx
*r600_bc_vtx(void)
115 struct r600_bc_vtx
*vtx
= CALLOC_STRUCT(r600_bc_vtx
);
119 LIST_INITHEAD(&vtx
->list
);
123 static struct r600_bc_tex
*r600_bc_tex(void)
125 struct r600_bc_tex
*tex
= CALLOC_STRUCT(r600_bc_tex
);
129 LIST_INITHEAD(&tex
->list
);
133 int r600_bc_init(struct r600_bc
*bc
, enum radeon_family family
)
135 LIST_INITHEAD(&bc
->cf
);
137 switch (bc
->family
) {
146 bc
->chiprev
= CHIPREV_R600
;
152 bc
->chiprev
= CHIPREV_R700
;
160 bc
->chiprev
= CHIPREV_EVERGREEN
;
163 R600_ERR("unknown family %d\n", bc
->family
);
169 static int r600_bc_add_cf(struct r600_bc
*bc
)
171 struct r600_bc_cf
*cf
= r600_bc_cf();
175 LIST_ADDTAIL(&cf
->list
, &bc
->cf
);
177 cf
->id
= bc
->cf_last
->id
+ 2;
181 bc
->force_add_cf
= 0;
185 int r600_bc_add_output(struct r600_bc
*bc
, const struct r600_bc_output
*output
)
189 r
= r600_bc_add_cf(bc
);
192 bc
->cf_last
->inst
= output
->inst
;
193 memcpy(&bc
->cf_last
->output
, output
, sizeof(struct r600_bc_output
));
197 /* alu instructions that can ony exits once per group */
198 static int is_alu_once_inst(struct r600_bc_alu
*alu
)
200 return !alu
->is_op3
&& (
201 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
202 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
203 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
204 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
205 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
206 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
207 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
208 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
209 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
210 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
211 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
212 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
213 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
214 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
215 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
216 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
217 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
218 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
219 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
220 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
221 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
222 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
223 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
224 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
225 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
226 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
227 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
228 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
229 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
230 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
231 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
232 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
233 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
234 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
237 static int is_alu_reduction_inst(struct r600_bc_alu
*alu
)
239 return !alu
->is_op3
&& (
240 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
241 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
242 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
243 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
246 static int is_alu_mova_inst(struct r600_bc_alu
*alu
)
248 return !alu
->is_op3
&& (
249 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
||
250 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
||
251 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
254 /* alu instructions that can only execute on the vector unit */
255 static int is_alu_vec_unit_inst(struct r600_bc_alu
*alu
)
257 return is_alu_reduction_inst(alu
) ||
258 is_alu_mova_inst(alu
);
261 /* alu instructions that can only execute on the trans unit */
262 static int is_alu_trans_unit_inst(struct r600_bc_alu
*alu
)
265 return alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
||
266 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
||
267 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
||
268 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
||
269 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
||
270 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
||
271 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
||
272 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
||
273 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
||
274 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
||
275 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
||
276 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
||
277 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
||
278 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
||
279 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
||
280 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
||
281 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
||
282 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF
||
283 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
||
284 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
||
285 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF
||
286 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
||
287 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
||
288 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE
;
290 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
||
291 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_D2
||
292 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M2
||
293 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M4
;
296 /* alu instructions that can execute on any unit */
297 static int is_alu_any_unit_inst(struct r600_bc_alu
*alu
)
299 return !is_alu_vec_unit_inst(alu
) &&
300 !is_alu_trans_unit_inst(alu
);
303 static int assign_alu_units(struct r600_bc_alu
*alu_first
, struct r600_bc_alu
*assignment
[5])
305 struct r600_bc_alu
*alu
;
306 unsigned i
, chan
, trans
;
308 for (i
= 0; i
< 5; i
++)
309 assignment
[i
] = NULL
;
311 for (alu
= alu_first
; alu
; alu
= LIST_ENTRY(struct r600_bc_alu
, alu
->list
.next
, list
)) {
312 chan
= alu
->dst
.chan
;
313 if (is_alu_trans_unit_inst(alu
))
315 else if (is_alu_vec_unit_inst(alu
))
317 else if (assignment
[chan
])
318 trans
= 1; // assume ALU_INST_PREFER_VECTOR
324 assert(0); //ALU.Trans has already been allocated
329 if (assignment
[chan
]) {
330 assert(0); //ALU.chan has already been allocated
333 assignment
[chan
] = alu
;
342 struct alu_bank_swizzle
{
343 int hw_gpr
[NUM_OF_CYCLES
][NUM_OF_COMPONENTS
];
344 int hw_cfile_addr
[4];
345 int hw_cfile_elem
[4];
348 const unsigned cycle_for_bank_swizzle_vec
[][3] = {
349 [SQ_ALU_VEC_012
] = { 0, 1, 2 },
350 [SQ_ALU_VEC_021
] = { 0, 2, 1 },
351 [SQ_ALU_VEC_120
] = { 1, 2, 0 },
352 [SQ_ALU_VEC_102
] = { 1, 0, 2 },
353 [SQ_ALU_VEC_201
] = { 2, 0, 1 },
354 [SQ_ALU_VEC_210
] = { 2, 1, 0 }
357 const unsigned cycle_for_bank_swizzle_scl
[][3] = {
358 [SQ_ALU_SCL_210
] = { 2, 1, 0 },
359 [SQ_ALU_SCL_122
] = { 1, 2, 2 },
360 [SQ_ALU_SCL_212
] = { 2, 1, 2 },
361 [SQ_ALU_SCL_221
] = { 2, 2, 1 }
364 static void init_bank_swizzle(struct alu_bank_swizzle
*bs
)
366 int i
, cycle
, component
;
368 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
369 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
370 bs
->hw_gpr
[cycle
][component
] = -1;
371 for (i
= 0; i
< 4; i
++)
372 bs
->hw_cfile_addr
[i
] = -1;
373 for (i
= 0; i
< 4; i
++)
374 bs
->hw_cfile_elem
[i
] = -1;
377 static int reserve_gpr(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
, unsigned cycle
)
379 if (bs
->hw_gpr
[cycle
][chan
] == -1)
380 bs
->hw_gpr
[cycle
][chan
] = sel
;
381 else if (bs
->hw_gpr
[cycle
][chan
] != (int)sel
) {
382 // Another scalar operation has already used GPR read port for channel
388 static int reserve_cfile(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
)
390 int res
, resmatch
= -1, resempty
= -1;
391 for (res
= 3; res
>= 0; --res
) {
392 if (bs
->hw_cfile_addr
[res
] == -1)
394 else if (bs
->hw_cfile_addr
[res
] == sel
&&
395 bs
->hw_cfile_elem
[res
] == chan
)
399 return 0; // Read for this scalar element already reserved, nothing to do here.
400 else if (resempty
!= -1) {
401 bs
->hw_cfile_addr
[resempty
] = sel
;
402 bs
->hw_cfile_elem
[resempty
] = chan
;
404 // All cfile read ports are used, cannot reference vector element
410 static int is_gpr(unsigned sel
)
412 return (sel
>= 0 && sel
<= 127);
415 static int is_cfile(unsigned sel
)
417 return (sel
> 255 && sel
< 512);
420 static int is_const(int sel
)
422 return is_cfile(sel
) ||
423 (sel
>= V_SQ_ALU_SRC_0
&&
424 sel
<= V_SQ_ALU_SRC_LITERAL
);
427 static int check_vector(struct r600_bc_alu
*alu
, struct alu_bank_swizzle
*bs
, int bank_swizzle
)
429 int r
, src
, num_src
, sel
, elem
, cycle
;
431 num_src
= r600_bc_get_num_operands(alu
);
432 for (src
= 0; src
< num_src
; src
++) {
433 sel
= alu
->src
[src
].sel
;
434 elem
= alu
->src
[src
].chan
;
436 cycle
= cycle_for_bank_swizzle_vec
[bank_swizzle
][src
];
437 if (src
== 1 && sel
== alu
->src
[0].sel
&& elem
== alu
->src
[0].chan
)
438 // Nothing to do; special-case optimization,
439 // second source uses first source’s reservation
442 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
446 } else if (is_cfile(sel
)) {
447 r
= reserve_cfile(bs
, sel
, elem
);
451 // No restrictions on PV, PS, literal or special constants
456 static int check_scalar(struct r600_bc_alu
*alu
, struct alu_bank_swizzle
*bs
, int bank_swizzle
)
458 int r
, src
, num_src
, const_count
, sel
, elem
, cycle
;
460 num_src
= r600_bc_get_num_operands(alu
);
461 for (const_count
= 0, src
= 0; src
< num_src
; ++src
) {
462 sel
= alu
->src
[src
].sel
;
463 elem
= alu
->src
[src
].chan
;
464 if (is_const(sel
)) { // Any constant, including literal and inline constants
465 if (const_count
>= 2)
466 // More than two references to a constant in
467 // transcendental operation.
473 r
= reserve_cfile(bs
, sel
, elem
);
478 for (src
= 0; src
< num_src
; ++src
) {
479 sel
= alu
->src
[src
].sel
;
480 elem
= alu
->src
[src
].chan
;
482 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
483 if (cycle
< const_count
)
484 // Cycle for GPR load conflicts with
485 // constant load in transcendental operation.
487 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
491 // Constants already processed
492 // No restrictions on PV, PS
497 static int check_and_set_bank_swizzle(struct r600_bc_alu
*slots
[5])
499 struct alu_bank_swizzle bs
;
501 int i
, r
= 0, forced
= 0;
503 for (i
= 0; i
< 5; i
++)
504 if (slots
[i
] && slots
[i
]->bank_swizzle_force
) {
505 slots
[i
]->bank_swizzle
= slots
[i
]->bank_swizzle_force
;
512 // just check every possible combination of bank swizzle
513 // not very efficent, but works on the first try in most of the cases
514 for (i
= 0; i
< 4; i
++)
515 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
516 bank_swizzle
[4] = SQ_ALU_SCL_210
;
517 while(bank_swizzle
[4] <= SQ_ALU_SCL_221
) {
518 init_bank_swizzle(&bs
);
519 for (i
= 0; i
< 4; i
++) {
521 r
= check_vector(slots
[i
], &bs
, bank_swizzle
[i
]);
526 if (!r
&& slots
[4]) {
527 r
= check_scalar(slots
[4], &bs
, bank_swizzle
[4]);
530 for (i
= 0; i
< 5; i
++) {
532 slots
[i
]->bank_swizzle
= bank_swizzle
[i
];
537 for (i
= 0; i
< 5; i
++) {
539 if (bank_swizzle
[i
] <= SQ_ALU_VEC_210
)
542 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
546 // couldn't find a working swizzle
550 static int replace_gpr_with_pv_ps(struct r600_bc_alu
*slots
[5], struct r600_bc_alu
*alu_prev
)
552 struct r600_bc_alu
*prev
[5];
554 int i
, j
, r
, src
, num_src
;
556 r
= assign_alu_units(alu_prev
, prev
);
560 for (i
= 0; i
< 5; ++i
) {
561 if(prev
[i
] && prev
[i
]->dst
.write
&& !prev
[i
]->dst
.rel
) {
562 gpr
[i
] = prev
[i
]->dst
.sel
;
563 if (is_alu_reduction_inst(prev
[i
]))
566 chan
[i
] = prev
[i
]->dst
.chan
;
571 for (i
= 0; i
< 5; ++i
) {
572 struct r600_bc_alu
*alu
= slots
[i
];
576 num_src
= r600_bc_get_num_operands(alu
);
577 for (src
= 0; src
< num_src
; ++src
) {
578 if (!is_gpr(alu
->src
[src
].sel
) || alu
->src
[src
].rel
)
581 if (alu
->src
[src
].sel
== gpr
[4] &&
582 alu
->src
[src
].chan
== chan
[4]) {
583 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PS
;
584 alu
->src
[src
].chan
= 0;
588 for (j
= 0; j
< 4; ++j
) {
589 if (alu
->src
[src
].sel
== gpr
[j
] &&
590 alu
->src
[src
].chan
== j
) {
591 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PV
;
592 alu
->src
[src
].chan
= chan
[j
];
602 static int merge_inst_groups(struct r600_bc
*bc
, struct r600_bc_alu
*slots
[5], struct r600_bc_alu
*alu_prev
)
604 struct r600_bc_alu
*prev
[5];
605 struct r600_bc_alu
*result
[5] = { NULL
};
606 int i
, j
, r
, src
, num_src
;
607 int num_once_inst
= 0;
609 r
= assign_alu_units(alu_prev
, prev
);
613 for (i
= 0; i
< 5; ++i
) {
614 // TODO: we have literals? forget it!
615 if (prev
[i
] && prev
[i
]->nliteral
)
617 if (slots
[i
] && slots
[i
]->nliteral
)
621 // let's check used slots
622 if (prev
[i
] && !slots
[i
]) {
624 num_once_inst
+= is_alu_once_inst(prev
[i
]);
626 } else if (prev
[i
] && slots
[i
]) {
627 if (result
[4] == NULL
&& prev
[4] == NULL
&& slots
[4] == NULL
) {
628 // trans unit is still free try to use it
629 if (is_alu_any_unit_inst(slots
[i
])) {
631 result
[4] = slots
[i
];
632 } else if (is_alu_any_unit_inst(prev
[i
])) {
633 result
[i
] = slots
[i
];
639 } else if(!slots
[i
]) {
642 result
[i
] = slots
[i
];
644 // let's check source gprs
645 struct r600_bc_alu
*alu
= slots
[i
];
646 num_once_inst
+= is_alu_once_inst(alu
);
648 num_src
= r600_bc_get_num_operands(alu
);
649 for (src
= 0; src
< num_src
; ++src
) {
650 // constants doesn't matter
651 if (!is_gpr(alu
->src
[src
].sel
))
654 for (j
= 0; j
< 5; ++j
) {
655 if (!prev
[j
] || !prev
[j
]->dst
.write
)
658 // if it's relative then we can't determin which gpr is really used
659 if (prev
[j
]->dst
.chan
== alu
->src
[src
].chan
&&
660 (prev
[j
]->dst
.sel
== alu
->src
[src
].sel
||
661 prev
[j
]->dst
.rel
|| alu
->src
[src
].rel
))
667 /* more than one PRED_ or KILL_ ? */
668 if (num_once_inst
> 1)
671 /* check if the result can still be swizzlet */
672 r
= check_and_set_bank_swizzle(result
);
676 /* looks like everything worked out right, apply the changes */
678 /* sort instructions */
679 for (i
= 0; i
< 5; ++i
) {
680 slots
[i
] = result
[i
];
682 LIST_DEL(&result
[i
]->list
);
684 LIST_ADDTAIL(&result
[i
]->list
, &bc
->cf_last
->alu
);
688 /* determine new last instruction */
689 LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
)->last
= 1;
691 /* determine new first instruction */
692 for (i
= 0; i
< 5; ++i
) {
694 bc
->cf_last
->curr_bs_head
= result
[i
];
699 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->prev2_bs_head
;
700 bc
->cf_last
->prev2_bs_head
= NULL
;
705 int r600_bc_add_alu_type(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
, int type
)
707 struct r600_bc_alu
*nalu
= r600_bc_alu();
708 struct r600_bc_alu
*lalu
;
713 memcpy(nalu
, alu
, sizeof(struct r600_bc_alu
));
716 if (bc
->cf_last
!= NULL
&& bc
->cf_last
->inst
!= (type
<< 3)) {
717 /* check if we could add it anyway */
718 if (bc
->cf_last
->inst
== (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3) &&
719 type
== V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
) {
720 LIST_FOR_EACH_ENTRY(lalu
, &bc
->cf_last
->alu
, list
) {
721 if (lalu
->predicate
) {
722 bc
->force_add_cf
= 1;
727 bc
->force_add_cf
= 1;
730 /* cf can contains only alu or only vtx or only tex */
731 if (bc
->cf_last
== NULL
|| bc
->force_add_cf
) {
732 r
= r600_bc_add_cf(bc
);
738 bc
->cf_last
->inst
= (type
<< 3);
739 if (!bc
->cf_last
->curr_bs_head
) {
740 bc
->cf_last
->curr_bs_head
= nalu
;
742 /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots)
744 if (alu
->last
&& (bc
->cf_last
->ndw
>> 1) >= 120) {
745 bc
->force_add_cf
= 1;
747 /* number of gpr == the last gpr used in any alu */
748 for (i
= 0; i
< 3; i
++) {
749 if (alu
->src
[i
].sel
>= bc
->ngpr
&& alu
->src
[i
].sel
< 128) {
750 bc
->ngpr
= alu
->src
[i
].sel
+ 1;
752 /* compute how many literal are needed
753 * either 2 or 4 literals
755 if (alu
->src
[i
].sel
== 253) {
756 if (((alu
->src
[i
].chan
+ 2) & 0x6) > nalu
->nliteral
) {
757 nalu
->nliteral
= (alu
->src
[i
].chan
+ 2) & 0x6;
761 if (!LIST_IS_EMPTY(&bc
->cf_last
->alu
)) {
762 lalu
= LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
);
763 if (!lalu
->last
&& lalu
->nliteral
> nalu
->nliteral
) {
764 nalu
->nliteral
= lalu
->nliteral
;
767 if (alu
->dst
.sel
>= bc
->ngpr
) {
768 bc
->ngpr
= alu
->dst
.sel
+ 1;
770 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
771 /* each alu use 2 dwords */
772 bc
->cf_last
->ndw
+= 2;
775 bc
->cf_last
->kcache0_mode
= 2;
777 /* process cur ALU instructions for bank swizzle */
779 struct r600_bc_alu
*slots
[5];
780 r
= assign_alu_units(bc
->cf_last
->curr_bs_head
, slots
);
784 if (bc
->cf_last
->prev_bs_head
) {
785 r
= merge_inst_groups(bc
, slots
, bc
->cf_last
->prev_bs_head
);
790 if (bc
->cf_last
->prev_bs_head
) {
791 r
= replace_gpr_with_pv_ps(slots
, bc
->cf_last
->prev_bs_head
);
796 r
= check_and_set_bank_swizzle(slots
);
800 bc
->cf_last
->prev2_bs_head
= bc
->cf_last
->prev_bs_head
;
801 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->curr_bs_head
;
802 bc
->cf_last
->curr_bs_head
= NULL
;
807 int r600_bc_add_alu(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
)
809 return r600_bc_add_alu_type(bc
, alu
, BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
));
812 int r600_bc_add_literal(struct r600_bc
*bc
, const u32
*value
)
814 struct r600_bc_alu
*alu
;
816 if (bc
->cf_last
== NULL
) {
819 if (bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_TEX
) {
823 if (bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_JUMP
||
824 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_ELSE
||
825 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
||
826 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
||
827 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
||
828 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
||
829 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_POP
) {
833 if (((bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3)) &&
834 (bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3)) &&
835 (bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3)) &&
836 (bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3))) ||
837 LIST_IS_EMPTY(&bc
->cf_last
->alu
)) {
838 R600_ERR("last CF is not ALU (%p)\n", bc
->cf_last
);
841 alu
= LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
);
842 if (!alu
->last
|| !alu
->nliteral
|| alu
->literal_added
) {
845 memcpy(alu
->value
, value
, 4 * 4);
846 bc
->cf_last
->ndw
+= alu
->nliteral
;
847 bc
->ndw
+= alu
->nliteral
;
848 alu
->literal_added
= 1;
852 int r600_bc_add_vtx(struct r600_bc
*bc
, const struct r600_bc_vtx
*vtx
)
854 struct r600_bc_vtx
*nvtx
= r600_bc_vtx();
859 memcpy(nvtx
, vtx
, sizeof(struct r600_bc_vtx
));
861 /* cf can contains only alu or only vtx or only tex */
862 if (bc
->cf_last
== NULL
||
863 (bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
864 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) ||
866 r
= r600_bc_add_cf(bc
);
871 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
873 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
874 /* each fetch use 4 dwords */
875 bc
->cf_last
->ndw
+= 4;
877 if ((bc
->cf_last
->ndw
/ 4) > 7)
878 bc
->force_add_cf
= 1;
882 int r600_bc_add_tex(struct r600_bc
*bc
, const struct r600_bc_tex
*tex
)
884 struct r600_bc_tex
*ntex
= r600_bc_tex();
889 memcpy(ntex
, tex
, sizeof(struct r600_bc_tex
));
891 /* cf can contains only alu or only vtx or only tex */
892 if (bc
->cf_last
== NULL
||
893 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_TEX
||
895 r
= r600_bc_add_cf(bc
);
900 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_TEX
;
902 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
903 /* each texture fetch use 4 dwords */
904 bc
->cf_last
->ndw
+= 4;
906 if ((bc
->cf_last
->ndw
/ 4) > 7)
907 bc
->force_add_cf
= 1;
911 int r600_bc_add_cfinst(struct r600_bc
*bc
, int inst
)
914 r
= r600_bc_add_cf(bc
);
918 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
919 bc
->cf_last
->inst
= inst
;
923 /* common to all 3 families */
924 static int r600_bc_vtx_build(struct r600_bc
*bc
, struct r600_bc_vtx
*vtx
, unsigned id
)
926 unsigned fetch_resource_start
= 0;
928 /* check if we are fetch shader */
929 /* fetch shader can also access vertex resource,
930 * first fetch shader resource is at 160
932 if (bc
->type
== -1) {
933 switch (bc
->chiprev
) {
938 fetch_resource_start
= 160;
941 case CHIPREV_EVERGREEN
:
942 fetch_resource_start
= 0;
945 fprintf(stderr
, "%s:%s:%d unknown chiprev %d\n",
946 __FILE__
, __func__
, __LINE__
, bc
->chiprev
);
950 bc
->bytecode
[id
++] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
+ fetch_resource_start
) |
951 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
952 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
) |
953 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
954 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
955 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
956 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
957 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
958 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
959 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
960 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
961 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
962 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
963 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
964 bc
->bytecode
[id
++] = S_SQ_VTX_WORD2_MEGA_FETCH(1);
965 bc
->bytecode
[id
++] = 0;
969 /* common to all 3 families */
970 static int r600_bc_tex_build(struct r600_bc
*bc
, struct r600_bc_tex
*tex
, unsigned id
)
972 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
973 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
974 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
975 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
976 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
977 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
978 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
979 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
980 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
981 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
982 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
983 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
984 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
985 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
986 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
987 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
988 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
989 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
990 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
991 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
992 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
993 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
994 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
995 bc
->bytecode
[id
++] = 0;
999 /* r600 only, r700/eg bits in r700_asm.c */
1000 static int r600_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
)
1004 /* don't replace gpr by pv or ps for destination register */
1005 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
1006 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
1007 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
1008 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
1009 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
1010 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
1011 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
1012 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
1013 S_SQ_ALU_WORD0_LAST(alu
->last
);
1016 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1017 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1018 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1019 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1020 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
1021 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
1022 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
1023 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
1024 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
1025 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
1027 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1028 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1029 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1030 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1031 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
1032 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
1033 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
1034 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
1035 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
1036 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
1037 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->predicate
) |
1038 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->predicate
);
1041 if (alu
->nliteral
&& !alu
->literal_added
) {
1042 R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu
->inst
);
1044 for (i
= 0; i
< alu
->nliteral
; i
++) {
1045 bc
->bytecode
[id
++] = alu
->value
[i
];
1051 /* common for r600/r700 - eg in eg_asm.c */
1052 static int r600_bc_cf_build(struct r600_bc
*bc
, struct r600_bc_cf
*cf
)
1054 unsigned id
= cf
->id
;
1057 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1058 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1059 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1060 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1061 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
1062 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache0_mode
) |
1063 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache0_bank
) |
1064 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache1_bank
);
1066 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
>> 3) |
1067 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache1_mode
) |
1068 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache0_addr
) |
1069 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache1_addr
) |
1070 S_SQ_CF_ALU_WORD1_BARRIER(1) |
1071 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chiprev
== CHIPREV_R600
? cf
->r6xx_uses_waterfall
: 0) |
1072 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
1074 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1075 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1076 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1077 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
1078 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
1079 S_SQ_CF_WORD1_BARRIER(1) |
1080 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
1082 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1083 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1084 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1085 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1086 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1087 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1088 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
1089 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
1090 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
1091 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
1092 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1093 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
) |
1094 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
1096 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1097 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1098 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1099 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1100 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1101 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1102 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1103 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1104 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1105 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
1106 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
1107 S_SQ_CF_WORD1_BARRIER(1) |
1108 S_SQ_CF_WORD1_COND(cf
->cond
) |
1109 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
1113 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1119 int r600_bc_build(struct r600_bc
*bc
)
1121 struct r600_bc_cf
*cf
;
1122 struct r600_bc_alu
*alu
;
1123 struct r600_bc_vtx
*vtx
;
1124 struct r600_bc_tex
*tex
;
1128 if (bc
->callstack
[0].max
> 0)
1129 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
1130 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
1134 /* first path compute addr of each CF block */
1135 /* addr start after all the CF instructions */
1136 addr
= bc
->cf_last
->id
+ 2;
1137 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1139 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1140 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1141 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1142 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1144 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1145 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1146 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1147 /* fetch node need to be 16 bytes aligned*/
1149 addr
&= 0xFFFFFFFCUL
;
1151 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1152 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1153 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1154 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1156 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1157 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1158 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1159 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1160 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1161 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1162 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1163 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1164 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1167 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1172 bc
->ndw
= cf
->addr
+ cf
->ndw
;
1175 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
1176 if (bc
->bytecode
== NULL
)
1178 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1180 if (bc
->chiprev
== CHIPREV_EVERGREEN
)
1181 r
= eg_bc_cf_build(bc
, cf
);
1183 r
= r600_bc_cf_build(bc
, cf
);
1187 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1188 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1189 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1190 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1191 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1192 switch(bc
->chiprev
) {
1194 r
= r600_bc_alu_build(bc
, alu
, addr
);
1197 case CHIPREV_EVERGREEN
: /* eg alu is same encoding as r700 */
1198 r
= r700_bc_alu_build(bc
, alu
, addr
);
1201 R600_ERR("unknown family %d\n", bc
->family
);
1208 addr
+= alu
->nliteral
;
1212 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1213 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1214 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1215 r
= r600_bc_vtx_build(bc
, vtx
, addr
);
1221 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1222 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1223 r
= r600_bc_tex_build(bc
, tex
, addr
);
1229 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1230 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1231 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1232 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1233 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1234 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1235 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1236 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1237 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1238 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1239 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1240 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1241 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1244 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1251 void r600_bc_clear(struct r600_bc
*bc
)
1253 struct r600_bc_cf
*cf
= NULL
, *next_cf
;
1256 bc
->bytecode
= NULL
;
1258 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
1259 struct r600_bc_alu
*alu
= NULL
, *next_alu
;
1260 struct r600_bc_tex
*tex
= NULL
, *next_tex
;
1261 struct r600_bc_tex
*vtx
= NULL
, *next_vtx
;
1263 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
1267 LIST_INITHEAD(&cf
->alu
);
1269 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
1273 LIST_INITHEAD(&cf
->tex
);
1275 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
1279 LIST_INITHEAD(&cf
->vtx
);
1284 LIST_INITHEAD(&cf
->list
);
1287 void r600_bc_dump(struct r600_bc
*bc
)
1289 struct r600_bc_cf
*cf
;
1290 struct r600_bc_alu
*alu
;
1291 struct r600_bc_vtx
*vtx
;
1292 struct r600_bc_tex
*tex
;
1297 switch (bc
->chiprev
) {
1309 fprintf(stderr
, "bytecode %d dw -----------------------\n", bc
->ndw
);
1310 fprintf(stderr
, " %c\n", chip
);
1312 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1316 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1317 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1318 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1319 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1320 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1321 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
1322 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache0_mode
);
1323 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache0_bank
);
1324 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache1_bank
);
1326 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1327 fprintf(stderr
, "INST:%d ", cf
->inst
);
1328 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache1_mode
);
1329 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache0_addr
);
1330 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache1_addr
);
1331 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
1333 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1334 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1335 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1336 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1337 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
1339 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1340 fprintf(stderr
, "INST:%d ", cf
->inst
);
1341 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
1343 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1344 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1345 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
1346 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
1347 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
1348 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
1349 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
1351 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
1352 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
1353 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
1354 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
1355 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
1356 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
1357 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
1358 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
1359 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
1361 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1362 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1363 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1364 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1365 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1366 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1367 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1368 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1369 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1370 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1371 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
1373 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1374 fprintf(stderr
, "INST:%d ", cf
->inst
);
1375 fprintf(stderr
, "COND:%X ", cf
->cond
);
1376 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
1381 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1382 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1383 fprintf(stderr
, "SRC0(SEL:%d ", alu
->src
[0].sel
);
1384 fprintf(stderr
, "REL:%d ", alu
->src
[0].rel
);
1385 fprintf(stderr
, "CHAN:%d ", alu
->src
[0].chan
);
1386 fprintf(stderr
, "NEG:%d) ", alu
->src
[0].neg
);
1387 fprintf(stderr
, "SRC1(SEL:%d ", alu
->src
[1].sel
);
1388 fprintf(stderr
, "REL:%d ", alu
->src
[1].rel
);
1389 fprintf(stderr
, "CHAN:%d ", alu
->src
[1].chan
);
1390 fprintf(stderr
, "NEG:%d) ", alu
->src
[1].neg
);
1391 fprintf(stderr
, "LAST:%d)\n", alu
->last
);
1393 fprintf(stderr
, "%04d %08X %c ", id
, bc
->bytecode
[id
], alu
->last
? '*' : ' ');
1394 fprintf(stderr
, "INST:%d ", alu
->inst
);
1395 fprintf(stderr
, "DST(SEL:%d ", alu
->dst
.sel
);
1396 fprintf(stderr
, "CHAN:%d ", alu
->dst
.chan
);
1397 fprintf(stderr
, "REL:%d ", alu
->dst
.rel
);
1398 fprintf(stderr
, "CLAMP:%d) ", alu
->dst
.clamp
);
1399 fprintf(stderr
, "BANK_SWIZZLE:%d ", alu
->bank_swizzle
);
1401 fprintf(stderr
, "SRC2(SEL:%d ", alu
->src
[2].sel
);
1402 fprintf(stderr
, "REL:%d ", alu
->src
[2].rel
);
1403 fprintf(stderr
, "CHAN:%d ", alu
->src
[2].chan
);
1404 fprintf(stderr
, "NEG:%d)\n", alu
->src
[2].neg
);
1406 fprintf(stderr
, "SRC0_ABS:%d ", alu
->src
[0].abs
);
1407 fprintf(stderr
, "SRC1_ABS:%d ", alu
->src
[1].abs
);
1408 fprintf(stderr
, "WRITE_MASK:%d ", alu
->dst
.write
);
1409 fprintf(stderr
, "OMOD:%d ", alu
->omod
);
1410 fprintf(stderr
, "EXECUTE_MASK:%d ", alu
->predicate
);
1411 fprintf(stderr
, "UPDATE_PRED:%d\n", alu
->predicate
);
1416 for (i
= 0; i
< alu
->nliteral
; i
++, id
++) {
1417 float *f
= (float*)(bc
->bytecode
+ id
);
1418 fprintf(stderr
, "%04d %08X %f\n", id
, bc
->bytecode
[id
], *f
);
1423 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1427 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1432 fprintf(stderr
, "--------------------------------------\n");
1435 void r600_cf_vtx(struct r600_vertex_element
*ve
, u32
*bytecode
, unsigned count
)
1437 struct r600_pipe_state
*rstate
;
1441 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1442 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
1443 S_SQ_CF_WORD1_BARRIER(1) |
1444 S_SQ_CF_WORD1_COUNT(8 - 1);
1445 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(40 >> 1);
1446 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
1447 S_SQ_CF_WORD1_BARRIER(1) |
1448 S_SQ_CF_WORD1_COUNT(count
- 8 - 1);
1450 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1451 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
1452 S_SQ_CF_WORD1_BARRIER(1) |
1453 S_SQ_CF_WORD1_COUNT(count
- 1);
1455 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(0);
1456 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN
) |
1457 S_SQ_CF_WORD1_BARRIER(1);
1459 rstate
= &ve
->rstate
;
1460 rstate
->id
= R600_PIPE_STATE_FETCH_SHADER
;
1462 r600_pipe_state_add_reg(rstate
, R_0288A4_SQ_PGM_RESOURCES_FS
,
1463 0x00000000, 0xFFFFFFFF, NULL
);
1464 r600_pipe_state_add_reg(rstate
, R_0288DC_SQ_PGM_CF_OFFSET_FS
,
1465 0x00000000, 0xFFFFFFFF, NULL
);
1466 r600_pipe_state_add_reg(rstate
, R_028894_SQ_PGM_START_FS
,
1467 r600_bo_offset(ve
->fetch_shader
) >> 8,
1468 0xFFFFFFFF, ve
->fetch_shader
);
1471 void r600_cf_vtx_tc(struct r600_vertex_element
*ve
, u32
*bytecode
, unsigned count
)
1473 struct r600_pipe_state
*rstate
;
1477 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1478 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1479 S_SQ_CF_WORD1_BARRIER(1) |
1480 S_SQ_CF_WORD1_COUNT(8 - 1);
1481 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(40 >> 1);
1482 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1483 S_SQ_CF_WORD1_BARRIER(1) |
1484 S_SQ_CF_WORD1_COUNT((count
- 8) - 1);
1486 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1487 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1488 S_SQ_CF_WORD1_BARRIER(1) |
1489 S_SQ_CF_WORD1_COUNT(count
- 1);
1491 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(0);
1492 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN
) |
1493 S_SQ_CF_WORD1_BARRIER(1);
1495 rstate
= &ve
->rstate
;
1496 rstate
->id
= R600_PIPE_STATE_FETCH_SHADER
;
1498 r600_pipe_state_add_reg(rstate
, R_0288A4_SQ_PGM_RESOURCES_FS
,
1499 0x00000000, 0xFFFFFFFF, NULL
);
1500 r600_pipe_state_add_reg(rstate
, R_0288DC_SQ_PGM_CF_OFFSET_FS
,
1501 0x00000000, 0xFFFFFFFF, NULL
);
1502 r600_pipe_state_add_reg(rstate
, R_028894_SQ_PGM_START_FS
,
1503 r600_bo_offset(ve
->fetch_shader
) >> 8,
1504 0xFFFFFFFF, ve
->fetch_shader
);
1507 static void r600_vertex_data_type(enum pipe_format pformat
, unsigned *format
,
1508 unsigned *num_format
, unsigned *format_comp
)
1510 const struct util_format_description
*desc
;
1517 desc
= util_format_description(pformat
);
1518 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
1522 /* Find the first non-VOID channel. */
1523 for (i
= 0; i
< 4; i
++) {
1524 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
1529 switch (desc
->channel
[i
].type
) {
1530 /* Half-floats, floats, doubles */
1531 case UTIL_FORMAT_TYPE_FLOAT
:
1532 switch (desc
->channel
[i
].size
) {
1534 switch (desc
->nr_channels
) {
1536 *format
= FMT_16_FLOAT
;
1539 *format
= FMT_16_16_FLOAT
;
1542 *format
= FMT_16_16_16_FLOAT
;
1545 *format
= FMT_16_16_16_16_FLOAT
;
1550 switch (desc
->nr_channels
) {
1552 *format
= FMT_32_FLOAT
;
1555 *format
= FMT_32_32_FLOAT
;
1558 *format
= FMT_32_32_32_FLOAT
;
1561 *format
= FMT_32_32_32_32_FLOAT
;
1570 case UTIL_FORMAT_TYPE_UNSIGNED
:
1572 case UTIL_FORMAT_TYPE_SIGNED
:
1573 switch (desc
->channel
[i
].size
) {
1575 switch (desc
->nr_channels
) {
1583 // *format = FMT_8_8_8; /* fails piglit draw-vertices test */
1586 *format
= FMT_8_8_8_8
;
1591 switch (desc
->nr_channels
) {
1596 *format
= FMT_16_16
;
1599 // *format = FMT_16_16_16; /* fails piglit draw-vertices test */
1602 *format
= FMT_16_16_16_16
;
1607 switch (desc
->nr_channels
) {
1612 *format
= FMT_32_32
;
1615 *format
= FMT_32_32_32
;
1618 *format
= FMT_32_32_32_32
;
1630 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
1633 if (desc
->channel
[i
].normalized
) {
1640 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
1643 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context
*rctx
, struct r600_vertex_element
*ve
)
1647 unsigned fetch_resource_start
= 0, format
, num_format
, format_comp
;
1648 struct pipe_vertex_element
*elements
= ve
->elements
;
1649 const struct util_format_description
*desc
;
1651 /* 2 dwords for cf aligned to 4 + 4 dwords per input */
1652 ndw
= 8 + ve
->count
* 4;
1653 ve
->fs_size
= ndw
* 4;
1655 /* use PIPE_BIND_VERTEX_BUFFER so we use the cache buffer manager */
1656 ve
->fetch_shader
= r600_bo(rctx
->radeon
, ndw
*4, 256, PIPE_BIND_VERTEX_BUFFER
, 0);
1657 if (ve
->fetch_shader
== NULL
) {
1661 bytecode
= r600_bo_map(rctx
->radeon
, ve
->fetch_shader
, 0, NULL
);
1662 if (bytecode
== NULL
) {
1663 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
1667 if (rctx
->family
>= CHIP_CEDAR
) {
1668 eg_cf_vtx(ve
, &bytecode
[0], (ndw
- 8) / 4);
1670 r600_cf_vtx(ve
, &bytecode
[0], (ndw
- 8) / 4);
1671 fetch_resource_start
= 160;
1674 /* vertex elements offset need special handling, if offset is bigger
1675 * than what we can put in fetch instruction then we need to alterate
1676 * the vertex resource offset. In such case in order to simplify code
1677 * we will bound one resource per elements. It's a worst case scenario.
1679 for (i
= 0; i
< ve
->count
; i
++) {
1680 ve
->vbuffer_offset
[i
] = C_SQ_VTX_WORD2_OFFSET
& elements
[i
].src_offset
;
1681 if (ve
->vbuffer_offset
[i
]) {
1682 ve
->vbuffer_need_offset
= 1;
1686 for (i
= 0; i
< ve
->count
; i
++) {
1687 unsigned vbuffer_index
;
1688 r600_vertex_data_type(ve
->hw_format
[i
], &format
, &num_format
, &format_comp
);
1689 desc
= util_format_description(ve
->hw_format
[i
]);
1691 R600_ERR("unknown format %d\n", ve
->hw_format
[i
]);
1692 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
1696 /* see above for vbuffer_need_offset explanation */
1697 vbuffer_index
= elements
[i
].vertex_buffer_index
;
1698 if (ve
->vbuffer_need_offset
) {
1699 bytecode
[8 + i
* 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(i
+ fetch_resource_start
);
1701 bytecode
[8 + i
* 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(vbuffer_index
+ fetch_resource_start
);
1703 bytecode
[8 + i
* 4 + 0] |= S_SQ_VTX_WORD0_SRC_GPR(0) |
1704 S_SQ_VTX_WORD0_SRC_SEL_X(0) |
1705 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(0x1F);
1706 bytecode
[8 + i
* 4 + 1] = S_SQ_VTX_WORD1_DST_SEL_X(desc
->swizzle
[0]) |
1707 S_SQ_VTX_WORD1_DST_SEL_Y(desc
->swizzle
[1]) |
1708 S_SQ_VTX_WORD1_DST_SEL_Z(desc
->swizzle
[2]) |
1709 S_SQ_VTX_WORD1_DST_SEL_W(desc
->swizzle
[3]) |
1710 S_SQ_VTX_WORD1_USE_CONST_FIELDS(0) |
1711 S_SQ_VTX_WORD1_DATA_FORMAT(format
) |
1712 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(num_format
) |
1713 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(format_comp
) |
1714 S_SQ_VTX_WORD1_SRF_MODE_ALL(1) |
1715 S_SQ_VTX_WORD1_GPR_DST_GPR(i
+ 1);
1716 bytecode
[8 + i
* 4 + 2] = S_SQ_VTX_WORD2_OFFSET(elements
[i
].src_offset
) |
1717 S_SQ_VTX_WORD2_MEGA_FETCH(1);
1718 bytecode
[8 + i
* 4 + 3] = 0;
1720 r600_bo_unmap(rctx
->radeon
, ve
->fetch_shader
);