1b8e80941Smrg/*
2b8e80941Smrg * Copyright © 2019 Intel Corporation
3b8e80941Smrg *
4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
6b8e80941Smrg * to deal in the Software without restriction, including without limitation
7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
9b8e80941Smrg * Software is furnished to do so, subject to the following conditions:
10b8e80941Smrg *
11b8e80941Smrg * The above copyright notice and this permission notice shall be included
12b8e80941Smrg * in all copies or substantial portions of the Software.
13b8e80941Smrg *
14b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15b8e80941Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20b8e80941Smrg * DEALINGS IN THE SOFTWARE.
21b8e80941Smrg */
22b8e80941Smrg
23b8e80941Smrg/**
24b8e80941Smrg * @file brw_debug_recompiles.c
25b8e80941Smrg */
26b8e80941Smrg
27b8e80941Smrg#include <stdio.h>
28b8e80941Smrg
29b8e80941Smrg#include "brw_compiler.h"
30b8e80941Smrg
31b8e80941Smrgstatic bool
32b8e80941Smrgkey_debug(const struct brw_compiler *c, void *log,
33b8e80941Smrg          const char *name, int a, int b)
34b8e80941Smrg{
35b8e80941Smrg   if (a != b) {
36b8e80941Smrg      c->shader_perf_log(log, "  %s %d->%d\n", name, a, b);
37b8e80941Smrg      return true;
38b8e80941Smrg   }
39b8e80941Smrg   return false;
40b8e80941Smrg}
41b8e80941Smrg
42b8e80941Smrgstatic bool
43b8e80941Smrgkey_debug_float(const struct brw_compiler *c, void *log,
44b8e80941Smrg                const char *name, float a, float b)
45b8e80941Smrg{
46b8e80941Smrg   if (a != b) {
47b8e80941Smrg      c->shader_perf_log(log, "  %s %f->%f\n", name, a, b);
48b8e80941Smrg      return true;
49b8e80941Smrg   }
50b8e80941Smrg   return false;
51b8e80941Smrg}
52b8e80941Smrg
53b8e80941Smrg#define check(name, field) \
54b8e80941Smrg   key_debug(c, log, name, old_key->field, key->field)
55b8e80941Smrg#define check_float(name, field) \
56b8e80941Smrg   key_debug_float(c, log, name, old_key->field, key->field)
57b8e80941Smrg
58b8e80941Smrgstatic bool
59b8e80941Smrgdebug_sampler_recompile(const struct brw_compiler *c, void *log,
60b8e80941Smrg                        const struct brw_sampler_prog_key_data *old_key,
61b8e80941Smrg                        const struct brw_sampler_prog_key_data *key)
62b8e80941Smrg{
63b8e80941Smrg   bool found = false;
64b8e80941Smrg
65b8e80941Smrg   found |= check("gather channel quirk", gather_channel_quirk_mask);
66b8e80941Smrg   found |= check("compressed multisample layout",
67b8e80941Smrg                  compressed_multisample_layout_mask);
68b8e80941Smrg   found |= check("16x msaa", msaa_16);
69b8e80941Smrg   found |= check("y_uv image bound", y_uv_image_mask);
70b8e80941Smrg   found |= check("y_u_v image bound", y_u_v_image_mask);
71b8e80941Smrg   found |= check("yx_xuxv image bound", yx_xuxv_image_mask);
72b8e80941Smrg   found |= check("xy_uxvx image bound", xy_uxvx_image_mask);
73b8e80941Smrg   found |= check("ayuv image bound", ayuv_image_mask);
74b8e80941Smrg   found |= check("xyuv image bound", xyuv_image_mask);
75b8e80941Smrg
76b8e80941Smrg   for (unsigned i = 0; i < MAX_SAMPLERS; i++) {
77b8e80941Smrg      found |= check("EXT_texture_swizzle or DEPTH_TEXTURE_MODE", swizzles[i]);
78b8e80941Smrg      found |= check("textureGather workarounds", gen6_gather_wa[i]);
79b8e80941Smrg      found |= check_float("scale factor", scale_factors[i]);
80b8e80941Smrg   }
81b8e80941Smrg
82b8e80941Smrg   for (unsigned i = 0; i < 3; i++) {
83b8e80941Smrg      found |= check("GL_CLAMP enabled on any texture unit", gl_clamp_mask[i]);
84b8e80941Smrg   }
85b8e80941Smrg
86b8e80941Smrg   return found;
87b8e80941Smrg}
88b8e80941Smrg
89b8e80941Smrgstatic void
90b8e80941Smrgdebug_vs_recompile(const struct brw_compiler *c, void *log,
91b8e80941Smrg                   const struct brw_vs_prog_key *old_key,
92b8e80941Smrg                   const struct brw_vs_prog_key *key)
93b8e80941Smrg{
94b8e80941Smrg   bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex);
95b8e80941Smrg
96b8e80941Smrg   for (unsigned i = 0; i < VERT_ATTRIB_MAX; i++) {
97b8e80941Smrg      found |= check("vertex attrib w/a flags", gl_attrib_wa_flags[i]);
98b8e80941Smrg   }
99b8e80941Smrg
100b8e80941Smrg   found |= check("legacy user clipping", nr_userclip_plane_consts);
101b8e80941Smrg   found |= check("copy edgeflag", copy_edgeflag);
102b8e80941Smrg   found |= check("pointcoord replace", point_coord_replace);
103b8e80941Smrg   found |= check("vertex color clamping", clamp_vertex_color);
104b8e80941Smrg
105b8e80941Smrg   if (!found) {
106b8e80941Smrg      c->shader_perf_log(log, "  something else\n");
107b8e80941Smrg   }
108b8e80941Smrg}
109b8e80941Smrg
110b8e80941Smrgstatic void
111b8e80941Smrgdebug_tcs_recompile(const struct brw_compiler *c, void *log,
112b8e80941Smrg                    const struct brw_tcs_prog_key *old_key,
113b8e80941Smrg                    const struct brw_tcs_prog_key *key)
114b8e80941Smrg{
115b8e80941Smrg   bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex);
116b8e80941Smrg
117b8e80941Smrg   found |= check("input vertices", input_vertices);
118b8e80941Smrg   found |= check("outputs written", outputs_written);
119b8e80941Smrg   found |= check("patch outputs written", patch_outputs_written);
120b8e80941Smrg   found |= check("tes primitive mode", tes_primitive_mode);
121b8e80941Smrg   found |= check("quads and equal_spacing workaround", quads_workaround);
122b8e80941Smrg
123b8e80941Smrg   if (!found) {
124b8e80941Smrg      c->shader_perf_log(log, "  something else\n");
125b8e80941Smrg   }
126b8e80941Smrg}
127b8e80941Smrg
128b8e80941Smrgstatic void
129b8e80941Smrgdebug_tes_recompile(const struct brw_compiler *c, void *log,
130b8e80941Smrg                    const struct brw_tes_prog_key *old_key,
131b8e80941Smrg                    const struct brw_tes_prog_key *key)
132b8e80941Smrg{
133b8e80941Smrg   bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex);
134b8e80941Smrg
135b8e80941Smrg   found |= check("inputs read", inputs_read);
136b8e80941Smrg   found |= check("patch inputs read", patch_inputs_read);
137b8e80941Smrg
138b8e80941Smrg   if (!found) {
139b8e80941Smrg      c->shader_perf_log(log, "  something else\n");
140b8e80941Smrg   }
141b8e80941Smrg}
142b8e80941Smrg
143b8e80941Smrgstatic void
144b8e80941Smrgdebug_gs_recompile(const struct brw_compiler *c, void *log,
145b8e80941Smrg                   const struct brw_gs_prog_key *old_key,
146b8e80941Smrg                   const struct brw_gs_prog_key *key)
147b8e80941Smrg{
148b8e80941Smrg   bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex);
149b8e80941Smrg
150b8e80941Smrg   if (!found) {
151b8e80941Smrg      c->shader_perf_log(log, "  something else\n");
152b8e80941Smrg   }
153b8e80941Smrg}
154b8e80941Smrg
155b8e80941Smrgstatic void
156b8e80941Smrgdebug_fs_recompile(const struct brw_compiler *c, void *log,
157b8e80941Smrg                   const struct brw_wm_prog_key *old_key,
158b8e80941Smrg                   const struct brw_wm_prog_key *key)
159b8e80941Smrg{
160b8e80941Smrg   bool found = false;
161b8e80941Smrg
162b8e80941Smrg   found |= check("alphatest, computed depth, depth test, or depth write",
163b8e80941Smrg                  iz_lookup);
164b8e80941Smrg   found |= check("depth statistics", stats_wm);
165b8e80941Smrg   found |= check("flat shading", flat_shade);
166b8e80941Smrg   found |= check("number of color buffers", nr_color_regions);
167b8e80941Smrg   found |= check("MRT alpha test", alpha_test_replicate_alpha);
168b8e80941Smrg   found |= check("alpha to coverage", alpha_to_coverage);
169b8e80941Smrg   found |= check("fragment color clamping", clamp_fragment_color);
170b8e80941Smrg   found |= check("per-sample interpolation", persample_interp);
171b8e80941Smrg   found |= check("multisampled FBO", multisample_fbo);
172b8e80941Smrg   found |= check("frag coord adds sample pos", frag_coord_adds_sample_pos);
173b8e80941Smrg   found |= check("line smoothing", line_aa);
174b8e80941Smrg   found |= check("high quality derivatives", high_quality_derivatives);
175b8e80941Smrg   found |= check("force dual color blending", force_dual_color_blend);
176b8e80941Smrg   found |= check("coherent fb fetch", coherent_fb_fetch);
177b8e80941Smrg
178b8e80941Smrg   found |= check("input slots valid", input_slots_valid);
179b8e80941Smrg   found |= check("mrt alpha test function", alpha_test_func);
180b8e80941Smrg   found |= check("mrt alpha test reference value", alpha_test_ref);
181b8e80941Smrg
182b8e80941Smrg   found |= debug_sampler_recompile(c, log, &old_key->tex, &key->tex);
183b8e80941Smrg
184b8e80941Smrg   if (!found) {
185b8e80941Smrg      c->shader_perf_log(log, "  something else\n");
186b8e80941Smrg   }
187b8e80941Smrg}
188b8e80941Smrg
189b8e80941Smrgstatic void
190b8e80941Smrgdebug_cs_recompile(const struct brw_compiler *c, void *log,
191b8e80941Smrg                   const struct brw_cs_prog_key *old_key,
192b8e80941Smrg                   const struct brw_cs_prog_key *key)
193b8e80941Smrg{
194b8e80941Smrg   bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex);
195b8e80941Smrg
196b8e80941Smrg   if (!found) {
197b8e80941Smrg      c->shader_perf_log(log, "  something else\n");
198b8e80941Smrg   }
199b8e80941Smrg}
200b8e80941Smrg
201b8e80941Smrgvoid
202b8e80941Smrgbrw_debug_key_recompile(const struct brw_compiler *c, void *log,
203b8e80941Smrg                        gl_shader_stage stage,
204b8e80941Smrg                        const void *old_key, const void *key)
205b8e80941Smrg{
206b8e80941Smrg   if (!old_key) {
207b8e80941Smrg      c->shader_perf_log(log, "  No previous compile found...\n");
208b8e80941Smrg      return;
209b8e80941Smrg   }
210b8e80941Smrg
211b8e80941Smrg   switch (stage) {
212b8e80941Smrg   case MESA_SHADER_VERTEX:
213b8e80941Smrg      debug_vs_recompile(c, log, old_key, key);
214b8e80941Smrg      break;
215b8e80941Smrg   case MESA_SHADER_TESS_CTRL:
216b8e80941Smrg      debug_tcs_recompile(c, log, old_key, key);
217b8e80941Smrg      break;
218b8e80941Smrg   case MESA_SHADER_TESS_EVAL:
219b8e80941Smrg      debug_tes_recompile(c, log, old_key, key);
220b8e80941Smrg      break;
221b8e80941Smrg   case MESA_SHADER_GEOMETRY:
222b8e80941Smrg      debug_gs_recompile(c, log, old_key, key);
223b8e80941Smrg      break;
224b8e80941Smrg   case MESA_SHADER_FRAGMENT:
225b8e80941Smrg      debug_fs_recompile(c, log, old_key, key);
226b8e80941Smrg      break;
227b8e80941Smrg   case MESA_SHADER_COMPUTE:
228b8e80941Smrg      debug_cs_recompile(c, log, old_key, key);
229b8e80941Smrg      break;
230b8e80941Smrg   default:
231b8e80941Smrg      break;
232b8e80941Smrg   }
233b8e80941Smrg}
234