Module: Mesa
Branch: main
Commit: c01ac4b58367718130681b464be835e670d8b700
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c01ac4b58367718130681b464be835e670d8b700

Author: Rob Clark <[email protected]>
Date:   Fri Nov  4 15:07:40 2022 -0700

freedreno/cffdec: Add helper to find next pkt

Signed-off-by: Rob Clark <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19551>

---

 src/freedreno/.gitlab-ci/reference/crash.log |  2 ++
 src/freedreno/decode/cffdec.c                | 10 ++--------
 src/freedreno/decode/cffdec.h                | 16 ++++++++++++++++
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/freedreno/.gitlab-ci/reference/crash.log 
b/src/freedreno/.gitlab-ci/reference/crash.log
index 2b1a08e9d4e..098aed2d504 100644
--- a/src/freedreno/.gitlab-ci/reference/crash.log
+++ b/src/freedreno/.gitlab-ci/reference/crash.log
@@ -1703,6 +1703,8 @@ got cmdszdw=27
 bad type! deadd00d
                        opcode: CP_NOP (10) (1 dwords)
 ESTIMATED CRASH LOCATION!
+000000010000001c:                      0000: 70108000
+                       opcode: CP_NOP (10) (1 dwords)
 0000000100000020:                      0000: 70108000
                        opcode: CP_NOP (10) (1 dwords)
 0000000100000024:                      0000: 70108000
diff --git a/src/freedreno/decode/cffdec.c b/src/freedreno/decode/cffdec.c
index c9dfa2c0ea3..69749904e06 100644
--- a/src/freedreno/decode/cffdec.c
+++ b/src/freedreno/decode/cffdec.c
@@ -2899,18 +2899,12 @@ dump_commands(uint32_t *dwords, uint32_t sizedwords, 
int level)
          printl(3, "%snop\n", levels[level + 1]);
          count = 1;
       } else {
+         printf("bad type! %08x\n", dwords[0]);
          /* for 5xx+ we can do a passable job of looking for start of next 
valid
           * packet: */
          if (options->gpu_id >= 500) {
-            while (dwords_left > 0) {
-               if (pkt_is_type7(dwords[0]) || pkt_is_type4(dwords[0]))
-                  break;
-               printf("bad type! %08x\n", dwords[0]);
-               dwords++;
-               dwords_left--;
-            }
+            count = find_next_packet(dwords, dwords_left);
          } else {
-            printf("bad type! %08x\n", dwords[0]);
             return;
          }
       }
diff --git a/src/freedreno/decode/cffdec.h b/src/freedreno/decode/cffdec.h
index 3c96562aedb..055462a793b 100644
--- a/src/freedreno/decode/cffdec.h
+++ b/src/freedreno/decode/cffdec.h
@@ -158,4 +158,20 @@ pkt_is_opcode(uint32_t dword, uint32_t *opcode, uint32_t 
*size)
    return false;
 }
 
+/**
+ * For a5xx+ we can detect valid packet headers vs random other noise, and
+ * can use this to "re-sync" to the start of the next valid packet.  So that
+ * the same cmdstream corruption that confused the GPU doesn't confuse us!
+ */
+static inline uint32_t
+find_next_packet(uint32_t *dwords, uint32_t sizedwords)
+{
+   for (uint32_t c = 0; c < sizedwords; c++) {
+      if (pkt_is_type7(dwords[c]) || pkt_is_type4(dwords[c]))
+         return c;
+   }
+   return sizedwords;
+}
+
+
 #endif /* __CFFDEC_H__ */

Reply via email to