llvmpipe: Add vertex id support.

Signed-off-by: Olivier Galibert <galibert@pobox.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Olivier Galibert 2012-06-19 20:51:21 +02:00 committed by Brian Paul
parent 46931ecf48
commit c790c2c759
4 changed files with 42 additions and 19 deletions

View File

@ -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);

View File

@ -145,6 +145,15 @@ struct lp_tgsi_info
const struct lp_tgsi_channel_info *cbuf[PIPE_MAX_COLOR_BUFS];
};
/**
* Reference to system values.
*/
struct lp_bld_tgsi_system_values {
LLVMValueRef instance_id;
LLVMValueRef vertex_id;
};
/**
* Sampler code generation interface.
*
@ -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;

View File

@ -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);

View File

@ -245,6 +245,9 @@ generate_fs(struct gallivm_state *gallivm,
unsigned chan;
unsigned cbuf;
unsigned depth_mode;
struct lp_bld_tgsi_system_values system_values;
memset(&system_values, 0, sizeof(system_values));
if (key->depth.enabled ||
key->stencil[0].enabled ||
@ -334,7 +337,7 @@ generate_fs(struct gallivm_state *gallivm,
/* Build the actual shader */
lp_build_tgsi_soa(gallivm, tokens, type, &mask,
consts_ptr, NULL, /* instance id */
consts_ptr, &system_values,
interp->pos, interp->inputs,
outputs, sampler, &shader->info.base);