xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/etnaviv/etnaviv_debug.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (c) 2012-2013 Etnaviv Project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sub license,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 /* Common debug stuffl */
25 #ifndef H_ETNA_DEBUG
26 #define H_ETNA_DEBUG
27 
28 #include "util/u_debug.h"
29 #include "util/log.h"
30 #include "util/macros.h"
31 
32 #include <stdint.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 
36 enum etna_dbg {
37    /* Logging */
38    ETNA_DBG_MSGS            = BITFIELD_BIT(0), /* Warnings and non-fatal errors */
39    ETNA_DBG_FRAME_MSGS      = BITFIELD_BIT(1),
40    ETNA_DBG_RESOURCE_MSGS   = BITFIELD_BIT(2),
41    ETNA_DBG_COMPILER_MSGS   = BITFIELD_BIT(3),
42    ETNA_DBG_LINKER_MSGS     = BITFIELD_BIT(4),
43    ETNA_DBG_DUMP_SHADERS    = BITFIELD_BIT(5),
44    ETNA_DRM_MSGS            = BITFIELD_BIT(6), /* Debug messages from DRM */
45    ETNA_DBG_PERF            = BITFIELD_BIT(7),
46    ETNA_DBG_ML_MSGS         = BITFIELD_BIT(8),
47 
48    /* Bypasses */
49    ETNA_DBG_NO_TS           = BITFIELD_BIT(12), /* Disable TS */
50    ETNA_DBG_NO_AUTODISABLE  = BITFIELD_BIT(13), /* Disable autodisable */
51    ETNA_DBG_NO_SUPERTILE    = BITFIELD_BIT(14), /* Disable supertile */
52    ETNA_DBG_NO_EARLY_Z      = BITFIELD_BIT(15), /* Disable early z */
53    ETNA_DBG_CFLUSH_ALL      = BITFIELD_BIT(16), /* Flush before every state update + draw call */
54    ETNA_DBG_FINISH_ALL      = BITFIELD_BIT(17), /* Finish on every flush */
55    ETNA_DBG_FLUSH_ALL       = BITFIELD_BIT(18), /* Flush after every rendered primitive */
56    ETNA_DBG_ZERO            = BITFIELD_BIT(19), /* Zero all resources after allocation */
57    ETNA_DBG_DRAW_STALL      = BITFIELD_BIT(20), /* Stall FE/PE after every draw op */
58    ETNA_DBG_SHADERDB        = BITFIELD_BIT(21), /* dump program compile information */
59    ETNA_DBG_NO_SINGLEBUF    = BITFIELD_BIT(22), /* disable single buffer feature */
60    ETNA_DBG_DEQP            = BITFIELD_BIT(23), /* Hacks to run dEQP GLES3 tests */
61    ETNA_DBG_NOCACHE         = BITFIELD_BIT(24), /* Disable shader cache */
62    ETNA_DBG_LINEAR_PE       = BITFIELD_BIT(25), /* Enable linear PE */
63    ETNA_DBG_NO_MSAA         = BITFIELD_BIT(26), /* Disable MSAA */
64    ETNA_DBG_SHARED_TS       = BITFIELD_BIT(27), /* Enable TS sharing */
65    ETNA_DBG_NPU_PARALLEL    = BITFIELD_BIT(28), /* Enable parallelism inside NPU batches (unsafe) */
66    ETNA_DBG_NPU_NO_BATCHING = BITFIELD_BIT(29), /* Disable batching NPU jobs */
67 };
68 
69 extern int etna_mesa_debug; /* set in etnaviv_screen.c from ETNA_MESA_DEBUG */
70 
71 #define DBG_ENABLED(flag) unlikely(etna_mesa_debug & (flag))
72 
73 #define DBG_F(flag, fmt, ...)                             \
74    do {                                                   \
75       if (DBG_ENABLED(flag))                              \
76          mesa_logd("%s:%d: " fmt, __func__, __LINE__,     \
77                    ##__VA_ARGS__);                        \
78    } while (0)
79 
80 #define DBG(fmt, ...)                                     \
81    do {                                                   \
82       if (DBG_ENABLED(ETNA_DBG_MSGS))                     \
83          mesa_logd("%s:%d: " fmt, __func__, __LINE__,     \
84                    ##__VA_ARGS__);                        \
85    } while (0)
86 
87 /* A serious bug, show this even in non-debug mode */
88 #define BUG(fmt, ...)                                                  \
89    do {                                                                \
90       mesa_loge("%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__);     \
91    } while (0)
92 
93 #define perf_debug_message(debug, type, ...)                           \
94    do {                                                                \
95       if (DBG_ENABLED(ETNA_DBG_PERF))                                  \
96          mesa_logw(__VA_ARGS__);                                       \
97       struct util_debug_callback *__d = (debug);                       \
98       if (__d)                                                         \
99          util_debug_message(__d, type, __VA_ARGS__);                   \
100    } while (0)
101 
102 #define perf_debug_ctx(ctx, ...)                                                 \
103    do {                                                                          \
104       struct etna_context *__c = (ctx);                                          \
105       perf_debug_message(__c ? &__c->base.debug : NULL, PERF_INFO, __VA_ARGS__); \
106    } while (0)
107 
108 #define perf_debug(...) perf_debug_ctx(NULL, PERF_INFO, __VA_ARGS__)
109 
110 #endif
111