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"
66 #define DEBUG_EXECUTION 0
71 #define TILE_TOP_LEFT 0
72 #define TILE_TOP_RIGHT 1
73 #define TILE_BOTTOM_LEFT 2
74 #define TILE_BOTTOM_RIGHT 3
76 union tgsi_double_channel
{
77 double d
[TGSI_QUAD_SIZE
];
78 unsigned u
[TGSI_QUAD_SIZE
][2];
81 struct tgsi_double_vector
{
82 union tgsi_double_channel xy
;
83 union tgsi_double_channel zw
;
87 micro_abs(union tgsi_exec_channel
*dst
,
88 const union tgsi_exec_channel
*src
)
90 dst
->f
[0] = fabsf(src
->f
[0]);
91 dst
->f
[1] = fabsf(src
->f
[1]);
92 dst
->f
[2] = fabsf(src
->f
[2]);
93 dst
->f
[3] = fabsf(src
->f
[3]);
97 micro_arl(union tgsi_exec_channel
*dst
,
98 const union tgsi_exec_channel
*src
)
100 dst
->i
[0] = (int)floorf(src
->f
[0]);
101 dst
->i
[1] = (int)floorf(src
->f
[1]);
102 dst
->i
[2] = (int)floorf(src
->f
[2]);
103 dst
->i
[3] = (int)floorf(src
->f
[3]);
107 micro_arr(union tgsi_exec_channel
*dst
,
108 const union tgsi_exec_channel
*src
)
110 dst
->i
[0] = (int)floorf(src
->f
[0] + 0.5f
);
111 dst
->i
[1] = (int)floorf(src
->f
[1] + 0.5f
);
112 dst
->i
[2] = (int)floorf(src
->f
[2] + 0.5f
);
113 dst
->i
[3] = (int)floorf(src
->f
[3] + 0.5f
);
117 micro_ceil(union tgsi_exec_channel
*dst
,
118 const union tgsi_exec_channel
*src
)
120 dst
->f
[0] = ceilf(src
->f
[0]);
121 dst
->f
[1] = ceilf(src
->f
[1]);
122 dst
->f
[2] = ceilf(src
->f
[2]);
123 dst
->f
[3] = ceilf(src
->f
[3]);
127 micro_clamp(union tgsi_exec_channel
*dst
,
128 const union tgsi_exec_channel
*src0
,
129 const union tgsi_exec_channel
*src1
,
130 const union tgsi_exec_channel
*src2
)
132 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src1
->f
[0] : src0
->f
[0] > src2
->f
[0] ? src2
->f
[0] : src0
->f
[0];
133 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src1
->f
[1] : src0
->f
[1] > src2
->f
[1] ? src2
->f
[1] : src0
->f
[1];
134 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src1
->f
[2] : src0
->f
[2] > src2
->f
[2] ? src2
->f
[2] : src0
->f
[2];
135 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src1
->f
[3] : src0
->f
[3] > src2
->f
[3] ? src2
->f
[3] : src0
->f
[3];
139 micro_cmp(union tgsi_exec_channel
*dst
,
140 const union tgsi_exec_channel
*src0
,
141 const union tgsi_exec_channel
*src1
,
142 const union tgsi_exec_channel
*src2
)
144 dst
->f
[0] = src0
->f
[0] < 0.0f
? src1
->f
[0] : src2
->f
[0];
145 dst
->f
[1] = src0
->f
[1] < 0.0f
? src1
->f
[1] : src2
->f
[1];
146 dst
->f
[2] = src0
->f
[2] < 0.0f
? src1
->f
[2] : src2
->f
[2];
147 dst
->f
[3] = src0
->f
[3] < 0.0f
? src1
->f
[3] : src2
->f
[3];
151 micro_cos(union tgsi_exec_channel
*dst
,
152 const union tgsi_exec_channel
*src
)
154 dst
->f
[0] = cosf(src
->f
[0]);
155 dst
->f
[1] = cosf(src
->f
[1]);
156 dst
->f
[2] = cosf(src
->f
[2]);
157 dst
->f
[3] = cosf(src
->f
[3]);
161 micro_d2f(union tgsi_exec_channel
*dst
,
162 const union tgsi_double_channel
*src
)
164 dst
->f
[0] = (float)src
->d
[0];
165 dst
->f
[1] = (float)src
->d
[1];
166 dst
->f
[2] = (float)src
->d
[2];
167 dst
->f
[3] = (float)src
->d
[3];
171 micro_d2i(union tgsi_exec_channel
*dst
,
172 const union tgsi_double_channel
*src
)
174 dst
->i
[0] = (int)src
->d
[0];
175 dst
->i
[1] = (int)src
->d
[1];
176 dst
->i
[2] = (int)src
->d
[2];
177 dst
->i
[3] = (int)src
->d
[3];
181 micro_d2u(union tgsi_exec_channel
*dst
,
182 const union tgsi_double_channel
*src
)
184 dst
->u
[0] = (unsigned)src
->d
[0];
185 dst
->u
[1] = (unsigned)src
->d
[1];
186 dst
->u
[2] = (unsigned)src
->d
[2];
187 dst
->u
[3] = (unsigned)src
->d
[3];
190 micro_dabs(union tgsi_double_channel
*dst
,
191 const union tgsi_double_channel
*src
)
193 dst
->d
[0] = src
->d
[0] >= 0.0 ? src
->d
[0] : -src
->d
[0];
194 dst
->d
[1] = src
->d
[1] >= 0.0 ? src
->d
[1] : -src
->d
[1];
195 dst
->d
[2] = src
->d
[2] >= 0.0 ? src
->d
[2] : -src
->d
[2];
196 dst
->d
[3] = src
->d
[3] >= 0.0 ? src
->d
[3] : -src
->d
[3];
200 micro_dadd(union tgsi_double_channel
*dst
,
201 const union tgsi_double_channel
*src
)
203 dst
->d
[0] = src
[0].d
[0] + src
[1].d
[0];
204 dst
->d
[1] = src
[0].d
[1] + src
[1].d
[1];
205 dst
->d
[2] = src
[0].d
[2] + src
[1].d
[2];
206 dst
->d
[3] = src
[0].d
[3] + src
[1].d
[3];
210 micro_ddx(union tgsi_exec_channel
*dst
,
211 const union tgsi_exec_channel
*src
)
216 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
220 micro_ddy(union tgsi_exec_channel
*dst
,
221 const union tgsi_exec_channel
*src
)
226 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
230 micro_dmul(union tgsi_double_channel
*dst
,
231 const union tgsi_double_channel
*src
)
233 dst
->d
[0] = src
[0].d
[0] * src
[1].d
[0];
234 dst
->d
[1] = src
[0].d
[1] * src
[1].d
[1];
235 dst
->d
[2] = src
[0].d
[2] * src
[1].d
[2];
236 dst
->d
[3] = src
[0].d
[3] * src
[1].d
[3];
240 micro_dmax(union tgsi_double_channel
*dst
,
241 const union tgsi_double_channel
*src
)
243 dst
->d
[0] = src
[0].d
[0] > src
[1].d
[0] ? src
[0].d
[0] : src
[1].d
[0];
244 dst
->d
[1] = src
[0].d
[1] > src
[1].d
[1] ? src
[0].d
[1] : src
[1].d
[1];
245 dst
->d
[2] = src
[0].d
[2] > src
[1].d
[2] ? src
[0].d
[2] : src
[1].d
[2];
246 dst
->d
[3] = src
[0].d
[3] > src
[1].d
[3] ? src
[0].d
[3] : src
[1].d
[3];
250 micro_dmin(union tgsi_double_channel
*dst
,
251 const union tgsi_double_channel
*src
)
253 dst
->d
[0] = src
[0].d
[0] < src
[1].d
[0] ? src
[0].d
[0] : src
[1].d
[0];
254 dst
->d
[1] = src
[0].d
[1] < src
[1].d
[1] ? src
[0].d
[1] : src
[1].d
[1];
255 dst
->d
[2] = src
[0].d
[2] < src
[1].d
[2] ? src
[0].d
[2] : src
[1].d
[2];
256 dst
->d
[3] = src
[0].d
[3] < src
[1].d
[3] ? src
[0].d
[3] : src
[1].d
[3];
260 micro_dneg(union tgsi_double_channel
*dst
,
261 const union tgsi_double_channel
*src
)
263 dst
->d
[0] = -src
->d
[0];
264 dst
->d
[1] = -src
->d
[1];
265 dst
->d
[2] = -src
->d
[2];
266 dst
->d
[3] = -src
->d
[3];
270 micro_dslt(union tgsi_double_channel
*dst
,
271 const union tgsi_double_channel
*src
)
273 dst
->u
[0][0] = src
[0].d
[0] < src
[1].d
[0] ? ~0U : 0U;
274 dst
->u
[1][0] = src
[0].d
[1] < src
[1].d
[1] ? ~0U : 0U;
275 dst
->u
[2][0] = src
[0].d
[2] < src
[1].d
[2] ? ~0U : 0U;
276 dst
->u
[3][0] = src
[0].d
[3] < src
[1].d
[3] ? ~0U : 0U;
280 micro_dsne(union tgsi_double_channel
*dst
,
281 const union tgsi_double_channel
*src
)
283 dst
->u
[0][0] = src
[0].d
[0] != src
[1].d
[0] ? ~0U : 0U;
284 dst
->u
[1][0] = src
[0].d
[1] != src
[1].d
[1] ? ~0U : 0U;
285 dst
->u
[2][0] = src
[0].d
[2] != src
[1].d
[2] ? ~0U : 0U;
286 dst
->u
[3][0] = src
[0].d
[3] != src
[1].d
[3] ? ~0U : 0U;
290 micro_dsge(union tgsi_double_channel
*dst
,
291 const union tgsi_double_channel
*src
)
293 dst
->u
[0][0] = src
[0].d
[0] >= src
[1].d
[0] ? ~0U : 0U;
294 dst
->u
[1][0] = src
[0].d
[1] >= src
[1].d
[1] ? ~0U : 0U;
295 dst
->u
[2][0] = src
[0].d
[2] >= src
[1].d
[2] ? ~0U : 0U;
296 dst
->u
[3][0] = src
[0].d
[3] >= src
[1].d
[3] ? ~0U : 0U;
300 micro_dseq(union tgsi_double_channel
*dst
,
301 const union tgsi_double_channel
*src
)
303 dst
->u
[0][0] = src
[0].d
[0] == src
[1].d
[0] ? ~0U : 0U;
304 dst
->u
[1][0] = src
[0].d
[1] == src
[1].d
[1] ? ~0U : 0U;
305 dst
->u
[2][0] = src
[0].d
[2] == src
[1].d
[2] ? ~0U : 0U;
306 dst
->u
[3][0] = src
[0].d
[3] == src
[1].d
[3] ? ~0U : 0U;
310 micro_drcp(union tgsi_double_channel
*dst
,
311 const union tgsi_double_channel
*src
)
313 dst
->d
[0] = 1.0 / src
->d
[0];
314 dst
->d
[1] = 1.0 / src
->d
[1];
315 dst
->d
[2] = 1.0 / src
->d
[2];
316 dst
->d
[3] = 1.0 / src
->d
[3];
320 micro_dsqrt(union tgsi_double_channel
*dst
,
321 const union tgsi_double_channel
*src
)
323 dst
->d
[0] = sqrt(src
->d
[0]);
324 dst
->d
[1] = sqrt(src
->d
[1]);
325 dst
->d
[2] = sqrt(src
->d
[2]);
326 dst
->d
[3] = sqrt(src
->d
[3]);
330 micro_drsq(union tgsi_double_channel
*dst
,
331 const union tgsi_double_channel
*src
)
333 dst
->d
[0] = 1.0 / sqrt(src
->d
[0]);
334 dst
->d
[1] = 1.0 / sqrt(src
->d
[1]);
335 dst
->d
[2] = 1.0 / sqrt(src
->d
[2]);
336 dst
->d
[3] = 1.0 / sqrt(src
->d
[3]);
340 micro_dmad(union tgsi_double_channel
*dst
,
341 const union tgsi_double_channel
*src
)
343 dst
->d
[0] = src
[0].d
[0] * src
[1].d
[0] + src
[2].d
[0];
344 dst
->d
[1] = src
[0].d
[1] * src
[1].d
[1] + src
[2].d
[1];
345 dst
->d
[2] = src
[0].d
[2] * src
[1].d
[2] + src
[2].d
[2];
346 dst
->d
[3] = src
[0].d
[3] * src
[1].d
[3] + src
[2].d
[3];
350 micro_dfrac(union tgsi_double_channel
*dst
,
351 const union tgsi_double_channel
*src
)
353 dst
->d
[0] = src
->d
[0] - floor(src
->d
[0]);
354 dst
->d
[1] = src
->d
[1] - floor(src
->d
[1]);
355 dst
->d
[2] = src
->d
[2] - floor(src
->d
[2]);
356 dst
->d
[3] = src
->d
[3] - floor(src
->d
[3]);
360 micro_dldexp(union tgsi_double_channel
*dst
,
361 const union tgsi_double_channel
*src0
,
362 union tgsi_exec_channel
*src1
)
364 dst
->d
[0] = ldexp(src0
->d
[0], src1
->i
[0]);
365 dst
->d
[1] = ldexp(src0
->d
[1], src1
->i
[1]);
366 dst
->d
[2] = ldexp(src0
->d
[2], src1
->i
[2]);
367 dst
->d
[3] = ldexp(src0
->d
[3], src1
->i
[3]);
371 micro_dfracexp(union tgsi_double_channel
*dst
,
372 union tgsi_exec_channel
*dst_exp
,
373 const union tgsi_double_channel
*src
)
375 dst
->d
[0] = frexp(src
->d
[0], &dst_exp
->i
[0]);
376 dst
->d
[1] = frexp(src
->d
[1], &dst_exp
->i
[1]);
377 dst
->d
[2] = frexp(src
->d
[2], &dst_exp
->i
[2]);
378 dst
->d
[3] = frexp(src
->d
[3], &dst_exp
->i
[3]);
382 micro_exp2(union tgsi_exec_channel
*dst
,
383 const union tgsi_exec_channel
*src
)
386 dst
->f
[0] = util_fast_exp2(src
->f
[0]);
387 dst
->f
[1] = util_fast_exp2(src
->f
[1]);
388 dst
->f
[2] = util_fast_exp2(src
->f
[2]);
389 dst
->f
[3] = util_fast_exp2(src
->f
[3]);
392 /* Inf is okay for this instruction, so clamp it to silence assertions. */
394 union tgsi_exec_channel clamped
;
396 for (i
= 0; i
< 4; i
++) {
397 if (src
->f
[i
] > 127.99999f
) {
398 clamped
.f
[i
] = 127.99999f
;
399 } else if (src
->f
[i
] < -126.99999f
) {
400 clamped
.f
[i
] = -126.99999f
;
402 clamped
.f
[i
] = src
->f
[i
];
408 dst
->f
[0] = powf(2.0f
, src
->f
[0]);
409 dst
->f
[1] = powf(2.0f
, src
->f
[1]);
410 dst
->f
[2] = powf(2.0f
, src
->f
[2]);
411 dst
->f
[3] = powf(2.0f
, src
->f
[3]);
412 #endif /* FAST_MATH */
416 micro_f2d(union tgsi_double_channel
*dst
,
417 const union tgsi_exec_channel
*src
)
419 dst
->d
[0] = (double)src
->f
[0];
420 dst
->d
[1] = (double)src
->f
[1];
421 dst
->d
[2] = (double)src
->f
[2];
422 dst
->d
[3] = (double)src
->f
[3];
426 micro_flr(union tgsi_exec_channel
*dst
,
427 const union tgsi_exec_channel
*src
)
429 dst
->f
[0] = floorf(src
->f
[0]);
430 dst
->f
[1] = floorf(src
->f
[1]);
431 dst
->f
[2] = floorf(src
->f
[2]);
432 dst
->f
[3] = floorf(src
->f
[3]);
436 micro_frc(union tgsi_exec_channel
*dst
,
437 const union tgsi_exec_channel
*src
)
439 dst
->f
[0] = src
->f
[0] - floorf(src
->f
[0]);
440 dst
->f
[1] = src
->f
[1] - floorf(src
->f
[1]);
441 dst
->f
[2] = src
->f
[2] - floorf(src
->f
[2]);
442 dst
->f
[3] = src
->f
[3] - floorf(src
->f
[3]);
446 micro_i2d(union tgsi_double_channel
*dst
,
447 const union tgsi_exec_channel
*src
)
449 dst
->d
[0] = (double)src
->i
[0];
450 dst
->d
[1] = (double)src
->i
[1];
451 dst
->d
[2] = (double)src
->i
[2];
452 dst
->d
[3] = (double)src
->i
[3];
456 micro_iabs(union tgsi_exec_channel
*dst
,
457 const union tgsi_exec_channel
*src
)
459 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
460 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
461 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
462 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
466 micro_ineg(union tgsi_exec_channel
*dst
,
467 const union tgsi_exec_channel
*src
)
469 dst
->i
[0] = -src
->i
[0];
470 dst
->i
[1] = -src
->i
[1];
471 dst
->i
[2] = -src
->i
[2];
472 dst
->i
[3] = -src
->i
[3];
476 micro_lg2(union tgsi_exec_channel
*dst
,
477 const union tgsi_exec_channel
*src
)
480 dst
->f
[0] = util_fast_log2(src
->f
[0]);
481 dst
->f
[1] = util_fast_log2(src
->f
[1]);
482 dst
->f
[2] = util_fast_log2(src
->f
[2]);
483 dst
->f
[3] = util_fast_log2(src
->f
[3]);
485 dst
->f
[0] = logf(src
->f
[0]) * 1.442695f
;
486 dst
->f
[1] = logf(src
->f
[1]) * 1.442695f
;
487 dst
->f
[2] = logf(src
->f
[2]) * 1.442695f
;
488 dst
->f
[3] = logf(src
->f
[3]) * 1.442695f
;
493 micro_lrp(union tgsi_exec_channel
*dst
,
494 const union tgsi_exec_channel
*src0
,
495 const union tgsi_exec_channel
*src1
,
496 const union tgsi_exec_channel
*src2
)
498 dst
->f
[0] = src0
->f
[0] * (src1
->f
[0] - src2
->f
[0]) + src2
->f
[0];
499 dst
->f
[1] = src0
->f
[1] * (src1
->f
[1] - src2
->f
[1]) + src2
->f
[1];
500 dst
->f
[2] = src0
->f
[2] * (src1
->f
[2] - src2
->f
[2]) + src2
->f
[2];
501 dst
->f
[3] = src0
->f
[3] * (src1
->f
[3] - src2
->f
[3]) + src2
->f
[3];
505 micro_mad(union tgsi_exec_channel
*dst
,
506 const union tgsi_exec_channel
*src0
,
507 const union tgsi_exec_channel
*src1
,
508 const union tgsi_exec_channel
*src2
)
510 dst
->f
[0] = src0
->f
[0] * src1
->f
[0] + src2
->f
[0];
511 dst
->f
[1] = src0
->f
[1] * src1
->f
[1] + src2
->f
[1];
512 dst
->f
[2] = src0
->f
[2] * src1
->f
[2] + src2
->f
[2];
513 dst
->f
[3] = src0
->f
[3] * src1
->f
[3] + src2
->f
[3];
517 micro_mov(union tgsi_exec_channel
*dst
,
518 const union tgsi_exec_channel
*src
)
520 dst
->u
[0] = src
->u
[0];
521 dst
->u
[1] = src
->u
[1];
522 dst
->u
[2] = src
->u
[2];
523 dst
->u
[3] = src
->u
[3];
527 micro_rcp(union tgsi_exec_channel
*dst
,
528 const union tgsi_exec_channel
*src
)
530 #if 0 /* for debugging */
531 assert(src
->f
[0] != 0.0f
);
532 assert(src
->f
[1] != 0.0f
);
533 assert(src
->f
[2] != 0.0f
);
534 assert(src
->f
[3] != 0.0f
);
536 dst
->f
[0] = 1.0f
/ src
->f
[0];
537 dst
->f
[1] = 1.0f
/ src
->f
[1];
538 dst
->f
[2] = 1.0f
/ src
->f
[2];
539 dst
->f
[3] = 1.0f
/ src
->f
[3];
543 micro_rnd(union tgsi_exec_channel
*dst
,
544 const union tgsi_exec_channel
*src
)
546 dst
->f
[0] = floorf(src
->f
[0] + 0.5f
);
547 dst
->f
[1] = floorf(src
->f
[1] + 0.5f
);
548 dst
->f
[2] = floorf(src
->f
[2] + 0.5f
);
549 dst
->f
[3] = floorf(src
->f
[3] + 0.5f
);
553 micro_rsq(union tgsi_exec_channel
*dst
,
554 const union tgsi_exec_channel
*src
)
556 #if 0 /* for debugging */
557 assert(src
->f
[0] != 0.0f
);
558 assert(src
->f
[1] != 0.0f
);
559 assert(src
->f
[2] != 0.0f
);
560 assert(src
->f
[3] != 0.0f
);
562 dst
->f
[0] = 1.0f
/ sqrtf(src
->f
[0]);
563 dst
->f
[1] = 1.0f
/ sqrtf(src
->f
[1]);
564 dst
->f
[2] = 1.0f
/ sqrtf(src
->f
[2]);
565 dst
->f
[3] = 1.0f
/ sqrtf(src
->f
[3]);
569 micro_sqrt(union tgsi_exec_channel
*dst
,
570 const union tgsi_exec_channel
*src
)
572 dst
->f
[0] = sqrtf(src
->f
[0]);
573 dst
->f
[1] = sqrtf(src
->f
[1]);
574 dst
->f
[2] = sqrtf(src
->f
[2]);
575 dst
->f
[3] = sqrtf(src
->f
[3]);
579 micro_seq(union tgsi_exec_channel
*dst
,
580 const union tgsi_exec_channel
*src0
,
581 const union tgsi_exec_channel
*src1
)
583 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? 1.0f
: 0.0f
;
584 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? 1.0f
: 0.0f
;
585 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? 1.0f
: 0.0f
;
586 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? 1.0f
: 0.0f
;
590 micro_sge(union tgsi_exec_channel
*dst
,
591 const union tgsi_exec_channel
*src0
,
592 const union tgsi_exec_channel
*src1
)
594 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? 1.0f
: 0.0f
;
595 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? 1.0f
: 0.0f
;
596 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? 1.0f
: 0.0f
;
597 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? 1.0f
: 0.0f
;
601 micro_sgn(union tgsi_exec_channel
*dst
,
602 const union tgsi_exec_channel
*src
)
604 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
605 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
606 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
607 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
611 micro_isgn(union tgsi_exec_channel
*dst
,
612 const union tgsi_exec_channel
*src
)
614 dst
->i
[0] = src
->i
[0] < 0 ? -1 : src
->i
[0] > 0 ? 1 : 0;
615 dst
->i
[1] = src
->i
[1] < 0 ? -1 : src
->i
[1] > 0 ? 1 : 0;
616 dst
->i
[2] = src
->i
[2] < 0 ? -1 : src
->i
[2] > 0 ? 1 : 0;
617 dst
->i
[3] = src
->i
[3] < 0 ? -1 : src
->i
[3] > 0 ? 1 : 0;
621 micro_sgt(union tgsi_exec_channel
*dst
,
622 const union tgsi_exec_channel
*src0
,
623 const union tgsi_exec_channel
*src1
)
625 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? 1.0f
: 0.0f
;
626 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? 1.0f
: 0.0f
;
627 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? 1.0f
: 0.0f
;
628 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? 1.0f
: 0.0f
;
632 micro_sin(union tgsi_exec_channel
*dst
,
633 const union tgsi_exec_channel
*src
)
635 dst
->f
[0] = sinf(src
->f
[0]);
636 dst
->f
[1] = sinf(src
->f
[1]);
637 dst
->f
[2] = sinf(src
->f
[2]);
638 dst
->f
[3] = sinf(src
->f
[3]);
642 micro_sle(union tgsi_exec_channel
*dst
,
643 const union tgsi_exec_channel
*src0
,
644 const union tgsi_exec_channel
*src1
)
646 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? 1.0f
: 0.0f
;
647 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? 1.0f
: 0.0f
;
648 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? 1.0f
: 0.0f
;
649 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? 1.0f
: 0.0f
;
653 micro_slt(union tgsi_exec_channel
*dst
,
654 const union tgsi_exec_channel
*src0
,
655 const union tgsi_exec_channel
*src1
)
657 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? 1.0f
: 0.0f
;
658 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? 1.0f
: 0.0f
;
659 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? 1.0f
: 0.0f
;
660 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? 1.0f
: 0.0f
;
664 micro_sne(union tgsi_exec_channel
*dst
,
665 const union tgsi_exec_channel
*src0
,
666 const union tgsi_exec_channel
*src1
)
668 dst
->f
[0] = src0
->f
[0] != src1
->f
[0] ? 1.0f
: 0.0f
;
669 dst
->f
[1] = src0
->f
[1] != src1
->f
[1] ? 1.0f
: 0.0f
;
670 dst
->f
[2] = src0
->f
[2] != src1
->f
[2] ? 1.0f
: 0.0f
;
671 dst
->f
[3] = src0
->f
[3] != src1
->f
[3] ? 1.0f
: 0.0f
;
675 micro_trunc(union tgsi_exec_channel
*dst
,
676 const union tgsi_exec_channel
*src
)
678 dst
->f
[0] = (float)(int)src
->f
[0];
679 dst
->f
[1] = (float)(int)src
->f
[1];
680 dst
->f
[2] = (float)(int)src
->f
[2];
681 dst
->f
[3] = (float)(int)src
->f
[3];
685 micro_u2d(union tgsi_double_channel
*dst
,
686 const union tgsi_exec_channel
*src
)
688 dst
->d
[0] = (double)src
->u
[0];
689 dst
->d
[1] = (double)src
->u
[1];
690 dst
->d
[2] = (double)src
->u
[2];
691 dst
->d
[3] = (double)src
->u
[3];
694 enum tgsi_exec_datatype
{
695 TGSI_EXEC_DATA_FLOAT
,
698 TGSI_EXEC_DATA_DOUBLE
702 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
704 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
705 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
706 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
707 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
708 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
709 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
712 /** The execution mask depends on the conditional mask and the loop mask */
713 #define UPDATE_EXEC_MASK(MACH) \
714 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
717 static const union tgsi_exec_channel ZeroVec
=
718 { { 0.0, 0.0, 0.0, 0.0 } };
720 static const union tgsi_exec_channel OneVec
= {
721 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
724 static const union tgsi_exec_channel P128Vec
= {
725 {128.0f
, 128.0f
, 128.0f
, 128.0f
}
728 static const union tgsi_exec_channel M128Vec
= {
729 {-128.0f
, -128.0f
, -128.0f
, -128.0f
}
734 * Assert that none of the float values in 'chan' are infinite or NaN.
735 * NaN and Inf may occur normally during program execution and should
736 * not lead to crashes, etc. But when debugging, it's helpful to catch
740 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
742 assert(!util_is_inf_or_nan((chan
)->f
[0]));
743 assert(!util_is_inf_or_nan((chan
)->f
[1]));
744 assert(!util_is_inf_or_nan((chan
)->f
[2]));
745 assert(!util_is_inf_or_nan((chan
)->f
[3]));
751 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
753 debug_printf("%s = {%f, %f, %f, %f}\n",
754 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
761 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
763 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
765 debug_printf("Temp[%u] =\n", index
);
766 for (i
= 0; i
< 4; i
++) {
767 debug_printf(" %c: { %f, %f, %f, %f }\n",
779 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine
*mach
,
782 const unsigned *buf_sizes
)
786 for (i
= 0; i
< num_bufs
; i
++) {
787 mach
->Consts
[i
] = bufs
[i
];
788 mach
->ConstsSize
[i
] = buf_sizes
[i
];
794 * Check if there's a potential src/dst register data dependency when
795 * using SOA execution.
798 * This would expand into:
803 * The second instruction will have the wrong value for t0 if executed as-is.
806 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
810 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
811 if (writemask
== TGSI_WRITEMASK_X
||
812 writemask
== TGSI_WRITEMASK_Y
||
813 writemask
== TGSI_WRITEMASK_Z
||
814 writemask
== TGSI_WRITEMASK_W
||
815 writemask
== TGSI_WRITEMASK_NONE
) {
816 /* no chance of data dependency */
820 /* loop over src regs */
821 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
822 if ((inst
->Src
[i
].Register
.File
==
823 inst
->Dst
[0].Register
.File
) &&
824 ((inst
->Src
[i
].Register
.Index
==
825 inst
->Dst
[0].Register
.Index
) ||
826 inst
->Src
[i
].Register
.Indirect
||
827 inst
->Dst
[0].Register
.Indirect
)) {
828 /* loop over dest channels */
829 uint channelsWritten
= 0x0;
830 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
831 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
832 /* check if we're reading a channel that's been written */
833 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
834 if (channelsWritten
& (1 << swizzle
)) {
838 channelsWritten
|= (1 << chan
);
848 * Initialize machine state by expanding tokens to full instructions,
849 * allocating temporary storage, setting up constants, etc.
850 * After this, we can call tgsi_exec_machine_run() many times.
853 tgsi_exec_machine_bind_shader(
854 struct tgsi_exec_machine
*mach
,
855 const struct tgsi_token
*tokens
,
856 struct tgsi_sampler
*sampler
,
857 struct tgsi_image
*image
)
860 struct tgsi_parse_context parse
;
861 struct tgsi_full_instruction
*instructions
;
862 struct tgsi_full_declaration
*declarations
;
863 uint maxInstructions
= 10, numInstructions
= 0;
864 uint maxDeclarations
= 10, numDeclarations
= 0;
867 tgsi_dump(tokens
, 0);
873 mach
->Tokens
= tokens
;
874 mach
->Sampler
= sampler
;
878 /* unbind and free all */
879 FREE(mach
->Declarations
);
880 mach
->Declarations
= NULL
;
881 mach
->NumDeclarations
= 0;
883 FREE(mach
->Instructions
);
884 mach
->Instructions
= NULL
;
885 mach
->NumInstructions
= 0;
890 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
891 if (k
!= TGSI_PARSE_OK
) {
892 debug_printf( "Problem parsing!\n" );
896 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
898 mach
->NumOutputs
= 0;
900 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
&&
901 !mach
->UsedGeometryShader
) {
902 struct tgsi_exec_vector
*inputs
;
903 struct tgsi_exec_vector
*outputs
;
905 inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
906 TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_SHADER_INPUTS
,
912 outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
913 TGSI_MAX_TOTAL_VERTICES
, 16);
920 align_free(mach
->Inputs
);
921 align_free(mach
->Outputs
);
923 mach
->Inputs
= inputs
;
924 mach
->Outputs
= outputs
;
925 mach
->UsedGeometryShader
= TRUE
;
928 declarations
= (struct tgsi_full_declaration
*)
929 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
935 instructions
= (struct tgsi_full_instruction
*)
936 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
939 FREE( declarations
);
943 while( !tgsi_parse_end_of_tokens( &parse
) ) {
946 tgsi_parse_token( &parse
);
947 switch( parse
.FullToken
.Token
.Type
) {
948 case TGSI_TOKEN_TYPE_DECLARATION
:
949 /* save expanded declaration */
950 if (numDeclarations
== maxDeclarations
) {
951 declarations
= REALLOC(declarations
,
953 * sizeof(struct tgsi_full_declaration
),
954 (maxDeclarations
+ 10)
955 * sizeof(struct tgsi_full_declaration
));
956 maxDeclarations
+= 10;
958 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
960 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
961 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
966 memcpy(declarations
+ numDeclarations
,
967 &parse
.FullToken
.FullDeclaration
,
968 sizeof(declarations
[0]));
972 case TGSI_TOKEN_TYPE_IMMEDIATE
:
974 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
976 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
978 for( i
= 0; i
< size
; i
++ ) {
979 mach
->Imms
[mach
->ImmLimit
][i
] =
980 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
986 case TGSI_TOKEN_TYPE_INSTRUCTION
:
988 /* save expanded instruction */
989 if (numInstructions
== maxInstructions
) {
990 instructions
= REALLOC(instructions
,
992 * sizeof(struct tgsi_full_instruction
),
993 (maxInstructions
+ 10)
994 * sizeof(struct tgsi_full_instruction
));
995 maxInstructions
+= 10;
998 memcpy(instructions
+ numInstructions
,
999 &parse
.FullToken
.FullInstruction
,
1000 sizeof(instructions
[0]));
1005 case TGSI_TOKEN_TYPE_PROPERTY
:
1006 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
1007 if (parse
.FullToken
.FullProperty
.Property
.PropertyName
== TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
) {
1008 mach
->MaxOutputVertices
= parse
.FullToken
.FullProperty
.u
[0].Data
;
1017 tgsi_parse_free (&parse
);
1019 FREE(mach
->Declarations
);
1020 mach
->Declarations
= declarations
;
1021 mach
->NumDeclarations
= numDeclarations
;
1023 FREE(mach
->Instructions
);
1024 mach
->Instructions
= instructions
;
1025 mach
->NumInstructions
= numInstructions
;
1029 struct tgsi_exec_machine
*
1030 tgsi_exec_machine_create( void )
1032 struct tgsi_exec_machine
*mach
;
1035 mach
= align_malloc( sizeof *mach
, 16 );
1039 memset(mach
, 0, sizeof(*mach
));
1041 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
1042 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
1043 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
1045 mach
->Inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_INPUTS
, 16);
1046 mach
->Outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_OUTPUTS
, 16);
1047 if (!mach
->Inputs
|| !mach
->Outputs
)
1050 /* Setup constants needed by the SSE2 executor. */
1051 for( i
= 0; i
< 4; i
++ ) {
1052 mach
->Temps
[TGSI_EXEC_TEMP_00000000_I
].xyzw
[TGSI_EXEC_TEMP_00000000_C
].u
[i
] = 0x00000000;
1053 mach
->Temps
[TGSI_EXEC_TEMP_7FFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_7FFFFFFF_C
].u
[i
] = 0x7FFFFFFF;
1054 mach
->Temps
[TGSI_EXEC_TEMP_80000000_I
].xyzw
[TGSI_EXEC_TEMP_80000000_C
].u
[i
] = 0x80000000;
1055 mach
->Temps
[TGSI_EXEC_TEMP_FFFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_FFFFFFFF_C
].u
[i
] = 0xFFFFFFFF; /* not used */
1056 mach
->Temps
[TGSI_EXEC_TEMP_ONE_I
].xyzw
[TGSI_EXEC_TEMP_ONE_C
].f
[i
] = 1.0f
;
1057 mach
->Temps
[TGSI_EXEC_TEMP_TWO_I
].xyzw
[TGSI_EXEC_TEMP_TWO_C
].f
[i
] = 2.0f
; /* not used */
1058 mach
->Temps
[TGSI_EXEC_TEMP_128_I
].xyzw
[TGSI_EXEC_TEMP_128_C
].f
[i
] = 128.0f
;
1059 mach
->Temps
[TGSI_EXEC_TEMP_MINUS_128_I
].xyzw
[TGSI_EXEC_TEMP_MINUS_128_C
].f
[i
] = -128.0f
;
1060 mach
->Temps
[TGSI_EXEC_TEMP_THREE_I
].xyzw
[TGSI_EXEC_TEMP_THREE_C
].f
[i
] = 3.0f
;
1061 mach
->Temps
[TGSI_EXEC_TEMP_HALF_I
].xyzw
[TGSI_EXEC_TEMP_HALF_C
].f
[i
] = 0.5f
;
1065 /* silence warnings */
1074 align_free(mach
->Inputs
);
1075 align_free(mach
->Outputs
);
1083 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
1086 FREE(mach
->Instructions
);
1087 FREE(mach
->Declarations
);
1089 align_free(mach
->Inputs
);
1090 align_free(mach
->Outputs
);
1097 micro_add(union tgsi_exec_channel
*dst
,
1098 const union tgsi_exec_channel
*src0
,
1099 const union tgsi_exec_channel
*src1
)
1101 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
1102 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
1103 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
1104 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
1109 union tgsi_exec_channel
*dst
,
1110 const union tgsi_exec_channel
*src0
,
1111 const union tgsi_exec_channel
*src1
)
1113 if (src1
->f
[0] != 0) {
1114 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
1116 if (src1
->f
[1] != 0) {
1117 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
1119 if (src1
->f
[2] != 0) {
1120 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
1122 if (src1
->f
[3] != 0) {
1123 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
1129 union tgsi_exec_channel
*dst
,
1130 const union tgsi_exec_channel
*src0
,
1131 const union tgsi_exec_channel
*src1
,
1132 const union tgsi_exec_channel
*src2
,
1133 const union tgsi_exec_channel
*src3
)
1135 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
1136 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
1137 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
1138 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
1142 micro_max(union tgsi_exec_channel
*dst
,
1143 const union tgsi_exec_channel
*src0
,
1144 const union tgsi_exec_channel
*src1
)
1146 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
1147 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
1148 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
1149 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
1153 micro_min(union tgsi_exec_channel
*dst
,
1154 const union tgsi_exec_channel
*src0
,
1155 const union tgsi_exec_channel
*src1
)
1157 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
1158 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
1159 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
1160 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
1164 micro_mul(union tgsi_exec_channel
*dst
,
1165 const union tgsi_exec_channel
*src0
,
1166 const union tgsi_exec_channel
*src1
)
1168 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
1169 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
1170 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
1171 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
1176 union tgsi_exec_channel
*dst
,
1177 const union tgsi_exec_channel
*src
)
1179 dst
->f
[0] = -src
->f
[0];
1180 dst
->f
[1] = -src
->f
[1];
1181 dst
->f
[2] = -src
->f
[2];
1182 dst
->f
[3] = -src
->f
[3];
1187 union tgsi_exec_channel
*dst
,
1188 const union tgsi_exec_channel
*src0
,
1189 const union tgsi_exec_channel
*src1
)
1192 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
1193 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
1194 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
1195 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
1197 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
1198 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
1199 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
1200 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
1205 micro_sub(union tgsi_exec_channel
*dst
,
1206 const union tgsi_exec_channel
*src0
,
1207 const union tgsi_exec_channel
*src1
)
1209 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1210 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1211 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1212 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1216 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
1217 const uint chan_index
,
1220 const union tgsi_exec_channel
*index
,
1221 const union tgsi_exec_channel
*index2D
,
1222 union tgsi_exec_channel
*chan
)
1226 assert(swizzle
< 4);
1229 case TGSI_FILE_CONSTANT
:
1230 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1231 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
1232 assert(mach
->Consts
[index2D
->i
[i
]]);
1234 if (index
->i
[i
] < 0) {
1237 /* NOTE: copying the const value as a uint instead of float */
1238 const uint constbuf
= index2D
->i
[i
];
1239 const uint
*buf
= (const uint
*)mach
->Consts
[constbuf
];
1240 const int pos
= index
->i
[i
] * 4 + swizzle
;
1241 /* const buffer bounds check */
1242 if (pos
< 0 || pos
>= (int) mach
->ConstsSize
[constbuf
]) {
1244 /* Debug: print warning */
1245 static int count
= 0;
1247 debug_printf("TGSI Exec: const buffer index %d"
1248 " out of bounds\n", pos
);
1253 chan
->u
[i
] = buf
[pos
];
1258 case TGSI_FILE_INPUT
:
1259 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1261 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1262 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1263 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1264 index2D->i[i], index->i[i]);
1266 int pos
= index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
];
1268 assert(pos
< TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
);
1269 chan
->u
[i
] = mach
->Inputs
[pos
].xyzw
[swizzle
].u
[i
];
1273 case TGSI_FILE_SYSTEM_VALUE
:
1274 /* XXX no swizzling at this point. Will be needed if we put
1275 * gl_FragCoord, for example, in a sys value register.
1277 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1278 chan
->u
[i
] = mach
->SystemValue
[index
->i
[i
]].u
[i
];
1282 case TGSI_FILE_TEMPORARY
:
1283 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1284 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1285 assert(index2D
->i
[i
] == 0);
1287 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1291 case TGSI_FILE_IMMEDIATE
:
1292 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1293 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1294 assert(index2D
->i
[i
] == 0);
1296 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1300 case TGSI_FILE_ADDRESS
:
1301 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1302 assert(index
->i
[i
] >= 0);
1303 assert(index2D
->i
[i
] == 0);
1305 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1309 case TGSI_FILE_PREDICATE
:
1310 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1311 assert(index
->i
[i
] >= 0 && index
->i
[i
] < TGSI_EXEC_NUM_PREDS
);
1312 assert(index2D
->i
[i
] == 0);
1314 chan
->u
[i
] = mach
->Predicates
[0].xyzw
[swizzle
].u
[i
];
1318 case TGSI_FILE_OUTPUT
:
1319 /* vertex/fragment output vars can be read too */
1320 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1321 assert(index
->i
[i
] >= 0);
1322 assert(index2D
->i
[i
] == 0);
1324 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1330 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1337 fetch_source_d(const struct tgsi_exec_machine
*mach
,
1338 union tgsi_exec_channel
*chan
,
1339 const struct tgsi_full_src_register
*reg
,
1340 const uint chan_index
,
1341 enum tgsi_exec_datatype src_datatype
)
1343 union tgsi_exec_channel index
;
1344 union tgsi_exec_channel index2D
;
1347 /* We start with a direct index into a register file.
1351 * file = Register.File
1352 * [1] = Register.Index
1357 index
.i
[3] = reg
->Register
.Index
;
1359 /* There is an extra source register that indirectly subscripts
1360 * a register file. The direct index now becomes an offset
1361 * that is being added to the indirect register.
1365 * ind = Indirect.File
1366 * [2] = Indirect.Index
1367 * .x = Indirect.SwizzleX
1369 if (reg
->Register
.Indirect
) {
1370 union tgsi_exec_channel index2
;
1371 union tgsi_exec_channel indir_index
;
1372 const uint execmask
= mach
->ExecMask
;
1375 /* which address register (always zero now) */
1379 index2
.i
[3] = reg
->Indirect
.Index
;
1380 /* get current value of address register[swizzle] */
1381 swizzle
= reg
->Indirect
.Swizzle
;
1382 fetch_src_file_channel(mach
,
1390 /* add value of address register to the offset */
1391 index
.i
[0] += indir_index
.i
[0];
1392 index
.i
[1] += indir_index
.i
[1];
1393 index
.i
[2] += indir_index
.i
[2];
1394 index
.i
[3] += indir_index
.i
[3];
1396 /* for disabled execution channels, zero-out the index to
1397 * avoid using a potential garbage value.
1399 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1400 if ((execmask
& (1 << i
)) == 0)
1405 /* There is an extra source register that is a second
1406 * subscript to a register file. Effectively it means that
1407 * the register file is actually a 2D array of registers.
1411 * [3] = Dimension.Index
1413 if (reg
->Register
.Dimension
) {
1417 index2D
.i
[3] = reg
->Dimension
.Index
;
1419 /* Again, the second subscript index can be addressed indirectly
1420 * identically to the first one.
1421 * Nothing stops us from indirectly addressing the indirect register,
1422 * but there is no need for that, so we won't exercise it.
1424 * file[ind[4].y+3][1],
1426 * ind = DimIndirect.File
1427 * [4] = DimIndirect.Index
1428 * .y = DimIndirect.SwizzleX
1430 if (reg
->Dimension
.Indirect
) {
1431 union tgsi_exec_channel index2
;
1432 union tgsi_exec_channel indir_index
;
1433 const uint execmask
= mach
->ExecMask
;
1439 index2
.i
[3] = reg
->DimIndirect
.Index
;
1441 swizzle
= reg
->DimIndirect
.Swizzle
;
1442 fetch_src_file_channel(mach
,
1444 reg
->DimIndirect
.File
,
1450 index2D
.i
[0] += indir_index
.i
[0];
1451 index2D
.i
[1] += indir_index
.i
[1];
1452 index2D
.i
[2] += indir_index
.i
[2];
1453 index2D
.i
[3] += indir_index
.i
[3];
1455 /* for disabled execution channels, zero-out the index to
1456 * avoid using a potential garbage value.
1458 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1459 if ((execmask
& (1 << i
)) == 0) {
1465 /* If by any chance there was a need for a 3D array of register
1466 * files, we would have to check whether Dimension is followed
1467 * by a dimension register and continue the saga.
1476 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1477 fetch_src_file_channel(mach
,
1487 fetch_source(const struct tgsi_exec_machine
*mach
,
1488 union tgsi_exec_channel
*chan
,
1489 const struct tgsi_full_src_register
*reg
,
1490 const uint chan_index
,
1491 enum tgsi_exec_datatype src_datatype
)
1493 fetch_source_d(mach
, chan
, reg
, chan_index
, src_datatype
);
1495 if (reg
->Register
.Absolute
) {
1496 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1497 micro_abs(chan
, chan
);
1499 micro_iabs(chan
, chan
);
1503 if (reg
->Register
.Negate
) {
1504 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1505 micro_neg(chan
, chan
);
1507 micro_ineg(chan
, chan
);
1512 static union tgsi_exec_channel
*
1513 store_dest_dstret(struct tgsi_exec_machine
*mach
,
1514 const union tgsi_exec_channel
*chan
,
1515 const struct tgsi_full_dst_register
*reg
,
1516 const struct tgsi_full_instruction
*inst
,
1518 enum tgsi_exec_datatype dst_datatype
)
1521 static union tgsi_exec_channel null
;
1522 union tgsi_exec_channel
*dst
;
1523 union tgsi_exec_channel index2D
;
1524 uint execmask
= mach
->ExecMask
;
1525 int offset
= 0; /* indirection offset */
1529 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1530 check_inf_or_nan(chan
);
1533 /* There is an extra source register that indirectly subscripts
1534 * a register file. The direct index now becomes an offset
1535 * that is being added to the indirect register.
1539 * ind = Indirect.File
1540 * [2] = Indirect.Index
1541 * .x = Indirect.SwizzleX
1543 if (reg
->Register
.Indirect
) {
1544 union tgsi_exec_channel index
;
1545 union tgsi_exec_channel indir_index
;
1548 /* which address register (always zero for now) */
1552 index
.i
[3] = reg
->Indirect
.Index
;
1554 /* get current value of address register[swizzle] */
1555 swizzle
= reg
->Indirect
.Swizzle
;
1557 /* fetch values from the address/indirection register */
1558 fetch_src_file_channel(mach
,
1566 /* save indirection offset */
1567 offset
= indir_index
.i
[0];
1570 /* There is an extra source register that is a second
1571 * subscript to a register file. Effectively it means that
1572 * the register file is actually a 2D array of registers.
1576 * [3] = Dimension.Index
1578 if (reg
->Register
.Dimension
) {
1582 index2D
.i
[3] = reg
->Dimension
.Index
;
1584 /* Again, the second subscript index can be addressed indirectly
1585 * identically to the first one.
1586 * Nothing stops us from indirectly addressing the indirect register,
1587 * but there is no need for that, so we won't exercise it.
1589 * file[ind[4].y+3][1],
1591 * ind = DimIndirect.File
1592 * [4] = DimIndirect.Index
1593 * .y = DimIndirect.SwizzleX
1595 if (reg
->Dimension
.Indirect
) {
1596 union tgsi_exec_channel index2
;
1597 union tgsi_exec_channel indir_index
;
1598 const uint execmask
= mach
->ExecMask
;
1605 index2
.i
[3] = reg
->DimIndirect
.Index
;
1607 swizzle
= reg
->DimIndirect
.Swizzle
;
1608 fetch_src_file_channel(mach
,
1610 reg
->DimIndirect
.File
,
1616 index2D
.i
[0] += indir_index
.i
[0];
1617 index2D
.i
[1] += indir_index
.i
[1];
1618 index2D
.i
[2] += indir_index
.i
[2];
1619 index2D
.i
[3] += indir_index
.i
[3];
1621 /* for disabled execution channels, zero-out the index to
1622 * avoid using a potential garbage value.
1624 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1625 if ((execmask
& (1 << i
)) == 0) {
1631 /* If by any chance there was a need for a 3D array of register
1632 * files, we would have to check whether Dimension is followed
1633 * by a dimension register and continue the saga.
1642 switch (reg
->Register
.File
) {
1643 case TGSI_FILE_NULL
:
1647 case TGSI_FILE_OUTPUT
:
1648 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1649 + reg
->Register
.Index
;
1650 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1652 debug_printf("NumOutputs = %d, TEMP_O_C/I = %d, redindex = %d\n",
1653 mach
->NumOutputs
, mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0],
1654 reg
->Register
.Index
);
1655 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1656 debug_printf("STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1657 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1658 if (execmask
& (1 << i
))
1659 debug_printf("%f, ", chan
->f
[i
]);
1660 debug_printf(")\n");
1665 case TGSI_FILE_TEMPORARY
:
1666 index
= reg
->Register
.Index
;
1667 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1668 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1671 case TGSI_FILE_ADDRESS
:
1672 index
= reg
->Register
.Index
;
1673 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1676 case TGSI_FILE_PREDICATE
:
1677 index
= reg
->Register
.Index
;
1678 assert(index
< TGSI_EXEC_NUM_PREDS
);
1679 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1687 if (inst
->Instruction
.Predicate
) {
1689 union tgsi_exec_channel
*pred
;
1691 switch (chan_index
) {
1693 swizzle
= inst
->Predicate
.SwizzleX
;
1696 swizzle
= inst
->Predicate
.SwizzleY
;
1699 swizzle
= inst
->Predicate
.SwizzleZ
;
1702 swizzle
= inst
->Predicate
.SwizzleW
;
1709 assert(inst
->Predicate
.Index
== 0);
1711 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1713 if (inst
->Predicate
.Negate
) {
1714 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1716 execmask
&= ~(1 << i
);
1720 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1722 execmask
&= ~(1 << i
);
1732 store_dest_double(struct tgsi_exec_machine
*mach
,
1733 const union tgsi_exec_channel
*chan
,
1734 const struct tgsi_full_dst_register
*reg
,
1735 const struct tgsi_full_instruction
*inst
,
1737 enum tgsi_exec_datatype dst_datatype
)
1739 union tgsi_exec_channel
*dst
;
1740 const uint execmask
= mach
->ExecMask
;
1743 dst
= store_dest_dstret(mach
, chan
, reg
, inst
, chan_index
,
1749 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1750 if (execmask
& (1 << i
))
1751 dst
->i
[i
] = chan
->i
[i
];
1755 store_dest(struct tgsi_exec_machine
*mach
,
1756 const union tgsi_exec_channel
*chan
,
1757 const struct tgsi_full_dst_register
*reg
,
1758 const struct tgsi_full_instruction
*inst
,
1760 enum tgsi_exec_datatype dst_datatype
)
1762 union tgsi_exec_channel
*dst
;
1763 const uint execmask
= mach
->ExecMask
;
1766 dst
= store_dest_dstret(mach
, chan
, reg
, inst
, chan_index
,
1771 if (!inst
->Instruction
.Saturate
) {
1772 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1773 if (execmask
& (1 << i
))
1774 dst
->i
[i
] = chan
->i
[i
];
1777 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1778 if (execmask
& (1 << i
)) {
1779 if (chan
->f
[i
] < 0.0f
)
1781 else if (chan
->f
[i
] > 1.0f
)
1784 dst
->i
[i
] = chan
->i
[i
];
1789 #define FETCH(VAL,INDEX,CHAN)\
1790 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1792 #define IFETCH(VAL,INDEX,CHAN)\
1793 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
1797 * Execute ARB-style KIL which is predicated by a src register.
1798 * Kill fragment if any of the four values is less than zero.
1801 exec_kill_if(struct tgsi_exec_machine
*mach
,
1802 const struct tgsi_full_instruction
*inst
)
1806 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1807 union tgsi_exec_channel r
[1];
1809 /* This mask stores component bits that were already tested. */
1812 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1817 /* unswizzle channel */
1818 swizzle
= tgsi_util_get_full_src_register_swizzle (
1822 /* check if the component has not been already tested */
1823 if (uniquemask
& (1 << swizzle
))
1825 uniquemask
|= 1 << swizzle
;
1827 FETCH(&r
[0], 0, chan_index
);
1828 for (i
= 0; i
< 4; i
++)
1829 if (r
[0].f
[i
] < 0.0f
)
1833 /* restrict to fragments currently executing */
1834 kilmask
&= mach
->ExecMask
;
1836 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1840 * Unconditional fragment kill/discard.
1843 exec_kill(struct tgsi_exec_machine
*mach
,
1844 const struct tgsi_full_instruction
*inst
)
1846 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1848 /* kill fragment for all fragments currently executing */
1849 kilmask
= mach
->ExecMask
;
1850 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1854 emit_vertex(struct tgsi_exec_machine
*mach
)
1856 /* FIXME: check for exec mask correctly
1858 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1859 if ((mach->ExecMask & (1 << i)))
1861 if (mach
->ExecMask
) {
1862 if (mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] >= mach
->MaxOutputVertices
)
1865 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1866 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1871 emit_primitive(struct tgsi_exec_machine
*mach
)
1873 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1874 /* FIXME: check for exec mask correctly
1876 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1877 if ((mach->ExecMask & (1 << i)))
1879 if (mach
->ExecMask
) {
1881 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1882 mach
->Primitives
[*prim_count
] = 0;
1887 conditional_emit_primitive(struct tgsi_exec_machine
*mach
)
1889 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1891 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]];
1892 if (emitted_verts
) {
1893 emit_primitive(mach
);
1900 * Fetch four texture samples using STR texture coordinates.
1903 fetch_texel( struct tgsi_sampler
*sampler
,
1904 const unsigned sview_idx
,
1905 const unsigned sampler_idx
,
1906 const union tgsi_exec_channel
*s
,
1907 const union tgsi_exec_channel
*t
,
1908 const union tgsi_exec_channel
*p
,
1909 const union tgsi_exec_channel
*c0
,
1910 const union tgsi_exec_channel
*c1
,
1911 float derivs
[3][2][TGSI_QUAD_SIZE
],
1912 const int8_t offset
[3],
1913 enum tgsi_sampler_control control
,
1914 union tgsi_exec_channel
*r
,
1915 union tgsi_exec_channel
*g
,
1916 union tgsi_exec_channel
*b
,
1917 union tgsi_exec_channel
*a
)
1920 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1922 /* FIXME: handle explicit derivs, offsets */
1923 sampler
->get_samples(sampler
, sview_idx
, sampler_idx
,
1924 s
->f
, t
->f
, p
->f
, c0
->f
, c1
->f
, derivs
, offset
, control
, rgba
);
1926 for (j
= 0; j
< 4; j
++) {
1927 r
->f
[j
] = rgba
[0][j
];
1928 g
->f
[j
] = rgba
[1][j
];
1929 b
->f
[j
] = rgba
[2][j
];
1930 a
->f
[j
] = rgba
[3][j
];
1935 #define TEX_MODIFIER_NONE 0
1936 #define TEX_MODIFIER_PROJECTED 1
1937 #define TEX_MODIFIER_LOD_BIAS 2
1938 #define TEX_MODIFIER_EXPLICIT_LOD 3
1939 #define TEX_MODIFIER_LEVEL_ZERO 4
1940 #define TEX_MODIFIER_GATHER 5
1943 * Fetch all 3 (for s,t,r coords) texel offsets, put them into int array.
1946 fetch_texel_offsets(struct tgsi_exec_machine
*mach
,
1947 const struct tgsi_full_instruction
*inst
,
1950 if (inst
->Texture
.NumOffsets
== 1) {
1951 union tgsi_exec_channel index
;
1952 union tgsi_exec_channel offset
[3];
1953 index
.i
[0] = index
.i
[1] = index
.i
[2] = index
.i
[3] = inst
->TexOffsets
[0].Index
;
1954 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1955 inst
->TexOffsets
[0].SwizzleX
, &index
, &ZeroVec
, &offset
[0]);
1956 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1957 inst
->TexOffsets
[0].SwizzleY
, &index
, &ZeroVec
, &offset
[1]);
1958 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1959 inst
->TexOffsets
[0].SwizzleZ
, &index
, &ZeroVec
, &offset
[2]);
1960 offsets
[0] = offset
[0].i
[0];
1961 offsets
[1] = offset
[1].i
[0];
1962 offsets
[2] = offset
[2].i
[0];
1964 assert(inst
->Texture
.NumOffsets
== 0);
1965 offsets
[0] = offsets
[1] = offsets
[2] = 0;
1971 * Fetch dx and dy values for one channel (s, t or r).
1972 * Put dx values into one float array, dy values into another.
1975 fetch_assign_deriv_channel(struct tgsi_exec_machine
*mach
,
1976 const struct tgsi_full_instruction
*inst
,
1979 float derivs
[2][TGSI_QUAD_SIZE
])
1981 union tgsi_exec_channel d
;
1982 FETCH(&d
, regdsrcx
, chan
);
1983 derivs
[0][0] = d
.f
[0];
1984 derivs
[0][1] = d
.f
[1];
1985 derivs
[0][2] = d
.f
[2];
1986 derivs
[0][3] = d
.f
[3];
1987 FETCH(&d
, regdsrcx
+ 1, chan
);
1988 derivs
[1][0] = d
.f
[0];
1989 derivs
[1][1] = d
.f
[1];
1990 derivs
[1][2] = d
.f
[2];
1991 derivs
[1][3] = d
.f
[3];
1995 fetch_sampler_unit(struct tgsi_exec_machine
*mach
,
1996 const struct tgsi_full_instruction
*inst
,
2001 if (inst
->Src
[sampler
].Register
.Indirect
) {
2002 const struct tgsi_full_src_register
*reg
= &inst
->Src
[sampler
];
2003 union tgsi_exec_channel indir_index
, index2
;
2004 const uint execmask
= mach
->ExecMask
;
2008 index2
.i
[3] = reg
->Indirect
.Index
;
2010 fetch_src_file_channel(mach
,
2013 reg
->Indirect
.Swizzle
,
2017 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2018 if (execmask
& (1 << i
)) {
2019 unit
= inst
->Src
[sampler
].Register
.Index
+ indir_index
.i
[i
];
2025 unit
= inst
->Src
[sampler
].Register
.Index
;
2031 * execute a texture instruction.
2033 * modifier is used to control the channel routing for the
2034 * instruction variants like proj, lod, and texture with lod bias.
2035 * sampler indicates which src register the sampler is contained in.
2038 exec_tex(struct tgsi_exec_machine
*mach
,
2039 const struct tgsi_full_instruction
*inst
,
2040 uint modifier
, uint sampler
)
2042 const union tgsi_exec_channel
*args
[5], *proj
= NULL
;
2043 union tgsi_exec_channel r
[5];
2044 enum tgsi_sampler_control control
= TGSI_SAMPLER_LOD_NONE
;
2048 int dim
, shadow_ref
, i
;
2050 unit
= fetch_sampler_unit(mach
, inst
, sampler
);
2051 /* always fetch all 3 offsets, overkill but keeps code simple */
2052 fetch_texel_offsets(mach
, inst
, offsets
);
2054 assert(modifier
!= TEX_MODIFIER_LEVEL_ZERO
);
2055 assert(inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
);
2057 dim
= tgsi_util_get_texture_coord_dim(inst
->Texture
.Texture
, &shadow_ref
);
2060 if (shadow_ref
>= 0)
2061 assert(shadow_ref
>= dim
&& shadow_ref
< Elements(args
));
2063 /* fetch modifier to the last argument */
2064 if (modifier
!= TEX_MODIFIER_NONE
) {
2065 const int last
= Elements(args
) - 1;
2067 /* fetch modifier from src0.w or src1.x */
2069 assert(dim
<= TGSI_CHAN_W
&& shadow_ref
!= TGSI_CHAN_W
);
2070 FETCH(&r
[last
], 0, TGSI_CHAN_W
);
2073 assert(shadow_ref
!= 4);
2074 FETCH(&r
[last
], 1, TGSI_CHAN_X
);
2077 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
2078 args
[last
] = &r
[last
];
2082 args
[last
] = &ZeroVec
;
2085 /* point unused arguments to zero vector */
2086 for (i
= dim
; i
< last
; i
++)
2089 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
)
2090 control
= TGSI_SAMPLER_LOD_EXPLICIT
;
2091 else if (modifier
== TEX_MODIFIER_LOD_BIAS
)
2092 control
= TGSI_SAMPLER_LOD_BIAS
;
2093 else if (modifier
== TEX_MODIFIER_GATHER
)
2094 control
= TGSI_SAMPLER_GATHER
;
2097 for (i
= dim
; i
< Elements(args
); i
++)
2101 /* fetch coordinates */
2102 for (i
= 0; i
< dim
; i
++) {
2103 FETCH(&r
[i
], 0, TGSI_CHAN_X
+ i
);
2106 micro_div(&r
[i
], &r
[i
], proj
);
2111 /* fetch reference value */
2112 if (shadow_ref
>= 0) {
2113 FETCH(&r
[shadow_ref
], shadow_ref
/ 4, TGSI_CHAN_X
+ (shadow_ref
% 4));
2116 micro_div(&r
[shadow_ref
], &r
[shadow_ref
], proj
);
2118 args
[shadow_ref
] = &r
[shadow_ref
];
2121 fetch_texel(mach
->Sampler
, unit
, unit
,
2122 args
[0], args
[1], args
[2], args
[3], args
[4],
2123 NULL
, offsets
, control
,
2124 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2127 debug_printf("fetch r: %g %g %g %g\n",
2128 r
[0].f
[0], r
[0].f
[1], r
[0].f
[2], r
[0].f
[3]);
2129 debug_printf("fetch g: %g %g %g %g\n",
2130 r
[1].f
[0], r
[1].f
[1], r
[1].f
[2], r
[1].f
[3]);
2131 debug_printf("fetch b: %g %g %g %g\n",
2132 r
[2].f
[0], r
[2].f
[1], r
[2].f
[2], r
[2].f
[3]);
2133 debug_printf("fetch a: %g %g %g %g\n",
2134 r
[3].f
[0], r
[3].f
[1], r
[3].f
[2], r
[3].f
[3]);
2137 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2138 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2139 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2145 exec_lodq(struct tgsi_exec_machine
*mach
,
2146 const struct tgsi_full_instruction
*inst
)
2151 union tgsi_exec_channel coords
[4];
2152 const union tgsi_exec_channel
*args
[Elements(coords
)];
2153 union tgsi_exec_channel r
[2];
2155 unit
= fetch_sampler_unit(mach
, inst
, 1);
2156 dim
= tgsi_util_get_texture_coord_dim(inst
->Texture
.Texture
, NULL
);
2157 assert(dim
<= Elements(coords
));
2158 /* fetch coordinates */
2159 for (i
= 0; i
< dim
; i
++) {
2160 FETCH(&coords
[i
], 0, TGSI_CHAN_X
+ i
);
2161 args
[i
] = &coords
[i
];
2163 for (i
= dim
; i
< Elements(coords
); i
++) {
2166 mach
->Sampler
->query_lod(mach
->Sampler
, unit
, unit
,
2171 TGSI_SAMPLER_LOD_NONE
,
2175 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2176 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
,
2177 TGSI_EXEC_DATA_FLOAT
);
2179 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2180 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
,
2181 TGSI_EXEC_DATA_FLOAT
);
2186 exec_txd(struct tgsi_exec_machine
*mach
,
2187 const struct tgsi_full_instruction
*inst
)
2189 union tgsi_exec_channel r
[4];
2190 float derivs
[3][2][TGSI_QUAD_SIZE
];
2195 unit
= fetch_sampler_unit(mach
, inst
, 3);
2196 /* always fetch all 3 offsets, overkill but keeps code simple */
2197 fetch_texel_offsets(mach
, inst
, offsets
);
2199 switch (inst
->Texture
.Texture
) {
2200 case TGSI_TEXTURE_1D
:
2201 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2203 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2205 fetch_texel(mach
->Sampler
, unit
, unit
,
2206 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2207 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2208 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2211 case TGSI_TEXTURE_SHADOW1D
:
2212 case TGSI_TEXTURE_1D_ARRAY
:
2213 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
2214 /* SHADOW1D/1D_ARRAY would not need Y/Z respectively, but don't bother */
2215 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2216 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2217 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2219 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2221 fetch_texel(mach
->Sampler
, unit
, unit
,
2222 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2223 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2224 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2227 case TGSI_TEXTURE_2D
:
2228 case TGSI_TEXTURE_RECT
:
2229 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2230 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2232 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2233 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
2235 fetch_texel(mach
->Sampler
, unit
, unit
,
2236 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2237 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2238 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2242 case TGSI_TEXTURE_SHADOW2D
:
2243 case TGSI_TEXTURE_SHADOWRECT
:
2244 case TGSI_TEXTURE_2D_ARRAY
:
2245 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2246 /* only SHADOW2D_ARRAY actually needs W */
2247 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2248 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2249 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2250 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2252 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2253 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
2255 fetch_texel(mach
->Sampler
, unit
, unit
,
2256 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
2257 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2258 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2261 case TGSI_TEXTURE_3D
:
2262 case TGSI_TEXTURE_CUBE
:
2263 case TGSI_TEXTURE_CUBE_ARRAY
:
2264 case TGSI_TEXTURE_SHADOWCUBE
:
2265 /* only TEXTURE_CUBE_ARRAY and TEXTURE_SHADOWCUBE actually need W */
2266 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2267 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2268 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2269 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2271 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
2272 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
2273 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Z
, derivs
[2]);
2275 fetch_texel(mach
->Sampler
, unit
, unit
,
2276 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
2277 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2278 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2285 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2286 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2287 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2294 exec_txf(struct tgsi_exec_machine
*mach
,
2295 const struct tgsi_full_instruction
*inst
)
2297 union tgsi_exec_channel r
[4];
2300 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2305 unit
= fetch_sampler_unit(mach
, inst
, 1);
2306 /* always fetch all 3 offsets, overkill but keeps code simple */
2307 fetch_texel_offsets(mach
, inst
, offsets
);
2309 IFETCH(&r
[3], 0, TGSI_CHAN_W
);
2311 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
||
2312 inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I_MS
) {
2313 target
= mach
->SamplerViews
[unit
].Resource
;
2316 target
= inst
->Texture
.Texture
;
2319 case TGSI_TEXTURE_3D
:
2320 case TGSI_TEXTURE_2D_ARRAY
:
2321 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2322 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
2323 IFETCH(&r
[2], 0, TGSI_CHAN_Z
);
2325 case TGSI_TEXTURE_2D
:
2326 case TGSI_TEXTURE_RECT
:
2327 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
2328 case TGSI_TEXTURE_SHADOW2D
:
2329 case TGSI_TEXTURE_SHADOWRECT
:
2330 case TGSI_TEXTURE_1D_ARRAY
:
2331 case TGSI_TEXTURE_2D_MSAA
:
2332 IFETCH(&r
[1], 0, TGSI_CHAN_Y
);
2334 case TGSI_TEXTURE_BUFFER
:
2335 case TGSI_TEXTURE_1D
:
2336 case TGSI_TEXTURE_SHADOW1D
:
2337 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
2344 mach
->Sampler
->get_texel(mach
->Sampler
, unit
, r
[0].i
, r
[1].i
, r
[2].i
, r
[3].i
,
2347 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2348 r
[0].f
[j
] = rgba
[0][j
];
2349 r
[1].f
[j
] = rgba
[1][j
];
2350 r
[2].f
[j
] = rgba
[2][j
];
2351 r
[3].f
[j
] = rgba
[3][j
];
2354 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
||
2355 inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I_MS
) {
2356 unsigned char swizzles
[4];
2357 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2358 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2359 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2360 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2362 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2363 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2364 store_dest(mach
, &r
[swizzles
[chan
]],
2365 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2370 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2371 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2372 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2379 exec_txq(struct tgsi_exec_machine
*mach
,
2380 const struct tgsi_full_instruction
*inst
)
2383 union tgsi_exec_channel r
[4], src
;
2388 unit
= fetch_sampler_unit(mach
, inst
, 1);
2390 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
2392 /* XXX: This interface can't return per-pixel values */
2393 mach
->Sampler
->get_dims(mach
->Sampler
, unit
, src
.i
[0], result
);
2395 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2396 for (j
= 0; j
< 4; j
++) {
2397 r
[j
].i
[i
] = result
[j
];
2401 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2402 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2403 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
2404 TGSI_EXEC_DATA_INT
);
2410 exec_sample(struct tgsi_exec_machine
*mach
,
2411 const struct tgsi_full_instruction
*inst
,
2412 uint modifier
, boolean compare
)
2414 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2415 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2416 union tgsi_exec_channel r
[5], c1
;
2417 const union tgsi_exec_channel
*lod
= &ZeroVec
;
2418 enum tgsi_sampler_control control
= TGSI_SAMPLER_LOD_NONE
;
2420 unsigned char swizzles
[4];
2423 /* always fetch all 3 offsets, overkill but keeps code simple */
2424 fetch_texel_offsets(mach
, inst
, offsets
);
2426 assert(modifier
!= TEX_MODIFIER_PROJECTED
);
2428 if (modifier
!= TEX_MODIFIER_NONE
) {
2429 if (modifier
== TEX_MODIFIER_LOD_BIAS
) {
2430 FETCH(&c1
, 3, TGSI_CHAN_X
);
2432 control
= TGSI_SAMPLER_LOD_BIAS
;
2434 else if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
2435 FETCH(&c1
, 3, TGSI_CHAN_X
);
2437 control
= TGSI_SAMPLER_LOD_EXPLICIT
;
2440 assert(modifier
== TEX_MODIFIER_LEVEL_ZERO
);
2441 control
= TGSI_SAMPLER_LOD_ZERO
;
2445 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2447 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2448 case TGSI_TEXTURE_1D
:
2450 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2451 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2452 &r
[0], &ZeroVec
, &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2453 NULL
, offsets
, control
,
2454 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2457 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2458 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2459 NULL
, offsets
, control
,
2460 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2464 case TGSI_TEXTURE_1D_ARRAY
:
2465 case TGSI_TEXTURE_2D
:
2466 case TGSI_TEXTURE_RECT
:
2467 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2469 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2470 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2471 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2472 NULL
, offsets
, control
,
2473 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2476 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2477 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2478 NULL
, offsets
, control
,
2479 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2483 case TGSI_TEXTURE_2D_ARRAY
:
2484 case TGSI_TEXTURE_3D
:
2485 case TGSI_TEXTURE_CUBE
:
2486 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2487 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2489 FETCH(&r
[3], 3, TGSI_CHAN_X
);
2490 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2491 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2492 NULL
, offsets
, control
,
2493 &r
[0], &r
[1], &r
[2], &r
[3]);
2496 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2497 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
,
2498 NULL
, offsets
, control
,
2499 &r
[0], &r
[1], &r
[2], &r
[3]);
2503 case TGSI_TEXTURE_CUBE_ARRAY
:
2504 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2505 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2506 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2508 FETCH(&r
[4], 3, TGSI_CHAN_X
);
2509 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2510 &r
[0], &r
[1], &r
[2], &r
[3], &r
[4],
2511 NULL
, offsets
, control
,
2512 &r
[0], &r
[1], &r
[2], &r
[3]);
2515 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2516 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2517 NULL
, offsets
, control
,
2518 &r
[0], &r
[1], &r
[2], &r
[3]);
2527 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2528 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2529 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2530 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2532 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2533 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2534 store_dest(mach
, &r
[swizzles
[chan
]],
2535 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2541 exec_sample_d(struct tgsi_exec_machine
*mach
,
2542 const struct tgsi_full_instruction
*inst
)
2544 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2545 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2546 union tgsi_exec_channel r
[4];
2547 float derivs
[3][2][TGSI_QUAD_SIZE
];
2549 unsigned char swizzles
[4];
2552 /* always fetch all 3 offsets, overkill but keeps code simple */
2553 fetch_texel_offsets(mach
, inst
, offsets
);
2555 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2557 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2558 case TGSI_TEXTURE_1D
:
2559 case TGSI_TEXTURE_1D_ARRAY
:
2560 /* only 1D array actually needs Y */
2561 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2563 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2565 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2566 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2567 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2568 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2571 case TGSI_TEXTURE_2D
:
2572 case TGSI_TEXTURE_RECT
:
2573 case TGSI_TEXTURE_2D_ARRAY
:
2574 /* only 2D array actually needs Z */
2575 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2576 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2578 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2579 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2581 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2582 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* inputs */
2583 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2584 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2587 case TGSI_TEXTURE_3D
:
2588 case TGSI_TEXTURE_CUBE
:
2589 case TGSI_TEXTURE_CUBE_ARRAY
:
2590 /* only cube array actually needs W */
2591 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2592 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2593 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2595 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2596 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2597 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Z
, derivs
[2]);
2599 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2600 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
,
2601 derivs
, offsets
, TGSI_SAMPLER_DERIVS_EXPLICIT
,
2602 &r
[0], &r
[1], &r
[2], &r
[3]);
2609 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2610 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2611 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2612 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2614 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2615 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2616 store_dest(mach
, &r
[swizzles
[chan
]],
2617 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2624 * Evaluate a constant-valued coefficient at the position of the
2629 struct tgsi_exec_machine
*mach
,
2635 for( i
= 0; i
< TGSI_QUAD_SIZE
; i
++ ) {
2636 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
2641 * Evaluate a linear-valued coefficient at the position of the
2646 struct tgsi_exec_machine
*mach
,
2650 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2651 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2652 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2653 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2654 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2655 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
2656 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
2657 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
2658 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
2662 * Evaluate a perspective-valued coefficient at the position of the
2666 eval_perspective_coef(
2667 struct tgsi_exec_machine
*mach
,
2671 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2672 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2673 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2674 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2675 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2676 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
2677 /* divide by W here */
2678 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
2679 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
2680 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
2681 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
2685 typedef void (* eval_coef_func
)(
2686 struct tgsi_exec_machine
*mach
,
2691 exec_declaration(struct tgsi_exec_machine
*mach
,
2692 const struct tgsi_full_declaration
*decl
)
2694 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
2695 mach
->SamplerViews
[decl
->Range
.First
] = decl
->SamplerView
;
2699 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
2700 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
2701 uint first
, last
, mask
;
2703 first
= decl
->Range
.First
;
2704 last
= decl
->Range
.Last
;
2705 mask
= decl
->Declaration
.UsageMask
;
2707 /* XXX we could remove this special-case code since
2708 * mach->InterpCoefs[first].a0 should already have the
2709 * front/back-face value. But we should first update the
2710 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2711 * Then, we could remove the tgsi_exec_machine::Face field.
2713 /* XXX make FACE a system value */
2714 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
2717 assert(decl
->Semantic
.Index
== 0);
2718 assert(first
== last
);
2720 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2721 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
2724 eval_coef_func eval
;
2727 switch (decl
->Interp
.Interpolate
) {
2728 case TGSI_INTERPOLATE_CONSTANT
:
2729 eval
= eval_constant_coef
;
2732 case TGSI_INTERPOLATE_LINEAR
:
2733 eval
= eval_linear_coef
;
2736 case TGSI_INTERPOLATE_PERSPECTIVE
:
2737 eval
= eval_perspective_coef
;
2740 case TGSI_INTERPOLATE_COLOR
:
2741 eval
= mach
->flatshade_color
? eval_constant_coef
: eval_perspective_coef
;
2749 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2750 if (mask
& (1 << j
)) {
2751 for (i
= first
; i
<= last
; i
++) {
2758 if (DEBUG_EXECUTION
) {
2760 for (i
= first
; i
<= last
; ++i
) {
2761 debug_printf("IN[%2u] = ", i
);
2762 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2766 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
2767 mach
->Inputs
[i
].xyzw
[0].f
[j
], mach
->Inputs
[i
].xyzw
[0].u
[j
],
2768 mach
->Inputs
[i
].xyzw
[1].f
[j
], mach
->Inputs
[i
].xyzw
[1].u
[j
],
2769 mach
->Inputs
[i
].xyzw
[2].f
[j
], mach
->Inputs
[i
].xyzw
[2].u
[j
],
2770 mach
->Inputs
[i
].xyzw
[3].f
[j
], mach
->Inputs
[i
].xyzw
[3].u
[j
]);
2777 if (decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
2778 mach
->SysSemanticToIndex
[decl
->Declaration
.Semantic
] = decl
->Range
.First
;
2782 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
2783 const union tgsi_exec_channel
*src
);
2786 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
2787 const struct tgsi_full_instruction
*inst
,
2789 enum tgsi_exec_datatype dst_datatype
,
2790 enum tgsi_exec_datatype src_datatype
)
2793 union tgsi_exec_channel src
;
2794 union tgsi_exec_channel dst
;
2796 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2798 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2799 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2800 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2806 exec_vector_unary(struct tgsi_exec_machine
*mach
,
2807 const struct tgsi_full_instruction
*inst
,
2809 enum tgsi_exec_datatype dst_datatype
,
2810 enum tgsi_exec_datatype src_datatype
)
2813 struct tgsi_exec_vector dst
;
2815 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2816 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2817 union tgsi_exec_channel src
;
2819 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
2820 op(&dst
.xyzw
[chan
], &src
);
2823 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2824 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2825 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2830 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
2831 const union tgsi_exec_channel
*src0
,
2832 const union tgsi_exec_channel
*src1
);
2835 exec_scalar_binary(struct tgsi_exec_machine
*mach
,
2836 const struct tgsi_full_instruction
*inst
,
2838 enum tgsi_exec_datatype dst_datatype
,
2839 enum tgsi_exec_datatype src_datatype
)
2842 union tgsi_exec_channel src
[2];
2843 union tgsi_exec_channel dst
;
2845 fetch_source(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2846 fetch_source(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, src_datatype
);
2847 op(&dst
, &src
[0], &src
[1]);
2848 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2849 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2850 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2856 exec_vector_binary(struct tgsi_exec_machine
*mach
,
2857 const struct tgsi_full_instruction
*inst
,
2859 enum tgsi_exec_datatype dst_datatype
,
2860 enum tgsi_exec_datatype src_datatype
)
2863 struct tgsi_exec_vector dst
;
2865 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2866 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2867 union tgsi_exec_channel src
[2];
2869 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2870 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2871 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
2874 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2875 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2876 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2881 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
2882 const union tgsi_exec_channel
*src0
,
2883 const union tgsi_exec_channel
*src1
,
2884 const union tgsi_exec_channel
*src2
);
2887 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
2888 const struct tgsi_full_instruction
*inst
,
2889 micro_trinary_op op
,
2890 enum tgsi_exec_datatype dst_datatype
,
2891 enum tgsi_exec_datatype src_datatype
)
2894 struct tgsi_exec_vector dst
;
2896 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2897 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2898 union tgsi_exec_channel src
[3];
2900 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2901 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2902 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2903 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
2906 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2907 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2908 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2913 typedef void (* micro_quaternary_op
)(union tgsi_exec_channel
*dst
,
2914 const union tgsi_exec_channel
*src0
,
2915 const union tgsi_exec_channel
*src1
,
2916 const union tgsi_exec_channel
*src2
,
2917 const union tgsi_exec_channel
*src3
);
2920 exec_vector_quaternary(struct tgsi_exec_machine
*mach
,
2921 const struct tgsi_full_instruction
*inst
,
2922 micro_quaternary_op op
,
2923 enum tgsi_exec_datatype dst_datatype
,
2924 enum tgsi_exec_datatype src_datatype
)
2927 struct tgsi_exec_vector dst
;
2929 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2930 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2931 union tgsi_exec_channel src
[4];
2933 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2934 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2935 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2936 fetch_source(mach
, &src
[3], &inst
->Src
[3], chan
, src_datatype
);
2937 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2], &src
[3]);
2940 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2941 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2942 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2948 exec_dp3(struct tgsi_exec_machine
*mach
,
2949 const struct tgsi_full_instruction
*inst
)
2952 union tgsi_exec_channel arg
[3];
2954 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2955 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2956 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2958 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
2959 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2960 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2961 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2964 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2965 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2966 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2972 exec_dp4(struct tgsi_exec_machine
*mach
,
2973 const struct tgsi_full_instruction
*inst
)
2976 union tgsi_exec_channel arg
[3];
2978 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2979 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2980 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2982 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
2983 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2984 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2985 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2988 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2989 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2990 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2996 exec_dp2a(struct tgsi_exec_machine
*mach
,
2997 const struct tgsi_full_instruction
*inst
)
3000 union tgsi_exec_channel arg
[3];
3002 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3003 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3004 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
3006 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3007 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3008 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
3010 fetch_source(mach
, &arg
[1], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3011 micro_add(&arg
[0], &arg
[0], &arg
[1]);
3013 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3014 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3015 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3021 exec_dph(struct tgsi_exec_machine
*mach
,
3022 const struct tgsi_full_instruction
*inst
)
3025 union tgsi_exec_channel arg
[3];
3027 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3028 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3029 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
3031 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3032 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3033 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
3035 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3036 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3037 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
3039 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3040 micro_add(&arg
[0], &arg
[0], &arg
[1]);
3042 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3043 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3044 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3050 exec_dp2(struct tgsi_exec_machine
*mach
,
3051 const struct tgsi_full_instruction
*inst
)
3054 union tgsi_exec_channel arg
[3];
3056 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3057 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3058 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
3060 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3061 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3062 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
3064 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3065 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3066 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3072 exec_pk2h(struct tgsi_exec_machine
*mach
,
3073 const struct tgsi_full_instruction
*inst
)
3076 union tgsi_exec_channel arg
[2], dst
;
3078 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3079 fetch_source(mach
, &arg
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3080 for (chan
= 0; chan
< TGSI_QUAD_SIZE
; chan
++) {
3081 dst
.u
[chan
] = util_float_to_half(arg
[0].f
[chan
]) |
3082 (util_float_to_half(arg
[1].f
[chan
]) << 16);
3084 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3085 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3086 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_UINT
);
3092 exec_up2h(struct tgsi_exec_machine
*mach
,
3093 const struct tgsi_full_instruction
*inst
)
3096 union tgsi_exec_channel arg
, dst
[2];
3098 fetch_source(mach
, &arg
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3099 for (chan
= 0; chan
< TGSI_QUAD_SIZE
; chan
++) {
3100 dst
[0].f
[chan
] = util_half_to_float(arg
.u
[chan
] & 0xffff);
3101 dst
[1].f
[chan
] = util_half_to_float(arg
.u
[chan
] >> 16);
3103 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3104 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3105 store_dest(mach
, &dst
[chan
& 1], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3111 exec_scs(struct tgsi_exec_machine
*mach
,
3112 const struct tgsi_full_instruction
*inst
)
3114 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) {
3115 union tgsi_exec_channel arg
;
3116 union tgsi_exec_channel result
;
3118 fetch_source(mach
, &arg
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3120 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3121 micro_cos(&result
, &arg
);
3122 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3124 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3125 micro_sin(&result
, &arg
);
3126 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3129 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3130 store_dest(mach
, &ZeroVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3132 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3133 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3138 exec_xpd(struct tgsi_exec_machine
*mach
,
3139 const struct tgsi_full_instruction
*inst
)
3141 union tgsi_exec_channel r
[6];
3142 union tgsi_exec_channel d
[3];
3144 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3145 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3147 micro_mul(&r
[2], &r
[0], &r
[1]);
3149 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3150 fetch_source(mach
, &r
[4], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3152 micro_mul(&r
[5], &r
[3], &r
[4] );
3153 micro_sub(&d
[TGSI_CHAN_X
], &r
[2], &r
[5]);
3155 fetch_source(mach
, &r
[2], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3157 micro_mul(&r
[3], &r
[3], &r
[2]);
3159 fetch_source(mach
, &r
[5], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3161 micro_mul(&r
[1], &r
[1], &r
[5]);
3162 micro_sub(&d
[TGSI_CHAN_Y
], &r
[3], &r
[1]);
3164 micro_mul(&r
[5], &r
[5], &r
[4]);
3165 micro_mul(&r
[0], &r
[0], &r
[2]);
3166 micro_sub(&d
[TGSI_CHAN_Z
], &r
[5], &r
[0]);
3168 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3169 store_dest(mach
, &d
[TGSI_CHAN_X
], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3171 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3172 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3174 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3175 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3177 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3178 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3183 exec_dst(struct tgsi_exec_machine
*mach
,
3184 const struct tgsi_full_instruction
*inst
)
3186 union tgsi_exec_channel r
[2];
3187 union tgsi_exec_channel d
[4];
3189 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3190 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3191 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3192 micro_mul(&d
[TGSI_CHAN_Y
], &r
[0], &r
[1]);
3194 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3195 fetch_source(mach
, &d
[TGSI_CHAN_Z
], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3197 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3198 fetch_source(mach
, &d
[TGSI_CHAN_W
], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3201 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3202 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3204 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3205 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3207 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3208 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3210 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3211 store_dest(mach
, &d
[TGSI_CHAN_W
], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3216 exec_log(struct tgsi_exec_machine
*mach
,
3217 const struct tgsi_full_instruction
*inst
)
3219 union tgsi_exec_channel r
[3];
3221 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3222 micro_abs(&r
[2], &r
[0]); /* r2 = abs(r0) */
3223 micro_lg2(&r
[1], &r
[2]); /* r1 = lg2(r2) */
3224 micro_flr(&r
[0], &r
[1]); /* r0 = floor(r1) */
3225 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3226 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3228 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3229 micro_exp2(&r
[0], &r
[0]); /* r0 = 2 ^ r0 */
3230 micro_div(&r
[0], &r
[2], &r
[0]); /* r0 = r2 / r0 */
3231 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3233 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3234 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3236 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3237 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3242 exec_exp(struct tgsi_exec_machine
*mach
,
3243 const struct tgsi_full_instruction
*inst
)
3245 union tgsi_exec_channel r
[3];
3247 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3248 micro_flr(&r
[1], &r
[0]); /* r1 = floor(r0) */
3249 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3250 micro_exp2(&r
[2], &r
[1]); /* r2 = 2 ^ r1 */
3251 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3253 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3254 micro_sub(&r
[2], &r
[0], &r
[1]); /* r2 = r0 - r1 */
3255 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3257 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3258 micro_exp2(&r
[2], &r
[0]); /* r2 = 2 ^ r0 */
3259 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3261 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3262 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3267 exec_lit(struct tgsi_exec_machine
*mach
,
3268 const struct tgsi_full_instruction
*inst
)
3270 union tgsi_exec_channel r
[3];
3271 union tgsi_exec_channel d
[3];
3273 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YZ
) {
3274 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3275 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3276 fetch_source(mach
, &r
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3277 micro_max(&r
[1], &r
[1], &ZeroVec
);
3279 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3280 micro_min(&r
[2], &r
[2], &P128Vec
);
3281 micro_max(&r
[2], &r
[2], &M128Vec
);
3282 micro_pow(&r
[1], &r
[1], &r
[2]);
3283 micro_lt(&d
[TGSI_CHAN_Z
], &ZeroVec
, &r
[0], &r
[1], &ZeroVec
);
3284 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3286 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3287 micro_max(&d
[TGSI_CHAN_Y
], &r
[0], &ZeroVec
);
3288 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3291 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3292 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3295 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3296 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3301 exec_break(struct tgsi_exec_machine
*mach
)
3303 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
3304 /* turn off loop channels for each enabled exec channel */
3305 mach
->LoopMask
&= ~mach
->ExecMask
;
3306 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3307 UPDATE_EXEC_MASK(mach
);
3309 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
3311 mach
->Switch
.mask
= 0x0;
3313 UPDATE_EXEC_MASK(mach
);
3318 exec_switch(struct tgsi_exec_machine
*mach
,
3319 const struct tgsi_full_instruction
*inst
)
3321 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3322 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3324 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3325 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3326 mach
->Switch
.mask
= 0x0;
3327 mach
->Switch
.defaultMask
= 0x0;
3329 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3330 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
3332 UPDATE_EXEC_MASK(mach
);
3336 exec_case(struct tgsi_exec_machine
*mach
,
3337 const struct tgsi_full_instruction
*inst
)
3339 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3340 union tgsi_exec_channel src
;
3343 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3345 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
3348 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
3351 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
3354 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
3358 mach
->Switch
.defaultMask
|= mask
;
3360 mach
->Switch
.mask
|= mask
& prevMask
;
3362 UPDATE_EXEC_MASK(mach
);
3365 /* FIXME: this will only work if default is last */
3367 exec_default(struct tgsi_exec_machine
*mach
)
3369 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3371 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
3373 UPDATE_EXEC_MASK(mach
);
3377 exec_endswitch(struct tgsi_exec_machine
*mach
)
3379 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
3380 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3382 UPDATE_EXEC_MASK(mach
);
3385 typedef void (* micro_dop
)(union tgsi_double_channel
*dst
,
3386 const union tgsi_double_channel
*src
);
3389 fetch_double_channel(struct tgsi_exec_machine
*mach
,
3390 union tgsi_double_channel
*chan
,
3391 const struct tgsi_full_src_register
*reg
,
3395 union tgsi_exec_channel src
[2];
3398 fetch_source_d(mach
, &src
[0], reg
, chan_0
, TGSI_EXEC_DATA_UINT
);
3399 fetch_source_d(mach
, &src
[1], reg
, chan_1
, TGSI_EXEC_DATA_UINT
);
3401 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
3402 chan
->u
[i
][0] = src
[0].u
[i
];
3403 chan
->u
[i
][1] = src
[1].u
[i
];
3405 if (reg
->Register
.Absolute
) {
3406 micro_dabs(chan
, chan
);
3408 if (reg
->Register
.Negate
) {
3409 micro_dneg(chan
, chan
);
3414 store_double_channel(struct tgsi_exec_machine
*mach
,
3415 const union tgsi_double_channel
*chan
,
3416 const struct tgsi_full_dst_register
*reg
,
3417 const struct tgsi_full_instruction
*inst
,
3421 union tgsi_exec_channel dst
[2];
3423 union tgsi_double_channel temp
;
3424 const uint execmask
= mach
->ExecMask
;
3426 if (!inst
->Instruction
.Saturate
) {
3427 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
3428 if (execmask
& (1 << i
)) {
3429 dst
[0].u
[i
] = chan
->u
[i
][0];
3430 dst
[1].u
[i
] = chan
->u
[i
][1];
3434 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
3435 if (execmask
& (1 << i
)) {
3436 if (chan
->d
[i
] < 0.0)
3438 else if (chan
->d
[i
] > 1.0)
3441 temp
.d
[i
] = chan
->d
[i
];
3443 dst
[0].u
[i
] = temp
.u
[i
][0];
3444 dst
[1].u
[i
] = temp
.u
[i
][1];
3448 store_dest_double(mach
, &dst
[0], reg
, inst
, chan_0
, TGSI_EXEC_DATA_UINT
);
3450 store_dest_double(mach
, &dst
[1], reg
, inst
, chan_1
, TGSI_EXEC_DATA_UINT
);
3454 exec_double_unary(struct tgsi_exec_machine
*mach
,
3455 const struct tgsi_full_instruction
*inst
,
3458 union tgsi_double_channel src
;
3459 union tgsi_double_channel dst
;
3461 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
3462 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3464 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3466 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
3467 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3469 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3474 exec_double_binary(struct tgsi_exec_machine
*mach
,
3475 const struct tgsi_full_instruction
*inst
,
3477 enum tgsi_exec_datatype dst_datatype
)
3479 union tgsi_double_channel src
[2];
3480 union tgsi_double_channel dst
;
3481 int first_dest_chan
, second_dest_chan
;
3484 wmask
= inst
->Dst
[0].Register
.WriteMask
;
3485 /* these are & because of the way DSLT etc store their destinations */
3486 if (wmask
& TGSI_WRITEMASK_XY
) {
3487 first_dest_chan
= TGSI_CHAN_X
;
3488 second_dest_chan
= TGSI_CHAN_Y
;
3489 if (dst_datatype
== TGSI_EXEC_DATA_UINT
) {
3490 first_dest_chan
= (wmask
& TGSI_WRITEMASK_X
) ? TGSI_CHAN_X
: TGSI_CHAN_Y
;
3491 second_dest_chan
= -1;
3494 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3495 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3497 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, first_dest_chan
, second_dest_chan
);
3500 if (wmask
& TGSI_WRITEMASK_ZW
) {
3501 first_dest_chan
= TGSI_CHAN_Z
;
3502 second_dest_chan
= TGSI_CHAN_W
;
3503 if (dst_datatype
== TGSI_EXEC_DATA_UINT
) {
3504 first_dest_chan
= (wmask
& TGSI_WRITEMASK_Z
) ? TGSI_CHAN_Z
: TGSI_CHAN_W
;
3505 second_dest_chan
= -1;
3508 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3509 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3511 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, first_dest_chan
, second_dest_chan
);
3516 exec_double_trinary(struct tgsi_exec_machine
*mach
,
3517 const struct tgsi_full_instruction
*inst
,
3520 union tgsi_double_channel src
[3];
3521 union tgsi_double_channel dst
;
3523 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
3524 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3525 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3526 fetch_double_channel(mach
, &src
[2], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3528 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3530 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
3531 fetch_double_channel(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3532 fetch_double_channel(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3533 fetch_double_channel(mach
, &src
[2], &inst
->Src
[2], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3535 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3540 exec_f2d(struct tgsi_exec_machine
*mach
,
3541 const struct tgsi_full_instruction
*inst
)
3543 union tgsi_exec_channel src
;
3544 union tgsi_double_channel dst
;
3546 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
3547 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3548 micro_f2d(&dst
, &src
);
3549 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3551 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
3552 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3553 micro_f2d(&dst
, &src
);
3554 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3559 exec_d2f(struct tgsi_exec_machine
*mach
,
3560 const struct tgsi_full_instruction
*inst
)
3562 union tgsi_double_channel src
;
3563 union tgsi_exec_channel dst
;
3564 int wm
= inst
->Dst
[0].Register
.WriteMask
;
3567 for (i
= 0; i
< 2; i
++) {
3570 wm
&= ~(1 << (bit
- 1));
3572 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3574 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3575 micro_d2f(&dst
, &src
);
3576 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, bit
- 1, TGSI_EXEC_DATA_FLOAT
);
3582 exec_i2d(struct tgsi_exec_machine
*mach
,
3583 const struct tgsi_full_instruction
*inst
)
3585 union tgsi_exec_channel src
;
3586 union tgsi_double_channel dst
;
3588 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
3589 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
3590 micro_i2d(&dst
, &src
);
3591 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3593 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
3594 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_INT
);
3595 micro_i2d(&dst
, &src
);
3596 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3601 exec_d2i(struct tgsi_exec_machine
*mach
,
3602 const struct tgsi_full_instruction
*inst
)
3604 union tgsi_double_channel src
;
3605 union tgsi_exec_channel dst
;
3606 int wm
= inst
->Dst
[0].Register
.WriteMask
;
3609 for (i
= 0; i
< 2; i
++) {
3612 wm
&= ~(1 << (bit
- 1));
3614 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3616 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3617 micro_d2i(&dst
, &src
);
3618 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, bit
- 1, TGSI_EXEC_DATA_INT
);
3623 exec_u2d(struct tgsi_exec_machine
*mach
,
3624 const struct tgsi_full_instruction
*inst
)
3626 union tgsi_exec_channel src
;
3627 union tgsi_double_channel dst
;
3629 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
) {
3630 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3631 micro_u2d(&dst
, &src
);
3632 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3634 if ((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
) {
3635 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_UINT
);
3636 micro_u2d(&dst
, &src
);
3637 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3642 exec_d2u(struct tgsi_exec_machine
*mach
,
3643 const struct tgsi_full_instruction
*inst
)
3645 union tgsi_double_channel src
;
3646 union tgsi_exec_channel dst
;
3647 int wm
= inst
->Dst
[0].Register
.WriteMask
;
3650 for (i
= 0; i
< 2; i
++) {
3653 wm
&= ~(1 << (bit
- 1));
3655 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3657 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3658 micro_d2u(&dst
, &src
);
3659 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, bit
- 1, TGSI_EXEC_DATA_UINT
);
3665 exec_dldexp(struct tgsi_exec_machine
*mach
,
3666 const struct tgsi_full_instruction
*inst
)
3668 union tgsi_double_channel src0
;
3669 union tgsi_exec_channel src1
;
3670 union tgsi_double_channel dst
;
3673 wmask
= inst
->Dst
[0].Register
.WriteMask
;
3674 if (wmask
& TGSI_WRITEMASK_XY
) {
3675 fetch_double_channel(mach
, &src0
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3676 fetch_source(mach
, &src1
, &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
3677 micro_dldexp(&dst
, &src0
, &src1
);
3678 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3681 if (wmask
& TGSI_WRITEMASK_ZW
) {
3682 fetch_double_channel(mach
, &src0
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3683 fetch_source(mach
, &src1
, &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_INT
);
3684 micro_dldexp(&dst
, &src0
, &src1
);
3685 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3690 exec_dfracexp(struct tgsi_exec_machine
*mach
,
3691 const struct tgsi_full_instruction
*inst
)
3693 union tgsi_double_channel src
;
3694 union tgsi_double_channel dst
;
3695 union tgsi_exec_channel dst_exp
;
3697 if (((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) == TGSI_WRITEMASK_XY
)) {
3698 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_CHAN_Y
);
3699 micro_dfracexp(&dst
, &dst_exp
, &src
);
3700 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_CHAN_Y
);
3701 store_dest(mach
, &dst_exp
, &inst
->Dst
[1], inst
, ffs(inst
->Dst
[1].Register
.WriteMask
) - 1, TGSI_EXEC_DATA_INT
);
3703 if (((inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_ZW
) == TGSI_WRITEMASK_ZW
)) {
3704 fetch_double_channel(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_CHAN_W
);
3705 micro_dfracexp(&dst
, &dst_exp
, &src
);
3706 store_double_channel(mach
, &dst
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_CHAN_W
);
3707 store_dest(mach
, &dst_exp
, &inst
->Dst
[1], inst
, ffs(inst
->Dst
[1].Register
.WriteMask
) - 1, TGSI_EXEC_DATA_INT
);
3712 get_image_coord_dim(unsigned tgsi_tex
)
3716 case TGSI_TEXTURE_BUFFER
:
3717 case TGSI_TEXTURE_1D
:
3720 case TGSI_TEXTURE_2D
:
3721 case TGSI_TEXTURE_RECT
:
3722 case TGSI_TEXTURE_1D_ARRAY
:
3723 case TGSI_TEXTURE_2D_MSAA
:
3726 case TGSI_TEXTURE_3D
:
3727 case TGSI_TEXTURE_CUBE
:
3728 case TGSI_TEXTURE_2D_ARRAY
:
3729 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
3730 case TGSI_TEXTURE_CUBE_ARRAY
:
3734 assert(!"unknown texture target");
3743 get_image_coord_sample(unsigned tgsi_tex
)
3747 case TGSI_TEXTURE_2D_MSAA
:
3750 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
3760 exec_load(struct tgsi_exec_machine
*mach
,
3761 const struct tgsi_full_instruction
*inst
)
3763 union tgsi_exec_channel r
[4], sample_r
;
3769 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3770 struct tgsi_image_params params
;
3771 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3773 unit
= fetch_sampler_unit(mach
, inst
, 0);
3774 dim
= get_image_coord_dim(inst
->Memory
.Texture
);
3775 sample
= get_image_coord_sample(inst
->Memory
.Texture
);
3778 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3780 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
3781 params
.format
= inst
->Memory
.Format
;
3783 for (i
= 0; i
< dim
; i
++) {
3784 IFETCH(&r
[i
], 1, TGSI_CHAN_X
+ i
);
3788 IFETCH(&sample_r
, 1, TGSI_CHAN_X
+ sample
);
3790 mach
->Image
->load(mach
->Image
, ¶ms
,
3791 r
[0].i
, r
[1].i
, r
[2].i
, sample_r
.i
,
3793 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3794 r
[0].f
[j
] = rgba
[0][j
];
3795 r
[1].f
[j
] = rgba
[1][j
];
3796 r
[2].f
[j
] = rgba
[2][j
];
3797 r
[3].f
[j
] = rgba
[3][j
];
3799 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3800 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3801 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3807 exec_store(struct tgsi_exec_machine
*mach
,
3808 const struct tgsi_full_instruction
*inst
)
3810 union tgsi_exec_channel r
[3], sample_r
;
3811 union tgsi_exec_channel value
[4];
3812 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3813 struct tgsi_image_params params
;
3818 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3819 unit
= inst
->Dst
[0].Register
.Index
;
3820 dim
= get_image_coord_dim(inst
->Memory
.Texture
);
3821 sample
= get_image_coord_sample(inst
->Memory
.Texture
);
3824 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3826 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
3827 params
.format
= inst
->Memory
.Format
;
3829 for (i
= 0; i
< dim
; i
++) {
3830 IFETCH(&r
[i
], 0, TGSI_CHAN_X
+ i
);
3833 for (i
= 0; i
< 4; i
++) {
3834 FETCH(&value
[i
], 1, TGSI_CHAN_X
+ i
);
3837 IFETCH(&sample_r
, 0, TGSI_CHAN_X
+ sample
);
3839 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3840 rgba
[0][j
] = value
[0].f
[j
];
3841 rgba
[1][j
] = value
[1].f
[j
];
3842 rgba
[2][j
] = value
[2].f
[j
];
3843 rgba
[3][j
] = value
[3].f
[j
];
3846 mach
->Image
->store(mach
->Image
, ¶ms
,
3847 r
[0].i
, r
[1].i
, r
[2].i
, sample_r
.i
,
3852 exec_atomop(struct tgsi_exec_machine
*mach
,
3853 const struct tgsi_full_instruction
*inst
)
3855 union tgsi_exec_channel r
[3], sample_r
;
3856 union tgsi_exec_channel value
[4], value2
[4];
3857 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3858 float rgba2
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
3859 struct tgsi_image_params params
;
3864 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3865 unit
= fetch_sampler_unit(mach
, inst
, 0);
3866 dim
= get_image_coord_dim(inst
->Memory
.Texture
);
3867 sample
= get_image_coord_sample(inst
->Memory
.Texture
);
3870 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3872 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
3873 params
.format
= inst
->Memory
.Format
;
3875 for (i
= 0; i
< dim
; i
++) {
3876 IFETCH(&r
[i
], 1, TGSI_CHAN_X
+ i
);
3879 for (i
= 0; i
< 4; i
++) {
3880 FETCH(&value
[i
], 2, TGSI_CHAN_X
+ i
);
3881 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_ATOMCAS
)
3882 FETCH(&value2
[i
], 3, TGSI_CHAN_X
+ i
);
3885 IFETCH(&sample_r
, 1, TGSI_CHAN_X
+ sample
);
3887 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3888 rgba
[0][j
] = value
[0].f
[j
];
3889 rgba
[1][j
] = value
[1].f
[j
];
3890 rgba
[2][j
] = value
[2].f
[j
];
3891 rgba
[3][j
] = value
[3].f
[j
];
3893 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_ATOMCAS
) {
3894 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3895 rgba2
[0][j
] = value2
[0].f
[j
];
3896 rgba2
[1][j
] = value2
[1].f
[j
];
3897 rgba2
[2][j
] = value2
[2].f
[j
];
3898 rgba2
[3][j
] = value2
[3].f
[j
];
3902 mach
->Image
->op(mach
->Image
, ¶ms
, inst
->Instruction
.Opcode
,
3903 r
[0].i
, r
[1].i
, r
[2].i
, sample_r
.i
,
3906 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
3907 r
[0].f
[j
] = rgba
[0][j
];
3908 r
[1].f
[j
] = rgba
[1][j
];
3909 r
[2].f
[j
] = rgba
[2][j
];
3910 r
[3].f
[j
] = rgba
[3][j
];
3912 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3913 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3914 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
3920 exec_resq(struct tgsi_exec_machine
*mach
,
3921 const struct tgsi_full_instruction
*inst
)
3924 union tgsi_exec_channel r
[4];
3927 struct tgsi_image_params params
;
3928 int kilmask
= mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];
3930 unit
= fetch_sampler_unit(mach
, inst
, 0);
3932 params
.execmask
= mach
->ExecMask
& mach
->NonHelperMask
& ~kilmask
;
3934 params
.tgsi_tex_instr
= inst
->Memory
.Texture
;
3935 params
.format
= inst
->Memory
.Format
;
3937 mach
->Image
->get_dims(mach
->Image
, ¶ms
, result
);
3939 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
3940 for (j
= 0; j
< 4; j
++) {
3941 r
[j
].i
[i
] = result
[j
];
3945 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
3946 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
3947 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
3948 TGSI_EXEC_DATA_INT
);
3954 micro_i2f(union tgsi_exec_channel
*dst
,
3955 const union tgsi_exec_channel
*src
)
3957 dst
->f
[0] = (float)src
->i
[0];
3958 dst
->f
[1] = (float)src
->i
[1];
3959 dst
->f
[2] = (float)src
->i
[2];
3960 dst
->f
[3] = (float)src
->i
[3];
3964 micro_not(union tgsi_exec_channel
*dst
,
3965 const union tgsi_exec_channel
*src
)
3967 dst
->u
[0] = ~src
->u
[0];
3968 dst
->u
[1] = ~src
->u
[1];
3969 dst
->u
[2] = ~src
->u
[2];
3970 dst
->u
[3] = ~src
->u
[3];
3974 micro_shl(union tgsi_exec_channel
*dst
,
3975 const union tgsi_exec_channel
*src0
,
3976 const union tgsi_exec_channel
*src1
)
3978 unsigned masked_count
;
3979 masked_count
= src1
->u
[0] & 0x1f;
3980 dst
->u
[0] = src0
->u
[0] << masked_count
;
3981 masked_count
= src1
->u
[1] & 0x1f;
3982 dst
->u
[1] = src0
->u
[1] << masked_count
;
3983 masked_count
= src1
->u
[2] & 0x1f;
3984 dst
->u
[2] = src0
->u
[2] << masked_count
;
3985 masked_count
= src1
->u
[3] & 0x1f;
3986 dst
->u
[3] = src0
->u
[3] << masked_count
;
3990 micro_and(union tgsi_exec_channel
*dst
,
3991 const union tgsi_exec_channel
*src0
,
3992 const union tgsi_exec_channel
*src1
)
3994 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
3995 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
3996 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
3997 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
4001 micro_or(union tgsi_exec_channel
*dst
,
4002 const union tgsi_exec_channel
*src0
,
4003 const union tgsi_exec_channel
*src1
)
4005 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
4006 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
4007 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
4008 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
4012 micro_xor(union tgsi_exec_channel
*dst
,
4013 const union tgsi_exec_channel
*src0
,
4014 const union tgsi_exec_channel
*src1
)
4016 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
4017 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
4018 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
4019 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
4023 micro_mod(union tgsi_exec_channel
*dst
,
4024 const union tgsi_exec_channel
*src0
,
4025 const union tgsi_exec_channel
*src1
)
4027 dst
->i
[0] = src0
->i
[0] % src1
->i
[0];
4028 dst
->i
[1] = src0
->i
[1] % src1
->i
[1];
4029 dst
->i
[2] = src0
->i
[2] % src1
->i
[2];
4030 dst
->i
[3] = src0
->i
[3] % src1
->i
[3];
4034 micro_f2i(union tgsi_exec_channel
*dst
,
4035 const union tgsi_exec_channel
*src
)
4037 dst
->i
[0] = (int)src
->f
[0];
4038 dst
->i
[1] = (int)src
->f
[1];
4039 dst
->i
[2] = (int)src
->f
[2];
4040 dst
->i
[3] = (int)src
->f
[3];
4044 micro_fseq(union tgsi_exec_channel
*dst
,
4045 const union tgsi_exec_channel
*src0
,
4046 const union tgsi_exec_channel
*src1
)
4048 dst
->u
[0] = src0
->f
[0] == src1
->f
[0] ? ~0 : 0;
4049 dst
->u
[1] = src0
->f
[1] == src1
->f
[1] ? ~0 : 0;
4050 dst
->u
[2] = src0
->f
[2] == src1
->f
[2] ? ~0 : 0;
4051 dst
->u
[3] = src0
->f
[3] == src1
->f
[3] ? ~0 : 0;
4055 micro_fsge(union tgsi_exec_channel
*dst
,
4056 const union tgsi_exec_channel
*src0
,
4057 const union tgsi_exec_channel
*src1
)
4059 dst
->u
[0] = src0
->f
[0] >= src1
->f
[0] ? ~0 : 0;
4060 dst
->u
[1] = src0
->f
[1] >= src1
->f
[1] ? ~0 : 0;
4061 dst
->u
[2] = src0
->f
[2] >= src1
->f
[2] ? ~0 : 0;
4062 dst
->u
[3] = src0
->f
[3] >= src1
->f
[3] ? ~0 : 0;
4066 micro_fslt(union tgsi_exec_channel
*dst
,
4067 const union tgsi_exec_channel
*src0
,
4068 const union tgsi_exec_channel
*src1
)
4070 dst
->u
[0] = src0
->f
[0] < src1
->f
[0] ? ~0 : 0;
4071 dst
->u
[1] = src0
->f
[1] < src1
->f
[1] ? ~0 : 0;
4072 dst
->u
[2] = src0
->f
[2] < src1
->f
[2] ? ~0 : 0;
4073 dst
->u
[3] = src0
->f
[3] < src1
->f
[3] ? ~0 : 0;
4077 micro_fsne(union tgsi_exec_channel
*dst
,
4078 const union tgsi_exec_channel
*src0
,
4079 const union tgsi_exec_channel
*src1
)
4081 dst
->u
[0] = src0
->f
[0] != src1
->f
[0] ? ~0 : 0;
4082 dst
->u
[1] = src0
->f
[1] != src1
->f
[1] ? ~0 : 0;
4083 dst
->u
[2] = src0
->f
[2] != src1
->f
[2] ? ~0 : 0;
4084 dst
->u
[3] = src0
->f
[3] != src1
->f
[3] ? ~0 : 0;
4088 micro_idiv(union tgsi_exec_channel
*dst
,
4089 const union tgsi_exec_channel
*src0
,
4090 const union tgsi_exec_channel
*src1
)
4092 dst
->i
[0] = src1
->i
[0] ? src0
->i
[0] / src1
->i
[0] : 0;
4093 dst
->i
[1] = src1
->i
[1] ? src0
->i
[1] / src1
->i
[1] : 0;
4094 dst
->i
[2] = src1
->i
[2] ? src0
->i
[2] / src1
->i
[2] : 0;
4095 dst
->i
[3] = src1
->i
[3] ? src0
->i
[3] / src1
->i
[3] : 0;
4099 micro_imax(union tgsi_exec_channel
*dst
,
4100 const union tgsi_exec_channel
*src0
,
4101 const union tgsi_exec_channel
*src1
)
4103 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
4104 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
4105 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
4106 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
4110 micro_imin(union tgsi_exec_channel
*dst
,
4111 const union tgsi_exec_channel
*src0
,
4112 const union tgsi_exec_channel
*src1
)
4114 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
4115 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
4116 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
4117 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
4121 micro_isge(union tgsi_exec_channel
*dst
,
4122 const union tgsi_exec_channel
*src0
,
4123 const union tgsi_exec_channel
*src1
)
4125 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
4126 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
4127 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
4128 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
4132 micro_ishr(union tgsi_exec_channel
*dst
,
4133 const union tgsi_exec_channel
*src0
,
4134 const union tgsi_exec_channel
*src1
)
4136 unsigned masked_count
;
4137 masked_count
= src1
->i
[0] & 0x1f;
4138 dst
->i
[0] = src0
->i
[0] >> masked_count
;
4139 masked_count
= src1
->i
[1] & 0x1f;
4140 dst
->i
[1] = src0
->i
[1] >> masked_count
;
4141 masked_count
= src1
->i
[2] & 0x1f;
4142 dst
->i
[2] = src0
->i
[2] >> masked_count
;
4143 masked_count
= src1
->i
[3] & 0x1f;
4144 dst
->i
[3] = src0
->i
[3] >> masked_count
;
4148 micro_islt(union tgsi_exec_channel
*dst
,
4149 const union tgsi_exec_channel
*src0
,
4150 const union tgsi_exec_channel
*src1
)
4152 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
4153 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
4154 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
4155 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
4159 micro_f2u(union tgsi_exec_channel
*dst
,
4160 const union tgsi_exec_channel
*src
)
4162 dst
->u
[0] = (uint
)src
->f
[0];
4163 dst
->u
[1] = (uint
)src
->f
[1];
4164 dst
->u
[2] = (uint
)src
->f
[2];
4165 dst
->u
[3] = (uint
)src
->f
[3];
4169 micro_u2f(union tgsi_exec_channel
*dst
,
4170 const union tgsi_exec_channel
*src
)
4172 dst
->f
[0] = (float)src
->u
[0];
4173 dst
->f
[1] = (float)src
->u
[1];
4174 dst
->f
[2] = (float)src
->u
[2];
4175 dst
->f
[3] = (float)src
->u
[3];
4179 micro_uadd(union tgsi_exec_channel
*dst
,
4180 const union tgsi_exec_channel
*src0
,
4181 const union tgsi_exec_channel
*src1
)
4183 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
4184 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
4185 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
4186 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
4190 micro_udiv(union tgsi_exec_channel
*dst
,
4191 const union tgsi_exec_channel
*src0
,
4192 const union tgsi_exec_channel
*src1
)
4194 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] / src1
->u
[0] : ~0u;
4195 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] / src1
->u
[1] : ~0u;
4196 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] / src1
->u
[2] : ~0u;
4197 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] / src1
->u
[3] : ~0u;
4201 micro_umad(union tgsi_exec_channel
*dst
,
4202 const union tgsi_exec_channel
*src0
,
4203 const union tgsi_exec_channel
*src1
,
4204 const union tgsi_exec_channel
*src2
)
4206 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
4207 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
4208 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
4209 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
4213 micro_umax(union tgsi_exec_channel
*dst
,
4214 const union tgsi_exec_channel
*src0
,
4215 const union tgsi_exec_channel
*src1
)
4217 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
4218 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
4219 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
4220 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
4224 micro_umin(union tgsi_exec_channel
*dst
,
4225 const union tgsi_exec_channel
*src0
,
4226 const union tgsi_exec_channel
*src1
)
4228 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
4229 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
4230 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
4231 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
4235 micro_umod(union tgsi_exec_channel
*dst
,
4236 const union tgsi_exec_channel
*src0
,
4237 const union tgsi_exec_channel
*src1
)
4239 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] % src1
->u
[0] : ~0u;
4240 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] % src1
->u
[1] : ~0u;
4241 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] % src1
->u
[2] : ~0u;
4242 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] % src1
->u
[3] : ~0u;
4246 micro_umul(union tgsi_exec_channel
*dst
,
4247 const union tgsi_exec_channel
*src0
,
4248 const union tgsi_exec_channel
*src1
)
4250 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
4251 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
4252 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
4253 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
4257 micro_imul_hi(union tgsi_exec_channel
*dst
,
4258 const union tgsi_exec_channel
*src0
,
4259 const union tgsi_exec_channel
*src1
)
4261 #define I64M(x, y) ((((int64_t)x) * ((int64_t)y)) >> 32)
4262 dst
->i
[0] = I64M(src0
->i
[0], src1
->i
[0]);
4263 dst
->i
[1] = I64M(src0
->i
[1], src1
->i
[1]);
4264 dst
->i
[2] = I64M(src0
->i
[2], src1
->i
[2]);
4265 dst
->i
[3] = I64M(src0
->i
[3], src1
->i
[3]);
4270 micro_umul_hi(union tgsi_exec_channel
*dst
,
4271 const union tgsi_exec_channel
*src0
,
4272 const union tgsi_exec_channel
*src1
)
4274 #define U64M(x, y) ((((uint64_t)x) * ((uint64_t)y)) >> 32)
4275 dst
->u
[0] = U64M(src0
->u
[0], src1
->u
[0]);
4276 dst
->u
[1] = U64M(src0
->u
[1], src1
->u
[1]);
4277 dst
->u
[2] = U64M(src0
->u
[2], src1
->u
[2]);
4278 dst
->u
[3] = U64M(src0
->u
[3], src1
->u
[3]);
4283 micro_useq(union tgsi_exec_channel
*dst
,
4284 const union tgsi_exec_channel
*src0
,
4285 const union tgsi_exec_channel
*src1
)
4287 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
4288 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
4289 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
4290 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
4294 micro_usge(union tgsi_exec_channel
*dst
,
4295 const union tgsi_exec_channel
*src0
,
4296 const union tgsi_exec_channel
*src1
)
4298 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
4299 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
4300 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
4301 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
4305 micro_ushr(union tgsi_exec_channel
*dst
,
4306 const union tgsi_exec_channel
*src0
,
4307 const union tgsi_exec_channel
*src1
)
4309 unsigned masked_count
;
4310 masked_count
= src1
->u
[0] & 0x1f;
4311 dst
->u
[0] = src0
->u
[0] >> masked_count
;
4312 masked_count
= src1
->u
[1] & 0x1f;
4313 dst
->u
[1] = src0
->u
[1] >> masked_count
;
4314 masked_count
= src1
->u
[2] & 0x1f;
4315 dst
->u
[2] = src0
->u
[2] >> masked_count
;
4316 masked_count
= src1
->u
[3] & 0x1f;
4317 dst
->u
[3] = src0
->u
[3] >> masked_count
;
4321 micro_uslt(union tgsi_exec_channel
*dst
,
4322 const union tgsi_exec_channel
*src0
,
4323 const union tgsi_exec_channel
*src1
)
4325 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
4326 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
4327 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
4328 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
4332 micro_usne(union tgsi_exec_channel
*dst
,
4333 const union tgsi_exec_channel
*src0
,
4334 const union tgsi_exec_channel
*src1
)
4336 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
4337 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
4338 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
4339 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
4343 micro_uarl(union tgsi_exec_channel
*dst
,
4344 const union tgsi_exec_channel
*src
)
4346 dst
->i
[0] = src
->u
[0];
4347 dst
->i
[1] = src
->u
[1];
4348 dst
->i
[2] = src
->u
[2];
4349 dst
->i
[3] = src
->u
[3];
4353 micro_ucmp(union tgsi_exec_channel
*dst
,
4354 const union tgsi_exec_channel
*src0
,
4355 const union tgsi_exec_channel
*src1
,
4356 const union tgsi_exec_channel
*src2
)
4358 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
4359 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
4360 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
4361 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
4365 * Signed bitfield extract (i.e. sign-extend the extracted bits)
4368 micro_ibfe(union tgsi_exec_channel
*dst
,
4369 const union tgsi_exec_channel
*src0
,
4370 const union tgsi_exec_channel
*src1
,
4371 const union tgsi_exec_channel
*src2
)
4374 for (i
= 0; i
< 4; i
++) {
4375 int width
= src2
->i
[i
] & 0x1f;
4376 int offset
= src1
->i
[i
] & 0x1f;
4379 else if (width
+ offset
< 32)
4380 dst
->i
[i
] = (src0
->i
[i
] << (32 - width
- offset
)) >> (32 - width
);
4382 dst
->i
[i
] = src0
->i
[i
] >> offset
;
4387 * Unsigned bitfield extract
4390 micro_ubfe(union tgsi_exec_channel
*dst
,
4391 const union tgsi_exec_channel
*src0
,
4392 const union tgsi_exec_channel
*src1
,
4393 const union tgsi_exec_channel
*src2
)
4396 for (i
= 0; i
< 4; i
++) {
4397 int width
= src2
->u
[i
] & 0x1f;
4398 int offset
= src1
->u
[i
] & 0x1f;
4401 else if (width
+ offset
< 32)
4402 dst
->u
[i
] = (src0
->u
[i
] << (32 - width
- offset
)) >> (32 - width
);
4404 dst
->u
[i
] = src0
->u
[i
] >> offset
;
4409 * Bitfield insert: copy low bits from src1 into a region of src0.
4412 micro_bfi(union tgsi_exec_channel
*dst
,
4413 const union tgsi_exec_channel
*src0
,
4414 const union tgsi_exec_channel
*src1
,
4415 const union tgsi_exec_channel
*src2
,
4416 const union tgsi_exec_channel
*src3
)
4419 for (i
= 0; i
< 4; i
++) {
4420 int width
= src3
->u
[i
] & 0x1f;
4421 int offset
= src2
->u
[i
] & 0x1f;
4422 int bitmask
= ((1 << width
) - 1) << offset
;
4423 dst
->u
[i
] = ((src1
->u
[i
] << offset
) & bitmask
) | (src0
->u
[i
] & ~bitmask
);
4428 micro_brev(union tgsi_exec_channel
*dst
,
4429 const union tgsi_exec_channel
*src
)
4431 dst
->u
[0] = util_bitreverse(src
->u
[0]);
4432 dst
->u
[1] = util_bitreverse(src
->u
[1]);
4433 dst
->u
[2] = util_bitreverse(src
->u
[2]);
4434 dst
->u
[3] = util_bitreverse(src
->u
[3]);
4438 micro_popc(union tgsi_exec_channel
*dst
,
4439 const union tgsi_exec_channel
*src
)
4441 dst
->u
[0] = util_bitcount(src
->u
[0]);
4442 dst
->u
[1] = util_bitcount(src
->u
[1]);
4443 dst
->u
[2] = util_bitcount(src
->u
[2]);
4444 dst
->u
[3] = util_bitcount(src
->u
[3]);
4448 micro_lsb(union tgsi_exec_channel
*dst
,
4449 const union tgsi_exec_channel
*src
)
4451 dst
->i
[0] = ffs(src
->u
[0]) - 1;
4452 dst
->i
[1] = ffs(src
->u
[1]) - 1;
4453 dst
->i
[2] = ffs(src
->u
[2]) - 1;
4454 dst
->i
[3] = ffs(src
->u
[3]) - 1;
4458 micro_imsb(union tgsi_exec_channel
*dst
,
4459 const union tgsi_exec_channel
*src
)
4461 dst
->i
[0] = util_last_bit_signed(src
->i
[0]) - 1;
4462 dst
->i
[1] = util_last_bit_signed(src
->i
[1]) - 1;
4463 dst
->i
[2] = util_last_bit_signed(src
->i
[2]) - 1;
4464 dst
->i
[3] = util_last_bit_signed(src
->i
[3]) - 1;
4468 micro_umsb(union tgsi_exec_channel
*dst
,
4469 const union tgsi_exec_channel
*src
)
4471 dst
->i
[0] = util_last_bit(src
->u
[0]) - 1;
4472 dst
->i
[1] = util_last_bit(src
->u
[1]) - 1;
4473 dst
->i
[2] = util_last_bit(src
->u
[2]) - 1;
4474 dst
->i
[3] = util_last_bit(src
->u
[3]) - 1;
4479 struct tgsi_exec_machine
*mach
,
4480 const struct tgsi_full_instruction
*inst
,
4483 union tgsi_exec_channel r
[10];
4487 switch (inst
->Instruction
.Opcode
) {
4488 case TGSI_OPCODE_ARL
:
4489 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
4492 case TGSI_OPCODE_MOV
:
4493 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4496 case TGSI_OPCODE_LIT
:
4497 exec_lit(mach
, inst
);
4500 case TGSI_OPCODE_RCP
:
4501 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4504 case TGSI_OPCODE_RSQ
:
4505 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4508 case TGSI_OPCODE_EXP
:
4509 exec_exp(mach
, inst
);
4512 case TGSI_OPCODE_LOG
:
4513 exec_log(mach
, inst
);
4516 case TGSI_OPCODE_MUL
:
4517 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4520 case TGSI_OPCODE_ADD
:
4521 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4524 case TGSI_OPCODE_DP3
:
4525 exec_dp3(mach
, inst
);
4528 case TGSI_OPCODE_DP4
:
4529 exec_dp4(mach
, inst
);
4532 case TGSI_OPCODE_DST
:
4533 exec_dst(mach
, inst
);
4536 case TGSI_OPCODE_MIN
:
4537 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4540 case TGSI_OPCODE_MAX
:
4541 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4544 case TGSI_OPCODE_SLT
:
4545 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4548 case TGSI_OPCODE_SGE
:
4549 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4552 case TGSI_OPCODE_MAD
:
4553 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4556 case TGSI_OPCODE_SUB
:
4557 exec_vector_binary(mach
, inst
, micro_sub
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4560 case TGSI_OPCODE_LRP
:
4561 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4564 case TGSI_OPCODE_SQRT
:
4565 exec_scalar_unary(mach
, inst
, micro_sqrt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4568 case TGSI_OPCODE_DP2A
:
4569 exec_dp2a(mach
, inst
);
4572 case TGSI_OPCODE_FRC
:
4573 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4576 case TGSI_OPCODE_CLAMP
:
4577 exec_vector_trinary(mach
, inst
, micro_clamp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4580 case TGSI_OPCODE_FLR
:
4581 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4584 case TGSI_OPCODE_ROUND
:
4585 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4588 case TGSI_OPCODE_EX2
:
4589 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4592 case TGSI_OPCODE_LG2
:
4593 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4596 case TGSI_OPCODE_POW
:
4597 exec_scalar_binary(mach
, inst
, micro_pow
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4600 case TGSI_OPCODE_XPD
:
4601 exec_xpd(mach
, inst
);
4604 case TGSI_OPCODE_ABS
:
4605 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4608 case TGSI_OPCODE_DPH
:
4609 exec_dph(mach
, inst
);
4612 case TGSI_OPCODE_COS
:
4613 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4616 case TGSI_OPCODE_DDX
:
4617 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4620 case TGSI_OPCODE_DDY
:
4621 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4624 case TGSI_OPCODE_KILL
:
4625 exec_kill (mach
, inst
);
4628 case TGSI_OPCODE_KILL_IF
:
4629 exec_kill_if (mach
, inst
);
4632 case TGSI_OPCODE_PK2H
:
4633 exec_pk2h(mach
, inst
);
4636 case TGSI_OPCODE_PK2US
:
4640 case TGSI_OPCODE_PK4B
:
4644 case TGSI_OPCODE_PK4UB
:
4648 case TGSI_OPCODE_SEQ
:
4649 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4652 case TGSI_OPCODE_SGT
:
4653 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4656 case TGSI_OPCODE_SIN
:
4657 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4660 case TGSI_OPCODE_SLE
:
4661 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4664 case TGSI_OPCODE_SNE
:
4665 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4668 case TGSI_OPCODE_TEX
:
4669 /* simple texture lookup */
4670 /* src[0] = texcoord */
4671 /* src[1] = sampler unit */
4672 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 1);
4675 case TGSI_OPCODE_TXB
:
4676 /* Texture lookup with lod bias */
4677 /* src[0] = texcoord (src[0].w = LOD bias) */
4678 /* src[1] = sampler unit */
4679 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 1);
4682 case TGSI_OPCODE_TXD
:
4683 /* Texture lookup with explict partial derivatives */
4684 /* src[0] = texcoord */
4685 /* src[1] = d[strq]/dx */
4686 /* src[2] = d[strq]/dy */
4687 /* src[3] = sampler unit */
4688 exec_txd(mach
, inst
);
4691 case TGSI_OPCODE_TXL
:
4692 /* Texture lookup with explit LOD */
4693 /* src[0] = texcoord (src[0].w = LOD) */
4694 /* src[1] = sampler unit */
4695 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 1);
4698 case TGSI_OPCODE_TXP
:
4699 /* Texture lookup with projection */
4700 /* src[0] = texcoord (src[0].w = projection) */
4701 /* src[1] = sampler unit */
4702 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
, 1);
4705 case TGSI_OPCODE_TG4
:
4706 /* src[0] = texcoord */
4707 /* src[1] = component */
4708 /* src[2] = sampler unit */
4709 exec_tex(mach
, inst
, TEX_MODIFIER_GATHER
, 2);
4712 case TGSI_OPCODE_LODQ
:
4713 /* src[0] = texcoord */
4714 /* src[1] = sampler unit */
4715 exec_lodq(mach
, inst
);
4718 case TGSI_OPCODE_UP2H
:
4719 exec_up2h(mach
, inst
);
4722 case TGSI_OPCODE_UP2US
:
4726 case TGSI_OPCODE_UP4B
:
4730 case TGSI_OPCODE_UP4UB
:
4734 case TGSI_OPCODE_ARR
:
4735 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
4738 case TGSI_OPCODE_CAL
:
4739 /* skip the call if no execution channels are enabled */
4740 if (mach
->ExecMask
) {
4743 /* First, record the depths of the execution stacks.
4744 * This is important for deeply nested/looped return statements.
4745 * We have to unwind the stacks by the correct amount. For a
4746 * real code generator, we could determine the number of entries
4747 * to pop off each stack with simple static analysis and avoid
4748 * implementing this data structure at run time.
4750 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
4751 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
4752 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
4753 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
4754 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
4755 /* note that PC was already incremented above */
4756 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
4758 mach
->CallStackTop
++;
4760 /* Second, push the Cond, Loop, Cont, Func stacks */
4761 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
4762 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4763 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4764 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
4765 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
4766 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
4768 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
4769 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
4770 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
4771 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
4772 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
4773 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
4775 /* Finally, jump to the subroutine. The label is a pointer
4776 * (an instruction number) to the BGNSUB instruction.
4778 *pc
= inst
->Label
.Label
;
4779 assert(mach
->Instructions
[*pc
].Instruction
.Opcode
4780 == TGSI_OPCODE_BGNSUB
);
4784 case TGSI_OPCODE_RET
:
4785 mach
->FuncMask
&= ~mach
->ExecMask
;
4786 UPDATE_EXEC_MASK(mach
);
4788 if (mach
->FuncMask
== 0x0) {
4789 /* really return now (otherwise, keep executing */
4791 if (mach
->CallStackTop
== 0) {
4792 /* returning from main() */
4793 mach
->CondStackTop
= 0;
4794 mach
->LoopStackTop
= 0;
4799 assert(mach
->CallStackTop
> 0);
4800 mach
->CallStackTop
--;
4802 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
4803 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
4805 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
4806 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
4808 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
4809 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
4811 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
4812 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
4814 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
4815 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
4817 assert(mach
->FuncStackTop
> 0);
4818 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
4820 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
4822 UPDATE_EXEC_MASK(mach
);
4826 case TGSI_OPCODE_SSG
:
4827 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4830 case TGSI_OPCODE_CMP
:
4831 exec_vector_trinary(mach
, inst
, micro_cmp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4834 case TGSI_OPCODE_SCS
:
4835 exec_scs(mach
, inst
);
4838 case TGSI_OPCODE_DIV
:
4839 exec_vector_binary(mach
, inst
, micro_div
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4842 case TGSI_OPCODE_DP2
:
4843 exec_dp2(mach
, inst
);
4846 case TGSI_OPCODE_IF
:
4848 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
4849 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
4850 FETCH( &r
[0], 0, TGSI_CHAN_X
);
4851 /* update CondMask */
4853 mach
->CondMask
&= ~0x1;
4856 mach
->CondMask
&= ~0x2;
4859 mach
->CondMask
&= ~0x4;
4862 mach
->CondMask
&= ~0x8;
4864 UPDATE_EXEC_MASK(mach
);
4865 /* Todo: If CondMask==0, jump to ELSE */
4868 case TGSI_OPCODE_UIF
:
4870 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
4871 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
4872 IFETCH( &r
[0], 0, TGSI_CHAN_X
);
4873 /* update CondMask */
4875 mach
->CondMask
&= ~0x1;
4878 mach
->CondMask
&= ~0x2;
4881 mach
->CondMask
&= ~0x4;
4884 mach
->CondMask
&= ~0x8;
4886 UPDATE_EXEC_MASK(mach
);
4887 /* Todo: If CondMask==0, jump to ELSE */
4890 case TGSI_OPCODE_ELSE
:
4891 /* invert CondMask wrt previous mask */
4894 assert(mach
->CondStackTop
> 0);
4895 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
4896 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
4897 UPDATE_EXEC_MASK(mach
);
4898 /* Todo: If CondMask==0, jump to ENDIF */
4902 case TGSI_OPCODE_ENDIF
:
4904 assert(mach
->CondStackTop
> 0);
4905 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
4906 UPDATE_EXEC_MASK(mach
);
4909 case TGSI_OPCODE_END
:
4910 /* make sure we end primitives which haven't
4911 * been explicitly emitted */
4912 conditional_emit_primitive(mach
);
4913 /* halt execution */
4917 case TGSI_OPCODE_PUSHA
:
4921 case TGSI_OPCODE_POPA
:
4925 case TGSI_OPCODE_CEIL
:
4926 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4929 case TGSI_OPCODE_I2F
:
4930 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
4933 case TGSI_OPCODE_NOT
:
4934 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4937 case TGSI_OPCODE_TRUNC
:
4938 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4941 case TGSI_OPCODE_SHL
:
4942 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4945 case TGSI_OPCODE_AND
:
4946 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4949 case TGSI_OPCODE_OR
:
4950 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4953 case TGSI_OPCODE_MOD
:
4954 exec_vector_binary(mach
, inst
, micro_mod
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4957 case TGSI_OPCODE_XOR
:
4958 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4961 case TGSI_OPCODE_SAD
:
4965 case TGSI_OPCODE_TXF
:
4966 exec_txf(mach
, inst
);
4969 case TGSI_OPCODE_TXQ
:
4970 exec_txq(mach
, inst
);
4973 case TGSI_OPCODE_EMIT
:
4977 case TGSI_OPCODE_ENDPRIM
:
4978 emit_primitive(mach
);
4981 case TGSI_OPCODE_BGNLOOP
:
4982 /* push LoopMask and ContMasks */
4983 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4984 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4985 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4986 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
4988 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
4989 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
4990 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
4991 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
4992 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
4995 case TGSI_OPCODE_ENDLOOP
:
4996 /* Restore ContMask, but don't pop */
4997 assert(mach
->ContStackTop
> 0);
4998 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
4999 UPDATE_EXEC_MASK(mach
);
5000 if (mach
->ExecMask
) {
5001 /* repeat loop: jump to instruction just past BGNLOOP */
5002 assert(mach
->LoopLabelStackTop
> 0);
5003 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
5006 /* exit loop: pop LoopMask */
5007 assert(mach
->LoopStackTop
> 0);
5008 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
5010 assert(mach
->ContStackTop
> 0);
5011 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
5012 assert(mach
->LoopLabelStackTop
> 0);
5013 --mach
->LoopLabelStackTop
;
5015 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
5017 UPDATE_EXEC_MASK(mach
);
5020 case TGSI_OPCODE_BRK
:
5024 case TGSI_OPCODE_CONT
:
5025 /* turn off cont channels for each enabled exec channel */
5026 mach
->ContMask
&= ~mach
->ExecMask
;
5027 /* Todo: if mach->LoopMask == 0, jump to end of loop */
5028 UPDATE_EXEC_MASK(mach
);
5031 case TGSI_OPCODE_BGNSUB
:
5035 case TGSI_OPCODE_ENDSUB
:
5037 * XXX: This really should be a no-op. We should never reach this opcode.
5040 assert(mach
->CallStackTop
> 0);
5041 mach
->CallStackTop
--;
5043 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
5044 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
5046 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
5047 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
5049 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
5050 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
5052 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
5053 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
5055 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
5056 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
5058 assert(mach
->FuncStackTop
> 0);
5059 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
5061 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
5063 UPDATE_EXEC_MASK(mach
);
5066 case TGSI_OPCODE_NOP
:
5069 case TGSI_OPCODE_BREAKC
:
5070 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
5071 /* update CondMask */
5072 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
5073 mach
->LoopMask
&= ~0x1;
5075 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
5076 mach
->LoopMask
&= ~0x2;
5078 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
5079 mach
->LoopMask
&= ~0x4;
5081 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
5082 mach
->LoopMask
&= ~0x8;
5084 /* Todo: if mach->LoopMask == 0, jump to end of loop */
5085 UPDATE_EXEC_MASK(mach
);
5088 case TGSI_OPCODE_F2I
:
5089 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
5092 case TGSI_OPCODE_FSEQ
:
5093 exec_vector_binary(mach
, inst
, micro_fseq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5096 case TGSI_OPCODE_FSGE
:
5097 exec_vector_binary(mach
, inst
, micro_fsge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5100 case TGSI_OPCODE_FSLT
:
5101 exec_vector_binary(mach
, inst
, micro_fslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5104 case TGSI_OPCODE_FSNE
:
5105 exec_vector_binary(mach
, inst
, micro_fsne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5108 case TGSI_OPCODE_IDIV
:
5109 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5112 case TGSI_OPCODE_IMAX
:
5113 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5116 case TGSI_OPCODE_IMIN
:
5117 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5120 case TGSI_OPCODE_INEG
:
5121 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5124 case TGSI_OPCODE_ISGE
:
5125 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5128 case TGSI_OPCODE_ISHR
:
5129 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5132 case TGSI_OPCODE_ISLT
:
5133 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5136 case TGSI_OPCODE_F2U
:
5137 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
5140 case TGSI_OPCODE_U2F
:
5141 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
5144 case TGSI_OPCODE_UADD
:
5145 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5148 case TGSI_OPCODE_UDIV
:
5149 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5152 case TGSI_OPCODE_UMAD
:
5153 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5156 case TGSI_OPCODE_UMAX
:
5157 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5160 case TGSI_OPCODE_UMIN
:
5161 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5164 case TGSI_OPCODE_UMOD
:
5165 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5168 case TGSI_OPCODE_UMUL
:
5169 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5172 case TGSI_OPCODE_IMUL_HI
:
5173 exec_vector_binary(mach
, inst
, micro_imul_hi
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5176 case TGSI_OPCODE_UMUL_HI
:
5177 exec_vector_binary(mach
, inst
, micro_umul_hi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5180 case TGSI_OPCODE_USEQ
:
5181 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5184 case TGSI_OPCODE_USGE
:
5185 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5188 case TGSI_OPCODE_USHR
:
5189 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5192 case TGSI_OPCODE_USLT
:
5193 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5196 case TGSI_OPCODE_USNE
:
5197 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5200 case TGSI_OPCODE_SWITCH
:
5201 exec_switch(mach
, inst
);
5204 case TGSI_OPCODE_CASE
:
5205 exec_case(mach
, inst
);
5208 case TGSI_OPCODE_DEFAULT
:
5212 case TGSI_OPCODE_ENDSWITCH
:
5213 exec_endswitch(mach
);
5216 case TGSI_OPCODE_SAMPLE_I
:
5217 exec_txf(mach
, inst
);
5220 case TGSI_OPCODE_SAMPLE_I_MS
:
5221 exec_txf(mach
, inst
);
5224 case TGSI_OPCODE_SAMPLE
:
5225 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, FALSE
);
5228 case TGSI_OPCODE_SAMPLE_B
:
5229 exec_sample(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, FALSE
);
5232 case TGSI_OPCODE_SAMPLE_C
:
5233 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, TRUE
);
5236 case TGSI_OPCODE_SAMPLE_C_LZ
:
5237 exec_sample(mach
, inst
, TEX_MODIFIER_LEVEL_ZERO
, TRUE
);
5240 case TGSI_OPCODE_SAMPLE_D
:
5241 exec_sample_d(mach
, inst
);
5244 case TGSI_OPCODE_SAMPLE_L
:
5245 exec_sample(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, FALSE
);
5248 case TGSI_OPCODE_GATHER4
:
5252 case TGSI_OPCODE_SVIEWINFO
:
5253 exec_txq(mach
, inst
);
5256 case TGSI_OPCODE_SAMPLE_POS
:
5260 case TGSI_OPCODE_SAMPLE_INFO
:
5264 case TGSI_OPCODE_UARL
:
5265 exec_vector_unary(mach
, inst
, micro_uarl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
5268 case TGSI_OPCODE_UCMP
:
5269 exec_vector_trinary(mach
, inst
, micro_ucmp
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5272 case TGSI_OPCODE_IABS
:
5273 exec_vector_unary(mach
, inst
, micro_iabs
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5276 case TGSI_OPCODE_ISSG
:
5277 exec_vector_unary(mach
, inst
, micro_isgn
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5280 case TGSI_OPCODE_TEX2
:
5281 /* simple texture lookup */
5282 /* src[0] = texcoord */
5283 /* src[1] = compare */
5284 /* src[2] = sampler unit */
5285 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 2);
5287 case TGSI_OPCODE_TXB2
:
5288 /* simple texture lookup */
5289 /* src[0] = texcoord */
5291 /* src[2] = sampler unit */
5292 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 2);
5294 case TGSI_OPCODE_TXL2
:
5295 /* simple texture lookup */
5296 /* src[0] = texcoord */
5298 /* src[2] = sampler unit */
5299 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 2);
5302 case TGSI_OPCODE_IBFE
:
5303 exec_vector_trinary(mach
, inst
, micro_ibfe
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5305 case TGSI_OPCODE_UBFE
:
5306 exec_vector_trinary(mach
, inst
, micro_ubfe
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5308 case TGSI_OPCODE_BFI
:
5309 exec_vector_quaternary(mach
, inst
, micro_bfi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5311 case TGSI_OPCODE_BREV
:
5312 exec_vector_unary(mach
, inst
, micro_brev
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5314 case TGSI_OPCODE_POPC
:
5315 exec_vector_unary(mach
, inst
, micro_popc
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
5317 case TGSI_OPCODE_LSB
:
5318 exec_vector_unary(mach
, inst
, micro_lsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
5320 case TGSI_OPCODE_IMSB
:
5321 exec_vector_unary(mach
, inst
, micro_imsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
5323 case TGSI_OPCODE_UMSB
:
5324 exec_vector_unary(mach
, inst
, micro_umsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
5327 case TGSI_OPCODE_F2D
:
5328 exec_f2d(mach
, inst
);
5331 case TGSI_OPCODE_D2F
:
5332 exec_d2f(mach
, inst
);
5335 case TGSI_OPCODE_DABS
:
5336 exec_double_unary(mach
, inst
, micro_dabs
);
5339 case TGSI_OPCODE_DNEG
:
5340 exec_double_unary(mach
, inst
, micro_dneg
);
5343 case TGSI_OPCODE_DADD
:
5344 exec_double_binary(mach
, inst
, micro_dadd
, TGSI_EXEC_DATA_DOUBLE
);
5347 case TGSI_OPCODE_DMUL
:
5348 exec_double_binary(mach
, inst
, micro_dmul
, TGSI_EXEC_DATA_DOUBLE
);
5351 case TGSI_OPCODE_DMAX
:
5352 exec_double_binary(mach
, inst
, micro_dmax
, TGSI_EXEC_DATA_DOUBLE
);
5355 case TGSI_OPCODE_DMIN
:
5356 exec_double_binary(mach
, inst
, micro_dmin
, TGSI_EXEC_DATA_DOUBLE
);
5359 case TGSI_OPCODE_DSLT
:
5360 exec_double_binary(mach
, inst
, micro_dslt
, TGSI_EXEC_DATA_UINT
);
5363 case TGSI_OPCODE_DSGE
:
5364 exec_double_binary(mach
, inst
, micro_dsge
, TGSI_EXEC_DATA_UINT
);
5367 case TGSI_OPCODE_DSEQ
:
5368 exec_double_binary(mach
, inst
, micro_dseq
, TGSI_EXEC_DATA_UINT
);
5371 case TGSI_OPCODE_DSNE
:
5372 exec_double_binary(mach
, inst
, micro_dsne
, TGSI_EXEC_DATA_UINT
);
5375 case TGSI_OPCODE_DRCP
:
5376 exec_double_unary(mach
, inst
, micro_drcp
);
5379 case TGSI_OPCODE_DSQRT
:
5380 exec_double_unary(mach
, inst
, micro_dsqrt
);
5383 case TGSI_OPCODE_DRSQ
:
5384 exec_double_unary(mach
, inst
, micro_drsq
);
5387 case TGSI_OPCODE_DMAD
:
5388 exec_double_trinary(mach
, inst
, micro_dmad
);
5391 case TGSI_OPCODE_DFRAC
:
5392 exec_double_unary(mach
, inst
, micro_dfrac
);
5395 case TGSI_OPCODE_DLDEXP
:
5396 exec_dldexp(mach
, inst
);
5399 case TGSI_OPCODE_DFRACEXP
:
5400 exec_dfracexp(mach
, inst
);
5403 case TGSI_OPCODE_I2D
:
5404 exec_i2d(mach
, inst
);
5407 case TGSI_OPCODE_D2I
:
5408 exec_d2i(mach
, inst
);
5411 case TGSI_OPCODE_U2D
:
5412 exec_u2d(mach
, inst
);
5415 case TGSI_OPCODE_D2U
:
5416 exec_d2u(mach
, inst
);
5419 case TGSI_OPCODE_LOAD
:
5420 exec_load(mach
, inst
);
5423 case TGSI_OPCODE_STORE
:
5424 exec_store(mach
, inst
);
5427 case TGSI_OPCODE_ATOMUADD
:
5428 case TGSI_OPCODE_ATOMXCHG
:
5429 case TGSI_OPCODE_ATOMCAS
:
5430 case TGSI_OPCODE_ATOMAND
:
5431 case TGSI_OPCODE_ATOMOR
:
5432 case TGSI_OPCODE_ATOMXOR
:
5433 case TGSI_OPCODE_ATOMUMIN
:
5434 case TGSI_OPCODE_ATOMUMAX
:
5435 case TGSI_OPCODE_ATOMIMIN
:
5436 case TGSI_OPCODE_ATOMIMAX
:
5437 exec_atomop(mach
, inst
);
5440 case TGSI_OPCODE_RESQ
:
5441 exec_resq(mach
, inst
);
5443 case TGSI_OPCODE_BARRIER
:
5444 case TGSI_OPCODE_MEMBAR
:
5453 * Run TGSI interpreter.
5454 * \return bitmask of "alive" quad components
5457 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
5461 uint default_mask
= 0xf;
5463 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
5464 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
5466 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
5467 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
5468 mach
->Primitives
[0] = 0;
5469 /* GS runs on a single primitive for now */
5473 if (mach
->NonHelperMask
== 0)
5474 mach
->NonHelperMask
= default_mask
;
5475 mach
->CondMask
= default_mask
;
5476 mach
->LoopMask
= default_mask
;
5477 mach
->ContMask
= default_mask
;
5478 mach
->FuncMask
= default_mask
;
5479 mach
->ExecMask
= default_mask
;
5481 mach
->Switch
.mask
= default_mask
;
5483 assert(mach
->CondStackTop
== 0);
5484 assert(mach
->LoopStackTop
== 0);
5485 assert(mach
->ContStackTop
== 0);
5486 assert(mach
->SwitchStackTop
== 0);
5487 assert(mach
->BreakStackTop
== 0);
5488 assert(mach
->CallStackTop
== 0);
5491 /* execute declarations (interpolants) */
5492 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
5493 exec_declaration( mach
, mach
->Declarations
+i
);
5498 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
5499 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
5502 memset(mach
->Temps
, 0, sizeof(temps
));
5503 memset(mach
->Outputs
, 0, sizeof(outputs
));
5504 memset(temps
, 0, sizeof(temps
));
5505 memset(outputs
, 0, sizeof(outputs
));
5508 /* execute instructions, until pc is set to -1 */
5514 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
5517 assert(pc
< (int) mach
->NumInstructions
);
5518 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
5521 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
5522 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
5525 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
5526 debug_printf("TEMP[%2u] = ", i
);
5527 for (j
= 0; j
< 4; j
++) {
5531 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
5532 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
5533 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
5534 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
5535 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
5539 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
5540 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
5543 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
5544 debug_printf("OUT[%2u] = ", i
);
5545 for (j
= 0; j
< 4; j
++) {
5549 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
5550 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
5551 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
5552 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
5553 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
5562 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
5563 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
5565 * Scale back depth component.
5567 for (i
= 0; i
< 4; i
++)
5568 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
5572 /* Strictly speaking, these assertions aren't really needed but they
5573 * can potentially catch some bugs in the control flow code.
5575 assert(mach
->CondStackTop
== 0);
5576 assert(mach
->LoopStackTop
== 0);
5577 assert(mach
->ContStackTop
== 0);
5578 assert(mach
->SwitchStackTop
== 0);
5579 assert(mach
->BreakStackTop
== 0);
5580 assert(mach
->CallStackTop
== 0);
5582 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];