gallivm: Add a new debug flag to warn about performance issues.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 9 Sep 2010 11:09:44 +0000 (12:09 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 11 Sep 2010 12:29:29 +0000 (13:29 +0100)
src/gallium/auxiliary/gallivm/lp_bld_arit.c
src/gallium/auxiliary/gallivm/lp_bld_debug.h
src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
src/gallium/auxiliary/gallivm/lp_bld_init.c
src/gallium/auxiliary/gallivm/lp_bld_logic.c
src/gallium/auxiliary/gallivm/lp_bld_pack.c
src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c

index e0d30be98d9749db0c57c49afe65242d52dfa931..dce3c3745b52d0f4e1143a65ddbecc5dc6526b1d 100644 (file)
@@ -56,6 +56,7 @@
 #include "lp_bld_intr.h"
 #include "lp_bld_logic.h"
 #include "lp_bld_pack.h"
+#include "lp_bld_debug.h"
 #include "lp_bld_arit.h"
 
 
@@ -1850,9 +1851,11 @@ lp_build_pow(struct lp_build_context *bld,
              LLVMValueRef y)
 {
    /* TODO: optimize the constant case */
-   if(LLVMIsConstant(x) && LLVMIsConstant(y))
+   if (gallivm_debug & GALLIVM_DEBUG_PERF &&
+       LLVMIsConstant(x) && LLVMIsConstant(y)) {
       debug_printf("%s: inefficient/imprecise constant arithmetic\n",
                    __FUNCTION__);
+   }
 
    return lp_build_exp2(bld, lp_build_mul(bld, lp_build_log2(bld, x), y));
 }
@@ -1907,9 +1910,11 @@ lp_build_polynomial(struct lp_build_context *bld,
    assert(lp_check_value(bld->type, x));
 
    /* TODO: optimize the constant case */
-   if(LLVMIsConstant(x))
+   if (gallivm_debug & GALLIVM_DEBUG_PERF &&
+       LLVMIsConstant(x)) {
       debug_printf("%s: inefficient/imprecise constant arithmetic\n",
                    __FUNCTION__);
+   }
 
    for (i = num_coeffs; i--; ) {
       LLVMValueRef coeff;
@@ -1981,9 +1986,11 @@ lp_build_exp2_approx(struct lp_build_context *bld,
 
    if(p_exp2_int_part || p_frac_part || p_exp2) {
       /* TODO: optimize the constant case */
-      if(LLVMIsConstant(x))
+      if (gallivm_debug & GALLIVM_DEBUG_PERF &&
+          LLVMIsConstant(x)) {
          debug_printf("%s: inefficient/imprecise constant arithmetic\n",
                       __FUNCTION__);
+      }
 
       assert(type.floating && type.width == 32);
 
@@ -2096,9 +2103,11 @@ lp_build_log2_approx(struct lp_build_context *bld,
 
    if(p_exp || p_floor_log2 || p_log2) {
       /* TODO: optimize the constant case */
-      if(LLVMIsConstant(x))
+      if (gallivm_debug & GALLIVM_DEBUG_PERF &&
+          LLVMIsConstant(x)) {
          debug_printf("%s: inefficient/imprecise constant arithmetic\n",
                       __FUNCTION__);
+      }
 
       assert(type.floating && type.width == 32);
 
index 858002b34feda33fb79b838242f9c067e4083504..369c1bbf09acb948e33ddae99fbd7b431ba6297f 100644 (file)
@@ -40,6 +40,7 @@
 #define GALLIVM_DEBUG_IR        0x2
 #define GALLIVM_DEBUG_ASM       0x4
 #define GALLIVM_DEBUG_NO_OPT    0x8
+#define GALLIVM_DEBUG_PERF      0x10
 
 
 #ifdef DEBUG
index 92123e09d3289c5d00a706749928c00d7fc24994..6b9189e1da5a06f3a44c5ee199c4606a66e63cd1 100644 (file)
@@ -46,6 +46,7 @@
 #include "lp_bld_conv.h"
 #include "lp_bld_swizzle.h"
 #include "lp_bld_gather.h"
+#include "lp_bld_debug.h"
 #include "lp_bld_format.h"
 
 
@@ -449,6 +450,11 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
        * integer conversions.
        */
 
+      if (gallivm_debug & GALLIVM_DEBUG_PERF && !type.floating) {
+         debug_printf("%s: unpacking %s with floating point\n",
+                      __FUNCTION__, format_desc->short_name);
+      }
+
       lp_build_conv(builder,
                     lp_float32_vec4_type(),
                     type,
@@ -513,6 +519,10 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
       util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_8unorm",
                     format_desc->short_name);
 
+      if (gallivm_debug & GALLIVM_DEBUG_PERF) {
+         debug_printf("%s: falling back to %s\n", __FUNCTION__, name);
+      }
+
       /*
        * Declare and bind format_desc->fetch_rgba_8unorm().
        */
@@ -612,6 +622,10 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
       util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_float",
                     format_desc->short_name);
 
+      if (gallivm_debug & GALLIVM_DEBUG_PERF) {
+         debug_printf("%s: falling back to %s\n", __FUNCTION__, name);
+      }
+
       /*
        * Declare and bind format_desc->fetch_rgba_float().
        */
index c724a4453e6e0ad2b11417d7c4d68f4aff15a8d7..ce7e54afc76a49be536fe39bdaa0f91dc1ef2792 100644 (file)
@@ -37,6 +37,7 @@
 #include "lp_bld_conv.h"
 #include "lp_bld_swizzle.h"
 #include "lp_bld_gather.h"
+#include "lp_bld_debug.h"
 #include "lp_bld_format.h"
 
 
@@ -387,6 +388,11 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
       unsigned k, chan;
       struct lp_type tmp_type;
 
+      if (gallivm_debug & GALLIVM_DEBUG_PERF) {
+         debug_printf("%s: scalar unpacking of %s\n",
+                      __FUNCTION__, format_desc->short_name);
+      }
+
       tmp_type = type;
       tmp_type.length = 4;
 
index 60d8bcfa55e82dd032bc3c5571fc25567a5daa40..761f33b578d3f8889b184c3d5bcf68c3cd6ea147 100644 (file)
@@ -43,6 +43,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = {
    { "ir",     GALLIVM_DEBUG_IR, NULL },
    { "asm",    GALLIVM_DEBUG_ASM, NULL },
    { "nopt",   GALLIVM_DEBUG_NO_OPT, NULL },
+   { "perf",   GALLIVM_DEBUG_PERF, NULL },
    DEBUG_NAMED_VALUE_END
 };
 
index db259814914fc7aee8fb03e8b64671e2891f2d0a..a959bd4ad4c07bc6e2f6e62424fd2f1b01537efc 100644 (file)
@@ -40,6 +40,7 @@
 #include "lp_bld_type.h"
 #include "lp_bld_const.h"
 #include "lp_bld_intr.h"
+#include "lp_bld_debug.h"
 #include "lp_bld_logic.h"
 
 
@@ -325,8 +326,10 @@ lp_build_compare(LLVMBuilderRef builder,
 
          res = LLVMGetUndef(int_vec_type);
 
-         debug_printf("%s: warning: using slow element-wise int"
-                      " vector comparison\n", __FUNCTION__);
+         if (gallivm_debug & GALLIVM_DEBUG_PERF) {
+            debug_printf("%s: using slow element-wise int"
+                         " vector comparison\n", __FUNCTION__);
+         }
 
          for(i = 0; i < type.length; ++i) {
             LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
index b7b630f2e8d2226d02e04fabd3b9af5ef8bfc0e3..f7eb7148ab8332866c84c2982b8d12cda18c523d 100644 (file)
@@ -111,8 +111,6 @@ lp_build_const_pack_shuffle(unsigned n)
 
    assert(n <= LP_MAX_VECTOR_LENGTH);
 
-   /* TODO: cache results in a static table */
-
    for(i = 0; i < n; ++i)
       elems[i] = LLVMConstInt(LLVMInt32Type(), 2*i, 0);
 
index 1f39d9c98b5cb3082eb03d7bebd51ee69572a9db..93cbf159aa406640a790685c1f76a7d1d9c91b98 100644 (file)
@@ -2203,6 +2203,16 @@ lp_build_sample_soa(LLVMBuilderRef builder,
                                     row_stride_array, data_array, texel_out);
    }
    else {
+      if (gallivm_debug & GALLIVM_DEBUG_PERF &&
+          bld.format_desc->nr_channels > 1 &&
+          (static_state->min_img_filter != PIPE_TEX_FILTER_NEAREST ||
+           static_state->mag_img_filter != PIPE_TEX_FILTER_NEAREST ||
+           static_state->min_mip_filter == PIPE_TEX_MIPFILTER_LINEAR) &&
+          util_format_fits_8unorm(bld.format_desc)) {
+         debug_printf("%s: using floating point linear filtering for %s\n",
+                      __FUNCTION__, bld.format_desc->short_name);
+      }
+
       lp_build_sample_general(&bld, unit, s, t, r, ddx, ddy,
                               lod_bias, explicit_lod,
                               width, height, depth,