1 /**************************************************************************
3 * Copyright 2010 VMware.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "util/u_math.h"
30 #include "util/u_memory.h"
31 #include "util/u_simple_list.h"
32 #include "os/os_time.h"
33 #include "gallivm/lp_bld_debug.h"
34 #include "gallivm/lp_bld_init.h"
35 #include "gallivm/lp_bld_intr.h"
36 #include <llvm-c/Analysis.h> /* for LLVMVerifyFunction */
41 #include "lp_screen.h"
42 #include "lp_context.h"
43 #include "lp_setup_context.h"
46 #include "lp_state_fs.h"
47 #include "lp_state_setup.h"
51 /* currently organized to interpolate full float[4] attributes even
52 * when some elements are unused. Later, can pack vertex data more
59 /* Function arguments:
64 LLVMValueRef facing
; /* boolean */
71 LLVMValueRef x0_center
;
72 LLVMValueRef y0_center
;
73 LLVMValueRef dy20_ooa
;
74 LLVMValueRef dy01_ooa
;
75 LLVMValueRef dx20_ooa
;
76 LLVMValueRef dx01_ooa
;
79 static LLVMTypeRef
type4f(void)
81 return LLVMVectorType(LLVMFloatType(), 4);
85 /* Equivalent of _mm_setr_ps(a,b,c,d)
87 static LLVMValueRef
vec4f(LLVMBuilderRef bld
,
88 LLVMValueRef a
, LLVMValueRef b
, LLVMValueRef c
, LLVMValueRef d
,
91 LLVMValueRef i0
= LLVMConstInt(LLVMInt32Type(), 0, 0);
92 LLVMValueRef i1
= LLVMConstInt(LLVMInt32Type(), 1, 0);
93 LLVMValueRef i2
= LLVMConstInt(LLVMInt32Type(), 2, 0);
94 LLVMValueRef i3
= LLVMConstInt(LLVMInt32Type(), 3, 0);
96 LLVMValueRef res
= LLVMGetUndef(type4f());
98 res
= LLVMBuildInsertElement(bld
, res
, a
, i0
, "");
99 res
= LLVMBuildInsertElement(bld
, res
, b
, i1
, "");
100 res
= LLVMBuildInsertElement(bld
, res
, c
, i2
, "");
101 res
= LLVMBuildInsertElement(bld
, res
, d
, i3
, name
);
106 /* Equivalent of _mm_set1_ps(a)
108 static LLVMValueRef
vec4f_from_scalar(LLVMBuilderRef bld
,
112 LLVMValueRef res
= LLVMGetUndef(type4f());
115 for(i
= 0; i
< 4; ++i
) {
116 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), i
, 0);
117 res
= LLVMBuildInsertElement(bld
, res
, a
, index
, i
== 3 ? name
: "");
124 store_coef(LLVMBuilderRef builder
,
125 struct lp_setup_args
*args
,
131 LLVMValueRef idx
= LLVMConstInt(LLVMInt32Type(), slot
, 0);
133 LLVMBuildStore(builder
,
135 LLVMBuildGEP(builder
, args
->a0
, &idx
, 1, ""));
137 LLVMBuildStore(builder
,
139 LLVMBuildGEP(builder
, args
->dadx
, &idx
, 1, ""));
141 LLVMBuildStore(builder
,
143 LLVMBuildGEP(builder
, args
->dady
, &idx
, 1, ""));
149 emit_constant_coef4( LLVMBuilderRef builder
,
150 struct lp_setup_args
*args
,
155 LLVMValueRef zero
= LLVMConstReal(LLVMFloatType(), 0.0);
156 LLVMValueRef zerovec
= vec4f_from_scalar(builder
, zero
, "zero");
157 LLVMValueRef idx
= LLVMConstInt(LLVMInt32Type(), attr
, 0);
158 LLVMValueRef attr_ptr
= LLVMBuildGEP(builder
, vert
, &idx
, 1, "attr_ptr");
159 LLVMValueRef vert_attr
= LLVMBuildLoad(builder
, attr_ptr
, "vert_attr");
161 store_coef(builder
, args
, slot
, vert_attr
, zerovec
, zerovec
);
167 * Setup the fragment input attribute with the front-facing value.
168 * \param frontface is the triangle front facing?
171 emit_facing_coef( LLVMBuilderRef builder
,
172 struct lp_setup_args
*args
,
175 LLVMValueRef a0_0
= args
->facing
;
176 LLVMValueRef a0_0f
= LLVMBuildSIToFP(builder
, a0_0
, LLVMFloatType(), "");
177 LLVMValueRef zero
= LLVMConstReal(LLVMFloatType(), 0.0);
178 LLVMValueRef a0
= vec4f(builder
, a0_0f
, zero
, zero
, zero
, "facing");
179 LLVMValueRef zerovec
= vec4f_from_scalar(builder
, zero
, "zero");
181 store_coef(builder
, args
, slot
, a0
, zerovec
, zerovec
);
186 vert_attrib(LLVMBuilderRef b
,
193 idx
[0] = LLVMConstInt(LLVMInt32Type(), attr
, 0);
194 idx
[1] = LLVMConstInt(LLVMInt32Type(), elem
, 0);
195 return LLVMBuildLoad(b
, LLVMBuildGEP(b
, vert
, idx
, 2, ""), name
);
201 emit_coef4( LLVMBuilderRef b
,
202 struct lp_setup_args
*args
,
208 LLVMValueRef dy20_ooa
= args
->dy20_ooa
;
209 LLVMValueRef dy01_ooa
= args
->dy01_ooa
;
210 LLVMValueRef dx20_ooa
= args
->dx20_ooa
;
211 LLVMValueRef dx01_ooa
= args
->dx01_ooa
;
212 LLVMValueRef x0_center
= args
->x0_center
;
213 LLVMValueRef y0_center
= args
->y0_center
;
215 /* XXX: using fsub, fmul on vector types -- does this work??
217 LLVMValueRef da01
= LLVMBuildFSub(b
, a0
, a1
, "da01");
218 LLVMValueRef da20
= LLVMBuildFSub(b
, a2
, a0
, "da20");
220 /* Calculate dadx (vec4f)
222 LLVMValueRef da01_dy20_ooa
= LLVMBuildFMul(b
, da01
, dy20_ooa
, "da01_dy20_ooa");
223 LLVMValueRef da20_dy01_ooa
= LLVMBuildFMul(b
, da20
, dy01_ooa
, "da20_dy01_ooa");
224 LLVMValueRef dadx
= LLVMBuildFSub(b
, da01_dy20_ooa
, da20_dy01_ooa
, "dadx");
226 /* Calculate dady (vec4f)
228 LLVMValueRef da01_dx20_ooa
= LLVMBuildFMul(b
, da01
, dx20_ooa
, "da01_dx20_ooa");
229 LLVMValueRef da20_dx01_ooa
= LLVMBuildFMul(b
, da20
, dx01_ooa
, "da20_dx01_ooa");
230 LLVMValueRef dady
= LLVMBuildFSub(b
, da20_dx01_ooa
, da01_dx20_ooa
, "dady");
232 /* Calculate a0 - the attribute value at the origin
234 LLVMValueRef dadx_x0
= LLVMBuildFMul(b
, dadx
, x0_center
, "dadx_x0");
235 LLVMValueRef dady_y0
= LLVMBuildFMul(b
, dady
, y0_center
, "dady_y0");
236 LLVMValueRef attr_v0
= LLVMBuildFAdd(b
, dadx_x0
, dady_y0
, "attr_v0");
237 LLVMValueRef attr_0
= LLVMBuildFSub(b
, a0
, attr_v0
, "attr_0");
239 store_coef(b
, args
, slot
, attr_0
, dadx
, dady
);
244 emit_linear_coef( LLVMBuilderRef b
,
245 struct lp_setup_args
*args
,
249 LLVMValueRef idx
= LLVMConstInt(LLVMInt32Type(), vert_attr
, 0);
251 LLVMValueRef a0
= LLVMBuildLoad(b
, LLVMBuildGEP(b
, args
->v0
, &idx
, 1, ""), "v0a");
252 LLVMValueRef a1
= LLVMBuildLoad(b
, LLVMBuildGEP(b
, args
->v1
, &idx
, 1, ""), "v1a");
253 LLVMValueRef a2
= LLVMBuildLoad(b
, LLVMBuildGEP(b
, args
->v2
, &idx
, 1, ""), "v2a");
255 emit_coef4(b
, args
, slot
, a0
, a1
, a2
);
261 * Compute a0, dadx and dady for a perspective-corrected interpolant,
263 * We basically multiply the vertex value by 1/w before computing
264 * the plane coefficients (a0, dadx, dady).
265 * Later, when we compute the value at a particular fragment position we'll
266 * divide the interpolated value by the interpolated W at that fragment.
269 emit_perspective_coef( LLVMBuilderRef b
,
270 struct lp_setup_args
*args
,
274 /* premultiply by 1/w (v[0][3] is always 1/w):
276 LLVMValueRef idx
= LLVMConstInt(LLVMInt32Type(), vert_attr
, 0);
278 LLVMValueRef v0a
= LLVMBuildLoad(b
, LLVMBuildGEP(b
, args
->v0
, &idx
, 1, ""), "v0a");
279 LLVMValueRef v1a
= LLVMBuildLoad(b
, LLVMBuildGEP(b
, args
->v1
, &idx
, 1, ""), "v1a");
280 LLVMValueRef v2a
= LLVMBuildLoad(b
, LLVMBuildGEP(b
, args
->v2
, &idx
, 1, ""), "v2a");
282 LLVMValueRef v0_oow
= vec4f_from_scalar(b
, vert_attrib(b
, args
->v0
, 0, 3, ""), "v0_oow");
283 LLVMValueRef v1_oow
= vec4f_from_scalar(b
, vert_attrib(b
, args
->v1
, 0, 3, ""), "v1_oow");
284 LLVMValueRef v2_oow
= vec4f_from_scalar(b
, vert_attrib(b
, args
->v2
, 0, 3, ""), "v2_oow");
286 LLVMValueRef v0_oow_v0a
= LLVMBuildFMul(b
, v0a
, v0_oow
, "v0_oow_v0a");
287 LLVMValueRef v1_oow_v1a
= LLVMBuildFMul(b
, v1a
, v1_oow
, "v1_oow_v1a");
288 LLVMValueRef v2_oow_v2a
= LLVMBuildFMul(b
, v2a
, v2_oow
, "v2_oow_v2a");
290 emit_coef4(b
, args
, slot
, v0_oow_v0a
, v1_oow_v1a
, v2_oow_v2a
);
295 emit_position_coef( LLVMBuilderRef builder
,
296 struct lp_setup_args
*args
,
297 int slot
, int attrib
)
299 emit_linear_coef(builder
, args
, slot
, attrib
);
306 * Compute the inputs-> dadx, dady, a0 values.
309 emit_tri_coef( LLVMBuilderRef builder
,
310 const struct lp_setup_variant_key
*key
,
311 struct lp_setup_args
*args
)
315 /* The internal position input is in slot zero:
317 emit_position_coef(builder
, args
, 0, 0);
319 /* setup interpolation for all the remaining attributes:
321 for (slot
= 0; slot
< key
->num_inputs
; slot
++) {
322 unsigned vert_attr
= key
->inputs
[slot
].src_index
;
324 switch (key
->inputs
[slot
].interp
) {
325 case LP_INTERP_CONSTANT
:
326 if (key
->flatshade_first
) {
327 emit_constant_coef4(builder
, args
, slot
+1, args
->v0
, vert_attr
);
330 emit_constant_coef4(builder
, args
, slot
+1, args
->v2
, vert_attr
);
334 case LP_INTERP_LINEAR
:
335 emit_linear_coef(builder
, args
, slot
+1, vert_attr
);
338 case LP_INTERP_PERSPECTIVE
:
339 emit_perspective_coef(builder
, args
, slot
+1, vert_attr
);
342 case LP_INTERP_POSITION
:
344 * The generated pixel interpolators will pick up the coeffs from
349 case LP_INTERP_FACING
:
350 emit_facing_coef(builder
, args
, slot
+1);
360 /* XXX: This is generic code, share with fs/vs codegen:
362 static lp_jit_setup_triangle
363 finalize_function(struct llvmpipe_screen
*screen
,
364 LLVMBuilderRef builder
,
365 LLVMValueRef function
)
369 /* Verify the LLVM IR. If invalid, dump and abort */
371 if (LLVMVerifyFunction(function
, LLVMPrintMessageAction
)) {
373 lp_debug_dump_value(function
);
378 /* Apply optimizations to LLVM IR */
379 LLVMRunFunctionPassManager(screen
->pass
, function
);
381 if (gallivm_debug
& GALLIVM_DEBUG_IR
)
383 /* Print the LLVM IR to stderr */
384 lp_debug_dump_value(function
);
389 * Translate the LLVM IR into machine code.
391 f
= LLVMGetPointerToGlobal(screen
->engine
, function
);
393 if (gallivm_debug
& GALLIVM_DEBUG_ASM
)
398 lp_func_delete_body(function
);
403 /* XXX: Generic code:
406 lp_emit_emms(LLVMBuilderRef builder
)
409 /* Avoid corrupting the FPU stack on 32bit OSes. */
410 lp_build_intrinsic(builder
, "llvm.x86.mmx.emms", LLVMVoidType(), NULL
, 0);
415 /* XXX: generic code:
418 set_noalias(LLVMBuilderRef builder
,
419 LLVMValueRef function
,
420 const LLVMTypeRef
*arg_types
,
424 for(i
= 0; i
< Elements(arg_types
); ++i
)
425 if(LLVMGetTypeKind(arg_types
[i
]) == LLVMPointerTypeKind
)
426 LLVMAddAttribute(LLVMGetParam(function
, i
),
427 LLVMNoAliasAttribute
);
431 init_args(LLVMBuilderRef b
,
432 struct lp_setup_args
*args
,
433 const struct lp_setup_variant
*variant
)
435 LLVMValueRef v0_x
= vert_attrib(b
, args
->v0
, 0, 0, "v0_x");
436 LLVMValueRef v0_y
= vert_attrib(b
, args
->v0
, 0, 1, "v0_y");
438 LLVMValueRef v1_x
= vert_attrib(b
, args
->v1
, 0, 0, "v1_x");
439 LLVMValueRef v1_y
= vert_attrib(b
, args
->v1
, 0, 1, "v1_y");
441 LLVMValueRef v2_x
= vert_attrib(b
, args
->v2
, 0, 0, "v2_x");
442 LLVMValueRef v2_y
= vert_attrib(b
, args
->v2
, 0, 1, "v2_y");
444 LLVMValueRef pixel_center
= LLVMConstReal(LLVMFloatType(),
445 variant
->key
.pixel_center_half
? 0.5 : 0);
447 LLVMValueRef x0_center
= LLVMBuildFSub(b
, v0_x
, pixel_center
, "x0_center" );
448 LLVMValueRef y0_center
= LLVMBuildFSub(b
, v0_y
, pixel_center
, "y0_center" );
450 LLVMValueRef dx01
= LLVMBuildFSub(b
, v0_x
, v1_x
, "dx01");
451 LLVMValueRef dy01
= LLVMBuildFSub(b
, v0_y
, v1_y
, "dy01");
452 LLVMValueRef dx20
= LLVMBuildFSub(b
, v2_x
, v0_x
, "dx20");
453 LLVMValueRef dy20
= LLVMBuildFSub(b
, v2_y
, v0_y
, "dy20");
455 LLVMValueRef one
= LLVMConstReal(LLVMFloatType(), 1.0);
456 LLVMValueRef e
= LLVMBuildFMul(b
, dx01
, dy20
, "e");
457 LLVMValueRef f
= LLVMBuildFMul(b
, dx20
, dy01
, "f");
458 LLVMValueRef ooa
= LLVMBuildFDiv(b
, one
, LLVMBuildFSub(b
, e
, f
, ""), "ooa");
460 LLVMValueRef dy20_ooa
= LLVMBuildFMul(b
, dy20
, ooa
, "dy20_ooa");
461 LLVMValueRef dy01_ooa
= LLVMBuildFMul(b
, dy01
, ooa
, "dy01_ooa");
462 LLVMValueRef dx20_ooa
= LLVMBuildFMul(b
, dx20
, ooa
, "dx20_ooa");
463 LLVMValueRef dx01_ooa
= LLVMBuildFMul(b
, dx01
, ooa
, "dx01_ooa");
465 args
->dy20_ooa
= vec4f_from_scalar(b
, dy20_ooa
, "dy20_ooa_4f");
466 args
->dy01_ooa
= vec4f_from_scalar(b
, dy01_ooa
, "dy01_ooa_4f");
468 args
->dx20_ooa
= vec4f_from_scalar(b
, dx20_ooa
, "dx20_ooa_4f");
469 args
->dx01_ooa
= vec4f_from_scalar(b
, dx01_ooa
, "dx01_ooa_4f");
471 args
->x0_center
= vec4f_from_scalar(b
, x0_center
, "x0_center_4f");
472 args
->y0_center
= vec4f_from_scalar(b
, y0_center
, "y0_center_4f");
476 * Generate the runtime callable function for the coefficient calculation.
479 static struct lp_setup_variant
*
480 generate_setup_variant(struct llvmpipe_screen
*screen
,
481 struct lp_setup_variant_key
*key
)
483 struct lp_setup_variant
*variant
= NULL
;
484 struct lp_setup_args args
;
486 LLVMTypeRef vec4f_type
;
487 LLVMTypeRef func_type
;
488 LLVMTypeRef arg_types
[7];
489 LLVMBasicBlockRef block
;
490 LLVMBuilderRef builder
;
496 variant
= CALLOC_STRUCT(lp_setup_variant
);
500 if (LP_DEBUG
& DEBUG_COUNTERS
) {
504 memcpy(&variant
->key
, key
, key
->size
);
505 variant
->list_item_global
.base
= variant
;
507 util_snprintf(func_name
, sizeof(func_name
), "fs%u_setup%u",
511 /* Currently always deal with full 4-wide vertex attributes from
515 vec4f_type
= LLVMVectorType(LLVMFloatType(), 4);
517 arg_types
[0] = LLVMPointerType(vec4f_type
, 0); /* v0 */
518 arg_types
[1] = LLVMPointerType(vec4f_type
, 0); /* v1 */
519 arg_types
[2] = LLVMPointerType(vec4f_type
, 0); /* v2 */
520 arg_types
[3] = LLVMInt32Type(); /* facing */
521 arg_types
[4] = LLVMPointerType(vec4f_type
, 0); /* a0, aligned */
522 arg_types
[5] = LLVMPointerType(vec4f_type
, 0); /* dadx, aligned */
523 arg_types
[6] = LLVMPointerType(vec4f_type
, 0); /* dady, aligned */
525 func_type
= LLVMFunctionType(LLVMVoidType(), arg_types
, Elements(arg_types
), 0);
527 variant
->function
= LLVMAddFunction(screen
->module
, func_name
, func_type
);
528 if (!variant
->function
)
531 LLVMSetFunctionCallConv(variant
->function
, LLVMCCallConv
);
533 args
.v0
= LLVMGetParam(variant
->function
, 0);
534 args
.v1
= LLVMGetParam(variant
->function
, 1);
535 args
.v2
= LLVMGetParam(variant
->function
, 2);
536 args
.facing
= LLVMGetParam(variant
->function
, 3);
537 args
.a0
= LLVMGetParam(variant
->function
, 4);
538 args
.dadx
= LLVMGetParam(variant
->function
, 5);
539 args
.dady
= LLVMGetParam(variant
->function
, 6);
541 lp_build_name(args
.v0
, "in_v0");
542 lp_build_name(args
.v1
, "in_v1");
543 lp_build_name(args
.v2
, "in_v2");
544 lp_build_name(args
.facing
, "in_facing");
545 lp_build_name(args
.a0
, "out_a0");
546 lp_build_name(args
.dadx
, "out_dadx");
547 lp_build_name(args
.dady
, "out_dady");
552 block
= LLVMAppendBasicBlock(variant
->function
, "entry");
553 builder
= LLVMCreateBuilder();
554 LLVMPositionBuilderAtEnd(builder
, block
);
556 set_noalias(builder
, variant
->function
, arg_types
, Elements(arg_types
));
557 init_args(builder
, &args
, variant
);
558 emit_tri_coef(builder
, &variant
->key
, &args
);
560 lp_emit_emms(builder
);
561 LLVMBuildRetVoid(builder
);
562 LLVMDisposeBuilder(builder
);
564 variant
->jit_function
= finalize_function(screen
, builder
,
566 if (!variant
->jit_function
)
570 * Update timing information:
572 if (LP_DEBUG
& DEBUG_COUNTERS
) {
574 LP_COUNT_ADD(llvm_compile_time
, t1
- t0
);
575 LP_COUNT_ADD(nr_llvm_compiles
, 1);
582 if (variant
->function
) {
583 if (variant
->jit_function
)
584 LLVMFreeMachineCodeForFunction(screen
->engine
,
586 LLVMDeleteFunction(variant
->function
);
597 lp_make_setup_variant_key(struct llvmpipe_context
*lp
,
598 struct lp_setup_variant_key
*key
)
600 struct lp_fragment_shader
*fs
= lp
->fs
;
603 assert(sizeof key
->inputs
[0] == sizeof(ushort
));
605 key
->num_inputs
= fs
->info
.base
.num_inputs
;
606 key
->flatshade_first
= lp
->rasterizer
->flatshade_first
;
607 key
->pixel_center_half
= lp
->rasterizer
->gl_rasterization_rules
;
608 key
->size
= Offset(struct lp_setup_variant_key
,
609 inputs
[key
->num_inputs
]);
612 memcpy(key
->inputs
, fs
->inputs
, key
->num_inputs
* sizeof key
->inputs
[0]);
613 for (i
= 0; i
< key
->num_inputs
; i
++) {
614 if (key
->inputs
[i
].interp
== LP_INTERP_COLOR
) {
615 if (lp
->rasterizer
->flatshade
)
616 key
->inputs
[i
].interp
= LP_INTERP_CONSTANT
;
618 key
->inputs
[i
].interp
= LP_INTERP_LINEAR
;
626 remove_setup_variant(struct llvmpipe_context
*lp
,
627 struct lp_setup_variant
*variant
)
629 struct llvmpipe_screen
*screen
= llvmpipe_screen(lp
->pipe
.screen
);
631 if (gallivm_debug
& GALLIVM_DEBUG_IR
) {
632 debug_printf("llvmpipe: del setup_variant #%u total %u\n",
633 variant
->no
, lp
->nr_setup_variants
);
636 if (variant
->function
) {
637 if (variant
->jit_function
)
638 LLVMFreeMachineCodeForFunction(screen
->engine
,
640 LLVMDeleteFunction(variant
->function
);
643 remove_from_list(&variant
->list_item_global
);
644 lp
->nr_setup_variants
--;
650 /* When the number of setup variants exceeds a threshold, cull a
651 * fraction (currently a quarter) of them.
654 cull_setup_variants(struct llvmpipe_context
*lp
)
656 struct pipe_context
*pipe
= &lp
->pipe
;
660 * XXX: we need to flush the context until we have some sort of reference
661 * counting in fragment shaders as they may still be binned
662 * Flushing alone might not be sufficient we need to wait on it too.
664 llvmpipe_finish(pipe
, __FUNCTION__
);
666 for (i
= 0; i
< LP_MAX_SETUP_VARIANTS
/ 4; i
++) {
667 struct lp_setup_variant_list_item
*item
= last_elem(&lp
->setup_variants_list
);
668 remove_setup_variant(lp
, item
->base
);
674 * Update fragment/vertex shader linkage state. This is called just
675 * prior to drawing something when some fragment-related state has
679 llvmpipe_update_setup(struct llvmpipe_context
*lp
)
681 struct llvmpipe_screen
*screen
= llvmpipe_screen(lp
->pipe
.screen
);
683 struct lp_setup_variant_key
*key
= &lp
->setup_variant
.key
;
684 struct lp_setup_variant
*variant
= NULL
;
685 struct lp_setup_variant_list_item
*li
;
687 lp_make_setup_variant_key(lp
, key
);
689 foreach(li
, &lp
->setup_variants_list
) {
690 if(li
->base
->key
.size
== key
->size
&&
691 memcmp(&li
->base
->key
, key
, key
->size
) == 0) {
698 move_to_head(&lp
->setup_variants_list
, &variant
->list_item_global
);
701 if (lp
->nr_setup_variants
>= LP_MAX_SETUP_VARIANTS
) {
702 cull_setup_variants(lp
);
705 variant
= generate_setup_variant(screen
, key
);
706 insert_at_head(&lp
->setup_variants_list
, &variant
->list_item_global
);
707 lp
->nr_setup_variants
++;
710 lp_setup_set_setup_variant(lp
->setup
,
715 lp_delete_setup_variants(struct llvmpipe_context
*lp
)
717 struct lp_setup_variant_list_item
*li
;
718 li
= first_elem(&lp
->setup_variants_list
);
719 while(!at_end(&lp
->setup_variants_list
, li
)) {
720 struct lp_setup_variant_list_item
*next
= next_elem(li
);
721 remove_setup_variant(lp
, li
->base
);
727 lp_dump_setup_coef( const struct lp_setup_variant_key
*key
,
728 const float (*sa0
)[4],
729 const float (*sdadx
)[4],
730 const float (*sdady
)[4])
734 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
735 float a0
= sa0
[0][i
];
736 float dadx
= sdadx
[0][i
];
737 float dady
= sdady
[0][i
];
739 debug_printf("POS.%c: a0 = %f, dadx = %f, dady = %f\n",
744 for (slot
= 0; slot
< key
->num_inputs
; slot
++) {
745 unsigned usage_mask
= key
->inputs
[slot
].usage_mask
;
746 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
747 if (usage_mask
& (1 << i
)) {
748 float a0
= sa0
[1 + slot
][i
];
749 float dadx
= sdadx
[1 + slot
][i
];
750 float dady
= sdady
[1 + slot
][i
];
752 debug_printf("IN[%u].%c: a0 = %f, dadx = %f, dady = %f\n",