[Mesa-dev] [PATCH 0/2] Add vertex id to llvmpipe.

Olivier Galibert galibert at pobox.com
Sun Jun 10 05:25:33 PDT 2012


On Fri, Jun 08, 2012 at 09:01:42AM -0700, Jose Fonseca wrote:
> Oliver,
> 
> There will be other system values in the future, so instead of passing every value as a different parameter, please define a structure in src/gallium/auxiliary/gallivm/lp_bld_tgsi.h as
> 
> struct lp_bld_tgsi_system_values {
>   LLVMValueRef facing;
>   LLVMValueRef instance_id;
>   LLVMValueRef vertex_id;
>   ...
> }
> 
> which is then passed to lp_build_tgsi_soa and all other functions.
> 
> Otherwise the change looks good overall.

Something like that for the second part?

  OG.

Author: Olivier Galibert <galibert at pobox.com>
Date:   Fri Jun 1 22:58:58 2012 +0200

llvmpipe: Add vertex id support.
    
Signed-off-by: Olivier Galibert <galibert at pobox.com>

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index d5eb727..de495cf 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -456,7 +456,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)
@@ -488,7 +488,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,
@@ -1245,7 +1245,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;
@@ -1267,6 +1266,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 */
@@ -1297,19 +1299,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);
@@ -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
+      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,
@@ -1392,7 +1395,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 =
@@ -1400,7 +1406,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,
@@ -1411,7 +1417,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 c4e690c..4423bc5 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 26be902..d9faaf2 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);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 3b69dad..7e52eb0 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -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);
 


More information about the mesa-dev mailing list