[Mesa-dev] [PATCH 17/25] gallium/u_dump: add and use util_dump_transfer_usage

Nicolai Hähnle nhaehnle at gmail.com
Sun Oct 22 19:08:00 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/gallium/auxiliary/util/u_debug.c        | 19 +++--------
 src/gallium/auxiliary/util/u_dump.h         |  3 ++
 src/gallium/auxiliary/util/u_dump_defines.c | 53 +++++++++++++++++++++++++++++
 src/gallium/auxiliary/util/u_dump_state.c   |  2 +-
 4 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index dd3e16791d6..866cfbdd35e 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -24,20 +24,21 @@
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  **************************************************************************/
 
 
 #include "pipe/p_config.h"
 
 #include "pipe/p_compiler.h"
 #include "util/u_debug.h"
+#include "util/u_dump.h"
 #include "pipe/p_format.h"
 #include "pipe/p_state.h"
 #include "util/u_inlines.h"
 #include "util/u_format.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
 #include "util/u_math.h"
 #include "util/u_prim.h"
 #include <inttypes.h>
 
@@ -477,35 +478,23 @@ debug_funclog_enter_exit(const char* f, const int line, const char* file)
 
 
 
 #ifdef DEBUG
 /**
  * Print PIPE_TRANSFER_x flags with a message.
  */
 void
 debug_print_transfer_flags(const char *msg, unsigned usage)
 {
-   static const struct debug_named_value names[] = {
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_READ),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_WRITE),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_MAP_DIRECTLY),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_DISCARD_RANGE),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_DONTBLOCK),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_UNSYNCHRONIZED),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_FLUSH_EXPLICIT),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_PERSISTENT),
-      DEBUG_NAMED_VALUE(PIPE_TRANSFER_COHERENT),
-      DEBUG_NAMED_VALUE_END
-   };
-
-   debug_printf("%s: %s\n", msg, debug_dump_flags(names, usage));
+   debug_printf("%s: ", msg);
+   util_dump_transfer_usage(stdout, usage);
+   printf("\n");
 }
 
 
 /**
  * Print PIPE_BIND_x flags with a message.
  */
 void
 debug_print_bind_flags(const char *msg, unsigned usage)
 {
    static const struct debug_named_value names[] = {
diff --git a/src/gallium/auxiliary/util/u_dump.h b/src/gallium/auxiliary/util/u_dump.h
index be9a0fa26d0..8c1a8f3f4ee 100644
--- a/src/gallium/auxiliary/util/u_dump.h
+++ b/src/gallium/auxiliary/util/u_dump.h
@@ -95,20 +95,23 @@ util_dump_ns(FILE *f, uint64_t time);
 
 void
 util_dump_ptr(FILE *stream, const void *value);
 
 void
 util_dump_query_type(FILE *stream, unsigned value);
 
 void
 util_dump_query_value_type(FILE *stream, unsigned value);
 
+void
+util_dump_transfer_usage(FILE *stream, unsigned value);
+
 /*
  * p_state.h, through a FILE
  */
 
 void
 util_dump_resource(FILE *stream, const struct pipe_resource *state);
 
 void
 util_dump_rasterizer_state(FILE *stream,
                            const struct pipe_rasterizer_state *state);
diff --git a/src/gallium/auxiliary/util/u_dump_defines.c b/src/gallium/auxiliary/util/u_dump_defines.c
index e87e5301600..e431cd969bd 100644
--- a/src/gallium/auxiliary/util/u_dump_defines.c
+++ b/src/gallium/auxiliary/util/u_dump_defines.c
@@ -22,20 +22,21 @@
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * 
  **************************************************************************/
 
 
 #include "util/u_memory.h"
 #include "util/u_debug.h" 
 #include "util/u_dump.h"
+#include "util/u_math.h"
 
 
 #if 0
 static const char *
 util_dump_strip_prefix(const char *name,
                         const char *prefix) 
 {
    const char *stripped;
    assert(name);
    assert(prefix);
@@ -82,20 +83,55 @@ util_dump_enum_continuous(unsigned value,
    util_str_##_name(unsigned value, boolean shortened) \
    { \
       STATIC_ASSERT(ARRAY_SIZE(util_##_name##_names) == _count); \
       STATIC_ASSERT(ARRAY_SIZE(util_##_name##_short_names) == _count); \
       if(shortened) \
          return util_dump_enum_continuous(value, ARRAY_SIZE(util_##_name##_short_names), util_##_name##_short_names); \
       else \
          return util_dump_enum_continuous(value, ARRAY_SIZE(util_##_name##_names), util_##_name##_names); \
    }
 
+static void
+util_dump_flags_continuous(FILE *stream, unsigned value, unsigned num_names,
+                           const char * const *names)
+{
+   unsigned unknown = 0;
+   bool first = true;
+
+   while (value) {
+      int i = u_bit_scan(&value);
+      if (i >= num_names || !names[i])
+         unknown |= 1u << i;
+      if (!first)
+         fputs("|", stream);
+      fputs(names[i], stream);
+      first = false;
+   }
+
+   if (unknown) {
+      if (!first)
+         fputs("|", stream);
+      fprintf(stream, "%x", unknown);
+      first = false;
+   }
+
+   if (first)
+      fputs("0", stream);
+}
+
+#define DEFINE_UTIL_DUMP_FLAGS_CONTINUOUS(_name) \
+void \
+util_dump_##_name(FILE *stream, unsigned value) \
+{ \
+   util_dump_flags_continuous(stream, value, ARRAY_SIZE(util_##_name##_names), \
+                              util_##_name##_names); \
+}
 
 static const char *
 util_blend_factor_names[] = {
    UTIL_DUMP_INVALID_NAME, /* 0x0 */
    "PIPE_BLENDFACTOR_ONE",
    "PIPE_BLENDFACTOR_SRC_COLOR",
    "PIPE_BLENDFACTOR_SRC_ALPHA",
    "PIPE_BLENDFACTOR_DST_ALPHA",
    "PIPE_BLENDFACTOR_DST_COLOR",
    "PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE",
@@ -463,10 +499,27 @@ util_dump_query_type(FILE *stream, unsigned value)
               value - PIPE_QUERY_DRIVER_SPECIFIC);
    else
       fprintf(stream, "%s", util_str_query_type(value, false));
 }
 
 void
 util_dump_query_value_type(FILE *stream, unsigned value)
 {
    fprintf(stream, "%s", util_str_query_value_type(value, false));
 }
+
+
+static const char * const
+util_transfer_usage_names[] = {
+      "PIPE_TRANSFER_READ",
+      "PIPE_TRANSFER_WRITE",
+      "PIPE_TRANSFER_MAP_DIRECTLY",
+      "PIPE_TRANSFER_DISCARD_RANGE",
+      "PIPE_TRANSFER_DONTBLOCK",
+      "PIPE_TRANSFER_UNSYNCHRONIZED",
+      "PIPE_TRANSFER_FLUSH_EXPLICIT",
+      "PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE",
+      "PIPE_TRANSFER_PERSISTENT",
+      "PIPE_TRANSFER_COHERENT",
+};
+
+DEFINE_UTIL_DUMP_FLAGS_CONTINUOUS(transfer_usage)
diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c
index a2543beaf38..2725d50cd9a 100644
--- a/src/gallium/auxiliary/util/u_dump_state.c
+++ b/src/gallium/auxiliary/util/u_dump_state.c
@@ -805,21 +805,21 @@ util_dump_transfer(FILE *stream, const struct pipe_transfer *state)
 {
    if (!state) {
       util_dump_null(stream);
       return;
    }
 
    util_dump_struct_begin(stream, "pipe_transfer");
 
    util_dump_member(stream, ptr, state, resource);
    util_dump_member(stream, uint, state, level);
-   util_dump_member(stream, uint, state, usage);
+   util_dump_member(stream, transfer_usage, state, usage);
    util_dump_member_begin(stream, "box");
    util_dump_box(stream, &state->box);
    util_dump_member_end(stream);
    util_dump_member(stream, uint, state, stride);
    util_dump_member(stream, uint, state, layer_stride);
 
    util_dump_struct_end(stream);
 }
 
 
-- 
2.11.0



More information about the mesa-dev mailing list