1 /**************************************************************************
3 * Copyright 2007-2008 VMware, Inc.
5 * Copyright 2009-2010 VMware, Inc. All rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 * TGSI interpreter/executor.
32 * Flow control information:
34 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
35 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
36 * care since a condition may be true for some quad components but false
37 * for other components.
39 * We basically execute all statements (even if they're in the part of
40 * an IF/ELSE clause that's "not taken") and use a special mask to
41 * control writing to destination registers. This is the ExecMask.
44 * The ExecMask is computed from three other masks (CondMask, LoopMask and
45 * ContMask) which are controlled by the flow control instructions (namely:
46 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
54 #include "pipe/p_compiler.h"
55 #include "pipe/p_state.h"
56 #include "pipe/p_shader_tokens.h"
57 #include "tgsi/tgsi_dump.h"
58 #include "tgsi/tgsi_parse.h"
59 #include "tgsi/tgsi_util.h"
60 #include "tgsi_exec.h"
61 #include "util/u_memory.h"
62 #include "util/u_math.h"
65 #define DEBUG_EXECUTION 0
70 #define TILE_TOP_LEFT 0
71 #define TILE_TOP_RIGHT 1
72 #define TILE_BOTTOM_LEFT 2
73 #define TILE_BOTTOM_RIGHT 3
76 micro_abs(union tgsi_exec_channel
*dst
,
77 const union tgsi_exec_channel
*src
)
79 dst
->f
[0] = fabsf(src
->f
[0]);
80 dst
->f
[1] = fabsf(src
->f
[1]);
81 dst
->f
[2] = fabsf(src
->f
[2]);
82 dst
->f
[3] = fabsf(src
->f
[3]);
86 micro_arl(union tgsi_exec_channel
*dst
,
87 const union tgsi_exec_channel
*src
)
89 dst
->i
[0] = (int)floorf(src
->f
[0]);
90 dst
->i
[1] = (int)floorf(src
->f
[1]);
91 dst
->i
[2] = (int)floorf(src
->f
[2]);
92 dst
->i
[3] = (int)floorf(src
->f
[3]);
96 micro_arr(union tgsi_exec_channel
*dst
,
97 const union tgsi_exec_channel
*src
)
99 dst
->i
[0] = (int)floorf(src
->f
[0] + 0.5f
);
100 dst
->i
[1] = (int)floorf(src
->f
[1] + 0.5f
);
101 dst
->i
[2] = (int)floorf(src
->f
[2] + 0.5f
);
102 dst
->i
[3] = (int)floorf(src
->f
[3] + 0.5f
);
106 micro_ceil(union tgsi_exec_channel
*dst
,
107 const union tgsi_exec_channel
*src
)
109 dst
->f
[0] = ceilf(src
->f
[0]);
110 dst
->f
[1] = ceilf(src
->f
[1]);
111 dst
->f
[2] = ceilf(src
->f
[2]);
112 dst
->f
[3] = ceilf(src
->f
[3]);
116 micro_clamp(union tgsi_exec_channel
*dst
,
117 const union tgsi_exec_channel
*src0
,
118 const union tgsi_exec_channel
*src1
,
119 const union tgsi_exec_channel
*src2
)
121 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src1
->f
[0] : src0
->f
[0] > src2
->f
[0] ? src2
->f
[0] : src0
->f
[0];
122 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src1
->f
[1] : src0
->f
[1] > src2
->f
[1] ? src2
->f
[1] : src0
->f
[1];
123 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src1
->f
[2] : src0
->f
[2] > src2
->f
[2] ? src2
->f
[2] : src0
->f
[2];
124 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src1
->f
[3] : src0
->f
[3] > src2
->f
[3] ? src2
->f
[3] : src0
->f
[3];
128 micro_cmp(union tgsi_exec_channel
*dst
,
129 const union tgsi_exec_channel
*src0
,
130 const union tgsi_exec_channel
*src1
,
131 const union tgsi_exec_channel
*src2
)
133 dst
->f
[0] = src0
->f
[0] < 0.0f
? src1
->f
[0] : src2
->f
[0];
134 dst
->f
[1] = src0
->f
[1] < 0.0f
? src1
->f
[1] : src2
->f
[1];
135 dst
->f
[2] = src0
->f
[2] < 0.0f
? src1
->f
[2] : src2
->f
[2];
136 dst
->f
[3] = src0
->f
[3] < 0.0f
? src1
->f
[3] : src2
->f
[3];
140 micro_cnd(union tgsi_exec_channel
*dst
,
141 const union tgsi_exec_channel
*src0
,
142 const union tgsi_exec_channel
*src1
,
143 const union tgsi_exec_channel
*src2
)
145 dst
->f
[0] = src2
->f
[0] > 0.5f
? src0
->f
[0] : src1
->f
[0];
146 dst
->f
[1] = src2
->f
[1] > 0.5f
? src0
->f
[1] : src1
->f
[1];
147 dst
->f
[2] = src2
->f
[2] > 0.5f
? src0
->f
[2] : src1
->f
[2];
148 dst
->f
[3] = src2
->f
[3] > 0.5f
? src0
->f
[3] : src1
->f
[3];
152 micro_cos(union tgsi_exec_channel
*dst
,
153 const union tgsi_exec_channel
*src
)
155 dst
->f
[0] = cosf(src
->f
[0]);
156 dst
->f
[1] = cosf(src
->f
[1]);
157 dst
->f
[2] = cosf(src
->f
[2]);
158 dst
->f
[3] = cosf(src
->f
[3]);
162 micro_ddx(union tgsi_exec_channel
*dst
,
163 const union tgsi_exec_channel
*src
)
168 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
172 micro_ddy(union tgsi_exec_channel
*dst
,
173 const union tgsi_exec_channel
*src
)
178 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
182 micro_exp2(union tgsi_exec_channel
*dst
,
183 const union tgsi_exec_channel
*src
)
186 dst
->f
[0] = util_fast_exp2(src
->f
[0]);
187 dst
->f
[1] = util_fast_exp2(src
->f
[1]);
188 dst
->f
[2] = util_fast_exp2(src
->f
[2]);
189 dst
->f
[3] = util_fast_exp2(src
->f
[3]);
192 /* Inf is okay for this instruction, so clamp it to silence assertions. */
194 union tgsi_exec_channel clamped
;
196 for (i
= 0; i
< 4; i
++) {
197 if (src
->f
[i
] > 127.99999f
) {
198 clamped
.f
[i
] = 127.99999f
;
199 } else if (src
->f
[i
] < -126.99999f
) {
200 clamped
.f
[i
] = -126.99999f
;
202 clamped
.f
[i
] = src
->f
[i
];
208 dst
->f
[0] = powf(2.0f
, src
->f
[0]);
209 dst
->f
[1] = powf(2.0f
, src
->f
[1]);
210 dst
->f
[2] = powf(2.0f
, src
->f
[2]);
211 dst
->f
[3] = powf(2.0f
, src
->f
[3]);
212 #endif /* FAST_MATH */
216 micro_flr(union tgsi_exec_channel
*dst
,
217 const union tgsi_exec_channel
*src
)
219 dst
->f
[0] = floorf(src
->f
[0]);
220 dst
->f
[1] = floorf(src
->f
[1]);
221 dst
->f
[2] = floorf(src
->f
[2]);
222 dst
->f
[3] = floorf(src
->f
[3]);
226 micro_frc(union tgsi_exec_channel
*dst
,
227 const union tgsi_exec_channel
*src
)
229 dst
->f
[0] = src
->f
[0] - floorf(src
->f
[0]);
230 dst
->f
[1] = src
->f
[1] - floorf(src
->f
[1]);
231 dst
->f
[2] = src
->f
[2] - floorf(src
->f
[2]);
232 dst
->f
[3] = src
->f
[3] - floorf(src
->f
[3]);
236 micro_iabs(union tgsi_exec_channel
*dst
,
237 const union tgsi_exec_channel
*src
)
239 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
240 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
241 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
242 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
246 micro_ineg(union tgsi_exec_channel
*dst
,
247 const union tgsi_exec_channel
*src
)
249 dst
->i
[0] = -src
->i
[0];
250 dst
->i
[1] = -src
->i
[1];
251 dst
->i
[2] = -src
->i
[2];
252 dst
->i
[3] = -src
->i
[3];
256 micro_lg2(union tgsi_exec_channel
*dst
,
257 const union tgsi_exec_channel
*src
)
260 dst
->f
[0] = util_fast_log2(src
->f
[0]);
261 dst
->f
[1] = util_fast_log2(src
->f
[1]);
262 dst
->f
[2] = util_fast_log2(src
->f
[2]);
263 dst
->f
[3] = util_fast_log2(src
->f
[3]);
265 dst
->f
[0] = logf(src
->f
[0]) * 1.442695f
;
266 dst
->f
[1] = logf(src
->f
[1]) * 1.442695f
;
267 dst
->f
[2] = logf(src
->f
[2]) * 1.442695f
;
268 dst
->f
[3] = logf(src
->f
[3]) * 1.442695f
;
273 micro_lrp(union tgsi_exec_channel
*dst
,
274 const union tgsi_exec_channel
*src0
,
275 const union tgsi_exec_channel
*src1
,
276 const union tgsi_exec_channel
*src2
)
278 dst
->f
[0] = src0
->f
[0] * (src1
->f
[0] - src2
->f
[0]) + src2
->f
[0];
279 dst
->f
[1] = src0
->f
[1] * (src1
->f
[1] - src2
->f
[1]) + src2
->f
[1];
280 dst
->f
[2] = src0
->f
[2] * (src1
->f
[2] - src2
->f
[2]) + src2
->f
[2];
281 dst
->f
[3] = src0
->f
[3] * (src1
->f
[3] - src2
->f
[3]) + src2
->f
[3];
285 micro_mad(union tgsi_exec_channel
*dst
,
286 const union tgsi_exec_channel
*src0
,
287 const union tgsi_exec_channel
*src1
,
288 const union tgsi_exec_channel
*src2
)
290 dst
->f
[0] = src0
->f
[0] * src1
->f
[0] + src2
->f
[0];
291 dst
->f
[1] = src0
->f
[1] * src1
->f
[1] + src2
->f
[1];
292 dst
->f
[2] = src0
->f
[2] * src1
->f
[2] + src2
->f
[2];
293 dst
->f
[3] = src0
->f
[3] * src1
->f
[3] + src2
->f
[3];
297 micro_mov(union tgsi_exec_channel
*dst
,
298 const union tgsi_exec_channel
*src
)
300 dst
->u
[0] = src
->u
[0];
301 dst
->u
[1] = src
->u
[1];
302 dst
->u
[2] = src
->u
[2];
303 dst
->u
[3] = src
->u
[3];
307 micro_rcp(union tgsi_exec_channel
*dst
,
308 const union tgsi_exec_channel
*src
)
310 #if 0 /* for debugging */
311 assert(src
->f
[0] != 0.0f
);
312 assert(src
->f
[1] != 0.0f
);
313 assert(src
->f
[2] != 0.0f
);
314 assert(src
->f
[3] != 0.0f
);
316 dst
->f
[0] = 1.0f
/ src
->f
[0];
317 dst
->f
[1] = 1.0f
/ src
->f
[1];
318 dst
->f
[2] = 1.0f
/ src
->f
[2];
319 dst
->f
[3] = 1.0f
/ src
->f
[3];
323 micro_rnd(union tgsi_exec_channel
*dst
,
324 const union tgsi_exec_channel
*src
)
326 dst
->f
[0] = floorf(src
->f
[0] + 0.5f
);
327 dst
->f
[1] = floorf(src
->f
[1] + 0.5f
);
328 dst
->f
[2] = floorf(src
->f
[2] + 0.5f
);
329 dst
->f
[3] = floorf(src
->f
[3] + 0.5f
);
333 micro_rsq(union tgsi_exec_channel
*dst
,
334 const union tgsi_exec_channel
*src
)
336 #if 0 /* for debugging */
337 assert(src
->f
[0] != 0.0f
);
338 assert(src
->f
[1] != 0.0f
);
339 assert(src
->f
[2] != 0.0f
);
340 assert(src
->f
[3] != 0.0f
);
342 dst
->f
[0] = 1.0f
/ sqrtf(src
->f
[0]);
343 dst
->f
[1] = 1.0f
/ sqrtf(src
->f
[1]);
344 dst
->f
[2] = 1.0f
/ sqrtf(src
->f
[2]);
345 dst
->f
[3] = 1.0f
/ sqrtf(src
->f
[3]);
349 micro_sqrt(union tgsi_exec_channel
*dst
,
350 const union tgsi_exec_channel
*src
)
352 dst
->f
[0] = sqrtf(src
->f
[0]);
353 dst
->f
[1] = sqrtf(src
->f
[1]);
354 dst
->f
[2] = sqrtf(src
->f
[2]);
355 dst
->f
[3] = sqrtf(src
->f
[3]);
359 micro_seq(union tgsi_exec_channel
*dst
,
360 const union tgsi_exec_channel
*src0
,
361 const union tgsi_exec_channel
*src1
)
363 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? 1.0f
: 0.0f
;
364 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? 1.0f
: 0.0f
;
365 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? 1.0f
: 0.0f
;
366 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? 1.0f
: 0.0f
;
370 micro_sge(union tgsi_exec_channel
*dst
,
371 const union tgsi_exec_channel
*src0
,
372 const union tgsi_exec_channel
*src1
)
374 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? 1.0f
: 0.0f
;
375 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? 1.0f
: 0.0f
;
376 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? 1.0f
: 0.0f
;
377 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? 1.0f
: 0.0f
;
381 micro_sgn(union tgsi_exec_channel
*dst
,
382 const union tgsi_exec_channel
*src
)
384 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
385 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
386 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
387 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
391 micro_isgn(union tgsi_exec_channel
*dst
,
392 const union tgsi_exec_channel
*src
)
394 dst
->i
[0] = src
->i
[0] < 0 ? -1 : src
->i
[0] > 0 ? 1 : 0;
395 dst
->i
[1] = src
->i
[1] < 0 ? -1 : src
->i
[1] > 0 ? 1 : 0;
396 dst
->i
[2] = src
->i
[2] < 0 ? -1 : src
->i
[2] > 0 ? 1 : 0;
397 dst
->i
[3] = src
->i
[3] < 0 ? -1 : src
->i
[3] > 0 ? 1 : 0;
401 micro_sgt(union tgsi_exec_channel
*dst
,
402 const union tgsi_exec_channel
*src0
,
403 const union tgsi_exec_channel
*src1
)
405 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? 1.0f
: 0.0f
;
406 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? 1.0f
: 0.0f
;
407 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? 1.0f
: 0.0f
;
408 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? 1.0f
: 0.0f
;
412 micro_sin(union tgsi_exec_channel
*dst
,
413 const union tgsi_exec_channel
*src
)
415 dst
->f
[0] = sinf(src
->f
[0]);
416 dst
->f
[1] = sinf(src
->f
[1]);
417 dst
->f
[2] = sinf(src
->f
[2]);
418 dst
->f
[3] = sinf(src
->f
[3]);
422 micro_sle(union tgsi_exec_channel
*dst
,
423 const union tgsi_exec_channel
*src0
,
424 const union tgsi_exec_channel
*src1
)
426 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? 1.0f
: 0.0f
;
427 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? 1.0f
: 0.0f
;
428 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? 1.0f
: 0.0f
;
429 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? 1.0f
: 0.0f
;
433 micro_slt(union tgsi_exec_channel
*dst
,
434 const union tgsi_exec_channel
*src0
,
435 const union tgsi_exec_channel
*src1
)
437 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? 1.0f
: 0.0f
;
438 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? 1.0f
: 0.0f
;
439 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? 1.0f
: 0.0f
;
440 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? 1.0f
: 0.0f
;
444 micro_sne(union tgsi_exec_channel
*dst
,
445 const union tgsi_exec_channel
*src0
,
446 const union tgsi_exec_channel
*src1
)
448 dst
->f
[0] = src0
->f
[0] != src1
->f
[0] ? 1.0f
: 0.0f
;
449 dst
->f
[1] = src0
->f
[1] != src1
->f
[1] ? 1.0f
: 0.0f
;
450 dst
->f
[2] = src0
->f
[2] != src1
->f
[2] ? 1.0f
: 0.0f
;
451 dst
->f
[3] = src0
->f
[3] != src1
->f
[3] ? 1.0f
: 0.0f
;
455 micro_trunc(union tgsi_exec_channel
*dst
,
456 const union tgsi_exec_channel
*src
)
458 dst
->f
[0] = (float)(int)src
->f
[0];
459 dst
->f
[1] = (float)(int)src
->f
[1];
460 dst
->f
[2] = (float)(int)src
->f
[2];
461 dst
->f
[3] = (float)(int)src
->f
[3];
465 enum tgsi_exec_datatype
{
466 TGSI_EXEC_DATA_FLOAT
,
472 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
474 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
475 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
476 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
477 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
478 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
479 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
482 /** The execution mask depends on the conditional mask and the loop mask */
483 #define UPDATE_EXEC_MASK(MACH) \
484 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
487 static const union tgsi_exec_channel ZeroVec
=
488 { { 0.0, 0.0, 0.0, 0.0 } };
490 static const union tgsi_exec_channel OneVec
= {
491 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
494 static const union tgsi_exec_channel P128Vec
= {
495 {128.0f
, 128.0f
, 128.0f
, 128.0f
}
498 static const union tgsi_exec_channel M128Vec
= {
499 {-128.0f
, -128.0f
, -128.0f
, -128.0f
}
504 * Assert that none of the float values in 'chan' are infinite or NaN.
505 * NaN and Inf may occur normally during program execution and should
506 * not lead to crashes, etc. But when debugging, it's helpful to catch
510 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
512 assert(!util_is_inf_or_nan((chan
)->f
[0]));
513 assert(!util_is_inf_or_nan((chan
)->f
[1]));
514 assert(!util_is_inf_or_nan((chan
)->f
[2]));
515 assert(!util_is_inf_or_nan((chan
)->f
[3]));
521 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
523 debug_printf("%s = {%f, %f, %f, %f}\n",
524 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
531 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
533 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
535 debug_printf("Temp[%u] =\n", index
);
536 for (i
= 0; i
< 4; i
++) {
537 debug_printf(" %c: { %f, %f, %f, %f }\n",
549 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine
*mach
,
552 const unsigned *buf_sizes
)
556 for (i
= 0; i
< num_bufs
; i
++) {
557 mach
->Consts
[i
] = bufs
[i
];
558 mach
->ConstsSize
[i
] = buf_sizes
[i
];
564 * Check if there's a potential src/dst register data dependency when
565 * using SOA execution.
568 * This would expand into:
573 * The second instruction will have the wrong value for t0 if executed as-is.
576 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
580 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
581 if (writemask
== TGSI_WRITEMASK_X
||
582 writemask
== TGSI_WRITEMASK_Y
||
583 writemask
== TGSI_WRITEMASK_Z
||
584 writemask
== TGSI_WRITEMASK_W
||
585 writemask
== TGSI_WRITEMASK_NONE
) {
586 /* no chance of data dependency */
590 /* loop over src regs */
591 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
592 if ((inst
->Src
[i
].Register
.File
==
593 inst
->Dst
[0].Register
.File
) &&
594 ((inst
->Src
[i
].Register
.Index
==
595 inst
->Dst
[0].Register
.Index
) ||
596 inst
->Src
[i
].Register
.Indirect
||
597 inst
->Dst
[0].Register
.Indirect
)) {
598 /* loop over dest channels */
599 uint channelsWritten
= 0x0;
600 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
601 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
602 /* check if we're reading a channel that's been written */
603 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
604 if (channelsWritten
& (1 << swizzle
)) {
608 channelsWritten
|= (1 << chan
);
618 * Initialize machine state by expanding tokens to full instructions,
619 * allocating temporary storage, setting up constants, etc.
620 * After this, we can call tgsi_exec_machine_run() many times.
623 tgsi_exec_machine_bind_shader(
624 struct tgsi_exec_machine
*mach
,
625 const struct tgsi_token
*tokens
,
626 struct tgsi_sampler
*sampler
)
629 struct tgsi_parse_context parse
;
630 struct tgsi_full_instruction
*instructions
;
631 struct tgsi_full_declaration
*declarations
;
632 uint maxInstructions
= 10, numInstructions
= 0;
633 uint maxDeclarations
= 10, numDeclarations
= 0;
636 tgsi_dump(tokens
, 0);
642 mach
->Tokens
= tokens
;
643 mach
->Sampler
= sampler
;
646 /* unbind and free all */
647 FREE(mach
->Declarations
);
648 mach
->Declarations
= NULL
;
649 mach
->NumDeclarations
= 0;
651 FREE(mach
->Instructions
);
652 mach
->Instructions
= NULL
;
653 mach
->NumInstructions
= 0;
658 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
659 if (k
!= TGSI_PARSE_OK
) {
660 debug_printf( "Problem parsing!\n" );
664 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
666 mach
->NumOutputs
= 0;
668 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
&&
669 !mach
->UsedGeometryShader
) {
670 struct tgsi_exec_vector
*inputs
;
671 struct tgsi_exec_vector
*outputs
;
673 inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
674 TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_SHADER_INPUTS
,
680 outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
681 TGSI_MAX_TOTAL_VERTICES
, 16);
688 align_free(mach
->Inputs
);
689 align_free(mach
->Outputs
);
691 mach
->Inputs
= inputs
;
692 mach
->Outputs
= outputs
;
693 mach
->UsedGeometryShader
= TRUE
;
696 declarations
= (struct tgsi_full_declaration
*)
697 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
703 instructions
= (struct tgsi_full_instruction
*)
704 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
707 FREE( declarations
);
711 while( !tgsi_parse_end_of_tokens( &parse
) ) {
714 tgsi_parse_token( &parse
);
715 switch( parse
.FullToken
.Token
.Type
) {
716 case TGSI_TOKEN_TYPE_DECLARATION
:
717 /* save expanded declaration */
718 if (numDeclarations
== maxDeclarations
) {
719 declarations
= REALLOC(declarations
,
721 * sizeof(struct tgsi_full_declaration
),
722 (maxDeclarations
+ 10)
723 * sizeof(struct tgsi_full_declaration
));
724 maxDeclarations
+= 10;
726 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
728 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
729 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
734 memcpy(declarations
+ numDeclarations
,
735 &parse
.FullToken
.FullDeclaration
,
736 sizeof(declarations
[0]));
740 case TGSI_TOKEN_TYPE_IMMEDIATE
:
742 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
744 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
746 for( i
= 0; i
< size
; i
++ ) {
747 mach
->Imms
[mach
->ImmLimit
][i
] =
748 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
754 case TGSI_TOKEN_TYPE_INSTRUCTION
:
756 /* save expanded instruction */
757 if (numInstructions
== maxInstructions
) {
758 instructions
= REALLOC(instructions
,
760 * sizeof(struct tgsi_full_instruction
),
761 (maxInstructions
+ 10)
762 * sizeof(struct tgsi_full_instruction
));
763 maxInstructions
+= 10;
766 memcpy(instructions
+ numInstructions
,
767 &parse
.FullToken
.FullInstruction
,
768 sizeof(instructions
[0]));
773 case TGSI_TOKEN_TYPE_PROPERTY
:
774 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
775 if (parse
.FullToken
.FullProperty
.Property
.PropertyName
== TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
) {
776 mach
->MaxOutputVertices
= parse
.FullToken
.FullProperty
.u
[0].Data
;
785 tgsi_parse_free (&parse
);
787 FREE(mach
->Declarations
);
788 mach
->Declarations
= declarations
;
789 mach
->NumDeclarations
= numDeclarations
;
791 FREE(mach
->Instructions
);
792 mach
->Instructions
= instructions
;
793 mach
->NumInstructions
= numInstructions
;
797 struct tgsi_exec_machine
*
798 tgsi_exec_machine_create( void )
800 struct tgsi_exec_machine
*mach
;
803 mach
= align_malloc( sizeof *mach
, 16 );
807 memset(mach
, 0, sizeof(*mach
));
809 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
810 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
811 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
813 mach
->Inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_INPUTS
, 16);
814 mach
->Outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_OUTPUTS
, 16);
815 if (!mach
->Inputs
|| !mach
->Outputs
)
818 /* Setup constants needed by the SSE2 executor. */
819 for( i
= 0; i
< 4; i
++ ) {
820 mach
->Temps
[TGSI_EXEC_TEMP_00000000_I
].xyzw
[TGSI_EXEC_TEMP_00000000_C
].u
[i
] = 0x00000000;
821 mach
->Temps
[TGSI_EXEC_TEMP_7FFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_7FFFFFFF_C
].u
[i
] = 0x7FFFFFFF;
822 mach
->Temps
[TGSI_EXEC_TEMP_80000000_I
].xyzw
[TGSI_EXEC_TEMP_80000000_C
].u
[i
] = 0x80000000;
823 mach
->Temps
[TGSI_EXEC_TEMP_FFFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_FFFFFFFF_C
].u
[i
] = 0xFFFFFFFF; /* not used */
824 mach
->Temps
[TGSI_EXEC_TEMP_ONE_I
].xyzw
[TGSI_EXEC_TEMP_ONE_C
].f
[i
] = 1.0f
;
825 mach
->Temps
[TGSI_EXEC_TEMP_TWO_I
].xyzw
[TGSI_EXEC_TEMP_TWO_C
].f
[i
] = 2.0f
; /* not used */
826 mach
->Temps
[TGSI_EXEC_TEMP_128_I
].xyzw
[TGSI_EXEC_TEMP_128_C
].f
[i
] = 128.0f
;
827 mach
->Temps
[TGSI_EXEC_TEMP_MINUS_128_I
].xyzw
[TGSI_EXEC_TEMP_MINUS_128_C
].f
[i
] = -128.0f
;
828 mach
->Temps
[TGSI_EXEC_TEMP_THREE_I
].xyzw
[TGSI_EXEC_TEMP_THREE_C
].f
[i
] = 3.0f
;
829 mach
->Temps
[TGSI_EXEC_TEMP_HALF_I
].xyzw
[TGSI_EXEC_TEMP_HALF_C
].f
[i
] = 0.5f
;
833 /* silence warnings */
842 align_free(mach
->Inputs
);
843 align_free(mach
->Outputs
);
851 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
854 FREE(mach
->Instructions
);
855 FREE(mach
->Declarations
);
857 align_free(mach
->Inputs
);
858 align_free(mach
->Outputs
);
865 micro_add(union tgsi_exec_channel
*dst
,
866 const union tgsi_exec_channel
*src0
,
867 const union tgsi_exec_channel
*src1
)
869 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
870 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
871 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
872 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
877 union tgsi_exec_channel
*dst
,
878 const union tgsi_exec_channel
*src0
,
879 const union tgsi_exec_channel
*src1
)
881 if (src1
->f
[0] != 0) {
882 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
884 if (src1
->f
[1] != 0) {
885 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
887 if (src1
->f
[2] != 0) {
888 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
890 if (src1
->f
[3] != 0) {
891 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
897 union tgsi_exec_channel
*dst
,
898 const union tgsi_exec_channel
*src0
,
899 const union tgsi_exec_channel
*src1
,
900 const union tgsi_exec_channel
*src2
,
901 const union tgsi_exec_channel
*src3
)
903 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
904 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
905 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
906 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
910 micro_max(union tgsi_exec_channel
*dst
,
911 const union tgsi_exec_channel
*src0
,
912 const union tgsi_exec_channel
*src1
)
914 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
915 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
916 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
917 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
921 micro_min(union tgsi_exec_channel
*dst
,
922 const union tgsi_exec_channel
*src0
,
923 const union tgsi_exec_channel
*src1
)
925 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
926 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
927 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
928 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
932 micro_mul(union tgsi_exec_channel
*dst
,
933 const union tgsi_exec_channel
*src0
,
934 const union tgsi_exec_channel
*src1
)
936 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
937 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
938 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
939 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
944 union tgsi_exec_channel
*dst
,
945 const union tgsi_exec_channel
*src
)
947 dst
->f
[0] = -src
->f
[0];
948 dst
->f
[1] = -src
->f
[1];
949 dst
->f
[2] = -src
->f
[2];
950 dst
->f
[3] = -src
->f
[3];
955 union tgsi_exec_channel
*dst
,
956 const union tgsi_exec_channel
*src0
,
957 const union tgsi_exec_channel
*src1
)
960 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
961 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
962 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
963 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
965 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
966 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
967 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
968 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
973 micro_sub(union tgsi_exec_channel
*dst
,
974 const union tgsi_exec_channel
*src0
,
975 const union tgsi_exec_channel
*src1
)
977 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
978 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
979 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
980 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
984 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
985 const uint chan_index
,
988 const union tgsi_exec_channel
*index
,
989 const union tgsi_exec_channel
*index2D
,
990 union tgsi_exec_channel
*chan
)
997 case TGSI_FILE_CONSTANT
:
998 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
999 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
1000 assert(mach
->Consts
[index2D
->i
[i
]]);
1002 if (index
->i
[i
] < 0) {
1005 /* NOTE: copying the const value as a uint instead of float */
1006 const uint constbuf
= index2D
->i
[i
];
1007 const uint
*buf
= (const uint
*)mach
->Consts
[constbuf
];
1008 const int pos
= index
->i
[i
] * 4 + swizzle
;
1009 /* const buffer bounds check */
1010 if (pos
< 0 || pos
>= (int) mach
->ConstsSize
[constbuf
]) {
1012 /* Debug: print warning */
1013 static int count
= 0;
1015 debug_printf("TGSI Exec: const buffer index %d"
1016 " out of bounds\n", pos
);
1021 chan
->u
[i
] = buf
[pos
];
1026 case TGSI_FILE_INPUT
:
1027 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1029 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1030 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1031 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1032 index2D->i[i], index->i[i]);
1034 int pos
= index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
];
1036 assert(pos
< TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
);
1037 chan
->u
[i
] = mach
->Inputs
[pos
].xyzw
[swizzle
].u
[i
];
1041 case TGSI_FILE_SYSTEM_VALUE
:
1042 /* XXX no swizzling at this point. Will be needed if we put
1043 * gl_FragCoord, for example, in a sys value register.
1045 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1046 chan
->u
[i
] = mach
->SystemValue
[index
->i
[i
]].u
[i
];
1050 case TGSI_FILE_TEMPORARY
:
1051 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1052 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1053 assert(index2D
->i
[i
] == 0);
1055 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1059 case TGSI_FILE_IMMEDIATE
:
1060 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1061 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1062 assert(index2D
->i
[i
] == 0);
1064 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1068 case TGSI_FILE_ADDRESS
:
1069 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1070 assert(index
->i
[i
] >= 0);
1071 assert(index2D
->i
[i
] == 0);
1073 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1077 case TGSI_FILE_PREDICATE
:
1078 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1079 assert(index
->i
[i
] >= 0 && index
->i
[i
] < TGSI_EXEC_NUM_PREDS
);
1080 assert(index2D
->i
[i
] == 0);
1082 chan
->u
[i
] = mach
->Predicates
[0].xyzw
[swizzle
].u
[i
];
1086 case TGSI_FILE_OUTPUT
:
1087 /* vertex/fragment output vars can be read too */
1088 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1089 assert(index
->i
[i
] >= 0);
1090 assert(index2D
->i
[i
] == 0);
1092 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1098 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1105 fetch_source(const struct tgsi_exec_machine
*mach
,
1106 union tgsi_exec_channel
*chan
,
1107 const struct tgsi_full_src_register
*reg
,
1108 const uint chan_index
,
1109 enum tgsi_exec_datatype src_datatype
)
1111 union tgsi_exec_channel index
;
1112 union tgsi_exec_channel index2D
;
1115 /* We start with a direct index into a register file.
1119 * file = Register.File
1120 * [1] = Register.Index
1125 index
.i
[3] = reg
->Register
.Index
;
1127 /* There is an extra source register that indirectly subscripts
1128 * a register file. The direct index now becomes an offset
1129 * that is being added to the indirect register.
1133 * ind = Indirect.File
1134 * [2] = Indirect.Index
1135 * .x = Indirect.SwizzleX
1137 if (reg
->Register
.Indirect
) {
1138 union tgsi_exec_channel index2
;
1139 union tgsi_exec_channel indir_index
;
1140 const uint execmask
= mach
->ExecMask
;
1143 /* which address register (always zero now) */
1147 index2
.i
[3] = reg
->Indirect
.Index
;
1148 /* get current value of address register[swizzle] */
1149 swizzle
= reg
->Indirect
.Swizzle
;
1150 fetch_src_file_channel(mach
,
1158 /* add value of address register to the offset */
1159 index
.i
[0] += indir_index
.i
[0];
1160 index
.i
[1] += indir_index
.i
[1];
1161 index
.i
[2] += indir_index
.i
[2];
1162 index
.i
[3] += indir_index
.i
[3];
1164 /* for disabled execution channels, zero-out the index to
1165 * avoid using a potential garbage value.
1167 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1168 if ((execmask
& (1 << i
)) == 0)
1173 /* There is an extra source register that is a second
1174 * subscript to a register file. Effectively it means that
1175 * the register file is actually a 2D array of registers.
1179 * [3] = Dimension.Index
1181 if (reg
->Register
.Dimension
) {
1185 index2D
.i
[3] = reg
->Dimension
.Index
;
1187 /* Again, the second subscript index can be addressed indirectly
1188 * identically to the first one.
1189 * Nothing stops us from indirectly addressing the indirect register,
1190 * but there is no need for that, so we won't exercise it.
1192 * file[ind[4].y+3][1],
1194 * ind = DimIndirect.File
1195 * [4] = DimIndirect.Index
1196 * .y = DimIndirect.SwizzleX
1198 if (reg
->Dimension
.Indirect
) {
1199 union tgsi_exec_channel index2
;
1200 union tgsi_exec_channel indir_index
;
1201 const uint execmask
= mach
->ExecMask
;
1207 index2
.i
[3] = reg
->DimIndirect
.Index
;
1209 swizzle
= reg
->DimIndirect
.Swizzle
;
1210 fetch_src_file_channel(mach
,
1212 reg
->DimIndirect
.File
,
1218 index2D
.i
[0] += indir_index
.i
[0];
1219 index2D
.i
[1] += indir_index
.i
[1];
1220 index2D
.i
[2] += indir_index
.i
[2];
1221 index2D
.i
[3] += indir_index
.i
[3];
1223 /* for disabled execution channels, zero-out the index to
1224 * avoid using a potential garbage value.
1226 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1227 if ((execmask
& (1 << i
)) == 0) {
1233 /* If by any chance there was a need for a 3D array of register
1234 * files, we would have to check whether Dimension is followed
1235 * by a dimension register and continue the saga.
1244 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1245 fetch_src_file_channel(mach
,
1253 if (reg
->Register
.Absolute
) {
1254 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1255 micro_abs(chan
, chan
);
1257 micro_iabs(chan
, chan
);
1261 if (reg
->Register
.Negate
) {
1262 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1263 micro_neg(chan
, chan
);
1265 micro_ineg(chan
, chan
);
1271 store_dest(struct tgsi_exec_machine
*mach
,
1272 const union tgsi_exec_channel
*chan
,
1273 const struct tgsi_full_dst_register
*reg
,
1274 const struct tgsi_full_instruction
*inst
,
1276 enum tgsi_exec_datatype dst_datatype
)
1279 union tgsi_exec_channel null
;
1280 union tgsi_exec_channel
*dst
;
1281 union tgsi_exec_channel index2D
;
1282 uint execmask
= mach
->ExecMask
;
1283 int offset
= 0; /* indirection offset */
1287 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1288 check_inf_or_nan(chan
);
1291 /* There is an extra source register that indirectly subscripts
1292 * a register file. The direct index now becomes an offset
1293 * that is being added to the indirect register.
1297 * ind = Indirect.File
1298 * [2] = Indirect.Index
1299 * .x = Indirect.SwizzleX
1301 if (reg
->Register
.Indirect
) {
1302 union tgsi_exec_channel index
;
1303 union tgsi_exec_channel indir_index
;
1306 /* which address register (always zero for now) */
1310 index
.i
[3] = reg
->Indirect
.Index
;
1312 /* get current value of address register[swizzle] */
1313 swizzle
= reg
->Indirect
.Swizzle
;
1315 /* fetch values from the address/indirection register */
1316 fetch_src_file_channel(mach
,
1324 /* save indirection offset */
1325 offset
= indir_index
.i
[0];
1328 /* There is an extra source register that is a second
1329 * subscript to a register file. Effectively it means that
1330 * the register file is actually a 2D array of registers.
1334 * [3] = Dimension.Index
1336 if (reg
->Register
.Dimension
) {
1340 index2D
.i
[3] = reg
->Dimension
.Index
;
1342 /* Again, the second subscript index can be addressed indirectly
1343 * identically to the first one.
1344 * Nothing stops us from indirectly addressing the indirect register,
1345 * but there is no need for that, so we won't exercise it.
1347 * file[ind[4].y+3][1],
1349 * ind = DimIndirect.File
1350 * [4] = DimIndirect.Index
1351 * .y = DimIndirect.SwizzleX
1353 if (reg
->Dimension
.Indirect
) {
1354 union tgsi_exec_channel index2
;
1355 union tgsi_exec_channel indir_index
;
1356 const uint execmask
= mach
->ExecMask
;
1363 index2
.i
[3] = reg
->DimIndirect
.Index
;
1365 swizzle
= reg
->DimIndirect
.Swizzle
;
1366 fetch_src_file_channel(mach
,
1368 reg
->DimIndirect
.File
,
1374 index2D
.i
[0] += indir_index
.i
[0];
1375 index2D
.i
[1] += indir_index
.i
[1];
1376 index2D
.i
[2] += indir_index
.i
[2];
1377 index2D
.i
[3] += indir_index
.i
[3];
1379 /* for disabled execution channels, zero-out the index to
1380 * avoid using a potential garbage value.
1382 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1383 if ((execmask
& (1 << i
)) == 0) {
1389 /* If by any chance there was a need for a 3D array of register
1390 * files, we would have to check whether Dimension is followed
1391 * by a dimension register and continue the saga.
1400 switch (reg
->Register
.File
) {
1401 case TGSI_FILE_NULL
:
1405 case TGSI_FILE_OUTPUT
:
1406 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1407 + reg
->Register
.Index
;
1408 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1410 debug_printf("NumOutputs = %d, TEMP_O_C/I = %d, redindex = %d\n",
1411 mach
->NumOutputs
, mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0],
1412 reg
->Register
.Index
);
1413 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1414 debug_printf("STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1415 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1416 if (execmask
& (1 << i
))
1417 debug_printf("%f, ", chan
->f
[i
]);
1418 debug_printf(")\n");
1423 case TGSI_FILE_TEMPORARY
:
1424 index
= reg
->Register
.Index
;
1425 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1426 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1429 case TGSI_FILE_ADDRESS
:
1430 index
= reg
->Register
.Index
;
1431 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1434 case TGSI_FILE_PREDICATE
:
1435 index
= reg
->Register
.Index
;
1436 assert(index
< TGSI_EXEC_NUM_PREDS
);
1437 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1445 if (inst
->Instruction
.Predicate
) {
1447 union tgsi_exec_channel
*pred
;
1449 switch (chan_index
) {
1451 swizzle
= inst
->Predicate
.SwizzleX
;
1454 swizzle
= inst
->Predicate
.SwizzleY
;
1457 swizzle
= inst
->Predicate
.SwizzleZ
;
1460 swizzle
= inst
->Predicate
.SwizzleW
;
1467 assert(inst
->Predicate
.Index
== 0);
1469 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1471 if (inst
->Predicate
.Negate
) {
1472 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1474 execmask
&= ~(1 << i
);
1478 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1480 execmask
&= ~(1 << i
);
1486 switch (inst
->Instruction
.Saturate
) {
1488 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1489 if (execmask
& (1 << i
))
1490 dst
->i
[i
] = chan
->i
[i
];
1493 case TGSI_SAT_ZERO_ONE
:
1494 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1495 if (execmask
& (1 << i
)) {
1496 if (chan
->f
[i
] < 0.0f
)
1498 else if (chan
->f
[i
] > 1.0f
)
1501 dst
->i
[i
] = chan
->i
[i
];
1505 case TGSI_SAT_MINUS_PLUS_ONE
:
1506 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1507 if (execmask
& (1 << i
)) {
1508 if (chan
->f
[i
] < -1.0f
)
1510 else if (chan
->f
[i
] > 1.0f
)
1513 dst
->i
[i
] = chan
->i
[i
];
1522 #define FETCH(VAL,INDEX,CHAN)\
1523 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1525 #define IFETCH(VAL,INDEX,CHAN)\
1526 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
1530 * Execute ARB-style KIL which is predicated by a src register.
1531 * Kill fragment if any of the four values is less than zero.
1534 exec_kill_if(struct tgsi_exec_machine
*mach
,
1535 const struct tgsi_full_instruction
*inst
)
1539 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1540 union tgsi_exec_channel r
[1];
1542 /* This mask stores component bits that were already tested. */
1545 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1550 /* unswizzle channel */
1551 swizzle
= tgsi_util_get_full_src_register_swizzle (
1555 /* check if the component has not been already tested */
1556 if (uniquemask
& (1 << swizzle
))
1558 uniquemask
|= 1 << swizzle
;
1560 FETCH(&r
[0], 0, chan_index
);
1561 for (i
= 0; i
< 4; i
++)
1562 if (r
[0].f
[i
] < 0.0f
)
1566 /* restrict to fragments currently executing */
1567 kilmask
&= mach
->ExecMask
;
1569 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1573 * Unconditional fragment kill/discard.
1576 exec_kill(struct tgsi_exec_machine
*mach
,
1577 const struct tgsi_full_instruction
*inst
)
1579 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1581 /* kill fragment for all fragments currently executing */
1582 kilmask
= mach
->ExecMask
;
1583 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1587 emit_vertex(struct tgsi_exec_machine
*mach
)
1589 /* FIXME: check for exec mask correctly
1591 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1592 if ((mach->ExecMask & (1 << i)))
1594 if (mach
->ExecMask
) {
1595 if (mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] >= mach
->MaxOutputVertices
)
1598 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1599 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1604 emit_primitive(struct tgsi_exec_machine
*mach
)
1606 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1607 /* FIXME: check for exec mask correctly
1609 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1610 if ((mach->ExecMask & (1 << i)))
1612 if (mach
->ExecMask
) {
1614 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1615 mach
->Primitives
[*prim_count
] = 0;
1620 conditional_emit_primitive(struct tgsi_exec_machine
*mach
)
1622 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1624 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]];
1625 if (emitted_verts
) {
1626 emit_primitive(mach
);
1633 * Fetch four texture samples using STR texture coordinates.
1636 fetch_texel( struct tgsi_sampler
*sampler
,
1637 const unsigned sview_idx
,
1638 const unsigned sampler_idx
,
1639 const union tgsi_exec_channel
*s
,
1640 const union tgsi_exec_channel
*t
,
1641 const union tgsi_exec_channel
*p
,
1642 const union tgsi_exec_channel
*c0
,
1643 const union tgsi_exec_channel
*c1
,
1644 float derivs
[3][2][TGSI_QUAD_SIZE
],
1645 const int8_t offset
[3],
1646 enum tgsi_sampler_control control
,
1647 union tgsi_exec_channel
*r
,
1648 union tgsi_exec_channel
*g
,
1649 union tgsi_exec_channel
*b
,
1650 union tgsi_exec_channel
*a
)
1653 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1655 /* FIXME: handle explicit derivs, offsets */
1656 sampler
->get_samples(sampler
, sview_idx
, sampler_idx
,
1657 s
->f
, t
->f
, p
->f
, c0
->f
, c1
->f
, derivs
, offset
, control
, rgba
);
1659 for (j
= 0; j
< 4; j
++) {
1660 r
->f
[j
] = rgba
[0][j
];
1661 g
->f
[j
] = rgba
[1][j
];
1662 b
->f
[j
] = rgba
[2][j
];
1663 a
->f
[j
] = rgba
[3][j
];
1668 #define TEX_MODIFIER_NONE 0
1669 #define TEX_MODIFIER_PROJECTED 1
1670 #define TEX_MODIFIER_LOD_BIAS 2
1671 #define TEX_MODIFIER_EXPLICIT_LOD 3
1672 #define TEX_MODIFIER_LEVEL_ZERO 4
1676 * Fetch all 3 (for s,t,r coords) texel offsets, put them into int array.
1679 fetch_texel_offsets(struct tgsi_exec_machine
*mach
,
1680 const struct tgsi_full_instruction
*inst
,
1683 if (inst
->Texture
.NumOffsets
== 1) {
1684 union tgsi_exec_channel index
;
1685 union tgsi_exec_channel offset
[3];
1686 index
.i
[0] = index
.i
[1] = index
.i
[2] = index
.i
[3] = inst
->TexOffsets
[0].Index
;
1687 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1688 inst
->TexOffsets
[0].SwizzleX
, &index
, &ZeroVec
, &offset
[0]);
1689 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1690 inst
->TexOffsets
[0].SwizzleY
, &index
, &ZeroVec
, &offset
[1]);
1691 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1692 inst
->TexOffsets
[0].SwizzleZ
, &index
, &ZeroVec
, &offset
[2]);
1693 offsets
[0] = offset
[0].i
[0];
1694 offsets
[1] = offset
[1].i
[0];
1695 offsets
[2] = offset
[2].i
[0];
1697 assert(inst
->Texture
.NumOffsets
== 0);
1698 offsets
[0] = offsets
[1] = offsets
[2] = 0;
1704 * Fetch dx and dy values for one channel (s, t or r).
1705 * Put dx values into one float array, dy values into another.
1708 fetch_assign_deriv_channel(struct tgsi_exec_machine
*mach
,
1709 const struct tgsi_full_instruction
*inst
,
1712 float derivs
[2][TGSI_QUAD_SIZE
])
1714 union tgsi_exec_channel d
;
1715 FETCH(&d
, regdsrcx
, chan
);
1716 derivs
[0][0] = d
.f
[0];
1717 derivs
[0][1] = d
.f
[1];
1718 derivs
[0][2] = d
.f
[2];
1719 derivs
[0][3] = d
.f
[3];
1720 FETCH(&d
, regdsrcx
+ 1, chan
);
1721 derivs
[1][0] = d
.f
[0];
1722 derivs
[1][1] = d
.f
[1];
1723 derivs
[1][2] = d
.f
[2];
1724 derivs
[1][3] = d
.f
[3];
1729 * execute a texture instruction.
1731 * modifier is used to control the channel routing for the\
1732 * instruction variants like proj, lod, and texture with lod bias.
1733 * sampler indicates which src register the sampler is contained in.
1736 exec_tex(struct tgsi_exec_machine
*mach
,
1737 const struct tgsi_full_instruction
*inst
,
1738 uint modifier
, uint sampler
)
1740 const uint unit
= inst
->Src
[sampler
].Register
.Index
;
1741 const union tgsi_exec_channel
*args
[5], *proj
= NULL
;
1742 union tgsi_exec_channel r
[5];
1743 enum tgsi_sampler_control control
= tgsi_sampler_lod_none
;
1746 int dim
, shadow_ref
, i
;
1748 /* always fetch all 3 offsets, overkill but keeps code simple */
1749 fetch_texel_offsets(mach
, inst
, offsets
);
1751 assert(modifier
!= TEX_MODIFIER_LEVEL_ZERO
);
1752 assert(inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
);
1754 dim
= tgsi_util_get_texture_coord_dim(inst
->Texture
.Texture
, &shadow_ref
);
1757 if (shadow_ref
>= 0)
1758 assert(shadow_ref
>= dim
&& shadow_ref
< Elements(args
));
1760 /* fetch modifier to the last argument */
1761 if (modifier
!= TEX_MODIFIER_NONE
) {
1762 const int last
= Elements(args
) - 1;
1764 /* fetch modifier from src0.w or src1.x */
1766 assert(dim
<= TGSI_CHAN_W
&& shadow_ref
!= TGSI_CHAN_W
);
1767 FETCH(&r
[last
], 0, TGSI_CHAN_W
);
1770 assert(shadow_ref
!= 4);
1771 FETCH(&r
[last
], 1, TGSI_CHAN_X
);
1774 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
1775 args
[last
] = &r
[last
];
1779 args
[last
] = &ZeroVec
;
1782 /* point unused arguments to zero vector */
1783 for (i
= dim
; i
< last
; i
++)
1786 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
)
1787 control
= tgsi_sampler_lod_explicit
;
1788 else if (modifier
== TEX_MODIFIER_LOD_BIAS
)
1789 control
= tgsi_sampler_lod_bias
;
1792 for (i
= dim
; i
< Elements(args
); i
++)
1796 /* fetch coordinates */
1797 for (i
= 0; i
< dim
; i
++) {
1798 FETCH(&r
[i
], 0, TGSI_CHAN_X
+ i
);
1801 micro_div(&r
[i
], &r
[i
], proj
);
1806 /* fetch reference value */
1807 if (shadow_ref
>= 0) {
1808 FETCH(&r
[shadow_ref
], shadow_ref
/ 4, TGSI_CHAN_X
+ (shadow_ref
% 4));
1811 micro_div(&r
[shadow_ref
], &r
[shadow_ref
], proj
);
1813 args
[shadow_ref
] = &r
[shadow_ref
];
1816 fetch_texel(mach
->Sampler
, unit
, unit
,
1817 args
[0], args
[1], args
[2], args
[3], args
[4],
1818 NULL
, offsets
, control
,
1819 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1822 debug_printf("fetch r: %g %g %g %g\n",
1823 r
[0].f
[0], r
[0].f
[1], r
[0].f
[2], r
[0].f
[3]);
1824 debug_printf("fetch g: %g %g %g %g\n",
1825 r
[1].f
[0], r
[1].f
[1], r
[1].f
[2], r
[1].f
[3]);
1826 debug_printf("fetch b: %g %g %g %g\n",
1827 r
[2].f
[0], r
[2].f
[1], r
[2].f
[2], r
[2].f
[3]);
1828 debug_printf("fetch a: %g %g %g %g\n",
1829 r
[3].f
[0], r
[3].f
[1], r
[3].f
[2], r
[3].f
[3]);
1832 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1833 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1834 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1841 exec_txd(struct tgsi_exec_machine
*mach
,
1842 const struct tgsi_full_instruction
*inst
)
1844 const uint unit
= inst
->Src
[3].Register
.Index
;
1845 union tgsi_exec_channel r
[4];
1846 float derivs
[3][2][TGSI_QUAD_SIZE
];
1850 /* always fetch all 3 offsets, overkill but keeps code simple */
1851 fetch_texel_offsets(mach
, inst
, offsets
);
1853 switch (inst
->Texture
.Texture
) {
1854 case TGSI_TEXTURE_1D
:
1855 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1857 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1859 fetch_texel(mach
->Sampler
, unit
, unit
,
1860 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
1861 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1862 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1865 case TGSI_TEXTURE_SHADOW1D
:
1866 case TGSI_TEXTURE_1D_ARRAY
:
1867 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1868 /* SHADOW1D/1D_ARRAY would not need Y/Z respectively, but don't bother */
1869 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1870 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1871 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1873 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1875 fetch_texel(mach
->Sampler
, unit
, unit
,
1876 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
1877 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1878 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1881 case TGSI_TEXTURE_2D
:
1882 case TGSI_TEXTURE_RECT
:
1883 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1884 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1886 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1887 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
1889 fetch_texel(mach
->Sampler
, unit
, unit
,
1890 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
1891 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1892 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1896 case TGSI_TEXTURE_SHADOW2D
:
1897 case TGSI_TEXTURE_SHADOWRECT
:
1898 case TGSI_TEXTURE_2D_ARRAY
:
1899 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1900 /* only SHADOW2D_ARRAY actually needs W */
1901 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1902 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1903 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1904 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1906 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1907 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
1909 fetch_texel(mach
->Sampler
, unit
, unit
,
1910 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
1911 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1912 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1915 case TGSI_TEXTURE_3D
:
1916 case TGSI_TEXTURE_CUBE
:
1917 case TGSI_TEXTURE_CUBE_ARRAY
:
1918 case TGSI_TEXTURE_SHADOWCUBE
:
1919 /* only TEXTURE_CUBE_ARRAY and TEXTURE_SHADOWCUBE actually need W */
1920 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1921 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1922 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1923 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1925 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1926 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
1927 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Z
, derivs
[2]);
1929 fetch_texel(mach
->Sampler
, unit
, unit
,
1930 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
1931 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1932 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1939 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1940 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1941 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1948 exec_txf(struct tgsi_exec_machine
*mach
,
1949 const struct tgsi_full_instruction
*inst
)
1951 const uint unit
= inst
->Src
[1].Register
.Index
;
1952 union tgsi_exec_channel r
[4];
1954 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1959 /* always fetch all 3 offsets, overkill but keeps code simple */
1960 fetch_texel_offsets(mach
, inst
, offsets
);
1962 IFETCH(&r
[3], 0, TGSI_CHAN_W
);
1964 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
) {
1965 target
= mach
->SamplerViews
[unit
].Resource
;
1968 target
= inst
->Texture
.Texture
;
1971 case TGSI_TEXTURE_3D
:
1972 case TGSI_TEXTURE_2D_ARRAY
:
1973 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1974 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
1975 IFETCH(&r
[2], 0, TGSI_CHAN_Z
);
1977 case TGSI_TEXTURE_2D
:
1978 case TGSI_TEXTURE_RECT
:
1979 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1980 case TGSI_TEXTURE_SHADOW2D
:
1981 case TGSI_TEXTURE_SHADOWRECT
:
1982 case TGSI_TEXTURE_1D_ARRAY
:
1983 case TGSI_TEXTURE_2D_MSAA
:
1984 IFETCH(&r
[1], 0, TGSI_CHAN_Y
);
1986 case TGSI_TEXTURE_BUFFER
:
1987 case TGSI_TEXTURE_1D
:
1988 case TGSI_TEXTURE_SHADOW1D
:
1989 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
1996 mach
->Sampler
->get_texel(mach
->Sampler
, unit
, r
[0].i
, r
[1].i
, r
[2].i
, r
[3].i
,
1999 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2000 r
[0].f
[j
] = rgba
[0][j
];
2001 r
[1].f
[j
] = rgba
[1][j
];
2002 r
[2].f
[j
] = rgba
[2][j
];
2003 r
[3].f
[j
] = rgba
[3][j
];
2006 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
) {
2007 unsigned char swizzles
[4];
2008 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2009 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2010 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2011 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2013 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2014 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2015 store_dest(mach
, &r
[swizzles
[chan
]],
2016 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2021 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2022 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2023 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2030 exec_txq(struct tgsi_exec_machine
*mach
,
2031 const struct tgsi_full_instruction
*inst
)
2033 const uint unit
= inst
->Src
[1].Register
.Index
;
2035 union tgsi_exec_channel r
[4], src
;
2039 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
2041 /* XXX: This interface can't return per-pixel values */
2042 mach
->Sampler
->get_dims(mach
->Sampler
, unit
, src
.i
[0], result
);
2044 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2045 for (j
= 0; j
< 4; j
++) {
2046 r
[j
].i
[i
] = result
[j
];
2050 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2051 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2052 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
2053 TGSI_EXEC_DATA_INT
);
2059 exec_sample(struct tgsi_exec_machine
*mach
,
2060 const struct tgsi_full_instruction
*inst
,
2061 uint modifier
, boolean compare
)
2063 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2064 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2065 union tgsi_exec_channel r
[4], c1
;
2066 const union tgsi_exec_channel
*lod
= &ZeroVec
;
2067 enum tgsi_sampler_control control
= tgsi_sampler_lod_none
;
2069 unsigned char swizzles
[4];
2072 /* always fetch all 3 offsets, overkill but keeps code simple */
2073 fetch_texel_offsets(mach
, inst
, offsets
);
2075 assert(modifier
!= TEX_MODIFIER_PROJECTED
);
2077 if (modifier
!= TEX_MODIFIER_NONE
) {
2078 if (modifier
== TEX_MODIFIER_LOD_BIAS
) {
2079 FETCH(&c1
, 3, TGSI_CHAN_X
);
2081 control
= tgsi_sampler_lod_bias
;
2083 else if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
2084 FETCH(&c1
, 3, TGSI_CHAN_X
);
2086 control
= tgsi_sampler_lod_explicit
;
2089 assert(modifier
== TEX_MODIFIER_LEVEL_ZERO
);
2090 control
= tgsi_sampler_lod_zero
;
2094 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2096 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2097 case TGSI_TEXTURE_1D
:
2099 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2100 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2101 &r
[0], &ZeroVec
, &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2102 NULL
, offsets
, control
,
2103 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2106 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2107 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2108 NULL
, offsets
, control
,
2109 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2113 case TGSI_TEXTURE_1D_ARRAY
:
2114 case TGSI_TEXTURE_2D
:
2115 case TGSI_TEXTURE_RECT
:
2116 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2118 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2119 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2120 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2121 NULL
, offsets
, control
,
2122 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2125 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2126 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2127 NULL
, offsets
, control
,
2128 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2132 case TGSI_TEXTURE_2D_ARRAY
:
2133 case TGSI_TEXTURE_3D
:
2134 case TGSI_TEXTURE_CUBE
:
2135 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2136 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2138 FETCH(&r
[3], 3, TGSI_CHAN_X
);
2139 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2140 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2141 NULL
, offsets
, control
,
2142 &r
[0], &r
[1], &r
[2], &r
[3]);
2145 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2146 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
,
2147 NULL
, offsets
, control
,
2148 &r
[0], &r
[1], &r
[2], &r
[3]);
2152 case TGSI_TEXTURE_CUBE_ARRAY
:
2153 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2154 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2155 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2157 FETCH(&r
[4], 3, TGSI_CHAN_X
);
2158 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2159 &r
[0], &r
[1], &r
[2], &r
[3], &r
[4],
2160 NULL
, offsets
, control
,
2161 &r
[0], &r
[1], &r
[2], &r
[3]);
2164 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2165 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2166 NULL
, offsets
, control
,
2167 &r
[0], &r
[1], &r
[2], &r
[3]);
2176 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2177 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2178 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2179 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2181 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2182 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2183 store_dest(mach
, &r
[swizzles
[chan
]],
2184 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2190 exec_sample_d(struct tgsi_exec_machine
*mach
,
2191 const struct tgsi_full_instruction
*inst
)
2193 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2194 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2195 union tgsi_exec_channel r
[4];
2196 float derivs
[3][2][TGSI_QUAD_SIZE
];
2198 unsigned char swizzles
[4];
2201 /* always fetch all 3 offsets, overkill but keeps code simple */
2202 fetch_texel_offsets(mach
, inst
, offsets
);
2204 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2206 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2207 case TGSI_TEXTURE_1D
:
2208 case TGSI_TEXTURE_1D_ARRAY
:
2209 /* only 1D array actually needs Y */
2210 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2212 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2214 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2215 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2216 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
2217 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2220 case TGSI_TEXTURE_2D
:
2221 case TGSI_TEXTURE_RECT
:
2222 case TGSI_TEXTURE_2D_ARRAY
:
2223 /* only 2D array actually needs Z */
2224 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2225 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2227 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2228 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2230 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2231 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* inputs */
2232 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
2233 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2236 case TGSI_TEXTURE_3D
:
2237 case TGSI_TEXTURE_CUBE
:
2238 case TGSI_TEXTURE_CUBE_ARRAY
:
2239 /* only cube array actually needs W */
2240 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2241 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2242 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2244 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2245 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2246 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Z
, derivs
[2]);
2248 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2249 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
,
2250 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
2251 &r
[0], &r
[1], &r
[2], &r
[3]);
2258 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2259 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2260 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2261 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2263 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2264 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2265 store_dest(mach
, &r
[swizzles
[chan
]],
2266 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2273 * Evaluate a constant-valued coefficient at the position of the
2278 struct tgsi_exec_machine
*mach
,
2284 for( i
= 0; i
< TGSI_QUAD_SIZE
; i
++ ) {
2285 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
2290 * Evaluate a linear-valued coefficient at the position of the
2295 struct tgsi_exec_machine
*mach
,
2299 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2300 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2301 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2302 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2303 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2304 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
2305 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
2306 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
2307 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
2311 * Evaluate a perspective-valued coefficient at the position of the
2315 eval_perspective_coef(
2316 struct tgsi_exec_machine
*mach
,
2320 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2321 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2322 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2323 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2324 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2325 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
2326 /* divide by W here */
2327 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
2328 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
2329 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
2330 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
2334 typedef void (* eval_coef_func
)(
2335 struct tgsi_exec_machine
*mach
,
2340 exec_declaration(struct tgsi_exec_machine
*mach
,
2341 const struct tgsi_full_declaration
*decl
)
2343 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
2344 mach
->SamplerViews
[decl
->Range
.First
] = decl
->SamplerView
;
2348 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
2349 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
2350 uint first
, last
, mask
;
2352 first
= decl
->Range
.First
;
2353 last
= decl
->Range
.Last
;
2354 mask
= decl
->Declaration
.UsageMask
;
2356 /* XXX we could remove this special-case code since
2357 * mach->InterpCoefs[first].a0 should already have the
2358 * front/back-face value. But we should first update the
2359 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2360 * Then, we could remove the tgsi_exec_machine::Face field.
2362 /* XXX make FACE a system value */
2363 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
2366 assert(decl
->Semantic
.Index
== 0);
2367 assert(first
== last
);
2369 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2370 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
2373 eval_coef_func eval
;
2376 switch (decl
->Interp
.Interpolate
) {
2377 case TGSI_INTERPOLATE_CONSTANT
:
2378 eval
= eval_constant_coef
;
2381 case TGSI_INTERPOLATE_LINEAR
:
2382 eval
= eval_linear_coef
;
2385 case TGSI_INTERPOLATE_PERSPECTIVE
:
2386 eval
= eval_perspective_coef
;
2389 case TGSI_INTERPOLATE_COLOR
:
2390 eval
= mach
->flatshade_color
? eval_constant_coef
: eval_perspective_coef
;
2398 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2399 if (mask
& (1 << j
)) {
2400 for (i
= first
; i
<= last
; i
++) {
2407 if (DEBUG_EXECUTION
) {
2409 for (i
= first
; i
<= last
; ++i
) {
2410 debug_printf("IN[%2u] = ", i
);
2411 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2415 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
2416 mach
->Inputs
[i
].xyzw
[0].f
[j
], mach
->Inputs
[i
].xyzw
[0].u
[j
],
2417 mach
->Inputs
[i
].xyzw
[1].f
[j
], mach
->Inputs
[i
].xyzw
[1].u
[j
],
2418 mach
->Inputs
[i
].xyzw
[2].f
[j
], mach
->Inputs
[i
].xyzw
[2].u
[j
],
2419 mach
->Inputs
[i
].xyzw
[3].f
[j
], mach
->Inputs
[i
].xyzw
[3].u
[j
]);
2426 if (decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
2427 mach
->SysSemanticToIndex
[decl
->Declaration
.Semantic
] = decl
->Range
.First
;
2431 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
2432 const union tgsi_exec_channel
*src
);
2435 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
2436 const struct tgsi_full_instruction
*inst
,
2438 enum tgsi_exec_datatype dst_datatype
,
2439 enum tgsi_exec_datatype src_datatype
)
2442 union tgsi_exec_channel src
;
2443 union tgsi_exec_channel dst
;
2445 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2447 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2448 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2449 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2455 exec_vector_unary(struct tgsi_exec_machine
*mach
,
2456 const struct tgsi_full_instruction
*inst
,
2458 enum tgsi_exec_datatype dst_datatype
,
2459 enum tgsi_exec_datatype src_datatype
)
2462 struct tgsi_exec_vector dst
;
2464 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2465 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2466 union tgsi_exec_channel src
;
2468 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
2469 op(&dst
.xyzw
[chan
], &src
);
2472 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2473 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2474 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2479 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
2480 const union tgsi_exec_channel
*src0
,
2481 const union tgsi_exec_channel
*src1
);
2484 exec_scalar_binary(struct tgsi_exec_machine
*mach
,
2485 const struct tgsi_full_instruction
*inst
,
2487 enum tgsi_exec_datatype dst_datatype
,
2488 enum tgsi_exec_datatype src_datatype
)
2491 union tgsi_exec_channel src
[2];
2492 union tgsi_exec_channel dst
;
2494 fetch_source(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2495 fetch_source(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, src_datatype
);
2496 op(&dst
, &src
[0], &src
[1]);
2497 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2498 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2499 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2505 exec_vector_binary(struct tgsi_exec_machine
*mach
,
2506 const struct tgsi_full_instruction
*inst
,
2508 enum tgsi_exec_datatype dst_datatype
,
2509 enum tgsi_exec_datatype src_datatype
)
2512 struct tgsi_exec_vector dst
;
2514 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2515 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2516 union tgsi_exec_channel src
[2];
2518 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2519 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2520 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
2523 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2524 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2525 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2530 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
2531 const union tgsi_exec_channel
*src0
,
2532 const union tgsi_exec_channel
*src1
,
2533 const union tgsi_exec_channel
*src2
);
2536 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
2537 const struct tgsi_full_instruction
*inst
,
2538 micro_trinary_op op
,
2539 enum tgsi_exec_datatype dst_datatype
,
2540 enum tgsi_exec_datatype src_datatype
)
2543 struct tgsi_exec_vector dst
;
2545 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2546 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2547 union tgsi_exec_channel src
[3];
2549 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2550 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2551 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2552 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
2555 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2556 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2557 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2562 typedef void (* micro_quaternary_op
)(union tgsi_exec_channel
*dst
,
2563 const union tgsi_exec_channel
*src0
,
2564 const union tgsi_exec_channel
*src1
,
2565 const union tgsi_exec_channel
*src2
,
2566 const union tgsi_exec_channel
*src3
);
2569 exec_vector_quaternary(struct tgsi_exec_machine
*mach
,
2570 const struct tgsi_full_instruction
*inst
,
2571 micro_quaternary_op op
,
2572 enum tgsi_exec_datatype dst_datatype
,
2573 enum tgsi_exec_datatype src_datatype
)
2576 struct tgsi_exec_vector dst
;
2578 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2579 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2580 union tgsi_exec_channel src
[4];
2582 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2583 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2584 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2585 fetch_source(mach
, &src
[3], &inst
->Src
[3], chan
, src_datatype
);
2586 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2], &src
[3]);
2589 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2590 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2591 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2597 exec_dp3(struct tgsi_exec_machine
*mach
,
2598 const struct tgsi_full_instruction
*inst
)
2601 union tgsi_exec_channel arg
[3];
2603 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2604 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2605 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2607 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
2608 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2609 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2610 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2613 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2614 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2615 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2621 exec_dp4(struct tgsi_exec_machine
*mach
,
2622 const struct tgsi_full_instruction
*inst
)
2625 union tgsi_exec_channel arg
[3];
2627 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2628 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2629 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2631 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
2632 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2633 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2634 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2637 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2638 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2639 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2645 exec_dp2a(struct tgsi_exec_machine
*mach
,
2646 const struct tgsi_full_instruction
*inst
)
2649 union tgsi_exec_channel arg
[3];
2651 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2652 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2653 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2655 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2656 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2657 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2659 fetch_source(mach
, &arg
[1], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2660 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2662 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2663 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2664 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2670 exec_dph(struct tgsi_exec_machine
*mach
,
2671 const struct tgsi_full_instruction
*inst
)
2674 union tgsi_exec_channel arg
[3];
2676 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2677 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2678 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2680 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2681 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2682 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2684 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2685 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2686 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2688 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2689 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2691 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2692 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2693 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2699 exec_dp2(struct tgsi_exec_machine
*mach
,
2700 const struct tgsi_full_instruction
*inst
)
2703 union tgsi_exec_channel arg
[3];
2705 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2706 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2707 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2709 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2710 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2711 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2713 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2714 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2715 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2721 exec_scs(struct tgsi_exec_machine
*mach
,
2722 const struct tgsi_full_instruction
*inst
)
2724 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) {
2725 union tgsi_exec_channel arg
;
2726 union tgsi_exec_channel result
;
2728 fetch_source(mach
, &arg
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2730 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2731 micro_cos(&result
, &arg
);
2732 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2734 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2735 micro_sin(&result
, &arg
);
2736 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2739 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2740 store_dest(mach
, &ZeroVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2742 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2743 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2748 exec_xpd(struct tgsi_exec_machine
*mach
,
2749 const struct tgsi_full_instruction
*inst
)
2751 union tgsi_exec_channel r
[6];
2752 union tgsi_exec_channel d
[3];
2754 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2755 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2757 micro_mul(&r
[2], &r
[0], &r
[1]);
2759 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2760 fetch_source(mach
, &r
[4], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2762 micro_mul(&r
[5], &r
[3], &r
[4] );
2763 micro_sub(&d
[TGSI_CHAN_X
], &r
[2], &r
[5]);
2765 fetch_source(mach
, &r
[2], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2767 micro_mul(&r
[3], &r
[3], &r
[2]);
2769 fetch_source(mach
, &r
[5], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2771 micro_mul(&r
[1], &r
[1], &r
[5]);
2772 micro_sub(&d
[TGSI_CHAN_Y
], &r
[3], &r
[1]);
2774 micro_mul(&r
[5], &r
[5], &r
[4]);
2775 micro_mul(&r
[0], &r
[0], &r
[2]);
2776 micro_sub(&d
[TGSI_CHAN_Z
], &r
[5], &r
[0]);
2778 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2779 store_dest(mach
, &d
[TGSI_CHAN_X
], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2781 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2782 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2784 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2785 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2787 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2788 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2793 exec_dst(struct tgsi_exec_machine
*mach
,
2794 const struct tgsi_full_instruction
*inst
)
2796 union tgsi_exec_channel r
[2];
2797 union tgsi_exec_channel d
[4];
2799 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2800 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2801 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2802 micro_mul(&d
[TGSI_CHAN_Y
], &r
[0], &r
[1]);
2804 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2805 fetch_source(mach
, &d
[TGSI_CHAN_Z
], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2807 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2808 fetch_source(mach
, &d
[TGSI_CHAN_W
], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2811 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2812 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2814 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2815 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2817 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2818 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2820 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2821 store_dest(mach
, &d
[TGSI_CHAN_W
], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2826 exec_log(struct tgsi_exec_machine
*mach
,
2827 const struct tgsi_full_instruction
*inst
)
2829 union tgsi_exec_channel r
[3];
2831 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2832 micro_abs(&r
[2], &r
[0]); /* r2 = abs(r0) */
2833 micro_lg2(&r
[1], &r
[2]); /* r1 = lg2(r2) */
2834 micro_flr(&r
[0], &r
[1]); /* r0 = floor(r1) */
2835 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2836 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2838 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2839 micro_exp2(&r
[0], &r
[0]); /* r0 = 2 ^ r0 */
2840 micro_div(&r
[0], &r
[2], &r
[0]); /* r0 = r2 / r0 */
2841 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2843 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2844 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2846 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2847 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2852 exec_exp(struct tgsi_exec_machine
*mach
,
2853 const struct tgsi_full_instruction
*inst
)
2855 union tgsi_exec_channel r
[3];
2857 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2858 micro_flr(&r
[1], &r
[0]); /* r1 = floor(r0) */
2859 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2860 micro_exp2(&r
[2], &r
[1]); /* r2 = 2 ^ r1 */
2861 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2863 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2864 micro_sub(&r
[2], &r
[0], &r
[1]); /* r2 = r0 - r1 */
2865 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2867 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2868 micro_exp2(&r
[2], &r
[0]); /* r2 = 2 ^ r0 */
2869 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2871 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2872 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2877 exec_lit(struct tgsi_exec_machine
*mach
,
2878 const struct tgsi_full_instruction
*inst
)
2880 union tgsi_exec_channel r
[3];
2881 union tgsi_exec_channel d
[3];
2883 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YZ
) {
2884 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2885 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2886 fetch_source(mach
, &r
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2887 micro_max(&r
[1], &r
[1], &ZeroVec
);
2889 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2890 micro_min(&r
[2], &r
[2], &P128Vec
);
2891 micro_max(&r
[2], &r
[2], &M128Vec
);
2892 micro_pow(&r
[1], &r
[1], &r
[2]);
2893 micro_lt(&d
[TGSI_CHAN_Z
], &ZeroVec
, &r
[0], &r
[1], &ZeroVec
);
2894 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2896 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2897 micro_max(&d
[TGSI_CHAN_Y
], &r
[0], &ZeroVec
);
2898 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2901 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2902 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2905 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2906 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2911 exec_break(struct tgsi_exec_machine
*mach
)
2913 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
2914 /* turn off loop channels for each enabled exec channel */
2915 mach
->LoopMask
&= ~mach
->ExecMask
;
2916 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2917 UPDATE_EXEC_MASK(mach
);
2919 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
2921 mach
->Switch
.mask
= 0x0;
2923 UPDATE_EXEC_MASK(mach
);
2928 exec_switch(struct tgsi_exec_machine
*mach
,
2929 const struct tgsi_full_instruction
*inst
)
2931 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
2932 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
2934 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
2935 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
2936 mach
->Switch
.mask
= 0x0;
2937 mach
->Switch
.defaultMask
= 0x0;
2939 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
2940 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
2942 UPDATE_EXEC_MASK(mach
);
2946 exec_case(struct tgsi_exec_machine
*mach
,
2947 const struct tgsi_full_instruction
*inst
)
2949 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
2950 union tgsi_exec_channel src
;
2953 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
2955 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
2958 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
2961 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
2964 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
2968 mach
->Switch
.defaultMask
|= mask
;
2970 mach
->Switch
.mask
|= mask
& prevMask
;
2972 UPDATE_EXEC_MASK(mach
);
2975 /* FIXME: this will only work if default is last */
2977 exec_default(struct tgsi_exec_machine
*mach
)
2979 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
2981 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
2983 UPDATE_EXEC_MASK(mach
);
2987 exec_endswitch(struct tgsi_exec_machine
*mach
)
2989 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
2990 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
2992 UPDATE_EXEC_MASK(mach
);
2996 micro_i2f(union tgsi_exec_channel
*dst
,
2997 const union tgsi_exec_channel
*src
)
2999 dst
->f
[0] = (float)src
->i
[0];
3000 dst
->f
[1] = (float)src
->i
[1];
3001 dst
->f
[2] = (float)src
->i
[2];
3002 dst
->f
[3] = (float)src
->i
[3];
3006 micro_not(union tgsi_exec_channel
*dst
,
3007 const union tgsi_exec_channel
*src
)
3009 dst
->u
[0] = ~src
->u
[0];
3010 dst
->u
[1] = ~src
->u
[1];
3011 dst
->u
[2] = ~src
->u
[2];
3012 dst
->u
[3] = ~src
->u
[3];
3016 micro_shl(union tgsi_exec_channel
*dst
,
3017 const union tgsi_exec_channel
*src0
,
3018 const union tgsi_exec_channel
*src1
)
3020 unsigned masked_count
;
3021 masked_count
= src1
->u
[0] & 0x1f;
3022 dst
->u
[0] = src0
->u
[0] << masked_count
;
3023 masked_count
= src1
->u
[1] & 0x1f;
3024 dst
->u
[1] = src0
->u
[1] << masked_count
;
3025 masked_count
= src1
->u
[2] & 0x1f;
3026 dst
->u
[2] = src0
->u
[2] << masked_count
;
3027 masked_count
= src1
->u
[3] & 0x1f;
3028 dst
->u
[3] = src0
->u
[3] << masked_count
;
3032 micro_and(union tgsi_exec_channel
*dst
,
3033 const union tgsi_exec_channel
*src0
,
3034 const union tgsi_exec_channel
*src1
)
3036 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
3037 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
3038 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
3039 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
3043 micro_or(union tgsi_exec_channel
*dst
,
3044 const union tgsi_exec_channel
*src0
,
3045 const union tgsi_exec_channel
*src1
)
3047 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
3048 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
3049 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
3050 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
3054 micro_xor(union tgsi_exec_channel
*dst
,
3055 const union tgsi_exec_channel
*src0
,
3056 const union tgsi_exec_channel
*src1
)
3058 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
3059 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
3060 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
3061 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
3065 micro_mod(union tgsi_exec_channel
*dst
,
3066 const union tgsi_exec_channel
*src0
,
3067 const union tgsi_exec_channel
*src1
)
3069 dst
->i
[0] = src0
->i
[0] % src1
->i
[0];
3070 dst
->i
[1] = src0
->i
[1] % src1
->i
[1];
3071 dst
->i
[2] = src0
->i
[2] % src1
->i
[2];
3072 dst
->i
[3] = src0
->i
[3] % src1
->i
[3];
3076 micro_f2i(union tgsi_exec_channel
*dst
,
3077 const union tgsi_exec_channel
*src
)
3079 dst
->i
[0] = (int)src
->f
[0];
3080 dst
->i
[1] = (int)src
->f
[1];
3081 dst
->i
[2] = (int)src
->f
[2];
3082 dst
->i
[3] = (int)src
->f
[3];
3086 micro_fseq(union tgsi_exec_channel
*dst
,
3087 const union tgsi_exec_channel
*src0
,
3088 const union tgsi_exec_channel
*src1
)
3090 dst
->u
[0] = src0
->f
[0] == src1
->f
[0] ? ~0 : 0;
3091 dst
->u
[1] = src0
->f
[1] == src1
->f
[1] ? ~0 : 0;
3092 dst
->u
[2] = src0
->f
[2] == src1
->f
[2] ? ~0 : 0;
3093 dst
->u
[3] = src0
->f
[3] == src1
->f
[3] ? ~0 : 0;
3097 micro_fsge(union tgsi_exec_channel
*dst
,
3098 const union tgsi_exec_channel
*src0
,
3099 const union tgsi_exec_channel
*src1
)
3101 dst
->u
[0] = src0
->f
[0] >= src1
->f
[0] ? ~0 : 0;
3102 dst
->u
[1] = src0
->f
[1] >= src1
->f
[1] ? ~0 : 0;
3103 dst
->u
[2] = src0
->f
[2] >= src1
->f
[2] ? ~0 : 0;
3104 dst
->u
[3] = src0
->f
[3] >= src1
->f
[3] ? ~0 : 0;
3108 micro_fslt(union tgsi_exec_channel
*dst
,
3109 const union tgsi_exec_channel
*src0
,
3110 const union tgsi_exec_channel
*src1
)
3112 dst
->u
[0] = src0
->f
[0] < src1
->f
[0] ? ~0 : 0;
3113 dst
->u
[1] = src0
->f
[1] < src1
->f
[1] ? ~0 : 0;
3114 dst
->u
[2] = src0
->f
[2] < src1
->f
[2] ? ~0 : 0;
3115 dst
->u
[3] = src0
->f
[3] < src1
->f
[3] ? ~0 : 0;
3119 micro_fsne(union tgsi_exec_channel
*dst
,
3120 const union tgsi_exec_channel
*src0
,
3121 const union tgsi_exec_channel
*src1
)
3123 dst
->u
[0] = src0
->f
[0] != src1
->f
[0] ? ~0 : 0;
3124 dst
->u
[1] = src0
->f
[1] != src1
->f
[1] ? ~0 : 0;
3125 dst
->u
[2] = src0
->f
[2] != src1
->f
[2] ? ~0 : 0;
3126 dst
->u
[3] = src0
->f
[3] != src1
->f
[3] ? ~0 : 0;
3130 micro_idiv(union tgsi_exec_channel
*dst
,
3131 const union tgsi_exec_channel
*src0
,
3132 const union tgsi_exec_channel
*src1
)
3134 dst
->i
[0] = src1
->i
[0] ? src0
->i
[0] / src1
->i
[0] : 0;
3135 dst
->i
[1] = src1
->i
[1] ? src0
->i
[1] / src1
->i
[1] : 0;
3136 dst
->i
[2] = src1
->i
[2] ? src0
->i
[2] / src1
->i
[2] : 0;
3137 dst
->i
[3] = src1
->i
[3] ? src0
->i
[3] / src1
->i
[3] : 0;
3141 micro_imax(union tgsi_exec_channel
*dst
,
3142 const union tgsi_exec_channel
*src0
,
3143 const union tgsi_exec_channel
*src1
)
3145 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3146 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3147 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3148 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3152 micro_imin(union tgsi_exec_channel
*dst
,
3153 const union tgsi_exec_channel
*src0
,
3154 const union tgsi_exec_channel
*src1
)
3156 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3157 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3158 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3159 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3163 micro_isge(union tgsi_exec_channel
*dst
,
3164 const union tgsi_exec_channel
*src0
,
3165 const union tgsi_exec_channel
*src1
)
3167 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
3168 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
3169 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
3170 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
3174 micro_ishr(union tgsi_exec_channel
*dst
,
3175 const union tgsi_exec_channel
*src0
,
3176 const union tgsi_exec_channel
*src1
)
3178 unsigned masked_count
;
3179 masked_count
= src1
->i
[0] & 0x1f;
3180 dst
->i
[0] = src0
->i
[0] >> masked_count
;
3181 masked_count
= src1
->i
[1] & 0x1f;
3182 dst
->i
[1] = src0
->i
[1] >> masked_count
;
3183 masked_count
= src1
->i
[2] & 0x1f;
3184 dst
->i
[2] = src0
->i
[2] >> masked_count
;
3185 masked_count
= src1
->i
[3] & 0x1f;
3186 dst
->i
[3] = src0
->i
[3] >> masked_count
;
3190 micro_islt(union tgsi_exec_channel
*dst
,
3191 const union tgsi_exec_channel
*src0
,
3192 const union tgsi_exec_channel
*src1
)
3194 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
3195 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
3196 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
3197 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
3201 micro_f2u(union tgsi_exec_channel
*dst
,
3202 const union tgsi_exec_channel
*src
)
3204 dst
->u
[0] = (uint
)src
->f
[0];
3205 dst
->u
[1] = (uint
)src
->f
[1];
3206 dst
->u
[2] = (uint
)src
->f
[2];
3207 dst
->u
[3] = (uint
)src
->f
[3];
3211 micro_u2f(union tgsi_exec_channel
*dst
,
3212 const union tgsi_exec_channel
*src
)
3214 dst
->f
[0] = (float)src
->u
[0];
3215 dst
->f
[1] = (float)src
->u
[1];
3216 dst
->f
[2] = (float)src
->u
[2];
3217 dst
->f
[3] = (float)src
->u
[3];
3221 micro_uadd(union tgsi_exec_channel
*dst
,
3222 const union tgsi_exec_channel
*src0
,
3223 const union tgsi_exec_channel
*src1
)
3225 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
3226 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
3227 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
3228 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
3232 micro_udiv(union tgsi_exec_channel
*dst
,
3233 const union tgsi_exec_channel
*src0
,
3234 const union tgsi_exec_channel
*src1
)
3236 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] / src1
->u
[0] : ~0u;
3237 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] / src1
->u
[1] : ~0u;
3238 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] / src1
->u
[2] : ~0u;
3239 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] / src1
->u
[3] : ~0u;
3243 micro_umad(union tgsi_exec_channel
*dst
,
3244 const union tgsi_exec_channel
*src0
,
3245 const union tgsi_exec_channel
*src1
,
3246 const union tgsi_exec_channel
*src2
)
3248 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
3249 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
3250 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
3251 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
3255 micro_umax(union tgsi_exec_channel
*dst
,
3256 const union tgsi_exec_channel
*src0
,
3257 const union tgsi_exec_channel
*src1
)
3259 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3260 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3261 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3262 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3266 micro_umin(union tgsi_exec_channel
*dst
,
3267 const union tgsi_exec_channel
*src0
,
3268 const union tgsi_exec_channel
*src1
)
3270 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3271 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3272 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3273 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3277 micro_umod(union tgsi_exec_channel
*dst
,
3278 const union tgsi_exec_channel
*src0
,
3279 const union tgsi_exec_channel
*src1
)
3281 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] % src1
->u
[0] : ~0u;
3282 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] % src1
->u
[1] : ~0u;
3283 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] % src1
->u
[2] : ~0u;
3284 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] % src1
->u
[3] : ~0u;
3288 micro_umul(union tgsi_exec_channel
*dst
,
3289 const union tgsi_exec_channel
*src0
,
3290 const union tgsi_exec_channel
*src1
)
3292 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
3293 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
3294 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
3295 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
3299 micro_imul_hi(union tgsi_exec_channel
*dst
,
3300 const union tgsi_exec_channel
*src0
,
3301 const union tgsi_exec_channel
*src1
)
3303 #define I64M(x, y) ((((int64_t)x) * ((int64_t)y)) >> 32)
3304 dst
->i
[0] = I64M(src0
->i
[0], src1
->i
[0]);
3305 dst
->i
[1] = I64M(src0
->i
[1], src1
->i
[1]);
3306 dst
->i
[2] = I64M(src0
->i
[2], src1
->i
[2]);
3307 dst
->i
[3] = I64M(src0
->i
[3], src1
->i
[3]);
3312 micro_umul_hi(union tgsi_exec_channel
*dst
,
3313 const union tgsi_exec_channel
*src0
,
3314 const union tgsi_exec_channel
*src1
)
3316 #define U64M(x, y) ((((uint64_t)x) * ((uint64_t)y)) >> 32)
3317 dst
->u
[0] = U64M(src0
->u
[0], src1
->u
[0]);
3318 dst
->u
[1] = U64M(src0
->u
[1], src1
->u
[1]);
3319 dst
->u
[2] = U64M(src0
->u
[2], src1
->u
[2]);
3320 dst
->u
[3] = U64M(src0
->u
[3], src1
->u
[3]);
3325 micro_useq(union tgsi_exec_channel
*dst
,
3326 const union tgsi_exec_channel
*src0
,
3327 const union tgsi_exec_channel
*src1
)
3329 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
3330 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
3331 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
3332 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
3336 micro_usge(union tgsi_exec_channel
*dst
,
3337 const union tgsi_exec_channel
*src0
,
3338 const union tgsi_exec_channel
*src1
)
3340 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
3341 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
3342 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
3343 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
3347 micro_ushr(union tgsi_exec_channel
*dst
,
3348 const union tgsi_exec_channel
*src0
,
3349 const union tgsi_exec_channel
*src1
)
3351 unsigned masked_count
;
3352 masked_count
= src1
->u
[0] & 0x1f;
3353 dst
->u
[0] = src0
->u
[0] >> masked_count
;
3354 masked_count
= src1
->u
[1] & 0x1f;
3355 dst
->u
[1] = src0
->u
[1] >> masked_count
;
3356 masked_count
= src1
->u
[2] & 0x1f;
3357 dst
->u
[2] = src0
->u
[2] >> masked_count
;
3358 masked_count
= src1
->u
[3] & 0x1f;
3359 dst
->u
[3] = src0
->u
[3] >> masked_count
;
3363 micro_uslt(union tgsi_exec_channel
*dst
,
3364 const union tgsi_exec_channel
*src0
,
3365 const union tgsi_exec_channel
*src1
)
3367 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
3368 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
3369 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
3370 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
3374 micro_usne(union tgsi_exec_channel
*dst
,
3375 const union tgsi_exec_channel
*src0
,
3376 const union tgsi_exec_channel
*src1
)
3378 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
3379 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
3380 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
3381 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
3385 micro_uarl(union tgsi_exec_channel
*dst
,
3386 const union tgsi_exec_channel
*src
)
3388 dst
->i
[0] = src
->u
[0];
3389 dst
->i
[1] = src
->u
[1];
3390 dst
->i
[2] = src
->u
[2];
3391 dst
->i
[3] = src
->u
[3];
3395 micro_ucmp(union tgsi_exec_channel
*dst
,
3396 const union tgsi_exec_channel
*src0
,
3397 const union tgsi_exec_channel
*src1
,
3398 const union tgsi_exec_channel
*src2
)
3400 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
3401 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
3402 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
3403 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
3407 * Signed bitfield extract (i.e. sign-extend the extracted bits)
3410 micro_ibfe(union tgsi_exec_channel
*dst
,
3411 const union tgsi_exec_channel
*src0
,
3412 const union tgsi_exec_channel
*src1
,
3413 const union tgsi_exec_channel
*src2
)
3416 for (i
= 0; i
< 4; i
++) {
3417 int width
= src2
->i
[i
] & 0x1f;
3418 int offset
= src1
->i
[i
] & 0x1f;
3421 else if (width
+ offset
< 32)
3422 dst
->i
[i
] = (src0
->i
[i
] << (32 - width
- offset
)) >> (32 - width
);
3424 dst
->i
[i
] = src0
->i
[i
] >> offset
;
3429 * Unsigned bitfield extract
3432 micro_ubfe(union tgsi_exec_channel
*dst
,
3433 const union tgsi_exec_channel
*src0
,
3434 const union tgsi_exec_channel
*src1
,
3435 const union tgsi_exec_channel
*src2
)
3438 for (i
= 0; i
< 4; i
++) {
3439 int width
= src2
->u
[i
] & 0x1f;
3440 int offset
= src1
->u
[i
] & 0x1f;
3443 else if (width
+ offset
< 32)
3444 dst
->u
[i
] = (src0
->u
[i
] << (32 - width
- offset
)) >> (32 - width
);
3446 dst
->u
[i
] = src0
->u
[i
] >> offset
;
3451 * Bitfield insert: copy low bits from src1 into a region of src0.
3454 micro_bfi(union tgsi_exec_channel
*dst
,
3455 const union tgsi_exec_channel
*src0
,
3456 const union tgsi_exec_channel
*src1
,
3457 const union tgsi_exec_channel
*src2
,
3458 const union tgsi_exec_channel
*src3
)
3461 for (i
= 0; i
< 4; i
++) {
3462 int width
= src3
->u
[i
] & 0x1f;
3463 int offset
= src2
->u
[i
] & 0x1f;
3464 int bitmask
= ((1 << width
) - 1) << offset
;
3465 dst
->u
[i
] = ((src1
->u
[i
] << offset
) & bitmask
) | (src0
->u
[i
] & ~bitmask
);
3470 micro_brev(union tgsi_exec_channel
*dst
,
3471 const union tgsi_exec_channel
*src
)
3473 dst
->u
[0] = util_bitreverse(src
->u
[0]);
3474 dst
->u
[1] = util_bitreverse(src
->u
[1]);
3475 dst
->u
[2] = util_bitreverse(src
->u
[2]);
3476 dst
->u
[3] = util_bitreverse(src
->u
[3]);
3480 micro_popc(union tgsi_exec_channel
*dst
,
3481 const union tgsi_exec_channel
*src
)
3483 dst
->u
[0] = util_bitcount(src
->u
[0]);
3484 dst
->u
[1] = util_bitcount(src
->u
[1]);
3485 dst
->u
[2] = util_bitcount(src
->u
[2]);
3486 dst
->u
[3] = util_bitcount(src
->u
[3]);
3490 micro_lsb(union tgsi_exec_channel
*dst
,
3491 const union tgsi_exec_channel
*src
)
3493 dst
->i
[0] = ffs(src
->u
[0]) - 1;
3494 dst
->i
[1] = ffs(src
->u
[1]) - 1;
3495 dst
->i
[2] = ffs(src
->u
[2]) - 1;
3496 dst
->i
[3] = ffs(src
->u
[3]) - 1;
3500 micro_imsb(union tgsi_exec_channel
*dst
,
3501 const union tgsi_exec_channel
*src
)
3503 dst
->i
[0] = util_last_bit_signed(src
->i
[0]) - 1;
3504 dst
->i
[1] = util_last_bit_signed(src
->i
[1]) - 1;
3505 dst
->i
[2] = util_last_bit_signed(src
->i
[2]) - 1;
3506 dst
->i
[3] = util_last_bit_signed(src
->i
[3]) - 1;
3510 micro_umsb(union tgsi_exec_channel
*dst
,
3511 const union tgsi_exec_channel
*src
)
3513 dst
->i
[0] = util_last_bit(src
->u
[0]) - 1;
3514 dst
->i
[1] = util_last_bit(src
->u
[1]) - 1;
3515 dst
->i
[2] = util_last_bit(src
->u
[2]) - 1;
3516 dst
->i
[3] = util_last_bit(src
->u
[3]) - 1;
3521 struct tgsi_exec_machine
*mach
,
3522 const struct tgsi_full_instruction
*inst
,
3525 union tgsi_exec_channel r
[10];
3529 switch (inst
->Instruction
.Opcode
) {
3530 case TGSI_OPCODE_ARL
:
3531 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3534 case TGSI_OPCODE_MOV
:
3535 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3538 case TGSI_OPCODE_LIT
:
3539 exec_lit(mach
, inst
);
3542 case TGSI_OPCODE_RCP
:
3543 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3546 case TGSI_OPCODE_RSQ
:
3547 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3550 case TGSI_OPCODE_EXP
:
3551 exec_exp(mach
, inst
);
3554 case TGSI_OPCODE_LOG
:
3555 exec_log(mach
, inst
);
3558 case TGSI_OPCODE_MUL
:
3559 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3562 case TGSI_OPCODE_ADD
:
3563 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3566 case TGSI_OPCODE_DP3
:
3567 exec_dp3(mach
, inst
);
3570 case TGSI_OPCODE_DP4
:
3571 exec_dp4(mach
, inst
);
3574 case TGSI_OPCODE_DST
:
3575 exec_dst(mach
, inst
);
3578 case TGSI_OPCODE_MIN
:
3579 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3582 case TGSI_OPCODE_MAX
:
3583 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3586 case TGSI_OPCODE_SLT
:
3587 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3590 case TGSI_OPCODE_SGE
:
3591 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3594 case TGSI_OPCODE_MAD
:
3595 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3598 case TGSI_OPCODE_SUB
:
3599 exec_vector_binary(mach
, inst
, micro_sub
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3602 case TGSI_OPCODE_LRP
:
3603 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3606 case TGSI_OPCODE_CND
:
3607 exec_vector_trinary(mach
, inst
, micro_cnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3610 case TGSI_OPCODE_SQRT
:
3611 exec_scalar_unary(mach
, inst
, micro_sqrt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3614 case TGSI_OPCODE_DP2A
:
3615 exec_dp2a(mach
, inst
);
3618 case TGSI_OPCODE_FRC
:
3619 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3622 case TGSI_OPCODE_CLAMP
:
3623 exec_vector_trinary(mach
, inst
, micro_clamp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3626 case TGSI_OPCODE_FLR
:
3627 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3630 case TGSI_OPCODE_ROUND
:
3631 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3634 case TGSI_OPCODE_EX2
:
3635 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3638 case TGSI_OPCODE_LG2
:
3639 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3642 case TGSI_OPCODE_POW
:
3643 exec_scalar_binary(mach
, inst
, micro_pow
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3646 case TGSI_OPCODE_XPD
:
3647 exec_xpd(mach
, inst
);
3650 case TGSI_OPCODE_ABS
:
3651 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3654 case TGSI_OPCODE_DPH
:
3655 exec_dph(mach
, inst
);
3658 case TGSI_OPCODE_COS
:
3659 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3662 case TGSI_OPCODE_DDX
:
3663 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3666 case TGSI_OPCODE_DDY
:
3667 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3670 case TGSI_OPCODE_KILL
:
3671 exec_kill (mach
, inst
);
3674 case TGSI_OPCODE_KILL_IF
:
3675 exec_kill_if (mach
, inst
);
3678 case TGSI_OPCODE_PK2H
:
3682 case TGSI_OPCODE_PK2US
:
3686 case TGSI_OPCODE_PK4B
:
3690 case TGSI_OPCODE_PK4UB
:
3694 case TGSI_OPCODE_SEQ
:
3695 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3698 case TGSI_OPCODE_SGT
:
3699 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3702 case TGSI_OPCODE_SIN
:
3703 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3706 case TGSI_OPCODE_SLE
:
3707 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3710 case TGSI_OPCODE_SNE
:
3711 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3714 case TGSI_OPCODE_TEX
:
3715 /* simple texture lookup */
3716 /* src[0] = texcoord */
3717 /* src[1] = sampler unit */
3718 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 1);
3721 case TGSI_OPCODE_TXB
:
3722 /* Texture lookup with lod bias */
3723 /* src[0] = texcoord (src[0].w = LOD bias) */
3724 /* src[1] = sampler unit */
3725 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 1);
3728 case TGSI_OPCODE_TXD
:
3729 /* Texture lookup with explict partial derivatives */
3730 /* src[0] = texcoord */
3731 /* src[1] = d[strq]/dx */
3732 /* src[2] = d[strq]/dy */
3733 /* src[3] = sampler unit */
3734 exec_txd(mach
, inst
);
3737 case TGSI_OPCODE_TXL
:
3738 /* Texture lookup with explit LOD */
3739 /* src[0] = texcoord (src[0].w = LOD) */
3740 /* src[1] = sampler unit */
3741 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 1);
3744 case TGSI_OPCODE_TXP
:
3745 /* Texture lookup with projection */
3746 /* src[0] = texcoord (src[0].w = projection) */
3747 /* src[1] = sampler unit */
3748 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
, 1);
3751 case TGSI_OPCODE_UP2H
:
3755 case TGSI_OPCODE_UP2US
:
3759 case TGSI_OPCODE_UP4B
:
3763 case TGSI_OPCODE_UP4UB
:
3767 case TGSI_OPCODE_ARR
:
3768 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3771 case TGSI_OPCODE_CAL
:
3772 /* skip the call if no execution channels are enabled */
3773 if (mach
->ExecMask
) {
3776 /* First, record the depths of the execution stacks.
3777 * This is important for deeply nested/looped return statements.
3778 * We have to unwind the stacks by the correct amount. For a
3779 * real code generator, we could determine the number of entries
3780 * to pop off each stack with simple static analysis and avoid
3781 * implementing this data structure at run time.
3783 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
3784 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
3785 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
3786 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
3787 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
3788 /* note that PC was already incremented above */
3789 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
3791 mach
->CallStackTop
++;
3793 /* Second, push the Cond, Loop, Cont, Func stacks */
3794 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3795 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3796 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3797 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3798 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3799 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
3801 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3802 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3803 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3804 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3805 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3806 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
3808 /* Finally, jump to the subroutine */
3809 *pc
= inst
->Label
.Label
;
3813 case TGSI_OPCODE_RET
:
3814 mach
->FuncMask
&= ~mach
->ExecMask
;
3815 UPDATE_EXEC_MASK(mach
);
3817 if (mach
->FuncMask
== 0x0) {
3818 /* really return now (otherwise, keep executing */
3820 if (mach
->CallStackTop
== 0) {
3821 /* returning from main() */
3822 mach
->CondStackTop
= 0;
3823 mach
->LoopStackTop
= 0;
3828 assert(mach
->CallStackTop
> 0);
3829 mach
->CallStackTop
--;
3831 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3832 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3834 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3835 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3837 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3838 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3840 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3841 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3843 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3844 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3846 assert(mach
->FuncStackTop
> 0);
3847 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3849 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3851 UPDATE_EXEC_MASK(mach
);
3855 case TGSI_OPCODE_SSG
:
3856 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3859 case TGSI_OPCODE_CMP
:
3860 exec_vector_trinary(mach
, inst
, micro_cmp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3863 case TGSI_OPCODE_SCS
:
3864 exec_scs(mach
, inst
);
3867 case TGSI_OPCODE_DIV
:
3868 exec_vector_binary(mach
, inst
, micro_div
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3871 case TGSI_OPCODE_DP2
:
3872 exec_dp2(mach
, inst
);
3875 case TGSI_OPCODE_IF
:
3877 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3878 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3879 FETCH( &r
[0], 0, TGSI_CHAN_X
);
3880 /* update CondMask */
3882 mach
->CondMask
&= ~0x1;
3885 mach
->CondMask
&= ~0x2;
3888 mach
->CondMask
&= ~0x4;
3891 mach
->CondMask
&= ~0x8;
3893 UPDATE_EXEC_MASK(mach
);
3894 /* Todo: If CondMask==0, jump to ELSE */
3897 case TGSI_OPCODE_UIF
:
3899 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3900 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3901 IFETCH( &r
[0], 0, TGSI_CHAN_X
);
3902 /* update CondMask */
3904 mach
->CondMask
&= ~0x1;
3907 mach
->CondMask
&= ~0x2;
3910 mach
->CondMask
&= ~0x4;
3913 mach
->CondMask
&= ~0x8;
3915 UPDATE_EXEC_MASK(mach
);
3916 /* Todo: If CondMask==0, jump to ELSE */
3919 case TGSI_OPCODE_ELSE
:
3920 /* invert CondMask wrt previous mask */
3923 assert(mach
->CondStackTop
> 0);
3924 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3925 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3926 UPDATE_EXEC_MASK(mach
);
3927 /* Todo: If CondMask==0, jump to ENDIF */
3931 case TGSI_OPCODE_ENDIF
:
3933 assert(mach
->CondStackTop
> 0);
3934 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3935 UPDATE_EXEC_MASK(mach
);
3938 case TGSI_OPCODE_END
:
3939 /* make sure we end primitives which haven't
3940 * been explicitly emitted */
3941 conditional_emit_primitive(mach
);
3942 /* halt execution */
3946 case TGSI_OPCODE_PUSHA
:
3950 case TGSI_OPCODE_POPA
:
3954 case TGSI_OPCODE_CEIL
:
3955 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3958 case TGSI_OPCODE_I2F
:
3959 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
3962 case TGSI_OPCODE_NOT
:
3963 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3966 case TGSI_OPCODE_TRUNC
:
3967 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3970 case TGSI_OPCODE_SHL
:
3971 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3974 case TGSI_OPCODE_AND
:
3975 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3978 case TGSI_OPCODE_OR
:
3979 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3982 case TGSI_OPCODE_MOD
:
3983 exec_vector_binary(mach
, inst
, micro_mod
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3986 case TGSI_OPCODE_XOR
:
3987 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3990 case TGSI_OPCODE_SAD
:
3994 case TGSI_OPCODE_TXF
:
3995 exec_txf(mach
, inst
);
3998 case TGSI_OPCODE_TXQ
:
3999 exec_txq(mach
, inst
);
4002 case TGSI_OPCODE_EMIT
:
4006 case TGSI_OPCODE_ENDPRIM
:
4007 emit_primitive(mach
);
4010 case TGSI_OPCODE_BGNLOOP
:
4011 /* push LoopMask and ContMasks */
4012 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4013 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4014 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4015 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
4017 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
4018 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
4019 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
4020 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
4021 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
4024 case TGSI_OPCODE_ENDLOOP
:
4025 /* Restore ContMask, but don't pop */
4026 assert(mach
->ContStackTop
> 0);
4027 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
4028 UPDATE_EXEC_MASK(mach
);
4029 if (mach
->ExecMask
) {
4030 /* repeat loop: jump to instruction just past BGNLOOP */
4031 assert(mach
->LoopLabelStackTop
> 0);
4032 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
4035 /* exit loop: pop LoopMask */
4036 assert(mach
->LoopStackTop
> 0);
4037 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
4039 assert(mach
->ContStackTop
> 0);
4040 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
4041 assert(mach
->LoopLabelStackTop
> 0);
4042 --mach
->LoopLabelStackTop
;
4044 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
4046 UPDATE_EXEC_MASK(mach
);
4049 case TGSI_OPCODE_BRK
:
4053 case TGSI_OPCODE_CONT
:
4054 /* turn off cont channels for each enabled exec channel */
4055 mach
->ContMask
&= ~mach
->ExecMask
;
4056 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4057 UPDATE_EXEC_MASK(mach
);
4060 case TGSI_OPCODE_BGNSUB
:
4064 case TGSI_OPCODE_ENDSUB
:
4066 * XXX: This really should be a no-op. We should never reach this opcode.
4069 assert(mach
->CallStackTop
> 0);
4070 mach
->CallStackTop
--;
4072 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
4073 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
4075 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
4076 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
4078 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
4079 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
4081 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
4082 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
4084 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
4085 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
4087 assert(mach
->FuncStackTop
> 0);
4088 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
4090 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
4092 UPDATE_EXEC_MASK(mach
);
4095 case TGSI_OPCODE_NOP
:
4098 case TGSI_OPCODE_BREAKC
:
4099 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
4100 /* update CondMask */
4101 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
4102 mach
->LoopMask
&= ~0x1;
4104 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
4105 mach
->LoopMask
&= ~0x2;
4107 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
4108 mach
->LoopMask
&= ~0x4;
4110 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
4111 mach
->LoopMask
&= ~0x8;
4113 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4114 UPDATE_EXEC_MASK(mach
);
4117 case TGSI_OPCODE_F2I
:
4118 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
4121 case TGSI_OPCODE_FSEQ
:
4122 exec_vector_binary(mach
, inst
, micro_fseq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4125 case TGSI_OPCODE_FSGE
:
4126 exec_vector_binary(mach
, inst
, micro_fsge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4129 case TGSI_OPCODE_FSLT
:
4130 exec_vector_binary(mach
, inst
, micro_fslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4133 case TGSI_OPCODE_FSNE
:
4134 exec_vector_binary(mach
, inst
, micro_fsne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4137 case TGSI_OPCODE_IDIV
:
4138 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4141 case TGSI_OPCODE_IMAX
:
4142 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4145 case TGSI_OPCODE_IMIN
:
4146 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4149 case TGSI_OPCODE_INEG
:
4150 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4153 case TGSI_OPCODE_ISGE
:
4154 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4157 case TGSI_OPCODE_ISHR
:
4158 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4161 case TGSI_OPCODE_ISLT
:
4162 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4165 case TGSI_OPCODE_F2U
:
4166 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4169 case TGSI_OPCODE_U2F
:
4170 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
4173 case TGSI_OPCODE_UADD
:
4174 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4177 case TGSI_OPCODE_UDIV
:
4178 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4181 case TGSI_OPCODE_UMAD
:
4182 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4185 case TGSI_OPCODE_UMAX
:
4186 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4189 case TGSI_OPCODE_UMIN
:
4190 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4193 case TGSI_OPCODE_UMOD
:
4194 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4197 case TGSI_OPCODE_UMUL
:
4198 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4201 case TGSI_OPCODE_IMUL_HI
:
4202 exec_vector_binary(mach
, inst
, micro_imul_hi
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4205 case TGSI_OPCODE_UMUL_HI
:
4206 exec_vector_binary(mach
, inst
, micro_umul_hi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4209 case TGSI_OPCODE_USEQ
:
4210 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4213 case TGSI_OPCODE_USGE
:
4214 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4217 case TGSI_OPCODE_USHR
:
4218 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4221 case TGSI_OPCODE_USLT
:
4222 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4225 case TGSI_OPCODE_USNE
:
4226 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4229 case TGSI_OPCODE_SWITCH
:
4230 exec_switch(mach
, inst
);
4233 case TGSI_OPCODE_CASE
:
4234 exec_case(mach
, inst
);
4237 case TGSI_OPCODE_DEFAULT
:
4241 case TGSI_OPCODE_ENDSWITCH
:
4242 exec_endswitch(mach
);
4245 case TGSI_OPCODE_SAMPLE_I
:
4246 exec_txf(mach
, inst
);
4249 case TGSI_OPCODE_SAMPLE_I_MS
:
4253 case TGSI_OPCODE_SAMPLE
:
4254 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, FALSE
);
4257 case TGSI_OPCODE_SAMPLE_B
:
4258 exec_sample(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, FALSE
);
4261 case TGSI_OPCODE_SAMPLE_C
:
4262 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, TRUE
);
4265 case TGSI_OPCODE_SAMPLE_C_LZ
:
4266 exec_sample(mach
, inst
, TEX_MODIFIER_LEVEL_ZERO
, TRUE
);
4269 case TGSI_OPCODE_SAMPLE_D
:
4270 exec_sample_d(mach
, inst
);
4273 case TGSI_OPCODE_SAMPLE_L
:
4274 exec_sample(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, FALSE
);
4277 case TGSI_OPCODE_GATHER4
:
4281 case TGSI_OPCODE_SVIEWINFO
:
4282 exec_txq(mach
, inst
);
4285 case TGSI_OPCODE_SAMPLE_POS
:
4289 case TGSI_OPCODE_SAMPLE_INFO
:
4293 case TGSI_OPCODE_UARL
:
4294 exec_vector_unary(mach
, inst
, micro_uarl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4297 case TGSI_OPCODE_UCMP
:
4298 exec_vector_trinary(mach
, inst
, micro_ucmp
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4301 case TGSI_OPCODE_IABS
:
4302 exec_vector_unary(mach
, inst
, micro_iabs
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4305 case TGSI_OPCODE_ISSG
:
4306 exec_vector_unary(mach
, inst
, micro_isgn
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4309 case TGSI_OPCODE_TEX2
:
4310 /* simple texture lookup */
4311 /* src[0] = texcoord */
4312 /* src[1] = compare */
4313 /* src[2] = sampler unit */
4314 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 2);
4316 case TGSI_OPCODE_TXB2
:
4317 /* simple texture lookup */
4318 /* src[0] = texcoord */
4320 /* src[2] = sampler unit */
4321 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 2);
4323 case TGSI_OPCODE_TXL2
:
4324 /* simple texture lookup */
4325 /* src[0] = texcoord */
4327 /* src[2] = sampler unit */
4328 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 2);
4331 case TGSI_OPCODE_IBFE
:
4332 exec_vector_trinary(mach
, inst
, micro_ibfe
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4334 case TGSI_OPCODE_UBFE
:
4335 exec_vector_trinary(mach
, inst
, micro_ubfe
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4337 case TGSI_OPCODE_BFI
:
4338 exec_vector_quaternary(mach
, inst
, micro_bfi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4340 case TGSI_OPCODE_BREV
:
4341 exec_vector_unary(mach
, inst
, micro_brev
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4343 case TGSI_OPCODE_POPC
:
4344 exec_vector_unary(mach
, inst
, micro_popc
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4346 case TGSI_OPCODE_LSB
:
4347 exec_vector_unary(mach
, inst
, micro_lsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4349 case TGSI_OPCODE_IMSB
:
4350 exec_vector_unary(mach
, inst
, micro_imsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4352 case TGSI_OPCODE_UMSB
:
4353 exec_vector_unary(mach
, inst
, micro_umsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4362 * Run TGSI interpreter.
4363 * \return bitmask of "alive" quad components
4366 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
4370 uint default_mask
= 0xf;
4372 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
4373 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
4375 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
4376 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
4377 mach
->Primitives
[0] = 0;
4378 /* GS runs on a single primitive for now */
4382 mach
->CondMask
= default_mask
;
4383 mach
->LoopMask
= default_mask
;
4384 mach
->ContMask
= default_mask
;
4385 mach
->FuncMask
= default_mask
;
4386 mach
->ExecMask
= default_mask
;
4388 mach
->Switch
.mask
= default_mask
;
4390 assert(mach
->CondStackTop
== 0);
4391 assert(mach
->LoopStackTop
== 0);
4392 assert(mach
->ContStackTop
== 0);
4393 assert(mach
->SwitchStackTop
== 0);
4394 assert(mach
->BreakStackTop
== 0);
4395 assert(mach
->CallStackTop
== 0);
4398 /* execute declarations (interpolants) */
4399 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
4400 exec_declaration( mach
, mach
->Declarations
+i
);
4405 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
4406 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
4409 memset(mach
->Temps
, 0, sizeof(temps
));
4410 memset(mach
->Outputs
, 0, sizeof(outputs
));
4411 memset(temps
, 0, sizeof(temps
));
4412 memset(outputs
, 0, sizeof(outputs
));
4415 /* execute instructions, until pc is set to -1 */
4421 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
4424 assert(pc
< (int) mach
->NumInstructions
);
4425 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
4428 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
4429 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
4432 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
4433 debug_printf("TEMP[%2u] = ", i
);
4434 for (j
= 0; j
< 4; j
++) {
4438 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4439 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
4440 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
4441 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
4442 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
4446 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
4447 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
4450 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
4451 debug_printf("OUT[%2u] = ", i
);
4452 for (j
= 0; j
< 4; j
++) {
4456 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4457 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
4458 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
4459 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
4460 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
4469 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
4470 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
4472 * Scale back depth component.
4474 for (i
= 0; i
< 4; i
++)
4475 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
4479 /* Strictly speaking, these assertions aren't really needed but they
4480 * can potentially catch some bugs in the control flow code.
4482 assert(mach
->CondStackTop
== 0);
4483 assert(mach
->LoopStackTop
== 0);
4484 assert(mach
->ContStackTop
== 0);
4485 assert(mach
->SwitchStackTop
== 0);
4486 assert(mach
->BreakStackTop
== 0);
4487 assert(mach
->CallStackTop
== 0);
4489 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];