diff options
author | Olivier Galibert <[email protected]> | 2012-06-19 20:51:21 +0200 |
---|---|---|
committer | Brian Paul <[email protected]> | 2012-06-19 14:40:44 -0600 |
commit | c790c2c7598dea2d5a5b0bfbe47732956e1e89a6 (patch) | |
tree | 76c69bbe525b74b870551c0863c10787583973de /src/gallium/auxiliary | |
parent | 46931ecf480e1d231bb6c2236d91b5390f2465ac (diff) |
llvmpipe: Add vertex id support.
Signed-off-by: Olivier Galibert <[email protected]>
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/draw/draw_llvm.c | 32 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 13 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 11 |
3 files changed, 38 insertions, 18 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 8e787c580db..e08221eb392 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -459,7 +459,7 @@ generate_vs(struct draw_llvm *llvm, LLVMBuilderRef builder, LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS], const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS], - LLVMValueRef instance_id, + const struct lp_bld_tgsi_system_values *system_values, LLVMValueRef context_ptr, struct lp_build_sampler_soa *draw_sampler, boolean clamp_vertex_color) @@ -491,7 +491,7 @@ generate_vs(struct draw_llvm *llvm, vs_type, NULL /*struct lp_build_mask_context *mask*/, consts_ptr, - instance_id, + system_values, NULL /*pos*/, inputs, outputs, @@ -1248,7 +1248,6 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, LLVMValueRef count, fetch_elts, fetch_count; LLVMValueRef stride, step, io_itr; LLVMValueRef io_ptr, vbuffers_ptr, vb_ptr; - LLVMValueRef instance_id; LLVMValueRef zero = lp_build_const_int32(gallivm, 0); LLVMValueRef one = lp_build_const_int32(gallivm, 1); struct draw_context *draw = llvm->draw; @@ -1270,6 +1269,9 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, const unsigned pos = draw_current_shader_position_output(llvm->draw); const unsigned cv = draw_current_shader_clipvertex_output(llvm->draw); boolean have_clipdist = FALSE; + struct lp_bld_tgsi_system_values system_values; + + memset(&system_values, 0, sizeof(system_values)); arg_types[0] = get_context_ptr_type(llvm); /* context */ arg_types[1] = get_vertex_header_ptr_type(llvm); /* vertex_header */ @@ -1300,19 +1302,19 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, LLVMAddAttribute(LLVMGetParam(variant_func, i), LLVMNoAliasAttribute); - context_ptr = LLVMGetParam(variant_func, 0); - io_ptr = LLVMGetParam(variant_func, 1); - vbuffers_ptr = LLVMGetParam(variant_func, 2); - stride = LLVMGetParam(variant_func, 5); - vb_ptr = LLVMGetParam(variant_func, 6); - instance_id = LLVMGetParam(variant_func, 7); + context_ptr = LLVMGetParam(variant_func, 0); + io_ptr = LLVMGetParam(variant_func, 1); + vbuffers_ptr = LLVMGetParam(variant_func, 2); + stride = LLVMGetParam(variant_func, 5); + vb_ptr = LLVMGetParam(variant_func, 6); + system_values.instance_id = LLVMGetParam(variant_func, 7); lp_build_name(context_ptr, "context"); lp_build_name(io_ptr, "io"); lp_build_name(vbuffers_ptr, "vbuffers"); lp_build_name(stride, "stride"); lp_build_name(vb_ptr, "vb"); - lp_build_name(instance_id, "instance_id"); + lp_build_name(system_values.instance_id, "instance_id"); if (elts) { fetch_elts = LLVMGetParam(variant_func, 3); @@ -1378,6 +1380,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, lp_build_printf(builder, " --- io %d = %p, loop counter %d\n", io_itr, io, lp_loop.counter); #endif + system_values.vertex_id = lp_build_zero(gallivm, lp_type_uint_vec(32)); for (i = 0; i < TGSI_NUM_CHANNELS; ++i) { LLVMValueRef true_index = LLVMBuildAdd(builder, @@ -1395,7 +1398,10 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, &true_index, 1, ""); true_index = LLVMBuildLoad(builder, fetch_ptr, "fetch_elt"); } - + + system_values.vertex_id = LLVMBuildInsertElement(gallivm->builder, + system_values.vertex_id, true_index, + lp_build_const_int32(gallivm, i), ""); for (j = 0; j < draw->pt.nr_vertex_elements; ++j) { struct pipe_vertex_element *velem = &draw->pt.vertex_element[j]; LLVMValueRef vb_index = @@ -1403,7 +1409,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, LLVMValueRef vb = LLVMBuildGEP(builder, vb_ptr, &vb_index, 1, ""); generate_fetch(gallivm, vbuffers_ptr, &aos_attribs[j][i], velem, vb, true_index, - instance_id); + system_values.instance_id); } } convert_to_soa(gallivm, aos_attribs, inputs, @@ -1414,7 +1420,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant, builder, outputs, ptr_aos, - instance_id, + &system_values, context_ptr, sampler, variant->key.clamp_vertex_color); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index c4e690c43c6..4423bc5dedd 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -146,6 +146,15 @@ struct lp_tgsi_info }; /** + * Reference to system values. + */ +struct lp_bld_tgsi_system_values { + LLVMValueRef instance_id; + LLVMValueRef vertex_id; +}; + + +/** * Sampler code generation interface. * * Although texture sampling is a requirement for TGSI translation, it is @@ -205,7 +214,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, struct lp_type type, struct lp_build_mask_context *mask, LLVMValueRef consts_ptr, - LLVMValueRef instance_id, + const struct lp_bld_tgsi_system_values *system_values, const LLVMValueRef *pos, const LLVMValueRef (*inputs)[4], LLVMValueRef (*outputs)[4], @@ -381,7 +390,7 @@ struct lp_build_tgsi_soa_context */ LLVMValueRef inputs_array; - LLVMValueRef instance_id; + struct lp_bld_tgsi_system_values system_values; /** bitmask indicating which register files are accessed indirectly */ unsigned indirect_files; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index 26be9021fdf..d9faaf20273 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -795,7 +795,12 @@ emit_fetch_system_value( switch (info->system_value_semantic_name[reg->Register.Index]) { case TGSI_SEMANTIC_INSTANCEID: - res = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->instance_id); + res = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.instance_id); + atype = TGSI_TYPE_UNSIGNED; + break; + + case TGSI_SEMANTIC_VERTEXID: + res = bld->system_values.vertex_id; atype = TGSI_TYPE_UNSIGNED; break; @@ -1995,7 +2000,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, struct lp_type type, struct lp_build_mask_context *mask, LLVMValueRef consts_ptr, - LLVMValueRef instance_id, + const struct lp_bld_tgsi_system_values *system_values, const LLVMValueRef *pos, const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS], LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS], @@ -2070,7 +2075,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, lp_exec_mask_init(&bld.exec_mask, &bld.bld_base.base); - bld.instance_id = instance_id; + bld.system_values = *system_values; lp_build_tgsi_llvm(&bld.bld_base, tokens); |