2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
28 #include "tgsi/tgsi_parse.h"
29 #include "tgsi/tgsi_info.h"
30 #include "tgsi/tgsi_strings.h"
31 #include "util/u_hash_table.h"
32 #include "toy_helpers.h"
35 /* map TGSI opcode to GEN opcode 1-to-1 */
40 } aos_simple_opcode_map
[TGSI_OPCODE_LAST
] = {
41 [TGSI_OPCODE_ARL
] = { GEN6_OPCODE_RNDD
, 1, 1 },
42 [TGSI_OPCODE_MOV
] = { GEN6_OPCODE_MOV
, 1, 1 },
43 [TGSI_OPCODE_RCP
] = { TOY_OPCODE_INV
, 1, 1 },
44 [TGSI_OPCODE_RSQ
] = { TOY_OPCODE_RSQ
, 1, 1 },
45 [TGSI_OPCODE_MUL
] = { GEN6_OPCODE_MUL
, 1, 2 },
46 [TGSI_OPCODE_ADD
] = { GEN6_OPCODE_ADD
, 1, 2 },
47 [TGSI_OPCODE_DP3
] = { GEN6_OPCODE_DP3
, 1, 2 },
48 [TGSI_OPCODE_DP4
] = { GEN6_OPCODE_DP4
, 1, 2 },
49 [TGSI_OPCODE_MIN
] = { GEN6_OPCODE_SEL
, 1, 2 },
50 [TGSI_OPCODE_MAX
] = { GEN6_OPCODE_SEL
, 1, 2 },
51 /* a later pass will move src[2] to accumulator */
52 [TGSI_OPCODE_MAD
] = { GEN6_OPCODE_MAC
, 1, 3 },
53 [TGSI_OPCODE_SUB
] = { GEN6_OPCODE_ADD
, 1, 2 },
54 [TGSI_OPCODE_SQRT
] = { TOY_OPCODE_SQRT
, 1, 1 },
55 [TGSI_OPCODE_FRC
] = { GEN6_OPCODE_FRC
, 1, 1 },
56 [TGSI_OPCODE_FLR
] = { GEN6_OPCODE_RNDD
, 1, 1 },
57 [TGSI_OPCODE_ROUND
] = { GEN6_OPCODE_RNDE
, 1, 1 },
58 [TGSI_OPCODE_EX2
] = { TOY_OPCODE_EXP
, 1, 1 },
59 [TGSI_OPCODE_LG2
] = { TOY_OPCODE_LOG
, 1, 1 },
60 [TGSI_OPCODE_POW
] = { TOY_OPCODE_POW
, 1, 2 },
61 [TGSI_OPCODE_ABS
] = { GEN6_OPCODE_MOV
, 1, 1 },
62 [TGSI_OPCODE_DPH
] = { GEN6_OPCODE_DPH
, 1, 2 },
63 [TGSI_OPCODE_COS
] = { TOY_OPCODE_COS
, 1, 1 },
64 [TGSI_OPCODE_KILL
] = { TOY_OPCODE_KIL
, 0, 0 },
65 [TGSI_OPCODE_SIN
] = { TOY_OPCODE_SIN
, 1, 1 },
66 [TGSI_OPCODE_ARR
] = { GEN6_OPCODE_RNDZ
, 1, 1 },
67 [TGSI_OPCODE_DP2
] = { GEN6_OPCODE_DP2
, 1, 2 },
68 [TGSI_OPCODE_IF
] = { GEN6_OPCODE_IF
, 0, 1 },
69 [TGSI_OPCODE_UIF
] = { GEN6_OPCODE_IF
, 0, 1 },
70 [TGSI_OPCODE_ELSE
] = { GEN6_OPCODE_ELSE
, 0, 0 },
71 [TGSI_OPCODE_ENDIF
] = { GEN6_OPCODE_ENDIF
, 0, 0 },
72 [TGSI_OPCODE_I2F
] = { GEN6_OPCODE_MOV
, 1, 1 },
73 [TGSI_OPCODE_NOT
] = { GEN6_OPCODE_NOT
, 1, 1 },
74 [TGSI_OPCODE_TRUNC
] = { GEN6_OPCODE_RNDZ
, 1, 1 },
75 [TGSI_OPCODE_SHL
] = { GEN6_OPCODE_SHL
, 1, 2 },
76 [TGSI_OPCODE_AND
] = { GEN6_OPCODE_AND
, 1, 2 },
77 [TGSI_OPCODE_OR
] = { GEN6_OPCODE_OR
, 1, 2 },
78 [TGSI_OPCODE_MOD
] = { TOY_OPCODE_INT_DIV_REMAINDER
, 1, 2 },
79 [TGSI_OPCODE_XOR
] = { GEN6_OPCODE_XOR
, 1, 2 },
80 [TGSI_OPCODE_EMIT
] = { TOY_OPCODE_EMIT
, 0, 0 },
81 [TGSI_OPCODE_ENDPRIM
] = { TOY_OPCODE_ENDPRIM
, 0, 0 },
82 [TGSI_OPCODE_NOP
] = { GEN6_OPCODE_NOP
, 0, 0 },
83 [TGSI_OPCODE_KILL_IF
] = { TOY_OPCODE_KIL
, 0, 1 },
84 [TGSI_OPCODE_END
] = { GEN6_OPCODE_NOP
, 0, 0 },
85 [TGSI_OPCODE_F2I
] = { GEN6_OPCODE_MOV
, 1, 1 },
86 [TGSI_OPCODE_IDIV
] = { TOY_OPCODE_INT_DIV_QUOTIENT
, 1, 2 },
87 [TGSI_OPCODE_IMAX
] = { GEN6_OPCODE_SEL
, 1, 2 },
88 [TGSI_OPCODE_IMIN
] = { GEN6_OPCODE_SEL
, 1, 2 },
89 [TGSI_OPCODE_INEG
] = { GEN6_OPCODE_MOV
, 1, 1 },
90 [TGSI_OPCODE_ISHR
] = { GEN6_OPCODE_ASR
, 1, 2 },
91 [TGSI_OPCODE_F2U
] = { GEN6_OPCODE_MOV
, 1, 1 },
92 [TGSI_OPCODE_U2F
] = { GEN6_OPCODE_MOV
, 1, 1 },
93 [TGSI_OPCODE_UADD
] = { GEN6_OPCODE_ADD
, 1, 2 },
94 [TGSI_OPCODE_UDIV
] = { TOY_OPCODE_INT_DIV_QUOTIENT
, 1, 2 },
95 /* a later pass will move src[2] to accumulator */
96 [TGSI_OPCODE_UMAD
] = { GEN6_OPCODE_MAC
, 1, 3 },
97 [TGSI_OPCODE_UMAX
] = { GEN6_OPCODE_SEL
, 1, 2 },
98 [TGSI_OPCODE_UMIN
] = { GEN6_OPCODE_SEL
, 1, 2 },
99 [TGSI_OPCODE_UMOD
] = { TOY_OPCODE_INT_DIV_REMAINDER
, 1, 2 },
100 [TGSI_OPCODE_UMUL
] = { GEN6_OPCODE_MUL
, 1, 2 },
101 [TGSI_OPCODE_USHR
] = { GEN6_OPCODE_SHR
, 1, 2 },
102 [TGSI_OPCODE_UARL
] = { GEN6_OPCODE_MOV
, 1, 1 },
103 [TGSI_OPCODE_IABS
] = { GEN6_OPCODE_MOV
, 1, 1 },
107 aos_simple(struct toy_compiler
*tc
,
108 const struct tgsi_full_instruction
*tgsi_inst
,
112 struct toy_inst
*inst
;
114 int cond_modifier
= GEN6_COND_NONE
;
115 int num_dst
= tgsi_inst
->Instruction
.NumDstRegs
;
116 int num_src
= tgsi_inst
->Instruction
.NumSrcRegs
;
119 opcode
= aos_simple_opcode_map
[tgsi_inst
->Instruction
.Opcode
].opcode
;
120 assert(num_dst
== aos_simple_opcode_map
[tgsi_inst
->Instruction
.Opcode
].num_dst
);
121 assert(num_src
== aos_simple_opcode_map
[tgsi_inst
->Instruction
.Opcode
].num_src
);
123 assert(!"invalid aos_simple() call");
127 /* no need to emit nop */
128 if (opcode
== GEN6_OPCODE_NOP
)
135 inst
->opcode
= opcode
;
137 switch (tgsi_inst
->Instruction
.Opcode
) {
138 case TGSI_OPCODE_MIN
:
139 case TGSI_OPCODE_IMIN
:
140 case TGSI_OPCODE_UMIN
:
141 cond_modifier
= GEN6_COND_L
;
143 case TGSI_OPCODE_MAX
:
144 case TGSI_OPCODE_IMAX
:
145 case TGSI_OPCODE_UMAX
:
146 cond_modifier
= GEN6_COND_GE
;
148 case TGSI_OPCODE_SUB
:
149 src
[1] = tsrc_negate(src
[1]);
151 case TGSI_OPCODE_ABS
:
152 case TGSI_OPCODE_IABS
:
153 src
[0] = tsrc_absolute(src
[0]);
156 cond_modifier
= GEN6_COND_NZ
;
158 assert(src
[0].type
== TOY_TYPE_F
);
159 src
[0] = tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
);
160 src
[1] = tsrc_imm_f(0.0f
);
162 case TGSI_OPCODE_UIF
:
163 cond_modifier
= GEN6_COND_NZ
;
165 assert(src
[0].type
== TOY_TYPE_UD
);
166 src
[0] = tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
);
167 src
[1] = tsrc_imm_d(0);
169 case TGSI_OPCODE_INEG
:
170 src
[0] = tsrc_negate(src
[0]);
172 case TGSI_OPCODE_RCP
:
173 case TGSI_OPCODE_RSQ
:
174 case TGSI_OPCODE_EX2
:
175 case TGSI_OPCODE_LG2
:
176 case TGSI_OPCODE_COS
:
177 case TGSI_OPCODE_SIN
:
178 src
[0] = tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
);
180 case TGSI_OPCODE_POW
:
181 src
[0] = tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
);
182 src
[1] = tsrc_swizzle1(src
[1], TOY_SWIZZLE_X
);
186 inst
->cond_modifier
= cond_modifier
;
189 assert(num_dst
== 1);
193 assert(num_src
<= Elements(inst
->src
));
194 for (i
= 0; i
< num_src
; i
++)
195 inst
->src
[i
] = src
[i
];
199 aos_set_on_cond(struct toy_compiler
*tc
,
200 const struct tgsi_full_instruction
*tgsi_inst
,
204 struct toy_inst
*inst
;
206 struct toy_src zero
, one
;
208 switch (tgsi_inst
->Instruction
.Opcode
) {
209 case TGSI_OPCODE_SLT
:
210 case TGSI_OPCODE_ISLT
:
211 case TGSI_OPCODE_USLT
:
212 case TGSI_OPCODE_FSLT
:
215 case TGSI_OPCODE_SGE
:
216 case TGSI_OPCODE_ISGE
:
217 case TGSI_OPCODE_USGE
:
218 case TGSI_OPCODE_FSGE
:
221 case TGSI_OPCODE_SEQ
:
222 case TGSI_OPCODE_USEQ
:
223 case TGSI_OPCODE_FSEQ
:
226 case TGSI_OPCODE_SGT
:
229 case TGSI_OPCODE_SLE
:
232 case TGSI_OPCODE_SNE
:
233 case TGSI_OPCODE_USNE
:
234 case TGSI_OPCODE_FSNE
:
238 assert(!"invalid aos_set_on_cond() call");
242 /* note that for integer versions, all bits are set */
243 switch (dst
[0].type
) {
246 zero
= tsrc_imm_f(0.0f
);
247 one
= tsrc_imm_f(1.0f
);
250 zero
= tsrc_imm_d(0);
251 one
= tsrc_imm_d(-1);
254 zero
= tsrc_imm_ud(0);
255 one
= tsrc_imm_ud(~0);
259 tc_MOV(tc
, dst
[0], zero
);
260 tc_CMP(tc
, tdst_null(), src
[0], src
[1], cond
);
261 inst
= tc_MOV(tc
, dst
[0], one
);
262 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
266 aos_compare(struct toy_compiler
*tc
,
267 const struct tgsi_full_instruction
*tgsi_inst
,
271 struct toy_inst
*inst
;
274 switch (tgsi_inst
->Instruction
.Opcode
) {
275 case TGSI_OPCODE_CMP
:
276 zero
= tsrc_imm_f(0.0f
);
278 case TGSI_OPCODE_UCMP
:
279 zero
= tsrc_imm_ud(0);
282 assert(!"invalid aos_compare() call");
286 tc_CMP(tc
, tdst_null(), src
[0], zero
, GEN6_COND_L
);
287 inst
= tc_SEL(tc
, dst
[0], src
[1], src
[2], GEN6_COND_NONE
);
288 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
292 aos_set_sign(struct toy_compiler
*tc
,
293 const struct tgsi_full_instruction
*tgsi_inst
,
297 struct toy_inst
*inst
;
298 struct toy_src zero
, one
, neg_one
;
300 switch (tgsi_inst
->Instruction
.Opcode
) {
301 case TGSI_OPCODE_SSG
:
302 zero
= tsrc_imm_f(0.0f
);
303 one
= tsrc_imm_f(1.0f
);
304 neg_one
= tsrc_imm_f(-1.0f
);
306 case TGSI_OPCODE_ISSG
:
307 zero
= tsrc_imm_d(0);
309 neg_one
= tsrc_imm_d(-1);
312 assert(!"invalid aos_set_sign() call");
316 tc_MOV(tc
, dst
[0], zero
);
318 tc_CMP(tc
, tdst_null(), src
[0], zero
, GEN6_COND_G
);
319 inst
= tc_MOV(tc
, dst
[0], one
);
320 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
322 tc_CMP(tc
, tdst_null(), src
[0], zero
, GEN6_COND_L
);
323 inst
= tc_MOV(tc
, dst
[0], neg_one
);
324 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
328 aos_tex(struct toy_compiler
*tc
,
329 const struct tgsi_full_instruction
*tgsi_inst
,
333 struct toy_inst
*inst
;
334 enum toy_opcode opcode
;
337 switch (tgsi_inst
->Instruction
.Opcode
) {
338 case TGSI_OPCODE_TEX
:
339 opcode
= TOY_OPCODE_TGSI_TEX
;
341 case TGSI_OPCODE_TXD
:
342 opcode
= TOY_OPCODE_TGSI_TXD
;
344 case TGSI_OPCODE_TXP
:
345 opcode
= TOY_OPCODE_TGSI_TXP
;
347 case TGSI_OPCODE_TXB
:
348 opcode
= TOY_OPCODE_TGSI_TXB
;
350 case TGSI_OPCODE_TXL
:
351 opcode
= TOY_OPCODE_TGSI_TXL
;
353 case TGSI_OPCODE_TXF
:
354 opcode
= TOY_OPCODE_TGSI_TXF
;
356 case TGSI_OPCODE_TXQ
:
357 opcode
= TOY_OPCODE_TGSI_TXQ
;
359 case TGSI_OPCODE_TXQ_LZ
:
360 opcode
= TOY_OPCODE_TGSI_TXQ_LZ
;
362 case TGSI_OPCODE_TEX2
:
363 opcode
= TOY_OPCODE_TGSI_TEX2
;
365 case TGSI_OPCODE_TXB2
:
366 opcode
= TOY_OPCODE_TGSI_TXB2
;
368 case TGSI_OPCODE_TXL2
:
369 opcode
= TOY_OPCODE_TGSI_TXL2
;
372 assert(!"unsupported texturing opcode");
377 assert(tgsi_inst
->Instruction
.Texture
);
380 inst
->opcode
= opcode
;
381 inst
->tex
.target
= tgsi_inst
->Texture
.Texture
;
383 assert(tgsi_inst
->Instruction
.NumSrcRegs
<= Elements(inst
->src
));
384 assert(tgsi_inst
->Instruction
.NumDstRegs
== 1);
387 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++)
388 inst
->src
[i
] = src
[i
];
390 for (i
= 0; i
< tgsi_inst
->Texture
.NumOffsets
; i
++)
391 tc_fail(tc
, "texelFetchOffset unsupported");
395 aos_sample(struct toy_compiler
*tc
,
396 const struct tgsi_full_instruction
*tgsi_inst
,
400 struct toy_inst
*inst
;
401 enum toy_opcode opcode
;
404 assert(!"sampling untested");
406 switch (tgsi_inst
->Instruction
.Opcode
) {
407 case TGSI_OPCODE_SAMPLE
:
408 opcode
= TOY_OPCODE_TGSI_SAMPLE
;
410 case TGSI_OPCODE_SAMPLE_I
:
411 opcode
= TOY_OPCODE_TGSI_SAMPLE_I
;
413 case TGSI_OPCODE_SAMPLE_I_MS
:
414 opcode
= TOY_OPCODE_TGSI_SAMPLE_I_MS
;
416 case TGSI_OPCODE_SAMPLE_B
:
417 opcode
= TOY_OPCODE_TGSI_SAMPLE_B
;
419 case TGSI_OPCODE_SAMPLE_C
:
420 opcode
= TOY_OPCODE_TGSI_SAMPLE_C
;
422 case TGSI_OPCODE_SAMPLE_C_LZ
:
423 opcode
= TOY_OPCODE_TGSI_SAMPLE_C_LZ
;
425 case TGSI_OPCODE_SAMPLE_D
:
426 opcode
= TOY_OPCODE_TGSI_SAMPLE_D
;
428 case TGSI_OPCODE_SAMPLE_L
:
429 opcode
= TOY_OPCODE_TGSI_SAMPLE_L
;
431 case TGSI_OPCODE_GATHER4
:
432 opcode
= TOY_OPCODE_TGSI_GATHER4
;
434 case TGSI_OPCODE_SVIEWINFO
:
435 opcode
= TOY_OPCODE_TGSI_SVIEWINFO
;
437 case TGSI_OPCODE_SAMPLE_POS
:
438 opcode
= TOY_OPCODE_TGSI_SAMPLE_POS
;
440 case TGSI_OPCODE_SAMPLE_INFO
:
441 opcode
= TOY_OPCODE_TGSI_SAMPLE_INFO
;
444 assert(!"unsupported sampling opcode");
450 inst
->opcode
= opcode
;
452 assert(tgsi_inst
->Instruction
.NumSrcRegs
<= Elements(inst
->src
));
453 assert(tgsi_inst
->Instruction
.NumDstRegs
== 1);
456 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++)
457 inst
->src
[i
] = src
[i
];
461 aos_LIT(struct toy_compiler
*tc
,
462 const struct tgsi_full_instruction
*tgsi_inst
,
466 struct toy_inst
*inst
;
468 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_XW
), tsrc_imm_f(1.0f
));
470 if (!(dst
[0].writemask
& TOY_WRITEMASK_YZ
))
473 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_YZ
), tsrc_imm_f(0.0f
));
475 tc_CMP(tc
, tdst_null(),
476 tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
),
481 tdst_writemask(dst
[0], TOY_WRITEMASK_Y
),
482 tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
));
483 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
485 /* clamp W to (-128, 128)? */
487 tdst_writemask(dst
[0], TOY_WRITEMASK_Z
),
488 tsrc_swizzle1(src
[0], TOY_SWIZZLE_Y
),
489 tsrc_swizzle1(src
[0], TOY_SWIZZLE_W
));
490 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
494 aos_EXP(struct toy_compiler
*tc
,
495 const struct tgsi_full_instruction
*tgsi_inst
,
499 struct toy_src src0
= tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
);
501 if (dst
[0].writemask
& TOY_WRITEMASK_X
) {
503 tdst_d(tdst_writemask(tc_alloc_tmp(tc
), TOY_WRITEMASK_X
));
505 tc_RNDD(tc
, tmp
, src0
);
507 /* construct the floating point number manually */
508 tc_ADD(tc
, tmp
, tsrc_from(tmp
), tsrc_imm_d(127));
509 tc_SHL(tc
, tdst_d(tdst_writemask(dst
[0], TOY_WRITEMASK_X
)),
510 tsrc_from(tmp
), tsrc_imm_d(23));
513 tc_FRC(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_Y
), src0
);
514 tc_EXP(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_Z
), src0
);
515 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_W
), tsrc_imm_f(1.0f
));
519 aos_LOG(struct toy_compiler
*tc
,
520 const struct tgsi_full_instruction
*tgsi_inst
,
524 struct toy_src src0
= tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
);
526 if (dst
[0].writemask
& TOY_WRITEMASK_XY
) {
529 tmp
= tdst_d(tdst_writemask(tc_alloc_tmp(tc
), TOY_WRITEMASK_X
));
532 tc_SHR(tc
, tmp
, tsrc_absolute(tsrc_d(src0
)), tsrc_imm_d(23));
533 tc_ADD(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_X
),
534 tsrc_from(tmp
), tsrc_imm_d(-127));
537 tc_AND(tc
, tmp
, tsrc_d(src0
), tsrc_imm_d((1 << 23) - 1));
538 tc_OR(tc
, tdst_writemask(tdst_d(dst
[0]), TOY_WRITEMASK_Y
),
539 tsrc_from(tmp
), tsrc_imm_d(127 << 23));
542 tc_LOG(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_Z
), src0
);
543 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_W
), tsrc_imm_f(1.0f
));
547 aos_DST(struct toy_compiler
*tc
,
548 const struct tgsi_full_instruction
*tgsi_inst
,
552 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_X
), tsrc_imm_f(1.0f
));
553 tc_MUL(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_Y
), src
[0], src
[1]);
554 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_Z
), src
[0]);
555 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_W
), src
[1]);
559 aos_LRP(struct toy_compiler
*tc
,
560 const struct tgsi_full_instruction
*tgsi_inst
,
564 struct toy_dst tmp
= tc_alloc_tmp(tc
);
566 tc_ADD(tc
, tmp
, tsrc_negate(src
[0]), tsrc_imm_f(1.0f
));
567 tc_MUL(tc
, tmp
, tsrc_from(tmp
), src
[2]);
568 tc_MAC(tc
, dst
[0], src
[0], src
[1], tsrc_from(tmp
));
572 aos_CND(struct toy_compiler
*tc
,
573 const struct tgsi_full_instruction
*tgsi_inst
,
577 struct toy_inst
*inst
;
579 assert(!"CND untested");
581 tc_CMP(tc
, tdst_null(), src
[2], tsrc_imm_f(0.5f
), GEN6_COND_G
);
582 inst
= tc_SEL(tc
, dst
[0], src
[0], src
[1], GEN6_COND_NONE
);
583 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
587 aos_DP2A(struct toy_compiler
*tc
,
588 const struct tgsi_full_instruction
*tgsi_inst
,
592 struct toy_dst tmp
= tc_alloc_tmp(tc
);
594 assert(!"DP2A untested");
596 tc_DP2(tc
, tmp
, src
[0], src
[1]);
597 tc_ADD(tc
, dst
[0], tsrc_swizzle1(tsrc_from(tmp
), TOY_SWIZZLE_X
), src
[2]);
601 aos_CLAMP(struct toy_compiler
*tc
,
602 const struct tgsi_full_instruction
*tgsi_inst
,
606 assert(!"CLAMP untested");
608 tc_SEL(tc
, dst
[0], src
[0], src
[1], GEN6_COND_GE
);
609 tc_SEL(tc
, dst
[0], src
[2], tsrc_from(dst
[0]), GEN6_COND_L
);
613 aos_XPD(struct toy_compiler
*tc
,
614 const struct tgsi_full_instruction
*tgsi_inst
,
618 struct toy_dst tmp
= tc_alloc_tmp(tc
);
620 tc_MUL(tc
, tdst_writemask(tmp
, TOY_WRITEMASK_XYZ
),
621 tsrc_swizzle(src
[0], TOY_SWIZZLE_Z
, TOY_SWIZZLE_X
,
622 TOY_SWIZZLE_Y
, TOY_SWIZZLE_W
),
623 tsrc_swizzle(src
[1], TOY_SWIZZLE_Y
, TOY_SWIZZLE_Z
,
624 TOY_SWIZZLE_X
, TOY_SWIZZLE_W
));
626 tc_MAC(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_XYZ
),
627 tsrc_swizzle(src
[0], TOY_SWIZZLE_Y
, TOY_SWIZZLE_Z
,
628 TOY_SWIZZLE_X
, TOY_SWIZZLE_W
),
629 tsrc_swizzle(src
[1], TOY_SWIZZLE_Z
, TOY_SWIZZLE_X
,
630 TOY_SWIZZLE_Y
, TOY_SWIZZLE_W
),
631 tsrc_negate(tsrc_from(tmp
)));
633 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_W
),
638 aos_PK2H(struct toy_compiler
*tc
,
639 const struct tgsi_full_instruction
*tgsi_inst
,
643 const struct toy_src h1
= tsrc_ud(tsrc_swizzle1(src
[0], TOY_SWIZZLE_X
));
644 const struct toy_src h2
= tsrc_ud(tsrc_swizzle1(src
[0], TOY_SWIZZLE_Y
));
645 struct toy_dst tmp
= tdst_ud(tc_alloc_tmp(tc
));
647 assert(!"PK2H untested");
649 tc_SHL(tc
, tmp
, h2
, tsrc_imm_ud(16));
650 tc_OR(tc
, tdst_ud(dst
[0]), h1
, tsrc_from(tmp
));
654 aos_SFL(struct toy_compiler
*tc
,
655 const struct tgsi_full_instruction
*tgsi_inst
,
659 assert(!"SFL untested");
661 tc_MOV(tc
, dst
[0], tsrc_imm_f(0.0f
));
665 aos_STR(struct toy_compiler
*tc
,
666 const struct tgsi_full_instruction
*tgsi_inst
,
670 assert(!"STR untested");
672 tc_MOV(tc
, dst
[0], tsrc_imm_f(1.0f
));
676 aos_UP2H(struct toy_compiler
*tc
,
677 const struct tgsi_full_instruction
*tgsi_inst
,
681 assert(!"UP2H untested");
683 tc_AND(tc
, tdst_writemask(tdst_ud(dst
[0]), TOY_WRITEMASK_XZ
),
684 tsrc_ud(src
[0]), tsrc_imm_ud(0xffff));
685 tc_SHR(tc
, tdst_writemask(tdst_ud(dst
[0]), TOY_WRITEMASK_YW
),
686 tsrc_ud(src
[0]), tsrc_imm_ud(16));
690 aos_SCS(struct toy_compiler
*tc
,
691 const struct tgsi_full_instruction
*tgsi_inst
,
695 assert(!"SCS untested");
697 tc_add1(tc
, TOY_OPCODE_COS
,
698 tdst_writemask(dst
[0], TOY_WRITEMASK_X
), src
[0]);
700 tc_add1(tc
, TOY_OPCODE_SIN
,
701 tdst_writemask(dst
[0], TOY_WRITEMASK_Y
), src
[0]);
703 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_Z
), tsrc_imm_f(0.0f
));
704 tc_MOV(tc
, tdst_writemask(dst
[0], TOY_WRITEMASK_W
), tsrc_imm_f(1.0f
));
708 aos_DIV(struct toy_compiler
*tc
,
709 const struct tgsi_full_instruction
*tgsi_inst
,
713 struct toy_dst tmp
= tc_alloc_tmp(tc
);
715 assert(!"DIV untested");
717 tc_INV(tc
, tmp
, src
[1]);
718 tc_MUL(tc
, dst
[0], src
[0], tsrc_from(tmp
));
722 aos_BRK(struct toy_compiler
*tc
,
723 const struct tgsi_full_instruction
*tgsi_inst
,
727 tc_add0(tc
, GEN6_OPCODE_BREAK
);
731 aos_CEIL(struct toy_compiler
*tc
,
732 const struct tgsi_full_instruction
*tgsi_inst
,
736 struct toy_dst tmp
= tc_alloc_tmp(tc
);
738 tc_RNDD(tc
, tmp
, tsrc_negate(src
[0]));
739 tc_MOV(tc
, dst
[0], tsrc_negate(tsrc_from(tmp
)));
743 aos_SAD(struct toy_compiler
*tc
,
744 const struct tgsi_full_instruction
*tgsi_inst
,
748 struct toy_dst tmp
= tc_alloc_tmp(tc
);
750 assert(!"SAD untested");
752 tc_ADD(tc
, tmp
, src
[0], tsrc_negate(src
[1]));
753 tc_ADD(tc
, dst
[0], tsrc_absolute(tsrc_from(tmp
)), src
[2]);
757 aos_CONT(struct toy_compiler
*tc
,
758 const struct tgsi_full_instruction
*tgsi_inst
,
762 tc_add0(tc
, GEN6_OPCODE_CONT
);
766 aos_BGNLOOP(struct toy_compiler
*tc
,
767 const struct tgsi_full_instruction
*tgsi_inst
,
771 struct toy_inst
*inst
;
773 inst
= tc_add0(tc
, TOY_OPCODE_DO
);
774 /* this is just a marker */
779 aos_ENDLOOP(struct toy_compiler
*tc
,
780 const struct tgsi_full_instruction
*tgsi_inst
,
784 tc_add0(tc
, GEN6_OPCODE_WHILE
);
788 aos_unsupported(struct toy_compiler
*tc
,
789 const struct tgsi_full_instruction
*tgsi_inst
,
793 const char *name
= tgsi_get_opcode_name(tgsi_inst
->Instruction
.Opcode
);
795 ilo_warn("unsupported TGSI opcode: TGSI_OPCODE_%s\n", name
);
797 tc_fail(tc
, "unsupported TGSI instruction");
800 static const toy_tgsi_translate aos_translate_table
[TGSI_OPCODE_LAST
] = {
801 [TGSI_OPCODE_ARL
] = aos_simple
,
802 [TGSI_OPCODE_MOV
] = aos_simple
,
803 [TGSI_OPCODE_LIT
] = aos_LIT
,
804 [TGSI_OPCODE_RCP
] = aos_simple
,
805 [TGSI_OPCODE_RSQ
] = aos_simple
,
806 [TGSI_OPCODE_EXP
] = aos_EXP
,
807 [TGSI_OPCODE_LOG
] = aos_LOG
,
808 [TGSI_OPCODE_MUL
] = aos_simple
,
809 [TGSI_OPCODE_ADD
] = aos_simple
,
810 [TGSI_OPCODE_DP3
] = aos_simple
,
811 [TGSI_OPCODE_DP4
] = aos_simple
,
812 [TGSI_OPCODE_DST
] = aos_DST
,
813 [TGSI_OPCODE_MIN
] = aos_simple
,
814 [TGSI_OPCODE_MAX
] = aos_simple
,
815 [TGSI_OPCODE_SLT
] = aos_set_on_cond
,
816 [TGSI_OPCODE_SGE
] = aos_set_on_cond
,
817 [TGSI_OPCODE_MAD
] = aos_simple
,
818 [TGSI_OPCODE_SUB
] = aos_simple
,
819 [TGSI_OPCODE_LRP
] = aos_LRP
,
820 [TGSI_OPCODE_CND
] = aos_CND
,
821 [TGSI_OPCODE_SQRT
] = aos_simple
,
822 [TGSI_OPCODE_DP2A
] = aos_DP2A
,
823 [TGSI_OPCODE_FRC
] = aos_simple
,
824 [TGSI_OPCODE_CLAMP
] = aos_CLAMP
,
825 [TGSI_OPCODE_FLR
] = aos_simple
,
826 [TGSI_OPCODE_ROUND
] = aos_simple
,
827 [TGSI_OPCODE_EX2
] = aos_simple
,
828 [TGSI_OPCODE_LG2
] = aos_simple
,
829 [TGSI_OPCODE_POW
] = aos_simple
,
830 [TGSI_OPCODE_XPD
] = aos_XPD
,
831 [TGSI_OPCODE_ABS
] = aos_simple
,
832 [TGSI_OPCODE_DPH
] = aos_simple
,
833 [TGSI_OPCODE_COS
] = aos_simple
,
834 [TGSI_OPCODE_DDX
] = aos_unsupported
,
835 [TGSI_OPCODE_DDY
] = aos_unsupported
,
836 [TGSI_OPCODE_KILL
] = aos_simple
,
837 [TGSI_OPCODE_PK2H
] = aos_PK2H
,
838 [TGSI_OPCODE_PK2US
] = aos_unsupported
,
839 [TGSI_OPCODE_PK4B
] = aos_unsupported
,
840 [TGSI_OPCODE_PK4UB
] = aos_unsupported
,
841 [TGSI_OPCODE_RFL
] = aos_unsupported
,
842 [TGSI_OPCODE_SEQ
] = aos_set_on_cond
,
843 [TGSI_OPCODE_SFL
] = aos_SFL
,
844 [TGSI_OPCODE_SGT
] = aos_set_on_cond
,
845 [TGSI_OPCODE_SIN
] = aos_simple
,
846 [TGSI_OPCODE_SLE
] = aos_set_on_cond
,
847 [TGSI_OPCODE_SNE
] = aos_set_on_cond
,
848 [TGSI_OPCODE_STR
] = aos_STR
,
849 [TGSI_OPCODE_TEX
] = aos_tex
,
850 [TGSI_OPCODE_TXD
] = aos_tex
,
851 [TGSI_OPCODE_TXP
] = aos_tex
,
852 [TGSI_OPCODE_UP2H
] = aos_UP2H
,
853 [TGSI_OPCODE_UP2US
] = aos_unsupported
,
854 [TGSI_OPCODE_UP4B
] = aos_unsupported
,
855 [TGSI_OPCODE_UP4UB
] = aos_unsupported
,
856 [TGSI_OPCODE_X2D
] = aos_unsupported
,
857 [TGSI_OPCODE_ARR
] = aos_simple
,
858 [TGSI_OPCODE_BRA
] = aos_unsupported
,
859 [TGSI_OPCODE_CAL
] = aos_unsupported
,
860 [TGSI_OPCODE_RET
] = aos_unsupported
,
861 [TGSI_OPCODE_SSG
] = aos_set_sign
,
862 [TGSI_OPCODE_CMP
] = aos_compare
,
863 [TGSI_OPCODE_SCS
] = aos_SCS
,
864 [TGSI_OPCODE_TXB
] = aos_tex
,
865 [TGSI_OPCODE_DIV
] = aos_DIV
,
866 [TGSI_OPCODE_DP2
] = aos_simple
,
867 [TGSI_OPCODE_TXL
] = aos_tex
,
868 [TGSI_OPCODE_BRK
] = aos_BRK
,
869 [TGSI_OPCODE_IF
] = aos_simple
,
870 [TGSI_OPCODE_UIF
] = aos_simple
,
871 [TGSI_OPCODE_ELSE
] = aos_simple
,
872 [TGSI_OPCODE_ENDIF
] = aos_simple
,
873 [TGSI_OPCODE_PUSHA
] = aos_unsupported
,
874 [TGSI_OPCODE_POPA
] = aos_unsupported
,
875 [TGSI_OPCODE_CEIL
] = aos_CEIL
,
876 [TGSI_OPCODE_I2F
] = aos_simple
,
877 [TGSI_OPCODE_NOT
] = aos_simple
,
878 [TGSI_OPCODE_TRUNC
] = aos_simple
,
879 [TGSI_OPCODE_SHL
] = aos_simple
,
880 [TGSI_OPCODE_AND
] = aos_simple
,
881 [TGSI_OPCODE_OR
] = aos_simple
,
882 [TGSI_OPCODE_MOD
] = aos_simple
,
883 [TGSI_OPCODE_XOR
] = aos_simple
,
884 [TGSI_OPCODE_SAD
] = aos_SAD
,
885 [TGSI_OPCODE_TXF
] = aos_tex
,
886 [TGSI_OPCODE_TXQ
] = aos_tex
,
887 [TGSI_OPCODE_CONT
] = aos_CONT
,
888 [TGSI_OPCODE_EMIT
] = aos_simple
,
889 [TGSI_OPCODE_ENDPRIM
] = aos_simple
,
890 [TGSI_OPCODE_BGNLOOP
] = aos_BGNLOOP
,
891 [TGSI_OPCODE_BGNSUB
] = aos_unsupported
,
892 [TGSI_OPCODE_ENDLOOP
] = aos_ENDLOOP
,
893 [TGSI_OPCODE_ENDSUB
] = aos_unsupported
,
894 [TGSI_OPCODE_TXQ_LZ
] = aos_tex
,
895 [TGSI_OPCODE_NOP
] = aos_simple
,
896 [TGSI_OPCODE_FSEQ
] = aos_set_on_cond
,
897 [TGSI_OPCODE_FSGE
] = aos_set_on_cond
,
898 [TGSI_OPCODE_FSLT
] = aos_set_on_cond
,
899 [TGSI_OPCODE_FSNE
] = aos_set_on_cond
,
900 [TGSI_OPCODE_CALLNZ
] = aos_unsupported
,
901 [TGSI_OPCODE_BREAKC
] = aos_unsupported
,
902 [TGSI_OPCODE_KILL_IF
] = aos_simple
,
903 [TGSI_OPCODE_END
] = aos_simple
,
904 [TGSI_OPCODE_F2I
] = aos_simple
,
905 [TGSI_OPCODE_IDIV
] = aos_simple
,
906 [TGSI_OPCODE_IMAX
] = aos_simple
,
907 [TGSI_OPCODE_IMIN
] = aos_simple
,
908 [TGSI_OPCODE_INEG
] = aos_simple
,
909 [TGSI_OPCODE_ISGE
] = aos_set_on_cond
,
910 [TGSI_OPCODE_ISHR
] = aos_simple
,
911 [TGSI_OPCODE_ISLT
] = aos_set_on_cond
,
912 [TGSI_OPCODE_F2U
] = aos_simple
,
913 [TGSI_OPCODE_U2F
] = aos_simple
,
914 [TGSI_OPCODE_UADD
] = aos_simple
,
915 [TGSI_OPCODE_UDIV
] = aos_simple
,
916 [TGSI_OPCODE_UMAD
] = aos_simple
,
917 [TGSI_OPCODE_UMAX
] = aos_simple
,
918 [TGSI_OPCODE_UMIN
] = aos_simple
,
919 [TGSI_OPCODE_UMOD
] = aos_simple
,
920 [TGSI_OPCODE_UMUL
] = aos_simple
,
921 [TGSI_OPCODE_USEQ
] = aos_set_on_cond
,
922 [TGSI_OPCODE_USGE
] = aos_set_on_cond
,
923 [TGSI_OPCODE_USHR
] = aos_simple
,
924 [TGSI_OPCODE_USLT
] = aos_set_on_cond
,
925 [TGSI_OPCODE_USNE
] = aos_set_on_cond
,
926 [TGSI_OPCODE_SWITCH
] = aos_unsupported
,
927 [TGSI_OPCODE_CASE
] = aos_unsupported
,
928 [TGSI_OPCODE_DEFAULT
] = aos_unsupported
,
929 [TGSI_OPCODE_ENDSWITCH
] = aos_unsupported
,
930 [TGSI_OPCODE_SAMPLE
] = aos_sample
,
931 [TGSI_OPCODE_SAMPLE_I
] = aos_sample
,
932 [TGSI_OPCODE_SAMPLE_I_MS
] = aos_sample
,
933 [TGSI_OPCODE_SAMPLE_B
] = aos_sample
,
934 [TGSI_OPCODE_SAMPLE_C
] = aos_sample
,
935 [TGSI_OPCODE_SAMPLE_C_LZ
] = aos_sample
,
936 [TGSI_OPCODE_SAMPLE_D
] = aos_sample
,
937 [TGSI_OPCODE_SAMPLE_L
] = aos_sample
,
938 [TGSI_OPCODE_GATHER4
] = aos_sample
,
939 [TGSI_OPCODE_SVIEWINFO
] = aos_sample
,
940 [TGSI_OPCODE_SAMPLE_POS
] = aos_sample
,
941 [TGSI_OPCODE_SAMPLE_INFO
] = aos_sample
,
942 [TGSI_OPCODE_UARL
] = aos_simple
,
943 [TGSI_OPCODE_UCMP
] = aos_compare
,
944 [TGSI_OPCODE_IABS
] = aos_simple
,
945 [TGSI_OPCODE_ISSG
] = aos_set_sign
,
946 [TGSI_OPCODE_LOAD
] = aos_unsupported
,
947 [TGSI_OPCODE_STORE
] = aos_unsupported
,
948 [TGSI_OPCODE_MFENCE
] = aos_unsupported
,
949 [TGSI_OPCODE_LFENCE
] = aos_unsupported
,
950 [TGSI_OPCODE_SFENCE
] = aos_unsupported
,
951 [TGSI_OPCODE_BARRIER
] = aos_unsupported
,
952 [TGSI_OPCODE_ATOMUADD
] = aos_unsupported
,
953 [TGSI_OPCODE_ATOMXCHG
] = aos_unsupported
,
954 [TGSI_OPCODE_ATOMCAS
] = aos_unsupported
,
955 [TGSI_OPCODE_ATOMAND
] = aos_unsupported
,
956 [TGSI_OPCODE_ATOMOR
] = aos_unsupported
,
957 [TGSI_OPCODE_ATOMXOR
] = aos_unsupported
,
958 [TGSI_OPCODE_ATOMUMIN
] = aos_unsupported
,
959 [TGSI_OPCODE_ATOMUMAX
] = aos_unsupported
,
960 [TGSI_OPCODE_ATOMIMIN
] = aos_unsupported
,
961 [TGSI_OPCODE_ATOMIMAX
] = aos_unsupported
,
962 [TGSI_OPCODE_TEX2
] = aos_tex
,
963 [TGSI_OPCODE_TXB2
] = aos_tex
,
964 [TGSI_OPCODE_TXL2
] = aos_tex
,
968 soa_passthrough(struct toy_compiler
*tc
,
969 const struct tgsi_full_instruction
*tgsi_inst
,
970 struct toy_dst
*dst_
,
971 struct toy_src
*src_
)
973 const toy_tgsi_translate translate
=
974 aos_translate_table
[tgsi_inst
->Instruction
.Opcode
];
976 translate(tc
, tgsi_inst
, dst_
, src_
);
980 soa_per_channel(struct toy_compiler
*tc
,
981 const struct tgsi_full_instruction
*tgsi_inst
,
982 struct toy_dst
*dst_
,
983 struct toy_src
*src_
)
985 struct toy_dst dst
[TGSI_FULL_MAX_DST_REGISTERS
][4];
986 struct toy_src src
[TGSI_FULL_MAX_SRC_REGISTERS
][4];
989 for (i
= 0; i
< tgsi_inst
->Instruction
.NumDstRegs
; i
++)
990 tdst_transpose(dst_
[i
], dst
[i
]);
991 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++)
992 tsrc_transpose(src_
[i
], src
[i
]);
994 /* emit the same instruction four times for the four channels */
995 for (ch
= 0; ch
< 4; ch
++) {
996 struct toy_dst aos_dst
[TGSI_FULL_MAX_DST_REGISTERS
];
997 struct toy_src aos_src
[TGSI_FULL_MAX_SRC_REGISTERS
];
999 for (i
= 0; i
< tgsi_inst
->Instruction
.NumDstRegs
; i
++)
1000 aos_dst
[i
] = dst
[i
][ch
];
1001 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++)
1002 aos_src
[i
] = src
[i
][ch
];
1004 aos_translate_table
[tgsi_inst
->Instruction
.Opcode
](tc
,
1005 tgsi_inst
, aos_dst
, aos_src
);
1010 soa_scalar_replicate(struct toy_compiler
*tc
,
1011 const struct tgsi_full_instruction
*tgsi_inst
,
1012 struct toy_dst
*dst_
,
1013 struct toy_src
*src_
)
1015 struct toy_dst dst0
[4], tmp
;
1016 struct toy_src srcx
[TGSI_FULL_MAX_SRC_REGISTERS
];
1019 assert(tgsi_inst
->Instruction
.NumDstRegs
== 1);
1021 tdst_transpose(dst_
[0], dst0
);
1022 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++) {
1023 struct toy_src tmp
[4];
1025 tsrc_transpose(src_
[i
], tmp
);
1026 /* only the X channels */
1030 tmp
= tc_alloc_tmp(tc
);
1032 opcode
= aos_simple_opcode_map
[tgsi_inst
->Instruction
.Opcode
].opcode
;
1035 switch (tgsi_inst
->Instruction
.Opcode
) {
1036 case TGSI_OPCODE_RCP
:
1037 case TGSI_OPCODE_RSQ
:
1038 case TGSI_OPCODE_SQRT
:
1039 case TGSI_OPCODE_EX2
:
1040 case TGSI_OPCODE_LG2
:
1041 case TGSI_OPCODE_COS
:
1042 case TGSI_OPCODE_SIN
:
1043 tc_add1(tc
, opcode
, tmp
, srcx
[0]);
1045 case TGSI_OPCODE_POW
:
1046 tc_add2(tc
, opcode
, tmp
, srcx
[0], srcx
[1]);
1049 assert(!"invalid soa_scalar_replicate() call");
1053 /* replicate the result */
1054 for (i
= 0; i
< 4; i
++)
1055 tc_MOV(tc
, dst0
[i
], tsrc_from(tmp
));
1059 soa_dot_product(struct toy_compiler
*tc
,
1060 const struct tgsi_full_instruction
*tgsi_inst
,
1061 struct toy_dst
*dst_
,
1062 struct toy_src
*src_
)
1064 struct toy_dst dst0
[4], tmp
;
1065 struct toy_src src
[TGSI_FULL_MAX_SRC_REGISTERS
][4];
1068 tdst_transpose(dst_
[0], dst0
);
1069 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++)
1070 tsrc_transpose(src_
[i
], src
[i
]);
1072 tmp
= tc_alloc_tmp(tc
);
1074 switch (tgsi_inst
->Instruction
.Opcode
) {
1075 case TGSI_OPCODE_DP2
:
1076 tc_MUL(tc
, tmp
, src
[0][1], src
[1][1]);
1077 tc_MAC(tc
, tmp
, src
[0][0], src
[1][0], tsrc_from(tmp
));
1079 case TGSI_OPCODE_DP2A
:
1080 tc_MAC(tc
, tmp
, src
[0][1], src
[1][1], src
[2][0]);
1081 tc_MAC(tc
, tmp
, src
[0][0], src
[1][0], tsrc_from(tmp
));
1083 case TGSI_OPCODE_DP3
:
1084 tc_MUL(tc
, tmp
, src
[0][2], src
[1][2]);
1085 tc_MAC(tc
, tmp
, src
[0][1], src
[1][1], tsrc_from(tmp
));
1086 tc_MAC(tc
, tmp
, src
[0][0], src
[1][0], tsrc_from(tmp
));
1088 case TGSI_OPCODE_DPH
:
1089 tc_MAC(tc
, tmp
, src
[0][2], src
[1][2], src
[1][3]);
1090 tc_MAC(tc
, tmp
, src
[0][1], src
[1][1], tsrc_from(tmp
));
1091 tc_MAC(tc
, tmp
, src
[0][0], src
[1][0], tsrc_from(tmp
));
1093 case TGSI_OPCODE_DP4
:
1094 tc_MUL(tc
, tmp
, src
[0][3], src
[1][3]);
1095 tc_MAC(tc
, tmp
, src
[0][2], src
[1][2], tsrc_from(tmp
));
1096 tc_MAC(tc
, tmp
, src
[0][1], src
[1][1], tsrc_from(tmp
));
1097 tc_MAC(tc
, tmp
, src
[0][0], src
[1][0], tsrc_from(tmp
));
1100 assert(!"invalid soa_dot_product() call");
1104 for (i
= 0; i
< 4; i
++)
1105 tc_MOV(tc
, dst0
[i
], tsrc_from(tmp
));
1109 soa_partial_derivative(struct toy_compiler
*tc
,
1110 const struct tgsi_full_instruction
*tgsi_inst
,
1111 struct toy_dst
*dst_
,
1112 struct toy_src
*src_
)
1114 if (tgsi_inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX
)
1115 tc_add1(tc
, TOY_OPCODE_DDX
, dst_
[0], src_
[0]);
1117 tc_add1(tc
, TOY_OPCODE_DDY
, dst_
[0], src_
[0]);
1121 soa_if(struct toy_compiler
*tc
,
1122 const struct tgsi_full_instruction
*tgsi_inst
,
1123 struct toy_dst
*dst_
,
1124 struct toy_src
*src_
)
1126 struct toy_src src0
[4];
1128 assert(tsrc_is_swizzle1(src_
[0]));
1129 tsrc_transpose(src_
[0], src0
);
1131 if (tgsi_inst
->Instruction
.Opcode
== TGSI_OPCODE_IF
)
1132 tc_IF(tc
, tdst_null(), src0
[0], tsrc_imm_f(0.0f
), GEN6_COND_NZ
);
1134 tc_IF(tc
, tdst_null(), src0
[0], tsrc_imm_d(0), GEN6_COND_NZ
);
1138 soa_LIT(struct toy_compiler
*tc
,
1139 const struct tgsi_full_instruction
*tgsi_inst
,
1140 struct toy_dst
*dst_
,
1141 struct toy_src
*src_
)
1143 struct toy_inst
*inst
;
1144 struct toy_dst dst0
[4];
1145 struct toy_src src0
[4];
1147 tdst_transpose(dst_
[0], dst0
);
1148 tsrc_transpose(src_
[0], src0
);
1150 tc_MOV(tc
, dst0
[0], tsrc_imm_f(1.0f
));
1151 tc_MOV(tc
, dst0
[1], src0
[0]);
1152 tc_POW(tc
, dst0
[2], src0
[1], src0
[3]);
1153 tc_MOV(tc
, dst0
[3], tsrc_imm_f(1.0f
));
1156 * POW is calculated first because math with pred_ctrl is broken here.
1159 tc_CMP(tc
, tdst_null(), src0
[0], tsrc_imm_f(0.0f
), GEN6_COND_L
);
1160 inst
= tc_MOV(tc
, dst0
[1], tsrc_imm_f(0.0f
));
1161 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
1162 inst
= tc_MOV(tc
, dst0
[2], tsrc_imm_f(0.0f
));
1163 inst
->pred_ctrl
= GEN6_PREDCTRL_NORMAL
;
1167 soa_EXP(struct toy_compiler
*tc
,
1168 const struct tgsi_full_instruction
*tgsi_inst
,
1169 struct toy_dst
*dst_
,
1170 struct toy_src
*src_
)
1172 struct toy_dst dst0
[4];
1173 struct toy_src src0
[4];
1175 assert(!"SoA EXP untested");
1177 tdst_transpose(dst_
[0], dst0
);
1178 tsrc_transpose(src_
[0], src0
);
1180 if (!tdst_is_null(dst0
[0])) {
1181 struct toy_dst tmp
= tdst_d(tc_alloc_tmp(tc
));
1183 tc_RNDD(tc
, tmp
, src0
[0]);
1185 /* construct the floating point number manually */
1186 tc_ADD(tc
, tmp
, tsrc_from(tmp
), tsrc_imm_d(127));
1187 tc_SHL(tc
, tdst_d(dst0
[0]), tsrc_from(tmp
), tsrc_imm_d(23));
1190 tc_FRC(tc
, dst0
[1], src0
[0]);
1191 tc_EXP(tc
, dst0
[2], src0
[0]);
1192 tc_MOV(tc
, dst0
[3], tsrc_imm_f(1.0f
));
1196 soa_LOG(struct toy_compiler
*tc
,
1197 const struct tgsi_full_instruction
*tgsi_inst
,
1198 struct toy_dst
*dst_
,
1199 struct toy_src
*src_
)
1201 struct toy_dst dst0
[4];
1202 struct toy_src src0
[4];
1204 assert(!"SoA LOG untested");
1206 tdst_transpose(dst_
[0], dst0
);
1207 tsrc_transpose(src_
[0], src0
);
1209 if (dst_
[0].writemask
& TOY_WRITEMASK_XY
) {
1210 struct toy_dst tmp
= tdst_d(tc_alloc_tmp(tc
));
1213 tc_SHR(tc
, tmp
, tsrc_absolute(tsrc_d(src0
[0])), tsrc_imm_d(23));
1214 tc_ADD(tc
, dst0
[0], tsrc_from(tmp
), tsrc_imm_d(-127));
1217 tc_AND(tc
, tmp
, tsrc_d(src0
[0]), tsrc_imm_d((1 << 23) - 1));
1218 tc_OR(tc
, dst0
[1], tsrc_from(tmp
), tsrc_imm_d(127 << 23));
1221 tc_LOG(tc
, dst0
[2], src0
[0]);
1222 tc_MOV(tc
, dst0
[3], tsrc_imm_f(1.0f
));
1226 soa_DST(struct toy_compiler
*tc
,
1227 const struct tgsi_full_instruction
*tgsi_inst
,
1228 struct toy_dst
*dst_
,
1229 struct toy_src
*src_
)
1231 struct toy_dst dst0
[4];
1232 struct toy_src src
[2][4];
1234 tdst_transpose(dst_
[0], dst0
);
1235 tsrc_transpose(src_
[0], src
[0]);
1236 tsrc_transpose(src_
[1], src
[1]);
1238 tc_MOV(tc
, dst0
[0], tsrc_imm_f(1.0f
));
1239 tc_MUL(tc
, dst0
[1], src
[0][1], src
[1][1]);
1240 tc_MOV(tc
, dst0
[2], src
[0][2]);
1241 tc_MOV(tc
, dst0
[3], src
[1][3]);
1245 soa_XPD(struct toy_compiler
*tc
,
1246 const struct tgsi_full_instruction
*tgsi_inst
,
1247 struct toy_dst
*dst_
,
1248 struct toy_src
*src_
)
1250 struct toy_dst dst0
[4];
1251 struct toy_src src
[2][4];
1253 tdst_transpose(dst_
[0], dst0
);
1254 tsrc_transpose(src_
[0], src
[0]);
1255 tsrc_transpose(src_
[1], src
[1]);
1257 /* dst.x = src0.y * src1.z - src1.y * src0.z */
1258 tc_MUL(tc
, dst0
[0], src
[0][2], src
[1][1]);
1259 tc_MAC(tc
, dst0
[0], src
[0][1], src
[1][2], tsrc_negate(tsrc_from(dst0
[0])));
1261 /* dst.y = src0.z * src1.x - src1.z * src0.x */
1262 tc_MUL(tc
, dst0
[1], src
[0][0], src
[1][2]);
1263 tc_MAC(tc
, dst0
[1], src
[0][2], src
[1][0], tsrc_negate(tsrc_from(dst0
[1])));
1265 /* dst.z = src0.x * src1.y - src1.x * src0.y */
1266 tc_MUL(tc
, dst0
[2], src
[0][1], src
[1][0]);
1267 tc_MAC(tc
, dst0
[2], src
[0][0], src
[1][1], tsrc_negate(tsrc_from(dst0
[2])));
1269 tc_MOV(tc
, dst0
[3], tsrc_imm_f(1.0f
));
1273 soa_PK2H(struct toy_compiler
*tc
,
1274 const struct tgsi_full_instruction
*tgsi_inst
,
1275 struct toy_dst
*dst_
,
1276 struct toy_src
*src_
)
1278 struct toy_dst tmp
= tdst_ud(tc_alloc_tmp(tc
));
1279 struct toy_dst dst0
[4];
1280 struct toy_src src0
[4];
1283 assert(!"SoA PK2H untested");
1285 tdst_transpose(dst_
[0], dst0
);
1286 tsrc_transpose(src_
[0], src0
);
1288 tc_SHL(tc
, tmp
, src0
[1], tsrc_imm_ud(16));
1289 tc_OR(tc
, tmp
, src0
[0], tsrc_from(tmp
));
1291 for (i
= 0; i
< 4; i
++)
1292 tc_MOV(tc
, dst0
[i
], tsrc_from(tmp
));
1296 soa_UP2H(struct toy_compiler
*tc
,
1297 const struct tgsi_full_instruction
*tgsi_inst
,
1298 struct toy_dst
*dst_
,
1299 struct toy_src
*src_
)
1301 struct toy_dst dst0
[4];
1302 struct toy_src src0
[4];
1304 assert(!"SoA UP2H untested");
1306 tdst_transpose(dst_
[0], dst0
);
1307 tsrc_transpose(src_
[0], src0
);
1309 tc_AND(tc
, tdst_ud(dst0
[0]), tsrc_ud(src0
[0]), tsrc_imm_ud(0xffff));
1310 tc_SHR(tc
, tdst_ud(dst0
[1]), tsrc_ud(src0
[1]), tsrc_imm_ud(16));
1311 tc_AND(tc
, tdst_ud(dst0
[2]), tsrc_ud(src0
[2]), tsrc_imm_ud(0xffff));
1312 tc_SHR(tc
, tdst_ud(dst0
[3]), tsrc_ud(src0
[3]), tsrc_imm_ud(16));
1317 soa_SCS(struct toy_compiler
*tc
,
1318 const struct tgsi_full_instruction
*tgsi_inst
,
1319 struct toy_dst
*dst_
,
1320 struct toy_src
*src_
)
1322 struct toy_dst dst0
[4];
1323 struct toy_src src0
[4];
1325 tdst_transpose(dst_
[0], dst0
);
1326 tsrc_transpose(src_
[0], src0
);
1328 tc_add1(tc
, TOY_OPCODE_COS
, dst0
[0], src0
[0]);
1329 tc_add1(tc
, TOY_OPCODE_SIN
, dst0
[1], src0
[0]);
1330 tc_MOV(tc
, dst0
[2], tsrc_imm_f(0.0f
));
1331 tc_MOV(tc
, dst0
[3], tsrc_imm_f(1.0f
));
1335 soa_unsupported(struct toy_compiler
*tc
,
1336 const struct tgsi_full_instruction
*tgsi_inst
,
1337 struct toy_dst
*dst_
,
1338 struct toy_src
*src_
)
1340 const struct tgsi_opcode_info
*info
=
1341 tgsi_get_opcode_info(tgsi_inst
->Instruction
.Opcode
);
1343 ilo_warn("unsupported TGSI opcode in SoA form: TGSI_OPCODE_%s\n",
1346 tc_fail(tc
, "unsupported TGSI instruction in SoA form");
1349 static const toy_tgsi_translate soa_translate_table
[TGSI_OPCODE_LAST
] = {
1350 [TGSI_OPCODE_ARL
] = soa_per_channel
,
1351 [TGSI_OPCODE_MOV
] = soa_per_channel
,
1352 [TGSI_OPCODE_LIT
] = soa_LIT
,
1353 [TGSI_OPCODE_RCP
] = soa_scalar_replicate
,
1354 [TGSI_OPCODE_RSQ
] = soa_scalar_replicate
,
1355 [TGSI_OPCODE_EXP
] = soa_EXP
,
1356 [TGSI_OPCODE_LOG
] = soa_LOG
,
1357 [TGSI_OPCODE_MUL
] = soa_per_channel
,
1358 [TGSI_OPCODE_ADD
] = soa_per_channel
,
1359 [TGSI_OPCODE_DP3
] = soa_dot_product
,
1360 [TGSI_OPCODE_DP4
] = soa_dot_product
,
1361 [TGSI_OPCODE_DST
] = soa_DST
,
1362 [TGSI_OPCODE_MIN
] = soa_per_channel
,
1363 [TGSI_OPCODE_MAX
] = soa_per_channel
,
1364 [TGSI_OPCODE_SLT
] = soa_per_channel
,
1365 [TGSI_OPCODE_SGE
] = soa_per_channel
,
1366 [TGSI_OPCODE_MAD
] = soa_per_channel
,
1367 [TGSI_OPCODE_SUB
] = soa_per_channel
,
1368 [TGSI_OPCODE_LRP
] = soa_per_channel
,
1369 [TGSI_OPCODE_CND
] = soa_per_channel
,
1370 [TGSI_OPCODE_SQRT
] = soa_scalar_replicate
,
1371 [TGSI_OPCODE_DP2A
] = soa_dot_product
,
1372 [TGSI_OPCODE_FRC
] = soa_per_channel
,
1373 [TGSI_OPCODE_CLAMP
] = soa_per_channel
,
1374 [TGSI_OPCODE_FLR
] = soa_per_channel
,
1375 [TGSI_OPCODE_ROUND
] = soa_per_channel
,
1376 [TGSI_OPCODE_EX2
] = soa_scalar_replicate
,
1377 [TGSI_OPCODE_LG2
] = soa_scalar_replicate
,
1378 [TGSI_OPCODE_POW
] = soa_scalar_replicate
,
1379 [TGSI_OPCODE_XPD
] = soa_XPD
,
1380 [TGSI_OPCODE_ABS
] = soa_per_channel
,
1381 [TGSI_OPCODE_DPH
] = soa_dot_product
,
1382 [TGSI_OPCODE_COS
] = soa_scalar_replicate
,
1383 [TGSI_OPCODE_DDX
] = soa_partial_derivative
,
1384 [TGSI_OPCODE_DDY
] = soa_partial_derivative
,
1385 [TGSI_OPCODE_KILL
] = soa_passthrough
,
1386 [TGSI_OPCODE_PK2H
] = soa_PK2H
,
1387 [TGSI_OPCODE_PK2US
] = soa_unsupported
,
1388 [TGSI_OPCODE_PK4B
] = soa_unsupported
,
1389 [TGSI_OPCODE_PK4UB
] = soa_unsupported
,
1390 [TGSI_OPCODE_RFL
] = soa_unsupported
,
1391 [TGSI_OPCODE_SEQ
] = soa_per_channel
,
1392 [TGSI_OPCODE_SFL
] = soa_per_channel
,
1393 [TGSI_OPCODE_SGT
] = soa_per_channel
,
1394 [TGSI_OPCODE_SIN
] = soa_scalar_replicate
,
1395 [TGSI_OPCODE_SLE
] = soa_per_channel
,
1396 [TGSI_OPCODE_SNE
] = soa_per_channel
,
1397 [TGSI_OPCODE_STR
] = soa_per_channel
,
1398 [TGSI_OPCODE_TEX
] = soa_passthrough
,
1399 [TGSI_OPCODE_TXD
] = soa_passthrough
,
1400 [TGSI_OPCODE_TXP
] = soa_passthrough
,
1401 [TGSI_OPCODE_UP2H
] = soa_UP2H
,
1402 [TGSI_OPCODE_UP2US
] = soa_unsupported
,
1403 [TGSI_OPCODE_UP4B
] = soa_unsupported
,
1404 [TGSI_OPCODE_UP4UB
] = soa_unsupported
,
1405 [TGSI_OPCODE_X2D
] = soa_unsupported
,
1406 [TGSI_OPCODE_ARR
] = soa_per_channel
,
1407 [TGSI_OPCODE_BRA
] = soa_unsupported
,
1408 [TGSI_OPCODE_CAL
] = soa_unsupported
,
1409 [TGSI_OPCODE_RET
] = soa_unsupported
,
1410 [TGSI_OPCODE_SSG
] = soa_per_channel
,
1411 [TGSI_OPCODE_CMP
] = soa_per_channel
,
1412 [TGSI_OPCODE_SCS
] = soa_SCS
,
1413 [TGSI_OPCODE_TXB
] = soa_passthrough
,
1414 [TGSI_OPCODE_DIV
] = soa_per_channel
,
1415 [TGSI_OPCODE_DP2
] = soa_dot_product
,
1416 [TGSI_OPCODE_TXL
] = soa_passthrough
,
1417 [TGSI_OPCODE_BRK
] = soa_passthrough
,
1418 [TGSI_OPCODE_IF
] = soa_if
,
1419 [TGSI_OPCODE_UIF
] = soa_if
,
1420 [TGSI_OPCODE_ELSE
] = soa_passthrough
,
1421 [TGSI_OPCODE_ENDIF
] = soa_passthrough
,
1422 [TGSI_OPCODE_PUSHA
] = soa_unsupported
,
1423 [TGSI_OPCODE_POPA
] = soa_unsupported
,
1424 [TGSI_OPCODE_CEIL
] = soa_per_channel
,
1425 [TGSI_OPCODE_I2F
] = soa_per_channel
,
1426 [TGSI_OPCODE_NOT
] = soa_per_channel
,
1427 [TGSI_OPCODE_TRUNC
] = soa_per_channel
,
1428 [TGSI_OPCODE_SHL
] = soa_per_channel
,
1429 [TGSI_OPCODE_AND
] = soa_per_channel
,
1430 [TGSI_OPCODE_OR
] = soa_per_channel
,
1431 [TGSI_OPCODE_MOD
] = soa_per_channel
,
1432 [TGSI_OPCODE_XOR
] = soa_per_channel
,
1433 [TGSI_OPCODE_SAD
] = soa_per_channel
,
1434 [TGSI_OPCODE_TXF
] = soa_passthrough
,
1435 [TGSI_OPCODE_TXQ
] = soa_passthrough
,
1436 [TGSI_OPCODE_CONT
] = soa_passthrough
,
1437 [TGSI_OPCODE_EMIT
] = soa_unsupported
,
1438 [TGSI_OPCODE_ENDPRIM
] = soa_unsupported
,
1439 [TGSI_OPCODE_BGNLOOP
] = soa_passthrough
,
1440 [TGSI_OPCODE_BGNSUB
] = soa_unsupported
,
1441 [TGSI_OPCODE_ENDLOOP
] = soa_passthrough
,
1442 [TGSI_OPCODE_ENDSUB
] = soa_unsupported
,
1443 [TGSI_OPCODE_TXQ_LZ
] = soa_passthrough
,
1444 [TGSI_OPCODE_NOP
] = soa_passthrough
,
1445 [TGSI_OPCODE_FSEQ
] = soa_per_channel
,
1446 [TGSI_OPCODE_FSGE
] = soa_per_channel
,
1447 [TGSI_OPCODE_FSLT
] = soa_per_channel
,
1448 [TGSI_OPCODE_FSNE
] = soa_per_channel
,
1449 [TGSI_OPCODE_CALLNZ
] = soa_unsupported
,
1450 [TGSI_OPCODE_BREAKC
] = soa_unsupported
,
1451 [TGSI_OPCODE_KILL_IF
] = soa_passthrough
,
1452 [TGSI_OPCODE_END
] = soa_passthrough
,
1453 [TGSI_OPCODE_F2I
] = soa_per_channel
,
1454 [TGSI_OPCODE_IDIV
] = soa_per_channel
,
1455 [TGSI_OPCODE_IMAX
] = soa_per_channel
,
1456 [TGSI_OPCODE_IMIN
] = soa_per_channel
,
1457 [TGSI_OPCODE_INEG
] = soa_per_channel
,
1458 [TGSI_OPCODE_ISGE
] = soa_per_channel
,
1459 [TGSI_OPCODE_ISHR
] = soa_per_channel
,
1460 [TGSI_OPCODE_ISLT
] = soa_per_channel
,
1461 [TGSI_OPCODE_F2U
] = soa_per_channel
,
1462 [TGSI_OPCODE_U2F
] = soa_per_channel
,
1463 [TGSI_OPCODE_UADD
] = soa_per_channel
,
1464 [TGSI_OPCODE_UDIV
] = soa_per_channel
,
1465 [TGSI_OPCODE_UMAD
] = soa_per_channel
,
1466 [TGSI_OPCODE_UMAX
] = soa_per_channel
,
1467 [TGSI_OPCODE_UMIN
] = soa_per_channel
,
1468 [TGSI_OPCODE_UMOD
] = soa_per_channel
,
1469 [TGSI_OPCODE_UMUL
] = soa_per_channel
,
1470 [TGSI_OPCODE_USEQ
] = soa_per_channel
,
1471 [TGSI_OPCODE_USGE
] = soa_per_channel
,
1472 [TGSI_OPCODE_USHR
] = soa_per_channel
,
1473 [TGSI_OPCODE_USLT
] = soa_per_channel
,
1474 [TGSI_OPCODE_USNE
] = soa_per_channel
,
1475 [TGSI_OPCODE_SWITCH
] = soa_unsupported
,
1476 [TGSI_OPCODE_CASE
] = soa_unsupported
,
1477 [TGSI_OPCODE_DEFAULT
] = soa_unsupported
,
1478 [TGSI_OPCODE_ENDSWITCH
] = soa_unsupported
,
1479 [TGSI_OPCODE_SAMPLE
] = soa_passthrough
,
1480 [TGSI_OPCODE_SAMPLE_I
] = soa_passthrough
,
1481 [TGSI_OPCODE_SAMPLE_I_MS
] = soa_passthrough
,
1482 [TGSI_OPCODE_SAMPLE_B
] = soa_passthrough
,
1483 [TGSI_OPCODE_SAMPLE_C
] = soa_passthrough
,
1484 [TGSI_OPCODE_SAMPLE_C_LZ
] = soa_passthrough
,
1485 [TGSI_OPCODE_SAMPLE_D
] = soa_passthrough
,
1486 [TGSI_OPCODE_SAMPLE_L
] = soa_passthrough
,
1487 [TGSI_OPCODE_GATHER4
] = soa_passthrough
,
1488 [TGSI_OPCODE_SVIEWINFO
] = soa_passthrough
,
1489 [TGSI_OPCODE_SAMPLE_POS
] = soa_passthrough
,
1490 [TGSI_OPCODE_SAMPLE_INFO
] = soa_passthrough
,
1491 [TGSI_OPCODE_UARL
] = soa_per_channel
,
1492 [TGSI_OPCODE_UCMP
] = soa_per_channel
,
1493 [TGSI_OPCODE_IABS
] = soa_per_channel
,
1494 [TGSI_OPCODE_ISSG
] = soa_per_channel
,
1495 [TGSI_OPCODE_LOAD
] = soa_unsupported
,
1496 [TGSI_OPCODE_STORE
] = soa_unsupported
,
1497 [TGSI_OPCODE_MFENCE
] = soa_unsupported
,
1498 [TGSI_OPCODE_LFENCE
] = soa_unsupported
,
1499 [TGSI_OPCODE_SFENCE
] = soa_unsupported
,
1500 [TGSI_OPCODE_BARRIER
] = soa_unsupported
,
1501 [TGSI_OPCODE_ATOMUADD
] = soa_unsupported
,
1502 [TGSI_OPCODE_ATOMXCHG
] = soa_unsupported
,
1503 [TGSI_OPCODE_ATOMCAS
] = soa_unsupported
,
1504 [TGSI_OPCODE_ATOMAND
] = soa_unsupported
,
1505 [TGSI_OPCODE_ATOMOR
] = soa_unsupported
,
1506 [TGSI_OPCODE_ATOMXOR
] = soa_unsupported
,
1507 [TGSI_OPCODE_ATOMUMIN
] = soa_unsupported
,
1508 [TGSI_OPCODE_ATOMUMAX
] = soa_unsupported
,
1509 [TGSI_OPCODE_ATOMIMIN
] = soa_unsupported
,
1510 [TGSI_OPCODE_ATOMIMAX
] = soa_unsupported
,
1511 [TGSI_OPCODE_TEX2
] = soa_passthrough
,
1512 [TGSI_OPCODE_TXB2
] = soa_passthrough
,
1513 [TGSI_OPCODE_TXL2
] = soa_passthrough
,
1517 ra_dst_is_indirect(const struct tgsi_full_dst_register
*d
)
1519 return (d
->Register
.Indirect
||
1520 (d
->Register
.Dimension
&& d
->Dimension
.Indirect
));
1524 ra_dst_index(const struct tgsi_full_dst_register
*d
)
1526 assert(!d
->Register
.Indirect
);
1527 return d
->Register
.Index
;
1531 ra_dst_dimension(const struct tgsi_full_dst_register
*d
)
1533 if (d
->Register
.Dimension
) {
1534 assert(!d
->Dimension
.Indirect
);
1535 return d
->Dimension
.Index
;
1543 ra_is_src_indirect(const struct tgsi_full_src_register
*s
)
1545 return (s
->Register
.Indirect
||
1546 (s
->Register
.Dimension
&& s
->Dimension
.Indirect
));
1550 ra_src_index(const struct tgsi_full_src_register
*s
)
1552 assert(!s
->Register
.Indirect
);
1553 return s
->Register
.Index
;
1557 ra_src_dimension(const struct tgsi_full_src_register
*s
)
1559 if (s
->Register
.Dimension
) {
1560 assert(!s
->Dimension
.Indirect
);
1561 return s
->Dimension
.Index
;
1569 * Infer the type of either the sources or the destination.
1571 static enum toy_type
1572 ra_infer_opcode_type(int tgsi_opcode
, bool is_dst
)
1574 enum tgsi_opcode_type type
;
1577 type
= tgsi_opcode_infer_dst_type(tgsi_opcode
);
1579 type
= tgsi_opcode_infer_src_type(tgsi_opcode
);
1582 case TGSI_TYPE_UNSIGNED
:
1584 case TGSI_TYPE_SIGNED
:
1586 case TGSI_TYPE_FLOAT
:
1588 case TGSI_TYPE_UNTYPED
:
1589 case TGSI_TYPE_VOID
:
1590 case TGSI_TYPE_DOUBLE
:
1592 assert(!"unsupported TGSI type");
1598 * Return the type of an operand of the specified instruction.
1600 static enum toy_type
1601 ra_get_type(struct toy_tgsi
*tgsi
, const struct tgsi_full_instruction
*tgsi_inst
,
1602 int operand
, bool is_dst
)
1605 enum tgsi_file_type file
;
1607 /* we need to look at both src and dst for MOV */
1608 /* XXX it should not be this complex */
1609 if (tgsi_inst
->Instruction
.Opcode
== TGSI_OPCODE_MOV
) {
1610 const enum tgsi_file_type dst_file
= tgsi_inst
->Dst
[0].Register
.File
;
1611 const enum tgsi_file_type src_file
= tgsi_inst
->Src
[0].Register
.File
;
1613 if (dst_file
== TGSI_FILE_ADDRESS
|| src_file
== TGSI_FILE_ADDRESS
) {
1616 else if (src_file
== TGSI_FILE_IMMEDIATE
&&
1617 !tgsi_inst
->Src
[0].Register
.Indirect
) {
1618 const int src_idx
= tgsi_inst
->Src
[0].Register
.Index
;
1619 type
= tgsi
->imm_data
.types
[src_idx
];
1622 /* this is the best we can do */
1628 else if (tgsi_inst
->Instruction
.Opcode
== TGSI_OPCODE_UCMP
) {
1629 if (!is_dst
&& operand
== 0)
1637 type
= ra_infer_opcode_type(tgsi_inst
->Instruction
.Opcode
, is_dst
);
1641 tgsi_inst
->Dst
[operand
].Register
.File
:
1642 tgsi_inst
->Src
[operand
].Register
.File
;
1644 case TGSI_FILE_SAMPLER
:
1645 case TGSI_FILE_RESOURCE
:
1646 case TGSI_FILE_SAMPLER_VIEW
:
1649 case TGSI_FILE_ADDRESS
:
1650 assert(type
== TOY_TYPE_D
);
1660 * Allocate a VRF register.
1663 ra_alloc_reg(struct toy_tgsi
*tgsi
, enum tgsi_file_type file
)
1665 const int count
= (tgsi
->aos
) ? 1 : 4;
1666 return tc_alloc_vrf(tgsi
->tc
, count
);
1670 * Construct the key for VRF mapping look-up.
1673 ra_get_map_key(enum tgsi_file_type file
, unsigned dim
, unsigned index
)
1677 /* this is ugly... */
1678 assert(file
< 1 << 4);
1679 assert(dim
< 1 << 12);
1680 assert(index
< 1 << 16);
1681 key
= (file
<< 28) | (dim
<< 16) | index
;
1683 return intptr_to_pointer(key
);
1687 * Map a TGSI register to a VRF register.
1690 ra_map_reg(struct toy_tgsi
*tgsi
, enum tgsi_file_type file
,
1691 int dim
, int index
, bool *is_new
)
1696 key
= ra_get_map_key(file
, dim
, index
);
1699 * because we allocate vrf from 1 and on, val is never NULL as long as the
1702 val
= util_hash_table_get(tgsi
->reg_mapping
, key
);
1704 vrf
= pointer_to_intptr(val
);
1710 vrf
= (intptr_t) ra_alloc_reg(tgsi
, file
);
1712 /* add to the mapping */
1713 val
= intptr_to_pointer(vrf
);
1714 util_hash_table_set(tgsi
->reg_mapping
, key
, val
);
1724 * Return true if the destination aliases any of the sources.
1727 ra_dst_is_aliasing(const struct tgsi_full_instruction
*tgsi_inst
, int dst_index
)
1729 const struct tgsi_full_dst_register
*d
= &tgsi_inst
->Dst
[dst_index
];
1732 /* we need a scratch register for indirect dst anyway */
1733 if (ra_dst_is_indirect(d
))
1736 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++) {
1737 const struct tgsi_full_src_register
*s
= &tgsi_inst
->Src
[i
];
1739 if (s
->Register
.File
!= d
->Register
.File
)
1743 * we can go on to check dimension and index respectively, but
1744 * keep it simple for now
1746 if (ra_is_src_indirect(s
))
1748 if (ra_src_dimension(s
) == ra_dst_dimension(d
) &&
1749 ra_src_index(s
) == ra_dst_index(d
))
1757 * Return the toy register for a TGSI destination operand.
1759 static struct toy_dst
1760 ra_get_dst(struct toy_tgsi
*tgsi
,
1761 const struct tgsi_full_instruction
*tgsi_inst
, int dst_index
,
1764 const struct tgsi_full_dst_register
*d
= &tgsi_inst
->Dst
[dst_index
];
1765 bool need_vrf
= false;
1768 switch (d
->Register
.File
) {
1769 case TGSI_FILE_NULL
:
1772 case TGSI_FILE_OUTPUT
:
1773 case TGSI_FILE_TEMPORARY
:
1774 case TGSI_FILE_ADDRESS
:
1775 case TGSI_FILE_PREDICATE
:
1779 assert(!"unhandled dst file");
1785 /* XXX we do not always need a scratch given the conditions... */
1786 const bool need_scratch
=
1787 (ra_dst_is_indirect(d
) || ra_dst_is_aliasing(tgsi_inst
, dst_index
) ||
1788 tgsi_inst
->Instruction
.Saturate
);
1789 const enum toy_type type
= ra_get_type(tgsi
, tgsi_inst
, dst_index
, true);
1793 vrf
= ra_alloc_reg(tgsi
, d
->Register
.File
);
1796 vrf
= ra_map_reg(tgsi
, d
->Register
.File
,
1797 ra_dst_dimension(d
), ra_dst_index(d
), NULL
);
1801 *is_scratch
= need_scratch
;
1803 dst
= tdst_full(TOY_FILE_VRF
, type
, TOY_RECT_LINEAR
,
1804 false, 0, d
->Register
.WriteMask
, vrf
* TOY_REG_WIDTH
);
1810 static struct toy_src
1811 ra_get_src_for_vrf(const struct tgsi_full_src_register
*s
,
1812 enum toy_type type
, int vrf
)
1814 return tsrc_full(TOY_FILE_VRF
, type
, TOY_RECT_LINEAR
,
1816 s
->Register
.SwizzleX
, s
->Register
.SwizzleY
,
1817 s
->Register
.SwizzleZ
, s
->Register
.SwizzleW
,
1818 s
->Register
.Absolute
, s
->Register
.Negate
,
1819 vrf
* TOY_REG_WIDTH
);
1823 init_tgsi_reg(struct toy_tgsi
*tgsi
, struct toy_inst
*inst
,
1824 enum tgsi_file_type file
, int index
,
1825 const struct tgsi_ind_register
*indirect
,
1826 const struct tgsi_dimension
*dimension
,
1827 const struct tgsi_ind_register
*dim_indirect
)
1832 /* src[0]: TGSI file */
1833 inst
->src
[num_src
++] = tsrc_imm_d(file
);
1835 /* src[1]: TGSI dimension */
1836 inst
->src
[num_src
++] = tsrc_imm_d((dimension
) ? dimension
->Index
: 0);
1838 /* src[2]: TGSI dimension indirection */
1840 const int vrf
= ra_map_reg(tgsi
, dim_indirect
->File
, 0,
1841 dim_indirect
->Index
, NULL
);
1843 src
= tsrc(TOY_FILE_VRF
, vrf
, 0);
1844 src
= tsrc_swizzle1(tsrc_d(src
), indirect
->Swizzle
);
1847 src
= tsrc_imm_d(0);
1850 inst
->src
[num_src
++] = src
;
1852 /* src[3]: TGSI index */
1853 inst
->src
[num_src
++] = tsrc_imm_d(index
);
1855 /* src[4]: TGSI index indirection */
1857 const int vrf
= ra_map_reg(tgsi
, indirect
->File
, 0,
1858 indirect
->Index
, NULL
);
1860 src
= tsrc(TOY_FILE_VRF
, vrf
, 0);
1861 src
= tsrc_swizzle1(tsrc_d(src
), indirect
->Swizzle
);
1864 src
= tsrc_imm_d(0);
1867 inst
->src
[num_src
++] = src
;
1872 static struct toy_src
1873 ra_get_src_indirect(struct toy_tgsi
*tgsi
,
1874 const struct tgsi_full_instruction
*tgsi_inst
,
1877 const struct tgsi_full_src_register
*s
= &tgsi_inst
->Src
[src_index
];
1878 bool need_vrf
= false, is_resource
= false;
1881 switch (s
->Register
.File
) {
1882 case TGSI_FILE_NULL
:
1885 case TGSI_FILE_SAMPLER
:
1886 case TGSI_FILE_RESOURCE
:
1887 case TGSI_FILE_SAMPLER_VIEW
:
1890 case TGSI_FILE_CONSTANT
:
1891 case TGSI_FILE_INPUT
:
1892 case TGSI_FILE_SYSTEM_VALUE
:
1893 case TGSI_FILE_TEMPORARY
:
1894 case TGSI_FILE_ADDRESS
:
1895 case TGSI_FILE_IMMEDIATE
:
1896 case TGSI_FILE_PREDICATE
:
1900 assert(!"unhandled src file");
1906 const enum toy_type type
= ra_get_type(tgsi
, tgsi_inst
, src_index
, false);
1910 assert(!s
->Register
.Dimension
);
1911 assert(s
->Register
.Indirect
);
1913 vrf
= ra_map_reg(tgsi
, s
->Indirect
.File
, 0, s
->Indirect
.Index
, NULL
);
1916 vrf
= ra_alloc_reg(tgsi
, s
->Register
.File
);
1919 src
= ra_get_src_for_vrf(s
, type
, vrf
);
1921 /* emit indirect fetch */
1923 struct toy_inst
*inst
;
1925 inst
= tc_add(tgsi
->tc
);
1926 inst
->opcode
= TOY_OPCODE_TGSI_INDIRECT_FETCH
;
1927 inst
->dst
= tdst_from(src
);
1928 inst
->dst
.writemask
= TOY_WRITEMASK_XYZW
;
1930 init_tgsi_reg(tgsi
, inst
, s
->Register
.File
, s
->Register
.Index
,
1931 (s
->Register
.Indirect
) ? &s
->Indirect
: NULL
,
1932 (s
->Register
.Dimension
) ? &s
->Dimension
: NULL
,
1933 (s
->Dimension
.Indirect
) ? &s
->DimIndirect
: NULL
);
1941 * Return the toy register for a TGSI source operand.
1943 static struct toy_src
1944 ra_get_src(struct toy_tgsi
*tgsi
,
1945 const struct tgsi_full_instruction
*tgsi_inst
,
1948 const struct tgsi_full_src_register
*s
= &tgsi_inst
->Src
[src_index
];
1949 bool need_vrf
= false;
1952 if (ra_is_src_indirect(s
))
1953 return ra_get_src_indirect(tgsi
, tgsi_inst
, src_index
);
1955 switch (s
->Register
.File
) {
1956 case TGSI_FILE_NULL
:
1959 case TGSI_FILE_CONSTANT
:
1960 case TGSI_FILE_INPUT
:
1961 case TGSI_FILE_SYSTEM_VALUE
:
1964 case TGSI_FILE_TEMPORARY
:
1965 case TGSI_FILE_ADDRESS
:
1966 case TGSI_FILE_PREDICATE
:
1969 case TGSI_FILE_SAMPLER
:
1970 case TGSI_FILE_RESOURCE
:
1971 case TGSI_FILE_SAMPLER_VIEW
:
1972 assert(!s
->Register
.Dimension
);
1973 src
= tsrc_imm_d(s
->Register
.Index
);
1975 case TGSI_FILE_IMMEDIATE
:
1977 const uint32_t *imm
;
1978 enum toy_type imm_type
;
1981 imm
= toy_tgsi_get_imm(tgsi
, s
->Register
.Index
, &imm_type
);
1984 (imm
[s
->Register
.SwizzleX
] == imm
[s
->Register
.SwizzleY
] &&
1985 imm
[s
->Register
.SwizzleX
] == imm
[s
->Register
.SwizzleZ
] &&
1986 imm
[s
->Register
.SwizzleX
] == imm
[s
->Register
.SwizzleW
]);
1989 const enum toy_type type
=
1990 ra_get_type(tgsi
, tgsi_inst
, src_index
, false);
1992 /* ignore imm_type */
1993 src
= tsrc_imm_ud(imm
[s
->Register
.SwizzleX
]);
1995 src
.absolute
= s
->Register
.Absolute
;
1996 src
.negate
= s
->Register
.Negate
;
2004 assert(!"unhandled src file");
2010 const enum toy_type type
= ra_get_type(tgsi
, tgsi_inst
, src_index
, false);
2014 vrf
= ra_map_reg(tgsi
, s
->Register
.File
,
2015 ra_src_dimension(s
), ra_src_index(s
), &is_new
);
2017 src
= ra_get_src_for_vrf(s
, type
, vrf
);
2020 switch (s
->Register
.File
) {
2021 case TGSI_FILE_TEMPORARY
:
2022 case TGSI_FILE_ADDRESS
:
2023 case TGSI_FILE_PREDICATE
:
2025 struct toy_dst dst
= tdst_from(src
);
2026 dst
.writemask
= TOY_WRITEMASK_XYZW
;
2028 /* always initialize registers before use */
2030 tc_MOV(tgsi
->tc
, dst
, tsrc_type(tsrc_imm_d(0), type
));
2033 struct toy_dst tdst
[4];
2036 tdst_transpose(dst
, tdst
);
2038 for (i
= 0; i
< 4; i
++) {
2039 tc_MOV(tgsi
->tc
, tdst
[i
],
2040 tsrc_type(tsrc_imm_d(0), type
));
2056 parse_instruction(struct toy_tgsi
*tgsi
,
2057 const struct tgsi_full_instruction
*tgsi_inst
)
2059 struct toy_dst dst
[TGSI_FULL_MAX_DST_REGISTERS
];
2060 struct toy_src src
[TGSI_FULL_MAX_SRC_REGISTERS
];
2061 bool dst_is_scratch
[TGSI_FULL_MAX_DST_REGISTERS
];
2062 toy_tgsi_translate translate
;
2065 /* convert TGSI registers to toy registers */
2066 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++)
2067 src
[i
] = ra_get_src(tgsi
, tgsi_inst
, i
);
2068 for (i
= 0; i
< tgsi_inst
->Instruction
.NumDstRegs
; i
++)
2069 dst
[i
] = ra_get_dst(tgsi
, tgsi_inst
, i
, &dst_is_scratch
[i
]);
2071 /* translate the instruction */
2072 translate
= tgsi
->translate_table
[tgsi_inst
->Instruction
.Opcode
];
2074 if (tgsi
->translate_table
== soa_translate_table
)
2075 soa_unsupported(tgsi
->tc
, tgsi_inst
, dst
, src
);
2077 aos_unsupported(tgsi
->tc
, tgsi_inst
, dst
, src
);
2079 translate(tgsi
->tc
, tgsi_inst
, dst
, src
);
2081 /* write the result to the real destinations if needed */
2082 for (i
= 0; i
< tgsi_inst
->Instruction
.NumDstRegs
; i
++) {
2083 const struct tgsi_full_dst_register
*d
= &tgsi_inst
->Dst
[i
];
2085 if (!dst_is_scratch
[i
])
2088 if (tgsi_inst
->Instruction
.Saturate
== TGSI_SAT_MINUS_PLUS_ONE
)
2089 tc_fail(tgsi
->tc
, "TGSI_SAT_MINUS_PLUS_ONE unhandled");
2091 tgsi
->tc
->templ
.saturate
= tgsi_inst
->Instruction
.Saturate
;
2093 /* emit indirect store */
2094 if (ra_dst_is_indirect(d
)) {
2095 struct toy_inst
*inst
;
2097 inst
= tc_add(tgsi
->tc
);
2098 inst
->opcode
= TOY_OPCODE_TGSI_INDIRECT_STORE
;
2101 init_tgsi_reg(tgsi
, inst
, d
->Register
.File
, d
->Register
.Index
,
2102 (d
->Register
.Indirect
) ? &d
->Indirect
: NULL
,
2103 (d
->Register
.Dimension
) ? &d
->Dimension
: NULL
,
2104 (d
->Dimension
.Indirect
) ? &d
->DimIndirect
: NULL
);
2107 const enum toy_type type
= ra_get_type(tgsi
, tgsi_inst
, i
, true);
2108 struct toy_dst real_dst
;
2111 vrf
= ra_map_reg(tgsi
, d
->Register
.File
,
2112 ra_dst_dimension(d
), ra_dst_index(d
), NULL
);
2113 real_dst
= tdst_full(TOY_FILE_VRF
, type
, TOY_RECT_LINEAR
,
2114 false, 0, d
->Register
.WriteMask
, vrf
* TOY_REG_WIDTH
);
2117 tc_MOV(tgsi
->tc
, real_dst
, tsrc_from(dst
[i
]));
2120 struct toy_dst tdst
[4];
2121 struct toy_src tsrc
[4];
2124 tdst_transpose(real_dst
, tdst
);
2125 tsrc_transpose(tsrc_from(dst
[i
]), tsrc
);
2127 for (j
= 0; j
< 4; j
++)
2128 tc_MOV(tgsi
->tc
, tdst
[j
], tsrc
[j
]);
2132 tgsi
->tc
->templ
.saturate
= false;
2135 switch (tgsi_inst
->Instruction
.Opcode
) {
2136 case TGSI_OPCODE_KILL_IF
:
2137 case TGSI_OPCODE_KILL
:
2138 tgsi
->uses_kill
= true;
2142 for (i
= 0; i
< tgsi_inst
->Instruction
.NumSrcRegs
; i
++) {
2143 const struct tgsi_full_src_register
*s
= &tgsi_inst
->Src
[i
];
2144 if (s
->Register
.File
== TGSI_FILE_CONSTANT
&& s
->Register
.Indirect
)
2145 tgsi
->const_indirect
= true;
2148 /* remember channels written */
2149 for (i
= 0; i
< tgsi_inst
->Instruction
.NumDstRegs
; i
++) {
2150 const struct tgsi_full_dst_register
*d
= &tgsi_inst
->Dst
[i
];
2152 if (d
->Register
.File
!= TGSI_FILE_OUTPUT
)
2154 for (i
= 0; i
< tgsi
->num_outputs
; i
++) {
2155 if (tgsi
->outputs
[i
].index
== d
->Register
.Index
) {
2156 tgsi
->outputs
[i
].undefined_mask
&= ~d
->Register
.WriteMask
;
2164 decl_add_in(struct toy_tgsi
*tgsi
, const struct tgsi_full_declaration
*decl
)
2166 static const struct tgsi_declaration_interp default_interp
= {
2167 TGSI_INTERPOLATE_PERSPECTIVE
, false, 0,
2169 const struct tgsi_declaration_interp
*interp
=
2170 (decl
->Declaration
.Interpolate
) ? &decl
->Interp
: &default_interp
;
2173 if (decl
->Range
.Last
>= Elements(tgsi
->inputs
)) {
2174 assert(!"invalid IN");
2178 for (index
= decl
->Range
.First
; index
<= decl
->Range
.Last
; index
++) {
2179 const int slot
= tgsi
->num_inputs
++;
2181 tgsi
->inputs
[slot
].index
= index
;
2182 tgsi
->inputs
[slot
].usage_mask
= decl
->Declaration
.UsageMask
;
2183 if (decl
->Declaration
.Semantic
) {
2184 tgsi
->inputs
[slot
].semantic_name
= decl
->Semantic
.Name
;
2185 tgsi
->inputs
[slot
].semantic_index
= decl
->Semantic
.Index
;
2188 tgsi
->inputs
[slot
].semantic_name
= TGSI_SEMANTIC_GENERIC
;
2189 tgsi
->inputs
[slot
].semantic_index
= index
;
2191 tgsi
->inputs
[slot
].interp
= interp
->Interpolate
;
2192 tgsi
->inputs
[slot
].centroid
= interp
->Location
== TGSI_INTERPOLATE_LOC_CENTROID
;
2197 decl_add_out(struct toy_tgsi
*tgsi
, const struct tgsi_full_declaration
*decl
)
2201 if (decl
->Range
.Last
>= Elements(tgsi
->outputs
)) {
2202 assert(!"invalid OUT");
2206 assert(decl
->Declaration
.Semantic
);
2208 for (index
= decl
->Range
.First
; index
<= decl
->Range
.Last
; index
++) {
2209 const int slot
= tgsi
->num_outputs
++;
2211 tgsi
->outputs
[slot
].index
= index
;
2212 tgsi
->outputs
[slot
].undefined_mask
= TOY_WRITEMASK_XYZW
;
2213 tgsi
->outputs
[slot
].usage_mask
= decl
->Declaration
.UsageMask
;
2214 tgsi
->outputs
[slot
].semantic_name
= decl
->Semantic
.Name
;
2215 tgsi
->outputs
[slot
].semantic_index
= decl
->Semantic
.Index
;
2220 decl_add_sv(struct toy_tgsi
*tgsi
, const struct tgsi_full_declaration
*decl
)
2224 if (decl
->Range
.Last
>= Elements(tgsi
->system_values
)) {
2225 assert(!"invalid SV");
2229 for (index
= decl
->Range
.First
; index
<= decl
->Range
.Last
; index
++) {
2230 const int slot
= tgsi
->num_system_values
++;
2232 tgsi
->system_values
[slot
].index
= index
;
2233 if (decl
->Declaration
.Semantic
) {
2234 tgsi
->system_values
[slot
].semantic_name
= decl
->Semantic
.Name
;
2235 tgsi
->system_values
[slot
].semantic_index
= decl
->Semantic
.Index
;
2238 tgsi
->system_values
[slot
].semantic_name
= TGSI_SEMANTIC_GENERIC
;
2239 tgsi
->system_values
[slot
].semantic_index
= index
;
2245 * Emit an instruction to fetch the value of a TGSI register.
2248 fetch_source(struct toy_tgsi
*tgsi
, enum tgsi_file_type file
, int dim
, int idx
)
2252 enum toy_opcode opcode
;
2253 enum toy_type type
= TOY_TYPE_F
;
2256 case TGSI_FILE_INPUT
:
2257 opcode
= TOY_OPCODE_TGSI_IN
;
2259 case TGSI_FILE_CONSTANT
:
2260 opcode
= TOY_OPCODE_TGSI_CONST
;
2262 case TGSI_FILE_SYSTEM_VALUE
:
2263 opcode
= TOY_OPCODE_TGSI_SV
;
2265 case TGSI_FILE_IMMEDIATE
:
2266 opcode
= TOY_OPCODE_TGSI_IMM
;
2267 toy_tgsi_get_imm(tgsi
, idx
, &type
);
2270 /* no need to fetch */
2275 vrf
= ra_map_reg(tgsi
, file
, dim
, idx
, NULL
);
2276 dst
= tdst(TOY_FILE_VRF
, vrf
, 0);
2277 dst
= tdst_type(dst
, type
);
2279 tc_add2(tgsi
->tc
, opcode
, dst
, tsrc_imm_d(dim
), tsrc_imm_d(idx
));
2283 parse_declaration(struct toy_tgsi
*tgsi
,
2284 const struct tgsi_full_declaration
*decl
)
2288 switch (decl
->Declaration
.File
) {
2289 case TGSI_FILE_INPUT
:
2290 decl_add_in(tgsi
, decl
);
2292 case TGSI_FILE_OUTPUT
:
2293 decl_add_out(tgsi
, decl
);
2295 case TGSI_FILE_SYSTEM_VALUE
:
2296 decl_add_sv(tgsi
, decl
);
2298 case TGSI_FILE_IMMEDIATE
:
2299 /* immediates should be declared with TGSI_TOKEN_TYPE_IMMEDIATE */
2300 assert(!"unexpected immediate declaration");
2302 case TGSI_FILE_CONSTANT
:
2303 if (tgsi
->const_count
<= decl
->Range
.Last
)
2304 tgsi
->const_count
= decl
->Range
.Last
+ 1;
2306 case TGSI_FILE_NULL
:
2307 case TGSI_FILE_TEMPORARY
:
2308 case TGSI_FILE_SAMPLER
:
2309 case TGSI_FILE_PREDICATE
:
2310 case TGSI_FILE_ADDRESS
:
2311 case TGSI_FILE_RESOURCE
:
2312 case TGSI_FILE_SAMPLER_VIEW
:
2316 assert(!"unhandled TGSI file");
2320 /* fetch the registers now */
2321 for (i
= decl
->Range
.First
; i
<= decl
->Range
.Last
; i
++) {
2322 const int dim
= (decl
->Declaration
.Dimension
) ? decl
->Dim
.Index2D
: 0;
2323 fetch_source(tgsi
, decl
->Declaration
.File
, dim
, i
);
2328 add_imm(struct toy_tgsi
*tgsi
, enum toy_type type
, const uint32_t *buf
)
2330 /* reallocate the buffer if necessary */
2331 if (tgsi
->imm_data
.cur
>= tgsi
->imm_data
.size
) {
2332 const int cur_size
= tgsi
->imm_data
.size
;
2334 enum toy_type
*new_types
;
2335 uint32_t (*new_buf
)[4];
2337 new_size
= (cur_size
) ? cur_size
<< 1 : 16;
2338 while (new_size
<= tgsi
->imm_data
.cur
)
2341 new_buf
= REALLOC(tgsi
->imm_data
.buf
,
2342 cur_size
* sizeof(new_buf
[0]),
2343 new_size
* sizeof(new_buf
[0]));
2344 new_types
= REALLOC(tgsi
->imm_data
.types
,
2345 cur_size
* sizeof(new_types
[0]),
2346 new_size
* sizeof(new_types
[0]));
2347 if (!new_buf
|| !new_types
) {
2355 tgsi
->imm_data
.buf
= new_buf
;
2356 tgsi
->imm_data
.types
= new_types
;
2357 tgsi
->imm_data
.size
= new_size
;
2360 tgsi
->imm_data
.types
[tgsi
->imm_data
.cur
] = type
;
2361 memcpy(&tgsi
->imm_data
.buf
[tgsi
->imm_data
.cur
],
2362 buf
, sizeof(tgsi
->imm_data
.buf
[0]));
2364 return tgsi
->imm_data
.cur
++;
2368 parse_immediate(struct toy_tgsi
*tgsi
, const struct tgsi_full_immediate
*imm
)
2371 uint32_t imm_buf
[4];
2374 switch (imm
->Immediate
.DataType
) {
2375 case TGSI_IMM_FLOAT32
:
2377 imm_buf
[0] = fui(imm
->u
[0].Float
);
2378 imm_buf
[1] = fui(imm
->u
[1].Float
);
2379 imm_buf
[2] = fui(imm
->u
[2].Float
);
2380 imm_buf
[3] = fui(imm
->u
[3].Float
);
2382 case TGSI_IMM_INT32
:
2384 imm_buf
[0] = (uint32_t) imm
->u
[0].Int
;
2385 imm_buf
[1] = (uint32_t) imm
->u
[1].Int
;
2386 imm_buf
[2] = (uint32_t) imm
->u
[2].Int
;
2387 imm_buf
[3] = (uint32_t) imm
->u
[3].Int
;
2389 case TGSI_IMM_UINT32
:
2391 imm_buf
[0] = imm
->u
[0].Uint
;
2392 imm_buf
[1] = imm
->u
[1].Uint
;
2393 imm_buf
[2] = imm
->u
[2].Uint
;
2394 imm_buf
[3] = imm
->u
[3].Uint
;
2397 assert(!"unhandled TGSI imm type");
2399 memset(imm_buf
, 0, sizeof(imm_buf
));
2403 idx
= add_imm(tgsi
, type
, imm_buf
);
2405 fetch_source(tgsi
, TGSI_FILE_IMMEDIATE
, 0, idx
);
2407 tc_fail(tgsi
->tc
, "failed to add TGSI imm");
2411 parse_property(struct toy_tgsi
*tgsi
, const struct tgsi_full_property
*prop
)
2413 switch (prop
->Property
.PropertyName
) {
2414 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
2415 tgsi
->props
.vs_prohibit_ucps
= prop
->u
[0].Data
;
2417 case TGSI_PROPERTY_FS_COORD_ORIGIN
:
2418 tgsi
->props
.fs_coord_origin
= prop
->u
[0].Data
;
2420 case TGSI_PROPERTY_FS_COORD_PIXEL_CENTER
:
2421 tgsi
->props
.fs_coord_pixel_center
= prop
->u
[0].Data
;
2423 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
2424 tgsi
->props
.fs_color0_writes_all_cbufs
= prop
->u
[0].Data
;
2426 case TGSI_PROPERTY_FS_DEPTH_LAYOUT
:
2427 tgsi
->props
.fs_depth_layout
= prop
->u
[0].Data
;
2429 case TGSI_PROPERTY_GS_INPUT_PRIM
:
2430 tgsi
->props
.gs_input_prim
= prop
->u
[0].Data
;
2432 case TGSI_PROPERTY_GS_OUTPUT_PRIM
:
2433 tgsi
->props
.gs_output_prim
= prop
->u
[0].Data
;
2435 case TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
:
2436 tgsi
->props
.gs_max_output_vertices
= prop
->u
[0].Data
;
2439 assert(!"unhandled TGSI property");
2445 parse_token(struct toy_tgsi
*tgsi
, const union tgsi_full_token
*token
)
2447 switch (token
->Token
.Type
) {
2448 case TGSI_TOKEN_TYPE_DECLARATION
:
2449 parse_declaration(tgsi
, &token
->FullDeclaration
);
2451 case TGSI_TOKEN_TYPE_IMMEDIATE
:
2452 parse_immediate(tgsi
, &token
->FullImmediate
);
2454 case TGSI_TOKEN_TYPE_INSTRUCTION
:
2455 parse_instruction(tgsi
, &token
->FullInstruction
);
2457 case TGSI_TOKEN_TYPE_PROPERTY
:
2458 parse_property(tgsi
, &token
->FullProperty
);
2461 assert(!"unhandled TGSI token type");
2466 static enum pipe_error
2467 dump_reg_mapping(void *key
, void *val
, void *data
)
2469 int tgsi_file
, tgsi_dim
, tgsi_index
;
2472 sig
= (uint32_t) pointer_to_intptr(key
);
2473 vrf
= (uint32_t) pointer_to_intptr(val
);
2475 /* see ra_get_map_key() */
2476 tgsi_file
= (sig
>> 28) & 0xf;
2477 tgsi_dim
= (sig
>> 16) & 0xfff;
2478 tgsi_index
= (sig
>> 0) & 0xffff;
2481 ilo_printf(" v%d:\t%s[%d][%d]\n", vrf
,
2482 tgsi_file_name(tgsi_file
), tgsi_dim
, tgsi_index
);
2485 ilo_printf(" v%d:\t%s[%d]\n", vrf
,
2486 tgsi_file_name(tgsi_file
), tgsi_index
);
2493 * Dump the TGSI translator, currently only the register mapping.
2496 toy_tgsi_dump(const struct toy_tgsi
*tgsi
)
2498 util_hash_table_foreach(tgsi
->reg_mapping
, dump_reg_mapping
, NULL
);
2502 * Clean up the TGSI translator.
2505 toy_tgsi_cleanup(struct toy_tgsi
*tgsi
)
2507 FREE(tgsi
->imm_data
.buf
);
2508 FREE(tgsi
->imm_data
.types
);
2510 util_hash_table_destroy(tgsi
->reg_mapping
);
2514 reg_mapping_hash(void *key
)
2516 return (unsigned) pointer_to_intptr(key
);
2520 reg_mapping_compare(void *key1
, void *key2
)
2522 return (key1
!= key2
);
2526 * Initialize the TGSI translator.
2529 init_tgsi(struct toy_tgsi
*tgsi
, struct toy_compiler
*tc
, bool aos
)
2531 memset(tgsi
, 0, sizeof(*tgsi
));
2535 tgsi
->translate_table
= (aos
) ? aos_translate_table
: soa_translate_table
;
2537 /* create a mapping of TGSI registers to VRF reigsters */
2539 util_hash_table_create(reg_mapping_hash
, reg_mapping_compare
);
2541 return (tgsi
->reg_mapping
!= NULL
);
2545 * Translate TGSI tokens into toy instructions.
2548 toy_compiler_translate_tgsi(struct toy_compiler
*tc
,
2549 const struct tgsi_token
*tokens
, bool aos
,
2550 struct toy_tgsi
*tgsi
)
2552 struct tgsi_parse_context parse
;
2554 if (!init_tgsi(tgsi
, tc
, aos
)) {
2555 tc_fail(tc
, "failed to initialize TGSI translator");
2559 tgsi_parse_init(&parse
, tokens
);
2560 while (!tgsi_parse_end_of_tokens(&parse
)) {
2561 tgsi_parse_token(&parse
);
2562 parse_token(tgsi
, &parse
.FullToken
);
2564 tgsi_parse_free(&parse
);
2568 * Map the TGSI register to VRF register.
2571 toy_tgsi_get_vrf(const struct toy_tgsi
*tgsi
,
2572 enum tgsi_file_type file
, int dimension
, int index
)
2576 key
= ra_get_map_key(file
, dimension
, index
);
2578 val
= util_hash_table_get(tgsi
->reg_mapping
, key
);
2580 return (val
) ? pointer_to_intptr(val
) : -1;