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_sfl(union tgsi_exec_channel
*dst
)
464 micro_str(union tgsi_exec_channel
*dst
)
473 micro_trunc(union tgsi_exec_channel
*dst
,
474 const union tgsi_exec_channel
*src
)
476 dst
->f
[0] = (float)(int)src
->f
[0];
477 dst
->f
[1] = (float)(int)src
->f
[1];
478 dst
->f
[2] = (float)(int)src
->f
[2];
479 dst
->f
[3] = (float)(int)src
->f
[3];
483 enum tgsi_exec_datatype
{
484 TGSI_EXEC_DATA_FLOAT
,
490 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
492 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
493 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
494 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
495 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
496 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
497 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
500 /** The execution mask depends on the conditional mask and the loop mask */
501 #define UPDATE_EXEC_MASK(MACH) \
502 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
505 static const union tgsi_exec_channel ZeroVec
=
506 { { 0.0, 0.0, 0.0, 0.0 } };
508 static const union tgsi_exec_channel OneVec
= {
509 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
512 static const union tgsi_exec_channel P128Vec
= {
513 {128.0f
, 128.0f
, 128.0f
, 128.0f
}
516 static const union tgsi_exec_channel M128Vec
= {
517 {-128.0f
, -128.0f
, -128.0f
, -128.0f
}
522 * Assert that none of the float values in 'chan' are infinite or NaN.
523 * NaN and Inf may occur normally during program execution and should
524 * not lead to crashes, etc. But when debugging, it's helpful to catch
528 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
530 assert(!util_is_inf_or_nan((chan
)->f
[0]));
531 assert(!util_is_inf_or_nan((chan
)->f
[1]));
532 assert(!util_is_inf_or_nan((chan
)->f
[2]));
533 assert(!util_is_inf_or_nan((chan
)->f
[3]));
539 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
541 debug_printf("%s = {%f, %f, %f, %f}\n",
542 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
549 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
551 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
553 debug_printf("Temp[%u] =\n", index
);
554 for (i
= 0; i
< 4; i
++) {
555 debug_printf(" %c: { %f, %f, %f, %f }\n",
567 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine
*mach
,
570 const unsigned *buf_sizes
)
574 for (i
= 0; i
< num_bufs
; i
++) {
575 mach
->Consts
[i
] = bufs
[i
];
576 mach
->ConstsSize
[i
] = buf_sizes
[i
];
582 * Check if there's a potential src/dst register data dependency when
583 * using SOA execution.
586 * This would expand into:
591 * The second instruction will have the wrong value for t0 if executed as-is.
594 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
598 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
599 if (writemask
== TGSI_WRITEMASK_X
||
600 writemask
== TGSI_WRITEMASK_Y
||
601 writemask
== TGSI_WRITEMASK_Z
||
602 writemask
== TGSI_WRITEMASK_W
||
603 writemask
== TGSI_WRITEMASK_NONE
) {
604 /* no chance of data dependency */
608 /* loop over src regs */
609 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
610 if ((inst
->Src
[i
].Register
.File
==
611 inst
->Dst
[0].Register
.File
) &&
612 ((inst
->Src
[i
].Register
.Index
==
613 inst
->Dst
[0].Register
.Index
) ||
614 inst
->Src
[i
].Register
.Indirect
||
615 inst
->Dst
[0].Register
.Indirect
)) {
616 /* loop over dest channels */
617 uint channelsWritten
= 0x0;
618 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
619 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
620 /* check if we're reading a channel that's been written */
621 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
622 if (channelsWritten
& (1 << swizzle
)) {
626 channelsWritten
|= (1 << chan
);
636 * Initialize machine state by expanding tokens to full instructions,
637 * allocating temporary storage, setting up constants, etc.
638 * After this, we can call tgsi_exec_machine_run() many times.
641 tgsi_exec_machine_bind_shader(
642 struct tgsi_exec_machine
*mach
,
643 const struct tgsi_token
*tokens
,
644 struct tgsi_sampler
*sampler
)
647 struct tgsi_parse_context parse
;
648 struct tgsi_full_instruction
*instructions
;
649 struct tgsi_full_declaration
*declarations
;
650 uint maxInstructions
= 10, numInstructions
= 0;
651 uint maxDeclarations
= 10, numDeclarations
= 0;
654 tgsi_dump(tokens
, 0);
660 mach
->Tokens
= tokens
;
661 mach
->Sampler
= sampler
;
664 /* unbind and free all */
665 FREE(mach
->Declarations
);
666 mach
->Declarations
= NULL
;
667 mach
->NumDeclarations
= 0;
669 FREE(mach
->Instructions
);
670 mach
->Instructions
= NULL
;
671 mach
->NumInstructions
= 0;
676 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
677 if (k
!= TGSI_PARSE_OK
) {
678 debug_printf( "Problem parsing!\n" );
682 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
684 mach
->NumOutputs
= 0;
686 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
&&
687 !mach
->UsedGeometryShader
) {
688 struct tgsi_exec_vector
*inputs
;
689 struct tgsi_exec_vector
*outputs
;
691 inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
692 TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_SHADER_INPUTS
,
698 outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
699 TGSI_MAX_TOTAL_VERTICES
, 16);
706 align_free(mach
->Inputs
);
707 align_free(mach
->Outputs
);
709 mach
->Inputs
= inputs
;
710 mach
->Outputs
= outputs
;
711 mach
->UsedGeometryShader
= TRUE
;
714 declarations
= (struct tgsi_full_declaration
*)
715 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
721 instructions
= (struct tgsi_full_instruction
*)
722 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
725 FREE( declarations
);
729 while( !tgsi_parse_end_of_tokens( &parse
) ) {
732 tgsi_parse_token( &parse
);
733 switch( parse
.FullToken
.Token
.Type
) {
734 case TGSI_TOKEN_TYPE_DECLARATION
:
735 /* save expanded declaration */
736 if (numDeclarations
== maxDeclarations
) {
737 declarations
= REALLOC(declarations
,
739 * sizeof(struct tgsi_full_declaration
),
740 (maxDeclarations
+ 10)
741 * sizeof(struct tgsi_full_declaration
));
742 maxDeclarations
+= 10;
744 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
746 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
747 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
752 memcpy(declarations
+ numDeclarations
,
753 &parse
.FullToken
.FullDeclaration
,
754 sizeof(declarations
[0]));
758 case TGSI_TOKEN_TYPE_IMMEDIATE
:
760 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
762 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
764 for( i
= 0; i
< size
; i
++ ) {
765 mach
->Imms
[mach
->ImmLimit
][i
] =
766 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
772 case TGSI_TOKEN_TYPE_INSTRUCTION
:
774 /* save expanded instruction */
775 if (numInstructions
== maxInstructions
) {
776 instructions
= REALLOC(instructions
,
778 * sizeof(struct tgsi_full_instruction
),
779 (maxInstructions
+ 10)
780 * sizeof(struct tgsi_full_instruction
));
781 maxInstructions
+= 10;
784 memcpy(instructions
+ numInstructions
,
785 &parse
.FullToken
.FullInstruction
,
786 sizeof(instructions
[0]));
791 case TGSI_TOKEN_TYPE_PROPERTY
:
792 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
793 if (parse
.FullToken
.FullProperty
.Property
.PropertyName
== TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
) {
794 mach
->MaxOutputVertices
= parse
.FullToken
.FullProperty
.u
[0].Data
;
803 tgsi_parse_free (&parse
);
805 FREE(mach
->Declarations
);
806 mach
->Declarations
= declarations
;
807 mach
->NumDeclarations
= numDeclarations
;
809 FREE(mach
->Instructions
);
810 mach
->Instructions
= instructions
;
811 mach
->NumInstructions
= numInstructions
;
815 struct tgsi_exec_machine
*
816 tgsi_exec_machine_create( void )
818 struct tgsi_exec_machine
*mach
;
821 mach
= align_malloc( sizeof *mach
, 16 );
825 memset(mach
, 0, sizeof(*mach
));
827 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
828 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
829 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
831 mach
->Inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_INPUTS
, 16);
832 mach
->Outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_SHADER_OUTPUTS
, 16);
833 if (!mach
->Inputs
|| !mach
->Outputs
)
836 /* Setup constants needed by the SSE2 executor. */
837 for( i
= 0; i
< 4; i
++ ) {
838 mach
->Temps
[TGSI_EXEC_TEMP_00000000_I
].xyzw
[TGSI_EXEC_TEMP_00000000_C
].u
[i
] = 0x00000000;
839 mach
->Temps
[TGSI_EXEC_TEMP_7FFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_7FFFFFFF_C
].u
[i
] = 0x7FFFFFFF;
840 mach
->Temps
[TGSI_EXEC_TEMP_80000000_I
].xyzw
[TGSI_EXEC_TEMP_80000000_C
].u
[i
] = 0x80000000;
841 mach
->Temps
[TGSI_EXEC_TEMP_FFFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_FFFFFFFF_C
].u
[i
] = 0xFFFFFFFF; /* not used */
842 mach
->Temps
[TGSI_EXEC_TEMP_ONE_I
].xyzw
[TGSI_EXEC_TEMP_ONE_C
].f
[i
] = 1.0f
;
843 mach
->Temps
[TGSI_EXEC_TEMP_TWO_I
].xyzw
[TGSI_EXEC_TEMP_TWO_C
].f
[i
] = 2.0f
; /* not used */
844 mach
->Temps
[TGSI_EXEC_TEMP_128_I
].xyzw
[TGSI_EXEC_TEMP_128_C
].f
[i
] = 128.0f
;
845 mach
->Temps
[TGSI_EXEC_TEMP_MINUS_128_I
].xyzw
[TGSI_EXEC_TEMP_MINUS_128_C
].f
[i
] = -128.0f
;
846 mach
->Temps
[TGSI_EXEC_TEMP_THREE_I
].xyzw
[TGSI_EXEC_TEMP_THREE_C
].f
[i
] = 3.0f
;
847 mach
->Temps
[TGSI_EXEC_TEMP_HALF_I
].xyzw
[TGSI_EXEC_TEMP_HALF_C
].f
[i
] = 0.5f
;
851 /* silence warnings */
860 align_free(mach
->Inputs
);
861 align_free(mach
->Outputs
);
869 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
872 FREE(mach
->Instructions
);
873 FREE(mach
->Declarations
);
875 align_free(mach
->Inputs
);
876 align_free(mach
->Outputs
);
883 micro_add(union tgsi_exec_channel
*dst
,
884 const union tgsi_exec_channel
*src0
,
885 const union tgsi_exec_channel
*src1
)
887 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
888 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
889 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
890 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
895 union tgsi_exec_channel
*dst
,
896 const union tgsi_exec_channel
*src0
,
897 const union tgsi_exec_channel
*src1
)
899 if (src1
->f
[0] != 0) {
900 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
902 if (src1
->f
[1] != 0) {
903 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
905 if (src1
->f
[2] != 0) {
906 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
908 if (src1
->f
[3] != 0) {
909 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
915 union tgsi_exec_channel
*dst
,
916 const union tgsi_exec_channel
*src0
,
917 const union tgsi_exec_channel
*src1
,
918 const union tgsi_exec_channel
*src2
,
919 const union tgsi_exec_channel
*src3
)
921 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
922 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
923 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
924 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
928 micro_max(union tgsi_exec_channel
*dst
,
929 const union tgsi_exec_channel
*src0
,
930 const union tgsi_exec_channel
*src1
)
932 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
933 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
934 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
935 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
939 micro_min(union tgsi_exec_channel
*dst
,
940 const union tgsi_exec_channel
*src0
,
941 const union tgsi_exec_channel
*src1
)
943 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
944 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
945 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
946 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
950 micro_mul(union tgsi_exec_channel
*dst
,
951 const union tgsi_exec_channel
*src0
,
952 const union tgsi_exec_channel
*src1
)
954 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
955 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
956 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
957 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
962 union tgsi_exec_channel
*dst
,
963 const union tgsi_exec_channel
*src
)
965 dst
->f
[0] = -src
->f
[0];
966 dst
->f
[1] = -src
->f
[1];
967 dst
->f
[2] = -src
->f
[2];
968 dst
->f
[3] = -src
->f
[3];
973 union tgsi_exec_channel
*dst
,
974 const union tgsi_exec_channel
*src0
,
975 const union tgsi_exec_channel
*src1
)
978 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
979 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
980 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
981 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
983 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
984 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
985 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
986 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
991 micro_sub(union tgsi_exec_channel
*dst
,
992 const union tgsi_exec_channel
*src0
,
993 const union tgsi_exec_channel
*src1
)
995 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
996 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
997 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
998 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1002 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
1003 const uint chan_index
,
1006 const union tgsi_exec_channel
*index
,
1007 const union tgsi_exec_channel
*index2D
,
1008 union tgsi_exec_channel
*chan
)
1012 assert(swizzle
< 4);
1015 case TGSI_FILE_CONSTANT
:
1016 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1017 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
1018 assert(mach
->Consts
[index2D
->i
[i
]]);
1020 if (index
->i
[i
] < 0) {
1023 /* NOTE: copying the const value as a uint instead of float */
1024 const uint constbuf
= index2D
->i
[i
];
1025 const uint
*buf
= (const uint
*)mach
->Consts
[constbuf
];
1026 const int pos
= index
->i
[i
] * 4 + swizzle
;
1027 /* const buffer bounds check */
1028 if (pos
< 0 || pos
>= (int) mach
->ConstsSize
[constbuf
]) {
1030 /* Debug: print warning */
1031 static int count
= 0;
1033 debug_printf("TGSI Exec: const buffer index %d"
1034 " out of bounds\n", pos
);
1039 chan
->u
[i
] = buf
[pos
];
1044 case TGSI_FILE_INPUT
:
1045 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1047 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1048 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1049 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1050 index2D->i[i], index->i[i]);
1052 int pos
= index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
];
1054 assert(pos
< TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
);
1055 chan
->u
[i
] = mach
->Inputs
[pos
].xyzw
[swizzle
].u
[i
];
1059 case TGSI_FILE_SYSTEM_VALUE
:
1060 /* XXX no swizzling at this point. Will be needed if we put
1061 * gl_FragCoord, for example, in a sys value register.
1063 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1064 chan
->u
[i
] = mach
->SystemValue
[index
->i
[i
]].u
[i
];
1068 case TGSI_FILE_TEMPORARY
:
1069 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1070 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1071 assert(index2D
->i
[i
] == 0);
1073 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1077 case TGSI_FILE_IMMEDIATE
:
1078 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1079 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1080 assert(index2D
->i
[i
] == 0);
1082 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1086 case TGSI_FILE_ADDRESS
:
1087 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1088 assert(index
->i
[i
] >= 0);
1089 assert(index2D
->i
[i
] == 0);
1091 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1095 case TGSI_FILE_PREDICATE
:
1096 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1097 assert(index
->i
[i
] >= 0 && index
->i
[i
] < TGSI_EXEC_NUM_PREDS
);
1098 assert(index2D
->i
[i
] == 0);
1100 chan
->u
[i
] = mach
->Predicates
[0].xyzw
[swizzle
].u
[i
];
1104 case TGSI_FILE_OUTPUT
:
1105 /* vertex/fragment output vars can be read too */
1106 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1107 assert(index
->i
[i
] >= 0);
1108 assert(index2D
->i
[i
] == 0);
1110 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1116 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1123 fetch_source(const struct tgsi_exec_machine
*mach
,
1124 union tgsi_exec_channel
*chan
,
1125 const struct tgsi_full_src_register
*reg
,
1126 const uint chan_index
,
1127 enum tgsi_exec_datatype src_datatype
)
1129 union tgsi_exec_channel index
;
1130 union tgsi_exec_channel index2D
;
1133 /* We start with a direct index into a register file.
1137 * file = Register.File
1138 * [1] = Register.Index
1143 index
.i
[3] = reg
->Register
.Index
;
1145 /* There is an extra source register that indirectly subscripts
1146 * a register file. The direct index now becomes an offset
1147 * that is being added to the indirect register.
1151 * ind = Indirect.File
1152 * [2] = Indirect.Index
1153 * .x = Indirect.SwizzleX
1155 if (reg
->Register
.Indirect
) {
1156 union tgsi_exec_channel index2
;
1157 union tgsi_exec_channel indir_index
;
1158 const uint execmask
= mach
->ExecMask
;
1161 /* which address register (always zero now) */
1165 index2
.i
[3] = reg
->Indirect
.Index
;
1166 /* get current value of address register[swizzle] */
1167 swizzle
= reg
->Indirect
.Swizzle
;
1168 fetch_src_file_channel(mach
,
1176 /* add value of address register to the offset */
1177 index
.i
[0] += indir_index
.i
[0];
1178 index
.i
[1] += indir_index
.i
[1];
1179 index
.i
[2] += indir_index
.i
[2];
1180 index
.i
[3] += indir_index
.i
[3];
1182 /* for disabled execution channels, zero-out the index to
1183 * avoid using a potential garbage value.
1185 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1186 if ((execmask
& (1 << i
)) == 0)
1191 /* There is an extra source register that is a second
1192 * subscript to a register file. Effectively it means that
1193 * the register file is actually a 2D array of registers.
1197 * [3] = Dimension.Index
1199 if (reg
->Register
.Dimension
) {
1203 index2D
.i
[3] = reg
->Dimension
.Index
;
1205 /* Again, the second subscript index can be addressed indirectly
1206 * identically to the first one.
1207 * Nothing stops us from indirectly addressing the indirect register,
1208 * but there is no need for that, so we won't exercise it.
1210 * file[ind[4].y+3][1],
1212 * ind = DimIndirect.File
1213 * [4] = DimIndirect.Index
1214 * .y = DimIndirect.SwizzleX
1216 if (reg
->Dimension
.Indirect
) {
1217 union tgsi_exec_channel index2
;
1218 union tgsi_exec_channel indir_index
;
1219 const uint execmask
= mach
->ExecMask
;
1225 index2
.i
[3] = reg
->DimIndirect
.Index
;
1227 swizzle
= reg
->DimIndirect
.Swizzle
;
1228 fetch_src_file_channel(mach
,
1230 reg
->DimIndirect
.File
,
1236 index2D
.i
[0] += indir_index
.i
[0];
1237 index2D
.i
[1] += indir_index
.i
[1];
1238 index2D
.i
[2] += indir_index
.i
[2];
1239 index2D
.i
[3] += indir_index
.i
[3];
1241 /* for disabled execution channels, zero-out the index to
1242 * avoid using a potential garbage value.
1244 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1245 if ((execmask
& (1 << i
)) == 0) {
1251 /* If by any chance there was a need for a 3D array of register
1252 * files, we would have to check whether Dimension is followed
1253 * by a dimension register and continue the saga.
1262 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1263 fetch_src_file_channel(mach
,
1271 if (reg
->Register
.Absolute
) {
1272 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1273 micro_abs(chan
, chan
);
1275 micro_iabs(chan
, chan
);
1279 if (reg
->Register
.Negate
) {
1280 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1281 micro_neg(chan
, chan
);
1283 micro_ineg(chan
, chan
);
1289 store_dest(struct tgsi_exec_machine
*mach
,
1290 const union tgsi_exec_channel
*chan
,
1291 const struct tgsi_full_dst_register
*reg
,
1292 const struct tgsi_full_instruction
*inst
,
1294 enum tgsi_exec_datatype dst_datatype
)
1297 union tgsi_exec_channel null
;
1298 union tgsi_exec_channel
*dst
;
1299 union tgsi_exec_channel index2D
;
1300 uint execmask
= mach
->ExecMask
;
1301 int offset
= 0; /* indirection offset */
1305 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1306 check_inf_or_nan(chan
);
1309 /* There is an extra source register that indirectly subscripts
1310 * a register file. The direct index now becomes an offset
1311 * that is being added to the indirect register.
1315 * ind = Indirect.File
1316 * [2] = Indirect.Index
1317 * .x = Indirect.SwizzleX
1319 if (reg
->Register
.Indirect
) {
1320 union tgsi_exec_channel index
;
1321 union tgsi_exec_channel indir_index
;
1324 /* which address register (always zero for now) */
1328 index
.i
[3] = reg
->Indirect
.Index
;
1330 /* get current value of address register[swizzle] */
1331 swizzle
= reg
->Indirect
.Swizzle
;
1333 /* fetch values from the address/indirection register */
1334 fetch_src_file_channel(mach
,
1342 /* save indirection offset */
1343 offset
= indir_index
.i
[0];
1346 /* There is an extra source register that is a second
1347 * subscript to a register file. Effectively it means that
1348 * the register file is actually a 2D array of registers.
1352 * [3] = Dimension.Index
1354 if (reg
->Register
.Dimension
) {
1358 index2D
.i
[3] = reg
->Dimension
.Index
;
1360 /* Again, the second subscript index can be addressed indirectly
1361 * identically to the first one.
1362 * Nothing stops us from indirectly addressing the indirect register,
1363 * but there is no need for that, so we won't exercise it.
1365 * file[ind[4].y+3][1],
1367 * ind = DimIndirect.File
1368 * [4] = DimIndirect.Index
1369 * .y = DimIndirect.SwizzleX
1371 if (reg
->Dimension
.Indirect
) {
1372 union tgsi_exec_channel index2
;
1373 union tgsi_exec_channel indir_index
;
1374 const uint execmask
= mach
->ExecMask
;
1381 index2
.i
[3] = reg
->DimIndirect
.Index
;
1383 swizzle
= reg
->DimIndirect
.Swizzle
;
1384 fetch_src_file_channel(mach
,
1386 reg
->DimIndirect
.File
,
1392 index2D
.i
[0] += indir_index
.i
[0];
1393 index2D
.i
[1] += indir_index
.i
[1];
1394 index2D
.i
[2] += indir_index
.i
[2];
1395 index2D
.i
[3] += indir_index
.i
[3];
1397 /* for disabled execution channels, zero-out the index to
1398 * avoid using a potential garbage value.
1400 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1401 if ((execmask
& (1 << i
)) == 0) {
1407 /* If by any chance there was a need for a 3D array of register
1408 * files, we would have to check whether Dimension is followed
1409 * by a dimension register and continue the saga.
1418 switch (reg
->Register
.File
) {
1419 case TGSI_FILE_NULL
:
1423 case TGSI_FILE_OUTPUT
:
1424 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1425 + reg
->Register
.Index
;
1426 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1428 debug_printf("NumOutputs = %d, TEMP_O_C/I = %d, redindex = %d\n",
1429 mach
->NumOutputs
, mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0],
1430 reg
->Register
.Index
);
1431 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1432 debug_printf("STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1433 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1434 if (execmask
& (1 << i
))
1435 debug_printf("%f, ", chan
->f
[i
]);
1436 debug_printf(")\n");
1441 case TGSI_FILE_TEMPORARY
:
1442 index
= reg
->Register
.Index
;
1443 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1444 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1447 case TGSI_FILE_ADDRESS
:
1448 index
= reg
->Register
.Index
;
1449 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1452 case TGSI_FILE_PREDICATE
:
1453 index
= reg
->Register
.Index
;
1454 assert(index
< TGSI_EXEC_NUM_PREDS
);
1455 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1463 if (inst
->Instruction
.Predicate
) {
1465 union tgsi_exec_channel
*pred
;
1467 switch (chan_index
) {
1469 swizzle
= inst
->Predicate
.SwizzleX
;
1472 swizzle
= inst
->Predicate
.SwizzleY
;
1475 swizzle
= inst
->Predicate
.SwizzleZ
;
1478 swizzle
= inst
->Predicate
.SwizzleW
;
1485 assert(inst
->Predicate
.Index
== 0);
1487 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1489 if (inst
->Predicate
.Negate
) {
1490 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1492 execmask
&= ~(1 << i
);
1496 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1498 execmask
&= ~(1 << i
);
1504 switch (inst
->Instruction
.Saturate
) {
1506 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1507 if (execmask
& (1 << i
))
1508 dst
->i
[i
] = chan
->i
[i
];
1511 case TGSI_SAT_ZERO_ONE
:
1512 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1513 if (execmask
& (1 << i
)) {
1514 if (chan
->f
[i
] < 0.0f
)
1516 else if (chan
->f
[i
] > 1.0f
)
1519 dst
->i
[i
] = chan
->i
[i
];
1523 case TGSI_SAT_MINUS_PLUS_ONE
:
1524 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1525 if (execmask
& (1 << i
)) {
1526 if (chan
->f
[i
] < -1.0f
)
1528 else if (chan
->f
[i
] > 1.0f
)
1531 dst
->i
[i
] = chan
->i
[i
];
1540 #define FETCH(VAL,INDEX,CHAN)\
1541 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1543 #define IFETCH(VAL,INDEX,CHAN)\
1544 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
1548 * Execute ARB-style KIL which is predicated by a src register.
1549 * Kill fragment if any of the four values is less than zero.
1552 exec_kill_if(struct tgsi_exec_machine
*mach
,
1553 const struct tgsi_full_instruction
*inst
)
1557 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1558 union tgsi_exec_channel r
[1];
1560 /* This mask stores component bits that were already tested. */
1563 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1568 /* unswizzle channel */
1569 swizzle
= tgsi_util_get_full_src_register_swizzle (
1573 /* check if the component has not been already tested */
1574 if (uniquemask
& (1 << swizzle
))
1576 uniquemask
|= 1 << swizzle
;
1578 FETCH(&r
[0], 0, chan_index
);
1579 for (i
= 0; i
< 4; i
++)
1580 if (r
[0].f
[i
] < 0.0f
)
1584 /* restrict to fragments currently executing */
1585 kilmask
&= mach
->ExecMask
;
1587 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1591 * Unconditional fragment kill/discard.
1594 exec_kill(struct tgsi_exec_machine
*mach
,
1595 const struct tgsi_full_instruction
*inst
)
1597 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1599 /* kill fragment for all fragments currently executing */
1600 kilmask
= mach
->ExecMask
;
1601 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1605 emit_vertex(struct tgsi_exec_machine
*mach
)
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
) {
1613 if (mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]] >= mach
->MaxOutputVertices
)
1616 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1617 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1622 emit_primitive(struct tgsi_exec_machine
*mach
)
1624 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1625 /* FIXME: check for exec mask correctly
1627 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1628 if ((mach->ExecMask & (1 << i)))
1630 if (mach
->ExecMask
) {
1632 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1633 mach
->Primitives
[*prim_count
] = 0;
1638 conditional_emit_primitive(struct tgsi_exec_machine
*mach
)
1640 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1642 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]];
1643 if (emitted_verts
) {
1644 emit_primitive(mach
);
1651 * Fetch four texture samples using STR texture coordinates.
1654 fetch_texel( struct tgsi_sampler
*sampler
,
1655 const unsigned sview_idx
,
1656 const unsigned sampler_idx
,
1657 const union tgsi_exec_channel
*s
,
1658 const union tgsi_exec_channel
*t
,
1659 const union tgsi_exec_channel
*p
,
1660 const union tgsi_exec_channel
*c0
,
1661 const union tgsi_exec_channel
*c1
,
1662 float derivs
[3][2][TGSI_QUAD_SIZE
],
1663 const int8_t offset
[3],
1664 enum tgsi_sampler_control control
,
1665 union tgsi_exec_channel
*r
,
1666 union tgsi_exec_channel
*g
,
1667 union tgsi_exec_channel
*b
,
1668 union tgsi_exec_channel
*a
)
1671 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1673 /* FIXME: handle explicit derivs, offsets */
1674 sampler
->get_samples(sampler
, sview_idx
, sampler_idx
,
1675 s
->f
, t
->f
, p
->f
, c0
->f
, c1
->f
, derivs
, offset
, control
, rgba
);
1677 for (j
= 0; j
< 4; j
++) {
1678 r
->f
[j
] = rgba
[0][j
];
1679 g
->f
[j
] = rgba
[1][j
];
1680 b
->f
[j
] = rgba
[2][j
];
1681 a
->f
[j
] = rgba
[3][j
];
1686 #define TEX_MODIFIER_NONE 0
1687 #define TEX_MODIFIER_PROJECTED 1
1688 #define TEX_MODIFIER_LOD_BIAS 2
1689 #define TEX_MODIFIER_EXPLICIT_LOD 3
1690 #define TEX_MODIFIER_LEVEL_ZERO 4
1694 * Fetch all 3 (for s,t,r coords) texel offsets, put them into int array.
1697 fetch_texel_offsets(struct tgsi_exec_machine
*mach
,
1698 const struct tgsi_full_instruction
*inst
,
1701 if (inst
->Texture
.NumOffsets
== 1) {
1702 union tgsi_exec_channel index
;
1703 union tgsi_exec_channel offset
[3];
1704 index
.i
[0] = index
.i
[1] = index
.i
[2] = index
.i
[3] = inst
->TexOffsets
[0].Index
;
1705 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1706 inst
->TexOffsets
[0].SwizzleX
, &index
, &ZeroVec
, &offset
[0]);
1707 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1708 inst
->TexOffsets
[0].SwizzleY
, &index
, &ZeroVec
, &offset
[1]);
1709 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
1710 inst
->TexOffsets
[0].SwizzleZ
, &index
, &ZeroVec
, &offset
[2]);
1711 offsets
[0] = offset
[0].i
[0];
1712 offsets
[1] = offset
[1].i
[0];
1713 offsets
[2] = offset
[2].i
[0];
1715 assert(inst
->Texture
.NumOffsets
== 0);
1716 offsets
[0] = offsets
[1] = offsets
[2] = 0;
1722 * Fetch dx and dy values for one channel (s, t or r).
1723 * Put dx values into one float array, dy values into another.
1726 fetch_assign_deriv_channel(struct tgsi_exec_machine
*mach
,
1727 const struct tgsi_full_instruction
*inst
,
1730 float derivs
[2][TGSI_QUAD_SIZE
])
1732 union tgsi_exec_channel d
;
1733 FETCH(&d
, regdsrcx
, chan
);
1734 derivs
[0][0] = d
.f
[0];
1735 derivs
[0][1] = d
.f
[1];
1736 derivs
[0][2] = d
.f
[2];
1737 derivs
[0][3] = d
.f
[3];
1738 FETCH(&d
, regdsrcx
+ 1, chan
);
1739 derivs
[1][0] = d
.f
[0];
1740 derivs
[1][1] = d
.f
[1];
1741 derivs
[1][2] = d
.f
[2];
1742 derivs
[1][3] = d
.f
[3];
1747 * execute a texture instruction.
1749 * modifier is used to control the channel routing for the\
1750 * instruction variants like proj, lod, and texture with lod bias.
1751 * sampler indicates which src register the sampler is contained in.
1754 exec_tex(struct tgsi_exec_machine
*mach
,
1755 const struct tgsi_full_instruction
*inst
,
1756 uint modifier
, uint sampler
)
1758 const uint unit
= inst
->Src
[sampler
].Register
.Index
;
1759 const union tgsi_exec_channel
*args
[5], *proj
= NULL
;
1760 union tgsi_exec_channel r
[5];
1761 enum tgsi_sampler_control control
= tgsi_sampler_lod_none
;
1764 int dim
, shadow_ref
, i
;
1766 /* always fetch all 3 offsets, overkill but keeps code simple */
1767 fetch_texel_offsets(mach
, inst
, offsets
);
1769 assert(modifier
!= TEX_MODIFIER_LEVEL_ZERO
);
1770 assert(inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
);
1772 dim
= tgsi_util_get_texture_coord_dim(inst
->Texture
.Texture
, &shadow_ref
);
1775 if (shadow_ref
>= 0)
1776 assert(shadow_ref
>= dim
&& shadow_ref
< Elements(args
));
1778 /* fetch modifier to the last argument */
1779 if (modifier
!= TEX_MODIFIER_NONE
) {
1780 const int last
= Elements(args
) - 1;
1782 /* fetch modifier from src0.w or src1.x */
1784 assert(dim
<= TGSI_CHAN_W
&& shadow_ref
!= TGSI_CHAN_W
);
1785 FETCH(&r
[last
], 0, TGSI_CHAN_W
);
1788 assert(shadow_ref
!= 4);
1789 FETCH(&r
[last
], 1, TGSI_CHAN_X
);
1792 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
1793 args
[last
] = &r
[last
];
1797 args
[last
] = &ZeroVec
;
1800 /* point unused arguments to zero vector */
1801 for (i
= dim
; i
< last
; i
++)
1804 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
)
1805 control
= tgsi_sampler_lod_explicit
;
1806 else if (modifier
== TEX_MODIFIER_LOD_BIAS
)
1807 control
= tgsi_sampler_lod_bias
;
1810 for (i
= dim
; i
< Elements(args
); i
++)
1814 /* fetch coordinates */
1815 for (i
= 0; i
< dim
; i
++) {
1816 FETCH(&r
[i
], 0, TGSI_CHAN_X
+ i
);
1819 micro_div(&r
[i
], &r
[i
], proj
);
1824 /* fetch reference value */
1825 if (shadow_ref
>= 0) {
1826 FETCH(&r
[shadow_ref
], shadow_ref
/ 4, TGSI_CHAN_X
+ (shadow_ref
% 4));
1829 micro_div(&r
[shadow_ref
], &r
[shadow_ref
], proj
);
1831 args
[shadow_ref
] = &r
[shadow_ref
];
1834 fetch_texel(mach
->Sampler
, unit
, unit
,
1835 args
[0], args
[1], args
[2], args
[3], args
[4],
1836 NULL
, offsets
, control
,
1837 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1840 debug_printf("fetch r: %g %g %g %g\n",
1841 r
[0].f
[0], r
[0].f
[1], r
[0].f
[2], r
[0].f
[3]);
1842 debug_printf("fetch g: %g %g %g %g\n",
1843 r
[1].f
[0], r
[1].f
[1], r
[1].f
[2], r
[1].f
[3]);
1844 debug_printf("fetch b: %g %g %g %g\n",
1845 r
[2].f
[0], r
[2].f
[1], r
[2].f
[2], r
[2].f
[3]);
1846 debug_printf("fetch a: %g %g %g %g\n",
1847 r
[3].f
[0], r
[3].f
[1], r
[3].f
[2], r
[3].f
[3]);
1850 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1851 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1852 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1859 exec_txd(struct tgsi_exec_machine
*mach
,
1860 const struct tgsi_full_instruction
*inst
)
1862 const uint unit
= inst
->Src
[3].Register
.Index
;
1863 union tgsi_exec_channel r
[4];
1864 float derivs
[3][2][TGSI_QUAD_SIZE
];
1868 /* always fetch all 3 offsets, overkill but keeps code simple */
1869 fetch_texel_offsets(mach
, inst
, offsets
);
1871 switch (inst
->Texture
.Texture
) {
1872 case TGSI_TEXTURE_1D
:
1873 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1875 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1877 fetch_texel(mach
->Sampler
, unit
, unit
,
1878 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
1879 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1880 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1883 case TGSI_TEXTURE_SHADOW1D
:
1884 case TGSI_TEXTURE_1D_ARRAY
:
1885 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1886 /* SHADOW1D/1D_ARRAY would not need Y/Z respectively, but don't bother */
1887 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1888 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1889 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1891 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1893 fetch_texel(mach
->Sampler
, unit
, unit
,
1894 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
1895 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1896 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1899 case TGSI_TEXTURE_2D
:
1900 case TGSI_TEXTURE_RECT
:
1901 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1902 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1904 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1905 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
1907 fetch_texel(mach
->Sampler
, unit
, unit
,
1908 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
1909 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1910 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1914 case TGSI_TEXTURE_SHADOW2D
:
1915 case TGSI_TEXTURE_SHADOWRECT
:
1916 case TGSI_TEXTURE_2D_ARRAY
:
1917 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1918 /* only SHADOW2D_ARRAY actually needs W */
1919 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1920 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1921 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1922 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1924 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1925 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
1927 fetch_texel(mach
->Sampler
, unit
, unit
,
1928 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
1929 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1930 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1933 case TGSI_TEXTURE_3D
:
1934 case TGSI_TEXTURE_CUBE
:
1935 case TGSI_TEXTURE_CUBE_ARRAY
:
1936 case TGSI_TEXTURE_SHADOWCUBE
:
1937 /* only TEXTURE_CUBE_ARRAY and TEXTURE_SHADOWCUBE actually need W */
1938 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1939 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1940 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1941 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1943 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_X
, derivs
[0]);
1944 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Y
, derivs
[1]);
1945 fetch_assign_deriv_channel(mach
, inst
, 1, TGSI_CHAN_Z
, derivs
[2]);
1947 fetch_texel(mach
->Sampler
, unit
, unit
,
1948 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* inputs */
1949 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
1950 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1957 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1958 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1959 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1966 exec_txf(struct tgsi_exec_machine
*mach
,
1967 const struct tgsi_full_instruction
*inst
)
1969 const uint unit
= inst
->Src
[1].Register
.Index
;
1970 union tgsi_exec_channel r
[4];
1972 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1977 /* always fetch all 3 offsets, overkill but keeps code simple */
1978 fetch_texel_offsets(mach
, inst
, offsets
);
1980 IFETCH(&r
[3], 0, TGSI_CHAN_W
);
1982 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
) {
1983 target
= mach
->SamplerViews
[unit
].Resource
;
1986 target
= inst
->Texture
.Texture
;
1989 case TGSI_TEXTURE_3D
:
1990 case TGSI_TEXTURE_2D_ARRAY
:
1991 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1992 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
1993 IFETCH(&r
[2], 0, TGSI_CHAN_Z
);
1995 case TGSI_TEXTURE_2D
:
1996 case TGSI_TEXTURE_RECT
:
1997 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1998 case TGSI_TEXTURE_SHADOW2D
:
1999 case TGSI_TEXTURE_SHADOWRECT
:
2000 case TGSI_TEXTURE_1D_ARRAY
:
2001 case TGSI_TEXTURE_2D_MSAA
:
2002 IFETCH(&r
[1], 0, TGSI_CHAN_Y
);
2004 case TGSI_TEXTURE_BUFFER
:
2005 case TGSI_TEXTURE_1D
:
2006 case TGSI_TEXTURE_SHADOW1D
:
2007 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
2014 mach
->Sampler
->get_texel(mach
->Sampler
, unit
, r
[0].i
, r
[1].i
, r
[2].i
, r
[3].i
,
2017 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2018 r
[0].f
[j
] = rgba
[0][j
];
2019 r
[1].f
[j
] = rgba
[1][j
];
2020 r
[2].f
[j
] = rgba
[2][j
];
2021 r
[3].f
[j
] = rgba
[3][j
];
2024 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_SAMPLE_I
) {
2025 unsigned char swizzles
[4];
2026 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2027 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2028 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2029 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2031 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2032 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2033 store_dest(mach
, &r
[swizzles
[chan
]],
2034 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2039 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2040 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2041 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2048 exec_txq(struct tgsi_exec_machine
*mach
,
2049 const struct tgsi_full_instruction
*inst
)
2051 const uint unit
= inst
->Src
[1].Register
.Index
;
2053 union tgsi_exec_channel r
[4], src
;
2057 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
2059 /* XXX: This interface can't return per-pixel values */
2060 mach
->Sampler
->get_dims(mach
->Sampler
, unit
, src
.i
[0], result
);
2062 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2063 for (j
= 0; j
< 4; j
++) {
2064 r
[j
].i
[i
] = result
[j
];
2068 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2069 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2070 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
2071 TGSI_EXEC_DATA_INT
);
2077 exec_sample(struct tgsi_exec_machine
*mach
,
2078 const struct tgsi_full_instruction
*inst
,
2079 uint modifier
, boolean compare
)
2081 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2082 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2083 union tgsi_exec_channel r
[4], c1
;
2084 const union tgsi_exec_channel
*lod
= &ZeroVec
;
2085 enum tgsi_sampler_control control
= tgsi_sampler_lod_none
;
2087 unsigned char swizzles
[4];
2090 /* always fetch all 3 offsets, overkill but keeps code simple */
2091 fetch_texel_offsets(mach
, inst
, offsets
);
2093 assert(modifier
!= TEX_MODIFIER_PROJECTED
);
2095 if (modifier
!= TEX_MODIFIER_NONE
) {
2096 if (modifier
== TEX_MODIFIER_LOD_BIAS
) {
2097 FETCH(&c1
, 3, TGSI_CHAN_X
);
2099 control
= tgsi_sampler_lod_bias
;
2101 else if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
2102 FETCH(&c1
, 3, TGSI_CHAN_X
);
2104 control
= tgsi_sampler_lod_explicit
;
2107 assert(modifier
== TEX_MODIFIER_LEVEL_ZERO
);
2108 control
= tgsi_sampler_lod_zero
;
2112 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2114 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2115 case TGSI_TEXTURE_1D
:
2117 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2118 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2119 &r
[0], &ZeroVec
, &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2120 NULL
, offsets
, control
,
2121 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2124 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2125 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2126 NULL
, offsets
, control
,
2127 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2131 case TGSI_TEXTURE_1D_ARRAY
:
2132 case TGSI_TEXTURE_2D
:
2133 case TGSI_TEXTURE_RECT
:
2134 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2136 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2137 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2138 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
, /* S, T, P, C, LOD */
2139 NULL
, offsets
, control
,
2140 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2143 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2144 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, C, LOD */
2145 NULL
, offsets
, control
,
2146 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2150 case TGSI_TEXTURE_2D_ARRAY
:
2151 case TGSI_TEXTURE_3D
:
2152 case TGSI_TEXTURE_CUBE
:
2153 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2154 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2156 FETCH(&r
[3], 3, TGSI_CHAN_X
);
2157 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2158 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2159 NULL
, offsets
, control
,
2160 &r
[0], &r
[1], &r
[2], &r
[3]);
2163 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2164 &r
[0], &r
[1], &r
[2], &ZeroVec
, lod
,
2165 NULL
, offsets
, control
,
2166 &r
[0], &r
[1], &r
[2], &r
[3]);
2170 case TGSI_TEXTURE_CUBE_ARRAY
:
2171 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2172 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2173 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2175 FETCH(&r
[4], 3, TGSI_CHAN_X
);
2176 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2177 &r
[0], &r
[1], &r
[2], &r
[3], &r
[4],
2178 NULL
, offsets
, control
,
2179 &r
[0], &r
[1], &r
[2], &r
[3]);
2182 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2183 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2184 NULL
, offsets
, control
,
2185 &r
[0], &r
[1], &r
[2], &r
[3]);
2194 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2195 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2196 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2197 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2199 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2200 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2201 store_dest(mach
, &r
[swizzles
[chan
]],
2202 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2208 exec_sample_d(struct tgsi_exec_machine
*mach
,
2209 const struct tgsi_full_instruction
*inst
)
2211 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2212 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2213 union tgsi_exec_channel r
[4];
2214 float derivs
[3][2][TGSI_QUAD_SIZE
];
2216 unsigned char swizzles
[4];
2219 /* always fetch all 3 offsets, overkill but keeps code simple */
2220 fetch_texel_offsets(mach
, inst
, offsets
);
2222 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2224 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2225 case TGSI_TEXTURE_1D
:
2226 case TGSI_TEXTURE_1D_ARRAY
:
2227 /* only 1D array actually needs Y */
2228 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2230 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2232 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2233 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, C, LOD */
2234 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
2235 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2238 case TGSI_TEXTURE_2D
:
2239 case TGSI_TEXTURE_RECT
:
2240 case TGSI_TEXTURE_2D_ARRAY
:
2241 /* only 2D array actually needs Z */
2242 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2243 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2245 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2246 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2248 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2249 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* inputs */
2250 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
2251 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2254 case TGSI_TEXTURE_3D
:
2255 case TGSI_TEXTURE_CUBE
:
2256 case TGSI_TEXTURE_CUBE_ARRAY
:
2257 /* only cube array actually needs W */
2258 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2259 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2260 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2262 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_X
, derivs
[0]);
2263 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Y
, derivs
[1]);
2264 fetch_assign_deriv_channel(mach
, inst
, 3, TGSI_CHAN_Z
, derivs
[2]);
2266 fetch_texel(mach
->Sampler
, resource_unit
, sampler_unit
,
2267 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
,
2268 derivs
, offsets
, tgsi_sampler_derivs_explicit
,
2269 &r
[0], &r
[1], &r
[2], &r
[3]);
2276 swizzles
[0] = inst
->Src
[1].Register
.SwizzleX
;
2277 swizzles
[1] = inst
->Src
[1].Register
.SwizzleY
;
2278 swizzles
[2] = inst
->Src
[1].Register
.SwizzleZ
;
2279 swizzles
[3] = inst
->Src
[1].Register
.SwizzleW
;
2281 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2282 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2283 store_dest(mach
, &r
[swizzles
[chan
]],
2284 &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2291 * Evaluate a constant-valued coefficient at the position of the
2296 struct tgsi_exec_machine
*mach
,
2302 for( i
= 0; i
< TGSI_QUAD_SIZE
; i
++ ) {
2303 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
2308 * Evaluate a linear-valued coefficient at the position of the
2313 struct tgsi_exec_machine
*mach
,
2317 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2318 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2319 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2320 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2321 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2322 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
2323 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
2324 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
2325 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
2329 * Evaluate a perspective-valued coefficient at the position of the
2333 eval_perspective_coef(
2334 struct tgsi_exec_machine
*mach
,
2338 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2339 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2340 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2341 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2342 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2343 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
2344 /* divide by W here */
2345 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
2346 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
2347 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
2348 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
2352 typedef void (* eval_coef_func
)(
2353 struct tgsi_exec_machine
*mach
,
2358 exec_declaration(struct tgsi_exec_machine
*mach
,
2359 const struct tgsi_full_declaration
*decl
)
2361 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
2362 mach
->SamplerViews
[decl
->Range
.First
] = decl
->SamplerView
;
2366 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
2367 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
2368 uint first
, last
, mask
;
2370 first
= decl
->Range
.First
;
2371 last
= decl
->Range
.Last
;
2372 mask
= decl
->Declaration
.UsageMask
;
2374 /* XXX we could remove this special-case code since
2375 * mach->InterpCoefs[first].a0 should already have the
2376 * front/back-face value. But we should first update the
2377 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2378 * Then, we could remove the tgsi_exec_machine::Face field.
2380 /* XXX make FACE a system value */
2381 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
2384 assert(decl
->Semantic
.Index
== 0);
2385 assert(first
== last
);
2387 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2388 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
2391 eval_coef_func eval
;
2394 switch (decl
->Interp
.Interpolate
) {
2395 case TGSI_INTERPOLATE_CONSTANT
:
2396 eval
= eval_constant_coef
;
2399 case TGSI_INTERPOLATE_LINEAR
:
2400 eval
= eval_linear_coef
;
2403 case TGSI_INTERPOLATE_PERSPECTIVE
:
2404 eval
= eval_perspective_coef
;
2407 case TGSI_INTERPOLATE_COLOR
:
2408 eval
= mach
->flatshade_color
? eval_constant_coef
: eval_perspective_coef
;
2416 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2417 if (mask
& (1 << j
)) {
2418 for (i
= first
; i
<= last
; i
++) {
2425 if (DEBUG_EXECUTION
) {
2427 for (i
= first
; i
<= last
; ++i
) {
2428 debug_printf("IN[%2u] = ", i
);
2429 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2433 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
2434 mach
->Inputs
[i
].xyzw
[0].f
[j
], mach
->Inputs
[i
].xyzw
[0].u
[j
],
2435 mach
->Inputs
[i
].xyzw
[1].f
[j
], mach
->Inputs
[i
].xyzw
[1].u
[j
],
2436 mach
->Inputs
[i
].xyzw
[2].f
[j
], mach
->Inputs
[i
].xyzw
[2].u
[j
],
2437 mach
->Inputs
[i
].xyzw
[3].f
[j
], mach
->Inputs
[i
].xyzw
[3].u
[j
]);
2444 if (decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
2445 mach
->SysSemanticToIndex
[decl
->Declaration
.Semantic
] = decl
->Range
.First
;
2450 typedef void (* micro_op
)(union tgsi_exec_channel
*dst
);
2453 exec_vector(struct tgsi_exec_machine
*mach
,
2454 const struct tgsi_full_instruction
*inst
,
2456 enum tgsi_exec_datatype dst_datatype
)
2460 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2461 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2462 union tgsi_exec_channel dst
;
2465 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2470 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
2471 const union tgsi_exec_channel
*src
);
2474 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
2475 const struct tgsi_full_instruction
*inst
,
2477 enum tgsi_exec_datatype dst_datatype
,
2478 enum tgsi_exec_datatype src_datatype
)
2481 union tgsi_exec_channel src
;
2482 union tgsi_exec_channel dst
;
2484 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2486 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2487 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2488 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2494 exec_vector_unary(struct tgsi_exec_machine
*mach
,
2495 const struct tgsi_full_instruction
*inst
,
2497 enum tgsi_exec_datatype dst_datatype
,
2498 enum tgsi_exec_datatype src_datatype
)
2501 struct tgsi_exec_vector dst
;
2503 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2504 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2505 union tgsi_exec_channel src
;
2507 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
2508 op(&dst
.xyzw
[chan
], &src
);
2511 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2512 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2513 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2518 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
2519 const union tgsi_exec_channel
*src0
,
2520 const union tgsi_exec_channel
*src1
);
2523 exec_scalar_binary(struct tgsi_exec_machine
*mach
,
2524 const struct tgsi_full_instruction
*inst
,
2526 enum tgsi_exec_datatype dst_datatype
,
2527 enum tgsi_exec_datatype src_datatype
)
2530 union tgsi_exec_channel src
[2];
2531 union tgsi_exec_channel dst
;
2533 fetch_source(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2534 fetch_source(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_X
, src_datatype
);
2535 op(&dst
, &src
[0], &src
[1]);
2536 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2537 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2538 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2544 exec_vector_binary(struct tgsi_exec_machine
*mach
,
2545 const struct tgsi_full_instruction
*inst
,
2547 enum tgsi_exec_datatype dst_datatype
,
2548 enum tgsi_exec_datatype src_datatype
)
2551 struct tgsi_exec_vector dst
;
2553 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2554 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2555 union tgsi_exec_channel src
[2];
2557 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2558 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2559 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
2562 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2563 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2564 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2569 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
2570 const union tgsi_exec_channel
*src0
,
2571 const union tgsi_exec_channel
*src1
,
2572 const union tgsi_exec_channel
*src2
);
2575 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
2576 const struct tgsi_full_instruction
*inst
,
2577 micro_trinary_op op
,
2578 enum tgsi_exec_datatype dst_datatype
,
2579 enum tgsi_exec_datatype src_datatype
)
2582 struct tgsi_exec_vector dst
;
2584 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2585 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2586 union tgsi_exec_channel src
[3];
2588 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2589 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2590 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2591 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
2594 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2595 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2596 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2601 typedef void (* micro_quaternary_op
)(union tgsi_exec_channel
*dst
,
2602 const union tgsi_exec_channel
*src0
,
2603 const union tgsi_exec_channel
*src1
,
2604 const union tgsi_exec_channel
*src2
,
2605 const union tgsi_exec_channel
*src3
);
2608 exec_vector_quaternary(struct tgsi_exec_machine
*mach
,
2609 const struct tgsi_full_instruction
*inst
,
2610 micro_quaternary_op op
,
2611 enum tgsi_exec_datatype dst_datatype
,
2612 enum tgsi_exec_datatype src_datatype
)
2615 struct tgsi_exec_vector dst
;
2617 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2618 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2619 union tgsi_exec_channel src
[4];
2621 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2622 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2623 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2624 fetch_source(mach
, &src
[3], &inst
->Src
[3], chan
, src_datatype
);
2625 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2], &src
[3]);
2628 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2629 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2630 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2636 exec_dp3(struct tgsi_exec_machine
*mach
,
2637 const struct tgsi_full_instruction
*inst
)
2640 union tgsi_exec_channel arg
[3];
2642 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2643 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2644 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2646 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
2647 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2648 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2649 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2652 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2653 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2654 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2660 exec_dp4(struct tgsi_exec_machine
*mach
,
2661 const struct tgsi_full_instruction
*inst
)
2664 union tgsi_exec_channel arg
[3];
2666 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2667 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2668 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2670 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
2671 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2672 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2673 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2676 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2677 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2678 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2684 exec_dp2a(struct tgsi_exec_machine
*mach
,
2685 const struct tgsi_full_instruction
*inst
)
2688 union tgsi_exec_channel arg
[3];
2690 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2691 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2692 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2694 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2695 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2696 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2698 fetch_source(mach
, &arg
[1], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2699 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2701 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2702 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2703 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2709 exec_dph(struct tgsi_exec_machine
*mach
,
2710 const struct tgsi_full_instruction
*inst
)
2713 union tgsi_exec_channel arg
[3];
2715 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2716 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2717 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2719 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2720 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2721 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2723 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2724 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2725 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2727 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2728 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2730 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2731 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2732 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2738 exec_dp2(struct tgsi_exec_machine
*mach
,
2739 const struct tgsi_full_instruction
*inst
)
2742 union tgsi_exec_channel arg
[3];
2744 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2745 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2746 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2748 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2749 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2750 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2752 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2753 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2754 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2760 exec_scs(struct tgsi_exec_machine
*mach
,
2761 const struct tgsi_full_instruction
*inst
)
2763 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) {
2764 union tgsi_exec_channel arg
;
2765 union tgsi_exec_channel result
;
2767 fetch_source(mach
, &arg
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2769 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2770 micro_cos(&result
, &arg
);
2771 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2773 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2774 micro_sin(&result
, &arg
);
2775 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2778 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2779 store_dest(mach
, &ZeroVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2781 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2782 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2787 exec_xpd(struct tgsi_exec_machine
*mach
,
2788 const struct tgsi_full_instruction
*inst
)
2790 union tgsi_exec_channel r
[6];
2791 union tgsi_exec_channel d
[3];
2793 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2794 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2796 micro_mul(&r
[2], &r
[0], &r
[1]);
2798 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2799 fetch_source(mach
, &r
[4], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2801 micro_mul(&r
[5], &r
[3], &r
[4] );
2802 micro_sub(&d
[TGSI_CHAN_X
], &r
[2], &r
[5]);
2804 fetch_source(mach
, &r
[2], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2806 micro_mul(&r
[3], &r
[3], &r
[2]);
2808 fetch_source(mach
, &r
[5], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2810 micro_mul(&r
[1], &r
[1], &r
[5]);
2811 micro_sub(&d
[TGSI_CHAN_Y
], &r
[3], &r
[1]);
2813 micro_mul(&r
[5], &r
[5], &r
[4]);
2814 micro_mul(&r
[0], &r
[0], &r
[2]);
2815 micro_sub(&d
[TGSI_CHAN_Z
], &r
[5], &r
[0]);
2817 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2818 store_dest(mach
, &d
[TGSI_CHAN_X
], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2820 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2821 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2823 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2824 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2826 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2827 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2832 exec_dst(struct tgsi_exec_machine
*mach
,
2833 const struct tgsi_full_instruction
*inst
)
2835 union tgsi_exec_channel r
[2];
2836 union tgsi_exec_channel d
[4];
2838 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2839 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2840 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2841 micro_mul(&d
[TGSI_CHAN_Y
], &r
[0], &r
[1]);
2843 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2844 fetch_source(mach
, &d
[TGSI_CHAN_Z
], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2846 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2847 fetch_source(mach
, &d
[TGSI_CHAN_W
], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2850 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2851 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2853 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2854 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2856 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2857 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2859 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2860 store_dest(mach
, &d
[TGSI_CHAN_W
], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2865 exec_log(struct tgsi_exec_machine
*mach
,
2866 const struct tgsi_full_instruction
*inst
)
2868 union tgsi_exec_channel r
[3];
2870 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2871 micro_abs(&r
[2], &r
[0]); /* r2 = abs(r0) */
2872 micro_lg2(&r
[1], &r
[2]); /* r1 = lg2(r2) */
2873 micro_flr(&r
[0], &r
[1]); /* r0 = floor(r1) */
2874 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2875 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2877 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2878 micro_exp2(&r
[0], &r
[0]); /* r0 = 2 ^ r0 */
2879 micro_div(&r
[0], &r
[2], &r
[0]); /* r0 = r2 / r0 */
2880 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2882 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2883 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2885 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2886 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2891 exec_exp(struct tgsi_exec_machine
*mach
,
2892 const struct tgsi_full_instruction
*inst
)
2894 union tgsi_exec_channel r
[3];
2896 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2897 micro_flr(&r
[1], &r
[0]); /* r1 = floor(r0) */
2898 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2899 micro_exp2(&r
[2], &r
[1]); /* r2 = 2 ^ r1 */
2900 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2902 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2903 micro_sub(&r
[2], &r
[0], &r
[1]); /* r2 = r0 - r1 */
2904 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2906 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2907 micro_exp2(&r
[2], &r
[0]); /* r2 = 2 ^ r0 */
2908 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2910 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2911 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2916 exec_lit(struct tgsi_exec_machine
*mach
,
2917 const struct tgsi_full_instruction
*inst
)
2919 union tgsi_exec_channel r
[3];
2920 union tgsi_exec_channel d
[3];
2922 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YZ
) {
2923 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2924 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2925 fetch_source(mach
, &r
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2926 micro_max(&r
[1], &r
[1], &ZeroVec
);
2928 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2929 micro_min(&r
[2], &r
[2], &P128Vec
);
2930 micro_max(&r
[2], &r
[2], &M128Vec
);
2931 micro_pow(&r
[1], &r
[1], &r
[2]);
2932 micro_lt(&d
[TGSI_CHAN_Z
], &ZeroVec
, &r
[0], &r
[1], &ZeroVec
);
2933 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2935 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2936 micro_max(&d
[TGSI_CHAN_Y
], &r
[0], &ZeroVec
);
2937 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2940 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2941 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2944 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2945 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2950 exec_break(struct tgsi_exec_machine
*mach
)
2952 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
2953 /* turn off loop channels for each enabled exec channel */
2954 mach
->LoopMask
&= ~mach
->ExecMask
;
2955 /* Todo: if mach->LoopMask == 0, jump to end of loop */
2956 UPDATE_EXEC_MASK(mach
);
2958 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
2960 mach
->Switch
.mask
= 0x0;
2962 UPDATE_EXEC_MASK(mach
);
2967 exec_switch(struct tgsi_exec_machine
*mach
,
2968 const struct tgsi_full_instruction
*inst
)
2970 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
2971 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
2973 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
2974 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
2975 mach
->Switch
.mask
= 0x0;
2976 mach
->Switch
.defaultMask
= 0x0;
2978 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
2979 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
2981 UPDATE_EXEC_MASK(mach
);
2985 exec_case(struct tgsi_exec_machine
*mach
,
2986 const struct tgsi_full_instruction
*inst
)
2988 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
2989 union tgsi_exec_channel src
;
2992 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
2994 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
2997 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
3000 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
3003 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
3007 mach
->Switch
.defaultMask
|= mask
;
3009 mach
->Switch
.mask
|= mask
& prevMask
;
3011 UPDATE_EXEC_MASK(mach
);
3014 /* FIXME: this will only work if default is last */
3016 exec_default(struct tgsi_exec_machine
*mach
)
3018 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3020 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
3022 UPDATE_EXEC_MASK(mach
);
3026 exec_endswitch(struct tgsi_exec_machine
*mach
)
3028 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
3029 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3031 UPDATE_EXEC_MASK(mach
);
3035 micro_i2f(union tgsi_exec_channel
*dst
,
3036 const union tgsi_exec_channel
*src
)
3038 dst
->f
[0] = (float)src
->i
[0];
3039 dst
->f
[1] = (float)src
->i
[1];
3040 dst
->f
[2] = (float)src
->i
[2];
3041 dst
->f
[3] = (float)src
->i
[3];
3045 micro_not(union tgsi_exec_channel
*dst
,
3046 const union tgsi_exec_channel
*src
)
3048 dst
->u
[0] = ~src
->u
[0];
3049 dst
->u
[1] = ~src
->u
[1];
3050 dst
->u
[2] = ~src
->u
[2];
3051 dst
->u
[3] = ~src
->u
[3];
3055 micro_shl(union tgsi_exec_channel
*dst
,
3056 const union tgsi_exec_channel
*src0
,
3057 const union tgsi_exec_channel
*src1
)
3059 unsigned masked_count
;
3060 masked_count
= src1
->u
[0] & 0x1f;
3061 dst
->u
[0] = src0
->u
[0] << masked_count
;
3062 masked_count
= src1
->u
[1] & 0x1f;
3063 dst
->u
[1] = src0
->u
[1] << masked_count
;
3064 masked_count
= src1
->u
[2] & 0x1f;
3065 dst
->u
[2] = src0
->u
[2] << masked_count
;
3066 masked_count
= src1
->u
[3] & 0x1f;
3067 dst
->u
[3] = src0
->u
[3] << masked_count
;
3071 micro_and(union tgsi_exec_channel
*dst
,
3072 const union tgsi_exec_channel
*src0
,
3073 const union tgsi_exec_channel
*src1
)
3075 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
3076 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
3077 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
3078 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
3082 micro_or(union tgsi_exec_channel
*dst
,
3083 const union tgsi_exec_channel
*src0
,
3084 const union tgsi_exec_channel
*src1
)
3086 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
3087 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
3088 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
3089 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
3093 micro_xor(union tgsi_exec_channel
*dst
,
3094 const union tgsi_exec_channel
*src0
,
3095 const union tgsi_exec_channel
*src1
)
3097 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
3098 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
3099 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
3100 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
3104 micro_mod(union tgsi_exec_channel
*dst
,
3105 const union tgsi_exec_channel
*src0
,
3106 const union tgsi_exec_channel
*src1
)
3108 dst
->i
[0] = src0
->i
[0] % src1
->i
[0];
3109 dst
->i
[1] = src0
->i
[1] % src1
->i
[1];
3110 dst
->i
[2] = src0
->i
[2] % src1
->i
[2];
3111 dst
->i
[3] = src0
->i
[3] % src1
->i
[3];
3115 micro_f2i(union tgsi_exec_channel
*dst
,
3116 const union tgsi_exec_channel
*src
)
3118 dst
->i
[0] = (int)src
->f
[0];
3119 dst
->i
[1] = (int)src
->f
[1];
3120 dst
->i
[2] = (int)src
->f
[2];
3121 dst
->i
[3] = (int)src
->f
[3];
3125 micro_fseq(union tgsi_exec_channel
*dst
,
3126 const union tgsi_exec_channel
*src0
,
3127 const union tgsi_exec_channel
*src1
)
3129 dst
->u
[0] = src0
->f
[0] == src1
->f
[0] ? ~0 : 0;
3130 dst
->u
[1] = src0
->f
[1] == src1
->f
[1] ? ~0 : 0;
3131 dst
->u
[2] = src0
->f
[2] == src1
->f
[2] ? ~0 : 0;
3132 dst
->u
[3] = src0
->f
[3] == src1
->f
[3] ? ~0 : 0;
3136 micro_fsge(union tgsi_exec_channel
*dst
,
3137 const union tgsi_exec_channel
*src0
,
3138 const union tgsi_exec_channel
*src1
)
3140 dst
->u
[0] = src0
->f
[0] >= src1
->f
[0] ? ~0 : 0;
3141 dst
->u
[1] = src0
->f
[1] >= src1
->f
[1] ? ~0 : 0;
3142 dst
->u
[2] = src0
->f
[2] >= src1
->f
[2] ? ~0 : 0;
3143 dst
->u
[3] = src0
->f
[3] >= src1
->f
[3] ? ~0 : 0;
3147 micro_fslt(union tgsi_exec_channel
*dst
,
3148 const union tgsi_exec_channel
*src0
,
3149 const union tgsi_exec_channel
*src1
)
3151 dst
->u
[0] = src0
->f
[0] < src1
->f
[0] ? ~0 : 0;
3152 dst
->u
[1] = src0
->f
[1] < src1
->f
[1] ? ~0 : 0;
3153 dst
->u
[2] = src0
->f
[2] < src1
->f
[2] ? ~0 : 0;
3154 dst
->u
[3] = src0
->f
[3] < src1
->f
[3] ? ~0 : 0;
3158 micro_fsne(union tgsi_exec_channel
*dst
,
3159 const union tgsi_exec_channel
*src0
,
3160 const union tgsi_exec_channel
*src1
)
3162 dst
->u
[0] = src0
->f
[0] != src1
->f
[0] ? ~0 : 0;
3163 dst
->u
[1] = src0
->f
[1] != src1
->f
[1] ? ~0 : 0;
3164 dst
->u
[2] = src0
->f
[2] != src1
->f
[2] ? ~0 : 0;
3165 dst
->u
[3] = src0
->f
[3] != src1
->f
[3] ? ~0 : 0;
3169 micro_idiv(union tgsi_exec_channel
*dst
,
3170 const union tgsi_exec_channel
*src0
,
3171 const union tgsi_exec_channel
*src1
)
3173 dst
->i
[0] = src1
->i
[0] ? src0
->i
[0] / src1
->i
[0] : 0;
3174 dst
->i
[1] = src1
->i
[1] ? src0
->i
[1] / src1
->i
[1] : 0;
3175 dst
->i
[2] = src1
->i
[2] ? src0
->i
[2] / src1
->i
[2] : 0;
3176 dst
->i
[3] = src1
->i
[3] ? src0
->i
[3] / src1
->i
[3] : 0;
3180 micro_imax(union tgsi_exec_channel
*dst
,
3181 const union tgsi_exec_channel
*src0
,
3182 const union tgsi_exec_channel
*src1
)
3184 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3185 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3186 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3187 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3191 micro_imin(union tgsi_exec_channel
*dst
,
3192 const union tgsi_exec_channel
*src0
,
3193 const union tgsi_exec_channel
*src1
)
3195 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3196 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3197 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3198 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3202 micro_isge(union tgsi_exec_channel
*dst
,
3203 const union tgsi_exec_channel
*src0
,
3204 const union tgsi_exec_channel
*src1
)
3206 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
3207 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
3208 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
3209 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
3213 micro_ishr(union tgsi_exec_channel
*dst
,
3214 const union tgsi_exec_channel
*src0
,
3215 const union tgsi_exec_channel
*src1
)
3217 unsigned masked_count
;
3218 masked_count
= src1
->i
[0] & 0x1f;
3219 dst
->i
[0] = src0
->i
[0] >> masked_count
;
3220 masked_count
= src1
->i
[1] & 0x1f;
3221 dst
->i
[1] = src0
->i
[1] >> masked_count
;
3222 masked_count
= src1
->i
[2] & 0x1f;
3223 dst
->i
[2] = src0
->i
[2] >> masked_count
;
3224 masked_count
= src1
->i
[3] & 0x1f;
3225 dst
->i
[3] = src0
->i
[3] >> masked_count
;
3229 micro_islt(union tgsi_exec_channel
*dst
,
3230 const union tgsi_exec_channel
*src0
,
3231 const union tgsi_exec_channel
*src1
)
3233 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
3234 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
3235 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
3236 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
3240 micro_f2u(union tgsi_exec_channel
*dst
,
3241 const union tgsi_exec_channel
*src
)
3243 dst
->u
[0] = (uint
)src
->f
[0];
3244 dst
->u
[1] = (uint
)src
->f
[1];
3245 dst
->u
[2] = (uint
)src
->f
[2];
3246 dst
->u
[3] = (uint
)src
->f
[3];
3250 micro_u2f(union tgsi_exec_channel
*dst
,
3251 const union tgsi_exec_channel
*src
)
3253 dst
->f
[0] = (float)src
->u
[0];
3254 dst
->f
[1] = (float)src
->u
[1];
3255 dst
->f
[2] = (float)src
->u
[2];
3256 dst
->f
[3] = (float)src
->u
[3];
3260 micro_uadd(union tgsi_exec_channel
*dst
,
3261 const union tgsi_exec_channel
*src0
,
3262 const union tgsi_exec_channel
*src1
)
3264 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
3265 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
3266 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
3267 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
3271 micro_udiv(union tgsi_exec_channel
*dst
,
3272 const union tgsi_exec_channel
*src0
,
3273 const union tgsi_exec_channel
*src1
)
3275 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] / src1
->u
[0] : ~0u;
3276 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] / src1
->u
[1] : ~0u;
3277 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] / src1
->u
[2] : ~0u;
3278 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] / src1
->u
[3] : ~0u;
3282 micro_umad(union tgsi_exec_channel
*dst
,
3283 const union tgsi_exec_channel
*src0
,
3284 const union tgsi_exec_channel
*src1
,
3285 const union tgsi_exec_channel
*src2
)
3287 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
3288 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
3289 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
3290 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
3294 micro_umax(union tgsi_exec_channel
*dst
,
3295 const union tgsi_exec_channel
*src0
,
3296 const union tgsi_exec_channel
*src1
)
3298 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3299 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3300 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3301 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3305 micro_umin(union tgsi_exec_channel
*dst
,
3306 const union tgsi_exec_channel
*src0
,
3307 const union tgsi_exec_channel
*src1
)
3309 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3310 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3311 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3312 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3316 micro_umod(union tgsi_exec_channel
*dst
,
3317 const union tgsi_exec_channel
*src0
,
3318 const union tgsi_exec_channel
*src1
)
3320 dst
->u
[0] = src1
->u
[0] ? src0
->u
[0] % src1
->u
[0] : ~0u;
3321 dst
->u
[1] = src1
->u
[1] ? src0
->u
[1] % src1
->u
[1] : ~0u;
3322 dst
->u
[2] = src1
->u
[2] ? src0
->u
[2] % src1
->u
[2] : ~0u;
3323 dst
->u
[3] = src1
->u
[3] ? src0
->u
[3] % src1
->u
[3] : ~0u;
3327 micro_umul(union tgsi_exec_channel
*dst
,
3328 const union tgsi_exec_channel
*src0
,
3329 const union tgsi_exec_channel
*src1
)
3331 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
3332 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
3333 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
3334 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
3338 micro_imul_hi(union tgsi_exec_channel
*dst
,
3339 const union tgsi_exec_channel
*src0
,
3340 const union tgsi_exec_channel
*src1
)
3342 #define I64M(x, y) ((((int64_t)x) * ((int64_t)y)) >> 32)
3343 dst
->i
[0] = I64M(src0
->i
[0], src1
->i
[0]);
3344 dst
->i
[1] = I64M(src0
->i
[1], src1
->i
[1]);
3345 dst
->i
[2] = I64M(src0
->i
[2], src1
->i
[2]);
3346 dst
->i
[3] = I64M(src0
->i
[3], src1
->i
[3]);
3351 micro_umul_hi(union tgsi_exec_channel
*dst
,
3352 const union tgsi_exec_channel
*src0
,
3353 const union tgsi_exec_channel
*src1
)
3355 #define U64M(x, y) ((((uint64_t)x) * ((uint64_t)y)) >> 32)
3356 dst
->u
[0] = U64M(src0
->u
[0], src1
->u
[0]);
3357 dst
->u
[1] = U64M(src0
->u
[1], src1
->u
[1]);
3358 dst
->u
[2] = U64M(src0
->u
[2], src1
->u
[2]);
3359 dst
->u
[3] = U64M(src0
->u
[3], src1
->u
[3]);
3364 micro_useq(union tgsi_exec_channel
*dst
,
3365 const union tgsi_exec_channel
*src0
,
3366 const union tgsi_exec_channel
*src1
)
3368 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
3369 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
3370 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
3371 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
3375 micro_usge(union tgsi_exec_channel
*dst
,
3376 const union tgsi_exec_channel
*src0
,
3377 const union tgsi_exec_channel
*src1
)
3379 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
3380 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
3381 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
3382 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
3386 micro_ushr(union tgsi_exec_channel
*dst
,
3387 const union tgsi_exec_channel
*src0
,
3388 const union tgsi_exec_channel
*src1
)
3390 unsigned masked_count
;
3391 masked_count
= src1
->u
[0] & 0x1f;
3392 dst
->u
[0] = src0
->u
[0] >> masked_count
;
3393 masked_count
= src1
->u
[1] & 0x1f;
3394 dst
->u
[1] = src0
->u
[1] >> masked_count
;
3395 masked_count
= src1
->u
[2] & 0x1f;
3396 dst
->u
[2] = src0
->u
[2] >> masked_count
;
3397 masked_count
= src1
->u
[3] & 0x1f;
3398 dst
->u
[3] = src0
->u
[3] >> masked_count
;
3402 micro_uslt(union tgsi_exec_channel
*dst
,
3403 const union tgsi_exec_channel
*src0
,
3404 const union tgsi_exec_channel
*src1
)
3406 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
3407 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
3408 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
3409 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
3413 micro_usne(union tgsi_exec_channel
*dst
,
3414 const union tgsi_exec_channel
*src0
,
3415 const union tgsi_exec_channel
*src1
)
3417 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
3418 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
3419 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
3420 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
3424 micro_uarl(union tgsi_exec_channel
*dst
,
3425 const union tgsi_exec_channel
*src
)
3427 dst
->i
[0] = src
->u
[0];
3428 dst
->i
[1] = src
->u
[1];
3429 dst
->i
[2] = src
->u
[2];
3430 dst
->i
[3] = src
->u
[3];
3434 micro_ucmp(union tgsi_exec_channel
*dst
,
3435 const union tgsi_exec_channel
*src0
,
3436 const union tgsi_exec_channel
*src1
,
3437 const union tgsi_exec_channel
*src2
)
3439 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
3440 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
3441 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
3442 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
3446 * Signed bitfield extract (i.e. sign-extend the extracted bits)
3449 micro_ibfe(union tgsi_exec_channel
*dst
,
3450 const union tgsi_exec_channel
*src0
,
3451 const union tgsi_exec_channel
*src1
,
3452 const union tgsi_exec_channel
*src2
)
3455 for (i
= 0; i
< 4; i
++) {
3456 int width
= src2
->i
[i
] & 0x1f;
3457 int offset
= src1
->i
[i
] & 0x1f;
3460 else if (width
+ offset
< 32)
3461 dst
->i
[i
] = (src0
->i
[i
] << (32 - width
- offset
)) >> (32 - width
);
3463 dst
->i
[i
] = src0
->i
[i
] >> offset
;
3468 * Unsigned bitfield extract
3471 micro_ubfe(union tgsi_exec_channel
*dst
,
3472 const union tgsi_exec_channel
*src0
,
3473 const union tgsi_exec_channel
*src1
,
3474 const union tgsi_exec_channel
*src2
)
3477 for (i
= 0; i
< 4; i
++) {
3478 int width
= src2
->u
[i
] & 0x1f;
3479 int offset
= src1
->u
[i
] & 0x1f;
3482 else if (width
+ offset
< 32)
3483 dst
->u
[i
] = (src0
->u
[i
] << (32 - width
- offset
)) >> (32 - width
);
3485 dst
->u
[i
] = src0
->u
[i
] >> offset
;
3490 * Bitfield insert: copy low bits from src1 into a region of src0.
3493 micro_bfi(union tgsi_exec_channel
*dst
,
3494 const union tgsi_exec_channel
*src0
,
3495 const union tgsi_exec_channel
*src1
,
3496 const union tgsi_exec_channel
*src2
,
3497 const union tgsi_exec_channel
*src3
)
3500 for (i
= 0; i
< 4; i
++) {
3501 int width
= src3
->u
[i
] & 0x1f;
3502 int offset
= src2
->u
[i
] & 0x1f;
3503 int bitmask
= ((1 << width
) - 1) << offset
;
3504 dst
->u
[i
] = ((src1
->u
[i
] << offset
) & bitmask
) | (src0
->u
[i
] & ~bitmask
);
3509 micro_brev(union tgsi_exec_channel
*dst
,
3510 const union tgsi_exec_channel
*src
)
3512 dst
->u
[0] = util_bitreverse(src
->u
[0]);
3513 dst
->u
[1] = util_bitreverse(src
->u
[1]);
3514 dst
->u
[2] = util_bitreverse(src
->u
[2]);
3515 dst
->u
[3] = util_bitreverse(src
->u
[3]);
3519 micro_popc(union tgsi_exec_channel
*dst
,
3520 const union tgsi_exec_channel
*src
)
3522 dst
->u
[0] = util_bitcount(src
->u
[0]);
3523 dst
->u
[1] = util_bitcount(src
->u
[1]);
3524 dst
->u
[2] = util_bitcount(src
->u
[2]);
3525 dst
->u
[3] = util_bitcount(src
->u
[3]);
3529 micro_lsb(union tgsi_exec_channel
*dst
,
3530 const union tgsi_exec_channel
*src
)
3532 dst
->i
[0] = ffs(src
->u
[0]) - 1;
3533 dst
->i
[1] = ffs(src
->u
[1]) - 1;
3534 dst
->i
[2] = ffs(src
->u
[2]) - 1;
3535 dst
->i
[3] = ffs(src
->u
[3]) - 1;
3539 micro_imsb(union tgsi_exec_channel
*dst
,
3540 const union tgsi_exec_channel
*src
)
3542 dst
->i
[0] = util_last_bit_signed(src
->i
[0]) - 1;
3543 dst
->i
[1] = util_last_bit_signed(src
->i
[1]) - 1;
3544 dst
->i
[2] = util_last_bit_signed(src
->i
[2]) - 1;
3545 dst
->i
[3] = util_last_bit_signed(src
->i
[3]) - 1;
3549 micro_umsb(union tgsi_exec_channel
*dst
,
3550 const union tgsi_exec_channel
*src
)
3552 dst
->i
[0] = util_last_bit(src
->u
[0]) - 1;
3553 dst
->i
[1] = util_last_bit(src
->u
[1]) - 1;
3554 dst
->i
[2] = util_last_bit(src
->u
[2]) - 1;
3555 dst
->i
[3] = util_last_bit(src
->u
[3]) - 1;
3560 struct tgsi_exec_machine
*mach
,
3561 const struct tgsi_full_instruction
*inst
,
3564 union tgsi_exec_channel r
[10];
3568 switch (inst
->Instruction
.Opcode
) {
3569 case TGSI_OPCODE_ARL
:
3570 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3573 case TGSI_OPCODE_MOV
:
3574 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3577 case TGSI_OPCODE_LIT
:
3578 exec_lit(mach
, inst
);
3581 case TGSI_OPCODE_RCP
:
3582 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3585 case TGSI_OPCODE_RSQ
:
3586 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3589 case TGSI_OPCODE_EXP
:
3590 exec_exp(mach
, inst
);
3593 case TGSI_OPCODE_LOG
:
3594 exec_log(mach
, inst
);
3597 case TGSI_OPCODE_MUL
:
3598 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3601 case TGSI_OPCODE_ADD
:
3602 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3605 case TGSI_OPCODE_DP3
:
3606 exec_dp3(mach
, inst
);
3609 case TGSI_OPCODE_DP4
:
3610 exec_dp4(mach
, inst
);
3613 case TGSI_OPCODE_DST
:
3614 exec_dst(mach
, inst
);
3617 case TGSI_OPCODE_MIN
:
3618 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3621 case TGSI_OPCODE_MAX
:
3622 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3625 case TGSI_OPCODE_SLT
:
3626 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3629 case TGSI_OPCODE_SGE
:
3630 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3633 case TGSI_OPCODE_MAD
:
3634 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3637 case TGSI_OPCODE_SUB
:
3638 exec_vector_binary(mach
, inst
, micro_sub
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3641 case TGSI_OPCODE_LRP
:
3642 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3645 case TGSI_OPCODE_CND
:
3646 exec_vector_trinary(mach
, inst
, micro_cnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3649 case TGSI_OPCODE_SQRT
:
3650 exec_scalar_unary(mach
, inst
, micro_sqrt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3653 case TGSI_OPCODE_DP2A
:
3654 exec_dp2a(mach
, inst
);
3657 case TGSI_OPCODE_FRC
:
3658 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3661 case TGSI_OPCODE_CLAMP
:
3662 exec_vector_trinary(mach
, inst
, micro_clamp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3665 case TGSI_OPCODE_FLR
:
3666 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3669 case TGSI_OPCODE_ROUND
:
3670 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3673 case TGSI_OPCODE_EX2
:
3674 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3677 case TGSI_OPCODE_LG2
:
3678 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3681 case TGSI_OPCODE_POW
:
3682 exec_scalar_binary(mach
, inst
, micro_pow
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3685 case TGSI_OPCODE_XPD
:
3686 exec_xpd(mach
, inst
);
3689 case TGSI_OPCODE_ABS
:
3690 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3693 case TGSI_OPCODE_DPH
:
3694 exec_dph(mach
, inst
);
3697 case TGSI_OPCODE_COS
:
3698 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3701 case TGSI_OPCODE_DDX
:
3702 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3705 case TGSI_OPCODE_DDY
:
3706 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3709 case TGSI_OPCODE_KILL
:
3710 exec_kill (mach
, inst
);
3713 case TGSI_OPCODE_KILL_IF
:
3714 exec_kill_if (mach
, inst
);
3717 case TGSI_OPCODE_PK2H
:
3721 case TGSI_OPCODE_PK2US
:
3725 case TGSI_OPCODE_PK4B
:
3729 case TGSI_OPCODE_PK4UB
:
3733 case TGSI_OPCODE_SEQ
:
3734 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3737 case TGSI_OPCODE_SFL
:
3738 exec_vector(mach
, inst
, micro_sfl
, TGSI_EXEC_DATA_FLOAT
);
3741 case TGSI_OPCODE_SGT
:
3742 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3745 case TGSI_OPCODE_SIN
:
3746 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3749 case TGSI_OPCODE_SLE
:
3750 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3753 case TGSI_OPCODE_SNE
:
3754 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3757 case TGSI_OPCODE_STR
:
3758 exec_vector(mach
, inst
, micro_str
, TGSI_EXEC_DATA_FLOAT
);
3761 case TGSI_OPCODE_TEX
:
3762 /* simple texture lookup */
3763 /* src[0] = texcoord */
3764 /* src[1] = sampler unit */
3765 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 1);
3768 case TGSI_OPCODE_TXB
:
3769 /* Texture lookup with lod bias */
3770 /* src[0] = texcoord (src[0].w = LOD bias) */
3771 /* src[1] = sampler unit */
3772 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 1);
3775 case TGSI_OPCODE_TXD
:
3776 /* Texture lookup with explict partial derivatives */
3777 /* src[0] = texcoord */
3778 /* src[1] = d[strq]/dx */
3779 /* src[2] = d[strq]/dy */
3780 /* src[3] = sampler unit */
3781 exec_txd(mach
, inst
);
3784 case TGSI_OPCODE_TXL
:
3785 /* Texture lookup with explit LOD */
3786 /* src[0] = texcoord (src[0].w = LOD) */
3787 /* src[1] = sampler unit */
3788 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 1);
3791 case TGSI_OPCODE_TXP
:
3792 /* Texture lookup with projection */
3793 /* src[0] = texcoord (src[0].w = projection) */
3794 /* src[1] = sampler unit */
3795 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
, 1);
3798 case TGSI_OPCODE_UP2H
:
3802 case TGSI_OPCODE_UP2US
:
3806 case TGSI_OPCODE_UP4B
:
3810 case TGSI_OPCODE_UP4UB
:
3814 case TGSI_OPCODE_ARR
:
3815 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3818 case TGSI_OPCODE_BRA
:
3822 case TGSI_OPCODE_CAL
:
3823 /* skip the call if no execution channels are enabled */
3824 if (mach
->ExecMask
) {
3827 /* First, record the depths of the execution stacks.
3828 * This is important for deeply nested/looped return statements.
3829 * We have to unwind the stacks by the correct amount. For a
3830 * real code generator, we could determine the number of entries
3831 * to pop off each stack with simple static analysis and avoid
3832 * implementing this data structure at run time.
3834 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
3835 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
3836 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
3837 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
3838 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
3839 /* note that PC was already incremented above */
3840 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
3842 mach
->CallStackTop
++;
3844 /* Second, push the Cond, Loop, Cont, Func stacks */
3845 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3846 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3847 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3848 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3849 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3850 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
3852 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3853 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3854 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3855 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3856 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3857 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
3859 /* Finally, jump to the subroutine */
3860 *pc
= inst
->Label
.Label
;
3864 case TGSI_OPCODE_RET
:
3865 mach
->FuncMask
&= ~mach
->ExecMask
;
3866 UPDATE_EXEC_MASK(mach
);
3868 if (mach
->FuncMask
== 0x0) {
3869 /* really return now (otherwise, keep executing */
3871 if (mach
->CallStackTop
== 0) {
3872 /* returning from main() */
3873 mach
->CondStackTop
= 0;
3874 mach
->LoopStackTop
= 0;
3879 assert(mach
->CallStackTop
> 0);
3880 mach
->CallStackTop
--;
3882 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3883 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3885 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3886 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3888 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3889 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3891 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3892 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3894 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3895 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3897 assert(mach
->FuncStackTop
> 0);
3898 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3900 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3902 UPDATE_EXEC_MASK(mach
);
3906 case TGSI_OPCODE_SSG
:
3907 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3910 case TGSI_OPCODE_CMP
:
3911 exec_vector_trinary(mach
, inst
, micro_cmp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3914 case TGSI_OPCODE_SCS
:
3915 exec_scs(mach
, inst
);
3918 case TGSI_OPCODE_DIV
:
3919 exec_vector_binary(mach
, inst
, micro_div
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3922 case TGSI_OPCODE_DP2
:
3923 exec_dp2(mach
, inst
);
3926 case TGSI_OPCODE_IF
:
3928 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3929 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3930 FETCH( &r
[0], 0, TGSI_CHAN_X
);
3931 /* update CondMask */
3933 mach
->CondMask
&= ~0x1;
3936 mach
->CondMask
&= ~0x2;
3939 mach
->CondMask
&= ~0x4;
3942 mach
->CondMask
&= ~0x8;
3944 UPDATE_EXEC_MASK(mach
);
3945 /* Todo: If CondMask==0, jump to ELSE */
3948 case TGSI_OPCODE_UIF
:
3950 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3951 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3952 IFETCH( &r
[0], 0, TGSI_CHAN_X
);
3953 /* update CondMask */
3955 mach
->CondMask
&= ~0x1;
3958 mach
->CondMask
&= ~0x2;
3961 mach
->CondMask
&= ~0x4;
3964 mach
->CondMask
&= ~0x8;
3966 UPDATE_EXEC_MASK(mach
);
3967 /* Todo: If CondMask==0, jump to ELSE */
3970 case TGSI_OPCODE_ELSE
:
3971 /* invert CondMask wrt previous mask */
3974 assert(mach
->CondStackTop
> 0);
3975 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3976 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3977 UPDATE_EXEC_MASK(mach
);
3978 /* Todo: If CondMask==0, jump to ENDIF */
3982 case TGSI_OPCODE_ENDIF
:
3984 assert(mach
->CondStackTop
> 0);
3985 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3986 UPDATE_EXEC_MASK(mach
);
3989 case TGSI_OPCODE_END
:
3990 /* make sure we end primitives which haven't
3991 * been explicitly emitted */
3992 conditional_emit_primitive(mach
);
3993 /* halt execution */
3997 case TGSI_OPCODE_PUSHA
:
4001 case TGSI_OPCODE_POPA
:
4005 case TGSI_OPCODE_CEIL
:
4006 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4009 case TGSI_OPCODE_I2F
:
4010 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
4013 case TGSI_OPCODE_NOT
:
4014 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4017 case TGSI_OPCODE_TRUNC
:
4018 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
4021 case TGSI_OPCODE_SHL
:
4022 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4025 case TGSI_OPCODE_AND
:
4026 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4029 case TGSI_OPCODE_OR
:
4030 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4033 case TGSI_OPCODE_MOD
:
4034 exec_vector_binary(mach
, inst
, micro_mod
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4037 case TGSI_OPCODE_XOR
:
4038 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4041 case TGSI_OPCODE_SAD
:
4045 case TGSI_OPCODE_TXF
:
4046 exec_txf(mach
, inst
);
4049 case TGSI_OPCODE_TXQ
:
4050 exec_txq(mach
, inst
);
4053 case TGSI_OPCODE_EMIT
:
4057 case TGSI_OPCODE_ENDPRIM
:
4058 emit_primitive(mach
);
4061 case TGSI_OPCODE_BGNLOOP
:
4062 /* push LoopMask and ContMasks */
4063 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4064 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4065 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4066 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
4068 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
4069 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
4070 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
4071 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
4072 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
4075 case TGSI_OPCODE_ENDLOOP
:
4076 /* Restore ContMask, but don't pop */
4077 assert(mach
->ContStackTop
> 0);
4078 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
4079 UPDATE_EXEC_MASK(mach
);
4080 if (mach
->ExecMask
) {
4081 /* repeat loop: jump to instruction just past BGNLOOP */
4082 assert(mach
->LoopLabelStackTop
> 0);
4083 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
4086 /* exit loop: pop LoopMask */
4087 assert(mach
->LoopStackTop
> 0);
4088 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
4090 assert(mach
->ContStackTop
> 0);
4091 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
4092 assert(mach
->LoopLabelStackTop
> 0);
4093 --mach
->LoopLabelStackTop
;
4095 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
4097 UPDATE_EXEC_MASK(mach
);
4100 case TGSI_OPCODE_BRK
:
4104 case TGSI_OPCODE_CONT
:
4105 /* turn off cont channels for each enabled exec channel */
4106 mach
->ContMask
&= ~mach
->ExecMask
;
4107 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4108 UPDATE_EXEC_MASK(mach
);
4111 case TGSI_OPCODE_BGNSUB
:
4115 case TGSI_OPCODE_ENDSUB
:
4117 * XXX: This really should be a no-op. We should never reach this opcode.
4120 assert(mach
->CallStackTop
> 0);
4121 mach
->CallStackTop
--;
4123 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
4124 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
4126 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
4127 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
4129 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
4130 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
4132 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
4133 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
4135 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
4136 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
4138 assert(mach
->FuncStackTop
> 0);
4139 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
4141 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
4143 UPDATE_EXEC_MASK(mach
);
4146 case TGSI_OPCODE_NOP
:
4149 case TGSI_OPCODE_BREAKC
:
4150 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
4151 /* update CondMask */
4152 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
4153 mach
->LoopMask
&= ~0x1;
4155 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
4156 mach
->LoopMask
&= ~0x2;
4158 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
4159 mach
->LoopMask
&= ~0x4;
4161 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
4162 mach
->LoopMask
&= ~0x8;
4164 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4165 UPDATE_EXEC_MASK(mach
);
4168 case TGSI_OPCODE_F2I
:
4169 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
4172 case TGSI_OPCODE_FSEQ
:
4173 exec_vector_binary(mach
, inst
, micro_fseq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4176 case TGSI_OPCODE_FSGE
:
4177 exec_vector_binary(mach
, inst
, micro_fsge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4180 case TGSI_OPCODE_FSLT
:
4181 exec_vector_binary(mach
, inst
, micro_fslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4184 case TGSI_OPCODE_FSNE
:
4185 exec_vector_binary(mach
, inst
, micro_fsne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4188 case TGSI_OPCODE_IDIV
:
4189 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4192 case TGSI_OPCODE_IMAX
:
4193 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4196 case TGSI_OPCODE_IMIN
:
4197 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4200 case TGSI_OPCODE_INEG
:
4201 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4204 case TGSI_OPCODE_ISGE
:
4205 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4208 case TGSI_OPCODE_ISHR
:
4209 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4212 case TGSI_OPCODE_ISLT
:
4213 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4216 case TGSI_OPCODE_F2U
:
4217 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4220 case TGSI_OPCODE_U2F
:
4221 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
4224 case TGSI_OPCODE_UADD
:
4225 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4228 case TGSI_OPCODE_UDIV
:
4229 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4232 case TGSI_OPCODE_UMAD
:
4233 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4236 case TGSI_OPCODE_UMAX
:
4237 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4240 case TGSI_OPCODE_UMIN
:
4241 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4244 case TGSI_OPCODE_UMOD
:
4245 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4248 case TGSI_OPCODE_UMUL
:
4249 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4252 case TGSI_OPCODE_IMUL_HI
:
4253 exec_vector_binary(mach
, inst
, micro_imul_hi
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4256 case TGSI_OPCODE_UMUL_HI
:
4257 exec_vector_binary(mach
, inst
, micro_umul_hi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4260 case TGSI_OPCODE_USEQ
:
4261 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4264 case TGSI_OPCODE_USGE
:
4265 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4268 case TGSI_OPCODE_USHR
:
4269 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4272 case TGSI_OPCODE_USLT
:
4273 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4276 case TGSI_OPCODE_USNE
:
4277 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4280 case TGSI_OPCODE_SWITCH
:
4281 exec_switch(mach
, inst
);
4284 case TGSI_OPCODE_CASE
:
4285 exec_case(mach
, inst
);
4288 case TGSI_OPCODE_DEFAULT
:
4292 case TGSI_OPCODE_ENDSWITCH
:
4293 exec_endswitch(mach
);
4296 case TGSI_OPCODE_SAMPLE_I
:
4297 exec_txf(mach
, inst
);
4300 case TGSI_OPCODE_SAMPLE_I_MS
:
4304 case TGSI_OPCODE_SAMPLE
:
4305 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, FALSE
);
4308 case TGSI_OPCODE_SAMPLE_B
:
4309 exec_sample(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, FALSE
);
4312 case TGSI_OPCODE_SAMPLE_C
:
4313 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, TRUE
);
4316 case TGSI_OPCODE_SAMPLE_C_LZ
:
4317 exec_sample(mach
, inst
, TEX_MODIFIER_LEVEL_ZERO
, TRUE
);
4320 case TGSI_OPCODE_SAMPLE_D
:
4321 exec_sample_d(mach
, inst
);
4324 case TGSI_OPCODE_SAMPLE_L
:
4325 exec_sample(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, FALSE
);
4328 case TGSI_OPCODE_GATHER4
:
4332 case TGSI_OPCODE_SVIEWINFO
:
4333 exec_txq(mach
, inst
);
4336 case TGSI_OPCODE_SAMPLE_POS
:
4340 case TGSI_OPCODE_SAMPLE_INFO
:
4344 case TGSI_OPCODE_UARL
:
4345 exec_vector_unary(mach
, inst
, micro_uarl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4348 case TGSI_OPCODE_UCMP
:
4349 exec_vector_trinary(mach
, inst
, micro_ucmp
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4352 case TGSI_OPCODE_IABS
:
4353 exec_vector_unary(mach
, inst
, micro_iabs
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4356 case TGSI_OPCODE_ISSG
:
4357 exec_vector_unary(mach
, inst
, micro_isgn
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4360 case TGSI_OPCODE_TEX2
:
4361 /* simple texture lookup */
4362 /* src[0] = texcoord */
4363 /* src[1] = compare */
4364 /* src[2] = sampler unit */
4365 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 2);
4367 case TGSI_OPCODE_TXB2
:
4368 /* simple texture lookup */
4369 /* src[0] = texcoord */
4371 /* src[2] = sampler unit */
4372 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 2);
4374 case TGSI_OPCODE_TXL2
:
4375 /* simple texture lookup */
4376 /* src[0] = texcoord */
4378 /* src[2] = sampler unit */
4379 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 2);
4382 case TGSI_OPCODE_IBFE
:
4383 exec_vector_trinary(mach
, inst
, micro_ibfe
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4385 case TGSI_OPCODE_UBFE
:
4386 exec_vector_trinary(mach
, inst
, micro_ubfe
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4388 case TGSI_OPCODE_BFI
:
4389 exec_vector_quaternary(mach
, inst
, micro_bfi
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4391 case TGSI_OPCODE_BREV
:
4392 exec_vector_unary(mach
, inst
, micro_brev
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4394 case TGSI_OPCODE_POPC
:
4395 exec_vector_unary(mach
, inst
, micro_popc
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4397 case TGSI_OPCODE_LSB
:
4398 exec_vector_unary(mach
, inst
, micro_lsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4400 case TGSI_OPCODE_IMSB
:
4401 exec_vector_unary(mach
, inst
, micro_imsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4403 case TGSI_OPCODE_UMSB
:
4404 exec_vector_unary(mach
, inst
, micro_umsb
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4413 * Run TGSI interpreter.
4414 * \return bitmask of "alive" quad components
4417 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
4421 uint default_mask
= 0xf;
4423 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
4424 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
4426 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
4427 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
4428 mach
->Primitives
[0] = 0;
4429 /* GS runs on a single primitive for now */
4433 mach
->CondMask
= default_mask
;
4434 mach
->LoopMask
= default_mask
;
4435 mach
->ContMask
= default_mask
;
4436 mach
->FuncMask
= default_mask
;
4437 mach
->ExecMask
= default_mask
;
4439 mach
->Switch
.mask
= default_mask
;
4441 assert(mach
->CondStackTop
== 0);
4442 assert(mach
->LoopStackTop
== 0);
4443 assert(mach
->ContStackTop
== 0);
4444 assert(mach
->SwitchStackTop
== 0);
4445 assert(mach
->BreakStackTop
== 0);
4446 assert(mach
->CallStackTop
== 0);
4449 /* execute declarations (interpolants) */
4450 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
4451 exec_declaration( mach
, mach
->Declarations
+i
);
4456 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
4457 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
4460 memset(mach
->Temps
, 0, sizeof(temps
));
4461 memset(mach
->Outputs
, 0, sizeof(outputs
));
4462 memset(temps
, 0, sizeof(temps
));
4463 memset(outputs
, 0, sizeof(outputs
));
4466 /* execute instructions, until pc is set to -1 */
4472 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
4475 assert(pc
< (int) mach
->NumInstructions
);
4476 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
4479 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
4480 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
4483 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
4484 debug_printf("TEMP[%2u] = ", i
);
4485 for (j
= 0; j
< 4; j
++) {
4489 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4490 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
4491 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
4492 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
4493 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
4497 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
4498 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
4501 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
4502 debug_printf("OUT[%2u] = ", i
);
4503 for (j
= 0; j
< 4; j
++) {
4507 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4508 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
4509 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
4510 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
4511 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
4520 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
4521 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
4523 * Scale back depth component.
4525 for (i
= 0; i
< 4; i
++)
4526 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
4530 /* Strictly speaking, these assertions aren't really needed but they
4531 * can potentially catch some bugs in the control flow code.
4533 assert(mach
->CondStackTop
== 0);
4534 assert(mach
->LoopStackTop
== 0);
4535 assert(mach
->ContStackTop
== 0);
4536 assert(mach
->SwitchStackTop
== 0);
4537 assert(mach
->BreakStackTop
== 0);
4538 assert(mach
->CallStackTop
== 0);
4540 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];