1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2009-2010 VMware, Inc. All rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 * TGSI interpreter/executor.
32 * Flow control information:
34 * Since we operate on 'quads' (4 pixels or 4 vertices in parallel)
35 * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special
36 * care since a condition may be true for some quad components but false
37 * for other components.
39 * We basically execute all statements (even if they're in the part of
40 * an IF/ELSE clause that's "not taken") and use a special mask to
41 * control writing to destination registers. This is the ExecMask.
44 * The ExecMask is computed from three other masks (CondMask, LoopMask and
45 * ContMask) which are controlled by the flow control instructions (namely:
46 * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT).
54 #include "pipe/p_compiler.h"
55 #include "pipe/p_state.h"
56 #include "pipe/p_shader_tokens.h"
57 #include "tgsi/tgsi_dump.h"
58 #include "tgsi/tgsi_parse.h"
59 #include "tgsi/tgsi_util.h"
60 #include "tgsi_exec.h"
61 #include "util/u_memory.h"
62 #include "util/u_math.h"
67 #define TILE_TOP_LEFT 0
68 #define TILE_TOP_RIGHT 1
69 #define TILE_BOTTOM_LEFT 2
70 #define TILE_BOTTOM_RIGHT 3
73 micro_abs(union tgsi_exec_channel
*dst
,
74 const union tgsi_exec_channel
*src
)
76 dst
->f
[0] = fabsf(src
->f
[0]);
77 dst
->f
[1] = fabsf(src
->f
[1]);
78 dst
->f
[2] = fabsf(src
->f
[2]);
79 dst
->f
[3] = fabsf(src
->f
[3]);
83 micro_arl(union tgsi_exec_channel
*dst
,
84 const union tgsi_exec_channel
*src
)
86 dst
->i
[0] = (int)floorf(src
->f
[0]);
87 dst
->i
[1] = (int)floorf(src
->f
[1]);
88 dst
->i
[2] = (int)floorf(src
->f
[2]);
89 dst
->i
[3] = (int)floorf(src
->f
[3]);
93 micro_arr(union tgsi_exec_channel
*dst
,
94 const union tgsi_exec_channel
*src
)
96 dst
->i
[0] = (int)floorf(src
->f
[0] + 0.5f
);
97 dst
->i
[1] = (int)floorf(src
->f
[1] + 0.5f
);
98 dst
->i
[2] = (int)floorf(src
->f
[2] + 0.5f
);
99 dst
->i
[3] = (int)floorf(src
->f
[3] + 0.5f
);
103 micro_ceil(union tgsi_exec_channel
*dst
,
104 const union tgsi_exec_channel
*src
)
106 dst
->f
[0] = ceilf(src
->f
[0]);
107 dst
->f
[1] = ceilf(src
->f
[1]);
108 dst
->f
[2] = ceilf(src
->f
[2]);
109 dst
->f
[3] = ceilf(src
->f
[3]);
113 micro_clamp(union tgsi_exec_channel
*dst
,
114 const union tgsi_exec_channel
*src0
,
115 const union tgsi_exec_channel
*src1
,
116 const union tgsi_exec_channel
*src2
)
118 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src1
->f
[0] : src0
->f
[0] > src2
->f
[0] ? src2
->f
[0] : src0
->f
[0];
119 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src1
->f
[1] : src0
->f
[1] > src2
->f
[1] ? src2
->f
[1] : src0
->f
[1];
120 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src1
->f
[2] : src0
->f
[2] > src2
->f
[2] ? src2
->f
[2] : src0
->f
[2];
121 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src1
->f
[3] : src0
->f
[3] > src2
->f
[3] ? src2
->f
[3] : src0
->f
[3];
125 micro_cmp(union tgsi_exec_channel
*dst
,
126 const union tgsi_exec_channel
*src0
,
127 const union tgsi_exec_channel
*src1
,
128 const union tgsi_exec_channel
*src2
)
130 dst
->f
[0] = src0
->f
[0] < 0.0f
? src1
->f
[0] : src2
->f
[0];
131 dst
->f
[1] = src0
->f
[1] < 0.0f
? src1
->f
[1] : src2
->f
[1];
132 dst
->f
[2] = src0
->f
[2] < 0.0f
? src1
->f
[2] : src2
->f
[2];
133 dst
->f
[3] = src0
->f
[3] < 0.0f
? src1
->f
[3] : src2
->f
[3];
137 micro_cnd(union tgsi_exec_channel
*dst
,
138 const union tgsi_exec_channel
*src0
,
139 const union tgsi_exec_channel
*src1
,
140 const union tgsi_exec_channel
*src2
)
142 dst
->f
[0] = src2
->f
[0] > 0.5f
? src0
->f
[0] : src1
->f
[0];
143 dst
->f
[1] = src2
->f
[1] > 0.5f
? src0
->f
[1] : src1
->f
[1];
144 dst
->f
[2] = src2
->f
[2] > 0.5f
? src0
->f
[2] : src1
->f
[2];
145 dst
->f
[3] = src2
->f
[3] > 0.5f
? src0
->f
[3] : src1
->f
[3];
149 micro_cos(union tgsi_exec_channel
*dst
,
150 const union tgsi_exec_channel
*src
)
152 dst
->f
[0] = cosf(src
->f
[0]);
153 dst
->f
[1] = cosf(src
->f
[1]);
154 dst
->f
[2] = cosf(src
->f
[2]);
155 dst
->f
[3] = cosf(src
->f
[3]);
159 micro_ddx(union tgsi_exec_channel
*dst
,
160 const union tgsi_exec_channel
*src
)
165 dst
->f
[3] = src
->f
[TILE_BOTTOM_RIGHT
] - src
->f
[TILE_BOTTOM_LEFT
];
169 micro_ddy(union tgsi_exec_channel
*dst
,
170 const union tgsi_exec_channel
*src
)
175 dst
->f
[3] = src
->f
[TILE_BOTTOM_LEFT
] - src
->f
[TILE_TOP_LEFT
];
179 micro_exp2(union tgsi_exec_channel
*dst
,
180 const union tgsi_exec_channel
*src
)
183 dst
->f
[0] = util_fast_exp2(src
->f
[0]);
184 dst
->f
[1] = util_fast_exp2(src
->f
[1]);
185 dst
->f
[2] = util_fast_exp2(src
->f
[2]);
186 dst
->f
[3] = util_fast_exp2(src
->f
[3]);
189 /* Inf is okay for this instruction, so clamp it to silence assertions. */
191 union tgsi_exec_channel clamped
;
193 for (i
= 0; i
< 4; i
++) {
194 if (src
->f
[i
] > 127.99999f
) {
195 clamped
.f
[i
] = 127.99999f
;
196 } else if (src
->f
[i
] < -126.99999f
) {
197 clamped
.f
[i
] = -126.99999f
;
199 clamped
.f
[i
] = src
->f
[i
];
205 dst
->f
[0] = powf(2.0f
, src
->f
[0]);
206 dst
->f
[1] = powf(2.0f
, src
->f
[1]);
207 dst
->f
[2] = powf(2.0f
, src
->f
[2]);
208 dst
->f
[3] = powf(2.0f
, src
->f
[3]);
209 #endif /* FAST_MATH */
213 micro_flr(union tgsi_exec_channel
*dst
,
214 const union tgsi_exec_channel
*src
)
216 dst
->f
[0] = floorf(src
->f
[0]);
217 dst
->f
[1] = floorf(src
->f
[1]);
218 dst
->f
[2] = floorf(src
->f
[2]);
219 dst
->f
[3] = floorf(src
->f
[3]);
223 micro_frc(union tgsi_exec_channel
*dst
,
224 const union tgsi_exec_channel
*src
)
226 dst
->f
[0] = src
->f
[0] - floorf(src
->f
[0]);
227 dst
->f
[1] = src
->f
[1] - floorf(src
->f
[1]);
228 dst
->f
[2] = src
->f
[2] - floorf(src
->f
[2]);
229 dst
->f
[3] = src
->f
[3] - floorf(src
->f
[3]);
233 micro_iabs(union tgsi_exec_channel
*dst
,
234 const union tgsi_exec_channel
*src
)
236 dst
->i
[0] = src
->i
[0] >= 0 ? src
->i
[0] : -src
->i
[0];
237 dst
->i
[1] = src
->i
[1] >= 0 ? src
->i
[1] : -src
->i
[1];
238 dst
->i
[2] = src
->i
[2] >= 0 ? src
->i
[2] : -src
->i
[2];
239 dst
->i
[3] = src
->i
[3] >= 0 ? src
->i
[3] : -src
->i
[3];
243 micro_ineg(union tgsi_exec_channel
*dst
,
244 const union tgsi_exec_channel
*src
)
246 dst
->i
[0] = -src
->i
[0];
247 dst
->i
[1] = -src
->i
[1];
248 dst
->i
[2] = -src
->i
[2];
249 dst
->i
[3] = -src
->i
[3];
253 micro_lg2(union tgsi_exec_channel
*dst
,
254 const union tgsi_exec_channel
*src
)
257 dst
->f
[0] = util_fast_log2(src
->f
[0]);
258 dst
->f
[1] = util_fast_log2(src
->f
[1]);
259 dst
->f
[2] = util_fast_log2(src
->f
[2]);
260 dst
->f
[3] = util_fast_log2(src
->f
[3]);
262 dst
->f
[0] = logf(src
->f
[0]) * 1.442695f
;
263 dst
->f
[1] = logf(src
->f
[1]) * 1.442695f
;
264 dst
->f
[2] = logf(src
->f
[2]) * 1.442695f
;
265 dst
->f
[3] = logf(src
->f
[3]) * 1.442695f
;
270 micro_lrp(union tgsi_exec_channel
*dst
,
271 const union tgsi_exec_channel
*src0
,
272 const union tgsi_exec_channel
*src1
,
273 const union tgsi_exec_channel
*src2
)
275 dst
->f
[0] = src0
->f
[0] * (src1
->f
[0] - src2
->f
[0]) + src2
->f
[0];
276 dst
->f
[1] = src0
->f
[1] * (src1
->f
[1] - src2
->f
[1]) + src2
->f
[1];
277 dst
->f
[2] = src0
->f
[2] * (src1
->f
[2] - src2
->f
[2]) + src2
->f
[2];
278 dst
->f
[3] = src0
->f
[3] * (src1
->f
[3] - src2
->f
[3]) + src2
->f
[3];
282 micro_mad(union tgsi_exec_channel
*dst
,
283 const union tgsi_exec_channel
*src0
,
284 const union tgsi_exec_channel
*src1
,
285 const union tgsi_exec_channel
*src2
)
287 dst
->f
[0] = src0
->f
[0] * src1
->f
[0] + src2
->f
[0];
288 dst
->f
[1] = src0
->f
[1] * src1
->f
[1] + src2
->f
[1];
289 dst
->f
[2] = src0
->f
[2] * src1
->f
[2] + src2
->f
[2];
290 dst
->f
[3] = src0
->f
[3] * src1
->f
[3] + src2
->f
[3];
294 micro_mov(union tgsi_exec_channel
*dst
,
295 const union tgsi_exec_channel
*src
)
297 dst
->u
[0] = src
->u
[0];
298 dst
->u
[1] = src
->u
[1];
299 dst
->u
[2] = src
->u
[2];
300 dst
->u
[3] = src
->u
[3];
304 micro_rcp(union tgsi_exec_channel
*dst
,
305 const union tgsi_exec_channel
*src
)
307 #if 0 /* for debugging */
308 assert(src
->f
[0] != 0.0f
);
309 assert(src
->f
[1] != 0.0f
);
310 assert(src
->f
[2] != 0.0f
);
311 assert(src
->f
[3] != 0.0f
);
313 dst
->f
[0] = 1.0f
/ src
->f
[0];
314 dst
->f
[1] = 1.0f
/ src
->f
[1];
315 dst
->f
[2] = 1.0f
/ src
->f
[2];
316 dst
->f
[3] = 1.0f
/ src
->f
[3];
320 micro_rnd(union tgsi_exec_channel
*dst
,
321 const union tgsi_exec_channel
*src
)
323 dst
->f
[0] = floorf(src
->f
[0] + 0.5f
);
324 dst
->f
[1] = floorf(src
->f
[1] + 0.5f
);
325 dst
->f
[2] = floorf(src
->f
[2] + 0.5f
);
326 dst
->f
[3] = floorf(src
->f
[3] + 0.5f
);
330 micro_rsq(union tgsi_exec_channel
*dst
,
331 const union tgsi_exec_channel
*src
)
333 #if 0 /* for debugging */
334 assert(src
->f
[0] != 0.0f
);
335 assert(src
->f
[1] != 0.0f
);
336 assert(src
->f
[2] != 0.0f
);
337 assert(src
->f
[3] != 0.0f
);
339 dst
->f
[0] = 1.0f
/ sqrtf(fabsf(src
->f
[0]));
340 dst
->f
[1] = 1.0f
/ sqrtf(fabsf(src
->f
[1]));
341 dst
->f
[2] = 1.0f
/ sqrtf(fabsf(src
->f
[2]));
342 dst
->f
[3] = 1.0f
/ sqrtf(fabsf(src
->f
[3]));
346 micro_seq(union tgsi_exec_channel
*dst
,
347 const union tgsi_exec_channel
*src0
,
348 const union tgsi_exec_channel
*src1
)
350 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? 1.0f
: 0.0f
;
351 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? 1.0f
: 0.0f
;
352 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? 1.0f
: 0.0f
;
353 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? 1.0f
: 0.0f
;
357 micro_sge(union tgsi_exec_channel
*dst
,
358 const union tgsi_exec_channel
*src0
,
359 const union tgsi_exec_channel
*src1
)
361 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? 1.0f
: 0.0f
;
362 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? 1.0f
: 0.0f
;
363 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? 1.0f
: 0.0f
;
364 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? 1.0f
: 0.0f
;
368 micro_sgn(union tgsi_exec_channel
*dst
,
369 const union tgsi_exec_channel
*src
)
371 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
372 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
373 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
374 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
378 micro_isgn(union tgsi_exec_channel
*dst
,
379 const union tgsi_exec_channel
*src
)
381 dst
->i
[0] = src
->i
[0] < 0 ? -1 : src
->i
[0] > 0 ? 1 : 0;
382 dst
->i
[1] = src
->i
[1] < 0 ? -1 : src
->i
[1] > 0 ? 1 : 0;
383 dst
->i
[2] = src
->i
[2] < 0 ? -1 : src
->i
[2] > 0 ? 1 : 0;
384 dst
->i
[3] = src
->i
[3] < 0 ? -1 : src
->i
[3] > 0 ? 1 : 0;
388 micro_sgt(union tgsi_exec_channel
*dst
,
389 const union tgsi_exec_channel
*src0
,
390 const union tgsi_exec_channel
*src1
)
392 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? 1.0f
: 0.0f
;
393 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? 1.0f
: 0.0f
;
394 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? 1.0f
: 0.0f
;
395 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? 1.0f
: 0.0f
;
399 micro_sin(union tgsi_exec_channel
*dst
,
400 const union tgsi_exec_channel
*src
)
402 dst
->f
[0] = sinf(src
->f
[0]);
403 dst
->f
[1] = sinf(src
->f
[1]);
404 dst
->f
[2] = sinf(src
->f
[2]);
405 dst
->f
[3] = sinf(src
->f
[3]);
409 micro_sle(union tgsi_exec_channel
*dst
,
410 const union tgsi_exec_channel
*src0
,
411 const union tgsi_exec_channel
*src1
)
413 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? 1.0f
: 0.0f
;
414 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? 1.0f
: 0.0f
;
415 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? 1.0f
: 0.0f
;
416 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? 1.0f
: 0.0f
;
420 micro_slt(union tgsi_exec_channel
*dst
,
421 const union tgsi_exec_channel
*src0
,
422 const union tgsi_exec_channel
*src1
)
424 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? 1.0f
: 0.0f
;
425 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? 1.0f
: 0.0f
;
426 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? 1.0f
: 0.0f
;
427 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? 1.0f
: 0.0f
;
431 micro_sne(union tgsi_exec_channel
*dst
,
432 const union tgsi_exec_channel
*src0
,
433 const union tgsi_exec_channel
*src1
)
435 dst
->f
[0] = src0
->f
[0] != src1
->f
[0] ? 1.0f
: 0.0f
;
436 dst
->f
[1] = src0
->f
[1] != src1
->f
[1] ? 1.0f
: 0.0f
;
437 dst
->f
[2] = src0
->f
[2] != src1
->f
[2] ? 1.0f
: 0.0f
;
438 dst
->f
[3] = src0
->f
[3] != src1
->f
[3] ? 1.0f
: 0.0f
;
442 micro_sfl(union tgsi_exec_channel
*dst
)
451 micro_str(union tgsi_exec_channel
*dst
)
460 micro_trunc(union tgsi_exec_channel
*dst
,
461 const union tgsi_exec_channel
*src
)
463 dst
->f
[0] = (float)(int)src
->f
[0];
464 dst
->f
[1] = (float)(int)src
->f
[1];
465 dst
->f
[2] = (float)(int)src
->f
[2];
466 dst
->f
[3] = (float)(int)src
->f
[3];
470 enum tgsi_exec_datatype
{
471 TGSI_EXEC_DATA_FLOAT
,
477 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
479 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
480 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
481 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
482 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
483 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
484 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
487 /** The execution mask depends on the conditional mask and the loop mask */
488 #define UPDATE_EXEC_MASK(MACH) \
489 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
492 static const union tgsi_exec_channel ZeroVec
=
493 { { 0.0, 0.0, 0.0, 0.0 } };
495 static const union tgsi_exec_channel OneVec
= {
496 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
499 static const union tgsi_exec_channel P128Vec
= {
500 {128.0f
, 128.0f
, 128.0f
, 128.0f
}
503 static const union tgsi_exec_channel M128Vec
= {
504 {-128.0f
, -128.0f
, -128.0f
, -128.0f
}
509 * Assert that none of the float values in 'chan' are infinite or NaN.
510 * NaN and Inf may occur normally during program execution and should
511 * not lead to crashes, etc. But when debugging, it's helpful to catch
515 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
517 assert(!util_is_inf_or_nan((chan
)->f
[0]));
518 assert(!util_is_inf_or_nan((chan
)->f
[1]));
519 assert(!util_is_inf_or_nan((chan
)->f
[2]));
520 assert(!util_is_inf_or_nan((chan
)->f
[3]));
526 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
528 debug_printf("%s = {%f, %f, %f, %f}\n",
529 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
536 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
538 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
540 debug_printf("Temp[%u] =\n", index
);
541 for (i
= 0; i
< 4; i
++) {
542 debug_printf(" %c: { %f, %f, %f, %f }\n",
554 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine
*mach
,
557 const unsigned *buf_sizes
)
561 for (i
= 0; i
< num_bufs
; i
++) {
562 mach
->Consts
[i
] = bufs
[i
];
563 mach
->ConstsSize
[i
] = buf_sizes
[i
];
569 * Check if there's a potential src/dst register data dependency when
570 * using SOA execution.
573 * This would expand into:
578 * The second instruction will have the wrong value for t0 if executed as-is.
581 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
585 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
586 if (writemask
== TGSI_WRITEMASK_X
||
587 writemask
== TGSI_WRITEMASK_Y
||
588 writemask
== TGSI_WRITEMASK_Z
||
589 writemask
== TGSI_WRITEMASK_W
||
590 writemask
== TGSI_WRITEMASK_NONE
) {
591 /* no chance of data dependency */
595 /* loop over src regs */
596 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
597 if ((inst
->Src
[i
].Register
.File
==
598 inst
->Dst
[0].Register
.File
) &&
599 ((inst
->Src
[i
].Register
.Index
==
600 inst
->Dst
[0].Register
.Index
) ||
601 inst
->Src
[i
].Register
.Indirect
||
602 inst
->Dst
[0].Register
.Indirect
)) {
603 /* loop over dest channels */
604 uint channelsWritten
= 0x0;
605 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
606 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
607 /* check if we're reading a channel that's been written */
608 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
609 if (channelsWritten
& (1 << swizzle
)) {
613 channelsWritten
|= (1 << chan
);
623 * Initialize machine state by expanding tokens to full instructions,
624 * allocating temporary storage, setting up constants, etc.
625 * After this, we can call tgsi_exec_machine_run() many times.
628 tgsi_exec_machine_bind_shader(
629 struct tgsi_exec_machine
*mach
,
630 const struct tgsi_token
*tokens
,
632 struct tgsi_sampler
**samplers
)
635 struct tgsi_parse_context parse
;
636 struct tgsi_full_instruction
*instructions
;
637 struct tgsi_full_declaration
*declarations
;
638 uint maxInstructions
= 10, numInstructions
= 0;
639 uint maxDeclarations
= 10, numDeclarations
= 0;
642 tgsi_dump(tokens
, 0);
651 mach
->Tokens
= tokens
;
652 mach
->Samplers
= samplers
;
655 /* unbind and free all */
656 FREE(mach
->Declarations
);
657 mach
->Declarations
= NULL
;
658 mach
->NumDeclarations
= 0;
660 FREE(mach
->Instructions
);
661 mach
->Instructions
= NULL
;
662 mach
->NumInstructions
= 0;
667 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
668 if (k
!= TGSI_PARSE_OK
) {
669 debug_printf( "Problem parsing!\n" );
673 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
676 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
&&
677 !mach
->UsedGeometryShader
) {
678 struct tgsi_exec_vector
*inputs
;
679 struct tgsi_exec_vector
*outputs
;
681 inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
682 TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
,
688 outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
689 TGSI_MAX_TOTAL_VERTICES
, 16);
696 align_free(mach
->Inputs
);
697 align_free(mach
->Outputs
);
699 mach
->Inputs
= inputs
;
700 mach
->Outputs
= outputs
;
701 mach
->UsedGeometryShader
= TRUE
;
704 declarations
= (struct tgsi_full_declaration
*)
705 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
711 instructions
= (struct tgsi_full_instruction
*)
712 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
715 FREE( declarations
);
719 while( !tgsi_parse_end_of_tokens( &parse
) ) {
722 tgsi_parse_token( &parse
);
723 switch( parse
.FullToken
.Token
.Type
) {
724 case TGSI_TOKEN_TYPE_DECLARATION
:
725 /* save expanded declaration */
726 if (numDeclarations
== maxDeclarations
) {
727 declarations
= REALLOC(declarations
,
729 * sizeof(struct tgsi_full_declaration
),
730 (maxDeclarations
+ 10)
731 * sizeof(struct tgsi_full_declaration
));
732 maxDeclarations
+= 10;
734 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
736 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
737 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
742 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
==
743 TGSI_FILE_IMMEDIATE_ARRAY
) {
745 struct tgsi_full_declaration
*decl
=
746 &parse
.FullToken
.FullDeclaration
;
747 debug_assert(decl
->Range
.Last
< TGSI_EXEC_NUM_IMMEDIATES
);
748 for (reg
= decl
->Range
.First
; reg
<= decl
->Range
.Last
; ++reg
) {
749 for( i
= 0; i
< 4; i
++ ) {
750 int idx
= reg
* 4 + i
;
751 mach
->ImmArray
[reg
][i
] = decl
->ImmediateData
.u
[idx
].Float
;
755 memcpy(declarations
+ numDeclarations
,
756 &parse
.FullToken
.FullDeclaration
,
757 sizeof(declarations
[0]));
761 case TGSI_TOKEN_TYPE_IMMEDIATE
:
763 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
765 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
767 for( i
= 0; i
< size
; i
++ ) {
768 mach
->Imms
[mach
->ImmLimit
][i
] =
769 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
775 case TGSI_TOKEN_TYPE_INSTRUCTION
:
777 /* save expanded instruction */
778 if (numInstructions
== maxInstructions
) {
779 instructions
= REALLOC(instructions
,
781 * sizeof(struct tgsi_full_instruction
),
782 (maxInstructions
+ 10)
783 * sizeof(struct tgsi_full_instruction
));
784 maxInstructions
+= 10;
787 memcpy(instructions
+ numInstructions
,
788 &parse
.FullToken
.FullInstruction
,
789 sizeof(instructions
[0]));
794 case TGSI_TOKEN_TYPE_PROPERTY
:
801 tgsi_parse_free (&parse
);
803 FREE(mach
->Declarations
);
804 mach
->Declarations
= declarations
;
805 mach
->NumDeclarations
= numDeclarations
;
807 FREE(mach
->Instructions
);
808 mach
->Instructions
= instructions
;
809 mach
->NumInstructions
= numInstructions
;
813 struct tgsi_exec_machine
*
814 tgsi_exec_machine_create( void )
816 struct tgsi_exec_machine
*mach
;
819 mach
= align_malloc( sizeof *mach
, 16 );
823 memset(mach
, 0, sizeof(*mach
));
825 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
826 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
827 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
829 mach
->Inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_ATTRIBS
, 16);
830 mach
->Outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_ATTRIBS
, 16);
831 if (!mach
->Inputs
|| !mach
->Outputs
)
834 /* Setup constants needed by the SSE2 executor. */
835 for( i
= 0; i
< 4; i
++ ) {
836 mach
->Temps
[TGSI_EXEC_TEMP_00000000_I
].xyzw
[TGSI_EXEC_TEMP_00000000_C
].u
[i
] = 0x00000000;
837 mach
->Temps
[TGSI_EXEC_TEMP_7FFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_7FFFFFFF_C
].u
[i
] = 0x7FFFFFFF;
838 mach
->Temps
[TGSI_EXEC_TEMP_80000000_I
].xyzw
[TGSI_EXEC_TEMP_80000000_C
].u
[i
] = 0x80000000;
839 mach
->Temps
[TGSI_EXEC_TEMP_FFFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_FFFFFFFF_C
].u
[i
] = 0xFFFFFFFF; /* not used */
840 mach
->Temps
[TGSI_EXEC_TEMP_ONE_I
].xyzw
[TGSI_EXEC_TEMP_ONE_C
].f
[i
] = 1.0f
;
841 mach
->Temps
[TGSI_EXEC_TEMP_TWO_I
].xyzw
[TGSI_EXEC_TEMP_TWO_C
].f
[i
] = 2.0f
; /* not used */
842 mach
->Temps
[TGSI_EXEC_TEMP_128_I
].xyzw
[TGSI_EXEC_TEMP_128_C
].f
[i
] = 128.0f
;
843 mach
->Temps
[TGSI_EXEC_TEMP_MINUS_128_I
].xyzw
[TGSI_EXEC_TEMP_MINUS_128_C
].f
[i
] = -128.0f
;
844 mach
->Temps
[TGSI_EXEC_TEMP_THREE_I
].xyzw
[TGSI_EXEC_TEMP_THREE_C
].f
[i
] = 3.0f
;
845 mach
->Temps
[TGSI_EXEC_TEMP_HALF_I
].xyzw
[TGSI_EXEC_TEMP_HALF_C
].f
[i
] = 0.5f
;
849 /* silence warnings */
858 align_free(mach
->Inputs
);
859 align_free(mach
->Outputs
);
867 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
870 FREE(mach
->Instructions
);
871 FREE(mach
->Declarations
);
873 align_free(mach
->Inputs
);
874 align_free(mach
->Outputs
);
881 micro_add(union tgsi_exec_channel
*dst
,
882 const union tgsi_exec_channel
*src0
,
883 const union tgsi_exec_channel
*src1
)
885 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
886 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
887 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
888 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
893 union tgsi_exec_channel
*dst
,
894 const union tgsi_exec_channel
*src0
,
895 const union tgsi_exec_channel
*src1
)
897 if (src1
->f
[0] != 0) {
898 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
900 if (src1
->f
[1] != 0) {
901 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
903 if (src1
->f
[2] != 0) {
904 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
906 if (src1
->f
[3] != 0) {
907 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
912 micro_rcc(union tgsi_exec_channel
*dst
,
913 const union tgsi_exec_channel
*src
)
917 for (i
= 0; i
< 4; i
++) {
918 float recip
= 1.0f
/ src
->f
[i
];
921 if (recip
> 1.884467e+019f
) {
922 dst
->f
[i
] = 1.884467e+019f
;
924 else if (recip
< 5.42101e-020f
) {
925 dst
->f
[i
] = 5.42101e-020f
;
932 if (recip
< -1.884467e+019f
) {
933 dst
->f
[i
] = -1.884467e+019f
;
935 else if (recip
> -5.42101e-020f
) {
936 dst
->f
[i
] = -5.42101e-020f
;
947 union tgsi_exec_channel
*dst
,
948 const union tgsi_exec_channel
*src0
,
949 const union tgsi_exec_channel
*src1
,
950 const union tgsi_exec_channel
*src2
,
951 const union tgsi_exec_channel
*src3
)
953 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
954 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
955 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
956 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
960 micro_max(union tgsi_exec_channel
*dst
,
961 const union tgsi_exec_channel
*src0
,
962 const union tgsi_exec_channel
*src1
)
964 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
965 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
966 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
967 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
971 micro_min(union tgsi_exec_channel
*dst
,
972 const union tgsi_exec_channel
*src0
,
973 const union tgsi_exec_channel
*src1
)
975 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
976 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
977 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
978 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
982 micro_mul(union tgsi_exec_channel
*dst
,
983 const union tgsi_exec_channel
*src0
,
984 const union tgsi_exec_channel
*src1
)
986 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
987 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
988 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
989 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
994 union tgsi_exec_channel
*dst
,
995 const union tgsi_exec_channel
*src
)
997 dst
->f
[0] = -src
->f
[0];
998 dst
->f
[1] = -src
->f
[1];
999 dst
->f
[2] = -src
->f
[2];
1000 dst
->f
[3] = -src
->f
[3];
1005 union tgsi_exec_channel
*dst
,
1006 const union tgsi_exec_channel
*src0
,
1007 const union tgsi_exec_channel
*src1
)
1010 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
1011 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
1012 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
1013 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
1015 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
1016 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
1017 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
1018 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
1023 micro_sub(union tgsi_exec_channel
*dst
,
1024 const union tgsi_exec_channel
*src0
,
1025 const union tgsi_exec_channel
*src1
)
1027 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1028 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1029 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1030 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1034 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
1035 const uint chan_index
,
1038 const union tgsi_exec_channel
*index
,
1039 const union tgsi_exec_channel
*index2D
,
1040 union tgsi_exec_channel
*chan
)
1044 assert(swizzle
< 4);
1047 case TGSI_FILE_CONSTANT
:
1048 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1049 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
1050 assert(mach
->Consts
[index2D
->i
[i
]]);
1052 if (index
->i
[i
] < 0) {
1055 /* NOTE: copying the const value as a uint instead of float */
1056 const uint constbuf
= index2D
->i
[i
];
1057 const uint
*buf
= (const uint
*)mach
->Consts
[constbuf
];
1058 const int pos
= index
->i
[i
] * 4 + swizzle
;
1059 /* const buffer bounds check */
1060 if (pos
< 0 || pos
>= (int) mach
->ConstsSize
[constbuf
]) {
1062 /* Debug: print warning */
1063 static int count
= 0;
1065 debug_printf("TGSI Exec: const buffer index %d"
1066 " out of bounds\n", pos
);
1071 chan
->u
[i
] = buf
[pos
];
1076 case TGSI_FILE_INPUT
:
1077 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1079 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1080 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1081 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1082 index2D->i[i], index->i[i]);
1084 int pos
= index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
];
1086 assert(pos
< TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
);
1087 chan
->u
[i
] = mach
->Inputs
[pos
].xyzw
[swizzle
].u
[i
];
1091 case TGSI_FILE_SYSTEM_VALUE
:
1092 /* XXX no swizzling at this point. Will be needed if we put
1093 * gl_FragCoord, for example, in a sys value register.
1095 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1096 chan
->u
[i
] = mach
->SystemValue
[index
->i
[i
]].u
[i
];
1100 case TGSI_FILE_TEMPORARY
:
1101 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1102 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1103 assert(index2D
->i
[i
] == 0);
1105 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1109 case TGSI_FILE_TEMPORARY_ARRAY
:
1110 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1111 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1112 assert(index2D
->i
[i
] < TGSI_EXEC_NUM_TEMP_ARRAYS
);
1115 mach
->TempArray
[index2D
->i
[i
]][index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1119 case TGSI_FILE_IMMEDIATE
:
1120 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1121 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1122 assert(index2D
->i
[i
] == 0);
1124 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1128 case TGSI_FILE_IMMEDIATE_ARRAY
:
1129 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1130 assert(index2D
->i
[i
] == 0);
1132 chan
->f
[i
] = mach
->ImmArray
[index
->i
[i
]][swizzle
];
1136 case TGSI_FILE_ADDRESS
:
1137 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1138 assert(index
->i
[i
] >= 0);
1139 assert(index2D
->i
[i
] == 0);
1141 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1145 case TGSI_FILE_PREDICATE
:
1146 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1147 assert(index
->i
[i
] >= 0 && index
->i
[i
] < TGSI_EXEC_NUM_PREDS
);
1148 assert(index2D
->i
[i
] == 0);
1150 chan
->u
[i
] = mach
->Predicates
[0].xyzw
[swizzle
].u
[i
];
1154 case TGSI_FILE_OUTPUT
:
1155 /* vertex/fragment output vars can be read too */
1156 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1157 assert(index
->i
[i
] >= 0);
1158 assert(index2D
->i
[i
] == 0);
1160 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1166 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1173 fetch_source(const struct tgsi_exec_machine
*mach
,
1174 union tgsi_exec_channel
*chan
,
1175 const struct tgsi_full_src_register
*reg
,
1176 const uint chan_index
,
1177 enum tgsi_exec_datatype src_datatype
)
1179 union tgsi_exec_channel index
;
1180 union tgsi_exec_channel index2D
;
1183 /* We start with a direct index into a register file.
1187 * file = Register.File
1188 * [1] = Register.Index
1193 index
.i
[3] = reg
->Register
.Index
;
1195 /* There is an extra source register that indirectly subscripts
1196 * a register file. The direct index now becomes an offset
1197 * that is being added to the indirect register.
1201 * ind = Indirect.File
1202 * [2] = Indirect.Index
1203 * .x = Indirect.SwizzleX
1205 if (reg
->Register
.Indirect
) {
1206 union tgsi_exec_channel index2
;
1207 union tgsi_exec_channel indir_index
;
1208 const uint execmask
= mach
->ExecMask
;
1211 /* which address register (always zero now) */
1215 index2
.i
[3] = reg
->Indirect
.Index
;
1216 assert(reg
->Indirect
.File
== TGSI_FILE_ADDRESS
);
1217 /* get current value of address register[swizzle] */
1218 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, TGSI_CHAN_X
);
1219 fetch_src_file_channel(mach
,
1227 /* add value of address register to the offset */
1228 index
.i
[0] += indir_index
.i
[0];
1229 index
.i
[1] += indir_index
.i
[1];
1230 index
.i
[2] += indir_index
.i
[2];
1231 index
.i
[3] += indir_index
.i
[3];
1233 /* for disabled execution channels, zero-out the index to
1234 * avoid using a potential garbage value.
1236 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1237 if ((execmask
& (1 << i
)) == 0)
1242 /* There is an extra source register that is a second
1243 * subscript to a register file. Effectively it means that
1244 * the register file is actually a 2D array of registers.
1248 * [3] = Dimension.Index
1250 if (reg
->Register
.Dimension
) {
1254 index2D
.i
[3] = reg
->Dimension
.Index
;
1256 /* Again, the second subscript index can be addressed indirectly
1257 * identically to the first one.
1258 * Nothing stops us from indirectly addressing the indirect register,
1259 * but there is no need for that, so we won't exercise it.
1261 * file[ind[4].y+3][1],
1263 * ind = DimIndirect.File
1264 * [4] = DimIndirect.Index
1265 * .y = DimIndirect.SwizzleX
1267 if (reg
->Dimension
.Indirect
) {
1268 union tgsi_exec_channel index2
;
1269 union tgsi_exec_channel indir_index
;
1270 const uint execmask
= mach
->ExecMask
;
1276 index2
.i
[3] = reg
->DimIndirect
.Index
;
1278 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, TGSI_CHAN_X
);
1279 fetch_src_file_channel(mach
,
1281 reg
->DimIndirect
.File
,
1287 index2D
.i
[0] += indir_index
.i
[0];
1288 index2D
.i
[1] += indir_index
.i
[1];
1289 index2D
.i
[2] += indir_index
.i
[2];
1290 index2D
.i
[3] += indir_index
.i
[3];
1292 /* for disabled execution channels, zero-out the index to
1293 * avoid using a potential garbage value.
1295 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1296 if ((execmask
& (1 << i
)) == 0) {
1302 /* If by any chance there was a need for a 3D array of register
1303 * files, we would have to check whether Dimension is followed
1304 * by a dimension register and continue the saga.
1313 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1314 fetch_src_file_channel(mach
,
1322 if (reg
->Register
.Absolute
) {
1323 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1324 micro_abs(chan
, chan
);
1326 micro_iabs(chan
, chan
);
1330 if (reg
->Register
.Negate
) {
1331 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1332 micro_neg(chan
, chan
);
1334 micro_ineg(chan
, chan
);
1340 store_dest(struct tgsi_exec_machine
*mach
,
1341 const union tgsi_exec_channel
*chan
,
1342 const struct tgsi_full_dst_register
*reg
,
1343 const struct tgsi_full_instruction
*inst
,
1345 enum tgsi_exec_datatype dst_datatype
)
1348 union tgsi_exec_channel null
;
1349 union tgsi_exec_channel
*dst
;
1350 union tgsi_exec_channel index2D
;
1351 uint execmask
= mach
->ExecMask
;
1352 int offset
= 0; /* indirection offset */
1356 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1357 check_inf_or_nan(chan
);
1360 /* There is an extra source register that indirectly subscripts
1361 * a register file. The direct index now becomes an offset
1362 * that is being added to the indirect register.
1366 * ind = Indirect.File
1367 * [2] = Indirect.Index
1368 * .x = Indirect.SwizzleX
1370 if (reg
->Register
.Indirect
) {
1371 union tgsi_exec_channel index
;
1372 union tgsi_exec_channel indir_index
;
1375 /* which address register (always zero for now) */
1379 index
.i
[3] = reg
->Indirect
.Index
;
1381 /* get current value of address register[swizzle] */
1382 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, TGSI_CHAN_X
);
1384 /* fetch values from the address/indirection register */
1385 fetch_src_file_channel(mach
,
1393 /* save indirection offset */
1394 offset
= indir_index
.i
[0];
1397 /* There is an extra source register that is a second
1398 * subscript to a register file. Effectively it means that
1399 * the register file is actually a 2D array of registers.
1403 * [3] = Dimension.Index
1405 if (reg
->Register
.Dimension
) {
1409 index2D
.i
[3] = reg
->Dimension
.Index
;
1411 /* Again, the second subscript index can be addressed indirectly
1412 * identically to the first one.
1413 * Nothing stops us from indirectly addressing the indirect register,
1414 * but there is no need for that, so we won't exercise it.
1416 * file[ind[4].y+3][1],
1418 * ind = DimIndirect.File
1419 * [4] = DimIndirect.Index
1420 * .y = DimIndirect.SwizzleX
1422 if (reg
->Dimension
.Indirect
) {
1423 union tgsi_exec_channel index2
;
1424 union tgsi_exec_channel indir_index
;
1425 const uint execmask
= mach
->ExecMask
;
1432 index2
.i
[3] = reg
->DimIndirect
.Index
;
1434 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, TGSI_CHAN_X
);
1435 fetch_src_file_channel(mach
,
1437 reg
->DimIndirect
.File
,
1443 index2D
.i
[0] += indir_index
.i
[0];
1444 index2D
.i
[1] += indir_index
.i
[1];
1445 index2D
.i
[2] += indir_index
.i
[2];
1446 index2D
.i
[3] += indir_index
.i
[3];
1448 /* for disabled execution channels, zero-out the index to
1449 * avoid using a potential garbage value.
1451 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1452 if ((execmask
& (1 << i
)) == 0) {
1458 /* If by any chance there was a need for a 3D array of register
1459 * files, we would have to check whether Dimension is followed
1460 * by a dimension register and continue the saga.
1469 switch (reg
->Register
.File
) {
1470 case TGSI_FILE_NULL
:
1474 case TGSI_FILE_OUTPUT
:
1475 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1476 + reg
->Register
.Index
;
1477 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1479 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1480 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1481 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1482 if (execmask
& (1 << i
))
1483 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1484 fprintf(stderr
, ")\n");
1489 case TGSI_FILE_TEMPORARY
:
1490 index
= reg
->Register
.Index
;
1491 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1492 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1495 case TGSI_FILE_TEMPORARY_ARRAY
:
1496 index
= reg
->Register
.Index
;
1497 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1498 assert( index2D
.i
[0] < TGSI_EXEC_NUM_TEMP_ARRAYS
);
1499 /* XXX we use index2D.i[0] here but somehow we might
1500 * end up with someone trying to store indirectly in
1501 * different buffers */
1502 dst
= &mach
->TempArray
[index2D
.i
[0]][offset
+ index
].xyzw
[chan_index
];
1505 case TGSI_FILE_ADDRESS
:
1506 index
= reg
->Register
.Index
;
1507 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1510 case TGSI_FILE_PREDICATE
:
1511 index
= reg
->Register
.Index
;
1512 assert(index
< TGSI_EXEC_NUM_PREDS
);
1513 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1521 if (inst
->Instruction
.Predicate
) {
1523 union tgsi_exec_channel
*pred
;
1525 switch (chan_index
) {
1527 swizzle
= inst
->Predicate
.SwizzleX
;
1530 swizzle
= inst
->Predicate
.SwizzleY
;
1533 swizzle
= inst
->Predicate
.SwizzleZ
;
1536 swizzle
= inst
->Predicate
.SwizzleW
;
1543 assert(inst
->Predicate
.Index
== 0);
1545 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1547 if (inst
->Predicate
.Negate
) {
1548 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1550 execmask
&= ~(1 << i
);
1554 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1556 execmask
&= ~(1 << i
);
1562 switch (inst
->Instruction
.Saturate
) {
1564 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1565 if (execmask
& (1 << i
))
1566 dst
->i
[i
] = chan
->i
[i
];
1569 case TGSI_SAT_ZERO_ONE
:
1570 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1571 if (execmask
& (1 << i
)) {
1572 if (chan
->f
[i
] < 0.0f
)
1574 else if (chan
->f
[i
] > 1.0f
)
1577 dst
->i
[i
] = chan
->i
[i
];
1581 case TGSI_SAT_MINUS_PLUS_ONE
:
1582 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1583 if (execmask
& (1 << i
)) {
1584 if (chan
->f
[i
] < -1.0f
)
1586 else if (chan
->f
[i
] > 1.0f
)
1589 dst
->i
[i
] = chan
->i
[i
];
1598 #define FETCH(VAL,INDEX,CHAN)\
1599 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1601 #define IFETCH(VAL,INDEX,CHAN)\
1602 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
1606 * Execute ARB-style KIL which is predicated by a src register.
1607 * Kill fragment if any of the four values is less than zero.
1610 exec_kil(struct tgsi_exec_machine
*mach
,
1611 const struct tgsi_full_instruction
*inst
)
1615 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1616 union tgsi_exec_channel r
[1];
1618 /* This mask stores component bits that were already tested. */
1621 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1626 /* unswizzle channel */
1627 swizzle
= tgsi_util_get_full_src_register_swizzle (
1631 /* check if the component has not been already tested */
1632 if (uniquemask
& (1 << swizzle
))
1634 uniquemask
|= 1 << swizzle
;
1636 FETCH(&r
[0], 0, chan_index
);
1637 for (i
= 0; i
< 4; i
++)
1638 if (r
[0].f
[i
] < 0.0f
)
1642 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1646 * Execute NVIDIA-style KIL which is predicated by a condition code.
1647 * Kill fragment if the condition code is TRUE.
1650 exec_kilp(struct tgsi_exec_machine
*mach
,
1651 const struct tgsi_full_instruction
*inst
)
1653 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1655 /* "unconditional" kil */
1656 kilmask
= mach
->ExecMask
;
1657 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1661 emit_vertex(struct tgsi_exec_machine
*mach
)
1663 /* FIXME: check for exec mask correctly
1665 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1666 if ((mach->ExecMask & (1 << i)))
1668 if (mach
->ExecMask
) {
1669 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1670 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1675 emit_primitive(struct tgsi_exec_machine
*mach
)
1677 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1678 /* FIXME: check for exec mask correctly
1680 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1681 if ((mach->ExecMask & (1 << i)))
1683 if (mach
->ExecMask
) {
1685 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1686 mach
->Primitives
[*prim_count
] = 0;
1691 conditional_emit_primitive(struct tgsi_exec_machine
*mach
)
1693 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1695 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]];
1696 if (emitted_verts
) {
1697 emit_primitive(mach
);
1704 * Fetch four texture samples using STR texture coordinates.
1707 fetch_texel( struct tgsi_sampler
*sampler
,
1708 const union tgsi_exec_channel
*s
,
1709 const union tgsi_exec_channel
*t
,
1710 const union tgsi_exec_channel
*p
,
1711 const union tgsi_exec_channel
*c0
,
1712 enum tgsi_sampler_control control
,
1713 union tgsi_exec_channel
*r
,
1714 union tgsi_exec_channel
*g
,
1715 union tgsi_exec_channel
*b
,
1716 union tgsi_exec_channel
*a
)
1719 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1721 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, c0
->f
, control
, rgba
);
1723 for (j
= 0; j
< 4; j
++) {
1724 r
->f
[j
] = rgba
[0][j
];
1725 g
->f
[j
] = rgba
[1][j
];
1726 b
->f
[j
] = rgba
[2][j
];
1727 a
->f
[j
] = rgba
[3][j
];
1732 #define TEX_MODIFIER_NONE 0
1733 #define TEX_MODIFIER_PROJECTED 1
1734 #define TEX_MODIFIER_LOD_BIAS 2
1735 #define TEX_MODIFIER_EXPLICIT_LOD 3
1739 exec_tex(struct tgsi_exec_machine
*mach
,
1740 const struct tgsi_full_instruction
*inst
,
1743 const uint unit
= inst
->Src
[1].Register
.Index
;
1744 union tgsi_exec_channel r
[4];
1745 const union tgsi_exec_channel
*lod
= &ZeroVec
;
1746 enum tgsi_sampler_control control
;
1749 if (modifier
!= TEX_MODIFIER_NONE
) {
1750 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1751 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
1756 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
1757 control
= tgsi_sampler_lod_explicit
;
1759 control
= tgsi_sampler_lod_bias
;
1762 switch (inst
->Texture
.Texture
) {
1763 case TGSI_TEXTURE_1D
:
1764 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1766 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1767 micro_div(&r
[0], &r
[0], &r
[3]);
1770 fetch_texel(mach
->Samplers
[unit
],
1771 &r
[0], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, LOD */
1773 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1775 case TGSI_TEXTURE_SHADOW1D
:
1776 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1777 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1779 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1780 micro_div(&r
[0], &r
[0], &r
[3]);
1783 fetch_texel(mach
->Samplers
[unit
],
1784 &r
[0], &ZeroVec
, &r
[2], lod
, /* S, T, P, LOD */
1786 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1789 case TGSI_TEXTURE_2D
:
1790 case TGSI_TEXTURE_RECT
:
1791 case TGSI_TEXTURE_SHADOW2D
:
1792 case TGSI_TEXTURE_SHADOWRECT
:
1793 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1794 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1795 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1797 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1798 micro_div(&r
[0], &r
[0], &r
[3]);
1799 micro_div(&r
[1], &r
[1], &r
[3]);
1800 micro_div(&r
[2], &r
[2], &r
[3]);
1803 fetch_texel(mach
->Samplers
[unit
],
1804 &r
[0], &r
[1], &r
[2], lod
, /* S, T, P, LOD */
1806 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1809 case TGSI_TEXTURE_1D_ARRAY
:
1810 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1811 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1813 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1814 micro_div(&r
[0], &r
[0], &r
[3]);
1817 fetch_texel(mach
->Samplers
[unit
],
1818 &r
[0], &r
[1], &ZeroVec
, lod
, /* S, T, P, LOD */
1820 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1822 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1823 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1824 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1825 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1827 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1828 micro_div(&r
[0], &r
[0], &r
[3]);
1831 fetch_texel(mach
->Samplers
[unit
],
1832 &r
[0], &r
[1], &r
[2], lod
, /* S, T, P, LOD */
1834 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1837 case TGSI_TEXTURE_2D_ARRAY
:
1838 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1839 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1840 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1842 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1843 micro_div(&r
[0], &r
[0], &r
[3]);
1844 micro_div(&r
[1], &r
[1], &r
[3]);
1847 fetch_texel(mach
->Samplers
[unit
],
1848 &r
[0], &r
[1], &r
[2], lod
, /* S, T, P, LOD */
1850 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1852 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1853 case TGSI_TEXTURE_SHADOWCUBE
:
1854 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1855 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1856 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1857 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1859 fetch_texel(mach
->Samplers
[unit
],
1860 &r
[0], &r
[1], &r
[2], &r
[3], /* S, T, P, LOD */
1862 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1864 case TGSI_TEXTURE_3D
:
1865 case TGSI_TEXTURE_CUBE
:
1866 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1867 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1868 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1870 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1871 micro_div(&r
[0], &r
[0], &r
[3]);
1872 micro_div(&r
[1], &r
[1], &r
[3]);
1873 micro_div(&r
[2], &r
[2], &r
[3]);
1876 fetch_texel(mach
->Samplers
[unit
],
1877 &r
[0], &r
[1], &r
[2], lod
,
1879 &r
[0], &r
[1], &r
[2], &r
[3]);
1887 debug_printf("fetch r: %g %g %g %g\n",
1888 r
[0].f
[0], r
[0].f
[1], r
[0].f
[2], r
[0].f
[3]);
1889 debug_printf("fetch g: %g %g %g %g\n",
1890 r
[1].f
[0], r
[1].f
[1], r
[1].f
[2], r
[1].f
[3]);
1891 debug_printf("fetch b: %g %g %g %g\n",
1892 r
[2].f
[0], r
[2].f
[1], r
[2].f
[2], r
[2].f
[3]);
1893 debug_printf("fetch a: %g %g %g %g\n",
1894 r
[3].f
[0], r
[3].f
[1], r
[3].f
[2], r
[3].f
[3]);
1897 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1898 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1899 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1905 exec_txd(struct tgsi_exec_machine
*mach
,
1906 const struct tgsi_full_instruction
*inst
)
1908 const uint unit
= inst
->Src
[3].Register
.Index
;
1909 union tgsi_exec_channel r
[4];
1913 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1916 switch (inst
->Texture
.Texture
) {
1917 case TGSI_TEXTURE_1D
:
1918 case TGSI_TEXTURE_SHADOW1D
:
1920 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1922 fetch_texel(mach
->Samplers
[unit
],
1923 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, BIAS */
1924 tgsi_sampler_lod_bias
,
1925 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1928 case TGSI_TEXTURE_1D_ARRAY
:
1929 case TGSI_TEXTURE_2D
:
1930 case TGSI_TEXTURE_RECT
:
1931 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1932 case TGSI_TEXTURE_SHADOW2D
:
1933 case TGSI_TEXTURE_SHADOWRECT
:
1935 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1936 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1937 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1939 fetch_texel(mach
->Samplers
[unit
],
1940 &r
[0], &r
[1], &r
[2], &ZeroVec
, /* inputs */
1941 tgsi_sampler_lod_bias
,
1942 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1945 case TGSI_TEXTURE_2D_ARRAY
:
1946 case TGSI_TEXTURE_3D
:
1947 case TGSI_TEXTURE_CUBE
:
1949 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1950 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1951 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1953 fetch_texel(mach
->Samplers
[unit
],
1954 &r
[0], &r
[1], &r
[2], &ZeroVec
,
1955 tgsi_sampler_lod_bias
,
1956 &r
[0], &r
[1], &r
[2], &r
[3]);
1959 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1961 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1962 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1963 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1964 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1966 fetch_texel(mach
->Samplers
[unit
],
1967 &r
[0], &r
[1], &r
[2], &r
[3],
1968 tgsi_sampler_lod_bias
,
1969 &r
[0], &r
[1], &r
[2], &r
[3]);
1976 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1977 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1978 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1985 exec_txf(struct tgsi_exec_machine
*mach
,
1986 const struct tgsi_full_instruction
*inst
)
1988 struct tgsi_sampler
*sampler
;
1989 const uint unit
= inst
->Src
[2].Register
.Index
;
1990 union tgsi_exec_channel r
[4];
1991 union tgsi_exec_channel offset
[3];
1993 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1997 if (inst
->Texture
.NumOffsets
== 1) {
1998 union tgsi_exec_channel index
;
1999 index
.i
[0] = index
.i
[1] = index
.i
[2] = index
.i
[3] = inst
->TexOffsets
[0].Index
;
2000 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2001 inst
->TexOffsets
[0].SwizzleX
, &index
, &ZeroVec
, &offset
[0]);
2002 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2003 inst
->TexOffsets
[0].SwizzleY
, &index
, &ZeroVec
, &offset
[1]);
2004 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2005 inst
->TexOffsets
[0].SwizzleZ
, &index
, &ZeroVec
, &offset
[2]);
2006 offsets
[0] = offset
[0].i
[0];
2007 offsets
[1] = offset
[1].i
[0];
2008 offsets
[2] = offset
[2].i
[0];
2010 offsets
[0] = offsets
[1] = offsets
[2] = 0;
2012 IFETCH(&r
[3], 0, TGSI_CHAN_W
);
2014 switch(inst
->Texture
.Texture
) {
2015 case TGSI_TEXTURE_3D
:
2016 case TGSI_TEXTURE_2D_ARRAY
:
2017 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2018 IFETCH(&r
[2], 0, TGSI_CHAN_Z
);
2020 case TGSI_TEXTURE_2D
:
2021 case TGSI_TEXTURE_RECT
:
2022 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
2023 case TGSI_TEXTURE_SHADOW2D
:
2024 case TGSI_TEXTURE_SHADOWRECT
:
2025 case TGSI_TEXTURE_1D_ARRAY
:
2026 IFETCH(&r
[1], 0, TGSI_CHAN_Y
);
2028 case TGSI_TEXTURE_1D
:
2029 case TGSI_TEXTURE_SHADOW1D
:
2030 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
2037 sampler
= mach
->Samplers
[unit
];
2038 sampler
->get_texel(sampler
, r
[0].i
, r
[1].i
, r
[2].i
, r
[3].i
,
2041 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2042 r
[0].f
[j
] = rgba
[0][j
];
2043 r
[1].f
[j
] = rgba
[1][j
];
2044 r
[2].f
[j
] = rgba
[2][j
];
2045 r
[3].f
[j
] = rgba
[3][j
];
2048 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2049 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2050 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2056 exec_txq(struct tgsi_exec_machine
*mach
,
2057 const struct tgsi_full_instruction
*inst
)
2059 struct tgsi_sampler
*sampler
;
2060 const uint unit
= inst
->Src
[1].Register
.Index
;
2062 union tgsi_exec_channel r
[4], src
;
2066 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
2067 sampler
= mach
->Samplers
[unit
];
2069 sampler
->get_dims(sampler
, src
.i
[0], result
);
2071 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2072 for (j
= 0; j
< 4; j
++) {
2073 r
[j
].i
[i
] = result
[j
];
2077 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2078 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2079 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
2080 TGSI_EXEC_DATA_INT
);
2086 exec_sample(struct tgsi_exec_machine
*mach
,
2087 const struct tgsi_full_instruction
*inst
,
2090 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2091 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2092 union tgsi_exec_channel r
[4];
2093 const union tgsi_exec_channel
*lod
= &ZeroVec
;
2094 enum tgsi_sampler_control control
;
2097 if (modifier
!= TEX_MODIFIER_NONE
) {
2098 if (modifier
== TEX_MODIFIER_LOD_BIAS
)
2099 FETCH(&r
[3], 3, TGSI_CHAN_X
);
2100 else /*TEX_MODIFIER_LOD*/
2101 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2103 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
2108 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
2109 control
= tgsi_sampler_lod_explicit
;
2111 control
= tgsi_sampler_lod_bias
;
2114 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2115 case TGSI_TEXTURE_1D
:
2116 case TGSI_TEXTURE_SHADOW1D
:
2117 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2119 if (modifier
== TEX_MODIFIER_PROJECTED
) {
2120 micro_div(&r
[0], &r
[0], &r
[3]);
2123 fetch_texel(mach
->Samplers
[sampler_unit
],
2124 &r
[0], &ZeroVec
, &ZeroVec
, lod
, /* S, T, P, LOD */
2126 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2129 case TGSI_TEXTURE_1D_ARRAY
:
2130 case TGSI_TEXTURE_2D
:
2131 case TGSI_TEXTURE_RECT
:
2132 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
2133 case TGSI_TEXTURE_SHADOW2D
:
2134 case TGSI_TEXTURE_SHADOWRECT
:
2135 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2136 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2137 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2139 if (modifier
== TEX_MODIFIER_PROJECTED
) {
2140 micro_div(&r
[0], &r
[0], &r
[3]);
2141 micro_div(&r
[1], &r
[1], &r
[3]);
2142 micro_div(&r
[2], &r
[2], &r
[3]);
2145 fetch_texel(mach
->Samplers
[sampler_unit
],
2146 &r
[0], &r
[1], &r
[2], lod
, /* S, T, P, LOD */
2148 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2151 case TGSI_TEXTURE_2D_ARRAY
:
2152 case TGSI_TEXTURE_3D
:
2153 case TGSI_TEXTURE_CUBE
:
2154 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2155 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2156 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2158 if (modifier
== TEX_MODIFIER_PROJECTED
) {
2159 micro_div(&r
[0], &r
[0], &r
[3]);
2160 micro_div(&r
[1], &r
[1], &r
[3]);
2161 micro_div(&r
[2], &r
[2], &r
[3]);
2164 fetch_texel(mach
->Samplers
[sampler_unit
],
2165 &r
[0], &r
[1], &r
[2], lod
,
2167 &r
[0], &r
[1], &r
[2], &r
[3]);
2170 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2171 case TGSI_TEXTURE_SHADOWCUBE
:
2172 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2173 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2174 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2175 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2177 assert(modifier
!= TEX_MODIFIER_PROJECTED
);
2179 fetch_texel(mach
->Samplers
[sampler_unit
],
2180 &r
[0], &r
[1], &r
[2], &r
[3],
2182 &r
[0], &r
[1], &r
[2], &r
[3]);
2189 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2190 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2191 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2197 exec_sample_d(struct tgsi_exec_machine
*mach
,
2198 const struct tgsi_full_instruction
*inst
)
2200 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2201 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2202 union tgsi_exec_channel r
[4];
2205 * XXX: This is fake SAMPLE_D -- the derivatives are not taken into account, yet.
2208 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2209 case TGSI_TEXTURE_1D
:
2210 case TGSI_TEXTURE_SHADOW1D
:
2212 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2214 fetch_texel(mach
->Samplers
[sampler_unit
],
2215 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, BIAS */
2216 tgsi_sampler_lod_bias
,
2217 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2220 case TGSI_TEXTURE_2D
:
2221 case TGSI_TEXTURE_RECT
:
2222 case TGSI_TEXTURE_SHADOW2D
:
2223 case TGSI_TEXTURE_SHADOWRECT
:
2225 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2226 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2227 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2229 fetch_texel(mach
->Samplers
[sampler_unit
],
2230 &r
[0], &r
[1], &r
[2], &ZeroVec
, /* inputs */
2231 tgsi_sampler_lod_bias
,
2232 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2235 case TGSI_TEXTURE_3D
:
2236 case TGSI_TEXTURE_CUBE
:
2238 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2239 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2240 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2242 fetch_texel(mach
->Samplers
[sampler_unit
],
2243 &r
[0], &r
[1], &r
[2], &ZeroVec
,
2244 tgsi_sampler_lod_bias
,
2245 &r
[0], &r
[1], &r
[2], &r
[3]);
2252 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2253 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2254 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2261 * Evaluate a constant-valued coefficient at the position of the
2266 struct tgsi_exec_machine
*mach
,
2272 for( i
= 0; i
< TGSI_QUAD_SIZE
; i
++ ) {
2273 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
2278 * Evaluate a linear-valued coefficient at the position of the
2283 struct tgsi_exec_machine
*mach
,
2287 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2288 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2289 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2290 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2291 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2292 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
2293 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
2294 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
2295 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
2299 * Evaluate a perspective-valued coefficient at the position of the
2303 eval_perspective_coef(
2304 struct tgsi_exec_machine
*mach
,
2308 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2309 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2310 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2311 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2312 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2313 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
2314 /* divide by W here */
2315 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
2316 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
2317 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
2318 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
2322 typedef void (* eval_coef_func
)(
2323 struct tgsi_exec_machine
*mach
,
2328 exec_declaration(struct tgsi_exec_machine
*mach
,
2329 const struct tgsi_full_declaration
*decl
)
2331 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
2332 mach
->SamplerViews
[decl
->Range
.First
] = decl
->SamplerView
;
2336 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
2337 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
2338 uint first
, last
, mask
;
2340 first
= decl
->Range
.First
;
2341 last
= decl
->Range
.Last
;
2342 mask
= decl
->Declaration
.UsageMask
;
2344 /* XXX we could remove this special-case code since
2345 * mach->InterpCoefs[first].a0 should already have the
2346 * front/back-face value. But we should first update the
2347 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2348 * Then, we could remove the tgsi_exec_machine::Face field.
2350 /* XXX make FACE a system value */
2351 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
2354 assert(decl
->Semantic
.Index
== 0);
2355 assert(first
== last
);
2357 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2358 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
2361 eval_coef_func eval
;
2364 switch (decl
->Interp
.Interpolate
) {
2365 case TGSI_INTERPOLATE_CONSTANT
:
2366 eval
= eval_constant_coef
;
2369 case TGSI_INTERPOLATE_LINEAR
:
2370 eval
= eval_linear_coef
;
2373 case TGSI_INTERPOLATE_PERSPECTIVE
:
2374 eval
= eval_perspective_coef
;
2377 case TGSI_INTERPOLATE_COLOR
:
2378 eval
= mach
->flatshade_color
? eval_constant_coef
: eval_perspective_coef
;
2386 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2387 if (mask
& (1 << j
)) {
2388 for (i
= first
; i
<= last
; i
++) {
2397 if (decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
2398 mach
->SysSemanticToIndex
[decl
->Declaration
.Semantic
] = decl
->Range
.First
;
2403 typedef void (* micro_op
)(union tgsi_exec_channel
*dst
);
2406 exec_vector(struct tgsi_exec_machine
*mach
,
2407 const struct tgsi_full_instruction
*inst
,
2409 enum tgsi_exec_datatype dst_datatype
)
2413 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2414 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2415 union tgsi_exec_channel dst
;
2418 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2423 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
2424 const union tgsi_exec_channel
*src
);
2427 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
2428 const struct tgsi_full_instruction
*inst
,
2430 enum tgsi_exec_datatype dst_datatype
,
2431 enum tgsi_exec_datatype src_datatype
)
2434 union tgsi_exec_channel src
;
2435 union tgsi_exec_channel dst
;
2437 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2439 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2440 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2441 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2447 exec_vector_unary(struct tgsi_exec_machine
*mach
,
2448 const struct tgsi_full_instruction
*inst
,
2450 enum tgsi_exec_datatype dst_datatype
,
2451 enum tgsi_exec_datatype src_datatype
)
2454 struct tgsi_exec_vector dst
;
2456 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2457 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2458 union tgsi_exec_channel src
;
2460 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
2461 op(&dst
.xyzw
[chan
], &src
);
2464 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2465 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2466 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2471 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
2472 const union tgsi_exec_channel
*src0
,
2473 const union tgsi_exec_channel
*src1
);
2476 exec_scalar_binary(struct tgsi_exec_machine
*mach
,
2477 const struct tgsi_full_instruction
*inst
,
2479 enum tgsi_exec_datatype dst_datatype
,
2480 enum tgsi_exec_datatype src_datatype
)
2483 union tgsi_exec_channel src
[2];
2484 union tgsi_exec_channel dst
;
2486 fetch_source(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2487 fetch_source(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_Y
, src_datatype
);
2488 op(&dst
, &src
[0], &src
[1]);
2489 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2490 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2491 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2497 exec_vector_binary(struct tgsi_exec_machine
*mach
,
2498 const struct tgsi_full_instruction
*inst
,
2500 enum tgsi_exec_datatype dst_datatype
,
2501 enum tgsi_exec_datatype src_datatype
)
2504 struct tgsi_exec_vector dst
;
2506 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2507 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2508 union tgsi_exec_channel src
[2];
2510 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2511 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2512 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
2515 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2516 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2517 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2522 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
2523 const union tgsi_exec_channel
*src0
,
2524 const union tgsi_exec_channel
*src1
,
2525 const union tgsi_exec_channel
*src2
);
2528 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
2529 const struct tgsi_full_instruction
*inst
,
2530 micro_trinary_op op
,
2531 enum tgsi_exec_datatype dst_datatype
,
2532 enum tgsi_exec_datatype src_datatype
)
2535 struct tgsi_exec_vector dst
;
2537 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2538 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2539 union tgsi_exec_channel src
[3];
2541 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2542 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2543 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2544 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
2547 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2548 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2549 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2555 exec_dp3(struct tgsi_exec_machine
*mach
,
2556 const struct tgsi_full_instruction
*inst
)
2559 union tgsi_exec_channel arg
[3];
2561 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2562 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2563 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2565 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
2566 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2567 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2568 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2571 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2572 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2573 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2579 exec_dp4(struct tgsi_exec_machine
*mach
,
2580 const struct tgsi_full_instruction
*inst
)
2583 union tgsi_exec_channel arg
[3];
2585 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2586 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2587 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2589 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
2590 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2591 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2592 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2595 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2596 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2597 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2603 exec_dp2a(struct tgsi_exec_machine
*mach
,
2604 const struct tgsi_full_instruction
*inst
)
2607 union tgsi_exec_channel arg
[3];
2609 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2610 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2611 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2613 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2614 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2615 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2617 fetch_source(mach
, &arg
[1], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2618 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2620 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2621 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2622 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2628 exec_dph(struct tgsi_exec_machine
*mach
,
2629 const struct tgsi_full_instruction
*inst
)
2632 union tgsi_exec_channel arg
[3];
2634 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2635 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2636 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2638 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2639 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2640 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2642 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2643 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2644 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2646 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2647 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2649 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2650 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2651 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2657 exec_dp2(struct tgsi_exec_machine
*mach
,
2658 const struct tgsi_full_instruction
*inst
)
2661 union tgsi_exec_channel arg
[3];
2663 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2664 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2665 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2667 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2668 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2669 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2671 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2672 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2673 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2679 exec_nrm4(struct tgsi_exec_machine
*mach
,
2680 const struct tgsi_full_instruction
*inst
)
2683 union tgsi_exec_channel arg
[4];
2684 union tgsi_exec_channel scale
;
2686 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2687 micro_mul(&scale
, &arg
[0], &arg
[0]);
2689 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
2690 union tgsi_exec_channel product
;
2692 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2693 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2694 micro_add(&scale
, &scale
, &product
);
2697 micro_rsq(&scale
, &scale
);
2699 for (chan
= TGSI_CHAN_X
; chan
<= TGSI_CHAN_W
; chan
++) {
2700 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2701 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2702 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2708 exec_nrm3(struct tgsi_exec_machine
*mach
,
2709 const struct tgsi_full_instruction
*inst
)
2711 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XYZ
) {
2713 union tgsi_exec_channel arg
[3];
2714 union tgsi_exec_channel scale
;
2716 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2717 micro_mul(&scale
, &arg
[0], &arg
[0]);
2719 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
2720 union tgsi_exec_channel product
;
2722 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2723 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2724 micro_add(&scale
, &scale
, &product
);
2727 micro_rsq(&scale
, &scale
);
2729 for (chan
= TGSI_CHAN_X
; chan
<= TGSI_CHAN_Z
; chan
++) {
2730 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2731 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2732 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2737 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2738 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2743 exec_scs(struct tgsi_exec_machine
*mach
,
2744 const struct tgsi_full_instruction
*inst
)
2746 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) {
2747 union tgsi_exec_channel arg
;
2748 union tgsi_exec_channel result
;
2750 fetch_source(mach
, &arg
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2752 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2753 micro_cos(&result
, &arg
);
2754 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2756 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2757 micro_sin(&result
, &arg
);
2758 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2761 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2762 store_dest(mach
, &ZeroVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2764 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2765 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2770 exec_x2d(struct tgsi_exec_machine
*mach
,
2771 const struct tgsi_full_instruction
*inst
)
2773 union tgsi_exec_channel r
[4];
2774 union tgsi_exec_channel d
[2];
2776 fetch_source(mach
, &r
[0], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2777 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2778 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XZ
) {
2779 fetch_source(mach
, &r
[2], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2780 micro_mul(&r
[2], &r
[2], &r
[0]);
2781 fetch_source(mach
, &r
[3], &inst
->Src
[2], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2782 micro_mul(&r
[3], &r
[3], &r
[1]);
2783 micro_add(&r
[2], &r
[2], &r
[3]);
2784 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2785 micro_add(&d
[0], &r
[2], &r
[3]);
2787 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YW
) {
2788 fetch_source(mach
, &r
[2], &inst
->Src
[2], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2789 micro_mul(&r
[2], &r
[2], &r
[0]);
2790 fetch_source(mach
, &r
[3], &inst
->Src
[2], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2791 micro_mul(&r
[3], &r
[3], &r
[1]);
2792 micro_add(&r
[2], &r
[2], &r
[3]);
2793 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2794 micro_add(&d
[1], &r
[2], &r
[3]);
2796 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2797 store_dest(mach
, &d
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2799 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2800 store_dest(mach
, &d
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2802 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2803 store_dest(mach
, &d
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2805 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2806 store_dest(mach
, &d
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2811 exec_rfl(struct tgsi_exec_machine
*mach
,
2812 const struct tgsi_full_instruction
*inst
)
2814 union tgsi_exec_channel r
[9];
2816 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XYZ
) {
2817 /* r0 = dp3(src0, src0) */
2818 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2819 micro_mul(&r
[0], &r
[2], &r
[2]);
2820 fetch_source(mach
, &r
[4], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2821 micro_mul(&r
[8], &r
[4], &r
[4]);
2822 micro_add(&r
[0], &r
[0], &r
[8]);
2823 fetch_source(mach
, &r
[6], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2824 micro_mul(&r
[8], &r
[6], &r
[6]);
2825 micro_add(&r
[0], &r
[0], &r
[8]);
2827 /* r1 = dp3(src0, src1) */
2828 fetch_source(mach
, &r
[3], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2829 micro_mul(&r
[1], &r
[2], &r
[3]);
2830 fetch_source(mach
, &r
[5], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2831 micro_mul(&r
[8], &r
[4], &r
[5]);
2832 micro_add(&r
[1], &r
[1], &r
[8]);
2833 fetch_source(mach
, &r
[7], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2834 micro_mul(&r
[8], &r
[6], &r
[7]);
2835 micro_add(&r
[1], &r
[1], &r
[8]);
2837 /* r1 = 2 * r1 / r0 */
2838 micro_add(&r
[1], &r
[1], &r
[1]);
2839 micro_div(&r
[1], &r
[1], &r
[0]);
2841 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2842 micro_mul(&r
[2], &r
[2], &r
[1]);
2843 micro_sub(&r
[2], &r
[2], &r
[3]);
2844 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2846 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2847 micro_mul(&r
[4], &r
[4], &r
[1]);
2848 micro_sub(&r
[4], &r
[4], &r
[5]);
2849 store_dest(mach
, &r
[4], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2851 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2852 micro_mul(&r
[6], &r
[6], &r
[1]);
2853 micro_sub(&r
[6], &r
[6], &r
[7]);
2854 store_dest(mach
, &r
[6], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2857 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2858 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2863 exec_xpd(struct tgsi_exec_machine
*mach
,
2864 const struct tgsi_full_instruction
*inst
)
2866 union tgsi_exec_channel r
[6];
2867 union tgsi_exec_channel d
[3];
2869 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2870 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2872 micro_mul(&r
[2], &r
[0], &r
[1]);
2874 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2875 fetch_source(mach
, &r
[4], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2877 micro_mul(&r
[5], &r
[3], &r
[4] );
2878 micro_sub(&d
[TGSI_CHAN_X
], &r
[2], &r
[5]);
2880 fetch_source(mach
, &r
[2], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2882 micro_mul(&r
[3], &r
[3], &r
[2]);
2884 fetch_source(mach
, &r
[5], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2886 micro_mul(&r
[1], &r
[1], &r
[5]);
2887 micro_sub(&d
[TGSI_CHAN_Y
], &r
[3], &r
[1]);
2889 micro_mul(&r
[5], &r
[5], &r
[4]);
2890 micro_mul(&r
[0], &r
[0], &r
[2]);
2891 micro_sub(&d
[TGSI_CHAN_Z
], &r
[5], &r
[0]);
2893 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2894 store_dest(mach
, &d
[TGSI_CHAN_X
], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2896 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2897 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2899 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2900 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2902 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2903 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2908 exec_dst(struct tgsi_exec_machine
*mach
,
2909 const struct tgsi_full_instruction
*inst
)
2911 union tgsi_exec_channel r
[2];
2912 union tgsi_exec_channel d
[4];
2914 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2915 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2916 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2917 micro_mul(&d
[TGSI_CHAN_Y
], &r
[0], &r
[1]);
2919 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2920 fetch_source(mach
, &d
[TGSI_CHAN_Z
], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2922 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2923 fetch_source(mach
, &d
[TGSI_CHAN_W
], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2926 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2927 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2929 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2930 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2932 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
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_W
) {
2936 store_dest(mach
, &d
[TGSI_CHAN_W
], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2941 exec_log(struct tgsi_exec_machine
*mach
,
2942 const struct tgsi_full_instruction
*inst
)
2944 union tgsi_exec_channel r
[3];
2946 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2947 micro_abs(&r
[2], &r
[0]); /* r2 = abs(r0) */
2948 micro_lg2(&r
[1], &r
[2]); /* r1 = lg2(r2) */
2949 micro_flr(&r
[0], &r
[1]); /* r0 = floor(r1) */
2950 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2951 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2953 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2954 micro_exp2(&r
[0], &r
[0]); /* r0 = 2 ^ r0 */
2955 micro_div(&r
[0], &r
[2], &r
[0]); /* r0 = r2 / r0 */
2956 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2958 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2959 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2961 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2962 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2967 exec_exp(struct tgsi_exec_machine
*mach
,
2968 const struct tgsi_full_instruction
*inst
)
2970 union tgsi_exec_channel r
[3];
2972 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2973 micro_flr(&r
[1], &r
[0]); /* r1 = floor(r0) */
2974 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2975 micro_exp2(&r
[2], &r
[1]); /* r2 = 2 ^ r1 */
2976 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2978 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2979 micro_sub(&r
[2], &r
[0], &r
[1]); /* r2 = r0 - r1 */
2980 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2982 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2983 micro_exp2(&r
[2], &r
[0]); /* r2 = 2 ^ r0 */
2984 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2986 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2987 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2992 exec_lit(struct tgsi_exec_machine
*mach
,
2993 const struct tgsi_full_instruction
*inst
)
2995 union tgsi_exec_channel r
[3];
2996 union tgsi_exec_channel d
[3];
2998 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YZ
) {
2999 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3000 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3001 fetch_source(mach
, &r
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3002 micro_max(&r
[1], &r
[1], &ZeroVec
);
3004 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3005 micro_min(&r
[2], &r
[2], &P128Vec
);
3006 micro_max(&r
[2], &r
[2], &M128Vec
);
3007 micro_pow(&r
[1], &r
[1], &r
[2]);
3008 micro_lt(&d
[TGSI_CHAN_Z
], &ZeroVec
, &r
[0], &r
[1], &ZeroVec
);
3009 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3011 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3012 micro_max(&d
[TGSI_CHAN_Y
], &r
[0], &ZeroVec
);
3013 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3016 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3017 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3020 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3021 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3026 exec_break(struct tgsi_exec_machine
*mach
)
3028 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
3029 /* turn off loop channels for each enabled exec channel */
3030 mach
->LoopMask
&= ~mach
->ExecMask
;
3031 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3032 UPDATE_EXEC_MASK(mach
);
3034 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
3036 mach
->Switch
.mask
= 0x0;
3038 UPDATE_EXEC_MASK(mach
);
3043 exec_switch(struct tgsi_exec_machine
*mach
,
3044 const struct tgsi_full_instruction
*inst
)
3046 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3047 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3049 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3050 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3051 mach
->Switch
.mask
= 0x0;
3052 mach
->Switch
.defaultMask
= 0x0;
3054 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3055 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
3057 UPDATE_EXEC_MASK(mach
);
3061 exec_case(struct tgsi_exec_machine
*mach
,
3062 const struct tgsi_full_instruction
*inst
)
3064 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3065 union tgsi_exec_channel src
;
3068 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3070 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
3073 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
3076 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
3079 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
3083 mach
->Switch
.defaultMask
|= mask
;
3085 mach
->Switch
.mask
|= mask
& prevMask
;
3087 UPDATE_EXEC_MASK(mach
);
3091 exec_default(struct tgsi_exec_machine
*mach
)
3093 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3095 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
3097 UPDATE_EXEC_MASK(mach
);
3101 exec_endswitch(struct tgsi_exec_machine
*mach
)
3103 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
3104 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3106 UPDATE_EXEC_MASK(mach
);
3110 micro_i2f(union tgsi_exec_channel
*dst
,
3111 const union tgsi_exec_channel
*src
)
3113 dst
->f
[0] = (float)src
->i
[0];
3114 dst
->f
[1] = (float)src
->i
[1];
3115 dst
->f
[2] = (float)src
->i
[2];
3116 dst
->f
[3] = (float)src
->i
[3];
3120 micro_not(union tgsi_exec_channel
*dst
,
3121 const union tgsi_exec_channel
*src
)
3123 dst
->u
[0] = ~src
->u
[0];
3124 dst
->u
[1] = ~src
->u
[1];
3125 dst
->u
[2] = ~src
->u
[2];
3126 dst
->u
[3] = ~src
->u
[3];
3130 micro_shl(union tgsi_exec_channel
*dst
,
3131 const union tgsi_exec_channel
*src0
,
3132 const union tgsi_exec_channel
*src1
)
3134 dst
->u
[0] = src0
->u
[0] << src1
->u
[0];
3135 dst
->u
[1] = src0
->u
[1] << src1
->u
[1];
3136 dst
->u
[2] = src0
->u
[2] << src1
->u
[2];
3137 dst
->u
[3] = src0
->u
[3] << src1
->u
[3];
3141 micro_and(union tgsi_exec_channel
*dst
,
3142 const union tgsi_exec_channel
*src0
,
3143 const union tgsi_exec_channel
*src1
)
3145 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
3146 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
3147 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
3148 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
3152 micro_or(union tgsi_exec_channel
*dst
,
3153 const union tgsi_exec_channel
*src0
,
3154 const union tgsi_exec_channel
*src1
)
3156 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
3157 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
3158 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
3159 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
3163 micro_xor(union tgsi_exec_channel
*dst
,
3164 const union tgsi_exec_channel
*src0
,
3165 const union tgsi_exec_channel
*src1
)
3167 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
3168 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
3169 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
3170 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
3174 micro_mod(union tgsi_exec_channel
*dst
,
3175 const union tgsi_exec_channel
*src0
,
3176 const union tgsi_exec_channel
*src1
)
3178 dst
->i
[0] = src0
->i
[0] % src1
->i
[0];
3179 dst
->i
[1] = src0
->i
[1] % src1
->i
[1];
3180 dst
->i
[2] = src0
->i
[2] % src1
->i
[2];
3181 dst
->i
[3] = src0
->i
[3] % src1
->i
[3];
3185 micro_f2i(union tgsi_exec_channel
*dst
,
3186 const union tgsi_exec_channel
*src
)
3188 dst
->i
[0] = (int)src
->f
[0];
3189 dst
->i
[1] = (int)src
->f
[1];
3190 dst
->i
[2] = (int)src
->f
[2];
3191 dst
->i
[3] = (int)src
->f
[3];
3195 micro_idiv(union tgsi_exec_channel
*dst
,
3196 const union tgsi_exec_channel
*src0
,
3197 const union tgsi_exec_channel
*src1
)
3199 dst
->i
[0] = src0
->i
[0] / src1
->i
[0];
3200 dst
->i
[1] = src0
->i
[1] / src1
->i
[1];
3201 dst
->i
[2] = src0
->i
[2] / src1
->i
[2];
3202 dst
->i
[3] = src0
->i
[3] / src1
->i
[3];
3206 micro_imax(union tgsi_exec_channel
*dst
,
3207 const union tgsi_exec_channel
*src0
,
3208 const union tgsi_exec_channel
*src1
)
3210 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3211 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3212 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3213 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3217 micro_imin(union tgsi_exec_channel
*dst
,
3218 const union tgsi_exec_channel
*src0
,
3219 const union tgsi_exec_channel
*src1
)
3221 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3222 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3223 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3224 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3228 micro_isge(union tgsi_exec_channel
*dst
,
3229 const union tgsi_exec_channel
*src0
,
3230 const union tgsi_exec_channel
*src1
)
3232 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
3233 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
3234 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
3235 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
3239 micro_ishr(union tgsi_exec_channel
*dst
,
3240 const union tgsi_exec_channel
*src0
,
3241 const union tgsi_exec_channel
*src1
)
3243 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
3244 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
3245 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
3246 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
3250 micro_islt(union tgsi_exec_channel
*dst
,
3251 const union tgsi_exec_channel
*src0
,
3252 const union tgsi_exec_channel
*src1
)
3254 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
3255 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
3256 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
3257 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
3261 micro_f2u(union tgsi_exec_channel
*dst
,
3262 const union tgsi_exec_channel
*src
)
3264 dst
->u
[0] = (uint
)src
->f
[0];
3265 dst
->u
[1] = (uint
)src
->f
[1];
3266 dst
->u
[2] = (uint
)src
->f
[2];
3267 dst
->u
[3] = (uint
)src
->f
[3];
3271 micro_u2f(union tgsi_exec_channel
*dst
,
3272 const union tgsi_exec_channel
*src
)
3274 dst
->f
[0] = (float)src
->u
[0];
3275 dst
->f
[1] = (float)src
->u
[1];
3276 dst
->f
[2] = (float)src
->u
[2];
3277 dst
->f
[3] = (float)src
->u
[3];
3281 micro_uadd(union tgsi_exec_channel
*dst
,
3282 const union tgsi_exec_channel
*src0
,
3283 const union tgsi_exec_channel
*src1
)
3285 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
3286 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
3287 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
3288 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
3292 micro_udiv(union tgsi_exec_channel
*dst
,
3293 const union tgsi_exec_channel
*src0
,
3294 const union tgsi_exec_channel
*src1
)
3296 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
3297 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
3298 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
3299 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
3303 micro_umad(union tgsi_exec_channel
*dst
,
3304 const union tgsi_exec_channel
*src0
,
3305 const union tgsi_exec_channel
*src1
,
3306 const union tgsi_exec_channel
*src2
)
3308 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
3309 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
3310 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
3311 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
3315 micro_umax(union tgsi_exec_channel
*dst
,
3316 const union tgsi_exec_channel
*src0
,
3317 const union tgsi_exec_channel
*src1
)
3319 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3320 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3321 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3322 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3326 micro_umin(union tgsi_exec_channel
*dst
,
3327 const union tgsi_exec_channel
*src0
,
3328 const union tgsi_exec_channel
*src1
)
3330 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3331 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3332 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3333 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3337 micro_umod(union tgsi_exec_channel
*dst
,
3338 const union tgsi_exec_channel
*src0
,
3339 const union tgsi_exec_channel
*src1
)
3341 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
3342 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
3343 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
3344 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
3348 micro_umul(union tgsi_exec_channel
*dst
,
3349 const union tgsi_exec_channel
*src0
,
3350 const union tgsi_exec_channel
*src1
)
3352 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
3353 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
3354 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
3355 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
3359 micro_useq(union tgsi_exec_channel
*dst
,
3360 const union tgsi_exec_channel
*src0
,
3361 const union tgsi_exec_channel
*src1
)
3363 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
3364 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
3365 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
3366 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
3370 micro_usge(union tgsi_exec_channel
*dst
,
3371 const union tgsi_exec_channel
*src0
,
3372 const union tgsi_exec_channel
*src1
)
3374 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
3375 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
3376 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
3377 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
3381 micro_ushr(union tgsi_exec_channel
*dst
,
3382 const union tgsi_exec_channel
*src0
,
3383 const union tgsi_exec_channel
*src1
)
3385 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
3386 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
3387 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
3388 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
3392 micro_uslt(union tgsi_exec_channel
*dst
,
3393 const union tgsi_exec_channel
*src0
,
3394 const union tgsi_exec_channel
*src1
)
3396 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
3397 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
3398 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
3399 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
3403 micro_usne(union tgsi_exec_channel
*dst
,
3404 const union tgsi_exec_channel
*src0
,
3405 const union tgsi_exec_channel
*src1
)
3407 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
3408 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
3409 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
3410 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
3414 micro_uarl(union tgsi_exec_channel
*dst
,
3415 const union tgsi_exec_channel
*src
)
3417 dst
->i
[0] = src
->u
[0];
3418 dst
->i
[1] = src
->u
[1];
3419 dst
->i
[2] = src
->u
[2];
3420 dst
->i
[3] = src
->u
[3];
3424 micro_ucmp(union tgsi_exec_channel
*dst
,
3425 const union tgsi_exec_channel
*src0
,
3426 const union tgsi_exec_channel
*src1
,
3427 const union tgsi_exec_channel
*src2
)
3429 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
3430 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
3431 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
3432 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
3437 struct tgsi_exec_machine
*mach
,
3438 const struct tgsi_full_instruction
*inst
,
3441 union tgsi_exec_channel r
[10];
3445 switch (inst
->Instruction
.Opcode
) {
3446 case TGSI_OPCODE_ARL
:
3447 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3450 case TGSI_OPCODE_MOV
:
3451 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3454 case TGSI_OPCODE_LIT
:
3455 exec_lit(mach
, inst
);
3458 case TGSI_OPCODE_RCP
:
3459 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3462 case TGSI_OPCODE_RSQ
:
3463 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3466 case TGSI_OPCODE_EXP
:
3467 exec_exp(mach
, inst
);
3470 case TGSI_OPCODE_LOG
:
3471 exec_log(mach
, inst
);
3474 case TGSI_OPCODE_MUL
:
3475 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3478 case TGSI_OPCODE_ADD
:
3479 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3482 case TGSI_OPCODE_DP3
:
3483 exec_dp3(mach
, inst
);
3486 case TGSI_OPCODE_DP4
:
3487 exec_dp4(mach
, inst
);
3490 case TGSI_OPCODE_DST
:
3491 exec_dst(mach
, inst
);
3494 case TGSI_OPCODE_MIN
:
3495 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3498 case TGSI_OPCODE_MAX
:
3499 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3502 case TGSI_OPCODE_SLT
:
3503 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3506 case TGSI_OPCODE_SGE
:
3507 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3510 case TGSI_OPCODE_MAD
:
3511 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3514 case TGSI_OPCODE_SUB
:
3515 exec_vector_binary(mach
, inst
, micro_sub
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3518 case TGSI_OPCODE_LRP
:
3519 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3522 case TGSI_OPCODE_CND
:
3523 exec_vector_trinary(mach
, inst
, micro_cnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3526 case TGSI_OPCODE_DP2A
:
3527 exec_dp2a(mach
, inst
);
3530 case TGSI_OPCODE_FRC
:
3531 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3534 case TGSI_OPCODE_CLAMP
:
3535 exec_vector_trinary(mach
, inst
, micro_clamp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3538 case TGSI_OPCODE_FLR
:
3539 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3542 case TGSI_OPCODE_ROUND
:
3543 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3546 case TGSI_OPCODE_EX2
:
3547 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3550 case TGSI_OPCODE_LG2
:
3551 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3554 case TGSI_OPCODE_POW
:
3555 exec_scalar_binary(mach
, inst
, micro_pow
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3558 case TGSI_OPCODE_XPD
:
3559 exec_xpd(mach
, inst
);
3562 case TGSI_OPCODE_ABS
:
3563 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3566 case TGSI_OPCODE_RCC
:
3567 exec_scalar_unary(mach
, inst
, micro_rcc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3570 case TGSI_OPCODE_DPH
:
3571 exec_dph(mach
, inst
);
3574 case TGSI_OPCODE_COS
:
3575 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3578 case TGSI_OPCODE_DDX
:
3579 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3582 case TGSI_OPCODE_DDY
:
3583 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3586 case TGSI_OPCODE_KILP
:
3587 exec_kilp (mach
, inst
);
3590 case TGSI_OPCODE_KIL
:
3591 exec_kil (mach
, inst
);
3594 case TGSI_OPCODE_PK2H
:
3598 case TGSI_OPCODE_PK2US
:
3602 case TGSI_OPCODE_PK4B
:
3606 case TGSI_OPCODE_PK4UB
:
3610 case TGSI_OPCODE_RFL
:
3611 exec_rfl(mach
, inst
);
3614 case TGSI_OPCODE_SEQ
:
3615 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3618 case TGSI_OPCODE_SFL
:
3619 exec_vector(mach
, inst
, micro_sfl
, TGSI_EXEC_DATA_FLOAT
);
3622 case TGSI_OPCODE_SGT
:
3623 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3626 case TGSI_OPCODE_SIN
:
3627 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3630 case TGSI_OPCODE_SLE
:
3631 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3634 case TGSI_OPCODE_SNE
:
3635 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3638 case TGSI_OPCODE_STR
:
3639 exec_vector(mach
, inst
, micro_str
, TGSI_EXEC_DATA_FLOAT
);
3642 case TGSI_OPCODE_TEX
:
3643 /* simple texture lookup */
3644 /* src[0] = texcoord */
3645 /* src[1] = sampler unit */
3646 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
);
3649 case TGSI_OPCODE_TXB
:
3650 /* Texture lookup with lod bias */
3651 /* src[0] = texcoord (src[0].w = LOD bias) */
3652 /* src[1] = sampler unit */
3653 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
);
3656 case TGSI_OPCODE_TXD
:
3657 /* Texture lookup with explict partial derivatives */
3658 /* src[0] = texcoord */
3659 /* src[1] = d[strq]/dx */
3660 /* src[2] = d[strq]/dy */
3661 /* src[3] = sampler unit */
3662 exec_txd(mach
, inst
);
3665 case TGSI_OPCODE_TXL
:
3666 /* Texture lookup with explit LOD */
3667 /* src[0] = texcoord (src[0].w = LOD) */
3668 /* src[1] = sampler unit */
3669 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
);
3672 case TGSI_OPCODE_TXP
:
3673 /* Texture lookup with projection */
3674 /* src[0] = texcoord (src[0].w = projection) */
3675 /* src[1] = sampler unit */
3676 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
);
3679 case TGSI_OPCODE_UP2H
:
3683 case TGSI_OPCODE_UP2US
:
3687 case TGSI_OPCODE_UP4B
:
3691 case TGSI_OPCODE_UP4UB
:
3695 case TGSI_OPCODE_X2D
:
3696 exec_x2d(mach
, inst
);
3699 case TGSI_OPCODE_ARA
:
3703 case TGSI_OPCODE_ARR
:
3704 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3707 case TGSI_OPCODE_BRA
:
3711 case TGSI_OPCODE_CAL
:
3712 /* skip the call if no execution channels are enabled */
3713 if (mach
->ExecMask
) {
3716 /* First, record the depths of the execution stacks.
3717 * This is important for deeply nested/looped return statements.
3718 * We have to unwind the stacks by the correct amount. For a
3719 * real code generator, we could determine the number of entries
3720 * to pop off each stack with simple static analysis and avoid
3721 * implementing this data structure at run time.
3723 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
3724 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
3725 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
3726 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
3727 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
3728 /* note that PC was already incremented above */
3729 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
3731 mach
->CallStackTop
++;
3733 /* Second, push the Cond, Loop, Cont, Func stacks */
3734 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3735 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3736 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3737 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3738 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3739 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
3741 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3742 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3743 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3744 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3745 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3746 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
3748 /* Finally, jump to the subroutine */
3749 *pc
= inst
->Label
.Label
;
3753 case TGSI_OPCODE_RET
:
3754 mach
->FuncMask
&= ~mach
->ExecMask
;
3755 UPDATE_EXEC_MASK(mach
);
3757 if (mach
->FuncMask
== 0x0) {
3758 /* really return now (otherwise, keep executing */
3760 if (mach
->CallStackTop
== 0) {
3761 /* returning from main() */
3762 mach
->CondStackTop
= 0;
3763 mach
->LoopStackTop
= 0;
3768 assert(mach
->CallStackTop
> 0);
3769 mach
->CallStackTop
--;
3771 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3772 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3774 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3775 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3777 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3778 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3780 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3781 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3783 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3784 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3786 assert(mach
->FuncStackTop
> 0);
3787 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3789 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3791 UPDATE_EXEC_MASK(mach
);
3795 case TGSI_OPCODE_SSG
:
3796 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3799 case TGSI_OPCODE_CMP
:
3800 exec_vector_trinary(mach
, inst
, micro_cmp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3803 case TGSI_OPCODE_SCS
:
3804 exec_scs(mach
, inst
);
3807 case TGSI_OPCODE_NRM
:
3808 exec_nrm3(mach
, inst
);
3811 case TGSI_OPCODE_NRM4
:
3812 exec_nrm4(mach
, inst
);
3815 case TGSI_OPCODE_DIV
:
3816 exec_vector_binary(mach
, inst
, micro_div
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3819 case TGSI_OPCODE_DP2
:
3820 exec_dp2(mach
, inst
);
3823 case TGSI_OPCODE_IF
:
3825 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3826 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3827 FETCH( &r
[0], 0, TGSI_CHAN_X
);
3828 /* update CondMask */
3830 mach
->CondMask
&= ~0x1;
3833 mach
->CondMask
&= ~0x2;
3836 mach
->CondMask
&= ~0x4;
3839 mach
->CondMask
&= ~0x8;
3841 UPDATE_EXEC_MASK(mach
);
3842 /* Todo: If CondMask==0, jump to ELSE */
3845 case TGSI_OPCODE_ELSE
:
3846 /* invert CondMask wrt previous mask */
3849 assert(mach
->CondStackTop
> 0);
3850 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3851 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3852 UPDATE_EXEC_MASK(mach
);
3853 /* Todo: If CondMask==0, jump to ENDIF */
3857 case TGSI_OPCODE_ENDIF
:
3859 assert(mach
->CondStackTop
> 0);
3860 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3861 UPDATE_EXEC_MASK(mach
);
3864 case TGSI_OPCODE_END
:
3865 /* make sure we end primitives which haven't
3866 * been explicitly emitted */
3867 conditional_emit_primitive(mach
);
3868 /* halt execution */
3872 case TGSI_OPCODE_PUSHA
:
3876 case TGSI_OPCODE_POPA
:
3880 case TGSI_OPCODE_CEIL
:
3881 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3884 case TGSI_OPCODE_I2F
:
3885 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
3888 case TGSI_OPCODE_NOT
:
3889 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3892 case TGSI_OPCODE_TRUNC
:
3893 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3896 case TGSI_OPCODE_SHL
:
3897 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3900 case TGSI_OPCODE_AND
:
3901 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3904 case TGSI_OPCODE_OR
:
3905 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3908 case TGSI_OPCODE_MOD
:
3909 exec_vector_binary(mach
, inst
, micro_mod
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3912 case TGSI_OPCODE_XOR
:
3913 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3916 case TGSI_OPCODE_SAD
:
3920 case TGSI_OPCODE_TXF
:
3921 exec_txf(mach
, inst
);
3924 case TGSI_OPCODE_TXQ
:
3925 exec_txq(mach
, inst
);
3928 case TGSI_OPCODE_EMIT
:
3932 case TGSI_OPCODE_ENDPRIM
:
3933 emit_primitive(mach
);
3936 case TGSI_OPCODE_BGNLOOP
:
3937 /* push LoopMask and ContMasks */
3938 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3939 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3940 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3941 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3943 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3944 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3945 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
3946 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3947 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
3950 case TGSI_OPCODE_ENDLOOP
:
3951 /* Restore ContMask, but don't pop */
3952 assert(mach
->ContStackTop
> 0);
3953 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
3954 UPDATE_EXEC_MASK(mach
);
3955 if (mach
->ExecMask
) {
3956 /* repeat loop: jump to instruction just past BGNLOOP */
3957 assert(mach
->LoopLabelStackTop
> 0);
3958 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
3961 /* exit loop: pop LoopMask */
3962 assert(mach
->LoopStackTop
> 0);
3963 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
3965 assert(mach
->ContStackTop
> 0);
3966 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
3967 assert(mach
->LoopLabelStackTop
> 0);
3968 --mach
->LoopLabelStackTop
;
3970 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3972 UPDATE_EXEC_MASK(mach
);
3975 case TGSI_OPCODE_BRK
:
3979 case TGSI_OPCODE_CONT
:
3980 /* turn off cont channels for each enabled exec channel */
3981 mach
->ContMask
&= ~mach
->ExecMask
;
3982 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3983 UPDATE_EXEC_MASK(mach
);
3986 case TGSI_OPCODE_BGNSUB
:
3990 case TGSI_OPCODE_ENDSUB
:
3992 * XXX: This really should be a no-op. We should never reach this opcode.
3995 assert(mach
->CallStackTop
> 0);
3996 mach
->CallStackTop
--;
3998 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3999 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
4001 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
4002 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
4004 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
4005 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
4007 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
4008 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
4010 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
4011 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
4013 assert(mach
->FuncStackTop
> 0);
4014 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
4016 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
4018 UPDATE_EXEC_MASK(mach
);
4021 case TGSI_OPCODE_NOP
:
4024 case TGSI_OPCODE_BREAKC
:
4025 FETCH(&r
[0], 0, TGSI_CHAN_X
);
4026 /* update CondMask */
4027 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
4028 mach
->LoopMask
&= ~0x1;
4030 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
4031 mach
->LoopMask
&= ~0x2;
4033 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
4034 mach
->LoopMask
&= ~0x4;
4036 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
4037 mach
->LoopMask
&= ~0x8;
4039 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4040 UPDATE_EXEC_MASK(mach
);
4043 case TGSI_OPCODE_F2I
:
4044 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
4047 case TGSI_OPCODE_IDIV
:
4048 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4051 case TGSI_OPCODE_IMAX
:
4052 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4055 case TGSI_OPCODE_IMIN
:
4056 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4059 case TGSI_OPCODE_INEG
:
4060 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4063 case TGSI_OPCODE_ISGE
:
4064 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4067 case TGSI_OPCODE_ISHR
:
4068 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4071 case TGSI_OPCODE_ISLT
:
4072 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4075 case TGSI_OPCODE_F2U
:
4076 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4079 case TGSI_OPCODE_U2F
:
4080 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
4083 case TGSI_OPCODE_UADD
:
4084 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4087 case TGSI_OPCODE_UDIV
:
4088 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4091 case TGSI_OPCODE_UMAD
:
4092 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4095 case TGSI_OPCODE_UMAX
:
4096 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4099 case TGSI_OPCODE_UMIN
:
4100 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4103 case TGSI_OPCODE_UMOD
:
4104 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4107 case TGSI_OPCODE_UMUL
:
4108 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4111 case TGSI_OPCODE_USEQ
:
4112 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4115 case TGSI_OPCODE_USGE
:
4116 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4119 case TGSI_OPCODE_USHR
:
4120 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4123 case TGSI_OPCODE_USLT
:
4124 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4127 case TGSI_OPCODE_USNE
:
4128 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4131 case TGSI_OPCODE_SWITCH
:
4132 exec_switch(mach
, inst
);
4135 case TGSI_OPCODE_CASE
:
4136 exec_case(mach
, inst
);
4139 case TGSI_OPCODE_DEFAULT
:
4143 case TGSI_OPCODE_ENDSWITCH
:
4144 exec_endswitch(mach
);
4147 case TGSI_OPCODE_SAMPLE_I
:
4151 case TGSI_OPCODE_SAMPLE_I_MS
:
4155 case TGSI_OPCODE_SAMPLE
:
4156 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
);
4159 case TGSI_OPCODE_SAMPLE_B
:
4160 exec_sample(mach
, inst
, TEX_MODIFIER_LOD_BIAS
);
4163 case TGSI_OPCODE_SAMPLE_C
:
4164 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
);
4167 case TGSI_OPCODE_SAMPLE_C_LZ
:
4168 exec_sample(mach
, inst
, TEX_MODIFIER_LOD_BIAS
);
4171 case TGSI_OPCODE_SAMPLE_D
:
4172 exec_sample_d(mach
, inst
);
4175 case TGSI_OPCODE_SAMPLE_L
:
4176 exec_sample(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
);
4179 case TGSI_OPCODE_GATHER4
:
4183 case TGSI_OPCODE_SVIEWINFO
:
4187 case TGSI_OPCODE_SAMPLE_POS
:
4191 case TGSI_OPCODE_SAMPLE_INFO
:
4195 case TGSI_OPCODE_UARL
:
4196 exec_vector_unary(mach
, inst
, micro_uarl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4199 case TGSI_OPCODE_UCMP
:
4200 exec_vector_trinary(mach
, inst
, micro_ucmp
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4203 case TGSI_OPCODE_IABS
:
4204 exec_vector_unary(mach
, inst
, micro_iabs
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4207 case TGSI_OPCODE_ISSG
:
4208 exec_vector_unary(mach
, inst
, micro_isgn
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4217 #define DEBUG_EXECUTION 0
4221 * Run TGSI interpreter.
4222 * \return bitmask of "alive" quad components
4225 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
4230 mach
->CondMask
= 0xf;
4231 mach
->LoopMask
= 0xf;
4232 mach
->ContMask
= 0xf;
4233 mach
->FuncMask
= 0xf;
4234 mach
->ExecMask
= 0xf;
4236 mach
->Switch
.mask
= 0xf;
4238 assert(mach
->CondStackTop
== 0);
4239 assert(mach
->LoopStackTop
== 0);
4240 assert(mach
->ContStackTop
== 0);
4241 assert(mach
->SwitchStackTop
== 0);
4242 assert(mach
->BreakStackTop
== 0);
4243 assert(mach
->CallStackTop
== 0);
4245 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
4246 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
4248 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
4249 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
4250 mach
->Primitives
[0] = 0;
4253 /* execute declarations (interpolants) */
4254 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
4255 exec_declaration( mach
, mach
->Declarations
+i
);
4260 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
4261 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
4264 memcpy(temps
, mach
->Temps
, sizeof(temps
));
4265 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
4268 /* execute instructions, until pc is set to -1 */
4274 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
4277 assert(pc
< (int) mach
->NumInstructions
);
4278 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
4281 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
4282 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
4285 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
4286 debug_printf("TEMP[%2u] = ", i
);
4287 for (j
= 0; j
< 4; j
++) {
4291 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4292 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
4293 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
4294 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
4295 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
4299 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
4300 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
4303 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
4304 debug_printf("OUT[%2u] = ", i
);
4305 for (j
= 0; j
< 4; j
++) {
4309 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4310 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
4311 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
4312 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
4313 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
4322 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
4323 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
4325 * Scale back depth component.
4327 for (i
= 0; i
< 4; i
++)
4328 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
4332 /* Strictly speaking, these assertions aren't really needed but they
4333 * can potentially catch some bugs in the control flow code.
4335 assert(mach
->CondStackTop
== 0);
4336 assert(mach
->LoopStackTop
== 0);
4337 assert(mach
->ContStackTop
== 0);
4338 assert(mach
->SwitchStackTop
== 0);
4339 assert(mach
->BreakStackTop
== 0);
4340 assert(mach
->CallStackTop
== 0);
4342 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];