1 /**************************************************************************
3 * Copyright 2007-2008 VMware, Inc.
5 * Copyright 2009-2010 VMware, Inc. All rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 * TGSI interpreter/executor.
32 * Flow control information:
34 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
35 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
36 * care since a condition may be true for some quad components but false
37 * for other components.
39 * We basically execute all statements (even if they're in the part of
40 * an IF/ELSE clause that's "not taken") and use a special mask to
41 * control writing to destination registers. This is the ExecMask.
44 * The ExecMask is computed from three other masks (CondMask, LoopMask and
45 * ContMask) which are controlled by the flow control instructions (namely:
46 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
54 #include "pipe/p_compiler.h"
55 #include "pipe/p_state.h"
56 #include "pipe/p_shader_tokens.h"
57 #include "tgsi/tgsi_dump.h"
58 #include "tgsi/tgsi_parse.h"
59 #include "tgsi/tgsi_util.h"
60 #include "tgsi_exec.h"
61 #include "util/u_half.h"
62 #include "util/u_memory.h"
63 #include "util/u_math.h"
64 #include "util/rounding.h"
67 #define DEBUG_EXECUTION 0
72 #define TILE_TOP_LEFT 0
73 #define TILE_TOP_RIGHT 1
74 #define TILE_BOTTOM_LEFT 2
75 #define TILE_BOTTOM_RIGHT 3
77 union tgsi_double_channel
{
78 double d
[TGSI_QUAD_SIZE
];
79 unsigned u
[TGSI_QUAD_SIZE
][2];
80 uint64_t u64
[TGSI_QUAD_SIZE
];
81 int64_t i64
[TGSI_QUAD_SIZE
];
84 struct tgsi_double_vector
{
85 union tgsi_double_channel xy
;
86 union tgsi_double_channel zw
;
90 micro_abs(union tgsi_exec_channel
*dst
,
91 const union tgsi_exec_channel
*src
)
93 dst
->f
[0] = fabsf(src
->f
[0]);
94 dst
->f
[1] = fabsf(src
->f
[1]);
95 dst
->f
[2] = fabsf(src
->f
[2]);
96 dst
->f
[3] = fabsf(src
->f
[3]);
100 micro_arl(union tgsi_exec_channel
*dst
,
101 const union tgsi_exec_channel
*src
)
103 dst
->i
[0] = (int)floorf(src
->f
[0]);
104 dst
->i
[1] = (int)floorf(src
->f
[1]);
105 dst
->i
[2] = (int)floorf(src
->f
[2]);
106 dst
->i
[3] = (int)floorf(src
->f
[3]);
110 micro_arr(union tgsi_exec_channel
*dst
,
111 const union tgsi_exec_channel
*src
)
113 dst
->i
[0] = (int)floorf(src
->f
[0] + 0.5f
);
114 dst
->i
[1] = (int)floorf(src
->f
[1] + 0.5f
);
115 dst
->i
[2] = (int)floorf(src
->f
[2] + 0.5f
);
116 dst
->i
[3] = (int)floorf(src
->f
[3] + 0.5f
);
120 micro_ceil(union tgsi_exec_channel
*dst
,
121 const union tgsi_exec_channel
*src
)
123 dst
->f
[0] = ceilf(src
->f
[0]);
124 dst
->f
[1] = ceilf(src
->f
[1]);
125 dst
->f
[2] = ceilf(src
->f
[2]);
126 dst
->f
[3] = ceilf(src
->f
[3]);
130 micro_cmp(union tgsi_exec_channel
*dst
,
131 const union tgsi_exec_channel
*src0
,
132 const union tgsi_exec_channel
*src1
,
133 const union tgsi_exec_channel
*src2
)
135 dst
->f
[0] = src0
->f
[0] < 0.0f
? src1
->f
[0] : src2
->f
[0];
136 dst
->f
[1] = src0
->f
[1] < 0.0f
? src1
->f
[1] : src2
->f
[1];
137 dst
->f
[2] = src0
->f
[2] < 0.0f
? src1
->f
[2] : src2
->f
[2];
138 dst
->f
[3] = src0
->f
[3] < 0.0f
? src1
->f
[3] : src2
->f
[3];
142 micro_cos(union tgsi_exec_channel
*dst
,
143 const union tgsi_exec_channel
*src
)
145 dst
->f
[0] = cosf(src
->f
[0]);
146 dst
->f
[1] = cosf(src
->f
[1]);
147 dst
->f
[2] = cosf(src
->f
[2]);
148 dst
->f
[3] = cosf(src
->f
[3]);
152 micro_d2f(union tgsi_exec_channel
*dst
,
153 const union tgsi_double_channel
*src
)
155 dst
->f
[0] = (float)src
->d
[0];
156 dst
->f
[1] = (float)src
->d
[1];
157 dst
->f
[2] = (float)src
->d
[2];
158 dst
->f
[3] = (float)src
->d
[3];
162 micro_d2i(union tgsi_exec_channel
*dst
,
163 const union tgsi_double_channel
*src
)
165 dst
->i
[0] = (int)src
->d
[0];
166 dst
->i
[1] = (int)src
->d
[1];
167 dst
->i
[2] = (int)src
->d
[2];
168 dst
->i
[3] = (int)src
->d
[3];
172 micro_d2u(union tgsi_exec_channel
*dst
,
173 const union tgsi_double_channel
*src
)
175 dst
->u
[0] = (unsigned)src
->d
[0];
176 dst
->u
[1] = (unsigned)src
->d
[1];
177 dst
->u
[2] = (unsigned)src
->d
[2];
178 dst
->u
[3] = (unsigned)src
->d
[3];
181 micro_dabs(union tgsi_double_channel
*dst
,
182 const union tgsi_double_channel
*src
)
184 dst
->d
[0] = src
->d
[0] >= 0.0 ? src
->d
[0] : -src
->d
[0];
185 dst
->d
[1] = src
->d
[1] >= 0.0 ? src
->d
[1] : -src
->d
[1];
186 dst
->d
[2] = src
->d
[2] >= 0.0 ? src
->d
[2] : -src
->d
[2];
187 dst
->d
[3] = src
->d
[3] >= 0.0 ? src
->d
[3] : -src
->d
[3];
191 micro_dadd(union tgsi_double_channel
*dst
,
192 const union tgsi_double_channel
*src
)
194 dst
->d
[0] = src
[0].d
[0] + src
[1].d
[0];
195 dst
->d
[1] = src
[0].d
[1] + src
[1].d
[1];
196 dst
->d
[2] = src
[0].d
[2] + src
[1].d
[2];
197 dst
->d
[3] = src
[0].d
[3] + src
[1].d
[3];
201 micro_ddiv(union tgsi_double_channel
*dst
,
202 const union tgsi_double_channel
*src
)
204 dst
->d
[0] = src
[0].d
[0] / src
[1].d
[0];
205 dst
->d
[1] = src
[0].d
[1] / src
[1].d
[1];
206 dst
->d
[2] = src
[0].d
[2] / src
[1].d
[2];
207 dst
->d
[3] = src
[0].d
[3] / src
[1].d
[3];
211 micro_ddx(union tgsi_exec_channel
*dst
,
212 const union tgsi_exec_channel
*src
)
217 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
221 micro_ddy(union tgsi_exec_channel
*dst
,
222 const union tgsi_exec_channel
*src
)
227 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
231 micro_dmul(union tgsi_double_channel
*dst
,
232 const union tgsi_double_channel
*src
)
234 dst
->d
[0] = src
[0].d
[0] * src
[1].d
[0];
235 dst
->d
[1] = src
[0].d
[1] * src
[1].d
[1];
236 dst
->d
[2] = src
[0].d
[2] * src
[1].d
[2];
237 dst
->d
[3] = src
[0].d
[3] * src
[1].d
[3];
241 micro_dmax(union tgsi_double_channel
*dst
,
242 const union tgsi_double_channel
*src
)
244 dst
->d
[0] = src
[0].d
[0] > src
[1].d
[0] ? src
[0].d
[0] : src
[1].d
[0];
245 dst
->d
[1] = src
[0].d
[1] > src
[1].d
[1] ? src
[0].d
[1] : src
[1].d
[1];
246 dst
->d
[2] = src
[0].d
[2] > src
[1].d
[2] ? src
[0].d
[2] : src
[1].d
[2];
247 dst
->d
[3] = src
[0].d
[3] > src
[1].d
[3] ? src
[0].d
[3] : src
[1].d
[3];
251 micro_dmin(union tgsi_double_channel
*dst
,
252 const union tgsi_double_channel
*src
)
254 dst
->d
[0] = src
[0].d
[0] < src
[1].d
[0] ? src
[0].d
[0] : src
[1].d
[0];
255 dst
->d
[1] = src
[0].d
[1] < src
[1].d
[1] ? src
[0].d
[1] : src
[1].d
[1];
256 dst
->d
[2] = src
[0].d
[2] < src
[1].d
[2] ? src
[0].d
[2] : src
[1].d
[2];
257 dst
->d
[3] = src
[0].d
[3] < src
[1].d
[3] ? src
[0].d
[3] : src
[1].d
[3];
261 micro_dneg(union tgsi_double_channel
*dst
,
262 const union tgsi_double_channel
*src
)
264 dst
->d
[0] = -src
->d
[0];
265 dst
->d
[1] = -src
->d
[1];
266 dst
->d
[2] = -src
->d
[2];
267 dst
->d
[3] = -src
->d
[3];
271 micro_dslt(union tgsi_double_channel
*dst
,
272 const union tgsi_double_channel
*src
)
274 dst
->u
[0][0] = src
[0].d
[0] < src
[1].d
[0] ? ~0U : 0U;
275 dst
->u
[1][0] = src
[0].d
[1] < src
[1].d
[1] ? ~0U : 0U;
276 dst
->u
[2][0] = src
[0].d
[2] < src
[1].d
[2] ? ~0U : 0U;
277 dst
->u
[3][0] = src
[0].d
[3] < src
[1].d
[3] ? ~0U : 0U;
281 micro_dsne(union tgsi_double_channel
*dst
,
282 const union tgsi_double_channel
*src
)
284 dst
->u
[0][0] = src
[0].d
[0] != src
[1].d
[0] ? ~0U : 0U;
285 dst
->u
[1][0] = src
[0].d
[1] != src
[1].d
[1] ? ~0U : 0U;
286 dst
->u
[2][0] = src
[0].d
[2] != src
[1].d
[2] ? ~0U : 0U;
287 dst
->u
[3][0] = src
[0].d
[3] != src
[1].d
[3] ? ~0U : 0U;
291 micro_dsge(union tgsi_double_channel
*dst
,
292 const union tgsi_double_channel
*src
)
294 dst
->u
[0][0] = src
[0].d
[0] >= src
[1].d
[0] ? ~0U : 0U;
295 dst
->u
[1][0] = src
[0].d
[1] >= src
[1].d
[1] ? ~0U : 0U;
296 dst
->u
[2][0] = src
[0].d
[2] >= src
[1].d
[2] ? ~0U : 0U;
297 dst
->u
[3][0] = src
[0].d
[3] >= src
[1].d
[3] ? ~0U : 0U;
301 micro_dseq(union tgsi_double_channel
*dst
,
302 const union tgsi_double_channel
*src
)
304 dst
->u
[0][0] = src
[0].d
[0] == src
[1].d
[0] ? ~0U : 0U;
305 dst
->u
[1][0] = src
[0].d
[1] == src
[1].d
[1] ? ~0U : 0U;
306 dst
->u
[2][0] = src
[0].d
[2] == src
[1].d
[2] ? ~0U : 0U;
307 dst
->u
[3][0] = src
[0].d
[3] == src
[1].d
[3] ? ~0U : 0U;
311 micro_drcp(union tgsi_double_channel
*dst
,
312 const union tgsi_double_channel
*src
)
314 dst
->d
[0] = 1.0 / src
->d
[0];
315 dst
->d
[1] = 1.0 / src
->d
[1];
316 dst
->d
[2] = 1.0 / src
->d
[2];
317 dst
->d
[3] = 1.0 / src
->d
[3];
321 micro_dsqrt(union tgsi_double_channel
*dst
,
322 const union tgsi_double_channel
*src
)
324 dst
->d
[0] = sqrt(src
->d
[0]);
325 dst
->d
[1] = sqrt(src
->d
[1]);
326 dst
->d
[2] = sqrt(src
->d
[2]);
327 dst
->d
[3] = sqrt(src
->d
[3]);
331 micro_drsq(union tgsi_double_channel
*dst
,
332 const union tgsi_double_channel
*src
)
334 dst
->d
[0] = 1.0 / sqrt(src
->d
[0]);
335 dst
->d
[1] = 1.0 / sqrt(src
->d
[1]);
336 dst
->d
[2] = 1.0 / sqrt(src
->d
[2]);
337 dst
->d
[3] = 1.0 / sqrt(src
->d
[3]);
341 micro_dmad(union tgsi_double_channel
*dst
,
342 const union tgsi_double_channel
*src
)
344 dst
->d
[0] = src
[0].d
[0] * src
[1].d
[0] + src
[2].d
[0];
345 dst
->d
[1] = src
[0].d
[1] * src
[1].d
[1] + src
[2].d
[1];
346 dst
->d
[2] = src
[0].d
[2] * src
[1].d
[2] + src
[2].d
[2];
347 dst
->d
[3] = src
[0].d
[3] * src
[1].d
[3] + src
[2].d
[3];
351 micro_dfrac(union tgsi_double_channel
*dst
,
352 const union tgsi_double_channel
*src
)
354 dst
->d
[0] = src
->d
[0] - floor(src
->d
[0]);
355 dst
->d
[1] = src
->d
[1] - floor(src
->d
[1]);
356 dst
->d
[2] = src
->d
[2] - floor(src
->d
[2]);
357 dst
->d
[3] = src
->d
[3] - floor(src
->d
[3]);
361 micro_dldexp(union tgsi_double_channel
*dst
,
362 const union tgsi_double_channel
*src0
,
363 union tgsi_exec_channel
*src1
)
365 dst
->d
[0] = ldexp(src0
->d
[0], src1
->i
[0]);
366 dst
->d
[1] = ldexp(src0
->d
[1], src1
->i
[1]);
367 dst
->d
[2] = ldexp(src0
->d
[2], src1
->i
[2]);
368 dst
->d
[3] = ldexp(src0
->d
[3], src1
->i
[3]);
372 micro_dfracexp(union tgsi_double_channel
*dst
,
373 union tgsi_exec_channel
*dst_exp
,
374 const union tgsi_double_channel
*src
)
376 dst
->d
[0] = frexp(src
->d
[0], &dst_exp
->i
[0]);
377 dst
->d
[1] = frexp(src
->d
[1], &dst_exp
->i
[1]);
378 dst
->d
[2] = frexp(src
->d
[2], &dst_exp
->i
[2]);
379 dst
->d
[3] = frexp(src
->d
[3], &dst_exp
->i
[3]);
383 micro_exp2(union tgsi_exec_channel
*dst
,
384 const union tgsi_exec_channel
*src
)
387 dst
->f
[0] = util_fast_exp2(src
->f
[0]);
388 dst
->f
[1] = util_fast_exp2(src
->f
[1]);
389 dst
->f
[2] = util_fast_exp2(src
->f
[2]);
390 dst
->f
[3] = util_fast_exp2(src
->f
[3]);
393 /* Inf is okay for this instruction, so clamp it to silence assertions. */
395 union tgsi_exec_channel clamped
;
397 for (i
= 0; i
< 4; i
++) {
398 if (src
->f
[i
] > 127.99999f
) {
399 clamped
.f
[i
] = 127.99999f
;
400 } else if (src
->f
[i
] < -126.99999f
) {
401 clamped
.f
[i
] = -126.99999f
;
403 clamped
.f
[i
] = src
->f
[i
];
409 dst
->f
[0] = powf(2.0f
, src
->f
[0]);
410 dst
->f
[1] = powf(2.0f
, src
->f
[1]);
411 dst
->f
[2] = powf(2.0f
, src
->f
[2]);
412 dst
->f
[3] = powf(2.0f
, src
->f
[3]);
413 #endif /* FAST_MATH */
417 micro_f2d(union tgsi_double_channel
*dst
,
418 const union tgsi_exec_channel
*src
)
420 dst
->d
[0] = (double)src
->f
[0];
421 dst
->d
[1] = (double)src
->f
[1];
422 dst
->d
[2] = (double)src
->f
[2];
423 dst
->d
[3] = (double)src
->f
[3];
427 micro_flr(union tgsi_exec_channel
*dst
,
428 const union tgsi_exec_channel
*src
)
430 dst
->f
[0] = floorf(src
->f
[0]);
431 dst
->f
[1] = floorf(src
->f
[1]);
432 dst
->f
[2] = floorf(src
->f
[2]);
433 dst
->f
[3] = floorf(src
->f
[3]);
437 micro_frc(union tgsi_exec_channel
*dst
,
438 const union tgsi_exec_channel
*src
)
440 dst
->f
[0] = src
->f
[0] - floorf(src
->f
[0]);
441 dst
->f
[1] = src
->f
[1] - floorf(src
->f
[1]);
442 dst
->f
[2] = src
->f
[2] - floorf(src
->f
[2]);
443 dst
->f
[3] = src
->f
[3] - floorf(src
->f
[3]);
447 micro_i2d(union tgsi_double_channel
*dst
,
448 const union tgsi_exec_channel
*src
)
450 dst
->d
[0] = (double)src
->i
[0];
451 dst
->d
[1] = (double)src
->i
[1];
452 dst
->d
[2] = (double)src
->i
[2];
453 dst
->d
[3] = (double)src
->i
[3];
457 micro_iabs(union tgsi_exec_channel
*dst
,
458 const union tgsi_exec_channel
*src
)
460 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
461 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
462 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
463 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
467 micro_ineg(union tgsi_exec_channel
*dst
,
468 const union tgsi_exec_channel
*src
)
470 dst
->i
[0] = -src
->i
[0];
471 dst
->i
[1] = -src
->i
[1];
472 dst
->i
[2] = -src
->i
[2];
473 dst
->i
[3] = -src
->i
[3];
477 micro_lg2(union tgsi_exec_channel
*dst
,
478 const union tgsi_exec_channel
*src
)
481 dst
->f
[0] = util_fast_log2(src
->f
[0]);
482 dst
->f
[1] = util_fast_log2(src
->f
[1]);
483 dst
->f
[2] = util_fast_log2(src
->f
[2]);
484 dst
->f
[3] = util_fast_log2(src
->f
[3]);
486 dst
->f
[0] = logf(src
->f
[0]) * 1.442695f
;
487 dst
->f
[1] = logf(src
->f
[1]) * 1.442695f
;
488 dst
->f
[2] = logf(src
->f
[2]) * 1.442695f
;
489 dst
->f
[3] = logf(src
->f
[3]) * 1.442695f
;
494 micro_lrp(union tgsi_exec_channel
*dst
,
495 const union tgsi_exec_channel
*src0
,
496 const union tgsi_exec_channel
*src1
,
497 const union tgsi_exec_channel
*src2
)
499 dst
->f
[0] = src0
->f
[0] * (src1
->f
[0] - src2
->f
[0]) + src2
->f
[0];
500 dst
->f
[1] = src0
->f
[1] * (src1
->f
[1] - src2
->f
[1]) + src2
->f
[1];
501 dst
->f
[2] = src0
->f
[2] * (src1
->f
[2] - src2
->f
[2]) + src2
->f
[2];
502 dst
->f
[3] = src0
->f
[3] * (src1
->f
[3] - src2
->f
[3]) + src2
->f
[3];
506 micro_mad(union tgsi_exec_channel
*dst
,
507 const union tgsi_exec_channel
*src0
,
508 const union tgsi_exec_channel
*src1
,
509 const union tgsi_exec_channel
*src2
)
511 dst
->f
[0] = src0
->f
[0] * src1
->f
[0] + src2
->f
[0];
512 dst
->f
[1] = src0
->f
[1] * src1
->f
[1] + src2
->f
[1];
513 dst
->f
[2] = src0
->f
[2] * src1
->f
[2] + src2
->f
[2];
514 dst
->f
[3] = src0
->f
[3] * src1
->f
[3] + src2
->f
[3];
518 micro_mov(union tgsi_exec_channel
*dst
,
519 const union tgsi_exec_channel
*src
)
521 dst
->u
[0] = src
->u
[0];
522 dst
->u
[1] = src
->u
[1];
523 dst
->u
[2] = src
->u
[2];
524 dst
->u
[3] = src
->u
[3];
528 micro_rcp(union tgsi_exec_channel
*dst
,
529 const union tgsi_exec_channel
*src
)
531 #if 0 /* for debugging */
532 assert(src
->f
[0] != 0.0f
);
533 assert(src
->f
[1] != 0.0f
);
534 assert(src
->f
[2] != 0.0f
);
535 assert(src
->f
[3] != 0.0f
);
537 dst
->f
[0] = 1.0f
/ src
->f
[0];
538 dst
->f
[1] = 1.0f
/ src
->f
[1];
539 dst
->f
[2] = 1.0f
/ src
->f
[2];
540 dst
->f
[3] = 1.0f
/ src
->f
[3];
544 micro_rnd(union tgsi_exec_channel
*dst
,
545 const union tgsi_exec_channel
*src
)
547 dst
->f
[0] = _mesa_roundevenf(src
->f
[0]);
548 dst
->f
[1] = _mesa_roundevenf(src
->f
[1]);
549 dst
->f
[2] = _mesa_roundevenf(src
->f
[2]);
550 dst
->f
[3] = _mesa_roundevenf(src
->f
[3]);
554 micro_rsq(union tgsi_exec_channel
*dst
,
555 const union tgsi_exec_channel
*src
)
557 #if 0 /* for debugging */
558 assert(src
->f
[0] != 0.0f
);
559 assert(src
->f
[1] != 0.0f
);
560 assert(src
->f
[2] != 0.0f
);
561 assert(src
->f
[3] != 0.0f
);
563 dst
->f
[0] = 1.0f
/ sqrtf(src
->f
[0]);
564 dst
->f
[1] = 1.0f
/ sqrtf(src
->f
[1]);
565 dst
->f
[2] = 1.0f
/ sqrtf(src
->f
[2]);
566 dst
->f
[3] = 1.0f
/ sqrtf(src
->f
[3]);
570 micro_sqrt(union tgsi_exec_channel
*dst
,
571 const union tgsi_exec_channel
*src
)
573 dst
->f
[0] = sqrtf(src
->f
[0]);
574 dst
->f
[1] = sqrtf(src
->f
[1]);
575 dst
->f
[2] = sqrtf(src
->f
[2]);
576 dst
->f
[3] = sqrtf(src
->f
[3]);
580 micro_seq(union tgsi_exec_channel
*dst
,
581 const union tgsi_exec_channel
*src0
,
582 const union tgsi_exec_channel
*src1
)
584 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? 1.0f
: 0.0f
;
585 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? 1.0f
: 0.0f
;
586 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? 1.0f
: 0.0f
;
587 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? 1.0f
: 0.0f
;
591 micro_sge(union tgsi_exec_channel
*dst
,
592 const union tgsi_exec_channel
*src0
,
593 const union tgsi_exec_channel
*src1
)
595 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? 1.0f
: 0.0f
;
596 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? 1.0f
: 0.0f
;
597 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? 1.0f
: 0.0f
;
598 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? 1.0f
: 0.0f
;
602 micro_sgn(union tgsi_exec_channel
*dst
,
603 const union tgsi_exec_channel
*src
)
605 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
606 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
607 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
608 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
612 micro_isgn(union tgsi_exec_channel
*dst
,
613 const union tgsi_exec_channel
*src
)
615 dst
->i
[0] = src
->i
[0] < 0 ? -1 : src
->i
[0] > 0 ? 1 : 0;
616 dst
->i
[1] = src
->i
[1] < 0 ? -1 : src
->i
[1] > 0 ? 1 : 0;
617 dst
->i
[2] = src
->i
[2] < 0 ? -1 : src
->i
[2] > 0 ? 1 : 0;
618 dst
->i
[3] = src
->i
[3] < 0 ? -1 : src
->i
[3] > 0 ? 1 : 0;
622 micro_sgt(union tgsi_exec_channel
*dst
,
623 const union tgsi_exec_channel
*src0
,
624 const union tgsi_exec_channel
*src1
)
626 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? 1.0f
: 0.0f
;
627 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? 1.0f
: 0.0f
;
628 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? 1.0f
: 0.0f
;
629 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? 1.0f
: 0.0f
;
633 micro_sin(union tgsi_exec_channel
*dst
,
634 const union tgsi_exec_channel
*src
)
636 dst
->f
[0] = sinf(src
->f
[0]);
637 dst
->f
[1] = sinf(src
->f
[1]);
638 dst
->f
[2] = sinf(src
->f
[2]);
639 dst
->f
[3] = sinf(src
->f
[3]);
643 micro_sle(union tgsi_exec_channel
*dst
,
644 const union tgsi_exec_channel
*src0
,
645 const union tgsi_exec_channel
*src1
)
647 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? 1.0f
: 0.0f
;
648 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? 1.0f
: 0.0f
;
649 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? 1.0f
: 0.0f
;
650 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? 1.0f
: 0.0f
;
654 micro_slt(union tgsi_exec_channel
*dst
,
655 const union tgsi_exec_channel
*src0
,
656 const union tgsi_exec_channel
*src1
)
658 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? 1.0f
: 0.0f
;
659 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? 1.0f
: 0.0f
;
660 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? 1.0f
: 0.0f
;
661 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? 1.0f
: 0.0f
;
665 micro_sne(union tgsi_exec_channel
*dst
,
666 const union tgsi_exec_channel
*src0
,
667 const union tgsi_exec_channel
*src1
)
669 dst
->f
[0] = src0
->f
[0] != src1
->f
[0] ? 1.0f
: 0.0f
;
670 dst
->f
[1] = src0
->f
[1] != src1
->f
[1] ? 1.0f
: 0.0f
;
671 dst
->f
[2] = src0
->f
[2] != src1
->f
[2] ? 1.0f
: 0.0f
;
672 dst
->f
[3] = src0
->f
[3] != src1
->f
[3] ? 1.0f
: 0.0f
;
676 micro_trunc(union tgsi_exec_channel
*dst
,
677 const union tgsi_exec_channel
*src
)
679 dst
->f
[0] = truncf(src
->f
[0]);
680 dst
->f
[1] = truncf(src
->f
[1]);
681 dst
->f
[2] = truncf(src
->f
[2]);
682 dst
->f
[3] = truncf(src
->f
[3]);
686 micro_u2d(union tgsi_double_channel
*dst
,
687 const union tgsi_exec_channel
*src
)
689 dst
->d
[0] = (double)src
->u
[0];
690 dst
->d
[1] = (double)src
->u
[1];
691 dst
->d
[2] = (double)src
->u
[2];
692 dst
->d
[3] = (double)src
->u
[3];
696 micro_i64abs(union tgsi_double_channel
*dst
,
697 const union tgsi_double_channel
*src
)
699 dst
->i64
[0] = src
->i64
[0] >= 0.0 ? src
->i64
[0] : -src
->i64
[0];
700 dst
->i64
[1] = src
->i64
[1] >= 0.0 ? src
->i64
[1] : -src
->i64
[1];
701 dst
->i64
[2] = src
->i64
[2] >= 0.0 ? src
->i64
[2] : -src
->i64
[2];
702 dst
->i64
[3] = src
->i64
[3] >= 0.0 ? src
->i64
[3] : -src
->i64
[3];
706 micro_i64sgn(union tgsi_double_channel
*dst
,
707 const union tgsi_double_channel
*src
)
709 dst
->i64
[0] = src
->i64
[0] < 0 ? -1 : src
->i64
[0] > 0 ? 1 : 0;
710 dst
->i64
[1] = src
->i64
[1] < 0 ? -1 : src
->i64
[1] > 0 ? 1 : 0;
711 dst
->i64
[2] = src
->i64
[2] < 0 ? -1 : src
->i64
[2] > 0 ? 1 : 0;
712 dst
->i64
[3] = src
->i64
[3] < 0 ? -1 : src
->i64
[3] > 0 ? 1 : 0;
716 micro_i64neg(union tgsi_double_channel
*dst
,
717 const union tgsi_double_channel
*src
)
719 dst
->i64
[0] = -src
->i64
[0];
720 dst
->i64
[1] = -src
->i64
[1];
721 dst
->i64
[2] = -src
->i64
[2];
722 dst
->i64
[3] = -src
->i64
[3];
726 micro_u64seq(union tgsi_double_channel
*dst
,
727 const union tgsi_double_channel
*src
)
729 dst
->u
[0][0] = src
[0].u64
[0] == src
[1].u64
[0] ? ~0U : 0U;
730 dst
->u
[1][0] = src
[0].u64
[1] == src
[1].u64
[1] ? ~0U : 0U;
731 dst
->u
[2][0] = src
[0].u64
[2] == src
[1].u64
[2] ? ~0U : 0U;
732 dst
->u
[3][0] = src
[0].u64
[3] == src
[1].u64
[3] ? ~0U : 0U;
736 micro_u64sne(union tgsi_double_channel
*dst
,
737 const union tgsi_double_channel
*src
)
739 dst
->u
[0][0] = src
[0].u64
[0] != src
[1].u64
[0] ? ~0U : 0U;
740 dst
->u
[1][0] = src
[0].u64
[1] != src
[1].u64
[1] ? ~0U : 0U;
741 dst
->u
[2][0] = src
[0].u64
[2] != src
[1].u64
[2] ? ~0U : 0U;
742 dst
->u
[3][0] = src
[0].u64
[3] != src
[1].u64
[3] ? ~0U : 0U;
746 micro_i64slt(union tgsi_double_channel
*dst
,
747 const union tgsi_double_channel
*src
)
749 dst
->u
[0][0] = src
[0].i64
[0] < src
[1].i64
[0] ? ~0U : 0U;
750 dst
->u
[1][0] = src
[0].i64
[1] < src
[1].i64
[1] ? ~0U : 0U;
751 dst
->u
[2][0] = src
[0].i64
[2] < src
[1].i64
[2] ? ~0U : 0U;
752 dst
->u
[3][0] = src
[0].i64
[3] < src
[1].i64
[3] ? ~0U : 0U;
756 micro_u64slt(union tgsi_double_channel
*dst
,
757 const union tgsi_double_channel
*src
)
759 dst
->u
[0][0] = src
[0].u64
[0] < src
[1].u64
[0] ? ~0U : 0U;
760 dst
->u
[1][0] = src
[0].u64
[1] < src
[1].u64
[1] ? ~0U : 0U;
761 dst
->u
[2][0] = src
[0].u64
[2] < src
[1].u64
[2] ? ~0U : 0U;
762 dst
->u
[3][0] = src
[0].u64
[3] < src
[1].u64
[3] ? ~0U : 0U;
766 micro_i64sge(union tgsi_double_channel
*dst
,
767 const union tgsi_double_channel
*src
)
769 dst
->u
[0][0] = src
[0].i64
[0] >= src
[1].i64
[0] ? ~0U : 0U;
770 dst
->u
[1][0] = src
[0].i64
[1] >= src
[1].i64
[1] ? ~0U : 0U;
771 dst
->u
[2][0] = src
[0].i64
[2] >= src
[1].i64
[2] ? ~0U : 0U;
772 dst
->u
[3][0] = src
[0].i64
[3] >= src
[1].i64
[3] ? ~0U : 0U;
776 micro_u64sge(union tgsi_double_channel
*dst
,
777 const union tgsi_double_channel
*src
)
779 dst
->u
[0][0] = src
[0].u64
[0] >= src
[1].u64
[0] ? ~0U : 0U;
780 dst
->u
[1][0] = src
[0].u64
[1] >= src
[1].u64
[1] ? ~0U : 0U;
781 dst
->u
[2][0] = src
[0].u64
[2] >= src
[1].u64
[2] ? ~0U : 0U;
782 dst
->u
[3][0] = src
[0].u64
[3] >= src
[1].u64
[3] ? ~0U : 0U;
786 micro_u64max(union tgsi_double_channel
*dst
,
787 const union tgsi_double_channel
*src
)
789 dst
->u64
[0] = src
[0].u64
[0] > src
[1].u64
[0] ? src
[0].u64
[0] : src
[1].u64
[0];
790 dst
->u64
[1] = src
[0].u64
[1] > src
[1].u64
[1] ? src
[0].u64
[1] : src
[1].u64
[1];
791 dst
->u64
[2] = src
[0].u64
[2] > src
[1].u64
[2] ? src
[0].u64
[2] : src
[1].u64
[2];
792 dst
->u64
[3] = src
[0].u64
[3] > src
[1].u64
[3] ? src
[0].u64
[3] : src
[1].u64
[3];
796 micro_i64max(union tgsi_double_channel
*dst
,
797 const union tgsi_double_channel
*src
)
799 dst
->i64
[0] = src
[0].i64
[0] > src
[1].i64
[0] ? src
[0].i64
[0] : src
[1].i64
[0];
800 dst
->i64
[1] = src
[0].i64
[1] > src
[1].i64
[1] ? src
[0].i64
[1] : src
[1].i64
[1];
801 dst
->i64
[2] = src
[0].i64
[2] > src
[1].i64
[2] ? src
[0].i64
[2] : src
[1].i64
[2];
802 dst
->i64
[3] = src
[0].i64
[3] > src
[1].i64
[3] ? src
[0].i64
[3] : src
[1].i64
[3];
806 micro_u64min(union tgsi_double_channel
*dst
,
807 const union tgsi_double_channel
*src
)
809 dst
->u64
[0] = src
[0].u64
[0] < src
[1].u64
[0] ? src
[0].u64
[0] : src
[1].u64
[0];
810 dst
->u64
[1] = src
[0].u64
[1] < src
[1].u64
[1] ? src
[0].u64
[1] : src
[1].u64
[1];
811 dst
->u64
[2] = src
[0].u64
[2] < src
[1].u64
[2] ? src
[0].u64
[2] : src
[1].u64
[2];
812 dst
->u64
[3] = src
[0].u64
[3] < src
[1].u64
[3] ? src
[0].u64
[3] : src
[1].u64
[3];
816 micro_i64min(union tgsi_double_channel
*dst
,
817 const union tgsi_double_channel
*src
)
819 dst
->i64
[0] = src
[0].i64
[0] < src
[1].i64
[0] ? src
[0].i64
[0] : src
[1].i64
[0];
820 dst
->i64
[1] = src
[0].i64
[1] < src
[1].i64
[1] ? src
[0].i64
[1] : src
[1].i64
[1];
821 dst
->i64
[2] = src
[0].i64
[2] < src
[1].i64
[2] ? src
[0].i64
[2] : src
[1].i64
[2];
822 dst
->i64
[3] = src
[0].i64
[3] < src
[1].i64
[3] ? src
[0].i64
[3] : src
[1].i64
[3];
826 micro_u64add(union tgsi_double_channel
*dst
,
827 const union tgsi_double_channel
*src
)
829 dst
->u64
[0] = src
[0].u64
[0] + src
[1].u64
[0];
830 dst
->u64
[1] = src
[0].u64
[1] + src
[1].u64
[1];
831 dst
->u64
[2] = src
[0].u64
[2] + src
[1].u64
[2];
832 dst
->u64
[3] = src
[0].u64
[3] + src
[1].u64
[3];
836 micro_u64mul(union tgsi_double_channel
*dst
,
837 const union tgsi_double_channel
*src
)
839 dst
->u64
[0] = src
[0].u64
[0] * src
[1].u64
[0];
840 dst
->u64
[1] = src
[0].u64
[1] * src
[1].u64
[1];
841 dst
->u64
[2] = src
[0].u64
[2] * src
[1].u64
[2];
842 dst
->u64
[3] = src
[0].u64
[3] * src
[1].u64
[3];
846 micro_u64div(union tgsi_double_channel
*dst
,
847 const union tgsi_double_channel
*src
)
849 dst
->u64
[0] = src
[1].u64
[0] ? src
[0].u64
[0] / src
[1].u64
[0] : ~0ull;
850 dst
->u64
[1] = src
[1].u64
[1] ? src
[0].u64
[1] / src
[1].u64
[1] : ~0ull;
851 dst
->u64
[2] = src
[1].u64
[2] ? src
[0].u64
[2] / src
[1].u64
[2] : ~0ull;
852 dst
->u64
[3] = src
[1].u64
[3] ? src
[0].u64
[3] / src
[1].u64
[3] : ~0ull;
856 micro_i64div(union tgsi_double_channel
*dst
,
857 const union tgsi_double_channel
*src
)
859 dst
->i64
[0] = src
[1].i64
[0] ? src
[0].i64
[0] / src
[1].i64
[0] : 0;
860 dst
->i64
[1] = src
[1].i64
[1] ? src
[0].i64
[1] / src
[1].i64
[1] : 0;
861 dst
->i64
[2] = src
[1].i64
[2] ? src
[0].i64
[2] / src
[1].i64
[2] : 0;
862 dst
->i64
[3] = src
[1].i64
[3] ? src
[0].i64
[3] / src
[1].i64
[3] : 0;
866 micro_u64mod(union tgsi_double_channel
*dst
,
867 const union tgsi_double_channel
*src
)
869 dst
->u64
[0] = src
[1].u64
[0] ? src
[0].u64
[0] % src
[1].u64
[0] : ~0ull;
870 dst
->u64
[1] = src
[1].u64
[1] ? src
[0].u64
[1] % src
[1].u64
[1] : ~0ull;
871 dst
->u64
[2] = src
[1].u64
[2] ? src
[0].u64
[2] % src
[1].u64
[2] : ~0ull;
872 dst
->u64
[3] = src
[1].u64
[3] ? src
[0].u64
[3] % src
[1].u64
[3] : ~0ull;
876 micro_i64mod(union tgsi_double_channel
*dst
,
877 const union tgsi_double_channel
*src
)
879 dst
->i64
[0] = src
[1].i64
[0] ? src
[0].i64
[0] % src
[1].i64
[0] : ~0ll;
880 dst
->i64
[1] = src
[1].i64
[1] ? src
[0].i64
[1] % src
[1].i64
[1] : ~0ll;
881 dst
->i64
[2] = src
[1].i64
[2] ? src
[0].i64
[2] % src
[1].i64
[2] : ~0ll;
882 dst
->i64
[3] = src
[1].i64
[3] ? src
[0].i64
[3] % src
[1].i64
[3] : ~0ll;
886 micro_u64shl(union tgsi_double_channel
*dst
,
887 const union tgsi_double_channel
*src0
,
888 union tgsi_exec_channel
*src1
)
890 unsigned masked_count
;
891 masked_count
= src1
->u
[0] & 0x3f;
892 dst
->u64
[0] = src0
->u64
[0] << masked_count
;
893 masked_count
= src1
->u
[1] & 0x3f;
894 dst
->u64
[1] = src0
->u64
[1] << masked_count
;
895 masked_count
= src1
->u
[2] & 0x3f;
896 dst
->u64
[2] = src0
->u64
[2] << masked_count
;
897 masked_count
= src1
->u
[3] & 0x3f;
898 dst
->u64
[3] = src0
->u64
[3] << masked_count
;
902 micro_i64shr(union tgsi_double_channel
*dst
,
903 const union tgsi_double_channel
*src0
,
904 union tgsi_exec_channel
*src1
)
906 unsigned masked_count
;
907 masked_count
= src1
->u
[0] & 0x3f;
908 dst
->i64
[0] = src0
->i64
[0] >> masked_count
;
909 masked_count
= src1
->u
[1] & 0x3f;
910 dst
->i64
[1] = src0
->i64
[1] >> masked_count
;
911 masked_count
= src1
->u
[2] & 0x3f;
912 dst
->i64
[2] = src0
->i64
[2] >> masked_count
;
913 masked_count
= src1
->u
[3] & 0x3f;
914 dst
->i64
[3] = src0
->i64
[3] >> masked_count
;
918 micro_u64shr(union tgsi_double_channel
*dst
,
919 const union tgsi_double_channel
*src0
,
920 union tgsi_exec_channel
*src1
)
922 unsigned masked_count
;
923 masked_count
= src1
->u
[0] & 0x3f;
924 dst
->u64
[0] = src0
->u64
[0] >> masked_count
;
925 masked_count
= src1
->u
[1] & 0x3f;
926 dst
->u64
[1] = src0
->u64
[1] >> masked_count
;
927 masked_count
= src1
->u
[2] & 0x3f;
928 dst
->u64
[2] = src0
->u64
[2] >> masked_count
;
929 masked_count
= src1
->u
[3] & 0x3f;
930 dst
->u64
[3] = src0
->u64
[3] >> masked_count
;
933 enum tgsi_exec_datatype
{
934 TGSI_EXEC_DATA_FLOAT
,
937 TGSI_EXEC_DATA_DOUBLE
,
938 TGSI_EXEC_DATA_INT64
,
939 TGSI_EXEC_DATA_UINT64
,
943 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
945 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
946 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
947 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
948 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
949 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
950 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
953 /** The execution mask depends on the conditional mask and the loop mask */
954 #define UPDATE_EXEC_MASK(MACH) \
955 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
958 static const union tgsi_exec_channel ZeroVec
=
959 { { 0.0, 0.0, 0.0, 0.0 } };
961 static const union tgsi_exec_channel OneVec
= {
962 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
965 static const union tgsi_exec_channel P128Vec
= {
966 {128.0f
, 128.0f
, 128.0f
, 128.0f
}
969 static const union tgsi_exec_channel M128Vec
= {
970 {-128.0f
, -128.0f
, -128.0f
, -128.0f
}
975 * Assert that none of the float values in 'chan' are infinite or NaN.
976 * NaN and Inf may occur normally during program execution and should
977 * not lead to crashes, etc. But when debugging, it's helpful to catch
981 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
983 assert(!util_is_inf_or_nan((chan
)->f
[0]));
984 assert(!util_is_inf_or_nan((chan
)->f
[1]));
985 assert(!util_is_inf_or_nan((chan
)->f
[2]));
986 assert(!util_is_inf_or_nan((chan
)->f
[3]));
992 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
994 debug_printf("%s = {%f, %f, %f, %f}\n",
995 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
1002 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
1004 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
1006 debug_printf("Temp[%u] =\n", index
);
1007 for (i
= 0; i
< 4; i
++) {
1008 debug_printf(" %c: { %f, %f, %f, %f }\n",
1020 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine
*mach
,
1023 const unsigned *buf_sizes
)
1027 for (i
= 0; i
< num_bufs
; i
++) {
1028 mach
->Consts
[i
] = bufs
[i
];
1029 mach
->ConstsSize
[i
] = buf_sizes
[i
];
1035 * Check if there's a potential src/dst register data dependency when
1036 * using SOA execution.
1039 * This would expand into:
1044 * The second instruction will have the wrong value for t0 if executed as-is.
1047 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
1051 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
1052 if (writemask
== TGSI_WRITEMASK_X
||
1053 writemask
== TGSI_WRITEMASK_Y
||
1054 writemask
== TGSI_WRITEMASK_Z
||
1055 writemask
== TGSI_WRITEMASK_W
||
1056 writemask
== TGSI_WRITEMASK_NONE
) {
1057 /* no chance of data dependency */
1061 /* loop over src regs */
1062 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1063 if ((inst
->Src
[i
].Register
.File
==
1064 inst
->Dst
[0].Register
.File
) &&
1065 ((inst
->Src
[i
].Register
.Index
==
1066 inst
->Dst
[0].Register
.Index
) ||
1067 inst
->Src
[i
].Register
.Indirect
||
1068 inst
->Dst
[0].Register
.Indirect
)) {
1069 /* loop over dest channels */
1070 uint channelsWritten
= 0x0;
1071 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1072 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1073 /* check if we're reading a channel that's been written */
1074 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
1075 if (channelsWritten
& (1 << swizzle
)) {
1079 channelsWritten
|= (1 << chan
);
1089 * Initialize machine state by expanding tokens to full instructions,
1090 * allocating temporary storage, setting up constants, etc.
1091 * After this, we can call tgsi_exec_machine_run() many times.
1094 tgsi_exec_machine_bind_shader(
1095 struct tgsi_exec_machine
*mach
,
1096 const struct tgsi_token
*tokens
,
1097 struct tgsi_sampler
*sampler
,
1098 struct tgsi_image
*image
,
1099 struct tgsi_buffer
*buffer
)
1102 struct tgsi_parse_context parse
;
1103 struct tgsi_full_instruction
*instructions
;
1104 struct tgsi_full_declaration
*declarations
;
1105 uint maxInstructions
= 10, numInstructions
= 0;
1106 uint maxDeclarations
= 10, numDeclarations
= 0;
1109 tgsi_dump(tokens
, 0);
1115 mach
->Tokens
= tokens
;
1116 mach
->Sampler
= sampler
;
1117 mach
->Image
= image
;
1118 mach
->Buffer
= buffer
;
1121 /* unbind and free all */
1122 FREE(mach
->Declarations
);
1123 mach
->Declarations
= NULL
;
1124 mach
->NumDeclarations
= 0;
1126 FREE(mach
->Instructions
);
1127 mach
->Instructions
= NULL
;
1128 mach
->NumInstructions
= 0;
1133 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
1134 if (k
!= TGSI_PARSE_OK
) {
1135 debug_printf( "Problem parsing!\n" );
1140 mach
->NumOutputs
= 0;
1142 for (k
= 0; k
< TGSI_SEMANTIC_COUNT
; k
++)
1143 mach
->SysSemanticToIndex
[k
] = -1;
1145 if (mach
->ShaderType
== PIPE_SHADER_GEOMETRY
&&
1146 !mach
->UsedGeometryShader
) {
1147 struct tgsi_exec_vector
*inputs
;
1148 struct tgsi_exec_vector
*outputs
;
1150 inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
1151 TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_SHADER_INPUTS
,
1157 outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
1158 TGSI_MAX_TOTAL_VERTICES
, 16);
1165 align_free(mach
->Inputs
);
1166 align_free(mach
->Outputs
);
1168 mach
->Inputs
= inputs
;
1169 mach
->Outputs
= outputs
;
1170 mach
->UsedGeometryShader
= TRUE
;
1173 declarations
= (struct tgsi_full_declaration
*)
1174 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
1176 if (!declarations
) {
1180 instructions
= (struct tgsi_full_instruction
*)
1181 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
1183 if (!instructions
) {
1184 FREE( declarations
);
1188 while( !tgsi_parse_end_of_tokens( &parse
) ) {
1191 tgsi_parse_token( &parse
);
1192 switch( parse
.FullToken
.Token
.Type
) {
1193 case TGSI_TOKEN_TYPE_DECLARATION
:
1194 /* save expanded declaration */
1195 if (numDeclarations
== maxDeclarations
) {
1196 declarations
= REALLOC(declarations
,
1198 * sizeof(struct tgsi_full_declaration
),
1199 (maxDeclarations
+ 10)
1200 * sizeof(struct tgsi_full_declaration
));
1201 maxDeclarations
+= 10;
1203 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
1205 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
1206 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
1211 else if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1212 const struct tgsi_full_declaration
*decl
= &parse
.FullToken
.FullDeclaration
;
1213 mach
->SysSemanticToIndex
[decl
->Semantic
.Name
] = decl
->Range
.First
;
1216 memcpy(declarations
+ numDeclarations
,
1217 &parse
.FullToken
.FullDeclaration
,
1218 sizeof(declarations
[0]));
1222 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1224 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
1225 assert( size
<= 4 );
1226 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
1228 for( i
= 0; i
< size
; i
++ ) {
1229 mach
->Imms
[mach
->ImmLimit
][i
] =
1230 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
1232 mach
->ImmLimit
+= 1;
1236 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1238 /* save expanded instruction */
1239 if (numInstructions
== maxInstructions
) {
1240 instructions
= REALLOC(instructions
,
1242 * sizeof(struct tgsi_full_instruction
),
1243 (maxInstructions
+ 10)
1244 * sizeof(struct tgsi_full_instruction
));
1245 maxInstructions
+= 10;
1248 memcpy(instructions
+ numInstructions
,
1249 &parse
.FullToken
.FullInstruction
,
1250 sizeof(instructions
[0]));
1255 case TGSI_TOKEN_TYPE_PROPERTY
:
1256 if (mach
->ShaderType
== PIPE_SHADER_GEOMETRY
) {
1257 if (parse
.FullToken
.FullProperty
.Property
.PropertyName
== TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
) {
1258 mach
->MaxOutputVertices
= parse
.FullToken
.FullProperty
.u
[0].Data
;
1267 tgsi_parse_free (&parse
);
1269 FREE(mach
->Declarations
);
1270 mach
->Declarations
= declarations
;
1271 mach
->NumDeclarations
= numDeclarations
;
1273 FREE(mach
->Instructions
);
1274 mach
->Instructions
= instructions
;
1275 mach
->NumInstructions
= numInstructions
;
1279 struct tgsi_exec_machine
*
1280 tgsi_exec_machine_create(enum pipe_shader_type shader_type
)
1282 struct tgsi_exec_machine
*mach
;
1285 mach
= align_malloc( sizeof *mach
, 16 );
1289 memset(mach
, 0, sizeof(*mach
));
1291 mach
->ShaderType
= shader_type
;
1292 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
1293 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
1295 if (shader_type
!= PIPE_SHADER_COMPUTE
) {
1296 mach
->Inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_INPUTS
, 16);
1297 mach
->Outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_OUTPUTS
, 16);
1298 if (!mach
->Inputs
|| !mach
->Outputs
)
1302 /* Setup constants needed by the SSE2 executor. */
1303 for( i
= 0; i
< 4; i
++ ) {
1304 mach
->Temps
[TGSI_EXEC_TEMP_00000000_I
].xyzw
[TGSI_EXEC_TEMP_00000000_C
].u
[i
] = 0x00000000;
1305 mach
->Temps
[TGSI_EXEC_TEMP_7FFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_7FFFFFFF_C
].u
[i
] = 0x7FFFFFFF;
1306 mach
->Temps
[TGSI_EXEC_TEMP_80000000_I
].xyzw
[TGSI_EXEC_TEMP_80000000_C
].u
[i
] = 0x80000000;
1307 mach
->Temps
[TGSI_EXEC_TEMP_FFFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_FFFFFFFF_C
].u
[i
] = 0xFFFFFFFF; /* not used */
1308 mach
->Temps
[TGSI_EXEC_TEMP_ONE_I
].xyzw
[TGSI_EXEC_TEMP_ONE_C
].f
[i
] = 1.0f
;
1309 mach
->Temps
[TGSI_EXEC_TEMP_TWO_I
].xyzw
[TGSI_EXEC_TEMP_TWO_C
].f
[i
] = 2.0f
; /* not used */
1310 mach
->Temps
[TGSI_EXEC_TEMP_128_I
].xyzw
[TGSI_EXEC_TEMP_128_C
].f
[i
] = 128.0f
;
1311 mach
->Temps
[TGSI_EXEC_TEMP_MINUS_128_I
].xyzw
[TGSI_EXEC_TEMP_MINUS_128_C
].f
[i
] = -128.0f
;
1312 mach
->Temps
[TGSI_EXEC_TEMP_THREE_I
].xyzw
[TGSI_EXEC_TEMP_THREE_C
].f
[i
] = 3.0f
;
1313 mach
->Temps
[TGSI_EXEC_TEMP_HALF_I
].xyzw
[TGSI_EXEC_TEMP_HALF_C
].f
[i
] = 0.5f
;
1317 /* silence warnings */
1326 align_free(mach
->Inputs
);
1327 align_free(mach
->Outputs
);
1335 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
1338 FREE(mach
->Instructions
);
1339 FREE(mach
->Declarations
);
1341 align_free(mach
->Inputs
);
1342 align_free(mach
->Outputs
);
1349 micro_add(union tgsi_exec_channel
*dst
,
1350 const union tgsi_exec_channel
*src0
,
1351 const union tgsi_exec_channel
*src1
)
1353 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
1354 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
1355 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
1356 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
1361 union tgsi_exec_channel
*dst
,
1362 const union tgsi_exec_channel
*src0
,
1363 const union tgsi_exec_channel
*src1
)
1365 if (src1
->f
[0] != 0) {
1366 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
1368 if (src1
->f
[1] != 0) {
1369 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
1371 if (src1
->f
[2] != 0) {
1372 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
1374 if (src1
->f
[3] != 0) {
1375 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
1381 union tgsi_exec_channel
*dst
,
1382 const union tgsi_exec_channel
*src0
,
1383 const union tgsi_exec_channel
*src1
,
1384 const union tgsi_exec_channel
*src2
,
1385 const union tgsi_exec_channel
*src3
)
1387 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
1388 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
1389 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
1390 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
1394 micro_max(union tgsi_exec_channel
*dst
,
1395 const union tgsi_exec_channel
*src0
,
1396 const union tgsi_exec_channel
*src1
)
1398 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
1399 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
1400 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
1401 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
1405 micro_min(union tgsi_exec_channel
*dst
,
1406 const union tgsi_exec_channel
*src0
,
1407 const union tgsi_exec_channel
*src1
)
1409 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
1410 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
1411 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
1412 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
1416 micro_mul(union tgsi_exec_channel
*dst
,
1417 const union tgsi_exec_channel
*src0
,
1418 const union tgsi_exec_channel
*src1
)
1420 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
1421 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
1422 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
1423 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
1428 union tgsi_exec_channel
*dst
,
1429 const union tgsi_exec_channel
*src
)
1431 dst
->f
[0] = -src
->f
[0];
1432 dst
->f
[1] = -src
->f
[1];
1433 dst
->f
[2] = -src
->f
[2];
1434 dst
->f
[3] = -src
->f
[3];
1439 union tgsi_exec_channel
*dst
,
1440 const union tgsi_exec_channel
*src0
,
1441 const union tgsi_exec_channel
*src1
)
1444 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
1445 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
1446 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
1447 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
1449 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
1450 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
1451 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
1452 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
1457 micro_ldexp(union tgsi_exec_channel
*dst
,
1458 const union tgsi_exec_channel
*src0
,
1459 const union tgsi_exec_channel
*src1
)
1461 dst
->f
[0] = ldexpf(src0
->f
[0], src1
->i
[0]);
1462 dst
->f
[1] = ldexpf(src0
->f
[1], src1
->i
[1]);
1463 dst
->f
[2] = ldexpf(src0
->f
[2], src1
->i
[2]);
1464 dst
->f
[3] = ldexpf(src0
->f
[3], src1
->i
[3]);
1468 micro_sub(union tgsi_exec_channel
*dst
,
1469 const union tgsi_exec_channel
*src0
,
1470 const union tgsi_exec_channel
*src1
)
1472 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1473 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1474 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1475 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1479 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
1480 const uint chan_index
,
1483 const union tgsi_exec_channel
*index
,
1484 const union tgsi_exec_channel
*index2D
,
1485 union tgsi_exec_channel
*chan
)
1489 assert(swizzle
< 4);
1492 case TGSI_FILE_CONSTANT
:
1493 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1494 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
1495 assert(mach
->Consts
[index2D
->i
[i
]]);
1497 if (index
->i
[i
] < 0) {
1500 /* NOTE: copying the const value as a uint instead of float */
1501 const uint constbuf
= index2D
->i
[i
];
1502 const uint
*buf
= (const uint
*)mach
->Consts
[constbuf
];
1503 const int pos
= index
->i
[i
] * 4 + swizzle
;
1504 /* const buffer bounds check */
1505 if (pos
< 0 || pos
>= (int) mach
->ConstsSize
[constbuf
]) {
1507 /* Debug: print warning */
1508 static int count
= 0;
1510 debug_printf("TGSI Exec: const buffer index %d"
1511 " out of bounds\n", pos
);
1516 chan
->u
[i
] = buf
[pos
];
1521 case TGSI_FILE_INPUT
:
1522 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1524 if (PIPE_SHADER_GEOMETRY == mach->ShaderType) {
1525 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1526 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1527 index2D->i[i], index->i[i]);
1529 int pos
= index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
];
1531 assert(pos
< TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
);
1532 chan
->u
[i
] = mach
->Inputs
[pos
].xyzw
[swizzle
].u
[i
];
1536 case TGSI_FILE_SYSTEM_VALUE
:
1537 /* XXX no swizzling at this point. Will be needed if we put
1538 * gl_FragCoord, for example, in a sys value register.
1540 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1541 chan
->u
[i
] = mach
->SystemValue
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1545 case TGSI_FILE_TEMPORARY
:
1546 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1547 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1548 assert(index2D
->i
[i
] == 0);
1550 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1554 case TGSI_FILE_IMMEDIATE
:
1555 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1556 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1557 assert(index2D
->i
[i
] == 0);
1559 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1563 case TGSI_FILE_ADDRESS
:
1564 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1565 assert(index
->i
[i
] >= 0);
1566 assert(index2D
->i
[i
] == 0);
1568 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1572 case TGSI_FILE_OUTPUT
:
1573 /* vertex/fragment output vars can be read too */
1574 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1575 assert(index
->i
[i
] >= 0);
1576 assert(index2D
->i
[i
] == 0);
1578 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1584 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1591 fetch_source_d(const struct tgsi_exec_machine
*mach
,
1592 union tgsi_exec_channel
*chan
,
1593 const struct tgsi_full_src_register
*reg
,
1594 const uint chan_index
,
1595 enum tgsi_exec_datatype src_datatype
)
1597 union tgsi_exec_channel index
;
1598 union tgsi_exec_channel index2D
;
1601 /* We start with a direct index into a register file.
1605 * file = Register.File
1606 * [1] = Register.Index
1611 index
.i
[3] = reg
->Register
.Index
;
1613 /* There is an extra source register that indirectly subscripts
1614 * a register file. The direct index now becomes an offset
1615 * that is being added to the indirect register.
1619 * ind = Indirect.File
1620 * [2] = Indirect.Index
1621 * .x = Indirect.SwizzleX
1623 if (reg
->Register
.Indirect
) {
1624 union tgsi_exec_channel index2
;
1625 union tgsi_exec_channel indir_index
;
1626 const uint execmask
= mach
->ExecMask
;
1629 /* which address register (always zero now) */
1633 index2
.i
[3] = reg
->Indirect
.Index
;
1634 /* get current value of address register[swizzle] */
1635 swizzle
= reg
->Indirect
.Swizzle
;
1636 fetch_src_file_channel(mach
,
1644 /* add value of address register to the offset */
1645 index
.i
[0] += indir_index
.i
[0];
1646 index
.i
[1] += indir_index
.i
[1];
1647 index
.i
[2] += indir_index
.i
[2];
1648 index
.i
[3] += indir_index
.i
[3];
1650 /* for disabled execution channels, zero-out the index to
1651 * avoid using a potential garbage value.
1653 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1654 if ((execmask
& (1 << i
)) == 0)
1659 /* There is an extra source register that is a second
1660 * subscript to a register file. Effectively it means that
1661 * the register file is actually a 2D array of registers.
1665 * [3] = Dimension.Index
1667 if (reg
->Register
.Dimension
) {
1671 index2D
.i
[3] = reg
->Dimension
.Index
;
1673 /* Again, the second subscript index can be addressed indirectly
1674 * identically to the first one.
1675 * Nothing stops us from indirectly addressing the indirect register,
1676 * but there is no need for that, so we won't exercise it.
1678 * file[ind[4].y+3][1],
1680 * ind = DimIndirect.File
1681 * [4] = DimIndirect.Index
1682 * .y = DimIndirect.SwizzleX
1684 if (reg
->Dimension
.Indirect
) {
1685 union tgsi_exec_channel index2
;
1686 union tgsi_exec_channel indir_index
;
1687 const uint execmask
= mach
->ExecMask
;
1693 index2
.i
[3] = reg
->DimIndirect
.Index
;
1695 swizzle
= reg
->DimIndirect
.Swizzle
;
1696 fetch_src_file_channel(mach
,
1698 reg
->DimIndirect
.File
,
1704 index2D
.i
[0] += indir_index
.i
[0];
1705 index2D
.i
[1] += indir_index
.i
[1];
1706 index2D
.i
[2] += indir_index
.i
[2];
1707 index2D
.i
[3] += indir_index
.i
[3];
1709 /* for disabled execution channels, zero-out the index to
1710 * avoid using a potential garbage value.
1712 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1713 if ((execmask
& (1 << i
)) == 0) {
1719 /* If by any chance there was a need for a 3D array of register
1720 * files, we would have to check whether Dimension is followed
1721 * by a dimension register and continue the saga.
1730 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1731 fetch_src_file_channel(mach
,
1741 fetch_source(const struct tgsi_exec_machine
*mach
,
1742 union tgsi_exec_channel
*chan
,
1743 const struct tgsi_full_src_register
*reg
,
1744 const uint chan_index
,
1745 enum tgsi_exec_datatype src_datatype
)
1747 fetch_source_d(mach
, chan
, reg
, chan_index
, src_datatype
);
1749 if (reg
->Register
.Absolute
) {
1750 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1751 micro_abs(chan
, chan
);
1753 micro_iabs(chan
, chan
);
1757 if (reg
->Register
.Negate
) {
1758 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1759 micro_neg(chan
, chan
);
1761 micro_ineg(chan
, chan
);
1766 static union tgsi_exec_channel
*
1767 store_dest_dstret(struct tgsi_exec_machine
*mach
,
1768 const union tgsi_exec_channel
*chan
,
1769 const struct tgsi_full_dst_register
*reg
,
1770 const struct tgsi_full_instruction
*inst
,
1772 enum tgsi_exec_datatype dst_datatype
)
1774 static union tgsi_exec_channel null
;
1775 union tgsi_exec_channel
*dst
;
1776 union tgsi_exec_channel index2D
;
1777 int offset
= 0; /* indirection offset */
1781 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1782 check_inf_or_nan(chan
);
1785 /* There is an extra source register that indirectly subscripts
1786 * a register file. The direct index now becomes an offset
1787 * that is being added to the indirect register.
1791 * ind = Indirect.File
1792 * [2] = Indirect.Index
1793 * .x = Indirect.SwizzleX
1795 if (reg
->Register
.Indirect
) {
1796 union tgsi_exec_channel index
;
1797 union tgsi_exec_channel indir_index
;
1800 /* which address register (always zero for now) */
1804 index
.i
[3] = reg
->Indirect
.Index
;
1806 /* get current value of address register[swizzle] */
1807 swizzle
= reg
->Indirect
.Swizzle
;
1809 /* fetch values from the address/indirection register */
1810 fetch_src_file_channel(mach
,
1818 /* save indirection offset */
1819 offset
= indir_index
.i
[0];
1822 /* There is an extra source register that is a second
1823 * subscript to a register file. Effectively it means that
1824 * the register file is actually a 2D array of registers.
1828 * [3] = Dimension.Index
1830 if (reg
->Register
.Dimension
) {
1834 index2D
.i
[3] = reg
->Dimension
.Index
;
1836 /* Again, the second subscript index can be addressed indirectly
1837 * identically to the first one.
1838 * Nothing stops us from indirectly addressing the indirect register,
1839 * but there is no need for that, so we won't exercise it.
1841 * file[ind[4].y+3][1],
1843 * ind = DimIndirect.File
1844 * [4] = DimIndirect.Index
1845 * .y = DimIndirect.SwizzleX
1847 if (reg
->Dimension
.Indirect
) {
1848 union tgsi_exec_channel index2
;
1849 union tgsi_exec_channel indir_index
;
1850 const uint execmask
= mach
->ExecMask
;
1857 index2
.i
[3] = reg
->DimIndirect
.Index
;
1859 swizzle
= reg
->DimIndirect
.Swizzle
;
1860 fetch_src_file_channel(mach
,
1862 reg
->DimIndirect
.File
,
1868 index2D
.i
[0] += indir_index
.i
[0];
1869 index2D
.i
[1] += indir_index
.i
[1];
1870 index2D
.i
[2] += indir_index
.i
[2];
1871 index2D
.i
[3] += indir_index
.i
[3];
1873 /* for disabled execution channels, zero-out the index to
1874 * avoid using a potential garbage value.
1876 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1877 if ((execmask
& (1 << i
)) == 0) {
1883 /* If by any chance there was a need for a 3D array of register
1884 * files, we would have to check whether Dimension is followed
1885 * by a dimension register and continue the saga.
1894 switch (reg
->Register
.File
) {
1895 case TGSI_FILE_NULL
:
1899 case TGSI_FILE_OUTPUT
:
1900 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1901 + reg
->Register
.Index
;
1902 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1904 debug_printf("NumOutputs = %d, TEMP_O_C/I = %d, redindex = %d\n",
1905 mach
->NumOutputs
, mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0],
1906 reg
->Register
.Index
);
1907 if (PIPE_SHADER_GEOMETRY
== mach
->ShaderType
) {
1908 debug_printf("STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1909 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1910 if (execmask
& (1 << i
))
1911 debug_printf("%f, ", chan
->f
[i
]);
1912 debug_printf(")\n");
1917 case TGSI_FILE_TEMPORARY
:
1918 index
= reg
->Register
.Index
;
1919 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1920 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1923 case TGSI_FILE_ADDRESS
:
1924 index
= reg
->Register
.Index
;
1925 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1937 store_dest_double(struct tgsi_exec_machine
*mach
,
1938 const union tgsi_exec_channel
*chan
,
1939 const struct tgsi_full_dst_register
*reg
,
1940 const struct tgsi_full_instruction
*inst
,
1942 enum tgsi_exec_datatype dst_datatype
)
1944 union tgsi_exec_channel
*dst
;
1945 const uint execmask
= mach
->ExecMask
;
1948 dst
= store_dest_dstret(mach
, chan
, reg
, inst
, chan_index
,
1954 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1955 if (execmask
& (1 << i
))
1956 dst
->i
[i
] = chan
->i
[i
];
1960 store_dest(struct tgsi_exec_machine
*mach
,
1961 const union tgsi_exec_channel
*chan
,
1962 const struct tgsi_full_dst_register
*reg
,
1963 const struct tgsi_full_instruction
*inst
,
1965 enum tgsi_exec_datatype dst_datatype
)
1967 union tgsi_exec_channel
*dst
;
1968 const uint execmask
= mach
->ExecMask
;
1971 dst
= store_dest_dstret(mach
, chan
, reg
, inst
, chan_index
,
1976 if (!inst
->Instruction
.Saturate
) {
1977 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1978 if (execmask
& (1 << i
))
1979 dst
->i
[i
] = chan
->i
[i
];
1982 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1983 if (execmask
& (1 << i
)) {
1984 if (chan
->f
[i
] < 0.0f
)
1986 else if (chan
->f
[i
] > 1.0f
)
1989 dst
->i
[i
] = chan
->i
[i
];
1994 #define FETCH(VAL,INDEX,CHAN)\
1995 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1997 #define IFETCH(VAL,INDEX,CHAN)\
1998 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
2002 * Execute ARB-style KIL which is predicated by a src register.
2003 * Kill fragment if any of the four values is less than zero.
2006 exec_kill_if(struct tgsi_exec_machine
*mach
,
2007 const struct tgsi_full_instruction
*inst
)
2011 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
2012 union tgsi_exec_channel r
[1];
2014 /* This mask stores component bits that were already tested. */
2017 for (chan_index
= 0; chan_index
< 4; chan_index
++)
2022 /* unswizzle channel */
2023 swizzle
= tgsi_util_get_full_src_register_swizzle (
2027 /* check if the component has not been already tested */
2028 if (uniquemask
& (1 << swizzle
))
2030 uniquemask
|= 1 << swizzle
;
2032 FETCH(&r
[0], 0, chan_index
);
2033 for (i
= 0; i
< 4; i
++)
2034 if (r
[0].f
[i
] < 0.0f
)
2038 /* restrict to fragments currently executing */
2039 kilmask
&= mach
->ExecMask
;
2041 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
2045 * Unconditional fragment kill/discard.
2048 exec_kill(struct tgsi_exec_machine
*mach
,
2049 const struct tgsi_full_instruction
*inst
)
2051 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
2053 /* kill fragment for all fragments currently executing */
2054 kilmask
= mach
->ExecMask
;
2055 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
2059 emit_vertex(struct tgsi_exec_machine
*mach
)
2061 /* FIXME: check for exec mask correctly
2063 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
2064 if ((mach->ExecMask & (1 << i)))
2066 if (mach
->ExecMask
) {
2067 if (mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] >= mach
->MaxOutputVertices
)
2070 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
2071 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
2076 emit_primitive(struct tgsi_exec_machine
*mach
)
2078 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
2079 /* FIXME: check for exec mask correctly
2081 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
2082 if ((mach->ExecMask & (1 << i)))
2084 if (mach
->ExecMask
) {
2086 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
2087 mach
->Primitives
[*prim_count
] = 0;
2092 conditional_emit_primitive(struct tgsi_exec_machine
*mach
)
2094 if (PIPE_SHADER_GEOMETRY
== mach
->ShaderType
) {
2096 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]];
2097 if (emitted_verts
) {
2098 emit_primitive(mach
);
2105 * Fetch four texture samples using STR texture coordinates.
2108 fetch_texel( struct tgsi_sampler
*sampler
,
2109 const unsigned sview_idx
,
2110 const unsigned sampler_idx
,
2111 const union tgsi_exec_channel
*s
,
2112 const union tgsi_exec_channel
*t
,
2113 const union tgsi_exec_channel
*p
,
2114 const union tgsi_exec_channel
*c0
,
2115 const union tgsi_exec_channel
*c1
,
2116 float derivs
[3][2][TGSI_QUAD_SIZE
],
2117 const int8_t offset
[3],
2118 enum tgsi_sampler_control control
,
2119 union tgsi_exec_channel
*r
,
2120 union tgsi_exec_channel
*g
,
2121 union tgsi_exec_channel
*b
,
2122 union tgsi_exec_channel
*a
)
2125 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2127 /* FIXME: handle explicit derivs, offsets */
2128 sampler
->get_samples(sampler
, sview_idx
, sampler_idx
,
2129 s
->f
, t
->f
, p
->f
, c0
->f
, c1
->f
, derivs
, offset
, control
, rgba
);
2131 for (j
= 0; j
< 4; j
++) {
2132 r
->f
[j
] = rgba
[0][j
];
2133 g
->f
[j
] = rgba
[1][j
];
2134 b
->f
[j
] = rgba
[2][j
];
2135 a
->f
[j
] = rgba
[3][j
];
2140 #define TEX_MODIFIER_NONE 0
2141 #define TEX_MODIFIER_PROJECTED 1
2142 #define TEX_MODIFIER_LOD_BIAS 2
2143 #define TEX_MODIFIER_EXPLICIT_LOD 3
2144 #define TEX_MODIFIER_LEVEL_ZERO 4
2145 #define TEX_MODIFIER_GATHER 5
2148 * Fetch all 3 (for s,t,r coords) texel offsets, put them into int array.
2151 fetch_texel_offsets(struct tgsi_exec_machine
*mach
,
2152 const struct tgsi_full_instruction
*inst
,
2155 if (inst
->Texture
.NumOffsets
== 1) {
2156 union tgsi_exec_channel index
;
2157 union tgsi_exec_channel offset
[3];
2158 index
.i
[0] = index
.i
[1] = index
.i
[2] = index
.i
[3] = inst
->TexOffsets
[0].Index
;
2159 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2160 inst
->TexOffsets
[0].SwizzleX
, &index
, &ZeroVec
, &offset
[0]);
2161 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2162 inst
->TexOffsets
[0].SwizzleY
, &index
, &ZeroVec
, &offset
[1]);
2163 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2164 inst
->TexOffsets
[0].SwizzleZ
, &index
, &ZeroVec
, &offset
[2]);
2165 offsets
[0] = offset
[0].i
[0];
2166 offsets
[1] = offset
[1].i
[0];
2167 offsets
[2] = offset
[2].i
[0];
2169 assert(inst
->Texture
.NumOffsets
== 0);
2170 offsets
[0] = offsets
[1] = offsets
[2] = 0;
2176 * Fetch dx and dy values for one channel (s, t or r).
2177 * Put dx values into one float array, dy values into another.
2180 fetch_assign_deriv_channel(struct tgsi_exec_machine
*mach
,
2181 const struct tgsi_full_instruction
*inst
,
2184 float derivs
[2][TGSI_QUAD_SIZE
])
2186 union tgsi_exec_channel d
;
2187 FETCH(&d
, regdsrcx
, chan
);
2188 derivs
[0][0] = d
.f
[0];
2189 derivs
[0][1] = d
.f
[1];
2190 derivs
[0][2] = d
.f
[2];
2191 derivs
[0][3] = d
.f
[3];
2192 FETCH(&d
, regdsrcx
+ 1, chan
);
2193 derivs
[1][0] = d
.f
[0];
2194 derivs
[1][1] = d
.f
[1];
2195 derivs
[1][2] = d
.f
[2];
2196 derivs
[1][3] = d
.f
[3];
2200 fetch_sampler_unit(struct tgsi_exec_machine
*mach
,
2201 const struct tgsi_full_instruction
*inst
,
2206 if (inst
->Src
[sampler
].Register
.Indirect
) {
2207 const struct tgsi_full_src_register
*reg
= &inst
->Src
[sampler
];
2208 union tgsi_exec_channel indir_index
, index2
;
2209 const uint execmask
= mach
->ExecMask
;
2213 index2
.i
[3] = reg
->Indirect
.Index
;
2215 fetch_src_file_channel(mach
,
2218 reg
->Indirect
.Swizzle
,
2222 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2223 if (execmask
& (1 << i
)) {
2224 unit
= inst
->Src
[sampler
].Register
.Index
+ indir_index
.i
[i
];
2230 unit
= inst
->Src
[sampler
].Register
.Index
;
2236 * execute a texture instruction.
2238 * modifier is used to control the channel routing for the
2239 * instruction variants like proj, lod, and texture with lod bias.
2240 * sampler indicates which src register the sampler is contained in.
2243 exec_tex(struct tgsi_exec_machine
*mach
,
2244 const struct tgsi_full_instruction
*inst
,
2245 uint modifier
, uint sampler
)
2247 const union tgsi_exec_channel
*args
[5], *proj
= NULL
;
2248 union tgsi_exec_channel r
[5];
2249 enum tgsi_sampler_control control
= TGSI_SAMPLER_LOD_NONE
;
2253 int dim
, shadow_ref
, i
;
2255 unit
= fetch_sampler_unit(mach
, inst
, sampler
);
2256 /* always fetch all 3 offsets, overkill but keeps code simple */
2257 fetch_texel_offsets(mach
, inst
, offsets
);
2259 assert(modifier
!= TEX_MODIFIER_LEVEL_ZERO
);
2260 assert(inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
);
2262 dim
= tgsi_util_get_texture_coord_dim(inst
->Texture
.Texture
);
2263 shadow_ref
= tgsi_util_get_shadow_ref_src_index(inst
->Texture
.Texture
);
2266 if (shadow_ref
>= 0)
2267 assert(shadow_ref
>= dim
&& shadow_ref
< ARRAY_SIZE(args
));
2269 /* fetch modifier to the last argument */
2270 if (modifier
!= TEX_MODIFIER_NONE
) {
2271 const int last
= ARRAY_SIZE(args
) - 1;
2273 /* fetch modifier from src0.w or src1.x */
2275 assert(dim
<= TGSI_CHAN_W
&& shadow_ref
!= TGSI_CHAN_W
);
2276 FETCH(&r
[last
], 0, TGSI_CHAN_W
);
2279 assert(shadow_ref
!= 4);
2280 FETCH(&r
[last
], 1, TGSI_CHAN_X
);
2283 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
2284 args
[last
] = &r
[last
];
2288 args
[last
] = &ZeroVec
;
2291 /* point unused arguments to zero vector */
2292 for (i
= dim
; i
< last
; i
++)
2295 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
)
2296 control
= TGSI_SAMPLER_LOD_EXPLICIT
;
2297 else if (modifier
== TEX_MODIFIER_LOD_BIAS
)
2298 control
= TGSI_SAMPLER_LOD_BIAS
;
2299 else if (modifier
== TEX_MODIFIER_GATHER
)
2300 control
= TGSI_SAMPLER_GATHER
;
2303 for (i
= dim
; i
< ARRAY_SIZE(args
); i
++)
2307 /* fetch coordinates */
2308 for (i
= 0; i
< dim
; i
++) {
2309 FETCH(&r
[i
], 0, TGSI_CHAN_X
+ i
);
2312 micro_div(&r
[i
], &r
[i
], proj
);
2317 /* fetch reference value */
2318 if (shadow_ref
>= 0) {
2319 FETCH(&r
[shadow_ref
], shadow_ref
/ 4, TGSI_CHAN_X
+ (shadow_ref
% 4));
2322 micro_div(&r
[shadow_ref
], &r
[shadow_ref
], proj
);
2324 args
[shadow_ref
] = &r
[shadow_ref
];
2327 fetch_texel(mach
->Sampler
, unit
, unit
,
2328 args
[0], args
[1], args
[2], args
[3], args
[4],
2329 NULL
, offsets
, control
,
2330 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2333 debug_printf("fetch r: %g %g %g %g\n",
2334 r
[0].f
[0], r
[0].f
[1], r
[0].f
[2], r
[0].f
[3]);
2335 debug_printf("fetch g: %g %g %g %g\n",
2336 r
[1].f
[0], r
[1].f
[1], r
[1].f
[2], r
[1].f
[3]);
2337 debug_printf("fetch b: %g %g %g %g\n",
2338 r
[2].f
[0], r
[2].f
[1], r
[2].f
[2], r
[2].f
[3]);
2339 debug_printf("fetch a: %g %g %g %g\n",
2340 r
[3].f
[0], r
[3].f
[1], r
[3].f
[2], r
[3].f
[3]);
2343 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2344 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2345 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2351 exec_lodq(struct tgsi_exec_machine
*mach
,
2352 const struct tgsi_full_instruction
*inst
)
2357 union tgsi_exec_channel coords
[4];
2358 const union tgsi_exec_channel
*args
[ARRAY_SIZE(coords
)];
2359 union tgsi_exec_channel r
[2];
2361 unit
= fetch_sampler_unit(mach
, inst
, 1);
2362 dim
= tgsi_util_get_texture_coord_dim(inst
->Texture
.Texture
);
2363 assert(dim
<= ARRAY_SIZE(coords
));
2364 /* fetch coordinates */
2365 for (i
= 0; i
< dim
; i
++) {
2366 FETCH(&coords
[i
], 0, TGSI_CHAN_X
+ i
);
2367 args
[i
] = &coords
[i
];
2369 for (i
= dim
; i
< ARRAY_SIZE(coords
); i
++) {
2372 mach
->Sampler
->query_lod(mach
->Sampler
, unit
, unit
,
2377 TGSI_SAMPLER_LOD_NONE
,
2381 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2382 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
,
2383 TGSI_EXEC_DATA_FLOAT
);
2385 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2386 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
,
2387 TGSI_EXEC_DATA_FLOAT
);
2392 exec_txd(struct tgsi_exec_machine
*mach
,
2393 const struct tgsi_full_instruction
*inst
)
2395 union tgsi_exec_channel r
[4];
2396 float derivs
[3][2][TGSI_QUAD_SIZE
];
2401 unit
= fetch_sampler_unit(mach
, inst
, 3);
2402 /* always fetch all 3 offsets, overkill but keeps code simple */
2403 fetch_texel_offsets(mach
, inst
, offsets
);
2405 switch (inst
->Texture
.Texture
) {
2406 case TGSI_TEXTURE_1D
:
2407 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2409 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2411 fetch_texel(mach
->Sampler
, unit
, unit
,
2412 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2413 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2414 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2417 case TGSI_TEXTURE_SHADOW1D
:
2418 case TGSI_TEXTURE_1D_ARRAY
:
2419 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
2420 /* SHADOW1D/1D_ARRAY would not need Y/Z respectively, but don't bother */
2421 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2422 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2423 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2425 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2427 fetch_texel(mach
->Sampler
, unit
, unit
,
2428 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2429 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2430 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2433 case TGSI_TEXTURE_2D
:
2434 case TGSI_TEXTURE_RECT
:
2435 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2436 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2438 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2439 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
2441 fetch_texel(mach
->Sampler
, unit
, unit
,
2442 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2443 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2444 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2448 case TGSI_TEXTURE_SHADOW2D
:
2449 case TGSI_TEXTURE_SHADOWRECT
:
2450 case TGSI_TEXTURE_2D_ARRAY
:
2451 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2452 /* only SHADOW2D_ARRAY actually needs W */
2453 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2454 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2455 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2456 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2458 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2459 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
2461 fetch_texel(mach
->Sampler
, unit
, unit
,
2462 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
2463 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2464 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2467 case TGSI_TEXTURE_3D
:
2468 case TGSI_TEXTURE_CUBE
:
2469 case TGSI_TEXTURE_CUBE_ARRAY
:
2470 case TGSI_TEXTURE_SHADOWCUBE
:
2471 /* only TEXTURE_CUBE_ARRAY and TEXTURE_SHADOWCUBE actually need W */
2472 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2473 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2474 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2475 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2477 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2478 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
2479 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Z
, derivs
[2]);
2481 fetch_texel(mach
->Sampler
, unit
, unit
,
2482 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
2483 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2484 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2491 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2492 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2493 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2500 exec_txf(struct tgsi_exec_machine
*mach
,
2501 const struct tgsi_full_instruction
*inst
)
2503 union tgsi_exec_channel r
[4];
2506 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2511 unit
= fetch_sampler_unit(mach
, inst
, 1);
2512 /* always fetch all 3 offsets, overkill but keeps code simple */
2513 fetch_texel_offsets(mach
, inst
, offsets
);
2515 IFETCH(&r
[3], 0, TGSI_CHAN_W
);
2517 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
||
2518 inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I_MS
) {
2519 target
= mach
->SamplerViews
[unit
].Resource
;
2522 target
= inst
->Texture
.Texture
;
2525 case TGSI_TEXTURE_3D
:
2526 case TGSI_TEXTURE_2D_ARRAY
:
2527 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2528 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
2529 IFETCH(&r
[2], 0, TGSI_CHAN_Z
);
2531 case TGSI_TEXTURE_2D
:
2532 case TGSI_TEXTURE_RECT
:
2533 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
2534 case TGSI_TEXTURE_SHADOW2D
:
2535 case TGSI_TEXTURE_SHADOWRECT
:
2536 case TGSI_TEXTURE_1D_ARRAY
:
2537 case TGSI_TEXTURE_2D_MSAA
:
2538 IFETCH(&r
[1], 0, TGSI_CHAN_Y
);
2540 case TGSI_TEXTURE_BUFFER
:
2541 case TGSI_TEXTURE_1D
:
2542 case TGSI_TEXTURE_SHADOW1D
:
2543 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
2550 mach
->Sampler
->get_texel(mach
->Sampler
, unit
, r
[0].i
, r
[1].i
, r
[2].i
, r
[3].i
,
2553 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2554 r
[0].f
[j
] = rgba
[0][j
];
2555 r
[1].f
[j
] = rgba
[1][j
];
2556 r
[2].f
[j
] = rgba
[2][j
];
2557 r
[3].f
[j
] = rgba
[3][j
];
2560 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
||
2561 inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I_MS
) {
2562 unsigned char swizzles
[4];
2563 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2564 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2565 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2566 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2568 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2569 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2570 store_dest(mach
, &r
[swizzles
[chan
]],
2571 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2576 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2577 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2578 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2585 exec_txq(struct tgsi_exec_machine
*mach
,
2586 const struct tgsi_full_instruction
*inst
)
2589 union tgsi_exec_channel r
[4], src
;
2594 unit
= fetch_sampler_unit(mach
, inst
, 1);
2596 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
2598 /* XXX: This interface can't return per-pixel values */
2599 mach
->Sampler
->get_dims(mach
->Sampler
, unit
, src
.i
[0], result
);
2601 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2602 for (j
= 0; j
< 4; j
++) {
2603 r
[j
].i
[i
] = result
[j
];
2607 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2608 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2609 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
2610 TGSI_EXEC_DATA_INT
);
2616 exec_sample(struct tgsi_exec_machine
*mach
,
2617 const struct tgsi_full_instruction
*inst
,
2618 uint modifier
, boolean compare
)
2620 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2621 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2622 union tgsi_exec_channel r
[5], c1
;
2623 const union tgsi_exec_channel
*lod
= &ZeroVec
;
2624 enum tgsi_sampler_control control
= TGSI_SAMPLER_LOD_NONE
;
2626 unsigned char swizzles
[4];
2629 /* always fetch all 3 offsets, overkill but keeps code simple */
2630 fetch_texel_offsets(mach
, inst
, offsets
);
2632 assert(modifier
!= TEX_MODIFIER_PROJECTED
);
2634 if (modifier
!= TEX_MODIFIER_NONE
) {
2635 if (modifier
== TEX_MODIFIER_LOD_BIAS
) {
2636 FETCH(&c1
, 3, TGSI_CHAN_X
);
2638 control
= TGSI_SAMPLER_LOD_BIAS
;
2640 else if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
2641 FETCH(&c1
, 3, TGSI_CHAN_X
);
2643 control
= TGSI_SAMPLER_LOD_EXPLICIT
;
2645 else if (modifier
== TEX_MODIFIER_GATHER
) {
2646 control
= TGSI_SAMPLER_GATHER
;
2649 assert(modifier
== TEX_MODIFIER_LEVEL_ZERO
);
2650 control
= TGSI_SAMPLER_LOD_ZERO
;
2654 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2656 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2657 case TGSI_TEXTURE_1D
:
2659 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2660 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2661 &r
[0], &ZeroVec
, &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2662 NULL
, offsets
, control
,
2663 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2666 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2667 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2668 NULL
, offsets
, control
,
2669 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2673 case TGSI_TEXTURE_1D_ARRAY
:
2674 case TGSI_TEXTURE_2D
:
2675 case TGSI_TEXTURE_RECT
:
2676 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2678 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2679 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2680 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2681 NULL
, offsets
, control
,
2682 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2685 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2686 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2687 NULL
, offsets
, control
,
2688 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2692 case TGSI_TEXTURE_2D_ARRAY
:
2693 case TGSI_TEXTURE_3D
:
2694 case TGSI_TEXTURE_CUBE
:
2695 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2696 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2698 FETCH(&r
[3], 3, TGSI_CHAN_X
);
2699 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2700 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2701 NULL
, offsets
, control
,
2702 &r
[0], &r
[1], &r
[2], &r
[3]);
2705 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2706 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
,
2707 NULL
, offsets
, control
,
2708 &r
[0], &r
[1], &r
[2], &r
[3]);
2712 case TGSI_TEXTURE_CUBE_ARRAY
:
2713 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2714 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2715 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2717 FETCH(&r
[4], 3, TGSI_CHAN_X
);
2718 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2719 &r
[0], &r
[1], &r
[2], &r
[3], &r
[4],
2720 NULL
, offsets
, control
,
2721 &r
[0], &r
[1], &r
[2], &r
[3]);
2724 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2725 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2726 NULL
, offsets
, control
,
2727 &r
[0], &r
[1], &r
[2], &r
[3]);
2736 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2737 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2738 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2739 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2741 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2742 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2743 store_dest(mach
, &r
[swizzles
[chan
]],
2744 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2750 exec_sample_d(struct tgsi_exec_machine
*mach
,
2751 const struct tgsi_full_instruction
*inst
)
2753 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2754 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2755 union tgsi_exec_channel r
[4];
2756 float derivs
[3][2][TGSI_QUAD_SIZE
];
2758 unsigned char swizzles
[4];
2761 /* always fetch all 3 offsets, overkill but keeps code simple */
2762 fetch_texel_offsets(mach
, inst
, offsets
);
2764 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2766 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2767 case TGSI_TEXTURE_1D
:
2768 case TGSI_TEXTURE_1D_ARRAY
:
2769 /* only 1D array actually needs Y */
2770 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2772 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2774 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2775 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2776 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2777 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2780 case TGSI_TEXTURE_2D
:
2781 case TGSI_TEXTURE_RECT
:
2782 case TGSI_TEXTURE_2D_ARRAY
:
2783 /* only 2D array actually needs Z */
2784 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2785 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2787 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2788 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2790 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2791 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* inputs */
2792 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2793 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2796 case TGSI_TEXTURE_3D
:
2797 case TGSI_TEXTURE_CUBE
:
2798 case TGSI_TEXTURE_CUBE_ARRAY
:
2799 /* only cube array actually needs W */
2800 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2801 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2802 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2804 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2805 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2806 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Z
, derivs
[2]);
2808 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2809 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
,
2810 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2811 &r
[0], &r
[1], &r
[2], &r
[3]);
2818 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2819 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2820 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2821 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2823 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2824 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2825 store_dest(mach
, &r
[swizzles
[chan
]],
2826 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2833 * Evaluate a constant-valued coefficient at the position of the
2838 struct tgsi_exec_machine
*mach
,
2844 for( i
= 0; i
< TGSI_QUAD_SIZE
; i
++ ) {
2845 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
2850 * Evaluate a linear-valued coefficient at the position of the
2855 struct tgsi_exec_machine
*mach
,
2859 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2860 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2861 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2862 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2863 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2864 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
2865 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
2866 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
2867 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
2871 * Evaluate a perspective-valued coefficient at the position of the
2875 eval_perspective_coef(
2876 struct tgsi_exec_machine
*mach
,
2880 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2881 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2882 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2883 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2884 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2885 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
2886 /* divide by W here */
2887 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
2888 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
2889 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
2890 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
2894 typedef void (* eval_coef_func
)(
2895 struct tgsi_exec_machine
*mach
,
2900 exec_declaration(struct tgsi_exec_machine
*mach
,
2901 const struct tgsi_full_declaration
*decl
)
2903 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
2904 mach
->SamplerViews
[decl
->Range
.First
] = decl
->SamplerView
;
2908 if (mach
->ShaderType
== PIPE_SHADER_FRAGMENT
) {
2909 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
2910 uint first
, last
, mask
;
2912 first
= decl
->Range
.First
;
2913 last
= decl
->Range
.Last
;
2914 mask
= decl
->Declaration
.UsageMask
;
2916 /* XXX we could remove this special-case code since
2917 * mach->InterpCoefs[first].a0 should already have the
2918 * front/back-face value. But we should first update the
2919 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2920 * Then, we could remove the tgsi_exec_machine::Face field.
2922 /* XXX make FACE a system value */
2923 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
2926 assert(decl
->Semantic
.Index
== 0);
2927 assert(first
== last
);
2929 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2930 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
2933 eval_coef_func eval
;
2936 switch (decl
->Interp
.Interpolate
) {
2937 case TGSI_INTERPOLATE_CONSTANT
:
2938 eval
= eval_constant_coef
;
2941 case TGSI_INTERPOLATE_LINEAR
:
2942 eval
= eval_linear_coef
;
2945 case TGSI_INTERPOLATE_PERSPECTIVE
:
2946 eval
= eval_perspective_coef
;
2949 case TGSI_INTERPOLATE_COLOR
:
2950 eval
= mach
->flatshade_color
? eval_constant_coef
: eval_perspective_coef
;
2958 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2959 if (mask
& (1 << j
)) {
2960 for (i
= first
; i
<= last
; i
++) {
2967 if (DEBUG_EXECUTION
) {
2969 for (i
= first
; i
<= last
; ++i
) {
2970 debug_printf("IN[%2u] = ", i
);
2971 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2975 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
2976 mach
->Inputs
[i
].xyzw
[0].f
[j
], mach
->Inputs
[i
].xyzw
[0].u
[j
],
2977 mach
->Inputs
[i
].xyzw
[1].f
[j
], mach
->Inputs
[i
].xyzw
[1].u
[j
],
2978 mach
->Inputs
[i
].xyzw
[2].f
[j
], mach
->Inputs
[i
].xyzw
[2].u
[j
],
2979 mach
->Inputs
[i
].xyzw
[3].f
[j
], mach
->Inputs
[i
].xyzw
[3].u
[j
]);
2988 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
2989 const union tgsi_exec_channel
*src
);
2992 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
2993 const struct tgsi_full_instruction
*inst
,
2995 enum tgsi_exec_datatype dst_datatype
,
2996 enum tgsi_exec_datatype src_datatype
)
2999 union tgsi_exec_channel src
;
3000 union tgsi_exec_channel dst
;
3002 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
3004 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3005 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3006 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
3012 exec_vector_unary(struct tgsi_exec_machine
*mach
,
3013 const struct tgsi_full_instruction
*inst
,
3015 enum tgsi_exec_datatype dst_datatype
,
3016 enum tgsi_exec_datatype src_datatype
)
3019 struct tgsi_exec_vector dst
;
3021 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3022 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3023 union tgsi_exec_channel src
;
3025 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
3026 op(&dst
.xyzw
[chan
], &src
);
3029 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3030 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3031 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
3036 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
3037 const union tgsi_exec_channel
*src0
,
3038 const union tgsi_exec_channel
*src1
);
3041 exec_scalar_binary(struct tgsi_exec_machine
*mach
,
3042 const struct tgsi_full_instruction
*inst
,
3044 enum tgsi_exec_datatype dst_datatype
,
3045 enum tgsi_exec_datatype src_datatype
)
3048 union tgsi_exec_channel src
[2];
3049 union tgsi_exec_channel dst
;
3051 fetch_source(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
3052 fetch_source(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, src_datatype
);
3053 op(&dst
, &src
[0], &src
[1]);
3054 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3055 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3056 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
3062 exec_vector_binary(struct tgsi_exec_machine
*mach
,
3063 const struct tgsi_full_instruction
*inst
,
3065 enum tgsi_exec_datatype dst_datatype
,
3066 enum tgsi_exec_datatype src_datatype
)
3069 struct tgsi_exec_vector dst
;
3071 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3072 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3073 union tgsi_exec_channel src
[2];
3075 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
3076 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
3077 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
3080 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3081 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3082 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
3087 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
3088 const union tgsi_exec_channel
*src0
,
3089 const union tgsi_exec_channel
*src1
,
3090 const union tgsi_exec_channel
*src2
);
3093 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
3094 const struct tgsi_full_instruction
*inst
,
3095 micro_trinary_op op
,
3096 enum tgsi_exec_datatype dst_datatype
,
3097 enum tgsi_exec_datatype src_datatype
)
3100 struct tgsi_exec_vector dst
;
3102 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3103 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3104 union tgsi_exec_channel src
[3];
3106 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
3107 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
3108 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
3109 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
3112 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3113 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3114 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
3119 typedef void (* micro_quaternary_op
)(union tgsi_exec_channel
*dst
,
3120 const union tgsi_exec_channel
*src0
,
3121 const union tgsi_exec_channel
*src1
,
3122 const union tgsi_exec_channel
*src2
,
3123 const union tgsi_exec_channel
*src3
);
3126 exec_vector_quaternary(struct tgsi_exec_machine
*mach
,
3127 const struct tgsi_full_instruction
*inst
,
3128 micro_quaternary_op op
,
3129 enum tgsi_exec_datatype dst_datatype
,
3130 enum tgsi_exec_datatype src_datatype
)
3133 struct tgsi_exec_vector dst
;
3135 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3136 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3137 union tgsi_exec_channel src
[4];
3139 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
3140 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
3141 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
3142 fetch_source(mach
, &src
[3], &inst
->Src
[3], chan
, src_datatype
);
3143 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2], &src
[3]);
3146 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3147 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3148 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
3154 exec_dp3(struct tgsi_exec_machine
*mach
,
3155 const struct tgsi_full_instruction
*inst
)
3158 union tgsi_exec_channel arg
[3];
3160 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3161 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3162 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
3164 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
3165 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
3166 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
3167 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
3170 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3171 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3172 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3178 exec_dp4(struct tgsi_exec_machine
*mach
,
3179 const struct tgsi_full_instruction
*inst
)
3182 union tgsi_exec_channel arg
[3];
3184 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3185 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3186 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
3188 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
3189 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
3190 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
3191 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
3194 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3195 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3196 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3202 exec_dp2(struct tgsi_exec_machine
*mach
,
3203 const struct tgsi_full_instruction
*inst
)
3206 union tgsi_exec_channel arg
[3];
3208 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3209 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3210 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
3212 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3213 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3214 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
3216 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3217 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3218 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3224 exec_pk2h(struct tgsi_exec_machine
*mach
,
3225 const struct tgsi_full_instruction
*inst
)
3228 union tgsi_exec_channel arg
[2], dst
;
3230 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3231 fetch_source(mach
, &arg
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3232 for (chan
= 0; chan
< TGSI_QUAD_SIZE
; chan
++) {
3233 dst
.u
[chan
] = util_float_to_half(arg
[0].f
[chan
]) |
3234 (util_float_to_half(arg
[1].f
[chan
]) << 16);
3236 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3237 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3238 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_UINT
);
3244 exec_up2h(struct tgsi_exec_machine
*mach
,
3245 const struct tgsi_full_instruction
*inst
)
3248 union tgsi_exec_channel arg
, dst
[2];
3250 fetch_source(mach
, &arg
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3251 for (chan
= 0; chan
< TGSI_QUAD_SIZE
; chan
++) {
3252 dst
[0].f
[chan
] = util_half_to_float(arg
.u
[chan
] & 0xffff);
3253 dst
[1].f
[chan
] = util_half_to_float(arg
.u
[chan
] >> 16);
3255 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3256 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3257 store_dest(mach
, &dst
[chan
& 1], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3263 micro_ucmp(union tgsi_exec_channel
*dst
,
3264 const union tgsi_exec_channel
*src0
,
3265 const union tgsi_exec_channel
*src1
,
3266 const union tgsi_exec_channel
*src2
)
3268 dst
->f
[0] = src0
->u
[0] ? src1
->f
[0] : src2
->f
[0];
3269 dst
->f
[1] = src0
->u
[1] ? src1
->f
[1] : src2
->f
[1];
3270 dst
->f
[2] = src0
->u
[2] ? src1
->f
[2] : src2
->f
[2];
3271 dst
->f
[3] = src0
->u
[3] ? src1
->f
[3] : src2
->f
[3];
3275 exec_ucmp(struct tgsi_exec_machine
*mach
,
3276 const struct tgsi_full_instruction
*inst
)
3279 struct tgsi_exec_vector dst
;
3281 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3282 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3283 union tgsi_exec_channel src
[3];
3285 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
,
3286 TGSI_EXEC_DATA_UINT
);
3287 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
,
3288 TGSI_EXEC_DATA_FLOAT
);
3289 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
,
3290 TGSI_EXEC_DATA_FLOAT
);
3291 micro_ucmp(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
3294 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3295 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3296 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
,
3297 TGSI_EXEC_DATA_FLOAT
);
3303 exec_dst(struct tgsi_exec_machine
*mach
,
3304 const struct tgsi_full_instruction
*inst
)
3306 union tgsi_exec_channel r
[2];
3307 union tgsi_exec_channel d
[4];
3309 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3310 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3311 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3312 micro_mul(&d
[TGSI_CHAN_Y
], &r
[0], &r
[1]);
3314 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3315 fetch_source(mach
, &d
[TGSI_CHAN_Z
], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3317 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3318 fetch_source(mach
, &d
[TGSI_CHAN_W
], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3321 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3322 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3324 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3325 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3327 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3328 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3330 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3331 store_dest(mach
, &d
[TGSI_CHAN_W
], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3336 exec_log(struct tgsi_exec_machine
*mach
,
3337 const struct tgsi_full_instruction
*inst
)
3339 union tgsi_exec_channel r
[3];
3341 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3342 micro_abs(&r
[2], &r
[0]); /* r2 = abs(r0) */
3343 micro_lg2(&r
[1], &r
[2]); /* r1 = lg2(r2) */
3344 micro_flr(&r
[0], &r
[1]); /* r0 = floor(r1) */
3345 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3346 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3348 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3349 micro_exp2(&r
[0], &r
[0]); /* r0 = 2 ^ r0 */
3350 micro_div(&r
[0], &r
[2], &r
[0]); /* r0 = r2 / r0 */
3351 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3353 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3354 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3356 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3357 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3362 exec_exp(struct tgsi_exec_machine
*mach
,
3363 const struct tgsi_full_instruction
*inst
)
3365 union tgsi_exec_channel r
[3];
3367 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3368 micro_flr(&r
[1], &r
[0]); /* r1 = floor(r0) */
3369 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3370 micro_exp2(&r
[2], &r
[1]); /* r2 = 2 ^ r1 */
3371 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3373 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3374 micro_sub(&r
[2], &r
[0], &r
[1]); /* r2 = r0 - r1 */
3375 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3377 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3378 micro_exp2(&r
[2], &r
[0]); /* r2 = 2 ^ r0 */
3379 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3381 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3382 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3387 exec_lit(struct tgsi_exec_machine
*mach
,
3388 const struct tgsi_full_instruction
*inst
)
3390 union tgsi_exec_channel r
[3];
3391 union tgsi_exec_channel d
[3];
3393 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YZ
) {
3394 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3395 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3396 fetch_source(mach
, &r
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3397 micro_max(&r
[1], &r
[1], &ZeroVec
);
3399 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3400 micro_min(&r
[2], &r
[2], &P128Vec
);
3401 micro_max(&r
[2], &r
[2], &M128Vec
);
3402 micro_pow(&r
[1], &r
[1], &r
[2]);
3403 micro_lt(&d
[TGSI_CHAN_Z
], &ZeroVec
, &r
[0], &r
[1], &ZeroVec
);
3404 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3406 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3407 micro_max(&d
[TGSI_CHAN_Y
], &r
[0], &ZeroVec
);
3408 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3411 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3412 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3415 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3416 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3421 exec_break(struct tgsi_exec_machine
*mach
)
3423 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
3424 /* turn off loop channels for each enabled exec channel */
3425 mach
->LoopMask
&= ~mach
->ExecMask
;
3426 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3427 UPDATE_EXEC_MASK(mach
);
3429 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
3431 mach
->Switch
.mask
= 0x0;
3433 UPDATE_EXEC_MASK(mach
);
3438 exec_switch(struct tgsi_exec_machine
*mach
,
3439 const struct tgsi_full_instruction
*inst
)
3441 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3442 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3444 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3445 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3446 mach
->Switch
.mask
= 0x0;
3447 mach
->Switch
.defaultMask
= 0x0;
3449 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3450 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
3452 UPDATE_EXEC_MASK(mach
);
3456 exec_case(struct tgsi_exec_machine
*mach
,
3457 const struct tgsi_full_instruction
*inst
)
3459 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3460 union tgsi_exec_channel src
;
3463 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3465 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
3468 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
3471 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
3474 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
3478 mach
->Switch
.defaultMask
|= mask
;
3480 mach
->Switch
.mask
|= mask
& prevMask
;
3482 UPDATE_EXEC_MASK(mach
);
3485 /* FIXME: this will only work if default is last */
3487 exec_default(struct tgsi_exec_machine
*mach
)
3489 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3491 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
3493 UPDATE_EXEC_MASK(mach
);
3497 exec_endswitch(struct tgsi_exec_machine
*mach
)
3499 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
3500 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3502 UPDATE_EXEC_MASK(mach
);
3505 typedef void (* micro_dop
)(union tgsi_double_channel
*dst
,
3506 const union tgsi_double_channel
*src
);
3508 typedef void (* micro_dop_sop
)(union tgsi_double_channel
*dst
,
3509 const union tgsi_double_channel
*src0
,
3510 union tgsi_exec_channel
*src1
);
3512 typedef void (* micro_dop_s
)(union tgsi_double_channel
*dst
,
3513 const union tgsi_exec_channel
*src
);
3515 typedef void (* micro_sop_d
)(union tgsi_exec_channel
*dst
,
3516 const union tgsi_double_channel
*src
);
3519 fetch_double_channel(struct tgsi_exec_machine
*mach
,
3520 union tgsi_double_channel
*chan
,
3521 const struct tgsi_full_src_register
*reg
,
3525 union tgsi_exec_channel src
[2];
3528 fetch_source_d(mach
, &src
[0], reg
, chan_0
, TGSI_EXEC_DATA_UINT
);
3529 fetch_source_d(mach
, &src
[1], reg
, chan_1
, TGSI_EXEC_DATA_UINT
);
3531 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
3532 chan
->u
[i
][0] = src
[0].u
[i
];
3533 chan
->u
[i
][1] = src
[1].u
[i
];
3535 if (reg
->Register
.Absolute
) {
3536 micro_dabs(chan
, chan
);
3538 if (reg
->Register
.Negate
) {
3539 micro_dneg(chan
, chan
);
3544 store_double_channel(struct tgsi_exec_machine
*mach
,
3545 const union tgsi_double_channel
*chan
,
3546 const struct tgsi_full_dst_register
*reg
,
3547 const struct tgsi_full_instruction
*inst
,
3551 union tgsi_exec_channel dst
[2];
3553 union tgsi_double_channel temp
;
3554 const uint execmask
= mach
->ExecMask
;
3556 if (!inst
->Instruction
.Saturate
) {
3557 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
3558 if (execmask
& (1 << i
)) {
3559 dst
[0].u
[i
] = chan
->u
[i
][0];
3560 dst
[1].u
[i
] = chan
->u
[i
][1];
3564 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
3565 if (execmask
& (1 << i
)) {
3566 if (chan
->d
[i
] < 0.0)
3568 else if (chan
->d
[i
] > 1.0)
3571 temp
.d
[i
] = chan
->d
[i
];
3573 dst
[0].u
[i
] = temp
.u
[i
][0];
3574 dst
[1].u
[i
] = temp
.u
[i
][1];
3578 store_dest_double(mach
, &dst
[0], reg
, inst
, chan_0
, TGSI_EXEC_DATA_UINT
);
3580 store_dest_double(mach
, &dst
[1], reg
, inst
, chan_1
, TGSI_EXEC_DATA_UINT
);
3584 exec_double_unary(struct tgsi_exec_machine
*mach
,
3585 const struct tgsi_full_instruction
*inst
,
3588 union tgsi_double_channel src
;
3589 union tgsi_double_channel dst
;
3591 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
3592 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3594 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3596 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
3597 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3599 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3604 exec_double_binary(struct tgsi_exec_machine
*mach
,
3605 const struct tgsi_full_instruction
*inst
,
3607 enum tgsi_exec_datatype dst_datatype
)
3609 union tgsi_double_channel src
[2];
3610 union tgsi_double_channel dst
;
3611 int first_dest_chan
, second_dest_chan
;
3614 wmask
= inst
->Dst
[0].Register
.WriteMask
;
3615 /* these are & because of the way DSLT etc store their destinations */
3616 if (wmask
& TGSI_WRITEMASK_XY
) {
3617 first_dest_chan
= TGSI_CHAN_X
;
3618 second_dest_chan
= TGSI_CHAN_Y
;
3619 if (dst_datatype
== TGSI_EXEC_DATA_UINT
) {
3620 first_dest_chan
= (wmask
& TGSI_WRITEMASK_X
) ? TGSI_CHAN_X
: TGSI_CHAN_Y
;
3621 second_dest_chan
= -1;
3624 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3625 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3627 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, first_dest_chan
, second_dest_chan
);
3630 if (wmask
& TGSI_WRITEMASK_ZW
) {
3631 first_dest_chan
= TGSI_CHAN_Z
;
3632 second_dest_chan
= TGSI_CHAN_W
;
3633 if (dst_datatype
== TGSI_EXEC_DATA_UINT
) {
3634 first_dest_chan
= (wmask
& TGSI_WRITEMASK_Z
) ? TGSI_CHAN_Z
: TGSI_CHAN_W
;
3635 second_dest_chan
= -1;
3638 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3639 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3641 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, first_dest_chan
, second_dest_chan
);
3646 exec_double_trinary(struct tgsi_exec_machine
*mach
,
3647 const struct tgsi_full_instruction
*inst
,
3650 union tgsi_double_channel src
[3];
3651 union tgsi_double_channel dst
;
3653 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
3654 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3655 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3656 fetch_double_channel(mach
, &src
[2], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3658 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3660 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
3661 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3662 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3663 fetch_double_channel(mach
, &src
[2], &inst
->Src
[2], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3665 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3670 exec_dldexp(struct tgsi_exec_machine
*mach
,
3671 const struct tgsi_full_instruction
*inst
)
3673 union tgsi_double_channel src0
;
3674 union tgsi_exec_channel src1
;
3675 union tgsi_double_channel dst
;
3678 wmask
= inst
->Dst
[0].Register
.WriteMask
;
3679 if (wmask
& TGSI_WRITEMASK_XY
) {
3680 fetch_double_channel(mach
, &src0
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3681 fetch_source(mach
, &src1
, &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
3682 micro_dldexp(&dst
, &src0
, &src1
);
3683 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3686 if (wmask
& TGSI_WRITEMASK_ZW
) {
3687 fetch_double_channel(mach
, &src0
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3688 fetch_source(mach
, &src1
, &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_INT
);
3689 micro_dldexp(&dst
, &src0
, &src1
);
3690 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3695 exec_dfracexp(struct tgsi_exec_machine
*mach
,
3696 const struct tgsi_full_instruction
*inst
)
3698 union tgsi_double_channel src
;
3699 union tgsi_double_channel dst
;
3700 union tgsi_exec_channel dst_exp
;
3702 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3703 micro_dfracexp(&dst
, &dst_exp
, &src
);
3704 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
)
3705 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3706 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
)
3707 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3708 for (unsigned chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3709 if (inst
->Dst
[1].Register
.WriteMask
& (1 << chan
))
3710 store_dest(mach
, &dst_exp
, &inst
->Dst
[1], inst
, chan
, TGSI_EXEC_DATA_INT
);
3715 exec_arg0_64_arg1_32(struct tgsi_exec_machine
*mach
,
3716 const struct tgsi_full_instruction
*inst
,
3719 union tgsi_double_channel src0
;
3720 union tgsi_exec_channel src1
;
3721 union tgsi_double_channel dst
;
3724 wmask
= inst
->Dst
[0].Register
.WriteMask
;
3725 if (wmask
& TGSI_WRITEMASK_XY
) {
3726 fetch_double_channel(mach
, &src0
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3727 fetch_source(mach
, &src1
, &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
3728 op(&dst
, &src0
, &src1
);
3729 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3732 if (wmask
& TGSI_WRITEMASK_ZW
) {
3733 fetch_double_channel(mach
, &src0
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3734 fetch_source(mach
, &src1
, &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_INT
);
3735 op(&dst
, &src0
, &src1
);
3736 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3741 get_image_coord_dim(unsigned tgsi_tex
)
3745 case TGSI_TEXTURE_BUFFER
:
3746 case TGSI_TEXTURE_1D
:
3749 case TGSI_TEXTURE_2D
:
3750 case TGSI_TEXTURE_RECT
:
3751 case TGSI_TEXTURE_1D_ARRAY
:
3752 case TGSI_TEXTURE_2D_MSAA
:
3755 case TGSI_TEXTURE_3D
:
3756 case TGSI_TEXTURE_CUBE
:
3757 case TGSI_TEXTURE_2D_ARRAY
:
3758 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
3759 case TGSI_TEXTURE_CUBE_ARRAY
:
3763 assert(!"unknown texture target");
3772 get_image_coord_sample(unsigned tgsi_tex
)
3776 case TGSI_TEXTURE_2D_MSAA
:
3779 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
3789 exec_load_img(struct tgsi_exec_machine
*mach
,
3790 const struct tgsi_full_instruction
*inst
)
3792 union tgsi_exec_channel r
[4], sample_r
;
3798 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3799 struct tgsi_image_params params
;
3800 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3802 unit
= fetch_sampler_unit(mach
, inst
, 0);
3803 dim
= get_image_coord_dim(inst
->Memory
.Texture
);
3804 sample
= get_image_coord_sample(inst
->Memory
.Texture
);
3807 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3809 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
3810 params
.format
= inst
->Memory
.Format
;
3812 for (i
= 0; i
< dim
; i
++) {
3813 IFETCH(&r
[i
], 1, TGSI_CHAN_X
+ i
);
3817 IFETCH(&sample_r
, 1, TGSI_CHAN_X
+ sample
);
3819 mach
->Image
->load(mach
->Image
, ¶ms
,
3820 r
[0].i
, r
[1].i
, r
[2].i
, sample_r
.i
,
3822 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3823 r
[0].f
[j
] = rgba
[0][j
];
3824 r
[1].f
[j
] = rgba
[1][j
];
3825 r
[2].f
[j
] = rgba
[2][j
];
3826 r
[3].f
[j
] = rgba
[3][j
];
3828 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3829 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3830 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3836 exec_load_buf(struct tgsi_exec_machine
*mach
,
3837 const struct tgsi_full_instruction
*inst
)
3839 union tgsi_exec_channel r
[4];
3843 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3844 struct tgsi_buffer_params params
;
3845 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3847 unit
= fetch_sampler_unit(mach
, inst
, 0);
3849 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3851 IFETCH(&r
[0], 1, TGSI_CHAN_X
);
3853 mach
->Buffer
->load(mach
->Buffer
, ¶ms
,
3855 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3856 r
[0].f
[j
] = rgba
[0][j
];
3857 r
[1].f
[j
] = rgba
[1][j
];
3858 r
[2].f
[j
] = rgba
[2][j
];
3859 r
[3].f
[j
] = rgba
[3][j
];
3861 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3862 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3863 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3869 exec_load_mem(struct tgsi_exec_machine
*mach
,
3870 const struct tgsi_full_instruction
*inst
)
3872 union tgsi_exec_channel r
[4];
3874 char *ptr
= mach
->LocalMem
;
3878 IFETCH(&r
[0], 1, TGSI_CHAN_X
);
3879 if (r
[0].u
[0] >= mach
->LocalMemSize
)
3885 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3886 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3887 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3888 memcpy(&r
[chan
].u
[j
], ptr
+ (4 * chan
), 4);
3893 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3894 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3895 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3901 exec_load(struct tgsi_exec_machine
*mach
,
3902 const struct tgsi_full_instruction
*inst
)
3904 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
3905 exec_load_img(mach
, inst
);
3906 else if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
3907 exec_load_buf(mach
, inst
);
3908 else if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
3909 exec_load_mem(mach
, inst
);
3913 exec_store_img(struct tgsi_exec_machine
*mach
,
3914 const struct tgsi_full_instruction
*inst
)
3916 union tgsi_exec_channel r
[3], sample_r
;
3917 union tgsi_exec_channel value
[4];
3918 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3919 struct tgsi_image_params params
;
3924 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3925 unit
= inst
->Dst
[0].Register
.Index
;
3926 dim
= get_image_coord_dim(inst
->Memory
.Texture
);
3927 sample
= get_image_coord_sample(inst
->Memory
.Texture
);
3930 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3932 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
3933 params
.format
= inst
->Memory
.Format
;
3935 for (i
= 0; i
< dim
; i
++) {
3936 IFETCH(&r
[i
], 0, TGSI_CHAN_X
+ i
);
3939 for (i
= 0; i
< 4; i
++) {
3940 FETCH(&value
[i
], 1, TGSI_CHAN_X
+ i
);
3943 IFETCH(&sample_r
, 0, TGSI_CHAN_X
+ sample
);
3945 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3946 rgba
[0][j
] = value
[0].f
[j
];
3947 rgba
[1][j
] = value
[1].f
[j
];
3948 rgba
[2][j
] = value
[2].f
[j
];
3949 rgba
[3][j
] = value
[3].f
[j
];
3952 mach
->Image
->store(mach
->Image
, ¶ms
,
3953 r
[0].i
, r
[1].i
, r
[2].i
, sample_r
.i
,
3958 exec_store_buf(struct tgsi_exec_machine
*mach
,
3959 const struct tgsi_full_instruction
*inst
)
3961 union tgsi_exec_channel r
[3];
3962 union tgsi_exec_channel value
[4];
3963 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3964 struct tgsi_buffer_params params
;
3967 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3969 unit
= inst
->Dst
[0].Register
.Index
;
3971 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3973 params
.writemask
= inst
->Dst
[0].Register
.WriteMask
;
3975 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
3976 for (i
= 0; i
< 4; i
++) {
3977 FETCH(&value
[i
], 1, TGSI_CHAN_X
+ i
);
3980 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3981 rgba
[0][j
] = value
[0].f
[j
];
3982 rgba
[1][j
] = value
[1].f
[j
];
3983 rgba
[2][j
] = value
[2].f
[j
];
3984 rgba
[3][j
] = value
[3].f
[j
];
3987 mach
->Buffer
->store(mach
->Buffer
, ¶ms
,
3993 exec_store_mem(struct tgsi_exec_machine
*mach
,
3994 const struct tgsi_full_instruction
*inst
)
3996 union tgsi_exec_channel r
[3];
3997 union tgsi_exec_channel value
[4];
3999 char *ptr
= mach
->LocalMem
;
4000 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
4001 int execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
4003 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
4005 for (i
= 0; i
< 4; i
++) {
4006 FETCH(&value
[i
], 1, TGSI_CHAN_X
+ i
);
4009 if (r
[0].u
[0] >= mach
->LocalMemSize
)
4013 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
4014 if (execmask
& (1 << i
)) {
4015 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
4016 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
4017 memcpy(ptr
+ (chan
* 4), &value
[chan
].u
[0], 4);
4025 exec_store(struct tgsi_exec_machine
*mach
,
4026 const struct tgsi_full_instruction
*inst
)
4028 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_IMAGE
)
4029 exec_store_img(mach
, inst
);
4030 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
4031 exec_store_buf(mach
, inst
);
4032 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
4033 exec_store_mem(mach
, inst
);
4037 exec_atomop_img(struct tgsi_exec_machine
*mach
,
4038 const struct tgsi_full_instruction
*inst
)
4040 union tgsi_exec_channel r
[4], sample_r
;
4041 union tgsi_exec_channel value
[4], value2
[4];
4042 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
4043 float rgba2
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
4044 struct tgsi_image_params params
;
4049 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
4050 unit
= fetch_sampler_unit(mach
, inst
, 0);
4051 dim
= get_image_coord_dim(inst
->Memory
.Texture
);
4052 sample
= get_image_coord_sample(inst
->Memory
.Texture
);
4055 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
4057 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
4058 params
.format
= inst
->Memory
.Format
;
4060 for (i
= 0; i
< dim
; i
++) {
4061 IFETCH(&r
[i
], 1, TGSI_CHAN_X
+ i
);
4064 for (i
= 0; i
< 4; i
++) {
4065 FETCH(&value
[i
], 2, TGSI_CHAN_X
+ i
);
4066 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_ATOMCAS
)
4067 FETCH(&value2
[i
], 3, TGSI_CHAN_X
+ i
);
4070 IFETCH(&sample_r
, 1, TGSI_CHAN_X
+ sample
);
4072 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
4073 rgba
[0][j
] = value
[0].f
[j
];
4074 rgba
[1][j
] = value
[1].f
[j
];
4075 rgba
[2][j
] = value
[2].f
[j
];
4076 rgba
[3][j
] = value
[3].f
[j
];
4078 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_ATOMCAS
) {
4079 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
4080 rgba2
[0][j
] = value2
[0].f
[j
];
4081 rgba2
[1][j
] = value2
[1].f
[j
];
4082 rgba2
[2][j
] = value2
[2].f
[j
];
4083 rgba2
[3][j
] = value2
[3].f
[j
];
4087 mach
->Image
->op(mach
->Image
, ¶ms
, inst
->Instruction
.Opcode
,
4088 r
[0].i
, r
[1].i
, r
[2].i
, sample_r
.i
,
4091 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
4092 r
[0].f
[j
] = rgba
[0][j
];
4093 r
[1].f
[j
] = rgba
[1][j
];
4094 r
[2].f
[j
] = rgba
[2][j
];
4095 r
[3].f
[j
] = rgba
[3][j
];
4097 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
4098 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
4099 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
4105 exec_atomop_buf(struct tgsi_exec_machine
*mach
,
4106 const struct tgsi_full_instruction
*inst
)
4108 union tgsi_exec_channel r
[4];
4109 union tgsi_exec_channel value
[4], value2
[4];
4110 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
4111 float rgba2
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
4112 struct tgsi_buffer_params params
;
4115 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
4117 unit
= fetch_sampler_unit(mach
, inst
, 0);
4119 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
4121 params
.writemask
= inst
->Dst
[0].Register
.WriteMask
;
4123 IFETCH(&r
[0], 1, TGSI_CHAN_X
);
4125 for (i
= 0; i
< 4; i
++) {
4126 FETCH(&value
[i
], 2, TGSI_CHAN_X
+ i
);
4127 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_ATOMCAS
)
4128 FETCH(&value2
[i
], 3, TGSI_CHAN_X
+ i
);
4131 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
4132 rgba
[0][j
] = value
[0].f
[j
];
4133 rgba
[1][j
] = value
[1].f
[j
];
4134 rgba
[2][j
] = value
[2].f
[j
];
4135 rgba
[3][j
] = value
[3].f
[j
];
4137 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_ATOMCAS
) {
4138 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
4139 rgba2
[0][j
] = value2
[0].f
[j
];
4140 rgba2
[1][j
] = value2
[1].f
[j
];
4141 rgba2
[2][j
] = value2
[2].f
[j
];
4142 rgba2
[3][j
] = value2
[3].f
[j
];
4146 mach
->Buffer
->op(mach
->Buffer
, ¶ms
, inst
->Instruction
.Opcode
,
4150 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
4151 r
[0].f
[j
] = rgba
[0][j
];
4152 r
[1].f
[j
] = rgba
[1][j
];
4153 r
[2].f
[j
] = rgba
[2][j
];
4154 r
[3].f
[j
] = rgba
[3][j
];
4156 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
4157 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
4158 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
4164 exec_atomop_mem(struct tgsi_exec_machine
*mach
,
4165 const struct tgsi_full_instruction
*inst
)
4167 union tgsi_exec_channel r
[4];
4168 union tgsi_exec_channel value
[4], value2
[4];
4169 char *ptr
= mach
->LocalMem
;
4173 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
4174 int execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
4175 IFETCH(&r
[0], 1, TGSI_CHAN_X
);
4177 if (r
[0].u
[0] >= mach
->LocalMemSize
)
4182 for (i
= 0; i
< 4; i
++) {
4183 FETCH(&value
[i
], 2, TGSI_CHAN_X
+ i
);
4184 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_ATOMCAS
)
4185 FETCH(&value2
[i
], 3, TGSI_CHAN_X
+ i
);
4188 memcpy(&r
[0].u
[0], ptr
, 4);
4190 switch (inst
->Instruction
.Opcode
) {
4191 case TGSI_OPCODE_ATOMUADD
:
4192 val
+= value
[0].u
[0];
4194 case TGSI_OPCODE_ATOMXOR
:
4195 val
^= value
[0].u
[0];
4197 case TGSI_OPCODE_ATOMOR
:
4198 val
|= value
[0].u
[0];
4200 case TGSI_OPCODE_ATOMAND
:
4201 val
&= value
[0].u
[0];
4203 case TGSI_OPCODE_ATOMUMIN
:
4204 val
= MIN2(val
, value
[0].u
[0]);
4206 case TGSI_OPCODE_ATOMUMAX
:
4207 val
= MAX2(val
, value
[0].u
[0]);
4209 case TGSI_OPCODE_ATOMIMIN
:
4210 val
= MIN2(r
[0].i
[0], value
[0].i
[0]);
4212 case TGSI_OPCODE_ATOMIMAX
:
4213 val
= MAX2(r
[0].i
[0], value
[0].i
[0]);
4215 case TGSI_OPCODE_ATOMXCHG
:
4216 val
= value
[0].i
[0];
4218 case TGSI_OPCODE_ATOMCAS
:
4219 if (val
== value
[0].u
[0])
4220 val
= value2
[0].u
[0];
4225 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
4226 if (execmask
& (1 << i
))
4227 memcpy(ptr
, &val
, 4);
4229 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
4230 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
4231 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
4237 exec_atomop(struct tgsi_exec_machine
*mach
,
4238 const struct tgsi_full_instruction
*inst
)
4240 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
4241 exec_atomop_img(mach
, inst
);
4242 else if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
4243 exec_atomop_buf(mach
, inst
);
4244 else if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
4245 exec_atomop_mem(mach
, inst
);
4249 exec_resq_img(struct tgsi_exec_machine
*mach
,
4250 const struct tgsi_full_instruction
*inst
)
4253 union tgsi_exec_channel r
[4];
4256 struct tgsi_image_params params
;
4257 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
4259 unit
= fetch_sampler_unit(mach
, inst
, 0);
4261 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
4263 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
4264 params
.format
= inst
->Memory
.Format
;
4266 mach
->Image
->get_dims(mach
->Image
, ¶ms
, result
);
4268 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
4269 for (j
= 0; j
< 4; j
++) {
4270 r
[j
].i
[i
] = result
[j
];
4274 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
4275 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
4276 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
4277 TGSI_EXEC_DATA_INT
);
4283 exec_resq_buf(struct tgsi_exec_machine
*mach
,
4284 const struct tgsi_full_instruction
*inst
)
4287 union tgsi_exec_channel r
[4];
4290 struct tgsi_buffer_params params
;
4291 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
4293 unit
= fetch_sampler_unit(mach
, inst
, 0);
4295 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
4298 mach
->Buffer
->get_dims(mach
->Buffer
, ¶ms
, &result
);
4300 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
4304 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
4305 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
4306 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
4307 TGSI_EXEC_DATA_INT
);
4313 exec_resq(struct tgsi_exec_machine
*mach
,
4314 const struct tgsi_full_instruction
*inst
)
4316 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
4317 exec_resq_img(mach
, inst
);
4319 exec_resq_buf(mach
, inst
);
4323 micro_f2u64(union tgsi_double_channel
*dst
,
4324 const union tgsi_exec_channel
*src
)
4326 dst
->u64
[0] = (uint64_t)src
->f
[0];
4327 dst
->u64
[1] = (uint64_t)src
->f
[1];
4328 dst
->u64
[2] = (uint64_t)src
->f
[2];
4329 dst
->u64
[3] = (uint64_t)src
->f
[3];
4333 micro_f2i64(union tgsi_double_channel
*dst
,
4334 const union tgsi_exec_channel
*src
)
4336 dst
->i64
[0] = (int64_t)src
->f
[0];
4337 dst
->i64
[1] = (int64_t)src
->f
[1];
4338 dst
->i64
[2] = (int64_t)src
->f
[2];
4339 dst
->i64
[3] = (int64_t)src
->f
[3];
4343 micro_u2i64(union tgsi_double_channel
*dst
,
4344 const union tgsi_exec_channel
*src
)
4346 dst
->u64
[0] = (uint64_t)src
->u
[0];
4347 dst
->u64
[1] = (uint64_t)src
->u
[1];
4348 dst
->u64
[2] = (uint64_t)src
->u
[2];
4349 dst
->u64
[3] = (uint64_t)src
->u
[3];
4353 micro_i2i64(union tgsi_double_channel
*dst
,
4354 const union tgsi_exec_channel
*src
)
4356 dst
->i64
[0] = (int64_t)src
->i
[0];
4357 dst
->i64
[1] = (int64_t)src
->i
[1];
4358 dst
->i64
[2] = (int64_t)src
->i
[2];
4359 dst
->i64
[3] = (int64_t)src
->i
[3];
4363 micro_d2u64(union tgsi_double_channel
*dst
,
4364 const union tgsi_double_channel
*src
)
4366 dst
->u64
[0] = (uint64_t)src
->d
[0];
4367 dst
->u64
[1] = (uint64_t)src
->d
[1];
4368 dst
->u64
[2] = (uint64_t)src
->d
[2];
4369 dst
->u64
[3] = (uint64_t)src
->d
[3];
4373 micro_d2i64(union tgsi_double_channel
*dst
,
4374 const union tgsi_double_channel
*src
)
4376 dst
->i64
[0] = (int64_t)src
->d
[0];
4377 dst
->i64
[1] = (int64_t)src
->d
[1];
4378 dst
->i64
[2] = (int64_t)src
->d
[2];
4379 dst
->i64
[3] = (int64_t)src
->d
[3];
4383 micro_u642d(union tgsi_double_channel
*dst
,
4384 const union tgsi_double_channel
*src
)
4386 dst
->d
[0] = (double)src
->u64
[0];
4387 dst
->d
[1] = (double)src
->u64
[1];
4388 dst
->d
[2] = (double)src
->u64
[2];
4389 dst
->d
[3] = (double)src
->u64
[3];
4393 micro_i642d(union tgsi_double_channel
*dst
,
4394 const union tgsi_double_channel
*src
)
4396 dst
->d
[0] = (double)src
->i64
[0];
4397 dst
->d
[1] = (double)src
->i64
[1];
4398 dst
->d
[2] = (double)src
->i64
[2];
4399 dst
->d
[3] = (double)src
->i64
[3];
4403 micro_u642f(union tgsi_exec_channel
*dst
,
4404 const union tgsi_double_channel
*src
)
4406 dst
->f
[0] = (float)src
->u64
[0];
4407 dst
->f
[1] = (float)src
->u64
[1];
4408 dst
->f
[2] = (float)src
->u64
[2];
4409 dst
->f
[3] = (float)src
->u64
[3];
4413 micro_i642f(union tgsi_exec_channel
*dst
,
4414 const union tgsi_double_channel
*src
)
4416 dst
->f
[0] = (float)src
->i64
[0];
4417 dst
->f
[1] = (float)src
->i64
[1];
4418 dst
->f
[2] = (float)src
->i64
[2];
4419 dst
->f
[3] = (float)src
->i64
[3];
4423 exec_t_2_64(struct tgsi_exec_machine
*mach
,
4424 const struct tgsi_full_instruction
*inst
,
4426 enum tgsi_exec_datatype src_datatype
)
4428 union tgsi_exec_channel src
;
4429 union tgsi_double_channel dst
;
4431 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
4432 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
4434 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
4436 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
4437 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Y
, src_datatype
);
4439 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
4444 exec_64_2_t(struct tgsi_exec_machine
*mach
,
4445 const struct tgsi_full_instruction
*inst
,
4447 enum tgsi_exec_datatype dst_datatype
)
4449 union tgsi_double_channel src
;
4450 union tgsi_exec_channel dst
;
4451 int wm
= inst
->Dst
[0].Register
.WriteMask
;
4454 for (i
= 0; i
< 2; i
++) {
4457 wm
&= ~(1 << (bit
- 1));
4459 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
4461 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
4463 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, bit
- 1, dst_datatype
);
4469 micro_i2f(union tgsi_exec_channel
*dst
,
4470 const union tgsi_exec_channel
*src
)
4472 dst
->f
[0] = (float)src
->i
[0];
4473 dst
->f
[1] = (float)src
->i
[1];
4474 dst
->f
[2] = (float)src
->i
[2];
4475 dst
->f
[3] = (float)src
->i
[3];
4479 micro_not(union tgsi_exec_channel
*dst
,
4480 const union tgsi_exec_channel
*src
)
4482 dst
->u
[0] = ~src
->u
[0];
4483 dst
->u
[1] = ~src
->u
[1];
4484 dst
->u
[2] = ~src
->u
[2];
4485 dst
->u
[3] = ~src
->u
[3];
4489 micro_shl(union tgsi_exec_channel
*dst
,
4490 const union tgsi_exec_channel
*src0
,
4491 const union tgsi_exec_channel
*src1
)
4493 unsigned masked_count
;
4494 masked_count
= src1
->u
[0] & 0x1f;
4495 dst
->u
[0] = src0
->u
[0] << masked_count
;
4496 masked_count
= src1
->u
[1] & 0x1f;
4497 dst
->u
[1] = src0
->u
[1] << masked_count
;
4498 masked_count
= src1
->u
[2] & 0x1f;
4499 dst
->u
[2] = src0
->u
[2] << masked_count
;
4500 masked_count
= src1
->u
[3] & 0x1f;
4501 dst
->u
[3] = src0
->u
[3] << masked_count
;
4505 micro_and(union tgsi_exec_channel
*dst
,
4506 const union tgsi_exec_channel
*src0
,
4507 const union tgsi_exec_channel
*src1
)
4509 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
4510 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
4511 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
4512 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
4516 micro_or(union tgsi_exec_channel
*dst
,
4517 const union tgsi_exec_channel
*src0
,
4518 const union tgsi_exec_channel
*src1
)
4520 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
4521 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
4522 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
4523 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
4527 micro_xor(union tgsi_exec_channel
*dst
,
4528 const union tgsi_exec_channel
*src0
,
4529 const union tgsi_exec_channel
*src1
)
4531 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
4532 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
4533 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
4534 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
4538 micro_mod(union tgsi_exec_channel
*dst
,
4539 const union tgsi_exec_channel
*src0
,
4540 const union tgsi_exec_channel
*src1
)
4542 dst
->i
[0] = src1
->i
[0] ? src0
->i
[0] % src1
->i
[0] : ~0;
4543 dst
->i
[1] = src1
->i
[1] ? src0
->i
[1] % src1
->i
[1] : ~0;
4544 dst
->i
[2] = src1
->i
[2] ? src0
->i
[2] % src1
->i
[2] : ~0;
4545 dst
->i
[3] = src1
->i
[3] ? src0
->i
[3] % src1
->i
[3] : ~0;
4549 micro_f2i(union tgsi_exec_channel
*dst
,
4550 const union tgsi_exec_channel
*src
)
4552 dst
->i
[0] = (int)src
->f
[0];
4553 dst
->i
[1] = (int)src
->f
[1];
4554 dst
->i
[2] = (int)src
->f
[2];
4555 dst
->i
[3] = (int)src
->f
[3];
4559 micro_fseq(union tgsi_exec_channel
*dst
,
4560 const union tgsi_exec_channel
*src0
,
4561 const union tgsi_exec_channel
*src1
)
4563 dst
->u
[0] = src0
->f
[0] == src1
->f
[0] ? ~0 : 0;
4564 dst
->u
[1] = src0
->f
[1] == src1
->f
[1] ? ~0 : 0;
4565 dst
->u
[2] = src0
->f
[2] == src1
->f
[2] ? ~0 : 0;
4566 dst
->u
[3] = src0
->f
[3] == src1
->f
[3] ? ~0 : 0;
4570 micro_fsge(union tgsi_exec_channel
*dst
,
4571 const union tgsi_exec_channel
*src0
,
4572 const union tgsi_exec_channel
*src1
)
4574 dst
->u
[0] = src0
->f
[0] >= src1
->f
[0] ? ~0 : 0;
4575 dst
->u
[1] = src0
->f
[1] >= src1
->f
[1] ? ~0 : 0;
4576 dst
->u
[2] = src0
->f
[2] >= src1
->f
[2] ? ~0 : 0;
4577 dst
->u
[3] = src0
->f
[3] >= src1
->f
[3] ? ~0 : 0;
4581 micro_fslt(union tgsi_exec_channel
*dst
,
4582 const union tgsi_exec_channel
*src0
,
4583 const union tgsi_exec_channel
*src1
)
4585 dst
->u
[0] = src0
->f
[0] < src1
->f
[0] ? ~0 : 0;
4586 dst
->u
[1] = src0
->f
[1] < src1
->f
[1] ? ~0 : 0;
4587 dst
->u
[2] = src0
->f
[2] < src1
->f
[2] ? ~0 : 0;
4588 dst
->u
[3] = src0
->f
[3] < src1
->f
[3] ? ~0 : 0;
4592 micro_fsne(union tgsi_exec_channel
*dst
,
4593 const union tgsi_exec_channel
*src0
,
4594 const union tgsi_exec_channel
*src1
)
4596 dst
->u
[0] = src0
->f
[0] != src1
->f
[0] ? ~0 : 0;
4597 dst
->u
[1] = src0
->f
[1] != src1
->f
[1] ? ~0 : 0;
4598 dst
->u
[2] = src0
->f
[2] != src1
->f
[2] ? ~0 : 0;
4599 dst
->u
[3] = src0
->f
[3] != src1
->f
[3] ? ~0 : 0;
4603 micro_idiv(union tgsi_exec_channel
*dst
,
4604 const union tgsi_exec_channel
*src0
,
4605 const union tgsi_exec_channel
*src1
)
4607 dst
->i
[0] = src1
->i
[0] ? src0
->i
[0] / src1
->i
[0] : 0;
4608 dst
->i
[1] = src1
->i
[1] ? src0
->i
[1] / src1
->i
[1] : 0;
4609 dst
->i
[2] = src1
->i
[2] ? src0
->i
[2] / src1
->i
[2] : 0;
4610 dst
->i
[3] = src1
->i
[3] ? src0
->i
[3] / src1
->i
[3] : 0;
4614 micro_imax(union tgsi_exec_channel
*dst
,
4615 const union tgsi_exec_channel
*src0
,
4616 const union tgsi_exec_channel
*src1
)
4618 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
4619 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
4620 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
4621 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
4625 micro_imin(union tgsi_exec_channel
*dst
,
4626 const union tgsi_exec_channel
*src0
,
4627 const union tgsi_exec_channel
*src1
)
4629 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
4630 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
4631 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
4632 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
4636 micro_isge(union tgsi_exec_channel
*dst
,
4637 const union tgsi_exec_channel
*src0
,
4638 const union tgsi_exec_channel
*src1
)
4640 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
4641 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
4642 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
4643 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
4647 micro_ishr(union tgsi_exec_channel
*dst
,
4648 const union tgsi_exec_channel
*src0
,
4649 const union tgsi_exec_channel
*src1
)
4651 unsigned masked_count
;
4652 masked_count
= src1
->i
[0] & 0x1f;
4653 dst
->i
[0] = src0
->i
[0] >> masked_count
;
4654 masked_count
= src1
->i
[1] & 0x1f;
4655 dst
->i
[1] = src0
->i
[1] >> masked_count
;
4656 masked_count
= src1
->i
[2] & 0x1f;
4657 dst
->i
[2] = src0
->i
[2] >> masked_count
;
4658 masked_count
= src1
->i
[3] & 0x1f;
4659 dst
->i
[3] = src0
->i
[3] >> masked_count
;
4663 micro_islt(union tgsi_exec_channel
*dst
,
4664 const union tgsi_exec_channel
*src0
,
4665 const union tgsi_exec_channel
*src1
)
4667 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
4668 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
4669 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
4670 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
4674 micro_f2u(union tgsi_exec_channel
*dst
,
4675 const union tgsi_exec_channel
*src
)
4677 dst
->u
[0] = (uint
)src
->f
[0];
4678 dst
->u
[1] = (uint
)src
->f
[1];
4679 dst
->u
[2] = (uint
)src
->f
[2];
4680 dst
->u
[3] = (uint
)src
->f
[3];
4684 micro_u2f(union tgsi_exec_channel
*dst
,
4685 const union tgsi_exec_channel
*src
)
4687 dst
->f
[0] = (float)src
->u
[0];
4688 dst
->f
[1] = (float)src
->u
[1];
4689 dst
->f
[2] = (float)src
->u
[2];
4690 dst
->f
[3] = (float)src
->u
[3];
4694 micro_uadd(union tgsi_exec_channel
*dst
,
4695 const union tgsi_exec_channel
*src0
,
4696 const union tgsi_exec_channel
*src1
)
4698 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
4699 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
4700 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
4701 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
4705 micro_udiv(union tgsi_exec_channel
*dst
,
4706 const union tgsi_exec_channel
*src0
,
4707 const union tgsi_exec_channel
*src1
)
4709 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] / src1
->u
[0] : ~0u;
4710 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] / src1
->u
[1] : ~0u;
4711 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] / src1
->u
[2] : ~0u;
4712 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] / src1
->u
[3] : ~0u;
4716 micro_umad(union tgsi_exec_channel
*dst
,
4717 const union tgsi_exec_channel
*src0
,
4718 const union tgsi_exec_channel
*src1
,
4719 const union tgsi_exec_channel
*src2
)
4721 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
4722 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
4723 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
4724 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
4728 micro_umax(union tgsi_exec_channel
*dst
,
4729 const union tgsi_exec_channel
*src0
,
4730 const union tgsi_exec_channel
*src1
)
4732 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
4733 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
4734 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
4735 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
4739 micro_umin(union tgsi_exec_channel
*dst
,
4740 const union tgsi_exec_channel
*src0
,
4741 const union tgsi_exec_channel
*src1
)
4743 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
4744 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
4745 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
4746 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
4750 micro_umod(union tgsi_exec_channel
*dst
,
4751 const union tgsi_exec_channel
*src0
,
4752 const union tgsi_exec_channel
*src1
)
4754 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] % src1
->u
[0] : ~0u;
4755 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] % src1
->u
[1] : ~0u;
4756 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] % src1
->u
[2] : ~0u;
4757 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] % src1
->u
[3] : ~0u;
4761 micro_umul(union tgsi_exec_channel
*dst
,
4762 const union tgsi_exec_channel
*src0
,
4763 const union tgsi_exec_channel
*src1
)
4765 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
4766 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
4767 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
4768 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
4772 micro_imul_hi(union tgsi_exec_channel
*dst
,
4773 const union tgsi_exec_channel
*src0
,
4774 const union tgsi_exec_channel
*src1
)
4776 #define I64M(x, y) ((((int64_t)x) * ((int64_t)y)) >> 32)
4777 dst
->i
[0] = I64M(src0
->i
[0], src1
->i
[0]);
4778 dst
->i
[1] = I64M(src0
->i
[1], src1
->i
[1]);
4779 dst
->i
[2] = I64M(src0
->i
[2], src1
->i
[2]);
4780 dst
->i
[3] = I64M(src0
->i
[3], src1
->i
[3]);
4785 micro_umul_hi(union tgsi_exec_channel
*dst
,
4786 const union tgsi_exec_channel
*src0
,
4787 const union tgsi_exec_channel
*src1
)
4789 #define U64M(x, y) ((((uint64_t)x) * ((uint64_t)y)) >> 32)
4790 dst
->u
[0] = U64M(src0
->u
[0], src1
->u
[0]);
4791 dst
->u
[1] = U64M(src0
->u
[1], src1
->u
[1]);
4792 dst
->u
[2] = U64M(src0
->u
[2], src1
->u
[2]);
4793 dst
->u
[3] = U64M(src0
->u
[3], src1
->u
[3]);
4798 micro_useq(union tgsi_exec_channel
*dst
,
4799 const union tgsi_exec_channel
*src0
,
4800 const union tgsi_exec_channel
*src1
)
4802 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
4803 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
4804 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
4805 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
4809 micro_usge(union tgsi_exec_channel
*dst
,
4810 const union tgsi_exec_channel
*src0
,
4811 const union tgsi_exec_channel
*src1
)
4813 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
4814 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
4815 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
4816 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
4820 micro_ushr(union tgsi_exec_channel
*dst
,
4821 const union tgsi_exec_channel
*src0
,
4822 const union tgsi_exec_channel
*src1
)
4824 unsigned masked_count
;
4825 masked_count
= src1
->u
[0] & 0x1f;
4826 dst
->u
[0] = src0
->u
[0] >> masked_count
;
4827 masked_count
= src1
->u
[1] & 0x1f;
4828 dst
->u
[1] = src0
->u
[1] >> masked_count
;
4829 masked_count
= src1
->u
[2] & 0x1f;
4830 dst
->u
[2] = src0
->u
[2] >> masked_count
;
4831 masked_count
= src1
->u
[3] & 0x1f;
4832 dst
->u
[3] = src0
->u
[3] >> masked_count
;
4836 micro_uslt(union tgsi_exec_channel
*dst
,
4837 const union tgsi_exec_channel
*src0
,
4838 const union tgsi_exec_channel
*src1
)
4840 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
4841 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
4842 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
4843 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
4847 micro_usne(union tgsi_exec_channel
*dst
,
4848 const union tgsi_exec_channel
*src0
,
4849 const union tgsi_exec_channel
*src1
)
4851 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
4852 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
4853 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
4854 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
4858 micro_uarl(union tgsi_exec_channel
*dst
,
4859 const union tgsi_exec_channel
*src
)
4861 dst
->i
[0] = src
->u
[0];
4862 dst
->i
[1] = src
->u
[1];
4863 dst
->i
[2] = src
->u
[2];
4864 dst
->i
[3] = src
->u
[3];
4868 * Signed bitfield extract (i.e. sign-extend the extracted bits)
4871 micro_ibfe(union tgsi_exec_channel
*dst
,
4872 const union tgsi_exec_channel
*src0
,
4873 const union tgsi_exec_channel
*src1
,
4874 const union tgsi_exec_channel
*src2
)
4877 for (i
= 0; i
< 4; i
++) {
4878 int width
= src2
->i
[i
] & 0x1f;
4879 int offset
= src1
->i
[i
] & 0x1f;
4882 else if (width
+ offset
< 32)
4883 dst
->i
[i
] = (src0
->i
[i
] << (32 - width
- offset
)) >> (32 - width
);
4885 dst
->i
[i
] = src0
->i
[i
] >> offset
;
4890 * Unsigned bitfield extract
4893 micro_ubfe(union tgsi_exec_channel
*dst
,
4894 const union tgsi_exec_channel
*src0
,
4895 const union tgsi_exec_channel
*src1
,
4896 const union tgsi_exec_channel
*src2
)
4899 for (i
= 0; i
< 4; i
++) {
4900 int width
= src2
->u
[i
] & 0x1f;
4901 int offset
= src1
->u
[i
] & 0x1f;
4904 else if (width
+ offset
< 32)
4905 dst
->u
[i
] = (src0
->u
[i
] << (32 - width
- offset
)) >> (32 - width
);
4907 dst
->u
[i
] = src0
->u
[i
] >> offset
;
4912 * Bitfield insert: copy low bits from src1 into a region of src0.
4915 micro_bfi(union tgsi_exec_channel
*dst
,
4916 const union tgsi_exec_channel
*src0
,
4917 const union tgsi_exec_channel
*src1
,
4918 const union tgsi_exec_channel
*src2
,
4919 const union tgsi_exec_channel
*src3
)
4922 for (i
= 0; i
< 4; i
++) {
4923 int width
= src3
->u
[i
] & 0x1f;
4924 int offset
= src2
->u
[i
] & 0x1f;
4925 int bitmask
= ((1 << width
) - 1) << offset
;
4926 dst
->u
[i
] = ((src1
->u
[i
] << offset
) & bitmask
) | (src0
->u
[i
] & ~bitmask
);
4931 micro_brev(union tgsi_exec_channel
*dst
,
4932 const union tgsi_exec_channel
*src
)
4934 dst
->u
[0] = util_bitreverse(src
->u
[0]);
4935 dst
->u
[1] = util_bitreverse(src
->u
[1]);
4936 dst
->u
[2] = util_bitreverse(src
->u
[2]);
4937 dst
->u
[3] = util_bitreverse(src
->u
[3]);
4941 micro_popc(union tgsi_exec_channel
*dst
,
4942 const union tgsi_exec_channel
*src
)
4944 dst
->u
[0] = util_bitcount(src
->u
[0]);
4945 dst
->u
[1] = util_bitcount(src
->u
[1]);
4946 dst
->u
[2] = util_bitcount(src
->u
[2]);
4947 dst
->u
[3] = util_bitcount(src
->u
[3]);
4951 micro_lsb(union tgsi_exec_channel
*dst
,
4952 const union tgsi_exec_channel
*src
)
4954 dst
->i
[0] = ffs(src
->u
[0]) - 1;
4955 dst
->i
[1] = ffs(src
->u
[1]) - 1;
4956 dst
->i
[2] = ffs(src
->u
[2]) - 1;
4957 dst
->i
[3] = ffs(src
->u
[3]) - 1;
4961 micro_imsb(union tgsi_exec_channel
*dst
,
4962 const union tgsi_exec_channel
*src
)
4964 dst
->i
[0] = util_last_bit_signed(src
->i
[0]) - 1;
4965 dst
->i
[1] = util_last_bit_signed(src
->i
[1]) - 1;
4966 dst
->i
[2] = util_last_bit_signed(src
->i
[2]) - 1;
4967 dst
->i
[3] = util_last_bit_signed(src
->i
[3]) - 1;
4971 micro_umsb(union tgsi_exec_channel
*dst
,
4972 const union tgsi_exec_channel
*src
)
4974 dst
->i
[0] = util_last_bit(src
->u
[0]) - 1;
4975 dst
->i
[1] = util_last_bit(src
->u
[1]) - 1;
4976 dst
->i
[2] = util_last_bit(src
->u
[2]) - 1;
4977 dst
->i
[3] = util_last_bit(src
->u
[3]) - 1;
4981 * Execute a TGSI instruction.
4982 * Returns TRUE if a barrier instruction is hit,
4987 struct tgsi_exec_machine
*mach
,
4988 const struct tgsi_full_instruction
*inst
,
4991 union tgsi_exec_channel r
[10];
4995 switch (inst
->Instruction
.Opcode
) {
4996 case TGSI_OPCODE_ARL
:
4997 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
5000 case TGSI_OPCODE_MOV
:
5001 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5004 case TGSI_OPCODE_LIT
:
5005 exec_lit(mach
, inst
);
5008 case TGSI_OPCODE_RCP
:
5009 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5012 case TGSI_OPCODE_RSQ
:
5013 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5016 case TGSI_OPCODE_EXP
:
5017 exec_exp(mach
, inst
);
5020 case TGSI_OPCODE_LOG
:
5021 exec_log(mach
, inst
);
5024 case TGSI_OPCODE_MUL
:
5025 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5028 case TGSI_OPCODE_ADD
:
5029 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5032 case TGSI_OPCODE_DP3
:
5033 exec_dp3(mach
, inst
);
5036 case TGSI_OPCODE_DP4
:
5037 exec_dp4(mach
, inst
);
5040 case TGSI_OPCODE_DST
:
5041 exec_dst(mach
, inst
);
5044 case TGSI_OPCODE_MIN
:
5045 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5048 case TGSI_OPCODE_MAX
:
5049 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5052 case TGSI_OPCODE_SLT
:
5053 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5056 case TGSI_OPCODE_SGE
:
5057 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5060 case TGSI_OPCODE_MAD
:
5061 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5064 case TGSI_OPCODE_LRP
:
5065 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5068 case TGSI_OPCODE_SQRT
:
5069 exec_scalar_unary(mach
, inst
, micro_sqrt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5072 case TGSI_OPCODE_FRC
:
5073 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5076 case TGSI_OPCODE_FLR
:
5077 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5080 case TGSI_OPCODE_ROUND
:
5081 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5084 case TGSI_OPCODE_EX2
:
5085 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5088 case TGSI_OPCODE_LG2
:
5089 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5092 case TGSI_OPCODE_POW
:
5093 exec_scalar_binary(mach
, inst
, micro_pow
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5096 case TGSI_OPCODE_LDEXP
:
5097 exec_scalar_binary(mach
, inst
, micro_ldexp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
5100 case TGSI_OPCODE_COS
:
5101 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5104 case TGSI_OPCODE_DDX
:
5105 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5108 case TGSI_OPCODE_DDY
:
5109 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5112 case TGSI_OPCODE_KILL
:
5113 exec_kill (mach
, inst
);
5116 case TGSI_OPCODE_KILL_IF
:
5117 exec_kill_if (mach
, inst
);
5120 case TGSI_OPCODE_PK2H
:
5121 exec_pk2h(mach
, inst
);
5124 case TGSI_OPCODE_PK2US
:
5128 case TGSI_OPCODE_PK4B
:
5132 case TGSI_OPCODE_PK4UB
:
5136 case TGSI_OPCODE_SEQ
:
5137 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5140 case TGSI_OPCODE_SGT
:
5141 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5144 case TGSI_OPCODE_SIN
:
5145 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5148 case TGSI_OPCODE_SLE
:
5149 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5152 case TGSI_OPCODE_SNE
:
5153 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5156 case TGSI_OPCODE_TEX
:
5157 /* simple texture lookup */
5158 /* src[0] = texcoord */
5159 /* src[1] = sampler unit */
5160 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 1);
5163 case TGSI_OPCODE_TXB
:
5164 /* Texture lookup with lod bias */
5165 /* src[0] = texcoord (src[0].w = LOD bias) */
5166 /* src[1] = sampler unit */
5167 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 1);
5170 case TGSI_OPCODE_TXD
:
5171 /* Texture lookup with explict partial derivatives */
5172 /* src[0] = texcoord */
5173 /* src[1] = d[strq]/dx */
5174 /* src[2] = d[strq]/dy */
5175 /* src[3] = sampler unit */
5176 exec_txd(mach
, inst
);
5179 case TGSI_OPCODE_TXL
:
5180 /* Texture lookup with explit LOD */
5181 /* src[0] = texcoord (src[0].w = LOD) */
5182 /* src[1] = sampler unit */
5183 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 1);
5186 case TGSI_OPCODE_TXP
:
5187 /* Texture lookup with projection */
5188 /* src[0] = texcoord (src[0].w = projection) */
5189 /* src[1] = sampler unit */
5190 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
, 1);
5193 case TGSI_OPCODE_TG4
:
5194 /* src[0] = texcoord */
5195 /* src[1] = component */
5196 /* src[2] = sampler unit */
5197 exec_tex(mach
, inst
, TEX_MODIFIER_GATHER
, 2);
5200 case TGSI_OPCODE_LODQ
:
5201 /* src[0] = texcoord */
5202 /* src[1] = sampler unit */
5203 exec_lodq(mach
, inst
);
5206 case TGSI_OPCODE_UP2H
:
5207 exec_up2h(mach
, inst
);
5210 case TGSI_OPCODE_UP2US
:
5214 case TGSI_OPCODE_UP4B
:
5218 case TGSI_OPCODE_UP4UB
:
5222 case TGSI_OPCODE_ARR
:
5223 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
5226 case TGSI_OPCODE_CAL
:
5227 /* skip the call if no execution channels are enabled */
5228 if (mach
->ExecMask
) {
5231 /* First, record the depths of the execution stacks.
5232 * This is important for deeply nested/looped return statements.
5233 * We have to unwind the stacks by the correct amount. For a
5234 * real code generator, we could determine the number of entries
5235 * to pop off each stack with simple static analysis and avoid
5236 * implementing this data structure at run time.
5238 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
5239 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
5240 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
5241 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
5242 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
5243 /* note that PC was already incremented above */
5244 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
5246 mach
->CallStackTop
++;
5248 /* Second, push the Cond, Loop, Cont, Func stacks */
5249 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
5250 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
5251 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
5252 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
5253 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
5254 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
5256 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
5257 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
5258 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
5259 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
5260 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
5261 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
5263 /* Finally, jump to the subroutine. The label is a pointer
5264 * (an instruction number) to the BGNSUB instruction.
5266 *pc
= inst
->Label
.Label
;
5267 assert(mach
->Instructions
[*pc
].Instruction
.Opcode
5268 == TGSI_OPCODE_BGNSUB
);
5272 case TGSI_OPCODE_RET
:
5273 mach
->FuncMask
&= ~mach
->ExecMask
;
5274 UPDATE_EXEC_MASK(mach
);
5276 if (mach
->FuncMask
== 0x0) {
5277 /* really return now (otherwise, keep executing */
5279 if (mach
->CallStackTop
== 0) {
5280 /* returning from main() */
5281 mach
->CondStackTop
= 0;
5282 mach
->LoopStackTop
= 0;
5283 mach
->ContStackTop
= 0;
5284 mach
->LoopLabelStackTop
= 0;
5285 mach
->SwitchStackTop
= 0;
5286 mach
->BreakStackTop
= 0;
5291 assert(mach
->CallStackTop
> 0);
5292 mach
->CallStackTop
--;
5294 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
5295 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
5297 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
5298 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
5300 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
5301 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
5303 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
5304 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
5306 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
5307 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
5309 assert(mach
->FuncStackTop
> 0);
5310 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
5312 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
5314 UPDATE_EXEC_MASK(mach
);
5318 case TGSI_OPCODE_SSG
:
5319 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5322 case TGSI_OPCODE_CMP
:
5323 exec_vector_trinary(mach
, inst
, micro_cmp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5326 case TGSI_OPCODE_DIV
:
5327 exec_vector_binary(mach
, inst
, micro_div
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5330 case TGSI_OPCODE_DP2
:
5331 exec_dp2(mach
, inst
);
5334 case TGSI_OPCODE_IF
:
5336 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
5337 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
5338 FETCH( &r
[0], 0, TGSI_CHAN_X
);
5339 /* update CondMask */
5341 mach
->CondMask
&= ~0x1;
5344 mach
->CondMask
&= ~0x2;
5347 mach
->CondMask
&= ~0x4;
5350 mach
->CondMask
&= ~0x8;
5352 UPDATE_EXEC_MASK(mach
);
5353 /* Todo: If CondMask==0, jump to ELSE */
5356 case TGSI_OPCODE_UIF
:
5358 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
5359 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
5360 IFETCH( &r
[0], 0, TGSI_CHAN_X
);
5361 /* update CondMask */
5363 mach
->CondMask
&= ~0x1;
5366 mach
->CondMask
&= ~0x2;
5369 mach
->CondMask
&= ~0x4;
5372 mach
->CondMask
&= ~0x8;
5374 UPDATE_EXEC_MASK(mach
);
5375 /* Todo: If CondMask==0, jump to ELSE */
5378 case TGSI_OPCODE_ELSE
:
5379 /* invert CondMask wrt previous mask */
5382 assert(mach
->CondStackTop
> 0);
5383 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
5384 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
5385 UPDATE_EXEC_MASK(mach
);
5386 /* Todo: If CondMask==0, jump to ENDIF */
5390 case TGSI_OPCODE_ENDIF
:
5392 assert(mach
->CondStackTop
> 0);
5393 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
5394 UPDATE_EXEC_MASK(mach
);
5397 case TGSI_OPCODE_END
:
5398 /* make sure we end primitives which haven't
5399 * been explicitly emitted */
5400 conditional_emit_primitive(mach
);
5401 /* halt execution */
5405 case TGSI_OPCODE_CEIL
:
5406 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5409 case TGSI_OPCODE_I2F
:
5410 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
5413 case TGSI_OPCODE_NOT
:
5414 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5417 case TGSI_OPCODE_TRUNC
:
5418 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
5421 case TGSI_OPCODE_SHL
:
5422 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5425 case TGSI_OPCODE_AND
:
5426 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5429 case TGSI_OPCODE_OR
:
5430 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5433 case TGSI_OPCODE_MOD
:
5434 exec_vector_binary(mach
, inst
, micro_mod
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5437 case TGSI_OPCODE_XOR
:
5438 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5441 case TGSI_OPCODE_TXF
:
5442 exec_txf(mach
, inst
);
5445 case TGSI_OPCODE_TXQ
:
5446 exec_txq(mach
, inst
);
5449 case TGSI_OPCODE_EMIT
:
5453 case TGSI_OPCODE_ENDPRIM
:
5454 emit_primitive(mach
);
5457 case TGSI_OPCODE_BGNLOOP
:
5458 /* push LoopMask and ContMasks */
5459 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
5460 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
5461 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
5462 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
5464 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
5465 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
5466 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
5467 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
5468 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
5471 case TGSI_OPCODE_ENDLOOP
:
5472 /* Restore ContMask, but don't pop */
5473 assert(mach
->ContStackTop
> 0);
5474 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
5475 UPDATE_EXEC_MASK(mach
);
5476 if (mach
->ExecMask
) {
5477 /* repeat loop: jump to instruction just past BGNLOOP */
5478 assert(mach
->LoopLabelStackTop
> 0);
5479 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
5482 /* exit loop: pop LoopMask */
5483 assert(mach
->LoopStackTop
> 0);
5484 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
5486 assert(mach
->ContStackTop
> 0);
5487 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
5488 assert(mach
->LoopLabelStackTop
> 0);
5489 --mach
->LoopLabelStackTop
;
5491 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
5493 UPDATE_EXEC_MASK(mach
);
5496 case TGSI_OPCODE_BRK
:
5500 case TGSI_OPCODE_CONT
:
5501 /* turn off cont channels for each enabled exec channel */
5502 mach
->ContMask
&= ~mach
->ExecMask
;
5503 /* Todo: if mach->LoopMask == 0, jump to end of loop */
5504 UPDATE_EXEC_MASK(mach
);
5507 case TGSI_OPCODE_BGNSUB
:
5511 case TGSI_OPCODE_ENDSUB
:
5513 * XXX: This really should be a no-op. We should never reach this opcode.
5516 assert(mach
->CallStackTop
> 0);
5517 mach
->CallStackTop
--;
5519 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
5520 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
5522 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
5523 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
5525 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
5526 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
5528 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
5529 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
5531 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
5532 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
5534 assert(mach
->FuncStackTop
> 0);
5535 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
5537 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
5539 UPDATE_EXEC_MASK(mach
);
5542 case TGSI_OPCODE_NOP
:
5545 case TGSI_OPCODE_F2I
:
5546 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
5549 case TGSI_OPCODE_FSEQ
:
5550 exec_vector_binary(mach
, inst
, micro_fseq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5553 case TGSI_OPCODE_FSGE
:
5554 exec_vector_binary(mach
, inst
, micro_fsge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5557 case TGSI_OPCODE_FSLT
:
5558 exec_vector_binary(mach
, inst
, micro_fslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5561 case TGSI_OPCODE_FSNE
:
5562 exec_vector_binary(mach
, inst
, micro_fsne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5565 case TGSI_OPCODE_IDIV
:
5566 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5569 case TGSI_OPCODE_IMAX
:
5570 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5573 case TGSI_OPCODE_IMIN
:
5574 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5577 case TGSI_OPCODE_INEG
:
5578 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5581 case TGSI_OPCODE_ISGE
:
5582 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5585 case TGSI_OPCODE_ISHR
:
5586 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5589 case TGSI_OPCODE_ISLT
:
5590 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5593 case TGSI_OPCODE_F2U
:
5594 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5597 case TGSI_OPCODE_U2F
:
5598 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
5601 case TGSI_OPCODE_UADD
:
5602 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5605 case TGSI_OPCODE_UDIV
:
5606 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5609 case TGSI_OPCODE_UMAD
:
5610 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5613 case TGSI_OPCODE_UMAX
:
5614 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5617 case TGSI_OPCODE_UMIN
:
5618 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5621 case TGSI_OPCODE_UMOD
:
5622 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5625 case TGSI_OPCODE_UMUL
:
5626 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5629 case TGSI_OPCODE_IMUL_HI
:
5630 exec_vector_binary(mach
, inst
, micro_imul_hi
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5633 case TGSI_OPCODE_UMUL_HI
:
5634 exec_vector_binary(mach
, inst
, micro_umul_hi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5637 case TGSI_OPCODE_USEQ
:
5638 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5641 case TGSI_OPCODE_USGE
:
5642 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5645 case TGSI_OPCODE_USHR
:
5646 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5649 case TGSI_OPCODE_USLT
:
5650 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5653 case TGSI_OPCODE_USNE
:
5654 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5657 case TGSI_OPCODE_SWITCH
:
5658 exec_switch(mach
, inst
);
5661 case TGSI_OPCODE_CASE
:
5662 exec_case(mach
, inst
);
5665 case TGSI_OPCODE_DEFAULT
:
5669 case TGSI_OPCODE_ENDSWITCH
:
5670 exec_endswitch(mach
);
5673 case TGSI_OPCODE_SAMPLE_I
:
5674 exec_txf(mach
, inst
);
5677 case TGSI_OPCODE_SAMPLE_I_MS
:
5678 exec_txf(mach
, inst
);
5681 case TGSI_OPCODE_SAMPLE
:
5682 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, FALSE
);
5685 case TGSI_OPCODE_SAMPLE_B
:
5686 exec_sample(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, FALSE
);
5689 case TGSI_OPCODE_SAMPLE_C
:
5690 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, TRUE
);
5693 case TGSI_OPCODE_SAMPLE_C_LZ
:
5694 exec_sample(mach
, inst
, TEX_MODIFIER_LEVEL_ZERO
, TRUE
);
5697 case TGSI_OPCODE_SAMPLE_D
:
5698 exec_sample_d(mach
, inst
);
5701 case TGSI_OPCODE_SAMPLE_L
:
5702 exec_sample(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, FALSE
);
5705 case TGSI_OPCODE_GATHER4
:
5706 exec_sample(mach
, inst
, TEX_MODIFIER_GATHER
, FALSE
);
5709 case TGSI_OPCODE_SVIEWINFO
:
5710 exec_txq(mach
, inst
);
5713 case TGSI_OPCODE_SAMPLE_POS
:
5717 case TGSI_OPCODE_SAMPLE_INFO
:
5721 case TGSI_OPCODE_UARL
:
5722 exec_vector_unary(mach
, inst
, micro_uarl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
5725 case TGSI_OPCODE_UCMP
:
5726 exec_ucmp(mach
, inst
);
5729 case TGSI_OPCODE_IABS
:
5730 exec_vector_unary(mach
, inst
, micro_iabs
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5733 case TGSI_OPCODE_ISSG
:
5734 exec_vector_unary(mach
, inst
, micro_isgn
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5737 case TGSI_OPCODE_TEX2
:
5738 /* simple texture lookup */
5739 /* src[0] = texcoord */
5740 /* src[1] = compare */
5741 /* src[2] = sampler unit */
5742 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 2);
5744 case TGSI_OPCODE_TXB2
:
5745 /* simple texture lookup */
5746 /* src[0] = texcoord */
5748 /* src[2] = sampler unit */
5749 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 2);
5751 case TGSI_OPCODE_TXL2
:
5752 /* simple texture lookup */
5753 /* src[0] = texcoord */
5755 /* src[2] = sampler unit */
5756 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 2);
5759 case TGSI_OPCODE_IBFE
:
5760 exec_vector_trinary(mach
, inst
, micro_ibfe
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5762 case TGSI_OPCODE_UBFE
:
5763 exec_vector_trinary(mach
, inst
, micro_ubfe
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5765 case TGSI_OPCODE_BFI
:
5766 exec_vector_quaternary(mach
, inst
, micro_bfi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5768 case TGSI_OPCODE_BREV
:
5769 exec_vector_unary(mach
, inst
, micro_brev
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5771 case TGSI_OPCODE_POPC
:
5772 exec_vector_unary(mach
, inst
, micro_popc
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5774 case TGSI_OPCODE_LSB
:
5775 exec_vector_unary(mach
, inst
, micro_lsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
5777 case TGSI_OPCODE_IMSB
:
5778 exec_vector_unary(mach
, inst
, micro_imsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5780 case TGSI_OPCODE_UMSB
:
5781 exec_vector_unary(mach
, inst
, micro_umsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
5784 case TGSI_OPCODE_F2D
:
5785 exec_t_2_64(mach
, inst
, micro_f2d
, TGSI_EXEC_DATA_FLOAT
);
5788 case TGSI_OPCODE_D2F
:
5789 exec_64_2_t(mach
, inst
, micro_d2f
, TGSI_EXEC_DATA_FLOAT
);
5792 case TGSI_OPCODE_DABS
:
5793 exec_double_unary(mach
, inst
, micro_dabs
);
5796 case TGSI_OPCODE_DNEG
:
5797 exec_double_unary(mach
, inst
, micro_dneg
);
5800 case TGSI_OPCODE_DADD
:
5801 exec_double_binary(mach
, inst
, micro_dadd
, TGSI_EXEC_DATA_DOUBLE
);
5804 case TGSI_OPCODE_DDIV
:
5805 exec_double_binary(mach
, inst
, micro_ddiv
, TGSI_EXEC_DATA_DOUBLE
);
5808 case TGSI_OPCODE_DMUL
:
5809 exec_double_binary(mach
, inst
, micro_dmul
, TGSI_EXEC_DATA_DOUBLE
);
5812 case TGSI_OPCODE_DMAX
:
5813 exec_double_binary(mach
, inst
, micro_dmax
, TGSI_EXEC_DATA_DOUBLE
);
5816 case TGSI_OPCODE_DMIN
:
5817 exec_double_binary(mach
, inst
, micro_dmin
, TGSI_EXEC_DATA_DOUBLE
);
5820 case TGSI_OPCODE_DSLT
:
5821 exec_double_binary(mach
, inst
, micro_dslt
, TGSI_EXEC_DATA_UINT
);
5824 case TGSI_OPCODE_DSGE
:
5825 exec_double_binary(mach
, inst
, micro_dsge
, TGSI_EXEC_DATA_UINT
);
5828 case TGSI_OPCODE_DSEQ
:
5829 exec_double_binary(mach
, inst
, micro_dseq
, TGSI_EXEC_DATA_UINT
);
5832 case TGSI_OPCODE_DSNE
:
5833 exec_double_binary(mach
, inst
, micro_dsne
, TGSI_EXEC_DATA_UINT
);
5836 case TGSI_OPCODE_DRCP
:
5837 exec_double_unary(mach
, inst
, micro_drcp
);
5840 case TGSI_OPCODE_DSQRT
:
5841 exec_double_unary(mach
, inst
, micro_dsqrt
);
5844 case TGSI_OPCODE_DRSQ
:
5845 exec_double_unary(mach
, inst
, micro_drsq
);
5848 case TGSI_OPCODE_DMAD
:
5849 exec_double_trinary(mach
, inst
, micro_dmad
);
5852 case TGSI_OPCODE_DFRAC
:
5853 exec_double_unary(mach
, inst
, micro_dfrac
);
5856 case TGSI_OPCODE_DLDEXP
:
5857 exec_dldexp(mach
, inst
);
5860 case TGSI_OPCODE_DFRACEXP
:
5861 exec_dfracexp(mach
, inst
);
5864 case TGSI_OPCODE_I2D
:
5865 exec_t_2_64(mach
, inst
, micro_i2d
, TGSI_EXEC_DATA_INT
);
5868 case TGSI_OPCODE_D2I
:
5869 exec_64_2_t(mach
, inst
, micro_d2i
, TGSI_EXEC_DATA_INT
);
5872 case TGSI_OPCODE_U2D
:
5873 exec_t_2_64(mach
, inst
, micro_u2d
, TGSI_EXEC_DATA_UINT
);
5876 case TGSI_OPCODE_D2U
:
5877 exec_64_2_t(mach
, inst
, micro_d2u
, TGSI_EXEC_DATA_INT
);
5880 case TGSI_OPCODE_LOAD
:
5881 exec_load(mach
, inst
);
5884 case TGSI_OPCODE_STORE
:
5885 exec_store(mach
, inst
);
5888 case TGSI_OPCODE_ATOMUADD
:
5889 case TGSI_OPCODE_ATOMXCHG
:
5890 case TGSI_OPCODE_ATOMCAS
:
5891 case TGSI_OPCODE_ATOMAND
:
5892 case TGSI_OPCODE_ATOMOR
:
5893 case TGSI_OPCODE_ATOMXOR
:
5894 case TGSI_OPCODE_ATOMUMIN
:
5895 case TGSI_OPCODE_ATOMUMAX
:
5896 case TGSI_OPCODE_ATOMIMIN
:
5897 case TGSI_OPCODE_ATOMIMAX
:
5898 exec_atomop(mach
, inst
);
5901 case TGSI_OPCODE_RESQ
:
5902 exec_resq(mach
, inst
);
5904 case TGSI_OPCODE_BARRIER
:
5905 case TGSI_OPCODE_MEMBAR
:
5909 case TGSI_OPCODE_I64ABS
:
5910 exec_double_unary(mach
, inst
, micro_i64abs
);
5913 case TGSI_OPCODE_I64SSG
:
5914 exec_double_unary(mach
, inst
, micro_i64sgn
);
5917 case TGSI_OPCODE_I64NEG
:
5918 exec_double_unary(mach
, inst
, micro_i64neg
);
5921 case TGSI_OPCODE_U64SEQ
:
5922 exec_double_binary(mach
, inst
, micro_u64seq
, TGSI_EXEC_DATA_UINT
);
5925 case TGSI_OPCODE_U64SNE
:
5926 exec_double_binary(mach
, inst
, micro_u64sne
, TGSI_EXEC_DATA_UINT
);
5929 case TGSI_OPCODE_I64SLT
:
5930 exec_double_binary(mach
, inst
, micro_i64slt
, TGSI_EXEC_DATA_UINT
);
5932 case TGSI_OPCODE_U64SLT
:
5933 exec_double_binary(mach
, inst
, micro_u64slt
, TGSI_EXEC_DATA_UINT
);
5936 case TGSI_OPCODE_I64SGE
:
5937 exec_double_binary(mach
, inst
, micro_i64sge
, TGSI_EXEC_DATA_UINT
);
5939 case TGSI_OPCODE_U64SGE
:
5940 exec_double_binary(mach
, inst
, micro_u64sge
, TGSI_EXEC_DATA_UINT
);
5943 case TGSI_OPCODE_I64MIN
:
5944 exec_double_binary(mach
, inst
, micro_i64min
, TGSI_EXEC_DATA_INT64
);
5946 case TGSI_OPCODE_U64MIN
:
5947 exec_double_binary(mach
, inst
, micro_u64min
, TGSI_EXEC_DATA_UINT64
);
5949 case TGSI_OPCODE_I64MAX
:
5950 exec_double_binary(mach
, inst
, micro_i64max
, TGSI_EXEC_DATA_INT64
);
5952 case TGSI_OPCODE_U64MAX
:
5953 exec_double_binary(mach
, inst
, micro_u64max
, TGSI_EXEC_DATA_UINT64
);
5955 case TGSI_OPCODE_U64ADD
:
5956 exec_double_binary(mach
, inst
, micro_u64add
, TGSI_EXEC_DATA_UINT64
);
5958 case TGSI_OPCODE_U64MUL
:
5959 exec_double_binary(mach
, inst
, micro_u64mul
, TGSI_EXEC_DATA_UINT64
);
5961 case TGSI_OPCODE_U64SHL
:
5962 exec_arg0_64_arg1_32(mach
, inst
, micro_u64shl
);
5964 case TGSI_OPCODE_I64SHR
:
5965 exec_arg0_64_arg1_32(mach
, inst
, micro_i64shr
);
5967 case TGSI_OPCODE_U64SHR
:
5968 exec_arg0_64_arg1_32(mach
, inst
, micro_u64shr
);
5970 case TGSI_OPCODE_U64DIV
:
5971 exec_double_binary(mach
, inst
, micro_u64div
, TGSI_EXEC_DATA_UINT64
);
5973 case TGSI_OPCODE_I64DIV
:
5974 exec_double_binary(mach
, inst
, micro_i64div
, TGSI_EXEC_DATA_INT64
);
5976 case TGSI_OPCODE_U64MOD
:
5977 exec_double_binary(mach
, inst
, micro_u64mod
, TGSI_EXEC_DATA_UINT64
);
5979 case TGSI_OPCODE_I64MOD
:
5980 exec_double_binary(mach
, inst
, micro_i64mod
, TGSI_EXEC_DATA_INT64
);
5983 case TGSI_OPCODE_F2U64
:
5984 exec_t_2_64(mach
, inst
, micro_f2u64
, TGSI_EXEC_DATA_FLOAT
);
5987 case TGSI_OPCODE_F2I64
:
5988 exec_t_2_64(mach
, inst
, micro_f2i64
, TGSI_EXEC_DATA_FLOAT
);
5991 case TGSI_OPCODE_U2I64
:
5992 exec_t_2_64(mach
, inst
, micro_u2i64
, TGSI_EXEC_DATA_INT
);
5994 case TGSI_OPCODE_I2I64
:
5995 exec_t_2_64(mach
, inst
, micro_i2i64
, TGSI_EXEC_DATA_INT
);
5998 case TGSI_OPCODE_D2U64
:
5999 exec_double_unary(mach
, inst
, micro_d2u64
);
6002 case TGSI_OPCODE_D2I64
:
6003 exec_double_unary(mach
, inst
, micro_d2i64
);
6006 case TGSI_OPCODE_U642F
:
6007 exec_64_2_t(mach
, inst
, micro_u642f
, TGSI_EXEC_DATA_FLOAT
);
6009 case TGSI_OPCODE_I642F
:
6010 exec_64_2_t(mach
, inst
, micro_i642f
, TGSI_EXEC_DATA_FLOAT
);
6013 case TGSI_OPCODE_U642D
:
6014 exec_double_unary(mach
, inst
, micro_u642d
);
6016 case TGSI_OPCODE_I642D
:
6017 exec_double_unary(mach
, inst
, micro_i642d
);
6027 tgsi_exec_machine_setup_masks(struct tgsi_exec_machine
*mach
)
6029 uint default_mask
= 0xf;
6031 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
6032 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
6034 if (mach
->ShaderType
== PIPE_SHADER_GEOMETRY
) {
6035 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
6036 mach
->Primitives
[0] = 0;
6037 /* GS runs on a single primitive for now */
6041 if (mach
->NonHelperMask
== 0)
6042 mach
->NonHelperMask
= default_mask
;
6043 mach
->CondMask
= default_mask
;
6044 mach
->LoopMask
= default_mask
;
6045 mach
->ContMask
= default_mask
;
6046 mach
->FuncMask
= default_mask
;
6047 mach
->ExecMask
= default_mask
;
6049 mach
->Switch
.mask
= default_mask
;
6051 assert(mach
->CondStackTop
== 0);
6052 assert(mach
->LoopStackTop
== 0);
6053 assert(mach
->ContStackTop
== 0);
6054 assert(mach
->SwitchStackTop
== 0);
6055 assert(mach
->BreakStackTop
== 0);
6056 assert(mach
->CallStackTop
== 0);
6060 * Run TGSI interpreter.
6061 * \return bitmask of "alive" quad components
6064 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
, int start_pc
)
6068 mach
->pc
= start_pc
;
6071 tgsi_exec_machine_setup_masks(mach
);
6073 /* execute declarations (interpolants) */
6074 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
6075 exec_declaration( mach
, mach
->Declarations
+i
);
6081 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
6082 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
6086 memset(mach
->Temps
, 0, sizeof(temps
));
6088 memset(mach
->Outputs
, 0, sizeof(outputs
));
6089 memset(temps
, 0, sizeof(temps
));
6090 memset(outputs
, 0, sizeof(outputs
));
6094 /* execute instructions, until pc is set to -1 */
6095 while (mach
->pc
!= -1) {
6096 boolean barrier_hit
;
6100 tgsi_dump_instruction(&mach
->Instructions
[mach
->pc
], inst
++);
6103 assert(mach
->pc
< (int) mach
->NumInstructions
);
6104 barrier_hit
= exec_instruction(mach
, mach
->Instructions
+ mach
->pc
, &mach
->pc
);
6106 /* for compute shaders if we hit a barrier return now for later rescheduling */
6107 if (barrier_hit
&& mach
->ShaderType
== PIPE_SHADER_COMPUTE
)
6111 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
6112 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
6115 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
6116 debug_printf("TEMP[%2u] = ", i
);
6117 for (j
= 0; j
< 4; j
++) {
6121 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
6122 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
6123 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
6124 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
6125 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
6129 if (mach
->Outputs
) {
6130 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
6131 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
6134 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
6135 debug_printf("OUT[%2u] = ", i
);
6136 for (j
= 0; j
< 4; j
++) {
6140 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
6141 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
6142 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
6143 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
6144 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
6154 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
6155 if (mach
->ShaderType
== PIPE_SHADER_FRAGMENT
) {
6157 * Scale back depth component.
6159 for (i
= 0; i
< 4; i
++)
6160 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
6164 /* Strictly speaking, these assertions aren't really needed but they
6165 * can potentially catch some bugs in the control flow code.
6167 assert(mach
->CondStackTop
== 0);
6168 assert(mach
->LoopStackTop
== 0);
6169 assert(mach
->ContStackTop
== 0);
6170 assert(mach
->SwitchStackTop
== 0);
6171 assert(mach
->BreakStackTop
== 0);
6172 assert(mach
->CallStackTop
== 0);
6174 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];