gallium: add PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_setup.c
index ec3fdcadf4b277d13d7aa377474a8df69fa7fc6c..ab38357872d3990c0ac6db03137d98683022a19b 100644 (file)
@@ -351,9 +351,9 @@ load_attribute(struct gallivm_state *gallivm,
    }
 
    if (key->twoside) {
-      if (vert_attr == key->color_slot && key->bcolor_slot != ~0)
+      if (vert_attr == key->color_slot && key->bcolor_slot >= 0)
          lp_twoside(gallivm, args, key, key->bcolor_slot);
-      else if (vert_attr == key->spec_slot && key->bspec_slot != ~0)
+      else if (vert_attr == key->spec_slot && key->bspec_slot >= 0)
          lp_twoside(gallivm, args, key, key->bspec_slot);
    }
 }
@@ -556,17 +556,18 @@ finalize_function(struct gallivm_state *gallivm,
 
    lp_func_delete_body(function);
 
-   return f;
+   return (lp_jit_setup_triangle) pointer_to_func(f);
 }
 
 /* XXX: Generic code:
  */
 static void
-lp_emit_emms(LLVMBuilderRef builder)
+lp_emit_emms(struct gallivm_state *gallivm)
 {
 #ifdef PIPE_ARCH_X86
    /* Avoid corrupting the FPU stack on 32bit OSes. */
-   lp_build_intrinsic(builder, "llvm.x86.mmx.emms", LLVMVoidType(), NULL, 0);
+   lp_build_intrinsic(gallivm->builder, "llvm.x86.mmx.emms",
+         LLVMVoidTypeInContext(gallivm->context), NULL, 0);
 #endif
 }
 
@@ -650,7 +651,7 @@ generate_setup_variant(struct gallivm_state *gallivm,
    LLVMTypeRef arg_types[7];
    LLVMBasicBlockRef block;
    LLVMBuilderRef builder = gallivm->builder;
-   int64_t t0, t1;
+   int64_t t0 = 0, t1;
 
    if (0)
       goto fail;
@@ -720,7 +721,7 @@ generate_setup_variant(struct gallivm_state *gallivm,
    init_args(gallivm, &args, variant);
    emit_tri_coef(gallivm, &variant->key, &args);
 
-   lp_emit_emms(builder);
+   lp_emit_emms(gallivm);
    LLVMBuildRetVoid(builder);
 
    variant->jit_function = finalize_function(gallivm, builder,
@@ -770,10 +771,16 @@ lp_make_setup_variant_key(struct llvmpipe_context *lp,
    key->twoside = lp->rasterizer->light_twoside;
    key->size = Offset(struct lp_setup_variant_key,
                      inputs[key->num_inputs]);
-   key->color_slot = lp->color_slot[0];
+
+   key->color_slot  = lp->color_slot [0];
    key->bcolor_slot = lp->bcolor_slot[0];
-   key->spec_slot = lp->color_slot[1];
-   key->bspec_slot = lp->bcolor_slot[1];
+   key->spec_slot   = lp->color_slot [1];
+   key->bspec_slot  = lp->bcolor_slot[1];
+   assert(key->color_slot  == lp->color_slot [0]);
+   assert(key->bcolor_slot == lp->bcolor_slot[0]);
+   assert(key->spec_slot   == lp->color_slot [1]);
+   assert(key->bspec_slot  == lp->bcolor_slot[1]);
+
    key->units = (float) (lp->rasterizer->offset_units * lp->mrd);
    key->scale = lp->rasterizer->offset_scale;
    key->pad = 0;
@@ -830,7 +837,13 @@ cull_setup_variants(struct llvmpipe_context *lp)
    llvmpipe_finish(pipe, __FUNCTION__);
 
    for (i = 0; i < LP_MAX_SETUP_VARIANTS / 4; i++) {
-      struct lp_setup_variant_list_item *item = last_elem(&lp->setup_variants_list);
+      struct lp_setup_variant_list_item *item;
+      if (is_empty_list(&lp->setup_variants_list)) {
+         break;
+      }
+      item = last_elem(&lp->setup_variants_list);
+      assert(item);
+      assert(item->base);
       remove_setup_variant(lp, item->base);
    }
 }
@@ -867,10 +880,11 @@ llvmpipe_update_setup(struct llvmpipe_context *lp)
       }
 
       variant = generate_setup_variant(lp->gallivm, key, lp);
-      insert_at_head(&lp->setup_variants_list, &variant->list_item_global);
-      lp->nr_setup_variants++;
-
-      llvmpipe_variant_count++;
+      if (variant) {
+         insert_at_head(&lp->setup_variants_list, &variant->list_item_global);
+         lp->nr_setup_variants++;
+         llvmpipe_variant_count++;
+      }
    }
 
    lp_setup_set_setup_variant(lp->setup,
@@ -897,7 +911,7 @@ lp_dump_setup_coef( const struct lp_setup_variant_key *key,
 {
    int i, slot;
 
-   for (i = 0; i < NUM_CHANNELS; i++) {
+   for (i = 0; i < TGSI_NUM_CHANNELS; i++) {
       float a0   = sa0  [0][i];
       float dadx = sdadx[0][i];
       float dady = sdady[0][i];
@@ -909,7 +923,7 @@ lp_dump_setup_coef( const struct lp_setup_variant_key *key,
 
    for (slot = 0; slot < key->num_inputs; slot++) {
       unsigned usage_mask = key->inputs[slot].usage_mask;
-      for (i = 0; i < NUM_CHANNELS; i++) {
+      for (i = 0; i < TGSI_NUM_CHANNELS; i++) {
         if (usage_mask & (1 << i)) {
            float a0   = sa0  [1 + slot][i];
            float dadx = sdadx[1 + slot][i];