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.
26 #include "util/u_format.h"
27 #include "util/u_memory.h"
28 #include "pipe/p_shader_tokens.h"
29 #include "r600_pipe.h"
31 #include "r600_opcodes.h"
33 #include "r600_formats.h"
36 #define NUM_OF_CYCLES 3
37 #define NUM_OF_COMPONENTS 4
39 static inline unsigned int r600_bc_get_num_operands(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
44 switch (bc
->chiprev
) {
48 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
50 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
51 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
:
52 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
53 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
54 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
55 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
56 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
57 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
:
58 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
59 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
60 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
61 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
62 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
63 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
64 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
65 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
66 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
67 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
68 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
69 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
70 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
73 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
74 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
:
75 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
:
76 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
:
77 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
78 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
79 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
80 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
81 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
82 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
83 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
:
84 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
85 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
:
86 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
87 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
88 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
:
89 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
90 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
93 "Need instruction operand number for 0x%x.\n", alu
->inst
);
96 case CHIPREV_EVERGREEN
:
98 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
100 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
101 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
:
102 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
103 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
104 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
105 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
106 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
107 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
:
108 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
109 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
110 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
111 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
112 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
113 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
114 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
115 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
116 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
117 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
118 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
119 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
120 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
121 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY
:
122 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW
:
125 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
126 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
:
127 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
128 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
129 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
130 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
131 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
132 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
133 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
:
134 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
135 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
:
136 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
137 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
138 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
:
139 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
:
140 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
141 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
144 "Need instruction operand number for 0x%x.\n", alu
->inst
);
152 int r700_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
);
154 static struct r600_bc_cf
*r600_bc_cf(void)
156 struct r600_bc_cf
*cf
= CALLOC_STRUCT(r600_bc_cf
);
160 LIST_INITHEAD(&cf
->list
);
161 LIST_INITHEAD(&cf
->alu
);
162 LIST_INITHEAD(&cf
->vtx
);
163 LIST_INITHEAD(&cf
->tex
);
167 static struct r600_bc_alu
*r600_bc_alu(void)
169 struct r600_bc_alu
*alu
= CALLOC_STRUCT(r600_bc_alu
);
173 LIST_INITHEAD(&alu
->list
);
177 static struct r600_bc_vtx
*r600_bc_vtx(void)
179 struct r600_bc_vtx
*vtx
= CALLOC_STRUCT(r600_bc_vtx
);
183 LIST_INITHEAD(&vtx
->list
);
187 static struct r600_bc_tex
*r600_bc_tex(void)
189 struct r600_bc_tex
*tex
= CALLOC_STRUCT(r600_bc_tex
);
193 LIST_INITHEAD(&tex
->list
);
197 int r600_bc_init(struct r600_bc
*bc
, enum radeon_family family
)
199 LIST_INITHEAD(&bc
->cf
);
201 switch (bc
->family
) {
210 bc
->chiprev
= CHIPREV_R600
;
216 bc
->chiprev
= CHIPREV_R700
;
227 bc
->chiprev
= CHIPREV_EVERGREEN
;
230 R600_ERR("unknown family %d\n", bc
->family
);
236 static int r600_bc_add_cf(struct r600_bc
*bc
)
238 struct r600_bc_cf
*cf
= r600_bc_cf();
242 LIST_ADDTAIL(&cf
->list
, &bc
->cf
);
244 cf
->id
= bc
->cf_last
->id
+ 2;
248 bc
->force_add_cf
= 0;
252 int r600_bc_add_output(struct r600_bc
*bc
, const struct r600_bc_output
*output
)
256 if (bc
->cf_last
&& (bc
->cf_last
->inst
== output
->inst
||
257 (bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
) &&
258 output
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
))) &&
259 output
->type
== bc
->cf_last
->output
.type
&&
260 output
->elem_size
== bc
->cf_last
->output
.elem_size
&&
261 output
->swizzle_x
== bc
->cf_last
->output
.swizzle_x
&&
262 output
->swizzle_y
== bc
->cf_last
->output
.swizzle_y
&&
263 output
->swizzle_z
== bc
->cf_last
->output
.swizzle_z
&&
264 output
->swizzle_w
== bc
->cf_last
->output
.swizzle_w
&&
265 (output
->burst_count
+ bc
->cf_last
->output
.burst_count
) <= 16) {
267 if ((output
->gpr
+ output
->burst_count
) == bc
->cf_last
->output
.gpr
&&
268 (output
->array_base
+ output
->burst_count
) == bc
->cf_last
->output
.array_base
) {
270 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
271 bc
->cf_last
->output
.inst
= output
->inst
;
272 bc
->cf_last
->output
.gpr
= output
->gpr
;
273 bc
->cf_last
->output
.array_base
= output
->array_base
;
274 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
277 } else if (output
->gpr
== (bc
->cf_last
->output
.gpr
+ bc
->cf_last
->output
.burst_count
) &&
278 output
->array_base
== (bc
->cf_last
->output
.array_base
+ bc
->cf_last
->output
.burst_count
)) {
280 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
281 bc
->cf_last
->output
.inst
= output
->inst
;
282 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
287 r
= r600_bc_add_cf(bc
);
290 bc
->cf_last
->inst
= output
->inst
;
291 memcpy(&bc
->cf_last
->output
, output
, sizeof(struct r600_bc_output
));
295 /* alu instructions that can ony exits once per group */
296 static int is_alu_once_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
298 switch (bc
->chiprev
) {
301 return !alu
->is_op3
&& (
302 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
303 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
304 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
305 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
306 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
307 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
308 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
309 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
310 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
311 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
312 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
313 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
314 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
315 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
316 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
317 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
318 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
319 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
320 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
321 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
322 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
323 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
324 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
325 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
326 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
327 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
328 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
329 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
330 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
331 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
332 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
333 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
334 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
335 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
336 case CHIPREV_EVERGREEN
:
338 return !alu
->is_op3
&& (
339 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
340 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
341 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
342 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
343 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
344 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
345 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
346 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
347 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
348 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
349 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
350 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
351 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
352 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
353 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
354 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
355 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
356 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
357 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
358 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
359 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
360 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
361 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
362 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
363 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
364 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
365 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
366 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
367 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
368 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
369 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
370 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
371 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
372 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
376 static int is_alu_reduction_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
378 switch (bc
->chiprev
) {
381 return !alu
->is_op3
&& (
382 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
383 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
384 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
385 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
386 case CHIPREV_EVERGREEN
:
388 return !alu
->is_op3
&& (
389 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
390 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
391 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
392 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
396 static int is_alu_cube_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
398 switch (bc
->chiprev
) {
401 return !alu
->is_op3
&&
402 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
403 case CHIPREV_EVERGREEN
:
405 return !alu
->is_op3
&&
406 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
410 static int is_alu_mova_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
412 switch (bc
->chiprev
) {
415 return !alu
->is_op3
&& (
416 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
||
417 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
||
418 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
419 case CHIPREV_EVERGREEN
:
421 return !alu
->is_op3
&& (
422 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
426 /* alu instructions that can only execute on the vector unit */
427 static int is_alu_vec_unit_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
429 return is_alu_reduction_inst(bc
, alu
) ||
430 is_alu_mova_inst(bc
, alu
) ||
431 (bc
->chiprev
== CHIPREV_EVERGREEN
&&
432 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
);
435 /* alu instructions that can only execute on the trans unit */
436 static int is_alu_trans_unit_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
438 switch (bc
->chiprev
) {
442 return alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
||
443 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
||
444 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
||
445 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
||
446 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
||
447 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
||
448 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
||
449 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
||
450 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
||
451 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
||
452 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
||
453 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
||
454 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
||
455 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
||
456 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
||
457 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
||
458 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
||
459 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF
||
460 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
||
461 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
||
462 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF
||
463 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
||
464 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
||
465 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE
;
467 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
||
468 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_D2
||
469 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M2
||
470 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M4
;
471 case CHIPREV_EVERGREEN
:
474 /* Note that FLT_TO_INT_* instructions are vector-only instructions
475 * on Evergreen, despite what the documentation says. FLT_TO_INT
476 * can do both vector and scalar. */
477 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
||
478 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
||
479 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
||
480 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
||
481 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
||
482 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
||
483 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
||
484 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
||
485 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
||
486 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
||
487 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
||
488 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
||
489 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
||
490 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
||
491 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
||
492 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
||
493 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF
||
494 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
||
495 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
||
496 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF
||
497 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
||
498 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
||
499 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE
;
501 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
505 /* alu instructions that can execute on any unit */
506 static int is_alu_any_unit_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
508 return !is_alu_vec_unit_inst(bc
, alu
) &&
509 !is_alu_trans_unit_inst(bc
, alu
);
512 static int assign_alu_units(struct r600_bc
*bc
, struct r600_bc_alu
*alu_first
,
513 struct r600_bc_alu
*assignment
[5])
515 struct r600_bc_alu
*alu
;
516 unsigned i
, chan
, trans
;
518 for (i
= 0; i
< 5; i
++)
519 assignment
[i
] = NULL
;
521 for (alu
= alu_first
; alu
; alu
= LIST_ENTRY(struct r600_bc_alu
, alu
->list
.next
, list
)) {
522 chan
= alu
->dst
.chan
;
523 if (is_alu_trans_unit_inst(bc
, alu
))
525 else if (is_alu_vec_unit_inst(bc
, alu
))
527 else if (assignment
[chan
])
528 trans
= 1; // assume ALU_INST_PREFER_VECTOR
534 assert(0); //ALU.Trans has already been allocated
539 if (assignment
[chan
]) {
540 assert(0); //ALU.chan has already been allocated
543 assignment
[chan
] = alu
;
552 struct alu_bank_swizzle
{
553 int hw_gpr
[NUM_OF_CYCLES
][NUM_OF_COMPONENTS
];
554 int hw_cfile_addr
[4];
555 int hw_cfile_elem
[4];
558 static const unsigned cycle_for_bank_swizzle_vec
[][3] = {
559 [SQ_ALU_VEC_012
] = { 0, 1, 2 },
560 [SQ_ALU_VEC_021
] = { 0, 2, 1 },
561 [SQ_ALU_VEC_120
] = { 1, 2, 0 },
562 [SQ_ALU_VEC_102
] = { 1, 0, 2 },
563 [SQ_ALU_VEC_201
] = { 2, 0, 1 },
564 [SQ_ALU_VEC_210
] = { 2, 1, 0 }
567 static const unsigned cycle_for_bank_swizzle_scl
[][3] = {
568 [SQ_ALU_SCL_210
] = { 2, 1, 0 },
569 [SQ_ALU_SCL_122
] = { 1, 2, 2 },
570 [SQ_ALU_SCL_212
] = { 2, 1, 2 },
571 [SQ_ALU_SCL_221
] = { 2, 2, 1 }
574 static void init_bank_swizzle(struct alu_bank_swizzle
*bs
)
576 int i
, cycle
, component
;
578 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
579 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
580 bs
->hw_gpr
[cycle
][component
] = -1;
581 for (i
= 0; i
< 4; i
++)
582 bs
->hw_cfile_addr
[i
] = -1;
583 for (i
= 0; i
< 4; i
++)
584 bs
->hw_cfile_elem
[i
] = -1;
587 static int reserve_gpr(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
, unsigned cycle
)
589 if (bs
->hw_gpr
[cycle
][chan
] == -1)
590 bs
->hw_gpr
[cycle
][chan
] = sel
;
591 else if (bs
->hw_gpr
[cycle
][chan
] != (int)sel
) {
592 // Another scalar operation has already used GPR read port for channel
598 static int reserve_cfile(struct r600_bc
*bc
, struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
)
600 int res
, num_res
= 4;
601 if (bc
->chiprev
>= CHIPREV_R700
) {
605 for (res
= 0; res
< num_res
; ++res
) {
606 if (bs
->hw_cfile_addr
[res
] == -1) {
607 bs
->hw_cfile_addr
[res
] = sel
;
608 bs
->hw_cfile_elem
[res
] = chan
;
610 } else if (bs
->hw_cfile_addr
[res
] == sel
&&
611 bs
->hw_cfile_elem
[res
] == chan
)
612 return 0; // Read for this scalar element already reserved, nothing to do here.
614 // All cfile read ports are used, cannot reference vector element
618 static int is_gpr(unsigned sel
)
620 return (sel
>= 0 && sel
<= 127);
623 /* CB constants start at 512, and get translated to a kcache index when ALU
624 * clauses are constructed. Note that we handle kcache constants the same way
625 * as (the now gone) cfile constants, is that really required? */
626 static int is_cfile(unsigned sel
)
628 return (sel
> 255 && sel
< 512) ||
629 (sel
> 511 && sel
< 4607) || // Kcache before translate
630 (sel
> 127 && sel
< 192); // Kcache after translate
633 static int is_const(int sel
)
635 return is_cfile(sel
) ||
636 (sel
>= V_SQ_ALU_SRC_0
&&
637 sel
<= V_SQ_ALU_SRC_LITERAL
);
640 static int check_vector(struct r600_bc
*bc
, struct r600_bc_alu
*alu
,
641 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
643 int r
, src
, num_src
, sel
, elem
, cycle
;
645 num_src
= r600_bc_get_num_operands(bc
, alu
);
646 for (src
= 0; src
< num_src
; src
++) {
647 sel
= alu
->src
[src
].sel
;
648 elem
= alu
->src
[src
].chan
;
650 cycle
= cycle_for_bank_swizzle_vec
[bank_swizzle
][src
];
651 if (src
== 1 && sel
== alu
->src
[0].sel
&& elem
== alu
->src
[0].chan
)
652 // Nothing to do; special-case optimization,
653 // second source uses first source’s reservation
656 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
660 } else if (is_cfile(sel
)) {
661 r
= reserve_cfile(bc
, bs
, sel
, elem
);
665 // No restrictions on PV, PS, literal or special constants
670 static int check_scalar(struct r600_bc
*bc
, struct r600_bc_alu
*alu
,
671 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
673 int r
, src
, num_src
, const_count
, sel
, elem
, cycle
;
675 num_src
= r600_bc_get_num_operands(bc
, alu
);
676 for (const_count
= 0, src
= 0; src
< num_src
; ++src
) {
677 sel
= alu
->src
[src
].sel
;
678 elem
= alu
->src
[src
].chan
;
679 if (is_const(sel
)) { // Any constant, including literal and inline constants
680 if (const_count
>= 2)
681 // More than two references to a constant in
682 // transcendental operation.
688 r
= reserve_cfile(bc
, bs
, sel
, elem
);
693 for (src
= 0; src
< num_src
; ++src
) {
694 sel
= alu
->src
[src
].sel
;
695 elem
= alu
->src
[src
].chan
;
697 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
698 if (cycle
< const_count
)
699 // Cycle for GPR load conflicts with
700 // constant load in transcendental operation.
702 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
706 // PV PS restrictions
707 if (const_count
&& (sel
== 254 || sel
== 255)) {
708 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
709 if (cycle
< const_count
)
716 static int check_and_set_bank_swizzle(struct r600_bc
*bc
,
717 struct r600_bc_alu
*slots
[5])
719 struct alu_bank_swizzle bs
;
721 int i
, r
= 0, forced
= 0;
722 boolean scalar_only
= true;
723 for (i
= 0; i
< 5; i
++) {
724 if (slots
[i
] && slots
[i
]->bank_swizzle_force
) {
725 slots
[i
]->bank_swizzle
= slots
[i
]->bank_swizzle_force
;
728 if (i
< 4 && slots
[i
])
734 // just check every possible combination of bank swizzle
735 // not very efficent, but works on the first try in most of the cases
736 for (i
= 0; i
< 4; i
++)
737 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
738 bank_swizzle
[4] = SQ_ALU_SCL_210
;
739 while(bank_swizzle
[4] <= SQ_ALU_SCL_221
) {
740 init_bank_swizzle(&bs
);
741 if (scalar_only
== false) {
742 for (i
= 0; i
< 4; i
++) {
744 r
= check_vector(bc
, slots
[i
], &bs
, bank_swizzle
[i
]);
752 if (!r
&& slots
[4]) {
753 r
= check_scalar(bc
, slots
[4], &bs
, bank_swizzle
[4]);
756 for (i
= 0; i
< 5; i
++) {
758 slots
[i
]->bank_swizzle
= bank_swizzle
[i
];
766 for (i
= 0; i
< 5; i
++) {
768 if (bank_swizzle
[i
] <= SQ_ALU_VEC_210
)
771 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
776 // couldn't find a working swizzle
780 static int replace_gpr_with_pv_ps(struct r600_bc
*bc
,
781 struct r600_bc_alu
*slots
[5], struct r600_bc_alu
*alu_prev
)
783 struct r600_bc_alu
*prev
[5];
785 int i
, j
, r
, src
, num_src
;
787 r
= assign_alu_units(bc
, alu_prev
, prev
);
791 for (i
= 0; i
< 5; ++i
) {
792 if(prev
[i
] && prev
[i
]->dst
.write
&& !prev
[i
]->dst
.rel
) {
793 gpr
[i
] = prev
[i
]->dst
.sel
;
794 /* cube writes more than PV.X */
795 if (!is_alu_cube_inst(bc
, prev
[i
]) && is_alu_reduction_inst(bc
, prev
[i
]))
798 chan
[i
] = prev
[i
]->dst
.chan
;
803 for (i
= 0; i
< 5; ++i
) {
804 struct r600_bc_alu
*alu
= slots
[i
];
808 num_src
= r600_bc_get_num_operands(bc
, alu
);
809 for (src
= 0; src
< num_src
; ++src
) {
810 if (!is_gpr(alu
->src
[src
].sel
) || alu
->src
[src
].rel
)
813 if (alu
->src
[src
].sel
== gpr
[4] &&
814 alu
->src
[src
].chan
== chan
[4]) {
815 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PS
;
816 alu
->src
[src
].chan
= 0;
820 for (j
= 0; j
< 4; ++j
) {
821 if (alu
->src
[src
].sel
== gpr
[j
] &&
822 alu
->src
[src
].chan
== j
) {
823 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PV
;
824 alu
->src
[src
].chan
= chan
[j
];
834 void r600_bc_special_constants(u32 value
, unsigned *sel
, unsigned *neg
)
838 *sel
= V_SQ_ALU_SRC_0
;
841 *sel
= V_SQ_ALU_SRC_1_INT
;
844 *sel
= V_SQ_ALU_SRC_M_1_INT
;
846 case 0x3F800000: // 1.0f
847 *sel
= V_SQ_ALU_SRC_1
;
849 case 0x3F000000: // 0.5f
850 *sel
= V_SQ_ALU_SRC_0_5
;
852 case 0xBF800000: // -1.0f
853 *sel
= V_SQ_ALU_SRC_1
;
856 case 0xBF000000: // -0.5f
857 *sel
= V_SQ_ALU_SRC_0_5
;
861 *sel
= V_SQ_ALU_SRC_LITERAL
;
866 /* compute how many literal are needed */
867 static int r600_bc_alu_nliterals(struct r600_bc
*bc
, struct r600_bc_alu
*alu
,
868 uint32_t literal
[4], unsigned *nliteral
)
870 unsigned num_src
= r600_bc_get_num_operands(bc
, alu
);
873 for (i
= 0; i
< num_src
; ++i
) {
874 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
875 uint32_t value
= alu
->src
[i
].value
;
877 for (j
= 0; j
< *nliteral
; ++j
) {
878 if (literal
[j
] == value
) {
886 literal
[(*nliteral
)++] = value
;
893 static void r600_bc_alu_adjust_literals(struct r600_bc
*bc
,
894 struct r600_bc_alu
*alu
,
895 uint32_t literal
[4], unsigned nliteral
)
897 unsigned num_src
= r600_bc_get_num_operands(bc
, alu
);
900 for (i
= 0; i
< num_src
; ++i
) {
901 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
902 uint32_t value
= alu
->src
[i
].value
;
903 for (j
= 0; j
< nliteral
; ++j
) {
904 if (literal
[j
] == value
) {
905 alu
->src
[i
].chan
= j
;
913 static int merge_inst_groups(struct r600_bc
*bc
, struct r600_bc_alu
*slots
[5],
914 struct r600_bc_alu
*alu_prev
)
916 struct r600_bc_alu
*prev
[5];
917 struct r600_bc_alu
*result
[5] = { NULL
};
919 uint32_t literal
[4], prev_literal
[4];
920 unsigned nliteral
= 0, prev_nliteral
= 0;
922 int i
, j
, r
, src
, num_src
;
923 int num_once_inst
= 0;
924 int have_mova
= 0, have_rel
= 0;
926 r
= assign_alu_units(bc
, alu_prev
, prev
);
930 for (i
= 0; i
< 5; ++i
) {
931 struct r600_bc_alu
*alu
;
933 /* check number of literals */
935 if (r600_bc_alu_nliterals(bc
, prev
[i
], literal
, &nliteral
))
937 if (r600_bc_alu_nliterals(bc
, prev
[i
], prev_literal
, &prev_nliteral
))
939 if (is_alu_mova_inst(bc
, prev
[i
])) {
944 num_once_inst
+= is_alu_once_inst(bc
, prev
[i
]);
946 if (slots
[i
] && r600_bc_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
))
949 // let's check used slots
950 if (prev
[i
] && !slots
[i
]) {
953 } else if (prev
[i
] && slots
[i
]) {
954 if (result
[4] == NULL
&& prev
[4] == NULL
&& slots
[4] == NULL
) {
955 // trans unit is still free try to use it
956 if (is_alu_any_unit_inst(bc
, slots
[i
])) {
958 result
[4] = slots
[i
];
959 } else if (is_alu_any_unit_inst(bc
, prev
[i
])) {
960 result
[i
] = slots
[i
];
966 } else if(!slots
[i
]) {
969 result
[i
] = slots
[i
];
972 num_once_inst
+= is_alu_once_inst(bc
, alu
);
974 // let's check dst gpr
981 // let's check source gprs
982 num_src
= r600_bc_get_num_operands(bc
, alu
);
983 for (src
= 0; src
< num_src
; ++src
) {
984 if (alu
->src
[src
].rel
) {
990 // constants doesn't matter
991 if (!is_gpr(alu
->src
[src
].sel
))
994 for (j
= 0; j
< 5; ++j
) {
995 if (!prev
[j
] || !prev
[j
]->dst
.write
)
998 // if it's relative then we can't determin which gpr is really used
999 if (prev
[j
]->dst
.chan
== alu
->src
[src
].chan
&&
1000 (prev
[j
]->dst
.sel
== alu
->src
[src
].sel
||
1001 prev
[j
]->dst
.rel
|| alu
->src
[src
].rel
))
1007 /* more than one PRED_ or KILL_ ? */
1008 if (num_once_inst
> 1)
1011 /* check if the result can still be swizzlet */
1012 r
= check_and_set_bank_swizzle(bc
, result
);
1016 /* looks like everything worked out right, apply the changes */
1018 /* undo adding previus literals */
1019 bc
->cf_last
->ndw
-= align(prev_nliteral
, 2);
1021 /* sort instructions */
1022 for (i
= 0; i
< 5; ++i
) {
1023 slots
[i
] = result
[i
];
1025 LIST_DEL(&result
[i
]->list
);
1026 result
[i
]->last
= 0;
1027 LIST_ADDTAIL(&result
[i
]->list
, &bc
->cf_last
->alu
);
1031 /* determine new last instruction */
1032 LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
)->last
= 1;
1034 /* determine new first instruction */
1035 for (i
= 0; i
< 5; ++i
) {
1037 bc
->cf_last
->curr_bs_head
= result
[i
];
1042 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->prev2_bs_head
;
1043 bc
->cf_last
->prev2_bs_head
= NULL
;
1048 /* This code handles kcache lines as single blocks of 32 constants. We could
1049 * probably do slightly better by recognizing that we actually have two
1050 * consecutive lines of 16 constants, but the resulting code would also be
1051 * somewhat more complicated. */
1052 static int r600_bc_alloc_kcache_lines(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, int type
)
1054 struct r600_bc_kcache
*kcache
= bc
->cf_last
->kcache
;
1055 unsigned int required_lines
;
1056 unsigned int free_lines
= 0;
1057 unsigned int cache_line
[3];
1058 unsigned int count
= 0;
1062 /* Collect required cache lines. */
1063 for (i
= 0; i
< 3; ++i
) {
1067 if (alu
->src
[i
].sel
< 512)
1070 line
= ((alu
->src
[i
].sel
- 512) / 32) * 2;
1072 for (j
= 0; j
< count
; ++j
) {
1073 if (cache_line
[j
] == line
) {
1080 cache_line
[count
++] = line
;
1083 /* This should never actually happen. */
1084 if (count
>= 3) return -ENOMEM
;
1086 for (i
= 0; i
< 2; ++i
) {
1087 if (kcache
[i
].mode
== V_SQ_CF_KCACHE_NOP
) {
1092 /* Filter lines pulled in by previous intructions. Note that this is
1093 * only for the required_lines count, we can't remove these from the
1094 * cache_line array since we may have to start a new ALU clause. */
1095 for (i
= 0, required_lines
= count
; i
< count
; ++i
) {
1096 for (j
= 0; j
< 2; ++j
) {
1097 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1098 kcache
[j
].addr
== cache_line
[i
]) {
1105 /* Start a new ALU clause if needed. */
1106 if (required_lines
> free_lines
) {
1107 if ((r
= r600_bc_add_cf(bc
))) {
1110 bc
->cf_last
->inst
= (type
<< 3);
1111 kcache
= bc
->cf_last
->kcache
;
1114 /* Setup the kcache lines. */
1115 for (i
= 0; i
< count
; ++i
) {
1118 for (j
= 0; j
< 2; ++j
) {
1119 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1120 kcache
[j
].addr
== cache_line
[i
]) {
1126 if (found
) continue;
1128 for (j
= 0; j
< 2; ++j
) {
1129 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_NOP
) {
1131 kcache
[j
].addr
= cache_line
[i
];
1132 kcache
[j
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
1138 /* Alter the src operands to refer to the kcache. */
1139 for (i
= 0; i
< 3; ++i
) {
1140 static const unsigned int base
[] = {128, 160, 256, 288};
1143 if (alu
->src
[i
].sel
< 512)
1146 alu
->src
[i
].sel
-= 512;
1147 line
= (alu
->src
[i
].sel
/ 32) * 2;
1149 for (j
= 0; j
< 2; ++j
) {
1150 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1151 kcache
[j
].addr
== line
) {
1152 alu
->src
[i
].sel
&= 0x1f;
1153 alu
->src
[i
].sel
+= base
[j
];
1162 int r600_bc_add_alu_type(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
, int type
)
1164 struct r600_bc_alu
*nalu
= r600_bc_alu();
1165 struct r600_bc_alu
*lalu
;
1170 memcpy(nalu
, alu
, sizeof(struct r600_bc_alu
));
1172 if (bc
->cf_last
!= NULL
&& bc
->cf_last
->inst
!= (type
<< 3)) {
1173 /* check if we could add it anyway */
1174 if (bc
->cf_last
->inst
== (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3) &&
1175 type
== V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
) {
1176 LIST_FOR_EACH_ENTRY(lalu
, &bc
->cf_last
->alu
, list
) {
1177 if (lalu
->predicate
) {
1178 bc
->force_add_cf
= 1;
1183 bc
->force_add_cf
= 1;
1186 /* cf can contains only alu or only vtx or only tex */
1187 if (bc
->cf_last
== NULL
|| bc
->force_add_cf
) {
1188 r
= r600_bc_add_cf(bc
);
1194 bc
->cf_last
->inst
= (type
<< 3);
1196 /* Setup the kcache for this ALU instruction. This will start a new
1197 * ALU clause if needed. */
1198 if ((r
= r600_bc_alloc_kcache_lines(bc
, nalu
, type
))) {
1203 if (!bc
->cf_last
->curr_bs_head
) {
1204 bc
->cf_last
->curr_bs_head
= nalu
;
1206 /* number of gpr == the last gpr used in any alu */
1207 for (i
= 0; i
< 3; i
++) {
1208 if (nalu
->src
[i
].sel
>= bc
->ngpr
&& nalu
->src
[i
].sel
< 128) {
1209 bc
->ngpr
= nalu
->src
[i
].sel
+ 1;
1211 if (nalu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
)
1212 r600_bc_special_constants(nalu
->src
[i
].value
,
1213 &nalu
->src
[i
].sel
, &nalu
->src
[i
].neg
);
1215 if (nalu
->dst
.sel
>= bc
->ngpr
) {
1216 bc
->ngpr
= nalu
->dst
.sel
+ 1;
1218 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
1219 /* each alu use 2 dwords */
1220 bc
->cf_last
->ndw
+= 2;
1223 /* process cur ALU instructions for bank swizzle */
1225 uint32_t literal
[4];
1227 struct r600_bc_alu
*slots
[5];
1228 r
= assign_alu_units(bc
, bc
->cf_last
->curr_bs_head
, slots
);
1232 if (bc
->cf_last
->prev_bs_head
) {
1233 r
= merge_inst_groups(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1238 if (bc
->cf_last
->prev_bs_head
) {
1239 r
= replace_gpr_with_pv_ps(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1244 r
= check_and_set_bank_swizzle(bc
, slots
);
1248 for (i
= 0, nliteral
= 0; i
< 5; i
++) {
1250 r
= r600_bc_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
);
1255 bc
->cf_last
->ndw
+= align(nliteral
, 2);
1257 /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots)
1259 if ((bc
->cf_last
->ndw
>> 1) >= 120) {
1260 bc
->force_add_cf
= 1;
1263 bc
->cf_last
->prev2_bs_head
= bc
->cf_last
->prev_bs_head
;
1264 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->curr_bs_head
;
1265 bc
->cf_last
->curr_bs_head
= NULL
;
1270 int r600_bc_add_alu(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
)
1272 return r600_bc_add_alu_type(bc
, alu
, BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
));
1275 static unsigned r600_bc_num_tex_and_vtx_instructions(const struct r600_bc
*bc
)
1277 switch (bc
->chiprev
) {
1284 case CHIPREV_EVERGREEN
:
1288 R600_ERR("Unknown chiprev %d.\n", bc
->chiprev
);
1293 int r600_bc_add_vtx(struct r600_bc
*bc
, const struct r600_bc_vtx
*vtx
)
1295 struct r600_bc_vtx
*nvtx
= r600_bc_vtx();
1300 memcpy(nvtx
, vtx
, sizeof(struct r600_bc_vtx
));
1302 /* cf can contains only alu or only vtx or only tex */
1303 if (bc
->cf_last
== NULL
||
1304 (bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
1305 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) ||
1307 r
= r600_bc_add_cf(bc
);
1312 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1314 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
1315 /* each fetch use 4 dwords */
1316 bc
->cf_last
->ndw
+= 4;
1318 if ((bc
->cf_last
->ndw
/ 4) >= r600_bc_num_tex_and_vtx_instructions(bc
))
1319 bc
->force_add_cf
= 1;
1323 int r600_bc_add_tex(struct r600_bc
*bc
, const struct r600_bc_tex
*tex
)
1325 struct r600_bc_tex
*ntex
= r600_bc_tex();
1330 memcpy(ntex
, tex
, sizeof(struct r600_bc_tex
));
1332 /* we can't fetch data und use it as texture lookup address in the same TEX clause */
1333 if (bc
->cf_last
!= NULL
&&
1334 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_TEX
) {
1335 struct r600_bc_tex
*ttex
;
1336 LIST_FOR_EACH_ENTRY(ttex
, &bc
->cf_last
->tex
, list
) {
1337 if (ttex
->dst_gpr
== ntex
->src_gpr
) {
1338 bc
->force_add_cf
= 1;
1344 /* cf can contains only alu or only vtx or only tex */
1345 if (bc
->cf_last
== NULL
||
1346 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_TEX
||
1348 r
= r600_bc_add_cf(bc
);
1353 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_TEX
;
1355 if (ntex
->src_gpr
>= bc
->ngpr
) {
1356 bc
->ngpr
= ntex
->src_gpr
+ 1;
1358 if (ntex
->dst_gpr
>= bc
->ngpr
) {
1359 bc
->ngpr
= ntex
->dst_gpr
+ 1;
1361 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
1362 /* each texture fetch use 4 dwords */
1363 bc
->cf_last
->ndw
+= 4;
1365 if ((bc
->cf_last
->ndw
/ 4) >= r600_bc_num_tex_and_vtx_instructions(bc
))
1366 bc
->force_add_cf
= 1;
1370 int r600_bc_add_cfinst(struct r600_bc
*bc
, int inst
)
1373 r
= r600_bc_add_cf(bc
);
1377 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
1378 bc
->cf_last
->inst
= inst
;
1382 /* common to all 3 families */
1383 static int r600_bc_vtx_build(struct r600_bc
*bc
, struct r600_bc_vtx
*vtx
, unsigned id
)
1385 bc
->bytecode
[id
++] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
) |
1386 S_SQ_VTX_WORD0_FETCH_TYPE(vtx
->fetch_type
) |
1387 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
1388 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
) |
1389 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
1390 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
1391 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
1392 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
1393 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
1394 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
1395 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
1396 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
1397 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
1398 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
1399 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
1400 bc
->bytecode
[id
++] = S_SQ_VTX_WORD2_OFFSET(vtx
->offset
) |
1401 S_SQ_VTX_WORD2_ENDIAN_SWAP(vtx
->endian
) |
1402 S_SQ_VTX_WORD2_MEGA_FETCH(1);
1403 bc
->bytecode
[id
++] = 0;
1407 /* common to all 3 families */
1408 static int r600_bc_tex_build(struct r600_bc
*bc
, struct r600_bc_tex
*tex
, unsigned id
)
1410 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
1411 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
1412 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
1413 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
1414 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
1415 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
1416 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
1417 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
1418 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
1419 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
1420 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
1421 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
1422 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
1423 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
1424 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
1425 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
1426 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
1427 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
1428 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
1429 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
1430 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
1431 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
1432 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
1433 bc
->bytecode
[id
++] = 0;
1437 /* r600 only, r700/eg bits in r700_asm.c */
1438 static int r600_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
)
1440 /* don't replace gpr by pv or ps for destination register */
1441 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
1442 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
1443 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
1444 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
1445 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
1446 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
1447 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
1448 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
1449 S_SQ_ALU_WORD0_LAST(alu
->last
);
1452 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1453 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1454 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1455 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1456 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
1457 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
1458 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
1459 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
1460 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
1461 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
1463 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1464 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1465 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1466 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1467 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
1468 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
1469 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
1470 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
1471 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
1472 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
1473 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->predicate
) |
1474 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->predicate
);
1479 static void r600_bc_cf_vtx_build(uint32_t *bytecode
, const struct r600_bc_cf
*cf
)
1481 *bytecode
++ = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
1482 *bytecode
++ = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
1483 S_SQ_CF_WORD1_BARRIER(1) |
1484 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
1487 /* common for r600/r700 - eg in eg_asm.c */
1488 static int r600_bc_cf_build(struct r600_bc
*bc
, struct r600_bc_cf
*cf
)
1490 unsigned id
= cf
->id
;
1493 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1494 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1495 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1496 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1497 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
1498 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache
[0].mode
) |
1499 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache
[0].bank
) |
1500 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache
[1].bank
);
1502 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
>> 3) |
1503 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache
[1].mode
) |
1504 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache
[0].addr
) |
1505 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache
[1].addr
) |
1506 S_SQ_CF_ALU_WORD1_BARRIER(1) |
1507 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chiprev
== CHIPREV_R600
? cf
->r6xx_uses_waterfall
: 0) |
1508 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
1510 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1511 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1512 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1513 if (bc
->chiprev
== CHIPREV_R700
)
1514 r700_bc_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1516 r600_bc_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1518 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1519 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1520 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1521 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1522 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1523 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1524 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1525 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
1526 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
1527 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
1528 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
1529 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1530 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
) |
1531 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
1533 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1534 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1535 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1536 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1537 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1538 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1539 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1540 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1541 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1542 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
1543 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
1544 S_SQ_CF_WORD1_BARRIER(1) |
1545 S_SQ_CF_WORD1_COND(cf
->cond
) |
1546 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
1550 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1556 int r600_bc_build(struct r600_bc
*bc
)
1558 struct r600_bc_cf
*cf
;
1559 struct r600_bc_alu
*alu
;
1560 struct r600_bc_vtx
*vtx
;
1561 struct r600_bc_tex
*tex
;
1562 uint32_t literal
[4];
1567 if (bc
->callstack
[0].max
> 0)
1568 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
1569 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
1573 /* first path compute addr of each CF block */
1574 /* addr start after all the CF instructions */
1575 addr
= bc
->cf_last
->id
+ 2;
1576 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1578 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1579 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1580 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1581 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1583 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1584 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1585 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1586 /* fetch node need to be 16 bytes aligned*/
1588 addr
&= 0xFFFFFFFCUL
;
1590 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1591 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1592 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1593 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1595 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1596 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1597 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1598 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1599 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1600 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1601 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1602 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1603 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1606 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1611 bc
->ndw
= cf
->addr
+ cf
->ndw
;
1614 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
1615 if (bc
->bytecode
== NULL
)
1617 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1619 if (bc
->chiprev
== CHIPREV_EVERGREEN
)
1620 r
= eg_bc_cf_build(bc
, cf
);
1622 r
= r600_bc_cf_build(bc
, cf
);
1626 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1627 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1628 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1629 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1631 memset(literal
, 0, sizeof(literal
));
1632 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1633 r
= r600_bc_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1636 r600_bc_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
1637 switch(bc
->chiprev
) {
1639 r
= r600_bc_alu_build(bc
, alu
, addr
);
1642 case CHIPREV_EVERGREEN
: /* eg alu is same encoding as r700 */
1643 r
= r700_bc_alu_build(bc
, alu
, addr
);
1646 R600_ERR("unknown family %d\n", bc
->family
);
1653 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
1654 bc
->bytecode
[addr
++] = literal
[i
];
1657 memset(literal
, 0, sizeof(literal
));
1661 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1662 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1663 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1664 r
= r600_bc_vtx_build(bc
, vtx
, addr
);
1670 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1671 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1672 r
= r600_bc_tex_build(bc
, tex
, addr
);
1678 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1679 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1680 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1681 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1682 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1683 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1684 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1685 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1686 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1687 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1688 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1689 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1690 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1693 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1700 void r600_bc_clear(struct r600_bc
*bc
)
1702 struct r600_bc_cf
*cf
= NULL
, *next_cf
;
1705 bc
->bytecode
= NULL
;
1707 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
1708 struct r600_bc_alu
*alu
= NULL
, *next_alu
;
1709 struct r600_bc_tex
*tex
= NULL
, *next_tex
;
1710 struct r600_bc_tex
*vtx
= NULL
, *next_vtx
;
1712 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
1716 LIST_INITHEAD(&cf
->alu
);
1718 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
1722 LIST_INITHEAD(&cf
->tex
);
1724 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
1728 LIST_INITHEAD(&cf
->vtx
);
1733 LIST_INITHEAD(&cf
->list
);
1736 void r600_bc_dump(struct r600_bc
*bc
)
1738 struct r600_bc_cf
*cf
= NULL
;
1739 struct r600_bc_alu
*alu
= NULL
;
1740 struct r600_bc_vtx
*vtx
= NULL
;
1741 struct r600_bc_tex
*tex
= NULL
;
1744 uint32_t literal
[4];
1748 switch (bc
->chiprev
) {
1760 fprintf(stderr
, "bytecode %d dw -- %d gprs ---------------------\n", bc
->ndw
, bc
->ngpr
);
1761 fprintf(stderr
, " %c\n", chip
);
1763 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1767 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1768 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1769 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1770 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1771 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1772 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
1773 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
1774 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
1775 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
1777 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1778 fprintf(stderr
, "INST:%d ", cf
->inst
);
1779 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
1780 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
1781 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
1782 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
1784 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1785 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1786 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1787 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1788 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
1790 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1791 fprintf(stderr
, "INST:%d ", cf
->inst
);
1792 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
1794 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1795 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1796 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
1797 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
1798 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
1799 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
1800 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
1802 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
1803 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
1804 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
1805 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
1806 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
1807 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
1808 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
1809 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
1810 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
1812 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1813 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1814 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1815 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1816 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1817 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1818 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1819 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1820 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1821 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1822 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
1824 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1825 fprintf(stderr
, "INST:%d ", cf
->inst
);
1826 fprintf(stderr
, "COND:%X ", cf
->cond
);
1827 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
1833 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1834 r600_bc_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1836 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1837 fprintf(stderr
, "SRC0(SEL:%d ", alu
->src
[0].sel
);
1838 fprintf(stderr
, "REL:%d ", alu
->src
[0].rel
);
1839 fprintf(stderr
, "CHAN:%d ", alu
->src
[0].chan
);
1840 fprintf(stderr
, "NEG:%d) ", alu
->src
[0].neg
);
1841 fprintf(stderr
, "SRC1(SEL:%d ", alu
->src
[1].sel
);
1842 fprintf(stderr
, "REL:%d ", alu
->src
[1].rel
);
1843 fprintf(stderr
, "CHAN:%d ", alu
->src
[1].chan
);
1844 fprintf(stderr
, "NEG:%d) ", alu
->src
[1].neg
);
1845 fprintf(stderr
, "LAST:%d)\n", alu
->last
);
1847 fprintf(stderr
, "%04d %08X %c ", id
, bc
->bytecode
[id
], alu
->last
? '*' : ' ');
1848 fprintf(stderr
, "INST:%d ", alu
->inst
);
1849 fprintf(stderr
, "DST(SEL:%d ", alu
->dst
.sel
);
1850 fprintf(stderr
, "CHAN:%d ", alu
->dst
.chan
);
1851 fprintf(stderr
, "REL:%d ", alu
->dst
.rel
);
1852 fprintf(stderr
, "CLAMP:%d) ", alu
->dst
.clamp
);
1853 fprintf(stderr
, "BANK_SWIZZLE:%d ", alu
->bank_swizzle
);
1855 fprintf(stderr
, "SRC2(SEL:%d ", alu
->src
[2].sel
);
1856 fprintf(stderr
, "REL:%d ", alu
->src
[2].rel
);
1857 fprintf(stderr
, "CHAN:%d ", alu
->src
[2].chan
);
1858 fprintf(stderr
, "NEG:%d)\n", alu
->src
[2].neg
);
1860 fprintf(stderr
, "SRC0_ABS:%d ", alu
->src
[0].abs
);
1861 fprintf(stderr
, "SRC1_ABS:%d ", alu
->src
[1].abs
);
1862 fprintf(stderr
, "WRITE_MASK:%d ", alu
->dst
.write
);
1863 fprintf(stderr
, "OMOD:%d ", alu
->omod
);
1864 fprintf(stderr
, "EXECUTE_MASK:%d ", alu
->predicate
);
1865 fprintf(stderr
, "UPDATE_PRED:%d\n", alu
->predicate
);
1870 for (i
= 0; i
< nliteral
; i
++, id
++) {
1871 float *f
= (float*)(bc
->bytecode
+ id
);
1872 fprintf(stderr
, "%04d %08X\t%f\n", id
, bc
->bytecode
[id
], *f
);
1879 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1880 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1881 fprintf(stderr
, "INST:%d ", tex
->inst
);
1882 fprintf(stderr
, "RESOURCE_ID:%d ", tex
->resource_id
);
1883 fprintf(stderr
, "SRC(GPR:%d ", tex
->src_gpr
);
1884 fprintf(stderr
, "REL:%d)\n", tex
->src_rel
);
1886 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1887 fprintf(stderr
, "DST(GPR:%d ", tex
->dst_gpr
);
1888 fprintf(stderr
, "REL:%d ", tex
->dst_rel
);
1889 fprintf(stderr
, "SEL_X:%d ", tex
->dst_sel_x
);
1890 fprintf(stderr
, "SEL_Y:%d ", tex
->dst_sel_y
);
1891 fprintf(stderr
, "SEL_Z:%d ", tex
->dst_sel_z
);
1892 fprintf(stderr
, "SEL_W:%d) ", tex
->dst_sel_w
);
1893 fprintf(stderr
, "LOD_BIAS:%d ", tex
->lod_bias
);
1894 fprintf(stderr
, "COORD_TYPE_X:%d ", tex
->coord_type_x
);
1895 fprintf(stderr
, "COORD_TYPE_Y:%d ", tex
->coord_type_y
);
1896 fprintf(stderr
, "COORD_TYPE_Z:%d ", tex
->coord_type_z
);
1897 fprintf(stderr
, "COORD_TYPE_W:%d\n", tex
->coord_type_w
);
1899 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1900 fprintf(stderr
, "OFFSET_X:%d ", tex
->offset_x
);
1901 fprintf(stderr
, "OFFSET_Y:%d ", tex
->offset_y
);
1902 fprintf(stderr
, "OFFSET_Z:%d ", tex
->offset_z
);
1903 fprintf(stderr
, "SAMPLER_ID:%d ", tex
->sampler_id
);
1904 fprintf(stderr
, "SRC(SEL_X:%d ", tex
->src_sel_x
);
1905 fprintf(stderr
, "SEL_Y:%d ", tex
->src_sel_y
);
1906 fprintf(stderr
, "SEL_Z:%d ", tex
->src_sel_z
);
1907 fprintf(stderr
, "SEL_W:%d)\n", tex
->src_sel_w
);
1909 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
1913 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1914 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1915 fprintf(stderr
, "INST:%d ", vtx
->inst
);
1916 fprintf(stderr
, "FETCH_TYPE:%d ", vtx
->fetch_type
);
1917 fprintf(stderr
, "BUFFER_ID:%d\n", vtx
->buffer_id
);
1919 /* This assumes that no semantic fetches exist */
1920 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1921 fprintf(stderr
, "SRC(GPR:%d ", vtx
->src_gpr
);
1922 fprintf(stderr
, "SEL_X:%d) ", vtx
->src_sel_x
);
1923 fprintf(stderr
, "MEGA_FETCH_COUNT:%d ", vtx
->mega_fetch_count
);
1924 fprintf(stderr
, "DST(GPR:%d ", vtx
->dst_gpr
);
1925 fprintf(stderr
, "SEL_X:%d ", vtx
->dst_sel_x
);
1926 fprintf(stderr
, "SEL_Y:%d ", vtx
->dst_sel_y
);
1927 fprintf(stderr
, "SEL_Z:%d ", vtx
->dst_sel_z
);
1928 fprintf(stderr
, "SEL_W:%d) ", vtx
->dst_sel_w
);
1929 fprintf(stderr
, "USE_CONST_FIELDS:%d ", vtx
->use_const_fields
);
1930 fprintf(stderr
, "FORMAT(DATA:%d ", vtx
->data_format
);
1931 fprintf(stderr
, "NUM:%d ", vtx
->num_format_all
);
1932 fprintf(stderr
, "COMP:%d ", vtx
->format_comp_all
);
1933 fprintf(stderr
, "MODE:%d)\n", vtx
->srf_mode_all
);
1935 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1936 fprintf(stderr
, "ENDIAN:%d ", vtx
->endian
);
1937 fprintf(stderr
, "OFFSET:%d\n", vtx
->offset
);
1940 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
1945 fprintf(stderr
, "--------------------------------------\n");
1948 static void r600_vertex_data_type(enum pipe_format pformat
, unsigned *format
,
1949 unsigned *num_format
, unsigned *format_comp
, unsigned *endian
)
1951 const struct util_format_description
*desc
;
1957 *endian
= ENDIAN_NONE
;
1959 desc
= util_format_description(pformat
);
1960 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
1964 /* Find the first non-VOID channel. */
1965 for (i
= 0; i
< 4; i
++) {
1966 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
1971 *endian
= r600_endian_swap(desc
->channel
[i
].size
);
1973 switch (desc
->channel
[i
].type
) {
1974 /* Half-floats, floats, ints */
1975 case UTIL_FORMAT_TYPE_FLOAT
:
1976 switch (desc
->channel
[i
].size
) {
1978 switch (desc
->nr_channels
) {
1980 *format
= FMT_16_FLOAT
;
1983 *format
= FMT_16_16_FLOAT
;
1987 *format
= FMT_16_16_16_16_FLOAT
;
1992 switch (desc
->nr_channels
) {
1994 *format
= FMT_32_FLOAT
;
1997 *format
= FMT_32_32_FLOAT
;
2000 *format
= FMT_32_32_32_FLOAT
;
2003 *format
= FMT_32_32_32_32_FLOAT
;
2012 case UTIL_FORMAT_TYPE_UNSIGNED
:
2014 case UTIL_FORMAT_TYPE_SIGNED
:
2015 switch (desc
->channel
[i
].size
) {
2017 switch (desc
->nr_channels
) {
2026 *format
= FMT_8_8_8_8
;
2031 switch (desc
->nr_channels
) {
2036 *format
= FMT_16_16
;
2040 *format
= FMT_16_16_16_16
;
2045 switch (desc
->nr_channels
) {
2050 *format
= FMT_32_32
;
2053 *format
= FMT_32_32_32
;
2056 *format
= FMT_32_32_32_32
;
2068 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2071 if (desc
->channel
[i
].normalized
) {
2078 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
2081 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context
*rctx
, struct r600_vertex_element
*ve
)
2083 static int dump_shaders
= -1;
2086 struct r600_bc_vtx vtx
;
2087 struct pipe_vertex_element
*elements
= ve
->elements
;
2088 const struct util_format_description
*desc
;
2089 unsigned fetch_resource_start
= rctx
->family
>= CHIP_CEDAR
? 0 : 160;
2090 unsigned format
, num_format
, format_comp
, endian
;
2094 /* vertex elements offset need special handling, if offset is bigger
2095 + * than what we can put in fetch instruction then we need to alterate
2096 * the vertex resource offset. In such case in order to simplify code
2097 * we will bound one resource per elements. It's a worst case scenario.
2099 for (i
= 0; i
< ve
->count
; i
++) {
2100 ve
->vbuffer_offset
[i
] = C_SQ_VTX_WORD2_OFFSET
& elements
[i
].src_offset
;
2101 if (ve
->vbuffer_offset
[i
]) {
2102 ve
->vbuffer_need_offset
= 1;
2106 memset(&bc
, 0, sizeof(bc
));
2107 r
= r600_bc_init(&bc
, r600_get_family(rctx
->radeon
));
2111 for (i
= 0; i
< ve
->count
; i
++) {
2112 if (elements
[i
].instance_divisor
> 1) {
2113 struct r600_bc_alu alu
;
2115 memset(&alu
, 0, sizeof(alu
));
2116 alu
.inst
= BC_INST(&bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2118 alu
.src
[0].chan
= 3;
2120 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2121 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2123 alu
.dst
.sel
= i
+ 1;
2128 if ((r
= r600_bc_add_alu(&bc
, &alu
))) {
2135 for (i
= 0; i
< ve
->count
; i
++) {
2136 unsigned vbuffer_index
;
2137 r600_vertex_data_type(ve
->elements
[i
].src_format
, &format
, &num_format
, &format_comp
, &endian
);
2138 desc
= util_format_description(ve
->elements
[i
].src_format
);
2141 R600_ERR("unknown format %d\n", ve
->elements
[i
].src_format
);
2145 /* see above for vbuffer_need_offset explanation */
2146 vbuffer_index
= elements
[i
].vertex_buffer_index
;
2147 memset(&vtx
, 0, sizeof(vtx
));
2148 vtx
.buffer_id
= (ve
->vbuffer_need_offset
? i
: vbuffer_index
) + fetch_resource_start
;
2149 vtx
.fetch_type
= elements
[i
].instance_divisor
? 1 : 0;
2150 vtx
.src_gpr
= elements
[i
].instance_divisor
> 1 ? i
+ 1 : 0;
2151 vtx
.src_sel_x
= elements
[i
].instance_divisor
? 3 : 0;
2152 vtx
.mega_fetch_count
= 0x1F;
2153 vtx
.dst_gpr
= i
+ 1;
2154 vtx
.dst_sel_x
= desc
->swizzle
[0];
2155 vtx
.dst_sel_y
= desc
->swizzle
[1];
2156 vtx
.dst_sel_z
= desc
->swizzle
[2];
2157 vtx
.dst_sel_w
= desc
->swizzle
[3];
2158 vtx
.data_format
= format
;
2159 vtx
.num_format_all
= num_format
;
2160 vtx
.format_comp_all
= format_comp
;
2161 vtx
.srf_mode_all
= 1;
2162 vtx
.offset
= elements
[i
].src_offset
;
2163 vtx
.endian
= endian
;
2165 if ((r
= r600_bc_add_vtx(&bc
, &vtx
))) {
2171 r600_bc_add_cfinst(&bc
, BC_INST(&bc
, V_SQ_CF_WORD1_SQ_CF_INST_RETURN
));
2173 if ((r
= r600_bc_build(&bc
))) {
2178 if (dump_shaders
== -1)
2179 dump_shaders
= debug_get_bool_option("R600_DUMP_SHADERS", FALSE
);
2182 fprintf(stderr
, "--------------------------------------------------------------\n");
2184 fprintf(stderr
, "______________________________________________________________\n");
2187 ve
->fs_size
= bc
.ndw
*4;
2189 /* use PIPE_BIND_VERTEX_BUFFER so we use the cache buffer manager */
2190 ve
->fetch_shader
= r600_bo(rctx
->radeon
, ve
->fs_size
, 256, PIPE_BIND_VERTEX_BUFFER
, 0);
2191 if (ve
->fetch_shader
== NULL
) {
2196 bytecode
= r600_bo_map(rctx
->radeon
, ve
->fetch_shader
, 0, NULL
);
2197 if (bytecode
== NULL
) {
2199 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
2203 if (R600_BIG_ENDIAN
) {
2204 for (i
= 0; i
< ve
->fs_size
/ 4; ++i
) {
2205 bytecode
[i
] = bswap_32(bc
.bytecode
[i
]);
2208 memcpy(bytecode
, bc
.bytecode
, ve
->fs_size
);
2211 r600_bo_unmap(rctx
->radeon
, ve
->fetch_shader
);
2214 if (rctx
->family
>= CHIP_CEDAR
)
2215 evergreen_fetch_shader(ve
);
2217 r600_fetch_shader(ve
);