vl: ...
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_fs.c
index 7bbf348e0b84bc4fbffe2af68a4263d67e134286..965777b641171a0ca4fca36961ed395bfceaf951 100644 (file)
@@ -37,7 +37,7 @@
  * - early depth test
  * - fragment shader
  * - alpha test
- * - depth/stencil test (stencil TBI)
+ * - depth/stencil test
  * - blending
  *
  * This file has only the glue to assemble the fragment pipeline.  The actual
 #include "gallivm/lp_bld_conv.h"
 #include "gallivm/lp_bld_intr.h"
 #include "gallivm/lp_bld_logic.h"
-#include "gallivm/lp_bld_depth.h"
-#include "gallivm/lp_bld_interp.h"
 #include "gallivm/lp_bld_tgsi.h"
-#include "gallivm/lp_bld_alpha.h"
-#include "gallivm/lp_bld_blend.h"
 #include "gallivm/lp_bld_swizzle.h"
 #include "gallivm/lp_bld_flow.h"
 #include "gallivm/lp_bld_debug.h"
-#include "lp_buffer.h"
+
+#include "lp_bld_alpha.h"
+#include "lp_bld_blend.h"
+#include "lp_bld_depth.h"
+#include "lp_bld_interp.h"
 #include "lp_context.h"
 #include "lp_debug.h"
 #include "lp_perf.h"
@@ -223,7 +223,7 @@ generate_tri_edge_mask(LLVMBuilderRef builder,
 #endif
    struct lp_build_flow_context *flow;
    struct lp_type i32_type;
-   LLVMTypeRef i32vec4_type, mask_type;
+   LLVMTypeRef i32vec4_type;
    LLVMValueRef c0_vec, c1_vec, c2_vec;
    LLVMValueRef in_out_mask;
 
@@ -239,8 +239,6 @@ generate_tri_edge_mask(LLVMBuilderRef builder,
 
    i32vec4_type = lp_build_int32_vec4_type();
 
-   mask_type = LLVMIntType(32 * 4);
-
    /*
     * Use a conditional here to do detailed pixel in/out testing.
     * We only have to do this if c0 != INT_MIN.
@@ -405,9 +403,7 @@ generate_fs(struct llvmpipe_context *lp,
             LLVMValueRef step2_ptr)
 {
    const struct tgsi_token *tokens = shader->base.tokens;
-   LLVMTypeRef elem_type;
    LLVMTypeRef vec_type;
-   LLVMTypeRef int_vec_type;
    LLVMValueRef consts_ptr;
    LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS];
    LLVMValueRef z = interp->pos[2];
@@ -424,9 +420,7 @@ generate_fs(struct llvmpipe_context *lp,
    stencil_refs[0] = lp_jit_context_stencil_ref_front_value(builder, context_ptr);
    stencil_refs[1] = lp_jit_context_stencil_ref_back_value(builder, context_ptr);
 
-   elem_type = lp_build_elem_type(type);
    vec_type = lp_build_vec_type(type);
-   int_vec_type = lp_build_int_vec_type(type);
 
    consts_ptr = lp_jit_context_constants(builder, context_ptr);
 
@@ -476,7 +470,7 @@ generate_fs(struct llvmpipe_context *lp,
 
    lp_build_tgsi_soa(builder, tokens, type, &mask,
                      consts_ptr, interp->pos, interp->inputs,
-                     outputs, sampler);
+                     outputs, sampler, &shader->info);
 
    for (attrib = 0; attrib < shader->info.num_outputs; ++attrib) {
       for(chan = 0; chan < NUM_CHANNELS; ++chan) {
@@ -548,7 +542,6 @@ generate_blend(const struct pipe_blend_state *blend,
    struct lp_build_flow_context *flow;
    struct lp_build_mask_context mask_ctx;
    LLVMTypeRef vec_type;
-   LLVMTypeRef int_vec_type;
    LLVMValueRef const_ptr;
    LLVMValueRef con[4];
    LLVMValueRef dst[4];
@@ -563,7 +556,6 @@ generate_blend(const struct pipe_blend_state *blend,
    lp_build_mask_begin(&mask_ctx, flow, type, mask);
 
    vec_type = lp_build_vec_type(type);
-   int_vec_type = lp_build_int_vec_type(type);
 
    const_ptr = lp_jit_context_blend_color(builder, context_ptr);
    const_ptr = LLVMBuildBitCast(builder, const_ptr,
@@ -629,7 +621,6 @@ generate_fragment(struct llvmpipe_context *lp,
    LLVMTypeRef fs_vec_type;
    LLVMTypeRef fs_int_vec_type;
    LLVMTypeRef blend_vec_type;
-   LLVMTypeRef blend_int_vec_type;
    LLVMTypeRef arg_types[15];
    LLVMTypeRef func_type;
    LLVMTypeRef int32_vec4_type = lp_build_int32_vec4_type();
@@ -688,7 +679,6 @@ generate_fragment(struct llvmpipe_context *lp,
    fs_int_vec_type = lp_build_int_vec_type(fs_type);
 
    blend_vec_type = lp_build_vec_type(blend_type);
-   blend_int_vec_type = lp_build_int_vec_type(blend_type);
 
    arg_types[0] = screen->context_ptr_type;            /* context */
    arg_types[1] = LLVMInt32Type();                     /* x */
@@ -780,7 +770,6 @@ generate_fragment(struct llvmpipe_context *lp,
       LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
       LLVMValueRef out_color[PIPE_MAX_COLOR_BUFS][NUM_CHANNELS];
       LLVMValueRef depth_ptr_i;
-      int cbuf;
 
       if(i != 0)
          lp_build_interp_soa_update(&interp, i);
@@ -948,7 +937,6 @@ generate_variant(struct llvmpipe_context *lp,
    if(!variant)
       return NULL;
 
-   variant->shader = shader;
    memcpy(&variant->key, key, sizeof *key);
 
    generate_fragment(lp, shader, variant, 0);
@@ -962,7 +950,7 @@ generate_variant(struct llvmpipe_context *lp,
 }
 
 
-void *
+static void *
 llvmpipe_create_fs_state(struct pipe_context *pipe,
                          const struct pipe_shader_state *templ)
 {
@@ -978,11 +966,16 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
    /* we need to keep a local copy of the tokens */
    shader->base.tokens = tgsi_dup_tokens(templ->tokens);
 
+   if (LP_DEBUG & DEBUG_TGSI) {
+      debug_printf("llvmpipe: Create fragment shader %p:\n", (void *) shader);
+      tgsi_dump(templ->tokens, 0);
+   }
+
    return shader;
 }
 
 
-void
+static void
 llvmpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
@@ -998,7 +991,7 @@ llvmpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
 }
 
 
-void
+static void
 llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
@@ -1041,14 +1034,14 @@ llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
 
 
 
-void
+static void
 llvmpipe_set_constant_buffer(struct pipe_context *pipe,
                              uint shader, uint index,
-                             struct pipe_buffer *constants)
+                             struct pipe_resource *constants)
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
-   unsigned size = constants ? constants->size : 0;
-   const void *data = constants ? llvmpipe_buffer(constants)->data : NULL;
+   unsigned size = constants ? constants->width0 : 0;
+   const void *data = constants ? llvmpipe_resource_data(constants) : NULL;
 
    assert(shader < PIPE_SHADER_TYPES);
    assert(index == 0);
@@ -1059,7 +1052,7 @@ llvmpipe_set_constant_buffer(struct pipe_context *pipe,
    draw_flush(llvmpipe->draw);
 
    /* note: reference counting */
-   pipe_buffer_reference(&llvmpipe->constants[shader], constants);
+   pipe_resource_reference(&llvmpipe->constants[shader], constants);
 
    if(shader == PIPE_SHADER_VERTEX) {
       draw_set_mapped_constant_buffer(llvmpipe->draw, PIPE_SHADER_VERTEX, 0,
@@ -1115,8 +1108,10 @@ make_variant_key(struct llvmpipe_context *lp,
       unsigned chan;
 
       format_desc = util_format_description(lp->framebuffer.cbufs[i]->format);
-      assert(format_desc->layout == UTIL_FORMAT_COLORSPACE_RGB ||
-             format_desc->layout == UTIL_FORMAT_COLORSPACE_SRGB);
+      assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB ||
+             format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB);
+
+      key->blend.rt[i].colormask = lp->blend->rt[i].colormask;
 
       /* mask out color channels not present in the color buffer.
        * Should be simple to incorporate per-cbuf writemasks:
@@ -1124,14 +1119,14 @@ make_variant_key(struct llvmpipe_context *lp,
       for(chan = 0; chan < 4; ++chan) {
          enum util_format_swizzle swizzle = format_desc->swizzle[chan];
 
-         if(swizzle <= UTIL_FORMAT_SWIZZLE_W)
-            key->blend.rt[0].colormask |= (1 << chan);
+         if(swizzle > UTIL_FORMAT_SWIZZLE_W)
+            key->blend.rt[i].colormask &= ~(1 << chan);
       }
    }
 
    for(i = 0; i < PIPE_MAX_SAMPLERS; ++i)
       if(shader->info.file_mask[TGSI_FILE_SAMPLER] & (1 << i))
-         lp_sampler_static_state(&key->sampler[i], lp->fragment_sampler_views[i]->texture, lp->sampler[i]);
+         lp_sampler_static_state(&key->sampler[i], lp->fragment_sampler_views[i], lp->sampler[i]);
 }
 
 
@@ -1170,8 +1165,6 @@ llvmpipe_update_fs(struct llvmpipe_context *lp)
       LP_COUNT_ADD(nr_llvm_compiles, 2);  /* emit vs. omit in/out test */
    }
 
-   shader->current = variant;
-
    /* TODO: put this in the variant */
    /* TODO: most of these can be relaxed, in particular the colormask */
    opaque = !key.blend.logicop_enable &&
@@ -1185,7 +1178,19 @@ llvmpipe_update_fs(struct llvmpipe_context *lp)
             ? TRUE : FALSE;
 
    lp_setup_set_fs_functions(lp->setup, 
-                             shader->current->jit_function[RAST_WHOLE],
-                             shader->current->jit_function[RAST_EDGE_TEST],
+                             variant->jit_function[RAST_WHOLE],
+                             variant->jit_function[RAST_EDGE_TEST],
                              opaque);
 }
+
+
+
+void
+llvmpipe_init_fs_funcs(struct llvmpipe_context *llvmpipe)
+{
+   llvmpipe->pipe.create_fs_state = llvmpipe_create_fs_state;
+   llvmpipe->pipe.bind_fs_state   = llvmpipe_bind_fs_state;
+   llvmpipe->pipe.delete_fs_state = llvmpipe_delete_fs_state;
+
+   llvmpipe->pipe.set_constant_buffer = llvmpipe_set_constant_buffer;
+}