llvmpipe: Don't waste time interpolating unused input channels.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_fs.c
index cc163ebd4fa987bbf788f578202228c639dc4732..d3f2eb2421eab7649dfabcf988c1d8978c76a568 100644 (file)
@@ -64,6 +64,7 @@
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
+#include "util/u_pointer.h"
 #include "util/u_format.h"
 #include "util/u_dump.h"
 #include "os/os_time.h"
@@ -759,7 +760,7 @@ generate_fragment(struct llvmpipe_context *lp,
    generate_pos0(builder, x, y, &x0, &y0);
 
    lp_build_interp_soa_init(&interp, 
-                            shader->base.tokens,
+                            &shader->info,
                             key->flatshade,
                             builder, fs_type,
                             a0_ptr, dadx_ptr, dady_ptr,
@@ -862,7 +863,7 @@ generate_fragment(struct llvmpipe_context *lp,
    if (1)
       LLVMRunFunctionPassManager(screen->pass, function);
 
-   if (LP_DEBUG & DEBUG_JIT) {
+   if (gallivm_debug & GALLIVM_DEBUG_IR) {
       /* Print the LLVM IR to stderr */
       lp_debug_dump_value(function);
       debug_printf("\n");
@@ -874,14 +875,86 @@ generate_fragment(struct llvmpipe_context *lp,
    {
       void *f = LLVMGetPointerToGlobal(screen->engine, function);
 
-      variant->jit_function[do_tri_test] = cast_voidptr_to_lp_jit_frag_func(f);
+      variant->jit_function[do_tri_test] = (lp_jit_frag_func)pointer_to_func(f);
 
-      if (LP_DEBUG & DEBUG_ASM)
+      if (gallivm_debug & GALLIVM_DEBUG_ASM) {
          lp_disassemble(f);
+      }
    }
 }
 
 
+static void
+dump_fs_variant_key(const struct lp_fragment_shader_variant_key *key)
+{
+   unsigned i;
+
+   debug_printf("fs variant %p:\n", (void *) key);
+
+   if (key->depth.enabled) {
+      debug_printf("depth.format = %s\n", util_format_name(key->zsbuf_format));
+      debug_printf("depth.func = %s\n", util_dump_func(key->depth.func, TRUE));
+      debug_printf("depth.writemask = %u\n", key->depth.writemask);
+   }
+
+   for (i = 0; i < 2; ++i) {
+      if (key->stencil[i].enabled) {
+         debug_printf("stencil[%u].func = %s\n", i, util_dump_func(key->stencil[i].func, TRUE));
+         debug_printf("stencil[%u].fail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].fail_op, TRUE));
+         debug_printf("stencil[%u].zpass_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zpass_op, TRUE));
+         debug_printf("stencil[%u].zfail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zfail_op, TRUE));
+         debug_printf("stencil[%u].valuemask = 0x%x\n", i, key->stencil[i].valuemask);
+         debug_printf("stencil[%u].writemask = 0x%x\n", i, key->stencil[i].writemask);
+      }
+   }
+
+   if (key->alpha.enabled) {
+      debug_printf("alpha.func = %s\n", util_dump_func(key->alpha.func, TRUE));
+      debug_printf("alpha.ref_value = %f\n", key->alpha.ref_value);
+   }
+
+   if (key->blend.logicop_enable) {
+      debug_printf("blend.logicop_func = %s\n", util_dump_logicop(key->blend.logicop_func, TRUE));
+   }
+   else if (key->blend.rt[0].blend_enable) {
+      debug_printf("blend.rgb_func = %s\n",   util_dump_blend_func  (key->blend.rt[0].rgb_func, TRUE));
+      debug_printf("blend.rgb_src_factor = %s\n",   util_dump_blend_factor(key->blend.rt[0].rgb_src_factor, TRUE));
+      debug_printf("blend.rgb_dst_factor = %s\n",   util_dump_blend_factor(key->blend.rt[0].rgb_dst_factor, TRUE));
+      debug_printf("blend.alpha_func = %s\n",       util_dump_blend_func  (key->blend.rt[0].alpha_func, TRUE));
+      debug_printf("blend.alpha_src_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_src_factor, TRUE));
+      debug_printf("blend.alpha_dst_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_dst_factor, TRUE));
+   }
+   debug_printf("blend.colormask = 0x%x\n", key->blend.rt[0].colormask);
+   for (i = 0; i < PIPE_MAX_SAMPLERS; ++i) {
+      if (key->sampler[i].format) {
+         debug_printf("sampler[%u] = \n", i);
+         debug_printf("  .format = %s\n",
+                      util_format_name(key->sampler[i].format));
+         debug_printf("  .target = %s\n",
+                      util_dump_tex_target(key->sampler[i].target, TRUE));
+         debug_printf("  .pot = %u %u %u\n",
+                      key->sampler[i].pot_width,
+                      key->sampler[i].pot_height,
+                      key->sampler[i].pot_depth);
+         debug_printf("  .wrap = %s %s %s\n",
+                      util_dump_tex_wrap(key->sampler[i].wrap_s, TRUE),
+                      util_dump_tex_wrap(key->sampler[i].wrap_t, TRUE),
+                      util_dump_tex_wrap(key->sampler[i].wrap_r, TRUE));
+         debug_printf("  .min_img_filter = %s\n",
+                      util_dump_tex_filter(key->sampler[i].min_img_filter, TRUE));
+         debug_printf("  .min_mip_filter = %s\n",
+                      util_dump_tex_mipfilter(key->sampler[i].min_mip_filter, TRUE));
+         debug_printf("  .mag_img_filter = %s\n",
+                      util_dump_tex_filter(key->sampler[i].mag_img_filter, TRUE));
+         if (key->sampler[i].compare_mode != PIPE_TEX_COMPARE_NONE)
+            debug_printf("  .compare_func = %s\n", util_dump_func(key->sampler[i].compare_func, TRUE));
+         debug_printf("  .normalized_coords = %u\n", key->sampler[i].normalized_coords);
+      }
+   }
+}
+
+
+
 static struct lp_fragment_shader_variant *
 generate_variant(struct llvmpipe_context *lp,
                  struct lp_fragment_shader *shader,
@@ -889,67 +962,9 @@ generate_variant(struct llvmpipe_context *lp,
 {
    struct lp_fragment_shader_variant *variant;
 
-   if (LP_DEBUG & DEBUG_JIT) {
-      unsigned i;
-
+   if (gallivm_debug & GALLIVM_DEBUG_IR) {
       tgsi_dump(shader->base.tokens, 0);
-      if(key->depth.enabled) {
-         debug_printf("depth.format = %s\n", util_format_name(key->zsbuf_format));
-         debug_printf("depth.func = %s\n", util_dump_func(key->depth.func, TRUE));
-         debug_printf("depth.writemask = %u\n", key->depth.writemask);
-      }
-      for (i = 0; i < 2; ++i) {
-         if(key->stencil[i].enabled) {
-            debug_printf("stencil[%u].func = %s\n", i, util_dump_func(key->stencil[i].func, TRUE));
-            debug_printf("stencil[%u].fail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].fail_op, TRUE));
-            debug_printf("stencil[%u].zpass_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zpass_op, TRUE));
-            debug_printf("stencil[%u].zfail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zfail_op, TRUE));
-            debug_printf("stencil[%u].valuemask = 0x%x\n", i, key->stencil[i].valuemask);
-            debug_printf("stencil[%u].writemask = 0x%x\n", i, key->stencil[i].writemask);
-         }
-      }
-      if(key->alpha.enabled) {
-         debug_printf("alpha.func = %s\n", util_dump_func(key->alpha.func, TRUE));
-         debug_printf("alpha.ref_value = %f\n", key->alpha.ref_value);
-      }
-      if(key->blend.logicop_enable) {
-         debug_printf("blend.logicop_func = %u\n", key->blend.logicop_func);
-      }
-      else if(key->blend.rt[0].blend_enable) {
-         debug_printf("blend.rgb_func = %s\n",   util_dump_blend_func  (key->blend.rt[0].rgb_func, TRUE));
-         debug_printf("rgb_src_factor = %s\n",   util_dump_blend_factor(key->blend.rt[0].rgb_src_factor, TRUE));
-         debug_printf("rgb_dst_factor = %s\n",   util_dump_blend_factor(key->blend.rt[0].rgb_dst_factor, TRUE));
-         debug_printf("alpha_func = %s\n",       util_dump_blend_func  (key->blend.rt[0].alpha_func, TRUE));
-         debug_printf("alpha_src_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_src_factor, TRUE));
-         debug_printf("alpha_dst_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_dst_factor, TRUE));
-      }
-      debug_printf("blend.colormask = 0x%x\n", key->blend.rt[0].colormask);
-      for(i = 0; i < PIPE_MAX_SAMPLERS; ++i) {
-         if(key->sampler[i].format) {
-            debug_printf("sampler[%u] = \n", i);
-            debug_printf("  .format = %s\n",
-                         util_format_name(key->sampler[i].format));
-            debug_printf("  .target = %s\n",
-                         util_dump_tex_target(key->sampler[i].target, TRUE));
-            debug_printf("  .pot = %u %u %u\n",
-                         key->sampler[i].pot_width,
-                         key->sampler[i].pot_height,
-                         key->sampler[i].pot_depth);
-            debug_printf("  .wrap = %s %s %s\n",
-                         util_dump_tex_wrap(key->sampler[i].wrap_s, TRUE),
-                         util_dump_tex_wrap(key->sampler[i].wrap_t, TRUE),
-                         util_dump_tex_wrap(key->sampler[i].wrap_r, TRUE));
-            debug_printf("  .min_img_filter = %s\n",
-                         util_dump_tex_filter(key->sampler[i].min_img_filter, TRUE));
-            debug_printf("  .min_mip_filter = %s\n",
-                         util_dump_tex_mipfilter(key->sampler[i].min_mip_filter, TRUE));
-            debug_printf("  .mag_img_filter = %s\n",
-                         util_dump_tex_filter(key->sampler[i].mag_img_filter, TRUE));
-            if(key->sampler[i].compare_mode != PIPE_TEX_COMPARE_NONE)
-               debug_printf("  .compare_func = %s\n", util_dump_func(key->sampler[i].compare_func, TRUE));
-            debug_printf("  .normalized_coords = %u\n", key->sampler[i].normalized_coords);
-         }
-      }
+      dump_fs_variant_key(key);
    }
 
    variant = CALLOC_STRUCT(lp_fragment_shader_variant);
@@ -998,8 +1013,20 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
    shader->base.tokens = tgsi_dup_tokens(templ->tokens);
 
    if (LP_DEBUG & DEBUG_TGSI) {
+      unsigned attrib;
       debug_printf("llvmpipe: Create fragment shader %p:\n", (void *) shader);
       tgsi_dump(templ->tokens, 0);
+      debug_printf("usage masks:\n");
+      for (attrib = 0; attrib < shader->info.num_inputs; ++attrib) {
+         unsigned usage_mask = shader->info.input_usage_mask[attrib];
+         debug_printf("  IN[%u].%s%s%s%s\n",
+                      attrib,
+                      usage_mask & TGSI_WRITEMASK_X ? "x" : "",
+                      usage_mask & TGSI_WRITEMASK_Y ? "y" : "",
+                      usage_mask & TGSI_WRITEMASK_Z ? "z" : "",
+                      usage_mask & TGSI_WRITEMASK_W ? "w" : "");
+      }
+      debug_printf("\n");
    }
 
    return shader;
@@ -1247,10 +1274,7 @@ llvmpipe_update_fs(struct llvmpipe_context *lp)
       LP_COUNT_ADD(nr_llvm_compiles, 2);  /* emit vs. omit in/out test */
    }
 
-   lp_setup_set_fs_functions(lp->setup, 
-                             variant->jit_function[RAST_WHOLE],
-                             variant->jit_function[RAST_EDGE_TEST],
-                             variant->opaque);
+   lp_setup_set_fs_variant(lp->setup, variant);
 }