• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 brw_debug_recompiles.c
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("line smoothing", line_aa);
143    found |= check("force dual color blending", force_dual_color_blend);
144    found |= check("coherent fb fetch", coherent_fb_fetch);
145    found |= check("ignore sample mask out", ignore_sample_mask_out);
146    found |= check("coarse pixel", coarse_pixel);
147 
148    found |= check("input slots valid", input_slots_valid);
149 
150    found |= debug_base_recompile(c, log, &old_key->base, &key->base);
151 
152    if (!found) {
153       brw_shader_perf_log(c, log, "  something else\n");
154    }
155 }
156 
157 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)158 debug_cs_recompile(const struct brw_compiler *c, void *log,
159                    const struct brw_cs_prog_key *old_key,
160                    const struct brw_cs_prog_key *key)
161 {
162    bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
163 
164    if (!found) {
165       brw_shader_perf_log(c, log, "  something else\n");
166    }
167 }
168 
169 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)170 brw_debug_key_recompile(const struct brw_compiler *c, void *log,
171                         gl_shader_stage stage,
172                         const struct brw_base_prog_key *old_key,
173                         const struct brw_base_prog_key *key)
174 {
175    if (!old_key) {
176       brw_shader_perf_log(c, log, "  No previous compile found...\n");
177       return;
178    }
179 
180    switch (stage) {
181    case MESA_SHADER_VERTEX:
182       debug_vs_recompile(c, log, (const struct brw_vs_prog_key *)old_key,
183                                  (const struct brw_vs_prog_key *)key);
184       break;
185    case MESA_SHADER_TESS_CTRL:
186       debug_tcs_recompile(c, log, (const struct brw_tcs_prog_key *)old_key,
187                                   (const struct brw_tcs_prog_key *)key);
188       break;
189    case MESA_SHADER_TESS_EVAL:
190       debug_tes_recompile(c, log, (const struct brw_tes_prog_key *)old_key,
191                                   (const struct brw_tes_prog_key *)key);
192       break;
193    case MESA_SHADER_GEOMETRY:
194       debug_gs_recompile(c, log, (const struct brw_gs_prog_key *)old_key,
195                                  (const struct brw_gs_prog_key *)key);
196       break;
197    case MESA_SHADER_FRAGMENT:
198       debug_fs_recompile(c, log, (const struct brw_wm_prog_key *)old_key,
199                                  (const struct brw_wm_prog_key *)key);
200       break;
201    case MESA_SHADER_COMPUTE:
202       debug_cs_recompile(c, log, (const struct brw_cs_prog_key *)old_key,
203                                  (const struct brw_cs_prog_key *)key);
204       break;
205    default:
206       break;
207    }
208 }
209