1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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_memory.h"
62 #include "util/u_math.h"
65 #define DEBUG_EXECUTION 0
70 #define TILE_TOP_LEFT 0
71 #define TILE_TOP_RIGHT 1
72 #define TILE_BOTTOM_LEFT 2
73 #define TILE_BOTTOM_RIGHT 3
76 micro_abs(union tgsi_exec_channel *dst,
77 const union tgsi_exec_channel *src)
79 dst->f[0] = fabsf(src->f[0]);
80 dst->f[1] = fabsf(src->f[1]);
81 dst->f[2] = fabsf(src->f[2]);
82 dst->f[3] = fabsf(src->f[3]);
86 micro_arl(union tgsi_exec_channel *dst,
87 const union tgsi_exec_channel *src)
89 dst->i[0] = (int)floorf(src->f[0]);
90 dst->i[1] = (int)floorf(src->f[1]);
91 dst->i[2] = (int)floorf(src->f[2]);
92 dst->i[3] = (int)floorf(src->f[3]);
96 micro_arr(union tgsi_exec_channel *dst,
97 const union tgsi_exec_channel *src)
99 dst->i[0] = (int)floorf(src->f[0] + 0.5f);
100 dst->i[1] = (int)floorf(src->f[1] + 0.5f);
101 dst->i[2] = (int)floorf(src->f[2] + 0.5f);
102 dst->i[3] = (int)floorf(src->f[3] + 0.5f);
106 micro_ceil(union tgsi_exec_channel *dst,
107 const union tgsi_exec_channel *src)
109 dst->f[0] = ceilf(src->f[0]);
110 dst->f[1] = ceilf(src->f[1]);
111 dst->f[2] = ceilf(src->f[2]);
112 dst->f[3] = ceilf(src->f[3]);
116 micro_clamp(union tgsi_exec_channel *dst,
117 const union tgsi_exec_channel *src0,
118 const union tgsi_exec_channel *src1,
119 const union tgsi_exec_channel *src2)
121 dst->f[0] = src0->f[0] < src1->f[0] ? src1->f[0] : src0->f[0] > src2->f[0] ? src2->f[0] : src0->f[0];
122 dst->f[1] = src0->f[1] < src1->f[1] ? src1->f[1] : src0->f[1] > src2->f[1] ? src2->f[1] : src0->f[1];
123 dst->f[2] = src0->f[2] < src1->f[2] ? src1->f[2] : src0->f[2] > src2->f[2] ? src2->f[2] : src0->f[2];
124 dst->f[3] = src0->f[3] < src1->f[3] ? src1->f[3] : src0->f[3] > src2->f[3] ? src2->f[3] : src0->f[3];
128 micro_cmp(union tgsi_exec_channel *dst,
129 const union tgsi_exec_channel *src0,
130 const union tgsi_exec_channel *src1,
131 const union tgsi_exec_channel *src2)
133 dst->f[0] = src0->f[0] < 0.0f ? src1->f[0] : src2->f[0];
134 dst->f[1] = src0->f[1] < 0.0f ? src1->f[1] : src2->f[1];
135 dst->f[2] = src0->f[2] < 0.0f ? src1->f[2] : src2->f[2];
136 dst->f[3] = src0->f[3] < 0.0f ? src1->f[3] : src2->f[3];
140 micro_cnd(union tgsi_exec_channel *dst,
141 const union tgsi_exec_channel *src0,
142 const union tgsi_exec_channel *src1,
143 const union tgsi_exec_channel *src2)
145 dst->f[0] = src2->f[0] > 0.5f ? src0->f[0] : src1->f[0];
146 dst->f[1] = src2->f[1] > 0.5f ? src0->f[1] : src1->f[1];
147 dst->f[2] = src2->f[2] > 0.5f ? src0->f[2] : src1->f[2];
148 dst->f[3] = src2->f[3] > 0.5f ? src0->f[3] : src1->f[3];
152 micro_cos(union tgsi_exec_channel *dst,
153 const union tgsi_exec_channel *src)
155 dst->f[0] = cosf(src->f[0]);
156 dst->f[1] = cosf(src->f[1]);
157 dst->f[2] = cosf(src->f[2]);
158 dst->f[3] = cosf(src->f[3]);
162 micro_ddx(union tgsi_exec_channel *dst,
163 const union tgsi_exec_channel *src)
168 dst->f[3] = src->f[TILE_BOTTOM_RIGHT] - src->f[TILE_BOTTOM_LEFT];
172 micro_ddy(union tgsi_exec_channel *dst,
173 const union tgsi_exec_channel *src)
178 dst->f[3] = src->f[TILE_BOTTOM_LEFT] - src->f[TILE_TOP_LEFT];
182 micro_exp2(union tgsi_exec_channel *dst,
183 const union tgsi_exec_channel *src)
186 dst->f[0] = util_fast_exp2(src->f[0]);
187 dst->f[1] = util_fast_exp2(src->f[1]);
188 dst->f[2] = util_fast_exp2(src->f[2]);
189 dst->f[3] = util_fast_exp2(src->f[3]);
192 /* Inf is okay for this instruction, so clamp it to silence assertions. */
194 union tgsi_exec_channel clamped;
196 for (i = 0; i < 4; i++) {
197 if (src->f[i] > 127.99999f) {
198 clamped.f[i] = 127.99999f;
199 } else if (src->f[i] < -126.99999f) {
200 clamped.f[i] = -126.99999f;
202 clamped.f[i] = src->f[i];
208 dst->f[0] = powf(2.0f, src->f[0]);
209 dst->f[1] = powf(2.0f, src->f[1]);
210 dst->f[2] = powf(2.0f, src->f[2]);
211 dst->f[3] = powf(2.0f, src->f[3]);
212 #endif /* FAST_MATH */
216 micro_flr(union tgsi_exec_channel *dst,
217 const union tgsi_exec_channel *src)
219 dst->f[0] = floorf(src->f[0]);
220 dst->f[1] = floorf(src->f[1]);
221 dst->f[2] = floorf(src->f[2]);
222 dst->f[3] = floorf(src->f[3]);
226 micro_frc(union tgsi_exec_channel *dst,
227 const union tgsi_exec_channel *src)
229 dst->f[0] = src->f[0] - floorf(src->f[0]);
230 dst->f[1] = src->f[1] - floorf(src->f[1]);
231 dst->f[2] = src->f[2] - floorf(src->f[2]);
232 dst->f[3] = src->f[3] - floorf(src->f[3]);
236 micro_iabs(union tgsi_exec_channel *dst,
237 const union tgsi_exec_channel *src)
239 dst->i[0] = src->i[0] >= 0 ? src->i[0] : -src->i[0];
240 dst->i[1] = src->i[1] >= 0 ? src->i[1] : -src->i[1];
241 dst->i[2] = src->i[2] >= 0 ? src->i[2] : -src->i[2];
242 dst->i[3] = src->i[3] >= 0 ? src->i[3] : -src->i[3];
246 micro_ineg(union tgsi_exec_channel *dst,
247 const union tgsi_exec_channel *src)
249 dst->i[0] = -src->i[0];
250 dst->i[1] = -src->i[1];
251 dst->i[2] = -src->i[2];
252 dst->i[3] = -src->i[3];
256 micro_lg2(union tgsi_exec_channel *dst,
257 const union tgsi_exec_channel *src)
260 dst->f[0] = util_fast_log2(src->f[0]);
261 dst->f[1] = util_fast_log2(src->f[1]);
262 dst->f[2] = util_fast_log2(src->f[2]);
263 dst->f[3] = util_fast_log2(src->f[3]);
265 dst->f[0] = logf(src->f[0]) * 1.442695f;
266 dst->f[1] = logf(src->f[1]) * 1.442695f;
267 dst->f[2] = logf(src->f[2]) * 1.442695f;
268 dst->f[3] = logf(src->f[3]) * 1.442695f;
273 micro_lrp(union tgsi_exec_channel *dst,
274 const union tgsi_exec_channel *src0,
275 const union tgsi_exec_channel *src1,
276 const union tgsi_exec_channel *src2)
278 dst->f[0] = src0->f[0] * (src1->f[0] - src2->f[0]) + src2->f[0];
279 dst->f[1] = src0->f[1] * (src1->f[1] - src2->f[1]) + src2->f[1];
280 dst->f[2] = src0->f[2] * (src1->f[2] - src2->f[2]) + src2->f[2];
281 dst->f[3] = src0->f[3] * (src1->f[3] - src2->f[3]) + src2->f[3];
285 micro_mad(union tgsi_exec_channel *dst,
286 const union tgsi_exec_channel *src0,
287 const union tgsi_exec_channel *src1,
288 const union tgsi_exec_channel *src2)
290 dst->f[0] = src0->f[0] * src1->f[0] + src2->f[0];
291 dst->f[1] = src0->f[1] * src1->f[1] + src2->f[1];
292 dst->f[2] = src0->f[2] * src1->f[2] + src2->f[2];
293 dst->f[3] = src0->f[3] * src1->f[3] + src2->f[3];
297 micro_mov(union tgsi_exec_channel *dst,
298 const union tgsi_exec_channel *src)
300 dst->u[0] = src->u[0];
301 dst->u[1] = src->u[1];
302 dst->u[2] = src->u[2];
303 dst->u[3] = src->u[3];
307 micro_rcp(union tgsi_exec_channel *dst,
308 const union tgsi_exec_channel *src)
310 #if 0 /* for debugging */
311 assert(src->f[0] != 0.0f);
312 assert(src->f[1] != 0.0f);
313 assert(src->f[2] != 0.0f);
314 assert(src->f[3] != 0.0f);
316 dst->f[0] = 1.0f / src->f[0];
317 dst->f[1] = 1.0f / src->f[1];
318 dst->f[2] = 1.0f / src->f[2];
319 dst->f[3] = 1.0f / src->f[3];
323 micro_rnd(union tgsi_exec_channel *dst,
324 const union tgsi_exec_channel *src)
326 dst->f[0] = floorf(src->f[0] + 0.5f);
327 dst->f[1] = floorf(src->f[1] + 0.5f);
328 dst->f[2] = floorf(src->f[2] + 0.5f);
329 dst->f[3] = floorf(src->f[3] + 0.5f);
333 micro_rsq(union tgsi_exec_channel *dst,
334 const union tgsi_exec_channel *src)
336 #if 0 /* for debugging */
337 assert(src->f[0] != 0.0f);
338 assert(src->f[1] != 0.0f);
339 assert(src->f[2] != 0.0f);
340 assert(src->f[3] != 0.0f);
342 dst->f[0] = 1.0f / sqrtf(fabsf(src->f[0]));
343 dst->f[1] = 1.0f / sqrtf(fabsf(src->f[1]));
344 dst->f[2] = 1.0f / sqrtf(fabsf(src->f[2]));
345 dst->f[3] = 1.0f / sqrtf(fabsf(src->f[3]));
349 micro_sqrt(union tgsi_exec_channel *dst,
350 const union tgsi_exec_channel *src)
352 dst->f[0] = sqrtf(fabsf(src->f[0]));
353 dst->f[1] = sqrtf(fabsf(src->f[1]));
354 dst->f[2] = sqrtf(fabsf(src->f[2]));
355 dst->f[3] = sqrtf(fabsf(src->f[3]));
359 micro_seq(union tgsi_exec_channel *dst,
360 const union tgsi_exec_channel *src0,
361 const union tgsi_exec_channel *src1)
363 dst->f[0] = src0->f[0] == src1->f[0] ? 1.0f : 0.0f;
364 dst->f[1] = src0->f[1] == src1->f[1] ? 1.0f : 0.0f;
365 dst->f[2] = src0->f[2] == src1->f[2] ? 1.0f : 0.0f;
366 dst->f[3] = src0->f[3] == src1->f[3] ? 1.0f : 0.0f;
370 micro_sge(union tgsi_exec_channel *dst,
371 const union tgsi_exec_channel *src0,
372 const union tgsi_exec_channel *src1)
374 dst->f[0] = src0->f[0] >= src1->f[0] ? 1.0f : 0.0f;
375 dst->f[1] = src0->f[1] >= src1->f[1] ? 1.0f : 0.0f;
376 dst->f[2] = src0->f[2] >= src1->f[2] ? 1.0f : 0.0f;
377 dst->f[3] = src0->f[3] >= src1->f[3] ? 1.0f : 0.0f;
381 micro_sgn(union tgsi_exec_channel *dst,
382 const union tgsi_exec_channel *src)
384 dst->f[0] = src->f[0] < 0.0f ? -1.0f : src->f[0] > 0.0f ? 1.0f : 0.0f;
385 dst->f[1] = src->f[1] < 0.0f ? -1.0f : src->f[1] > 0.0f ? 1.0f : 0.0f;
386 dst->f[2] = src->f[2] < 0.0f ? -1.0f : src->f[2] > 0.0f ? 1.0f : 0.0f;
387 dst->f[3] = src->f[3] < 0.0f ? -1.0f : src->f[3] > 0.0f ? 1.0f : 0.0f;
391 micro_isgn(union tgsi_exec_channel *dst,
392 const union tgsi_exec_channel *src)
394 dst->i[0] = src->i[0] < 0 ? -1 : src->i[0] > 0 ? 1 : 0;
395 dst->i[1] = src->i[1] < 0 ? -1 : src->i[1] > 0 ? 1 : 0;
396 dst->i[2] = src->i[2] < 0 ? -1 : src->i[2] > 0 ? 1 : 0;
397 dst->i[3] = src->i[3] < 0 ? -1 : src->i[3] > 0 ? 1 : 0;
401 micro_sgt(union tgsi_exec_channel *dst,
402 const union tgsi_exec_channel *src0,
403 const union tgsi_exec_channel *src1)
405 dst->f[0] = src0->f[0] > src1->f[0] ? 1.0f : 0.0f;
406 dst->f[1] = src0->f[1] > src1->f[1] ? 1.0f : 0.0f;
407 dst->f[2] = src0->f[2] > src1->f[2] ? 1.0f : 0.0f;
408 dst->f[3] = src0->f[3] > src1->f[3] ? 1.0f : 0.0f;
412 micro_sin(union tgsi_exec_channel *dst,
413 const union tgsi_exec_channel *src)
415 dst->f[0] = sinf(src->f[0]);
416 dst->f[1] = sinf(src->f[1]);
417 dst->f[2] = sinf(src->f[2]);
418 dst->f[3] = sinf(src->f[3]);
422 micro_sle(union tgsi_exec_channel *dst,
423 const union tgsi_exec_channel *src0,
424 const union tgsi_exec_channel *src1)
426 dst->f[0] = src0->f[0] <= src1->f[0] ? 1.0f : 0.0f;
427 dst->f[1] = src0->f[1] <= src1->f[1] ? 1.0f : 0.0f;
428 dst->f[2] = src0->f[2] <= src1->f[2] ? 1.0f : 0.0f;
429 dst->f[3] = src0->f[3] <= src1->f[3] ? 1.0f : 0.0f;
433 micro_slt(union tgsi_exec_channel *dst,
434 const union tgsi_exec_channel *src0,
435 const union tgsi_exec_channel *src1)
437 dst->f[0] = src0->f[0] < src1->f[0] ? 1.0f : 0.0f;
438 dst->f[1] = src0->f[1] < src1->f[1] ? 1.0f : 0.0f;
439 dst->f[2] = src0->f[2] < src1->f[2] ? 1.0f : 0.0f;
440 dst->f[3] = src0->f[3] < src1->f[3] ? 1.0f : 0.0f;
444 micro_sne(union tgsi_exec_channel *dst,
445 const union tgsi_exec_channel *src0,
446 const union tgsi_exec_channel *src1)
448 dst->f[0] = src0->f[0] != src1->f[0] ? 1.0f : 0.0f;
449 dst->f[1] = src0->f[1] != src1->f[1] ? 1.0f : 0.0f;
450 dst->f[2] = src0->f[2] != src1->f[2] ? 1.0f : 0.0f;
451 dst->f[3] = src0->f[3] != src1->f[3] ? 1.0f : 0.0f;
455 micro_sfl(union tgsi_exec_channel *dst)
464 micro_str(union tgsi_exec_channel *dst)
473 micro_trunc(union tgsi_exec_channel *dst,
474 const union tgsi_exec_channel *src)
476 dst->f[0] = (float)(int)src->f[0];
477 dst->f[1] = (float)(int)src->f[1];
478 dst->f[2] = (float)(int)src->f[2];
479 dst->f[3] = (float)(int)src->f[3];
483 enum tgsi_exec_datatype {
484 TGSI_EXEC_DATA_FLOAT,
490 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
492 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
493 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
494 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
495 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
496 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
497 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
500 /** The execution mask depends on the conditional mask and the loop mask */
501 #define UPDATE_EXEC_MASK(MACH) \
502 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
505 static const union tgsi_exec_channel ZeroVec =
506 { { 0.0, 0.0, 0.0, 0.0 } };
508 static const union tgsi_exec_channel OneVec = {
509 {1.0f, 1.0f, 1.0f, 1.0f}
512 static const union tgsi_exec_channel P128Vec = {
513 {128.0f, 128.0f, 128.0f, 128.0f}
516 static const union tgsi_exec_channel M128Vec = {
517 {-128.0f, -128.0f, -128.0f, -128.0f}
522 * Assert that none of the float values in 'chan' are infinite or NaN.
523 * NaN and Inf may occur normally during program execution and should
524 * not lead to crashes, etc. But when debugging, it's helpful to catch
528 check_inf_or_nan(const union tgsi_exec_channel *chan)
530 assert(!util_is_inf_or_nan((chan)->f[0]));
531 assert(!util_is_inf_or_nan((chan)->f[1]));
532 assert(!util_is_inf_or_nan((chan)->f[2]));
533 assert(!util_is_inf_or_nan((chan)->f[3]));
539 print_chan(const char *msg, const union tgsi_exec_channel *chan)
541 debug_printf("%s = {%f, %f, %f, %f}\n",
542 msg, chan->f[0], chan->f[1], chan->f[2], chan->f[3]);
549 print_temp(const struct tgsi_exec_machine *mach, uint index)
551 const struct tgsi_exec_vector *tmp = &mach->Temps[index];
553 debug_printf("Temp[%u] =\n", index);
554 for (i = 0; i < 4; i++) {
555 debug_printf(" %c: { %f, %f, %f, %f }\n",
567 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine *mach,
570 const unsigned *buf_sizes)
574 for (i = 0; i < num_bufs; i++) {
575 mach->Consts[i] = bufs[i];
576 mach->ConstsSize[i] = buf_sizes[i];
582 * Check if there's a potential src/dst register data dependency when
583 * using SOA execution.
586 * This would expand into:
591 * The second instruction will have the wrong value for t0 if executed as-is.
594 tgsi_check_soa_dependencies(const struct tgsi_full_instruction *inst)
598 uint writemask = inst->Dst[0].Register.WriteMask;
599 if (writemask == TGSI_WRITEMASK_X ||
600 writemask == TGSI_WRITEMASK_Y ||
601 writemask == TGSI_WRITEMASK_Z ||
602 writemask == TGSI_WRITEMASK_W ||
603 writemask == TGSI_WRITEMASK_NONE) {
604 /* no chance of data dependency */
608 /* loop over src regs */
609 for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
610 if ((inst->Src[i].Register.File ==
611 inst->Dst[0].Register.File) &&
612 ((inst->Src[i].Register.Index ==
613 inst->Dst[0].Register.Index) ||
614 inst->Src[i].Register.Indirect ||
615 inst->Dst[0].Register.Indirect)) {
616 /* loop over dest channels */
617 uint channelsWritten = 0x0;
618 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
619 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
620 /* check if we're reading a channel that's been written */
621 uint swizzle = tgsi_util_get_full_src_register_swizzle(&inst->Src[i], chan);
622 if (channelsWritten & (1 << swizzle)) {
626 channelsWritten |= (1 << chan);
636 * Initialize machine state by expanding tokens to full instructions,
637 * allocating temporary storage, setting up constants, etc.
638 * After this, we can call tgsi_exec_machine_run() many times.
641 tgsi_exec_machine_bind_shader(
642 struct tgsi_exec_machine *mach,
643 const struct tgsi_token *tokens,
644 struct tgsi_sampler *sampler)
647 struct tgsi_parse_context parse;
648 struct tgsi_full_instruction *instructions;
649 struct tgsi_full_declaration *declarations;
650 uint maxInstructions = 10, numInstructions = 0;
651 uint maxDeclarations = 10, numDeclarations = 0;
654 tgsi_dump(tokens, 0);
660 mach->Tokens = tokens;
661 mach->Sampler = sampler;
664 /* unbind and free all */
665 FREE(mach->Declarations);
666 mach->Declarations = NULL;
667 mach->NumDeclarations = 0;
669 FREE(mach->Instructions);
670 mach->Instructions = NULL;
671 mach->NumInstructions = 0;
676 k = tgsi_parse_init (&parse, mach->Tokens);
677 if (k != TGSI_PARSE_OK) {
678 debug_printf( "Problem parsing!\n" );
682 mach->Processor = parse.FullHeader.Processor.Processor;
684 mach->NumOutputs = 0;
686 if (mach->Processor == TGSI_PROCESSOR_GEOMETRY &&
687 !mach->UsedGeometryShader) {
688 struct tgsi_exec_vector *inputs;
689 struct tgsi_exec_vector *outputs;
691 inputs = align_malloc(sizeof(struct tgsi_exec_vector) *
692 TGSI_MAX_PRIM_VERTICES * PIPE_MAX_ATTRIBS,
698 outputs = align_malloc(sizeof(struct tgsi_exec_vector) *
699 TGSI_MAX_TOTAL_VERTICES, 16);
706 align_free(mach->Inputs);
707 align_free(mach->Outputs);
709 mach->Inputs = inputs;
710 mach->Outputs = outputs;
711 mach->UsedGeometryShader = TRUE;
714 declarations = (struct tgsi_full_declaration *)
715 MALLOC( maxDeclarations * sizeof(struct tgsi_full_declaration) );
721 instructions = (struct tgsi_full_instruction *)
722 MALLOC( maxInstructions * sizeof(struct tgsi_full_instruction) );
725 FREE( declarations );
729 while( !tgsi_parse_end_of_tokens( &parse ) ) {
732 tgsi_parse_token( &parse );
733 switch( parse.FullToken.Token.Type ) {
734 case TGSI_TOKEN_TYPE_DECLARATION:
735 /* save expanded declaration */
736 if (numDeclarations == maxDeclarations) {
737 declarations = REALLOC(declarations,
739 * sizeof(struct tgsi_full_declaration),
740 (maxDeclarations + 10)
741 * sizeof(struct tgsi_full_declaration));
742 maxDeclarations += 10;
744 if (parse.FullToken.FullDeclaration.Declaration.File == TGSI_FILE_OUTPUT) {
746 for (reg = parse.FullToken.FullDeclaration.Range.First;
747 reg <= parse.FullToken.FullDeclaration.Range.Last;
752 memcpy(declarations + numDeclarations,
753 &parse.FullToken.FullDeclaration,
754 sizeof(declarations[0]));
758 case TGSI_TOKEN_TYPE_IMMEDIATE:
760 uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1;
762 assert( mach->ImmLimit + 1 <= TGSI_EXEC_NUM_IMMEDIATES );
764 for( i = 0; i < size; i++ ) {
765 mach->Imms[mach->ImmLimit][i] =
766 parse.FullToken.FullImmediate.u[i].Float;
772 case TGSI_TOKEN_TYPE_INSTRUCTION:
774 /* save expanded instruction */
775 if (numInstructions == maxInstructions) {
776 instructions = REALLOC(instructions,
778 * sizeof(struct tgsi_full_instruction),
779 (maxInstructions + 10)
780 * sizeof(struct tgsi_full_instruction));
781 maxInstructions += 10;
784 memcpy(instructions + numInstructions,
785 &parse.FullToken.FullInstruction,
786 sizeof(instructions[0]));
791 case TGSI_TOKEN_TYPE_PROPERTY:
798 tgsi_parse_free (&parse);
800 FREE(mach->Declarations);
801 mach->Declarations = declarations;
802 mach->NumDeclarations = numDeclarations;
804 FREE(mach->Instructions);
805 mach->Instructions = instructions;
806 mach->NumInstructions = numInstructions;
810 struct tgsi_exec_machine *
811 tgsi_exec_machine_create( void )
813 struct tgsi_exec_machine *mach;
816 mach = align_malloc( sizeof *mach, 16 );
820 memset(mach, 0, sizeof(*mach));
822 mach->Addrs = &mach->Temps[TGSI_EXEC_TEMP_ADDR];
823 mach->MaxGeometryShaderOutputs = TGSI_MAX_TOTAL_VERTICES;
824 mach->Predicates = &mach->Temps[TGSI_EXEC_TEMP_P0];
826 mach->Inputs = align_malloc(sizeof(struct tgsi_exec_vector) * PIPE_MAX_ATTRIBS, 16);
827 mach->Outputs = align_malloc(sizeof(struct tgsi_exec_vector) * PIPE_MAX_ATTRIBS, 16);
828 if (!mach->Inputs || !mach->Outputs)
831 /* Setup constants needed by the SSE2 executor. */
832 for( i = 0; i < 4; i++ ) {
833 mach->Temps[TGSI_EXEC_TEMP_00000000_I].xyzw[TGSI_EXEC_TEMP_00000000_C].u[i] = 0x00000000;
834 mach->Temps[TGSI_EXEC_TEMP_7FFFFFFF_I].xyzw[TGSI_EXEC_TEMP_7FFFFFFF_C].u[i] = 0x7FFFFFFF;
835 mach->Temps[TGSI_EXEC_TEMP_80000000_I].xyzw[TGSI_EXEC_TEMP_80000000_C].u[i] = 0x80000000;
836 mach->Temps[TGSI_EXEC_TEMP_FFFFFFFF_I].xyzw[TGSI_EXEC_TEMP_FFFFFFFF_C].u[i] = 0xFFFFFFFF; /* not used */
837 mach->Temps[TGSI_EXEC_TEMP_ONE_I].xyzw[TGSI_EXEC_TEMP_ONE_C].f[i] = 1.0f;
838 mach->Temps[TGSI_EXEC_TEMP_TWO_I].xyzw[TGSI_EXEC_TEMP_TWO_C].f[i] = 2.0f; /* not used */
839 mach->Temps[TGSI_EXEC_TEMP_128_I].xyzw[TGSI_EXEC_TEMP_128_C].f[i] = 128.0f;
840 mach->Temps[TGSI_EXEC_TEMP_MINUS_128_I].xyzw[TGSI_EXEC_TEMP_MINUS_128_C].f[i] = -128.0f;
841 mach->Temps[TGSI_EXEC_TEMP_THREE_I].xyzw[TGSI_EXEC_TEMP_THREE_C].f[i] = 3.0f;
842 mach->Temps[TGSI_EXEC_TEMP_HALF_I].xyzw[TGSI_EXEC_TEMP_HALF_C].f[i] = 0.5f;
846 /* silence warnings */
855 align_free(mach->Inputs);
856 align_free(mach->Outputs);
864 tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach)
867 FREE(mach->Instructions);
868 FREE(mach->Declarations);
870 align_free(mach->Inputs);
871 align_free(mach->Outputs);
878 micro_add(union tgsi_exec_channel *dst,
879 const union tgsi_exec_channel *src0,
880 const union tgsi_exec_channel *src1)
882 dst->f[0] = src0->f[0] + src1->f[0];
883 dst->f[1] = src0->f[1] + src1->f[1];
884 dst->f[2] = src0->f[2] + src1->f[2];
885 dst->f[3] = src0->f[3] + src1->f[3];
890 union tgsi_exec_channel *dst,
891 const union tgsi_exec_channel *src0,
892 const union tgsi_exec_channel *src1 )
894 if (src1->f[0] != 0) {
895 dst->f[0] = src0->f[0] / src1->f[0];
897 if (src1->f[1] != 0) {
898 dst->f[1] = src0->f[1] / src1->f[1];
900 if (src1->f[2] != 0) {
901 dst->f[2] = src0->f[2] / src1->f[2];
903 if (src1->f[3] != 0) {
904 dst->f[3] = src0->f[3] / src1->f[3];
909 micro_rcc(union tgsi_exec_channel *dst,
910 const union tgsi_exec_channel *src)
914 for (i = 0; i < 4; i++) {
915 float recip = 1.0f / src->f[i];
918 if (recip > 1.884467e+019f) {
919 dst->f[i] = 1.884467e+019f;
921 else if (recip < 5.42101e-020f) {
922 dst->f[i] = 5.42101e-020f;
929 if (recip < -1.884467e+019f) {
930 dst->f[i] = -1.884467e+019f;
932 else if (recip > -5.42101e-020f) {
933 dst->f[i] = -5.42101e-020f;
944 union tgsi_exec_channel *dst,
945 const union tgsi_exec_channel *src0,
946 const union tgsi_exec_channel *src1,
947 const union tgsi_exec_channel *src2,
948 const union tgsi_exec_channel *src3 )
950 dst->f[0] = src0->f[0] < src1->f[0] ? src2->f[0] : src3->f[0];
951 dst->f[1] = src0->f[1] < src1->f[1] ? src2->f[1] : src3->f[1];
952 dst->f[2] = src0->f[2] < src1->f[2] ? src2->f[2] : src3->f[2];
953 dst->f[3] = src0->f[3] < src1->f[3] ? src2->f[3] : src3->f[3];
957 micro_max(union tgsi_exec_channel *dst,
958 const union tgsi_exec_channel *src0,
959 const union tgsi_exec_channel *src1)
961 dst->f[0] = src0->f[0] > src1->f[0] ? src0->f[0] : src1->f[0];
962 dst->f[1] = src0->f[1] > src1->f[1] ? src0->f[1] : src1->f[1];
963 dst->f[2] = src0->f[2] > src1->f[2] ? src0->f[2] : src1->f[2];
964 dst->f[3] = src0->f[3] > src1->f[3] ? src0->f[3] : src1->f[3];
968 micro_min(union tgsi_exec_channel *dst,
969 const union tgsi_exec_channel *src0,
970 const union tgsi_exec_channel *src1)
972 dst->f[0] = src0->f[0] < src1->f[0] ? src0->f[0] : src1->f[0];
973 dst->f[1] = src0->f[1] < src1->f[1] ? src0->f[1] : src1->f[1];
974 dst->f[2] = src0->f[2] < src1->f[2] ? src0->f[2] : src1->f[2];
975 dst->f[3] = src0->f[3] < src1->f[3] ? src0->f[3] : src1->f[3];
979 micro_mul(union tgsi_exec_channel *dst,
980 const union tgsi_exec_channel *src0,
981 const union tgsi_exec_channel *src1)
983 dst->f[0] = src0->f[0] * src1->f[0];
984 dst->f[1] = src0->f[1] * src1->f[1];
985 dst->f[2] = src0->f[2] * src1->f[2];
986 dst->f[3] = src0->f[3] * src1->f[3];
991 union tgsi_exec_channel *dst,
992 const union tgsi_exec_channel *src )
994 dst->f[0] = -src->f[0];
995 dst->f[1] = -src->f[1];
996 dst->f[2] = -src->f[2];
997 dst->f[3] = -src->f[3];
1002 union tgsi_exec_channel *dst,
1003 const union tgsi_exec_channel *src0,
1004 const union tgsi_exec_channel *src1 )
1007 dst->f[0] = util_fast_pow( src0->f[0], src1->f[0] );
1008 dst->f[1] = util_fast_pow( src0->f[1], src1->f[1] );
1009 dst->f[2] = util_fast_pow( src0->f[2], src1->f[2] );
1010 dst->f[3] = util_fast_pow( src0->f[3], src1->f[3] );
1012 dst->f[0] = powf( src0->f[0], src1->f[0] );
1013 dst->f[1] = powf( src0->f[1], src1->f[1] );
1014 dst->f[2] = powf( src0->f[2], src1->f[2] );
1015 dst->f[3] = powf( src0->f[3], src1->f[3] );
1020 micro_sub(union tgsi_exec_channel *dst,
1021 const union tgsi_exec_channel *src0,
1022 const union tgsi_exec_channel *src1)
1024 dst->f[0] = src0->f[0] - src1->f[0];
1025 dst->f[1] = src0->f[1] - src1->f[1];
1026 dst->f[2] = src0->f[2] - src1->f[2];
1027 dst->f[3] = src0->f[3] - src1->f[3];
1031 fetch_src_file_channel(const struct tgsi_exec_machine *mach,
1032 const uint chan_index,
1035 const union tgsi_exec_channel *index,
1036 const union tgsi_exec_channel *index2D,
1037 union tgsi_exec_channel *chan)
1041 assert(swizzle < 4);
1044 case TGSI_FILE_CONSTANT:
1045 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1046 assert(index2D->i[i] >= 0 && index2D->i[i] < PIPE_MAX_CONSTANT_BUFFERS);
1047 assert(mach->Consts[index2D->i[i]]);
1049 if (index->i[i] < 0) {
1052 /* NOTE: copying the const value as a uint instead of float */
1053 const uint constbuf = index2D->i[i];
1054 const uint *buf = (const uint *)mach->Consts[constbuf];
1055 const int pos = index->i[i] * 4 + swizzle;
1056 /* const buffer bounds check */
1057 if (pos < 0 || pos >= (int) mach->ConstsSize[constbuf]) {
1059 /* Debug: print warning */
1060 static int count = 0;
1062 debug_printf("TGSI Exec: const buffer index %d"
1063 " out of bounds\n", pos);
1068 chan->u[i] = buf[pos];
1073 case TGSI_FILE_INPUT:
1074 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1076 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1077 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1078 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1079 index2D->i[i], index->i[i]);
1081 int pos = index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i];
1083 assert(pos < TGSI_MAX_PRIM_VERTICES * PIPE_MAX_ATTRIBS);
1084 chan->u[i] = mach->Inputs[pos].xyzw[swizzle].u[i];
1088 case TGSI_FILE_SYSTEM_VALUE:
1089 /* XXX no swizzling at this point. Will be needed if we put
1090 * gl_FragCoord, for example, in a sys value register.
1092 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1093 chan->u[i] = mach->SystemValue[index->i[i]].u[i];
1097 case TGSI_FILE_TEMPORARY:
1098 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1099 assert(index->i[i] < TGSI_EXEC_NUM_TEMPS);
1100 assert(index2D->i[i] == 0);
1102 chan->u[i] = mach->Temps[index->i[i]].xyzw[swizzle].u[i];
1106 case TGSI_FILE_IMMEDIATE:
1107 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1108 assert(index->i[i] >= 0 && index->i[i] < (int)mach->ImmLimit);
1109 assert(index2D->i[i] == 0);
1111 chan->f[i] = mach->Imms[index->i[i]][swizzle];
1115 case TGSI_FILE_ADDRESS:
1116 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1117 assert(index->i[i] >= 0);
1118 assert(index2D->i[i] == 0);
1120 chan->u[i] = mach->Addrs[index->i[i]].xyzw[swizzle].u[i];
1124 case TGSI_FILE_PREDICATE:
1125 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1126 assert(index->i[i] >= 0 && index->i[i] < TGSI_EXEC_NUM_PREDS);
1127 assert(index2D->i[i] == 0);
1129 chan->u[i] = mach->Predicates[0].xyzw[swizzle].u[i];
1133 case TGSI_FILE_OUTPUT:
1134 /* vertex/fragment output vars can be read too */
1135 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1136 assert(index->i[i] >= 0);
1137 assert(index2D->i[i] == 0);
1139 chan->u[i] = mach->Outputs[index->i[i]].xyzw[swizzle].u[i];
1145 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1152 fetch_source(const struct tgsi_exec_machine *mach,
1153 union tgsi_exec_channel *chan,
1154 const struct tgsi_full_src_register *reg,
1155 const uint chan_index,
1156 enum tgsi_exec_datatype src_datatype)
1158 union tgsi_exec_channel index;
1159 union tgsi_exec_channel index2D;
1162 /* We start with a direct index into a register file.
1166 * file = Register.File
1167 * [1] = Register.Index
1172 index.i[3] = reg->Register.Index;
1174 /* There is an extra source register that indirectly subscripts
1175 * a register file. The direct index now becomes an offset
1176 * that is being added to the indirect register.
1180 * ind = Indirect.File
1181 * [2] = Indirect.Index
1182 * .x = Indirect.SwizzleX
1184 if (reg->Register.Indirect) {
1185 union tgsi_exec_channel index2;
1186 union tgsi_exec_channel indir_index;
1187 const uint execmask = mach->ExecMask;
1190 /* which address register (always zero now) */
1194 index2.i[3] = reg->Indirect.Index;
1195 /* get current value of address register[swizzle] */
1196 swizzle = reg->Indirect.Swizzle;
1197 fetch_src_file_channel(mach,
1205 /* add value of address register to the offset */
1206 index.i[0] += indir_index.i[0];
1207 index.i[1] += indir_index.i[1];
1208 index.i[2] += indir_index.i[2];
1209 index.i[3] += indir_index.i[3];
1211 /* for disabled execution channels, zero-out the index to
1212 * avoid using a potential garbage value.
1214 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1215 if ((execmask & (1 << i)) == 0)
1220 /* There is an extra source register that is a second
1221 * subscript to a register file. Effectively it means that
1222 * the register file is actually a 2D array of registers.
1226 * [3] = Dimension.Index
1228 if (reg->Register.Dimension) {
1232 index2D.i[3] = reg->Dimension.Index;
1234 /* Again, the second subscript index can be addressed indirectly
1235 * identically to the first one.
1236 * Nothing stops us from indirectly addressing the indirect register,
1237 * but there is no need for that, so we won't exercise it.
1239 * file[ind[4].y+3][1],
1241 * ind = DimIndirect.File
1242 * [4] = DimIndirect.Index
1243 * .y = DimIndirect.SwizzleX
1245 if (reg->Dimension.Indirect) {
1246 union tgsi_exec_channel index2;
1247 union tgsi_exec_channel indir_index;
1248 const uint execmask = mach->ExecMask;
1254 index2.i[3] = reg->DimIndirect.Index;
1256 swizzle = reg->DimIndirect.Swizzle;
1257 fetch_src_file_channel(mach,
1259 reg->DimIndirect.File,
1265 index2D.i[0] += indir_index.i[0];
1266 index2D.i[1] += indir_index.i[1];
1267 index2D.i[2] += indir_index.i[2];
1268 index2D.i[3] += indir_index.i[3];
1270 /* for disabled execution channels, zero-out the index to
1271 * avoid using a potential garbage value.
1273 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1274 if ((execmask & (1 << i)) == 0) {
1280 /* If by any chance there was a need for a 3D array of register
1281 * files, we would have to check whether Dimension is followed
1282 * by a dimension register and continue the saga.
1291 swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index );
1292 fetch_src_file_channel(mach,
1300 if (reg->Register.Absolute) {
1301 if (src_datatype == TGSI_EXEC_DATA_FLOAT) {
1302 micro_abs(chan, chan);
1304 micro_iabs(chan, chan);
1308 if (reg->Register.Negate) {
1309 if (src_datatype == TGSI_EXEC_DATA_FLOAT) {
1310 micro_neg(chan, chan);
1312 micro_ineg(chan, chan);
1318 store_dest(struct tgsi_exec_machine *mach,
1319 const union tgsi_exec_channel *chan,
1320 const struct tgsi_full_dst_register *reg,
1321 const struct tgsi_full_instruction *inst,
1323 enum tgsi_exec_datatype dst_datatype)
1326 union tgsi_exec_channel null;
1327 union tgsi_exec_channel *dst;
1328 union tgsi_exec_channel index2D;
1329 uint execmask = mach->ExecMask;
1330 int offset = 0; /* indirection offset */
1334 if (0 && dst_datatype == TGSI_EXEC_DATA_FLOAT) {
1335 check_inf_or_nan(chan);
1338 /* There is an extra source register that indirectly subscripts
1339 * a register file. The direct index now becomes an offset
1340 * that is being added to the indirect register.
1344 * ind = Indirect.File
1345 * [2] = Indirect.Index
1346 * .x = Indirect.SwizzleX
1348 if (reg->Register.Indirect) {
1349 union tgsi_exec_channel index;
1350 union tgsi_exec_channel indir_index;
1353 /* which address register (always zero for now) */
1357 index.i[3] = reg->Indirect.Index;
1359 /* get current value of address register[swizzle] */
1360 swizzle = reg->Indirect.Swizzle;
1362 /* fetch values from the address/indirection register */
1363 fetch_src_file_channel(mach,
1371 /* save indirection offset */
1372 offset = indir_index.i[0];
1375 /* There is an extra source register that is a second
1376 * subscript to a register file. Effectively it means that
1377 * the register file is actually a 2D array of registers.
1381 * [3] = Dimension.Index
1383 if (reg->Register.Dimension) {
1387 index2D.i[3] = reg->Dimension.Index;
1389 /* Again, the second subscript index can be addressed indirectly
1390 * identically to the first one.
1391 * Nothing stops us from indirectly addressing the indirect register,
1392 * but there is no need for that, so we won't exercise it.
1394 * file[ind[4].y+3][1],
1396 * ind = DimIndirect.File
1397 * [4] = DimIndirect.Index
1398 * .y = DimIndirect.SwizzleX
1400 if (reg->Dimension.Indirect) {
1401 union tgsi_exec_channel index2;
1402 union tgsi_exec_channel indir_index;
1403 const uint execmask = mach->ExecMask;
1410 index2.i[3] = reg->DimIndirect.Index;
1412 swizzle = reg->DimIndirect.Swizzle;
1413 fetch_src_file_channel(mach,
1415 reg->DimIndirect.File,
1421 index2D.i[0] += indir_index.i[0];
1422 index2D.i[1] += indir_index.i[1];
1423 index2D.i[2] += indir_index.i[2];
1424 index2D.i[3] += indir_index.i[3];
1426 /* for disabled execution channels, zero-out the index to
1427 * avoid using a potential garbage value.
1429 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1430 if ((execmask & (1 << i)) == 0) {
1436 /* If by any chance there was a need for a 3D array of register
1437 * files, we would have to check whether Dimension is followed
1438 * by a dimension register and continue the saga.
1447 switch (reg->Register.File) {
1448 case TGSI_FILE_NULL:
1452 case TGSI_FILE_OUTPUT:
1453 index = mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0]
1454 + reg->Register.Index;
1455 dst = &mach->Outputs[offset + index].xyzw[chan_index];
1457 debug_printf("NumOutputs = %d, TEMP_O_C/I = %d, redindex = %d\n",
1458 mach->NumOutputs, mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0],
1459 reg->Register.Index);
1460 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1461 debug_printf("STORING OUT[%d] mask(%d), = (", offset + index, execmask);
1462 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1463 if (execmask & (1 << i))
1464 debug_printf("%f, ", chan->f[i]);
1465 debug_printf(")\n");
1470 case TGSI_FILE_TEMPORARY:
1471 index = reg->Register.Index;
1472 assert( index < TGSI_EXEC_NUM_TEMPS );
1473 dst = &mach->Temps[offset + index].xyzw[chan_index];
1476 case TGSI_FILE_ADDRESS:
1477 index = reg->Register.Index;
1478 dst = &mach->Addrs[index].xyzw[chan_index];
1481 case TGSI_FILE_PREDICATE:
1482 index = reg->Register.Index;
1483 assert(index < TGSI_EXEC_NUM_PREDS);
1484 dst = &mach->Predicates[index].xyzw[chan_index];
1492 if (inst->Instruction.Predicate) {
1494 union tgsi_exec_channel *pred;
1496 switch (chan_index) {
1498 swizzle = inst->Predicate.SwizzleX;
1501 swizzle = inst->Predicate.SwizzleY;
1504 swizzle = inst->Predicate.SwizzleZ;
1507 swizzle = inst->Predicate.SwizzleW;
1514 assert(inst->Predicate.Index == 0);
1516 pred = &mach->Predicates[inst->Predicate.Index].xyzw[swizzle];
1518 if (inst->Predicate.Negate) {
1519 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1521 execmask &= ~(1 << i);
1525 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
1527 execmask &= ~(1 << i);
1533 switch (inst->Instruction.Saturate) {
1535 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1536 if (execmask & (1 << i))
1537 dst->i[i] = chan->i[i];
1540 case TGSI_SAT_ZERO_ONE:
1541 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1542 if (execmask & (1 << i)) {
1543 if (chan->f[i] < 0.0f)
1545 else if (chan->f[i] > 1.0f)
1548 dst->i[i] = chan->i[i];
1552 case TGSI_SAT_MINUS_PLUS_ONE:
1553 for (i = 0; i < TGSI_QUAD_SIZE; i++)
1554 if (execmask & (1 << i)) {
1555 if (chan->f[i] < -1.0f)
1557 else if (chan->f[i] > 1.0f)
1560 dst->i[i] = chan->i[i];
1569 #define FETCH(VAL,INDEX,CHAN)\
1570 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1572 #define IFETCH(VAL,INDEX,CHAN)\
1573 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
1577 * Execute ARB-style KIL which is predicated by a src register.
1578 * Kill fragment if any of the four values is less than zero.
1581 exec_kil(struct tgsi_exec_machine *mach,
1582 const struct tgsi_full_instruction *inst)
1586 uint kilmask = 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1587 union tgsi_exec_channel r[1];
1589 /* This mask stores component bits that were already tested. */
1592 for (chan_index = 0; chan_index < 4; chan_index++)
1597 /* unswizzle channel */
1598 swizzle = tgsi_util_get_full_src_register_swizzle (
1602 /* check if the component has not been already tested */
1603 if (uniquemask & (1 << swizzle))
1605 uniquemask |= 1 << swizzle;
1607 FETCH(&r[0], 0, chan_index);
1608 for (i = 0; i < 4; i++)
1609 if (r[0].f[i] < 0.0f)
1613 mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask;
1617 * Execute NVIDIA-style KIL which is predicated by a condition code.
1618 * Kill fragment if the condition code is TRUE.
1621 exec_kilp(struct tgsi_exec_machine *mach,
1622 const struct tgsi_full_instruction *inst)
1624 uint kilmask; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1626 /* "unconditional" kil */
1627 kilmask = mach->ExecMask;
1628 mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask;
1632 emit_vertex(struct tgsi_exec_machine *mach)
1634 /* FIXME: check for exec mask correctly
1636 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1637 if ((mach->ExecMask & (1 << i)))
1639 if (mach->ExecMask) {
1640 mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] += mach->NumOutputs;
1641 mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]]++;
1646 emit_primitive(struct tgsi_exec_machine *mach)
1648 unsigned *prim_count = &mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0];
1649 /* FIXME: check for exec mask correctly
1651 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1652 if ((mach->ExecMask & (1 << i)))
1654 if (mach->ExecMask) {
1656 debug_assert((*prim_count * mach->NumOutputs) < mach->MaxGeometryShaderOutputs);
1657 mach->Primitives[*prim_count] = 0;
1662 conditional_emit_primitive(struct tgsi_exec_machine *mach)
1664 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1666 mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]];
1667 if (emitted_verts) {
1668 emit_primitive(mach);
1675 * Fetch four texture samples using STR texture coordinates.
1678 fetch_texel( struct tgsi_sampler *sampler,
1679 const unsigned sview_idx,
1680 const unsigned sampler_idx,
1681 const union tgsi_exec_channel *s,
1682 const union tgsi_exec_channel *t,
1683 const union tgsi_exec_channel *p,
1684 const union tgsi_exec_channel *c0,
1685 const union tgsi_exec_channel *c1,
1686 float derivs[3][2][TGSI_QUAD_SIZE],
1687 const int8_t offset[3],
1688 enum tgsi_sampler_control control,
1689 union tgsi_exec_channel *r,
1690 union tgsi_exec_channel *g,
1691 union tgsi_exec_channel *b,
1692 union tgsi_exec_channel *a )
1695 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
1697 /* FIXME: handle explicit derivs, offsets */
1698 sampler->get_samples(sampler, sview_idx, sampler_idx,
1699 s->f, t->f, p->f, c0->f, c1->f, derivs, offset, control, rgba);
1701 for (j = 0; j < 4; j++) {
1702 r->f[j] = rgba[0][j];
1703 g->f[j] = rgba[1][j];
1704 b->f[j] = rgba[2][j];
1705 a->f[j] = rgba[3][j];
1710 #define TEX_MODIFIER_NONE 0
1711 #define TEX_MODIFIER_PROJECTED 1
1712 #define TEX_MODIFIER_LOD_BIAS 2
1713 #define TEX_MODIFIER_EXPLICIT_LOD 3
1714 #define TEX_MODIFIER_LEVEL_ZERO 4
1718 * Fetch all 3 (for s,t,r coords) texel offsets, put them into int array.
1721 fetch_texel_offsets(struct tgsi_exec_machine *mach,
1722 const struct tgsi_full_instruction *inst,
1725 if (inst->Texture.NumOffsets == 1) {
1726 union tgsi_exec_channel index;
1727 union tgsi_exec_channel offset[3];
1728 index.i[0] = index.i[1] = index.i[2] = index.i[3] = inst->TexOffsets[0].Index;
1729 fetch_src_file_channel(mach, 0, inst->TexOffsets[0].File,
1730 inst->TexOffsets[0].SwizzleX, &index, &ZeroVec, &offset[0]);
1731 fetch_src_file_channel(mach, 0, inst->TexOffsets[0].File,
1732 inst->TexOffsets[0].SwizzleY, &index, &ZeroVec, &offset[1]);
1733 fetch_src_file_channel(mach, 0, inst->TexOffsets[0].File,
1734 inst->TexOffsets[0].SwizzleZ, &index, &ZeroVec, &offset[2]);
1735 offsets[0] = offset[0].i[0];
1736 offsets[1] = offset[1].i[0];
1737 offsets[2] = offset[2].i[0];
1739 assert(inst->Texture.NumOffsets == 0);
1740 offsets[0] = offsets[1] = offsets[2] = 0;
1746 * Fetch dx and dy values for one channel (s, t or r).
1747 * Put dx values into one float array, dy values into another.
1750 fetch_assign_deriv_channel(struct tgsi_exec_machine *mach,
1751 const struct tgsi_full_instruction *inst,
1754 float derivs[2][TGSI_QUAD_SIZE])
1756 union tgsi_exec_channel d;
1757 FETCH(&d, regdsrcx, chan);
1758 derivs[0][0] = d.f[0];
1759 derivs[0][1] = d.f[1];
1760 derivs[0][2] = d.f[2];
1761 derivs[0][3] = d.f[3];
1762 FETCH(&d, regdsrcx + 1, chan);
1763 derivs[1][0] = d.f[0];
1764 derivs[1][1] = d.f[1];
1765 derivs[1][2] = d.f[2];
1766 derivs[1][3] = d.f[3];
1771 * execute a texture instruction.
1773 * modifier is used to control the channel routing for the\
1774 * instruction variants like proj, lod, and texture with lod bias.
1775 * sampler indicates which src register the sampler is contained in.
1778 exec_tex(struct tgsi_exec_machine *mach,
1779 const struct tgsi_full_instruction *inst,
1780 uint modifier, uint sampler)
1782 const uint unit = inst->Src[sampler].Register.Index;
1783 union tgsi_exec_channel r[4], cubearraycomp, cubelod;
1784 const union tgsi_exec_channel *lod = &ZeroVec;
1785 enum tgsi_sampler_control control = tgsi_sampler_lod_none;
1789 /* always fetch all 3 offsets, overkill but keeps code simple */
1790 fetch_texel_offsets(mach, inst, offsets);
1792 assert(modifier != TEX_MODIFIER_LEVEL_ZERO);
1794 if (modifier != TEX_MODIFIER_NONE && (sampler == 1)) {
1795 FETCH(&r[3], 0, TGSI_CHAN_W);
1796 if (modifier != TEX_MODIFIER_PROJECTED) {
1801 if (modifier == TEX_MODIFIER_EXPLICIT_LOD) {
1802 control = tgsi_sampler_lod_explicit;
1803 } else if (modifier == TEX_MODIFIER_LOD_BIAS){
1804 control = tgsi_sampler_lod_bias;
1807 switch (inst->Texture.Texture) {
1808 case TGSI_TEXTURE_1D:
1809 FETCH(&r[0], 0, TGSI_CHAN_X);
1811 if (modifier == TEX_MODIFIER_PROJECTED) {
1812 micro_div(&r[0], &r[0], &r[3]);
1815 fetch_texel(mach->Sampler, unit, unit,
1816 &r[0], &ZeroVec, &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */
1817 NULL, offsets, control,
1818 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
1821 case TGSI_TEXTURE_SHADOW1D:
1822 FETCH(&r[0], 0, TGSI_CHAN_X);
1823 FETCH(&r[2], 0, TGSI_CHAN_Z);
1825 if (modifier == TEX_MODIFIER_PROJECTED) {
1826 micro_div(&r[0], &r[0], &r[3]);
1827 micro_div(&r[2], &r[2], &r[3]);
1830 fetch_texel(mach->Sampler, unit, unit,
1831 &r[0], &ZeroVec, &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
1832 NULL, offsets, control,
1833 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
1836 case TGSI_TEXTURE_2D:
1837 case TGSI_TEXTURE_RECT:
1838 FETCH(&r[0], 0, TGSI_CHAN_X);
1839 FETCH(&r[1], 0, TGSI_CHAN_Y);
1841 if (modifier == TEX_MODIFIER_PROJECTED) {
1842 micro_div(&r[0], &r[0], &r[3]);
1843 micro_div(&r[1], &r[1], &r[3]);
1846 fetch_texel(mach->Sampler, unit, unit,
1847 &r[0], &r[1], &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */
1848 NULL, offsets, control,
1849 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1852 case TGSI_TEXTURE_SHADOW2D:
1853 case TGSI_TEXTURE_SHADOWRECT:
1854 FETCH(&r[0], 0, TGSI_CHAN_X);
1855 FETCH(&r[1], 0, TGSI_CHAN_Y);
1856 FETCH(&r[2], 0, TGSI_CHAN_Z);
1858 if (modifier == TEX_MODIFIER_PROJECTED) {
1859 micro_div(&r[0], &r[0], &r[3]);
1860 micro_div(&r[1], &r[1], &r[3]);
1861 micro_div(&r[2], &r[2], &r[3]);
1864 fetch_texel(mach->Sampler, unit, unit,
1865 &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
1866 NULL, offsets, control,
1867 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1870 case TGSI_TEXTURE_1D_ARRAY:
1871 FETCH(&r[0], 0, TGSI_CHAN_X);
1872 FETCH(&r[1], 0, TGSI_CHAN_Y);
1874 if (modifier == TEX_MODIFIER_PROJECTED) {
1875 micro_div(&r[0], &r[0], &r[3]);
1878 fetch_texel(mach->Sampler, unit, unit,
1879 &r[0], &r[1], &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */
1880 NULL, offsets, control,
1881 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1883 case TGSI_TEXTURE_SHADOW1D_ARRAY:
1884 FETCH(&r[0], 0, TGSI_CHAN_X);
1885 FETCH(&r[1], 0, TGSI_CHAN_Y);
1886 FETCH(&r[2], 0, TGSI_CHAN_Z);
1888 if (modifier == TEX_MODIFIER_PROJECTED) {
1889 micro_div(&r[0], &r[0], &r[3]);
1890 micro_div(&r[2], &r[2], &r[3]);
1893 fetch_texel(mach->Sampler, unit, unit,
1894 &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
1895 NULL, offsets, control,
1896 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1899 case TGSI_TEXTURE_2D_ARRAY:
1900 FETCH(&r[0], 0, TGSI_CHAN_X);
1901 FETCH(&r[1], 0, TGSI_CHAN_Y);
1902 FETCH(&r[2], 0, TGSI_CHAN_Z);
1904 if (modifier == TEX_MODIFIER_PROJECTED) {
1905 micro_div(&r[0], &r[0], &r[3]);
1906 micro_div(&r[1], &r[1], &r[3]);
1909 fetch_texel(mach->Sampler, unit, unit,
1910 &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
1911 NULL, offsets, control,
1912 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1914 case TGSI_TEXTURE_SHADOW2D_ARRAY:
1915 case TGSI_TEXTURE_SHADOWCUBE:
1916 FETCH(&r[0], 0, TGSI_CHAN_X);
1917 FETCH(&r[1], 0, TGSI_CHAN_Y);
1918 FETCH(&r[2], 0, TGSI_CHAN_Z);
1919 FETCH(&r[3], 0, TGSI_CHAN_W);
1921 fetch_texel(mach->Sampler, unit, unit,
1922 &r[0], &r[1], &r[2], &r[3], &ZeroVec, /* S, T, P, C, LOD */
1923 NULL, offsets, control,
1924 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1926 case TGSI_TEXTURE_CUBE_ARRAY:
1927 FETCH(&r[0], 0, TGSI_CHAN_X);
1928 FETCH(&r[1], 0, TGSI_CHAN_Y);
1929 FETCH(&r[2], 0, TGSI_CHAN_Z);
1930 FETCH(&r[3], 0, TGSI_CHAN_W);
1932 if (modifier == TEX_MODIFIER_EXPLICIT_LOD ||
1933 modifier == TEX_MODIFIER_LOD_BIAS)
1934 FETCH(&cubelod, 1, TGSI_CHAN_X);
1938 fetch_texel(mach->Sampler, unit, unit,
1939 &r[0], &r[1], &r[2], &r[3], &cubelod, /* S, T, P, C, LOD */
1940 NULL, offsets, control,
1941 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1943 case TGSI_TEXTURE_3D:
1944 case TGSI_TEXTURE_CUBE:
1945 FETCH(&r[0], 0, TGSI_CHAN_X);
1946 FETCH(&r[1], 0, TGSI_CHAN_Y);
1947 FETCH(&r[2], 0, TGSI_CHAN_Z);
1949 if (modifier == TEX_MODIFIER_PROJECTED) {
1950 micro_div(&r[0], &r[0], &r[3]);
1951 micro_div(&r[1], &r[1], &r[3]);
1952 micro_div(&r[2], &r[2], &r[3]);
1955 fetch_texel(mach->Sampler, unit, unit,
1956 &r[0], &r[1], &r[2], &ZeroVec, lod,
1957 NULL, offsets, control,
1958 &r[0], &r[1], &r[2], &r[3]);
1961 case TGSI_TEXTURE_SHADOWCUBE_ARRAY:
1962 FETCH(&r[0], 0, TGSI_CHAN_X);
1963 FETCH(&r[1], 0, TGSI_CHAN_Y);
1964 FETCH(&r[2], 0, TGSI_CHAN_Z);
1965 FETCH(&r[3], 0, TGSI_CHAN_W);
1967 FETCH(&cubearraycomp, 1, TGSI_CHAN_X);
1969 fetch_texel(mach->Sampler, unit, unit,
1970 &r[0], &r[1], &r[2], &r[3], &cubearraycomp, /* S, T, P, C, LOD */
1971 NULL, offsets, control,
1972 &r[0], &r[1], &r[2], &r[3]); /* outputs */
1979 debug_printf("fetch r: %g %g %g %g\n",
1980 r[0].f[0], r[0].f[1], r[0].f[2], r[0].f[3]);
1981 debug_printf("fetch g: %g %g %g %g\n",
1982 r[1].f[0], r[1].f[1], r[1].f[2], r[1].f[3]);
1983 debug_printf("fetch b: %g %g %g %g\n",
1984 r[2].f[0], r[2].f[1], r[2].f[2], r[2].f[3]);
1985 debug_printf("fetch a: %g %g %g %g\n",
1986 r[3].f[0], r[3].f[1], r[3].f[2], r[3].f[3]);
1989 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
1990 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
1991 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
1998 exec_txd(struct tgsi_exec_machine *mach,
1999 const struct tgsi_full_instruction *inst)
2001 const uint unit = inst->Src[3].Register.Index;
2002 union tgsi_exec_channel r[4];
2003 float derivs[3][2][TGSI_QUAD_SIZE];
2007 /* always fetch all 3 offsets, overkill but keeps code simple */
2008 fetch_texel_offsets(mach, inst, offsets);
2010 switch (inst->Texture.Texture) {
2011 case TGSI_TEXTURE_1D:
2012 FETCH(&r[0], 0, TGSI_CHAN_X);
2014 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2016 fetch_texel(mach->Sampler, unit, unit,
2017 &r[0], &ZeroVec, &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2018 derivs, offsets, tgsi_sampler_derivs_explicit,
2019 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2022 case TGSI_TEXTURE_SHADOW1D:
2023 case TGSI_TEXTURE_1D_ARRAY:
2024 case TGSI_TEXTURE_SHADOW1D_ARRAY:
2025 /* SHADOW1D/1D_ARRAY would not need Y/Z respectively, but don't bother */
2026 FETCH(&r[0], 0, TGSI_CHAN_X);
2027 FETCH(&r[1], 0, TGSI_CHAN_Y);
2028 FETCH(&r[2], 0, TGSI_CHAN_Z);
2030 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2032 fetch_texel(mach->Sampler, unit, unit,
2033 &r[0], &r[1], &r[2], &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2034 derivs, offsets, tgsi_sampler_derivs_explicit,
2035 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2038 case TGSI_TEXTURE_2D:
2039 case TGSI_TEXTURE_RECT:
2040 FETCH(&r[0], 0, TGSI_CHAN_X);
2041 FETCH(&r[1], 0, TGSI_CHAN_Y);
2043 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2044 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Y, derivs[1]);
2046 fetch_texel(mach->Sampler, unit, unit,
2047 &r[0], &r[1], &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2048 derivs, offsets, tgsi_sampler_derivs_explicit,
2049 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2053 case TGSI_TEXTURE_SHADOW2D:
2054 case TGSI_TEXTURE_SHADOWRECT:
2055 case TGSI_TEXTURE_2D_ARRAY:
2056 case TGSI_TEXTURE_SHADOW2D_ARRAY:
2057 /* only SHADOW2D_ARRAY actually needs W */
2058 FETCH(&r[0], 0, TGSI_CHAN_X);
2059 FETCH(&r[1], 0, TGSI_CHAN_Y);
2060 FETCH(&r[2], 0, TGSI_CHAN_Z);
2061 FETCH(&r[3], 0, TGSI_CHAN_W);
2063 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2064 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Y, derivs[1]);
2066 fetch_texel(mach->Sampler, unit, unit,
2067 &r[0], &r[1], &r[2], &r[3], &ZeroVec, /* inputs */
2068 derivs, offsets, tgsi_sampler_derivs_explicit,
2069 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2072 case TGSI_TEXTURE_3D:
2073 case TGSI_TEXTURE_CUBE:
2074 case TGSI_TEXTURE_CUBE_ARRAY:
2075 /* only TEXTURE_CUBE_ARRAY actually needs W */
2076 FETCH(&r[0], 0, TGSI_CHAN_X);
2077 FETCH(&r[1], 0, TGSI_CHAN_Y);
2078 FETCH(&r[2], 0, TGSI_CHAN_Z);
2079 FETCH(&r[3], 0, TGSI_CHAN_W);
2081 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_X, derivs[0]);
2082 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Y, derivs[1]);
2083 fetch_assign_deriv_channel(mach, inst, 1, TGSI_CHAN_Z, derivs[2]);
2085 fetch_texel(mach->Sampler, unit, unit,
2086 &r[0], &r[1], &r[2], &r[3], &ZeroVec, /* inputs */
2087 derivs, offsets, tgsi_sampler_derivs_explicit,
2088 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2095 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2096 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2097 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2104 exec_txf(struct tgsi_exec_machine *mach,
2105 const struct tgsi_full_instruction *inst)
2107 const uint unit = inst->Src[1].Register.Index;
2108 union tgsi_exec_channel r[4];
2110 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE];
2115 /* always fetch all 3 offsets, overkill but keeps code simple */
2116 fetch_texel_offsets(mach, inst, offsets);
2118 IFETCH(&r[3], 0, TGSI_CHAN_W);
2120 if (inst->Instruction.Opcode == TGSI_OPCODE_SAMPLE_I) {
2121 target = mach->SamplerViews[unit].Resource;
2124 target = inst->Texture.Texture;
2127 case TGSI_TEXTURE_3D:
2128 case TGSI_TEXTURE_2D_ARRAY:
2129 case TGSI_TEXTURE_SHADOW2D_ARRAY:
2130 IFETCH(&r[2], 0, TGSI_CHAN_Z);
2132 case TGSI_TEXTURE_2D:
2133 case TGSI_TEXTURE_RECT:
2134 case TGSI_TEXTURE_SHADOW1D_ARRAY:
2135 case TGSI_TEXTURE_SHADOW2D:
2136 case TGSI_TEXTURE_SHADOWRECT:
2137 case TGSI_TEXTURE_1D_ARRAY:
2138 IFETCH(&r[1], 0, TGSI_CHAN_Y);
2140 case TGSI_TEXTURE_BUFFER:
2141 case TGSI_TEXTURE_1D:
2142 case TGSI_TEXTURE_SHADOW1D:
2143 IFETCH(&r[0], 0, TGSI_CHAN_X);
2150 mach->Sampler->get_texel(mach->Sampler, unit, r[0].i, r[1].i, r[2].i, r[3].i,
2153 for (j = 0; j < TGSI_QUAD_SIZE; j++) {
2154 r[0].f[j] = rgba[0][j];
2155 r[1].f[j] = rgba[1][j];
2156 r[2].f[j] = rgba[2][j];
2157 r[3].f[j] = rgba[3][j];
2160 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2161 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2162 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2168 exec_txq(struct tgsi_exec_machine *mach,
2169 const struct tgsi_full_instruction *inst)
2171 const uint unit = inst->Src[1].Register.Index;
2173 union tgsi_exec_channel r[4], src;
2177 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_INT);
2179 mach->Sampler->get_dims(mach->Sampler, unit, src.i[0], result);
2181 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
2182 for (j = 0; j < 4; j++) {
2183 r[j].i[i] = result[j];
2187 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2188 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2189 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan,
2190 TGSI_EXEC_DATA_INT);
2196 exec_sample(struct tgsi_exec_machine *mach,
2197 const struct tgsi_full_instruction *inst,
2198 uint modifier, boolean compare)
2200 const uint resource_unit = inst->Src[1].Register.Index;
2201 const uint sampler_unit = inst->Src[2].Register.Index;
2202 union tgsi_exec_channel r[4], c1;
2203 const union tgsi_exec_channel *lod = &ZeroVec;
2204 enum tgsi_sampler_control control = tgsi_sampler_lod_none;
2208 /* always fetch all 3 offsets, overkill but keeps code simple */
2209 fetch_texel_offsets(mach, inst, offsets);
2211 assert(modifier != TEX_MODIFIER_PROJECTED);
2213 if (modifier != TEX_MODIFIER_NONE) {
2214 if (modifier == TEX_MODIFIER_LOD_BIAS) {
2215 FETCH(&c1, 3, TGSI_CHAN_X);
2217 control = tgsi_sampler_lod_bias;
2219 else if (modifier == TEX_MODIFIER_EXPLICIT_LOD) {
2220 FETCH(&c1, 3, TGSI_CHAN_X);
2222 control = tgsi_sampler_lod_explicit;
2225 assert(modifier == TEX_MODIFIER_LEVEL_ZERO);
2226 control = tgsi_sampler_lod_zero;
2230 FETCH(&r[0], 0, TGSI_CHAN_X);
2232 switch (mach->SamplerViews[resource_unit].Resource) {
2233 case TGSI_TEXTURE_1D:
2235 FETCH(&r[2], 3, TGSI_CHAN_X);
2236 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2237 &r[0], &ZeroVec, &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
2238 NULL, offsets, control,
2239 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2242 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2243 &r[0], &ZeroVec, &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */
2244 NULL, offsets, control,
2245 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2249 case TGSI_TEXTURE_1D_ARRAY:
2250 case TGSI_TEXTURE_2D:
2251 case TGSI_TEXTURE_RECT:
2252 FETCH(&r[1], 0, TGSI_CHAN_Y);
2254 FETCH(&r[2], 3, TGSI_CHAN_X);
2255 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2256 &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */
2257 NULL, offsets, control,
2258 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2261 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2262 &r[0], &r[1], &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */
2263 NULL, offsets, control,
2264 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2268 case TGSI_TEXTURE_2D_ARRAY:
2269 case TGSI_TEXTURE_3D:
2270 case TGSI_TEXTURE_CUBE:
2271 FETCH(&r[1], 0, TGSI_CHAN_Y);
2272 FETCH(&r[2], 0, TGSI_CHAN_Z);
2274 FETCH(&r[3], 3, TGSI_CHAN_X);
2275 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2276 &r[0], &r[1], &r[2], &r[3], lod,
2277 NULL, offsets, control,
2278 &r[0], &r[1], &r[2], &r[3]);
2281 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2282 &r[0], &r[1], &r[2], &ZeroVec, lod,
2283 NULL, offsets, control,
2284 &r[0], &r[1], &r[2], &r[3]);
2288 case TGSI_TEXTURE_CUBE_ARRAY:
2289 FETCH(&r[1], 0, TGSI_CHAN_Y);
2290 FETCH(&r[2], 0, TGSI_CHAN_Z);
2291 FETCH(&r[3], 0, TGSI_CHAN_W);
2293 FETCH(&r[4], 3, TGSI_CHAN_X);
2294 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2295 &r[0], &r[1], &r[2], &r[3], &r[4],
2296 NULL, offsets, control,
2297 &r[0], &r[1], &r[2], &r[3]);
2300 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2301 &r[0], &r[1], &r[2], &r[3], lod,
2302 NULL, offsets, control,
2303 &r[0], &r[1], &r[2], &r[3]);
2312 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2313 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2314 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2320 exec_sample_d(struct tgsi_exec_machine *mach,
2321 const struct tgsi_full_instruction *inst)
2323 const uint resource_unit = inst->Src[1].Register.Index;
2324 const uint sampler_unit = inst->Src[2].Register.Index;
2325 union tgsi_exec_channel r[4];
2326 float derivs[3][2][TGSI_QUAD_SIZE];
2330 /* always fetch all 3 offsets, overkill but keeps code simple */
2331 fetch_texel_offsets(mach, inst, offsets);
2333 FETCH(&r[0], 0, TGSI_CHAN_X);
2335 switch (mach->SamplerViews[resource_unit].Resource) {
2336 case TGSI_TEXTURE_1D:
2337 case TGSI_TEXTURE_1D_ARRAY:
2338 /* only 1D array actually needs Y */
2339 FETCH(&r[1], 0, TGSI_CHAN_Y);
2341 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_X, derivs[0]);
2343 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2344 &r[0], &r[1], &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */
2345 derivs, offsets, tgsi_sampler_derivs_explicit,
2346 &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
2349 case TGSI_TEXTURE_2D:
2350 case TGSI_TEXTURE_RECT:
2351 case TGSI_TEXTURE_2D_ARRAY:
2352 /* only 2D array actually needs Z */
2353 FETCH(&r[1], 0, TGSI_CHAN_Y);
2354 FETCH(&r[2], 0, TGSI_CHAN_Z);
2356 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_X, derivs[0]);
2357 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_Y, derivs[1]);
2359 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2360 &r[0], &r[1], &r[2], &ZeroVec, &ZeroVec, /* inputs */
2361 derivs, offsets, tgsi_sampler_derivs_explicit,
2362 &r[0], &r[1], &r[2], &r[3]); /* outputs */
2365 case TGSI_TEXTURE_3D:
2366 case TGSI_TEXTURE_CUBE:
2367 case TGSI_TEXTURE_CUBE_ARRAY:
2368 /* only cube array actually needs W */
2369 FETCH(&r[1], 0, TGSI_CHAN_Y);
2370 FETCH(&r[2], 0, TGSI_CHAN_Z);
2371 FETCH(&r[3], 0, TGSI_CHAN_W);
2373 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_X, derivs[0]);
2374 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_Y, derivs[1]);
2375 fetch_assign_deriv_channel(mach, inst, 3, TGSI_CHAN_Z, derivs[2]);
2377 fetch_texel(mach->Sampler, resource_unit, sampler_unit,
2378 &r[0], &r[1], &r[2], &r[3], &ZeroVec,
2379 derivs, offsets, tgsi_sampler_derivs_explicit,
2380 &r[0], &r[1], &r[2], &r[3]);
2387 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2388 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2389 store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2396 * Evaluate a constant-valued coefficient at the position of the
2401 struct tgsi_exec_machine *mach,
2407 for( i = 0; i < TGSI_QUAD_SIZE; i++ ) {
2408 mach->Inputs[attrib].xyzw[chan].f[i] = mach->InterpCoefs[attrib].a0[chan];
2413 * Evaluate a linear-valued coefficient at the position of the
2418 struct tgsi_exec_machine *mach,
2422 const float x = mach->QuadPos.xyzw[0].f[0];
2423 const float y = mach->QuadPos.xyzw[1].f[0];
2424 const float dadx = mach->InterpCoefs[attrib].dadx[chan];
2425 const float dady = mach->InterpCoefs[attrib].dady[chan];
2426 const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y;
2427 mach->Inputs[attrib].xyzw[chan].f[0] = a0;
2428 mach->Inputs[attrib].xyzw[chan].f[1] = a0 + dadx;
2429 mach->Inputs[attrib].xyzw[chan].f[2] = a0 + dady;
2430 mach->Inputs[attrib].xyzw[chan].f[3] = a0 + dadx + dady;
2434 * Evaluate a perspective-valued coefficient at the position of the
2438 eval_perspective_coef(
2439 struct tgsi_exec_machine *mach,
2443 const float x = mach->QuadPos.xyzw[0].f[0];
2444 const float y = mach->QuadPos.xyzw[1].f[0];
2445 const float dadx = mach->InterpCoefs[attrib].dadx[chan];
2446 const float dady = mach->InterpCoefs[attrib].dady[chan];
2447 const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y;
2448 const float *w = mach->QuadPos.xyzw[3].f;
2449 /* divide by W here */
2450 mach->Inputs[attrib].xyzw[chan].f[0] = a0 / w[0];
2451 mach->Inputs[attrib].xyzw[chan].f[1] = (a0 + dadx) / w[1];
2452 mach->Inputs[attrib].xyzw[chan].f[2] = (a0 + dady) / w[2];
2453 mach->Inputs[attrib].xyzw[chan].f[3] = (a0 + dadx + dady) / w[3];
2457 typedef void (* eval_coef_func)(
2458 struct tgsi_exec_machine *mach,
2463 exec_declaration(struct tgsi_exec_machine *mach,
2464 const struct tgsi_full_declaration *decl)
2466 if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
2467 mach->SamplerViews[decl->Range.First] = decl->SamplerView;
2471 if (mach->Processor == TGSI_PROCESSOR_FRAGMENT) {
2472 if (decl->Declaration.File == TGSI_FILE_INPUT) {
2473 uint first, last, mask;
2475 first = decl->Range.First;
2476 last = decl->Range.Last;
2477 mask = decl->Declaration.UsageMask;
2479 /* XXX we could remove this special-case code since
2480 * mach->InterpCoefs[first].a0 should already have the
2481 * front/back-face value. But we should first update the
2482 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2483 * Then, we could remove the tgsi_exec_machine::Face field.
2485 /* XXX make FACE a system value */
2486 if (decl->Semantic.Name == TGSI_SEMANTIC_FACE) {
2489 assert(decl->Semantic.Index == 0);
2490 assert(first == last);
2492 for (i = 0; i < TGSI_QUAD_SIZE; i++) {
2493 mach->Inputs[first].xyzw[0].f[i] = mach->Face;
2496 eval_coef_func eval;
2499 switch (decl->Interp.Interpolate) {
2500 case TGSI_INTERPOLATE_CONSTANT:
2501 eval = eval_constant_coef;
2504 case TGSI_INTERPOLATE_LINEAR:
2505 eval = eval_linear_coef;
2508 case TGSI_INTERPOLATE_PERSPECTIVE:
2509 eval = eval_perspective_coef;
2512 case TGSI_INTERPOLATE_COLOR:
2513 eval = mach->flatshade_color ? eval_constant_coef : eval_perspective_coef;
2521 for (j = 0; j < TGSI_NUM_CHANNELS; j++) {
2522 if (mask & (1 << j)) {
2523 for (i = first; i <= last; i++) {
2530 if (DEBUG_EXECUTION) {
2532 for (i = first; i <= last; ++i) {
2533 debug_printf("IN[%2u] = ", i);
2534 for (j = 0; j < TGSI_NUM_CHANNELS; j++) {
2538 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
2539 mach->Inputs[i].xyzw[0].f[j], mach->Inputs[i].xyzw[0].u[j],
2540 mach->Inputs[i].xyzw[1].f[j], mach->Inputs[i].xyzw[1].u[j],
2541 mach->Inputs[i].xyzw[2].f[j], mach->Inputs[i].xyzw[2].u[j],
2542 mach->Inputs[i].xyzw[3].f[j], mach->Inputs[i].xyzw[3].u[j]);
2549 if (decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE) {
2550 mach->SysSemanticToIndex[decl->Declaration.Semantic] = decl->Range.First;
2555 typedef void (* micro_op)(union tgsi_exec_channel *dst);
2558 exec_vector(struct tgsi_exec_machine *mach,
2559 const struct tgsi_full_instruction *inst,
2561 enum tgsi_exec_datatype dst_datatype)
2565 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2566 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2567 union tgsi_exec_channel dst;
2570 store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype);
2575 typedef void (* micro_unary_op)(union tgsi_exec_channel *dst,
2576 const union tgsi_exec_channel *src);
2579 exec_scalar_unary(struct tgsi_exec_machine *mach,
2580 const struct tgsi_full_instruction *inst,
2582 enum tgsi_exec_datatype dst_datatype,
2583 enum tgsi_exec_datatype src_datatype)
2586 union tgsi_exec_channel src;
2587 union tgsi_exec_channel dst;
2589 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, src_datatype);
2591 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2592 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2593 store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype);
2599 exec_vector_unary(struct tgsi_exec_machine *mach,
2600 const struct tgsi_full_instruction *inst,
2602 enum tgsi_exec_datatype dst_datatype,
2603 enum tgsi_exec_datatype src_datatype)
2606 struct tgsi_exec_vector dst;
2608 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2609 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2610 union tgsi_exec_channel src;
2612 fetch_source(mach, &src, &inst->Src[0], chan, src_datatype);
2613 op(&dst.xyzw[chan], &src);
2616 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2617 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2618 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype);
2623 typedef void (* micro_binary_op)(union tgsi_exec_channel *dst,
2624 const union tgsi_exec_channel *src0,
2625 const union tgsi_exec_channel *src1);
2628 exec_scalar_binary(struct tgsi_exec_machine *mach,
2629 const struct tgsi_full_instruction *inst,
2631 enum tgsi_exec_datatype dst_datatype,
2632 enum tgsi_exec_datatype src_datatype)
2635 union tgsi_exec_channel src[2];
2636 union tgsi_exec_channel dst;
2638 fetch_source(mach, &src[0], &inst->Src[0], TGSI_CHAN_X, src_datatype);
2639 fetch_source(mach, &src[1], &inst->Src[1], TGSI_CHAN_Y, src_datatype);
2640 op(&dst, &src[0], &src[1]);
2641 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2642 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2643 store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype);
2649 exec_vector_binary(struct tgsi_exec_machine *mach,
2650 const struct tgsi_full_instruction *inst,
2652 enum tgsi_exec_datatype dst_datatype,
2653 enum tgsi_exec_datatype src_datatype)
2656 struct tgsi_exec_vector dst;
2658 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2659 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2660 union tgsi_exec_channel src[2];
2662 fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype);
2663 fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype);
2664 op(&dst.xyzw[chan], &src[0], &src[1]);
2667 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2668 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2669 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype);
2674 typedef void (* micro_trinary_op)(union tgsi_exec_channel *dst,
2675 const union tgsi_exec_channel *src0,
2676 const union tgsi_exec_channel *src1,
2677 const union tgsi_exec_channel *src2);
2680 exec_vector_trinary(struct tgsi_exec_machine *mach,
2681 const struct tgsi_full_instruction *inst,
2682 micro_trinary_op op,
2683 enum tgsi_exec_datatype dst_datatype,
2684 enum tgsi_exec_datatype src_datatype)
2687 struct tgsi_exec_vector dst;
2689 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2690 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2691 union tgsi_exec_channel src[3];
2693 fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype);
2694 fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype);
2695 fetch_source(mach, &src[2], &inst->Src[2], chan, src_datatype);
2696 op(&dst.xyzw[chan], &src[0], &src[1], &src[2]);
2699 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2700 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2701 store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype);
2707 exec_dp3(struct tgsi_exec_machine *mach,
2708 const struct tgsi_full_instruction *inst)
2711 union tgsi_exec_channel arg[3];
2713 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2714 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2715 micro_mul(&arg[2], &arg[0], &arg[1]);
2717 for (chan = TGSI_CHAN_Y; chan <= TGSI_CHAN_Z; chan++) {
2718 fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT);
2719 fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT);
2720 micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]);
2723 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2724 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2725 store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2731 exec_dp4(struct tgsi_exec_machine *mach,
2732 const struct tgsi_full_instruction *inst)
2735 union tgsi_exec_channel arg[3];
2737 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2738 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2739 micro_mul(&arg[2], &arg[0], &arg[1]);
2741 for (chan = TGSI_CHAN_Y; chan <= TGSI_CHAN_W; chan++) {
2742 fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT);
2743 fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT);
2744 micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]);
2747 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2748 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2749 store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2755 exec_dp2a(struct tgsi_exec_machine *mach,
2756 const struct tgsi_full_instruction *inst)
2759 union tgsi_exec_channel arg[3];
2761 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2762 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2763 micro_mul(&arg[2], &arg[0], &arg[1]);
2765 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2766 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2767 micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]);
2769 fetch_source(mach, &arg[1], &inst->Src[2], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2770 micro_add(&arg[0], &arg[0], &arg[1]);
2772 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2773 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2774 store_dest(mach, &arg[0], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2780 exec_dph(struct tgsi_exec_machine *mach,
2781 const struct tgsi_full_instruction *inst)
2784 union tgsi_exec_channel arg[3];
2786 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2787 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2788 micro_mul(&arg[2], &arg[0], &arg[1]);
2790 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2791 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2792 micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]);
2794 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
2795 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
2796 micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]);
2798 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
2799 micro_add(&arg[0], &arg[0], &arg[1]);
2801 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2802 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2803 store_dest(mach, &arg[0], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2809 exec_dp2(struct tgsi_exec_machine *mach,
2810 const struct tgsi_full_instruction *inst)
2813 union tgsi_exec_channel arg[3];
2815 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2816 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2817 micro_mul(&arg[2], &arg[0], &arg[1]);
2819 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2820 fetch_source(mach, &arg[1], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2821 micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]);
2823 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
2824 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2825 store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2831 exec_nrm4(struct tgsi_exec_machine *mach,
2832 const struct tgsi_full_instruction *inst)
2835 union tgsi_exec_channel arg[4];
2836 union tgsi_exec_channel scale;
2838 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2839 micro_mul(&scale, &arg[0], &arg[0]);
2841 for (chan = TGSI_CHAN_Y; chan <= TGSI_CHAN_W; chan++) {
2842 union tgsi_exec_channel product;
2844 fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT);
2845 micro_mul(&product, &arg[chan], &arg[chan]);
2846 micro_add(&scale, &scale, &product);
2849 micro_rsq(&scale, &scale);
2851 for (chan = TGSI_CHAN_X; chan <= TGSI_CHAN_W; chan++) {
2852 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2853 micro_mul(&arg[chan], &arg[chan], &scale);
2854 store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2860 exec_nrm3(struct tgsi_exec_machine *mach,
2861 const struct tgsi_full_instruction *inst)
2863 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XYZ) {
2865 union tgsi_exec_channel arg[3];
2866 union tgsi_exec_channel scale;
2868 fetch_source(mach, &arg[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2869 micro_mul(&scale, &arg[0], &arg[0]);
2871 for (chan = TGSI_CHAN_Y; chan <= TGSI_CHAN_Z; chan++) {
2872 union tgsi_exec_channel product;
2874 fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT);
2875 micro_mul(&product, &arg[chan], &arg[chan]);
2876 micro_add(&scale, &scale, &product);
2879 micro_rsq(&scale, &scale);
2881 for (chan = TGSI_CHAN_X; chan <= TGSI_CHAN_Z; chan++) {
2882 if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
2883 micro_mul(&arg[chan], &arg[chan], &scale);
2884 store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
2889 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
2890 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
2895 exec_scs(struct tgsi_exec_machine *mach,
2896 const struct tgsi_full_instruction *inst)
2898 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY) {
2899 union tgsi_exec_channel arg;
2900 union tgsi_exec_channel result;
2902 fetch_source(mach, &arg, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2904 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
2905 micro_cos(&result, &arg);
2906 store_dest(mach, &result, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2908 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
2909 micro_sin(&result, &arg);
2910 store_dest(mach, &result, &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2913 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
2914 store_dest(mach, &ZeroVec, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
2916 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
2917 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
2922 exec_x2d(struct tgsi_exec_machine *mach,
2923 const struct tgsi_full_instruction *inst)
2925 union tgsi_exec_channel r[4];
2926 union tgsi_exec_channel d[2];
2928 fetch_source(mach, &r[0], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2929 fetch_source(mach, &r[1], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2930 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XZ) {
2931 fetch_source(mach, &r[2], &inst->Src[2], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2932 micro_mul(&r[2], &r[2], &r[0]);
2933 fetch_source(mach, &r[3], &inst->Src[2], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2934 micro_mul(&r[3], &r[3], &r[1]);
2935 micro_add(&r[2], &r[2], &r[3]);
2936 fetch_source(mach, &r[3], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2937 micro_add(&d[0], &r[2], &r[3]);
2939 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_YW) {
2940 fetch_source(mach, &r[2], &inst->Src[2], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
2941 micro_mul(&r[2], &r[2], &r[0]);
2942 fetch_source(mach, &r[3], &inst->Src[2], TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
2943 micro_mul(&r[3], &r[3], &r[1]);
2944 micro_add(&r[2], &r[2], &r[3]);
2945 fetch_source(mach, &r[3], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2946 micro_add(&d[1], &r[2], &r[3]);
2948 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
2949 store_dest(mach, &d[0], &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2951 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
2952 store_dest(mach, &d[1], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2954 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
2955 store_dest(mach, &d[0], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
2957 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
2958 store_dest(mach, &d[1], &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
2963 exec_rfl(struct tgsi_exec_machine *mach,
2964 const struct tgsi_full_instruction *inst)
2966 union tgsi_exec_channel r[9];
2968 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XYZ) {
2969 /* r0 = dp3(src0, src0) */
2970 fetch_source(mach, &r[2], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2971 micro_mul(&r[0], &r[2], &r[2]);
2972 fetch_source(mach, &r[4], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2973 micro_mul(&r[8], &r[4], &r[4]);
2974 micro_add(&r[0], &r[0], &r[8]);
2975 fetch_source(mach, &r[6], &inst->Src[0], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
2976 micro_mul(&r[8], &r[6], &r[6]);
2977 micro_add(&r[0], &r[0], &r[8]);
2979 /* r1 = dp3(src0, src1) */
2980 fetch_source(mach, &r[3], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2981 micro_mul(&r[1], &r[2], &r[3]);
2982 fetch_source(mach, &r[5], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
2983 micro_mul(&r[8], &r[4], &r[5]);
2984 micro_add(&r[1], &r[1], &r[8]);
2985 fetch_source(mach, &r[7], &inst->Src[1], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
2986 micro_mul(&r[8], &r[6], &r[7]);
2987 micro_add(&r[1], &r[1], &r[8]);
2989 /* r1 = 2 * r1 / r0 */
2990 micro_add(&r[1], &r[1], &r[1]);
2991 micro_div(&r[1], &r[1], &r[0]);
2993 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
2994 micro_mul(&r[2], &r[2], &r[1]);
2995 micro_sub(&r[2], &r[2], &r[3]);
2996 store_dest(mach, &r[2], &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
2998 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
2999 micro_mul(&r[4], &r[4], &r[1]);
3000 micro_sub(&r[4], &r[4], &r[5]);
3001 store_dest(mach, &r[4], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3003 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3004 micro_mul(&r[6], &r[6], &r[1]);
3005 micro_sub(&r[6], &r[6], &r[7]);
3006 store_dest(mach, &r[6], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3009 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3010 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3015 exec_xpd(struct tgsi_exec_machine *mach,
3016 const struct tgsi_full_instruction *inst)
3018 union tgsi_exec_channel r[6];
3019 union tgsi_exec_channel d[3];
3021 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3022 fetch_source(mach, &r[1], &inst->Src[1], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3024 micro_mul(&r[2], &r[0], &r[1]);
3026 fetch_source(mach, &r[3], &inst->Src[0], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3027 fetch_source(mach, &r[4], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3029 micro_mul(&r[5], &r[3], &r[4] );
3030 micro_sub(&d[TGSI_CHAN_X], &r[2], &r[5]);
3032 fetch_source(mach, &r[2], &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3034 micro_mul(&r[3], &r[3], &r[2]);
3036 fetch_source(mach, &r[5], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3038 micro_mul(&r[1], &r[1], &r[5]);
3039 micro_sub(&d[TGSI_CHAN_Y], &r[3], &r[1]);
3041 micro_mul(&r[5], &r[5], &r[4]);
3042 micro_mul(&r[0], &r[0], &r[2]);
3043 micro_sub(&d[TGSI_CHAN_Z], &r[5], &r[0]);
3045 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3046 store_dest(mach, &d[TGSI_CHAN_X], &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3048 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3049 store_dest(mach, &d[TGSI_CHAN_Y], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3051 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3052 store_dest(mach, &d[TGSI_CHAN_Z], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3054 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3055 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3060 exec_dst(struct tgsi_exec_machine *mach,
3061 const struct tgsi_full_instruction *inst)
3063 union tgsi_exec_channel r[2];
3064 union tgsi_exec_channel d[4];
3066 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3067 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3068 fetch_source(mach, &r[1], &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3069 micro_mul(&d[TGSI_CHAN_Y], &r[0], &r[1]);
3071 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3072 fetch_source(mach, &d[TGSI_CHAN_Z], &inst->Src[0], TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3074 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3075 fetch_source(mach, &d[TGSI_CHAN_W], &inst->Src[1], TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3078 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3079 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3081 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3082 store_dest(mach, &d[TGSI_CHAN_Y], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3084 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3085 store_dest(mach, &d[TGSI_CHAN_Z], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3087 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3088 store_dest(mach, &d[TGSI_CHAN_W], &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3093 exec_log(struct tgsi_exec_machine *mach,
3094 const struct tgsi_full_instruction *inst)
3096 union tgsi_exec_channel r[3];
3098 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3099 micro_abs(&r[2], &r[0]); /* r2 = abs(r0) */
3100 micro_lg2(&r[1], &r[2]); /* r1 = lg2(r2) */
3101 micro_flr(&r[0], &r[1]); /* r0 = floor(r1) */
3102 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3103 store_dest(mach, &r[0], &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3105 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3106 micro_exp2(&r[0], &r[0]); /* r0 = 2 ^ r0 */
3107 micro_div(&r[0], &r[2], &r[0]); /* r0 = r2 / r0 */
3108 store_dest(mach, &r[0], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3110 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3111 store_dest(mach, &r[1], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3113 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3114 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3119 exec_exp(struct tgsi_exec_machine *mach,
3120 const struct tgsi_full_instruction *inst)
3122 union tgsi_exec_channel r[3];
3124 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3125 micro_flr(&r[1], &r[0]); /* r1 = floor(r0) */
3126 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3127 micro_exp2(&r[2], &r[1]); /* r2 = 2 ^ r1 */
3128 store_dest(mach, &r[2], &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3130 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3131 micro_sub(&r[2], &r[0], &r[1]); /* r2 = r0 - r1 */
3132 store_dest(mach, &r[2], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3134 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3135 micro_exp2(&r[2], &r[0]); /* r2 = 2 ^ r0 */
3136 store_dest(mach, &r[2], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3138 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3139 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3144 exec_lit(struct tgsi_exec_machine *mach,
3145 const struct tgsi_full_instruction *inst)
3147 union tgsi_exec_channel r[3];
3148 union tgsi_exec_channel d[3];
3150 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_YZ) {
3151 fetch_source(mach, &r[0], &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3152 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
3153 fetch_source(mach, &r[1], &inst->Src[0], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3154 micro_max(&r[1], &r[1], &ZeroVec);
3156 fetch_source(mach, &r[2], &inst->Src[0], TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3157 micro_min(&r[2], &r[2], &P128Vec);
3158 micro_max(&r[2], &r[2], &M128Vec);
3159 micro_pow(&r[1], &r[1], &r[2]);
3160 micro_lt(&d[TGSI_CHAN_Z], &ZeroVec, &r[0], &r[1], &ZeroVec);
3161 store_dest(mach, &d[TGSI_CHAN_Z], &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_EXEC_DATA_FLOAT);
3163 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
3164 micro_max(&d[TGSI_CHAN_Y], &r[0], &ZeroVec);
3165 store_dest(mach, &d[TGSI_CHAN_Y], &inst->Dst[0], inst, TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
3168 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
3169 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
3172 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
3173 store_dest(mach, &OneVec, &inst->Dst[0], inst, TGSI_CHAN_W, TGSI_EXEC_DATA_FLOAT);
3178 exec_break(struct tgsi_exec_machine *mach)
3180 if (mach->BreakType == TGSI_EXEC_BREAK_INSIDE_LOOP) {
3181 /* turn off loop channels for each enabled exec channel */
3182 mach->LoopMask &= ~mach->ExecMask;
3183 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3184 UPDATE_EXEC_MASK(mach);
3186 assert(mach->BreakType == TGSI_EXEC_BREAK_INSIDE_SWITCH);
3188 mach->Switch.mask = 0x0;
3190 UPDATE_EXEC_MASK(mach);
3195 exec_switch(struct tgsi_exec_machine *mach,
3196 const struct tgsi_full_instruction *inst)
3198 assert(mach->SwitchStackTop < TGSI_EXEC_MAX_SWITCH_NESTING);
3199 assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK);
3201 mach->SwitchStack[mach->SwitchStackTop++] = mach->Switch;
3202 fetch_source(mach, &mach->Switch.selector, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_UINT);
3203 mach->Switch.mask = 0x0;
3204 mach->Switch.defaultMask = 0x0;
3206 mach->BreakStack[mach->BreakStackTop++] = mach->BreakType;
3207 mach->BreakType = TGSI_EXEC_BREAK_INSIDE_SWITCH;
3209 UPDATE_EXEC_MASK(mach);
3213 exec_case(struct tgsi_exec_machine *mach,
3214 const struct tgsi_full_instruction *inst)
3216 uint prevMask = mach->SwitchStack[mach->SwitchStackTop - 1].mask;
3217 union tgsi_exec_channel src;
3220 fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_UINT);
3222 if (mach->Switch.selector.u[0] == src.u[0]) {
3225 if (mach->Switch.selector.u[1] == src.u[1]) {
3228 if (mach->Switch.selector.u[2] == src.u[2]) {
3231 if (mach->Switch.selector.u[3] == src.u[3]) {
3235 mach->Switch.defaultMask |= mask;
3237 mach->Switch.mask |= mask & prevMask;
3239 UPDATE_EXEC_MASK(mach);
3243 exec_default(struct tgsi_exec_machine *mach)
3245 uint prevMask = mach->SwitchStack[mach->SwitchStackTop - 1].mask;
3247 mach->Switch.mask |= ~mach->Switch.defaultMask & prevMask;
3249 UPDATE_EXEC_MASK(mach);
3253 exec_endswitch(struct tgsi_exec_machine *mach)
3255 mach->Switch = mach->SwitchStack[--mach->SwitchStackTop];
3256 mach->BreakType = mach->BreakStack[--mach->BreakStackTop];
3258 UPDATE_EXEC_MASK(mach);
3262 micro_i2f(union tgsi_exec_channel *dst,
3263 const union tgsi_exec_channel *src)
3265 dst->f[0] = (float)src->i[0];
3266 dst->f[1] = (float)src->i[1];
3267 dst->f[2] = (float)src->i[2];
3268 dst->f[3] = (float)src->i[3];
3272 micro_not(union tgsi_exec_channel *dst,
3273 const union tgsi_exec_channel *src)
3275 dst->u[0] = ~src->u[0];
3276 dst->u[1] = ~src->u[1];
3277 dst->u[2] = ~src->u[2];
3278 dst->u[3] = ~src->u[3];
3282 micro_shl(union tgsi_exec_channel *dst,
3283 const union tgsi_exec_channel *src0,
3284 const union tgsi_exec_channel *src1)
3286 dst->u[0] = src0->u[0] << src1->u[0];
3287 dst->u[1] = src0->u[1] << src1->u[1];
3288 dst->u[2] = src0->u[2] << src1->u[2];
3289 dst->u[3] = src0->u[3] << src1->u[3];
3293 micro_and(union tgsi_exec_channel *dst,
3294 const union tgsi_exec_channel *src0,
3295 const union tgsi_exec_channel *src1)
3297 dst->u[0] = src0->u[0] & src1->u[0];
3298 dst->u[1] = src0->u[1] & src1->u[1];
3299 dst->u[2] = src0->u[2] & src1->u[2];
3300 dst->u[3] = src0->u[3] & src1->u[3];
3304 micro_or(union tgsi_exec_channel *dst,
3305 const union tgsi_exec_channel *src0,
3306 const union tgsi_exec_channel *src1)
3308 dst->u[0] = src0->u[0] | src1->u[0];
3309 dst->u[1] = src0->u[1] | src1->u[1];
3310 dst->u[2] = src0->u[2] | src1->u[2];
3311 dst->u[3] = src0->u[3] | src1->u[3];
3315 micro_xor(union tgsi_exec_channel *dst,
3316 const union tgsi_exec_channel *src0,
3317 const union tgsi_exec_channel *src1)
3319 dst->u[0] = src0->u[0] ^ src1->u[0];
3320 dst->u[1] = src0->u[1] ^ src1->u[1];
3321 dst->u[2] = src0->u[2] ^ src1->u[2];
3322 dst->u[3] = src0->u[3] ^ src1->u[3];
3326 micro_mod(union tgsi_exec_channel *dst,
3327 const union tgsi_exec_channel *src0,
3328 const union tgsi_exec_channel *src1)
3330 dst->i[0] = src0->i[0] % src1->i[0];
3331 dst->i[1] = src0->i[1] % src1->i[1];
3332 dst->i[2] = src0->i[2] % src1->i[2];
3333 dst->i[3] = src0->i[3] % src1->i[3];
3337 micro_f2i(union tgsi_exec_channel *dst,
3338 const union tgsi_exec_channel *src)
3340 dst->i[0] = (int)src->f[0];
3341 dst->i[1] = (int)src->f[1];
3342 dst->i[2] = (int)src->f[2];
3343 dst->i[3] = (int)src->f[3];
3347 micro_idiv(union tgsi_exec_channel *dst,
3348 const union tgsi_exec_channel *src0,
3349 const union tgsi_exec_channel *src1)
3351 dst->i[0] = src0->i[0] / src1->i[0];
3352 dst->i[1] = src0->i[1] / src1->i[1];
3353 dst->i[2] = src0->i[2] / src1->i[2];
3354 dst->i[3] = src0->i[3] / src1->i[3];
3358 micro_imax(union tgsi_exec_channel *dst,
3359 const union tgsi_exec_channel *src0,
3360 const union tgsi_exec_channel *src1)
3362 dst->i[0] = src0->i[0] > src1->i[0] ? src0->i[0] : src1->i[0];
3363 dst->i[1] = src0->i[1] > src1->i[1] ? src0->i[1] : src1->i[1];
3364 dst->i[2] = src0->i[2] > src1->i[2] ? src0->i[2] : src1->i[2];
3365 dst->i[3] = src0->i[3] > src1->i[3] ? src0->i[3] : src1->i[3];
3369 micro_imin(union tgsi_exec_channel *dst,
3370 const union tgsi_exec_channel *src0,
3371 const union tgsi_exec_channel *src1)
3373 dst->i[0] = src0->i[0] < src1->i[0] ? src0->i[0] : src1->i[0];
3374 dst->i[1] = src0->i[1] < src1->i[1] ? src0->i[1] : src1->i[1];
3375 dst->i[2] = src0->i[2] < src1->i[2] ? src0->i[2] : src1->i[2];
3376 dst->i[3] = src0->i[3] < src1->i[3] ? src0->i[3] : src1->i[3];
3380 micro_isge(union tgsi_exec_channel *dst,
3381 const union tgsi_exec_channel *src0,
3382 const union tgsi_exec_channel *src1)
3384 dst->i[0] = src0->i[0] >= src1->i[0] ? -1 : 0;
3385 dst->i[1] = src0->i[1] >= src1->i[1] ? -1 : 0;
3386 dst->i[2] = src0->i[2] >= src1->i[2] ? -1 : 0;
3387 dst->i[3] = src0->i[3] >= src1->i[3] ? -1 : 0;
3391 micro_ishr(union tgsi_exec_channel *dst,
3392 const union tgsi_exec_channel *src0,
3393 const union tgsi_exec_channel *src1)
3395 dst->i[0] = src0->i[0] >> src1->i[0];
3396 dst->i[1] = src0->i[1] >> src1->i[1];
3397 dst->i[2] = src0->i[2] >> src1->i[2];
3398 dst->i[3] = src0->i[3] >> src1->i[3];
3402 micro_islt(union tgsi_exec_channel *dst,
3403 const union tgsi_exec_channel *src0,
3404 const union tgsi_exec_channel *src1)
3406 dst->i[0] = src0->i[0] < src1->i[0] ? -1 : 0;
3407 dst->i[1] = src0->i[1] < src1->i[1] ? -1 : 0;
3408 dst->i[2] = src0->i[2] < src1->i[2] ? -1 : 0;
3409 dst->i[3] = src0->i[3] < src1->i[3] ? -1 : 0;
3413 micro_f2u(union tgsi_exec_channel *dst,
3414 const union tgsi_exec_channel *src)
3416 dst->u[0] = (uint)src->f[0];
3417 dst->u[1] = (uint)src->f[1];
3418 dst->u[2] = (uint)src->f[2];
3419 dst->u[3] = (uint)src->f[3];
3423 micro_u2f(union tgsi_exec_channel *dst,
3424 const union tgsi_exec_channel *src)
3426 dst->f[0] = (float)src->u[0];
3427 dst->f[1] = (float)src->u[1];
3428 dst->f[2] = (float)src->u[2];
3429 dst->f[3] = (float)src->u[3];
3433 micro_uadd(union tgsi_exec_channel *dst,
3434 const union tgsi_exec_channel *src0,
3435 const union tgsi_exec_channel *src1)
3437 dst->u[0] = src0->u[0] + src1->u[0];
3438 dst->u[1] = src0->u[1] + src1->u[1];
3439 dst->u[2] = src0->u[2] + src1->u[2];
3440 dst->u[3] = src0->u[3] + src1->u[3];
3444 micro_udiv(union tgsi_exec_channel *dst,
3445 const union tgsi_exec_channel *src0,
3446 const union tgsi_exec_channel *src1)
3448 dst->u[0] = src1->u[0] ? src0->u[0] / src1->u[0] : ~0u;
3449 dst->u[1] = src1->u[1] ? src0->u[1] / src1->u[1] : ~0u;
3450 dst->u[2] = src1->u[2] ? src0->u[2] / src1->u[2] : ~0u;
3451 dst->u[3] = src1->u[3] ? src0->u[3] / src1->u[3] : ~0u;
3455 micro_umad(union tgsi_exec_channel *dst,
3456 const union tgsi_exec_channel *src0,
3457 const union tgsi_exec_channel *src1,
3458 const union tgsi_exec_channel *src2)
3460 dst->u[0] = src0->u[0] * src1->u[0] + src2->u[0];
3461 dst->u[1] = src0->u[1] * src1->u[1] + src2->u[1];
3462 dst->u[2] = src0->u[2] * src1->u[2] + src2->u[2];
3463 dst->u[3] = src0->u[3] * src1->u[3] + src2->u[3];
3467 micro_umax(union tgsi_exec_channel *dst,
3468 const union tgsi_exec_channel *src0,
3469 const union tgsi_exec_channel *src1)
3471 dst->u[0] = src0->u[0] > src1->u[0] ? src0->u[0] : src1->u[0];
3472 dst->u[1] = src0->u[1] > src1->u[1] ? src0->u[1] : src1->u[1];
3473 dst->u[2] = src0->u[2] > src1->u[2] ? src0->u[2] : src1->u[2];
3474 dst->u[3] = src0->u[3] > src1->u[3] ? src0->u[3] : src1->u[3];
3478 micro_umin(union tgsi_exec_channel *dst,
3479 const union tgsi_exec_channel *src0,
3480 const union tgsi_exec_channel *src1)
3482 dst->u[0] = src0->u[0] < src1->u[0] ? src0->u[0] : src1->u[0];
3483 dst->u[1] = src0->u[1] < src1->u[1] ? src0->u[1] : src1->u[1];
3484 dst->u[2] = src0->u[2] < src1->u[2] ? src0->u[2] : src1->u[2];
3485 dst->u[3] = src0->u[3] < src1->u[3] ? src0->u[3] : src1->u[3];
3489 micro_umod(union tgsi_exec_channel *dst,
3490 const union tgsi_exec_channel *src0,
3491 const union tgsi_exec_channel *src1)
3493 dst->u[0] = src1->u[0] ? src0->u[0] % src1->u[0] : ~0u;
3494 dst->u[1] = src1->u[1] ? src0->u[1] % src1->u[1] : ~0u;
3495 dst->u[2] = src1->u[2] ? src0->u[2] % src1->u[2] : ~0u;
3496 dst->u[3] = src1->u[3] ? src0->u[3] % src1->u[3] : ~0u;
3500 micro_umul(union tgsi_exec_channel *dst,
3501 const union tgsi_exec_channel *src0,
3502 const union tgsi_exec_channel *src1)
3504 dst->u[0] = src0->u[0] * src1->u[0];
3505 dst->u[1] = src0->u[1] * src1->u[1];
3506 dst->u[2] = src0->u[2] * src1->u[2];
3507 dst->u[3] = src0->u[3] * src1->u[3];
3511 micro_useq(union tgsi_exec_channel *dst,
3512 const union tgsi_exec_channel *src0,
3513 const union tgsi_exec_channel *src1)
3515 dst->u[0] = src0->u[0] == src1->u[0] ? ~0 : 0;
3516 dst->u[1] = src0->u[1] == src1->u[1] ? ~0 : 0;
3517 dst->u[2] = src0->u[2] == src1->u[2] ? ~0 : 0;
3518 dst->u[3] = src0->u[3] == src1->u[3] ? ~0 : 0;
3522 micro_usge(union tgsi_exec_channel *dst,
3523 const union tgsi_exec_channel *src0,
3524 const union tgsi_exec_channel *src1)
3526 dst->u[0] = src0->u[0] >= src1->u[0] ? ~0 : 0;
3527 dst->u[1] = src0->u[1] >= src1->u[1] ? ~0 : 0;
3528 dst->u[2] = src0->u[2] >= src1->u[2] ? ~0 : 0;
3529 dst->u[3] = src0->u[3] >= src1->u[3] ? ~0 : 0;
3533 micro_ushr(union tgsi_exec_channel *dst,
3534 const union tgsi_exec_channel *src0,
3535 const union tgsi_exec_channel *src1)
3537 dst->u[0] = src0->u[0] >> src1->u[0];
3538 dst->u[1] = src0->u[1] >> src1->u[1];
3539 dst->u[2] = src0->u[2] >> src1->u[2];
3540 dst->u[3] = src0->u[3] >> src1->u[3];
3544 micro_uslt(union tgsi_exec_channel *dst,
3545 const union tgsi_exec_channel *src0,
3546 const union tgsi_exec_channel *src1)
3548 dst->u[0] = src0->u[0] < src1->u[0] ? ~0 : 0;
3549 dst->u[1] = src0->u[1] < src1->u[1] ? ~0 : 0;
3550 dst->u[2] = src0->u[2] < src1->u[2] ? ~0 : 0;
3551 dst->u[3] = src0->u[3] < src1->u[3] ? ~0 : 0;
3555 micro_usne(union tgsi_exec_channel *dst,
3556 const union tgsi_exec_channel *src0,
3557 const union tgsi_exec_channel *src1)
3559 dst->u[0] = src0->u[0] != src1->u[0] ? ~0 : 0;
3560 dst->u[1] = src0->u[1] != src1->u[1] ? ~0 : 0;
3561 dst->u[2] = src0->u[2] != src1->u[2] ? ~0 : 0;
3562 dst->u[3] = src0->u[3] != src1->u[3] ? ~0 : 0;
3566 micro_uarl(union tgsi_exec_channel *dst,
3567 const union tgsi_exec_channel *src)
3569 dst->i[0] = src->u[0];
3570 dst->i[1] = src->u[1];
3571 dst->i[2] = src->u[2];
3572 dst->i[3] = src->u[3];
3576 micro_ucmp(union tgsi_exec_channel *dst,
3577 const union tgsi_exec_channel *src0,
3578 const union tgsi_exec_channel *src1,
3579 const union tgsi_exec_channel *src2)
3581 dst->u[0] = src0->u[0] ? src1->u[0] : src2->u[0];
3582 dst->u[1] = src0->u[1] ? src1->u[1] : src2->u[1];
3583 dst->u[2] = src0->u[2] ? src1->u[2] : src2->u[2];
3584 dst->u[3] = src0->u[3] ? src1->u[3] : src2->u[3];
3589 struct tgsi_exec_machine *mach,
3590 const struct tgsi_full_instruction *inst,
3593 union tgsi_exec_channel r[10];
3597 switch (inst->Instruction.Opcode) {
3598 case TGSI_OPCODE_ARL:
3599 exec_vector_unary(mach, inst, micro_arl, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT);
3602 case TGSI_OPCODE_MOV:
3603 exec_vector_unary(mach, inst, micro_mov, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
3606 case TGSI_OPCODE_LIT:
3607 exec_lit(mach, inst);
3610 case TGSI_OPCODE_RCP:
3611 exec_scalar_unary(mach, inst, micro_rcp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3614 case TGSI_OPCODE_RSQ:
3615 exec_scalar_unary(mach, inst, micro_rsq, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3618 case TGSI_OPCODE_EXP:
3619 exec_exp(mach, inst);
3622 case TGSI_OPCODE_LOG:
3623 exec_log(mach, inst);
3626 case TGSI_OPCODE_MUL:
3627 exec_vector_binary(mach, inst, micro_mul, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3630 case TGSI_OPCODE_ADD:
3631 exec_vector_binary(mach, inst, micro_add, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3634 case TGSI_OPCODE_DP3:
3635 exec_dp3(mach, inst);
3638 case TGSI_OPCODE_DP4:
3639 exec_dp4(mach, inst);
3642 case TGSI_OPCODE_DST:
3643 exec_dst(mach, inst);
3646 case TGSI_OPCODE_MIN:
3647 exec_vector_binary(mach, inst, micro_min, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3650 case TGSI_OPCODE_MAX:
3651 exec_vector_binary(mach, inst, micro_max, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3654 case TGSI_OPCODE_SLT:
3655 exec_vector_binary(mach, inst, micro_slt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3658 case TGSI_OPCODE_SGE:
3659 exec_vector_binary(mach, inst, micro_sge, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3662 case TGSI_OPCODE_MAD:
3663 exec_vector_trinary(mach, inst, micro_mad, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3666 case TGSI_OPCODE_SUB:
3667 exec_vector_binary(mach, inst, micro_sub, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3670 case TGSI_OPCODE_LRP:
3671 exec_vector_trinary(mach, inst, micro_lrp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3674 case TGSI_OPCODE_CND:
3675 exec_vector_trinary(mach, inst, micro_cnd, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3678 case TGSI_OPCODE_SQRT:
3679 exec_vector_unary(mach, inst, micro_sqrt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3682 case TGSI_OPCODE_DP2A:
3683 exec_dp2a(mach, inst);
3686 case TGSI_OPCODE_FRC:
3687 exec_vector_unary(mach, inst, micro_frc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3690 case TGSI_OPCODE_CLAMP:
3691 exec_vector_trinary(mach, inst, micro_clamp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3694 case TGSI_OPCODE_FLR:
3695 exec_vector_unary(mach, inst, micro_flr, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3698 case TGSI_OPCODE_ROUND:
3699 exec_vector_unary(mach, inst, micro_rnd, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3702 case TGSI_OPCODE_EX2:
3703 exec_scalar_unary(mach, inst, micro_exp2, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3706 case TGSI_OPCODE_LG2:
3707 exec_scalar_unary(mach, inst, micro_lg2, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3710 case TGSI_OPCODE_POW:
3711 exec_scalar_binary(mach, inst, micro_pow, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3714 case TGSI_OPCODE_XPD:
3715 exec_xpd(mach, inst);
3718 case TGSI_OPCODE_ABS:
3719 exec_vector_unary(mach, inst, micro_abs, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3722 case TGSI_OPCODE_RCC:
3723 exec_scalar_unary(mach, inst, micro_rcc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3726 case TGSI_OPCODE_DPH:
3727 exec_dph(mach, inst);
3730 case TGSI_OPCODE_COS:
3731 exec_scalar_unary(mach, inst, micro_cos, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3734 case TGSI_OPCODE_DDX:
3735 exec_vector_unary(mach, inst, micro_ddx, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3738 case TGSI_OPCODE_DDY:
3739 exec_vector_unary(mach, inst, micro_ddy, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3742 case TGSI_OPCODE_KILP:
3743 exec_kilp (mach, inst);
3746 case TGSI_OPCODE_KIL:
3747 exec_kil (mach, inst);
3750 case TGSI_OPCODE_PK2H:
3754 case TGSI_OPCODE_PK2US:
3758 case TGSI_OPCODE_PK4B:
3762 case TGSI_OPCODE_PK4UB:
3766 case TGSI_OPCODE_RFL:
3767 exec_rfl(mach, inst);
3770 case TGSI_OPCODE_SEQ:
3771 exec_vector_binary(mach, inst, micro_seq, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3774 case TGSI_OPCODE_SFL:
3775 exec_vector(mach, inst, micro_sfl, TGSI_EXEC_DATA_FLOAT);
3778 case TGSI_OPCODE_SGT:
3779 exec_vector_binary(mach, inst, micro_sgt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3782 case TGSI_OPCODE_SIN:
3783 exec_scalar_unary(mach, inst, micro_sin, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3786 case TGSI_OPCODE_SLE:
3787 exec_vector_binary(mach, inst, micro_sle, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3790 case TGSI_OPCODE_SNE:
3791 exec_vector_binary(mach, inst, micro_sne, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3794 case TGSI_OPCODE_STR:
3795 exec_vector(mach, inst, micro_str, TGSI_EXEC_DATA_FLOAT);
3798 case TGSI_OPCODE_TEX:
3799 /* simple texture lookup */
3800 /* src[0] = texcoord */
3801 /* src[1] = sampler unit */
3802 exec_tex(mach, inst, TEX_MODIFIER_NONE, 1);
3805 case TGSI_OPCODE_TXB:
3806 /* Texture lookup with lod bias */
3807 /* src[0] = texcoord (src[0].w = LOD bias) */
3808 /* src[1] = sampler unit */
3809 exec_tex(mach, inst, TEX_MODIFIER_LOD_BIAS, 1);
3812 case TGSI_OPCODE_TXD:
3813 /* Texture lookup with explict partial derivatives */
3814 /* src[0] = texcoord */
3815 /* src[1] = d[strq]/dx */
3816 /* src[2] = d[strq]/dy */
3817 /* src[3] = sampler unit */
3818 exec_txd(mach, inst);
3821 case TGSI_OPCODE_TXL:
3822 /* Texture lookup with explit LOD */
3823 /* src[0] = texcoord (src[0].w = LOD) */
3824 /* src[1] = sampler unit */
3825 exec_tex(mach, inst, TEX_MODIFIER_EXPLICIT_LOD, 1);
3828 case TGSI_OPCODE_TXP:
3829 /* Texture lookup with projection */
3830 /* src[0] = texcoord (src[0].w = projection) */
3831 /* src[1] = sampler unit */
3832 exec_tex(mach, inst, TEX_MODIFIER_PROJECTED, 1);
3835 case TGSI_OPCODE_UP2H:
3839 case TGSI_OPCODE_UP2US:
3843 case TGSI_OPCODE_UP4B:
3847 case TGSI_OPCODE_UP4UB:
3851 case TGSI_OPCODE_X2D:
3852 exec_x2d(mach, inst);
3855 case TGSI_OPCODE_ARA:
3859 case TGSI_OPCODE_ARR:
3860 exec_vector_unary(mach, inst, micro_arr, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT);
3863 case TGSI_OPCODE_BRA:
3867 case TGSI_OPCODE_CAL:
3868 /* skip the call if no execution channels are enabled */
3869 if (mach->ExecMask) {
3872 /* First, record the depths of the execution stacks.
3873 * This is important for deeply nested/looped return statements.
3874 * We have to unwind the stacks by the correct amount. For a
3875 * real code generator, we could determine the number of entries
3876 * to pop off each stack with simple static analysis and avoid
3877 * implementing this data structure at run time.
3879 mach->CallStack[mach->CallStackTop].CondStackTop = mach->CondStackTop;
3880 mach->CallStack[mach->CallStackTop].LoopStackTop = mach->LoopStackTop;
3881 mach->CallStack[mach->CallStackTop].ContStackTop = mach->ContStackTop;
3882 mach->CallStack[mach->CallStackTop].SwitchStackTop = mach->SwitchStackTop;
3883 mach->CallStack[mach->CallStackTop].BreakStackTop = mach->BreakStackTop;
3884 /* note that PC was already incremented above */
3885 mach->CallStack[mach->CallStackTop].ReturnAddr = *pc;
3887 mach->CallStackTop++;
3889 /* Second, push the Cond, Loop, Cont, Func stacks */
3890 assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING);
3891 assert(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
3892 assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
3893 assert(mach->SwitchStackTop < TGSI_EXEC_MAX_SWITCH_NESTING);
3894 assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK);
3895 assert(mach->FuncStackTop < TGSI_EXEC_MAX_CALL_NESTING);
3897 mach->CondStack[mach->CondStackTop++] = mach->CondMask;
3898 mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask;
3899 mach->ContStack[mach->ContStackTop++] = mach->ContMask;
3900 mach->SwitchStack[mach->SwitchStackTop++] = mach->Switch;
3901 mach->BreakStack[mach->BreakStackTop++] = mach->BreakType;
3902 mach->FuncStack[mach->FuncStackTop++] = mach->FuncMask;
3904 /* Finally, jump to the subroutine */
3905 *pc = inst->Label.Label;
3909 case TGSI_OPCODE_RET:
3910 mach->FuncMask &= ~mach->ExecMask;
3911 UPDATE_EXEC_MASK(mach);
3913 if (mach->FuncMask == 0x0) {
3914 /* really return now (otherwise, keep executing */
3916 if (mach->CallStackTop == 0) {
3917 /* returning from main() */
3918 mach->CondStackTop = 0;
3919 mach->LoopStackTop = 0;
3924 assert(mach->CallStackTop > 0);
3925 mach->CallStackTop--;
3927 mach->CondStackTop = mach->CallStack[mach->CallStackTop].CondStackTop;
3928 mach->CondMask = mach->CondStack[mach->CondStackTop];
3930 mach->LoopStackTop = mach->CallStack[mach->CallStackTop].LoopStackTop;
3931 mach->LoopMask = mach->LoopStack[mach->LoopStackTop];
3933 mach->ContStackTop = mach->CallStack[mach->CallStackTop].ContStackTop;
3934 mach->ContMask = mach->ContStack[mach->ContStackTop];
3936 mach->SwitchStackTop = mach->CallStack[mach->CallStackTop].SwitchStackTop;
3937 mach->Switch = mach->SwitchStack[mach->SwitchStackTop];
3939 mach->BreakStackTop = mach->CallStack[mach->CallStackTop].BreakStackTop;
3940 mach->BreakType = mach->BreakStack[mach->BreakStackTop];
3942 assert(mach->FuncStackTop > 0);
3943 mach->FuncMask = mach->FuncStack[--mach->FuncStackTop];
3945 *pc = mach->CallStack[mach->CallStackTop].ReturnAddr;
3947 UPDATE_EXEC_MASK(mach);
3951 case TGSI_OPCODE_SSG:
3952 exec_vector_unary(mach, inst, micro_sgn, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3955 case TGSI_OPCODE_CMP:
3956 exec_vector_trinary(mach, inst, micro_cmp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3959 case TGSI_OPCODE_SCS:
3960 exec_scs(mach, inst);
3963 case TGSI_OPCODE_NRM:
3964 exec_nrm3(mach, inst);
3967 case TGSI_OPCODE_NRM4:
3968 exec_nrm4(mach, inst);
3971 case TGSI_OPCODE_DIV:
3972 exec_vector_binary(mach, inst, micro_div, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
3975 case TGSI_OPCODE_DP2:
3976 exec_dp2(mach, inst);
3979 case TGSI_OPCODE_IF:
3981 assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING);
3982 mach->CondStack[mach->CondStackTop++] = mach->CondMask;
3983 FETCH( &r[0], 0, TGSI_CHAN_X );
3984 /* update CondMask */
3986 mach->CondMask &= ~0x1;
3989 mach->CondMask &= ~0x2;
3992 mach->CondMask &= ~0x4;
3995 mach->CondMask &= ~0x8;
3997 UPDATE_EXEC_MASK(mach);
3998 /* Todo: If CondMask==0, jump to ELSE */
4001 case TGSI_OPCODE_UIF:
4003 assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING);
4004 mach->CondStack[mach->CondStackTop++] = mach->CondMask;
4005 IFETCH( &r[0], 0, TGSI_CHAN_X );
4006 /* update CondMask */
4008 mach->CondMask &= ~0x1;
4011 mach->CondMask &= ~0x2;
4014 mach->CondMask &= ~0x4;
4017 mach->CondMask &= ~0x8;
4019 UPDATE_EXEC_MASK(mach);
4020 /* Todo: If CondMask==0, jump to ELSE */
4023 case TGSI_OPCODE_ELSE:
4024 /* invert CondMask wrt previous mask */
4027 assert(mach->CondStackTop > 0);
4028 prevMask = mach->CondStack[mach->CondStackTop - 1];
4029 mach->CondMask = ~mach->CondMask & prevMask;
4030 UPDATE_EXEC_MASK(mach);
4031 /* Todo: If CondMask==0, jump to ENDIF */
4035 case TGSI_OPCODE_ENDIF:
4037 assert(mach->CondStackTop > 0);
4038 mach->CondMask = mach->CondStack[--mach->CondStackTop];
4039 UPDATE_EXEC_MASK(mach);
4042 case TGSI_OPCODE_END:
4043 /* make sure we end primitives which haven't
4044 * been explicitly emitted */
4045 conditional_emit_primitive(mach);
4046 /* halt execution */
4050 case TGSI_OPCODE_PUSHA:
4054 case TGSI_OPCODE_POPA:
4058 case TGSI_OPCODE_CEIL:
4059 exec_vector_unary(mach, inst, micro_ceil, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
4062 case TGSI_OPCODE_I2F:
4063 exec_vector_unary(mach, inst, micro_i2f, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_INT);
4066 case TGSI_OPCODE_NOT:
4067 exec_vector_unary(mach, inst, micro_not, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4070 case TGSI_OPCODE_TRUNC:
4071 exec_vector_unary(mach, inst, micro_trunc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT);
4074 case TGSI_OPCODE_SHL:
4075 exec_vector_binary(mach, inst, micro_shl, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4078 case TGSI_OPCODE_AND:
4079 exec_vector_binary(mach, inst, micro_and, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4082 case TGSI_OPCODE_OR:
4083 exec_vector_binary(mach, inst, micro_or, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4086 case TGSI_OPCODE_MOD:
4087 exec_vector_binary(mach, inst, micro_mod, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4090 case TGSI_OPCODE_XOR:
4091 exec_vector_binary(mach, inst, micro_xor, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4094 case TGSI_OPCODE_SAD:
4098 case TGSI_OPCODE_TXF:
4099 exec_txf(mach, inst);
4102 case TGSI_OPCODE_TXQ:
4103 exec_txq(mach, inst);
4106 case TGSI_OPCODE_EMIT:
4110 case TGSI_OPCODE_ENDPRIM:
4111 emit_primitive(mach);
4114 case TGSI_OPCODE_BGNLOOP:
4115 /* push LoopMask and ContMasks */
4116 assert(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
4117 assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
4118 assert(mach->LoopLabelStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
4119 assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK);
4121 mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask;
4122 mach->ContStack[mach->ContStackTop++] = mach->ContMask;
4123 mach->LoopLabelStack[mach->LoopLabelStackTop++] = *pc - 1;
4124 mach->BreakStack[mach->BreakStackTop++] = mach->BreakType;
4125 mach->BreakType = TGSI_EXEC_BREAK_INSIDE_LOOP;
4128 case TGSI_OPCODE_ENDLOOP:
4129 /* Restore ContMask, but don't pop */
4130 assert(mach->ContStackTop > 0);
4131 mach->ContMask = mach->ContStack[mach->ContStackTop - 1];
4132 UPDATE_EXEC_MASK(mach);
4133 if (mach->ExecMask) {
4134 /* repeat loop: jump to instruction just past BGNLOOP */
4135 assert(mach->LoopLabelStackTop > 0);
4136 *pc = mach->LoopLabelStack[mach->LoopLabelStackTop - 1] + 1;
4139 /* exit loop: pop LoopMask */
4140 assert(mach->LoopStackTop > 0);
4141 mach->LoopMask = mach->LoopStack[--mach->LoopStackTop];
4143 assert(mach->ContStackTop > 0);
4144 mach->ContMask = mach->ContStack[--mach->ContStackTop];
4145 assert(mach->LoopLabelStackTop > 0);
4146 --mach->LoopLabelStackTop;
4148 mach->BreakType = mach->BreakStack[--mach->BreakStackTop];
4150 UPDATE_EXEC_MASK(mach);
4153 case TGSI_OPCODE_BRK:
4157 case TGSI_OPCODE_CONT:
4158 /* turn off cont channels for each enabled exec channel */
4159 mach->ContMask &= ~mach->ExecMask;
4160 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4161 UPDATE_EXEC_MASK(mach);
4164 case TGSI_OPCODE_BGNSUB:
4168 case TGSI_OPCODE_ENDSUB:
4170 * XXX: This really should be a no-op. We should never reach this opcode.
4173 assert(mach->CallStackTop > 0);
4174 mach->CallStackTop--;
4176 mach->CondStackTop = mach->CallStack[mach->CallStackTop].CondStackTop;
4177 mach->CondMask = mach->CondStack[mach->CondStackTop];
4179 mach->LoopStackTop = mach->CallStack[mach->CallStackTop].LoopStackTop;
4180 mach->LoopMask = mach->LoopStack[mach->LoopStackTop];
4182 mach->ContStackTop = mach->CallStack[mach->CallStackTop].ContStackTop;
4183 mach->ContMask = mach->ContStack[mach->ContStackTop];
4185 mach->SwitchStackTop = mach->CallStack[mach->CallStackTop].SwitchStackTop;
4186 mach->Switch = mach->SwitchStack[mach->SwitchStackTop];
4188 mach->BreakStackTop = mach->CallStack[mach->CallStackTop].BreakStackTop;
4189 mach->BreakType = mach->BreakStack[mach->BreakStackTop];
4191 assert(mach->FuncStackTop > 0);
4192 mach->FuncMask = mach->FuncStack[--mach->FuncStackTop];
4194 *pc = mach->CallStack[mach->CallStackTop].ReturnAddr;
4196 UPDATE_EXEC_MASK(mach);
4199 case TGSI_OPCODE_NOP:
4202 case TGSI_OPCODE_BREAKC:
4203 FETCH(&r[0], 0, TGSI_CHAN_X);
4204 /* update CondMask */
4205 if (r[0].u[0] && (mach->ExecMask & 0x1)) {
4206 mach->LoopMask &= ~0x1;
4208 if (r[0].u[1] && (mach->ExecMask & 0x2)) {
4209 mach->LoopMask &= ~0x2;
4211 if (r[0].u[2] && (mach->ExecMask & 0x4)) {
4212 mach->LoopMask &= ~0x4;
4214 if (r[0].u[3] && (mach->ExecMask & 0x8)) {
4215 mach->LoopMask &= ~0x8;
4217 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4218 UPDATE_EXEC_MASK(mach);
4221 case TGSI_OPCODE_F2I:
4222 exec_vector_unary(mach, inst, micro_f2i, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT);
4225 case TGSI_OPCODE_IDIV:
4226 exec_vector_binary(mach, inst, micro_idiv, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4229 case TGSI_OPCODE_IMAX:
4230 exec_vector_binary(mach, inst, micro_imax, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4233 case TGSI_OPCODE_IMIN:
4234 exec_vector_binary(mach, inst, micro_imin, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4237 case TGSI_OPCODE_INEG:
4238 exec_vector_unary(mach, inst, micro_ineg, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4241 case TGSI_OPCODE_ISGE:
4242 exec_vector_binary(mach, inst, micro_isge, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4245 case TGSI_OPCODE_ISHR:
4246 exec_vector_binary(mach, inst, micro_ishr, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4249 case TGSI_OPCODE_ISLT:
4250 exec_vector_binary(mach, inst, micro_islt, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4253 case TGSI_OPCODE_F2U:
4254 exec_vector_unary(mach, inst, micro_f2u, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT);
4257 case TGSI_OPCODE_U2F:
4258 exec_vector_unary(mach, inst, micro_u2f, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_UINT);
4261 case TGSI_OPCODE_UADD:
4262 exec_vector_binary(mach, inst, micro_uadd, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4265 case TGSI_OPCODE_UDIV:
4266 exec_vector_binary(mach, inst, micro_udiv, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4269 case TGSI_OPCODE_UMAD:
4270 exec_vector_trinary(mach, inst, micro_umad, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4273 case TGSI_OPCODE_UMAX:
4274 exec_vector_binary(mach, inst, micro_umax, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4277 case TGSI_OPCODE_UMIN:
4278 exec_vector_binary(mach, inst, micro_umin, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4281 case TGSI_OPCODE_UMOD:
4282 exec_vector_binary(mach, inst, micro_umod, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4285 case TGSI_OPCODE_UMUL:
4286 exec_vector_binary(mach, inst, micro_umul, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4289 case TGSI_OPCODE_USEQ:
4290 exec_vector_binary(mach, inst, micro_useq, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4293 case TGSI_OPCODE_USGE:
4294 exec_vector_binary(mach, inst, micro_usge, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4297 case TGSI_OPCODE_USHR:
4298 exec_vector_binary(mach, inst, micro_ushr, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4301 case TGSI_OPCODE_USLT:
4302 exec_vector_binary(mach, inst, micro_uslt, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4305 case TGSI_OPCODE_USNE:
4306 exec_vector_binary(mach, inst, micro_usne, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4309 case TGSI_OPCODE_SWITCH:
4310 exec_switch(mach, inst);
4313 case TGSI_OPCODE_CASE:
4314 exec_case(mach, inst);
4317 case TGSI_OPCODE_DEFAULT:
4321 case TGSI_OPCODE_ENDSWITCH:
4322 exec_endswitch(mach);
4325 case TGSI_OPCODE_SAMPLE_I:
4326 exec_txf(mach, inst);
4329 case TGSI_OPCODE_SAMPLE_I_MS:
4333 case TGSI_OPCODE_SAMPLE:
4334 exec_sample(mach, inst, TEX_MODIFIER_NONE, FALSE);
4337 case TGSI_OPCODE_SAMPLE_B:
4338 exec_sample(mach, inst, TEX_MODIFIER_LOD_BIAS, FALSE);
4341 case TGSI_OPCODE_SAMPLE_C:
4342 exec_sample(mach, inst, TEX_MODIFIER_NONE, TRUE);
4345 case TGSI_OPCODE_SAMPLE_C_LZ:
4346 exec_sample(mach, inst, TEX_MODIFIER_LEVEL_ZERO, TRUE);
4349 case TGSI_OPCODE_SAMPLE_D:
4350 exec_sample_d(mach, inst);
4353 case TGSI_OPCODE_SAMPLE_L:
4354 exec_sample(mach, inst, TEX_MODIFIER_EXPLICIT_LOD, FALSE);
4357 case TGSI_OPCODE_GATHER4:
4361 case TGSI_OPCODE_SVIEWINFO:
4362 exec_txq(mach, inst);
4365 case TGSI_OPCODE_SAMPLE_POS:
4369 case TGSI_OPCODE_SAMPLE_INFO:
4373 case TGSI_OPCODE_UARL:
4374 exec_vector_unary(mach, inst, micro_uarl, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_UINT);
4377 case TGSI_OPCODE_UCMP:
4378 exec_vector_trinary(mach, inst, micro_ucmp, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT);
4381 case TGSI_OPCODE_IABS:
4382 exec_vector_unary(mach, inst, micro_iabs, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4385 case TGSI_OPCODE_ISSG:
4386 exec_vector_unary(mach, inst, micro_isgn, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
4389 case TGSI_OPCODE_TEX2:
4390 /* simple texture lookup */
4391 /* src[0] = texcoord */
4392 /* src[1] = compare */
4393 /* src[2] = sampler unit */
4394 exec_tex(mach, inst, TEX_MODIFIER_NONE, 2);
4396 case TGSI_OPCODE_TXB2:
4397 /* simple texture lookup */
4398 /* src[0] = texcoord */
4400 /* src[2] = sampler unit */
4401 exec_tex(mach, inst, TEX_MODIFIER_LOD_BIAS, 2);
4403 case TGSI_OPCODE_TXL2:
4404 /* simple texture lookup */
4405 /* src[0] = texcoord */
4407 /* src[2] = sampler unit */
4408 exec_tex(mach, inst, TEX_MODIFIER_EXPLICIT_LOD, 2);
4417 * Run TGSI interpreter.
4418 * \return bitmask of "alive" quad components
4421 tgsi_exec_machine_run( struct tgsi_exec_machine *mach )
4425 uint default_mask = 0xf;
4427 mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] = 0;
4428 mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] = 0;
4430 if( mach->Processor == TGSI_PROCESSOR_GEOMETRY ) {
4431 mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0] = 0;
4432 mach->Primitives[0] = 0;
4433 /* GS runs on a single primitive for now */
4437 mach->CondMask = default_mask;
4438 mach->LoopMask = default_mask;
4439 mach->ContMask = default_mask;
4440 mach->FuncMask = default_mask;
4441 mach->ExecMask = default_mask;
4443 mach->Switch.mask = default_mask;
4445 assert(mach->CondStackTop == 0);
4446 assert(mach->LoopStackTop == 0);
4447 assert(mach->ContStackTop == 0);
4448 assert(mach->SwitchStackTop == 0);
4449 assert(mach->BreakStackTop == 0);
4450 assert(mach->CallStackTop == 0);
4453 /* execute declarations (interpolants) */
4454 for (i = 0; i < mach->NumDeclarations; i++) {
4455 exec_declaration( mach, mach->Declarations+i );
4460 struct tgsi_exec_vector temps[TGSI_EXEC_NUM_TEMPS + TGSI_EXEC_NUM_TEMP_EXTRAS];
4461 struct tgsi_exec_vector outputs[PIPE_MAX_ATTRIBS];
4464 memset(mach->Temps, 0, sizeof(temps));
4465 memset(mach->Outputs, 0, sizeof(outputs));
4466 memset(temps, 0, sizeof(temps));
4467 memset(outputs, 0, sizeof(outputs));
4470 /* execute instructions, until pc is set to -1 */
4476 tgsi_dump_instruction(&mach->Instructions[pc], inst++);
4479 assert(pc < (int) mach->NumInstructions);
4480 exec_instruction(mach, mach->Instructions + pc, &pc);
4483 for (i = 0; i < TGSI_EXEC_NUM_TEMPS + TGSI_EXEC_NUM_TEMP_EXTRAS; i++) {
4484 if (memcmp(&temps[i], &mach->Temps[i], sizeof(temps[i]))) {
4487 memcpy(&temps[i], &mach->Temps[i], sizeof(temps[i]));
4488 debug_printf("TEMP[%2u] = ", i);
4489 for (j = 0; j < 4; j++) {
4493 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4494 temps[i].xyzw[0].f[j], temps[i].xyzw[0].u[j],
4495 temps[i].xyzw[1].f[j], temps[i].xyzw[1].u[j],
4496 temps[i].xyzw[2].f[j], temps[i].xyzw[2].u[j],
4497 temps[i].xyzw[3].f[j], temps[i].xyzw[3].u[j]);
4501 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
4502 if (memcmp(&outputs[i], &mach->Outputs[i], sizeof(outputs[i]))) {
4505 memcpy(&outputs[i], &mach->Outputs[i], sizeof(outputs[i]));
4506 debug_printf("OUT[%2u] = ", i);
4507 for (j = 0; j < 4; j++) {
4511 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4512 outputs[i].xyzw[0].f[j], outputs[i].xyzw[0].u[j],
4513 outputs[i].xyzw[1].f[j], outputs[i].xyzw[1].u[j],
4514 outputs[i].xyzw[2].f[j], outputs[i].xyzw[2].u[j],
4515 outputs[i].xyzw[3].f[j], outputs[i].xyzw[3].u[j]);
4524 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
4525 if (mach->Processor == TGSI_PROCESSOR_FRAGMENT) {
4527 * Scale back depth component.
4529 for (i = 0; i < 4; i++)
4530 mach->Outputs[0].xyzw[2].f[i] *= ctx->DrawBuffer->_DepthMaxF;
4534 /* Strictly speaking, these assertions aren't really needed but they
4535 * can potentially catch some bugs in the control flow code.
4537 assert(mach->CondStackTop == 0);
4538 assert(mach->LoopStackTop == 0);
4539 assert(mach->ContStackTop == 0);
4540 assert(mach->SwitchStackTop == 0);
4541 assert(mach->BreakStackTop == 0);
4542 assert(mach->CallStackTop == 0);
4544 return ~mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0];