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_bytecode_get_num_operands(struct r600_bytecode
*bc
, struct r600_bytecode_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_SUB_INT
:
53 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
:
54 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT
:
55 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
56 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
57 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
58 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
59 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
60 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
:
61 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
:
62 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
:
63 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
:
64 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
65 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
66 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT
:
67 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT
:
68 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT
:
69 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT
:
70 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
71 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT
:
72 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
73 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT
:
74 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
75 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT
:
76 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT
:
77 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
78 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT
:
79 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
:
80 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
81 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
82 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
83 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
84 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
:
85 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
86 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
87 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
88 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
:
89 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
:
90 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
:
91 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
:
94 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
95 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
:
96 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
:
97 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
:
98 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
99 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
100 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
101 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
102 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
103 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
104 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
:
105 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
106 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
:
107 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
108 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
109 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
:
110 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
:
111 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
:
112 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
113 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
114 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE
:
115 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT
:
118 "Need instruction operand number for 0x%x.\n", alu
->inst
);
124 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
126 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
127 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
:
128 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
:
129 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
:
130 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT
:
131 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
132 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
133 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
134 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
135 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
136 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
:
137 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
:
138 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
:
139 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
:
140 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
141 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
142 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT
:
143 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT
:
144 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT
:
145 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT
:
146 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
147 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT
:
148 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
149 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT
:
150 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
151 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT
:
152 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT
:
153 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
154 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT
:
155 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
:
156 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
157 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
158 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
159 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
160 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
:
161 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
162 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
163 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
164 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY
:
165 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW
:
166 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
:
167 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
:
168 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
:
169 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
:
172 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
173 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
:
174 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
175 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
176 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
177 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
178 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
179 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
180 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
:
181 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
182 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
:
183 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
184 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
185 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
:
186 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
:
187 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
:
188 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
:
189 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
190 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
191 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE
:
192 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT
:
193 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_LOAD_P0
:
196 "Need instruction operand number for 0x%x.\n", alu
->inst
);
204 int r700_bytecode_alu_build(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, unsigned id
);
206 static struct r600_bytecode_cf
*r600_bytecode_cf(void)
208 struct r600_bytecode_cf
*cf
= CALLOC_STRUCT(r600_bytecode_cf
);
212 LIST_INITHEAD(&cf
->list
);
213 LIST_INITHEAD(&cf
->alu
);
214 LIST_INITHEAD(&cf
->vtx
);
215 LIST_INITHEAD(&cf
->tex
);
219 static struct r600_bytecode_alu
*r600_bytecode_alu(void)
221 struct r600_bytecode_alu
*alu
= CALLOC_STRUCT(r600_bytecode_alu
);
225 LIST_INITHEAD(&alu
->list
);
229 static struct r600_bytecode_vtx
*r600_bytecode_vtx(void)
231 struct r600_bytecode_vtx
*vtx
= CALLOC_STRUCT(r600_bytecode_vtx
);
235 LIST_INITHEAD(&vtx
->list
);
239 static struct r600_bytecode_tex
*r600_bytecode_tex(void)
241 struct r600_bytecode_tex
*tex
= CALLOC_STRUCT(r600_bytecode_tex
);
245 LIST_INITHEAD(&tex
->list
);
249 void r600_bytecode_init(struct r600_bytecode
*bc
, enum chip_class chip_class
)
251 LIST_INITHEAD(&bc
->cf
);
252 bc
->chip_class
= chip_class
;
255 static int r600_bytecode_add_cf(struct r600_bytecode
*bc
)
257 struct r600_bytecode_cf
*cf
= r600_bytecode_cf();
261 LIST_ADDTAIL(&cf
->list
, &bc
->cf
);
263 cf
->id
= bc
->cf_last
->id
+ 2;
267 bc
->force_add_cf
= 0;
272 int r600_bytecode_add_output(struct r600_bytecode
*bc
, const struct r600_bytecode_output
*output
)
276 if (bc
->cf_last
&& (bc
->cf_last
->inst
== output
->inst
||
277 (bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
) &&
278 output
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
))) &&
279 output
->type
== bc
->cf_last
->output
.type
&&
280 output
->elem_size
== bc
->cf_last
->output
.elem_size
&&
281 output
->swizzle_x
== bc
->cf_last
->output
.swizzle_x
&&
282 output
->swizzle_y
== bc
->cf_last
->output
.swizzle_y
&&
283 output
->swizzle_z
== bc
->cf_last
->output
.swizzle_z
&&
284 output
->swizzle_w
== bc
->cf_last
->output
.swizzle_w
&&
285 (output
->burst_count
+ bc
->cf_last
->output
.burst_count
) <= 16) {
287 if ((output
->gpr
+ output
->burst_count
) == bc
->cf_last
->output
.gpr
&&
288 (output
->array_base
+ output
->burst_count
) == bc
->cf_last
->output
.array_base
) {
290 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
291 bc
->cf_last
->output
.inst
= output
->inst
;
292 bc
->cf_last
->output
.gpr
= output
->gpr
;
293 bc
->cf_last
->output
.array_base
= output
->array_base
;
294 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
297 } else if (output
->gpr
== (bc
->cf_last
->output
.gpr
+ bc
->cf_last
->output
.burst_count
) &&
298 output
->array_base
== (bc
->cf_last
->output
.array_base
+ bc
->cf_last
->output
.burst_count
)) {
300 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
301 bc
->cf_last
->output
.inst
= output
->inst
;
302 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
307 r
= r600_bytecode_add_cf(bc
);
310 bc
->cf_last
->inst
= output
->inst
;
311 memcpy(&bc
->cf_last
->output
, output
, sizeof(struct r600_bytecode_output
));
315 /* alu instructions that can ony exits once per group */
316 static int is_alu_once_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
318 switch (bc
->chip_class
) {
321 return !alu
->is_op3
&& (
322 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
323 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
324 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
325 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
326 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
327 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
328 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
329 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
330 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
331 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
332 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
333 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
334 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
335 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
336 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
337 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
338 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
339 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
340 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
341 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
342 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
343 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
344 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
345 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
346 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
347 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
348 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
349 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
350 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
351 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
352 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
353 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
354 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
355 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
359 return !alu
->is_op3
&& (
360 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
361 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
362 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
363 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
364 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
365 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
366 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
367 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
368 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
369 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
370 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
371 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
372 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
373 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
374 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
375 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
376 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
377 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
378 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
379 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
380 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
381 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
382 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
383 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
384 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
385 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
386 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
387 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
388 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
389 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
390 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
391 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
392 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
393 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
397 static int is_alu_reduction_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
399 switch (bc
->chip_class
) {
402 return !alu
->is_op3
&& (
403 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
404 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
405 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
406 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
410 return !alu
->is_op3
&& (
411 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
412 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
413 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
414 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
418 static int is_alu_cube_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
420 switch (bc
->chip_class
) {
423 return !alu
->is_op3
&&
424 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
428 return !alu
->is_op3
&&
429 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
433 static int is_alu_mova_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
435 switch (bc
->chip_class
) {
438 return !alu
->is_op3
&& (
439 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
||
440 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
||
441 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
445 return !alu
->is_op3
&& (
446 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
450 /* alu instructions that can only execute on the vector unit */
451 static int is_alu_vec_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
453 switch (bc
->chip_class
) {
456 return is_alu_reduction_inst(bc
, alu
) ||
457 is_alu_mova_inst(bc
, alu
);
461 return is_alu_reduction_inst(bc
, alu
) ||
462 is_alu_mova_inst(bc
, alu
) ||
463 (alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
||
464 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
||
465 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY
||
466 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW
);
470 /* alu instructions that can only execute on the trans unit */
471 static int is_alu_trans_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
473 switch (bc
->chip_class
) {
477 return alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
||
478 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
||
479 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
||
480 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
||
481 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
||
482 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
||
483 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
||
484 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
||
485 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
||
486 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
||
487 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
||
488 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
||
489 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
||
490 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
||
491 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
||
492 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
||
493 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
||
494 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
||
495 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF
||
496 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
||
497 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
||
498 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF
||
499 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
||
500 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
||
501 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE
;
503 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
||
504 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_D2
||
505 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M2
||
506 alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M4
;
511 /* Note that FLT_TO_INT_* instructions are vector-only instructions
512 * on Evergreen, despite what the documentation says. FLT_TO_INT
513 * can do both vector and scalar. */
514 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
||
515 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
||
516 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
||
517 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
||
518 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
||
519 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
||
520 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
||
521 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
||
522 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
||
523 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
||
524 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
||
525 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
||
526 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
||
527 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
||
528 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF
||
529 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
||
530 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
||
531 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF
||
532 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
||
533 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
||
534 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE
;
536 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
540 /* alu instructions that can execute on any unit */
541 static int is_alu_any_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
543 return !is_alu_vec_unit_inst(bc
, alu
) &&
544 !is_alu_trans_unit_inst(bc
, alu
);
547 static int assign_alu_units(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu_first
,
548 struct r600_bytecode_alu
*assignment
[5])
550 struct r600_bytecode_alu
*alu
;
551 unsigned i
, chan
, trans
;
552 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
554 for (i
= 0; i
< max_slots
; i
++)
555 assignment
[i
] = NULL
;
557 for (alu
= alu_first
; alu
; alu
= LIST_ENTRY(struct r600_bytecode_alu
, alu
->list
.next
, list
)) {
558 chan
= alu
->dst
.chan
;
561 else if (is_alu_trans_unit_inst(bc
, alu
))
563 else if (is_alu_vec_unit_inst(bc
, alu
))
565 else if (assignment
[chan
])
566 trans
= 1; /* Assume ALU_INST_PREFER_VECTOR. */
572 assert(0); /* ALU.Trans has already been allocated. */
577 if (assignment
[chan
]) {
578 assert(0); /* ALU.chan has already been allocated. */
581 assignment
[chan
] = alu
;
590 struct alu_bank_swizzle
{
591 int hw_gpr
[NUM_OF_CYCLES
][NUM_OF_COMPONENTS
];
592 int hw_cfile_addr
[4];
593 int hw_cfile_elem
[4];
596 static const unsigned cycle_for_bank_swizzle_vec
[][3] = {
597 [SQ_ALU_VEC_012
] = { 0, 1, 2 },
598 [SQ_ALU_VEC_021
] = { 0, 2, 1 },
599 [SQ_ALU_VEC_120
] = { 1, 2, 0 },
600 [SQ_ALU_VEC_102
] = { 1, 0, 2 },
601 [SQ_ALU_VEC_201
] = { 2, 0, 1 },
602 [SQ_ALU_VEC_210
] = { 2, 1, 0 }
605 static const unsigned cycle_for_bank_swizzle_scl
[][3] = {
606 [SQ_ALU_SCL_210
] = { 2, 1, 0 },
607 [SQ_ALU_SCL_122
] = { 1, 2, 2 },
608 [SQ_ALU_SCL_212
] = { 2, 1, 2 },
609 [SQ_ALU_SCL_221
] = { 2, 2, 1 }
612 static void init_bank_swizzle(struct alu_bank_swizzle
*bs
)
614 int i
, cycle
, component
;
616 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
617 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
618 bs
->hw_gpr
[cycle
][component
] = -1;
619 for (i
= 0; i
< 4; i
++)
620 bs
->hw_cfile_addr
[i
] = -1;
621 for (i
= 0; i
< 4; i
++)
622 bs
->hw_cfile_elem
[i
] = -1;
625 static int reserve_gpr(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
, unsigned cycle
)
627 if (bs
->hw_gpr
[cycle
][chan
] == -1)
628 bs
->hw_gpr
[cycle
][chan
] = sel
;
629 else if (bs
->hw_gpr
[cycle
][chan
] != (int)sel
) {
630 /* Another scalar operation has already used the GPR read port for the channel. */
636 static int reserve_cfile(struct r600_bytecode
*bc
, struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
)
638 int res
, num_res
= 4;
639 if (bc
->chip_class
>= R700
) {
643 for (res
= 0; res
< num_res
; ++res
) {
644 if (bs
->hw_cfile_addr
[res
] == -1) {
645 bs
->hw_cfile_addr
[res
] = sel
;
646 bs
->hw_cfile_elem
[res
] = chan
;
648 } else if (bs
->hw_cfile_addr
[res
] == sel
&&
649 bs
->hw_cfile_elem
[res
] == chan
)
650 return 0; /* Read for this scalar element already reserved, nothing to do here. */
652 /* All cfile read ports are used, cannot reference vector element. */
656 static int is_gpr(unsigned sel
)
658 return (sel
>= 0 && sel
<= 127);
661 /* CB constants start at 512, and get translated to a kcache index when ALU
662 * clauses are constructed. Note that we handle kcache constants the same way
663 * as (the now gone) cfile constants, is that really required? */
664 static int is_cfile(unsigned sel
)
666 return (sel
> 255 && sel
< 512) ||
667 (sel
> 511 && sel
< 4607) || /* Kcache before translation. */
668 (sel
> 127 && sel
< 192); /* Kcache after translation. */
671 static int is_const(int sel
)
673 return is_cfile(sel
) ||
674 (sel
>= V_SQ_ALU_SRC_0
&&
675 sel
<= V_SQ_ALU_SRC_LITERAL
);
678 static int check_vector(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
679 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
681 int r
, src
, num_src
, sel
, elem
, cycle
;
683 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
684 for (src
= 0; src
< num_src
; src
++) {
685 sel
= alu
->src
[src
].sel
;
686 elem
= alu
->src
[src
].chan
;
688 cycle
= cycle_for_bank_swizzle_vec
[bank_swizzle
][src
];
689 if (src
== 1 && sel
== alu
->src
[0].sel
&& elem
== alu
->src
[0].chan
)
690 /* Nothing to do; special-case optimization,
691 * second source uses first source’s reservation. */
694 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
698 } else if (is_cfile(sel
)) {
699 r
= reserve_cfile(bc
, bs
, sel
, elem
);
703 /* No restrictions on PV, PS, literal or special constants. */
708 static int check_scalar(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
709 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
711 int r
, src
, num_src
, const_count
, sel
, elem
, cycle
;
713 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
714 for (const_count
= 0, src
= 0; src
< num_src
; ++src
) {
715 sel
= alu
->src
[src
].sel
;
716 elem
= alu
->src
[src
].chan
;
717 if (is_const(sel
)) { /* Any constant, including literal and inline constants. */
718 if (const_count
>= 2)
719 /* More than two references to a constant in
720 * transcendental operation. */
726 r
= reserve_cfile(bc
, bs
, sel
, elem
);
731 for (src
= 0; src
< num_src
; ++src
) {
732 sel
= alu
->src
[src
].sel
;
733 elem
= alu
->src
[src
].chan
;
735 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
736 if (cycle
< const_count
)
737 /* Cycle for GPR load conflicts with
738 * constant load in transcendental operation. */
740 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
744 /* PV PS restrictions */
745 if (const_count
&& (sel
== 254 || sel
== 255)) {
746 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
747 if (cycle
< const_count
)
754 static int check_and_set_bank_swizzle(struct r600_bytecode
*bc
,
755 struct r600_bytecode_alu
*slots
[5])
757 struct alu_bank_swizzle bs
;
759 int i
, r
= 0, forced
= 1;
760 boolean scalar_only
= bc
->chip_class
== CAYMAN
? false : true;
761 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
763 for (i
= 0; i
< max_slots
; i
++) {
765 if (slots
[i
]->bank_swizzle_force
) {
766 slots
[i
]->bank_swizzle
= slots
[i
]->bank_swizzle_force
;
772 if (i
< 4 && slots
[i
])
778 /* Just check every possible combination of bank swizzle.
779 * Not very efficent, but works on the first try in most of the cases. */
780 for (i
= 0; i
< 4; i
++)
781 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
)
782 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
784 bank_swizzle
[i
] = slots
[i
]->bank_swizzle
;
786 bank_swizzle
[4] = SQ_ALU_SCL_210
;
787 while(bank_swizzle
[4] <= SQ_ALU_SCL_221
) {
789 if (max_slots
== 4) {
790 for (i
= 0; i
< max_slots
; i
++) {
791 if (bank_swizzle
[i
] == SQ_ALU_VEC_210
)
795 init_bank_swizzle(&bs
);
796 if (scalar_only
== false) {
797 for (i
= 0; i
< 4; i
++) {
799 r
= check_vector(bc
, slots
[i
], &bs
, bank_swizzle
[i
]);
807 if (!r
&& slots
[4] && max_slots
== 5) {
808 r
= check_scalar(bc
, slots
[4], &bs
, bank_swizzle
[4]);
811 for (i
= 0; i
< max_slots
; i
++) {
813 slots
[i
]->bank_swizzle
= bank_swizzle
[i
];
821 for (i
= 0; i
< max_slots
; i
++) {
822 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
) {
824 if (bank_swizzle
[i
] <= SQ_ALU_VEC_210
)
827 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
833 /* Couldn't find a working swizzle. */
837 static int replace_gpr_with_pv_ps(struct r600_bytecode
*bc
,
838 struct r600_bytecode_alu
*slots
[5], struct r600_bytecode_alu
*alu_prev
)
840 struct r600_bytecode_alu
*prev
[5];
842 int i
, j
, r
, src
, num_src
;
843 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
845 r
= assign_alu_units(bc
, alu_prev
, prev
);
849 for (i
= 0; i
< max_slots
; ++i
) {
850 if (prev
[i
] && (prev
[i
]->dst
.write
|| prev
[i
]->is_op3
) && !prev
[i
]->dst
.rel
) {
851 gpr
[i
] = prev
[i
]->dst
.sel
;
852 /* cube writes more than PV.X */
853 if (!is_alu_cube_inst(bc
, prev
[i
]) && is_alu_reduction_inst(bc
, prev
[i
]))
856 chan
[i
] = prev
[i
]->dst
.chan
;
861 for (i
= 0; i
< max_slots
; ++i
) {
862 struct r600_bytecode_alu
*alu
= slots
[i
];
866 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
867 for (src
= 0; src
< num_src
; ++src
) {
868 if (!is_gpr(alu
->src
[src
].sel
) || alu
->src
[src
].rel
)
871 if (bc
->chip_class
< CAYMAN
) {
872 if (alu
->src
[src
].sel
== gpr
[4] &&
873 alu
->src
[src
].chan
== chan
[4]) {
874 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PS
;
875 alu
->src
[src
].chan
= 0;
880 for (j
= 0; j
< 4; ++j
) {
881 if (alu
->src
[src
].sel
== gpr
[j
] &&
882 alu
->src
[src
].chan
== j
) {
883 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PV
;
884 alu
->src
[src
].chan
= chan
[j
];
894 void r600_bytecode_special_constants(u32 value
, unsigned *sel
, unsigned *neg
)
898 *sel
= V_SQ_ALU_SRC_0
;
901 *sel
= V_SQ_ALU_SRC_1_INT
;
904 *sel
= V_SQ_ALU_SRC_M_1_INT
;
906 case 0x3F800000: /* 1.0f */
907 *sel
= V_SQ_ALU_SRC_1
;
909 case 0x3F000000: /* 0.5f */
910 *sel
= V_SQ_ALU_SRC_0_5
;
912 case 0xBF800000: /* -1.0f */
913 *sel
= V_SQ_ALU_SRC_1
;
916 case 0xBF000000: /* -0.5f */
917 *sel
= V_SQ_ALU_SRC_0_5
;
921 *sel
= V_SQ_ALU_SRC_LITERAL
;
926 /* compute how many literal are needed */
927 static int r600_bytecode_alu_nliterals(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
928 uint32_t literal
[4], unsigned *nliteral
)
930 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
933 for (i
= 0; i
< num_src
; ++i
) {
934 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
935 uint32_t value
= alu
->src
[i
].value
;
937 for (j
= 0; j
< *nliteral
; ++j
) {
938 if (literal
[j
] == value
) {
946 literal
[(*nliteral
)++] = value
;
953 static void r600_bytecode_alu_adjust_literals(struct r600_bytecode
*bc
,
954 struct r600_bytecode_alu
*alu
,
955 uint32_t literal
[4], unsigned nliteral
)
957 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
960 for (i
= 0; i
< num_src
; ++i
) {
961 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
962 uint32_t value
= alu
->src
[i
].value
;
963 for (j
= 0; j
< nliteral
; ++j
) {
964 if (literal
[j
] == value
) {
965 alu
->src
[i
].chan
= j
;
973 static int merge_inst_groups(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*slots
[5],
974 struct r600_bytecode_alu
*alu_prev
)
976 struct r600_bytecode_alu
*prev
[5];
977 struct r600_bytecode_alu
*result
[5] = { NULL
};
979 uint32_t literal
[4], prev_literal
[4];
980 unsigned nliteral
= 0, prev_nliteral
= 0;
982 int i
, j
, r
, src
, num_src
;
983 int num_once_inst
= 0;
984 int have_mova
= 0, have_rel
= 0;
985 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
987 r
= assign_alu_units(bc
, alu_prev
, prev
);
991 for (i
= 0; i
< max_slots
; ++i
) {
992 struct r600_bytecode_alu
*alu
;
994 /* check number of literals */
996 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], literal
, &nliteral
))
998 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], prev_literal
, &prev_nliteral
))
1000 if (is_alu_mova_inst(bc
, prev
[i
])) {
1005 num_once_inst
+= is_alu_once_inst(bc
, prev
[i
]);
1007 if (slots
[i
] && r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
))
1010 /* Let's check used slots. */
1011 if (prev
[i
] && !slots
[i
]) {
1012 result
[i
] = prev
[i
];
1014 } else if (prev
[i
] && slots
[i
]) {
1015 if (max_slots
== 5 && result
[4] == NULL
&& prev
[4] == NULL
&& slots
[4] == NULL
) {
1016 /* Trans unit is still free try to use it. */
1017 if (is_alu_any_unit_inst(bc
, slots
[i
])) {
1018 result
[i
] = prev
[i
];
1019 result
[4] = slots
[i
];
1020 } else if (is_alu_any_unit_inst(bc
, prev
[i
])) {
1021 if (slots
[i
]->dst
.sel
== prev
[i
]->dst
.sel
&&
1022 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
1023 (prev
[i
]->dst
.write
== 1 || prev
[i
]->is_op3
))
1026 result
[i
] = slots
[i
];
1027 result
[4] = prev
[i
];
1032 } else if(!slots
[i
]) {
1035 if (max_slots
== 5 && slots
[i
] && prev
[4] &&
1036 slots
[i
]->dst
.sel
== prev
[4]->dst
.sel
&&
1037 slots
[i
]->dst
.chan
== prev
[4]->dst
.chan
&&
1038 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
1039 (prev
[4]->dst
.write
== 1 || prev
[4]->is_op3
))
1042 result
[i
] = slots
[i
];
1046 num_once_inst
+= is_alu_once_inst(bc
, alu
);
1048 /* Let's check dst gpr. */
1055 /* Let's check source gprs */
1056 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
1057 for (src
= 0; src
< num_src
; ++src
) {
1058 if (alu
->src
[src
].rel
) {
1064 /* Constants don't matter. */
1065 if (!is_gpr(alu
->src
[src
].sel
))
1068 for (j
= 0; j
< max_slots
; ++j
) {
1069 if (!prev
[j
] || !(prev
[j
]->dst
.write
|| prev
[j
]->is_op3
))
1072 /* If it's relative then we can't determin which gpr is really used. */
1073 if (prev
[j
]->dst
.chan
== alu
->src
[src
].chan
&&
1074 (prev
[j
]->dst
.sel
== alu
->src
[src
].sel
||
1075 prev
[j
]->dst
.rel
|| alu
->src
[src
].rel
))
1081 /* more than one PRED_ or KILL_ ? */
1082 if (num_once_inst
> 1)
1085 /* check if the result can still be swizzlet */
1086 r
= check_and_set_bank_swizzle(bc
, result
);
1090 /* looks like everything worked out right, apply the changes */
1092 /* undo adding previus literals */
1093 bc
->cf_last
->ndw
-= align(prev_nliteral
, 2);
1095 /* sort instructions */
1096 for (i
= 0; i
< max_slots
; ++i
) {
1097 slots
[i
] = result
[i
];
1099 LIST_DEL(&result
[i
]->list
);
1100 result
[i
]->last
= 0;
1101 LIST_ADDTAIL(&result
[i
]->list
, &bc
->cf_last
->alu
);
1105 /* determine new last instruction */
1106 LIST_ENTRY(struct r600_bytecode_alu
, bc
->cf_last
->alu
.prev
, list
)->last
= 1;
1108 /* determine new first instruction */
1109 for (i
= 0; i
< max_slots
; ++i
) {
1111 bc
->cf_last
->curr_bs_head
= result
[i
];
1116 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->prev2_bs_head
;
1117 bc
->cf_last
->prev2_bs_head
= NULL
;
1122 /* This code handles kcache lines as single blocks of 32 constants. We could
1123 * probably do slightly better by recognizing that we actually have two
1124 * consecutive lines of 16 constants, but the resulting code would also be
1125 * somewhat more complicated. */
1126 static int r600_bytecode_alloc_kcache_lines(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, int type
)
1128 struct r600_bytecode_kcache
*kcache
= bc
->cf_last
->kcache
;
1129 unsigned int required_lines
;
1130 unsigned int free_lines
= 0;
1131 unsigned int cache_line
[3];
1132 unsigned int count
= 0;
1136 /* Collect required cache lines. */
1137 for (i
= 0; i
< 3; ++i
) {
1138 boolean found
= false;
1141 if (alu
->src
[i
].sel
< 512)
1144 line
= ((alu
->src
[i
].sel
- 512) / 32) * 2;
1146 for (j
= 0; j
< count
; ++j
) {
1147 if (cache_line
[j
] == line
) {
1154 cache_line
[count
++] = line
;
1157 /* This should never actually happen. */
1158 if (count
>= 3) return -ENOMEM
;
1160 for (i
= 0; i
< 2; ++i
) {
1161 if (kcache
[i
].mode
== V_SQ_CF_KCACHE_NOP
) {
1166 /* Filter lines pulled in by previous intructions. Note that this is
1167 * only for the required_lines count, we can't remove these from the
1168 * cache_line array since we may have to start a new ALU clause. */
1169 for (i
= 0, required_lines
= count
; i
< count
; ++i
) {
1170 for (j
= 0; j
< 2; ++j
) {
1171 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1172 kcache
[j
].addr
== cache_line
[i
]) {
1179 /* Start a new ALU clause if needed. */
1180 if (required_lines
> free_lines
) {
1181 if ((r
= r600_bytecode_add_cf(bc
))) {
1184 bc
->cf_last
->inst
= type
;
1185 kcache
= bc
->cf_last
->kcache
;
1188 /* Setup the kcache lines. */
1189 for (i
= 0; i
< count
; ++i
) {
1190 boolean found
= false;
1192 for (j
= 0; j
< 2; ++j
) {
1193 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1194 kcache
[j
].addr
== cache_line
[i
]) {
1200 if (found
) continue;
1202 for (j
= 0; j
< 2; ++j
) {
1203 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_NOP
) {
1205 kcache
[j
].addr
= cache_line
[i
];
1206 kcache
[j
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
1212 /* Alter the src operands to refer to the kcache. */
1213 for (i
= 0; i
< 3; ++i
) {
1214 static const unsigned int base
[] = {128, 160, 256, 288};
1217 if (alu
->src
[i
].sel
< 512)
1220 alu
->src
[i
].sel
-= 512;
1221 line
= (alu
->src
[i
].sel
/ 32) * 2;
1223 for (j
= 0; j
< 2; ++j
) {
1224 if (kcache
[j
].mode
== V_SQ_CF_KCACHE_LOCK_2
&&
1225 kcache
[j
].addr
== line
) {
1226 alu
->src
[i
].sel
&= 0x1f;
1227 alu
->src
[i
].sel
+= base
[j
];
1236 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
1237 static int load_ar(struct r600_bytecode
*bc
)
1239 struct r600_bytecode_alu alu
;
1245 /* hack to avoid making MOVA the last instruction in the clause */
1246 if ((bc
->cf_last
->ndw
>>1) >= 110)
1247 bc
->force_add_cf
= 1;
1249 memset(&alu
, 0, sizeof(alu
));
1250 alu
.inst
= BC_INST(bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
1251 alu
.src
[0].sel
= bc
->ar_reg
;
1253 r
= r600_bytecode_add_alu(bc
, &alu
);
1257 bc
->cf_last
->r6xx_uses_waterfall
= 1;
1262 int r600_bytecode_add_alu_type(struct r600_bytecode
*bc
, const struct r600_bytecode_alu
*alu
, int type
)
1264 struct r600_bytecode_alu
*nalu
= r600_bytecode_alu();
1265 struct r600_bytecode_alu
*lalu
;
1270 memcpy(nalu
, alu
, sizeof(struct r600_bytecode_alu
));
1272 if (bc
->cf_last
!= NULL
&& bc
->cf_last
->inst
!= type
) {
1273 /* check if we could add it anyway */
1274 if (bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
) &&
1275 type
== BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
)) {
1276 LIST_FOR_EACH_ENTRY(lalu
, &bc
->cf_last
->alu
, list
) {
1277 if (lalu
->predicate
) {
1278 bc
->force_add_cf
= 1;
1283 bc
->force_add_cf
= 1;
1286 /* cf can contains only alu or only vtx or only tex */
1287 if (bc
->cf_last
== NULL
|| bc
->force_add_cf
) {
1288 r
= r600_bytecode_add_cf(bc
);
1294 bc
->cf_last
->inst
= type
;
1296 /* Check AR usage and load it if required */
1297 for (i
= 0; i
< 3; i
++)
1298 if (nalu
->src
[i
].rel
&& !bc
->ar_loaded
)
1301 if (nalu
->dst
.rel
&& !bc
->ar_loaded
)
1304 /* Setup the kcache for this ALU instruction. This will start a new
1305 * ALU clause if needed. */
1306 if ((r
= r600_bytecode_alloc_kcache_lines(bc
, nalu
, type
))) {
1311 if (!bc
->cf_last
->curr_bs_head
) {
1312 bc
->cf_last
->curr_bs_head
= nalu
;
1314 /* number of gpr == the last gpr used in any alu */
1315 for (i
= 0; i
< 3; i
++) {
1316 if (nalu
->src
[i
].sel
>= bc
->ngpr
&& nalu
->src
[i
].sel
< 128) {
1317 bc
->ngpr
= nalu
->src
[i
].sel
+ 1;
1319 if (nalu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
)
1320 r600_bytecode_special_constants(nalu
->src
[i
].value
,
1321 &nalu
->src
[i
].sel
, &nalu
->src
[i
].neg
);
1323 if (nalu
->dst
.sel
>= bc
->ngpr
) {
1324 bc
->ngpr
= nalu
->dst
.sel
+ 1;
1326 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
1327 /* each alu use 2 dwords */
1328 bc
->cf_last
->ndw
+= 2;
1331 /* process cur ALU instructions for bank swizzle */
1333 uint32_t literal
[4];
1335 struct r600_bytecode_alu
*slots
[5];
1336 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
1337 r
= assign_alu_units(bc
, bc
->cf_last
->curr_bs_head
, slots
);
1341 if (bc
->cf_last
->prev_bs_head
) {
1342 r
= merge_inst_groups(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1347 if (bc
->cf_last
->prev_bs_head
) {
1348 r
= replace_gpr_with_pv_ps(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1353 r
= check_and_set_bank_swizzle(bc
, slots
);
1357 for (i
= 0, nliteral
= 0; i
< max_slots
; i
++) {
1359 r
= r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
);
1364 bc
->cf_last
->ndw
+= align(nliteral
, 2);
1366 /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots)
1368 if ((bc
->cf_last
->ndw
>> 1) >= 120) {
1369 bc
->force_add_cf
= 1;
1372 bc
->cf_last
->prev2_bs_head
= bc
->cf_last
->prev_bs_head
;
1373 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->curr_bs_head
;
1374 bc
->cf_last
->curr_bs_head
= NULL
;
1379 int r600_bytecode_add_alu(struct r600_bytecode
*bc
, const struct r600_bytecode_alu
*alu
)
1381 return r600_bytecode_add_alu_type(bc
, alu
, BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
));
1384 static unsigned r600_bytecode_num_tex_and_vtx_instructions(const struct r600_bytecode
*bc
)
1386 switch (bc
->chip_class
) {
1396 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1401 static inline boolean
last_inst_was_not_vtx_fetch(struct r600_bytecode
*bc
)
1403 switch (bc
->chip_class
) {
1406 return bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
1407 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
;
1409 return bc
->cf_last
->inst
!= EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1411 return bc
->cf_last
->inst
!= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
;
1413 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1418 int r600_bytecode_add_vtx(struct r600_bytecode
*bc
, const struct r600_bytecode_vtx
*vtx
)
1420 struct r600_bytecode_vtx
*nvtx
= r600_bytecode_vtx();
1425 memcpy(nvtx
, vtx
, sizeof(struct r600_bytecode_vtx
));
1427 /* cf can contains only alu or only vtx or only tex */
1428 if (bc
->cf_last
== NULL
||
1429 last_inst_was_not_vtx_fetch(bc
) ||
1431 r
= r600_bytecode_add_cf(bc
);
1436 switch (bc
->chip_class
) {
1439 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1442 bc
->cf_last
->inst
= EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1445 bc
->cf_last
->inst
= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
;
1448 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1452 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
1453 /* each fetch use 4 dwords */
1454 bc
->cf_last
->ndw
+= 4;
1456 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1457 bc
->force_add_cf
= 1;
1461 int r600_bytecode_add_tex(struct r600_bytecode
*bc
, const struct r600_bytecode_tex
*tex
)
1463 struct r600_bytecode_tex
*ntex
= r600_bytecode_tex();
1468 memcpy(ntex
, tex
, sizeof(struct r600_bytecode_tex
));
1470 /* we can't fetch data und use it as texture lookup address in the same TEX clause */
1471 if (bc
->cf_last
!= NULL
&&
1472 bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
)) {
1473 struct r600_bytecode_tex
*ttex
;
1474 LIST_FOR_EACH_ENTRY(ttex
, &bc
->cf_last
->tex
, list
) {
1475 if (ttex
->dst_gpr
== ntex
->src_gpr
) {
1476 bc
->force_add_cf
= 1;
1480 /* slight hack to make gradients always go into same cf */
1481 if (ntex
->inst
== SQ_TEX_INST_SET_GRADIENTS_H
)
1482 bc
->force_add_cf
= 1;
1485 /* cf can contains only alu or only vtx or only tex */
1486 if (bc
->cf_last
== NULL
||
1487 bc
->cf_last
->inst
!= BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
) ||
1489 r
= r600_bytecode_add_cf(bc
);
1494 bc
->cf_last
->inst
= BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
);
1496 if (ntex
->src_gpr
>= bc
->ngpr
) {
1497 bc
->ngpr
= ntex
->src_gpr
+ 1;
1499 if (ntex
->dst_gpr
>= bc
->ngpr
) {
1500 bc
->ngpr
= ntex
->dst_gpr
+ 1;
1502 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
1503 /* each texture fetch use 4 dwords */
1504 bc
->cf_last
->ndw
+= 4;
1506 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1507 bc
->force_add_cf
= 1;
1511 int r600_bytecode_add_cfinst(struct r600_bytecode
*bc
, int inst
)
1514 r
= r600_bytecode_add_cf(bc
);
1518 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
1519 bc
->cf_last
->inst
= inst
;
1523 int cm_bytecode_add_cf_end(struct r600_bytecode
*bc
)
1525 return r600_bytecode_add_cfinst(bc
, CM_V_SQ_CF_WORD1_SQ_CF_INST_END
);
1528 /* common to all 3 families */
1529 static int r600_bytecode_vtx_build(struct r600_bytecode
*bc
, struct r600_bytecode_vtx
*vtx
, unsigned id
)
1531 bc
->bytecode
[id
] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
) |
1532 S_SQ_VTX_WORD0_FETCH_TYPE(vtx
->fetch_type
) |
1533 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
1534 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
);
1535 if (bc
->chip_class
< CAYMAN
)
1536 bc
->bytecode
[id
] |= S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
1538 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
1539 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
1540 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
1541 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
1542 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
1543 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
1544 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
1545 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
1546 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
1547 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
1548 bc
->bytecode
[id
] = S_SQ_VTX_WORD2_OFFSET(vtx
->offset
)|
1549 S_SQ_VTX_WORD2_ENDIAN_SWAP(vtx
->endian
);
1550 if (bc
->chip_class
< CAYMAN
)
1551 bc
->bytecode
[id
] |= S_SQ_VTX_WORD2_MEGA_FETCH(1);
1553 bc
->bytecode
[id
++] = 0;
1557 /* common to all 3 families */
1558 static int r600_bytecode_tex_build(struct r600_bytecode
*bc
, struct r600_bytecode_tex
*tex
, unsigned id
)
1560 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
1561 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
1562 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
1563 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
1564 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
1565 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
1566 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
1567 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
1568 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
1569 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
1570 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
1571 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
1572 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
1573 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
1574 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
1575 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
1576 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
1577 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
1578 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
1579 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
1580 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
1581 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
1582 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
1583 bc
->bytecode
[id
++] = 0;
1587 /* r600 only, r700/eg bits in r700_asm.c */
1588 static int r600_bytecode_alu_build(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, unsigned id
)
1590 /* don't replace gpr by pv or ps for destination register */
1591 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
1592 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
1593 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
1594 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
1595 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
1596 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
1597 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
1598 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
1599 S_SQ_ALU_WORD0_LAST(alu
->last
);
1602 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1603 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1604 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1605 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1606 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
1607 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
1608 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
1609 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
1610 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
1611 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
1613 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1614 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1615 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1616 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1617 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
1618 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
1619 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
1620 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
1621 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
1622 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
1623 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->predicate
) |
1624 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->predicate
);
1629 static void r600_bytecode_cf_vtx_build(uint32_t *bytecode
, const struct r600_bytecode_cf
*cf
)
1631 *bytecode
++ = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
1632 *bytecode
++ = cf
->inst
|
1633 S_SQ_CF_WORD1_BARRIER(1) |
1634 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
1637 /* common for r600/r700 - eg in eg_asm.c */
1638 static int r600_bytecode_cf_build(struct r600_bytecode
*bc
, struct r600_bytecode_cf
*cf
)
1640 unsigned id
= cf
->id
;
1643 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1644 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1645 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1646 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1647 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
1648 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache
[0].mode
) |
1649 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache
[0].bank
) |
1650 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache
[1].bank
);
1652 bc
->bytecode
[id
++] = cf
->inst
|
1653 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache
[1].mode
) |
1654 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache
[0].addr
) |
1655 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache
[1].addr
) |
1656 S_SQ_CF_ALU_WORD1_BARRIER(1) |
1657 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chip_class
== R600
? cf
->r6xx_uses_waterfall
: 0) |
1658 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
1660 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1661 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1662 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1663 if (bc
->chip_class
== R700
)
1664 r700_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1666 r600_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1668 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1669 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1670 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1671 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1672 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1673 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1674 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1675 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
1676 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
1677 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
1678 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
1679 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1681 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
1683 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
1684 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
1685 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
1686 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
1687 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1688 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1689 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1690 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1691 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1692 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1694 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
) |
1695 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(cf
->output
.array_size
) |
1696 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(cf
->output
.comp_mask
);
1698 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1699 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1700 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1701 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1702 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1703 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1704 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1705 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1706 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1707 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
1708 bc
->bytecode
[id
++] = cf
->inst
|
1709 S_SQ_CF_WORD1_BARRIER(1) |
1710 S_SQ_CF_WORD1_COND(cf
->cond
) |
1711 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
1715 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1721 int r600_bytecode_build(struct r600_bytecode
*bc
)
1723 struct r600_bytecode_cf
*cf
;
1724 struct r600_bytecode_alu
*alu
;
1725 struct r600_bytecode_vtx
*vtx
;
1726 struct r600_bytecode_tex
*tex
;
1727 uint32_t literal
[4];
1732 if (bc
->callstack
[0].max
> 0)
1733 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
1734 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
1738 /* first path compute addr of each CF block */
1739 /* addr start after all the CF instructions */
1740 addr
= bc
->cf_last
->id
+ 2;
1741 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1742 if (bc
->chip_class
>= EVERGREEN
) {
1744 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1745 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1746 /* fetch node need to be 16 bytes aligned*/
1748 addr
&= 0xFFFFFFFCUL
;
1750 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1751 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1752 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1753 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1754 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1755 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1756 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
1757 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
1758 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
1759 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
1760 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
1761 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
1762 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
1763 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
1764 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
1765 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
1766 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
1767 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
1768 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
1769 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
1770 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
1771 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
1772 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1773 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1774 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1775 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1776 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1777 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1778 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1779 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1780 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1781 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
1784 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1789 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1790 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1791 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1792 /* fetch node need to be 16 bytes aligned*/
1794 addr
&= 0xFFFFFFFCUL
;
1796 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1797 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1798 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1799 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1800 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1801 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1802 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
1803 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
1804 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
1805 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
1806 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1807 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1808 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1809 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1810 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1811 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1812 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1813 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1814 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1817 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1823 bc
->ndw
= cf
->addr
+ cf
->ndw
;
1826 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
1827 if (bc
->bytecode
== NULL
)
1829 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1831 if (bc
->chip_class
>= EVERGREEN
) {
1832 r
= eg_bytecode_cf_build(bc
, cf
);
1837 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1838 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1839 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1840 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1842 memset(literal
, 0, sizeof(literal
));
1843 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1844 r
= r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1847 r600_bytecode_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
1848 switch(bc
->chip_class
) {
1849 case EVERGREEN
: /* eg alu is same encoding as r700 */
1851 r
= r700_bytecode_alu_build(bc
, alu
, addr
);
1854 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
1861 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
1862 bc
->bytecode
[addr
++] = literal
[i
];
1865 memset(literal
, 0, sizeof(literal
));
1869 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1870 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1871 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
1877 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1878 if (bc
->chip_class
== CAYMAN
) {
1879 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1880 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
1886 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1887 r
= r600_bytecode_tex_build(bc
, tex
, addr
);
1893 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1894 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1895 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
1896 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
1897 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
1898 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
1899 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
1900 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
1901 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
1902 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
1903 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
1904 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
1905 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
1906 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
1907 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
1908 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
1909 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
1910 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
1911 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1912 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1913 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1914 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1915 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1916 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1917 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1918 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1919 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1920 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
1923 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1927 r
= r600_bytecode_cf_build(bc
, cf
);
1932 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1933 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1934 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1935 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1937 memset(literal
, 0, sizeof(literal
));
1938 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
1939 r
= r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
1942 r600_bytecode_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
1943 switch(bc
->chip_class
) {
1945 r
= r600_bytecode_alu_build(bc
, alu
, addr
);
1948 r
= r700_bytecode_alu_build(bc
, alu
, addr
);
1951 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
1958 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
1959 bc
->bytecode
[addr
++] = literal
[i
];
1962 memset(literal
, 0, sizeof(literal
));
1966 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1967 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1968 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
1969 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
1975 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1976 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
1977 r
= r600_bytecode_tex_build(bc
, tex
, addr
);
1983 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1984 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1985 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
1986 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
1987 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
1988 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
1989 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1990 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1991 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1992 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1993 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1994 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1995 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1996 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1997 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2000 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2008 void r600_bytecode_clear(struct r600_bytecode
*bc
)
2010 struct r600_bytecode_cf
*cf
= NULL
, *next_cf
;
2013 bc
->bytecode
= NULL
;
2015 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
2016 struct r600_bytecode_alu
*alu
= NULL
, *next_alu
;
2017 struct r600_bytecode_tex
*tex
= NULL
, *next_tex
;
2018 struct r600_bytecode_tex
*vtx
= NULL
, *next_vtx
;
2020 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
2024 LIST_INITHEAD(&cf
->alu
);
2026 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
2030 LIST_INITHEAD(&cf
->tex
);
2032 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
2036 LIST_INITHEAD(&cf
->vtx
);
2041 LIST_INITHEAD(&cf
->list
);
2044 void r600_bytecode_dump(struct r600_bytecode
*bc
)
2046 struct r600_bytecode_cf
*cf
= NULL
;
2047 struct r600_bytecode_alu
*alu
= NULL
;
2048 struct r600_bytecode_vtx
*vtx
= NULL
;
2049 struct r600_bytecode_tex
*tex
= NULL
;
2052 uint32_t literal
[4];
2056 switch (bc
->chip_class
) {
2071 fprintf(stderr
, "bytecode %d dw -- %d gprs ---------------------\n", bc
->ndw
, bc
->ngpr
);
2072 fprintf(stderr
, " %c\n", chip
);
2074 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
2077 if (bc
->chip_class
>= EVERGREEN
) {
2079 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2080 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2081 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2082 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2083 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2084 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
2085 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
2086 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
2087 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
2089 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2090 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
));
2091 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
2092 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
2093 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
2094 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
2096 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2097 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2098 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2099 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
2101 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2102 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2103 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
2105 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2106 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2107 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2108 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2109 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
2110 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
2111 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2113 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2114 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
2115 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
2116 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
2117 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
2118 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2119 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
));
2120 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2121 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2123 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
2124 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
2125 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
2126 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
2127 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
2128 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
2129 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
2130 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
2131 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
2132 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
2133 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
2134 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
2135 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
2136 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
2137 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
2138 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
2139 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i_BUF%i ", id
, bc
->bytecode
[id
],
2140 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2141 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) / 4,
2142 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2143 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) % 4);
2144 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2145 fprintf(stderr
, "ELEM_SIZE:%i ", cf
->output
.elem_size
);
2146 fprintf(stderr
, "ARRAY_BASE:%i ", cf
->output
.array_base
);
2147 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2149 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i_BUF%i ", id
, bc
->bytecode
[id
],
2150 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2151 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) / 4,
2152 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2153 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) % 4);
2154 fprintf(stderr
, "ARRAY_SIZE:%i ", cf
->output
.array_size
);
2155 fprintf(stderr
, "COMP_MASK:%X ", cf
->output
.comp_mask
);
2156 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2157 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
2158 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2159 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2161 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2162 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2163 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2164 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2165 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2166 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2167 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2168 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2169 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2170 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
2171 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2172 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
2174 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2175 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2176 fprintf(stderr
, "COND:%X ", cf
->cond
);
2177 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
2180 R600_ERR("Unknown instruction %0x\n", cf
->inst
);
2184 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2185 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2186 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2187 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2188 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2189 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
2190 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
2191 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
2192 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
2194 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2195 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
));
2196 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
2197 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
2198 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
2199 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
2201 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2202 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2203 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
2204 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2205 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
2207 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2208 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2209 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
2211 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2212 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2213 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2214 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2215 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
2216 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
2217 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2219 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2220 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
2221 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
2222 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
2223 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
2224 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2225 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
));
2226 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2227 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2229 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
2230 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
2231 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
2232 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
2233 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i ", id
, bc
->bytecode
[id
],
2234 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2235 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
));
2236 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2237 fprintf(stderr
, "ELEM_SIZE:%i ", cf
->output
.elem_size
);
2238 fprintf(stderr
, "ARRAY_BASE:%i ", cf
->output
.array_base
);
2239 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2241 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i ", id
, bc
->bytecode
[id
],
2242 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2243 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
));
2244 fprintf(stderr
, "ARRAY_SIZE:%i ", cf
->output
.array_size
);
2245 fprintf(stderr
, "COMP_MASK:%X ", cf
->output
.comp_mask
);
2246 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2247 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
2248 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2249 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2251 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2252 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2253 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2254 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2255 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2256 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2257 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2258 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2259 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2260 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2261 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
2263 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2264 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2265 fprintf(stderr
, "COND:%X ", cf
->cond
);
2266 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
2269 R600_ERR("Unknown instruction %0x\n", cf
->inst
);
2275 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
2276 r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
2278 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2279 fprintf(stderr
, "SRC0(SEL:%d ", alu
->src
[0].sel
);
2280 fprintf(stderr
, "REL:%d ", alu
->src
[0].rel
);
2281 fprintf(stderr
, "CHAN:%d ", alu
->src
[0].chan
);
2282 fprintf(stderr
, "NEG:%d) ", alu
->src
[0].neg
);
2283 fprintf(stderr
, "SRC1(SEL:%d ", alu
->src
[1].sel
);
2284 fprintf(stderr
, "REL:%d ", alu
->src
[1].rel
);
2285 fprintf(stderr
, "CHAN:%d ", alu
->src
[1].chan
);
2286 fprintf(stderr
, "NEG:%d) ", alu
->src
[1].neg
);
2287 fprintf(stderr
, "LAST:%d)\n", alu
->last
);
2289 fprintf(stderr
, "%04d %08X %c ", id
, bc
->bytecode
[id
], alu
->last
? '*' : ' ');
2290 fprintf(stderr
, "INST:0x%x ", alu
->inst
);
2291 fprintf(stderr
, "DST(SEL:%d ", alu
->dst
.sel
);
2292 fprintf(stderr
, "CHAN:%d ", alu
->dst
.chan
);
2293 fprintf(stderr
, "REL:%d ", alu
->dst
.rel
);
2294 fprintf(stderr
, "CLAMP:%d) ", alu
->dst
.clamp
);
2295 fprintf(stderr
, "BANK_SWIZZLE:%d ", alu
->bank_swizzle
);
2297 fprintf(stderr
, "SRC2(SEL:%d ", alu
->src
[2].sel
);
2298 fprintf(stderr
, "REL:%d ", alu
->src
[2].rel
);
2299 fprintf(stderr
, "CHAN:%d ", alu
->src
[2].chan
);
2300 fprintf(stderr
, "NEG:%d)\n", alu
->src
[2].neg
);
2302 fprintf(stderr
, "SRC0_ABS:%d ", alu
->src
[0].abs
);
2303 fprintf(stderr
, "SRC1_ABS:%d ", alu
->src
[1].abs
);
2304 fprintf(stderr
, "WRITE_MASK:%d ", alu
->dst
.write
);
2305 fprintf(stderr
, "OMOD:%d ", alu
->omod
);
2306 fprintf(stderr
, "EXECUTE_MASK:%d ", alu
->predicate
);
2307 fprintf(stderr
, "UPDATE_PRED:%d\n", alu
->predicate
);
2312 for (i
= 0; i
< nliteral
; i
++, id
++) {
2313 float *f
= (float*)(bc
->bytecode
+ id
);
2314 fprintf(stderr
, "%04d %08X\t%f\n", id
, bc
->bytecode
[id
], *f
);
2321 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
2322 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2323 fprintf(stderr
, "INST:0x%x ", tex
->inst
);
2324 fprintf(stderr
, "RESOURCE_ID:%d ", tex
->resource_id
);
2325 fprintf(stderr
, "SRC(GPR:%d ", tex
->src_gpr
);
2326 fprintf(stderr
, "REL:%d)\n", tex
->src_rel
);
2328 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2329 fprintf(stderr
, "DST(GPR:%d ", tex
->dst_gpr
);
2330 fprintf(stderr
, "REL:%d ", tex
->dst_rel
);
2331 fprintf(stderr
, "SEL_X:%d ", tex
->dst_sel_x
);
2332 fprintf(stderr
, "SEL_Y:%d ", tex
->dst_sel_y
);
2333 fprintf(stderr
, "SEL_Z:%d ", tex
->dst_sel_z
);
2334 fprintf(stderr
, "SEL_W:%d) ", tex
->dst_sel_w
);
2335 fprintf(stderr
, "LOD_BIAS:%d ", tex
->lod_bias
);
2336 fprintf(stderr
, "COORD_TYPE_X:%d ", tex
->coord_type_x
);
2337 fprintf(stderr
, "COORD_TYPE_Y:%d ", tex
->coord_type_y
);
2338 fprintf(stderr
, "COORD_TYPE_Z:%d ", tex
->coord_type_z
);
2339 fprintf(stderr
, "COORD_TYPE_W:%d\n", tex
->coord_type_w
);
2341 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2342 fprintf(stderr
, "OFFSET_X:%d ", tex
->offset_x
);
2343 fprintf(stderr
, "OFFSET_Y:%d ", tex
->offset_y
);
2344 fprintf(stderr
, "OFFSET_Z:%d ", tex
->offset_z
);
2345 fprintf(stderr
, "SAMPLER_ID:%d ", tex
->sampler_id
);
2346 fprintf(stderr
, "SRC(SEL_X:%d ", tex
->src_sel_x
);
2347 fprintf(stderr
, "SEL_Y:%d ", tex
->src_sel_y
);
2348 fprintf(stderr
, "SEL_Z:%d ", tex
->src_sel_z
);
2349 fprintf(stderr
, "SEL_W:%d)\n", tex
->src_sel_w
);
2351 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
2355 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2356 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2357 fprintf(stderr
, "INST:%d ", vtx
->inst
);
2358 fprintf(stderr
, "FETCH_TYPE:%d ", vtx
->fetch_type
);
2359 fprintf(stderr
, "BUFFER_ID:%d\n", vtx
->buffer_id
);
2361 /* This assumes that no semantic fetches exist */
2362 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2363 fprintf(stderr
, "SRC(GPR:%d ", vtx
->src_gpr
);
2364 fprintf(stderr
, "SEL_X:%d) ", vtx
->src_sel_x
);
2365 if (bc
->chip_class
< CAYMAN
)
2366 fprintf(stderr
, "MEGA_FETCH_COUNT:%d ", vtx
->mega_fetch_count
);
2368 fprintf(stderr
, "SEL_Y:%d) ", 0);
2369 fprintf(stderr
, "DST(GPR:%d ", vtx
->dst_gpr
);
2370 fprintf(stderr
, "SEL_X:%d ", vtx
->dst_sel_x
);
2371 fprintf(stderr
, "SEL_Y:%d ", vtx
->dst_sel_y
);
2372 fprintf(stderr
, "SEL_Z:%d ", vtx
->dst_sel_z
);
2373 fprintf(stderr
, "SEL_W:%d) ", vtx
->dst_sel_w
);
2374 fprintf(stderr
, "USE_CONST_FIELDS:%d ", vtx
->use_const_fields
);
2375 fprintf(stderr
, "FORMAT(DATA:%d ", vtx
->data_format
);
2376 fprintf(stderr
, "NUM:%d ", vtx
->num_format_all
);
2377 fprintf(stderr
, "COMP:%d ", vtx
->format_comp_all
);
2378 fprintf(stderr
, "MODE:%d)\n", vtx
->srf_mode_all
);
2380 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2381 fprintf(stderr
, "ENDIAN:%d ", vtx
->endian
);
2382 fprintf(stderr
, "OFFSET:%d\n", vtx
->offset
);
2385 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
2390 fprintf(stderr
, "--------------------------------------\n");
2393 static void r600_vertex_data_type(enum pipe_format pformat
,
2395 unsigned *num_format
, unsigned *format_comp
, unsigned *endian
)
2397 const struct util_format_description
*desc
;
2403 *endian
= ENDIAN_NONE
;
2405 desc
= util_format_description(pformat
);
2406 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
2410 /* Find the first non-VOID channel. */
2411 for (i
= 0; i
< 4; i
++) {
2412 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
2417 *endian
= r600_endian_swap(desc
->channel
[i
].size
);
2419 switch (desc
->channel
[i
].type
) {
2420 /* Half-floats, floats, ints */
2421 case UTIL_FORMAT_TYPE_FLOAT
:
2422 switch (desc
->channel
[i
].size
) {
2424 switch (desc
->nr_channels
) {
2426 *format
= FMT_16_FLOAT
;
2429 *format
= FMT_16_16_FLOAT
;
2433 *format
= FMT_16_16_16_16_FLOAT
;
2438 switch (desc
->nr_channels
) {
2440 *format
= FMT_32_FLOAT
;
2443 *format
= FMT_32_32_FLOAT
;
2446 *format
= FMT_32_32_32_FLOAT
;
2449 *format
= FMT_32_32_32_32_FLOAT
;
2458 case UTIL_FORMAT_TYPE_UNSIGNED
:
2460 case UTIL_FORMAT_TYPE_SIGNED
:
2461 switch (desc
->channel
[i
].size
) {
2463 switch (desc
->nr_channels
) {
2472 *format
= FMT_8_8_8_8
;
2477 if (desc
->nr_channels
!= 4)
2480 *format
= FMT_2_10_10_10
;
2483 switch (desc
->nr_channels
) {
2488 *format
= FMT_16_16
;
2492 *format
= FMT_16_16_16_16
;
2497 switch (desc
->nr_channels
) {
2502 *format
= FMT_32_32
;
2505 *format
= FMT_32_32_32
;
2508 *format
= FMT_32_32_32_32
;
2520 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2525 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
||
2526 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2527 if (!desc
->channel
[i
].normalized
) {
2528 if (desc
->channel
[i
].pure_integer
)
2536 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
2539 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context
*rctx
, struct r600_vertex_element
*ve
)
2541 static int dump_shaders
= -1;
2543 struct r600_bytecode bc
;
2544 struct r600_bytecode_vtx vtx
;
2545 struct pipe_vertex_element
*elements
= ve
->elements
;
2546 const struct util_format_description
*desc
;
2547 unsigned fetch_resource_start
= rctx
->chip_class
>= EVERGREEN
? 0 : 160;
2548 unsigned format
, num_format
, format_comp
, endian
;
2552 /* Vertex element offsets need special handling. If the offset is
2553 * bigger than what we can put in the fetch instruction we need to
2554 * alter the vertex resource offset. In order to simplify code we
2555 * will bind one resource per element in such cases. It's a worst
2557 for (i
= 0; i
< ve
->count
; i
++) {
2558 ve
->vbuffer_offset
[i
] = C_SQ_VTX_WORD2_OFFSET
& elements
[i
].src_offset
;
2559 if (ve
->vbuffer_offset
[i
]) {
2560 ve
->vbuffer_need_offset
= 1;
2564 memset(&bc
, 0, sizeof(bc
));
2565 r600_bytecode_init(&bc
, rctx
->chip_class
);
2567 for (i
= 0; i
< ve
->count
; i
++) {
2568 if (elements
[i
].instance_divisor
> 1) {
2569 struct r600_bytecode_alu alu
;
2571 memset(&alu
, 0, sizeof(alu
));
2572 alu
.inst
= BC_INST(&bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2574 alu
.src
[0].chan
= 3;
2576 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2577 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2579 alu
.dst
.sel
= i
+ 1;
2584 if ((r
= r600_bytecode_add_alu(&bc
, &alu
))) {
2585 r600_bytecode_clear(&bc
);
2591 for (i
= 0; i
< ve
->count
; i
++) {
2592 unsigned vbuffer_index
;
2593 r600_vertex_data_type(ve
->elements
[i
].src_format
,
2594 &format
, &num_format
, &format_comp
, &endian
);
2595 desc
= util_format_description(ve
->elements
[i
].src_format
);
2597 r600_bytecode_clear(&bc
);
2598 R600_ERR("unknown format %d\n", ve
->elements
[i
].src_format
);
2602 /* see above for vbuffer_need_offset explanation */
2603 vbuffer_index
= elements
[i
].vertex_buffer_index
;
2604 memset(&vtx
, 0, sizeof(vtx
));
2605 vtx
.buffer_id
= (ve
->vbuffer_need_offset
? i
: vbuffer_index
) + fetch_resource_start
;
2606 vtx
.fetch_type
= elements
[i
].instance_divisor
? 1 : 0;
2607 vtx
.src_gpr
= elements
[i
].instance_divisor
> 1 ? i
+ 1 : 0;
2608 vtx
.src_sel_x
= elements
[i
].instance_divisor
? 3 : 0;
2609 vtx
.mega_fetch_count
= 0x1F;
2610 vtx
.dst_gpr
= i
+ 1;
2611 vtx
.dst_sel_x
= desc
->swizzle
[0];
2612 vtx
.dst_sel_y
= desc
->swizzle
[1];
2613 vtx
.dst_sel_z
= desc
->swizzle
[2];
2614 vtx
.dst_sel_w
= desc
->swizzle
[3];
2615 vtx
.data_format
= format
;
2616 vtx
.num_format_all
= num_format
;
2617 vtx
.format_comp_all
= format_comp
;
2618 vtx
.srf_mode_all
= 1;
2619 vtx
.offset
= elements
[i
].src_offset
;
2620 vtx
.endian
= endian
;
2622 if ((r
= r600_bytecode_add_vtx(&bc
, &vtx
))) {
2623 r600_bytecode_clear(&bc
);
2628 r600_bytecode_add_cfinst(&bc
, BC_INST(&bc
, V_SQ_CF_WORD1_SQ_CF_INST_RETURN
));
2630 if ((r
= r600_bytecode_build(&bc
))) {
2631 r600_bytecode_clear(&bc
);
2635 if (dump_shaders
== -1)
2636 dump_shaders
= debug_get_bool_option("R600_DUMP_SHADERS", FALSE
);
2639 fprintf(stderr
, "--------------------------------------------------------------\n");
2640 r600_bytecode_dump(&bc
);
2641 fprintf(stderr
, "______________________________________________________________\n");
2644 ve
->fs_size
= bc
.ndw
*4;
2646 ve
->fetch_shader
= (struct r600_resource
*)
2647 pipe_buffer_create(rctx
->context
.screen
,
2649 PIPE_USAGE_IMMUTABLE
, ve
->fs_size
);
2650 if (ve
->fetch_shader
== NULL
) {
2651 r600_bytecode_clear(&bc
);
2655 bytecode
= rctx
->ws
->buffer_map(ve
->fetch_shader
->buf
, rctx
->ctx
.cs
, PIPE_TRANSFER_WRITE
);
2656 if (bytecode
== NULL
) {
2657 r600_bytecode_clear(&bc
);
2658 pipe_resource_reference((struct pipe_resource
**)&ve
->fetch_shader
, NULL
);
2662 if (R600_BIG_ENDIAN
) {
2663 for (i
= 0; i
< ve
->fs_size
/ 4; ++i
) {
2664 bytecode
[i
] = bswap_32(bc
.bytecode
[i
]);
2667 memcpy(bytecode
, bc
.bytecode
, ve
->fs_size
);
2670 rctx
->ws
->buffer_unmap(ve
->fetch_shader
->buf
);
2671 r600_bytecode_clear(&bc
);
2673 if (rctx
->chip_class
>= EVERGREEN
)
2674 evergreen_fetch_shader(&rctx
->context
, ve
);
2676 r600_fetch_shader(&rctx
->context
, ve
);