[Mesa-dev] [PATCH 2/2] llvmpipe: Add vertex id support.
Olivier Galibert
galibert at pobox.com
Fri Jun 1 14:28:06 PDT 2012
Signed-off-by: Olivier Galibert <galibert at pobox.com>
---
src/gallium/auxiliary/draw/draw_llvm.c | 10 ++++++++--
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 3 ++-
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 7 +++++++
src/gallium/drivers/llvmpipe/lp_state_fs.c | 2 +-
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index d5eb727..71125ba 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -457,6 +457,7 @@ generate_vs(struct draw_llvm *llvm,
LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS],
const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS],
LLVMValueRef instance_id,
+ LLVMValueRef vertex_id,
LLVMValueRef context_ptr,
struct lp_build_sampler_soa *draw_sampler,
boolean clamp_vertex_color)
@@ -489,6 +490,7 @@ generate_vs(struct draw_llvm *llvm,
NULL /*struct lp_build_mask_context *mask*/,
consts_ptr,
instance_id,
+ vertex_id,
NULL /*pos*/,
inputs,
outputs,
@@ -1245,7 +1247,7 @@ 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 instance_id, vertex_id;
LLVMValueRef zero = lp_build_const_int32(gallivm, 0);
LLVMValueRef one = lp_build_const_int32(gallivm, 1);
struct draw_context *draw = llvm->draw;
@@ -1375,6 +1377,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
+ vertex_id = lp_build_zero(gallivm, lp_type_uint_vec(32));
for (i = 0; i < TGSI_NUM_CHANNELS; ++i) {
LLVMValueRef true_index =
LLVMBuildAdd(builder,
@@ -1392,7 +1395,9 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant,
&true_index, 1, "");
true_index = LLVMBuildLoad(builder, fetch_ptr, "fetch_elt");
}
-
+
+ vertex_id = LLVMBuildInsertElement(gallivm->builder, 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 =
@@ -1412,6 +1417,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant,
outputs,
ptr_aos,
instance_id,
+ vertex_id,
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 c4e690c..f87f899 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
@@ -206,6 +206,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
struct lp_build_mask_context *mask,
LLVMValueRef consts_ptr,
LLVMValueRef instance_id,
+ LLVMValueRef vertex_id,
const LLVMValueRef *pos,
const LLVMValueRef (*inputs)[4],
LLVMValueRef (*outputs)[4],
@@ -381,7 +382,7 @@ struct lp_build_tgsi_soa_context
*/
LLVMValueRef inputs_array;
- LLVMValueRef instance_id;
+ LLVMValueRef instance_id, vertex_id;
/** 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 26be902..37599da 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -799,6 +799,11 @@ emit_fetch_system_value(
atype = TGSI_TYPE_UNSIGNED;
break;
+ case TGSI_SEMANTIC_VERTEXID:
+ res = bld->vertex_id;
+ atype = TGSI_TYPE_UNSIGNED;
+ break;
+
default:
assert(!"unexpected semantic in emit_fetch_system_value");
res = bld_base->base.zero;
@@ -1996,6 +2001,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
struct lp_build_mask_context *mask,
LLVMValueRef consts_ptr,
LLVMValueRef instance_id,
+ LLVMValueRef vertex_id,
const LLVMValueRef *pos,
const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS],
LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS],
@@ -2071,6 +2077,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.vertex_id = vertex_id;
lp_build_tgsi_llvm(&bld.bld_base, tokens);
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 3b69dad..05f1cad 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -334,7 +334,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, NULL, NULL, /* instance id, vertex id */
interp->pos, interp->inputs,
outputs, sampler, &shader->info.base);
--
1.7.10.rc3.1.gb306
More information about the mesa-dev
mailing list