From: Brian Paul Date: Sat, 15 Jan 2011 17:24:08 +0000 (-0700) Subject: Merge branch 'draw-instanced' X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=652901e95b4ed406293d0e1fabee857c054119b1;p=mesa.git Merge branch 'draw-instanced' Conflicts: src/gallium/auxiliary/draw/draw_llvm.c src/gallium/drivers/llvmpipe/lp_state_fs.c src/glsl/ir_set_program_inouts.cpp src/mesa/tnl/t_vb_program.c --- 652901e95b4ed406293d0e1fabee857c054119b1 diff --cc src/gallium/auxiliary/draw/draw_llvm.c index 943ec44bcde,eb162fb0f62..41269ee869d --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@@ -1172,20 -1068,22 +1176,23 @@@ draw_llvm_generate(struct draw_llvm *ll * Function body */ - block = LLVMAppendBasicBlock(variant->function, "entry"); - builder = LLVMCreateBuilder(); + block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function, "entry"); + builder = gallivm->builder; + assert(builder); LLVMPositionBuilderAtEnd(builder, block); - lp_build_context_init(&bld, builder, lp_type_int(32)); + lp_build_context_init(&bld, llvm->gallivm, lp_type_int(32)); - system_values_array = lp_build_system_values_array(builder, vs_info, ++ system_values_array = lp_build_system_values_array(gallivm, vs_info, + instance_id, NULL); + end = lp_build_add(&bld, start, count); - step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0); + step = lp_build_const_int32(gallivm, max_vertices); /* function will return non-zero i32 value if any clipped vertices */ - ret_ptr = lp_build_alloca(builder, LLVMInt32Type(), ""); - LLVMBuildStore(builder, LLVMConstInt(LLVMInt32Type(), 0, 0), ret_ptr); + ret_ptr = lp_build_alloca(gallivm, int32_type, ""); + LLVMBuildStore(builder, lp_build_const_int32(gallivm, 0), ret_ptr); /* code generated texture sampling */ sampler = draw_llvm_sampler_soa_create( @@@ -1262,12 -1163,11 +1270,11 @@@ } /* store clipmask in vertex header and positions in data */ - convert_to_aos(builder, io, outputs, clipmask, + convert_to_aos(gallivm, io, outputs, clipmask, - draw->vs.vertex_shader->info.num_outputs, - max_vertices); + vs_info->num_outputs, max_vertices); } - lp_build_loop_end_cond(builder, end, step, LLVMIntUGE, &lp_loop); + lp_build_loop_end_cond(&lp_loop, end, step, LLVMIntUGE); sampler->destroy(sampler); @@@ -1370,13 -1271,17 +1379,17 @@@ draw_llvm_generate_elts(struct draw_llv * Function body */ - block = LLVMAppendBasicBlock(variant->function_elts, "entry"); - builder = LLVMCreateBuilder(); + block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function_elts, "entry"); + builder = gallivm->builder; LLVMPositionBuilderAtEnd(builder, block); - lp_build_context_init(&bld, builder, lp_type_int(32)); + lp_build_context_init(&bld, gallivm, lp_type_int(32)); - system_values_array = lp_build_system_values_array(builder, vs_info, ++ system_values_array = lp_build_system_values_array(gallivm, vs_info, + instance_id, NULL); + + - step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0); + step = lp_build_const_int32(gallivm, max_vertices); /* code generated texture sampling */ sampler = draw_llvm_sampler_soa_create( @@@ -1470,12 -1378,11 +1484,11 @@@ * original positions in clip * and transformed positions in data */ - convert_to_aos(builder, io, outputs, clipmask, + convert_to_aos(gallivm, io, outputs, clipmask, - draw->vs.vertex_shader->info.num_outputs, - max_vertices); + vs_info->num_outputs, max_vertices); } - lp_build_loop_end_cond(builder, fetch_count, step, LLVMIntUGE, &lp_loop); + lp_build_loop_end_cond(&lp_loop, fetch_count, step, LLVMIntUGE); sampler->destroy(sampler); diff --cc src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index 40186befb9f,694818ccfb8..9713d100484 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@@ -199,4 -199,11 +200,11 @@@ lp_build_tgsi_aos(struct gallivm_state const struct tgsi_shader_info *info); + LLVMValueRef -lp_build_system_values_array(LLVMBuilderRef builder, ++lp_build_system_values_array(struct gallivm_state *gallivm, + const struct tgsi_shader_info *info, + LLVMValueRef instance_id, + LLVMValueRef facing); + + #endif /* LP_BLD_TGSI_H */ diff --cc src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index 1b5a8a5903b,3fdfac95a0a..d1585c8e2b7 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@@ -759,6 -734,22 +761,23 @@@ emit_fetch } break; + case TGSI_FILE_SYSTEM_VALUE: + assert(!reg->Register.Indirect); + { + LLVMValueRef index; /* index into the system value array */ + LLVMValueRef scalar, scalar_ptr; + - index = lp_build_const_int32(reg->Register.Index * 4 + swizzle); ++ index = lp_build_const_int32(gallivm, ++ reg->Register.Index * 4 + swizzle); + - scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->system_values_array, ++ scalar_ptr = LLVMBuildGEP(builder, bld->system_values_array, + &index, 1, ""); - scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, ""); ++ scalar = LLVMBuildLoad(builder, scalar_ptr, ""); + + res = lp_build_broadcast_scalar(&bld->base, scalar); + } + break; + default: assert(0 && "invalid src register in emit_fetch()"); return bld->base.undef; @@@ -2512,3 -2497,53 +2534,54 @@@ lp_build_tgsi_soa(struct gallivm_state FREE( bld.instructions ); } + + /** + * Build up the system values array out of individual values such as + * the instance ID, front-face, primitive ID, etc. The shader info is + * used to determine which system values are needed and where to put + * them in the system values array. + * + * XXX only instance ID is implemented at this time. + * + * The system values register file is similar to the constants buffer. + * Example declaration: + * DCL SV[0], INSTANCEID + * Example instruction: + * MOVE foo, SV[0].xxxx; + * + * \return LLVM float array (interpreted as float [][4]) + */ + LLVMValueRef -lp_build_system_values_array(LLVMBuilderRef builder, ++lp_build_system_values_array(struct gallivm_state *gallivm, + const struct tgsi_shader_info *info, + LLVMValueRef instance_id, + LLVMValueRef facing) + { - LLVMValueRef size = lp_build_const_int32(4 * info->num_system_values); - LLVMValueRef array = lp_build_array_alloca(builder, LLVMFloatType(), ++ LLVMValueRef size = lp_build_const_int32(gallivm, 4 * info->num_system_values); ++ LLVMTypeRef float_t = LLVMFloatTypeInContext(gallivm->context); ++ LLVMValueRef array = lp_build_array_alloca(gallivm, float_t, + size, "sysvals_array"); + unsigned i; + + for (i = 0; i < info->num_system_values; i++) { - LLVMValueRef index = lp_build_const_int32(i * 4); ++ LLVMValueRef index = lp_build_const_int32(gallivm, i * 4); + LLVMValueRef ptr, value; + + switch (info->system_value_semantic_name[i]) { + case TGSI_SEMANTIC_INSTANCEID: + /* convert instance ID from int to float */ - value = LLVMBuildSIToFP(builder, instance_id, LLVMFloatType(), ++ value = LLVMBuildSIToFP(gallivm->builder, instance_id, float_t, + "sysval_instanceid"); + break; + case TGSI_SEMANTIC_FACE: + /* fall-through */ + default: + assert(0 && "unexpected semantic in build_system_values_array()"); + } + - ptr = LLVMBuildGEP(builder, array, &index, 1, ""); - LLVMBuildStore(builder, value, ptr); ++ ptr = LLVMBuildGEP(gallivm->builder, array, &index, 1, ""); ++ LLVMBuildStore(gallivm->builder, value, ptr); + } + + return array; + } diff --cc src/gallium/drivers/llvmpipe/lp_state_fs.c index ae207617cc1,cd67d488616..1b9119eda00 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@@ -330,13 -330,15 +330,14 @@@ generate_fs(struct gallivm_state *galli } } - lp_build_interp_soa_update_inputs(interp, i); + lp_build_interp_soa_update_inputs(interp, gallivm, i); /* Build the actual shader */ - lp_build_tgsi_soa(builder, tokens, type, &mask, + lp_build_tgsi_soa(gallivm, tokens, type, &mask, - consts_ptr, interp->pos, interp->inputs, + consts_ptr, NULL, /* sys values array */ + interp->pos, interp->inputs, outputs, sampler, &shader->info.base); - /* Alpha test */ if (key->alpha.enabled) { int color0 = find_output_by_semantic(&shader->info.base, diff --cc src/glsl/ir_set_program_inouts.cpp index 714281539ac,31a122c6bb9..085456533c5 --- a/src/glsl/ir_set_program_inouts.cpp +++ b/src/glsl/ir_set_program_inouts.cpp @@@ -75,12 -75,28 +75,14 @@@ mark(struct gl_program *prog, ir_variab * something doing a more clever packing would use something other * than InputsRead/OutputsWritten. */ - const glsl_type *element_type; - int element_size; - - if (var->type->is_array()) - element_type = var->type->fields.array; - else - element_type = var->type; - - if (element_type->is_matrix()) - element_size = element_type->matrix_columns; - else - element_size = 1; - - index *= element_size; - for (int i = 0; i < element_size; i++) { - if (var->mode == ir_var_system_value) { - prog->SystemValuesRead |= (1 << (var->location + index + i)); - } - else if (var->mode == ir_var_in) - prog->InputsRead |= BITFIELD64_BIT(var->location + index + i); + + for (int i = 0; i < len; i++) { + if (var->mode == ir_var_in) + prog->InputsRead |= BITFIELD64_BIT(var->location + offset + i); ++ else if (var->mode == ir_var_system_value) ++ prog->SystemValuesRead |= (1 << (var->location + offset + i)); else - prog->OutputsWritten |= BITFIELD64_BIT(var->location + index + i); + prog->OutputsWritten |= BITFIELD64_BIT(var->location + offset + i); } } diff --cc src/mesa/tnl/t_vb_program.c index 94372bbafbc,a1853689a43..f5d8f7477aa --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@@ -341,7 -342,7 +344,7 @@@ run_vp( struct gl_context *ctx, struct for (i = 0; i < VB->Count; i++) { GLuint attr; - init_machine(ctx, machine); - init_machine(ctx, &machine, tnl->CurInstance); ++ init_machine(ctx, machine, tnl->CurInstance); #if 0 printf("Input %d: %f, %f, %f, %f\n", i,