1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
4 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 **************************************************************************/
31 * TGSI to LLVM IR translation -- SoA.
33 * @author Jose Fonseca <jfonseca@vmware.com>
35 * Based on tgsi_sse2.c code written by Michal Krol, Keith Whitwell,
36 * Brian Paul, and others.
39 #include "pipe/p_config.h"
40 #include "pipe/p_shader_tokens.h"
41 #include "util/u_debug.h"
42 #include "util/u_math.h"
43 #include "util/u_memory.h"
44 #include "tgsi/tgsi_dump.h"
45 #include "tgsi/tgsi_exec.h"
46 #include "tgsi/tgsi_info.h"
47 #include "tgsi/tgsi_parse.h"
48 #include "tgsi/tgsi_util.h"
49 #include "tgsi/tgsi_scan.h"
50 #include "lp_bld_tgsi_action.h"
51 #include "lp_bld_type.h"
52 #include "lp_bld_const.h"
53 #include "lp_bld_arit.h"
54 #include "lp_bld_bitarit.h"
55 #include "lp_bld_gather.h"
56 #include "lp_bld_init.h"
57 #include "lp_bld_logic.h"
58 #include "lp_bld_swizzle.h"
59 #include "lp_bld_flow.h"
60 #include "lp_bld_quad.h"
61 #include "lp_bld_tgsi.h"
62 #include "lp_bld_limits.h"
63 #include "lp_bld_debug.h"
64 #include "lp_bld_printf.h"
65 #include "lp_bld_sample.h"
66 #include "lp_bld_struct.h"
68 #define DUMP_GS_EMITS 0
70 static void lp_exec_mask_init(struct lp_exec_mask
*mask
, struct lp_build_context
*bld
)
72 LLVMTypeRef int_type
= LLVMInt32TypeInContext(bld
->gallivm
->context
);
73 LLVMBuilderRef builder
= bld
->gallivm
->builder
;
76 mask
->has_mask
= FALSE
;
77 mask
->ret_in_main
= FALSE
;
78 mask
->cond_stack_size
= 0;
79 mask
->loop_stack_size
= 0;
80 mask
->call_stack_size
= 0;
81 mask
->switch_stack_size
= 0;
83 mask
->int_vec_type
= lp_build_int_vec_type(bld
->gallivm
, mask
->bld
->type
);
84 mask
->exec_mask
= mask
->ret_mask
= mask
->break_mask
= mask
->cont_mask
=
85 mask
->cond_mask
= mask
->switch_mask
=
86 LLVMConstAllOnes(mask
->int_vec_type
);
88 mask
->loop_limiter
= lp_build_alloca(bld
->gallivm
, int_type
, "looplimiter");
92 LLVMConstInt(int_type
, LP_MAX_TGSI_LOOP_ITERATIONS
, false),
96 static void lp_exec_mask_update(struct lp_exec_mask
*mask
)
98 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
100 if (mask
->loop_stack_size
) {
101 /*for loops we need to update the entire mask at runtime */
103 assert(mask
->break_mask
);
104 tmp
= LLVMBuildAnd(builder
,
108 mask
->exec_mask
= LLVMBuildAnd(builder
,
113 mask
->exec_mask
= mask
->cond_mask
;
115 if (mask
->switch_stack_size
) {
116 mask
->exec_mask
= LLVMBuildAnd(builder
,
122 if (mask
->call_stack_size
|| mask
->ret_in_main
) {
123 mask
->exec_mask
= LLVMBuildAnd(builder
,
129 mask
->has_mask
= (mask
->cond_stack_size
> 0 ||
130 mask
->loop_stack_size
> 0 ||
131 mask
->call_stack_size
> 0 ||
132 mask
->switch_stack_size
> 0 ||
136 static void lp_exec_mask_cond_push(struct lp_exec_mask
*mask
,
139 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
141 assert(mask
->cond_stack_size
< LP_MAX_TGSI_NESTING
);
142 if (mask
->cond_stack_size
== 0) {
143 assert(mask
->cond_mask
== LLVMConstAllOnes(mask
->int_vec_type
));
145 mask
->cond_stack
[mask
->cond_stack_size
++] = mask
->cond_mask
;
146 assert(LLVMTypeOf(val
) == mask
->int_vec_type
);
147 mask
->cond_mask
= LLVMBuildAnd(builder
,
151 lp_exec_mask_update(mask
);
154 static void lp_exec_mask_cond_invert(struct lp_exec_mask
*mask
)
156 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
157 LLVMValueRef prev_mask
;
158 LLVMValueRef inv_mask
;
160 assert(mask
->cond_stack_size
);
161 prev_mask
= mask
->cond_stack
[mask
->cond_stack_size
- 1];
162 if (mask
->cond_stack_size
== 1) {
163 assert(prev_mask
== LLVMConstAllOnes(mask
->int_vec_type
));
166 inv_mask
= LLVMBuildNot(builder
, mask
->cond_mask
, "");
168 mask
->cond_mask
= LLVMBuildAnd(builder
,
171 lp_exec_mask_update(mask
);
174 static void lp_exec_mask_cond_pop(struct lp_exec_mask
*mask
)
176 assert(mask
->cond_stack_size
);
177 mask
->cond_mask
= mask
->cond_stack
[--mask
->cond_stack_size
];
178 lp_exec_mask_update(mask
);
181 static void lp_exec_bgnloop(struct lp_exec_mask
*mask
)
183 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
185 if (mask
->loop_stack_size
== 0) {
186 assert(mask
->loop_block
== NULL
);
187 assert(mask
->cont_mask
== LLVMConstAllOnes(mask
->int_vec_type
));
188 assert(mask
->break_mask
== LLVMConstAllOnes(mask
->int_vec_type
));
189 assert(mask
->break_var
== NULL
);
192 assert(mask
->loop_stack_size
< LP_MAX_TGSI_NESTING
);
194 mask
->break_type_stack
[mask
->loop_stack_size
+ mask
->switch_stack_size
] =
196 mask
->break_type
= LP_EXEC_MASK_BREAK_TYPE_LOOP
;
198 mask
->loop_stack
[mask
->loop_stack_size
].loop_block
= mask
->loop_block
;
199 mask
->loop_stack
[mask
->loop_stack_size
].cont_mask
= mask
->cont_mask
;
200 mask
->loop_stack
[mask
->loop_stack_size
].break_mask
= mask
->break_mask
;
201 mask
->loop_stack
[mask
->loop_stack_size
].break_var
= mask
->break_var
;
202 ++mask
->loop_stack_size
;
204 mask
->break_var
= lp_build_alloca(mask
->bld
->gallivm
, mask
->int_vec_type
, "");
205 LLVMBuildStore(builder
, mask
->break_mask
, mask
->break_var
);
207 mask
->loop_block
= lp_build_insert_new_block(mask
->bld
->gallivm
, "bgnloop");
209 LLVMBuildBr(builder
, mask
->loop_block
);
210 LLVMPositionBuilderAtEnd(builder
, mask
->loop_block
);
212 mask
->break_mask
= LLVMBuildLoad(builder
, mask
->break_var
, "");
214 lp_exec_mask_update(mask
);
217 static void lp_exec_break(struct lp_exec_mask
*mask
,
218 struct lp_build_tgsi_context
* bld_base
)
220 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
222 if (mask
->break_type
== LP_EXEC_MASK_BREAK_TYPE_LOOP
) {
223 LLVMValueRef exec_mask
= LLVMBuildNot(builder
,
227 mask
->break_mask
= LLVMBuildAnd(builder
,
229 exec_mask
, "break_full");
232 unsigned opcode
= bld_base
->instructions
[bld_base
->pc
+ 1].Instruction
.Opcode
;
233 boolean break_always
= (opcode
== TGSI_OPCODE_ENDSWITCH
||
234 opcode
== TGSI_OPCODE_CASE
);
237 if (mask
->switch_in_default
) {
239 * stop default execution but only if this is an unconditional switch.
240 * (The condition here is not perfect since dead code after break is
241 * allowed but should be sufficient since false negatives are just
242 * unoptimized - so we don't have to pre-evaluate that).
244 if(break_always
&& mask
->switch_pc
) {
245 bld_base
->pc
= mask
->switch_pc
;
251 mask
->switch_mask
= LLVMConstNull(mask
->bld
->int_vec_type
);
254 LLVMValueRef exec_mask
= LLVMBuildNot(builder
,
257 mask
->switch_mask
= LLVMBuildAnd(builder
,
259 exec_mask
, "break_switch");
263 lp_exec_mask_update(mask
);
266 static void lp_exec_break_condition(struct lp_exec_mask
*mask
,
269 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
270 LLVMValueRef cond_mask
= LLVMBuildAnd(builder
,
273 cond_mask
= LLVMBuildNot(builder
, cond_mask
, "break_cond");
275 if (mask
->break_type
== LP_EXEC_MASK_BREAK_TYPE_LOOP
) {
276 mask
->break_mask
= LLVMBuildAnd(builder
,
278 cond_mask
, "breakc_full");
281 mask
->switch_mask
= LLVMBuildAnd(builder
,
283 cond_mask
, "breakc_switch");
286 lp_exec_mask_update(mask
);
289 static void lp_exec_continue(struct lp_exec_mask
*mask
)
291 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
292 LLVMValueRef exec_mask
= LLVMBuildNot(builder
,
296 mask
->cont_mask
= LLVMBuildAnd(builder
,
300 lp_exec_mask_update(mask
);
304 static void lp_exec_endloop(struct gallivm_state
*gallivm
,
305 struct lp_exec_mask
*mask
)
307 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
308 LLVMBasicBlockRef endloop
;
309 LLVMTypeRef int_type
= LLVMInt32TypeInContext(mask
->bld
->gallivm
->context
);
310 LLVMTypeRef reg_type
= LLVMIntTypeInContext(gallivm
->context
,
311 mask
->bld
->type
.width
*
312 mask
->bld
->type
.length
);
313 LLVMValueRef i1cond
, i2cond
, icond
, limiter
;
315 assert(mask
->break_mask
);
318 * Restore the cont_mask, but don't pop
320 assert(mask
->loop_stack_size
);
321 mask
->cont_mask
= mask
->loop_stack
[mask
->loop_stack_size
- 1].cont_mask
;
322 lp_exec_mask_update(mask
);
325 * Unlike the continue mask, the break_mask must be preserved across loop
328 LLVMBuildStore(builder
, mask
->break_mask
, mask
->break_var
);
330 /* Decrement the loop limiter */
331 limiter
= LLVMBuildLoad(builder
, mask
->loop_limiter
, "");
333 limiter
= LLVMBuildSub(
336 LLVMConstInt(int_type
, 1, false),
339 LLVMBuildStore(builder
, limiter
, mask
->loop_limiter
);
341 /* i1cond = (mask != 0) */
342 i1cond
= LLVMBuildICmp(
345 LLVMBuildBitCast(builder
, mask
->exec_mask
, reg_type
, ""),
346 LLVMConstNull(reg_type
), "i1cond");
348 /* i2cond = (looplimiter > 0) */
349 i2cond
= LLVMBuildICmp(
353 LLVMConstNull(int_type
), "i2cond");
355 /* if( i1cond && i2cond ) */
356 icond
= LLVMBuildAnd(builder
, i1cond
, i2cond
, "");
358 endloop
= lp_build_insert_new_block(mask
->bld
->gallivm
, "endloop");
360 LLVMBuildCondBr(builder
,
361 icond
, mask
->loop_block
, endloop
);
363 LLVMPositionBuilderAtEnd(builder
, endloop
);
365 assert(mask
->loop_stack_size
);
366 --mask
->loop_stack_size
;
367 mask
->loop_block
= mask
->loop_stack
[mask
->loop_stack_size
].loop_block
;
368 mask
->cont_mask
= mask
->loop_stack
[mask
->loop_stack_size
].cont_mask
;
369 mask
->break_mask
= mask
->loop_stack
[mask
->loop_stack_size
].break_mask
;
370 mask
->break_var
= mask
->loop_stack
[mask
->loop_stack_size
].break_var
;
371 mask
->break_type
= mask
->break_type_stack
[mask
->loop_stack_size
+ mask
->switch_stack_size
];
373 lp_exec_mask_update(mask
);
376 static void lp_exec_switch(struct lp_exec_mask
*mask
,
377 LLVMValueRef switchval
)
379 mask
->break_type_stack
[mask
->loop_stack_size
+ mask
->switch_stack_size
] =
381 mask
->break_type
= LP_EXEC_MASK_BREAK_TYPE_SWITCH
;
383 mask
->switch_stack
[mask
->switch_stack_size
].switch_val
= mask
->switch_val
;
384 mask
->switch_stack
[mask
->switch_stack_size
].switch_mask
= mask
->switch_mask
;
385 mask
->switch_stack
[mask
->switch_stack_size
].switch_mask_default
= mask
->switch_mask_default
;
386 mask
->switch_stack
[mask
->switch_stack_size
].switch_in_default
= mask
->switch_in_default
;
387 mask
->switch_stack
[mask
->switch_stack_size
].switch_pc
= mask
->switch_pc
;
388 mask
->switch_stack_size
++;
390 mask
->switch_val
= switchval
;
391 mask
->switch_mask
= LLVMConstNull(mask
->int_vec_type
);
392 mask
->switch_mask_default
= LLVMConstNull(mask
->int_vec_type
);
393 mask
->switch_in_default
= false;
396 lp_exec_mask_update(mask
);
399 static void lp_exec_endswitch(struct lp_exec_mask
*mask
,
400 struct lp_build_tgsi_context
* bld_base
)
402 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
404 /* check if there's deferred default if so do it now */
405 if (mask
->switch_pc
&& !mask
->switch_in_default
) {
406 LLVMValueRef prevmask
, defaultmask
;
408 prevmask
= mask
->switch_stack
[mask
->switch_stack_size
- 1].switch_mask
;
409 defaultmask
= LLVMBuildNot(builder
, mask
->switch_mask_default
, "sw_default_mask");
410 mask
->switch_mask
= LLVMBuildAnd(builder
, prevmask
, defaultmask
, "sw_mask");
411 mask
->switch_in_default
= true;
413 lp_exec_mask_update(mask
);
415 assert(bld_base
->instructions
[mask
->switch_pc
- 1].Instruction
.Opcode
==
416 TGSI_OPCODE_DEFAULT
);
418 tmp_pc
= bld_base
->pc
;
419 bld_base
->pc
= mask
->switch_pc
;
421 * re-purpose switch_pc to point to here again, since we stop execution of
422 * the deferred default after next break.
424 mask
->switch_pc
= tmp_pc
- 1;
429 else if (mask
->switch_pc
&& mask
->switch_in_default
) {
430 assert(bld_base
->pc
== mask
->switch_pc
+ 1);
433 mask
->switch_stack_size
--;
434 mask
->switch_val
= mask
->switch_stack
[mask
->switch_stack_size
].switch_val
;
435 mask
->switch_mask
= mask
->switch_stack
[mask
->switch_stack_size
].switch_mask
;
436 mask
->switch_mask_default
= mask
->switch_stack
[mask
->switch_stack_size
].switch_mask_default
;
437 mask
->switch_in_default
= mask
->switch_stack
[mask
->switch_stack_size
].switch_in_default
;
438 mask
->switch_pc
= mask
->switch_stack
[mask
->switch_stack_size
].switch_pc
;
440 mask
->break_type
= mask
->break_type_stack
[mask
->loop_stack_size
+ mask
->switch_stack_size
];
442 lp_exec_mask_update(mask
);
445 static void lp_exec_case(struct lp_exec_mask
*mask
,
446 LLVMValueRef caseval
)
448 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
450 LLVMValueRef casemask
, prevmask
;
452 /* skipping case mask evaluation here is NOT optional (not in all cases anyway). */
453 if (!mask
->switch_in_default
) {
454 prevmask
= mask
->switch_stack
[mask
->switch_stack_size
- 1].switch_mask
;
455 casemask
= lp_build_cmp(mask
->bld
, PIPE_FUNC_EQUAL
, caseval
, mask
->switch_val
);
456 mask
->switch_mask_default
= LLVMBuildOr(builder
, casemask
,
457 mask
->switch_mask_default
, "sw_default_mask");
458 casemask
= LLVMBuildOr(builder
, casemask
, mask
->switch_mask
, "");
459 mask
->switch_mask
= LLVMBuildAnd(builder
, casemask
, prevmask
, "sw_mask");
461 lp_exec_mask_update(mask
);
466 * Analyse default statement in a switch.
467 * \return true if default is last statement, false otherwise
468 * \param default_pc_start contains pc of instruction to jump to
469 * if default wasn't last but there's no
470 * fallthrough into default.
472 static boolean
default_analyse_is_last(struct lp_exec_mask
*mask
,
473 struct lp_build_tgsi_context
* bld_base
,
474 int *default_pc_start
)
476 unsigned pc
= bld_base
->pc
;
477 unsigned curr_switch_stack
= mask
->switch_stack_size
;
479 /* skip over case statements which are together with default */
480 while (bld_base
->instructions
[pc
].Instruction
.Opcode
== TGSI_OPCODE_CASE
) {
484 while (pc
!= -1 && pc
< bld_base
->num_instructions
) {
485 unsigned opcode
= bld_base
->instructions
[pc
].Instruction
.Opcode
;
487 case TGSI_OPCODE_CASE
:
488 if (curr_switch_stack
== mask
->switch_stack_size
) {
489 *default_pc_start
= pc
- 1;
493 case TGSI_OPCODE_SWITCH
:
496 case TGSI_OPCODE_ENDSWITCH
:
497 if (curr_switch_stack
== mask
->switch_stack_size
) {
498 *default_pc_start
= pc
- 1;
506 /* should never arrive here */
511 static void lp_exec_default(struct lp_exec_mask
*mask
,
512 struct lp_build_tgsi_context
* bld_base
)
514 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
517 boolean default_is_last
;
520 * This is a messy opcode, because it may not be always at the end and
521 * there can be fallthrough in and out of it.
524 default_is_last
= default_analyse_is_last(mask
, bld_base
, &default_exec_pc
);
526 * If it is last statement in switch (note that case statements appearing
527 * "at the same time" as default don't change that) everything is just fine,
528 * update switch mask and go on. This means we can handle default with
529 * fallthrough INTO it without overhead, if it is last.
531 if (default_is_last
) {
532 LLVMValueRef prevmask
, defaultmask
;
533 prevmask
= mask
->switch_stack
[mask
->switch_stack_size
- 1].switch_mask
;
534 defaultmask
= LLVMBuildNot(builder
, mask
->switch_mask_default
, "sw_default_mask");
535 defaultmask
= LLVMBuildOr(builder
, defaultmask
, mask
->switch_mask
, "");
536 mask
->switch_mask
= LLVMBuildAnd(builder
, prevmask
, defaultmask
, "sw_mask");
537 mask
->switch_in_default
= true;
539 lp_exec_mask_update(mask
);
543 * Technically, "case" immediately before default isn't really a
544 * fallthrough, however we still have to count them as such as we
545 * already have updated the masks.
546 * If that happens in practice could add a switch optimizer pass
547 * which just gets rid of all case statements appearing together with
548 * default (or could do switch analysis at switch start time instead).
550 unsigned opcode
= bld_base
->instructions
[bld_base
->pc
- 1].Instruction
.Opcode
;
551 boolean ft_into
= (opcode
!= TGSI_OPCODE_BRK
||
552 opcode
!= TGSI_OPCODE_SWITCH
);
554 * If it is not last statement and there was no fallthrough into it,
555 * we record the PC and continue execution at next case (again, those
556 * case encountered at the same time don't count). At endswitch
557 * time, we update switchmask, and go back executing the code we skipped
558 * until the next break (possibly re-executing some code with changed mask
559 * if there was a fallthrough out of default).
560 * Finally, if it is not last statement and there was a fallthrough into it,
561 * do the same as with the former case, except instead of skipping the code
562 * just execute it without updating the mask, then go back and re-execute.
564 mask
->switch_pc
= bld_base
->pc
;
566 bld_base
->pc
= default_exec_pc
;
572 /* stores val into an address pointed to by dst_ptr.
573 * mask->exec_mask is used to figure out which bits of val
574 * should be stored into the address
575 * (0 means don't store this bit, 1 means do store).
577 static void lp_exec_mask_store(struct lp_exec_mask
*mask
,
578 struct lp_build_context
*bld_store
,
581 LLVMValueRef dst_ptr
)
583 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
585 assert(lp_check_value(bld_store
->type
, val
));
586 assert(LLVMGetTypeKind(LLVMTypeOf(dst_ptr
)) == LLVMPointerTypeKind
);
587 assert(LLVMGetElementType(LLVMTypeOf(dst_ptr
)) == LLVMTypeOf(val
));
589 /* Mix the predicate and execution mask */
590 if (mask
->has_mask
) {
592 pred
= LLVMBuildAnd(builder
, pred
, mask
->exec_mask
, "");
594 pred
= mask
->exec_mask
;
599 LLVMValueRef res
, dst
;
601 dst
= LLVMBuildLoad(builder
, dst_ptr
, "");
602 res
= lp_build_select(bld_store
, pred
, val
, dst
);
603 LLVMBuildStore(builder
, res
, dst_ptr
);
605 LLVMBuildStore(builder
, val
, dst_ptr
);
608 static void lp_exec_mask_call(struct lp_exec_mask
*mask
,
612 assert(mask
->call_stack_size
< LP_MAX_TGSI_NESTING
);
613 mask
->call_stack
[mask
->call_stack_size
].pc
= *pc
;
614 mask
->call_stack
[mask
->call_stack_size
].ret_mask
= mask
->ret_mask
;
615 mask
->call_stack_size
++;
619 static void lp_exec_mask_ret(struct lp_exec_mask
*mask
, int *pc
)
621 LLVMBuilderRef builder
= mask
->bld
->gallivm
->builder
;
622 LLVMValueRef exec_mask
;
624 if (mask
->cond_stack_size
== 0 &&
625 mask
->loop_stack_size
== 0 &&
626 mask
->switch_stack_size
== 0 &&
627 mask
->call_stack_size
== 0) {
628 /* returning from main() */
633 if (mask
->call_stack_size
== 0) {
635 * This requires special handling since we need to ensure
636 * we don't drop the mask even if we have no call stack
637 * (e.g. after a ret in a if clause after the endif)
639 mask
->ret_in_main
= TRUE
;
642 exec_mask
= LLVMBuildNot(builder
,
646 mask
->ret_mask
= LLVMBuildAnd(builder
,
648 exec_mask
, "ret_full");
650 lp_exec_mask_update(mask
);
653 static void lp_exec_mask_bgnsub(struct lp_exec_mask
*mask
)
657 static void lp_exec_mask_endsub(struct lp_exec_mask
*mask
, int *pc
)
659 assert(mask
->call_stack_size
);
660 mask
->call_stack_size
--;
661 *pc
= mask
->call_stack
[mask
->call_stack_size
].pc
;
662 mask
->ret_mask
= mask
->call_stack
[mask
->call_stack_size
].ret_mask
;
663 lp_exec_mask_update(mask
);
668 * Return pointer to a temporary register channel (src or dest).
669 * Note that indirect addressing cannot be handled here.
670 * \param index which temporary register
671 * \param chan which channel of the temp register.
674 lp_get_temp_ptr_soa(struct lp_build_tgsi_soa_context
*bld
,
678 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
680 if (bld
->indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
681 LLVMValueRef lindex
= lp_build_const_int32(bld
->bld_base
.base
.gallivm
, index
* 4 + chan
);
682 return LLVMBuildGEP(builder
, bld
->temps_array
, &lindex
, 1, "");
685 return bld
->temps
[index
][chan
];
690 * Return pointer to a output register channel (src or dest).
691 * Note that indirect addressing cannot be handled here.
692 * \param index which output register
693 * \param chan which channel of the output register.
696 lp_get_output_ptr(struct lp_build_tgsi_soa_context
*bld
,
700 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
702 if (bld
->indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
703 LLVMValueRef lindex
= lp_build_const_int32(bld
->bld_base
.base
.gallivm
,
705 return LLVMBuildGEP(builder
, bld
->outputs_array
, &lindex
, 1, "");
708 return bld
->outputs
[index
][chan
];
713 * If we have indirect addressing in outputs copy our alloca array
714 * to the outputs slots specified by the caller to make sure
715 * our outputs are delivered consistently via the same interface.
718 gather_outputs(struct lp_build_tgsi_soa_context
* bld
)
720 if ((bld
->indirect_files
& (1 << TGSI_FILE_OUTPUT
))) {
721 unsigned index
, chan
;
722 assert(bld
->bld_base
.info
->num_outputs
<=
723 bld
->bld_base
.info
->file_max
[TGSI_FILE_OUTPUT
] + 1);
724 for (index
= 0; index
< bld
->bld_base
.info
->num_outputs
; ++index
) {
725 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; ++chan
) {
726 bld
->outputs
[index
][chan
] = lp_get_output_ptr(bld
, index
, chan
);
734 * XXX the lp_build_gather() function should be capable of doing this
735 * with a little work.
738 build_gather(struct lp_build_context
*bld
,
739 LLVMValueRef base_ptr
,
740 LLVMValueRef indexes
)
742 LLVMBuilderRef builder
= bld
->gallivm
->builder
;
743 LLVMValueRef res
= bld
->undef
;
747 * Loop over elements of index_vec, load scalar value, insert it into 'res'.
749 for (i
= 0; i
< bld
->type
.length
; i
++) {
750 LLVMValueRef ii
= lp_build_const_int32(bld
->gallivm
, i
);
751 LLVMValueRef index
= LLVMBuildExtractElement(builder
,
753 LLVMValueRef scalar_ptr
= LLVMBuildGEP(builder
, base_ptr
,
754 &index
, 1, "gather_ptr");
755 LLVMValueRef scalar
= LLVMBuildLoad(builder
, scalar_ptr
, "");
757 res
= LLVMBuildInsertElement(builder
, res
, scalar
, ii
, "");
765 * Scatter/store vector.
768 emit_mask_scatter(struct lp_build_tgsi_soa_context
*bld
,
769 LLVMValueRef base_ptr
,
770 LLVMValueRef indexes
,
772 struct lp_exec_mask
*mask
,
775 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
776 LLVMBuilderRef builder
= gallivm
->builder
;
779 /* Mix the predicate and execution mask */
780 if (mask
->has_mask
) {
782 pred
= LLVMBuildAnd(builder
, pred
, mask
->exec_mask
, "");
785 pred
= mask
->exec_mask
;
790 * Loop over elements of index_vec, store scalar value.
792 for (i
= 0; i
< bld
->bld_base
.base
.type
.length
; i
++) {
793 LLVMValueRef ii
= lp_build_const_int32(gallivm
, i
);
794 LLVMValueRef index
= LLVMBuildExtractElement(builder
, indexes
, ii
, "");
795 LLVMValueRef scalar_ptr
= LLVMBuildGEP(builder
, base_ptr
, &index
, 1, "scatter_ptr");
796 LLVMValueRef val
= LLVMBuildExtractElement(builder
, values
, ii
, "scatter_val");
797 LLVMValueRef scalar_pred
= pred
?
798 LLVMBuildExtractElement(builder
, pred
, ii
, "scatter_pred") : NULL
;
801 lp_build_printf(gallivm
, "scatter %d: val %f at %d %p\n",
802 ii
, val
, index
, scalar_ptr
);
805 LLVMValueRef real_val
, dst_val
;
806 dst_val
= LLVMBuildLoad(builder
, scalar_ptr
, "");
807 real_val
= lp_build_select(&bld
->elem_bld
, scalar_pred
, val
, dst_val
);
808 LLVMBuildStore(builder
, real_val
, scalar_ptr
);
811 LLVMBuildStore(builder
, val
, scalar_ptr
);
818 * Read the current value of the ADDR register, convert the floats to
819 * ints, add the base index and return the vector of offsets.
820 * The offsets will be used to index into the constant buffer or
821 * temporary register file.
824 get_indirect_index(struct lp_build_tgsi_soa_context
*bld
,
825 unsigned reg_file
, unsigned reg_index
,
826 const struct tgsi_ind_register
*indirect_reg
)
828 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
829 struct lp_build_context
*uint_bld
= &bld
->bld_base
.uint_bld
;
830 /* always use X component of address register */
831 unsigned swizzle
= indirect_reg
->Swizzle
;
834 LLVMValueRef max_index
;
837 assert(bld
->indirect_files
& (1 << reg_file
));
839 base
= lp_build_const_int_vec(bld
->bld_base
.base
.gallivm
, uint_bld
->type
, reg_index
);
842 switch (indirect_reg
->File
) {
843 case TGSI_FILE_ADDRESS
:
844 rel
= LLVMBuildLoad(builder
,
845 bld
->addr
[indirect_reg
->Index
][swizzle
],
847 /* ADDR LLVM values already have LLVM integer type. */
849 case TGSI_FILE_TEMPORARY
:
850 rel
= lp_get_temp_ptr_soa(bld
, indirect_reg
->Index
, swizzle
);
851 rel
= LLVMBuildLoad(builder
, rel
, "load temp reg");
852 /* TEMP LLVM values always have LLVM float type, but for indirection, the
853 * value actually stored is expected to be an integer */
854 rel
= LLVMBuildBitCast(builder
, rel
, uint_bld
->vec_type
, "");
858 rel
= uint_bld
->zero
;
861 index
= lp_build_add(uint_bld
, base
, rel
);
863 max_index
= lp_build_const_int_vec(bld
->bld_base
.base
.gallivm
,
865 bld
->bld_base
.info
->file_max
[reg_file
]);
867 assert(!uint_bld
->type
.sign
);
868 index
= lp_build_min(uint_bld
, index
, max_index
);
873 static struct lp_build_context
*
874 stype_to_fetch(struct lp_build_tgsi_context
* bld_base
,
875 enum tgsi_opcode_type stype
)
877 struct lp_build_context
*bld_fetch
;
880 case TGSI_TYPE_FLOAT
:
881 case TGSI_TYPE_UNTYPED
:
882 bld_fetch
= &bld_base
->base
;
884 case TGSI_TYPE_UNSIGNED
:
885 bld_fetch
= &bld_base
->uint_bld
;
887 case TGSI_TYPE_SIGNED
:
888 bld_fetch
= &bld_base
->int_bld
;
891 case TGSI_TYPE_DOUBLE
:
902 struct lp_build_tgsi_context
* bld_base
,
903 const struct tgsi_full_src_register
* reg
,
904 enum tgsi_opcode_type stype
,
907 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
908 struct gallivm_state
*gallivm
= bld_base
->base
.gallivm
;
909 LLVMBuilderRef builder
= gallivm
->builder
;
910 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
911 LLVMValueRef indirect_index
= NULL
;
912 unsigned dimension
= 0;
913 LLVMValueRef dimension_index
;
914 LLVMValueRef consts_ptr
;
917 /* XXX: Handle fetching xyzw components as a vector */
918 assert(swizzle
!= ~0);
920 if (reg
->Register
.Dimension
) {
921 assert(!reg
->Dimension
.Indirect
);
922 dimension
= reg
->Dimension
.Index
;
923 assert(dimension
< LP_MAX_TGSI_CONST_BUFFERS
);
926 dimension_index
= lp_build_const_int32(gallivm
, dimension
);
927 consts_ptr
= lp_build_array_get(gallivm
, bld
->consts_ptr
, dimension_index
);
929 if (reg
->Register
.Indirect
) {
930 indirect_index
= get_indirect_index(bld
,
936 if (reg
->Register
.Indirect
) {
937 LLVMValueRef swizzle_vec
=
938 lp_build_const_int_vec(bld
->bld_base
.base
.gallivm
, uint_bld
->type
, swizzle
);
939 LLVMValueRef index_vec
; /* index into the const buffer */
941 /* index_vec = indirect_index * 4 + swizzle */
942 index_vec
= lp_build_shl_imm(uint_bld
, indirect_index
, 2);
943 index_vec
= lp_build_add(uint_bld
, index_vec
, swizzle_vec
);
945 /* Gather values from the constant buffer */
946 res
= build_gather(&bld_base
->base
, consts_ptr
, index_vec
);
949 LLVMValueRef index
; /* index into the const buffer */
950 LLVMValueRef scalar
, scalar_ptr
;
952 index
= lp_build_const_int32(gallivm
, reg
->Register
.Index
*4 + swizzle
);
954 scalar_ptr
= LLVMBuildGEP(builder
, consts_ptr
,
956 scalar
= LLVMBuildLoad(builder
, scalar_ptr
, "");
957 res
= lp_build_broadcast_scalar(&bld_base
->base
, scalar
);
960 if (stype
== TGSI_TYPE_SIGNED
|| stype
== TGSI_TYPE_UNSIGNED
) {
961 struct lp_build_context
*bld_fetch
= stype_to_fetch(bld_base
, stype
);
962 res
= LLVMBuildBitCast(builder
, res
, bld_fetch
->vec_type
, "");
968 emit_fetch_immediate(
969 struct lp_build_tgsi_context
* bld_base
,
970 const struct tgsi_full_src_register
* reg
,
971 enum tgsi_opcode_type stype
,
974 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
975 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
976 LLVMBuilderRef builder
= gallivm
->builder
;
977 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
978 struct lp_build_context
*float_bld
= &bld_base
->base
;
979 LLVMValueRef res
= NULL
;
980 LLVMValueRef indirect_index
= NULL
;
982 if (reg
->Register
.Indirect
) {
983 indirect_index
= get_indirect_index(bld
,
989 if (reg
->Register
.Indirect
) {
990 LLVMValueRef swizzle_vec
=
991 lp_build_const_int_vec(bld
->bld_base
.base
.gallivm
,
992 uint_bld
->type
, swizzle
);
993 LLVMValueRef length_vec
=
994 lp_build_const_int_vec(bld
->bld_base
.base
.gallivm
, uint_bld
->type
,
995 bld
->bld_base
.base
.type
.length
);
996 LLVMValueRef index_vec
; /* index into the const buffer */
997 LLVMValueRef imms_array
;
998 LLVMValueRef pixel_offsets
;
999 LLVMValueRef offsets
[LP_MAX_VECTOR_LENGTH
];
1000 LLVMTypeRef float4_ptr_type
;
1003 /* build pixel offset vector: {0, 1, 2, 3, ...} */
1004 for (i
= 0; i
< float_bld
->type
.length
; i
++) {
1005 offsets
[i
] = lp_build_const_int32(gallivm
, i
);
1007 pixel_offsets
= LLVMConstVector(offsets
, float_bld
->type
.length
);
1009 /* index_vec = (indirect_index * 4 + swizzle) * length */
1010 index_vec
= lp_build_shl_imm(uint_bld
, indirect_index
, 2);
1011 index_vec
= lp_build_add(uint_bld
, index_vec
, swizzle_vec
);
1012 index_vec
= lp_build_mul(uint_bld
, index_vec
, length_vec
);
1013 index_vec
= lp_build_add(uint_bld
, index_vec
, pixel_offsets
);
1015 /* cast imms_array pointer to float* */
1016 float4_ptr_type
= LLVMPointerType(
1017 LLVMFloatTypeInContext(bld
->bld_base
.base
.gallivm
->context
), 0);
1018 imms_array
= LLVMBuildBitCast(builder
, bld
->imms_array
,
1019 float4_ptr_type
, "");
1021 /* Gather values from the temporary register array */
1022 res
= build_gather(&bld_base
->base
, imms_array
, index_vec
);
1025 res
= bld
->immediates
[reg
->Register
.Index
][swizzle
];
1028 if (stype
== TGSI_TYPE_UNSIGNED
) {
1029 res
= LLVMConstBitCast(res
, bld_base
->uint_bld
.vec_type
);
1030 } else if (stype
== TGSI_TYPE_SIGNED
) {
1031 res
= LLVMConstBitCast(res
, bld_base
->int_bld
.vec_type
);
1038 struct lp_build_tgsi_context
* bld_base
,
1039 const struct tgsi_full_src_register
* reg
,
1040 enum tgsi_opcode_type stype
,
1043 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
1044 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
1045 LLVMBuilderRef builder
= gallivm
->builder
;
1046 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
1047 LLVMValueRef indirect_index
= NULL
;
1050 if (reg
->Register
.Indirect
) {
1051 indirect_index
= get_indirect_index(bld
,
1053 reg
->Register
.Index
,
1057 if (reg
->Register
.Indirect
) {
1058 LLVMValueRef swizzle_vec
=
1059 lp_build_const_int_vec(gallivm
, uint_bld
->type
, swizzle
);
1060 LLVMValueRef length_vec
=
1061 lp_build_const_int_vec(gallivm
, uint_bld
->type
, bld
->bld_base
.base
.type
.length
);
1062 LLVMValueRef index_vec
; /* index into the const buffer */
1063 LLVMValueRef inputs_array
;
1064 LLVMTypeRef float4_ptr_type
;
1066 /* index_vec = (indirect_index * 4 + swizzle) * length */
1067 index_vec
= lp_build_shl_imm(uint_bld
, indirect_index
, 2);
1068 index_vec
= lp_build_add(uint_bld
, index_vec
, swizzle_vec
);
1069 index_vec
= lp_build_mul(uint_bld
, index_vec
, length_vec
);
1071 /* cast inputs_array pointer to float* */
1072 float4_ptr_type
= LLVMPointerType(LLVMFloatTypeInContext(gallivm
->context
), 0);
1073 inputs_array
= LLVMBuildBitCast(builder
, bld
->inputs_array
,
1074 float4_ptr_type
, "");
1076 /* Gather values from the temporary register array */
1077 res
= build_gather(&bld_base
->base
, inputs_array
, index_vec
);
1079 if (bld
->indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1080 LLVMValueRef lindex
= lp_build_const_int32(gallivm
,
1081 reg
->Register
.Index
* 4 + swizzle
);
1082 LLVMValueRef input_ptr
= LLVMBuildGEP(builder
,
1083 bld
->inputs_array
, &lindex
, 1, "");
1084 res
= LLVMBuildLoad(builder
, input_ptr
, "");
1087 res
= bld
->inputs
[reg
->Register
.Index
][swizzle
];
1093 if (stype
== TGSI_TYPE_UNSIGNED
) {
1094 res
= LLVMBuildBitCast(builder
, res
, bld_base
->uint_bld
.vec_type
, "");
1095 } else if (stype
== TGSI_TYPE_SIGNED
) {
1096 res
= LLVMBuildBitCast(builder
, res
, bld_base
->int_bld
.vec_type
, "");
1104 emit_fetch_gs_input(
1105 struct lp_build_tgsi_context
* bld_base
,
1106 const struct tgsi_full_src_register
* reg
,
1107 enum tgsi_opcode_type stype
,
1110 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
1111 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
1112 LLVMBuilderRef builder
= gallivm
->builder
;
1113 LLVMValueRef attrib_index
= NULL
;
1114 LLVMValueRef vertex_index
= NULL
;
1115 LLVMValueRef swizzle_index
= lp_build_const_int32(gallivm
, swizzle
);
1118 if (reg
->Register
.Indirect
) {
1119 attrib_index
= get_indirect_index(bld
,
1121 reg
->Register
.Index
,
1124 attrib_index
= lp_build_const_int32(gallivm
, reg
->Register
.Index
);
1127 if (reg
->Dimension
.Indirect
) {
1128 vertex_index
= get_indirect_index(bld
,
1130 reg
->Dimension
.Index
,
1133 vertex_index
= lp_build_const_int32(gallivm
, reg
->Dimension
.Index
);
1136 res
= bld
->gs_iface
->fetch_input(bld
->gs_iface
, bld_base
,
1137 reg
->Dimension
.Indirect
,
1138 vertex_index
, attrib_index
,
1143 if (stype
== TGSI_TYPE_UNSIGNED
) {
1144 res
= LLVMBuildBitCast(builder
, res
, bld_base
->uint_bld
.vec_type
, "");
1145 } else if (stype
== TGSI_TYPE_SIGNED
) {
1146 res
= LLVMBuildBitCast(builder
, res
, bld_base
->int_bld
.vec_type
, "");
1153 emit_fetch_temporary(
1154 struct lp_build_tgsi_context
* bld_base
,
1155 const struct tgsi_full_src_register
* reg
,
1156 enum tgsi_opcode_type stype
,
1159 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
1160 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
1161 LLVMBuilderRef builder
= gallivm
->builder
;
1162 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
1163 struct lp_build_context
*float_bld
= &bld_base
->base
;
1164 LLVMValueRef indirect_index
= NULL
;
1167 if (reg
->Register
.Indirect
) {
1168 indirect_index
= get_indirect_index(bld
,
1170 reg
->Register
.Index
,
1174 if (reg
->Register
.Indirect
) {
1175 LLVMValueRef swizzle_vec
=
1176 lp_build_const_int_vec(bld
->bld_base
.base
.gallivm
, uint_bld
->type
, swizzle
);
1177 LLVMValueRef length_vec
=
1178 lp_build_const_int_vec(bld
->bld_base
.base
.gallivm
, uint_bld
->type
,
1179 bld
->bld_base
.base
.type
.length
);
1180 LLVMValueRef index_vec
; /* index into the const buffer */
1181 LLVMValueRef temps_array
;
1182 LLVMValueRef pixel_offsets
;
1183 LLVMValueRef offsets
[LP_MAX_VECTOR_LENGTH
];
1184 LLVMTypeRef float4_ptr_type
;
1187 /* build pixel offset vector: {0, 1, 2, 3, ...} */
1188 for (i
= 0; i
< float_bld
->type
.length
; i
++) {
1189 offsets
[i
] = lp_build_const_int32(gallivm
, i
);
1191 pixel_offsets
= LLVMConstVector(offsets
, float_bld
->type
.length
);
1193 /* index_vec = (indirect_index * 4 + swizzle) * length */
1194 index_vec
= lp_build_shl_imm(uint_bld
, indirect_index
, 2);
1195 index_vec
= lp_build_add(uint_bld
, index_vec
, swizzle_vec
);
1196 index_vec
= lp_build_mul(uint_bld
, index_vec
, length_vec
);
1197 index_vec
= lp_build_add(uint_bld
, index_vec
, pixel_offsets
);
1199 /* cast temps_array pointer to float* */
1200 float4_ptr_type
= LLVMPointerType(LLVMFloatTypeInContext(bld
->bld_base
.base
.gallivm
->context
), 0);
1201 temps_array
= LLVMBuildBitCast(builder
, bld
->temps_array
,
1202 float4_ptr_type
, "");
1204 /* Gather values from the temporary register array */
1205 res
= build_gather(&bld_base
->base
, temps_array
, index_vec
);
1208 LLVMValueRef temp_ptr
;
1209 temp_ptr
= lp_get_temp_ptr_soa(bld
, reg
->Register
.Index
, swizzle
);
1210 res
= LLVMBuildLoad(builder
, temp_ptr
, "");
1213 if (stype
== TGSI_TYPE_SIGNED
|| stype
== TGSI_TYPE_UNSIGNED
) {
1214 struct lp_build_context
*bld_fetch
= stype_to_fetch(bld_base
, stype
);
1215 res
= LLVMBuildBitCast(builder
, res
, bld_fetch
->vec_type
, "");
1222 emit_fetch_system_value(
1223 struct lp_build_tgsi_context
* bld_base
,
1224 const struct tgsi_full_src_register
* reg
,
1225 enum tgsi_opcode_type stype
,
1228 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
1229 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
1230 const struct tgsi_shader_info
*info
= bld
->bld_base
.info
;
1231 LLVMBuilderRef builder
= gallivm
->builder
;
1233 enum tgsi_opcode_type atype
; // Actual type of the value
1235 assert(!reg
->Register
.Indirect
);
1237 switch (info
->system_value_semantic_name
[reg
->Register
.Index
]) {
1238 case TGSI_SEMANTIC_INSTANCEID
:
1239 res
= lp_build_broadcast_scalar(&bld_base
->uint_bld
, bld
->system_values
.instance_id
);
1240 atype
= TGSI_TYPE_UNSIGNED
;
1243 case TGSI_SEMANTIC_VERTEXID
:
1244 res
= bld
->system_values
.vertex_id
;
1245 atype
= TGSI_TYPE_UNSIGNED
;
1248 case TGSI_SEMANTIC_PRIMID
:
1249 res
= bld
->system_values
.prim_id
;
1250 atype
= TGSI_TYPE_UNSIGNED
;
1254 assert(!"unexpected semantic in emit_fetch_system_value");
1255 res
= bld_base
->base
.zero
;
1256 atype
= TGSI_TYPE_FLOAT
;
1260 if (atype
!= stype
) {
1261 if (stype
== TGSI_TYPE_FLOAT
) {
1262 res
= LLVMBuildBitCast(builder
, res
, bld_base
->base
.vec_type
, "");
1263 } else if (stype
== TGSI_TYPE_UNSIGNED
) {
1264 res
= LLVMBuildBitCast(builder
, res
, bld_base
->uint_bld
.vec_type
, "");
1265 } else if (stype
== TGSI_TYPE_SIGNED
) {
1266 res
= LLVMBuildBitCast(builder
, res
, bld_base
->int_bld
.vec_type
, "");
1274 * Register fetch with derivatives.
1278 struct lp_build_tgsi_soa_context
*bld
,
1287 /* TODO: use interpolation coeffs for inputs */
1290 *ddx
= lp_build_ddx(&bld
->bld_base
.base
, src
);
1293 *ddy
= lp_build_ddy(&bld
->bld_base
.base
, src
);
1301 emit_fetch_predicate(
1302 struct lp_build_tgsi_soa_context
*bld
,
1303 const struct tgsi_full_instruction
*inst
,
1306 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
1308 unsigned char swizzles
[4];
1309 LLVMValueRef unswizzled
[4] = {NULL
, NULL
, NULL
, NULL
};
1313 if (!inst
->Instruction
.Predicate
) {
1314 TGSI_FOR_EACH_CHANNEL( chan
) {
1320 swizzles
[0] = inst
->Predicate
.SwizzleX
;
1321 swizzles
[1] = inst
->Predicate
.SwizzleY
;
1322 swizzles
[2] = inst
->Predicate
.SwizzleZ
;
1323 swizzles
[3] = inst
->Predicate
.SwizzleW
;
1325 index
= inst
->Predicate
.Index
;
1326 assert(index
< LP_MAX_TGSI_PREDS
);
1328 TGSI_FOR_EACH_CHANNEL( chan
) {
1329 unsigned swizzle
= swizzles
[chan
];
1332 * Only fetch the predicate register channels that are actually listed
1335 if (!unswizzled
[swizzle
]) {
1336 value
= LLVMBuildLoad(builder
,
1337 bld
->preds
[index
][swizzle
], "");
1340 * Convert the value to an integer mask.
1342 * TODO: Short-circuit this comparison -- a D3D setp_xx instructions
1343 * is needlessly causing two comparisons due to storing the intermediate
1344 * result as float vector instead of an integer mask vector.
1346 value
= lp_build_compare(bld
->bld_base
.base
.gallivm
,
1347 bld
->bld_base
.base
.type
,
1350 bld
->bld_base
.base
.zero
);
1351 if (inst
->Predicate
.Negate
) {
1352 value
= LLVMBuildNot(builder
, value
, "");
1355 unswizzled
[swizzle
] = value
;
1357 value
= unswizzled
[swizzle
];
1369 struct lp_build_tgsi_context
*bld_base
,
1370 const struct tgsi_full_instruction
*inst
,
1372 unsigned chan_index
,
1376 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
1377 struct gallivm_state
*gallivm
= bld_base
->base
.gallivm
;
1378 LLVMBuilderRef builder
= gallivm
->builder
;
1379 const struct tgsi_full_dst_register
*reg
= &inst
->Dst
[index
];
1380 struct lp_build_context
*float_bld
= &bld_base
->base
;
1381 struct lp_build_context
*int_bld
= &bld_base
->int_bld
;
1382 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
1383 LLVMValueRef indirect_index
= NULL
;
1384 enum tgsi_opcode_type dtype
= tgsi_opcode_infer_dst_type(inst
->Instruction
.Opcode
);
1389 * It is always assumed to be float.
1391 switch( inst
->Instruction
.Saturate
) {
1395 case TGSI_SAT_ZERO_ONE
:
1396 assert(dtype
== TGSI_TYPE_FLOAT
||
1397 dtype
== TGSI_TYPE_UNTYPED
);
1398 value
= LLVMBuildBitCast(builder
, value
, float_bld
->vec_type
, "");
1399 value
= lp_build_max(float_bld
, value
, float_bld
->zero
);
1400 value
= lp_build_min(float_bld
, value
, float_bld
->one
);
1403 case TGSI_SAT_MINUS_PLUS_ONE
:
1404 assert(dtype
== TGSI_TYPE_FLOAT
||
1405 dtype
== TGSI_TYPE_UNTYPED
);
1406 value
= LLVMBuildBitCast(builder
, value
, float_bld
->vec_type
, "");
1407 value
= lp_build_max(float_bld
, value
, lp_build_const_vec(gallivm
, float_bld
->type
, -1.0));
1408 value
= lp_build_min(float_bld
, value
, float_bld
->one
);
1415 if (reg
->Register
.Indirect
) {
1416 indirect_index
= get_indirect_index(bld
,
1418 reg
->Register
.Index
,
1421 assert(reg
->Register
.Index
<=
1422 bld_base
->info
->file_max
[reg
->Register
.File
]);
1425 switch( reg
->Register
.File
) {
1426 case TGSI_FILE_OUTPUT
:
1427 /* Outputs are always stored as floats */
1428 value
= LLVMBuildBitCast(builder
, value
, float_bld
->vec_type
, "");
1430 if (reg
->Register
.Indirect
) {
1431 LLVMValueRef chan_vec
=
1432 lp_build_const_int_vec(gallivm
, uint_bld
->type
, chan_index
);
1433 LLVMValueRef length_vec
=
1434 lp_build_const_int_vec(gallivm
, uint_bld
->type
, float_bld
->type
.length
);
1435 LLVMValueRef index_vec
; /* indexes into the temp registers */
1436 LLVMValueRef outputs_array
;
1437 LLVMValueRef pixel_offsets
;
1438 LLVMTypeRef float_ptr_type
;
1441 /* build pixel offset vector: {0, 1, 2, 3, ...} */
1442 pixel_offsets
= uint_bld
->undef
;
1443 for (i
= 0; i
< float_bld
->type
.length
; i
++) {
1444 LLVMValueRef ii
= lp_build_const_int32(gallivm
, i
);
1445 pixel_offsets
= LLVMBuildInsertElement(builder
, pixel_offsets
,
1449 /* index_vec = (indirect_index * 4 + chan_index) * length + offsets */
1450 index_vec
= lp_build_shl_imm(uint_bld
, indirect_index
, 2);
1451 index_vec
= lp_build_add(uint_bld
, index_vec
, chan_vec
);
1452 index_vec
= lp_build_mul(uint_bld
, index_vec
, length_vec
);
1453 index_vec
= lp_build_add(uint_bld
, index_vec
, pixel_offsets
);
1456 LLVMPointerType(LLVMFloatTypeInContext(gallivm
->context
), 0);
1457 outputs_array
= LLVMBuildBitCast(builder
, bld
->outputs_array
,
1458 float_ptr_type
, "");
1460 /* Scatter store values into temp registers */
1461 emit_mask_scatter(bld
, outputs_array
, index_vec
, value
,
1462 &bld
->exec_mask
, pred
);
1465 LLVMValueRef out_ptr
= lp_get_output_ptr(bld
, reg
->Register
.Index
,
1467 lp_exec_mask_store(&bld
->exec_mask
, float_bld
, pred
, value
, out_ptr
);
1471 case TGSI_FILE_TEMPORARY
:
1472 /* Temporaries are always stored as floats */
1473 value
= LLVMBuildBitCast(builder
, value
, float_bld
->vec_type
, "");
1475 if (reg
->Register
.Indirect
) {
1476 LLVMValueRef chan_vec
=
1477 lp_build_const_int_vec(gallivm
, uint_bld
->type
, chan_index
);
1478 LLVMValueRef length_vec
=
1479 lp_build_const_int_vec(gallivm
, uint_bld
->type
,
1480 float_bld
->type
.length
);
1481 LLVMValueRef index_vec
; /* indexes into the temp registers */
1482 LLVMValueRef temps_array
;
1483 LLVMValueRef pixel_offsets
;
1484 LLVMTypeRef float_ptr_type
;
1487 /* build pixel offset vector: {0, 1, 2, 3, ...} */
1488 pixel_offsets
= uint_bld
->undef
;
1489 for (i
= 0; i
< float_bld
->type
.length
; i
++) {
1490 LLVMValueRef ii
= lp_build_const_int32(gallivm
, i
);
1491 pixel_offsets
= LLVMBuildInsertElement(builder
, pixel_offsets
,
1495 /* index_vec = (indirect_index * 4 + chan_index) * length + offsets */
1496 index_vec
= lp_build_shl_imm(uint_bld
, indirect_index
, 2);
1497 index_vec
= lp_build_add(uint_bld
, index_vec
, chan_vec
);
1498 index_vec
= lp_build_mul(uint_bld
, index_vec
, length_vec
);
1499 index_vec
= lp_build_add(uint_bld
, index_vec
, pixel_offsets
);
1502 LLVMPointerType(LLVMFloatTypeInContext(gallivm
->context
), 0);
1503 temps_array
= LLVMBuildBitCast(builder
, bld
->temps_array
,
1504 float_ptr_type
, "");
1506 /* Scatter store values into temp registers */
1507 emit_mask_scatter(bld
, temps_array
, index_vec
, value
,
1508 &bld
->exec_mask
, pred
);
1511 LLVMValueRef temp_ptr
;
1512 temp_ptr
= lp_get_temp_ptr_soa(bld
, reg
->Register
.Index
,
1514 lp_exec_mask_store(&bld
->exec_mask
, float_bld
, pred
, value
, temp_ptr
);
1518 case TGSI_FILE_ADDRESS
:
1519 assert(dtype
== TGSI_TYPE_SIGNED
);
1520 assert(LLVMTypeOf(value
) == int_bld
->vec_type
);
1521 value
= LLVMBuildBitCast(builder
, value
, int_bld
->vec_type
, "");
1522 lp_exec_mask_store(&bld
->exec_mask
, int_bld
, pred
, value
,
1523 bld
->addr
[reg
->Register
.Index
][chan_index
]);
1526 case TGSI_FILE_PREDICATE
:
1527 assert(LLVMTypeOf(value
) == float_bld
->vec_type
);
1528 value
= LLVMBuildBitCast(builder
, value
, float_bld
->vec_type
, "");
1529 lp_exec_mask_store(&bld
->exec_mask
, float_bld
, pred
, value
,
1530 bld
->preds
[reg
->Register
.Index
][chan_index
]);
1542 struct lp_build_tgsi_context
* bld_base
,
1543 const struct tgsi_full_instruction
* inst
,
1544 const struct tgsi_opcode_info
* info
,
1545 LLVMValueRef dst
[4])
1548 unsigned chan_index
;
1549 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
1552 LLVMValueRef pred
[TGSI_NUM_CHANNELS
];
1554 emit_fetch_predicate( bld
, inst
, pred
);
1556 TGSI_FOR_EACH_DST0_ENABLED_CHANNEL( inst
, chan_index
) {
1557 emit_store_chan(bld_base
, inst
, 0, chan_index
, pred
[chan_index
], dst
[chan_index
]);
1563 * High-level instruction translators.
1567 emit_tex( struct lp_build_tgsi_soa_context
*bld
,
1568 const struct tgsi_full_instruction
*inst
,
1569 enum lp_build_tex_modifier modifier
,
1570 LLVMValueRef
*texel
)
1573 LLVMValueRef lod_bias
, explicit_lod
;
1574 LLVMValueRef oow
= NULL
;
1575 LLVMValueRef coords
[4];
1576 LLVMValueRef offsets
[3] = { NULL
};
1577 struct lp_derivatives derivs
;
1578 struct lp_derivatives
*deriv_ptr
= NULL
;
1579 unsigned num_coords
, num_derivs
, num_offsets
;
1582 if (!bld
->sampler
) {
1583 _debug_printf("warning: found texture instruction but no sampler generator supplied\n");
1584 for (i
= 0; i
< 4; i
++) {
1585 texel
[i
] = bld
->bld_base
.base
.undef
;
1590 switch (inst
->Texture
.Texture
) {
1591 case TGSI_TEXTURE_1D
:
1596 case TGSI_TEXTURE_1D_ARRAY
:
1601 case TGSI_TEXTURE_2D
:
1602 case TGSI_TEXTURE_RECT
:
1607 case TGSI_TEXTURE_SHADOW1D
:
1608 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
1613 case TGSI_TEXTURE_SHADOW2D
:
1614 case TGSI_TEXTURE_SHADOWRECT
:
1615 case TGSI_TEXTURE_2D_ARRAY
:
1620 case TGSI_TEXTURE_CUBE
:
1625 case TGSI_TEXTURE_3D
:
1630 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
1635 case TGSI_TEXTURE_SHADOWCUBE
:
1645 /* Note lod and especially projected are illegal in a LOT of cases */
1646 if (modifier
== LP_BLD_TEX_MODIFIER_LOD_BIAS
) {
1647 assert(num_coords
< 4);
1648 lod_bias
= lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, 3 );
1649 explicit_lod
= NULL
;
1651 else if (modifier
== LP_BLD_TEX_MODIFIER_EXPLICIT_LOD
) {
1652 assert(num_coords
< 4);
1654 explicit_lod
= lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, 3 );
1658 explicit_lod
= NULL
;
1661 if (modifier
== LP_BLD_TEX_MODIFIER_PROJECTED
) {
1662 assert(num_coords
< 4);
1663 oow
= lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, 3 );
1664 oow
= lp_build_rcp(&bld
->bld_base
.base
, oow
);
1667 for (i
= 0; i
< num_coords
; i
++) {
1668 coords
[i
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, i
);
1669 if (modifier
== LP_BLD_TEX_MODIFIER_PROJECTED
)
1670 coords
[i
] = lp_build_mul(&bld
->bld_base
.base
, coords
[i
], oow
);
1672 for (i
= num_coords
; i
< 4; i
++) {
1673 coords
[i
] = bld
->bld_base
.base
.undef
;
1676 if (modifier
== LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV
) {
1678 for (dim
= 0; dim
< num_derivs
; ++dim
) {
1679 derivs
.ddx
[dim
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 1, dim
);
1680 derivs
.ddy
[dim
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 2, dim
);
1682 deriv_ptr
= &derivs
;
1683 unit
= inst
->Src
[3].Register
.Index
;
1685 unit
= inst
->Src
[1].Register
.Index
;
1688 /* some advanced gather instructions (txgo) would require 4 offsets */
1689 if (inst
->Texture
.NumOffsets
== 1) {
1691 for (dim
= 0; dim
< num_offsets
; dim
++) {
1692 offsets
[dim
] = lp_build_emit_fetch_texoffset(&bld
->bld_base
, inst
, 0, dim
);
1696 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
1697 bld
->bld_base
.base
.gallivm
,
1698 bld
->bld_base
.base
.type
,
1704 lod_bias
, explicit_lod
,
1709 emit_sample(struct lp_build_tgsi_soa_context
*bld
,
1710 const struct tgsi_full_instruction
*inst
,
1711 enum lp_build_tex_modifier modifier
,
1713 LLVMValueRef
*texel
)
1715 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
1716 unsigned texture_unit
, sampler_unit
;
1717 LLVMValueRef lod_bias
, explicit_lod
;
1718 LLVMValueRef coords
[4];
1719 LLVMValueRef offsets
[3] = { NULL
};
1720 struct lp_derivatives derivs
;
1721 struct lp_derivatives
*deriv_ptr
= NULL
;
1722 unsigned num_coords
, num_offsets
, num_derivs
;
1725 if (!bld
->sampler
) {
1726 _debug_printf("warning: found texture instruction but no sampler generator supplied\n");
1727 for (i
= 0; i
< 4; i
++) {
1728 texel
[i
] = bld
->bld_base
.base
.undef
;
1734 * unlike old-style tex opcodes the texture/sampler indices
1735 * always come from src1 and src2 respectively.
1737 texture_unit
= inst
->Src
[1].Register
.Index
;
1738 sampler_unit
= inst
->Src
[2].Register
.Index
;
1741 * Note inst->Texture.Texture will contain the number of offsets,
1742 * however the target information is NOT there and comes from the
1743 * declared sampler views instead.
1745 switch (bld
->sv
[texture_unit
].Resource
) {
1746 case TGSI_TEXTURE_1D
:
1751 case TGSI_TEXTURE_1D_ARRAY
:
1756 case TGSI_TEXTURE_2D
:
1757 case TGSI_TEXTURE_RECT
:
1762 case TGSI_TEXTURE_2D_ARRAY
:
1767 case TGSI_TEXTURE_CUBE
:
1772 case TGSI_TEXTURE_3D
:
1777 case TGSI_TEXTURE_CUBE_ARRAY
:
1788 * unlike old-style tex opcodes the texture/sampler indices
1789 * always come from src1 and src2 respectively.
1791 texture_unit
= inst
->Src
[1].Register
.Index
;
1792 sampler_unit
= inst
->Src
[2].Register
.Index
;
1794 if (modifier
== LP_BLD_TEX_MODIFIER_LOD_BIAS
) {
1795 lod_bias
= lp_build_emit_fetch( &bld
->bld_base
, inst
, 3, 0 );
1796 explicit_lod
= NULL
;
1798 else if (modifier
== LP_BLD_TEX_MODIFIER_EXPLICIT_LOD
) {
1800 explicit_lod
= lp_build_emit_fetch( &bld
->bld_base
, inst
, 3, 0 );
1802 else if (modifier
== LP_BLD_TEX_MODIFIER_LOD_ZERO
) {
1804 /* XXX might be better to explicitly pass the level zero information */
1805 explicit_lod
= lp_build_const_vec(gallivm
, bld
->bld_base
.base
.type
, 0.0F
);
1809 explicit_lod
= NULL
;
1812 for (i
= 0; i
< num_coords
; i
++) {
1813 coords
[i
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, i
);
1815 for (i
= num_coords
; i
< 4; i
++) {
1816 coords
[i
] = bld
->bld_base
.base
.undef
;
1819 * XXX: whack shadow comparison value into place.
1820 * Should probably fix the interface for separate value
1821 * (it will not work for cube arrays if it is part of coords).
1824 unsigned c_coord
= num_coords
> 2 ? 3 : 2;
1825 assert(num_coords
< 4);
1826 coords
[c_coord
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 3, 0 );
1829 if (modifier
== LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV
) {
1831 for (dim
= 0; dim
< num_derivs
; ++dim
) {
1832 derivs
.ddx
[dim
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 3, dim
);
1833 derivs
.ddy
[dim
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 4, dim
);
1835 deriv_ptr
= &derivs
;
1838 /* some advanced gather instructions (txgo) would require 4 offsets */
1839 if (inst
->Texture
.NumOffsets
== 1) {
1841 for (dim
= 0; dim
< num_offsets
; dim
++) {
1842 offsets
[dim
] = lp_build_emit_fetch_texoffset(&bld
->bld_base
, inst
, 0, dim
);
1846 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
1847 bld
->bld_base
.base
.gallivm
,
1848 bld
->bld_base
.base
.type
,
1850 texture_unit
, sampler_unit
,
1854 lod_bias
, explicit_lod
,
1859 emit_fetch_texels( struct lp_build_tgsi_soa_context
*bld
,
1860 const struct tgsi_full_instruction
*inst
,
1861 LLVMValueRef
*texel
,
1864 unsigned unit
, target
;
1865 LLVMValueRef coord_undef
= LLVMGetUndef(bld
->bld_base
.base
.int_vec_type
);
1866 LLVMValueRef explicit_lod
= NULL
;
1867 LLVMValueRef coords
[3];
1868 LLVMValueRef offsets
[3] = { NULL
};
1869 unsigned num_coords
;
1873 if (!bld
->sampler
) {
1874 _debug_printf("warning: found texture instruction but no sampler generator supplied\n");
1875 for (i
= 0; i
< 4; i
++) {
1876 texel
[i
] = coord_undef
;
1881 unit
= inst
->Src
[1].Register
.Index
;
1884 target
= bld
->sv
[unit
].Resource
;
1887 target
= inst
->Texture
.Texture
;
1891 case TGSI_TEXTURE_1D
:
1892 case TGSI_TEXTURE_BUFFER
:
1896 case TGSI_TEXTURE_1D_ARRAY
:
1900 case TGSI_TEXTURE_2D
:
1901 case TGSI_TEXTURE_RECT
:
1905 case TGSI_TEXTURE_2D_ARRAY
:
1909 case TGSI_TEXTURE_3D
:
1918 /* always have lod except for buffers ? */
1919 if (target
!= TGSI_TEXTURE_BUFFER
) {
1920 explicit_lod
= lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, 3 );
1923 for (i
= 0; i
< num_coords
; i
++) {
1924 coords
[i
] = lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, i
);
1926 for (i
= num_coords
; i
< 3; i
++) {
1927 coords
[i
] = coord_undef
;
1930 if (inst
->Texture
.NumOffsets
== 1) {
1932 for (dim
= 0; dim
< dims
; dim
++) {
1933 offsets
[dim
] = lp_build_emit_fetch_texoffset(&bld
->bld_base
, inst
, 0, dim
);
1937 bld
->sampler
->emit_fetch_texel(bld
->sampler
,
1938 bld
->bld_base
.base
.gallivm
,
1939 bld
->bld_base
.base
.type
,
1950 emit_size_query( struct lp_build_tgsi_soa_context
*bld
,
1951 const struct tgsi_full_instruction
*inst
,
1952 LLVMValueRef
*sizes_out
,
1953 boolean is_sviewinfo
)
1955 LLVMValueRef explicit_lod
;
1958 unsigned unit
= inst
->Src
[1].Register
.Index
;
1962 target
= bld
->sv
[unit
].Resource
;
1965 target
= inst
->Texture
.Texture
;
1968 case TGSI_TEXTURE_BUFFER
:
1969 case TGSI_TEXTURE_RECT
:
1970 case TGSI_TEXTURE_SHADOWRECT
:
1978 if (!bld
->sampler
) {
1979 _debug_printf("warning: found texture query instruction but no sampler generator supplied\n");
1980 for (i
= 0; i
< 4; i
++)
1981 sizes_out
[i
] = bld
->bld_base
.int_bld
.undef
;
1986 explicit_lod
= lp_build_emit_fetch( &bld
->bld_base
, inst
, 0, 0 );
1988 explicit_lod
= NULL
;
1990 bld
->sampler
->emit_size_query(bld
->sampler
,
1991 bld
->bld_base
.base
.gallivm
,
1992 bld
->bld_base
.int_bld
.type
,
2000 near_end_of_shader(struct lp_build_tgsi_soa_context
*bld
,
2005 for (i
= 0; i
< 5; i
++) {
2008 if (pc
+ i
>= bld
->bld_base
.info
->num_instructions
)
2011 opcode
= bld
->bld_base
.instructions
[pc
+ i
].Instruction
.Opcode
;
2013 if (opcode
== TGSI_OPCODE_END
)
2016 if (opcode
== TGSI_OPCODE_TEX
||
2017 opcode
== TGSI_OPCODE_TXP
||
2018 opcode
== TGSI_OPCODE_TXD
||
2019 opcode
== TGSI_OPCODE_TXB
||
2020 opcode
== TGSI_OPCODE_TXL
||
2021 opcode
== TGSI_OPCODE_TXF
||
2022 opcode
== TGSI_OPCODE_TXQ
||
2023 opcode
== TGSI_OPCODE_CAL
||
2024 opcode
== TGSI_OPCODE_CALLNZ
||
2025 opcode
== TGSI_OPCODE_IF
||
2026 opcode
== TGSI_OPCODE_UIF
||
2027 opcode
== TGSI_OPCODE_BGNLOOP
||
2028 opcode
== TGSI_OPCODE_SWITCH
)
2038 * Kill fragment if any of the src register values are negative.
2042 struct lp_build_tgsi_soa_context
*bld
,
2043 const struct tgsi_full_instruction
*inst
,
2046 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
2047 const struct tgsi_full_src_register
*reg
= &inst
->Src
[0];
2048 LLVMValueRef terms
[TGSI_NUM_CHANNELS
];
2050 unsigned chan_index
;
2052 memset(&terms
, 0, sizeof terms
);
2054 TGSI_FOR_EACH_CHANNEL( chan_index
) {
2057 /* Unswizzle channel */
2058 swizzle
= tgsi_util_get_full_src_register_swizzle( reg
, chan_index
);
2060 /* Check if the component has not been already tested. */
2061 assert(swizzle
< TGSI_NUM_CHANNELS
);
2062 if( !terms
[swizzle
] )
2063 /* TODO: change the comparison operator instead of setting the sign */
2064 terms
[swizzle
] = lp_build_emit_fetch(&bld
->bld_base
, inst
, 0, chan_index
);
2068 TGSI_FOR_EACH_CHANNEL( chan_index
) {
2069 if(terms
[chan_index
]) {
2070 LLVMValueRef chan_mask
;
2073 * If term < 0 then mask = 0 else mask = ~0.
2075 chan_mask
= lp_build_cmp(&bld
->bld_base
.base
, PIPE_FUNC_GEQUAL
, terms
[chan_index
], bld
->bld_base
.base
.zero
);
2078 mask
= LLVMBuildAnd(builder
, mask
, chan_mask
, "");
2085 lp_build_mask_update(bld
->mask
, mask
);
2087 if (!near_end_of_shader(bld
, pc
))
2088 lp_build_mask_check(bld
->mask
);
2094 * Predicated fragment kill.
2095 * XXX Actually, we do an unconditional kill (as in tgsi_exec.c).
2096 * The only predication is the execution mask which will apply if
2097 * we're inside a loop or conditional.
2100 emit_kilp(struct lp_build_tgsi_soa_context
*bld
,
2103 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
2106 /* For those channels which are "alive", disable fragment shader
2109 if (bld
->exec_mask
.has_mask
) {
2110 mask
= LLVMBuildNot(builder
, bld
->exec_mask
.exec_mask
, "kilp");
2113 LLVMValueRef zero
= LLVMConstNull(bld
->bld_base
.base
.int_vec_type
);
2117 lp_build_mask_update(bld
->mask
, mask
);
2119 if (!near_end_of_shader(bld
, pc
))
2120 lp_build_mask_check(bld
->mask
);
2125 * Emit code which will dump the value of all the temporary registers
2129 emit_dump_temps(struct lp_build_tgsi_soa_context
*bld
)
2131 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
2132 LLVMBuilderRef builder
= gallivm
->builder
;
2133 LLVMValueRef temp_ptr
;
2134 LLVMValueRef i0
= lp_build_const_int32(gallivm
, 0);
2135 LLVMValueRef i1
= lp_build_const_int32(gallivm
, 1);
2136 LLVMValueRef i2
= lp_build_const_int32(gallivm
, 2);
2137 LLVMValueRef i3
= lp_build_const_int32(gallivm
, 3);
2139 int n
= bld
->bld_base
.info
->file_max
[TGSI_FILE_TEMPORARY
];
2141 for (index
= 0; index
< n
; index
++) {
2142 LLVMValueRef idx
= lp_build_const_int32(gallivm
, index
);
2143 LLVMValueRef v
[4][4], res
;
2146 lp_build_printf(gallivm
, "TEMP[%d]:\n", idx
);
2148 for (chan
= 0; chan
< 4; chan
++) {
2149 temp_ptr
= lp_get_temp_ptr_soa(bld
, index
, chan
);
2150 res
= LLVMBuildLoad(builder
, temp_ptr
, "");
2151 v
[chan
][0] = LLVMBuildExtractElement(builder
, res
, i0
, "");
2152 v
[chan
][1] = LLVMBuildExtractElement(builder
, res
, i1
, "");
2153 v
[chan
][2] = LLVMBuildExtractElement(builder
, res
, i2
, "");
2154 v
[chan
][3] = LLVMBuildExtractElement(builder
, res
, i3
, "");
2157 lp_build_printf(gallivm
, " X: %f %f %f %f\n",
2158 v
[0][0], v
[0][1], v
[0][2], v
[0][3]);
2159 lp_build_printf(gallivm
, " Y: %f %f %f %f\n",
2160 v
[1][0], v
[1][1], v
[1][2], v
[1][3]);
2161 lp_build_printf(gallivm
, " Z: %f %f %f %f\n",
2162 v
[2][0], v
[2][1], v
[2][2], v
[2][3]);
2163 lp_build_printf(gallivm
, " W: %f %f %f %f\n",
2164 v
[3][0], v
[3][1], v
[3][2], v
[3][3]);
2171 lp_emit_declaration_soa(
2172 struct lp_build_tgsi_context
*bld_base
,
2173 const struct tgsi_full_declaration
*decl
)
2175 struct lp_build_tgsi_soa_context
*bld
= lp_soa_context(bld_base
);
2176 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
2177 LLVMTypeRef vec_type
= bld
->bld_base
.base
.vec_type
;
2178 const unsigned first
= decl
->Range
.First
;
2179 const unsigned last
= decl
->Range
.Last
;
2182 for (idx
= first
; idx
<= last
; ++idx
) {
2183 assert(last
<= bld
->bld_base
.info
->file_max
[decl
->Declaration
.File
]);
2184 switch (decl
->Declaration
.File
) {
2185 case TGSI_FILE_TEMPORARY
:
2186 assert(idx
< LP_MAX_TGSI_TEMPS
);
2187 if (!(bld
->indirect_files
& (1 << TGSI_FILE_TEMPORARY
))) {
2188 for (i
= 0; i
< TGSI_NUM_CHANNELS
; i
++)
2189 bld
->temps
[idx
][i
] = lp_build_alloca(gallivm
, vec_type
, "temp");
2193 case TGSI_FILE_OUTPUT
:
2194 if (!(bld
->indirect_files
& (1 << TGSI_FILE_OUTPUT
))) {
2195 for (i
= 0; i
< TGSI_NUM_CHANNELS
; i
++)
2196 bld
->outputs
[idx
][i
] = lp_build_alloca(gallivm
,
2197 vec_type
, "output");
2201 case TGSI_FILE_ADDRESS
:
2202 /* ADDR registers are only allocated with an integer LLVM IR type,
2203 * as they are guaranteed to always have integers.
2204 * XXX: Not sure if this exception is worthwhile (or the whole idea of
2205 * an ADDR register for that matter).
2207 assert(idx
< LP_MAX_TGSI_ADDRS
);
2208 for (i
= 0; i
< TGSI_NUM_CHANNELS
; i
++)
2209 bld
->addr
[idx
][i
] = lp_build_alloca(gallivm
, bld_base
->base
.int_vec_type
, "addr");
2212 case TGSI_FILE_PREDICATE
:
2213 assert(idx
< LP_MAX_TGSI_PREDS
);
2214 for (i
= 0; i
< TGSI_NUM_CHANNELS
; i
++)
2215 bld
->preds
[idx
][i
] = lp_build_alloca(gallivm
, vec_type
,
2219 case TGSI_FILE_SAMPLER_VIEW
:
2221 * The target stored here MUST match whatever there actually
2222 * is in the set sampler views (what about return type?).
2224 assert(idx
< PIPE_MAX_SHADER_SAMPLER_VIEWS
);
2225 bld
->sv
[idx
] = decl
->SamplerView
;
2229 /* don't need to declare other vars */
2236 void lp_emit_immediate_soa(
2237 struct lp_build_tgsi_context
*bld_base
,
2238 const struct tgsi_full_immediate
*imm
)
2240 struct lp_build_tgsi_soa_context
*bld
= lp_soa_context(bld_base
);
2241 struct gallivm_state
* gallivm
= bld_base
->base
.gallivm
;
2243 /* simply copy the immediate values into the next immediates[] slot */
2245 const uint size
= imm
->Immediate
.NrTokens
- 1;
2247 assert(bld
->num_immediates
< LP_MAX_TGSI_IMMEDIATES
);
2248 switch (imm
->Immediate
.DataType
) {
2249 case TGSI_IMM_FLOAT32
:
2250 for( i
= 0; i
< size
; ++i
)
2251 bld
->immediates
[bld
->num_immediates
][i
] =
2252 lp_build_const_vec(gallivm
, bld_base
->base
.type
, imm
->u
[i
].Float
);
2255 case TGSI_IMM_UINT32
:
2256 for( i
= 0; i
< size
; ++i
) {
2257 LLVMValueRef tmp
= lp_build_const_vec(gallivm
, bld_base
->uint_bld
.type
, imm
->u
[i
].Uint
);
2258 bld
->immediates
[bld
->num_immediates
][i
] =
2259 LLVMConstBitCast(tmp
, bld_base
->base
.vec_type
);
2263 case TGSI_IMM_INT32
:
2264 for( i
= 0; i
< size
; ++i
) {
2265 LLVMValueRef tmp
= lp_build_const_vec(gallivm
, bld_base
->int_bld
.type
, imm
->u
[i
].Int
);
2266 bld
->immediates
[bld
->num_immediates
][i
] =
2267 LLVMConstBitCast(tmp
, bld_base
->base
.vec_type
);
2272 for( i
= size
; i
< 4; ++i
)
2273 bld
->immediates
[bld
->num_immediates
][i
] = bld_base
->base
.undef
;
2275 if (bld
->indirect_files
& (1 << TGSI_FILE_IMMEDIATE
)) {
2276 unsigned index
= bld
->num_immediates
;
2277 struct gallivm_state
*gallivm
= bld
->bld_base
.base
.gallivm
;
2278 LLVMBuilderRef builder
= gallivm
->builder
;
2279 for (i
= 0; i
< 4; ++i
) {
2280 LLVMValueRef lindex
= lp_build_const_int32(
2281 bld
->bld_base
.base
.gallivm
, index
* 4 + i
);
2282 LLVMValueRef imm_ptr
= LLVMBuildGEP(builder
,
2283 bld
->imms_array
, &lindex
, 1, "");
2284 LLVMBuildStore(builder
,
2285 bld
->immediates
[index
][i
],
2290 bld
->num_immediates
++;
2295 const struct lp_build_tgsi_action
* action
,
2296 struct lp_build_tgsi_context
* bld_base
,
2297 struct lp_build_emit_data
* emit_data
)
2299 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2301 emit_fetch_deriv(bld
, emit_data
->args
[0], NULL
,
2302 &emit_data
->output
[emit_data
->chan
], NULL
);
2307 const struct lp_build_tgsi_action
* action
,
2308 struct lp_build_tgsi_context
* bld_base
,
2309 struct lp_build_emit_data
* emit_data
)
2311 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2313 emit_fetch_deriv(bld
, emit_data
->args
[0], NULL
, NULL
,
2314 &emit_data
->output
[emit_data
->chan
]);
2319 const struct lp_build_tgsi_action
* action
,
2320 struct lp_build_tgsi_context
* bld_base
,
2321 struct lp_build_emit_data
* emit_data
)
2323 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2325 emit_kilp(bld
, bld_base
->pc
- 1);
2330 const struct lp_build_tgsi_action
* action
,
2331 struct lp_build_tgsi_context
* bld_base
,
2332 struct lp_build_emit_data
* emit_data
)
2334 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2336 emit_kil(bld
, emit_data
->inst
, bld_base
->pc
- 1);
2341 const struct lp_build_tgsi_action
* action
,
2342 struct lp_build_tgsi_context
* bld_base
,
2343 struct lp_build_emit_data
* emit_data
)
2345 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2347 emit_tex(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_NONE
, emit_data
->output
);
2352 const struct lp_build_tgsi_action
* action
,
2353 struct lp_build_tgsi_context
* bld_base
,
2354 struct lp_build_emit_data
* emit_data
)
2356 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2358 emit_tex(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_LOD_BIAS
,
2364 const struct lp_build_tgsi_action
* action
,
2365 struct lp_build_tgsi_context
* bld_base
,
2366 struct lp_build_emit_data
* emit_data
)
2368 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2370 emit_tex(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV
,
2376 const struct lp_build_tgsi_action
* action
,
2377 struct lp_build_tgsi_context
* bld_base
,
2378 struct lp_build_emit_data
* emit_data
)
2380 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2382 emit_tex(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_EXPLICIT_LOD
,
2388 const struct lp_build_tgsi_action
* action
,
2389 struct lp_build_tgsi_context
* bld_base
,
2390 struct lp_build_emit_data
* emit_data
)
2392 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2394 emit_tex(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_PROJECTED
,
2400 const struct lp_build_tgsi_action
* action
,
2401 struct lp_build_tgsi_context
* bld_base
,
2402 struct lp_build_emit_data
* emit_data
)
2404 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2406 emit_size_query(bld
, emit_data
->inst
, emit_data
->output
, FALSE
);
2411 const struct lp_build_tgsi_action
* action
,
2412 struct lp_build_tgsi_context
* bld_base
,
2413 struct lp_build_emit_data
* emit_data
)
2415 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2417 emit_fetch_texels(bld
, emit_data
->inst
, emit_data
->output
, FALSE
);
2422 const struct lp_build_tgsi_action
* action
,
2423 struct lp_build_tgsi_context
* bld_base
,
2424 struct lp_build_emit_data
* emit_data
)
2426 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2428 emit_fetch_texels(bld
, emit_data
->inst
, emit_data
->output
, TRUE
);
2433 const struct lp_build_tgsi_action
* action
,
2434 struct lp_build_tgsi_context
* bld_base
,
2435 struct lp_build_emit_data
* emit_data
)
2437 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2439 emit_sample(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_NONE
,
2440 FALSE
, emit_data
->output
);
2445 const struct lp_build_tgsi_action
* action
,
2446 struct lp_build_tgsi_context
* bld_base
,
2447 struct lp_build_emit_data
* emit_data
)
2449 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2451 emit_sample(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_LOD_BIAS
,
2452 FALSE
, emit_data
->output
);
2457 const struct lp_build_tgsi_action
* action
,
2458 struct lp_build_tgsi_context
* bld_base
,
2459 struct lp_build_emit_data
* emit_data
)
2461 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2463 emit_sample(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_NONE
,
2464 TRUE
, emit_data
->output
);
2469 const struct lp_build_tgsi_action
* action
,
2470 struct lp_build_tgsi_context
* bld_base
,
2471 struct lp_build_emit_data
* emit_data
)
2473 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2475 emit_sample(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_LOD_ZERO
,
2476 TRUE
, emit_data
->output
);
2481 const struct lp_build_tgsi_action
* action
,
2482 struct lp_build_tgsi_context
* bld_base
,
2483 struct lp_build_emit_data
* emit_data
)
2485 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2487 emit_sample(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV
,
2488 FALSE
, emit_data
->output
);
2493 const struct lp_build_tgsi_action
* action
,
2494 struct lp_build_tgsi_context
* bld_base
,
2495 struct lp_build_emit_data
* emit_data
)
2497 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2499 emit_sample(bld
, emit_data
->inst
, LP_BLD_TEX_MODIFIER_EXPLICIT_LOD
,
2500 FALSE
, emit_data
->output
);
2505 const struct lp_build_tgsi_action
* action
,
2506 struct lp_build_tgsi_context
* bld_base
,
2507 struct lp_build_emit_data
* emit_data
)
2509 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2511 emit_size_query(bld
, emit_data
->inst
, emit_data
->output
, TRUE
);
2515 mask_to_one_vec(struct lp_build_tgsi_context
*bld_base
)
2517 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2518 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
2519 LLVMValueRef one_vec
= bld_base
->int_bld
.one
;
2520 struct lp_exec_mask
*exec_mask
= &bld
->exec_mask
;
2522 if (exec_mask
->has_mask
) {
2523 one_vec
= LLVMBuildAnd(builder
, one_vec
, exec_mask
->exec_mask
, "");
2525 one_vec
= LLVMBuildAnd(builder
, one_vec
,
2526 lp_build_mask_value(bld
->mask
), "");
2531 increment_vec_ptr_by_mask(struct lp_build_tgsi_context
* bld_base
,
2535 LLVMBuilderRef builder
= bld_base
->base
.gallivm
->builder
;
2537 LLVMValueRef current_vec
= LLVMBuildLoad(builder
, ptr
, "");
2539 current_vec
= LLVMBuildAdd(builder
, current_vec
, mask
, "");
2541 LLVMBuildStore(builder
, current_vec
, ptr
);
2545 clear_uint_vec_ptr_from_mask(struct lp_build_tgsi_context
* bld_base
,
2549 LLVMBuilderRef builder
= bld_base
->base
.gallivm
->builder
;
2551 LLVMValueRef current_vec
= LLVMBuildLoad(builder
, ptr
, "");
2552 LLVMValueRef full_mask
= lp_build_cmp(&bld_base
->uint_bld
,
2555 bld_base
->uint_bld
.zero
);
2557 current_vec
= lp_build_select(&bld_base
->uint_bld
,
2559 bld_base
->uint_bld
.zero
,
2562 LLVMBuildStore(builder
, current_vec
, ptr
);
2566 clamp_mask_to_max_output_vertices(struct lp_build_tgsi_soa_context
* bld
,
2567 LLVMValueRef current_mask_vec
,
2568 LLVMValueRef total_emitted_vertices_vec
)
2570 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
2571 struct lp_build_context
*uint_bld
= &bld
->bld_base
.uint_bld
;
2572 LLVMValueRef max_mask
= lp_build_cmp(uint_bld
, PIPE_FUNC_LESS
,
2573 total_emitted_vertices_vec
,
2574 bld
->max_output_vertices_vec
);
2576 return LLVMBuildAnd(builder
, current_mask_vec
, max_mask
, "");
2581 const struct lp_build_tgsi_action
* action
,
2582 struct lp_build_tgsi_context
* bld_base
,
2583 struct lp_build_emit_data
* emit_data
)
2585 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2586 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
2588 if (bld
->gs_iface
->emit_vertex
) {
2589 LLVMValueRef masked_ones
= mask_to_one_vec(bld_base
);
2590 LLVMValueRef total_emitted_vertices_vec
=
2591 LLVMBuildLoad(builder
, bld
->total_emitted_vertices_vec_ptr
, "");
2592 masked_ones
= clamp_mask_to_max_output_vertices(bld
, masked_ones
,
2593 total_emitted_vertices_vec
);
2594 gather_outputs(bld
);
2595 bld
->gs_iface
->emit_vertex(bld
->gs_iface
, &bld
->bld_base
,
2597 total_emitted_vertices_vec
);
2598 increment_vec_ptr_by_mask(bld_base
, bld
->emitted_vertices_vec_ptr
,
2600 increment_vec_ptr_by_mask(bld_base
, bld
->total_emitted_vertices_vec_ptr
,
2603 lp_build_print_value(bld
->bld_base
.base
.gallivm
,
2604 " +++ emit vertex masked ones = ",
2606 lp_build_print_value(bld
->bld_base
.base
.gallivm
,
2607 " +++ emit vertex emitted = ",
2608 total_emitted_vertices_vec
);
2615 end_primitive_masked(struct lp_build_tgsi_context
* bld_base
,
2616 LLVMValueRef masked_ones
)
2618 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2619 LLVMBuilderRef builder
= bld
->bld_base
.base
.gallivm
->builder
;
2621 if (bld
->gs_iface
->end_primitive
) {
2622 LLVMValueRef emitted_vertices_vec
=
2623 LLVMBuildLoad(builder
, bld
->emitted_vertices_vec_ptr
, "");
2624 LLVMValueRef emitted_prims_vec
=
2625 LLVMBuildLoad(builder
, bld
->emitted_prims_vec_ptr
, "");
2627 bld
->gs_iface
->end_primitive(bld
->gs_iface
, &bld
->bld_base
,
2628 emitted_vertices_vec
,
2632 lp_build_print_value(bld
->bld_base
.base
.gallivm
,
2633 " +++ end prim masked ones = ",
2635 lp_build_print_value(bld
->bld_base
.base
.gallivm
,
2636 " +++ end prim emitted verts1 = ",
2637 emitted_vertices_vec
);
2638 lp_build_print_value(bld
->bld_base
.base
.gallivm
,
2639 " +++ end prim emitted prims1 = ",
2640 LLVMBuildLoad(builder
,
2641 bld
->emitted_prims_vec_ptr
, ""));
2643 increment_vec_ptr_by_mask(bld_base
, bld
->emitted_prims_vec_ptr
,
2645 clear_uint_vec_ptr_from_mask(bld_base
, bld
->emitted_vertices_vec_ptr
,
2648 lp_build_print_value(bld
->bld_base
.base
.gallivm
,
2649 " +++ end prim emitted verts2 = ",
2650 LLVMBuildLoad(builder
,
2651 bld
->emitted_vertices_vec_ptr
, ""));
2659 const struct lp_build_tgsi_action
* action
,
2660 struct lp_build_tgsi_context
* bld_base
,
2661 struct lp_build_emit_data
* emit_data
)
2663 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2665 if (bld
->gs_iface
->end_primitive
) {
2666 LLVMBuilderRef builder
= bld_base
->base
.gallivm
->builder
;
2667 LLVMValueRef masked_ones
= mask_to_one_vec(bld_base
);
2668 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
2669 LLVMValueRef emitted_verts
= LLVMBuildLoad(
2670 builder
, bld
->emitted_vertices_vec_ptr
, "");
2671 LLVMValueRef emitted_mask
= lp_build_cmp(uint_bld
, PIPE_FUNC_NOTEQUAL
,
2674 /* We need to combine the current execution mask with the mask
2675 telling us which, if any, execution slots actually have
2676 unemitted primitives, this way we make sure that end_primitives
2677 executes only on the paths that have unflushed vertices */
2678 masked_ones
= LLVMBuildAnd(builder
, masked_ones
, emitted_mask
, "");
2680 end_primitive_masked(bld_base
, masked_ones
);
2686 const struct lp_build_tgsi_action
* action
,
2687 struct lp_build_tgsi_context
* bld_base
,
2688 struct lp_build_emit_data
* emit_data
)
2690 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2692 lp_exec_mask_call(&bld
->exec_mask
, emit_data
->inst
->Label
.Label
,
2698 const struct lp_build_tgsi_action
* action
,
2699 struct lp_build_tgsi_context
* bld_base
,
2700 struct lp_build_emit_data
* emit_data
)
2702 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2704 lp_exec_mask_ret(&bld
->exec_mask
, &bld_base
->pc
);
2709 const struct lp_build_tgsi_action
* action
,
2710 struct lp_build_tgsi_context
* bld_base
,
2711 struct lp_build_emit_data
* emit_data
)
2713 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2715 lp_exec_break(&bld
->exec_mask
, bld_base
);
2720 const struct lp_build_tgsi_action
* action
,
2721 struct lp_build_tgsi_context
* bld_base
,
2722 struct lp_build_emit_data
* emit_data
)
2724 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2725 LLVMBuilderRef builder
= bld_base
->base
.gallivm
->builder
;
2726 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
2727 LLVMValueRef unsigned_cond
=
2728 LLVMBuildBitCast(builder
, emit_data
->args
[0], uint_bld
->vec_type
, "");
2729 LLVMValueRef cond
= lp_build_cmp(uint_bld
, PIPE_FUNC_NOTEQUAL
,
2733 lp_exec_break_condition(&bld
->exec_mask
, cond
);
2738 const struct lp_build_tgsi_action
* action
,
2739 struct lp_build_tgsi_context
* bld_base
,
2740 struct lp_build_emit_data
* emit_data
)
2743 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2745 tmp
= lp_build_cmp(&bld_base
->base
, PIPE_FUNC_NOTEQUAL
,
2746 emit_data
->args
[0], bld
->bld_base
.base
.zero
);
2747 lp_exec_mask_cond_push(&bld
->exec_mask
, tmp
);
2752 const struct lp_build_tgsi_action
* action
,
2753 struct lp_build_tgsi_context
* bld_base
,
2754 struct lp_build_emit_data
* emit_data
)
2757 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2758 struct lp_build_context
*uint_bld
= &bld_base
->uint_bld
;
2760 tmp
= lp_build_cmp(uint_bld
, PIPE_FUNC_NOTEQUAL
,
2761 emit_data
->args
[0], uint_bld
->zero
);
2762 lp_exec_mask_cond_push(&bld
->exec_mask
, tmp
);
2767 const struct lp_build_tgsi_action
* action
,
2768 struct lp_build_tgsi_context
* bld_base
,
2769 struct lp_build_emit_data
* emit_data
)
2771 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2773 lp_exec_case(&bld
->exec_mask
, emit_data
->args
[0]);
2778 const struct lp_build_tgsi_action
* action
,
2779 struct lp_build_tgsi_context
* bld_base
,
2780 struct lp_build_emit_data
* emit_data
)
2782 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2784 lp_exec_default(&bld
->exec_mask
, bld_base
);
2789 const struct lp_build_tgsi_action
* action
,
2790 struct lp_build_tgsi_context
* bld_base
,
2791 struct lp_build_emit_data
* emit_data
)
2793 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2795 lp_exec_switch(&bld
->exec_mask
, emit_data
->args
[0]);
2800 const struct lp_build_tgsi_action
* action
,
2801 struct lp_build_tgsi_context
* bld_base
,
2802 struct lp_build_emit_data
* emit_data
)
2804 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2806 lp_exec_endswitch(&bld
->exec_mask
, bld_base
);
2811 const struct lp_build_tgsi_action
* action
,
2812 struct lp_build_tgsi_context
* bld_base
,
2813 struct lp_build_emit_data
* emit_data
)
2815 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2817 lp_exec_bgnloop(&bld
->exec_mask
);
2822 const struct lp_build_tgsi_action
* action
,
2823 struct lp_build_tgsi_context
* bld_base
,
2824 struct lp_build_emit_data
* emit_data
)
2826 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2828 lp_exec_mask_bgnsub(&bld
->exec_mask
);
2833 const struct lp_build_tgsi_action
* action
,
2834 struct lp_build_tgsi_context
* bld_base
,
2835 struct lp_build_emit_data
* emit_data
)
2837 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2839 lp_exec_mask_cond_invert(&bld
->exec_mask
);
2844 const struct lp_build_tgsi_action
* action
,
2845 struct lp_build_tgsi_context
* bld_base
,
2846 struct lp_build_emit_data
* emit_data
)
2848 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2850 lp_exec_mask_cond_pop(&bld
->exec_mask
);
2855 const struct lp_build_tgsi_action
* action
,
2856 struct lp_build_tgsi_context
* bld_base
,
2857 struct lp_build_emit_data
* emit_data
)
2859 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2861 lp_exec_endloop(bld_base
->base
.gallivm
, &bld
->exec_mask
);
2866 const struct lp_build_tgsi_action
* action
,
2867 struct lp_build_tgsi_context
* bld_base
,
2868 struct lp_build_emit_data
* emit_data
)
2870 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2872 lp_exec_mask_endsub(&bld
->exec_mask
, &bld_base
->pc
);
2877 const struct lp_build_tgsi_action
* action
,
2878 struct lp_build_tgsi_context
* bld_base
,
2879 struct lp_build_emit_data
* emit_data
)
2881 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2883 lp_exec_continue(&bld
->exec_mask
);
2886 /* XXX: Refactor and move it to lp_bld_tgsi_action.c
2888 * XXX: What do the comments about xmm registers mean? Maybe they are left over
2889 * from old code, but there is no garauntee that LLVM will use those registers
2892 * XXX: There should be no calls to lp_build_emit_fetch in this function. This
2893 * should be handled by the emit_data->fetch_args function. */
2896 const struct lp_build_tgsi_action
* action
,
2897 struct lp_build_tgsi_context
* bld_base
,
2898 struct lp_build_emit_data
* emit_data
)
2900 LLVMValueRef tmp0
, tmp1
;
2901 LLVMValueRef tmp4
= NULL
;
2902 LLVMValueRef tmp5
= NULL
;
2903 LLVMValueRef tmp6
= NULL
;
2904 LLVMValueRef tmp7
= NULL
;
2905 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2907 uint dims
= (emit_data
->inst
->Instruction
.Opcode
== TGSI_OPCODE_NRM
) ? 3 : 4;
2909 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_X
) ||
2910 TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_Y
) ||
2911 TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_Z
) ||
2912 (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_W
) && dims
== 4)) {
2914 /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */
2917 /* xmm0 = src.x * src.x */
2918 tmp0
= lp_build_emit_fetch(&bld
->bld_base
, emit_data
->inst
, 0, TGSI_CHAN_X
);
2919 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_X
)) {
2922 tmp0
= lp_build_mul( &bld
->bld_base
.base
, tmp0
, tmp0
);
2925 /* xmm0 = xmm0 + src.y * src.y */
2926 tmp1
= lp_build_emit_fetch(&bld
->bld_base
, emit_data
->inst
, 0, TGSI_CHAN_Y
);
2927 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_Y
)) {
2930 tmp1
= lp_build_mul( &bld
->bld_base
.base
, tmp1
, tmp1
);
2931 tmp0
= lp_build_add( &bld
->bld_base
.base
, tmp0
, tmp1
);
2934 /* xmm0 = xmm0 + src.z * src.z */
2935 tmp1
= lp_build_emit_fetch(&bld
->bld_base
, emit_data
->inst
, 0, TGSI_CHAN_Z
);
2936 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_Z
)) {
2939 tmp1
= lp_build_mul( &bld
->bld_base
.base
, tmp1
, tmp1
);
2940 tmp0
= lp_build_add( &bld
->bld_base
.base
, tmp0
, tmp1
);
2944 /* xmm0 = xmm0 + src.w * src.w */
2945 tmp1
= lp_build_emit_fetch(&bld
->bld_base
, emit_data
->inst
, 0, TGSI_CHAN_W
);
2946 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_W
)) {
2949 tmp1
= lp_build_mul( &bld
->bld_base
.base
, tmp1
, tmp1
);
2950 tmp0
= lp_build_add( &bld
->bld_base
.base
, tmp0
, tmp1
);
2952 /* xmm1 = 1 / sqrt(xmm0) */
2953 tmp1
= lp_build_rsqrt( &bld
->bld_base
.base
, tmp0
);
2954 /* dst.x = xmm1 * src.x */
2955 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_X
)) {
2956 emit_data
->output
[TGSI_CHAN_X
] = lp_build_mul( &bld
->bld_base
.base
, tmp4
, tmp1
);
2958 /* dst.y = xmm1 * src.y */
2959 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_Y
)) {
2960 emit_data
->output
[TGSI_CHAN_Y
] = lp_build_mul( &bld
->bld_base
.base
, tmp5
, tmp1
);
2963 /* dst.z = xmm1 * src.z */
2964 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_Z
)) {
2965 emit_data
->output
[TGSI_CHAN_Z
] = lp_build_mul( &bld
->bld_base
.base
, tmp6
, tmp1
);
2967 /* dst.w = xmm1 * src.w */
2968 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_X
) && dims
== 4) {
2969 emit_data
->output
[TGSI_CHAN_W
] = lp_build_mul( &bld
->bld_base
.base
, tmp7
, tmp1
);
2974 if (TGSI_IS_DST0_CHANNEL_ENABLED(emit_data
->inst
, TGSI_CHAN_W
) && dims
== 3) {
2975 emit_data
->output
[TGSI_CHAN_W
] = bld
->bld_base
.base
.one
;
2979 static void emit_prologue(struct lp_build_tgsi_context
* bld_base
)
2981 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
2982 struct gallivm_state
* gallivm
= bld_base
->base
.gallivm
;
2984 if (bld
->indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
2985 LLVMValueRef array_size
=
2986 lp_build_const_int32(gallivm
,
2987 bld_base
->info
->file_max
[TGSI_FILE_TEMPORARY
] * 4 + 4);
2988 bld
->temps_array
= lp_build_array_alloca(gallivm
,
2989 bld_base
->base
.vec_type
, array_size
,
2993 if (bld
->indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
2994 LLVMValueRef array_size
=
2995 lp_build_const_int32(gallivm
,
2996 bld_base
->info
->file_max
[TGSI_FILE_OUTPUT
] * 4 + 4);
2997 bld
->outputs_array
= lp_build_array_alloca(gallivm
,
2998 bld_base
->base
.vec_type
, array_size
,
3002 if (bld
->indirect_files
& (1 << TGSI_FILE_IMMEDIATE
)) {
3003 LLVMValueRef array_size
=
3004 lp_build_const_int32(gallivm
,
3005 bld_base
->info
->file_max
[TGSI_FILE_IMMEDIATE
] * 4 + 4);
3006 bld
->imms_array
= lp_build_array_alloca(gallivm
,
3007 bld_base
->base
.vec_type
, array_size
,
3011 /* If we have indirect addressing in inputs we need to copy them into
3012 * our alloca array to be able to iterate over them */
3013 if (bld
->indirect_files
& (1 << TGSI_FILE_INPUT
) && !bld
->gs_iface
) {
3014 unsigned index
, chan
;
3015 LLVMTypeRef vec_type
= bld_base
->base
.vec_type
;
3016 LLVMValueRef array_size
= lp_build_const_int32(gallivm
,
3017 bld_base
->info
->file_max
[TGSI_FILE_INPUT
]*4 + 4);
3018 bld
->inputs_array
= lp_build_array_alloca(gallivm
,
3019 vec_type
, array_size
,
3022 assert(bld_base
->info
->num_inputs
3023 <= bld_base
->info
->file_max
[TGSI_FILE_INPUT
] + 1);
3025 for (index
= 0; index
< bld_base
->info
->num_inputs
; ++index
) {
3026 for (chan
= 0; chan
< TGSI_NUM_CHANNELS
; ++chan
) {
3027 LLVMValueRef lindex
=
3028 lp_build_const_int32(gallivm
, index
* 4 + chan
);
3029 LLVMValueRef input_ptr
=
3030 LLVMBuildGEP(gallivm
->builder
, bld
->inputs_array
,
3032 LLVMValueRef value
= bld
->inputs
[index
][chan
];
3034 LLVMBuildStore(gallivm
->builder
, value
, input_ptr
);
3039 if (bld
->gs_iface
) {
3040 struct lp_build_context
*uint_bld
= &bld
->bld_base
.uint_bld
;
3041 bld
->emitted_prims_vec_ptr
=
3042 lp_build_alloca(gallivm
,
3044 "emitted_prims_ptr");
3045 bld
->emitted_vertices_vec_ptr
=
3046 lp_build_alloca(gallivm
,
3048 "emitted_vertices_ptr");
3049 bld
->total_emitted_vertices_vec_ptr
=
3050 lp_build_alloca(gallivm
,
3052 "total_emitted_vertices_ptr");
3054 LLVMBuildStore(gallivm
->builder
, uint_bld
->zero
,
3055 bld
->emitted_prims_vec_ptr
);
3056 LLVMBuildStore(gallivm
->builder
, uint_bld
->zero
,
3057 bld
->emitted_vertices_vec_ptr
);
3058 LLVMBuildStore(gallivm
->builder
, uint_bld
->zero
,
3059 bld
->total_emitted_vertices_vec_ptr
);
3063 static void emit_epilogue(struct lp_build_tgsi_context
* bld_base
)
3065 struct lp_build_tgsi_soa_context
* bld
= lp_soa_context(bld_base
);
3066 LLVMBuilderRef builder
= bld_base
->base
.gallivm
->builder
;
3070 emit_dump_temps(bld
);
3073 /* If we have indirect addressing in outputs we need to copy our alloca array
3074 * to the outputs slots specified by the caller */
3075 if (bld
->gs_iface
) {
3076 LLVMValueRef total_emitted_vertices_vec
;
3077 LLVMValueRef emitted_prims_vec
;
3078 /* implicit end_primitives, needed in case there are any unflushed
3079 vertices in the cache */
3080 end_primitive(NULL
, bld_base
, NULL
);
3082 total_emitted_vertices_vec
=
3083 LLVMBuildLoad(builder
, bld
->total_emitted_vertices_vec_ptr
, "");
3085 LLVMBuildLoad(builder
, bld
->emitted_prims_vec_ptr
, "");
3087 bld
->gs_iface
->gs_epilogue(bld
->gs_iface
,
3089 total_emitted_vertices_vec
,
3092 gather_outputs(bld
);
3097 lp_build_tgsi_soa(struct gallivm_state
*gallivm
,
3098 const struct tgsi_token
*tokens
,
3099 struct lp_type type
,
3100 struct lp_build_mask_context
*mask
,
3101 LLVMValueRef consts_ptr
,
3102 const struct lp_bld_tgsi_system_values
*system_values
,
3103 const LLVMValueRef (*inputs
)[TGSI_NUM_CHANNELS
],
3104 LLVMValueRef (*outputs
)[TGSI_NUM_CHANNELS
],
3105 struct lp_build_sampler_soa
*sampler
,
3106 const struct tgsi_shader_info
*info
,
3107 const struct lp_build_tgsi_gs_iface
*gs_iface
)
3109 struct lp_build_tgsi_soa_context bld
;
3111 struct lp_type res_type
;
3113 assert(type
.length
<= LP_MAX_VECTOR_LENGTH
);
3114 memset(&res_type
, 0, sizeof res_type
);
3115 res_type
.width
= type
.width
;
3116 res_type
.length
= type
.length
;
3119 /* Setup build context */
3120 memset(&bld
, 0, sizeof bld
);
3121 lp_build_context_init(&bld
.bld_base
.base
, gallivm
, type
);
3122 lp_build_context_init(&bld
.bld_base
.uint_bld
, gallivm
, lp_uint_type(type
));
3123 lp_build_context_init(&bld
.bld_base
.int_bld
, gallivm
, lp_int_type(type
));
3124 lp_build_context_init(&bld
.elem_bld
, gallivm
, lp_elem_type(type
));
3126 bld
.inputs
= inputs
;
3127 bld
.outputs
= outputs
;
3128 bld
.consts_ptr
= consts_ptr
;
3129 bld
.sampler
= sampler
;
3130 bld
.bld_base
.info
= info
;
3131 bld
.indirect_files
= info
->indirect_files
;
3133 bld
.bld_base
.soa
= TRUE
;
3134 bld
.bld_base
.emit_fetch_funcs
[TGSI_FILE_CONSTANT
] = emit_fetch_constant
;
3135 bld
.bld_base
.emit_fetch_funcs
[TGSI_FILE_IMMEDIATE
] = emit_fetch_immediate
;
3136 bld
.bld_base
.emit_fetch_funcs
[TGSI_FILE_INPUT
] = emit_fetch_input
;
3137 bld
.bld_base
.emit_fetch_funcs
[TGSI_FILE_TEMPORARY
] = emit_fetch_temporary
;
3138 bld
.bld_base
.emit_fetch_funcs
[TGSI_FILE_SYSTEM_VALUE
] = emit_fetch_system_value
;
3139 bld
.bld_base
.emit_store
= emit_store
;
3141 bld
.bld_base
.emit_declaration
= lp_emit_declaration_soa
;
3142 bld
.bld_base
.emit_immediate
= lp_emit_immediate_soa
;
3144 bld
.bld_base
.emit_prologue
= emit_prologue
;
3145 bld
.bld_base
.emit_epilogue
= emit_epilogue
;
3147 /* Set opcode actions */
3148 lp_set_default_actions_cpu(&bld
.bld_base
);
3150 bld
.bld_base
.op_actions
[TGSI_OPCODE_BGNLOOP
].emit
= bgnloop_emit
;
3151 bld
.bld_base
.op_actions
[TGSI_OPCODE_BGNSUB
].emit
= bgnsub_emit
;
3152 bld
.bld_base
.op_actions
[TGSI_OPCODE_BRK
].emit
= brk_emit
;
3153 bld
.bld_base
.op_actions
[TGSI_OPCODE_BREAKC
].emit
= breakc_emit
;
3154 bld
.bld_base
.op_actions
[TGSI_OPCODE_CAL
].emit
= cal_emit
;
3155 bld
.bld_base
.op_actions
[TGSI_OPCODE_CASE
].emit
= case_emit
;
3156 bld
.bld_base
.op_actions
[TGSI_OPCODE_CONT
].emit
= cont_emit
;
3157 bld
.bld_base
.op_actions
[TGSI_OPCODE_DDX
].emit
= ddx_emit
;
3158 bld
.bld_base
.op_actions
[TGSI_OPCODE_DDY
].emit
= ddy_emit
;
3159 bld
.bld_base
.op_actions
[TGSI_OPCODE_DEFAULT
].emit
= default_emit
;
3160 bld
.bld_base
.op_actions
[TGSI_OPCODE_ELSE
].emit
= else_emit
;
3161 bld
.bld_base
.op_actions
[TGSI_OPCODE_ENDIF
].emit
= endif_emit
;
3162 bld
.bld_base
.op_actions
[TGSI_OPCODE_ENDLOOP
].emit
= endloop_emit
;
3163 bld
.bld_base
.op_actions
[TGSI_OPCODE_ENDSUB
].emit
= endsub_emit
;
3164 bld
.bld_base
.op_actions
[TGSI_OPCODE_ENDSWITCH
].emit
= endswitch_emit
;
3165 bld
.bld_base
.op_actions
[TGSI_OPCODE_IF
].emit
= if_emit
;
3166 bld
.bld_base
.op_actions
[TGSI_OPCODE_UIF
].emit
= uif_emit
;
3167 bld
.bld_base
.op_actions
[TGSI_OPCODE_KIL
].emit
= kil_emit
;
3168 bld
.bld_base
.op_actions
[TGSI_OPCODE_KILP
].emit
= kilp_emit
;
3169 bld
.bld_base
.op_actions
[TGSI_OPCODE_NRM
].emit
= nrm_emit
;
3170 bld
.bld_base
.op_actions
[TGSI_OPCODE_NRM4
].emit
= nrm_emit
;
3171 bld
.bld_base
.op_actions
[TGSI_OPCODE_RET
].emit
= ret_emit
;
3172 bld
.bld_base
.op_actions
[TGSI_OPCODE_SWITCH
].emit
= switch_emit
;
3173 bld
.bld_base
.op_actions
[TGSI_OPCODE_TEX
].emit
= tex_emit
;
3174 bld
.bld_base
.op_actions
[TGSI_OPCODE_TXB
].emit
= txb_emit
;
3175 bld
.bld_base
.op_actions
[TGSI_OPCODE_TXD
].emit
= txd_emit
;
3176 bld
.bld_base
.op_actions
[TGSI_OPCODE_TXL
].emit
= txl_emit
;
3177 bld
.bld_base
.op_actions
[TGSI_OPCODE_TXP
].emit
= txp_emit
;
3178 bld
.bld_base
.op_actions
[TGSI_OPCODE_TXQ
].emit
= txq_emit
;
3179 bld
.bld_base
.op_actions
[TGSI_OPCODE_TXF
].emit
= txf_emit
;
3180 /* DX10 sampling ops */
3181 bld
.bld_base
.op_actions
[TGSI_OPCODE_SAMPLE
].emit
= sample_emit
;
3182 bld
.bld_base
.op_actions
[TGSI_OPCODE_SAMPLE_B
].emit
= sample_b_emit
;
3183 bld
.bld_base
.op_actions
[TGSI_OPCODE_SAMPLE_C
].emit
= sample_c_emit
;
3184 bld
.bld_base
.op_actions
[TGSI_OPCODE_SAMPLE_C_LZ
].emit
= sample_c_lz_emit
;
3185 bld
.bld_base
.op_actions
[TGSI_OPCODE_SAMPLE_D
].emit
= sample_d_emit
;
3186 bld
.bld_base
.op_actions
[TGSI_OPCODE_SAMPLE_I
].emit
= sample_i_emit
;
3187 bld
.bld_base
.op_actions
[TGSI_OPCODE_SAMPLE_L
].emit
= sample_l_emit
;
3188 bld
.bld_base
.op_actions
[TGSI_OPCODE_SVIEWINFO
].emit
= sviewinfo_emit
;
3191 /* There's no specific value for this because it should always
3192 * be set, but apps using ext_geometry_shader4 quite often
3193 * were forgetting so we're using MAX_VERTEX_VARYING from
3194 * that spec even though we could debug_assert if it's not
3195 * set, but that's a lot uglier. */
3196 uint max_output_vertices
= 32;
3198 /* inputs are always indirect with gs */
3199 bld
.indirect_files
|= (1 << TGSI_FILE_INPUT
);
3200 bld
.gs_iface
= gs_iface
;
3201 bld
.bld_base
.emit_fetch_funcs
[TGSI_FILE_INPUT
] = emit_fetch_gs_input
;
3202 bld
.bld_base
.op_actions
[TGSI_OPCODE_EMIT
].emit
= emit_vertex
;
3203 bld
.bld_base
.op_actions
[TGSI_OPCODE_ENDPRIM
].emit
= end_primitive
;
3205 for (i
= 0; i
< info
->num_properties
; ++i
) {
3206 if (info
->properties
[i
].name
==
3207 TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
) {
3208 max_output_vertices
= info
->properties
[i
].data
[0];
3211 bld
.max_output_vertices_vec
=
3212 lp_build_const_int_vec(gallivm
, bld
.bld_base
.uint_bld
.type
,
3213 max_output_vertices
);
3216 lp_exec_mask_init(&bld
.exec_mask
, &bld
.bld_base
.int_bld
);
3218 bld
.system_values
= *system_values
;
3220 lp_build_tgsi_llvm(&bld
.bld_base
, tokens
);
3223 LLVMBasicBlockRef block
= LLVMGetInsertBlock(gallivm
->builder
);
3224 LLVMValueRef function
= LLVMGetBasicBlockParent(block
);
3225 debug_printf("11111111111111111111111111111 \n");
3226 tgsi_dump(tokens
, 0);
3227 lp_debug_dump_value(function
);
3228 debug_printf("2222222222222222222222222222 \n");
3232 LLVMModuleRef module
= LLVMGetGlobalParent(
3233 LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm
->builder
)));
3234 LLVMDumpModule(module
);