Hi José et al

So I got a bit annoyed at seeing the debug_get_*_option print outs
every single time it checks the value.

The first patch just adds another option to control if we print the
options or not.

The second adds helper defines so you can easily add functions which
only check the argument once.

The third uses this in various places.

Cheers Jakob.
From f775abb9874d92bff951c7fed077f1f3a9bab4af Mon Sep 17 00:00:00 2001
From: Jakob Bornecrantz <[email protected]>
Date: Thu, 22 Apr 2010 21:01:39 +0100
Subject: [PATCH] gallium: Add static get option helpers

---
 src/gallium/auxiliary/util/u_debug.h |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index b6d0b50..464e468 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -303,6 +303,39 @@ debug_get_flags_option(const char *name,
                        const struct debug_named_value *flags,
                        unsigned long dfault);
 
+#define DEBUG_GET_ONCE_BOOL_OPTION(sufix, name, dfault) \
+static boolean \
+debug_get_option_ ## sufix (void) \
+{ \
+   static boolean first = TRUE; \
+   static boolean value; \
+   if (first && !(first = FALSE)) \
+      value = debug_get_bool_option(name, dfault); \
+   return value; \
+}
+
+#define DEBUG_GET_ONCE_NUM_OPTION(sufix, name, dfault) \
+static long \
+debug_get_option_ ## sufix (void) \
+{ \
+   static boolean first = TRUE; \
+   static long value; \
+   if (first && !(first = FALSE)) \
+      value = debug_get_num_option(name, dfault); \
+   return value; \
+}
+
+#define DEBUG_GET_ONCE_FLAGS_OPTION(sufix, name, flags, dfault) \
+static unsigned long \
+debug_get_option_ ## sufix (void) \
+{ \
+   static boolean first = TRUE; \
+   unsigned long value; \
+   if (first && !(first = FALSE)) \
+      value = debug_get_num_option(name, flags, dfault); \
+   return value; \
+}
+
 
 unsigned long
 debug_memory_begin(void);
-- 
1.6.0.4

From ca452673ef36a964de79af27bce291f672804152 Mon Sep 17 00:00:00 2001
From: Jakob Bornecrantz <[email protected]>
Date: Thu, 22 Apr 2010 21:02:06 +0100
Subject: [PATCH] gallium: Add option to not print options

---
 src/gallium/auxiliary/util/u_debug.c |   42 +++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index dd04497..0de38e7 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -74,6 +74,24 @@ void debug_print_blob( const char *name,
 #endif
 
 
+static boolean
+debug_get_option_should_print(void)
+{
+   static boolean first = TRUE;
+   static boolean value = FALSE;
+
+   if (!first)
+      return value;
+
+   /* Oh hey this will call into this function,
+    * but its cool since we set first to false
+    */
+   first = FALSE;
+   value = debug_get_bool_option("GALLIUM_PRINT_OPTIONS", TRUE);
+   /* XXX should we print this option? Currently it wont */
+   return value;
+}
+
 const char *
 debug_get_option(const char *name, const char *dfault)
 {
@@ -82,8 +100,9 @@ debug_get_option(const char *name, const char *dfault)
    result = os_get_option(name);
    if(!result)
       result = dfault;
-      
-   debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
+
+   if (debug_get_option_should_print())
+      debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
    
    return result;
 }
@@ -109,7 +128,8 @@ debug_get_bool_option(const char *name, boolean dfault)
    else
       result = TRUE;
 
-   debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE");
+   if (debug_get_option_should_print())
+      debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE");
    
    return result;
 }
@@ -142,8 +162,9 @@ debug_get_num_option(const char *name, long dfault)
       }
       result *= sign;
    }
-   
-   debug_printf("%s: %s = %li\n", __FUNCTION__, name, result);
+
+   if (debug_get_option_should_print())
+      debug_printf("%s: %s = %li\n", __FUNCTION__, name, result);
 
    return result;
 }
@@ -176,11 +197,12 @@ debug_get_flags_option(const char *name,
       }
    }
 
-   if (str) {
-      debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__, name, result, str);
-   }
-   else {
-      debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result);
+   if (debug_get_option_should_print()) {
+      if (str) {
+         debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__, name, result, str);
+      } else {
+         debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result);
+      }
    }
 
    return result;
-- 
1.6.0.4

From f47ebe03291431cd8f87f1e200d1f5433a285fe0 Mon Sep 17 00:00:00 2001
From: Jakob Bornecrantz <[email protected]>
Date: Thu, 22 Apr 2010 20:02:31 +0100
Subject: [PATCH] gallium: Convert some uses of get option to static

---
 src/gallium/auxiliary/draw/draw_pt.c        |   13 ++++++++++---
 src/gallium/auxiliary/draw/draw_vs.c        |    4 ++--
 src/gallium/winsys/sw/xlib/xlib_sw_winsys.c |    4 +++-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c
index b5876bb..c40c25d 100644
--- a/src/gallium/auxiliary/draw/draw_pt.c
+++ b/src/gallium/auxiliary/draw/draw_pt.c
@@ -37,6 +37,13 @@
 #include "util/u_math.h"
 #include "util/u_prim.h"
 
+
+DEBUG_GET_ONCE_BOOL_OPTION(draw_fse, "DRAW_FSE", FALSE);
+DEBUG_GET_ONCE_BOOL_OPTION(draw_no_fse, "DRAW_NO_FSE", FALSE);
+#ifdef HAVE_LLVM
+DEBUG_GET_ONCE_BOOL_OPTION(draw_use_llvm, "DRAW_USE_LLVM", TRUE);
+#endif
+
 static unsigned trim( unsigned count, unsigned first, unsigned incr )
 {
    if (count < first)
@@ -122,8 +129,8 @@ draw_pt_arrays(struct draw_context *draw,
 
 boolean draw_pt_init( struct draw_context *draw )
 {
-   draw->pt.test_fse = debug_get_bool_option("DRAW_FSE", FALSE);
-   draw->pt.no_fse = debug_get_bool_option("DRAW_NO_FSE", FALSE);
+   draw->pt.test_fse = debug_get_option_draw_fse();
+   draw->pt.no_fse = debug_get_option_draw_no_fse();
 
    draw->pt.front.vcache = draw_pt_vcache( draw );
    if (!draw->pt.front.vcache)
@@ -142,7 +149,7 @@ boolean draw_pt_init( struct draw_context *draw )
       return FALSE;
 
 #if HAVE_LLVM
-   draw->use_llvm = debug_get_bool_option("DRAW_USE_LLVM", TRUE);
+   draw->use_llvm = debug_get_option_draw_use_llvm();
    if (draw->use_llvm)
       draw->pt.middle.general = draw_pt_fetch_pipeline_or_emit_llvm( draw );
 #else
diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c
index cfd5154..0c05957 100644
--- a/src/gallium/auxiliary/draw/draw_vs.c
+++ b/src/gallium/auxiliary/draw/draw_vs.c
@@ -46,7 +46,7 @@
 #include "tgsi/tgsi_dump.h"
 #include "tgsi/tgsi_exec.h"
 
-
+DEBUG_GET_ONCE_BOOL_OPTION(gallium_dump_vs, "GALLIUM_DUMP_VS", FALSE);
 
 void
 draw_vs_set_constants(struct draw_context *draw,
@@ -157,7 +157,7 @@ draw_delete_vertex_shader(struct draw_context *draw,
 boolean 
 draw_vs_init( struct draw_context *draw )
 {
-   draw->dump_vs = debug_get_bool_option("GALLIUM_DUMP_VS", FALSE);
+   draw->dump_vs = debug_get_option_gallium_dump_vs();
 
    draw->vs.machine = tgsi_exec_machine_create();
    if (!draw->vs.machine)
diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
index ec4f919..6aee7b2 100644
--- a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
+++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
@@ -48,6 +48,8 @@
 #include <sys/shm.h>
 #include <X11/extensions/XShm.h>
 
+DEBUG_GET_ONCE_BOOL_OPTION(xlib_no_shm, "XLIB_NO_SHM", FALSE);
+
 /**
  * Display target for Xlib winsys.
  * Low-level OS/window system memory buffer
@@ -383,7 +385,7 @@ xm_displaytarget_create(struct sw_winsys *winsys,
    xm_dt->stride = align(util_format_get_stride(format, width), alignment);
    size = xm_dt->stride * nblocksy;
 
-   if (!debug_get_bool_option("XLIB_NO_SHM", FALSE))
+   if (!debug_get_option_xlib_no_shm())
    {
       xm_dt->shminfo.shmid = -1;
       xm_dt->shminfo.shmaddr = (char *) -1;
-- 
1.6.0.4

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to