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"
67 #define TILE_TOP_LEFT 0
68 #define TILE_TOP_RIGHT 1
69 #define TILE_BOTTOM_LEFT 2
70 #define TILE_BOTTOM_RIGHT 3
73 micro_abs(union tgsi_exec_channel
*dst
,
74 const union tgsi_exec_channel
*src
)
76 dst
->f
[0] = fabsf(src
->f
[0]);
77 dst
->f
[1] = fabsf(src
->f
[1]);
78 dst
->f
[2] = fabsf(src
->f
[2]);
79 dst
->f
[3] = fabsf(src
->f
[3]);
83 micro_arl(union tgsi_exec_channel
*dst
,
84 const union tgsi_exec_channel
*src
)
86 dst
->i
[0] = (int)floorf(src
->f
[0]);
87 dst
->i
[1] = (int)floorf(src
->f
[1]);
88 dst
->i
[2] = (int)floorf(src
->f
[2]);
89 dst
->i
[3] = (int)floorf(src
->f
[3]);
93 micro_arr(union tgsi_exec_channel
*dst
,
94 const union tgsi_exec_channel
*src
)
96 dst
->i
[0] = (int)floorf(src
->f
[0] + 0.5f
);
97 dst
->i
[1] = (int)floorf(src
->f
[1] + 0.5f
);
98 dst
->i
[2] = (int)floorf(src
->f
[2] + 0.5f
);
99 dst
->i
[3] = (int)floorf(src
->f
[3] + 0.5f
);
103 micro_ceil(union tgsi_exec_channel
*dst
,
104 const union tgsi_exec_channel
*src
)
106 dst
->f
[0] = ceilf(src
->f
[0]);
107 dst
->f
[1] = ceilf(src
->f
[1]);
108 dst
->f
[2] = ceilf(src
->f
[2]);
109 dst
->f
[3] = ceilf(src
->f
[3]);
113 micro_cos(union tgsi_exec_channel
*dst
,
114 const union tgsi_exec_channel
*src
)
116 dst
->f
[0] = cosf(src
->f
[0]);
117 dst
->f
[1] = cosf(src
->f
[1]);
118 dst
->f
[2] = cosf(src
->f
[2]);
119 dst
->f
[3] = cosf(src
->f
[3]);
123 micro_ddx(union tgsi_exec_channel
*dst
,
124 const union tgsi_exec_channel
*src
)
129 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
133 micro_ddy(union tgsi_exec_channel
*dst
,
134 const union tgsi_exec_channel
*src
)
139 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
143 micro_exp2(union tgsi_exec_channel
*dst
,
144 const union tgsi_exec_channel
*src
)
147 dst
->f
[0] = util_fast_exp2(src
->f
[0]);
148 dst
->f
[1] = util_fast_exp2(src
->f
[1]);
149 dst
->f
[2] = util_fast_exp2(src
->f
[2]);
150 dst
->f
[3] = util_fast_exp2(src
->f
[3]);
153 /* Inf is okay for this instruction, so clamp it to silence assertions. */
155 union tgsi_exec_channel clamped
;
157 for (i
= 0; i
< 4; i
++) {
158 if (src
->f
[i
] > 127.99999f
) {
159 clamped
.f
[i
] = 127.99999f
;
160 } else if (src
->f
[i
] < -126.99999f
) {
161 clamped
.f
[i
] = -126.99999f
;
163 clamped
.f
[i
] = src
->f
[i
];
169 dst
->f
[0] = powf(2.0f
, src
->f
[0]);
170 dst
->f
[1] = powf(2.0f
, src
->f
[1]);
171 dst
->f
[2] = powf(2.0f
, src
->f
[2]);
172 dst
->f
[3] = powf(2.0f
, src
->f
[3]);
173 #endif /* FAST_MATH */
177 micro_flr(union tgsi_exec_channel
*dst
,
178 const union tgsi_exec_channel
*src
)
180 dst
->f
[0] = floorf(src
->f
[0]);
181 dst
->f
[1] = floorf(src
->f
[1]);
182 dst
->f
[2] = floorf(src
->f
[2]);
183 dst
->f
[3] = floorf(src
->f
[3]);
187 micro_frc(union tgsi_exec_channel
*dst
,
188 const union tgsi_exec_channel
*src
)
190 dst
->f
[0] = src
->f
[0] - floorf(src
->f
[0]);
191 dst
->f
[1] = src
->f
[1] - floorf(src
->f
[1]);
192 dst
->f
[2] = src
->f
[2] - floorf(src
->f
[2]);
193 dst
->f
[3] = src
->f
[3] - floorf(src
->f
[3]);
197 micro_iabs(union tgsi_exec_channel
*dst
,
198 const union tgsi_exec_channel
*src
)
200 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
201 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
202 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
203 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
207 micro_ineg(union tgsi_exec_channel
*dst
,
208 const union tgsi_exec_channel
*src
)
210 dst
->i
[0] = -src
->i
[0];
211 dst
->i
[1] = -src
->i
[1];
212 dst
->i
[2] = -src
->i
[2];
213 dst
->i
[3] = -src
->i
[3];
217 micro_lg2(union tgsi_exec_channel
*dst
,
218 const union tgsi_exec_channel
*src
)
221 dst
->f
[0] = util_fast_log2(src
->f
[0]);
222 dst
->f
[1] = util_fast_log2(src
->f
[1]);
223 dst
->f
[2] = util_fast_log2(src
->f
[2]);
224 dst
->f
[3] = util_fast_log2(src
->f
[3]);
226 dst
->f
[0] = logf(src
->f
[0]) * 1.442695f
;
227 dst
->f
[1] = logf(src
->f
[1]) * 1.442695f
;
228 dst
->f
[2] = logf(src
->f
[2]) * 1.442695f
;
229 dst
->f
[3] = logf(src
->f
[3]) * 1.442695f
;
234 micro_lrp(union tgsi_exec_channel
*dst
,
235 const union tgsi_exec_channel
*src
)
237 dst
->f
[0] = src
[0].f
[0] * (src
[1].f
[0] - src
[2].f
[0]) + src
[2].f
[0];
238 dst
->f
[1] = src
[0].f
[1] * (src
[1].f
[1] - src
[2].f
[1]) + src
[2].f
[1];
239 dst
->f
[2] = src
[0].f
[2] * (src
[1].f
[2] - src
[2].f
[2]) + src
[2].f
[2];
240 dst
->f
[3] = src
[0].f
[3] * (src
[1].f
[3] - src
[2].f
[3]) + src
[2].f
[3];
244 micro_mad(union tgsi_exec_channel
*dst
,
245 const union tgsi_exec_channel
*src
)
247 dst
->f
[0] = src
[0].f
[0] * src
[1].f
[0] + src
[2].f
[0];
248 dst
->f
[1] = src
[0].f
[1] * src
[1].f
[1] + src
[2].f
[1];
249 dst
->f
[2] = src
[0].f
[2] * src
[1].f
[2] + src
[2].f
[2];
250 dst
->f
[3] = src
[0].f
[3] * src
[1].f
[3] + src
[2].f
[3];
254 micro_mov(union tgsi_exec_channel
*dst
,
255 const union tgsi_exec_channel
*src
)
257 dst
->u
[0] = src
->u
[0];
258 dst
->u
[1] = src
->u
[1];
259 dst
->u
[2] = src
->u
[2];
260 dst
->u
[3] = src
->u
[3];
264 micro_rcp(union tgsi_exec_channel
*dst
,
265 const union tgsi_exec_channel
*src
)
267 dst
->f
[0] = 1.0f
/ src
->f
[0];
268 dst
->f
[1] = 1.0f
/ src
->f
[1];
269 dst
->f
[2] = 1.0f
/ src
->f
[2];
270 dst
->f
[3] = 1.0f
/ src
->f
[3];
274 micro_rnd(union tgsi_exec_channel
*dst
,
275 const union tgsi_exec_channel
*src
)
277 dst
->f
[0] = floorf(src
->f
[0] + 0.5f
);
278 dst
->f
[1] = floorf(src
->f
[1] + 0.5f
);
279 dst
->f
[2] = floorf(src
->f
[2] + 0.5f
);
280 dst
->f
[3] = floorf(src
->f
[3] + 0.5f
);
284 micro_rsq(union tgsi_exec_channel
*dst
,
285 const union tgsi_exec_channel
*src
)
287 dst
->f
[0] = 1.0f
/ sqrtf(fabsf(src
->f
[0]));
288 dst
->f
[1] = 1.0f
/ sqrtf(fabsf(src
->f
[1]));
289 dst
->f
[2] = 1.0f
/ sqrtf(fabsf(src
->f
[2]));
290 dst
->f
[3] = 1.0f
/ sqrtf(fabsf(src
->f
[3]));
294 micro_seq(union tgsi_exec_channel
*dst
,
295 const union tgsi_exec_channel
*src
)
297 dst
->f
[0] = src
[0].f
[0] == src
[1].f
[0] ? 1.0f
: 0.0f
;
298 dst
->f
[1] = src
[0].f
[1] == src
[1].f
[1] ? 1.0f
: 0.0f
;
299 dst
->f
[2] = src
[0].f
[2] == src
[1].f
[2] ? 1.0f
: 0.0f
;
300 dst
->f
[3] = src
[0].f
[3] == src
[1].f
[3] ? 1.0f
: 0.0f
;
304 micro_sge(union tgsi_exec_channel
*dst
,
305 const union tgsi_exec_channel
*src
)
307 dst
->f
[0] = src
[0].f
[0] >= src
[1].f
[0] ? 1.0f
: 0.0f
;
308 dst
->f
[1] = src
[0].f
[1] >= src
[1].f
[1] ? 1.0f
: 0.0f
;
309 dst
->f
[2] = src
[0].f
[2] >= src
[1].f
[2] ? 1.0f
: 0.0f
;
310 dst
->f
[3] = src
[0].f
[3] >= src
[1].f
[3] ? 1.0f
: 0.0f
;
314 micro_sgn(union tgsi_exec_channel
*dst
,
315 const union tgsi_exec_channel
*src
)
317 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
318 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
319 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
320 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
324 micro_sgt(union tgsi_exec_channel
*dst
,
325 const union tgsi_exec_channel
*src
)
327 dst
->f
[0] = src
[0].f
[0] > src
[1].f
[0] ? 1.0f
: 0.0f
;
328 dst
->f
[1] = src
[0].f
[1] > src
[1].f
[1] ? 1.0f
: 0.0f
;
329 dst
->f
[2] = src
[0].f
[2] > src
[1].f
[2] ? 1.0f
: 0.0f
;
330 dst
->f
[3] = src
[0].f
[3] > src
[1].f
[3] ? 1.0f
: 0.0f
;
334 micro_sin(union tgsi_exec_channel
*dst
,
335 const union tgsi_exec_channel
*src
)
337 dst
->f
[0] = sinf(src
->f
[0]);
338 dst
->f
[1] = sinf(src
->f
[1]);
339 dst
->f
[2] = sinf(src
->f
[2]);
340 dst
->f
[3] = sinf(src
->f
[3]);
344 micro_sle(union tgsi_exec_channel
*dst
,
345 const union tgsi_exec_channel
*src
)
347 dst
->f
[0] = src
[0].f
[0] <= src
[1].f
[0] ? 1.0f
: 0.0f
;
348 dst
->f
[1] = src
[0].f
[1] <= src
[1].f
[1] ? 1.0f
: 0.0f
;
349 dst
->f
[2] = src
[0].f
[2] <= src
[1].f
[2] ? 1.0f
: 0.0f
;
350 dst
->f
[3] = src
[0].f
[3] <= src
[1].f
[3] ? 1.0f
: 0.0f
;
354 micro_slt(union tgsi_exec_channel
*dst
,
355 const union tgsi_exec_channel
*src
)
357 dst
->f
[0] = src
[0].f
[0] < src
[1].f
[0] ? 1.0f
: 0.0f
;
358 dst
->f
[1] = src
[0].f
[1] < src
[1].f
[1] ? 1.0f
: 0.0f
;
359 dst
->f
[2] = src
[0].f
[2] < src
[1].f
[2] ? 1.0f
: 0.0f
;
360 dst
->f
[3] = src
[0].f
[3] < src
[1].f
[3] ? 1.0f
: 0.0f
;
364 micro_sne(union tgsi_exec_channel
*dst
,
365 const union tgsi_exec_channel
*src
)
367 dst
->f
[0] = src
[0].f
[0] != src
[1].f
[0] ? 1.0f
: 0.0f
;
368 dst
->f
[1] = src
[0].f
[1] != src
[1].f
[1] ? 1.0f
: 0.0f
;
369 dst
->f
[2] = src
[0].f
[2] != src
[1].f
[2] ? 1.0f
: 0.0f
;
370 dst
->f
[3] = src
[0].f
[3] != src
[1].f
[3] ? 1.0f
: 0.0f
;
374 micro_trunc(union tgsi_exec_channel
*dst
,
375 const union tgsi_exec_channel
*src
)
377 dst
->f
[0] = (float)(int)src
->f
[0];
378 dst
->f
[1] = (float)(int)src
->f
[1];
379 dst
->f
[2] = (float)(int)src
->f
[2];
380 dst
->f
[3] = (float)(int)src
->f
[3];
389 enum tgsi_exec_datatype
{
390 TGSI_EXEC_DATA_FLOAT
,
396 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
398 #define TEMP_0_I TGSI_EXEC_TEMP_00000000_I
399 #define TEMP_0_C TGSI_EXEC_TEMP_00000000_C
400 #define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I
401 #define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C
402 #define TEMP_80_I TGSI_EXEC_TEMP_80000000_I
403 #define TEMP_80_C TGSI_EXEC_TEMP_80000000_C
404 #define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I
405 #define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C
406 #define TEMP_1_I TGSI_EXEC_TEMP_ONE_I
407 #define TEMP_1_C TGSI_EXEC_TEMP_ONE_C
408 #define TEMP_2_I TGSI_EXEC_TEMP_TWO_I
409 #define TEMP_2_C TGSI_EXEC_TEMP_TWO_C
410 #define TEMP_128_I TGSI_EXEC_TEMP_128_I
411 #define TEMP_128_C TGSI_EXEC_TEMP_128_C
412 #define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I
413 #define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C
414 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
415 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
416 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
417 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
418 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
419 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
420 #define TEMP_CC_I TGSI_EXEC_TEMP_CC_I
421 #define TEMP_CC_C TGSI_EXEC_TEMP_CC_C
422 #define TEMP_3_I TGSI_EXEC_TEMP_THREE_I
423 #define TEMP_3_C TGSI_EXEC_TEMP_THREE_C
424 #define TEMP_HALF_I TGSI_EXEC_TEMP_HALF_I
425 #define TEMP_HALF_C TGSI_EXEC_TEMP_HALF_C
426 #define TEMP_R0 TGSI_EXEC_TEMP_R0
427 #define TEMP_P0 TGSI_EXEC_TEMP_P0
429 #define IS_CHANNEL_ENABLED(INST, CHAN)\
430 ((INST).Dst[0].Register.WriteMask & (1 << (CHAN)))
432 #define IS_CHANNEL_ENABLED2(INST, CHAN)\
433 ((INST).Dst[1].Register.WriteMask & (1 << (CHAN)))
435 #define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\
436 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
437 if (IS_CHANNEL_ENABLED( INST, CHAN ))
439 #define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\
440 for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++)\
441 if (IS_CHANNEL_ENABLED2( INST, CHAN ))
444 /** The execution mask depends on the conditional mask and the loop mask */
445 #define UPDATE_EXEC_MASK(MACH) \
446 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
449 static const union tgsi_exec_channel ZeroVec
=
450 { { 0.0, 0.0, 0.0, 0.0 } };
453 #define CHECK_INF_OR_NAN(chan) do {\
454 assert(!util_is_inf_or_nan((chan)->f[0]));\
455 assert(!util_is_inf_or_nan((chan)->f[1]));\
456 assert(!util_is_inf_or_nan((chan)->f[2]));\
457 assert(!util_is_inf_or_nan((chan)->f[3]));\
463 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
465 debug_printf("%s = {%f, %f, %f, %f}\n",
466 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
473 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
475 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
477 debug_printf("Temp[%u] =\n", index
);
478 for (i
= 0; i
< 4; i
++) {
479 debug_printf(" %c: { %f, %f, %f, %f }\n",
491 * Check if there's a potential src/dst register data dependency when
492 * using SOA execution.
495 * This would expand into:
500 * The second instruction will have the wrong value for t0 if executed as-is.
503 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
507 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
508 if (writemask
== TGSI_WRITEMASK_X
||
509 writemask
== TGSI_WRITEMASK_Y
||
510 writemask
== TGSI_WRITEMASK_Z
||
511 writemask
== TGSI_WRITEMASK_W
||
512 writemask
== TGSI_WRITEMASK_NONE
) {
513 /* no chance of data dependency */
517 /* loop over src regs */
518 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
519 if ((inst
->Src
[i
].Register
.File
==
520 inst
->Dst
[0].Register
.File
) &&
521 (inst
->Src
[i
].Register
.Index
==
522 inst
->Dst
[0].Register
.Index
)) {
523 /* loop over dest channels */
524 uint channelsWritten
= 0x0;
525 FOR_EACH_ENABLED_CHANNEL(*inst
, chan
) {
526 /* check if we're reading a channel that's been written */
527 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
528 if (channelsWritten
& (1 << swizzle
)) {
532 channelsWritten
|= (1 << chan
);
541 * Initialize machine state by expanding tokens to full instructions,
542 * allocating temporary storage, setting up constants, etc.
543 * After this, we can call tgsi_exec_machine_run() many times.
546 tgsi_exec_machine_bind_shader(
547 struct tgsi_exec_machine
*mach
,
548 const struct tgsi_token
*tokens
,
550 struct tgsi_sampler
**samplers
)
553 struct tgsi_parse_context parse
;
554 struct tgsi_exec_labels
*labels
= &mach
->Labels
;
555 struct tgsi_full_instruction
*instructions
;
556 struct tgsi_full_declaration
*declarations
;
557 uint maxInstructions
= 10, numInstructions
= 0;
558 uint maxDeclarations
= 10, numDeclarations
= 0;
562 tgsi_dump(tokens
, 0);
567 mach
->Tokens
= tokens
;
568 mach
->Samplers
= samplers
;
570 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
571 if (k
!= TGSI_PARSE_OK
) {
572 debug_printf( "Problem parsing!\n" );
576 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
580 declarations
= (struct tgsi_full_declaration
*)
581 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
587 instructions
= (struct tgsi_full_instruction
*)
588 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
591 FREE( declarations
);
595 while( !tgsi_parse_end_of_tokens( &parse
) ) {
596 uint pointer
= parse
.Position
;
599 tgsi_parse_token( &parse
);
600 switch( parse
.FullToken
.Token
.Type
) {
601 case TGSI_TOKEN_TYPE_DECLARATION
:
602 /* save expanded declaration */
603 if (numDeclarations
== maxDeclarations
) {
604 declarations
= REALLOC(declarations
,
606 * sizeof(struct tgsi_full_declaration
),
607 (maxDeclarations
+ 10)
608 * sizeof(struct tgsi_full_declaration
));
609 maxDeclarations
+= 10;
611 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
613 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
614 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
619 memcpy(declarations
+ numDeclarations
,
620 &parse
.FullToken
.FullDeclaration
,
621 sizeof(declarations
[0]));
625 case TGSI_TOKEN_TYPE_IMMEDIATE
:
627 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
629 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
631 for( i
= 0; i
< size
; i
++ ) {
632 mach
->Imms
[mach
->ImmLimit
][i
] =
633 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
639 case TGSI_TOKEN_TYPE_INSTRUCTION
:
640 assert( labels
->count
< MAX_LABELS
);
642 labels
->labels
[labels
->count
][0] = instno
;
643 labels
->labels
[labels
->count
][1] = pointer
;
646 /* save expanded instruction */
647 if (numInstructions
== maxInstructions
) {
648 instructions
= REALLOC(instructions
,
650 * sizeof(struct tgsi_full_instruction
),
651 (maxInstructions
+ 10)
652 * sizeof(struct tgsi_full_instruction
));
653 maxInstructions
+= 10;
656 memcpy(instructions
+ numInstructions
,
657 &parse
.FullToken
.FullInstruction
,
658 sizeof(instructions
[0]));
663 case TGSI_TOKEN_TYPE_PROPERTY
:
670 tgsi_parse_free (&parse
);
672 if (mach
->Declarations
) {
673 FREE( mach
->Declarations
);
675 mach
->Declarations
= declarations
;
676 mach
->NumDeclarations
= numDeclarations
;
678 if (mach
->Instructions
) {
679 FREE( mach
->Instructions
);
681 mach
->Instructions
= instructions
;
682 mach
->NumInstructions
= numInstructions
;
686 struct tgsi_exec_machine
*
687 tgsi_exec_machine_create( void )
689 struct tgsi_exec_machine
*mach
;
692 mach
= align_malloc( sizeof *mach
, 16 );
696 memset(mach
, 0, sizeof(*mach
));
698 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
699 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
700 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
702 /* Setup constants. */
703 for( i
= 0; i
< 4; i
++ ) {
704 mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
].u
[i
] = 0x00000000;
705 mach
->Temps
[TEMP_7F_I
].xyzw
[TEMP_7F_C
].u
[i
] = 0x7FFFFFFF;
706 mach
->Temps
[TEMP_80_I
].xyzw
[TEMP_80_C
].u
[i
] = 0x80000000;
707 mach
->Temps
[TEMP_FF_I
].xyzw
[TEMP_FF_C
].u
[i
] = 0xFFFFFFFF;
708 mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
].f
[i
] = 1.0f
;
709 mach
->Temps
[TEMP_2_I
].xyzw
[TEMP_2_C
].f
[i
] = 2.0f
;
710 mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
].f
[i
] = 128.0f
;
711 mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
].f
[i
] = -128.0f
;
712 mach
->Temps
[TEMP_3_I
].xyzw
[TEMP_3_C
].f
[i
] = 3.0f
;
713 mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
].f
[i
] = 0.5f
;
717 /* silence warnings */
731 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
734 FREE(mach
->Instructions
);
735 FREE(mach
->Declarations
);
743 union tgsi_exec_channel
*dst
,
744 const union tgsi_exec_channel
*src0
,
745 const union tgsi_exec_channel
*src1
)
747 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
748 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
749 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
750 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
755 union tgsi_exec_channel
*dst
,
756 const union tgsi_exec_channel
*src0
,
757 const union tgsi_exec_channel
*src1
)
759 if (src1
->f
[0] != 0) {
760 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
762 if (src1
->f
[1] != 0) {
763 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
765 if (src1
->f
[2] != 0) {
766 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
768 if (src1
->f
[3] != 0) {
769 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
774 micro_float_clamp(union tgsi_exec_channel
*dst
,
775 const union tgsi_exec_channel
*src
)
779 for (i
= 0; i
< 4; i
++) {
780 if (src
->f
[i
] > 0.0f
) {
781 if (src
->f
[i
] > 1.884467e+019f
)
782 dst
->f
[i
] = 1.884467e+019f
;
783 else if (src
->f
[i
] < 5.42101e-020f
)
784 dst
->f
[i
] = 5.42101e-020f
;
786 dst
->f
[i
] = src
->f
[i
];
789 if (src
->f
[i
] < -1.884467e+019f
)
790 dst
->f
[i
] = -1.884467e+019f
;
791 else if (src
->f
[i
] > -5.42101e-020f
)
792 dst
->f
[i
] = -5.42101e-020f
;
794 dst
->f
[i
] = src
->f
[i
];
801 union tgsi_exec_channel
*dst
,
802 const union tgsi_exec_channel
*src0
,
803 const union tgsi_exec_channel
*src1
,
804 const union tgsi_exec_channel
*src2
,
805 const union tgsi_exec_channel
*src3
)
807 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
808 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
809 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
810 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
815 union tgsi_exec_channel
*dst
,
816 const union tgsi_exec_channel
*src0
,
817 const union tgsi_exec_channel
*src1
)
819 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
820 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
821 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
822 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
827 union tgsi_exec_channel
*dst
,
828 const union tgsi_exec_channel
*src0
,
829 const union tgsi_exec_channel
*src1
)
831 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
832 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
833 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
834 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
839 union tgsi_exec_channel
*dst
,
840 const union tgsi_exec_channel
*src0
,
841 const union tgsi_exec_channel
*src1
)
843 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
844 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
845 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
846 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
852 union tgsi_exec_channel
*dst0
,
853 union tgsi_exec_channel
*dst1
,
854 const union tgsi_exec_channel
*src0
,
855 const union tgsi_exec_channel
*src1
)
857 dst1
->i
[0] = src0
->i
[0] * src1
->i
[0];
858 dst1
->i
[1] = src0
->i
[1] * src1
->i
[1];
859 dst1
->i
[2] = src0
->i
[2] * src1
->i
[2];
860 dst1
->i
[3] = src0
->i
[3] * src1
->i
[3];
871 union tgsi_exec_channel
*dst0
,
872 union tgsi_exec_channel
*dst1
,
873 const union tgsi_exec_channel
*src0
,
874 const union tgsi_exec_channel
*src1
)
876 dst1
->u
[0] = src0
->u
[0] * src1
->u
[0];
877 dst1
->u
[1] = src0
->u
[1] * src1
->u
[1];
878 dst1
->u
[2] = src0
->u
[2] * src1
->u
[2];
879 dst1
->u
[3] = src0
->u
[3] * src1
->u
[3];
891 union tgsi_exec_channel
*dst
,
892 const union tgsi_exec_channel
*src0
,
893 const union tgsi_exec_channel
*src1
,
894 const union tgsi_exec_channel
*src2
)
896 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
897 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
898 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
899 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
905 union tgsi_exec_channel
*dst
,
906 const union tgsi_exec_channel
*src
)
908 dst
->f
[0] = -src
->f
[0];
909 dst
->f
[1] = -src
->f
[1];
910 dst
->f
[2] = -src
->f
[2];
911 dst
->f
[3] = -src
->f
[3];
916 union tgsi_exec_channel
*dst
,
917 const union tgsi_exec_channel
*src0
,
918 const union tgsi_exec_channel
*src1
)
921 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
922 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
923 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
924 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
926 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
927 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
928 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
929 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
934 micro_sqrt( union tgsi_exec_channel
*dst
,
935 const union tgsi_exec_channel
*src
)
937 dst
->f
[0] = sqrtf( src
->f
[0] );
938 dst
->f
[1] = sqrtf( src
->f
[1] );
939 dst
->f
[2] = sqrtf( src
->f
[2] );
940 dst
->f
[3] = sqrtf( src
->f
[3] );
945 union tgsi_exec_channel
*dst
,
946 const union tgsi_exec_channel
*src0
,
947 const union tgsi_exec_channel
*src1
)
949 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
950 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
951 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
952 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
956 fetch_src_file_channel(
957 const struct tgsi_exec_machine
*mach
,
960 const union tgsi_exec_channel
*index
,
961 union tgsi_exec_channel
*chan
)
969 case TGSI_FILE_CONSTANT
:
970 assert(mach
->Consts
);
974 chan
->f
[0] = mach
->Consts
[index
->i
[0]][swizzle
];
978 chan
->f
[1] = mach
->Consts
[index
->i
[1]][swizzle
];
982 chan
->f
[2] = mach
->Consts
[index
->i
[2]][swizzle
];
986 chan
->f
[3] = mach
->Consts
[index
->i
[3]][swizzle
];
989 case TGSI_FILE_INPUT
:
990 case TGSI_FILE_SYSTEM_VALUE
:
991 chan
->u
[0] = mach
->Inputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
992 chan
->u
[1] = mach
->Inputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
993 chan
->u
[2] = mach
->Inputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
994 chan
->u
[3] = mach
->Inputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
997 case TGSI_FILE_TEMPORARY
:
998 assert(index
->i
[0] < TGSI_EXEC_NUM_TEMPS
);
999 chan
->u
[0] = mach
->Temps
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1000 chan
->u
[1] = mach
->Temps
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1001 chan
->u
[2] = mach
->Temps
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1002 chan
->u
[3] = mach
->Temps
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1005 case TGSI_FILE_IMMEDIATE
:
1006 assert( index
->i
[0] < (int) mach
->ImmLimit
);
1007 chan
->f
[0] = mach
->Imms
[index
->i
[0]][swizzle
];
1008 assert( index
->i
[1] < (int) mach
->ImmLimit
);
1009 chan
->f
[1] = mach
->Imms
[index
->i
[1]][swizzle
];
1010 assert( index
->i
[2] < (int) mach
->ImmLimit
);
1011 chan
->f
[2] = mach
->Imms
[index
->i
[2]][swizzle
];
1012 assert( index
->i
[3] < (int) mach
->ImmLimit
);
1013 chan
->f
[3] = mach
->Imms
[index
->i
[3]][swizzle
];
1016 case TGSI_FILE_ADDRESS
:
1017 chan
->u
[0] = mach
->Addrs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1018 chan
->u
[1] = mach
->Addrs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1019 chan
->u
[2] = mach
->Addrs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1020 chan
->u
[3] = mach
->Addrs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1023 case TGSI_FILE_PREDICATE
:
1024 assert(index
->i
[0] < TGSI_EXEC_NUM_PREDS
);
1025 assert(index
->i
[1] < TGSI_EXEC_NUM_PREDS
);
1026 assert(index
->i
[2] < TGSI_EXEC_NUM_PREDS
);
1027 assert(index
->i
[3] < TGSI_EXEC_NUM_PREDS
);
1028 chan
->u
[0] = mach
->Predicates
[0].xyzw
[swizzle
].u
[0];
1029 chan
->u
[1] = mach
->Predicates
[0].xyzw
[swizzle
].u
[1];
1030 chan
->u
[2] = mach
->Predicates
[0].xyzw
[swizzle
].u
[2];
1031 chan
->u
[3] = mach
->Predicates
[0].xyzw
[swizzle
].u
[3];
1034 case TGSI_FILE_OUTPUT
:
1035 /* vertex/fragment output vars can be read too */
1036 chan
->u
[0] = mach
->Outputs
[index
->i
[0]].xyzw
[swizzle
].u
[0];
1037 chan
->u
[1] = mach
->Outputs
[index
->i
[1]].xyzw
[swizzle
].u
[1];
1038 chan
->u
[2] = mach
->Outputs
[index
->i
[2]].xyzw
[swizzle
].u
[2];
1039 chan
->u
[3] = mach
->Outputs
[index
->i
[3]].xyzw
[swizzle
].u
[3];
1053 fetch_source(const struct tgsi_exec_machine
*mach
,
1054 union tgsi_exec_channel
*chan
,
1055 const struct tgsi_full_src_register
*reg
,
1056 const uint chan_index
,
1057 enum tgsi_exec_datatype src_datatype
)
1059 union tgsi_exec_channel index
;
1062 /* We start with a direct index into a register file.
1066 * file = Register.File
1067 * [1] = Register.Index
1072 index
.i
[3] = reg
->Register
.Index
;
1074 /* There is an extra source register that indirectly subscripts
1075 * a register file. The direct index now becomes an offset
1076 * that is being added to the indirect register.
1080 * ind = Indirect.File
1081 * [2] = Indirect.Index
1082 * .x = Indirect.SwizzleX
1084 if (reg
->Register
.Indirect
) {
1085 union tgsi_exec_channel index2
;
1086 union tgsi_exec_channel indir_index
;
1087 const uint execmask
= mach
->ExecMask
;
1090 /* which address register (always zero now) */
1094 index2
.i
[3] = reg
->Indirect
.Index
;
1096 /* get current value of address register[swizzle] */
1097 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1098 fetch_src_file_channel(
1105 /* add value of address register to the offset */
1106 index
.i
[0] += indir_index
.i
[0];
1107 index
.i
[1] += indir_index
.i
[1];
1108 index
.i
[2] += indir_index
.i
[2];
1109 index
.i
[3] += indir_index
.i
[3];
1111 /* for disabled execution channels, zero-out the index to
1112 * avoid using a potential garbage value.
1114 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1115 if ((execmask
& (1 << i
)) == 0)
1120 /* There is an extra source register that is a second
1121 * subscript to a register file. Effectively it means that
1122 * the register file is actually a 2D array of registers.
1124 * file[1][3] == file[1*sizeof(file[1])+3],
1126 * [3] = Dimension.Index
1128 if (reg
->Register
.Dimension
) {
1129 /* The size of the first-order array depends on the register file type.
1130 * We need to multiply the index to the first array to get an effective,
1131 * "flat" index that points to the beginning of the second-order array.
1133 switch (reg
->Register
.File
) {
1134 case TGSI_FILE_INPUT
:
1135 case TGSI_FILE_SYSTEM_VALUE
:
1136 index
.i
[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1137 index
.i
[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1138 index
.i
[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1139 index
.i
[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS
;
1141 case TGSI_FILE_CONSTANT
:
1142 index
.i
[0] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1143 index
.i
[1] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1144 index
.i
[2] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1145 index
.i
[3] *= TGSI_EXEC_MAX_CONST_BUFFER
;
1151 index
.i
[0] += reg
->Dimension
.Index
;
1152 index
.i
[1] += reg
->Dimension
.Index
;
1153 index
.i
[2] += reg
->Dimension
.Index
;
1154 index
.i
[3] += reg
->Dimension
.Index
;
1156 /* Again, the second subscript index can be addressed indirectly
1157 * identically to the first one.
1158 * Nothing stops us from indirectly addressing the indirect register,
1159 * but there is no need for that, so we won't exercise it.
1161 * file[1][ind[4].y+3],
1163 * ind = DimIndirect.File
1164 * [4] = DimIndirect.Index
1165 * .y = DimIndirect.SwizzleX
1167 if (reg
->Dimension
.Indirect
) {
1168 union tgsi_exec_channel index2
;
1169 union tgsi_exec_channel indir_index
;
1170 const uint execmask
= mach
->ExecMask
;
1176 index2
.i
[3] = reg
->DimIndirect
.Index
;
1178 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, CHAN_X
);
1179 fetch_src_file_channel(
1181 reg
->DimIndirect
.File
,
1186 index
.i
[0] += indir_index
.i
[0];
1187 index
.i
[1] += indir_index
.i
[1];
1188 index
.i
[2] += indir_index
.i
[2];
1189 index
.i
[3] += indir_index
.i
[3];
1191 /* for disabled execution channels, zero-out the index to
1192 * avoid using a potential garbage value.
1194 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1195 if ((execmask
& (1 << i
)) == 0)
1200 /* If by any chance there was a need for a 3D array of register
1201 * files, we would have to check whether Dimension is followed
1202 * by a dimension register and continue the saga.
1206 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1207 fetch_src_file_channel(
1214 if (reg
->Register
.Absolute
) {
1215 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1216 micro_abs(chan
, chan
);
1218 micro_iabs(chan
, chan
);
1222 if (reg
->Register
.Negate
) {
1223 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1224 micro_neg(chan
, chan
);
1226 micro_ineg(chan
, chan
);
1232 store_dest(struct tgsi_exec_machine
*mach
,
1233 const union tgsi_exec_channel
*chan
,
1234 const struct tgsi_full_dst_register
*reg
,
1235 const struct tgsi_full_instruction
*inst
,
1237 enum tgsi_exec_datatype dst_datatype
)
1240 union tgsi_exec_channel null
;
1241 union tgsi_exec_channel
*dst
;
1242 uint execmask
= mach
->ExecMask
;
1243 int offset
= 0; /* indirection offset */
1246 if (dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1247 CHECK_INF_OR_NAN(chan
);
1250 /* There is an extra source register that indirectly subscripts
1251 * a register file. The direct index now becomes an offset
1252 * that is being added to the indirect register.
1256 * ind = Indirect.File
1257 * [2] = Indirect.Index
1258 * .x = Indirect.SwizzleX
1260 if (reg
->Register
.Indirect
) {
1261 union tgsi_exec_channel index
;
1262 union tgsi_exec_channel indir_index
;
1265 /* which address register (always zero for now) */
1269 index
.i
[3] = reg
->Indirect
.Index
;
1271 /* get current value of address register[swizzle] */
1272 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, CHAN_X
);
1274 /* fetch values from the address/indirection register */
1275 fetch_src_file_channel(
1282 /* save indirection offset */
1283 offset
= indir_index
.i
[0];
1286 switch (reg
->Register
.File
) {
1287 case TGSI_FILE_NULL
:
1291 case TGSI_FILE_OUTPUT
:
1292 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1293 + reg
->Register
.Index
;
1294 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1296 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1297 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1298 for (i
= 0; i
< QUAD_SIZE
; i
++)
1299 if (execmask
& (1 << i
))
1300 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1301 fprintf(stderr
, ")\n");
1306 case TGSI_FILE_TEMPORARY
:
1307 index
= reg
->Register
.Index
;
1308 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1309 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1312 case TGSI_FILE_ADDRESS
:
1313 index
= reg
->Register
.Index
;
1314 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1317 case TGSI_FILE_LOOP
:
1318 assert(reg
->Register
.Index
== 0);
1319 assert(mach
->LoopCounterStackTop
> 0);
1320 assert(chan_index
== CHAN_X
);
1321 dst
= &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[chan_index
];
1324 case TGSI_FILE_PREDICATE
:
1325 index
= reg
->Register
.Index
;
1326 assert(index
< TGSI_EXEC_NUM_PREDS
);
1327 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1335 if (inst
->Instruction
.Predicate
) {
1337 union tgsi_exec_channel
*pred
;
1339 switch (chan_index
) {
1341 swizzle
= inst
->Predicate
.SwizzleX
;
1344 swizzle
= inst
->Predicate
.SwizzleY
;
1347 swizzle
= inst
->Predicate
.SwizzleZ
;
1350 swizzle
= inst
->Predicate
.SwizzleW
;
1357 assert(inst
->Predicate
.Index
== 0);
1359 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1361 if (inst
->Predicate
.Negate
) {
1362 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1364 execmask
&= ~(1 << i
);
1368 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1370 execmask
&= ~(1 << i
);
1376 switch (inst
->Instruction
.Saturate
) {
1378 for (i
= 0; i
< QUAD_SIZE
; i
++)
1379 if (execmask
& (1 << i
))
1380 dst
->i
[i
] = chan
->i
[i
];
1383 case TGSI_SAT_ZERO_ONE
:
1384 for (i
= 0; i
< QUAD_SIZE
; i
++)
1385 if (execmask
& (1 << i
)) {
1386 if (chan
->f
[i
] < 0.0f
)
1388 else if (chan
->f
[i
] > 1.0f
)
1391 dst
->i
[i
] = chan
->i
[i
];
1395 case TGSI_SAT_MINUS_PLUS_ONE
:
1396 for (i
= 0; i
< QUAD_SIZE
; i
++)
1397 if (execmask
& (1 << i
)) {
1398 if (chan
->f
[i
] < -1.0f
)
1400 else if (chan
->f
[i
] > 1.0f
)
1403 dst
->i
[i
] = chan
->i
[i
];
1412 #define FETCH(VAL,INDEX,CHAN)\
1413 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1415 #define STORE(VAL,INDEX,CHAN)\
1416 store_dest(mach, VAL, &inst->Dst[INDEX], inst, CHAN, TGSI_EXEC_DATA_FLOAT)
1420 * Execute ARB-style KIL which is predicated by a src register.
1421 * Kill fragment if any of the four values is less than zero.
1424 exec_kil(struct tgsi_exec_machine
*mach
,
1425 const struct tgsi_full_instruction
*inst
)
1429 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1430 union tgsi_exec_channel r
[1];
1432 /* This mask stores component bits that were already tested. */
1435 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1440 /* unswizzle channel */
1441 swizzle
= tgsi_util_get_full_src_register_swizzle (
1445 /* check if the component has not been already tested */
1446 if (uniquemask
& (1 << swizzle
))
1448 uniquemask
|= 1 << swizzle
;
1450 FETCH(&r
[0], 0, chan_index
);
1451 for (i
= 0; i
< 4; i
++)
1452 if (r
[0].f
[i
] < 0.0f
)
1456 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1460 * Execute NVIDIA-style KIL which is predicated by a condition code.
1461 * Kill fragment if the condition code is TRUE.
1464 exec_kilp(struct tgsi_exec_machine
*mach
,
1465 const struct tgsi_full_instruction
*inst
)
1467 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1469 /* "unconditional" kil */
1470 kilmask
= mach
->ExecMask
;
1471 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1475 emit_vertex(struct tgsi_exec_machine
*mach
)
1477 /* FIXME: check for exec mask correctly
1479 for (i = 0; i < QUAD_SIZE; ++i) {
1480 if ((mach->ExecMask & (1 << i)))
1482 if (mach
->ExecMask
) {
1483 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1484 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1489 emit_primitive(struct tgsi_exec_machine
*mach
)
1491 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1492 /* FIXME: check for exec mask correctly
1494 for (i = 0; i < QUAD_SIZE; ++i) {
1495 if ((mach->ExecMask & (1 << i)))
1497 if (mach
->ExecMask
) {
1499 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1500 mach
->Primitives
[*prim_count
] = 0;
1505 * Fetch a four texture samples using STR texture coordinates.
1508 fetch_texel( struct tgsi_sampler
*sampler
,
1509 const union tgsi_exec_channel
*s
,
1510 const union tgsi_exec_channel
*t
,
1511 const union tgsi_exec_channel
*p
,
1512 const union tgsi_exec_channel
*c0
,
1513 enum tgsi_sampler_control control
,
1514 union tgsi_exec_channel
*r
,
1515 union tgsi_exec_channel
*g
,
1516 union tgsi_exec_channel
*b
,
1517 union tgsi_exec_channel
*a
)
1520 float rgba
[NUM_CHANNELS
][QUAD_SIZE
];
1522 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, c0
->f
, control
, rgba
);
1524 for (j
= 0; j
< 4; j
++) {
1525 r
->f
[j
] = rgba
[0][j
];
1526 g
->f
[j
] = rgba
[1][j
];
1527 b
->f
[j
] = rgba
[2][j
];
1528 a
->f
[j
] = rgba
[3][j
];
1533 #define TEX_MODIFIER_NONE 0
1534 #define TEX_MODIFIER_PROJECTED 1
1535 #define TEX_MODIFIER_LOD_BIAS 2
1536 #define TEX_MODIFIER_EXPLICIT_LOD 3
1540 exec_tex(struct tgsi_exec_machine
*mach
,
1541 const struct tgsi_full_instruction
*inst
,
1544 const uint unit
= inst
->Src
[1].Register
.Index
;
1545 union tgsi_exec_channel r
[4];
1546 const union tgsi_exec_channel
*lod
= &ZeroVec
;
1547 enum tgsi_sampler_control control
;
1550 if (modifier
!= TEX_MODIFIER_NONE
) {
1551 FETCH(&r
[3], 0, CHAN_W
);
1552 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
1557 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
1558 control
= tgsi_sampler_lod_explicit
;
1560 control
= tgsi_sampler_lod_bias
;
1563 switch (inst
->Texture
.Texture
) {
1564 case TGSI_TEXTURE_1D
:
1565 case TGSI_TEXTURE_SHADOW1D
:
1566 FETCH(&r
[0], 0, CHAN_X
);
1568 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1569 micro_div(&r
[0], &r
[0], &r
[3]);
1572 fetch_texel(mach
->Samplers
[unit
],
1573 &r
[0], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, LOD */
1575 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1578 case TGSI_TEXTURE_2D
:
1579 case TGSI_TEXTURE_RECT
:
1580 case TGSI_TEXTURE_SHADOW2D
:
1581 case TGSI_TEXTURE_SHADOWRECT
:
1582 FETCH(&r
[0], 0, CHAN_X
);
1583 FETCH(&r
[1], 0, CHAN_Y
);
1584 FETCH(&r
[2], 0, CHAN_Z
);
1586 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1587 micro_div(&r
[0], &r
[0], &r
[3]);
1588 micro_div(&r
[1], &r
[1], &r
[3]);
1589 micro_div(&r
[2], &r
[2], &r
[3]);
1592 fetch_texel(mach
->Samplers
[unit
],
1593 &r
[0], &r
[1], &r
[2], lod
, /* S, T, P, LOD */
1595 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1598 case TGSI_TEXTURE_3D
:
1599 case TGSI_TEXTURE_CUBE
:
1600 FETCH(&r
[0], 0, CHAN_X
);
1601 FETCH(&r
[1], 0, CHAN_Y
);
1602 FETCH(&r
[2], 0, CHAN_Z
);
1604 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1605 micro_div(&r
[0], &r
[0], &r
[3]);
1606 micro_div(&r
[1], &r
[1], &r
[3]);
1607 micro_div(&r
[2], &r
[2], &r
[3]);
1610 fetch_texel(mach
->Samplers
[unit
],
1611 &r
[0], &r
[1], &r
[2], lod
,
1613 &r
[0], &r
[1], &r
[2], &r
[3]);
1620 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1621 STORE(&r
[chan_index
], 0, chan_index
);
1626 exec_txd(struct tgsi_exec_machine
*mach
,
1627 const struct tgsi_full_instruction
*inst
)
1629 const uint unit
= inst
->Src
[3].Register
.Index
;
1630 union tgsi_exec_channel r
[4];
1634 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1637 switch (inst
->Texture
.Texture
) {
1638 case TGSI_TEXTURE_1D
:
1639 case TGSI_TEXTURE_SHADOW1D
:
1641 FETCH(&r
[0], 0, CHAN_X
);
1643 fetch_texel(mach
->Samplers
[unit
],
1644 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, BIAS */
1645 tgsi_sampler_lod_bias
,
1646 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1649 case TGSI_TEXTURE_2D
:
1650 case TGSI_TEXTURE_RECT
:
1651 case TGSI_TEXTURE_SHADOW2D
:
1652 case TGSI_TEXTURE_SHADOWRECT
:
1654 FETCH(&r
[0], 0, CHAN_X
);
1655 FETCH(&r
[1], 0, CHAN_Y
);
1656 FETCH(&r
[2], 0, CHAN_Z
);
1658 fetch_texel(mach
->Samplers
[unit
],
1659 &r
[0], &r
[1], &r
[2], &ZeroVec
, /* inputs */
1660 tgsi_sampler_lod_bias
,
1661 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1664 case TGSI_TEXTURE_3D
:
1665 case TGSI_TEXTURE_CUBE
:
1667 FETCH(&r
[0], 0, CHAN_X
);
1668 FETCH(&r
[1], 0, CHAN_Y
);
1669 FETCH(&r
[2], 0, CHAN_Z
);
1671 fetch_texel(mach
->Samplers
[unit
],
1672 &r
[0], &r
[1], &r
[2], &ZeroVec
,
1673 tgsi_sampler_lod_bias
,
1674 &r
[0], &r
[1], &r
[2], &r
[3]);
1681 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
1682 STORE(&r
[chan_index
], 0, chan_index
);
1688 * Evaluate a constant-valued coefficient at the position of the
1693 struct tgsi_exec_machine
*mach
,
1699 for( i
= 0; i
< QUAD_SIZE
; i
++ ) {
1700 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
1705 * Evaluate a linear-valued coefficient at the position of the
1710 struct tgsi_exec_machine
*mach
,
1714 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1715 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1716 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1717 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1718 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1719 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
1720 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
1721 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
1722 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
1726 * Evaluate a perspective-valued coefficient at the position of the
1730 eval_perspective_coef(
1731 struct tgsi_exec_machine
*mach
,
1735 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
1736 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
1737 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
1738 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
1739 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
1740 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
1741 /* divide by W here */
1742 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
1743 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
1744 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
1745 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
1749 typedef void (* eval_coef_func
)(
1750 struct tgsi_exec_machine
*mach
,
1755 exec_declaration(struct tgsi_exec_machine
*mach
,
1756 const struct tgsi_full_declaration
*decl
)
1758 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
1759 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
||
1760 decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1761 uint first
, last
, mask
;
1763 first
= decl
->Range
.First
;
1764 last
= decl
->Range
.Last
;
1765 mask
= decl
->Declaration
.UsageMask
;
1767 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_POSITION
) {
1768 assert(decl
->Semantic
.Index
== 0);
1769 assert(first
== last
);
1770 assert(mask
== TGSI_WRITEMASK_XYZW
);
1772 mach
->Inputs
[first
] = mach
->QuadPos
;
1773 } else if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
1776 assert(decl
->Semantic
.Index
== 0);
1777 assert(first
== last
);
1779 for (i
= 0; i
< QUAD_SIZE
; i
++) {
1780 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
1783 eval_coef_func eval
;
1786 switch (decl
->Declaration
.Interpolate
) {
1787 case TGSI_INTERPOLATE_CONSTANT
:
1788 eval
= eval_constant_coef
;
1791 case TGSI_INTERPOLATE_LINEAR
:
1792 eval
= eval_linear_coef
;
1795 case TGSI_INTERPOLATE_PERSPECTIVE
:
1796 eval
= eval_perspective_coef
;
1804 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
1805 if (mask
& (1 << j
)) {
1806 for (i
= first
; i
<= last
; i
++) {
1816 typedef void (* micro_op
)(union tgsi_exec_channel
*dst
,
1817 const union tgsi_exec_channel
*src
);
1820 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
1821 const struct tgsi_full_instruction
*inst
,
1823 enum tgsi_exec_datatype dst_datatype
,
1824 enum tgsi_exec_datatype src_datatype
)
1827 union tgsi_exec_channel src
;
1828 union tgsi_exec_channel dst
;
1830 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
, src_datatype
);
1832 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1833 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1834 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1840 exec_vector_unary(struct tgsi_exec_machine
*mach
,
1841 const struct tgsi_full_instruction
*inst
,
1843 enum tgsi_exec_datatype dst_datatype
,
1844 enum tgsi_exec_datatype src_datatype
)
1847 struct tgsi_exec_vector dst
;
1849 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1850 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1851 union tgsi_exec_channel src
;
1853 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
1854 op(&dst
.xyzw
[chan
], &src
);
1857 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1858 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1859 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1865 exec_vector_binary(struct tgsi_exec_machine
*mach
,
1866 const struct tgsi_full_instruction
*inst
,
1868 enum tgsi_exec_datatype dst_datatype
,
1869 enum tgsi_exec_datatype src_datatype
)
1872 struct tgsi_exec_vector dst
;
1874 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1875 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1876 union tgsi_exec_channel src
[2];
1878 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
1879 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
1880 op(&dst
.xyzw
[chan
], src
);
1883 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1884 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1885 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1891 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
1892 const struct tgsi_full_instruction
*inst
,
1894 enum tgsi_exec_datatype dst_datatype
,
1895 enum tgsi_exec_datatype src_datatype
)
1898 struct tgsi_exec_vector dst
;
1900 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1901 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1902 union tgsi_exec_channel src
[3];
1904 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
1905 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
1906 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
1907 op(&dst
.xyzw
[chan
], src
);
1910 for (chan
= 0; chan
< NUM_CHANNELS
; chan
++) {
1911 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1912 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
1918 exec_break(struct tgsi_exec_machine
*mach
)
1920 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
1921 /* turn off loop channels for each enabled exec channel */
1922 mach
->LoopMask
&= ~mach
->ExecMask
;
1923 /* Todo: if mach->LoopMask == 0, jump to end of loop */
1924 UPDATE_EXEC_MASK(mach
);
1926 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
1928 mach
->Switch
.mask
= 0x0;
1930 UPDATE_EXEC_MASK(mach
);
1935 exec_switch(struct tgsi_exec_machine
*mach
,
1936 const struct tgsi_full_instruction
*inst
)
1938 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
1939 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
1941 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
1942 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
1943 mach
->Switch
.mask
= 0x0;
1944 mach
->Switch
.defaultMask
= 0x0;
1946 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
1947 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
1949 UPDATE_EXEC_MASK(mach
);
1953 exec_case(struct tgsi_exec_machine
*mach
,
1954 const struct tgsi_full_instruction
*inst
)
1956 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
1957 union tgsi_exec_channel src
;
1960 fetch_source(mach
, &src
, &inst
->Src
[0], CHAN_X
, TGSI_EXEC_DATA_UINT
);
1962 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
1965 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
1968 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
1971 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
1975 mach
->Switch
.defaultMask
|= mask
;
1977 mach
->Switch
.mask
|= mask
& prevMask
;
1979 UPDATE_EXEC_MASK(mach
);
1983 exec_default(struct tgsi_exec_machine
*mach
)
1985 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
1987 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
1989 UPDATE_EXEC_MASK(mach
);
1993 exec_endswitch(struct tgsi_exec_machine
*mach
)
1995 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
1996 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
1998 UPDATE_EXEC_MASK(mach
);
2002 micro_i2f(union tgsi_exec_channel
*dst
,
2003 const union tgsi_exec_channel
*src
)
2005 dst
->f
[0] = (float)src
->i
[0];
2006 dst
->f
[1] = (float)src
->i
[1];
2007 dst
->f
[2] = (float)src
->i
[2];
2008 dst
->f
[3] = (float)src
->i
[3];
2012 micro_not(union tgsi_exec_channel
*dst
,
2013 const union tgsi_exec_channel
*src
)
2015 dst
->u
[0] = ~src
->u
[0];
2016 dst
->u
[1] = ~src
->u
[1];
2017 dst
->u
[2] = ~src
->u
[2];
2018 dst
->u
[3] = ~src
->u
[3];
2022 micro_shl(union tgsi_exec_channel
*dst
,
2023 const union tgsi_exec_channel
*src
)
2025 dst
->u
[0] = src
[0].u
[0] << src
[1].u
[0];
2026 dst
->u
[1] = src
[0].u
[1] << src
[1].u
[1];
2027 dst
->u
[2] = src
[0].u
[2] << src
[1].u
[2];
2028 dst
->u
[3] = src
[0].u
[3] << src
[1].u
[3];
2032 micro_and(union tgsi_exec_channel
*dst
,
2033 const union tgsi_exec_channel
*src
)
2035 dst
->u
[0] = src
[0].u
[0] & src
[1].u
[0];
2036 dst
->u
[1] = src
[0].u
[1] & src
[1].u
[1];
2037 dst
->u
[2] = src
[0].u
[2] & src
[1].u
[2];
2038 dst
->u
[3] = src
[0].u
[3] & src
[1].u
[3];
2042 micro_or(union tgsi_exec_channel
*dst
,
2043 const union tgsi_exec_channel
*src
)
2045 dst
->u
[0] = src
[0].u
[0] | src
[1].u
[0];
2046 dst
->u
[1] = src
[0].u
[1] | src
[1].u
[1];
2047 dst
->u
[2] = src
[0].u
[2] | src
[1].u
[2];
2048 dst
->u
[3] = src
[0].u
[3] | src
[1].u
[3];
2052 micro_xor(union tgsi_exec_channel
*dst
,
2053 const union tgsi_exec_channel
*src
)
2055 dst
->u
[0] = src
[0].u
[0] ^ src
[1].u
[0];
2056 dst
->u
[1] = src
[0].u
[1] ^ src
[1].u
[1];
2057 dst
->u
[2] = src
[0].u
[2] ^ src
[1].u
[2];
2058 dst
->u
[3] = src
[0].u
[3] ^ src
[1].u
[3];
2062 micro_f2i(union tgsi_exec_channel
*dst
,
2063 const union tgsi_exec_channel
*src
)
2065 dst
->i
[0] = (int)src
->f
[0];
2066 dst
->i
[1] = (int)src
->f
[1];
2067 dst
->i
[2] = (int)src
->f
[2];
2068 dst
->i
[3] = (int)src
->f
[3];
2072 micro_idiv(union tgsi_exec_channel
*dst
,
2073 const union tgsi_exec_channel
*src
)
2075 dst
->i
[0] = src
[0].i
[0] / src
[1].i
[0];
2076 dst
->i
[1] = src
[0].i
[1] / src
[1].i
[1];
2077 dst
->i
[2] = src
[0].i
[2] / src
[1].i
[2];
2078 dst
->i
[3] = src
[0].i
[3] / src
[1].i
[3];
2082 micro_imax(union tgsi_exec_channel
*dst
,
2083 const union tgsi_exec_channel
*src
)
2085 dst
->i
[0] = src
[0].i
[0] > src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
2086 dst
->i
[1] = src
[0].i
[1] > src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
2087 dst
->i
[2] = src
[0].i
[2] > src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
2088 dst
->i
[3] = src
[0].i
[3] > src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
2092 micro_imin(union tgsi_exec_channel
*dst
,
2093 const union tgsi_exec_channel
*src
)
2095 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? src
[0].i
[0] : src
[1].i
[0];
2096 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? src
[0].i
[1] : src
[1].i
[1];
2097 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? src
[0].i
[2] : src
[1].i
[2];
2098 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? src
[0].i
[3] : src
[1].i
[3];
2102 micro_isge(union tgsi_exec_channel
*dst
,
2103 const union tgsi_exec_channel
*src
)
2105 dst
->i
[0] = src
[0].i
[0] >= src
[1].i
[0] ? -1 : 0;
2106 dst
->i
[1] = src
[0].i
[1] >= src
[1].i
[1] ? -1 : 0;
2107 dst
->i
[2] = src
[0].i
[2] >= src
[1].i
[2] ? -1 : 0;
2108 dst
->i
[3] = src
[0].i
[3] >= src
[1].i
[3] ? -1 : 0;
2112 micro_ishr(union tgsi_exec_channel
*dst
,
2113 const union tgsi_exec_channel
*src
)
2115 dst
->i
[0] = src
[0].i
[0] >> src
[1].i
[0];
2116 dst
->i
[1] = src
[0].i
[1] >> src
[1].i
[1];
2117 dst
->i
[2] = src
[0].i
[2] >> src
[1].i
[2];
2118 dst
->i
[3] = src
[0].i
[3] >> src
[1].i
[3];
2122 micro_islt(union tgsi_exec_channel
*dst
,
2123 const union tgsi_exec_channel
*src
)
2125 dst
->i
[0] = src
[0].i
[0] < src
[1].i
[0] ? -1 : 0;
2126 dst
->i
[1] = src
[0].i
[1] < src
[1].i
[1] ? -1 : 0;
2127 dst
->i
[2] = src
[0].i
[2] < src
[1].i
[2] ? -1 : 0;
2128 dst
->i
[3] = src
[0].i
[3] < src
[1].i
[3] ? -1 : 0;
2132 micro_f2u(union tgsi_exec_channel
*dst
,
2133 const union tgsi_exec_channel
*src
)
2135 dst
->u
[0] = (uint
)src
->f
[0];
2136 dst
->u
[1] = (uint
)src
->f
[1];
2137 dst
->u
[2] = (uint
)src
->f
[2];
2138 dst
->u
[3] = (uint
)src
->f
[3];
2142 micro_u2f(union tgsi_exec_channel
*dst
,
2143 const union tgsi_exec_channel
*src
)
2145 dst
->f
[0] = (float)src
->u
[0];
2146 dst
->f
[1] = (float)src
->u
[1];
2147 dst
->f
[2] = (float)src
->u
[2];
2148 dst
->f
[3] = (float)src
->u
[3];
2152 micro_uadd(union tgsi_exec_channel
*dst
,
2153 const union tgsi_exec_channel
*src
)
2155 dst
->u
[0] = src
[0].u
[0] + src
[1].u
[0];
2156 dst
->u
[1] = src
[0].u
[1] + src
[1].u
[1];
2157 dst
->u
[2] = src
[0].u
[2] + src
[1].u
[2];
2158 dst
->u
[3] = src
[0].u
[3] + src
[1].u
[3];
2162 micro_udiv(union tgsi_exec_channel
*dst
,
2163 const union tgsi_exec_channel
*src
)
2165 dst
->u
[0] = src
[0].u
[0] / src
[1].u
[0];
2166 dst
->u
[1] = src
[0].u
[1] / src
[1].u
[1];
2167 dst
->u
[2] = src
[0].u
[2] / src
[1].u
[2];
2168 dst
->u
[3] = src
[0].u
[3] / src
[1].u
[3];
2172 micro_umad(union tgsi_exec_channel
*dst
,
2173 const union tgsi_exec_channel
*src
)
2175 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0] + src
[2].u
[0];
2176 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1] + src
[2].u
[1];
2177 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2] + src
[2].u
[2];
2178 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3] + src
[2].u
[3];
2182 micro_umax(union tgsi_exec_channel
*dst
,
2183 const union tgsi_exec_channel
*src
)
2185 dst
->u
[0] = src
[0].u
[0] > src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2186 dst
->u
[1] = src
[0].u
[1] > src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2187 dst
->u
[2] = src
[0].u
[2] > src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2188 dst
->u
[3] = src
[0].u
[3] > src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2192 micro_umin(union tgsi_exec_channel
*dst
,
2193 const union tgsi_exec_channel
*src
)
2195 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? src
[0].u
[0] : src
[1].u
[0];
2196 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? src
[0].u
[1] : src
[1].u
[1];
2197 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? src
[0].u
[2] : src
[1].u
[2];
2198 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? src
[0].u
[3] : src
[1].u
[3];
2202 micro_umod(union tgsi_exec_channel
*dst
,
2203 const union tgsi_exec_channel
*src
)
2205 dst
->u
[0] = src
[0].u
[0] % src
[1].u
[0];
2206 dst
->u
[1] = src
[0].u
[1] % src
[1].u
[1];
2207 dst
->u
[2] = src
[0].u
[2] % src
[1].u
[2];
2208 dst
->u
[3] = src
[0].u
[3] % src
[1].u
[3];
2212 micro_umul(union tgsi_exec_channel
*dst
,
2213 const union tgsi_exec_channel
*src
)
2215 dst
->u
[0] = src
[0].u
[0] * src
[1].u
[0];
2216 dst
->u
[1] = src
[0].u
[1] * src
[1].u
[1];
2217 dst
->u
[2] = src
[0].u
[2] * src
[1].u
[2];
2218 dst
->u
[3] = src
[0].u
[3] * src
[1].u
[3];
2222 micro_useq(union tgsi_exec_channel
*dst
,
2223 const union tgsi_exec_channel
*src
)
2225 dst
->u
[0] = src
[0].u
[0] == src
[1].u
[0] ? ~0 : 0;
2226 dst
->u
[1] = src
[0].u
[1] == src
[1].u
[1] ? ~0 : 0;
2227 dst
->u
[2] = src
[0].u
[2] == src
[1].u
[2] ? ~0 : 0;
2228 dst
->u
[3] = src
[0].u
[3] == src
[1].u
[3] ? ~0 : 0;
2232 micro_usge(union tgsi_exec_channel
*dst
,
2233 const union tgsi_exec_channel
*src
)
2235 dst
->u
[0] = src
[0].u
[0] >= src
[1].u
[0] ? ~0 : 0;
2236 dst
->u
[1] = src
[0].u
[1] >= src
[1].u
[1] ? ~0 : 0;
2237 dst
->u
[2] = src
[0].u
[2] >= src
[1].u
[2] ? ~0 : 0;
2238 dst
->u
[3] = src
[0].u
[3] >= src
[1].u
[3] ? ~0 : 0;
2242 micro_ushr(union tgsi_exec_channel
*dst
,
2243 const union tgsi_exec_channel
*src
)
2245 dst
->u
[0] = src
[0].u
[0] >> src
[1].u
[0];
2246 dst
->u
[1] = src
[0].u
[1] >> src
[1].u
[1];
2247 dst
->u
[2] = src
[0].u
[2] >> src
[1].u
[2];
2248 dst
->u
[3] = src
[0].u
[3] >> src
[1].u
[3];
2252 micro_uslt(union tgsi_exec_channel
*dst
,
2253 const union tgsi_exec_channel
*src
)
2255 dst
->u
[0] = src
[0].u
[0] < src
[1].u
[0] ? ~0 : 0;
2256 dst
->u
[1] = src
[0].u
[1] < src
[1].u
[1] ? ~0 : 0;
2257 dst
->u
[2] = src
[0].u
[2] < src
[1].u
[2] ? ~0 : 0;
2258 dst
->u
[3] = src
[0].u
[3] < src
[1].u
[3] ? ~0 : 0;
2262 micro_usne(union tgsi_exec_channel
*dst
,
2263 const union tgsi_exec_channel
*src
)
2265 dst
->u
[0] = src
[0].u
[0] != src
[1].u
[0] ? ~0 : 0;
2266 dst
->u
[1] = src
[0].u
[1] != src
[1].u
[1] ? ~0 : 0;
2267 dst
->u
[2] = src
[0].u
[2] != src
[1].u
[2] ? ~0 : 0;
2268 dst
->u
[3] = src
[0].u
[3] != src
[1].u
[3] ? ~0 : 0;
2273 struct tgsi_exec_machine
*mach
,
2274 const struct tgsi_full_instruction
*inst
,
2278 union tgsi_exec_channel r
[10];
2279 union tgsi_exec_channel d
[8];
2283 switch (inst
->Instruction
.Opcode
) {
2284 case TGSI_OPCODE_ARL
:
2285 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
2288 case TGSI_OPCODE_MOV
:
2289 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
2292 case TGSI_OPCODE_LIT
:
2293 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2294 FETCH( &r
[0], 0, CHAN_X
);
2295 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2296 micro_max(&d
[CHAN_Y
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2299 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2300 FETCH( &r
[1], 0, CHAN_Y
);
2301 micro_max( &r
[1], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
] );
2303 FETCH( &r
[2], 0, CHAN_W
);
2304 micro_min( &r
[2], &r
[2], &mach
->Temps
[TEMP_128_I
].xyzw
[TEMP_128_C
] );
2305 micro_max( &r
[2], &r
[2], &mach
->Temps
[TEMP_M128_I
].xyzw
[TEMP_M128_C
] );
2306 micro_pow( &r
[1], &r
[1], &r
[2] );
2307 micro_lt(&d
[CHAN_Z
], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[0], &r
[1], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
]);
2310 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2311 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2313 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2314 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2317 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2318 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2320 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2321 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2325 case TGSI_OPCODE_RCP
:
2326 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2329 case TGSI_OPCODE_RSQ
:
2330 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2333 case TGSI_OPCODE_EXP
:
2334 FETCH( &r
[0], 0, CHAN_X
);
2335 micro_flr( &r
[1], &r
[0] ); /* r1 = floor(r0) */
2336 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2337 micro_exp2( &r
[2], &r
[1] ); /* r2 = 2 ^ r1 */
2338 STORE( &r
[2], 0, CHAN_X
); /* store r2 */
2340 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2341 micro_sub( &r
[2], &r
[0], &r
[1] ); /* r2 = r0 - r1 */
2342 STORE( &r
[2], 0, CHAN_Y
); /* store r2 */
2344 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2345 micro_exp2( &r
[2], &r
[0] ); /* r2 = 2 ^ r0 */
2346 STORE( &r
[2], 0, CHAN_Z
); /* store r2 */
2348 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2349 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2353 case TGSI_OPCODE_LOG
:
2354 FETCH( &r
[0], 0, CHAN_X
);
2355 micro_abs( &r
[2], &r
[0] ); /* r2 = abs(r0) */
2356 micro_lg2( &r
[1], &r
[2] ); /* r1 = lg2(r2) */
2357 micro_flr( &r
[0], &r
[1] ); /* r0 = floor(r1) */
2358 if (IS_CHANNEL_ENABLED( *inst
, CHAN_X
)) {
2359 STORE( &r
[0], 0, CHAN_X
);
2361 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2362 micro_exp2( &r
[0], &r
[0] ); /* r0 = 2 ^ r0 */
2363 micro_div( &r
[0], &r
[2], &r
[0] ); /* r0 = r2 / r0 */
2364 STORE( &r
[0], 0, CHAN_Y
);
2366 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2367 STORE( &r
[1], 0, CHAN_Z
);
2369 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2370 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2374 case TGSI_OPCODE_MUL
:
2375 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2376 FETCH(&r
[0], 0, chan_index
);
2377 FETCH(&r
[1], 1, chan_index
);
2378 micro_mul(&d
[chan_index
], &r
[0], &r
[1]);
2380 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2381 STORE(&d
[chan_index
], 0, chan_index
);
2385 case TGSI_OPCODE_ADD
:
2386 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2387 FETCH( &r
[0], 0, chan_index
);
2388 FETCH( &r
[1], 1, chan_index
);
2389 micro_add(&d
[chan_index
], &r
[0], &r
[1]);
2391 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2392 STORE(&d
[chan_index
], 0, chan_index
);
2396 case TGSI_OPCODE_DP3
:
2397 /* TGSI_OPCODE_DOT3 */
2398 FETCH( &r
[0], 0, CHAN_X
);
2399 FETCH( &r
[1], 1, CHAN_X
);
2400 micro_mul( &r
[0], &r
[0], &r
[1] );
2402 FETCH( &r
[1], 0, CHAN_Y
);
2403 FETCH( &r
[2], 1, CHAN_Y
);
2404 micro_mul( &r
[1], &r
[1], &r
[2] );
2405 micro_add( &r
[0], &r
[0], &r
[1] );
2407 FETCH( &r
[1], 0, CHAN_Z
);
2408 FETCH( &r
[2], 1, CHAN_Z
);
2409 micro_mul( &r
[1], &r
[1], &r
[2] );
2410 micro_add( &r
[0], &r
[0], &r
[1] );
2412 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2413 STORE( &r
[0], 0, chan_index
);
2417 case TGSI_OPCODE_DP4
:
2418 /* TGSI_OPCODE_DOT4 */
2419 FETCH(&r
[0], 0, CHAN_X
);
2420 FETCH(&r
[1], 1, CHAN_X
);
2422 micro_mul( &r
[0], &r
[0], &r
[1] );
2424 FETCH(&r
[1], 0, CHAN_Y
);
2425 FETCH(&r
[2], 1, CHAN_Y
);
2427 micro_mul( &r
[1], &r
[1], &r
[2] );
2428 micro_add( &r
[0], &r
[0], &r
[1] );
2430 FETCH(&r
[1], 0, CHAN_Z
);
2431 FETCH(&r
[2], 1, CHAN_Z
);
2433 micro_mul( &r
[1], &r
[1], &r
[2] );
2434 micro_add( &r
[0], &r
[0], &r
[1] );
2436 FETCH(&r
[1], 0, CHAN_W
);
2437 FETCH(&r
[2], 1, CHAN_W
);
2439 micro_mul( &r
[1], &r
[1], &r
[2] );
2440 micro_add( &r
[0], &r
[0], &r
[1] );
2442 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2443 STORE( &r
[0], 0, chan_index
);
2447 case TGSI_OPCODE_DST
:
2448 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Y
)) {
2449 FETCH( &r
[0], 0, CHAN_Y
);
2450 FETCH( &r
[1], 1, CHAN_Y
);
2451 micro_mul(&d
[CHAN_Y
], &r
[0], &r
[1]);
2453 if (IS_CHANNEL_ENABLED( *inst
, CHAN_Z
)) {
2454 FETCH(&d
[CHAN_Z
], 0, CHAN_Z
);
2456 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2457 FETCH(&d
[CHAN_W
], 1, CHAN_W
);
2460 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2461 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_X
);
2463 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2464 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2466 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2467 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2469 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2470 STORE(&d
[CHAN_W
], 0, CHAN_W
);
2474 case TGSI_OPCODE_MIN
:
2475 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2476 FETCH(&r
[0], 0, chan_index
);
2477 FETCH(&r
[1], 1, chan_index
);
2479 /* XXX use micro_min()?? */
2480 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[0], &r
[1]);
2482 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2483 STORE(&d
[chan_index
], 0, chan_index
);
2487 case TGSI_OPCODE_MAX
:
2488 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2489 FETCH(&r
[0], 0, chan_index
);
2490 FETCH(&r
[1], 1, chan_index
);
2492 /* XXX use micro_max()?? */
2493 micro_lt(&d
[chan_index
], &r
[0], &r
[1], &r
[1], &r
[0] );
2495 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2496 STORE(&d
[chan_index
], 0, chan_index
);
2500 case TGSI_OPCODE_SLT
:
2501 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2504 case TGSI_OPCODE_SGE
:
2505 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2508 case TGSI_OPCODE_MAD
:
2509 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2512 case TGSI_OPCODE_SUB
:
2513 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2514 FETCH(&r
[0], 0, chan_index
);
2515 FETCH(&r
[1], 1, chan_index
);
2516 micro_sub(&d
[chan_index
], &r
[0], &r
[1]);
2518 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2519 STORE(&d
[chan_index
], 0, chan_index
);
2523 case TGSI_OPCODE_LRP
:
2524 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2527 case TGSI_OPCODE_CND
:
2528 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2529 FETCH(&r
[0], 0, chan_index
);
2530 FETCH(&r
[1], 1, chan_index
);
2531 FETCH(&r
[2], 2, chan_index
);
2532 micro_lt(&d
[chan_index
], &mach
->Temps
[TEMP_HALF_I
].xyzw
[TEMP_HALF_C
], &r
[2], &r
[0], &r
[1]);
2534 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2535 STORE(&d
[chan_index
], 0, chan_index
);
2539 case TGSI_OPCODE_DP2A
:
2540 FETCH( &r
[0], 0, CHAN_X
);
2541 FETCH( &r
[1], 1, CHAN_X
);
2542 micro_mul( &r
[0], &r
[0], &r
[1] );
2544 FETCH( &r
[1], 0, CHAN_Y
);
2545 FETCH( &r
[2], 1, CHAN_Y
);
2546 micro_mul( &r
[1], &r
[1], &r
[2] );
2547 micro_add( &r
[0], &r
[0], &r
[1] );
2549 FETCH( &r
[2], 2, CHAN_X
);
2550 micro_add( &r
[0], &r
[0], &r
[2] );
2552 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2553 STORE( &r
[0], 0, chan_index
);
2557 case TGSI_OPCODE_FRC
:
2558 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2561 case TGSI_OPCODE_CLAMP
:
2562 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2563 FETCH(&r
[0], 0, chan_index
);
2564 FETCH(&r
[1], 1, chan_index
);
2565 micro_max(&r
[0], &r
[0], &r
[1]);
2566 FETCH(&r
[1], 2, chan_index
);
2567 micro_min(&d
[chan_index
], &r
[0], &r
[1]);
2569 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2570 STORE(&d
[chan_index
], 0, chan_index
);
2574 case TGSI_OPCODE_FLR
:
2575 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2578 case TGSI_OPCODE_ROUND
:
2579 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2582 case TGSI_OPCODE_EX2
:
2583 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2586 case TGSI_OPCODE_LG2
:
2587 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2590 case TGSI_OPCODE_POW
:
2591 FETCH(&r
[0], 0, CHAN_X
);
2592 FETCH(&r
[1], 1, CHAN_X
);
2594 micro_pow( &r
[0], &r
[0], &r
[1] );
2596 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2597 STORE( &r
[0], 0, chan_index
);
2601 case TGSI_OPCODE_XPD
:
2602 FETCH(&r
[0], 0, CHAN_Y
);
2603 FETCH(&r
[1], 1, CHAN_Z
);
2605 micro_mul( &r
[2], &r
[0], &r
[1] );
2607 FETCH(&r
[3], 0, CHAN_Z
);
2608 FETCH(&r
[4], 1, CHAN_Y
);
2610 micro_mul( &r
[5], &r
[3], &r
[4] );
2611 micro_sub(&d
[CHAN_X
], &r
[2], &r
[5]);
2613 FETCH(&r
[2], 1, CHAN_X
);
2615 micro_mul( &r
[3], &r
[3], &r
[2] );
2617 FETCH(&r
[5], 0, CHAN_X
);
2619 micro_mul( &r
[1], &r
[1], &r
[5] );
2620 micro_sub(&d
[CHAN_Y
], &r
[3], &r
[1]);
2622 micro_mul( &r
[5], &r
[5], &r
[4] );
2623 micro_mul( &r
[0], &r
[0], &r
[2] );
2624 micro_sub(&d
[CHAN_Z
], &r
[5], &r
[0]);
2626 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2627 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2629 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2630 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2632 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2633 STORE(&d
[CHAN_Z
], 0, CHAN_Z
);
2635 if (IS_CHANNEL_ENABLED( *inst
, CHAN_W
)) {
2636 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2640 case TGSI_OPCODE_ABS
:
2641 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2644 case TGSI_OPCODE_RCC
:
2645 FETCH(&r
[0], 0, CHAN_X
);
2646 micro_div(&r
[0], &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &r
[0]);
2647 micro_float_clamp(&r
[0], &r
[0]);
2648 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2649 STORE(&r
[0], 0, chan_index
);
2653 case TGSI_OPCODE_DPH
:
2654 FETCH(&r
[0], 0, CHAN_X
);
2655 FETCH(&r
[1], 1, CHAN_X
);
2657 micro_mul( &r
[0], &r
[0], &r
[1] );
2659 FETCH(&r
[1], 0, CHAN_Y
);
2660 FETCH(&r
[2], 1, CHAN_Y
);
2662 micro_mul( &r
[1], &r
[1], &r
[2] );
2663 micro_add( &r
[0], &r
[0], &r
[1] );
2665 FETCH(&r
[1], 0, CHAN_Z
);
2666 FETCH(&r
[2], 1, CHAN_Z
);
2668 micro_mul( &r
[1], &r
[1], &r
[2] );
2669 micro_add( &r
[0], &r
[0], &r
[1] );
2671 FETCH(&r
[1], 1, CHAN_W
);
2673 micro_add( &r
[0], &r
[0], &r
[1] );
2675 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2676 STORE( &r
[0], 0, chan_index
);
2680 case TGSI_OPCODE_COS
:
2681 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2684 case TGSI_OPCODE_DDX
:
2685 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2688 case TGSI_OPCODE_DDY
:
2689 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2692 case TGSI_OPCODE_KILP
:
2693 exec_kilp (mach
, inst
);
2696 case TGSI_OPCODE_KIL
:
2697 exec_kil (mach
, inst
);
2700 case TGSI_OPCODE_PK2H
:
2704 case TGSI_OPCODE_PK2US
:
2708 case TGSI_OPCODE_PK4B
:
2712 case TGSI_OPCODE_PK4UB
:
2716 case TGSI_OPCODE_RFL
:
2717 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2718 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2719 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2720 /* r0 = dp3(src0, src0) */
2721 FETCH(&r
[2], 0, CHAN_X
);
2722 micro_mul(&r
[0], &r
[2], &r
[2]);
2723 FETCH(&r
[4], 0, CHAN_Y
);
2724 micro_mul(&r
[8], &r
[4], &r
[4]);
2725 micro_add(&r
[0], &r
[0], &r
[8]);
2726 FETCH(&r
[6], 0, CHAN_Z
);
2727 micro_mul(&r
[8], &r
[6], &r
[6]);
2728 micro_add(&r
[0], &r
[0], &r
[8]);
2730 /* r1 = dp3(src0, src1) */
2731 FETCH(&r
[3], 1, CHAN_X
);
2732 micro_mul(&r
[1], &r
[2], &r
[3]);
2733 FETCH(&r
[5], 1, CHAN_Y
);
2734 micro_mul(&r
[8], &r
[4], &r
[5]);
2735 micro_add(&r
[1], &r
[1], &r
[8]);
2736 FETCH(&r
[7], 1, CHAN_Z
);
2737 micro_mul(&r
[8], &r
[6], &r
[7]);
2738 micro_add(&r
[1], &r
[1], &r
[8]);
2740 /* r1 = 2 * r1 / r0 */
2741 micro_add(&r
[1], &r
[1], &r
[1]);
2742 micro_div(&r
[1], &r
[1], &r
[0]);
2744 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2745 micro_mul(&r
[2], &r
[2], &r
[1]);
2746 micro_sub(&r
[2], &r
[2], &r
[3]);
2747 STORE(&r
[2], 0, CHAN_X
);
2749 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2750 micro_mul(&r
[4], &r
[4], &r
[1]);
2751 micro_sub(&r
[4], &r
[4], &r
[5]);
2752 STORE(&r
[4], 0, CHAN_Y
);
2754 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2755 micro_mul(&r
[6], &r
[6], &r
[1]);
2756 micro_sub(&r
[6], &r
[6], &r
[7]);
2757 STORE(&r
[6], 0, CHAN_Z
);
2760 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2761 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
2765 case TGSI_OPCODE_SEQ
:
2766 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2769 case TGSI_OPCODE_SFL
:
2770 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2771 STORE(&mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, chan_index
);
2775 case TGSI_OPCODE_SGT
:
2776 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2779 case TGSI_OPCODE_SIN
:
2780 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2783 case TGSI_OPCODE_SLE
:
2784 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2787 case TGSI_OPCODE_SNE
:
2788 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2791 case TGSI_OPCODE_STR
:
2792 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2793 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, chan_index
);
2797 case TGSI_OPCODE_TEX
:
2798 /* simple texture lookup */
2799 /* src[0] = texcoord */
2800 /* src[1] = sampler unit */
2801 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
);
2804 case TGSI_OPCODE_TXB
:
2805 /* Texture lookup with lod bias */
2806 /* src[0] = texcoord (src[0].w = LOD bias) */
2807 /* src[1] = sampler unit */
2808 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
);
2811 case TGSI_OPCODE_TXD
:
2812 /* Texture lookup with explict partial derivatives */
2813 /* src[0] = texcoord */
2814 /* src[1] = d[strq]/dx */
2815 /* src[2] = d[strq]/dy */
2816 /* src[3] = sampler unit */
2817 exec_txd(mach
, inst
);
2820 case TGSI_OPCODE_TXL
:
2821 /* Texture lookup with explit LOD */
2822 /* src[0] = texcoord (src[0].w = LOD) */
2823 /* src[1] = sampler unit */
2824 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
);
2827 case TGSI_OPCODE_TXP
:
2828 /* Texture lookup with projection */
2829 /* src[0] = texcoord (src[0].w = projection) */
2830 /* src[1] = sampler unit */
2831 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
);
2834 case TGSI_OPCODE_UP2H
:
2838 case TGSI_OPCODE_UP2US
:
2842 case TGSI_OPCODE_UP4B
:
2846 case TGSI_OPCODE_UP4UB
:
2850 case TGSI_OPCODE_X2D
:
2851 FETCH(&r
[0], 1, CHAN_X
);
2852 FETCH(&r
[1], 1, CHAN_Y
);
2853 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
2854 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2855 FETCH(&r
[2], 2, CHAN_X
);
2856 micro_mul(&r
[2], &r
[2], &r
[0]);
2857 FETCH(&r
[3], 2, CHAN_Y
);
2858 micro_mul(&r
[3], &r
[3], &r
[1]);
2859 micro_add(&r
[2], &r
[2], &r
[3]);
2860 FETCH(&r
[3], 0, CHAN_X
);
2861 micro_add(&d
[CHAN_X
], &r
[2], &r
[3]);
2864 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
2865 IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2866 FETCH(&r
[2], 2, CHAN_Z
);
2867 micro_mul(&r
[2], &r
[2], &r
[0]);
2868 FETCH(&r
[3], 2, CHAN_W
);
2869 micro_mul(&r
[3], &r
[3], &r
[1]);
2870 micro_add(&r
[2], &r
[2], &r
[3]);
2871 FETCH(&r
[3], 0, CHAN_Y
);
2872 micro_add(&d
[CHAN_Y
], &r
[2], &r
[3]);
2875 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
2876 STORE(&d
[CHAN_X
], 0, CHAN_X
);
2878 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
2879 STORE(&d
[CHAN_Y
], 0, CHAN_Y
);
2881 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
2882 STORE(&d
[CHAN_X
], 0, CHAN_Z
);
2884 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
2885 STORE(&d
[CHAN_Y
], 0, CHAN_W
);
2889 case TGSI_OPCODE_ARA
:
2893 case TGSI_OPCODE_ARR
:
2894 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
2897 case TGSI_OPCODE_BRA
:
2901 case TGSI_OPCODE_CAL
:
2902 /* skip the call if no execution channels are enabled */
2903 if (mach
->ExecMask
) {
2906 /* First, record the depths of the execution stacks.
2907 * This is important for deeply nested/looped return statements.
2908 * We have to unwind the stacks by the correct amount. For a
2909 * real code generator, we could determine the number of entries
2910 * to pop off each stack with simple static analysis and avoid
2911 * implementing this data structure at run time.
2913 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
2914 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
2915 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
2916 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
2917 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
2918 /* note that PC was already incremented above */
2919 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
2921 mach
->CallStackTop
++;
2923 /* Second, push the Cond, Loop, Cont, Func stacks */
2924 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
2925 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2926 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
2927 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
2928 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
2929 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
2931 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
2932 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
2933 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
2934 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
2935 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
2936 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
2938 /* Finally, jump to the subroutine */
2939 *pc
= inst
->Label
.Label
;
2943 case TGSI_OPCODE_RET
:
2944 mach
->FuncMask
&= ~mach
->ExecMask
;
2945 UPDATE_EXEC_MASK(mach
);
2947 if (mach
->FuncMask
== 0x0) {
2948 /* really return now (otherwise, keep executing */
2950 if (mach
->CallStackTop
== 0) {
2951 /* returning from main() */
2956 assert(mach
->CallStackTop
> 0);
2957 mach
->CallStackTop
--;
2959 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
2960 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
2962 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
2963 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
2965 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
2966 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
2968 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
2969 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
2971 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
2972 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
2974 assert(mach
->FuncStackTop
> 0);
2975 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
2977 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
2979 UPDATE_EXEC_MASK(mach
);
2983 case TGSI_OPCODE_SSG
:
2984 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
2987 case TGSI_OPCODE_CMP
:
2988 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
2989 FETCH(&r
[0], 0, chan_index
);
2990 FETCH(&r
[1], 1, chan_index
);
2991 FETCH(&r
[2], 2, chan_index
);
2992 micro_lt(&d
[chan_index
], &r
[0], &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], &r
[1], &r
[2]);
2994 FOR_EACH_ENABLED_CHANNEL(*inst
, chan_index
) {
2995 STORE(&d
[chan_index
], 0, chan_index
);
2999 case TGSI_OPCODE_SCS
:
3000 if( IS_CHANNEL_ENABLED( *inst
, CHAN_X
) || IS_CHANNEL_ENABLED( *inst
, CHAN_Y
) ) {
3001 FETCH( &r
[0], 0, CHAN_X
);
3002 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3003 micro_cos(&r
[1], &r
[0]);
3004 STORE(&r
[1], 0, CHAN_X
);
3006 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3007 micro_sin(&r
[1], &r
[0]);
3008 STORE(&r
[1], 0, CHAN_Y
);
3011 if( IS_CHANNEL_ENABLED( *inst
, CHAN_Z
) ) {
3012 STORE( &mach
->Temps
[TEMP_0_I
].xyzw
[TEMP_0_C
], 0, CHAN_Z
);
3014 if( IS_CHANNEL_ENABLED( *inst
, CHAN_W
) ) {
3015 STORE( &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3019 case TGSI_OPCODE_NRM
:
3020 /* 3-component vector normalize */
3021 if(IS_CHANNEL_ENABLED(*inst
, CHAN_X
) ||
3022 IS_CHANNEL_ENABLED(*inst
, CHAN_Y
) ||
3023 IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3024 /* r3 = sqrt(dp3(src0, src0)) */
3025 FETCH(&r
[0], 0, CHAN_X
);
3026 micro_mul(&r
[3], &r
[0], &r
[0]);
3027 FETCH(&r
[1], 0, CHAN_Y
);
3028 micro_mul(&r
[4], &r
[1], &r
[1]);
3029 micro_add(&r
[3], &r
[3], &r
[4]);
3030 FETCH(&r
[2], 0, CHAN_Z
);
3031 micro_mul(&r
[4], &r
[2], &r
[2]);
3032 micro_add(&r
[3], &r
[3], &r
[4]);
3033 micro_sqrt(&r
[3], &r
[3]);
3035 if (IS_CHANNEL_ENABLED(*inst
, CHAN_X
)) {
3036 micro_div(&r
[0], &r
[0], &r
[3]);
3037 STORE(&r
[0], 0, CHAN_X
);
3039 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Y
)) {
3040 micro_div(&r
[1], &r
[1], &r
[3]);
3041 STORE(&r
[1], 0, CHAN_Y
);
3043 if (IS_CHANNEL_ENABLED(*inst
, CHAN_Z
)) {
3044 micro_div(&r
[2], &r
[2], &r
[3]);
3045 STORE(&r
[2], 0, CHAN_Z
);
3048 if (IS_CHANNEL_ENABLED(*inst
, CHAN_W
)) {
3049 STORE(&mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], 0, CHAN_W
);
3053 case TGSI_OPCODE_NRM4
:
3054 /* 4-component vector normalize */
3056 union tgsi_exec_channel tmp
, dot
;
3058 /* tmp = dp4(src0, src0): */
3059 FETCH( &r
[0], 0, CHAN_X
);
3060 micro_mul( &tmp
, &r
[0], &r
[0] );
3062 FETCH( &r
[1], 0, CHAN_Y
);
3063 micro_mul( &dot
, &r
[1], &r
[1] );
3064 micro_add( &tmp
, &tmp
, &dot
);
3066 FETCH( &r
[2], 0, CHAN_Z
);
3067 micro_mul( &dot
, &r
[2], &r
[2] );
3068 micro_add( &tmp
, &tmp
, &dot
);
3070 FETCH( &r
[3], 0, CHAN_W
);
3071 micro_mul( &dot
, &r
[3], &r
[3] );
3072 micro_add( &tmp
, &tmp
, &dot
);
3074 /* tmp = 1 / sqrt(tmp) */
3075 micro_sqrt( &tmp
, &tmp
);
3076 micro_div( &tmp
, &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
], &tmp
);
3078 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3079 /* chan = chan * tmp */
3080 micro_mul( &r
[chan_index
], &tmp
, &r
[chan_index
] );
3081 STORE( &r
[chan_index
], 0, chan_index
);
3086 case TGSI_OPCODE_DIV
:
3090 case TGSI_OPCODE_DP2
:
3091 FETCH( &r
[0], 0, CHAN_X
);
3092 FETCH( &r
[1], 1, CHAN_X
);
3093 micro_mul( &r
[0], &r
[0], &r
[1] );
3095 FETCH( &r
[1], 0, CHAN_Y
);
3096 FETCH( &r
[2], 1, CHAN_Y
);
3097 micro_mul( &r
[1], &r
[1], &r
[2] );
3098 micro_add( &r
[0], &r
[0], &r
[1] );
3100 FOR_EACH_ENABLED_CHANNEL( *inst
, chan_index
) {
3101 STORE( &r
[0], 0, chan_index
);
3105 case TGSI_OPCODE_IF
:
3107 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3108 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3109 FETCH( &r
[0], 0, CHAN_X
);
3110 /* update CondMask */
3112 mach
->CondMask
&= ~0x1;
3115 mach
->CondMask
&= ~0x2;
3118 mach
->CondMask
&= ~0x4;
3121 mach
->CondMask
&= ~0x8;
3123 UPDATE_EXEC_MASK(mach
);
3124 /* Todo: If CondMask==0, jump to ELSE */
3127 case TGSI_OPCODE_ELSE
:
3128 /* invert CondMask wrt previous mask */
3131 assert(mach
->CondStackTop
> 0);
3132 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3133 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3134 UPDATE_EXEC_MASK(mach
);
3135 /* Todo: If CondMask==0, jump to ENDIF */
3139 case TGSI_OPCODE_ENDIF
:
3141 assert(mach
->CondStackTop
> 0);
3142 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3143 UPDATE_EXEC_MASK(mach
);
3146 case TGSI_OPCODE_END
:
3147 /* halt execution */
3151 case TGSI_OPCODE_REP
:
3155 case TGSI_OPCODE_ENDREP
:
3159 case TGSI_OPCODE_PUSHA
:
3163 case TGSI_OPCODE_POPA
:
3167 case TGSI_OPCODE_CEIL
:
3168 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3171 case TGSI_OPCODE_I2F
:
3172 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
3175 case TGSI_OPCODE_NOT
:
3176 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3179 case TGSI_OPCODE_TRUNC
:
3180 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3183 case TGSI_OPCODE_SHL
:
3184 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3187 case TGSI_OPCODE_AND
:
3188 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3191 case TGSI_OPCODE_OR
:
3192 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3195 case TGSI_OPCODE_MOD
:
3199 case TGSI_OPCODE_XOR
:
3200 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3203 case TGSI_OPCODE_SAD
:
3207 case TGSI_OPCODE_TXF
:
3211 case TGSI_OPCODE_TXQ
:
3215 case TGSI_OPCODE_EMIT
:
3219 case TGSI_OPCODE_ENDPRIM
:
3220 emit_primitive(mach
);
3223 case TGSI_OPCODE_BGNFOR
:
3224 assert(mach
->LoopCounterStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3225 for (chan_index
= 0; chan_index
< 3; chan_index
++) {
3226 FETCH( &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[chan_index
], 0, chan_index
);
3228 ++mach
->LoopCounterStackTop
;
3229 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
], 0, CHAN_X
);
3230 /* update LoopMask */
3231 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3232 mach
->LoopMask
&= ~0x1;
3234 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3235 mach
->LoopMask
&= ~0x2;
3237 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3238 mach
->LoopMask
&= ~0x4;
3240 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3241 mach
->LoopMask
&= ~0x8;
3243 /* TODO: if mach->LoopMask == 0, jump to end of loop */
3244 UPDATE_EXEC_MASK(mach
);
3245 /* fall-through (for now) */
3246 case TGSI_OPCODE_BGNLOOP
:
3247 /* push LoopMask and ContMasks */
3248 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3249 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3250 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3251 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3253 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3254 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3255 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3256 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3257 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
3260 case TGSI_OPCODE_ENDFOR
:
3261 assert(mach
->LoopCounterStackTop
> 0);
3262 micro_sub(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3263 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
],
3264 &mach
->Temps
[TEMP_1_I
].xyzw
[TEMP_1_C
]);
3265 /* update LoopMask */
3266 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[0] <= 0.0f
) {
3267 mach
->LoopMask
&= ~0x1;
3269 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[1] <= 0.0f
) {
3270 mach
->LoopMask
&= ~0x2;
3272 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[2] <= 0.0f
) {
3273 mach
->LoopMask
&= ~0x4;
3275 if (mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Y
].f
[3] <= 0.0f
) {
3276 mach
->LoopMask
&= ~0x8;
3278 micro_add(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3279 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_X
],
3280 &mach
->LoopCounterStack
[mach
->LoopCounterStackTop
- 1].xyzw
[CHAN_Z
]);
3281 assert(mach
->LoopLabelStackTop
> 0);
3282 inst
= mach
->Instructions
+ mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1];
3283 STORE(&mach
->LoopCounterStack
[mach
->LoopCounterStackTop
].xyzw
[CHAN_X
], 0, CHAN_X
);
3284 /* Restore ContMask, but don't pop */
3285 assert(mach
->ContStackTop
> 0);
3286 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3287 UPDATE_EXEC_MASK(mach
);
3288 if (mach
->ExecMask
) {
3289 /* repeat loop: jump to instruction just past BGNLOOP */
3290 assert(mach
->LoopLabelStackTop
> 0);
3291 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3294 /* exit loop: pop LoopMask */
3295 assert(mach
->LoopStackTop
> 0);
3296 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3298 assert(mach
->ContStackTop
> 0);
3299 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3300 assert(mach
->LoopLabelStackTop
> 0);
3301 --mach
->LoopLabelStackTop
;
3302 assert(mach
->LoopCounterStackTop
> 0);
3303 --mach
->LoopCounterStackTop
;
3305 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3307 UPDATE_EXEC_MASK(mach
);
3310 case TGSI_OPCODE_ENDLOOP
:
3311 /* Restore ContMask, but don't pop */
3312 assert(mach
->ContStackTop
> 0);
3313 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3314 UPDATE_EXEC_MASK(mach
);
3315 if (mach
->ExecMask
) {
3316 /* repeat loop: jump to instruction just past BGNLOOP */
3317 assert(mach
->LoopLabelStackTop
> 0);
3318 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3321 /* exit loop: pop LoopMask */
3322 assert(mach
->LoopStackTop
> 0);
3323 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3325 assert(mach
->ContStackTop
> 0);
3326 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3327 assert(mach
->LoopLabelStackTop
> 0);
3328 --mach
->LoopLabelStackTop
;
3330 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3332 UPDATE_EXEC_MASK(mach
);
3335 case TGSI_OPCODE_BRK
:
3339 case TGSI_OPCODE_CONT
:
3340 /* turn off cont channels for each enabled exec channel */
3341 mach
->ContMask
&= ~mach
->ExecMask
;
3342 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3343 UPDATE_EXEC_MASK(mach
);
3346 case TGSI_OPCODE_BGNSUB
:
3350 case TGSI_OPCODE_ENDSUB
:
3352 * XXX: This really should be a no-op. We should never reach this opcode.
3355 assert(mach
->CallStackTop
> 0);
3356 mach
->CallStackTop
--;
3358 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3359 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3361 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3362 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3364 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3365 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3367 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3368 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3370 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3371 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3373 assert(mach
->FuncStackTop
> 0);
3374 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3376 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3378 UPDATE_EXEC_MASK(mach
);
3381 case TGSI_OPCODE_NOP
:
3384 case TGSI_OPCODE_BREAKC
:
3385 FETCH(&r
[0], 0, CHAN_X
);
3386 /* update CondMask */
3387 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
3388 mach
->LoopMask
&= ~0x1;
3390 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
3391 mach
->LoopMask
&= ~0x2;
3393 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
3394 mach
->LoopMask
&= ~0x4;
3396 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
3397 mach
->LoopMask
&= ~0x8;
3399 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3400 UPDATE_EXEC_MASK(mach
);
3403 case TGSI_OPCODE_F2I
:
3404 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3407 case TGSI_OPCODE_IDIV
:
3408 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3411 case TGSI_OPCODE_IMAX
:
3412 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3415 case TGSI_OPCODE_IMIN
:
3416 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3419 case TGSI_OPCODE_INEG
:
3420 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3423 case TGSI_OPCODE_ISGE
:
3424 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3427 case TGSI_OPCODE_ISHR
:
3428 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3431 case TGSI_OPCODE_ISLT
:
3432 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3435 case TGSI_OPCODE_F2U
:
3436 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3439 case TGSI_OPCODE_U2F
:
3440 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
3443 case TGSI_OPCODE_UADD
:
3444 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3447 case TGSI_OPCODE_UDIV
:
3448 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3451 case TGSI_OPCODE_UMAD
:
3452 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3455 case TGSI_OPCODE_UMAX
:
3456 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3459 case TGSI_OPCODE_UMIN
:
3460 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3463 case TGSI_OPCODE_UMOD
:
3464 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3467 case TGSI_OPCODE_UMUL
:
3468 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3471 case TGSI_OPCODE_USEQ
:
3472 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3475 case TGSI_OPCODE_USGE
:
3476 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3479 case TGSI_OPCODE_USHR
:
3480 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3483 case TGSI_OPCODE_USLT
:
3484 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3487 case TGSI_OPCODE_USNE
:
3488 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3491 case TGSI_OPCODE_SWITCH
:
3492 exec_switch(mach
, inst
);
3495 case TGSI_OPCODE_CASE
:
3496 exec_case(mach
, inst
);
3499 case TGSI_OPCODE_DEFAULT
:
3503 case TGSI_OPCODE_ENDSWITCH
:
3504 exec_endswitch(mach
);
3513 #define DEBUG_EXECUTION 0
3517 * Run TGSI interpreter.
3518 * \return bitmask of "alive" quad components
3521 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
3526 mach
->CondMask
= 0xf;
3527 mach
->LoopMask
= 0xf;
3528 mach
->ContMask
= 0xf;
3529 mach
->FuncMask
= 0xf;
3530 mach
->ExecMask
= 0xf;
3532 mach
->Switch
.mask
= 0xf;
3534 assert(mach
->CondStackTop
== 0);
3535 assert(mach
->LoopStackTop
== 0);
3536 assert(mach
->ContStackTop
== 0);
3537 assert(mach
->SwitchStackTop
== 0);
3538 assert(mach
->BreakStackTop
== 0);
3539 assert(mach
->CallStackTop
== 0);
3541 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
3542 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
3544 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
3545 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
3546 mach
->Primitives
[0] = 0;
3549 for (i
= 0; i
< QUAD_SIZE
; i
++) {
3550 mach
->Temps
[TEMP_CC_I
].xyzw
[TEMP_CC_C
].u
[i
] =
3551 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_X_SHIFT
) |
3552 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Y_SHIFT
) |
3553 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_Z_SHIFT
) |
3554 (TGSI_EXEC_CC_EQ
<< TGSI_EXEC_CC_W_SHIFT
);
3557 /* execute declarations (interpolants) */
3558 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
3559 exec_declaration( mach
, mach
->Declarations
+i
);
3564 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
3565 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
3568 memcpy(temps
, mach
->Temps
, sizeof(temps
));
3569 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
3572 /* execute instructions, until pc is set to -1 */
3578 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
3581 assert(pc
< (int) mach
->NumInstructions
);
3582 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
3585 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
3586 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
3589 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
3590 debug_printf("TEMP[%2u] = ", i
);
3591 for (j
= 0; j
< 4; j
++) {
3595 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3596 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
3597 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
3598 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
3599 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
3603 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
3604 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
3607 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
3608 debug_printf("OUT[%2u] = ", i
);
3609 for (j
= 0; j
< 4; j
++) {
3613 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
3614 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
3615 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
3616 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
3617 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
3626 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
3627 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
3629 * Scale back depth component.
3631 for (i
= 0; i
< 4; i
++)
3632 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
3636 assert(mach
->CondStackTop
== 0);
3637 assert(mach
->LoopStackTop
== 0);
3638 assert(mach
->ContStackTop
== 0);
3639 assert(mach
->SwitchStackTop
== 0);
3640 assert(mach
->BreakStackTop
== 0);
3641 assert(mach
->CallStackTop
== 0);
3643 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];