gallium/u_dump: add and use util_dump_transfer_usage
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sun, 22 Oct 2017 15:38:57 +0000 (17:38 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 9 Nov 2017 13:01:02 +0000 (14:01 +0100)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/util/u_debug.c
src/gallium/auxiliary/util/u_dump.h
src/gallium/auxiliary/util/u_dump_defines.c
src/gallium/auxiliary/util/u_dump_state.c

index dd3e16791d6384d5b5444ff961b063d492ead9ae..866cfbdd35ebb8c241ac8bae5f8e46e8551d393a 100644 (file)
@@ -31,6 +31,7 @@
 
 #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"
@@ -484,21 +485,9 @@ debug_funclog_enter_exit(const char* f, const int line, const char* file)
 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");
 }
 
 
index be9a0fa26d0a27a9ae518c5c64b50a41f0717ca6..8c1a8f3f4ee9fa5b2a445acbbc015c9476b269b5 100644 (file)
@@ -102,6 +102,9 @@ 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
  */
index e87e530160040d421cfdfff2fff682a4be0d50c4..e431cd969bd290f2f58128648312d8a9058fd154 100644 (file)
@@ -29,6 +29,7 @@
 #include "util/u_memory.h"
 #include "util/u_debug.h" 
 #include "util/u_dump.h"
+#include "util/u_math.h"
 
 
 #if 0
@@ -89,6 +90,41 @@ util_dump_enum_continuous(unsigned value,
          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[] = {
@@ -470,3 +506,20 @@ 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)
index a2543beaf38fde6bb492be7c7f8d310c7e483961..2725d50cd9a771ac6e9f72f0a0d6121154649929 100644 (file)
@@ -812,7 +812,7 @@ util_dump_transfer(FILE *stream, const struct pipe_transfer *state)
 
    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);