X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fllvmpipe%2Flp_state_setup.c;h=77c7ac1bbde585e2a4717f2998c5088dbb814b0e;hb=ee2e1e85d4df83efeae0c2f47a1eb44da2a088a1;hp=1d79a4ab5282d4028b757d196dd0487adfca2b51;hpb=7c027666da1cd3691983bbc238847a2af57f336e;p=mesa.git diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c index 1d79a4ab528..77c7ac1bbde 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c @@ -28,8 +28,8 @@ #include "util/u_math.h" #include "util/u_memory.h" -#include "util/u_simple_list.h" -#include "os/os_time.h" +#include "util/simple_list.h" +#include "util/os_time.h" #include "gallivm/lp_bld_arit.h" #include "gallivm/lp_bld_bitarit.h" #include "gallivm/lp_bld_const.h" @@ -50,6 +50,10 @@ #include "lp_state_setup.h" +/** Setup shader number (for debugging) */ +static unsigned setup_no = 0; + + /* currently organized to interpolate full float[4] attributes even * when some elements are unused. Later, can pack vertex data more * closely. @@ -82,26 +86,26 @@ struct lp_setup_args static void store_coef(struct gallivm_state *gallivm, - struct lp_setup_args *args, - unsigned slot, - LLVMValueRef a0, - LLVMValueRef dadx, - LLVMValueRef dady) + struct lp_setup_args *args, + unsigned slot, + LLVMValueRef a0, + LLVMValueRef dadx, + LLVMValueRef dady) { LLVMBuilderRef builder = gallivm->builder; LLVMValueRef idx = lp_build_const_int32(gallivm, slot); LLVMBuildStore(builder, - a0, - LLVMBuildGEP(builder, args->a0, &idx, 1, "")); + a0, + LLVMBuildGEP(builder, args->a0, &idx, 1, "")); LLVMBuildStore(builder, - dadx, - LLVMBuildGEP(builder, args->dadx, &idx, 1, "")); + dadx, + LLVMBuildGEP(builder, args->dadx, &idx, 1, "")); LLVMBuildStore(builder, - dady, - LLVMBuildGEP(builder, args->dady, &idx, 1, "")); + dady, + LLVMBuildGEP(builder, args->dady, &idx, 1, "")); } @@ -131,8 +135,8 @@ emit_facing_coef(struct gallivm_state *gallivm, LLVMValueRef a0_0 = args->facing; LLVMValueRef a0_0f = LLVMBuildSIToFP(builder, a0_0, float_type, ""); LLVMValueRef a0, face_val; - const unsigned char swizzles[4] = { PIPE_SWIZZLE_RED, PIPE_SWIZZLE_ZERO, - PIPE_SWIZZLE_ZERO, PIPE_SWIZZLE_ZERO }; + const unsigned char swizzles[4] = { PIPE_SWIZZLE_X, PIPE_SWIZZLE_0, + PIPE_SWIZZLE_0, PIPE_SWIZZLE_0 }; /* Our face val is either 1 or 0 so we do * face = (val * 2) - 1 * to make it 1 or -1 @@ -620,8 +624,7 @@ set_noalias(LLVMBuilderRef builder, int i; for(i = 0; i < nr_args; ++i) if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) - LLVMAddAttribute(LLVMGetParam(function, i), - LLVMNoAliasAttribute); + lp_add_function_attr(function, i + 1, LP_FUNC_ATTR_NOALIAS); } static void @@ -707,7 +710,7 @@ generate_setup_variant(struct lp_setup_variant_key *key, struct lp_setup_variant *variant = NULL; struct gallivm_state *gallivm; struct lp_setup_args args; - char func_name[256]; + char func_name[64]; LLVMTypeRef vec4f_type; LLVMTypeRef func_type; LLVMTypeRef arg_types[7]; @@ -719,10 +722,15 @@ generate_setup_variant(struct lp_setup_variant_key *key, goto fail; variant = CALLOC_STRUCT(lp_setup_variant); - if (variant == NULL) + if (!variant) goto fail; - variant->gallivm = gallivm = gallivm_create(); + variant->no = setup_no++; + + util_snprintf(func_name, sizeof(func_name), "setup_variant_%u", + variant->no); + + variant->gallivm = gallivm = gallivm_create(func_name, lp->context); if (!variant->gallivm) { goto fail; } @@ -736,9 +744,6 @@ generate_setup_variant(struct lp_setup_variant_key *key, memcpy(&variant->key, key, key->size); variant->list_item_global.base = variant; - util_snprintf(func_name, sizeof(func_name), "fs%u_setup%u", - 0, variant->no); - /* Currently always deal with full 4-wide vertex attributes from * the vertices. */ @@ -754,7 +759,7 @@ generate_setup_variant(struct lp_setup_variant_key *key, arg_types[6] = LLVMPointerType(vec4f_type, 0); /* dady, aligned */ func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), - arg_types, Elements(arg_types), 0); + arg_types, ARRAY_SIZE(arg_types), 0); variant->function = LLVMAddFunction(gallivm->module, func_name, func_type); if (!variant->function) @@ -785,7 +790,7 @@ generate_setup_variant(struct lp_setup_variant_key *key, variant->function, "entry"); LLVMPositionBuilderAtEnd(builder, block); - set_noalias(builder, variant->function, arg_types, Elements(arg_types)); + set_noalias(builder, variant->function, arg_types, ARRAY_SIZE(arg_types)); init_args(gallivm, &variant->key, &args); emit_tri_coef(gallivm, &variant->key, &args); @@ -800,6 +805,8 @@ generate_setup_variant(struct lp_setup_variant_key *key, if (!variant->jit_function) goto fail; + gallivm_free_ir(variant->gallivm); + /* * Update timing information: */ @@ -808,22 +815,17 @@ generate_setup_variant(struct lp_setup_variant_key *key, LP_COUNT_ADD(llvm_compile_time, t1 - t0); LP_COUNT_ADD(nr_llvm_compiles, 1); } - + return variant; fail: if (variant) { - if (variant->function) { - gallivm_free_function(gallivm, - variant->function, - variant->jit_function); - } if (variant->gallivm) { gallivm_destroy(variant->gallivm); } FREE(variant); } - + return NULL; } @@ -831,13 +833,13 @@ fail: static void lp_make_setup_variant_key(struct llvmpipe_context *lp, - struct lp_setup_variant_key *key) + struct lp_setup_variant_key *key) { struct lp_fragment_shader *fs = lp->fs; unsigned i; assert(sizeof key->inputs[0] == sizeof(uint)); - + key->num_inputs = fs->info.base.num_inputs; key->flatshade_first = lp->rasterizer->flatshade_first; key->pixel_center_half = lp->rasterizer->half_pixel_center; @@ -845,14 +847,10 @@ lp_make_setup_variant_key(struct llvmpipe_context *lp, key->size = Offset(struct lp_setup_variant_key, inputs[key->num_inputs]); - key->color_slot = lp->color_slot [0]; + key->color_slot = lp->color_slot[0]; key->bcolor_slot = lp->bcolor_slot[0]; - key->spec_slot = lp->color_slot [1]; - key->bspec_slot = lp->bcolor_slot[1]; - assert(key->color_slot == lp->color_slot [0]); - assert(key->bcolor_slot == lp->bcolor_slot[0]); - assert(key->spec_slot == lp->color_slot [1]); - assert(key->bspec_slot == lp->bcolor_slot[1]); + key->spec_slot = lp->color_slot[1]; + key->bspec_slot = lp->bcolor_slot[1]; /* * If depth is floating point, depth bias is calculated with respect @@ -875,9 +873,9 @@ lp_make_setup_variant_key(struct llvmpipe_context *lp, for (i = 0; i < key->num_inputs; i++) { if (key->inputs[i].interp == LP_INTERP_COLOR) { if (lp->rasterizer->flatshade) - key->inputs[i].interp = LP_INTERP_CONSTANT; - else - key->inputs[i].interp = LP_INTERP_PERSPECTIVE; + key->inputs[i].interp = LP_INTERP_CONSTANT; + else + key->inputs[i].interp = LP_INTERP_PERSPECTIVE; } } @@ -886,17 +884,11 @@ lp_make_setup_variant_key(struct llvmpipe_context *lp, static void remove_setup_variant(struct llvmpipe_context *lp, - struct lp_setup_variant *variant) + struct lp_setup_variant *variant) { if (gallivm_debug & GALLIVM_DEBUG_IR) { debug_printf("llvmpipe: del setup_variant #%u total %u\n", - variant->no, lp->nr_setup_variants); - } - - if (variant->function) { - gallivm_free_function(variant->gallivm, - variant->function, - variant->jit_function); + variant->no, lp->nr_setup_variants); } if (variant->gallivm) { @@ -955,7 +947,7 @@ llvmpipe_update_setup(struct llvmpipe_context *lp) foreach(li, &lp->setup_variants_list) { if(li->base->key.size == key->size && - memcmp(&li->base->key, key, key->size) == 0) { + memcmp(&li->base->key, key, key->size) == 0) { variant = li->base; break; } @@ -966,19 +958,17 @@ llvmpipe_update_setup(struct llvmpipe_context *lp) } else { if (lp->nr_setup_variants >= LP_MAX_SETUP_VARIANTS) { - cull_setup_variants(lp); + cull_setup_variants(lp); } variant = generate_setup_variant(key, lp); if (variant) { insert_at_head(&lp->setup_variants_list, &variant->list_item_global); lp->nr_setup_variants++; - llvmpipe_variant_count++; } } - lp_setup_set_setup_variant(lp->setup, - variant); + lp_setup_set_setup_variant(lp->setup, variant); } void @@ -994,10 +984,10 @@ lp_delete_setup_variants(struct llvmpipe_context *lp) } void -lp_dump_setup_coef( const struct lp_setup_variant_key *key, - const float (*sa0)[4], - const float (*sdadx)[4], - const float (*sdady)[4]) +lp_dump_setup_coef(const struct lp_setup_variant_key *key, + const float (*sa0)[4], + const float (*sdadx)[4], + const float (*sdady)[4]) { int i, slot; @@ -1007,23 +997,20 @@ lp_dump_setup_coef( const struct lp_setup_variant_key *key, float dady = sdady[0][i]; debug_printf("POS.%c: a0 = %f, dadx = %f, dady = %f\n", - "xyzw"[i], - a0, dadx, dady); + "xyzw"[i], a0, dadx, dady); } for (slot = 0; slot < key->num_inputs; slot++) { unsigned usage_mask = key->inputs[slot].usage_mask; for (i = 0; i < TGSI_NUM_CHANNELS; i++) { - if (usage_mask & (1 << i)) { - float a0 = sa0 [1 + slot][i]; - float dadx = sdadx[1 + slot][i]; - float dady = sdady[1 + slot][i]; - - debug_printf("IN[%u].%c: a0 = %f, dadx = %f, dady = %f\n", - slot, - "xyzw"[i], - a0, dadx, dady); - } + if (usage_mask & (1 << i)) { + float a0 = sa0 [1 + slot][i]; + float dadx = sdadx[1 + slot][i]; + float dady = sdady[1 + slot][i]; + + debug_printf("IN[%u].%c: a0 = %f, dadx = %f, dady = %f\n", + slot, "xyzw"[i], a0, dadx, dady); + } } } }