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
->chip_class
) {
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
);
99 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
101 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
102 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
:
103 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
104 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
105 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
106 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
107 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
108 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
:
109 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
110 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
111 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
112 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
113 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
114 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
115 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
116 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
117 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
118 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
119 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
120 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
121 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
122 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY
:
123 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW
:
126 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
127 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
:
128 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
129 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
130 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
131 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
132 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
133 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
134 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
:
135 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
136 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
:
137 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
138 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
139 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
:
140 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
:
141 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
142 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
145 "Need instruction operand number for 0x%x.\n", alu
->inst
);
153 int r700_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
);
155 static struct r600_bc_cf
*r600_bc_cf(void)
157 struct r600_bc_cf
*cf
= CALLOC_STRUCT(r600_bc_cf
);
161 LIST_INITHEAD(&cf
->list
);
162 LIST_INITHEAD(&cf
->alu
);
163 LIST_INITHEAD(&cf
->vtx
);
164 LIST_INITHEAD(&cf
->tex
);
168 static struct r600_bc_alu
*r600_bc_alu(void)
170 struct r600_bc_alu
*alu
= CALLOC_STRUCT(r600_bc_alu
);
174 LIST_INITHEAD(&alu
->list
);
178 static struct r600_bc_vtx
*r600_bc_vtx(void)
180 struct r600_bc_vtx
*vtx
= CALLOC_STRUCT(r600_bc_vtx
);
184 LIST_INITHEAD(&vtx
->list
);
188 static struct r600_bc_tex
*r600_bc_tex(void)
190 struct r600_bc_tex
*tex
= CALLOC_STRUCT(r600_bc_tex
);
194 LIST_INITHEAD(&tex
->list
);
198 void r600_bc_init(struct r600_bc
*bc
, enum chip_class chip_class
)
200 LIST_INITHEAD(&bc
->cf
);
201 bc
->chip_class
= chip_class
;
204 static int r600_bc_add_cf(struct r600_bc
*bc
)
206 struct r600_bc_cf
*cf
= r600_bc_cf();
210 LIST_ADDTAIL(&cf
->list
, &bc
->cf
);
212 cf
->id
= bc
->cf_last
->id
+ 2;
216 bc
->force_add_cf
= 0;
220 int r600_bc_add_output(struct r600_bc
*bc
, const struct r600_bc_output
*output
)
224 if (bc
->cf_last
&& (bc
->cf_last
->inst
== output
->inst
||
225 (bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
) &&
226 output
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
))) &&
227 output
->type
== bc
->cf_last
->output
.type
&&
228 output
->elem_size
== bc
->cf_last
->output
.elem_size
&&
229 output
->swizzle_x
== bc
->cf_last
->output
.swizzle_x
&&
230 output
->swizzle_y
== bc
->cf_last
->output
.swizzle_y
&&
231 output
->swizzle_z
== bc
->cf_last
->output
.swizzle_z
&&
232 output
->swizzle_w
== bc
->cf_last
->output
.swizzle_w
&&
233 (output
->burst_count
+ bc
->cf_last
->output
.burst_count
) <= 16) {
235 if ((output
->gpr
+ output
->burst_count
) == bc
->cf_last
->output
.gpr
&&
236 (output
->array_base
+ output
->burst_count
) == bc
->cf_last
->output
.array_base
) {
238 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
239 bc
->cf_last
->output
.inst
= output
->inst
;
240 bc
->cf_last
->output
.gpr
= output
->gpr
;
241 bc
->cf_last
->output
.array_base
= output
->array_base
;
242 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
245 } else if (output
->gpr
== (bc
->cf_last
->output
.gpr
+ bc
->cf_last
->output
.burst_count
) &&
246 output
->array_base
== (bc
->cf_last
->output
.array_base
+ bc
->cf_last
->output
.burst_count
)) {
248 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
249 bc
->cf_last
->output
.inst
= output
->inst
;
250 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
255 r
= r600_bc_add_cf(bc
);
258 bc
->cf_last
->inst
= output
->inst
;
259 memcpy(&bc
->cf_last
->output
, output
, sizeof(struct r600_bc_output
));
263 /* alu instructions that can ony exits once per group */
264 static int is_alu_once_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
266 switch (bc
->chip_class
) {
269 return !alu
->is_op3
&& (
270 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
271 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
272 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
273 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
274 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
275 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
276 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
277 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
278 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
279 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
280 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
281 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
282 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
283 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
284 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
285 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
286 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
287 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
288 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
289 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
290 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
291 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
292 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
293 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
294 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
295 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
296 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
297 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
298 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
299 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
300 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
301 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
302 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
303 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
307 return !alu
->is_op3
&& (
308 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
309 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
310 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
311 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
312 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
313 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
314 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
315 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
316 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
317 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
318 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
319 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
320 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
321 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
322 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
323 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
324 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
325 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
326 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
327 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
328 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
329 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
330 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
331 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
332 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
333 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
334 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
335 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
336 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
337 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
338 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
339 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
340 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
341 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
345 static int is_alu_reduction_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
347 switch (bc
->chip_class
) {
350 return !alu
->is_op3
&& (
351 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
352 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
353 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
354 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
358 return !alu
->is_op3
&& (
359 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
360 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
361 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
362 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
366 static int is_alu_cube_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
368 switch (bc
->chip_class
) {
371 return !alu
->is_op3
&&
372 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
376 return !alu
->is_op3
&&
377 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
381 static int is_alu_mova_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
383 switch (bc
->chip_class
) {
386 return !alu
->is_op3
&& (
387 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
||
388 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
||
389 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
393 return !alu
->is_op3
&& (
394 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
398 /* alu instructions that can only execute on the vector unit */
399 static int is_alu_vec_unit_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
401 return is_alu_reduction_inst(bc
, alu
) ||
402 is_alu_mova_inst(bc
, alu
) ||
403 (bc
->chip_class
== EVERGREEN
&&
404 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
);
407 /* alu instructions that can only execute on the trans unit */
408 static int is_alu_trans_unit_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
410 switch (bc
->chip_class
) {
414 return alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
||
415 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
||
416 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
||
417 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
||
418 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
||
419 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
||
420 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
||
421 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
||
422 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
||
423 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
||
424 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
||
425 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
||
426 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
||
427 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
||
428 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
||
429 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
||
430 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
||
431 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF
||
432 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
||
433 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
||
434 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF
||
435 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
||
436 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
||
437 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE
;
439 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
||
440 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_D2
||
441 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M2
||
442 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M4
;
447 /* Note that FLT_TO_INT_* instructions are vector-only instructions
448 * on Evergreen, despite what the documentation says. FLT_TO_INT
449 * can do both vector and scalar. */
450 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
||
451 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
||
452 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
||
453 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
||
454 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
||
455 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
||
456 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
||
457 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
||
458 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
||
459 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
||
460 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
||
461 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
||
462 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
||
463 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
||
464 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
||
465 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
||
466 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF
||
467 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
||
468 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
||
469 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF
||
470 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
||
471 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
||
472 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE
;
474 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
478 /* alu instructions that can execute on any unit */
479 static int is_alu_any_unit_inst(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
481 return !is_alu_vec_unit_inst(bc
, alu
) &&
482 !is_alu_trans_unit_inst(bc
, alu
);
485 static int assign_alu_units(struct r600_bc
*bc
, struct r600_bc_alu
*alu_first
,
486 struct r600_bc_alu
*assignment
[5])
488 struct r600_bc_alu
*alu
;
489 unsigned i
, chan
, trans
;
490 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
492 for (i
= 0; i
< max_slots
; i
++)
493 assignment
[i
] = NULL
;
495 for (alu
= alu_first
; alu
; alu
= LIST_ENTRY(struct r600_bc_alu
, alu
->list
.next
, list
)) {
496 chan
= alu
->dst
.chan
;
499 else if (is_alu_trans_unit_inst(bc
, alu
))
501 else if (is_alu_vec_unit_inst(bc
, alu
))
503 else if (assignment
[chan
])
504 trans
= 1; /* Assume ALU_INST_PREFER_VECTOR. */
510 assert(0); /* ALU.Trans has already been allocated. */
515 if (assignment
[chan
]) {
516 assert(0); /* ALU.chan has already been allocated. */
519 assignment
[chan
] = alu
;
528 struct alu_bank_swizzle
{
529 int hw_gpr
[NUM_OF_CYCLES
][NUM_OF_COMPONENTS
];
530 int hw_cfile_addr
[4];
531 int hw_cfile_elem
[4];
534 static const unsigned cycle_for_bank_swizzle_vec
[][3] = {
535 [SQ_ALU_VEC_012
] = { 0, 1, 2 },
536 [SQ_ALU_VEC_021
] = { 0, 2, 1 },
537 [SQ_ALU_VEC_120
] = { 1, 2, 0 },
538 [SQ_ALU_VEC_102
] = { 1, 0, 2 },
539 [SQ_ALU_VEC_201
] = { 2, 0, 1 },
540 [SQ_ALU_VEC_210
] = { 2, 1, 0 }
543 static const unsigned cycle_for_bank_swizzle_scl
[][3] = {
544 [SQ_ALU_SCL_210
] = { 2, 1, 0 },
545 [SQ_ALU_SCL_122
] = { 1, 2, 2 },
546 [SQ_ALU_SCL_212
] = { 2, 1, 2 },
547 [SQ_ALU_SCL_221
] = { 2, 2, 1 }
550 static void init_bank_swizzle(struct alu_bank_swizzle
*bs
)
552 int i
, cycle
, component
;
554 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
555 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
556 bs
->hw_gpr
[cycle
][component
] = -1;
557 for (i
= 0; i
< 4; i
++)
558 bs
->hw_cfile_addr
[i
] = -1;
559 for (i
= 0; i
< 4; i
++)
560 bs
->hw_cfile_elem
[i
] = -1;
563 static int reserve_gpr(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
, unsigned cycle
)
565 if (bs
->hw_gpr
[cycle
][chan
] == -1)
566 bs
->hw_gpr
[cycle
][chan
] = sel
;
567 else if (bs
->hw_gpr
[cycle
][chan
] != (int)sel
) {
568 /* Another scalar operation has already used the GPR read port for the channel. */
574 static int reserve_cfile(struct r600_bc
*bc
, struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
)
576 int res
, num_res
= 4;
577 if (bc
->chip_class
>= R700
) {
581 for (res
= 0; res
< num_res
; ++res
) {
582 if (bs
->hw_cfile_addr
[res
] == -1) {
583 bs
->hw_cfile_addr
[res
] = sel
;
584 bs
->hw_cfile_elem
[res
] = chan
;
586 } else if (bs
->hw_cfile_addr
[res
] == sel
&&
587 bs
->hw_cfile_elem
[res
] == chan
)
588 return 0; /* Read for this scalar element already reserved, nothing to do here. */
590 /* All cfile read ports are used, cannot reference vector element. */
594 static int is_gpr(unsigned sel
)
596 return (sel
>= 0 && sel
<= 127);
599 /* CB constants start at 512, and get translated to a kcache index when ALU
600 * clauses are constructed. Note that we handle kcache constants the same way
601 * as (the now gone) cfile constants, is that really required? */
602 static int is_cfile(unsigned sel
)
604 return (sel
> 255 && sel
< 512) ||
605 (sel
> 511 && sel
< 4607) || /* Kcache before translation. */
606 (sel
> 127 && sel
< 192); /* Kcache after translation. */
609 static int is_const(int sel
)
611 return is_cfile(sel
) ||
612 (sel
>= V_SQ_ALU_SRC_0
&&
613 sel
<= V_SQ_ALU_SRC_LITERAL
);
616 static int check_vector(struct r600_bc
*bc
, struct r600_bc_alu
*alu
,
617 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
619 int r
, src
, num_src
, sel
, elem
, cycle
;
621 num_src
= r600_bc_get_num_operands(bc
, alu
);
622 for (src
= 0; src
< num_src
; src
++) {
623 sel
= alu
->src
[src
].sel
;
624 elem
= alu
->src
[src
].chan
;
626 cycle
= cycle_for_bank_swizzle_vec
[bank_swizzle
][src
];
627 if (src
== 1 && sel
== alu
->src
[0].sel
&& elem
== alu
->src
[0].chan
)
628 /* Nothing to do; special-case optimization,
629 * second source uses first source’s reservation. */
632 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
636 } else if (is_cfile(sel
)) {
637 r
= reserve_cfile(bc
, bs
, sel
, elem
);
641 /* No restrictions on PV, PS, literal or special constants. */
646 static int check_scalar(struct r600_bc
*bc
, struct r600_bc_alu
*alu
,
647 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
649 int r
, src
, num_src
, const_count
, sel
, elem
, cycle
;
651 num_src
= r600_bc_get_num_operands(bc
, alu
);
652 for (const_count
= 0, src
= 0; src
< num_src
; ++src
) {
653 sel
= alu
->src
[src
].sel
;
654 elem
= alu
->src
[src
].chan
;
655 if (is_const(sel
)) { /* Any constant, including literal and inline constants. */
656 if (const_count
>= 2)
657 /* More than two references to a constant in
658 * transcendental operation. */
664 r
= reserve_cfile(bc
, bs
, sel
, elem
);
669 for (src
= 0; src
< num_src
; ++src
) {
670 sel
= alu
->src
[src
].sel
;
671 elem
= alu
->src
[src
].chan
;
673 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
674 if (cycle
< const_count
)
675 /* Cycle for GPR load conflicts with
676 * constant load in transcendental operation. */
678 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
682 /* PV PS restrictions */
683 if (const_count
&& (sel
== 254 || sel
== 255)) {
684 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
685 if (cycle
< const_count
)
692 static int check_and_set_bank_swizzle(struct r600_bc
*bc
,
693 struct r600_bc_alu
*slots
[5])
695 struct alu_bank_swizzle bs
;
697 int i
, r
= 0, forced
= 0;
698 boolean scalar_only
= bc
->chip_class
== CAYMAN
? false : true;
699 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
701 for (i
= 0; i
< max_slots
; i
++) {
702 if (slots
[i
] && slots
[i
]->bank_swizzle_force
) {
703 slots
[i
]->bank_swizzle
= slots
[i
]->bank_swizzle_force
;
706 if (i
< 4 && slots
[i
])
712 /* Just check every possible combination of bank swizzle.
713 * Not very efficent, but works on the first try in most of the cases. */
714 for (i
= 0; i
< 4; i
++)
715 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
716 bank_swizzle
[4] = SQ_ALU_SCL_210
;
717 while(bank_swizzle
[4] <= SQ_ALU_SCL_221
) {
719 if (max_slots
== 4) {
720 for (i
= 0; i
< max_slots
; i
++) {
721 if (bank_swizzle
[i
] == SQ_ALU_VEC_210
)
725 init_bank_swizzle(&bs
);
726 if (scalar_only
== false) {
727 for (i
= 0; i
< 4; i
++) {
729 r
= check_vector(bc
, slots
[i
], &bs
, bank_swizzle
[i
]);
737 if (!r
&& slots
[4] && max_slots
== 5) {
738 r
= check_scalar(bc
, slots
[4], &bs
, bank_swizzle
[4]);
741 for (i
= 0; i
< max_slots
; i
++) {
743 slots
[i
]->bank_swizzle
= bank_swizzle
[i
];
751 for (i
= 0; i
< max_slots
; i
++) {
753 if (bank_swizzle
[i
] <= SQ_ALU_VEC_210
)
756 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
761 /* Couldn't find a working swizzle. */
765 static int replace_gpr_with_pv_ps(struct r600_bc
*bc
,
766 struct r600_bc_alu
*slots
[5], struct r600_bc_alu
*alu_prev
)
768 struct r600_bc_alu
*prev
[5];
770 int i
, j
, r
, src
, num_src
;
771 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
773 r
= assign_alu_units(bc
, alu_prev
, prev
);
777 for (i
= 0; i
< max_slots
; ++i
) {
778 if(prev
[i
] && prev
[i
]->dst
.write
&& !prev
[i
]->dst
.rel
) {
779 gpr
[i
] = prev
[i
]->dst
.sel
;
780 /* cube writes more than PV.X */
781 if (!is_alu_cube_inst(bc
, prev
[i
]) && is_alu_reduction_inst(bc
, prev
[i
]))
784 chan
[i
] = prev
[i
]->dst
.chan
;
789 for (i
= 0; i
< max_slots
; ++i
) {
790 struct r600_bc_alu
*alu
= slots
[i
];
794 num_src
= r600_bc_get_num_operands(bc
, alu
);
795 for (src
= 0; src
< num_src
; ++src
) {
796 if (!is_gpr(alu
->src
[src
].sel
) || alu
->src
[src
].rel
)
799 if (bc
->chip_class
< CAYMAN
) {
800 if (alu
->src
[src
].sel
== gpr
[4] &&
801 alu
->src
[src
].chan
== chan
[4]) {
802 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PS
;
803 alu
->src
[src
].chan
= 0;
808 for (j
= 0; j
< 4; ++j
) {
809 if (alu
->src
[src
].sel
== gpr
[j
] &&
810 alu
->src
[src
].chan
== j
) {
811 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PV
;
812 alu
->src
[src
].chan
= chan
[j
];
822 void r600_bc_special_constants(u32 value
, unsigned *sel
, unsigned *neg
)
826 *sel
= V_SQ_ALU_SRC_0
;
829 *sel
= V_SQ_ALU_SRC_1_INT
;
832 *sel
= V_SQ_ALU_SRC_M_1_INT
;
834 case 0x3F800000: /* 1.0f */
835 *sel
= V_SQ_ALU_SRC_1
;
837 case 0x3F000000: /* 0.5f */
838 *sel
= V_SQ_ALU_SRC_0_5
;
840 case 0xBF800000: /* -1.0f */
841 *sel
= V_SQ_ALU_SRC_1
;
844 case 0xBF000000: /* -0.5f */
845 *sel
= V_SQ_ALU_SRC_0_5
;
849 *sel
= V_SQ_ALU_SRC_LITERAL
;
854 /* compute how many literal are needed */
855 static int r600_bc_alu_nliterals(struct r600_bc
*bc
, struct r600_bc_alu
*alu
,
856 uint32_t literal
[4], unsigned *nliteral
)
858 unsigned num_src
= r600_bc_get_num_operands(bc
, alu
);
861 for (i
= 0; i
< num_src
; ++i
) {
862 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
863 uint32_t value
= alu
->src
[i
].value
;
865 for (j
= 0; j
< *nliteral
; ++j
) {
866 if (literal
[j
] == value
) {
874 literal
[(*nliteral
)++] = value
;
881 static void r600_bc_alu_adjust_literals(struct r600_bc
*bc
,
882 struct r600_bc_alu
*alu
,
883 uint32_t literal
[4], unsigned nliteral
)
885 unsigned num_src
= r600_bc_get_num_operands(bc
, alu
);
888 for (i
= 0; i
< num_src
; ++i
) {
889 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
890 uint32_t value
= alu
->src
[i
].value
;
891 for (j
= 0; j
< nliteral
; ++j
) {
892 if (literal
[j
] == value
) {
893 alu
->src
[i
].chan
= j
;
901 static int merge_inst_groups(struct r600_bc
*bc
, struct r600_bc_alu
*slots
[5],
902 struct r600_bc_alu
*alu_prev
)
904 struct r600_bc_alu
*prev
[5];
905 struct r600_bc_alu
*result
[5] = { NULL
};
907 uint32_t literal
[4], prev_literal
[4];
908 unsigned nliteral
= 0, prev_nliteral
= 0;
910 int i
, j
, r
, src
, num_src
;
911 int num_once_inst
= 0;
912 int have_mova
= 0, have_rel
= 0;
913 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
915 r
= assign_alu_units(bc
, alu_prev
, prev
);
919 for (i
= 0; i
< max_slots
; ++i
) {
920 struct r600_bc_alu
*alu
;
922 /* check number of literals */
924 if (r600_bc_alu_nliterals(bc
, prev
[i
], literal
, &nliteral
))
926 if (r600_bc_alu_nliterals(bc
, prev
[i
], prev_literal
, &prev_nliteral
))
928 if (is_alu_mova_inst(bc
, prev
[i
])) {
933 num_once_inst
+= is_alu_once_inst(bc
, prev
[i
]);
935 if (slots
[i
] && r600_bc_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
))
938 /* Let's check used slots. */
939 if (prev
[i
] && !slots
[i
]) {
942 } else if (prev
[i
] && slots
[i
]) {
943 if (max_slots
== 5 && result
[4] == NULL
&& prev
[4] == NULL
&& slots
[4] == NULL
) {
944 /* Trans unit is still free try to use it. */
945 if (is_alu_any_unit_inst(bc
, slots
[i
])) {
947 result
[4] = slots
[i
];
948 } else if (is_alu_any_unit_inst(bc
, prev
[i
])) {
949 result
[i
] = slots
[i
];
955 } else if(!slots
[i
]) {
958 result
[i
] = slots
[i
];
961 num_once_inst
+= is_alu_once_inst(bc
, alu
);
963 /* Let's check dst gpr. */
970 /* Let's check source gprs */
971 num_src
= r600_bc_get_num_operands(bc
, alu
);
972 for (src
= 0; src
< num_src
; ++src
) {
973 if (alu
->src
[src
].rel
) {
979 /* Constants don't matter. */
980 if (!is_gpr(alu
->src
[src
].sel
))
983 for (j
= 0; j
< max_slots
; ++j
) {
984 if (!prev
[j
] || !prev
[j
]->dst
.write
)
987 /* If it's relative then we can't determin which gpr is really used. */
988 if (prev
[j
]->dst
.chan
== alu
->src
[src
].chan
&&
989 (prev
[j
]->dst
.sel
== alu
->src
[src
].sel
||
990 prev
[j
]->dst
.rel
|| alu
->src
[src
].rel
))
996 /* more than one PRED_ or KILL_ ? */
997 if (num_once_inst
> 1)
1000 /* check if the result can still be swizzlet */
1001 r
= check_and_set_bank_swizzle(bc
, result
);
1005 /* looks like everything worked out right, apply the changes */
1007 /* undo adding previus literals */
1008 bc
->cf_last
->ndw
-= align(prev_nliteral
, 2);
1010 /* sort instructions */
1011 for (i
= 0; i
< max_slots
; ++i
) {
1012 slots
[i
] = result
[i
];
1014 LIST_DEL(&result
[i
]->list
);
1015 result
[i
]->last
= 0;
1016 LIST_ADDTAIL(&result
[i
]->list
, &bc
->cf_last
->alu
);
1020 /* determine new last instruction */
1021 LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
)->last
= 1;
1023 /* determine new first instruction */
1024 for (i
= 0; i
< max_slots
; ++i
) {
1026 bc
->cf_last
->curr_bs_head
= result
[i
];
1031 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->prev2_bs_head
;
1032 bc
->cf_last
->prev2_bs_head
= NULL
;
1037 /* This code handles kcache lines as single blocks of 32 constants. We could
1038 * probably do slightly better by recognizing that we actually have two
1039 * consecutive lines of 16 constants, but the resulting code would also be
1040 * somewhat more complicated. */
1041 static int r600_bc_alloc_kcache_lines(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, int type
)
1043 struct r600_bc_kcache
*kcache
= bc
->cf_last
->kcache
;
1044 unsigned int required_lines
;
1045 unsigned int free_lines
= 0;
1046 unsigned int cache_line
[3];
1047 unsigned int count
= 0;
1051 /* Collect required cache lines. */
1052 for (i
= 0; i
< 3; ++i
) {
1053 boolean found
= false;
1056 if (alu
->src
[i
].sel
< 512)
1059 line
= ((alu
->src
[i
].sel
- 512) / 32) * 2;
1061 for (j
= 0; j
< count
; ++j
) {
1062 if (cache_line
[j
] == line
) {
1069 cache_line
[count
++] = line
;
1072 /* This should never actually happen. */
1073 if (count
>= 3) return -ENOMEM
;
1075 for (i
= 0; i
< 2; ++i
) {
1076 if (kcache
[i
].mode
== V_SQ_CF_KCACHE_NOP
) {
1081 /* Filter lines pulled in by previous intructions. Note that this is
1082 * only for the required_lines count, we can't remove these from the
1083 * cache_line array since we may have to start a new ALU clause. */
1084 for (i
= 0, required_lines
= count
; i
< count
; ++i
) {
1085 for (j
= 0; j
< 2; ++j
) {
1086 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1087 kcache
[j
].addr
== cache_line
[i
]) {
1094 /* Start a new ALU clause if needed. */
1095 if (required_lines
> free_lines
) {
1096 if ((r
= r600_bc_add_cf(bc
))) {
1099 bc
->cf_last
->inst
= (type
<< 3);
1100 kcache
= bc
->cf_last
->kcache
;
1103 /* Setup the kcache lines. */
1104 for (i
= 0; i
< count
; ++i
) {
1105 boolean found
= false;
1107 for (j
= 0; j
< 2; ++j
) {
1108 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1109 kcache
[j
].addr
== cache_line
[i
]) {
1115 if (found
) continue;
1117 for (j
= 0; j
< 2; ++j
) {
1118 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_NOP
) {
1120 kcache
[j
].addr
= cache_line
[i
];
1121 kcache
[j
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
1127 /* Alter the src operands to refer to the kcache. */
1128 for (i
= 0; i
< 3; ++i
) {
1129 static const unsigned int base
[] = {128, 160, 256, 288};
1132 if (alu
->src
[i
].sel
< 512)
1135 alu
->src
[i
].sel
-= 512;
1136 line
= (alu
->src
[i
].sel
/ 32) * 2;
1138 for (j
= 0; j
< 2; ++j
) {
1139 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1140 kcache
[j
].addr
== line
) {
1141 alu
->src
[i
].sel
&= 0x1f;
1142 alu
->src
[i
].sel
+= base
[j
];
1151 int r600_bc_add_alu_type(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
, int type
)
1153 struct r600_bc_alu
*nalu
= r600_bc_alu();
1154 struct r600_bc_alu
*lalu
;
1159 memcpy(nalu
, alu
, sizeof(struct r600_bc_alu
));
1161 if (bc
->cf_last
!= NULL
&& bc
->cf_last
->inst
!= (type
<< 3)) {
1162 /* check if we could add it anyway */
1163 if (bc
->cf_last
->inst
== (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3) &&
1164 type
== V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
) {
1165 LIST_FOR_EACH_ENTRY(lalu
, &bc
->cf_last
->alu
, list
) {
1166 if (lalu
->predicate
) {
1167 bc
->force_add_cf
= 1;
1172 bc
->force_add_cf
= 1;
1175 /* cf can contains only alu or only vtx or only tex */
1176 if (bc
->cf_last
== NULL
|| bc
->force_add_cf
) {
1177 r
= r600_bc_add_cf(bc
);
1183 bc
->cf_last
->inst
= (type
<< 3);
1185 /* Setup the kcache for this ALU instruction. This will start a new
1186 * ALU clause if needed. */
1187 if ((r
= r600_bc_alloc_kcache_lines(bc
, nalu
, type
))) {
1192 if (!bc
->cf_last
->curr_bs_head
) {
1193 bc
->cf_last
->curr_bs_head
= nalu
;
1195 /* number of gpr == the last gpr used in any alu */
1196 for (i
= 0; i
< 3; i
++) {
1197 if (nalu
->src
[i
].sel
>= bc
->ngpr
&& nalu
->src
[i
].sel
< 128) {
1198 bc
->ngpr
= nalu
->src
[i
].sel
+ 1;
1200 if (nalu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
)
1201 r600_bc_special_constants(nalu
->src
[i
].value
,
1202 &nalu
->src
[i
].sel
, &nalu
->src
[i
].neg
);
1204 if (nalu
->dst
.sel
>= bc
->ngpr
) {
1205 bc
->ngpr
= nalu
->dst
.sel
+ 1;
1207 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
1208 /* each alu use 2 dwords */
1209 bc
->cf_last
->ndw
+= 2;
1212 /* process cur ALU instructions for bank swizzle */
1214 uint32_t literal
[4];
1216 struct r600_bc_alu
*slots
[5];
1217 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
1218 r
= assign_alu_units(bc
, bc
->cf_last
->curr_bs_head
, slots
);
1222 if (bc
->cf_last
->prev_bs_head
) {
1223 r
= merge_inst_groups(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1228 if (bc
->cf_last
->prev_bs_head
) {
1229 r
= replace_gpr_with_pv_ps(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1234 r
= check_and_set_bank_swizzle(bc
, slots
);
1238 for (i
= 0, nliteral
= 0; i
< max_slots
; i
++) {
1240 r
= r600_bc_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
);
1245 bc
->cf_last
->ndw
+= align(nliteral
, 2);
1247 /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots)
1249 if ((bc
->cf_last
->ndw
>> 1) >= 120) {
1250 bc
->force_add_cf
= 1;
1253 bc
->cf_last
->prev2_bs_head
= bc
->cf_last
->prev_bs_head
;
1254 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->curr_bs_head
;
1255 bc
->cf_last
->curr_bs_head
= NULL
;
1260 int r600_bc_add_alu(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
)
1262 return r600_bc_add_alu_type(bc
, alu
, BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
));
1265 static unsigned r600_bc_num_tex_and_vtx_instructions(const struct r600_bc
*bc
)
1267 switch (bc
->chip_class
) {
1279 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1284 static inline boolean
last_inst_was_vtx_fetch(struct r600_bc
*bc
)
1286 if (bc
->chip_class
== CAYMAN
) {
1287 if (bc
->cf_last
->inst
!= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
)
1290 if (bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
1291 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
)
1297 int r600_bc_add_vtx(struct r600_bc
*bc
, const struct r600_bc_vtx
*vtx
)
1299 struct r600_bc_vtx
*nvtx
= r600_bc_vtx();
1304 memcpy(nvtx
, vtx
, sizeof(struct r600_bc_vtx
));
1306 /* cf can contains only alu or only vtx or only tex */
1307 if (bc
->cf_last
== NULL
||
1308 last_inst_was_vtx_fetch(bc
) ||
1310 r
= r600_bc_add_cf(bc
);
1315 if (bc
->chip_class
== CAYMAN
)
1316 bc
->cf_last
->inst
= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
;
1318 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1320 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
1321 /* each fetch use 4 dwords */
1322 bc
->cf_last
->ndw
+= 4;
1324 if ((bc
->cf_last
->ndw
/ 4) >= r600_bc_num_tex_and_vtx_instructions(bc
))
1325 bc
->force_add_cf
= 1;
1329 int r600_bc_add_tex(struct r600_bc
*bc
, const struct r600_bc_tex
*tex
)
1331 struct r600_bc_tex
*ntex
= r600_bc_tex();
1336 memcpy(ntex
, tex
, sizeof(struct r600_bc_tex
));
1338 /* we can't fetch data und use it as texture lookup address in the same TEX clause */
1339 if (bc
->cf_last
!= NULL
&&
1340 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_TEX
) {
1341 struct r600_bc_tex
*ttex
;
1342 LIST_FOR_EACH_ENTRY(ttex
, &bc
->cf_last
->tex
, list
) {
1343 if (ttex
->dst_gpr
== ntex
->src_gpr
) {
1344 bc
->force_add_cf
= 1;
1348 /* slight hack to make gradients always go into same cf */
1349 if (ntex
->inst
== SQ_TEX_INST_SET_GRADIENTS_H
)
1350 bc
->force_add_cf
= 1;
1353 /* cf can contains only alu or only vtx or only tex */
1354 if (bc
->cf_last
== NULL
||
1355 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_TEX
||
1357 r
= r600_bc_add_cf(bc
);
1362 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_TEX
;
1364 if (ntex
->src_gpr
>= bc
->ngpr
) {
1365 bc
->ngpr
= ntex
->src_gpr
+ 1;
1367 if (ntex
->dst_gpr
>= bc
->ngpr
) {
1368 bc
->ngpr
= ntex
->dst_gpr
+ 1;
1370 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
1371 /* each texture fetch use 4 dwords */
1372 bc
->cf_last
->ndw
+= 4;
1374 if ((bc
->cf_last
->ndw
/ 4) >= r600_bc_num_tex_and_vtx_instructions(bc
))
1375 bc
->force_add_cf
= 1;
1379 int r600_bc_add_cfinst(struct r600_bc
*bc
, int inst
)
1382 r
= r600_bc_add_cf(bc
);
1386 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
1387 bc
->cf_last
->inst
= inst
;
1391 int cm_bc_add_cf_end(struct r600_bc
*bc
)
1393 return r600_bc_add_cfinst(bc
, CM_V_SQ_CF_WORD1_SQ_CF_INST_END
);
1396 /* common to all 3 families */
1397 static int r600_bc_vtx_build(struct r600_bc
*bc
, struct r600_bc_vtx
*vtx
, unsigned id
)
1399 bc
->bytecode
[id
] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
) |
1400 S_SQ_VTX_WORD0_FETCH_TYPE(vtx
->fetch_type
) |
1401 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
1402 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
);
1403 if (bc
->chip_class
< CAYMAN
)
1404 bc
->bytecode
[id
] |= S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
1406 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
1407 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
1408 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
1409 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
1410 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
1411 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
1412 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
1413 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
1414 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
1415 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
1416 bc
->bytecode
[id
] = S_SQ_VTX_WORD2_OFFSET(vtx
->offset
)|
1417 S_SQ_VTX_WORD2_ENDIAN_SWAP(vtx
->endian
);
1418 if (bc
->chip_class
< CAYMAN
)
1419 bc
->bytecode
[id
] |= S_SQ_VTX_WORD2_MEGA_FETCH(1);
1421 bc
->bytecode
[id
++] = 0;
1425 /* common to all 3 families */
1426 static int r600_bc_tex_build(struct r600_bc
*bc
, struct r600_bc_tex
*tex
, unsigned id
)
1428 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
1429 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
1430 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
1431 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
1432 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
1433 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
1434 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
1435 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
1436 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
1437 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
1438 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
1439 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
1440 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
1441 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
1442 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
1443 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
1444 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
1445 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
1446 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
1447 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
1448 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
1449 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
1450 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
1451 bc
->bytecode
[id
++] = 0;
1455 /* r600 only, r700/eg bits in r700_asm.c */
1456 static int r600_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
)
1458 /* don't replace gpr by pv or ps for destination register */
1459 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
1460 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
1461 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
1462 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
1463 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
1464 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
1465 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
1466 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
1467 S_SQ_ALU_WORD0_LAST(alu
->last
);
1470 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1471 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1472 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1473 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1474 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
1475 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
1476 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
1477 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
1478 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
1479 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
1481 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1482 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1483 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1484 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1485 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
1486 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
1487 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
1488 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
1489 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
1490 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
1491 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->predicate
) |
1492 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->predicate
);
1497 static void r600_bc_cf_vtx_build(uint32_t *bytecode
, const struct r600_bc_cf
*cf
)
1499 *bytecode
++ = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
1500 *bytecode
++ = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
1501 S_SQ_CF_WORD1_BARRIER(1) |
1502 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
1505 /* common for r600/r700 - eg in eg_asm.c */
1506 static int r600_bc_cf_build(struct r600_bc
*bc
, struct r600_bc_cf
*cf
)
1508 unsigned id
= cf
->id
;
1511 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1512 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1513 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1514 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1515 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
1516 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache
[0].mode
) |
1517 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache
[0].bank
) |
1518 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache
[1].bank
);
1520 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
>> 3) |
1521 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache
[1].mode
) |
1522 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache
[0].addr
) |
1523 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache
[1].addr
) |
1524 S_SQ_CF_ALU_WORD1_BARRIER(1) |
1525 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chip_class
== R600
? cf
->r6xx_uses_waterfall
: 0) |
1526 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
1528 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1529 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1530 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1531 if (bc
->chip_class
== R700
)
1532 r700_bc_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1534 r600_bc_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1536 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1537 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1538 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1539 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1540 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1541 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1542 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1543 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
1544 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
1545 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
1546 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
1547 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1548 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
) |
1549 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
1551 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1552 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1553 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1554 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1555 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1556 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1557 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1558 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1559 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1560 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
1561 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
1562 S_SQ_CF_WORD1_BARRIER(1) |
1563 S_SQ_CF_WORD1_COND(cf
->cond
) |
1564 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
1568 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1574 int r600_bc_build(struct r600_bc
*bc
)
1576 struct r600_bc_cf
*cf
;
1577 struct r600_bc_alu
*alu
;
1578 struct r600_bc_vtx
*vtx
;
1579 struct r600_bc_tex
*tex
;
1580 uint32_t literal
[4];
1585 if (bc
->callstack
[0].max
> 0)
1586 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
1587 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
1591 /* first path compute addr of each CF block */
1592 /* addr start after all the CF instructions */
1593 addr
= bc
->cf_last
->id
+ 2;
1594 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1596 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1597 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1598 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1599 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1601 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1602 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1603 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1604 /* fetch node need to be 16 bytes aligned*/
1606 addr
&= 0xFFFFFFFCUL
;
1608 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1609 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1610 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1611 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1613 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1614 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1615 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1616 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1617 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1618 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1619 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1620 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1621 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1622 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
1625 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1630 bc
->ndw
= cf
->addr
+ cf
->ndw
;
1633 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
1634 if (bc
->bytecode
== NULL
)
1636 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1638 if (bc
->chip_class
>= EVERGREEN
)
1639 r
= eg_bc_cf_build(bc
, cf
);
1641 r
= r600_bc_cf_build(bc
, cf
);
1645 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1646 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1647 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1648 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1650 memset(literal
, 0, sizeof(literal
));
1651 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1652 r
= r600_bc_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1655 r600_bc_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
1656 switch(bc
->chip_class
) {
1658 r
= r600_bc_alu_build(bc
, alu
, addr
);
1661 case EVERGREEN
: /* eg alu is same encoding as r700 */
1662 case CAYMAN
: /* eg alu is same encoding as r700 */
1663 r
= r700_bc_alu_build(bc
, alu
, addr
);
1666 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
1673 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
1674 bc
->bytecode
[addr
++] = literal
[i
];
1677 memset(literal
, 0, sizeof(literal
));
1681 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1682 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1683 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1684 r
= r600_bc_vtx_build(bc
, vtx
, addr
);
1690 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1691 if (bc
->chip_class
== CAYMAN
) {
1692 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1693 r
= r600_bc_vtx_build(bc
, vtx
, addr
);
1699 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1700 r
= r600_bc_tex_build(bc
, tex
, addr
);
1706 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1707 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1708 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1709 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1710 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1711 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1712 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1713 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1714 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1715 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1716 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1717 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1718 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1719 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
1722 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1729 void r600_bc_clear(struct r600_bc
*bc
)
1731 struct r600_bc_cf
*cf
= NULL
, *next_cf
;
1734 bc
->bytecode
= NULL
;
1736 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
1737 struct r600_bc_alu
*alu
= NULL
, *next_alu
;
1738 struct r600_bc_tex
*tex
= NULL
, *next_tex
;
1739 struct r600_bc_tex
*vtx
= NULL
, *next_vtx
;
1741 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
1745 LIST_INITHEAD(&cf
->alu
);
1747 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
1751 LIST_INITHEAD(&cf
->tex
);
1753 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
1757 LIST_INITHEAD(&cf
->vtx
);
1762 LIST_INITHEAD(&cf
->list
);
1765 void r600_bc_dump(struct r600_bc
*bc
)
1767 struct r600_bc_cf
*cf
= NULL
;
1768 struct r600_bc_alu
*alu
= NULL
;
1769 struct r600_bc_vtx
*vtx
= NULL
;
1770 struct r600_bc_tex
*tex
= NULL
;
1773 uint32_t literal
[4];
1777 switch (bc
->chip_class
) {
1792 fprintf(stderr
, "bytecode %d dw -- %d gprs ---------------------\n", bc
->ndw
, bc
->ngpr
);
1793 fprintf(stderr
, " %c\n", chip
);
1795 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1799 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
1800 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
1801 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
1802 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
1803 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1804 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
1805 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
1806 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
1807 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
1809 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
1810 fprintf(stderr
, "INST:%d ", cf
->inst
);
1811 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
1812 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
1813 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
1814 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
1816 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1817 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1818 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1819 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1820 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
1822 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
1823 fprintf(stderr
, "INST:%d ", cf
->inst
);
1824 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
1826 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1827 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1828 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1829 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1830 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
1831 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
1832 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
1833 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
1834 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
1836 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
1837 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
1838 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
1839 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
1840 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
1841 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
1842 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
1843 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
1844 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
1846 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1847 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1848 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1849 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1850 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1851 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1852 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1853 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1854 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1855 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
1856 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1857 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
1859 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
1860 fprintf(stderr
, "INST:%d ", cf
->inst
);
1861 fprintf(stderr
, "COND:%X ", cf
->cond
);
1862 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
1868 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1869 r600_bc_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1871 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1872 fprintf(stderr
, "SRC0(SEL:%d ", alu
->src
[0].sel
);
1873 fprintf(stderr
, "REL:%d ", alu
->src
[0].rel
);
1874 fprintf(stderr
, "CHAN:%d ", alu
->src
[0].chan
);
1875 fprintf(stderr
, "NEG:%d) ", alu
->src
[0].neg
);
1876 fprintf(stderr
, "SRC1(SEL:%d ", alu
->src
[1].sel
);
1877 fprintf(stderr
, "REL:%d ", alu
->src
[1].rel
);
1878 fprintf(stderr
, "CHAN:%d ", alu
->src
[1].chan
);
1879 fprintf(stderr
, "NEG:%d) ", alu
->src
[1].neg
);
1880 fprintf(stderr
, "LAST:%d)\n", alu
->last
);
1882 fprintf(stderr
, "%04d %08X %c ", id
, bc
->bytecode
[id
], alu
->last
? '*' : ' ');
1883 fprintf(stderr
, "INST:%d ", alu
->inst
);
1884 fprintf(stderr
, "DST(SEL:%d ", alu
->dst
.sel
);
1885 fprintf(stderr
, "CHAN:%d ", alu
->dst
.chan
);
1886 fprintf(stderr
, "REL:%d ", alu
->dst
.rel
);
1887 fprintf(stderr
, "CLAMP:%d) ", alu
->dst
.clamp
);
1888 fprintf(stderr
, "BANK_SWIZZLE:%d ", alu
->bank_swizzle
);
1890 fprintf(stderr
, "SRC2(SEL:%d ", alu
->src
[2].sel
);
1891 fprintf(stderr
, "REL:%d ", alu
->src
[2].rel
);
1892 fprintf(stderr
, "CHAN:%d ", alu
->src
[2].chan
);
1893 fprintf(stderr
, "NEG:%d)\n", alu
->src
[2].neg
);
1895 fprintf(stderr
, "SRC0_ABS:%d ", alu
->src
[0].abs
);
1896 fprintf(stderr
, "SRC1_ABS:%d ", alu
->src
[1].abs
);
1897 fprintf(stderr
, "WRITE_MASK:%d ", alu
->dst
.write
);
1898 fprintf(stderr
, "OMOD:%d ", alu
->omod
);
1899 fprintf(stderr
, "EXECUTE_MASK:%d ", alu
->predicate
);
1900 fprintf(stderr
, "UPDATE_PRED:%d\n", alu
->predicate
);
1905 for (i
= 0; i
< nliteral
; i
++, id
++) {
1906 float *f
= (float*)(bc
->bytecode
+ id
);
1907 fprintf(stderr
, "%04d %08X\t%f\n", id
, bc
->bytecode
[id
], *f
);
1914 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1915 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1916 fprintf(stderr
, "INST:%d ", tex
->inst
);
1917 fprintf(stderr
, "RESOURCE_ID:%d ", tex
->resource_id
);
1918 fprintf(stderr
, "SRC(GPR:%d ", tex
->src_gpr
);
1919 fprintf(stderr
, "REL:%d)\n", tex
->src_rel
);
1921 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1922 fprintf(stderr
, "DST(GPR:%d ", tex
->dst_gpr
);
1923 fprintf(stderr
, "REL:%d ", tex
->dst_rel
);
1924 fprintf(stderr
, "SEL_X:%d ", tex
->dst_sel_x
);
1925 fprintf(stderr
, "SEL_Y:%d ", tex
->dst_sel_y
);
1926 fprintf(stderr
, "SEL_Z:%d ", tex
->dst_sel_z
);
1927 fprintf(stderr
, "SEL_W:%d) ", tex
->dst_sel_w
);
1928 fprintf(stderr
, "LOD_BIAS:%d ", tex
->lod_bias
);
1929 fprintf(stderr
, "COORD_TYPE_X:%d ", tex
->coord_type_x
);
1930 fprintf(stderr
, "COORD_TYPE_Y:%d ", tex
->coord_type_y
);
1931 fprintf(stderr
, "COORD_TYPE_Z:%d ", tex
->coord_type_z
);
1932 fprintf(stderr
, "COORD_TYPE_W:%d\n", tex
->coord_type_w
);
1934 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1935 fprintf(stderr
, "OFFSET_X:%d ", tex
->offset_x
);
1936 fprintf(stderr
, "OFFSET_Y:%d ", tex
->offset_y
);
1937 fprintf(stderr
, "OFFSET_Z:%d ", tex
->offset_z
);
1938 fprintf(stderr
, "SAMPLER_ID:%d ", tex
->sampler_id
);
1939 fprintf(stderr
, "SRC(SEL_X:%d ", tex
->src_sel_x
);
1940 fprintf(stderr
, "SEL_Y:%d ", tex
->src_sel_y
);
1941 fprintf(stderr
, "SEL_Z:%d ", tex
->src_sel_z
);
1942 fprintf(stderr
, "SEL_W:%d)\n", tex
->src_sel_w
);
1944 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
1948 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1949 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1950 fprintf(stderr
, "INST:%d ", vtx
->inst
);
1951 fprintf(stderr
, "FETCH_TYPE:%d ", vtx
->fetch_type
);
1952 fprintf(stderr
, "BUFFER_ID:%d\n", vtx
->buffer_id
);
1954 /* This assumes that no semantic fetches exist */
1955 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1956 fprintf(stderr
, "SRC(GPR:%d ", vtx
->src_gpr
);
1957 fprintf(stderr
, "SEL_X:%d) ", vtx
->src_sel_x
);
1958 if (bc
->chip_class
< CAYMAN
)
1959 fprintf(stderr
, "MEGA_FETCH_COUNT:%d ", vtx
->mega_fetch_count
);
1961 fprintf(stderr
, "SEL_Y:%d) ", 0);
1962 fprintf(stderr
, "DST(GPR:%d ", vtx
->dst_gpr
);
1963 fprintf(stderr
, "SEL_X:%d ", vtx
->dst_sel_x
);
1964 fprintf(stderr
, "SEL_Y:%d ", vtx
->dst_sel_y
);
1965 fprintf(stderr
, "SEL_Z:%d ", vtx
->dst_sel_z
);
1966 fprintf(stderr
, "SEL_W:%d) ", vtx
->dst_sel_w
);
1967 fprintf(stderr
, "USE_CONST_FIELDS:%d ", vtx
->use_const_fields
);
1968 fprintf(stderr
, "FORMAT(DATA:%d ", vtx
->data_format
);
1969 fprintf(stderr
, "NUM:%d ", vtx
->num_format_all
);
1970 fprintf(stderr
, "COMP:%d ", vtx
->format_comp_all
);
1971 fprintf(stderr
, "MODE:%d)\n", vtx
->srf_mode_all
);
1973 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
1974 fprintf(stderr
, "ENDIAN:%d ", vtx
->endian
);
1975 fprintf(stderr
, "OFFSET:%d\n", vtx
->offset
);
1978 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
1983 fprintf(stderr
, "--------------------------------------\n");
1986 static void r600_vertex_data_type(enum pipe_format pformat
, unsigned *format
,
1987 unsigned *num_format
, unsigned *format_comp
, unsigned *endian
)
1989 const struct util_format_description
*desc
;
1995 *endian
= ENDIAN_NONE
;
1997 desc
= util_format_description(pformat
);
1998 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
2002 /* Find the first non-VOID channel. */
2003 for (i
= 0; i
< 4; i
++) {
2004 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
2009 *endian
= r600_endian_swap(desc
->channel
[i
].size
);
2011 switch (desc
->channel
[i
].type
) {
2012 /* Half-floats, floats, ints */
2013 case UTIL_FORMAT_TYPE_FLOAT
:
2014 switch (desc
->channel
[i
].size
) {
2016 switch (desc
->nr_channels
) {
2018 *format
= FMT_16_FLOAT
;
2021 *format
= FMT_16_16_FLOAT
;
2025 *format
= FMT_16_16_16_16_FLOAT
;
2030 switch (desc
->nr_channels
) {
2032 *format
= FMT_32_FLOAT
;
2035 *format
= FMT_32_32_FLOAT
;
2038 *format
= FMT_32_32_32_FLOAT
;
2041 *format
= FMT_32_32_32_32_FLOAT
;
2050 case UTIL_FORMAT_TYPE_UNSIGNED
:
2052 case UTIL_FORMAT_TYPE_SIGNED
:
2053 switch (desc
->channel
[i
].size
) {
2055 switch (desc
->nr_channels
) {
2064 *format
= FMT_8_8_8_8
;
2069 switch (desc
->nr_channels
) {
2074 *format
= FMT_16_16
;
2078 *format
= FMT_16_16_16_16
;
2083 switch (desc
->nr_channels
) {
2088 *format
= FMT_32_32
;
2091 *format
= FMT_32_32_32
;
2094 *format
= FMT_32_32_32_32
;
2106 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2109 if (desc
->channel
[i
].normalized
) {
2116 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
2119 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context
*rctx
, struct r600_vertex_element
*ve
)
2121 static int dump_shaders
= -1;
2124 struct r600_bc_vtx vtx
;
2125 struct pipe_vertex_element
*elements
= ve
->elements
;
2126 const struct util_format_description
*desc
;
2127 unsigned fetch_resource_start
= rctx
->chip_class
>= EVERGREEN
? 0 : 160;
2128 unsigned format
, num_format
, format_comp
, endian
;
2132 /* Vertex element offsets need special handling. If the offset is
2133 * bigger than what we can put in the fetch instruction we need to
2134 * alter the vertex resource offset. In order to simplify code we
2135 * will bind one resource per element in such cases. It's a worst
2137 for (i
= 0; i
< ve
->count
; i
++) {
2138 ve
->vbuffer_offset
[i
] = C_SQ_VTX_WORD2_OFFSET
& elements
[i
].src_offset
;
2139 if (ve
->vbuffer_offset
[i
]) {
2140 ve
->vbuffer_need_offset
= 1;
2144 memset(&bc
, 0, sizeof(bc
));
2145 r600_bc_init(&bc
, rctx
->chip_class
);
2147 for (i
= 0; i
< ve
->count
; i
++) {
2148 if (elements
[i
].instance_divisor
> 1) {
2149 struct r600_bc_alu alu
;
2151 memset(&alu
, 0, sizeof(alu
));
2152 alu
.inst
= BC_INST(&bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2154 alu
.src
[0].chan
= 3;
2156 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2157 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2159 alu
.dst
.sel
= i
+ 1;
2164 if ((r
= r600_bc_add_alu(&bc
, &alu
))) {
2171 for (i
= 0; i
< ve
->count
; i
++) {
2172 unsigned vbuffer_index
;
2173 r600_vertex_data_type(ve
->elements
[i
].src_format
, &format
, &num_format
, &format_comp
, &endian
);
2174 desc
= util_format_description(ve
->elements
[i
].src_format
);
2177 R600_ERR("unknown format %d\n", ve
->elements
[i
].src_format
);
2181 /* see above for vbuffer_need_offset explanation */
2182 vbuffer_index
= elements
[i
].vertex_buffer_index
;
2183 memset(&vtx
, 0, sizeof(vtx
));
2184 vtx
.buffer_id
= (ve
->vbuffer_need_offset
? i
: vbuffer_index
) + fetch_resource_start
;
2185 vtx
.fetch_type
= elements
[i
].instance_divisor
? 1 : 0;
2186 vtx
.src_gpr
= elements
[i
].instance_divisor
> 1 ? i
+ 1 : 0;
2187 vtx
.src_sel_x
= elements
[i
].instance_divisor
? 3 : 0;
2188 vtx
.mega_fetch_count
= 0x1F;
2189 vtx
.dst_gpr
= i
+ 1;
2190 vtx
.dst_sel_x
= desc
->swizzle
[0];
2191 vtx
.dst_sel_y
= desc
->swizzle
[1];
2192 vtx
.dst_sel_z
= desc
->swizzle
[2];
2193 vtx
.dst_sel_w
= desc
->swizzle
[3];
2194 vtx
.data_format
= format
;
2195 vtx
.num_format_all
= num_format
;
2196 vtx
.format_comp_all
= format_comp
;
2197 vtx
.srf_mode_all
= 1;
2198 vtx
.offset
= elements
[i
].src_offset
;
2199 vtx
.endian
= endian
;
2201 if ((r
= r600_bc_add_vtx(&bc
, &vtx
))) {
2207 r600_bc_add_cfinst(&bc
, BC_INST(&bc
, V_SQ_CF_WORD1_SQ_CF_INST_RETURN
));
2209 if ((r
= r600_bc_build(&bc
))) {
2214 if (dump_shaders
== -1)
2215 dump_shaders
= debug_get_bool_option("R600_DUMP_SHADERS", FALSE
);
2218 fprintf(stderr
, "--------------------------------------------------------------\n");
2220 fprintf(stderr
, "______________________________________________________________\n");
2223 ve
->fs_size
= bc
.ndw
*4;
2225 /* use PIPE_BIND_VERTEX_BUFFER so we use the cache buffer manager */
2226 ve
->fetch_shader
= r600_bo(rctx
->radeon
, ve
->fs_size
, 256, PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_IMMUTABLE
);
2227 if (ve
->fetch_shader
== NULL
) {
2232 bytecode
= r600_bo_map(rctx
->radeon
, ve
->fetch_shader
, 0, NULL
);
2233 if (bytecode
== NULL
) {
2235 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
2239 if (R600_BIG_ENDIAN
) {
2240 for (i
= 0; i
< ve
->fs_size
/ 4; ++i
) {
2241 bytecode
[i
] = bswap_32(bc
.bytecode
[i
]);
2244 memcpy(bytecode
, bc
.bytecode
, ve
->fs_size
);
2247 r600_bo_unmap(rctx
->radeon
, ve
->fetch_shader
);
2250 if (rctx
->chip_class
>= EVERGREEN
)
2251 evergreen_fetch_shader(&rctx
->context
, ve
);
2253 r600_fetch_shader(&rctx
->context
, ve
);