2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_opcodes.h"
25 #include "r600_formats.h"
26 #include "r600_shader.h"
31 #include "util/u_memory.h"
32 #include "pipe/p_shader_tokens.h"
34 #define NUM_OF_CYCLES 3
35 #define NUM_OF_COMPONENTS 4
37 static inline unsigned int r600_bytecode_get_num_operands(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
42 switch (bc
->chip_class
) {
47 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
49 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
50 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
:
51 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
:
52 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
:
53 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT
:
54 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
55 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
56 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
57 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
58 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
59 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_IEEE
:
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_PRED_SETE_INT
:
86 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
87 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
88 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
89 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
:
90 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
:
91 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
:
92 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
:
95 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
96 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
:
97 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
:
98 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
:
99 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
:
100 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
101 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL
:
102 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
103 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
104 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
105 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
106 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
107 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
:
108 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
109 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
:
110 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
:
111 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
:
112 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
113 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
114 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
:
115 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
:
116 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
:
117 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
118 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
119 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE
:
120 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT
:
123 "Need instruction operand number for 0x%x.\n", alu
->inst
);
129 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
131 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
132 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
:
133 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
:
134 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
:
135 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT
:
136 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
137 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
138 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
139 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
140 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
141 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_IEEE
:
142 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT
:
143 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
:
144 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
:
145 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
:
146 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
147 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
148 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT
:
149 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT
:
150 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT
:
151 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT
:
152 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
153 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT
:
154 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
155 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT
:
156 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
157 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT
:
158 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT
:
159 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
160 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT
:
161 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
:
162 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
163 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
:
164 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
165 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
166 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
167 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
:
168 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
169 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
170 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
171 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_XY
:
172 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_ZW
:
173 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
:
174 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
:
175 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
:
176 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
:
179 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
180 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
:
181 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
182 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL
:
183 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
184 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
185 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
186 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
187 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
188 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
:
189 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
190 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
:
191 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
192 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
193 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
:
194 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
:
195 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
:
196 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
:
197 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
198 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
199 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE
:
200 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT
:
201 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_LOAD_P0
:
202 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT
:
203 case EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
:
206 R600_ERR("Need instruction operand number for 0x%x.\n", alu
->inst
);
214 int r700_bytecode_alu_build(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, unsigned id
);
216 static struct r600_bytecode_cf
*r600_bytecode_cf(void)
218 struct r600_bytecode_cf
*cf
= CALLOC_STRUCT(r600_bytecode_cf
);
222 LIST_INITHEAD(&cf
->list
);
223 LIST_INITHEAD(&cf
->alu
);
224 LIST_INITHEAD(&cf
->vtx
);
225 LIST_INITHEAD(&cf
->tex
);
229 static struct r600_bytecode_alu
*r600_bytecode_alu(void)
231 struct r600_bytecode_alu
*alu
= CALLOC_STRUCT(r600_bytecode_alu
);
235 LIST_INITHEAD(&alu
->list
);
239 static struct r600_bytecode_vtx
*r600_bytecode_vtx(void)
241 struct r600_bytecode_vtx
*vtx
= CALLOC_STRUCT(r600_bytecode_vtx
);
245 LIST_INITHEAD(&vtx
->list
);
249 static struct r600_bytecode_tex
*r600_bytecode_tex(void)
251 struct r600_bytecode_tex
*tex
= CALLOC_STRUCT(r600_bytecode_tex
);
255 LIST_INITHEAD(&tex
->list
);
259 void r600_bytecode_init(struct r600_bytecode
*bc
,
260 enum chip_class chip_class
,
261 enum radeon_family family
,
262 enum r600_msaa_texture_mode msaa_texture_mode
)
264 if ((chip_class
== R600
) &&
265 (family
!= CHIP_RV670
&& family
!= CHIP_RS780
&& family
!= CHIP_RS880
)) {
266 bc
->ar_handling
= AR_HANDLE_RV6XX
;
267 bc
->r6xx_nop_after_rel_dst
= 1;
269 bc
->ar_handling
= AR_HANDLE_NORMAL
;
270 bc
->r6xx_nop_after_rel_dst
= 0;
273 LIST_INITHEAD(&bc
->cf
);
274 bc
->chip_class
= chip_class
;
275 bc
->msaa_texture_mode
= msaa_texture_mode
;
278 static int r600_bytecode_add_cf(struct r600_bytecode
*bc
)
280 struct r600_bytecode_cf
*cf
= r600_bytecode_cf();
284 LIST_ADDTAIL(&cf
->list
, &bc
->cf
);
286 cf
->id
= bc
->cf_last
->id
+ 2;
287 if (bc
->cf_last
->eg_alu_extended
) {
288 /* take into account extended alu size */
296 bc
->force_add_cf
= 0;
301 int r600_bytecode_add_output(struct r600_bytecode
*bc
, const struct r600_bytecode_output
*output
)
305 if (output
->gpr
>= bc
->ngpr
)
306 bc
->ngpr
= output
->gpr
+ 1;
308 if (bc
->cf_last
&& (bc
->cf_last
->inst
== output
->inst
||
309 (bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
) &&
310 output
->inst
== BC_INST(bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
))) &&
311 output
->type
== bc
->cf_last
->output
.type
&&
312 output
->elem_size
== bc
->cf_last
->output
.elem_size
&&
313 output
->swizzle_x
== bc
->cf_last
->output
.swizzle_x
&&
314 output
->swizzle_y
== bc
->cf_last
->output
.swizzle_y
&&
315 output
->swizzle_z
== bc
->cf_last
->output
.swizzle_z
&&
316 output
->swizzle_w
== bc
->cf_last
->output
.swizzle_w
&&
317 (output
->burst_count
+ bc
->cf_last
->output
.burst_count
) <= 16) {
319 if ((output
->gpr
+ output
->burst_count
) == bc
->cf_last
->output
.gpr
&&
320 (output
->array_base
+ output
->burst_count
) == bc
->cf_last
->output
.array_base
) {
322 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
323 bc
->cf_last
->output
.inst
= output
->inst
;
324 bc
->cf_last
->output
.gpr
= output
->gpr
;
325 bc
->cf_last
->output
.array_base
= output
->array_base
;
326 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
329 } else if (output
->gpr
== (bc
->cf_last
->output
.gpr
+ bc
->cf_last
->output
.burst_count
) &&
330 output
->array_base
== (bc
->cf_last
->output
.array_base
+ bc
->cf_last
->output
.burst_count
)) {
332 bc
->cf_last
->output
.end_of_program
|= output
->end_of_program
;
333 bc
->cf_last
->output
.inst
= output
->inst
;
334 bc
->cf_last
->output
.burst_count
+= output
->burst_count
;
339 r
= r600_bytecode_add_cf(bc
);
342 bc
->cf_last
->inst
= output
->inst
;
343 memcpy(&bc
->cf_last
->output
, output
, sizeof(struct r600_bytecode_output
));
347 /* alu instructions that can ony exits once per group */
348 static int is_alu_once_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
350 switch (bc
->chip_class
) {
353 return !alu
->is_op3
&& (
354 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
355 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
356 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
357 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
358 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
359 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
360 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
361 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
362 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
363 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
364 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
365 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
366 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
367 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
368 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
369 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
370 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
371 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
372 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
373 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
374 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
375 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
376 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
377 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
378 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
379 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
380 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
381 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
382 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
383 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
384 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
385 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
386 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
387 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
391 return !alu
->is_op3
&& (
392 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
||
393 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
||
394 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
||
395 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
||
396 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT
||
397 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT
||
398 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT
||
399 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT
||
400 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT
||
401 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT
||
402 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT
||
403 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT
||
404 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
||
405 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
||
406 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
||
407 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
||
408 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV
||
409 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP
||
410 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR
||
411 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE
||
412 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH
||
413 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH
||
414 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH
||
415 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH
||
416 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
||
417 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT
||
418 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT
||
419 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
||
420 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT
||
421 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT
||
422 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT
||
423 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT
||
424 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT
||
425 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT
);
429 static int is_alu_reduction_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
431 switch (bc
->chip_class
) {
434 return !alu
->is_op3
&& (
435 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
436 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
437 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
438 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
442 return !alu
->is_op3
&& (
443 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
||
444 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
||
445 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
||
446 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
);
450 static int is_alu_cube_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
452 switch (bc
->chip_class
) {
455 return !alu
->is_op3
&&
456 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
460 return !alu
->is_op3
&&
461 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
;
465 static int is_alu_mova_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
467 switch (bc
->chip_class
) {
470 return !alu
->is_op3
&& (
471 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
||
472 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
||
473 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
||
474 alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
);
478 return !alu
->is_op3
&& (
479 alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
483 static int is_opcode_in_range(unsigned opcode
, unsigned min
, unsigned max
)
485 return min
<= opcode
&& opcode
<= max
;
488 /* ALU instructions that can only execute on the vector unit:
492 * op3 : [0x08 - 0x0B]
493 * op2 : 0x07, [0x15 - 0x18], [0x1B - 0x1D], [0x50 - 0x53], [0x7A - 0x7E]
499 static int is_alu_vec_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
501 switch (bc
->chip_class
) {
505 return is_opcode_in_range(alu
->inst
,
506 V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_64
,
507 V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_64_D2
);
509 return (alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FREXP_64
) ||
510 is_opcode_in_range(alu
->inst
,
511 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
,
512 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
) ||
513 is_opcode_in_range(alu
->inst
,
514 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_64
,
515 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT32_TO_FLT64
) ||
516 is_opcode_in_range(alu
->inst
,
517 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
,
518 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
) ||
519 is_opcode_in_range(alu
->inst
,
520 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LDEXP_64
,
521 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_64
);
525 return is_opcode_in_range(alu
->inst
,
526 EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_BFE_UINT
,
527 EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_LDS_IDX_OP
);
529 return is_opcode_in_range(alu
->inst
,
530 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_BFM_INT
,
531 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_LOAD_P20
);
539 /* ALU instructions that can only execute on the trans unit:
548 * op2: [0x60 - 0x6F], [0x73 - 0x79]
554 static int is_alu_trans_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
557 switch (bc
->chip_class
) {
560 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
562 return is_opcode_in_range(alu
->inst
,
563 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
,
564 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
);
567 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
569 return is_opcode_in_range(alu
->inst
,
570 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
,
571 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
) ||
572 is_opcode_in_range(alu
->inst
,
573 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
,
574 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
);
577 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
579 return is_opcode_in_range(alu
->inst
,
580 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
,
581 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
);
589 /* alu instructions that can execute on any unit */
590 static int is_alu_any_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
592 return !is_alu_vec_unit_inst(bc
, alu
) &&
593 !is_alu_trans_unit_inst(bc
, alu
);
596 static int is_nop_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
598 switch (bc
->chip_class
) {
601 return (!alu
->is_op3
&& alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
);
605 return (!alu
->is_op3
&& alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
);
609 static int assign_alu_units(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu_first
,
610 struct r600_bytecode_alu
*assignment
[5])
612 struct r600_bytecode_alu
*alu
;
613 unsigned i
, chan
, trans
;
614 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
616 for (i
= 0; i
< max_slots
; i
++)
617 assignment
[i
] = NULL
;
619 for (alu
= alu_first
; alu
; alu
= LIST_ENTRY(struct r600_bytecode_alu
, alu
->list
.next
, list
)) {
620 chan
= alu
->dst
.chan
;
623 else if (is_alu_trans_unit_inst(bc
, alu
))
625 else if (is_alu_vec_unit_inst(bc
, alu
))
627 else if (assignment
[chan
])
628 trans
= 1; /* Assume ALU_INST_PREFER_VECTOR. */
634 assert(0); /* ALU.Trans has already been allocated. */
639 if (assignment
[chan
]) {
640 assert(0); /* ALU.chan has already been allocated. */
643 assignment
[chan
] = alu
;
652 struct alu_bank_swizzle
{
653 int hw_gpr
[NUM_OF_CYCLES
][NUM_OF_COMPONENTS
];
654 int hw_cfile_addr
[4];
655 int hw_cfile_elem
[4];
658 static const unsigned cycle_for_bank_swizzle_vec
[][3] = {
659 [SQ_ALU_VEC_012
] = { 0, 1, 2 },
660 [SQ_ALU_VEC_021
] = { 0, 2, 1 },
661 [SQ_ALU_VEC_120
] = { 1, 2, 0 },
662 [SQ_ALU_VEC_102
] = { 1, 0, 2 },
663 [SQ_ALU_VEC_201
] = { 2, 0, 1 },
664 [SQ_ALU_VEC_210
] = { 2, 1, 0 }
667 static const unsigned cycle_for_bank_swizzle_scl
[][3] = {
668 [SQ_ALU_SCL_210
] = { 2, 1, 0 },
669 [SQ_ALU_SCL_122
] = { 1, 2, 2 },
670 [SQ_ALU_SCL_212
] = { 2, 1, 2 },
671 [SQ_ALU_SCL_221
] = { 2, 2, 1 }
674 static void init_bank_swizzle(struct alu_bank_swizzle
*bs
)
676 int i
, cycle
, component
;
678 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
679 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
680 bs
->hw_gpr
[cycle
][component
] = -1;
681 for (i
= 0; i
< 4; i
++)
682 bs
->hw_cfile_addr
[i
] = -1;
683 for (i
= 0; i
< 4; i
++)
684 bs
->hw_cfile_elem
[i
] = -1;
687 static int reserve_gpr(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
, unsigned cycle
)
689 if (bs
->hw_gpr
[cycle
][chan
] == -1)
690 bs
->hw_gpr
[cycle
][chan
] = sel
;
691 else if (bs
->hw_gpr
[cycle
][chan
] != (int)sel
) {
692 /* Another scalar operation has already used the GPR read port for the channel. */
698 static int reserve_cfile(struct r600_bytecode
*bc
, struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
)
700 int res
, num_res
= 4;
701 if (bc
->chip_class
>= R700
) {
705 for (res
= 0; res
< num_res
; ++res
) {
706 if (bs
->hw_cfile_addr
[res
] == -1) {
707 bs
->hw_cfile_addr
[res
] = sel
;
708 bs
->hw_cfile_elem
[res
] = chan
;
710 } else if (bs
->hw_cfile_addr
[res
] == sel
&&
711 bs
->hw_cfile_elem
[res
] == chan
)
712 return 0; /* Read for this scalar element already reserved, nothing to do here. */
714 /* All cfile read ports are used, cannot reference vector element. */
718 static int is_gpr(unsigned sel
)
720 return (sel
>= 0 && sel
<= 127);
723 /* CB constants start at 512, and get translated to a kcache index when ALU
724 * clauses are constructed. Note that we handle kcache constants the same way
725 * as (the now gone) cfile constants, is that really required? */
726 static int is_cfile(unsigned sel
)
728 return (sel
> 255 && sel
< 512) ||
729 (sel
> 511 && sel
< 4607) || /* Kcache before translation. */
730 (sel
> 127 && sel
< 192); /* Kcache after translation. */
733 static int is_const(int sel
)
735 return is_cfile(sel
) ||
736 (sel
>= V_SQ_ALU_SRC_0
&&
737 sel
<= V_SQ_ALU_SRC_LITERAL
);
740 static int check_vector(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
741 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
743 int r
, src
, num_src
, sel
, elem
, cycle
;
745 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
746 for (src
= 0; src
< num_src
; src
++) {
747 sel
= alu
->src
[src
].sel
;
748 elem
= alu
->src
[src
].chan
;
750 cycle
= cycle_for_bank_swizzle_vec
[bank_swizzle
][src
];
751 if (src
== 1 && sel
== alu
->src
[0].sel
&& elem
== alu
->src
[0].chan
)
752 /* Nothing to do; special-case optimization,
753 * second source uses first source’s reservation. */
756 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
760 } else if (is_cfile(sel
)) {
761 r
= reserve_cfile(bc
, bs
, (alu
->src
[src
].kc_bank
<<16) + sel
, elem
);
765 /* No restrictions on PV, PS, literal or special constants. */
770 static int check_scalar(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
771 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
773 int r
, src
, num_src
, const_count
, sel
, elem
, cycle
;
775 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
776 for (const_count
= 0, src
= 0; src
< num_src
; ++src
) {
777 sel
= alu
->src
[src
].sel
;
778 elem
= alu
->src
[src
].chan
;
779 if (is_const(sel
)) { /* Any constant, including literal and inline constants. */
780 if (const_count
>= 2)
781 /* More than two references to a constant in
782 * transcendental operation. */
788 r
= reserve_cfile(bc
, bs
, (alu
->src
[src
].kc_bank
<<16) + sel
, elem
);
793 for (src
= 0; src
< num_src
; ++src
) {
794 sel
= alu
->src
[src
].sel
;
795 elem
= alu
->src
[src
].chan
;
797 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
798 if (cycle
< const_count
)
799 /* Cycle for GPR load conflicts with
800 * constant load in transcendental operation. */
802 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
806 /* PV PS restrictions */
807 if (const_count
&& (sel
== 254 || sel
== 255)) {
808 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
809 if (cycle
< const_count
)
816 static int check_and_set_bank_swizzle(struct r600_bytecode
*bc
,
817 struct r600_bytecode_alu
*slots
[5])
819 struct alu_bank_swizzle bs
;
821 int i
, r
= 0, forced
= 1;
822 boolean scalar_only
= bc
->chip_class
== CAYMAN
? false : true;
823 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
825 for (i
= 0; i
< max_slots
; i
++) {
827 if (slots
[i
]->bank_swizzle_force
) {
828 slots
[i
]->bank_swizzle
= slots
[i
]->bank_swizzle_force
;
834 if (i
< 4 && slots
[i
])
840 /* Just check every possible combination of bank swizzle.
841 * Not very efficent, but works on the first try in most of the cases. */
842 for (i
= 0; i
< 4; i
++)
843 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
)
844 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
846 bank_swizzle
[i
] = slots
[i
]->bank_swizzle
;
848 bank_swizzle
[4] = SQ_ALU_SCL_210
;
849 while(bank_swizzle
[4] <= SQ_ALU_SCL_221
) {
851 if (max_slots
== 4) {
852 for (i
= 0; i
< max_slots
; i
++) {
853 if (bank_swizzle
[i
] == SQ_ALU_VEC_210
)
857 init_bank_swizzle(&bs
);
858 if (scalar_only
== false) {
859 for (i
= 0; i
< 4; i
++) {
861 r
= check_vector(bc
, slots
[i
], &bs
, bank_swizzle
[i
]);
869 if (!r
&& slots
[4] && max_slots
== 5) {
870 r
= check_scalar(bc
, slots
[4], &bs
, bank_swizzle
[4]);
873 for (i
= 0; i
< max_slots
; i
++) {
875 slots
[i
]->bank_swizzle
= bank_swizzle
[i
];
883 for (i
= 0; i
< max_slots
; i
++) {
884 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
) {
886 if (bank_swizzle
[i
] <= SQ_ALU_VEC_210
)
889 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
895 /* Couldn't find a working swizzle. */
899 static int replace_gpr_with_pv_ps(struct r600_bytecode
*bc
,
900 struct r600_bytecode_alu
*slots
[5], struct r600_bytecode_alu
*alu_prev
)
902 struct r600_bytecode_alu
*prev
[5];
904 int i
, j
, r
, src
, num_src
;
905 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
907 r
= assign_alu_units(bc
, alu_prev
, prev
);
911 for (i
= 0; i
< max_slots
; ++i
) {
912 if (prev
[i
] && (prev
[i
]->dst
.write
|| prev
[i
]->is_op3
) && !prev
[i
]->dst
.rel
) {
913 gpr
[i
] = prev
[i
]->dst
.sel
;
914 /* cube writes more than PV.X */
915 if (!is_alu_cube_inst(bc
, prev
[i
]) && is_alu_reduction_inst(bc
, prev
[i
]))
918 chan
[i
] = prev
[i
]->dst
.chan
;
923 for (i
= 0; i
< max_slots
; ++i
) {
924 struct r600_bytecode_alu
*alu
= slots
[i
];
928 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
929 for (src
= 0; src
< num_src
; ++src
) {
930 if (!is_gpr(alu
->src
[src
].sel
) || alu
->src
[src
].rel
)
933 if (bc
->chip_class
< CAYMAN
) {
934 if (alu
->src
[src
].sel
== gpr
[4] &&
935 alu
->src
[src
].chan
== chan
[4] &&
936 alu_prev
->pred_sel
== alu
->pred_sel
) {
937 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PS
;
938 alu
->src
[src
].chan
= 0;
943 for (j
= 0; j
< 4; ++j
) {
944 if (alu
->src
[src
].sel
== gpr
[j
] &&
945 alu
->src
[src
].chan
== j
&&
946 alu_prev
->pred_sel
== alu
->pred_sel
) {
947 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PV
;
948 alu
->src
[src
].chan
= chan
[j
];
958 void r600_bytecode_special_constants(uint32_t value
, unsigned *sel
, unsigned *neg
)
962 *sel
= V_SQ_ALU_SRC_0
;
965 *sel
= V_SQ_ALU_SRC_1_INT
;
968 *sel
= V_SQ_ALU_SRC_M_1_INT
;
970 case 0x3F800000: /* 1.0f */
971 *sel
= V_SQ_ALU_SRC_1
;
973 case 0x3F000000: /* 0.5f */
974 *sel
= V_SQ_ALU_SRC_0_5
;
976 case 0xBF800000: /* -1.0f */
977 *sel
= V_SQ_ALU_SRC_1
;
980 case 0xBF000000: /* -0.5f */
981 *sel
= V_SQ_ALU_SRC_0_5
;
985 *sel
= V_SQ_ALU_SRC_LITERAL
;
990 /* compute how many literal are needed */
991 static int r600_bytecode_alu_nliterals(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
992 uint32_t literal
[4], unsigned *nliteral
)
994 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
997 for (i
= 0; i
< num_src
; ++i
) {
998 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
999 uint32_t value
= alu
->src
[i
].value
;
1001 for (j
= 0; j
< *nliteral
; ++j
) {
1002 if (literal
[j
] == value
) {
1010 literal
[(*nliteral
)++] = value
;
1017 static void r600_bytecode_alu_adjust_literals(struct r600_bytecode
*bc
,
1018 struct r600_bytecode_alu
*alu
,
1019 uint32_t literal
[4], unsigned nliteral
)
1021 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
1024 for (i
= 0; i
< num_src
; ++i
) {
1025 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1026 uint32_t value
= alu
->src
[i
].value
;
1027 for (j
= 0; j
< nliteral
; ++j
) {
1028 if (literal
[j
] == value
) {
1029 alu
->src
[i
].chan
= j
;
1037 static int merge_inst_groups(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*slots
[5],
1038 struct r600_bytecode_alu
*alu_prev
)
1040 struct r600_bytecode_alu
*prev
[5];
1041 struct r600_bytecode_alu
*result
[5] = { NULL
};
1043 uint32_t literal
[4], prev_literal
[4];
1044 unsigned nliteral
= 0, prev_nliteral
= 0;
1046 int i
, j
, r
, src
, num_src
;
1047 int num_once_inst
= 0;
1048 int have_mova
= 0, have_rel
= 0;
1049 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
1051 r
= assign_alu_units(bc
, alu_prev
, prev
);
1055 for (i
= 0; i
< max_slots
; ++i
) {
1057 if (prev
[i
]->pred_sel
)
1059 if (is_alu_once_inst(bc
, prev
[i
]))
1063 if (slots
[i
]->pred_sel
)
1065 if (is_alu_once_inst(bc
, slots
[i
]))
1070 for (i
= 0; i
< max_slots
; ++i
) {
1071 struct r600_bytecode_alu
*alu
;
1073 if (num_once_inst
> 0)
1076 /* check number of literals */
1078 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], literal
, &nliteral
))
1080 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], prev_literal
, &prev_nliteral
))
1082 if (is_alu_mova_inst(bc
, prev
[i
])) {
1087 num_once_inst
+= is_alu_once_inst(bc
, prev
[i
]);
1089 if (slots
[i
] && r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
))
1092 /* Let's check used slots. */
1093 if (prev
[i
] && !slots
[i
]) {
1094 result
[i
] = prev
[i
];
1096 } else if (prev
[i
] && slots
[i
]) {
1097 if (max_slots
== 5 && result
[4] == NULL
&& prev
[4] == NULL
&& slots
[4] == NULL
) {
1098 /* Trans unit is still free try to use it. */
1099 if (is_alu_any_unit_inst(bc
, slots
[i
])) {
1100 result
[i
] = prev
[i
];
1101 result
[4] = slots
[i
];
1102 } else if (is_alu_any_unit_inst(bc
, prev
[i
])) {
1103 if (slots
[i
]->dst
.sel
== prev
[i
]->dst
.sel
&&
1104 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
1105 (prev
[i
]->dst
.write
== 1 || prev
[i
]->is_op3
))
1108 result
[i
] = slots
[i
];
1109 result
[4] = prev
[i
];
1114 } else if(!slots
[i
]) {
1117 if (max_slots
== 5 && slots
[i
] && prev
[4] &&
1118 slots
[i
]->dst
.sel
== prev
[4]->dst
.sel
&&
1119 slots
[i
]->dst
.chan
== prev
[4]->dst
.chan
&&
1120 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
1121 (prev
[4]->dst
.write
== 1 || prev
[4]->is_op3
))
1124 result
[i
] = slots
[i
];
1128 num_once_inst
+= is_alu_once_inst(bc
, alu
);
1130 /* don't reschedule NOPs */
1131 if (is_nop_inst(bc
, alu
))
1134 /* Let's check dst gpr. */
1141 /* Let's check source gprs */
1142 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
1143 for (src
= 0; src
< num_src
; ++src
) {
1144 if (alu
->src
[src
].rel
) {
1150 /* Constants don't matter. */
1151 if (!is_gpr(alu
->src
[src
].sel
))
1154 for (j
= 0; j
< max_slots
; ++j
) {
1155 if (!prev
[j
] || !(prev
[j
]->dst
.write
|| prev
[j
]->is_op3
))
1158 /* If it's relative then we can't determin which gpr is really used. */
1159 if (prev
[j
]->dst
.chan
== alu
->src
[src
].chan
&&
1160 (prev
[j
]->dst
.sel
== alu
->src
[src
].sel
||
1161 prev
[j
]->dst
.rel
|| alu
->src
[src
].rel
))
1167 /* more than one PRED_ or KILL_ ? */
1168 if (num_once_inst
> 1)
1171 /* check if the result can still be swizzlet */
1172 r
= check_and_set_bank_swizzle(bc
, result
);
1176 /* looks like everything worked out right, apply the changes */
1178 /* undo adding previus literals */
1179 bc
->cf_last
->ndw
-= align(prev_nliteral
, 2);
1181 /* sort instructions */
1182 for (i
= 0; i
< max_slots
; ++i
) {
1183 slots
[i
] = result
[i
];
1185 LIST_DEL(&result
[i
]->list
);
1186 result
[i
]->last
= 0;
1187 LIST_ADDTAIL(&result
[i
]->list
, &bc
->cf_last
->alu
);
1191 /* determine new last instruction */
1192 LIST_ENTRY(struct r600_bytecode_alu
, bc
->cf_last
->alu
.prev
, list
)->last
= 1;
1194 /* determine new first instruction */
1195 for (i
= 0; i
< max_slots
; ++i
) {
1197 bc
->cf_last
->curr_bs_head
= result
[i
];
1202 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->prev2_bs_head
;
1203 bc
->cf_last
->prev2_bs_head
= NULL
;
1208 /* we'll keep kcache sets sorted by bank & addr */
1209 static int r600_bytecode_alloc_kcache_line(struct r600_bytecode
*bc
,
1210 struct r600_bytecode_kcache
*kcache
,
1211 unsigned bank
, unsigned line
)
1213 int i
, kcache_banks
= bc
->chip_class
>= EVERGREEN
? 4 : 2;
1215 for (i
= 0; i
< kcache_banks
; i
++) {
1216 if (kcache
[i
].mode
) {
1219 if (kcache
[i
].bank
< bank
)
1222 if ((kcache
[i
].bank
== bank
&& kcache
[i
].addr
> line
+1) ||
1223 kcache
[i
].bank
> bank
) {
1224 /* try to insert new line */
1225 if (kcache
[kcache_banks
-1].mode
) {
1226 /* all sets are in use */
1230 memmove(&kcache
[i
+1],&kcache
[i
], (kcache_banks
-i
-1)*sizeof(struct r600_bytecode_kcache
));
1231 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_1
;
1232 kcache
[i
].bank
= bank
;
1233 kcache
[i
].addr
= line
;
1237 d
= line
- kcache
[i
].addr
;
1241 if (kcache
[i
].mode
== V_SQ_CF_KCACHE_LOCK_2
) {
1242 /* we are prepending the line to the current set,
1243 * discarding the existing second line,
1244 * so we'll have to insert line+2 after it */
1247 } else if (kcache
[i
].mode
== V_SQ_CF_KCACHE_LOCK_1
) {
1248 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
1251 /* V_SQ_CF_KCACHE_LOCK_LOOP_INDEX is not supported */
1254 } else if (d
== 1) {
1255 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
1259 } else { /* free kcache set - use it */
1260 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_1
;
1261 kcache
[i
].bank
= bank
;
1262 kcache
[i
].addr
= line
;
1269 static int r600_bytecode_alloc_inst_kcache_lines(struct r600_bytecode
*bc
,
1270 struct r600_bytecode_kcache
*kcache
,
1271 struct r600_bytecode_alu
*alu
)
1275 for (i
= 0; i
< 3; i
++) {
1276 unsigned bank
, line
, sel
= alu
->src
[i
].sel
;
1281 bank
= alu
->src
[i
].kc_bank
;
1282 line
= (sel
-512)>>4;
1284 if ((r
= r600_bytecode_alloc_kcache_line(bc
, kcache
, bank
, line
)))
1290 static int r600_bytecode_assign_kcache_banks(struct r600_bytecode
*bc
,
1291 struct r600_bytecode_alu
*alu
,
1292 struct r600_bytecode_kcache
* kcache
)
1296 /* Alter the src operands to refer to the kcache. */
1297 for (i
= 0; i
< 3; ++i
) {
1298 static const unsigned int base
[] = {128, 160, 256, 288};
1299 unsigned int line
, sel
= alu
->src
[i
].sel
, found
= 0;
1307 for (j
= 0; j
< 4 && !found
; ++j
) {
1308 switch (kcache
[j
].mode
) {
1309 case V_SQ_CF_KCACHE_NOP
:
1310 case V_SQ_CF_KCACHE_LOCK_LOOP_INDEX
:
1311 R600_ERR("unexpected kcache line mode\n");
1314 if (kcache
[j
].bank
== alu
->src
[i
].kc_bank
&&
1315 kcache
[j
].addr
<= line
&&
1316 line
< kcache
[j
].addr
+ kcache
[j
].mode
) {
1317 alu
->src
[i
].sel
= sel
- (kcache
[j
].addr
<<4);
1318 alu
->src
[i
].sel
+= base
[j
];
1327 static int r600_bytecode_alloc_kcache_lines(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, int type
)
1329 struct r600_bytecode_kcache kcache_sets
[4];
1330 struct r600_bytecode_kcache
*kcache
= kcache_sets
;
1333 memcpy(kcache
, bc
->cf_last
->kcache
, 4 * sizeof(struct r600_bytecode_kcache
));
1335 if ((r
= r600_bytecode_alloc_inst_kcache_lines(bc
, kcache
, alu
))) {
1336 /* can't alloc, need to start new clause */
1337 if ((r
= r600_bytecode_add_cf(bc
))) {
1340 bc
->cf_last
->inst
= type
;
1342 /* retry with the new clause */
1343 kcache
= bc
->cf_last
->kcache
;
1344 if ((r
= r600_bytecode_alloc_inst_kcache_lines(bc
, kcache
, alu
))) {
1345 /* can't alloc again- should never happen */
1349 /* update kcache sets */
1350 memcpy(bc
->cf_last
->kcache
, kcache
, 4 * sizeof(struct r600_bytecode_kcache
));
1353 /* if we actually used more than 2 kcache sets - use ALU_EXTENDED on eg+ */
1354 if (kcache
[2].mode
!= V_SQ_CF_KCACHE_NOP
) {
1355 if (bc
->chip_class
< EVERGREEN
)
1357 bc
->cf_last
->eg_alu_extended
= 1;
1363 static int insert_nop_r6xx(struct r600_bytecode
*bc
)
1365 struct r600_bytecode_alu alu
;
1368 for (i
= 0; i
< 4; i
++) {
1369 memset(&alu
, 0, sizeof(alu
));
1370 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
;
1371 alu
.src
[0].chan
= i
;
1373 alu
.last
= (i
== 3);
1374 r
= r600_bytecode_add_alu(bc
, &alu
);
1381 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
1382 static int load_ar_r6xx(struct r600_bytecode
*bc
)
1384 struct r600_bytecode_alu alu
;
1390 /* hack to avoid making MOVA the last instruction in the clause */
1391 if ((bc
->cf_last
->ndw
>>1) >= 110)
1392 bc
->force_add_cf
= 1;
1394 memset(&alu
, 0, sizeof(alu
));
1395 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
;
1396 alu
.src
[0].sel
= bc
->ar_reg
;
1398 alu
.index_mode
= INDEX_MODE_LOOP
;
1399 r
= r600_bytecode_add_alu(bc
, &alu
);
1403 /* no requirement to set uses waterfall on MOVA_GPR_INT */
1408 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
1409 static int load_ar(struct r600_bytecode
*bc
)
1411 struct r600_bytecode_alu alu
;
1414 if (bc
->ar_handling
)
1415 return load_ar_r6xx(bc
);
1420 /* hack to avoid making MOVA the last instruction in the clause */
1421 if ((bc
->cf_last
->ndw
>>1) >= 110)
1422 bc
->force_add_cf
= 1;
1424 memset(&alu
, 0, sizeof(alu
));
1425 alu
.inst
= BC_INST(bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
1426 alu
.src
[0].sel
= bc
->ar_reg
;
1428 r
= r600_bytecode_add_alu(bc
, &alu
);
1432 bc
->cf_last
->r6xx_uses_waterfall
= 1;
1437 int r600_bytecode_add_alu_type(struct r600_bytecode
*bc
, const struct r600_bytecode_alu
*alu
, int type
)
1439 struct r600_bytecode_alu
*nalu
= r600_bytecode_alu();
1440 struct r600_bytecode_alu
*lalu
;
1445 memcpy(nalu
, alu
, sizeof(struct r600_bytecode_alu
));
1447 if (bc
->cf_last
!= NULL
&& bc
->cf_last
->inst
!= type
) {
1448 /* check if we could add it anyway */
1449 if (bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
) &&
1450 type
== BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
)) {
1451 LIST_FOR_EACH_ENTRY(lalu
, &bc
->cf_last
->alu
, list
) {
1452 if (lalu
->execute_mask
) {
1453 bc
->force_add_cf
= 1;
1458 bc
->force_add_cf
= 1;
1461 /* cf can contains only alu or only vtx or only tex */
1462 if (bc
->cf_last
== NULL
|| bc
->force_add_cf
) {
1463 r
= r600_bytecode_add_cf(bc
);
1469 bc
->cf_last
->inst
= type
;
1471 /* Check AR usage and load it if required */
1472 for (i
= 0; i
< 3; i
++)
1473 if (nalu
->src
[i
].rel
&& !bc
->ar_loaded
)
1476 if (nalu
->dst
.rel
&& !bc
->ar_loaded
)
1479 /* Setup the kcache for this ALU instruction. This will start a new
1480 * ALU clause if needed. */
1481 if ((r
= r600_bytecode_alloc_kcache_lines(bc
, nalu
, type
))) {
1486 if (!bc
->cf_last
->curr_bs_head
) {
1487 bc
->cf_last
->curr_bs_head
= nalu
;
1489 /* number of gpr == the last gpr used in any alu */
1490 for (i
= 0; i
< 3; i
++) {
1491 if (nalu
->src
[i
].sel
>= bc
->ngpr
&& nalu
->src
[i
].sel
< 128) {
1492 bc
->ngpr
= nalu
->src
[i
].sel
+ 1;
1494 if (nalu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
)
1495 r600_bytecode_special_constants(nalu
->src
[i
].value
,
1496 &nalu
->src
[i
].sel
, &nalu
->src
[i
].neg
);
1498 if (nalu
->dst
.sel
>= bc
->ngpr
) {
1499 bc
->ngpr
= nalu
->dst
.sel
+ 1;
1501 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
1502 /* each alu use 2 dwords */
1503 bc
->cf_last
->ndw
+= 2;
1506 /* process cur ALU instructions for bank swizzle */
1508 uint32_t literal
[4];
1510 struct r600_bytecode_alu
*slots
[5];
1511 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
1512 r
= assign_alu_units(bc
, bc
->cf_last
->curr_bs_head
, slots
);
1516 if (bc
->cf_last
->prev_bs_head
) {
1517 r
= merge_inst_groups(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1522 if (bc
->cf_last
->prev_bs_head
) {
1523 r
= replace_gpr_with_pv_ps(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1528 r
= check_and_set_bank_swizzle(bc
, slots
);
1532 for (i
= 0, nliteral
= 0; i
< max_slots
; i
++) {
1534 r
= r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
);
1539 bc
->cf_last
->ndw
+= align(nliteral
, 2);
1541 /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots)
1543 if ((bc
->cf_last
->ndw
>> 1) >= 120) {
1544 bc
->force_add_cf
= 1;
1547 bc
->cf_last
->prev2_bs_head
= bc
->cf_last
->prev_bs_head
;
1548 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->curr_bs_head
;
1549 bc
->cf_last
->curr_bs_head
= NULL
;
1552 if (nalu
->dst
.rel
&& bc
->r6xx_nop_after_rel_dst
)
1553 insert_nop_r6xx(bc
);
1558 int r600_bytecode_add_alu(struct r600_bytecode
*bc
, const struct r600_bytecode_alu
*alu
)
1560 return r600_bytecode_add_alu_type(bc
, alu
, BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
));
1563 static unsigned r600_bytecode_num_tex_and_vtx_instructions(const struct r600_bytecode
*bc
)
1565 switch (bc
->chip_class
) {
1575 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1580 static inline boolean
last_inst_was_not_vtx_fetch(struct r600_bytecode
*bc
)
1582 switch (bc
->chip_class
) {
1585 return bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
1586 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
;
1588 return bc
->cf_last
->inst
!= EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1590 return bc
->cf_last
->inst
!= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
;
1592 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1597 int r600_bytecode_add_vtx(struct r600_bytecode
*bc
, const struct r600_bytecode_vtx
*vtx
)
1599 struct r600_bytecode_vtx
*nvtx
= r600_bytecode_vtx();
1604 memcpy(nvtx
, vtx
, sizeof(struct r600_bytecode_vtx
));
1606 /* cf can contains only alu or only vtx or only tex */
1607 if (bc
->cf_last
== NULL
||
1608 last_inst_was_not_vtx_fetch(bc
) ||
1610 r
= r600_bytecode_add_cf(bc
);
1615 switch (bc
->chip_class
) {
1618 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1621 bc
->cf_last
->inst
= EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1624 bc
->cf_last
->inst
= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
;
1627 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1632 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
1633 /* each fetch use 4 dwords */
1634 bc
->cf_last
->ndw
+= 4;
1636 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1637 bc
->force_add_cf
= 1;
1639 bc
->ngpr
= MAX2(bc
->ngpr
, vtx
->src_gpr
+ 1);
1640 bc
->ngpr
= MAX2(bc
->ngpr
, vtx
->dst_gpr
+ 1);
1645 int r600_bytecode_add_tex(struct r600_bytecode
*bc
, const struct r600_bytecode_tex
*tex
)
1647 struct r600_bytecode_tex
*ntex
= r600_bytecode_tex();
1652 memcpy(ntex
, tex
, sizeof(struct r600_bytecode_tex
));
1654 /* we can't fetch data und use it as texture lookup address in the same TEX clause */
1655 if (bc
->cf_last
!= NULL
&&
1656 bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
)) {
1657 struct r600_bytecode_tex
*ttex
;
1658 LIST_FOR_EACH_ENTRY(ttex
, &bc
->cf_last
->tex
, list
) {
1659 if (ttex
->dst_gpr
== ntex
->src_gpr
) {
1660 bc
->force_add_cf
= 1;
1664 /* slight hack to make gradients always go into same cf */
1665 if (ntex
->inst
== SQ_TEX_INST_SET_GRADIENTS_H
)
1666 bc
->force_add_cf
= 1;
1669 /* cf can contains only alu or only vtx or only tex */
1670 if (bc
->cf_last
== NULL
||
1671 bc
->cf_last
->inst
!= BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
) ||
1673 r
= r600_bytecode_add_cf(bc
);
1678 bc
->cf_last
->inst
= BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
);
1680 if (ntex
->src_gpr
>= bc
->ngpr
) {
1681 bc
->ngpr
= ntex
->src_gpr
+ 1;
1683 if (ntex
->dst_gpr
>= bc
->ngpr
) {
1684 bc
->ngpr
= ntex
->dst_gpr
+ 1;
1686 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
1687 /* each texture fetch use 4 dwords */
1688 bc
->cf_last
->ndw
+= 4;
1690 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1691 bc
->force_add_cf
= 1;
1695 int r600_bytecode_add_cfinst(struct r600_bytecode
*bc
, int inst
)
1698 r
= r600_bytecode_add_cf(bc
);
1702 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
1703 bc
->cf_last
->inst
= inst
;
1707 int cm_bytecode_add_cf_end(struct r600_bytecode
*bc
)
1709 return r600_bytecode_add_cfinst(bc
, CM_V_SQ_CF_WORD1_SQ_CF_INST_END
);
1712 /* common to all 3 families */
1713 static int r600_bytecode_vtx_build(struct r600_bytecode
*bc
, struct r600_bytecode_vtx
*vtx
, unsigned id
)
1715 bc
->bytecode
[id
] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
) |
1716 S_SQ_VTX_WORD0_FETCH_TYPE(vtx
->fetch_type
) |
1717 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
1718 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
);
1719 if (bc
->chip_class
< CAYMAN
)
1720 bc
->bytecode
[id
] |= S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
1722 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
1723 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
1724 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
1725 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
1726 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
1727 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
1728 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
1729 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
1730 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
1731 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
1732 bc
->bytecode
[id
] = S_SQ_VTX_WORD2_OFFSET(vtx
->offset
)|
1733 S_SQ_VTX_WORD2_ENDIAN_SWAP(vtx
->endian
);
1734 if (bc
->chip_class
< CAYMAN
)
1735 bc
->bytecode
[id
] |= S_SQ_VTX_WORD2_MEGA_FETCH(1);
1737 bc
->bytecode
[id
++] = 0;
1741 /* common to all 3 families */
1742 static int r600_bytecode_tex_build(struct r600_bytecode
*bc
, struct r600_bytecode_tex
*tex
, unsigned id
)
1744 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
1745 EG_S_SQ_TEX_WORD0_INST_MOD(tex
->inst_mod
) |
1746 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
1747 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
1748 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
1749 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
1750 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
1751 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
1752 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
1753 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
1754 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
1755 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
1756 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
1757 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
1758 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
1759 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
1760 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
1761 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
1762 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
1763 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
1764 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
1765 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
1766 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
1767 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
1768 bc
->bytecode
[id
++] = 0;
1772 /* r600 only, r700/eg bits in r700_asm.c */
1773 static int r600_bytecode_alu_build(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, unsigned id
)
1775 /* don't replace gpr by pv or ps for destination register */
1776 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
1777 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
1778 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
1779 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
1780 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
1781 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
1782 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
1783 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
1784 S_SQ_ALU_WORD0_INDEX_MODE(alu
->index_mode
) |
1785 S_SQ_ALU_WORD0_PRED_SEL(alu
->pred_sel
) |
1786 S_SQ_ALU_WORD0_LAST(alu
->last
);
1789 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1790 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1791 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1792 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1793 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
1794 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
1795 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
1796 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
1797 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
1798 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
1800 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1801 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1802 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1803 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1804 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
1805 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
1806 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
1807 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
1808 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
1809 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
1810 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->execute_mask
) |
1811 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->update_pred
);
1816 static void r600_bytecode_cf_vtx_build(uint32_t *bytecode
, const struct r600_bytecode_cf
*cf
)
1818 *bytecode
++ = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
1819 *bytecode
++ = cf
->inst
|
1820 S_SQ_CF_WORD1_BARRIER(1) |
1821 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
1824 /* common for r600/r700 - eg in eg_asm.c */
1825 static int r600_bytecode_cf_build(struct r600_bytecode
*bc
, struct r600_bytecode_cf
*cf
)
1827 unsigned id
= cf
->id
;
1830 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1831 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1832 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1833 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1834 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
1835 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache
[0].mode
) |
1836 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache
[0].bank
) |
1837 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache
[1].bank
);
1839 bc
->bytecode
[id
++] = cf
->inst
|
1840 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache
[1].mode
) |
1841 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache
[0].addr
) |
1842 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache
[1].addr
) |
1843 S_SQ_CF_ALU_WORD1_BARRIER(1) |
1844 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chip_class
== R600
? cf
->r6xx_uses_waterfall
: 0) |
1845 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
1847 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1848 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1849 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1850 if (bc
->chip_class
== R700
)
1851 r700_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1853 r600_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1855 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1856 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1857 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1858 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1859 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1860 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1861 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1862 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
1863 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
1864 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
1865 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
1866 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1868 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
1870 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
1871 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
1872 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
1873 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
1874 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1875 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1876 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1877 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1878 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1879 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1881 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
) |
1882 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(cf
->output
.array_size
) |
1883 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(cf
->output
.comp_mask
);
1885 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1886 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1887 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1888 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1889 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
1890 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1891 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1892 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1893 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1894 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1895 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
1896 bc
->bytecode
[id
++] = cf
->inst
|
1897 S_SQ_CF_WORD1_BARRIER(1) |
1898 S_SQ_CF_WORD1_COND(cf
->cond
) |
1899 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
1903 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1909 int r600_bytecode_build(struct r600_bytecode
*bc
)
1911 struct r600_bytecode_cf
*cf
;
1912 struct r600_bytecode_alu
*alu
;
1913 struct r600_bytecode_vtx
*vtx
;
1914 struct r600_bytecode_tex
*tex
;
1915 uint32_t literal
[4];
1920 if (bc
->callstack
[0].max
> 0)
1921 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
1922 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
1926 /* first path compute addr of each CF block */
1927 /* addr start after all the CF instructions */
1928 addr
= bc
->cf_last
->id
+ 2;
1929 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1930 if (bc
->chip_class
>= EVERGREEN
) {
1932 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1933 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1934 /* fetch node need to be 16 bytes aligned*/
1936 addr
&= 0xFFFFFFFCUL
;
1938 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1939 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1940 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1941 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1942 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1943 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1944 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
1945 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
1946 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
1947 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
1948 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
1949 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
1950 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
1951 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
1952 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
1953 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
1954 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
1955 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
1956 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
1957 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
1958 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
1959 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
1960 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1961 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1962 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1963 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1964 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
1965 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1966 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1967 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1968 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1969 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1970 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
1974 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1979 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1980 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1981 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1982 /* fetch node need to be 16 bytes aligned*/
1984 addr
&= 0xFFFFFFFCUL
;
1986 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1987 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1988 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1989 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1990 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1991 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1992 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
1993 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
1994 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
1995 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
1996 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1997 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1998 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1999 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2000 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2001 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2002 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2003 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2004 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2007 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2013 bc
->ndw
= cf
->addr
+ cf
->ndw
;
2016 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
2017 if (bc
->bytecode
== NULL
)
2019 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
2021 if (bc
->chip_class
>= EVERGREEN
) {
2022 r
= eg_bytecode_cf_build(bc
, cf
);
2027 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2028 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2029 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2030 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2032 memset(literal
, 0, sizeof(literal
));
2033 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
2034 r
= r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
2037 r600_bytecode_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
2038 r600_bytecode_assign_kcache_banks(bc
, alu
, cf
->kcache
);
2040 switch(bc
->chip_class
) {
2041 case EVERGREEN
: /* eg alu is same encoding as r700 */
2043 r
= r700_bytecode_alu_build(bc
, alu
, addr
);
2046 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
2053 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
2054 bc
->bytecode
[addr
++] = literal
[i
];
2057 memset(literal
, 0, sizeof(literal
));
2061 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2062 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2063 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
2069 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2070 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2071 assert(bc
->chip_class
>= EVERGREEN
);
2072 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
2077 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
2078 r
= r600_bytecode_tex_build(bc
, tex
, addr
);
2084 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2085 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2086 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
2087 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
2088 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
2089 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
2090 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
2091 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
2092 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
2093 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
2094 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
2095 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
2096 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
2097 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
2098 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
2099 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
2100 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
2101 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
2102 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2103 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2104 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2105 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2106 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2107 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2108 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2109 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2110 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2111 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2112 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
2117 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2121 r
= r600_bytecode_cf_build(bc
, cf
);
2126 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2127 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2128 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2129 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2131 memset(literal
, 0, sizeof(literal
));
2132 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
2133 r
= r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
2136 r600_bytecode_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
2137 r600_bytecode_assign_kcache_banks(bc
, alu
, cf
->kcache
);
2139 switch(bc
->chip_class
) {
2141 r
= r600_bytecode_alu_build(bc
, alu
, addr
);
2144 r
= r700_bytecode_alu_build(bc
, alu
, addr
);
2147 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
2154 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
2155 bc
->bytecode
[addr
++] = literal
[i
];
2158 memset(literal
, 0, sizeof(literal
));
2162 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2163 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
2164 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2165 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
2171 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2172 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
2173 r
= r600_bytecode_tex_build(bc
, tex
, addr
);
2179 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2180 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2181 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
2182 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
2183 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
2184 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
2185 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2186 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2187 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2188 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2189 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2190 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2191 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2192 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2193 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2194 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2197 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2205 void r600_bytecode_clear(struct r600_bytecode
*bc
)
2207 struct r600_bytecode_cf
*cf
= NULL
, *next_cf
;
2210 bc
->bytecode
= NULL
;
2212 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
2213 struct r600_bytecode_alu
*alu
= NULL
, *next_alu
;
2214 struct r600_bytecode_tex
*tex
= NULL
, *next_tex
;
2215 struct r600_bytecode_tex
*vtx
= NULL
, *next_vtx
;
2217 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
2221 LIST_INITHEAD(&cf
->alu
);
2223 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
2227 LIST_INITHEAD(&cf
->tex
);
2229 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
2233 LIST_INITHEAD(&cf
->vtx
);
2238 LIST_INITHEAD(&cf
->list
);
2241 void r600_bytecode_dump(struct r600_bytecode
*bc
)
2243 struct r600_bytecode_cf
*cf
= NULL
;
2244 struct r600_bytecode_alu
*alu
= NULL
;
2245 struct r600_bytecode_vtx
*vtx
= NULL
;
2246 struct r600_bytecode_tex
*tex
= NULL
;
2249 uint32_t literal
[4];
2253 switch (bc
->chip_class
) {
2268 fprintf(stderr
, "bytecode %d dw -- %d gprs ---------------------\n", bc
->ndw
, bc
->ngpr
);
2269 fprintf(stderr
, " %c\n", chip
);
2271 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
2274 if (bc
->chip_class
>= EVERGREEN
) {
2276 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2277 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2278 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2279 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2280 if (cf
->eg_alu_extended
) {
2281 fprintf(stderr
, "%04d %08X ALU_EXT0 ", id
, bc
->bytecode
[id
]);
2282 fprintf(stderr
, "KCACHE_BANK2:%X ", cf
->kcache
[2].bank
);
2283 fprintf(stderr
, "KCACHE_BANK3:%X ", cf
->kcache
[3].bank
);
2284 fprintf(stderr
, "KCACHE_MODE2:%X\n", cf
->kcache
[2].mode
);
2286 fprintf(stderr
, "%04d %08X ALU_EXT1 ", id
, bc
->bytecode
[id
]);
2287 fprintf(stderr
, "KCACHE_MODE3:%X ", cf
->kcache
[3].mode
);
2288 fprintf(stderr
, "KCACHE_ADDR2:%X ", cf
->kcache
[2].addr
);
2289 fprintf(stderr
, "KCACHE_ADDR3:%X\n", cf
->kcache
[3].addr
);
2293 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2294 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
2295 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
2296 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
2297 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
2299 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2300 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
));
2301 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
2302 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
2303 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
2304 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
2306 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2307 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2308 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2309 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
2311 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2312 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2313 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
2315 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2316 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2317 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2318 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2319 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
2320 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
2321 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2323 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2324 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
2325 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
2326 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
2327 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
2328 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2329 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
));
2330 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2331 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2333 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
2334 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
2335 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
2336 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
2337 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
2338 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
2339 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
2340 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
2341 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
2342 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
2343 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
2344 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
2345 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
2346 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
2347 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
2348 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
2349 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i_BUF%i ", id
, bc
->bytecode
[id
],
2350 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2351 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) / 4,
2352 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2353 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) % 4);
2354 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2355 fprintf(stderr
, "ELEM_SIZE:%i ", cf
->output
.elem_size
);
2356 fprintf(stderr
, "ARRAY_BASE:%i ", cf
->output
.array_base
);
2357 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2359 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i_BUF%i ", id
, bc
->bytecode
[id
],
2360 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2361 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) / 4,
2362 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2363 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) % 4);
2364 fprintf(stderr
, "ARRAY_SIZE:%i ", cf
->output
.array_size
);
2365 fprintf(stderr
, "COMP_MASK:%X ", cf
->output
.comp_mask
);
2366 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2367 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
2368 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2369 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2371 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2372 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2373 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2374 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2375 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2376 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2377 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2378 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2379 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2380 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2381 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
2382 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2383 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
2385 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2386 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2387 fprintf(stderr
, "COND:%X ", cf
->cond
);
2388 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
2391 fprintf(stderr
, "%04d %08X CF NATIVE\n", id
, bc
->bytecode
[id
]);
2392 fprintf(stderr
, "%04d %08X CF NATIVE\n", id
+ 1, bc
->bytecode
[id
+ 1]);
2395 R600_ERR("Unknown instruction %0x\n", cf
->inst
);
2399 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2400 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2401 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2402 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2403 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2404 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
2405 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
2406 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
2407 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
2409 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2410 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
));
2411 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
2412 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
2413 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
2414 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
2416 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2417 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2418 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
2419 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2420 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
2422 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2423 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2424 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
2426 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2427 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2428 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2429 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2430 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
2431 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
2432 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2434 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2435 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
2436 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
2437 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
2438 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
2439 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2440 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
));
2441 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2442 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2444 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
2445 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
2446 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
2447 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
2448 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i ", id
, bc
->bytecode
[id
],
2449 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2450 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
));
2451 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2452 fprintf(stderr
, "ELEM_SIZE:%i ", cf
->output
.elem_size
);
2453 fprintf(stderr
, "ARRAY_BASE:%i ", cf
->output
.array_base
);
2454 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2456 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i ", id
, bc
->bytecode
[id
],
2457 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2458 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
));
2459 fprintf(stderr
, "ARRAY_SIZE:%i ", cf
->output
.array_size
);
2460 fprintf(stderr
, "COMP_MASK:%X ", cf
->output
.comp_mask
);
2461 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2462 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
2463 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2464 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2466 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2467 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2468 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2469 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2470 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2471 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2472 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2473 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2474 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2475 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2476 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2477 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
2479 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2480 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2481 fprintf(stderr
, "COND:%X ", cf
->cond
);
2482 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
2485 R600_ERR("Unknown instruction %0x\n", cf
->inst
);
2491 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
2492 r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
2494 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2495 fprintf(stderr
, "SRC0(SEL:%d ", alu
->src
[0].sel
);
2496 fprintf(stderr
, "REL:%d ", alu
->src
[0].rel
);
2497 fprintf(stderr
, "CHAN:%d ", alu
->src
[0].chan
);
2498 fprintf(stderr
, "NEG:%d) ", alu
->src
[0].neg
);
2499 fprintf(stderr
, "SRC1(SEL:%d ", alu
->src
[1].sel
);
2500 fprintf(stderr
, "REL:%d ", alu
->src
[1].rel
);
2501 fprintf(stderr
, "CHAN:%d ", alu
->src
[1].chan
);
2502 fprintf(stderr
, "NEG:%d ", alu
->src
[1].neg
);
2503 fprintf(stderr
, "IM:%d) ", alu
->index_mode
);
2504 fprintf(stderr
, "PRED_SEL:%d ", alu
->pred_sel
);
2505 fprintf(stderr
, "LAST:%d)\n", alu
->last
);
2507 fprintf(stderr
, "%04d %08X %c ", id
, bc
->bytecode
[id
], alu
->last
? '*' : ' ');
2508 fprintf(stderr
, "INST:0x%x ", alu
->inst
);
2509 fprintf(stderr
, "DST(SEL:%d ", alu
->dst
.sel
);
2510 fprintf(stderr
, "CHAN:%d ", alu
->dst
.chan
);
2511 fprintf(stderr
, "REL:%d ", alu
->dst
.rel
);
2512 fprintf(stderr
, "CLAMP:%d) ", alu
->dst
.clamp
);
2513 fprintf(stderr
, "BANK_SWIZZLE:%d ", alu
->bank_swizzle
);
2515 fprintf(stderr
, "SRC2(SEL:%d ", alu
->src
[2].sel
);
2516 fprintf(stderr
, "REL:%d ", alu
->src
[2].rel
);
2517 fprintf(stderr
, "CHAN:%d ", alu
->src
[2].chan
);
2518 fprintf(stderr
, "NEG:%d)\n", alu
->src
[2].neg
);
2520 fprintf(stderr
, "SRC0_ABS:%d ", alu
->src
[0].abs
);
2521 fprintf(stderr
, "SRC1_ABS:%d ", alu
->src
[1].abs
);
2522 fprintf(stderr
, "WRITE_MASK:%d ", alu
->dst
.write
);
2523 fprintf(stderr
, "OMOD:%d ", alu
->omod
);
2524 fprintf(stderr
, "EXECUTE_MASK:%d ", alu
->execute_mask
);
2525 fprintf(stderr
, "UPDATE_PRED:%d\n", alu
->update_pred
);
2530 for (i
= 0; i
< nliteral
; i
++, id
++) {
2531 float *f
= (float*)(bc
->bytecode
+ id
);
2532 fprintf(stderr
, "%04d %08X\t%f (%d)\n", id
, bc
->bytecode
[id
], *f
,
2533 *(bc
->bytecode
+ id
));
2540 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
2541 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2542 fprintf(stderr
, "INST:0x%x ", tex
->inst
);
2543 fprintf(stderr
, "RESOURCE_ID:%d ", tex
->resource_id
);
2544 fprintf(stderr
, "SRC(GPR:%d ", tex
->src_gpr
);
2545 fprintf(stderr
, "REL:%d)\n", tex
->src_rel
);
2547 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2548 fprintf(stderr
, "DST(GPR:%d ", tex
->dst_gpr
);
2549 fprintf(stderr
, "REL:%d ", tex
->dst_rel
);
2550 fprintf(stderr
, "SEL_X:%d ", tex
->dst_sel_x
);
2551 fprintf(stderr
, "SEL_Y:%d ", tex
->dst_sel_y
);
2552 fprintf(stderr
, "SEL_Z:%d ", tex
->dst_sel_z
);
2553 fprintf(stderr
, "SEL_W:%d) ", tex
->dst_sel_w
);
2554 fprintf(stderr
, "LOD_BIAS:%d ", tex
->lod_bias
);
2555 fprintf(stderr
, "COORD_TYPE_X:%d ", tex
->coord_type_x
);
2556 fprintf(stderr
, "COORD_TYPE_Y:%d ", tex
->coord_type_y
);
2557 fprintf(stderr
, "COORD_TYPE_Z:%d ", tex
->coord_type_z
);
2558 fprintf(stderr
, "COORD_TYPE_W:%d\n", tex
->coord_type_w
);
2560 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2561 fprintf(stderr
, "OFFSET_X:%d ", tex
->offset_x
);
2562 fprintf(stderr
, "OFFSET_Y:%d ", tex
->offset_y
);
2563 fprintf(stderr
, "OFFSET_Z:%d ", tex
->offset_z
);
2564 fprintf(stderr
, "SAMPLER_ID:%d ", tex
->sampler_id
);
2565 fprintf(stderr
, "SRC(SEL_X:%d ", tex
->src_sel_x
);
2566 fprintf(stderr
, "SEL_Y:%d ", tex
->src_sel_y
);
2567 fprintf(stderr
, "SEL_Z:%d ", tex
->src_sel_z
);
2568 fprintf(stderr
, "SEL_W:%d)\n", tex
->src_sel_w
);
2570 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
2574 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2575 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2576 fprintf(stderr
, "INST:%d ", vtx
->inst
);
2577 fprintf(stderr
, "FETCH_TYPE:%d ", vtx
->fetch_type
);
2578 fprintf(stderr
, "BUFFER_ID:%d\n", vtx
->buffer_id
);
2580 /* This assumes that no semantic fetches exist */
2581 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2582 fprintf(stderr
, "SRC(GPR:%d ", vtx
->src_gpr
);
2583 fprintf(stderr
, "SEL_X:%d) ", vtx
->src_sel_x
);
2584 if (bc
->chip_class
< CAYMAN
)
2585 fprintf(stderr
, "MEGA_FETCH_COUNT:%d ", vtx
->mega_fetch_count
);
2587 fprintf(stderr
, "SEL_Y:%d) ", 0);
2588 fprintf(stderr
, "DST(GPR:%d ", vtx
->dst_gpr
);
2589 fprintf(stderr
, "SEL_X:%d ", vtx
->dst_sel_x
);
2590 fprintf(stderr
, "SEL_Y:%d ", vtx
->dst_sel_y
);
2591 fprintf(stderr
, "SEL_Z:%d ", vtx
->dst_sel_z
);
2592 fprintf(stderr
, "SEL_W:%d) ", vtx
->dst_sel_w
);
2593 fprintf(stderr
, "USE_CONST_FIELDS:%d ", vtx
->use_const_fields
);
2594 fprintf(stderr
, "FORMAT(DATA:%d ", vtx
->data_format
);
2595 fprintf(stderr
, "NUM:%d ", vtx
->num_format_all
);
2596 fprintf(stderr
, "COMP:%d ", vtx
->format_comp_all
);
2597 fprintf(stderr
, "MODE:%d)\n", vtx
->srf_mode_all
);
2599 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2600 fprintf(stderr
, "ENDIAN:%d ", vtx
->endian
);
2601 fprintf(stderr
, "OFFSET:%d\n", vtx
->offset
);
2604 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
2609 fprintf(stderr
, "--------------------------------------\n");
2612 void r600_vertex_data_type(enum pipe_format pformat
,
2614 unsigned *num_format
, unsigned *format_comp
, unsigned *endian
)
2616 const struct util_format_description
*desc
;
2622 *endian
= ENDIAN_NONE
;
2624 desc
= util_format_description(pformat
);
2625 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
2629 /* Find the first non-VOID channel. */
2630 for (i
= 0; i
< 4; i
++) {
2631 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
2636 *endian
= r600_endian_swap(desc
->channel
[i
].size
);
2638 switch (desc
->channel
[i
].type
) {
2639 /* Half-floats, floats, ints */
2640 case UTIL_FORMAT_TYPE_FLOAT
:
2641 switch (desc
->channel
[i
].size
) {
2643 switch (desc
->nr_channels
) {
2645 *format
= FMT_16_FLOAT
;
2648 *format
= FMT_16_16_FLOAT
;
2652 *format
= FMT_16_16_16_16_FLOAT
;
2657 switch (desc
->nr_channels
) {
2659 *format
= FMT_32_FLOAT
;
2662 *format
= FMT_32_32_FLOAT
;
2665 *format
= FMT_32_32_32_FLOAT
;
2668 *format
= FMT_32_32_32_32_FLOAT
;
2677 case UTIL_FORMAT_TYPE_UNSIGNED
:
2679 case UTIL_FORMAT_TYPE_SIGNED
:
2680 switch (desc
->channel
[i
].size
) {
2682 switch (desc
->nr_channels
) {
2691 *format
= FMT_8_8_8_8
;
2696 if (desc
->nr_channels
!= 4)
2699 *format
= FMT_2_10_10_10
;
2702 switch (desc
->nr_channels
) {
2707 *format
= FMT_16_16
;
2711 *format
= FMT_16_16_16_16
;
2716 switch (desc
->nr_channels
) {
2721 *format
= FMT_32_32
;
2724 *format
= FMT_32_32_32
;
2727 *format
= FMT_32_32_32_32
;
2739 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2744 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
||
2745 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2746 if (!desc
->channel
[i
].normalized
) {
2747 if (desc
->channel
[i
].pure_integer
)
2755 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
2758 void *r600_create_vertex_fetch_shader(struct pipe_context
*ctx
,
2760 const struct pipe_vertex_element
*elements
)
2762 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2763 static int dump_shaders
= -1;
2764 struct r600_bytecode bc
;
2765 struct r600_bytecode_vtx vtx
;
2766 const struct util_format_description
*desc
;
2767 unsigned fetch_resource_start
= rctx
->chip_class
>= EVERGREEN
? 0 : 160;
2768 unsigned format
, num_format
, format_comp
, endian
;
2770 int i
, j
, r
, fs_size
;
2771 struct r600_fetch_shader
*shader
;
2775 memset(&bc
, 0, sizeof(bc
));
2776 r600_bytecode_init(&bc
, rctx
->chip_class
, rctx
->family
,
2777 rctx
->screen
->msaa_texture_support
);
2779 for (i
= 0; i
< count
; i
++) {
2780 if (elements
[i
].instance_divisor
> 1) {
2781 if (rctx
->chip_class
== CAYMAN
) {
2782 for (j
= 0; j
< 4; j
++) {
2783 struct r600_bytecode_alu alu
;
2784 memset(&alu
, 0, sizeof(alu
));
2785 alu
.inst
= BC_INST(&bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2787 alu
.src
[0].chan
= 3;
2788 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2789 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2790 alu
.dst
.sel
= i
+ 1;
2792 alu
.dst
.write
= j
== 3;
2794 if ((r
= r600_bytecode_add_alu(&bc
, &alu
))) {
2795 r600_bytecode_clear(&bc
);
2800 struct r600_bytecode_alu alu
;
2801 memset(&alu
, 0, sizeof(alu
));
2802 alu
.inst
= BC_INST(&bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2804 alu
.src
[0].chan
= 3;
2805 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2806 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2807 alu
.dst
.sel
= i
+ 1;
2811 if ((r
= r600_bytecode_add_alu(&bc
, &alu
))) {
2812 r600_bytecode_clear(&bc
);
2819 for (i
= 0; i
< count
; i
++) {
2820 r600_vertex_data_type(elements
[i
].src_format
,
2821 &format
, &num_format
, &format_comp
, &endian
);
2823 desc
= util_format_description(elements
[i
].src_format
);
2825 r600_bytecode_clear(&bc
);
2826 R600_ERR("unknown format %d\n", elements
[i
].src_format
);
2830 if (elements
[i
].src_offset
> 65535) {
2831 r600_bytecode_clear(&bc
);
2832 R600_ERR("too big src_offset: %u\n", elements
[i
].src_offset
);
2836 memset(&vtx
, 0, sizeof(vtx
));
2837 vtx
.buffer_id
= elements
[i
].vertex_buffer_index
+ fetch_resource_start
;
2838 vtx
.fetch_type
= elements
[i
].instance_divisor
? 1 : 0;
2839 vtx
.src_gpr
= elements
[i
].instance_divisor
> 1 ? i
+ 1 : 0;
2840 vtx
.src_sel_x
= elements
[i
].instance_divisor
? 3 : 0;
2841 vtx
.mega_fetch_count
= 0x1F;
2842 vtx
.dst_gpr
= i
+ 1;
2843 vtx
.dst_sel_x
= desc
->swizzle
[0];
2844 vtx
.dst_sel_y
= desc
->swizzle
[1];
2845 vtx
.dst_sel_z
= desc
->swizzle
[2];
2846 vtx
.dst_sel_w
= desc
->swizzle
[3];
2847 vtx
.data_format
= format
;
2848 vtx
.num_format_all
= num_format
;
2849 vtx
.format_comp_all
= format_comp
;
2850 vtx
.srf_mode_all
= 1;
2851 vtx
.offset
= elements
[i
].src_offset
;
2852 vtx
.endian
= endian
;
2854 if ((r
= r600_bytecode_add_vtx(&bc
, &vtx
))) {
2855 r600_bytecode_clear(&bc
);
2860 r600_bytecode_add_cfinst(&bc
, BC_INST(&bc
, V_SQ_CF_WORD1_SQ_CF_INST_RETURN
));
2862 if ((r
= r600_bytecode_build(&bc
))) {
2863 r600_bytecode_clear(&bc
);
2867 if (dump_shaders
== -1)
2868 dump_shaders
= debug_get_bool_option("R600_DUMP_SHADERS", FALSE
);
2871 fprintf(stderr
, "--------------------------------------------------------------\n");
2872 r600_bytecode_dump(&bc
);
2873 fprintf(stderr
, "______________________________________________________________\n");
2878 /* Allocate the CSO. */
2879 shader
= CALLOC_STRUCT(r600_fetch_shader
);
2881 r600_bytecode_clear(&bc
);
2885 u_suballocator_alloc(rctx
->allocator_fetch_shader
, fs_size
, &shader
->offset
,
2886 (struct pipe_resource
**)&shader
->buffer
);
2887 if (!shader
->buffer
) {
2888 r600_bytecode_clear(&bc
);
2893 bytecode
= rctx
->ws
->buffer_map(shader
->buffer
->cs_buf
, rctx
->cs
,
2894 PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_UNSYNCHRONIZED
);
2895 bytecode
+= shader
->offset
/ 4;
2897 if (R600_BIG_ENDIAN
) {
2898 for (i
= 0; i
< fs_size
/ 4; ++i
) {
2899 bytecode
[i
] = bswap_32(bc
.bytecode
[i
]);
2902 memcpy(bytecode
, bc
.bytecode
, fs_size
);
2904 rctx
->ws
->buffer_unmap(shader
->buffer
->cs_buf
);
2906 r600_bytecode_clear(&bc
);
2910 void r600_bytecode_alu_read(struct r600_bytecode_alu
*alu
, uint32_t word0
, uint32_t word1
)
2913 alu
->src
[0].sel
= G_SQ_ALU_WORD0_SRC0_SEL(word0
);
2914 alu
->src
[0].rel
= G_SQ_ALU_WORD0_SRC0_REL(word0
);
2915 alu
->src
[0].chan
= G_SQ_ALU_WORD0_SRC0_CHAN(word0
);
2916 alu
->src
[0].neg
= G_SQ_ALU_WORD0_SRC0_NEG(word0
);
2917 alu
->src
[1].sel
= G_SQ_ALU_WORD0_SRC1_SEL(word0
);
2918 alu
->src
[1].rel
= G_SQ_ALU_WORD0_SRC1_REL(word0
);
2919 alu
->src
[1].chan
= G_SQ_ALU_WORD0_SRC1_CHAN(word0
);
2920 alu
->src
[1].neg
= G_SQ_ALU_WORD0_SRC1_NEG(word0
);
2921 alu
->index_mode
= G_SQ_ALU_WORD0_INDEX_MODE(word0
);
2922 alu
->pred_sel
= G_SQ_ALU_WORD0_PRED_SEL(word0
);
2923 alu
->last
= G_SQ_ALU_WORD0_LAST(word0
);
2926 alu
->bank_swizzle
= G_SQ_ALU_WORD1_BANK_SWIZZLE(word1
);
2927 if (alu
->bank_swizzle
)
2928 alu
->bank_swizzle_force
= alu
->bank_swizzle
;
2929 alu
->dst
.sel
= G_SQ_ALU_WORD1_DST_GPR(word1
);
2930 alu
->dst
.rel
= G_SQ_ALU_WORD1_DST_REL(word1
);
2931 alu
->dst
.chan
= G_SQ_ALU_WORD1_DST_CHAN(word1
);
2932 alu
->dst
.clamp
= G_SQ_ALU_WORD1_CLAMP(word1
);
2933 if (G_SQ_ALU_WORD1_ENCODING(word1
)) /*ALU_DWORD1_OP3*/
2936 alu
->src
[2].sel
= G_SQ_ALU_WORD1_OP3_SRC2_SEL(word1
);
2937 alu
->src
[2].rel
= G_SQ_ALU_WORD1_OP3_SRC2_REL(word1
);
2938 alu
->src
[2].chan
= G_SQ_ALU_WORD1_OP3_SRC2_CHAN(word1
);
2939 alu
->src
[2].neg
= G_SQ_ALU_WORD1_OP3_SRC2_NEG(word1
);
2940 alu
->inst
= G_SQ_ALU_WORD1_OP3_ALU_INST(word1
);
2942 else /*ALU_DWORD1_OP2*/
2944 alu
->src
[0].abs
= G_SQ_ALU_WORD1_OP2_SRC0_ABS(word1
);
2945 alu
->src
[1].abs
= G_SQ_ALU_WORD1_OP2_SRC1_ABS(word1
);
2946 alu
->inst
= G_SQ_ALU_WORD1_OP2_ALU_INST(word1
);
2947 alu
->omod
= G_SQ_ALU_WORD1_OP2_OMOD(word1
);
2948 alu
->dst
.write
= G_SQ_ALU_WORD1_OP2_WRITE_MASK(word1
);
2949 alu
->update_pred
= G_SQ_ALU_WORD1_OP2_UPDATE_PRED(word1
);
2951 G_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(word1
);
2955 void r600_bytecode_export_read(struct r600_bytecode_output
*output
, uint32_t word0
, uint32_t word1
)
2957 output
->array_base
= G_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(word0
);
2958 output
->type
= G_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(word0
);
2959 output
->gpr
= G_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(word0
);
2960 output
->elem_size
= G_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(word0
);
2962 output
->swizzle_x
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(word1
);
2963 output
->swizzle_y
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(word1
);
2964 output
->swizzle_z
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(word1
);
2965 output
->swizzle_w
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(word1
);
2966 output
->burst_count
= G_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(word1
);
2967 output
->end_of_program
= G_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(word1
);
2968 output
->inst
= R600_S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(word1
));
2969 output
->barrier
= G_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(word1
);