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 alu_uses_rel(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
485 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
492 for (src
= 0; src
< num_src
; ++src
) {
493 if (alu
->src
[src
].rel
) {
500 static int is_opcode_in_range(unsigned opcode
, unsigned min
, unsigned max
)
502 return min
<= opcode
&& opcode
<= max
;
505 /* ALU instructions that can only execute on the vector unit:
509 * op3 : [0x08 - 0x0B]
510 * op2 : 0x07, [0x15 - 0x18], [0x1B - 0x1D], [0x50 - 0x53], [0x7A - 0x7E]
516 static int is_alu_vec_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
518 switch (bc
->chip_class
) {
522 return is_opcode_in_range(alu
->inst
,
523 V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_64
,
524 V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_64_D2
);
526 return (alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FREXP_64
) ||
527 is_opcode_in_range(alu
->inst
,
528 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA
,
529 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
) ||
530 is_opcode_in_range(alu
->inst
,
531 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_64
,
532 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT32_TO_FLT64
) ||
533 is_opcode_in_range(alu
->inst
,
534 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
,
535 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4
) ||
536 is_opcode_in_range(alu
->inst
,
537 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LDEXP_64
,
538 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_64
);
542 return is_opcode_in_range(alu
->inst
,
543 EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_BFE_UINT
,
544 EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_LDS_IDX_OP
);
546 return is_opcode_in_range(alu
->inst
,
547 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_BFM_INT
,
548 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_LOAD_P20
);
556 /* ALU instructions that can only execute on the trans unit:
565 * op2: [0x60 - 0x6F], [0x73 - 0x79]
571 static int is_alu_trans_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
574 switch (bc
->chip_class
) {
577 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
579 return is_opcode_in_range(alu
->inst
,
580 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
,
581 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
);
584 return alu
->inst
== V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
586 return is_opcode_in_range(alu
->inst
,
587 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
,
588 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
) ||
589 is_opcode_in_range(alu
->inst
,
590 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
,
591 V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
);
594 return alu
->inst
== EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
;
596 return is_opcode_in_range(alu
->inst
,
597 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
,
598 EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
);
606 /* alu instructions that can execute on any unit */
607 static int is_alu_any_unit_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
609 return !is_alu_vec_unit_inst(bc
, alu
) &&
610 !is_alu_trans_unit_inst(bc
, alu
);
613 static int is_nop_inst(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
)
615 switch (bc
->chip_class
) {
618 return (!alu
->is_op3
&& alu
->inst
== V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
);
622 return (!alu
->is_op3
&& alu
->inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
);
626 static int assign_alu_units(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu_first
,
627 struct r600_bytecode_alu
*assignment
[5])
629 struct r600_bytecode_alu
*alu
;
630 unsigned i
, chan
, trans
;
631 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
633 for (i
= 0; i
< max_slots
; i
++)
634 assignment
[i
] = NULL
;
636 for (alu
= alu_first
; alu
; alu
= LIST_ENTRY(struct r600_bytecode_alu
, alu
->list
.next
, list
)) {
637 chan
= alu
->dst
.chan
;
640 else if (is_alu_trans_unit_inst(bc
, alu
))
642 else if (is_alu_vec_unit_inst(bc
, alu
))
644 else if (assignment
[chan
])
645 trans
= 1; /* Assume ALU_INST_PREFER_VECTOR. */
651 assert(0); /* ALU.Trans has already been allocated. */
656 if (assignment
[chan
]) {
657 assert(0); /* ALU.chan has already been allocated. */
660 assignment
[chan
] = alu
;
669 struct alu_bank_swizzle
{
670 int hw_gpr
[NUM_OF_CYCLES
][NUM_OF_COMPONENTS
];
671 int hw_cfile_addr
[4];
672 int hw_cfile_elem
[4];
675 static const unsigned cycle_for_bank_swizzle_vec
[][3] = {
676 [SQ_ALU_VEC_012
] = { 0, 1, 2 },
677 [SQ_ALU_VEC_021
] = { 0, 2, 1 },
678 [SQ_ALU_VEC_120
] = { 1, 2, 0 },
679 [SQ_ALU_VEC_102
] = { 1, 0, 2 },
680 [SQ_ALU_VEC_201
] = { 2, 0, 1 },
681 [SQ_ALU_VEC_210
] = { 2, 1, 0 }
684 static const unsigned cycle_for_bank_swizzle_scl
[][3] = {
685 [SQ_ALU_SCL_210
] = { 2, 1, 0 },
686 [SQ_ALU_SCL_122
] = { 1, 2, 2 },
687 [SQ_ALU_SCL_212
] = { 2, 1, 2 },
688 [SQ_ALU_SCL_221
] = { 2, 2, 1 }
691 static void init_bank_swizzle(struct alu_bank_swizzle
*bs
)
693 int i
, cycle
, component
;
695 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
696 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
697 bs
->hw_gpr
[cycle
][component
] = -1;
698 for (i
= 0; i
< 4; i
++)
699 bs
->hw_cfile_addr
[i
] = -1;
700 for (i
= 0; i
< 4; i
++)
701 bs
->hw_cfile_elem
[i
] = -1;
704 static int reserve_gpr(struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
, unsigned cycle
)
706 if (bs
->hw_gpr
[cycle
][chan
] == -1)
707 bs
->hw_gpr
[cycle
][chan
] = sel
;
708 else if (bs
->hw_gpr
[cycle
][chan
] != (int)sel
) {
709 /* Another scalar operation has already used the GPR read port for the channel. */
715 static int reserve_cfile(struct r600_bytecode
*bc
, struct alu_bank_swizzle
*bs
, unsigned sel
, unsigned chan
)
717 int res
, num_res
= 4;
718 if (bc
->chip_class
>= R700
) {
722 for (res
= 0; res
< num_res
; ++res
) {
723 if (bs
->hw_cfile_addr
[res
] == -1) {
724 bs
->hw_cfile_addr
[res
] = sel
;
725 bs
->hw_cfile_elem
[res
] = chan
;
727 } else if (bs
->hw_cfile_addr
[res
] == sel
&&
728 bs
->hw_cfile_elem
[res
] == chan
)
729 return 0; /* Read for this scalar element already reserved, nothing to do here. */
731 /* All cfile read ports are used, cannot reference vector element. */
735 static int is_gpr(unsigned sel
)
737 return (sel
>= 0 && sel
<= 127);
740 /* CB constants start at 512, and get translated to a kcache index when ALU
741 * clauses are constructed. Note that we handle kcache constants the same way
742 * as (the now gone) cfile constants, is that really required? */
743 static int is_cfile(unsigned sel
)
745 return (sel
> 255 && sel
< 512) ||
746 (sel
> 511 && sel
< 4607) || /* Kcache before translation. */
747 (sel
> 127 && sel
< 192); /* Kcache after translation. */
750 static int is_const(int sel
)
752 return is_cfile(sel
) ||
753 (sel
>= V_SQ_ALU_SRC_0
&&
754 sel
<= V_SQ_ALU_SRC_LITERAL
);
757 static int check_vector(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
758 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
760 int r
, src
, num_src
, sel
, elem
, cycle
;
762 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
763 for (src
= 0; src
< num_src
; src
++) {
764 sel
= alu
->src
[src
].sel
;
765 elem
= alu
->src
[src
].chan
;
767 cycle
= cycle_for_bank_swizzle_vec
[bank_swizzle
][src
];
768 if (src
== 1 && sel
== alu
->src
[0].sel
&& elem
== alu
->src
[0].chan
)
769 /* Nothing to do; special-case optimization,
770 * second source uses first source’s reservation. */
773 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
777 } else if (is_cfile(sel
)) {
778 r
= reserve_cfile(bc
, bs
, (alu
->src
[src
].kc_bank
<<16) + sel
, elem
);
782 /* No restrictions on PV, PS, literal or special constants. */
787 static int check_scalar(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
788 struct alu_bank_swizzle
*bs
, int bank_swizzle
)
790 int r
, src
, num_src
, const_count
, sel
, elem
, cycle
;
792 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
793 for (const_count
= 0, src
= 0; src
< num_src
; ++src
) {
794 sel
= alu
->src
[src
].sel
;
795 elem
= alu
->src
[src
].chan
;
796 if (is_const(sel
)) { /* Any constant, including literal and inline constants. */
797 if (const_count
>= 2)
798 /* More than two references to a constant in
799 * transcendental operation. */
805 r
= reserve_cfile(bc
, bs
, (alu
->src
[src
].kc_bank
<<16) + sel
, elem
);
810 for (src
= 0; src
< num_src
; ++src
) {
811 sel
= alu
->src
[src
].sel
;
812 elem
= alu
->src
[src
].chan
;
814 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
815 if (cycle
< const_count
)
816 /* Cycle for GPR load conflicts with
817 * constant load in transcendental operation. */
819 r
= reserve_gpr(bs
, sel
, elem
, cycle
);
823 /* PV PS restrictions */
824 if (const_count
&& (sel
== 254 || sel
== 255)) {
825 cycle
= cycle_for_bank_swizzle_scl
[bank_swizzle
][src
];
826 if (cycle
< const_count
)
833 static int check_and_set_bank_swizzle(struct r600_bytecode
*bc
,
834 struct r600_bytecode_alu
*slots
[5])
836 struct alu_bank_swizzle bs
;
838 int i
, r
= 0, forced
= 1;
839 boolean scalar_only
= bc
->chip_class
== CAYMAN
? false : true;
840 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
842 for (i
= 0; i
< max_slots
; i
++) {
844 if (slots
[i
]->bank_swizzle_force
) {
845 slots
[i
]->bank_swizzle
= slots
[i
]->bank_swizzle_force
;
851 if (i
< 4 && slots
[i
])
857 /* Just check every possible combination of bank swizzle.
858 * Not very efficent, but works on the first try in most of the cases. */
859 for (i
= 0; i
< 4; i
++)
860 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
)
861 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
863 bank_swizzle
[i
] = slots
[i
]->bank_swizzle
;
865 bank_swizzle
[4] = SQ_ALU_SCL_210
;
866 while(bank_swizzle
[4] <= SQ_ALU_SCL_221
) {
868 if (max_slots
== 4) {
869 for (i
= 0; i
< max_slots
; i
++) {
870 if (bank_swizzle
[i
] == SQ_ALU_VEC_210
)
874 init_bank_swizzle(&bs
);
875 if (scalar_only
== false) {
876 for (i
= 0; i
< 4; i
++) {
878 r
= check_vector(bc
, slots
[i
], &bs
, bank_swizzle
[i
]);
886 if (!r
&& slots
[4] && max_slots
== 5) {
887 r
= check_scalar(bc
, slots
[4], &bs
, bank_swizzle
[4]);
890 for (i
= 0; i
< max_slots
; i
++) {
892 slots
[i
]->bank_swizzle
= bank_swizzle
[i
];
900 for (i
= 0; i
< max_slots
; i
++) {
901 if (!slots
[i
] || !slots
[i
]->bank_swizzle_force
) {
903 if (bank_swizzle
[i
] <= SQ_ALU_VEC_210
)
906 bank_swizzle
[i
] = SQ_ALU_VEC_012
;
912 /* Couldn't find a working swizzle. */
916 static int replace_gpr_with_pv_ps(struct r600_bytecode
*bc
,
917 struct r600_bytecode_alu
*slots
[5], struct r600_bytecode_alu
*alu_prev
)
919 struct r600_bytecode_alu
*prev
[5];
921 int i
, j
, r
, src
, num_src
;
922 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
924 r
= assign_alu_units(bc
, alu_prev
, prev
);
928 for (i
= 0; i
< max_slots
; ++i
) {
929 if (prev
[i
] && (prev
[i
]->dst
.write
|| prev
[i
]->is_op3
) && !prev
[i
]->dst
.rel
) {
930 gpr
[i
] = prev
[i
]->dst
.sel
;
931 /* cube writes more than PV.X */
932 if (!is_alu_cube_inst(bc
, prev
[i
]) && is_alu_reduction_inst(bc
, prev
[i
]))
935 chan
[i
] = prev
[i
]->dst
.chan
;
940 for (i
= 0; i
< max_slots
; ++i
) {
941 struct r600_bytecode_alu
*alu
= slots
[i
];
945 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
946 for (src
= 0; src
< num_src
; ++src
) {
947 if (!is_gpr(alu
->src
[src
].sel
) || alu
->src
[src
].rel
)
950 if (bc
->chip_class
< CAYMAN
) {
951 if (alu
->src
[src
].sel
== gpr
[4] &&
952 alu
->src
[src
].chan
== chan
[4] &&
953 alu_prev
->pred_sel
== alu
->pred_sel
) {
954 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PS
;
955 alu
->src
[src
].chan
= 0;
960 for (j
= 0; j
< 4; ++j
) {
961 if (alu
->src
[src
].sel
== gpr
[j
] &&
962 alu
->src
[src
].chan
== j
&&
963 alu_prev
->pred_sel
== alu
->pred_sel
) {
964 alu
->src
[src
].sel
= V_SQ_ALU_SRC_PV
;
965 alu
->src
[src
].chan
= chan
[j
];
975 void r600_bytecode_special_constants(uint32_t value
, unsigned *sel
, unsigned *neg
)
979 *sel
= V_SQ_ALU_SRC_0
;
982 *sel
= V_SQ_ALU_SRC_1_INT
;
985 *sel
= V_SQ_ALU_SRC_M_1_INT
;
987 case 0x3F800000: /* 1.0f */
988 *sel
= V_SQ_ALU_SRC_1
;
990 case 0x3F000000: /* 0.5f */
991 *sel
= V_SQ_ALU_SRC_0_5
;
993 case 0xBF800000: /* -1.0f */
994 *sel
= V_SQ_ALU_SRC_1
;
997 case 0xBF000000: /* -0.5f */
998 *sel
= V_SQ_ALU_SRC_0_5
;
1002 *sel
= V_SQ_ALU_SRC_LITERAL
;
1007 /* compute how many literal are needed */
1008 static int r600_bytecode_alu_nliterals(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
,
1009 uint32_t literal
[4], unsigned *nliteral
)
1011 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
1014 for (i
= 0; i
< num_src
; ++i
) {
1015 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1016 uint32_t value
= alu
->src
[i
].value
;
1018 for (j
= 0; j
< *nliteral
; ++j
) {
1019 if (literal
[j
] == value
) {
1027 literal
[(*nliteral
)++] = value
;
1034 static void r600_bytecode_alu_adjust_literals(struct r600_bytecode
*bc
,
1035 struct r600_bytecode_alu
*alu
,
1036 uint32_t literal
[4], unsigned nliteral
)
1038 unsigned num_src
= r600_bytecode_get_num_operands(bc
, alu
);
1041 for (i
= 0; i
< num_src
; ++i
) {
1042 if (alu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1043 uint32_t value
= alu
->src
[i
].value
;
1044 for (j
= 0; j
< nliteral
; ++j
) {
1045 if (literal
[j
] == value
) {
1046 alu
->src
[i
].chan
= j
;
1054 static int merge_inst_groups(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*slots
[5],
1055 struct r600_bytecode_alu
*alu_prev
)
1057 struct r600_bytecode_alu
*prev
[5];
1058 struct r600_bytecode_alu
*result
[5] = { NULL
};
1060 uint32_t literal
[4], prev_literal
[4];
1061 unsigned nliteral
= 0, prev_nliteral
= 0;
1063 int i
, j
, r
, src
, num_src
;
1064 int num_once_inst
= 0;
1065 int have_mova
= 0, have_rel
= 0;
1066 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
1068 r
= assign_alu_units(bc
, alu_prev
, prev
);
1072 for (i
= 0; i
< max_slots
; ++i
) {
1074 if (prev
[i
]->pred_sel
)
1076 if (is_alu_once_inst(bc
, prev
[i
]))
1080 if (slots
[i
]->pred_sel
)
1082 if (is_alu_once_inst(bc
, slots
[i
]))
1087 for (i
= 0; i
< max_slots
; ++i
) {
1088 struct r600_bytecode_alu
*alu
;
1090 if (num_once_inst
> 0)
1093 /* check number of literals */
1095 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], literal
, &nliteral
))
1097 if (r600_bytecode_alu_nliterals(bc
, prev
[i
], prev_literal
, &prev_nliteral
))
1099 if (is_alu_mova_inst(bc
, prev
[i
])) {
1105 if (alu_uses_rel(bc
, prev
[i
])) {
1112 num_once_inst
+= is_alu_once_inst(bc
, prev
[i
]);
1114 if (slots
[i
] && r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
))
1117 /* Let's check used slots. */
1118 if (prev
[i
] && !slots
[i
]) {
1119 result
[i
] = prev
[i
];
1121 } else if (prev
[i
] && slots
[i
]) {
1122 if (max_slots
== 5 && result
[4] == NULL
&& prev
[4] == NULL
&& slots
[4] == NULL
) {
1123 /* Trans unit is still free try to use it. */
1124 if (is_alu_any_unit_inst(bc
, slots
[i
])) {
1125 result
[i
] = prev
[i
];
1126 result
[4] = slots
[i
];
1127 } else if (is_alu_any_unit_inst(bc
, prev
[i
])) {
1128 if (slots
[i
]->dst
.sel
== prev
[i
]->dst
.sel
&&
1129 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
1130 (prev
[i
]->dst
.write
== 1 || prev
[i
]->is_op3
))
1133 result
[i
] = slots
[i
];
1134 result
[4] = prev
[i
];
1139 } else if(!slots
[i
]) {
1142 if (max_slots
== 5 && slots
[i
] && prev
[4] &&
1143 slots
[i
]->dst
.sel
== prev
[4]->dst
.sel
&&
1144 slots
[i
]->dst
.chan
== prev
[4]->dst
.chan
&&
1145 (slots
[i
]->dst
.write
== 1 || slots
[i
]->is_op3
) &&
1146 (prev
[4]->dst
.write
== 1 || prev
[4]->is_op3
))
1149 result
[i
] = slots
[i
];
1153 num_once_inst
+= is_alu_once_inst(bc
, alu
);
1155 /* don't reschedule NOPs */
1156 if (is_nop_inst(bc
, alu
))
1159 if (is_alu_mova_inst(bc
, alu
)) {
1166 if (alu_uses_rel(bc
, alu
)) {
1173 /* Let's check source gprs */
1174 num_src
= r600_bytecode_get_num_operands(bc
, alu
);
1175 for (src
= 0; src
< num_src
; ++src
) {
1177 /* Constants don't matter. */
1178 if (!is_gpr(alu
->src
[src
].sel
))
1181 for (j
= 0; j
< max_slots
; ++j
) {
1182 if (!prev
[j
] || !(prev
[j
]->dst
.write
|| prev
[j
]->is_op3
))
1185 /* If it's relative then we can't determin which gpr is really used. */
1186 if (prev
[j
]->dst
.chan
== alu
->src
[src
].chan
&&
1187 (prev
[j
]->dst
.sel
== alu
->src
[src
].sel
||
1188 prev
[j
]->dst
.rel
|| alu
->src
[src
].rel
))
1194 /* more than one PRED_ or KILL_ ? */
1195 if (num_once_inst
> 1)
1198 /* check if the result can still be swizzlet */
1199 r
= check_and_set_bank_swizzle(bc
, result
);
1203 /* looks like everything worked out right, apply the changes */
1205 /* undo adding previus literals */
1206 bc
->cf_last
->ndw
-= align(prev_nliteral
, 2);
1208 /* sort instructions */
1209 for (i
= 0; i
< max_slots
; ++i
) {
1210 slots
[i
] = result
[i
];
1212 LIST_DEL(&result
[i
]->list
);
1213 result
[i
]->last
= 0;
1214 LIST_ADDTAIL(&result
[i
]->list
, &bc
->cf_last
->alu
);
1218 /* determine new last instruction */
1219 LIST_ENTRY(struct r600_bytecode_alu
, bc
->cf_last
->alu
.prev
, list
)->last
= 1;
1221 /* determine new first instruction */
1222 for (i
= 0; i
< max_slots
; ++i
) {
1224 bc
->cf_last
->curr_bs_head
= result
[i
];
1229 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->prev2_bs_head
;
1230 bc
->cf_last
->prev2_bs_head
= NULL
;
1235 /* we'll keep kcache sets sorted by bank & addr */
1236 static int r600_bytecode_alloc_kcache_line(struct r600_bytecode
*bc
,
1237 struct r600_bytecode_kcache
*kcache
,
1238 unsigned bank
, unsigned line
)
1240 int i
, kcache_banks
= bc
->chip_class
>= EVERGREEN
? 4 : 2;
1242 for (i
= 0; i
< kcache_banks
; i
++) {
1243 if (kcache
[i
].mode
) {
1246 if (kcache
[i
].bank
< bank
)
1249 if ((kcache
[i
].bank
== bank
&& kcache
[i
].addr
> line
+1) ||
1250 kcache
[i
].bank
> bank
) {
1251 /* try to insert new line */
1252 if (kcache
[kcache_banks
-1].mode
) {
1253 /* all sets are in use */
1257 memmove(&kcache
[i
+1],&kcache
[i
], (kcache_banks
-i
-1)*sizeof(struct r600_bytecode_kcache
));
1258 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_1
;
1259 kcache
[i
].bank
= bank
;
1260 kcache
[i
].addr
= line
;
1264 d
= line
- kcache
[i
].addr
;
1268 if (kcache
[i
].mode
== V_SQ_CF_KCACHE_LOCK_2
) {
1269 /* we are prepending the line to the current set,
1270 * discarding the existing second line,
1271 * so we'll have to insert line+2 after it */
1274 } else if (kcache
[i
].mode
== V_SQ_CF_KCACHE_LOCK_1
) {
1275 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
1278 /* V_SQ_CF_KCACHE_LOCK_LOOP_INDEX is not supported */
1281 } else if (d
== 1) {
1282 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_2
;
1286 } else { /* free kcache set - use it */
1287 kcache
[i
].mode
= V_SQ_CF_KCACHE_LOCK_1
;
1288 kcache
[i
].bank
= bank
;
1289 kcache
[i
].addr
= line
;
1296 static int r600_bytecode_alloc_inst_kcache_lines(struct r600_bytecode
*bc
,
1297 struct r600_bytecode_kcache
*kcache
,
1298 struct r600_bytecode_alu
*alu
)
1302 for (i
= 0; i
< 3; i
++) {
1303 unsigned bank
, line
, sel
= alu
->src
[i
].sel
;
1308 bank
= alu
->src
[i
].kc_bank
;
1309 line
= (sel
-512)>>4;
1311 if ((r
= r600_bytecode_alloc_kcache_line(bc
, kcache
, bank
, line
)))
1317 static int r600_bytecode_assign_kcache_banks(struct r600_bytecode
*bc
,
1318 struct r600_bytecode_alu
*alu
,
1319 struct r600_bytecode_kcache
* kcache
)
1323 /* Alter the src operands to refer to the kcache. */
1324 for (i
= 0; i
< 3; ++i
) {
1325 static const unsigned int base
[] = {128, 160, 256, 288};
1326 unsigned int line
, sel
= alu
->src
[i
].sel
, found
= 0;
1334 for (j
= 0; j
< 4 && !found
; ++j
) {
1335 switch (kcache
[j
].mode
) {
1336 case V_SQ_CF_KCACHE_NOP
:
1337 case V_SQ_CF_KCACHE_LOCK_LOOP_INDEX
:
1338 R600_ERR("unexpected kcache line mode\n");
1341 if (kcache
[j
].bank
== alu
->src
[i
].kc_bank
&&
1342 kcache
[j
].addr
<= line
&&
1343 line
< kcache
[j
].addr
+ kcache
[j
].mode
) {
1344 alu
->src
[i
].sel
= sel
- (kcache
[j
].addr
<<4);
1345 alu
->src
[i
].sel
+= base
[j
];
1354 static int r600_bytecode_alloc_kcache_lines(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, int type
)
1356 struct r600_bytecode_kcache kcache_sets
[4];
1357 struct r600_bytecode_kcache
*kcache
= kcache_sets
;
1360 memcpy(kcache
, bc
->cf_last
->kcache
, 4 * sizeof(struct r600_bytecode_kcache
));
1362 if ((r
= r600_bytecode_alloc_inst_kcache_lines(bc
, kcache
, alu
))) {
1363 /* can't alloc, need to start new clause */
1364 if ((r
= r600_bytecode_add_cf(bc
))) {
1367 bc
->cf_last
->inst
= type
;
1369 /* retry with the new clause */
1370 kcache
= bc
->cf_last
->kcache
;
1371 if ((r
= r600_bytecode_alloc_inst_kcache_lines(bc
, kcache
, alu
))) {
1372 /* can't alloc again- should never happen */
1376 /* update kcache sets */
1377 memcpy(bc
->cf_last
->kcache
, kcache
, 4 * sizeof(struct r600_bytecode_kcache
));
1380 /* if we actually used more than 2 kcache sets - use ALU_EXTENDED on eg+ */
1381 if (kcache
[2].mode
!= V_SQ_CF_KCACHE_NOP
) {
1382 if (bc
->chip_class
< EVERGREEN
)
1384 bc
->cf_last
->eg_alu_extended
= 1;
1390 static int insert_nop_r6xx(struct r600_bytecode
*bc
)
1392 struct r600_bytecode_alu alu
;
1395 for (i
= 0; i
< 4; i
++) {
1396 memset(&alu
, 0, sizeof(alu
));
1397 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
;
1398 alu
.src
[0].chan
= i
;
1400 alu
.last
= (i
== 3);
1401 r
= r600_bytecode_add_alu(bc
, &alu
);
1408 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
1409 static int load_ar_r6xx(struct r600_bytecode
*bc
)
1411 struct r600_bytecode_alu alu
;
1417 /* hack to avoid making MOVA the last instruction in the clause */
1418 if ((bc
->cf_last
->ndw
>>1) >= 110)
1419 bc
->force_add_cf
= 1;
1421 memset(&alu
, 0, sizeof(alu
));
1422 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT
;
1423 alu
.src
[0].sel
= bc
->ar_reg
;
1424 alu
.src
[0].chan
= bc
->ar_chan
;
1426 alu
.index_mode
= INDEX_MODE_LOOP
;
1427 r
= r600_bytecode_add_alu(bc
, &alu
);
1431 /* no requirement to set uses waterfall on MOVA_GPR_INT */
1436 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
1437 static int load_ar(struct r600_bytecode
*bc
)
1439 struct r600_bytecode_alu alu
;
1442 if (bc
->ar_handling
)
1443 return load_ar_r6xx(bc
);
1448 /* hack to avoid making MOVA the last instruction in the clause */
1449 if ((bc
->cf_last
->ndw
>>1) >= 110)
1450 bc
->force_add_cf
= 1;
1452 memset(&alu
, 0, sizeof(alu
));
1453 alu
.inst
= BC_INST(bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
);
1454 alu
.src
[0].sel
= bc
->ar_reg
;
1455 alu
.src
[0].chan
= bc
->ar_chan
;
1457 r
= r600_bytecode_add_alu(bc
, &alu
);
1461 bc
->cf_last
->r6xx_uses_waterfall
= 1;
1466 int r600_bytecode_add_alu_type(struct r600_bytecode
*bc
, const struct r600_bytecode_alu
*alu
, int type
)
1468 struct r600_bytecode_alu
*nalu
= r600_bytecode_alu();
1469 struct r600_bytecode_alu
*lalu
;
1474 memcpy(nalu
, alu
, sizeof(struct r600_bytecode_alu
));
1476 if (bc
->cf_last
!= NULL
&& bc
->cf_last
->inst
!= type
) {
1477 /* check if we could add it anyway */
1478 if (bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
) &&
1479 type
== BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
)) {
1480 LIST_FOR_EACH_ENTRY(lalu
, &bc
->cf_last
->alu
, list
) {
1481 if (lalu
->execute_mask
) {
1482 bc
->force_add_cf
= 1;
1487 bc
->force_add_cf
= 1;
1490 /* cf can contains only alu or only vtx or only tex */
1491 if (bc
->cf_last
== NULL
|| bc
->force_add_cf
) {
1492 r
= r600_bytecode_add_cf(bc
);
1498 bc
->cf_last
->inst
= type
;
1500 /* Check AR usage and load it if required */
1501 for (i
= 0; i
< 3; i
++)
1502 if (nalu
->src
[i
].rel
&& !bc
->ar_loaded
)
1505 if (nalu
->dst
.rel
&& !bc
->ar_loaded
)
1508 /* Setup the kcache for this ALU instruction. This will start a new
1509 * ALU clause if needed. */
1510 if ((r
= r600_bytecode_alloc_kcache_lines(bc
, nalu
, type
))) {
1515 if (!bc
->cf_last
->curr_bs_head
) {
1516 bc
->cf_last
->curr_bs_head
= nalu
;
1518 /* number of gpr == the last gpr used in any alu */
1519 for (i
= 0; i
< 3; i
++) {
1520 if (nalu
->src
[i
].sel
>= bc
->ngpr
&& nalu
->src
[i
].sel
< 128) {
1521 bc
->ngpr
= nalu
->src
[i
].sel
+ 1;
1523 if (nalu
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
)
1524 r600_bytecode_special_constants(nalu
->src
[i
].value
,
1525 &nalu
->src
[i
].sel
, &nalu
->src
[i
].neg
);
1527 if (nalu
->dst
.sel
>= bc
->ngpr
) {
1528 bc
->ngpr
= nalu
->dst
.sel
+ 1;
1530 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
1531 /* each alu use 2 dwords */
1532 bc
->cf_last
->ndw
+= 2;
1535 /* process cur ALU instructions for bank swizzle */
1537 uint32_t literal
[4];
1539 struct r600_bytecode_alu
*slots
[5];
1540 int max_slots
= bc
->chip_class
== CAYMAN
? 4 : 5;
1541 r
= assign_alu_units(bc
, bc
->cf_last
->curr_bs_head
, slots
);
1545 if (bc
->cf_last
->prev_bs_head
) {
1546 r
= merge_inst_groups(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1551 if (bc
->cf_last
->prev_bs_head
) {
1552 r
= replace_gpr_with_pv_ps(bc
, slots
, bc
->cf_last
->prev_bs_head
);
1557 r
= check_and_set_bank_swizzle(bc
, slots
);
1561 for (i
= 0, nliteral
= 0; i
< max_slots
; i
++) {
1563 r
= r600_bytecode_alu_nliterals(bc
, slots
[i
], literal
, &nliteral
);
1568 bc
->cf_last
->ndw
+= align(nliteral
, 2);
1570 /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots)
1572 if ((bc
->cf_last
->ndw
>> 1) >= 120) {
1573 bc
->force_add_cf
= 1;
1576 bc
->cf_last
->prev2_bs_head
= bc
->cf_last
->prev_bs_head
;
1577 bc
->cf_last
->prev_bs_head
= bc
->cf_last
->curr_bs_head
;
1578 bc
->cf_last
->curr_bs_head
= NULL
;
1581 if (nalu
->dst
.rel
&& bc
->r6xx_nop_after_rel_dst
)
1582 insert_nop_r6xx(bc
);
1587 int r600_bytecode_add_alu(struct r600_bytecode
*bc
, const struct r600_bytecode_alu
*alu
)
1589 return r600_bytecode_add_alu_type(bc
, alu
, BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
));
1592 static unsigned r600_bytecode_num_tex_and_vtx_instructions(const struct r600_bytecode
*bc
)
1594 switch (bc
->chip_class
) {
1604 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1609 static inline boolean
last_inst_was_not_vtx_fetch(struct r600_bytecode
*bc
)
1611 switch (bc
->chip_class
) {
1614 return bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
1615 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
;
1617 return bc
->cf_last
->inst
!= EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1619 return bc
->cf_last
->inst
!= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
;
1621 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1626 int r600_bytecode_add_vtx(struct r600_bytecode
*bc
, const struct r600_bytecode_vtx
*vtx
)
1628 struct r600_bytecode_vtx
*nvtx
= r600_bytecode_vtx();
1633 memcpy(nvtx
, vtx
, sizeof(struct r600_bytecode_vtx
));
1635 /* cf can contains only alu or only vtx or only tex */
1636 if (bc
->cf_last
== NULL
||
1637 last_inst_was_not_vtx_fetch(bc
) ||
1639 r
= r600_bytecode_add_cf(bc
);
1644 switch (bc
->chip_class
) {
1647 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1650 bc
->cf_last
->inst
= EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
1653 bc
->cf_last
->inst
= CM_V_SQ_CF_WORD1_SQ_CF_INST_TC
;
1656 R600_ERR("Unknown chip class %d.\n", bc
->chip_class
);
1661 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
1662 /* each fetch use 4 dwords */
1663 bc
->cf_last
->ndw
+= 4;
1665 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1666 bc
->force_add_cf
= 1;
1668 bc
->ngpr
= MAX2(bc
->ngpr
, vtx
->src_gpr
+ 1);
1669 bc
->ngpr
= MAX2(bc
->ngpr
, vtx
->dst_gpr
+ 1);
1674 int r600_bytecode_add_tex(struct r600_bytecode
*bc
, const struct r600_bytecode_tex
*tex
)
1676 struct r600_bytecode_tex
*ntex
= r600_bytecode_tex();
1681 memcpy(ntex
, tex
, sizeof(struct r600_bytecode_tex
));
1683 /* we can't fetch data und use it as texture lookup address in the same TEX clause */
1684 if (bc
->cf_last
!= NULL
&&
1685 bc
->cf_last
->inst
== BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
)) {
1686 struct r600_bytecode_tex
*ttex
;
1687 LIST_FOR_EACH_ENTRY(ttex
, &bc
->cf_last
->tex
, list
) {
1688 if (ttex
->dst_gpr
== ntex
->src_gpr
) {
1689 bc
->force_add_cf
= 1;
1693 /* slight hack to make gradients always go into same cf */
1694 if (ntex
->inst
== SQ_TEX_INST_SET_GRADIENTS_H
)
1695 bc
->force_add_cf
= 1;
1698 /* cf can contains only alu or only vtx or only tex */
1699 if (bc
->cf_last
== NULL
||
1700 bc
->cf_last
->inst
!= BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
) ||
1702 r
= r600_bytecode_add_cf(bc
);
1707 bc
->cf_last
->inst
= BC_INST(bc
, V_SQ_CF_WORD1_SQ_CF_INST_TEX
);
1709 if (ntex
->src_gpr
>= bc
->ngpr
) {
1710 bc
->ngpr
= ntex
->src_gpr
+ 1;
1712 if (ntex
->dst_gpr
>= bc
->ngpr
) {
1713 bc
->ngpr
= ntex
->dst_gpr
+ 1;
1715 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
1716 /* each texture fetch use 4 dwords */
1717 bc
->cf_last
->ndw
+= 4;
1719 if ((bc
->cf_last
->ndw
/ 4) >= r600_bytecode_num_tex_and_vtx_instructions(bc
))
1720 bc
->force_add_cf
= 1;
1724 int r600_bytecode_add_cfinst(struct r600_bytecode
*bc
, int inst
)
1727 r
= r600_bytecode_add_cf(bc
);
1731 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
1732 bc
->cf_last
->inst
= inst
;
1736 int cm_bytecode_add_cf_end(struct r600_bytecode
*bc
)
1738 return r600_bytecode_add_cfinst(bc
, CM_V_SQ_CF_WORD1_SQ_CF_INST_END
);
1741 /* common to all 3 families */
1742 static int r600_bytecode_vtx_build(struct r600_bytecode
*bc
, struct r600_bytecode_vtx
*vtx
, unsigned id
)
1744 bc
->bytecode
[id
] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
) |
1745 S_SQ_VTX_WORD0_FETCH_TYPE(vtx
->fetch_type
) |
1746 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
1747 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
);
1748 if (bc
->chip_class
< CAYMAN
)
1749 bc
->bytecode
[id
] |= S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
1751 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
1752 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
1753 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
1754 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
1755 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
1756 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
1757 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
1758 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
1759 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
1760 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
1761 bc
->bytecode
[id
] = S_SQ_VTX_WORD2_OFFSET(vtx
->offset
)|
1762 S_SQ_VTX_WORD2_ENDIAN_SWAP(vtx
->endian
);
1763 if (bc
->chip_class
< CAYMAN
)
1764 bc
->bytecode
[id
] |= S_SQ_VTX_WORD2_MEGA_FETCH(1);
1766 bc
->bytecode
[id
++] = 0;
1770 /* common to all 3 families */
1771 static int r600_bytecode_tex_build(struct r600_bytecode
*bc
, struct r600_bytecode_tex
*tex
, unsigned id
)
1773 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
1774 EG_S_SQ_TEX_WORD0_INST_MOD(tex
->inst_mod
) |
1775 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
1776 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
1777 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
1778 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
1779 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
1780 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
1781 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
1782 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
1783 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
1784 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
1785 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
1786 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
1787 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
1788 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
1789 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
1790 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
1791 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
1792 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
1793 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
1794 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
1795 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
1796 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
1797 bc
->bytecode
[id
++] = 0;
1801 /* r600 only, r700/eg bits in r700_asm.c */
1802 static int r600_bytecode_alu_build(struct r600_bytecode
*bc
, struct r600_bytecode_alu
*alu
, unsigned id
)
1804 /* don't replace gpr by pv or ps for destination register */
1805 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
1806 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
1807 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
1808 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
1809 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
1810 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
1811 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
1812 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
1813 S_SQ_ALU_WORD0_INDEX_MODE(alu
->index_mode
) |
1814 S_SQ_ALU_WORD0_PRED_SEL(alu
->pred_sel
) |
1815 S_SQ_ALU_WORD0_LAST(alu
->last
);
1818 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1819 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1820 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1821 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1822 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
1823 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
1824 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
1825 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
1826 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
1827 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
1829 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
1830 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
1831 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
1832 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
1833 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
1834 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
1835 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
1836 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
1837 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
1838 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
1839 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->execute_mask
) |
1840 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->update_pred
);
1845 static void r600_bytecode_cf_vtx_build(uint32_t *bytecode
, const struct r600_bytecode_cf
*cf
)
1847 *bytecode
++ = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
1848 *bytecode
++ = cf
->inst
|
1849 S_SQ_CF_WORD1_BARRIER(1) |
1850 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
1853 /* common for r600/r700 - eg in eg_asm.c */
1854 static int r600_bytecode_cf_build(struct r600_bytecode
*bc
, struct r600_bytecode_cf
*cf
)
1856 unsigned id
= cf
->id
;
1859 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1860 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1861 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1862 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1863 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
1864 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache
[0].mode
) |
1865 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache
[0].bank
) |
1866 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache
[1].bank
);
1868 bc
->bytecode
[id
++] = cf
->inst
|
1869 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache
[1].mode
) |
1870 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache
[0].addr
) |
1871 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache
[1].addr
) |
1872 S_SQ_CF_ALU_WORD1_BARRIER(1) |
1873 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chip_class
== R600
? cf
->r6xx_uses_waterfall
: 0) |
1874 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
1876 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1877 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1878 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
1879 if (bc
->chip_class
== R700
)
1880 r700_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1882 r600_bytecode_cf_vtx_build(&bc
->bytecode
[id
], cf
);
1884 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1885 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1886 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1887 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1888 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1889 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1890 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1891 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
1892 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
1893 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
1894 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
1895 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1897 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
1899 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
1900 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
1901 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
1902 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
1903 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
1904 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
1905 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
1906 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
1907 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf
->output
.burst_count
- 1) |
1908 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
1910 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
) |
1911 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(cf
->output
.array_size
) |
1912 S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(cf
->output
.comp_mask
);
1914 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1915 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1916 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1917 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1918 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
1919 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1920 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1921 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1922 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1923 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1924 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
1925 bc
->bytecode
[id
++] = cf
->inst
|
1926 S_SQ_CF_WORD1_BARRIER(1) |
1927 S_SQ_CF_WORD1_COND(cf
->cond
) |
1928 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
1932 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
1938 int r600_bytecode_build(struct r600_bytecode
*bc
)
1940 struct r600_bytecode_cf
*cf
;
1941 struct r600_bytecode_alu
*alu
;
1942 struct r600_bytecode_vtx
*vtx
;
1943 struct r600_bytecode_tex
*tex
;
1944 uint32_t literal
[4];
1949 if (bc
->callstack
[0].max
> 0)
1950 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
1951 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
1955 /* first path compute addr of each CF block */
1956 /* addr start after all the CF instructions */
1957 addr
= bc
->cf_last
->id
+ 2;
1958 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
1959 if (bc
->chip_class
>= EVERGREEN
) {
1961 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
1962 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
1963 /* fetch node need to be 16 bytes aligned*/
1965 addr
&= 0xFFFFFFFCUL
;
1967 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
1968 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
1969 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
1970 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
1971 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
1972 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
1973 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
1974 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
1975 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
1976 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
1977 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
1978 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
1979 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
1980 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
1981 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
1982 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
1983 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
1984 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
1985 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
1986 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
1987 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
1988 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
1989 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
1990 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
1991 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
1992 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
1993 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
1994 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
1995 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
1996 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
1997 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
1998 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
1999 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
2003 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2008 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2009 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2010 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
2011 /* fetch node need to be 16 bytes aligned*/
2013 addr
&= 0xFFFFFFFCUL
;
2015 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2016 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2017 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2018 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2019 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2020 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2021 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
2022 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
2023 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
2024 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
2025 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2026 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2027 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2028 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2029 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2030 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2031 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2032 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2033 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2036 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2042 bc
->ndw
= cf
->addr
+ cf
->ndw
;
2045 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
2046 if (bc
->bytecode
== NULL
)
2048 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
2050 if (bc
->chip_class
>= EVERGREEN
) {
2051 r
= eg_bytecode_cf_build(bc
, cf
);
2056 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2057 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2058 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2059 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2061 memset(literal
, 0, sizeof(literal
));
2062 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
2063 r
= r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
2066 r600_bytecode_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
2067 r600_bytecode_assign_kcache_banks(bc
, alu
, cf
->kcache
);
2069 switch(bc
->chip_class
) {
2070 case EVERGREEN
: /* eg alu is same encoding as r700 */
2072 r
= r700_bytecode_alu_build(bc
, alu
, addr
);
2075 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
2082 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
2083 bc
->bytecode
[addr
++] = literal
[i
];
2086 memset(literal
, 0, sizeof(literal
));
2090 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2091 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2092 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
2098 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2099 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2100 assert(bc
->chip_class
>= EVERGREEN
);
2101 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
2106 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
2107 r
= r600_bytecode_tex_build(bc
, tex
, addr
);
2113 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2114 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2115 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
2116 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
2117 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
2118 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
2119 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
2120 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
2121 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
2122 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
2123 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
2124 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
2125 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
2126 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
2127 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
2128 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
2129 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
2130 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
2131 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2132 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2133 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2134 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2135 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2136 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2137 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2138 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2139 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2140 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2141 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
2146 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2150 r
= r600_bytecode_cf_build(bc
, cf
);
2155 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2156 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2157 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2158 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2160 memset(literal
, 0, sizeof(literal
));
2161 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
2162 r
= r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
2165 r600_bytecode_alu_adjust_literals(bc
, alu
, literal
, nliteral
);
2166 r600_bytecode_assign_kcache_banks(bc
, alu
, cf
->kcache
);
2168 switch(bc
->chip_class
) {
2170 r
= r600_bytecode_alu_build(bc
, alu
, addr
);
2173 r
= r700_bytecode_alu_build(bc
, alu
, addr
);
2176 R600_ERR("unknown chip class %d.\n", bc
->chip_class
);
2183 for (i
= 0; i
< align(nliteral
, 2); ++i
) {
2184 bc
->bytecode
[addr
++] = literal
[i
];
2187 memset(literal
, 0, sizeof(literal
));
2191 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2192 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
2193 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2194 r
= r600_bytecode_vtx_build(bc
, vtx
, addr
);
2200 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2201 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
2202 r
= r600_bytecode_tex_build(bc
, tex
, addr
);
2208 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2209 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2210 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
2211 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
2212 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
2213 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
2214 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2215 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2216 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2217 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2218 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2219 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2220 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2221 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2222 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2223 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2226 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
2234 void r600_bytecode_clear(struct r600_bytecode
*bc
)
2236 struct r600_bytecode_cf
*cf
= NULL
, *next_cf
;
2239 bc
->bytecode
= NULL
;
2241 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
2242 struct r600_bytecode_alu
*alu
= NULL
, *next_alu
;
2243 struct r600_bytecode_tex
*tex
= NULL
, *next_tex
;
2244 struct r600_bytecode_tex
*vtx
= NULL
, *next_vtx
;
2246 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
2250 LIST_INITHEAD(&cf
->alu
);
2252 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
2256 LIST_INITHEAD(&cf
->tex
);
2258 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
2262 LIST_INITHEAD(&cf
->vtx
);
2267 LIST_INITHEAD(&cf
->list
);
2270 void r600_bytecode_dump(struct r600_bytecode
*bc
)
2272 struct r600_bytecode_cf
*cf
= NULL
;
2273 struct r600_bytecode_alu
*alu
= NULL
;
2274 struct r600_bytecode_vtx
*vtx
= NULL
;
2275 struct r600_bytecode_tex
*tex
= NULL
;
2278 uint32_t literal
[4];
2282 switch (bc
->chip_class
) {
2297 fprintf(stderr
, "bytecode %d dw -- %d gprs ---------------------\n", bc
->ndw
, bc
->ngpr
);
2298 fprintf(stderr
, " %c\n", chip
);
2300 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
2303 if (bc
->chip_class
>= EVERGREEN
) {
2305 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2306 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2307 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2308 case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2309 if (cf
->eg_alu_extended
) {
2310 fprintf(stderr
, "%04d %08X ALU_EXT0 ", id
, bc
->bytecode
[id
]);
2311 fprintf(stderr
, "KCACHE_BANK2:%X ", cf
->kcache
[2].bank
);
2312 fprintf(stderr
, "KCACHE_BANK3:%X ", cf
->kcache
[3].bank
);
2313 fprintf(stderr
, "KCACHE_MODE2:%X\n", cf
->kcache
[2].mode
);
2315 fprintf(stderr
, "%04d %08X ALU_EXT1 ", id
, bc
->bytecode
[id
]);
2316 fprintf(stderr
, "KCACHE_MODE3:%X ", cf
->kcache
[3].mode
);
2317 fprintf(stderr
, "KCACHE_ADDR2:%X ", cf
->kcache
[2].addr
);
2318 fprintf(stderr
, "KCACHE_ADDR3:%X\n", cf
->kcache
[3].addr
);
2322 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2323 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
2324 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
2325 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
2326 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
2328 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2329 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
));
2330 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
2331 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
2332 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
2333 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
2335 case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2336 case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2337 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2338 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
2340 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2341 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2342 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
2344 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2345 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2346 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2347 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2348 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
2349 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
2350 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2352 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2353 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
2354 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
2355 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
2356 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
2357 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2358 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
));
2359 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2360 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2362 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
:
2363 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
:
2364 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
:
2365 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
:
2366 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0
:
2367 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1
:
2368 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2
:
2369 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3
:
2370 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0
:
2371 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1
:
2372 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2
:
2373 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3
:
2374 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0
:
2375 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1
:
2376 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2
:
2377 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3
:
2378 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i_BUF%i ", id
, bc
->bytecode
[id
],
2379 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2380 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) / 4,
2381 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2382 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) % 4);
2383 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2384 fprintf(stderr
, "ELEM_SIZE:%i ", cf
->output
.elem_size
);
2385 fprintf(stderr
, "ARRAY_BASE:%i ", cf
->output
.array_base
);
2386 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2388 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i_BUF%i ", id
, bc
->bytecode
[id
],
2389 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2390 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) / 4,
2391 (EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2392 EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
)) % 4);
2393 fprintf(stderr
, "ARRAY_SIZE:%i ", cf
->output
.array_size
);
2394 fprintf(stderr
, "COMP_MASK:%X ", cf
->output
.comp_mask
);
2395 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2396 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
2397 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2398 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2400 case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2401 case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2402 case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2403 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2404 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2405 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2406 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2407 case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2408 case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2409 case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2410 case CM_V_SQ_CF_WORD1_SQ_CF_INST_END
:
2411 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2412 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
2414 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2415 fprintf(stderr
, "INST:0x%x ", EG_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2416 fprintf(stderr
, "COND:%X ", cf
->cond
);
2417 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
2420 fprintf(stderr
, "%04d %08X CF NATIVE\n", id
, bc
->bytecode
[id
]);
2421 fprintf(stderr
, "%04d %08X CF NATIVE\n", id
+ 1, bc
->bytecode
[id
+ 1]);
2424 R600_ERR("Unknown instruction %0x\n", cf
->inst
);
2428 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
:
2429 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
:
2430 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
:
2431 case V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
:
2432 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2433 fprintf(stderr
, "ADDR:%d ", cf
->addr
);
2434 fprintf(stderr
, "KCACHE_MODE0:%X ", cf
->kcache
[0].mode
);
2435 fprintf(stderr
, "KCACHE_BANK0:%X ", cf
->kcache
[0].bank
);
2436 fprintf(stderr
, "KCACHE_BANK1:%X\n", cf
->kcache
[1].bank
);
2438 fprintf(stderr
, "%04d %08X ALU ", id
, bc
->bytecode
[id
]);
2439 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
));
2440 fprintf(stderr
, "KCACHE_MODE1:%X ", cf
->kcache
[1].mode
);
2441 fprintf(stderr
, "KCACHE_ADDR0:%X ", cf
->kcache
[0].addr
);
2442 fprintf(stderr
, "KCACHE_ADDR1:%X ", cf
->kcache
[1].addr
);
2443 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 2);
2445 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
2446 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
2447 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
2448 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2449 fprintf(stderr
, "ADDR:%d\n", cf
->addr
);
2451 fprintf(stderr
, "%04d %08X TEX/VTX ", id
, bc
->bytecode
[id
]);
2452 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2453 fprintf(stderr
, "COUNT:%d\n", cf
->ndw
/ 4);
2455 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
2456 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
2457 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2458 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2459 fprintf(stderr
, "ELEM_SIZE:%X ", cf
->output
.elem_size
);
2460 fprintf(stderr
, "ARRAY_BASE:%X ", cf
->output
.array_base
);
2461 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2463 fprintf(stderr
, "%04d %08X EXPORT ", id
, bc
->bytecode
[id
]);
2464 fprintf(stderr
, "SWIZ_X:%X ", cf
->output
.swizzle_x
);
2465 fprintf(stderr
, "SWIZ_Y:%X ", cf
->output
.swizzle_y
);
2466 fprintf(stderr
, "SWIZ_Z:%X ", cf
->output
.swizzle_z
);
2467 fprintf(stderr
, "SWIZ_W:%X ", cf
->output
.swizzle_w
);
2468 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2469 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
));
2470 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2471 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2473 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
:
2474 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
:
2475 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
:
2476 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
:
2477 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i ", id
, bc
->bytecode
[id
],
2478 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2479 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
));
2480 fprintf(stderr
, "GPR:%X ", cf
->output
.gpr
);
2481 fprintf(stderr
, "ELEM_SIZE:%i ", cf
->output
.elem_size
);
2482 fprintf(stderr
, "ARRAY_BASE:%i ", cf
->output
.array_base
);
2483 fprintf(stderr
, "TYPE:%X\n", cf
->output
.type
);
2485 fprintf(stderr
, "%04d %08X EXPORT MEM_STREAM%i ", id
, bc
->bytecode
[id
],
2486 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->inst
) -
2487 R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
));
2488 fprintf(stderr
, "ARRAY_SIZE:%i ", cf
->output
.array_size
);
2489 fprintf(stderr
, "COMP_MASK:%X ", cf
->output
.comp_mask
);
2490 fprintf(stderr
, "BARRIER:%X ", cf
->output
.barrier
);
2491 fprintf(stderr
, "INST:%d ", cf
->output
.inst
);
2492 fprintf(stderr
, "BURST_COUNT:%d ", cf
->output
.burst_count
);
2493 fprintf(stderr
, "EOP:%X\n", cf
->output
.end_of_program
);
2495 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
2496 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
2497 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
2498 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
2499 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
:
2500 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
2501 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
2502 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
2503 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
2504 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
2505 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2506 fprintf(stderr
, "ADDR:%d\n", cf
->cf_addr
);
2508 fprintf(stderr
, "%04d %08X CF ", id
, bc
->bytecode
[id
]);
2509 fprintf(stderr
, "INST:0x%x ", R600_G_SQ_CF_WORD1_CF_INST(cf
->inst
));
2510 fprintf(stderr
, "COND:%X ", cf
->cond
);
2511 fprintf(stderr
, "POP_COUNT:%X\n", cf
->pop_count
);
2514 R600_ERR("Unknown instruction %0x\n", cf
->inst
);
2520 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
2521 r600_bytecode_alu_nliterals(bc
, alu
, literal
, &nliteral
);
2523 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2524 fprintf(stderr
, "SRC0(SEL:%d ", alu
->src
[0].sel
);
2525 fprintf(stderr
, "REL:%d ", alu
->src
[0].rel
);
2526 fprintf(stderr
, "CHAN:%d ", alu
->src
[0].chan
);
2527 fprintf(stderr
, "NEG:%d) ", alu
->src
[0].neg
);
2528 fprintf(stderr
, "SRC1(SEL:%d ", alu
->src
[1].sel
);
2529 fprintf(stderr
, "REL:%d ", alu
->src
[1].rel
);
2530 fprintf(stderr
, "CHAN:%d ", alu
->src
[1].chan
);
2531 fprintf(stderr
, "NEG:%d ", alu
->src
[1].neg
);
2532 fprintf(stderr
, "IM:%d) ", alu
->index_mode
);
2533 fprintf(stderr
, "PRED_SEL:%d ", alu
->pred_sel
);
2534 fprintf(stderr
, "LAST:%d)\n", alu
->last
);
2536 fprintf(stderr
, "%04d %08X %c ", id
, bc
->bytecode
[id
], alu
->last
? '*' : ' ');
2537 fprintf(stderr
, "INST:0x%x ", alu
->inst
);
2538 fprintf(stderr
, "DST(SEL:%d ", alu
->dst
.sel
);
2539 fprintf(stderr
, "CHAN:%d ", alu
->dst
.chan
);
2540 fprintf(stderr
, "REL:%d ", alu
->dst
.rel
);
2541 fprintf(stderr
, "CLAMP:%d) ", alu
->dst
.clamp
);
2542 fprintf(stderr
, "BANK_SWIZZLE:%d ", alu
->bank_swizzle
);
2544 fprintf(stderr
, "SRC2(SEL:%d ", alu
->src
[2].sel
);
2545 fprintf(stderr
, "REL:%d ", alu
->src
[2].rel
);
2546 fprintf(stderr
, "CHAN:%d ", alu
->src
[2].chan
);
2547 fprintf(stderr
, "NEG:%d)\n", alu
->src
[2].neg
);
2549 fprintf(stderr
, "SRC0_ABS:%d ", alu
->src
[0].abs
);
2550 fprintf(stderr
, "SRC1_ABS:%d ", alu
->src
[1].abs
);
2551 fprintf(stderr
, "WRITE_MASK:%d ", alu
->dst
.write
);
2552 fprintf(stderr
, "OMOD:%d ", alu
->omod
);
2553 fprintf(stderr
, "EXECUTE_MASK:%d ", alu
->execute_mask
);
2554 fprintf(stderr
, "UPDATE_PRED:%d\n", alu
->update_pred
);
2559 for (i
= 0; i
< nliteral
; i
++, id
++) {
2560 float *f
= (float*)(bc
->bytecode
+ id
);
2561 fprintf(stderr
, "%04d %08X\t%f (%d)\n", id
, bc
->bytecode
[id
], *f
,
2562 *(bc
->bytecode
+ id
));
2569 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
2570 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2571 fprintf(stderr
, "INST:0x%x ", tex
->inst
);
2572 fprintf(stderr
, "RESOURCE_ID:%d ", tex
->resource_id
);
2573 fprintf(stderr
, "SRC(GPR:%d ", tex
->src_gpr
);
2574 fprintf(stderr
, "REL:%d)\n", tex
->src_rel
);
2576 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2577 fprintf(stderr
, "DST(GPR:%d ", tex
->dst_gpr
);
2578 fprintf(stderr
, "REL:%d ", tex
->dst_rel
);
2579 fprintf(stderr
, "SEL_X:%d ", tex
->dst_sel_x
);
2580 fprintf(stderr
, "SEL_Y:%d ", tex
->dst_sel_y
);
2581 fprintf(stderr
, "SEL_Z:%d ", tex
->dst_sel_z
);
2582 fprintf(stderr
, "SEL_W:%d) ", tex
->dst_sel_w
);
2583 fprintf(stderr
, "LOD_BIAS:%d ", tex
->lod_bias
);
2584 fprintf(stderr
, "COORD_TYPE_X:%d ", tex
->coord_type_x
);
2585 fprintf(stderr
, "COORD_TYPE_Y:%d ", tex
->coord_type_y
);
2586 fprintf(stderr
, "COORD_TYPE_Z:%d ", tex
->coord_type_z
);
2587 fprintf(stderr
, "COORD_TYPE_W:%d\n", tex
->coord_type_w
);
2589 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2590 fprintf(stderr
, "OFFSET_X:%d ", tex
->offset_x
);
2591 fprintf(stderr
, "OFFSET_Y:%d ", tex
->offset_y
);
2592 fprintf(stderr
, "OFFSET_Z:%d ", tex
->offset_z
);
2593 fprintf(stderr
, "SAMPLER_ID:%d ", tex
->sampler_id
);
2594 fprintf(stderr
, "SRC(SEL_X:%d ", tex
->src_sel_x
);
2595 fprintf(stderr
, "SEL_Y:%d ", tex
->src_sel_y
);
2596 fprintf(stderr
, "SEL_Z:%d ", tex
->src_sel_z
);
2597 fprintf(stderr
, "SEL_W:%d)\n", tex
->src_sel_w
);
2599 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
2603 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
2604 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2605 fprintf(stderr
, "INST:%d ", vtx
->inst
);
2606 fprintf(stderr
, "FETCH_TYPE:%d ", vtx
->fetch_type
);
2607 fprintf(stderr
, "BUFFER_ID:%d\n", vtx
->buffer_id
);
2609 /* This assumes that no semantic fetches exist */
2610 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2611 fprintf(stderr
, "SRC(GPR:%d ", vtx
->src_gpr
);
2612 fprintf(stderr
, "SEL_X:%d) ", vtx
->src_sel_x
);
2613 if (bc
->chip_class
< CAYMAN
)
2614 fprintf(stderr
, "MEGA_FETCH_COUNT:%d ", vtx
->mega_fetch_count
);
2616 fprintf(stderr
, "SEL_Y:%d) ", 0);
2617 fprintf(stderr
, "DST(GPR:%d ", vtx
->dst_gpr
);
2618 fprintf(stderr
, "SEL_X:%d ", vtx
->dst_sel_x
);
2619 fprintf(stderr
, "SEL_Y:%d ", vtx
->dst_sel_y
);
2620 fprintf(stderr
, "SEL_Z:%d ", vtx
->dst_sel_z
);
2621 fprintf(stderr
, "SEL_W:%d) ", vtx
->dst_sel_w
);
2622 fprintf(stderr
, "USE_CONST_FIELDS:%d ", vtx
->use_const_fields
);
2623 fprintf(stderr
, "FORMAT(DATA:%d ", vtx
->data_format
);
2624 fprintf(stderr
, "NUM:%d ", vtx
->num_format_all
);
2625 fprintf(stderr
, "COMP:%d ", vtx
->format_comp_all
);
2626 fprintf(stderr
, "MODE:%d)\n", vtx
->srf_mode_all
);
2628 fprintf(stderr
, "%04d %08X ", id
, bc
->bytecode
[id
]);
2629 fprintf(stderr
, "ENDIAN:%d ", vtx
->endian
);
2630 fprintf(stderr
, "OFFSET:%d\n", vtx
->offset
);
2633 fprintf(stderr
, "%04d %08X \n", id
, bc
->bytecode
[id
]);
2638 fprintf(stderr
, "--------------------------------------\n");
2641 void r600_vertex_data_type(enum pipe_format pformat
,
2643 unsigned *num_format
, unsigned *format_comp
, unsigned *endian
)
2645 const struct util_format_description
*desc
;
2651 *endian
= ENDIAN_NONE
;
2653 desc
= util_format_description(pformat
);
2654 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
2658 /* Find the first non-VOID channel. */
2659 for (i
= 0; i
< 4; i
++) {
2660 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
2665 *endian
= r600_endian_swap(desc
->channel
[i
].size
);
2667 switch (desc
->channel
[i
].type
) {
2668 /* Half-floats, floats, ints */
2669 case UTIL_FORMAT_TYPE_FLOAT
:
2670 switch (desc
->channel
[i
].size
) {
2672 switch (desc
->nr_channels
) {
2674 *format
= FMT_16_FLOAT
;
2677 *format
= FMT_16_16_FLOAT
;
2681 *format
= FMT_16_16_16_16_FLOAT
;
2686 switch (desc
->nr_channels
) {
2688 *format
= FMT_32_FLOAT
;
2691 *format
= FMT_32_32_FLOAT
;
2694 *format
= FMT_32_32_32_FLOAT
;
2697 *format
= FMT_32_32_32_32_FLOAT
;
2706 case UTIL_FORMAT_TYPE_UNSIGNED
:
2708 case UTIL_FORMAT_TYPE_SIGNED
:
2709 switch (desc
->channel
[i
].size
) {
2711 switch (desc
->nr_channels
) {
2720 *format
= FMT_8_8_8_8
;
2725 if (desc
->nr_channels
!= 4)
2728 *format
= FMT_2_10_10_10
;
2731 switch (desc
->nr_channels
) {
2736 *format
= FMT_16_16
;
2740 *format
= FMT_16_16_16_16
;
2745 switch (desc
->nr_channels
) {
2750 *format
= FMT_32_32
;
2753 *format
= FMT_32_32_32
;
2756 *format
= FMT_32_32_32_32
;
2768 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2773 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
||
2774 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2775 if (!desc
->channel
[i
].normalized
) {
2776 if (desc
->channel
[i
].pure_integer
)
2784 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
2787 void *r600_create_vertex_fetch_shader(struct pipe_context
*ctx
,
2789 const struct pipe_vertex_element
*elements
)
2791 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2792 static int dump_shaders
= -1;
2793 struct r600_bytecode bc
;
2794 struct r600_bytecode_vtx vtx
;
2795 const struct util_format_description
*desc
;
2796 unsigned fetch_resource_start
= rctx
->chip_class
>= EVERGREEN
? 0 : 160;
2797 unsigned format
, num_format
, format_comp
, endian
;
2799 int i
, j
, r
, fs_size
;
2800 struct r600_fetch_shader
*shader
;
2804 memset(&bc
, 0, sizeof(bc
));
2805 r600_bytecode_init(&bc
, rctx
->chip_class
, rctx
->family
,
2806 rctx
->screen
->msaa_texture_support
);
2808 for (i
= 0; i
< count
; i
++) {
2809 if (elements
[i
].instance_divisor
> 1) {
2810 if (rctx
->chip_class
== CAYMAN
) {
2811 for (j
= 0; j
< 4; j
++) {
2812 struct r600_bytecode_alu alu
;
2813 memset(&alu
, 0, sizeof(alu
));
2814 alu
.inst
= BC_INST(&bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2816 alu
.src
[0].chan
= 3;
2817 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2818 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2819 alu
.dst
.sel
= i
+ 1;
2821 alu
.dst
.write
= j
== 3;
2823 if ((r
= r600_bytecode_add_alu(&bc
, &alu
))) {
2824 r600_bytecode_clear(&bc
);
2829 struct r600_bytecode_alu alu
;
2830 memset(&alu
, 0, sizeof(alu
));
2831 alu
.inst
= BC_INST(&bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2833 alu
.src
[0].chan
= 3;
2834 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2835 alu
.src
[1].value
= (1ll << 32) / elements
[i
].instance_divisor
+ 1;
2836 alu
.dst
.sel
= i
+ 1;
2840 if ((r
= r600_bytecode_add_alu(&bc
, &alu
))) {
2841 r600_bytecode_clear(&bc
);
2848 for (i
= 0; i
< count
; i
++) {
2849 r600_vertex_data_type(elements
[i
].src_format
,
2850 &format
, &num_format
, &format_comp
, &endian
);
2852 desc
= util_format_description(elements
[i
].src_format
);
2854 r600_bytecode_clear(&bc
);
2855 R600_ERR("unknown format %d\n", elements
[i
].src_format
);
2859 if (elements
[i
].src_offset
> 65535) {
2860 r600_bytecode_clear(&bc
);
2861 R600_ERR("too big src_offset: %u\n", elements
[i
].src_offset
);
2865 memset(&vtx
, 0, sizeof(vtx
));
2866 vtx
.buffer_id
= elements
[i
].vertex_buffer_index
+ fetch_resource_start
;
2867 vtx
.fetch_type
= elements
[i
].instance_divisor
? 1 : 0;
2868 vtx
.src_gpr
= elements
[i
].instance_divisor
> 1 ? i
+ 1 : 0;
2869 vtx
.src_sel_x
= elements
[i
].instance_divisor
? 3 : 0;
2870 vtx
.mega_fetch_count
= 0x1F;
2871 vtx
.dst_gpr
= i
+ 1;
2872 vtx
.dst_sel_x
= desc
->swizzle
[0];
2873 vtx
.dst_sel_y
= desc
->swizzle
[1];
2874 vtx
.dst_sel_z
= desc
->swizzle
[2];
2875 vtx
.dst_sel_w
= desc
->swizzle
[3];
2876 vtx
.data_format
= format
;
2877 vtx
.num_format_all
= num_format
;
2878 vtx
.format_comp_all
= format_comp
;
2879 vtx
.srf_mode_all
= 1;
2880 vtx
.offset
= elements
[i
].src_offset
;
2881 vtx
.endian
= endian
;
2883 if ((r
= r600_bytecode_add_vtx(&bc
, &vtx
))) {
2884 r600_bytecode_clear(&bc
);
2889 r600_bytecode_add_cfinst(&bc
, BC_INST(&bc
, V_SQ_CF_WORD1_SQ_CF_INST_RETURN
));
2891 if ((r
= r600_bytecode_build(&bc
))) {
2892 r600_bytecode_clear(&bc
);
2896 if (dump_shaders
== -1)
2897 dump_shaders
= debug_get_bool_option("R600_DUMP_SHADERS", FALSE
);
2900 fprintf(stderr
, "--------------------------------------------------------------\n");
2901 r600_bytecode_dump(&bc
);
2902 fprintf(stderr
, "______________________________________________________________\n");
2907 /* Allocate the CSO. */
2908 shader
= CALLOC_STRUCT(r600_fetch_shader
);
2910 r600_bytecode_clear(&bc
);
2914 u_suballocator_alloc(rctx
->allocator_fetch_shader
, fs_size
, &shader
->offset
,
2915 (struct pipe_resource
**)&shader
->buffer
);
2916 if (!shader
->buffer
) {
2917 r600_bytecode_clear(&bc
);
2922 bytecode
= r600_buffer_mmap_sync_with_rings(rctx
, shader
->buffer
, PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_UNSYNCHRONIZED
);
2923 bytecode
+= shader
->offset
/ 4;
2925 if (R600_BIG_ENDIAN
) {
2926 for (i
= 0; i
< fs_size
/ 4; ++i
) {
2927 bytecode
[i
] = bswap_32(bc
.bytecode
[i
]);
2930 memcpy(bytecode
, bc
.bytecode
, fs_size
);
2932 rctx
->ws
->buffer_unmap(shader
->buffer
->cs_buf
);
2934 r600_bytecode_clear(&bc
);
2938 void r600_bytecode_alu_read(struct r600_bytecode_alu
*alu
, uint32_t word0
, uint32_t word1
)
2941 alu
->src
[0].sel
= G_SQ_ALU_WORD0_SRC0_SEL(word0
);
2942 alu
->src
[0].rel
= G_SQ_ALU_WORD0_SRC0_REL(word0
);
2943 alu
->src
[0].chan
= G_SQ_ALU_WORD0_SRC0_CHAN(word0
);
2944 alu
->src
[0].neg
= G_SQ_ALU_WORD0_SRC0_NEG(word0
);
2945 alu
->src
[1].sel
= G_SQ_ALU_WORD0_SRC1_SEL(word0
);
2946 alu
->src
[1].rel
= G_SQ_ALU_WORD0_SRC1_REL(word0
);
2947 alu
->src
[1].chan
= G_SQ_ALU_WORD0_SRC1_CHAN(word0
);
2948 alu
->src
[1].neg
= G_SQ_ALU_WORD0_SRC1_NEG(word0
);
2949 alu
->index_mode
= G_SQ_ALU_WORD0_INDEX_MODE(word0
);
2950 alu
->pred_sel
= G_SQ_ALU_WORD0_PRED_SEL(word0
);
2951 alu
->last
= G_SQ_ALU_WORD0_LAST(word0
);
2954 alu
->bank_swizzle
= G_SQ_ALU_WORD1_BANK_SWIZZLE(word1
);
2955 if (alu
->bank_swizzle
)
2956 alu
->bank_swizzle_force
= alu
->bank_swizzle
;
2957 alu
->dst
.sel
= G_SQ_ALU_WORD1_DST_GPR(word1
);
2958 alu
->dst
.rel
= G_SQ_ALU_WORD1_DST_REL(word1
);
2959 alu
->dst
.chan
= G_SQ_ALU_WORD1_DST_CHAN(word1
);
2960 alu
->dst
.clamp
= G_SQ_ALU_WORD1_CLAMP(word1
);
2961 if (G_SQ_ALU_WORD1_ENCODING(word1
)) /*ALU_DWORD1_OP3*/
2964 alu
->src
[2].sel
= G_SQ_ALU_WORD1_OP3_SRC2_SEL(word1
);
2965 alu
->src
[2].rel
= G_SQ_ALU_WORD1_OP3_SRC2_REL(word1
);
2966 alu
->src
[2].chan
= G_SQ_ALU_WORD1_OP3_SRC2_CHAN(word1
);
2967 alu
->src
[2].neg
= G_SQ_ALU_WORD1_OP3_SRC2_NEG(word1
);
2968 alu
->inst
= G_SQ_ALU_WORD1_OP3_ALU_INST(word1
);
2970 else /*ALU_DWORD1_OP2*/
2972 alu
->src
[0].abs
= G_SQ_ALU_WORD1_OP2_SRC0_ABS(word1
);
2973 alu
->src
[1].abs
= G_SQ_ALU_WORD1_OP2_SRC1_ABS(word1
);
2974 alu
->inst
= G_SQ_ALU_WORD1_OP2_ALU_INST(word1
);
2975 alu
->omod
= G_SQ_ALU_WORD1_OP2_OMOD(word1
);
2976 alu
->dst
.write
= G_SQ_ALU_WORD1_OP2_WRITE_MASK(word1
);
2977 alu
->update_pred
= G_SQ_ALU_WORD1_OP2_UPDATE_PRED(word1
);
2979 G_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(word1
);
2983 void r600_bytecode_export_read(struct r600_bytecode_output
*output
, uint32_t word0
, uint32_t word1
)
2985 output
->array_base
= G_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(word0
);
2986 output
->type
= G_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(word0
);
2987 output
->gpr
= G_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(word0
);
2988 output
->elem_size
= G_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(word0
);
2990 output
->swizzle_x
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(word1
);
2991 output
->swizzle_y
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(word1
);
2992 output
->swizzle_z
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(word1
);
2993 output
->swizzle_w
= G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(word1
);
2994 output
->burst_count
= G_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(word1
);
2995 output
->end_of_program
= G_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(word1
);
2996 output
->inst
= R600_S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(word1
));
2997 output
->barrier
= G_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(word1
);
2998 output
->array_size
= G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(word1
);
2999 output
->comp_mask
= G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(word1
);