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_sqrt(union tgsi_exec_channel
*dst
,
347 const union tgsi_exec_channel
*src
)
349 dst
->f
[0] = sqrtf(fabsf(src
->f
[0]));
350 dst
->f
[1] = sqrtf(fabsf(src
->f
[1]));
351 dst
->f
[2] = sqrtf(fabsf(src
->f
[2]));
352 dst
->f
[3] = sqrtf(fabsf(src
->f
[3]));
356 micro_seq(union tgsi_exec_channel
*dst
,
357 const union tgsi_exec_channel
*src0
,
358 const union tgsi_exec_channel
*src1
)
360 dst
->f
[0] = src0
->f
[0] == src1
->f
[0] ? 1.0f
: 0.0f
;
361 dst
->f
[1] = src0
->f
[1] == src1
->f
[1] ? 1.0f
: 0.0f
;
362 dst
->f
[2] = src0
->f
[2] == src1
->f
[2] ? 1.0f
: 0.0f
;
363 dst
->f
[3] = src0
->f
[3] == src1
->f
[3] ? 1.0f
: 0.0f
;
367 micro_sge(union tgsi_exec_channel
*dst
,
368 const union tgsi_exec_channel
*src0
,
369 const union tgsi_exec_channel
*src1
)
371 dst
->f
[0] = src0
->f
[0] >= src1
->f
[0] ? 1.0f
: 0.0f
;
372 dst
->f
[1] = src0
->f
[1] >= src1
->f
[1] ? 1.0f
: 0.0f
;
373 dst
->f
[2] = src0
->f
[2] >= src1
->f
[2] ? 1.0f
: 0.0f
;
374 dst
->f
[3] = src0
->f
[3] >= src1
->f
[3] ? 1.0f
: 0.0f
;
378 micro_sgn(union tgsi_exec_channel
*dst
,
379 const union tgsi_exec_channel
*src
)
381 dst
->f
[0] = src
->f
[0] < 0.0f
? -1.0f
: src
->f
[0] > 0.0f
? 1.0f
: 0.0f
;
382 dst
->f
[1] = src
->f
[1] < 0.0f
? -1.0f
: src
->f
[1] > 0.0f
? 1.0f
: 0.0f
;
383 dst
->f
[2] = src
->f
[2] < 0.0f
? -1.0f
: src
->f
[2] > 0.0f
? 1.0f
: 0.0f
;
384 dst
->f
[3] = src
->f
[3] < 0.0f
? -1.0f
: src
->f
[3] > 0.0f
? 1.0f
: 0.0f
;
388 micro_isgn(union tgsi_exec_channel
*dst
,
389 const union tgsi_exec_channel
*src
)
391 dst
->i
[0] = src
->i
[0] < 0 ? -1 : src
->i
[0] > 0 ? 1 : 0;
392 dst
->i
[1] = src
->i
[1] < 0 ? -1 : src
->i
[1] > 0 ? 1 : 0;
393 dst
->i
[2] = src
->i
[2] < 0 ? -1 : src
->i
[2] > 0 ? 1 : 0;
394 dst
->i
[3] = src
->i
[3] < 0 ? -1 : src
->i
[3] > 0 ? 1 : 0;
398 micro_sgt(union tgsi_exec_channel
*dst
,
399 const union tgsi_exec_channel
*src0
,
400 const union tgsi_exec_channel
*src1
)
402 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? 1.0f
: 0.0f
;
403 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? 1.0f
: 0.0f
;
404 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? 1.0f
: 0.0f
;
405 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? 1.0f
: 0.0f
;
409 micro_sin(union tgsi_exec_channel
*dst
,
410 const union tgsi_exec_channel
*src
)
412 dst
->f
[0] = sinf(src
->f
[0]);
413 dst
->f
[1] = sinf(src
->f
[1]);
414 dst
->f
[2] = sinf(src
->f
[2]);
415 dst
->f
[3] = sinf(src
->f
[3]);
419 micro_sle(union tgsi_exec_channel
*dst
,
420 const union tgsi_exec_channel
*src0
,
421 const union tgsi_exec_channel
*src1
)
423 dst
->f
[0] = src0
->f
[0] <= src1
->f
[0] ? 1.0f
: 0.0f
;
424 dst
->f
[1] = src0
->f
[1] <= src1
->f
[1] ? 1.0f
: 0.0f
;
425 dst
->f
[2] = src0
->f
[2] <= src1
->f
[2] ? 1.0f
: 0.0f
;
426 dst
->f
[3] = src0
->f
[3] <= src1
->f
[3] ? 1.0f
: 0.0f
;
430 micro_slt(union tgsi_exec_channel
*dst
,
431 const union tgsi_exec_channel
*src0
,
432 const union tgsi_exec_channel
*src1
)
434 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? 1.0f
: 0.0f
;
435 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? 1.0f
: 0.0f
;
436 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? 1.0f
: 0.0f
;
437 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? 1.0f
: 0.0f
;
441 micro_sne(union tgsi_exec_channel
*dst
,
442 const union tgsi_exec_channel
*src0
,
443 const union tgsi_exec_channel
*src1
)
445 dst
->f
[0] = src0
->f
[0] != src1
->f
[0] ? 1.0f
: 0.0f
;
446 dst
->f
[1] = src0
->f
[1] != src1
->f
[1] ? 1.0f
: 0.0f
;
447 dst
->f
[2] = src0
->f
[2] != src1
->f
[2] ? 1.0f
: 0.0f
;
448 dst
->f
[3] = src0
->f
[3] != src1
->f
[3] ? 1.0f
: 0.0f
;
452 micro_sfl(union tgsi_exec_channel
*dst
)
461 micro_str(union tgsi_exec_channel
*dst
)
470 micro_trunc(union tgsi_exec_channel
*dst
,
471 const union tgsi_exec_channel
*src
)
473 dst
->f
[0] = (float)(int)src
->f
[0];
474 dst
->f
[1] = (float)(int)src
->f
[1];
475 dst
->f
[2] = (float)(int)src
->f
[2];
476 dst
->f
[3] = (float)(int)src
->f
[3];
480 enum tgsi_exec_datatype
{
481 TGSI_EXEC_DATA_FLOAT
,
487 * Shorthand locations of various utility registers (_I = Index, _C = Channel)
489 #define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I
490 #define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C
491 #define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I
492 #define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C
493 #define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I
494 #define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C
497 /** The execution mask depends on the conditional mask and the loop mask */
498 #define UPDATE_EXEC_MASK(MACH) \
499 MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask
502 static const union tgsi_exec_channel ZeroVec
=
503 { { 0.0, 0.0, 0.0, 0.0 } };
505 static const union tgsi_exec_channel OneVec
= {
506 {1.0f
, 1.0f
, 1.0f
, 1.0f
}
509 static const union tgsi_exec_channel P128Vec
= {
510 {128.0f
, 128.0f
, 128.0f
, 128.0f
}
513 static const union tgsi_exec_channel M128Vec
= {
514 {-128.0f
, -128.0f
, -128.0f
, -128.0f
}
519 * Assert that none of the float values in 'chan' are infinite or NaN.
520 * NaN and Inf may occur normally during program execution and should
521 * not lead to crashes, etc. But when debugging, it's helpful to catch
525 check_inf_or_nan(const union tgsi_exec_channel
*chan
)
527 assert(!util_is_inf_or_nan((chan
)->f
[0]));
528 assert(!util_is_inf_or_nan((chan
)->f
[1]));
529 assert(!util_is_inf_or_nan((chan
)->f
[2]));
530 assert(!util_is_inf_or_nan((chan
)->f
[3]));
536 print_chan(const char *msg
, const union tgsi_exec_channel
*chan
)
538 debug_printf("%s = {%f, %f, %f, %f}\n",
539 msg
, chan
->f
[0], chan
->f
[1], chan
->f
[2], chan
->f
[3]);
546 print_temp(const struct tgsi_exec_machine
*mach
, uint index
)
548 const struct tgsi_exec_vector
*tmp
= &mach
->Temps
[index
];
550 debug_printf("Temp[%u] =\n", index
);
551 for (i
= 0; i
< 4; i
++) {
552 debug_printf(" %c: { %f, %f, %f, %f }\n",
564 tgsi_exec_set_constant_buffers(struct tgsi_exec_machine
*mach
,
567 const unsigned *buf_sizes
)
571 for (i
= 0; i
< num_bufs
; i
++) {
572 mach
->Consts
[i
] = bufs
[i
];
573 mach
->ConstsSize
[i
] = buf_sizes
[i
];
579 * Check if there's a potential src/dst register data dependency when
580 * using SOA execution.
583 * This would expand into:
588 * The second instruction will have the wrong value for t0 if executed as-is.
591 tgsi_check_soa_dependencies(const struct tgsi_full_instruction
*inst
)
595 uint writemask
= inst
->Dst
[0].Register
.WriteMask
;
596 if (writemask
== TGSI_WRITEMASK_X
||
597 writemask
== TGSI_WRITEMASK_Y
||
598 writemask
== TGSI_WRITEMASK_Z
||
599 writemask
== TGSI_WRITEMASK_W
||
600 writemask
== TGSI_WRITEMASK_NONE
) {
601 /* no chance of data dependency */
605 /* loop over src regs */
606 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
607 if ((inst
->Src
[i
].Register
.File
==
608 inst
->Dst
[0].Register
.File
) &&
609 ((inst
->Src
[i
].Register
.Index
==
610 inst
->Dst
[0].Register
.Index
) ||
611 inst
->Src
[i
].Register
.Indirect
||
612 inst
->Dst
[0].Register
.Indirect
)) {
613 /* loop over dest channels */
614 uint channelsWritten
= 0x0;
615 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
616 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
617 /* check if we're reading a channel that's been written */
618 uint swizzle
= tgsi_util_get_full_src_register_swizzle(&inst
->Src
[i
], chan
);
619 if (channelsWritten
& (1 << swizzle
)) {
623 channelsWritten
|= (1 << chan
);
633 * Initialize machine state by expanding tokens to full instructions,
634 * allocating temporary storage, setting up constants, etc.
635 * After this, we can call tgsi_exec_machine_run() many times.
638 tgsi_exec_machine_bind_shader(
639 struct tgsi_exec_machine
*mach
,
640 const struct tgsi_token
*tokens
,
642 struct tgsi_sampler
**samplers
)
645 struct tgsi_parse_context parse
;
646 struct tgsi_full_instruction
*instructions
;
647 struct tgsi_full_declaration
*declarations
;
648 uint maxInstructions
= 10, numInstructions
= 0;
649 uint maxDeclarations
= 10, numDeclarations
= 0;
652 tgsi_dump(tokens
, 0);
661 mach
->Tokens
= tokens
;
662 mach
->Samplers
= samplers
;
665 /* unbind and free all */
666 FREE(mach
->Declarations
);
667 mach
->Declarations
= NULL
;
668 mach
->NumDeclarations
= 0;
670 FREE(mach
->Instructions
);
671 mach
->Instructions
= NULL
;
672 mach
->NumInstructions
= 0;
677 k
= tgsi_parse_init (&parse
, mach
->Tokens
);
678 if (k
!= TGSI_PARSE_OK
) {
679 debug_printf( "Problem parsing!\n" );
683 mach
->Processor
= parse
.FullHeader
.Processor
.Processor
;
686 if (mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
&&
687 !mach
->UsedGeometryShader
) {
688 struct tgsi_exec_vector
*inputs
;
689 struct tgsi_exec_vector
*outputs
;
691 inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
692 TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
,
698 outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) *
699 TGSI_MAX_TOTAL_VERTICES
, 16);
706 align_free(mach
->Inputs
);
707 align_free(mach
->Outputs
);
709 mach
->Inputs
= inputs
;
710 mach
->Outputs
= outputs
;
711 mach
->UsedGeometryShader
= TRUE
;
714 declarations
= (struct tgsi_full_declaration
*)
715 MALLOC( maxDeclarations
* sizeof(struct tgsi_full_declaration
) );
721 instructions
= (struct tgsi_full_instruction
*)
722 MALLOC( maxInstructions
* sizeof(struct tgsi_full_instruction
) );
725 FREE( declarations
);
729 while( !tgsi_parse_end_of_tokens( &parse
) ) {
732 tgsi_parse_token( &parse
);
733 switch( parse
.FullToken
.Token
.Type
) {
734 case TGSI_TOKEN_TYPE_DECLARATION
:
735 /* save expanded declaration */
736 if (numDeclarations
== maxDeclarations
) {
737 declarations
= REALLOC(declarations
,
739 * sizeof(struct tgsi_full_declaration
),
740 (maxDeclarations
+ 10)
741 * sizeof(struct tgsi_full_declaration
));
742 maxDeclarations
+= 10;
744 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
== TGSI_FILE_OUTPUT
) {
746 for (reg
= parse
.FullToken
.FullDeclaration
.Range
.First
;
747 reg
<= parse
.FullToken
.FullDeclaration
.Range
.Last
;
752 if (parse
.FullToken
.FullDeclaration
.Declaration
.File
==
753 TGSI_FILE_IMMEDIATE_ARRAY
) {
755 struct tgsi_full_declaration
*decl
=
756 &parse
.FullToken
.FullDeclaration
;
757 debug_assert(decl
->Range
.Last
< TGSI_EXEC_NUM_IMMEDIATES
);
758 for (reg
= decl
->Range
.First
; reg
<= decl
->Range
.Last
; ++reg
) {
759 for( i
= 0; i
< 4; i
++ ) {
760 int idx
= reg
* 4 + i
;
761 mach
->ImmArray
[reg
][i
] = decl
->ImmediateData
.u
[idx
].Float
;
765 memcpy(declarations
+ numDeclarations
,
766 &parse
.FullToken
.FullDeclaration
,
767 sizeof(declarations
[0]));
771 case TGSI_TOKEN_TYPE_IMMEDIATE
:
773 uint size
= parse
.FullToken
.FullImmediate
.Immediate
.NrTokens
- 1;
775 assert( mach
->ImmLimit
+ 1 <= TGSI_EXEC_NUM_IMMEDIATES
);
777 for( i
= 0; i
< size
; i
++ ) {
778 mach
->Imms
[mach
->ImmLimit
][i
] =
779 parse
.FullToken
.FullImmediate
.u
[i
].Float
;
785 case TGSI_TOKEN_TYPE_INSTRUCTION
:
787 /* save expanded instruction */
788 if (numInstructions
== maxInstructions
) {
789 instructions
= REALLOC(instructions
,
791 * sizeof(struct tgsi_full_instruction
),
792 (maxInstructions
+ 10)
793 * sizeof(struct tgsi_full_instruction
));
794 maxInstructions
+= 10;
797 memcpy(instructions
+ numInstructions
,
798 &parse
.FullToken
.FullInstruction
,
799 sizeof(instructions
[0]));
804 case TGSI_TOKEN_TYPE_PROPERTY
:
811 tgsi_parse_free (&parse
);
813 FREE(mach
->Declarations
);
814 mach
->Declarations
= declarations
;
815 mach
->NumDeclarations
= numDeclarations
;
817 FREE(mach
->Instructions
);
818 mach
->Instructions
= instructions
;
819 mach
->NumInstructions
= numInstructions
;
823 struct tgsi_exec_machine
*
824 tgsi_exec_machine_create( void )
826 struct tgsi_exec_machine
*mach
;
829 mach
= align_malloc( sizeof *mach
, 16 );
833 memset(mach
, 0, sizeof(*mach
));
835 mach
->Addrs
= &mach
->Temps
[TGSI_EXEC_TEMP_ADDR
];
836 mach
->MaxGeometryShaderOutputs
= TGSI_MAX_TOTAL_VERTICES
;
837 mach
->Predicates
= &mach
->Temps
[TGSI_EXEC_TEMP_P0
];
839 mach
->Inputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_ATTRIBS
, 16);
840 mach
->Outputs
= align_malloc(sizeof(struct tgsi_exec_vector
) * PIPE_MAX_ATTRIBS
, 16);
841 if (!mach
->Inputs
|| !mach
->Outputs
)
844 /* Setup constants needed by the SSE2 executor. */
845 for( i
= 0; i
< 4; i
++ ) {
846 mach
->Temps
[TGSI_EXEC_TEMP_00000000_I
].xyzw
[TGSI_EXEC_TEMP_00000000_C
].u
[i
] = 0x00000000;
847 mach
->Temps
[TGSI_EXEC_TEMP_7FFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_7FFFFFFF_C
].u
[i
] = 0x7FFFFFFF;
848 mach
->Temps
[TGSI_EXEC_TEMP_80000000_I
].xyzw
[TGSI_EXEC_TEMP_80000000_C
].u
[i
] = 0x80000000;
849 mach
->Temps
[TGSI_EXEC_TEMP_FFFFFFFF_I
].xyzw
[TGSI_EXEC_TEMP_FFFFFFFF_C
].u
[i
] = 0xFFFFFFFF; /* not used */
850 mach
->Temps
[TGSI_EXEC_TEMP_ONE_I
].xyzw
[TGSI_EXEC_TEMP_ONE_C
].f
[i
] = 1.0f
;
851 mach
->Temps
[TGSI_EXEC_TEMP_TWO_I
].xyzw
[TGSI_EXEC_TEMP_TWO_C
].f
[i
] = 2.0f
; /* not used */
852 mach
->Temps
[TGSI_EXEC_TEMP_128_I
].xyzw
[TGSI_EXEC_TEMP_128_C
].f
[i
] = 128.0f
;
853 mach
->Temps
[TGSI_EXEC_TEMP_MINUS_128_I
].xyzw
[TGSI_EXEC_TEMP_MINUS_128_C
].f
[i
] = -128.0f
;
854 mach
->Temps
[TGSI_EXEC_TEMP_THREE_I
].xyzw
[TGSI_EXEC_TEMP_THREE_C
].f
[i
] = 3.0f
;
855 mach
->Temps
[TGSI_EXEC_TEMP_HALF_I
].xyzw
[TGSI_EXEC_TEMP_HALF_C
].f
[i
] = 0.5f
;
859 /* silence warnings */
868 align_free(mach
->Inputs
);
869 align_free(mach
->Outputs
);
877 tgsi_exec_machine_destroy(struct tgsi_exec_machine
*mach
)
880 FREE(mach
->Instructions
);
881 FREE(mach
->Declarations
);
883 align_free(mach
->Inputs
);
884 align_free(mach
->Outputs
);
891 micro_add(union tgsi_exec_channel
*dst
,
892 const union tgsi_exec_channel
*src0
,
893 const union tgsi_exec_channel
*src1
)
895 dst
->f
[0] = src0
->f
[0] + src1
->f
[0];
896 dst
->f
[1] = src0
->f
[1] + src1
->f
[1];
897 dst
->f
[2] = src0
->f
[2] + src1
->f
[2];
898 dst
->f
[3] = src0
->f
[3] + src1
->f
[3];
903 union tgsi_exec_channel
*dst
,
904 const union tgsi_exec_channel
*src0
,
905 const union tgsi_exec_channel
*src1
)
907 if (src1
->f
[0] != 0) {
908 dst
->f
[0] = src0
->f
[0] / src1
->f
[0];
910 if (src1
->f
[1] != 0) {
911 dst
->f
[1] = src0
->f
[1] / src1
->f
[1];
913 if (src1
->f
[2] != 0) {
914 dst
->f
[2] = src0
->f
[2] / src1
->f
[2];
916 if (src1
->f
[3] != 0) {
917 dst
->f
[3] = src0
->f
[3] / src1
->f
[3];
922 micro_rcc(union tgsi_exec_channel
*dst
,
923 const union tgsi_exec_channel
*src
)
927 for (i
= 0; i
< 4; i
++) {
928 float recip
= 1.0f
/ src
->f
[i
];
931 if (recip
> 1.884467e+019f
) {
932 dst
->f
[i
] = 1.884467e+019f
;
934 else if (recip
< 5.42101e-020f
) {
935 dst
->f
[i
] = 5.42101e-020f
;
942 if (recip
< -1.884467e+019f
) {
943 dst
->f
[i
] = -1.884467e+019f
;
945 else if (recip
> -5.42101e-020f
) {
946 dst
->f
[i
] = -5.42101e-020f
;
957 union tgsi_exec_channel
*dst
,
958 const union tgsi_exec_channel
*src0
,
959 const union tgsi_exec_channel
*src1
,
960 const union tgsi_exec_channel
*src2
,
961 const union tgsi_exec_channel
*src3
)
963 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src2
->f
[0] : src3
->f
[0];
964 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src2
->f
[1] : src3
->f
[1];
965 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src2
->f
[2] : src3
->f
[2];
966 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src2
->f
[3] : src3
->f
[3];
970 micro_max(union tgsi_exec_channel
*dst
,
971 const union tgsi_exec_channel
*src0
,
972 const union tgsi_exec_channel
*src1
)
974 dst
->f
[0] = src0
->f
[0] > src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
975 dst
->f
[1] = src0
->f
[1] > src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
976 dst
->f
[2] = src0
->f
[2] > src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
977 dst
->f
[3] = src0
->f
[3] > src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
981 micro_min(union tgsi_exec_channel
*dst
,
982 const union tgsi_exec_channel
*src0
,
983 const union tgsi_exec_channel
*src1
)
985 dst
->f
[0] = src0
->f
[0] < src1
->f
[0] ? src0
->f
[0] : src1
->f
[0];
986 dst
->f
[1] = src0
->f
[1] < src1
->f
[1] ? src0
->f
[1] : src1
->f
[1];
987 dst
->f
[2] = src0
->f
[2] < src1
->f
[2] ? src0
->f
[2] : src1
->f
[2];
988 dst
->f
[3] = src0
->f
[3] < src1
->f
[3] ? src0
->f
[3] : src1
->f
[3];
992 micro_mul(union tgsi_exec_channel
*dst
,
993 const union tgsi_exec_channel
*src0
,
994 const union tgsi_exec_channel
*src1
)
996 dst
->f
[0] = src0
->f
[0] * src1
->f
[0];
997 dst
->f
[1] = src0
->f
[1] * src1
->f
[1];
998 dst
->f
[2] = src0
->f
[2] * src1
->f
[2];
999 dst
->f
[3] = src0
->f
[3] * src1
->f
[3];
1004 union tgsi_exec_channel
*dst
,
1005 const union tgsi_exec_channel
*src
)
1007 dst
->f
[0] = -src
->f
[0];
1008 dst
->f
[1] = -src
->f
[1];
1009 dst
->f
[2] = -src
->f
[2];
1010 dst
->f
[3] = -src
->f
[3];
1015 union tgsi_exec_channel
*dst
,
1016 const union tgsi_exec_channel
*src0
,
1017 const union tgsi_exec_channel
*src1
)
1020 dst
->f
[0] = util_fast_pow( src0
->f
[0], src1
->f
[0] );
1021 dst
->f
[1] = util_fast_pow( src0
->f
[1], src1
->f
[1] );
1022 dst
->f
[2] = util_fast_pow( src0
->f
[2], src1
->f
[2] );
1023 dst
->f
[3] = util_fast_pow( src0
->f
[3], src1
->f
[3] );
1025 dst
->f
[0] = powf( src0
->f
[0], src1
->f
[0] );
1026 dst
->f
[1] = powf( src0
->f
[1], src1
->f
[1] );
1027 dst
->f
[2] = powf( src0
->f
[2], src1
->f
[2] );
1028 dst
->f
[3] = powf( src0
->f
[3], src1
->f
[3] );
1033 micro_sub(union tgsi_exec_channel
*dst
,
1034 const union tgsi_exec_channel
*src0
,
1035 const union tgsi_exec_channel
*src1
)
1037 dst
->f
[0] = src0
->f
[0] - src1
->f
[0];
1038 dst
->f
[1] = src0
->f
[1] - src1
->f
[1];
1039 dst
->f
[2] = src0
->f
[2] - src1
->f
[2];
1040 dst
->f
[3] = src0
->f
[3] - src1
->f
[3];
1044 fetch_src_file_channel(const struct tgsi_exec_machine
*mach
,
1045 const uint chan_index
,
1048 const union tgsi_exec_channel
*index
,
1049 const union tgsi_exec_channel
*index2D
,
1050 union tgsi_exec_channel
*chan
)
1054 assert(swizzle
< 4);
1057 case TGSI_FILE_CONSTANT
:
1058 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1059 assert(index2D
->i
[i
] >= 0 && index2D
->i
[i
] < PIPE_MAX_CONSTANT_BUFFERS
);
1060 assert(mach
->Consts
[index2D
->i
[i
]]);
1062 if (index
->i
[i
] < 0) {
1065 /* NOTE: copying the const value as a uint instead of float */
1066 const uint constbuf
= index2D
->i
[i
];
1067 const uint
*buf
= (const uint
*)mach
->Consts
[constbuf
];
1068 const int pos
= index
->i
[i
] * 4 + swizzle
;
1069 /* const buffer bounds check */
1070 if (pos
< 0 || pos
>= (int) mach
->ConstsSize
[constbuf
]) {
1072 /* Debug: print warning */
1073 static int count
= 0;
1075 debug_printf("TGSI Exec: const buffer index %d"
1076 " out of bounds\n", pos
);
1081 chan
->u
[i
] = buf
[pos
];
1086 case TGSI_FILE_INPUT
:
1087 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1089 if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) {
1090 debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n",
1091 index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i],
1092 index2D->i[i], index->i[i]);
1094 int pos
= index2D
->i
[i
] * TGSI_EXEC_MAX_INPUT_ATTRIBS
+ index
->i
[i
];
1096 assert(pos
< TGSI_MAX_PRIM_VERTICES
* PIPE_MAX_ATTRIBS
);
1097 chan
->u
[i
] = mach
->Inputs
[pos
].xyzw
[swizzle
].u
[i
];
1101 case TGSI_FILE_SYSTEM_VALUE
:
1102 /* XXX no swizzling at this point. Will be needed if we put
1103 * gl_FragCoord, for example, in a sys value register.
1105 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1106 chan
->u
[i
] = mach
->SystemValue
[index
->i
[i
]].u
[i
];
1110 case TGSI_FILE_TEMPORARY
:
1111 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1112 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1113 assert(index2D
->i
[i
] == 0);
1115 chan
->u
[i
] = mach
->Temps
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1119 case TGSI_FILE_TEMPORARY_ARRAY
:
1120 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1121 assert(index
->i
[i
] < TGSI_EXEC_NUM_TEMPS
);
1122 assert(index2D
->i
[i
] < TGSI_EXEC_NUM_TEMP_ARRAYS
);
1125 mach
->TempArray
[index2D
->i
[i
]][index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1129 case TGSI_FILE_IMMEDIATE
:
1130 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1131 assert(index
->i
[i
] >= 0 && index
->i
[i
] < (int)mach
->ImmLimit
);
1132 assert(index2D
->i
[i
] == 0);
1134 chan
->f
[i
] = mach
->Imms
[index
->i
[i
]][swizzle
];
1138 case TGSI_FILE_IMMEDIATE_ARRAY
:
1139 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1140 assert(index2D
->i
[i
] == 0);
1142 chan
->f
[i
] = mach
->ImmArray
[index
->i
[i
]][swizzle
];
1146 case TGSI_FILE_ADDRESS
:
1147 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1148 assert(index
->i
[i
] >= 0);
1149 assert(index2D
->i
[i
] == 0);
1151 chan
->u
[i
] = mach
->Addrs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1155 case TGSI_FILE_PREDICATE
:
1156 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1157 assert(index
->i
[i
] >= 0 && index
->i
[i
] < TGSI_EXEC_NUM_PREDS
);
1158 assert(index2D
->i
[i
] == 0);
1160 chan
->u
[i
] = mach
->Predicates
[0].xyzw
[swizzle
].u
[i
];
1164 case TGSI_FILE_OUTPUT
:
1165 /* vertex/fragment output vars can be read too */
1166 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1167 assert(index
->i
[i
] >= 0);
1168 assert(index2D
->i
[i
] == 0);
1170 chan
->u
[i
] = mach
->Outputs
[index
->i
[i
]].xyzw
[swizzle
].u
[i
];
1176 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1183 fetch_source(const struct tgsi_exec_machine
*mach
,
1184 union tgsi_exec_channel
*chan
,
1185 const struct tgsi_full_src_register
*reg
,
1186 const uint chan_index
,
1187 enum tgsi_exec_datatype src_datatype
)
1189 union tgsi_exec_channel index
;
1190 union tgsi_exec_channel index2D
;
1193 /* We start with a direct index into a register file.
1197 * file = Register.File
1198 * [1] = Register.Index
1203 index
.i
[3] = reg
->Register
.Index
;
1205 /* There is an extra source register that indirectly subscripts
1206 * a register file. The direct index now becomes an offset
1207 * that is being added to the indirect register.
1211 * ind = Indirect.File
1212 * [2] = Indirect.Index
1213 * .x = Indirect.SwizzleX
1215 if (reg
->Register
.Indirect
) {
1216 union tgsi_exec_channel index2
;
1217 union tgsi_exec_channel indir_index
;
1218 const uint execmask
= mach
->ExecMask
;
1221 /* which address register (always zero now) */
1225 index2
.i
[3] = reg
->Indirect
.Index
;
1226 /* get current value of address register[swizzle] */
1227 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, TGSI_CHAN_X
);
1228 fetch_src_file_channel(mach
,
1236 /* add value of address register to the offset */
1237 index
.i
[0] += indir_index
.i
[0];
1238 index
.i
[1] += indir_index
.i
[1];
1239 index
.i
[2] += indir_index
.i
[2];
1240 index
.i
[3] += indir_index
.i
[3];
1242 /* for disabled execution channels, zero-out the index to
1243 * avoid using a potential garbage value.
1245 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1246 if ((execmask
& (1 << i
)) == 0)
1251 /* There is an extra source register that is a second
1252 * subscript to a register file. Effectively it means that
1253 * the register file is actually a 2D array of registers.
1257 * [3] = Dimension.Index
1259 if (reg
->Register
.Dimension
) {
1263 index2D
.i
[3] = reg
->Dimension
.Index
;
1265 /* Again, the second subscript index can be addressed indirectly
1266 * identically to the first one.
1267 * Nothing stops us from indirectly addressing the indirect register,
1268 * but there is no need for that, so we won't exercise it.
1270 * file[ind[4].y+3][1],
1272 * ind = DimIndirect.File
1273 * [4] = DimIndirect.Index
1274 * .y = DimIndirect.SwizzleX
1276 if (reg
->Dimension
.Indirect
) {
1277 union tgsi_exec_channel index2
;
1278 union tgsi_exec_channel indir_index
;
1279 const uint execmask
= mach
->ExecMask
;
1285 index2
.i
[3] = reg
->DimIndirect
.Index
;
1287 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, TGSI_CHAN_X
);
1288 fetch_src_file_channel(mach
,
1290 reg
->DimIndirect
.File
,
1296 index2D
.i
[0] += indir_index
.i
[0];
1297 index2D
.i
[1] += indir_index
.i
[1];
1298 index2D
.i
[2] += indir_index
.i
[2];
1299 index2D
.i
[3] += indir_index
.i
[3];
1301 /* for disabled execution channels, zero-out the index to
1302 * avoid using a potential garbage value.
1304 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1305 if ((execmask
& (1 << i
)) == 0) {
1311 /* If by any chance there was a need for a 3D array of register
1312 * files, we would have to check whether Dimension is followed
1313 * by a dimension register and continue the saga.
1322 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
1323 fetch_src_file_channel(mach
,
1331 if (reg
->Register
.Absolute
) {
1332 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1333 micro_abs(chan
, chan
);
1335 micro_iabs(chan
, chan
);
1339 if (reg
->Register
.Negate
) {
1340 if (src_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1341 micro_neg(chan
, chan
);
1343 micro_ineg(chan
, chan
);
1349 store_dest(struct tgsi_exec_machine
*mach
,
1350 const union tgsi_exec_channel
*chan
,
1351 const struct tgsi_full_dst_register
*reg
,
1352 const struct tgsi_full_instruction
*inst
,
1354 enum tgsi_exec_datatype dst_datatype
)
1357 union tgsi_exec_channel null
;
1358 union tgsi_exec_channel
*dst
;
1359 union tgsi_exec_channel index2D
;
1360 uint execmask
= mach
->ExecMask
;
1361 int offset
= 0; /* indirection offset */
1365 if (0 && dst_datatype
== TGSI_EXEC_DATA_FLOAT
) {
1366 check_inf_or_nan(chan
);
1369 /* There is an extra source register that indirectly subscripts
1370 * a register file. The direct index now becomes an offset
1371 * that is being added to the indirect register.
1375 * ind = Indirect.File
1376 * [2] = Indirect.Index
1377 * .x = Indirect.SwizzleX
1379 if (reg
->Register
.Indirect
) {
1380 union tgsi_exec_channel index
;
1381 union tgsi_exec_channel indir_index
;
1384 /* which address register (always zero for now) */
1388 index
.i
[3] = reg
->Indirect
.Index
;
1390 /* get current value of address register[swizzle] */
1391 swizzle
= tgsi_util_get_src_register_swizzle( ®
->Indirect
, TGSI_CHAN_X
);
1393 /* fetch values from the address/indirection register */
1394 fetch_src_file_channel(mach
,
1402 /* save indirection offset */
1403 offset
= indir_index
.i
[0];
1406 /* There is an extra source register that is a second
1407 * subscript to a register file. Effectively it means that
1408 * the register file is actually a 2D array of registers.
1412 * [3] = Dimension.Index
1414 if (reg
->Register
.Dimension
) {
1418 index2D
.i
[3] = reg
->Dimension
.Index
;
1420 /* Again, the second subscript index can be addressed indirectly
1421 * identically to the first one.
1422 * Nothing stops us from indirectly addressing the indirect register,
1423 * but there is no need for that, so we won't exercise it.
1425 * file[ind[4].y+3][1],
1427 * ind = DimIndirect.File
1428 * [4] = DimIndirect.Index
1429 * .y = DimIndirect.SwizzleX
1431 if (reg
->Dimension
.Indirect
) {
1432 union tgsi_exec_channel index2
;
1433 union tgsi_exec_channel indir_index
;
1434 const uint execmask
= mach
->ExecMask
;
1441 index2
.i
[3] = reg
->DimIndirect
.Index
;
1443 swizzle
= tgsi_util_get_src_register_swizzle( ®
->DimIndirect
, TGSI_CHAN_X
);
1444 fetch_src_file_channel(mach
,
1446 reg
->DimIndirect
.File
,
1452 index2D
.i
[0] += indir_index
.i
[0];
1453 index2D
.i
[1] += indir_index
.i
[1];
1454 index2D
.i
[2] += indir_index
.i
[2];
1455 index2D
.i
[3] += indir_index
.i
[3];
1457 /* for disabled execution channels, zero-out the index to
1458 * avoid using a potential garbage value.
1460 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1461 if ((execmask
& (1 << i
)) == 0) {
1467 /* If by any chance there was a need for a 3D array of register
1468 * files, we would have to check whether Dimension is followed
1469 * by a dimension register and continue the saga.
1478 switch (reg
->Register
.File
) {
1479 case TGSI_FILE_NULL
:
1483 case TGSI_FILE_OUTPUT
:
1484 index
= mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0]
1485 + reg
->Register
.Index
;
1486 dst
= &mach
->Outputs
[offset
+ index
].xyzw
[chan_index
];
1488 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1489 fprintf(stderr
, "STORING OUT[%d] mask(%d), = (", offset
+ index
, execmask
);
1490 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1491 if (execmask
& (1 << i
))
1492 fprintf(stderr
, "%f, ", chan
->f
[i
]);
1493 fprintf(stderr
, ")\n");
1498 case TGSI_FILE_TEMPORARY
:
1499 index
= reg
->Register
.Index
;
1500 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1501 dst
= &mach
->Temps
[offset
+ index
].xyzw
[chan_index
];
1504 case TGSI_FILE_TEMPORARY_ARRAY
:
1505 index
= reg
->Register
.Index
;
1506 assert( index
< TGSI_EXEC_NUM_TEMPS
);
1507 assert( index2D
.i
[0] < TGSI_EXEC_NUM_TEMP_ARRAYS
);
1508 /* XXX we use index2D.i[0] here but somehow we might
1509 * end up with someone trying to store indirectly in
1510 * different buffers */
1511 dst
= &mach
->TempArray
[index2D
.i
[0]][offset
+ index
].xyzw
[chan_index
];
1514 case TGSI_FILE_ADDRESS
:
1515 index
= reg
->Register
.Index
;
1516 dst
= &mach
->Addrs
[index
].xyzw
[chan_index
];
1519 case TGSI_FILE_PREDICATE
:
1520 index
= reg
->Register
.Index
;
1521 assert(index
< TGSI_EXEC_NUM_PREDS
);
1522 dst
= &mach
->Predicates
[index
].xyzw
[chan_index
];
1530 if (inst
->Instruction
.Predicate
) {
1532 union tgsi_exec_channel
*pred
;
1534 switch (chan_index
) {
1536 swizzle
= inst
->Predicate
.SwizzleX
;
1539 swizzle
= inst
->Predicate
.SwizzleY
;
1542 swizzle
= inst
->Predicate
.SwizzleZ
;
1545 swizzle
= inst
->Predicate
.SwizzleW
;
1552 assert(inst
->Predicate
.Index
== 0);
1554 pred
= &mach
->Predicates
[inst
->Predicate
.Index
].xyzw
[swizzle
];
1556 if (inst
->Predicate
.Negate
) {
1557 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1559 execmask
&= ~(1 << i
);
1563 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
1565 execmask
&= ~(1 << i
);
1571 switch (inst
->Instruction
.Saturate
) {
1573 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1574 if (execmask
& (1 << i
))
1575 dst
->i
[i
] = chan
->i
[i
];
1578 case TGSI_SAT_ZERO_ONE
:
1579 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1580 if (execmask
& (1 << i
)) {
1581 if (chan
->f
[i
] < 0.0f
)
1583 else if (chan
->f
[i
] > 1.0f
)
1586 dst
->i
[i
] = chan
->i
[i
];
1590 case TGSI_SAT_MINUS_PLUS_ONE
:
1591 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++)
1592 if (execmask
& (1 << i
)) {
1593 if (chan
->f
[i
] < -1.0f
)
1595 else if (chan
->f
[i
] > 1.0f
)
1598 dst
->i
[i
] = chan
->i
[i
];
1607 #define FETCH(VAL,INDEX,CHAN)\
1608 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT)
1610 #define IFETCH(VAL,INDEX,CHAN)\
1611 fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_INT)
1615 * Execute ARB-style KIL which is predicated by a src register.
1616 * Kill fragment if any of the four values is less than zero.
1619 exec_kil(struct tgsi_exec_machine
*mach
,
1620 const struct tgsi_full_instruction
*inst
)
1624 uint kilmask
= 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1625 union tgsi_exec_channel r
[1];
1627 /* This mask stores component bits that were already tested. */
1630 for (chan_index
= 0; chan_index
< 4; chan_index
++)
1635 /* unswizzle channel */
1636 swizzle
= tgsi_util_get_full_src_register_swizzle (
1640 /* check if the component has not been already tested */
1641 if (uniquemask
& (1 << swizzle
))
1643 uniquemask
|= 1 << swizzle
;
1645 FETCH(&r
[0], 0, chan_index
);
1646 for (i
= 0; i
< 4; i
++)
1647 if (r
[0].f
[i
] < 0.0f
)
1651 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1655 * Execute NVIDIA-style KIL which is predicated by a condition code.
1656 * Kill fragment if the condition code is TRUE.
1659 exec_kilp(struct tgsi_exec_machine
*mach
,
1660 const struct tgsi_full_instruction
*inst
)
1662 uint kilmask
; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
1664 /* "unconditional" kil */
1665 kilmask
= mach
->ExecMask
;
1666 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] |= kilmask
;
1670 emit_vertex(struct tgsi_exec_machine
*mach
)
1672 /* FIXME: check for exec mask correctly
1674 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1675 if ((mach->ExecMask & (1 << i)))
1677 if (mach
->ExecMask
) {
1678 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] += mach
->NumOutputs
;
1679 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]]++;
1684 emit_primitive(struct tgsi_exec_machine
*mach
)
1686 unsigned *prim_count
= &mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0];
1687 /* FIXME: check for exec mask correctly
1689 for (i = 0; i < TGSI_QUAD_SIZE; ++i) {
1690 if ((mach->ExecMask & (1 << i)))
1692 if (mach
->ExecMask
) {
1694 debug_assert((*prim_count
* mach
->NumOutputs
) < mach
->MaxGeometryShaderOutputs
);
1695 mach
->Primitives
[*prim_count
] = 0;
1700 conditional_emit_primitive(struct tgsi_exec_machine
*mach
)
1702 if (TGSI_PROCESSOR_GEOMETRY
== mach
->Processor
) {
1704 mach
->Primitives
[mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0]];
1705 if (emitted_verts
) {
1706 emit_primitive(mach
);
1713 * Fetch four texture samples using STR texture coordinates.
1716 fetch_texel( struct tgsi_sampler
*sampler
,
1717 const union tgsi_exec_channel
*s
,
1718 const union tgsi_exec_channel
*t
,
1719 const union tgsi_exec_channel
*p
,
1720 const union tgsi_exec_channel
*c0
,
1721 const union tgsi_exec_channel
*c1
,
1722 enum tgsi_sampler_control control
,
1723 union tgsi_exec_channel
*r
,
1724 union tgsi_exec_channel
*g
,
1725 union tgsi_exec_channel
*b
,
1726 union tgsi_exec_channel
*a
)
1729 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
1731 sampler
->get_samples(sampler
, s
->f
, t
->f
, p
->f
, c0
->f
, c1
->f
, control
, rgba
);
1733 for (j
= 0; j
< 4; j
++) {
1734 r
->f
[j
] = rgba
[0][j
];
1735 g
->f
[j
] = rgba
[1][j
];
1736 b
->f
[j
] = rgba
[2][j
];
1737 a
->f
[j
] = rgba
[3][j
];
1742 #define TEX_MODIFIER_NONE 0
1743 #define TEX_MODIFIER_PROJECTED 1
1744 #define TEX_MODIFIER_LOD_BIAS 2
1745 #define TEX_MODIFIER_EXPLICIT_LOD 3
1746 #define TEX_MODIFIER_LEVEL_ZERO 4
1749 * execute a texture instruction.
1751 * modifier is used to control the channel routing for the\
1752 * instruction variants like proj, lod, and texture with lod bias.
1753 * sampler indicates which src register the sampler is contained in.
1756 exec_tex(struct tgsi_exec_machine
*mach
,
1757 const struct tgsi_full_instruction
*inst
,
1758 uint modifier
, uint sampler
)
1760 const uint unit
= inst
->Src
[sampler
].Register
.Index
;
1761 union tgsi_exec_channel r
[4], cubearraycomp
, cubelod
;
1762 const union tgsi_exec_channel
*lod
= &ZeroVec
;
1763 enum tgsi_sampler_control control
;
1766 if (modifier
!= TEX_MODIFIER_NONE
&& (sampler
== 1)) {
1767 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1768 if (modifier
!= TEX_MODIFIER_PROJECTED
) {
1773 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
1774 control
= tgsi_sampler_lod_explicit
;
1776 control
= tgsi_sampler_lod_bias
;
1779 switch (inst
->Texture
.Texture
) {
1780 case TGSI_TEXTURE_1D
:
1781 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1783 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1784 micro_div(&r
[0], &r
[0], &r
[3]);
1787 fetch_texel(mach
->Samplers
[unit
],
1788 &r
[0], &ZeroVec
, &ZeroVec
, lod
, &ZeroVec
, /* S, T, P, LOD */
1790 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1792 case TGSI_TEXTURE_SHADOW1D
:
1793 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1794 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1796 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1797 micro_div(&r
[0], &r
[0], &r
[3]);
1800 fetch_texel(mach
->Samplers
[unit
],
1801 &r
[0], &ZeroVec
, &r
[2], lod
, &ZeroVec
, /* S, T, P, LOD */
1803 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1806 case TGSI_TEXTURE_2D
:
1807 case TGSI_TEXTURE_RECT
:
1808 case TGSI_TEXTURE_SHADOW2D
:
1809 case TGSI_TEXTURE_SHADOWRECT
:
1810 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1811 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1812 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1814 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1815 micro_div(&r
[0], &r
[0], &r
[3]);
1816 micro_div(&r
[1], &r
[1], &r
[3]);
1817 micro_div(&r
[2], &r
[2], &r
[3]);
1820 fetch_texel(mach
->Samplers
[unit
],
1821 &r
[0], &r
[1], &r
[2], lod
, &ZeroVec
, /* S, T, P, LOD */
1823 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1826 case TGSI_TEXTURE_1D_ARRAY
:
1827 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1828 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1830 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1831 micro_div(&r
[0], &r
[0], &r
[3]);
1834 fetch_texel(mach
->Samplers
[unit
],
1835 &r
[0], &r
[1], &ZeroVec
, lod
, &ZeroVec
, /* S, T, P, LOD */
1837 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1839 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1840 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1841 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1842 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1844 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1845 micro_div(&r
[0], &r
[0], &r
[3]);
1848 fetch_texel(mach
->Samplers
[unit
],
1849 &r
[0], &r
[1], &r
[2], lod
, &ZeroVec
, /* S, T, P, LOD */
1851 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1854 case TGSI_TEXTURE_2D_ARRAY
:
1855 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1856 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1857 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1859 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1860 micro_div(&r
[0], &r
[0], &r
[3]);
1861 micro_div(&r
[1], &r
[1], &r
[3]);
1864 fetch_texel(mach
->Samplers
[unit
],
1865 &r
[0], &r
[1], &r
[2], lod
, &ZeroVec
, /* S, T, P, LOD */
1867 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1869 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1870 case TGSI_TEXTURE_SHADOWCUBE
:
1871 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1872 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1873 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1874 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1876 fetch_texel(mach
->Samplers
[unit
],
1877 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
, /* S, T, P, LOD */
1879 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1881 case TGSI_TEXTURE_CUBE_ARRAY
:
1882 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1883 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1884 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1885 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1887 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
||
1888 modifier
== TEX_MODIFIER_LOD_BIAS
)
1889 FETCH(&cubelod
, 1, TGSI_CHAN_X
);
1893 fetch_texel(mach
->Samplers
[unit
],
1894 &r
[0], &r
[1], &r
[2], &r
[3], &cubelod
, /* S, T, P, LOD */
1896 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1898 case TGSI_TEXTURE_3D
:
1899 case TGSI_TEXTURE_CUBE
:
1900 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1901 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1902 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1904 if (modifier
== TEX_MODIFIER_PROJECTED
) {
1905 micro_div(&r
[0], &r
[0], &r
[3]);
1906 micro_div(&r
[1], &r
[1], &r
[3]);
1907 micro_div(&r
[2], &r
[2], &r
[3]);
1910 fetch_texel(mach
->Samplers
[unit
],
1911 &r
[0], &r
[1], &r
[2], lod
, &ZeroVec
,
1913 &r
[0], &r
[1], &r
[2], &r
[3]);
1916 case TGSI_TEXTURE_SHADOWCUBE_ARRAY
:
1917 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1918 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1919 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1920 FETCH(&r
[3], 0, TGSI_CHAN_W
);
1922 FETCH(&cubearraycomp
, 1, TGSI_CHAN_X
);
1924 fetch_texel(mach
->Samplers
[unit
],
1925 &r
[0], &r
[1], &r
[2], &r
[3], &cubearraycomp
, /* S, T, P, LOD */
1927 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1934 debug_printf("fetch r: %g %g %g %g\n",
1935 r
[0].f
[0], r
[0].f
[1], r
[0].f
[2], r
[0].f
[3]);
1936 debug_printf("fetch g: %g %g %g %g\n",
1937 r
[1].f
[0], r
[1].f
[1], r
[1].f
[2], r
[1].f
[3]);
1938 debug_printf("fetch b: %g %g %g %g\n",
1939 r
[2].f
[0], r
[2].f
[1], r
[2].f
[2], r
[2].f
[3]);
1940 debug_printf("fetch a: %g %g %g %g\n",
1941 r
[3].f
[0], r
[3].f
[1], r
[3].f
[2], r
[3].f
[3]);
1944 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
1945 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
1946 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
1952 exec_txd(struct tgsi_exec_machine
*mach
,
1953 const struct tgsi_full_instruction
*inst
)
1955 const uint unit
= inst
->Src
[3].Register
.Index
;
1956 union tgsi_exec_channel r
[4];
1960 * XXX: This is fake TXD -- the derivatives are not taken into account, yet.
1963 switch (inst
->Texture
.Texture
) {
1964 case TGSI_TEXTURE_1D
:
1965 case TGSI_TEXTURE_SHADOW1D
:
1967 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1969 fetch_texel(mach
->Samplers
[unit
],
1970 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, BIAS */
1971 tgsi_sampler_lod_bias
,
1972 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
1975 case TGSI_TEXTURE_1D_ARRAY
:
1976 case TGSI_TEXTURE_2D
:
1977 case TGSI_TEXTURE_RECT
:
1978 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1979 case TGSI_TEXTURE_SHADOW2D
:
1980 case TGSI_TEXTURE_SHADOWRECT
:
1982 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1983 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1984 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
1986 fetch_texel(mach
->Samplers
[unit
],
1987 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
, /* inputs */
1988 tgsi_sampler_lod_bias
,
1989 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
1992 case TGSI_TEXTURE_2D_ARRAY
:
1993 case TGSI_TEXTURE_3D
:
1994 case TGSI_TEXTURE_CUBE
:
1995 case TGSI_TEXTURE_CUBE_ARRAY
:
1996 FETCH(&r
[0], 0, TGSI_CHAN_X
);
1997 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
1998 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2000 fetch_texel(mach
->Samplers
[unit
],
2001 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
,
2002 tgsi_sampler_lod_bias
,
2003 &r
[0], &r
[1], &r
[2], &r
[3]);
2006 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2008 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2009 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2010 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2011 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2013 fetch_texel(mach
->Samplers
[unit
],
2014 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
,
2015 tgsi_sampler_lod_bias
,
2016 &r
[0], &r
[1], &r
[2], &r
[3]);
2023 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2024 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2025 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2032 exec_txf(struct tgsi_exec_machine
*mach
,
2033 const struct tgsi_full_instruction
*inst
)
2035 struct tgsi_sampler
*sampler
;
2036 const uint unit
= inst
->Src
[2].Register
.Index
;
2037 union tgsi_exec_channel r
[4];
2038 union tgsi_exec_channel offset
[3];
2040 float rgba
[TGSI_NUM_CHANNELS
][TGSI_QUAD_SIZE
];
2044 if (inst
->Texture
.NumOffsets
== 1) {
2045 union tgsi_exec_channel index
;
2046 index
.i
[0] = index
.i
[1] = index
.i
[2] = index
.i
[3] = inst
->TexOffsets
[0].Index
;
2047 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2048 inst
->TexOffsets
[0].SwizzleX
, &index
, &ZeroVec
, &offset
[0]);
2049 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2050 inst
->TexOffsets
[0].SwizzleY
, &index
, &ZeroVec
, &offset
[1]);
2051 fetch_src_file_channel(mach
, 0, inst
->TexOffsets
[0].File
,
2052 inst
->TexOffsets
[0].SwizzleZ
, &index
, &ZeroVec
, &offset
[2]);
2053 offsets
[0] = offset
[0].i
[0];
2054 offsets
[1] = offset
[1].i
[0];
2055 offsets
[2] = offset
[2].i
[0];
2057 offsets
[0] = offsets
[1] = offsets
[2] = 0;
2059 IFETCH(&r
[3], 0, TGSI_CHAN_W
);
2061 switch(inst
->Texture
.Texture
) {
2062 case TGSI_TEXTURE_3D
:
2063 case TGSI_TEXTURE_2D_ARRAY
:
2064 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
2065 IFETCH(&r
[2], 0, TGSI_CHAN_Z
);
2067 case TGSI_TEXTURE_2D
:
2068 case TGSI_TEXTURE_RECT
:
2069 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
2070 case TGSI_TEXTURE_SHADOW2D
:
2071 case TGSI_TEXTURE_SHADOWRECT
:
2072 case TGSI_TEXTURE_1D_ARRAY
:
2073 IFETCH(&r
[1], 0, TGSI_CHAN_Y
);
2075 case TGSI_TEXTURE_BUFFER
:
2076 case TGSI_TEXTURE_1D
:
2077 case TGSI_TEXTURE_SHADOW1D
:
2078 IFETCH(&r
[0], 0, TGSI_CHAN_X
);
2085 sampler
= mach
->Samplers
[unit
];
2086 sampler
->get_texel(sampler
, r
[0].i
, r
[1].i
, r
[2].i
, r
[3].i
,
2089 for (j
= 0; j
< TGSI_QUAD_SIZE
; j
++) {
2090 r
[0].f
[j
] = rgba
[0][j
];
2091 r
[1].f
[j
] = rgba
[1][j
];
2092 r
[2].f
[j
] = rgba
[2][j
];
2093 r
[3].f
[j
] = rgba
[3][j
];
2096 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2097 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2098 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2104 exec_txq(struct tgsi_exec_machine
*mach
,
2105 const struct tgsi_full_instruction
*inst
)
2107 struct tgsi_sampler
*sampler
;
2108 const uint unit
= inst
->Src
[1].Register
.Index
;
2110 union tgsi_exec_channel r
[4], src
;
2114 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_INT
);
2115 sampler
= mach
->Samplers
[unit
];
2117 sampler
->get_dims(sampler
, src
.i
[0], result
);
2119 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2120 for (j
= 0; j
< 4; j
++) {
2121 r
[j
].i
[i
] = result
[j
];
2125 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2126 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2127 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
,
2128 TGSI_EXEC_DATA_INT
);
2134 exec_sample(struct tgsi_exec_machine
*mach
,
2135 const struct tgsi_full_instruction
*inst
,
2136 uint modifier
, boolean compare
)
2138 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2139 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2140 union tgsi_exec_channel r
[4];
2141 const union tgsi_exec_channel
*lod
= &ZeroVec
;
2142 enum tgsi_sampler_control control
;
2145 assert(modifier
!= TEX_MODIFIER_PROJECTED
);
2147 if (modifier
!= TEX_MODIFIER_NONE
) {
2148 if (modifier
== TEX_MODIFIER_LOD_BIAS
) {
2149 FETCH(&r
[3], 3, TGSI_CHAN_X
);
2152 else if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
) {
2153 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2157 assert(modifier
== TEX_MODIFIER_LEVEL_ZERO
);
2160 if (modifier
== TEX_MODIFIER_EXPLICIT_LOD
||
2161 modifier
== TEX_MODIFIER_LEVEL_ZERO
) {
2162 control
= tgsi_sampler_lod_explicit
;
2164 control
= tgsi_sampler_lod_bias
;
2167 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2169 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2170 case TGSI_TEXTURE_1D
:
2172 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2173 fetch_texel(mach
->Samplers
[sampler_unit
],
2174 &r
[0], &ZeroVec
, &r
[2], lod
, &ZeroVec
, /* S, T, P, LOD */
2176 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2179 fetch_texel(mach
->Samplers
[sampler_unit
],
2180 &r
[0], &ZeroVec
, &ZeroVec
, lod
, &ZeroVec
, /* S, T, P, LOD */
2182 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2186 case TGSI_TEXTURE_1D_ARRAY
:
2187 case TGSI_TEXTURE_2D
:
2188 case TGSI_TEXTURE_RECT
:
2189 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2191 FETCH(&r
[2], 3, TGSI_CHAN_X
);
2192 fetch_texel(mach
->Samplers
[sampler_unit
],
2193 &r
[0], &r
[1], &r
[2], lod
, &ZeroVec
, /* S, T, P, LOD */
2195 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2198 fetch_texel(mach
->Samplers
[sampler_unit
],
2199 &r
[0], &r
[1], &ZeroVec
, lod
, &ZeroVec
, /* S, T, P, LOD */
2201 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2205 case TGSI_TEXTURE_2D_ARRAY
:
2206 case TGSI_TEXTURE_3D
:
2207 case TGSI_TEXTURE_CUBE
:
2208 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2209 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2211 FETCH(&r
[3], 3, TGSI_CHAN_X
);
2212 fetch_texel(mach
->Samplers
[sampler_unit
],
2213 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
,
2215 &r
[0], &r
[1], &r
[2], &r
[3]);
2218 fetch_texel(mach
->Samplers
[sampler_unit
],
2219 &r
[0], &r
[1], &r
[2], lod
, &ZeroVec
,
2221 &r
[0], &r
[1], &r
[2], &r
[3]);
2225 case TGSI_TEXTURE_CUBE_ARRAY
:
2226 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2227 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2228 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2230 assert(modifier
== TEX_MODIFIER_NONE
);
2232 * FIXME: lod bias and explicit lod are prohibited but
2233 * for sample_c_lz we pass the level zero info as explicit
2236 FETCH(&r
[4], 3, TGSI_CHAN_X
);
2237 fetch_texel(mach
->Samplers
[sampler_unit
],
2238 &r
[0], &r
[1], &r
[2], &r
[3], &r
[4],
2240 &r
[0], &r
[1], &r
[2], &r
[3]);
2243 fetch_texel(mach
->Samplers
[sampler_unit
],
2244 &r
[0], &r
[1], &r
[2], &r
[3], lod
,
2246 &r
[0], &r
[1], &r
[2], &r
[3]);
2255 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2256 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2257 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2263 exec_sample_d(struct tgsi_exec_machine
*mach
,
2264 const struct tgsi_full_instruction
*inst
)
2266 const uint resource_unit
= inst
->Src
[1].Register
.Index
;
2267 const uint sampler_unit
= inst
->Src
[2].Register
.Index
;
2268 union tgsi_exec_channel r
[4];
2271 * XXX: This is fake SAMPLE_D -- the derivatives are not taken into account, yet.
2274 switch (mach
->SamplerViews
[resource_unit
].Resource
) {
2275 case TGSI_TEXTURE_1D
:
2276 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2278 fetch_texel(mach
->Samplers
[sampler_unit
],
2279 &r
[0], &ZeroVec
, &ZeroVec
, &ZeroVec
, &ZeroVec
, /* S, T, P, BIAS */
2280 tgsi_sampler_lod_bias
,
2281 &r
[0], &r
[1], &r
[2], &r
[3]); /* R, G, B, A */
2284 case TGSI_TEXTURE_2D
:
2285 case TGSI_TEXTURE_RECT
:
2286 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2287 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2289 fetch_texel(mach
->Samplers
[sampler_unit
],
2290 &r
[0], &r
[1], &ZeroVec
, &ZeroVec
, &ZeroVec
, /* inputs */
2291 tgsi_sampler_lod_bias
,
2292 &r
[0], &r
[1], &r
[2], &r
[3]); /* outputs */
2295 case TGSI_TEXTURE_3D
:
2296 case TGSI_TEXTURE_CUBE
:
2297 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2298 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2299 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2301 fetch_texel(mach
->Samplers
[sampler_unit
],
2302 &r
[0], &r
[1], &r
[2], &ZeroVec
, &ZeroVec
,
2303 tgsi_sampler_lod_bias
,
2304 &r
[0], &r
[1], &r
[2], &r
[3]);
2307 case TGSI_TEXTURE_CUBE_ARRAY
:
2308 FETCH(&r
[0], 0, TGSI_CHAN_X
);
2309 FETCH(&r
[1], 0, TGSI_CHAN_Y
);
2310 FETCH(&r
[2], 0, TGSI_CHAN_Z
);
2311 FETCH(&r
[3], 0, TGSI_CHAN_W
);
2313 fetch_texel(mach
->Samplers
[sampler_unit
],
2314 &r
[0], &r
[1], &r
[2], &r
[3], &ZeroVec
,
2315 tgsi_sampler_lod_bias
,
2316 &r
[0], &r
[1], &r
[2], &r
[3]);
2323 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2324 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2325 store_dest(mach
, &r
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2332 * Evaluate a constant-valued coefficient at the position of the
2337 struct tgsi_exec_machine
*mach
,
2343 for( i
= 0; i
< TGSI_QUAD_SIZE
; i
++ ) {
2344 mach
->Inputs
[attrib
].xyzw
[chan
].f
[i
] = mach
->InterpCoefs
[attrib
].a0
[chan
];
2349 * Evaluate a linear-valued coefficient at the position of the
2354 struct tgsi_exec_machine
*mach
,
2358 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2359 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2360 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2361 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2362 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2363 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
;
2364 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = a0
+ dadx
;
2365 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = a0
+ dady
;
2366 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = a0
+ dadx
+ dady
;
2370 * Evaluate a perspective-valued coefficient at the position of the
2374 eval_perspective_coef(
2375 struct tgsi_exec_machine
*mach
,
2379 const float x
= mach
->QuadPos
.xyzw
[0].f
[0];
2380 const float y
= mach
->QuadPos
.xyzw
[1].f
[0];
2381 const float dadx
= mach
->InterpCoefs
[attrib
].dadx
[chan
];
2382 const float dady
= mach
->InterpCoefs
[attrib
].dady
[chan
];
2383 const float a0
= mach
->InterpCoefs
[attrib
].a0
[chan
] + dadx
* x
+ dady
* y
;
2384 const float *w
= mach
->QuadPos
.xyzw
[3].f
;
2385 /* divide by W here */
2386 mach
->Inputs
[attrib
].xyzw
[chan
].f
[0] = a0
/ w
[0];
2387 mach
->Inputs
[attrib
].xyzw
[chan
].f
[1] = (a0
+ dadx
) / w
[1];
2388 mach
->Inputs
[attrib
].xyzw
[chan
].f
[2] = (a0
+ dady
) / w
[2];
2389 mach
->Inputs
[attrib
].xyzw
[chan
].f
[3] = (a0
+ dadx
+ dady
) / w
[3];
2393 typedef void (* eval_coef_func
)(
2394 struct tgsi_exec_machine
*mach
,
2399 exec_declaration(struct tgsi_exec_machine
*mach
,
2400 const struct tgsi_full_declaration
*decl
)
2402 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER_VIEW
) {
2403 mach
->SamplerViews
[decl
->Range
.First
] = decl
->SamplerView
;
2407 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
2408 if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
2409 uint first
, last
, mask
;
2411 first
= decl
->Range
.First
;
2412 last
= decl
->Range
.Last
;
2413 mask
= decl
->Declaration
.UsageMask
;
2415 /* XXX we could remove this special-case code since
2416 * mach->InterpCoefs[first].a0 should already have the
2417 * front/back-face value. But we should first update the
2418 * ureg code to emit the right UsageMask value (WRITEMASK_X).
2419 * Then, we could remove the tgsi_exec_machine::Face field.
2421 /* XXX make FACE a system value */
2422 if (decl
->Semantic
.Name
== TGSI_SEMANTIC_FACE
) {
2425 assert(decl
->Semantic
.Index
== 0);
2426 assert(first
== last
);
2428 for (i
= 0; i
< TGSI_QUAD_SIZE
; i
++) {
2429 mach
->Inputs
[first
].xyzw
[0].f
[i
] = mach
->Face
;
2432 eval_coef_func eval
;
2435 switch (decl
->Interp
.Interpolate
) {
2436 case TGSI_INTERPOLATE_CONSTANT
:
2437 eval
= eval_constant_coef
;
2440 case TGSI_INTERPOLATE_LINEAR
:
2441 eval
= eval_linear_coef
;
2444 case TGSI_INTERPOLATE_PERSPECTIVE
:
2445 eval
= eval_perspective_coef
;
2448 case TGSI_INTERPOLATE_COLOR
:
2449 eval
= mach
->flatshade_color
? eval_constant_coef
: eval_perspective_coef
;
2457 for (j
= 0; j
< TGSI_NUM_CHANNELS
; j
++) {
2458 if (mask
& (1 << j
)) {
2459 for (i
= first
; i
<= last
; i
++) {
2468 if (decl
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
2469 mach
->SysSemanticToIndex
[decl
->Declaration
.Semantic
] = decl
->Range
.First
;
2474 typedef void (* micro_op
)(union tgsi_exec_channel
*dst
);
2477 exec_vector(struct tgsi_exec_machine
*mach
,
2478 const struct tgsi_full_instruction
*inst
,
2480 enum tgsi_exec_datatype dst_datatype
)
2484 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2485 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2486 union tgsi_exec_channel dst
;
2489 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2494 typedef void (* micro_unary_op
)(union tgsi_exec_channel
*dst
,
2495 const union tgsi_exec_channel
*src
);
2498 exec_scalar_unary(struct tgsi_exec_machine
*mach
,
2499 const struct tgsi_full_instruction
*inst
,
2501 enum tgsi_exec_datatype dst_datatype
,
2502 enum tgsi_exec_datatype src_datatype
)
2505 union tgsi_exec_channel src
;
2506 union tgsi_exec_channel dst
;
2508 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2510 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2511 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2512 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2518 exec_vector_unary(struct tgsi_exec_machine
*mach
,
2519 const struct tgsi_full_instruction
*inst
,
2521 enum tgsi_exec_datatype dst_datatype
,
2522 enum tgsi_exec_datatype src_datatype
)
2525 struct tgsi_exec_vector dst
;
2527 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2528 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2529 union tgsi_exec_channel src
;
2531 fetch_source(mach
, &src
, &inst
->Src
[0], chan
, src_datatype
);
2532 op(&dst
.xyzw
[chan
], &src
);
2535 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2536 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2537 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2542 typedef void (* micro_binary_op
)(union tgsi_exec_channel
*dst
,
2543 const union tgsi_exec_channel
*src0
,
2544 const union tgsi_exec_channel
*src1
);
2547 exec_scalar_binary(struct tgsi_exec_machine
*mach
,
2548 const struct tgsi_full_instruction
*inst
,
2550 enum tgsi_exec_datatype dst_datatype
,
2551 enum tgsi_exec_datatype src_datatype
)
2554 union tgsi_exec_channel src
[2];
2555 union tgsi_exec_channel dst
;
2557 fetch_source(mach
, &src
[0], &inst
->Src
[0], TGSI_CHAN_X
, src_datatype
);
2558 fetch_source(mach
, &src
[1], &inst
->Src
[1], TGSI_CHAN_Y
, src_datatype
);
2559 op(&dst
, &src
[0], &src
[1]);
2560 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2561 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2562 store_dest(mach
, &dst
, &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2568 exec_vector_binary(struct tgsi_exec_machine
*mach
,
2569 const struct tgsi_full_instruction
*inst
,
2571 enum tgsi_exec_datatype dst_datatype
,
2572 enum tgsi_exec_datatype src_datatype
)
2575 struct tgsi_exec_vector dst
;
2577 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2578 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2579 union tgsi_exec_channel src
[2];
2581 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2582 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2583 op(&dst
.xyzw
[chan
], &src
[0], &src
[1]);
2586 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2587 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2588 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2593 typedef void (* micro_trinary_op
)(union tgsi_exec_channel
*dst
,
2594 const union tgsi_exec_channel
*src0
,
2595 const union tgsi_exec_channel
*src1
,
2596 const union tgsi_exec_channel
*src2
);
2599 exec_vector_trinary(struct tgsi_exec_machine
*mach
,
2600 const struct tgsi_full_instruction
*inst
,
2601 micro_trinary_op op
,
2602 enum tgsi_exec_datatype dst_datatype
,
2603 enum tgsi_exec_datatype src_datatype
)
2606 struct tgsi_exec_vector dst
;
2608 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2609 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2610 union tgsi_exec_channel src
[3];
2612 fetch_source(mach
, &src
[0], &inst
->Src
[0], chan
, src_datatype
);
2613 fetch_source(mach
, &src
[1], &inst
->Src
[1], chan
, src_datatype
);
2614 fetch_source(mach
, &src
[2], &inst
->Src
[2], chan
, src_datatype
);
2615 op(&dst
.xyzw
[chan
], &src
[0], &src
[1], &src
[2]);
2618 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2619 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2620 store_dest(mach
, &dst
.xyzw
[chan
], &inst
->Dst
[0], inst
, chan
, dst_datatype
);
2626 exec_dp3(struct tgsi_exec_machine
*mach
,
2627 const struct tgsi_full_instruction
*inst
)
2630 union tgsi_exec_channel arg
[3];
2632 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2633 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2634 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2636 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
2637 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2638 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2639 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2642 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2643 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2644 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2650 exec_dp4(struct tgsi_exec_machine
*mach
,
2651 const struct tgsi_full_instruction
*inst
)
2654 union tgsi_exec_channel arg
[3];
2656 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2657 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2658 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2660 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
2661 fetch_source(mach
, &arg
[0], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2662 fetch_source(mach
, &arg
[1], &inst
->Src
[1], chan
, TGSI_EXEC_DATA_FLOAT
);
2663 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2666 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2667 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2668 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2674 exec_dp2a(struct tgsi_exec_machine
*mach
,
2675 const struct tgsi_full_instruction
*inst
)
2678 union tgsi_exec_channel arg
[3];
2680 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2681 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2682 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2684 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2685 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2686 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2688 fetch_source(mach
, &arg
[1], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2689 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2691 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2692 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2693 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2699 exec_dph(struct tgsi_exec_machine
*mach
,
2700 const struct tgsi_full_instruction
*inst
)
2703 union tgsi_exec_channel arg
[3];
2705 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2706 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2707 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2709 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2710 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2711 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2713 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2714 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2715 micro_mad(&arg
[0], &arg
[0], &arg
[1], &arg
[2]);
2717 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2718 micro_add(&arg
[0], &arg
[0], &arg
[1]);
2720 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2721 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2722 store_dest(mach
, &arg
[0], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2728 exec_dp2(struct tgsi_exec_machine
*mach
,
2729 const struct tgsi_full_instruction
*inst
)
2732 union tgsi_exec_channel arg
[3];
2734 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2735 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2736 micro_mul(&arg
[2], &arg
[0], &arg
[1]);
2738 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2739 fetch_source(mach
, &arg
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2740 micro_mad(&arg
[2], &arg
[0], &arg
[1], &arg
[2]);
2742 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; chan
++) {
2743 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2744 store_dest(mach
, &arg
[2], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2750 exec_nrm4(struct tgsi_exec_machine
*mach
,
2751 const struct tgsi_full_instruction
*inst
)
2754 union tgsi_exec_channel arg
[4];
2755 union tgsi_exec_channel scale
;
2757 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2758 micro_mul(&scale
, &arg
[0], &arg
[0]);
2760 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_W
; chan
++) {
2761 union tgsi_exec_channel product
;
2763 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2764 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2765 micro_add(&scale
, &scale
, &product
);
2768 micro_rsq(&scale
, &scale
);
2770 for (chan
= TGSI_CHAN_X
; chan
<= TGSI_CHAN_W
; chan
++) {
2771 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2772 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2773 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2779 exec_nrm3(struct tgsi_exec_machine
*mach
,
2780 const struct tgsi_full_instruction
*inst
)
2782 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XYZ
) {
2784 union tgsi_exec_channel arg
[3];
2785 union tgsi_exec_channel scale
;
2787 fetch_source(mach
, &arg
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2788 micro_mul(&scale
, &arg
[0], &arg
[0]);
2790 for (chan
= TGSI_CHAN_Y
; chan
<= TGSI_CHAN_Z
; chan
++) {
2791 union tgsi_exec_channel product
;
2793 fetch_source(mach
, &arg
[chan
], &inst
->Src
[0], chan
, TGSI_EXEC_DATA_FLOAT
);
2794 micro_mul(&product
, &arg
[chan
], &arg
[chan
]);
2795 micro_add(&scale
, &scale
, &product
);
2798 micro_rsq(&scale
, &scale
);
2800 for (chan
= TGSI_CHAN_X
; chan
<= TGSI_CHAN_Z
; chan
++) {
2801 if (inst
->Dst
[0].Register
.WriteMask
& (1 << chan
)) {
2802 micro_mul(&arg
[chan
], &arg
[chan
], &scale
);
2803 store_dest(mach
, &arg
[chan
], &inst
->Dst
[0], inst
, chan
, TGSI_EXEC_DATA_FLOAT
);
2808 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2809 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2814 exec_scs(struct tgsi_exec_machine
*mach
,
2815 const struct tgsi_full_instruction
*inst
)
2817 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
) {
2818 union tgsi_exec_channel arg
;
2819 union tgsi_exec_channel result
;
2821 fetch_source(mach
, &arg
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2823 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2824 micro_cos(&result
, &arg
);
2825 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2827 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2828 micro_sin(&result
, &arg
);
2829 store_dest(mach
, &result
, &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2832 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2833 store_dest(mach
, &ZeroVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2835 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2836 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2841 exec_x2d(struct tgsi_exec_machine
*mach
,
2842 const struct tgsi_full_instruction
*inst
)
2844 union tgsi_exec_channel r
[4];
2845 union tgsi_exec_channel d
[2];
2847 fetch_source(mach
, &r
[0], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2848 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2849 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XZ
) {
2850 fetch_source(mach
, &r
[2], &inst
->Src
[2], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2851 micro_mul(&r
[2], &r
[2], &r
[0]);
2852 fetch_source(mach
, &r
[3], &inst
->Src
[2], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2853 micro_mul(&r
[3], &r
[3], &r
[1]);
2854 micro_add(&r
[2], &r
[2], &r
[3]);
2855 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2856 micro_add(&d
[0], &r
[2], &r
[3]);
2858 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YW
) {
2859 fetch_source(mach
, &r
[2], &inst
->Src
[2], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2860 micro_mul(&r
[2], &r
[2], &r
[0]);
2861 fetch_source(mach
, &r
[3], &inst
->Src
[2], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2862 micro_mul(&r
[3], &r
[3], &r
[1]);
2863 micro_add(&r
[2], &r
[2], &r
[3]);
2864 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2865 micro_add(&d
[1], &r
[2], &r
[3]);
2867 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2868 store_dest(mach
, &d
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2870 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2871 store_dest(mach
, &d
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2873 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2874 store_dest(mach
, &d
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2876 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2877 store_dest(mach
, &d
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2882 exec_rfl(struct tgsi_exec_machine
*mach
,
2883 const struct tgsi_full_instruction
*inst
)
2885 union tgsi_exec_channel r
[9];
2887 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XYZ
) {
2888 /* r0 = dp3(src0, src0) */
2889 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2890 micro_mul(&r
[0], &r
[2], &r
[2]);
2891 fetch_source(mach
, &r
[4], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2892 micro_mul(&r
[8], &r
[4], &r
[4]);
2893 micro_add(&r
[0], &r
[0], &r
[8]);
2894 fetch_source(mach
, &r
[6], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2895 micro_mul(&r
[8], &r
[6], &r
[6]);
2896 micro_add(&r
[0], &r
[0], &r
[8]);
2898 /* r1 = dp3(src0, src1) */
2899 fetch_source(mach
, &r
[3], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2900 micro_mul(&r
[1], &r
[2], &r
[3]);
2901 fetch_source(mach
, &r
[5], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2902 micro_mul(&r
[8], &r
[4], &r
[5]);
2903 micro_add(&r
[1], &r
[1], &r
[8]);
2904 fetch_source(mach
, &r
[7], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2905 micro_mul(&r
[8], &r
[6], &r
[7]);
2906 micro_add(&r
[1], &r
[1], &r
[8]);
2908 /* r1 = 2 * r1 / r0 */
2909 micro_add(&r
[1], &r
[1], &r
[1]);
2910 micro_div(&r
[1], &r
[1], &r
[0]);
2912 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2913 micro_mul(&r
[2], &r
[2], &r
[1]);
2914 micro_sub(&r
[2], &r
[2], &r
[3]);
2915 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2917 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2918 micro_mul(&r
[4], &r
[4], &r
[1]);
2919 micro_sub(&r
[4], &r
[4], &r
[5]);
2920 store_dest(mach
, &r
[4], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2922 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2923 micro_mul(&r
[6], &r
[6], &r
[1]);
2924 micro_sub(&r
[6], &r
[6], &r
[7]);
2925 store_dest(mach
, &r
[6], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2928 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2929 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2934 exec_xpd(struct tgsi_exec_machine
*mach
,
2935 const struct tgsi_full_instruction
*inst
)
2937 union tgsi_exec_channel r
[6];
2938 union tgsi_exec_channel d
[3];
2940 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2941 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2943 micro_mul(&r
[2], &r
[0], &r
[1]);
2945 fetch_source(mach
, &r
[3], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2946 fetch_source(mach
, &r
[4], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2948 micro_mul(&r
[5], &r
[3], &r
[4] );
2949 micro_sub(&d
[TGSI_CHAN_X
], &r
[2], &r
[5]);
2951 fetch_source(mach
, &r
[2], &inst
->Src
[1], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2953 micro_mul(&r
[3], &r
[3], &r
[2]);
2955 fetch_source(mach
, &r
[5], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2957 micro_mul(&r
[1], &r
[1], &r
[5]);
2958 micro_sub(&d
[TGSI_CHAN_Y
], &r
[3], &r
[1]);
2960 micro_mul(&r
[5], &r
[5], &r
[4]);
2961 micro_mul(&r
[0], &r
[0], &r
[2]);
2962 micro_sub(&d
[TGSI_CHAN_Z
], &r
[5], &r
[0]);
2964 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2965 store_dest(mach
, &d
[TGSI_CHAN_X
], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
2967 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2968 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2970 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2971 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2973 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2974 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2979 exec_dst(struct tgsi_exec_machine
*mach
,
2980 const struct tgsi_full_instruction
*inst
)
2982 union tgsi_exec_channel r
[2];
2983 union tgsi_exec_channel d
[4];
2985 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2986 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2987 fetch_source(mach
, &r
[1], &inst
->Src
[1], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
2988 micro_mul(&d
[TGSI_CHAN_Y
], &r
[0], &r
[1]);
2990 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2991 fetch_source(mach
, &d
[TGSI_CHAN_Z
], &inst
->Src
[0], TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
2993 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2994 fetch_source(mach
, &d
[TGSI_CHAN_W
], &inst
->Src
[1], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
2997 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2998 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3000 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3001 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3003 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3004 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3006 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3007 store_dest(mach
, &d
[TGSI_CHAN_W
], &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3012 exec_log(struct tgsi_exec_machine
*mach
,
3013 const struct tgsi_full_instruction
*inst
)
3015 union tgsi_exec_channel r
[3];
3017 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3018 micro_abs(&r
[2], &r
[0]); /* r2 = abs(r0) */
3019 micro_lg2(&r
[1], &r
[2]); /* r1 = lg2(r2) */
3020 micro_flr(&r
[0], &r
[1]); /* r0 = floor(r1) */
3021 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3022 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3024 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3025 micro_exp2(&r
[0], &r
[0]); /* r0 = 2 ^ r0 */
3026 micro_div(&r
[0], &r
[2], &r
[0]); /* r0 = r2 / r0 */
3027 store_dest(mach
, &r
[0], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3029 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3030 store_dest(mach
, &r
[1], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3032 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3033 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3038 exec_exp(struct tgsi_exec_machine
*mach
,
3039 const struct tgsi_full_instruction
*inst
)
3041 union tgsi_exec_channel r
[3];
3043 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3044 micro_flr(&r
[1], &r
[0]); /* r1 = floor(r0) */
3045 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3046 micro_exp2(&r
[2], &r
[1]); /* r2 = 2 ^ r1 */
3047 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3049 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3050 micro_sub(&r
[2], &r
[0], &r
[1]); /* r2 = r0 - r1 */
3051 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3053 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3054 micro_exp2(&r
[2], &r
[0]); /* r2 = 2 ^ r0 */
3055 store_dest(mach
, &r
[2], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3057 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3058 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3063 exec_lit(struct tgsi_exec_machine
*mach
,
3064 const struct tgsi_full_instruction
*inst
)
3066 union tgsi_exec_channel r
[3];
3067 union tgsi_exec_channel d
[3];
3069 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_YZ
) {
3070 fetch_source(mach
, &r
[0], &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3071 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3072 fetch_source(mach
, &r
[1], &inst
->Src
[0], TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3073 micro_max(&r
[1], &r
[1], &ZeroVec
);
3075 fetch_source(mach
, &r
[2], &inst
->Src
[0], TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3076 micro_min(&r
[2], &r
[2], &P128Vec
);
3077 micro_max(&r
[2], &r
[2], &M128Vec
);
3078 micro_pow(&r
[1], &r
[1], &r
[2]);
3079 micro_lt(&d
[TGSI_CHAN_Z
], &ZeroVec
, &r
[0], &r
[1], &ZeroVec
);
3080 store_dest(mach
, &d
[TGSI_CHAN_Z
], &inst
->Dst
[0], inst
, TGSI_CHAN_Z
, TGSI_EXEC_DATA_FLOAT
);
3082 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3083 micro_max(&d
[TGSI_CHAN_Y
], &r
[0], &ZeroVec
);
3084 store_dest(mach
, &d
[TGSI_CHAN_Y
], &inst
->Dst
[0], inst
, TGSI_CHAN_Y
, TGSI_EXEC_DATA_FLOAT
);
3087 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3088 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_X
, TGSI_EXEC_DATA_FLOAT
);
3091 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3092 store_dest(mach
, &OneVec
, &inst
->Dst
[0], inst
, TGSI_CHAN_W
, TGSI_EXEC_DATA_FLOAT
);
3097 exec_break(struct tgsi_exec_machine
*mach
)
3099 if (mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_LOOP
) {
3100 /* turn off loop channels for each enabled exec channel */
3101 mach
->LoopMask
&= ~mach
->ExecMask
;
3102 /* Todo: if mach->LoopMask == 0, jump to end of loop */
3103 UPDATE_EXEC_MASK(mach
);
3105 assert(mach
->BreakType
== TGSI_EXEC_BREAK_INSIDE_SWITCH
);
3107 mach
->Switch
.mask
= 0x0;
3109 UPDATE_EXEC_MASK(mach
);
3114 exec_switch(struct tgsi_exec_machine
*mach
,
3115 const struct tgsi_full_instruction
*inst
)
3117 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3118 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3120 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3121 fetch_source(mach
, &mach
->Switch
.selector
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3122 mach
->Switch
.mask
= 0x0;
3123 mach
->Switch
.defaultMask
= 0x0;
3125 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3126 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_SWITCH
;
3128 UPDATE_EXEC_MASK(mach
);
3132 exec_case(struct tgsi_exec_machine
*mach
,
3133 const struct tgsi_full_instruction
*inst
)
3135 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3136 union tgsi_exec_channel src
;
3139 fetch_source(mach
, &src
, &inst
->Src
[0], TGSI_CHAN_X
, TGSI_EXEC_DATA_UINT
);
3141 if (mach
->Switch
.selector
.u
[0] == src
.u
[0]) {
3144 if (mach
->Switch
.selector
.u
[1] == src
.u
[1]) {
3147 if (mach
->Switch
.selector
.u
[2] == src
.u
[2]) {
3150 if (mach
->Switch
.selector
.u
[3] == src
.u
[3]) {
3154 mach
->Switch
.defaultMask
|= mask
;
3156 mach
->Switch
.mask
|= mask
& prevMask
;
3158 UPDATE_EXEC_MASK(mach
);
3162 exec_default(struct tgsi_exec_machine
*mach
)
3164 uint prevMask
= mach
->SwitchStack
[mach
->SwitchStackTop
- 1].mask
;
3166 mach
->Switch
.mask
|= ~mach
->Switch
.defaultMask
& prevMask
;
3168 UPDATE_EXEC_MASK(mach
);
3172 exec_endswitch(struct tgsi_exec_machine
*mach
)
3174 mach
->Switch
= mach
->SwitchStack
[--mach
->SwitchStackTop
];
3175 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
3177 UPDATE_EXEC_MASK(mach
);
3181 micro_i2f(union tgsi_exec_channel
*dst
,
3182 const union tgsi_exec_channel
*src
)
3184 dst
->f
[0] = (float)src
->i
[0];
3185 dst
->f
[1] = (float)src
->i
[1];
3186 dst
->f
[2] = (float)src
->i
[2];
3187 dst
->f
[3] = (float)src
->i
[3];
3191 micro_not(union tgsi_exec_channel
*dst
,
3192 const union tgsi_exec_channel
*src
)
3194 dst
->u
[0] = ~src
->u
[0];
3195 dst
->u
[1] = ~src
->u
[1];
3196 dst
->u
[2] = ~src
->u
[2];
3197 dst
->u
[3] = ~src
->u
[3];
3201 micro_shl(union tgsi_exec_channel
*dst
,
3202 const union tgsi_exec_channel
*src0
,
3203 const union tgsi_exec_channel
*src1
)
3205 dst
->u
[0] = src0
->u
[0] << src1
->u
[0];
3206 dst
->u
[1] = src0
->u
[1] << src1
->u
[1];
3207 dst
->u
[2] = src0
->u
[2] << src1
->u
[2];
3208 dst
->u
[3] = src0
->u
[3] << src1
->u
[3];
3212 micro_and(union tgsi_exec_channel
*dst
,
3213 const union tgsi_exec_channel
*src0
,
3214 const union tgsi_exec_channel
*src1
)
3216 dst
->u
[0] = src0
->u
[0] & src1
->u
[0];
3217 dst
->u
[1] = src0
->u
[1] & src1
->u
[1];
3218 dst
->u
[2] = src0
->u
[2] & src1
->u
[2];
3219 dst
->u
[3] = src0
->u
[3] & src1
->u
[3];
3223 micro_or(union tgsi_exec_channel
*dst
,
3224 const union tgsi_exec_channel
*src0
,
3225 const union tgsi_exec_channel
*src1
)
3227 dst
->u
[0] = src0
->u
[0] | src1
->u
[0];
3228 dst
->u
[1] = src0
->u
[1] | src1
->u
[1];
3229 dst
->u
[2] = src0
->u
[2] | src1
->u
[2];
3230 dst
->u
[3] = src0
->u
[3] | src1
->u
[3];
3234 micro_xor(union tgsi_exec_channel
*dst
,
3235 const union tgsi_exec_channel
*src0
,
3236 const union tgsi_exec_channel
*src1
)
3238 dst
->u
[0] = src0
->u
[0] ^ src1
->u
[0];
3239 dst
->u
[1] = src0
->u
[1] ^ src1
->u
[1];
3240 dst
->u
[2] = src0
->u
[2] ^ src1
->u
[2];
3241 dst
->u
[3] = src0
->u
[3] ^ src1
->u
[3];
3245 micro_mod(union tgsi_exec_channel
*dst
,
3246 const union tgsi_exec_channel
*src0
,
3247 const union tgsi_exec_channel
*src1
)
3249 dst
->i
[0] = src0
->i
[0] % src1
->i
[0];
3250 dst
->i
[1] = src0
->i
[1] % src1
->i
[1];
3251 dst
->i
[2] = src0
->i
[2] % src1
->i
[2];
3252 dst
->i
[3] = src0
->i
[3] % src1
->i
[3];
3256 micro_f2i(union tgsi_exec_channel
*dst
,
3257 const union tgsi_exec_channel
*src
)
3259 dst
->i
[0] = (int)src
->f
[0];
3260 dst
->i
[1] = (int)src
->f
[1];
3261 dst
->i
[2] = (int)src
->f
[2];
3262 dst
->i
[3] = (int)src
->f
[3];
3266 micro_idiv(union tgsi_exec_channel
*dst
,
3267 const union tgsi_exec_channel
*src0
,
3268 const union tgsi_exec_channel
*src1
)
3270 dst
->i
[0] = src0
->i
[0] / src1
->i
[0];
3271 dst
->i
[1] = src0
->i
[1] / src1
->i
[1];
3272 dst
->i
[2] = src0
->i
[2] / src1
->i
[2];
3273 dst
->i
[3] = src0
->i
[3] / src1
->i
[3];
3277 micro_imax(union tgsi_exec_channel
*dst
,
3278 const union tgsi_exec_channel
*src0
,
3279 const union tgsi_exec_channel
*src1
)
3281 dst
->i
[0] = src0
->i
[0] > src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3282 dst
->i
[1] = src0
->i
[1] > src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3283 dst
->i
[2] = src0
->i
[2] > src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3284 dst
->i
[3] = src0
->i
[3] > src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3288 micro_imin(union tgsi_exec_channel
*dst
,
3289 const union tgsi_exec_channel
*src0
,
3290 const union tgsi_exec_channel
*src1
)
3292 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? src0
->i
[0] : src1
->i
[0];
3293 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? src0
->i
[1] : src1
->i
[1];
3294 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? src0
->i
[2] : src1
->i
[2];
3295 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? src0
->i
[3] : src1
->i
[3];
3299 micro_isge(union tgsi_exec_channel
*dst
,
3300 const union tgsi_exec_channel
*src0
,
3301 const union tgsi_exec_channel
*src1
)
3303 dst
->i
[0] = src0
->i
[0] >= src1
->i
[0] ? -1 : 0;
3304 dst
->i
[1] = src0
->i
[1] >= src1
->i
[1] ? -1 : 0;
3305 dst
->i
[2] = src0
->i
[2] >= src1
->i
[2] ? -1 : 0;
3306 dst
->i
[3] = src0
->i
[3] >= src1
->i
[3] ? -1 : 0;
3310 micro_ishr(union tgsi_exec_channel
*dst
,
3311 const union tgsi_exec_channel
*src0
,
3312 const union tgsi_exec_channel
*src1
)
3314 dst
->i
[0] = src0
->i
[0] >> src1
->i
[0];
3315 dst
->i
[1] = src0
->i
[1] >> src1
->i
[1];
3316 dst
->i
[2] = src0
->i
[2] >> src1
->i
[2];
3317 dst
->i
[3] = src0
->i
[3] >> src1
->i
[3];
3321 micro_islt(union tgsi_exec_channel
*dst
,
3322 const union tgsi_exec_channel
*src0
,
3323 const union tgsi_exec_channel
*src1
)
3325 dst
->i
[0] = src0
->i
[0] < src1
->i
[0] ? -1 : 0;
3326 dst
->i
[1] = src0
->i
[1] < src1
->i
[1] ? -1 : 0;
3327 dst
->i
[2] = src0
->i
[2] < src1
->i
[2] ? -1 : 0;
3328 dst
->i
[3] = src0
->i
[3] < src1
->i
[3] ? -1 : 0;
3332 micro_f2u(union tgsi_exec_channel
*dst
,
3333 const union tgsi_exec_channel
*src
)
3335 dst
->u
[0] = (uint
)src
->f
[0];
3336 dst
->u
[1] = (uint
)src
->f
[1];
3337 dst
->u
[2] = (uint
)src
->f
[2];
3338 dst
->u
[3] = (uint
)src
->f
[3];
3342 micro_u2f(union tgsi_exec_channel
*dst
,
3343 const union tgsi_exec_channel
*src
)
3345 dst
->f
[0] = (float)src
->u
[0];
3346 dst
->f
[1] = (float)src
->u
[1];
3347 dst
->f
[2] = (float)src
->u
[2];
3348 dst
->f
[3] = (float)src
->u
[3];
3352 micro_uadd(union tgsi_exec_channel
*dst
,
3353 const union tgsi_exec_channel
*src0
,
3354 const union tgsi_exec_channel
*src1
)
3356 dst
->u
[0] = src0
->u
[0] + src1
->u
[0];
3357 dst
->u
[1] = src0
->u
[1] + src1
->u
[1];
3358 dst
->u
[2] = src0
->u
[2] + src1
->u
[2];
3359 dst
->u
[3] = src0
->u
[3] + src1
->u
[3];
3363 micro_udiv(union tgsi_exec_channel
*dst
,
3364 const union tgsi_exec_channel
*src0
,
3365 const union tgsi_exec_channel
*src1
)
3367 dst
->u
[0] = src0
->u
[0] / src1
->u
[0];
3368 dst
->u
[1] = src0
->u
[1] / src1
->u
[1];
3369 dst
->u
[2] = src0
->u
[2] / src1
->u
[2];
3370 dst
->u
[3] = src0
->u
[3] / src1
->u
[3];
3374 micro_umad(union tgsi_exec_channel
*dst
,
3375 const union tgsi_exec_channel
*src0
,
3376 const union tgsi_exec_channel
*src1
,
3377 const union tgsi_exec_channel
*src2
)
3379 dst
->u
[0] = src0
->u
[0] * src1
->u
[0] + src2
->u
[0];
3380 dst
->u
[1] = src0
->u
[1] * src1
->u
[1] + src2
->u
[1];
3381 dst
->u
[2] = src0
->u
[2] * src1
->u
[2] + src2
->u
[2];
3382 dst
->u
[3] = src0
->u
[3] * src1
->u
[3] + src2
->u
[3];
3386 micro_umax(union tgsi_exec_channel
*dst
,
3387 const union tgsi_exec_channel
*src0
,
3388 const union tgsi_exec_channel
*src1
)
3390 dst
->u
[0] = src0
->u
[0] > src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3391 dst
->u
[1] = src0
->u
[1] > src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3392 dst
->u
[2] = src0
->u
[2] > src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3393 dst
->u
[3] = src0
->u
[3] > src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3397 micro_umin(union tgsi_exec_channel
*dst
,
3398 const union tgsi_exec_channel
*src0
,
3399 const union tgsi_exec_channel
*src1
)
3401 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? src0
->u
[0] : src1
->u
[0];
3402 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? src0
->u
[1] : src1
->u
[1];
3403 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? src0
->u
[2] : src1
->u
[2];
3404 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? src0
->u
[3] : src1
->u
[3];
3408 micro_umod(union tgsi_exec_channel
*dst
,
3409 const union tgsi_exec_channel
*src0
,
3410 const union tgsi_exec_channel
*src1
)
3412 dst
->u
[0] = src0
->u
[0] % src1
->u
[0];
3413 dst
->u
[1] = src0
->u
[1] % src1
->u
[1];
3414 dst
->u
[2] = src0
->u
[2] % src1
->u
[2];
3415 dst
->u
[3] = src0
->u
[3] % src1
->u
[3];
3419 micro_umul(union tgsi_exec_channel
*dst
,
3420 const union tgsi_exec_channel
*src0
,
3421 const union tgsi_exec_channel
*src1
)
3423 dst
->u
[0] = src0
->u
[0] * src1
->u
[0];
3424 dst
->u
[1] = src0
->u
[1] * src1
->u
[1];
3425 dst
->u
[2] = src0
->u
[2] * src1
->u
[2];
3426 dst
->u
[3] = src0
->u
[3] * src1
->u
[3];
3430 micro_useq(union tgsi_exec_channel
*dst
,
3431 const union tgsi_exec_channel
*src0
,
3432 const union tgsi_exec_channel
*src1
)
3434 dst
->u
[0] = src0
->u
[0] == src1
->u
[0] ? ~0 : 0;
3435 dst
->u
[1] = src0
->u
[1] == src1
->u
[1] ? ~0 : 0;
3436 dst
->u
[2] = src0
->u
[2] == src1
->u
[2] ? ~0 : 0;
3437 dst
->u
[3] = src0
->u
[3] == src1
->u
[3] ? ~0 : 0;
3441 micro_usge(union tgsi_exec_channel
*dst
,
3442 const union tgsi_exec_channel
*src0
,
3443 const union tgsi_exec_channel
*src1
)
3445 dst
->u
[0] = src0
->u
[0] >= src1
->u
[0] ? ~0 : 0;
3446 dst
->u
[1] = src0
->u
[1] >= src1
->u
[1] ? ~0 : 0;
3447 dst
->u
[2] = src0
->u
[2] >= src1
->u
[2] ? ~0 : 0;
3448 dst
->u
[3] = src0
->u
[3] >= src1
->u
[3] ? ~0 : 0;
3452 micro_ushr(union tgsi_exec_channel
*dst
,
3453 const union tgsi_exec_channel
*src0
,
3454 const union tgsi_exec_channel
*src1
)
3456 dst
->u
[0] = src0
->u
[0] >> src1
->u
[0];
3457 dst
->u
[1] = src0
->u
[1] >> src1
->u
[1];
3458 dst
->u
[2] = src0
->u
[2] >> src1
->u
[2];
3459 dst
->u
[3] = src0
->u
[3] >> src1
->u
[3];
3463 micro_uslt(union tgsi_exec_channel
*dst
,
3464 const union tgsi_exec_channel
*src0
,
3465 const union tgsi_exec_channel
*src1
)
3467 dst
->u
[0] = src0
->u
[0] < src1
->u
[0] ? ~0 : 0;
3468 dst
->u
[1] = src0
->u
[1] < src1
->u
[1] ? ~0 : 0;
3469 dst
->u
[2] = src0
->u
[2] < src1
->u
[2] ? ~0 : 0;
3470 dst
->u
[3] = src0
->u
[3] < src1
->u
[3] ? ~0 : 0;
3474 micro_usne(union tgsi_exec_channel
*dst
,
3475 const union tgsi_exec_channel
*src0
,
3476 const union tgsi_exec_channel
*src1
)
3478 dst
->u
[0] = src0
->u
[0] != src1
->u
[0] ? ~0 : 0;
3479 dst
->u
[1] = src0
->u
[1] != src1
->u
[1] ? ~0 : 0;
3480 dst
->u
[2] = src0
->u
[2] != src1
->u
[2] ? ~0 : 0;
3481 dst
->u
[3] = src0
->u
[3] != src1
->u
[3] ? ~0 : 0;
3485 micro_uarl(union tgsi_exec_channel
*dst
,
3486 const union tgsi_exec_channel
*src
)
3488 dst
->i
[0] = src
->u
[0];
3489 dst
->i
[1] = src
->u
[1];
3490 dst
->i
[2] = src
->u
[2];
3491 dst
->i
[3] = src
->u
[3];
3495 micro_ucmp(union tgsi_exec_channel
*dst
,
3496 const union tgsi_exec_channel
*src0
,
3497 const union tgsi_exec_channel
*src1
,
3498 const union tgsi_exec_channel
*src2
)
3500 dst
->u
[0] = src0
->u
[0] ? src1
->u
[0] : src2
->u
[0];
3501 dst
->u
[1] = src0
->u
[1] ? src1
->u
[1] : src2
->u
[1];
3502 dst
->u
[2] = src0
->u
[2] ? src1
->u
[2] : src2
->u
[2];
3503 dst
->u
[3] = src0
->u
[3] ? src1
->u
[3] : src2
->u
[3];
3508 struct tgsi_exec_machine
*mach
,
3509 const struct tgsi_full_instruction
*inst
,
3512 union tgsi_exec_channel r
[10];
3516 switch (inst
->Instruction
.Opcode
) {
3517 case TGSI_OPCODE_ARL
:
3518 exec_vector_unary(mach
, inst
, micro_arl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3521 case TGSI_OPCODE_MOV
:
3522 exec_vector_unary(mach
, inst
, micro_mov
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
3525 case TGSI_OPCODE_LIT
:
3526 exec_lit(mach
, inst
);
3529 case TGSI_OPCODE_RCP
:
3530 exec_scalar_unary(mach
, inst
, micro_rcp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3533 case TGSI_OPCODE_RSQ
:
3534 exec_scalar_unary(mach
, inst
, micro_rsq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3537 case TGSI_OPCODE_EXP
:
3538 exec_exp(mach
, inst
);
3541 case TGSI_OPCODE_LOG
:
3542 exec_log(mach
, inst
);
3545 case TGSI_OPCODE_MUL
:
3546 exec_vector_binary(mach
, inst
, micro_mul
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3549 case TGSI_OPCODE_ADD
:
3550 exec_vector_binary(mach
, inst
, micro_add
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3553 case TGSI_OPCODE_DP3
:
3554 exec_dp3(mach
, inst
);
3557 case TGSI_OPCODE_DP4
:
3558 exec_dp4(mach
, inst
);
3561 case TGSI_OPCODE_DST
:
3562 exec_dst(mach
, inst
);
3565 case TGSI_OPCODE_MIN
:
3566 exec_vector_binary(mach
, inst
, micro_min
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3569 case TGSI_OPCODE_MAX
:
3570 exec_vector_binary(mach
, inst
, micro_max
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3573 case TGSI_OPCODE_SLT
:
3574 exec_vector_binary(mach
, inst
, micro_slt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3577 case TGSI_OPCODE_SGE
:
3578 exec_vector_binary(mach
, inst
, micro_sge
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3581 case TGSI_OPCODE_MAD
:
3582 exec_vector_trinary(mach
, inst
, micro_mad
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3585 case TGSI_OPCODE_SUB
:
3586 exec_vector_binary(mach
, inst
, micro_sub
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3589 case TGSI_OPCODE_LRP
:
3590 exec_vector_trinary(mach
, inst
, micro_lrp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3593 case TGSI_OPCODE_CND
:
3594 exec_vector_trinary(mach
, inst
, micro_cnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3597 case TGSI_OPCODE_SQRT
:
3598 exec_vector_unary(mach
, inst
, micro_sqrt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3601 case TGSI_OPCODE_DP2A
:
3602 exec_dp2a(mach
, inst
);
3605 case TGSI_OPCODE_FRC
:
3606 exec_vector_unary(mach
, inst
, micro_frc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3609 case TGSI_OPCODE_CLAMP
:
3610 exec_vector_trinary(mach
, inst
, micro_clamp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3613 case TGSI_OPCODE_FLR
:
3614 exec_vector_unary(mach
, inst
, micro_flr
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3617 case TGSI_OPCODE_ROUND
:
3618 exec_vector_unary(mach
, inst
, micro_rnd
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3621 case TGSI_OPCODE_EX2
:
3622 exec_scalar_unary(mach
, inst
, micro_exp2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3625 case TGSI_OPCODE_LG2
:
3626 exec_scalar_unary(mach
, inst
, micro_lg2
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3629 case TGSI_OPCODE_POW
:
3630 exec_scalar_binary(mach
, inst
, micro_pow
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3633 case TGSI_OPCODE_XPD
:
3634 exec_xpd(mach
, inst
);
3637 case TGSI_OPCODE_ABS
:
3638 exec_vector_unary(mach
, inst
, micro_abs
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3641 case TGSI_OPCODE_RCC
:
3642 exec_scalar_unary(mach
, inst
, micro_rcc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3645 case TGSI_OPCODE_DPH
:
3646 exec_dph(mach
, inst
);
3649 case TGSI_OPCODE_COS
:
3650 exec_scalar_unary(mach
, inst
, micro_cos
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3653 case TGSI_OPCODE_DDX
:
3654 exec_vector_unary(mach
, inst
, micro_ddx
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3657 case TGSI_OPCODE_DDY
:
3658 exec_vector_unary(mach
, inst
, micro_ddy
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3661 case TGSI_OPCODE_KILP
:
3662 exec_kilp (mach
, inst
);
3665 case TGSI_OPCODE_KIL
:
3666 exec_kil (mach
, inst
);
3669 case TGSI_OPCODE_PK2H
:
3673 case TGSI_OPCODE_PK2US
:
3677 case TGSI_OPCODE_PK4B
:
3681 case TGSI_OPCODE_PK4UB
:
3685 case TGSI_OPCODE_RFL
:
3686 exec_rfl(mach
, inst
);
3689 case TGSI_OPCODE_SEQ
:
3690 exec_vector_binary(mach
, inst
, micro_seq
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3693 case TGSI_OPCODE_SFL
:
3694 exec_vector(mach
, inst
, micro_sfl
, TGSI_EXEC_DATA_FLOAT
);
3697 case TGSI_OPCODE_SGT
:
3698 exec_vector_binary(mach
, inst
, micro_sgt
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3701 case TGSI_OPCODE_SIN
:
3702 exec_scalar_unary(mach
, inst
, micro_sin
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3705 case TGSI_OPCODE_SLE
:
3706 exec_vector_binary(mach
, inst
, micro_sle
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3709 case TGSI_OPCODE_SNE
:
3710 exec_vector_binary(mach
, inst
, micro_sne
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3713 case TGSI_OPCODE_STR
:
3714 exec_vector(mach
, inst
, micro_str
, TGSI_EXEC_DATA_FLOAT
);
3717 case TGSI_OPCODE_TEX
:
3718 /* simple texture lookup */
3719 /* src[0] = texcoord */
3720 /* src[1] = sampler unit */
3721 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 1);
3724 case TGSI_OPCODE_TXB
:
3725 /* Texture lookup with lod bias */
3726 /* src[0] = texcoord (src[0].w = LOD bias) */
3727 /* src[1] = sampler unit */
3728 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 1);
3731 case TGSI_OPCODE_TXD
:
3732 /* Texture lookup with explict partial derivatives */
3733 /* src[0] = texcoord */
3734 /* src[1] = d[strq]/dx */
3735 /* src[2] = d[strq]/dy */
3736 /* src[3] = sampler unit */
3737 exec_txd(mach
, inst
);
3740 case TGSI_OPCODE_TXL
:
3741 /* Texture lookup with explit LOD */
3742 /* src[0] = texcoord (src[0].w = LOD) */
3743 /* src[1] = sampler unit */
3744 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 1);
3747 case TGSI_OPCODE_TXP
:
3748 /* Texture lookup with projection */
3749 /* src[0] = texcoord (src[0].w = projection) */
3750 /* src[1] = sampler unit */
3751 exec_tex(mach
, inst
, TEX_MODIFIER_PROJECTED
, 1);
3754 case TGSI_OPCODE_UP2H
:
3758 case TGSI_OPCODE_UP2US
:
3762 case TGSI_OPCODE_UP4B
:
3766 case TGSI_OPCODE_UP4UB
:
3770 case TGSI_OPCODE_X2D
:
3771 exec_x2d(mach
, inst
);
3774 case TGSI_OPCODE_ARA
:
3778 case TGSI_OPCODE_ARR
:
3779 exec_vector_unary(mach
, inst
, micro_arr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
3782 case TGSI_OPCODE_BRA
:
3786 case TGSI_OPCODE_CAL
:
3787 /* skip the call if no execution channels are enabled */
3788 if (mach
->ExecMask
) {
3791 /* First, record the depths of the execution stacks.
3792 * This is important for deeply nested/looped return statements.
3793 * We have to unwind the stacks by the correct amount. For a
3794 * real code generator, we could determine the number of entries
3795 * to pop off each stack with simple static analysis and avoid
3796 * implementing this data structure at run time.
3798 mach
->CallStack
[mach
->CallStackTop
].CondStackTop
= mach
->CondStackTop
;
3799 mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
= mach
->LoopStackTop
;
3800 mach
->CallStack
[mach
->CallStackTop
].ContStackTop
= mach
->ContStackTop
;
3801 mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
= mach
->SwitchStackTop
;
3802 mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
= mach
->BreakStackTop
;
3803 /* note that PC was already incremented above */
3804 mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
= *pc
;
3806 mach
->CallStackTop
++;
3808 /* Second, push the Cond, Loop, Cont, Func stacks */
3809 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3810 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3811 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
3812 assert(mach
->SwitchStackTop
< TGSI_EXEC_MAX_SWITCH_NESTING
);
3813 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
3814 assert(mach
->FuncStackTop
< TGSI_EXEC_MAX_CALL_NESTING
);
3816 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3817 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
3818 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
3819 mach
->SwitchStack
[mach
->SwitchStackTop
++] = mach
->Switch
;
3820 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
3821 mach
->FuncStack
[mach
->FuncStackTop
++] = mach
->FuncMask
;
3823 /* Finally, jump to the subroutine */
3824 *pc
= inst
->Label
.Label
;
3828 case TGSI_OPCODE_RET
:
3829 mach
->FuncMask
&= ~mach
->ExecMask
;
3830 UPDATE_EXEC_MASK(mach
);
3832 if (mach
->FuncMask
== 0x0) {
3833 /* really return now (otherwise, keep executing */
3835 if (mach
->CallStackTop
== 0) {
3836 /* returning from main() */
3837 mach
->CondStackTop
= 0;
3838 mach
->LoopStackTop
= 0;
3843 assert(mach
->CallStackTop
> 0);
3844 mach
->CallStackTop
--;
3846 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
3847 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
3849 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
3850 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
3852 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
3853 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
3855 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
3856 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
3858 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
3859 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
3861 assert(mach
->FuncStackTop
> 0);
3862 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
3864 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
3866 UPDATE_EXEC_MASK(mach
);
3870 case TGSI_OPCODE_SSG
:
3871 exec_vector_unary(mach
, inst
, micro_sgn
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3874 case TGSI_OPCODE_CMP
:
3875 exec_vector_trinary(mach
, inst
, micro_cmp
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3878 case TGSI_OPCODE_SCS
:
3879 exec_scs(mach
, inst
);
3882 case TGSI_OPCODE_NRM
:
3883 exec_nrm3(mach
, inst
);
3886 case TGSI_OPCODE_NRM4
:
3887 exec_nrm4(mach
, inst
);
3890 case TGSI_OPCODE_DIV
:
3891 exec_vector_binary(mach
, inst
, micro_div
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3894 case TGSI_OPCODE_DP2
:
3895 exec_dp2(mach
, inst
);
3898 case TGSI_OPCODE_IF
:
3900 assert(mach
->CondStackTop
< TGSI_EXEC_MAX_COND_NESTING
);
3901 mach
->CondStack
[mach
->CondStackTop
++] = mach
->CondMask
;
3902 FETCH( &r
[0], 0, TGSI_CHAN_X
);
3903 /* update CondMask */
3905 mach
->CondMask
&= ~0x1;
3908 mach
->CondMask
&= ~0x2;
3911 mach
->CondMask
&= ~0x4;
3914 mach
->CondMask
&= ~0x8;
3916 UPDATE_EXEC_MASK(mach
);
3917 /* Todo: If CondMask==0, jump to ELSE */
3920 case TGSI_OPCODE_ELSE
:
3921 /* invert CondMask wrt previous mask */
3924 assert(mach
->CondStackTop
> 0);
3925 prevMask
= mach
->CondStack
[mach
->CondStackTop
- 1];
3926 mach
->CondMask
= ~mach
->CondMask
& prevMask
;
3927 UPDATE_EXEC_MASK(mach
);
3928 /* Todo: If CondMask==0, jump to ENDIF */
3932 case TGSI_OPCODE_ENDIF
:
3934 assert(mach
->CondStackTop
> 0);
3935 mach
->CondMask
= mach
->CondStack
[--mach
->CondStackTop
];
3936 UPDATE_EXEC_MASK(mach
);
3939 case TGSI_OPCODE_END
:
3940 /* make sure we end primitives which haven't
3941 * been explicitly emitted */
3942 conditional_emit_primitive(mach
);
3943 /* halt execution */
3947 case TGSI_OPCODE_PUSHA
:
3951 case TGSI_OPCODE_POPA
:
3955 case TGSI_OPCODE_CEIL
:
3956 exec_vector_unary(mach
, inst
, micro_ceil
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3959 case TGSI_OPCODE_I2F
:
3960 exec_vector_unary(mach
, inst
, micro_i2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_INT
);
3963 case TGSI_OPCODE_NOT
:
3964 exec_vector_unary(mach
, inst
, micro_not
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3967 case TGSI_OPCODE_TRUNC
:
3968 exec_vector_unary(mach
, inst
, micro_trunc
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_FLOAT
);
3971 case TGSI_OPCODE_SHL
:
3972 exec_vector_binary(mach
, inst
, micro_shl
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3975 case TGSI_OPCODE_AND
:
3976 exec_vector_binary(mach
, inst
, micro_and
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3979 case TGSI_OPCODE_OR
:
3980 exec_vector_binary(mach
, inst
, micro_or
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3983 case TGSI_OPCODE_MOD
:
3984 exec_vector_binary(mach
, inst
, micro_mod
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
3987 case TGSI_OPCODE_XOR
:
3988 exec_vector_binary(mach
, inst
, micro_xor
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
3991 case TGSI_OPCODE_SAD
:
3995 case TGSI_OPCODE_TXF
:
3996 exec_txf(mach
, inst
);
3999 case TGSI_OPCODE_TXQ
:
4000 exec_txq(mach
, inst
);
4003 case TGSI_OPCODE_EMIT
:
4007 case TGSI_OPCODE_ENDPRIM
:
4008 emit_primitive(mach
);
4011 case TGSI_OPCODE_BGNLOOP
:
4012 /* push LoopMask and ContMasks */
4013 assert(mach
->LoopStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4014 assert(mach
->ContStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4015 assert(mach
->LoopLabelStackTop
< TGSI_EXEC_MAX_LOOP_NESTING
);
4016 assert(mach
->BreakStackTop
< TGSI_EXEC_MAX_BREAK_STACK
);
4018 mach
->LoopStack
[mach
->LoopStackTop
++] = mach
->LoopMask
;
4019 mach
->ContStack
[mach
->ContStackTop
++] = mach
->ContMask
;
4020 mach
->LoopLabelStack
[mach
->LoopLabelStackTop
++] = *pc
- 1;
4021 mach
->BreakStack
[mach
->BreakStackTop
++] = mach
->BreakType
;
4022 mach
->BreakType
= TGSI_EXEC_BREAK_INSIDE_LOOP
;
4025 case TGSI_OPCODE_ENDLOOP
:
4026 /* Restore ContMask, but don't pop */
4027 assert(mach
->ContStackTop
> 0);
4028 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
- 1];
4029 UPDATE_EXEC_MASK(mach
);
4030 if (mach
->ExecMask
) {
4031 /* repeat loop: jump to instruction just past BGNLOOP */
4032 assert(mach
->LoopLabelStackTop
> 0);
4033 *pc
= mach
->LoopLabelStack
[mach
->LoopLabelStackTop
- 1] + 1;
4036 /* exit loop: pop LoopMask */
4037 assert(mach
->LoopStackTop
> 0);
4038 mach
->LoopMask
= mach
->LoopStack
[--mach
->LoopStackTop
];
4040 assert(mach
->ContStackTop
> 0);
4041 mach
->ContMask
= mach
->ContStack
[--mach
->ContStackTop
];
4042 assert(mach
->LoopLabelStackTop
> 0);
4043 --mach
->LoopLabelStackTop
;
4045 mach
->BreakType
= mach
->BreakStack
[--mach
->BreakStackTop
];
4047 UPDATE_EXEC_MASK(mach
);
4050 case TGSI_OPCODE_BRK
:
4054 case TGSI_OPCODE_CONT
:
4055 /* turn off cont channels for each enabled exec channel */
4056 mach
->ContMask
&= ~mach
->ExecMask
;
4057 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4058 UPDATE_EXEC_MASK(mach
);
4061 case TGSI_OPCODE_BGNSUB
:
4065 case TGSI_OPCODE_ENDSUB
:
4067 * XXX: This really should be a no-op. We should never reach this opcode.
4070 assert(mach
->CallStackTop
> 0);
4071 mach
->CallStackTop
--;
4073 mach
->CondStackTop
= mach
->CallStack
[mach
->CallStackTop
].CondStackTop
;
4074 mach
->CondMask
= mach
->CondStack
[mach
->CondStackTop
];
4076 mach
->LoopStackTop
= mach
->CallStack
[mach
->CallStackTop
].LoopStackTop
;
4077 mach
->LoopMask
= mach
->LoopStack
[mach
->LoopStackTop
];
4079 mach
->ContStackTop
= mach
->CallStack
[mach
->CallStackTop
].ContStackTop
;
4080 mach
->ContMask
= mach
->ContStack
[mach
->ContStackTop
];
4082 mach
->SwitchStackTop
= mach
->CallStack
[mach
->CallStackTop
].SwitchStackTop
;
4083 mach
->Switch
= mach
->SwitchStack
[mach
->SwitchStackTop
];
4085 mach
->BreakStackTop
= mach
->CallStack
[mach
->CallStackTop
].BreakStackTop
;
4086 mach
->BreakType
= mach
->BreakStack
[mach
->BreakStackTop
];
4088 assert(mach
->FuncStackTop
> 0);
4089 mach
->FuncMask
= mach
->FuncStack
[--mach
->FuncStackTop
];
4091 *pc
= mach
->CallStack
[mach
->CallStackTop
].ReturnAddr
;
4093 UPDATE_EXEC_MASK(mach
);
4096 case TGSI_OPCODE_NOP
:
4099 case TGSI_OPCODE_BREAKC
:
4100 FETCH(&r
[0], 0, TGSI_CHAN_X
);
4101 /* update CondMask */
4102 if (r
[0].u
[0] && (mach
->ExecMask
& 0x1)) {
4103 mach
->LoopMask
&= ~0x1;
4105 if (r
[0].u
[1] && (mach
->ExecMask
& 0x2)) {
4106 mach
->LoopMask
&= ~0x2;
4108 if (r
[0].u
[2] && (mach
->ExecMask
& 0x4)) {
4109 mach
->LoopMask
&= ~0x4;
4111 if (r
[0].u
[3] && (mach
->ExecMask
& 0x8)) {
4112 mach
->LoopMask
&= ~0x8;
4114 /* Todo: if mach->LoopMask == 0, jump to end of loop */
4115 UPDATE_EXEC_MASK(mach
);
4118 case TGSI_OPCODE_F2I
:
4119 exec_vector_unary(mach
, inst
, micro_f2i
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_FLOAT
);
4122 case TGSI_OPCODE_IDIV
:
4123 exec_vector_binary(mach
, inst
, micro_idiv
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4126 case TGSI_OPCODE_IMAX
:
4127 exec_vector_binary(mach
, inst
, micro_imax
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4130 case TGSI_OPCODE_IMIN
:
4131 exec_vector_binary(mach
, inst
, micro_imin
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4134 case TGSI_OPCODE_INEG
:
4135 exec_vector_unary(mach
, inst
, micro_ineg
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4138 case TGSI_OPCODE_ISGE
:
4139 exec_vector_binary(mach
, inst
, micro_isge
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4142 case TGSI_OPCODE_ISHR
:
4143 exec_vector_binary(mach
, inst
, micro_ishr
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4146 case TGSI_OPCODE_ISLT
:
4147 exec_vector_binary(mach
, inst
, micro_islt
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4150 case TGSI_OPCODE_F2U
:
4151 exec_vector_unary(mach
, inst
, micro_f2u
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_FLOAT
);
4154 case TGSI_OPCODE_U2F
:
4155 exec_vector_unary(mach
, inst
, micro_u2f
, TGSI_EXEC_DATA_FLOAT
, TGSI_EXEC_DATA_UINT
);
4158 case TGSI_OPCODE_UADD
:
4159 exec_vector_binary(mach
, inst
, micro_uadd
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4162 case TGSI_OPCODE_UDIV
:
4163 exec_vector_binary(mach
, inst
, micro_udiv
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4166 case TGSI_OPCODE_UMAD
:
4167 exec_vector_trinary(mach
, inst
, micro_umad
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4170 case TGSI_OPCODE_UMAX
:
4171 exec_vector_binary(mach
, inst
, micro_umax
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4174 case TGSI_OPCODE_UMIN
:
4175 exec_vector_binary(mach
, inst
, micro_umin
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4178 case TGSI_OPCODE_UMOD
:
4179 exec_vector_binary(mach
, inst
, micro_umod
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4182 case TGSI_OPCODE_UMUL
:
4183 exec_vector_binary(mach
, inst
, micro_umul
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4186 case TGSI_OPCODE_USEQ
:
4187 exec_vector_binary(mach
, inst
, micro_useq
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4190 case TGSI_OPCODE_USGE
:
4191 exec_vector_binary(mach
, inst
, micro_usge
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4194 case TGSI_OPCODE_USHR
:
4195 exec_vector_binary(mach
, inst
, micro_ushr
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4198 case TGSI_OPCODE_USLT
:
4199 exec_vector_binary(mach
, inst
, micro_uslt
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4202 case TGSI_OPCODE_USNE
:
4203 exec_vector_binary(mach
, inst
, micro_usne
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4206 case TGSI_OPCODE_SWITCH
:
4207 exec_switch(mach
, inst
);
4210 case TGSI_OPCODE_CASE
:
4211 exec_case(mach
, inst
);
4214 case TGSI_OPCODE_DEFAULT
:
4218 case TGSI_OPCODE_ENDSWITCH
:
4219 exec_endswitch(mach
);
4222 case TGSI_OPCODE_SAMPLE_I
:
4226 case TGSI_OPCODE_SAMPLE_I_MS
:
4230 case TGSI_OPCODE_SAMPLE
:
4231 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, FALSE
);
4234 case TGSI_OPCODE_SAMPLE_B
:
4235 exec_sample(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, FALSE
);
4238 case TGSI_OPCODE_SAMPLE_C
:
4239 exec_sample(mach
, inst
, TEX_MODIFIER_NONE
, TRUE
);
4242 case TGSI_OPCODE_SAMPLE_C_LZ
:
4243 exec_sample(mach
, inst
, TEX_MODIFIER_LEVEL_ZERO
, TRUE
);
4246 case TGSI_OPCODE_SAMPLE_D
:
4247 exec_sample_d(mach
, inst
);
4250 case TGSI_OPCODE_SAMPLE_L
:
4251 exec_sample(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, FALSE
);
4254 case TGSI_OPCODE_GATHER4
:
4258 case TGSI_OPCODE_SVIEWINFO
:
4262 case TGSI_OPCODE_SAMPLE_POS
:
4266 case TGSI_OPCODE_SAMPLE_INFO
:
4270 case TGSI_OPCODE_UARL
:
4271 exec_vector_unary(mach
, inst
, micro_uarl
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_UINT
);
4274 case TGSI_OPCODE_UCMP
:
4275 exec_vector_trinary(mach
, inst
, micro_ucmp
, TGSI_EXEC_DATA_UINT
, TGSI_EXEC_DATA_UINT
);
4278 case TGSI_OPCODE_IABS
:
4279 exec_vector_unary(mach
, inst
, micro_iabs
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4282 case TGSI_OPCODE_ISSG
:
4283 exec_vector_unary(mach
, inst
, micro_isgn
, TGSI_EXEC_DATA_INT
, TGSI_EXEC_DATA_INT
);
4286 case TGSI_OPCODE_TEX2
:
4287 /* simple texture lookup */
4288 /* src[0] = texcoord */
4289 /* src[1] = compare */
4290 /* src[2] = sampler unit */
4291 exec_tex(mach
, inst
, TEX_MODIFIER_NONE
, 2);
4293 case TGSI_OPCODE_TXB2
:
4294 /* simple texture lookup */
4295 /* src[0] = texcoord */
4297 /* src[2] = sampler unit */
4298 exec_tex(mach
, inst
, TEX_MODIFIER_LOD_BIAS
, 2);
4300 case TGSI_OPCODE_TXL2
:
4301 /* simple texture lookup */
4302 /* src[0] = texcoord */
4304 /* src[2] = sampler unit */
4305 exec_tex(mach
, inst
, TEX_MODIFIER_EXPLICIT_LOD
, 2);
4313 #define DEBUG_EXECUTION 0
4317 * Run TGSI interpreter.
4318 * \return bitmask of "alive" quad components
4321 tgsi_exec_machine_run( struct tgsi_exec_machine
*mach
)
4326 mach
->CondMask
= 0xf;
4327 mach
->LoopMask
= 0xf;
4328 mach
->ContMask
= 0xf;
4329 mach
->FuncMask
= 0xf;
4330 mach
->ExecMask
= 0xf;
4332 mach
->Switch
.mask
= 0xf;
4334 assert(mach
->CondStackTop
== 0);
4335 assert(mach
->LoopStackTop
== 0);
4336 assert(mach
->ContStackTop
== 0);
4337 assert(mach
->SwitchStackTop
== 0);
4338 assert(mach
->BreakStackTop
== 0);
4339 assert(mach
->CallStackTop
== 0);
4341 mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0] = 0;
4342 mach
->Temps
[TEMP_OUTPUT_I
].xyzw
[TEMP_OUTPUT_C
].u
[0] = 0;
4344 if( mach
->Processor
== TGSI_PROCESSOR_GEOMETRY
) {
4345 mach
->Temps
[TEMP_PRIMITIVE_I
].xyzw
[TEMP_PRIMITIVE_C
].u
[0] = 0;
4346 mach
->Primitives
[0] = 0;
4349 /* execute declarations (interpolants) */
4350 for (i
= 0; i
< mach
->NumDeclarations
; i
++) {
4351 exec_declaration( mach
, mach
->Declarations
+i
);
4356 struct tgsi_exec_vector temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
];
4357 struct tgsi_exec_vector outputs
[PIPE_MAX_ATTRIBS
];
4360 memcpy(temps
, mach
->Temps
, sizeof(temps
));
4361 memcpy(outputs
, mach
->Outputs
, sizeof(outputs
));
4364 /* execute instructions, until pc is set to -1 */
4370 tgsi_dump_instruction(&mach
->Instructions
[pc
], inst
++);
4373 assert(pc
< (int) mach
->NumInstructions
);
4374 exec_instruction(mach
, mach
->Instructions
+ pc
, &pc
);
4377 for (i
= 0; i
< TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_TEMP_EXTRAS
; i
++) {
4378 if (memcmp(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]))) {
4381 memcpy(&temps
[i
], &mach
->Temps
[i
], sizeof(temps
[i
]));
4382 debug_printf("TEMP[%2u] = ", i
);
4383 for (j
= 0; j
< 4; j
++) {
4387 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4388 temps
[i
].xyzw
[0].f
[j
], temps
[i
].xyzw
[0].u
[j
],
4389 temps
[i
].xyzw
[1].f
[j
], temps
[i
].xyzw
[1].u
[j
],
4390 temps
[i
].xyzw
[2].f
[j
], temps
[i
].xyzw
[2].u
[j
],
4391 temps
[i
].xyzw
[3].f
[j
], temps
[i
].xyzw
[3].u
[j
]);
4395 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; i
++) {
4396 if (memcmp(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]))) {
4399 memcpy(&outputs
[i
], &mach
->Outputs
[i
], sizeof(outputs
[i
]));
4400 debug_printf("OUT[%2u] = ", i
);
4401 for (j
= 0; j
< 4; j
++) {
4405 debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
4406 outputs
[i
].xyzw
[0].f
[j
], outputs
[i
].xyzw
[0].u
[j
],
4407 outputs
[i
].xyzw
[1].f
[j
], outputs
[i
].xyzw
[1].u
[j
],
4408 outputs
[i
].xyzw
[2].f
[j
], outputs
[i
].xyzw
[2].u
[j
],
4409 outputs
[i
].xyzw
[3].f
[j
], outputs
[i
].xyzw
[3].u
[j
]);
4418 /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */
4419 if (mach
->Processor
== TGSI_PROCESSOR_FRAGMENT
) {
4421 * Scale back depth component.
4423 for (i
= 0; i
< 4; i
++)
4424 mach
->Outputs
[0].xyzw
[2].f
[i
] *= ctx
->DrawBuffer
->_DepthMaxF
;
4428 /* Strictly speaking, these assertions aren't really needed but they
4429 * can potentially catch some bugs in the control flow code.
4431 assert(mach
->CondStackTop
== 0);
4432 assert(mach
->LoopStackTop
== 0);
4433 assert(mach
->ContStackTop
== 0);
4434 assert(mach
->SwitchStackTop
== 0);
4435 assert(mach
->BreakStackTop
== 0);
4436 assert(mach
->CallStackTop
== 0);
4438 return ~mach
->Temps
[TEMP_KILMASK_I
].xyzw
[TEMP_KILMASK_C
].u
[0];