Merge branch 'draw-instanced'
authorBrian Paul <brianp@vmware.com>
Sat, 15 Jan 2011 17:24:08 +0000 (10:24 -0700)
committerBrian Paul <brianp@vmware.com>
Sat, 15 Jan 2011 17:24:08 +0000 (10:24 -0700)
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

23 files changed:
1  2 
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_vs_exec.c
src/gallium/auxiliary/draw/draw_vs_sse.c
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
src/gallium/docs/source/screen.rst
src/gallium/drivers/llvmpipe/lp_screen.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/softpipe/sp_screen.c
src/gallium/include/pipe/p_defines.h
src/glsl/glsl_parser_extras.cpp
src/glsl/glsl_parser_extras.h
src/glsl/ir.h
src/glsl/ir_set_program_inouts.cpp
src/glsl/ir_variable.cpp
src/glsl/main.cpp
src/mesa/main/extensions.c
src/mesa/main/mtypes.h
src/mesa/program/ir_to_mesa.cpp
src/mesa/program/prog_execute.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_mesa_to_tgsi.c
src/mesa/tnl/t_vb_program.c

index 943ec44bcde47296b725b546d4673bcbca6849a9,eb162fb0f6263458063678f994d36d22b762d074..41269ee869d52c5fb3344e126af59616414f5992
@@@ -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(
        }
  
        /* 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(
         * 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);
  
index 40186befb9fda3e5687ede835152e7862844ef22,694818ccfb8350d7c3af96cebfcec64968f32a15..9713d100484c11d99d74ab7b46d567e272127a8e
@@@ -199,4 -199,11 +200,11 @@@ lp_build_tgsi_aos(struct gallivm_state 
                    const struct tgsi_shader_info *info);
  
  
 -lp_build_system_values_array(LLVMBuilderRef builder,
+ LLVMValueRef
++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 */
index 1b5a8a5903b7d7a11df900bcd59bbec39ca7a9ae,3fdfac95a0a195dd66f0d92b66135c1ebf82f52c..d1585c8e2b7598a667140eedc82504f2a53d3f45
@@@ -759,6 -734,22 +761,23 @@@ emit_fetch
        }
        break;
  
 -         index = lp_build_const_int32(reg->Register.Index * 4 + swizzle);
+    case TGSI_FILE_SYSTEM_VALUE:
+       assert(!reg->Register.Indirect);
+       {
+          LLVMValueRef index;  /* index into the system value array */
+          LLVMValueRef scalar, scalar_ptr;
 -         scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->system_values_array,
++         index = lp_build_const_int32(gallivm,
++                                      reg->Register.Index * 4 + swizzle);
 -         scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
++         scalar_ptr = LLVMBuildGEP(builder, bld->system_values_array,
+                                    &index, 1, "");
++         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 );
  }
  
 -lp_build_system_values_array(LLVMBuilderRef builder,
+ /**
+  * 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
 -   LLVMValueRef size = lp_build_const_int32(4 * info->num_system_values);
 -   LLVMValueRef array = lp_build_array_alloca(builder, LLVMFloatType(),
++lp_build_system_values_array(struct gallivm_state *gallivm,
+                              const struct tgsi_shader_info *info,
+                              LLVMValueRef instance_id,
+                              LLVMValueRef facing)
+ {
 -      LLVMValueRef index = lp_build_const_int32(i * 4);
++   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++) {
 -         value = LLVMBuildSIToFP(builder, instance_id, LLVMFloatType(),
++      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 */
 -      ptr = LLVMBuildGEP(builder, array, &index, 1, "");
 -      LLVMBuildStore(builder, value, ptr);
++         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(gallivm->builder, array, &index, 1, "");
++      LLVMBuildStore(gallivm->builder, value, ptr);
+    }
+       
+    return array;
+ }
Simple merge
index ae207617cc173e07d83108a5f8686945a9d0ca69,cd67d4886163ca74211d9b8568745954206cfbe6..1b9119eda0020f00579f1cf6939040c1fdcd6fca
@@@ -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,
Simple merge
Simple merge
Simple merge
diff --cc src/glsl/ir.h
Simple merge
index 714281539ac1c654ed22815e644ec6153f8a3cfb,31a122c6bb950984017a2c47ae14744bbe6fa3f0..085456533c5970a9b4c52e96ee63383e973b0c75
@@@ -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);
     }
  }
  
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 94372bbafbc26a70edd059d83b2fa84ca8aca26e,a1853689a437a568b1a3bbf554d2e46c14787ba8..f5d8f7477aaec5e0c137cef961cd22bc51bdc229
@@@ -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,