xref: /aosp_15_r20/external/mesa3d/src/intel/compiler/brw_debug_recompile.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2019 Intel Corporation
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, sublicense,
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 shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 /**
24  * @file
25  */
26 
27 #include <stdio.h>
28 
29 #include "brw_compiler.h"
30 
31 static bool
key_debug(const struct brw_compiler * c,void * log,const char * name,int a,int b)32 key_debug(const struct brw_compiler *c, void *log,
33           const char *name, int a, int b)
34 {
35    if (a != b) {
36       brw_shader_perf_log(c, log, "  %s %d->%d\n", name, a, b);
37       return true;
38    }
39    return false;
40 }
41 
42 static bool
key_debug_float(const struct brw_compiler * c,void * log,const char * name,float a,float b)43 key_debug_float(const struct brw_compiler *c, void *log,
44                 const char *name, float a, float b)
45 {
46    if (a != b) {
47       brw_shader_perf_log(c, log, "  %s %f->%f\n", name, a, b);
48       return true;
49    }
50    return false;
51 }
52 
53 #define check(name, field) \
54    key_debug(c, log, name, old_key->field, key->field)
55 #define check_float(name, field) \
56    key_debug_float(c, log, name, old_key->field, key->field)
57 
58 
59 static bool
debug_base_recompile(const struct brw_compiler * c,void * log,const struct brw_base_prog_key * old_key,const struct brw_base_prog_key * key)60 debug_base_recompile(const struct brw_compiler *c, void *log,
61                      const struct brw_base_prog_key *old_key,
62                      const struct brw_base_prog_key *key)
63 {
64    bool found = false;
65 
66    found |= check("robust_flags", robust_flags);
67    found |= check("limit_trig_input_range", limit_trig_input_range);
68 
69    return found;
70 }
71 
72 static void
debug_vs_recompile(const struct brw_compiler * c,void * log,const struct brw_vs_prog_key * old_key,const struct brw_vs_prog_key * key)73 debug_vs_recompile(const struct brw_compiler *c, void *log,
74                    const struct brw_vs_prog_key *old_key,
75                    const struct brw_vs_prog_key *key)
76 {
77    bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
78 
79    if (!found) {
80       brw_shader_perf_log(c, log, "  something else\n");
81    }
82 }
83 
84 static void
debug_tcs_recompile(const struct brw_compiler * c,void * log,const struct brw_tcs_prog_key * old_key,const struct brw_tcs_prog_key * key)85 debug_tcs_recompile(const struct brw_compiler *c, void *log,
86                     const struct brw_tcs_prog_key *old_key,
87                     const struct brw_tcs_prog_key *key)
88 {
89    bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
90 
91    found |= check("input vertices", input_vertices);
92    found |= check("outputs written", outputs_written);
93    found |= check("patch outputs written", patch_outputs_written);
94    found |= check("tes primitive mode", _tes_primitive_mode);
95 
96    if (!found) {
97       brw_shader_perf_log(c, log, "  something else\n");
98    }
99 }
100 
101 static void
debug_tes_recompile(const struct brw_compiler * c,void * log,const struct brw_tes_prog_key * old_key,const struct brw_tes_prog_key * key)102 debug_tes_recompile(const struct brw_compiler *c, void *log,
103                     const struct brw_tes_prog_key *old_key,
104                     const struct brw_tes_prog_key *key)
105 {
106    bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
107 
108    found |= check("inputs read", inputs_read);
109    found |= check("patch inputs read", patch_inputs_read);
110 
111    if (!found) {
112       brw_shader_perf_log(c, log, "  something else\n");
113    }
114 }
115 
116 static void
debug_gs_recompile(const struct brw_compiler * c,void * log,const struct brw_gs_prog_key * old_key,const struct brw_gs_prog_key * key)117 debug_gs_recompile(const struct brw_compiler *c, void *log,
118                    const struct brw_gs_prog_key *old_key,
119                    const struct brw_gs_prog_key *key)
120 {
121    bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
122 
123    if (!found) {
124       brw_shader_perf_log(c, log, "  something else\n");
125    }
126 }
127 
128 static void
debug_fs_recompile(const struct brw_compiler * c,void * log,const struct brw_wm_prog_key * old_key,const struct brw_wm_prog_key * key)129 debug_fs_recompile(const struct brw_compiler *c, void *log,
130                    const struct brw_wm_prog_key *old_key,
131                    const struct brw_wm_prog_key *key)
132 {
133    bool found = false;
134 
135    found |= check("flat shading", flat_shade);
136    found |= check("number of color buffers", nr_color_regions);
137    found |= check("MRT alpha test", alpha_test_replicate_alpha);
138    found |= check("alpha to coverage", alpha_to_coverage);
139    found |= check("fragment color clamping", clamp_fragment_color);
140    found |= check("per-sample interpolation", persample_interp);
141    found |= check("multisampled FBO", multisample_fbo);
142    found |= check("force dual color blending", force_dual_color_blend);
143    found |= check("coherent fb fetch", coherent_fb_fetch);
144    found |= check("ignore sample mask out", ignore_sample_mask_out);
145    found |= check("coarse pixel", coarse_pixel);
146 
147    found |= check("input slots valid", input_slots_valid);
148 
149    found |= debug_base_recompile(c, log, &old_key->base, &key->base);
150 
151    if (!found) {
152       brw_shader_perf_log(c, log, "  something else\n");
153    }
154 }
155 
156 static void
debug_cs_recompile(const struct brw_compiler * c,void * log,const struct brw_cs_prog_key * old_key,const struct brw_cs_prog_key * key)157 debug_cs_recompile(const struct brw_compiler *c, void *log,
158                    const struct brw_cs_prog_key *old_key,
159                    const struct brw_cs_prog_key *key)
160 {
161    bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
162 
163    if (!found) {
164       brw_shader_perf_log(c, log, "  something else\n");
165    }
166 }
167 
168 void
brw_debug_key_recompile(const struct brw_compiler * c,void * log,gl_shader_stage stage,const struct brw_base_prog_key * old_key,const struct brw_base_prog_key * key)169 brw_debug_key_recompile(const struct brw_compiler *c, void *log,
170                         gl_shader_stage stage,
171                         const struct brw_base_prog_key *old_key,
172                         const struct brw_base_prog_key *key)
173 {
174    if (!old_key) {
175       brw_shader_perf_log(c, log, "  No previous compile found...\n");
176       return;
177    }
178 
179    switch (stage) {
180    case MESA_SHADER_VERTEX:
181       debug_vs_recompile(c, log, (const struct brw_vs_prog_key *)old_key,
182                                  (const struct brw_vs_prog_key *)key);
183       break;
184    case MESA_SHADER_TESS_CTRL:
185       debug_tcs_recompile(c, log, (const struct brw_tcs_prog_key *)old_key,
186                                   (const struct brw_tcs_prog_key *)key);
187       break;
188    case MESA_SHADER_TESS_EVAL:
189       debug_tes_recompile(c, log, (const struct brw_tes_prog_key *)old_key,
190                                   (const struct brw_tes_prog_key *)key);
191       break;
192    case MESA_SHADER_GEOMETRY:
193       debug_gs_recompile(c, log, (const struct brw_gs_prog_key *)old_key,
194                                  (const struct brw_gs_prog_key *)key);
195       break;
196    case MESA_SHADER_FRAGMENT:
197       debug_fs_recompile(c, log, (const struct brw_wm_prog_key *)old_key,
198                                  (const struct brw_wm_prog_key *)key);
199       break;
200    case MESA_SHADER_COMPUTE:
201       debug_cs_recompile(c, log, (const struct brw_cs_prog_key *)old_key,
202                                  (const struct brw_cs_prog_key *)key);
203       break;
204    default:
205       break;
206    }
207 }
208