[Mesa-dev] [PATCH 3/4] aubinator: Reuse decode_structure code for handling commands

Kenneth Graunke kenneth at whitecape.org
Thu Mar 16 03:02:00 UTC 2017


The code for decoding structures and commands was almost identical.
The only differences are: we print dword headers for commands, and
we skip the first one (with the command opcode and lengths).

So, generalize decode_structure to add a starting DWord, and a flag
for printing the DWord headers, and reuse it.
---
 src/intel/tools/aubinator.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
index 676358f57a1..7ff8aca2ab8 100644
--- a/src/intel/tools/aubinator.c
+++ b/src/intel/tools/aubinator.c
@@ -134,8 +134,9 @@ print_iterator_values(struct gen_field_iterator *iter, int *idx)
 }
 
 static void
-decode_structure(struct gen_spec *spec, struct gen_group *strct,
-                 const uint32_t *p)
+decode_group(struct gen_spec *spec, struct gen_group *strct,
+             const uint32_t *p, int starting_dword,
+             bool print_dword_headers)
 {
    struct gen_field_iterator iter;
    char *token = NULL;
@@ -152,16 +153,26 @@ decode_structure(struct gen_spec *spec, struct gen_group *strct,
    while (gen_field_iterator_next(&iter)) {
       idx = 0;
       print_dword_val(&iter, offset, &dword_num);
-      token = print_iterator_values(&iter, &idx);
+      if (dword_num >= starting_dword)
+         token = print_iterator_values(&iter, &idx);
       if (token != NULL) {
+         printf("0x%08"PRIx64":  0x%08x : Dword %d\n",
+                offset + 4 * idx, p[idx], idx);
          struct gen_group *struct_val = gen_spec_find_struct(spec, token);
-         decode_structure(spec, struct_val, &p[idx]);
+         decode_group(spec, struct_val, &p[idx], 0, false);
          token = NULL;
       }
    }
 }
 
 static void
+decode_structure(struct gen_spec *spec, struct gen_group *strct,
+                 const uint32_t *p)
+{
+   decode_group(spec, strct, p, 0, false);
+}
+
+static void
 dump_binding_table(struct gen_spec *spec, uint32_t offset)
 {
    uint32_t *pointers, i;
@@ -780,25 +791,7 @@ parse_commands(struct gen_spec *spec, uint32_t *cmds, int size, int engine)
              gen_group_get_name(inst), reset_color);
 
       if (option_full_decode) {
-         struct gen_field_iterator iter;
-         char *token = NULL;
-         int idx = 0, dword_num = 0;
-         gen_field_iterator_init(&iter, inst, p,
-                                 option_color == COLOR_ALWAYS);
-         while (gen_field_iterator_next(&iter)) {
-            idx = 0;
-            print_dword_val(&iter, offset, &dword_num);
-            if (dword_num > 0)
-               token = print_iterator_values(&iter, &idx);
-            if (token != NULL) {
-               printf("0x%08"PRIx64":  0x%08x : Dword %d\n",
-                      offset + 4 * idx, p[idx], idx);
-               struct gen_group *struct_val =
-                  gen_spec_find_struct(spec, token);
-               decode_structure(spec, struct_val, &p[idx]);
-               token = NULL;
-            }
-         }
+         decode_group(spec, inst, p, 1, true);
 
          for (i = 0; i < ARRAY_LENGTH(custom_handlers); i++) {
             if (gen_group_get_opcode(inst) == custom_handlers[i].opcode)
-- 
2.12.0



More information about the mesa-dev mailing list