llvmpipe: twoside for specular color also
authorKeith Whitwell <keithw@vmware.com>
Fri, 19 Nov 2010 16:17:36 +0000 (16:17 +0000)
committerKeith Whitwell <keithw@vmware.com>
Fri, 19 Nov 2010 16:17:36 +0000 (16:17 +0000)
src/gallium/drivers/llvmpipe/lp_context.h
src/gallium/drivers/llvmpipe/lp_state_derived.c
src/gallium/drivers/llvmpipe/lp_state_setup.c
src/gallium/drivers/llvmpipe/lp_state_setup.h

index 4515dbb0af135ef6958ba0574c340ade94592b74..a35e09e8b47130f0e0771582cddea13dc029bf15 100644 (file)
@@ -105,10 +105,10 @@ struct llvmpipe_context {
    struct vertex_info vertex_info;
    
    /** Which vertex shader output slot contains color */
-   int color_slot;
+   int color_slot[2];
 
    /** Which vertex shader output slot contains bcolor */
-   int bcolor_slot;
+   int bcolor_slot[2];
 
    /** Which vertex shader output slot contains point size */
    int psize_slot;
index 1c9f03a381c8d5e32e077c25b1cc103bbf12f6ec..8725ea39fe971f8523a658d880bd194630c6d658 100644 (file)
@@ -53,6 +53,11 @@ compute_vertex_info(struct llvmpipe_context *llvmpipe)
    unsigned vs_index;
    uint i;
 
+   llvmpipe->color_slot[0] = ~0;
+   llvmpipe->color_slot[1] = ~0;
+   llvmpipe->bcolor_slot[0] = ~0;
+   llvmpipe->bcolor_slot[1] = ~0;
+
    /*
     * Match FS inputs against VS outputs, emitting the necessary
     * attributes.  Could cache these structs and look them up with a
@@ -75,9 +80,13 @@ compute_vertex_info(struct llvmpipe_context *llvmpipe)
       vs_index = draw_find_shader_output(llvmpipe->draw,
                                          lpfs->info.base.input_semantic_name[i],
                                          lpfs->info.base.input_semantic_index[i]);
-      if (lpfs->info.base.input_semantic_name[i]==TGSI_SEMANTIC_COLOR){
-         llvmpipe->color_slot = vinfo->num_attribs;
+
+      if (lpfs->info.base.input_semantic_name[i] == TGSI_SEMANTIC_COLOR &&
+          lpfs->info.base.input_semantic_index[i] < 2) {
+         int idx = lpfs->info.base.input_semantic_index[i];
+         llvmpipe->color_slot[idx] = vinfo->num_attribs;
       }
+
       /*
        * Emit the requested fs attribute for all but position.
        */
@@ -86,14 +95,17 @@ compute_vertex_info(struct llvmpipe_context *llvmpipe)
 
    /* Figure out if we need bcolor as well.
     */
-   vs_index = draw_find_shader_output(llvmpipe->draw,
-                                      TGSI_SEMANTIC_BCOLOR, 0);
+   for (i = 0; i < 2; i++) {
+      vs_index = draw_find_shader_output(llvmpipe->draw,
+                                         TGSI_SEMANTIC_BCOLOR, i);
 
-   if (vs_index > 0) {
-      llvmpipe->bcolor_slot = vinfo->num_attribs;
-      draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index);
+      if (vs_index > 0) {
+         llvmpipe->bcolor_slot[i] = vinfo->num_attribs;
+         draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index);
+      }
    }
 
+
    /* Figure out if we need pointsize as well.
     */
    vs_index = draw_find_shader_output(llvmpipe->draw,
index 129ec0af3de2b044f086181ea92ffa923db46d3b..194b014436541a3e62b3d595fe2257a7cd310a0b 100644 (file)
@@ -218,10 +218,11 @@ vert_clamp(LLVMBuilderRef b,
 static void
 lp_twoside(LLVMBuilderRef b, 
            struct lp_setup_args *args,
-           const struct lp_setup_variant_key *key)
+           const struct lp_setup_variant_key *key,
+           int bcolor_slot)
 {
    LLVMValueRef a0_back, a1_back, a2_back;
-   LLVMValueRef idx2 = LLVMConstInt(LLVMInt32Type(), key->bcolor_slot, 0);
+   LLVMValueRef idx2 = LLVMConstInt(LLVMInt32Type(), bcolor_slot, 0);
 
    LLVMValueRef facing = args->facing;
    LLVMValueRef front_facing = LLVMBuildICmp(b, LLVMIntEQ, facing, LLVMConstInt(LLVMInt32Type(), 0, 0), ""); /** need i1 for if condition */
@@ -335,8 +336,11 @@ load_attribute(LLVMBuilderRef b,
       lp_do_offset_tri(b, args, key);
    }
 
-   if (key->twoside && vert_attr == key->color_slot) {
-      lp_twoside(b, args, key);
+   if (key->twoside) {
+      if (vert_attr == key->color_slot && key->bcolor_slot != ~0)
+         lp_twoside(b, args, key, key->bcolor_slot);
+      else if (vert_attr == key->spec_slot && key->bspec_slot != ~0)
+         lp_twoside(b, args, key, key->bspec_slot);
    }
 }
 
@@ -746,9 +750,11 @@ lp_make_setup_variant_key(struct llvmpipe_context *lp,
    key->pixel_center_half = lp->rasterizer->gl_rasterization_rules;
    key->twoside = lp->rasterizer->light_twoside;
    key->size = Offset(struct lp_setup_variant_key,
-                     inputs[key->num_inputs]);   
-   key->color_slot = lp->color_slot;
-   key->bcolor_slot = lp->bcolor_slot;
+                     inputs[key->num_inputs]);
+   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->units = (float) (lp->rasterizer->offset_units * lp->mrd);
    key->scale = lp->rasterizer->offset_scale;
    key->pad = 0;
index 40fb8ef4282f78ec3b155db98f27a2100f7b418c..90c55ca4ce654a48a25c58c0e8441173602ffd6d 100644 (file)
@@ -15,14 +15,18 @@ struct lp_setup_variant_list_item
 
 
 struct lp_setup_variant_key {   
+   unsigned size:16;
    unsigned num_inputs:8;
+   unsigned color_slot:8;
+
+   unsigned bcolor_slot:8;
+   unsigned spec_slot:8;
+   unsigned bspec_slot:8;
    unsigned flatshade_first:1;
    unsigned pixel_center_half:1;
    unsigned twoside:1;
-   unsigned color_slot:8;
-   unsigned bcolor_slot:8;
-   unsigned size:16;
-   unsigned pad:21;
+   unsigned pad:5;
+
    float units;
    float scale;      
    struct lp_shader_input inputs[PIPE_MAX_SHADER_INPUTS];