19f464c52Smaya/*
29f464c52Smaya * Copyright © 2019 Intel Corporation
39f464c52Smaya *
49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a
59f464c52Smaya * copy of this software and associated documentation files (the "Software"),
69f464c52Smaya * to deal in the Software without restriction, including without limitation
79f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the
99f464c52Smaya * Software is furnished to do so, subject to the following conditions:
109f464c52Smaya *
119f464c52Smaya * The above copyright notice and this permission notice shall be included
129f464c52Smaya * in all copies or substantial portions of the Software.
139f464c52Smaya *
149f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
159f464c52Smaya * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
169f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
179f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
189f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
199f464c52Smaya * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
209f464c52Smaya * DEALINGS IN THE SOFTWARE.
219f464c52Smaya */
229f464c52Smaya
239f464c52Smaya/**
249f464c52Smaya * @file brw_debug_recompiles.c
259f464c52Smaya */
269f464c52Smaya
279f464c52Smaya#include <stdio.h>
289f464c52Smaya
299f464c52Smaya#include "brw_compiler.h"
309f464c52Smaya
319f464c52Smayastatic bool
329f464c52Smayakey_debug(const struct brw_compiler *c, void *log,
339f464c52Smaya          const char *name, int a, int b)
349f464c52Smaya{
359f464c52Smaya   if (a != b) {
367ec681f3Smrg      brw_shader_perf_log(c, log, "  %s %d->%d\n", name, a, b);
379f464c52Smaya      return true;
389f464c52Smaya   }
399f464c52Smaya   return false;
409f464c52Smaya}
419f464c52Smaya
429f464c52Smayastatic bool
439f464c52Smayakey_debug_float(const struct brw_compiler *c, void *log,
449f464c52Smaya                const char *name, float a, float b)
459f464c52Smaya{
469f464c52Smaya   if (a != b) {
477ec681f3Smrg      brw_shader_perf_log(c, log, "  %s %f->%f\n", name, a, b);
489f464c52Smaya      return true;
499f464c52Smaya   }
509f464c52Smaya   return false;
519f464c52Smaya}
529f464c52Smaya
539f464c52Smaya#define check(name, field) \
549f464c52Smaya   key_debug(c, log, name, old_key->field, key->field)
559f464c52Smaya#define check_float(name, field) \
569f464c52Smaya   key_debug_float(c, log, name, old_key->field, key->field)
579f464c52Smaya
589f464c52Smayastatic bool
599f464c52Smayadebug_sampler_recompile(const struct brw_compiler *c, void *log,
609f464c52Smaya                        const struct brw_sampler_prog_key_data *old_key,
619f464c52Smaya                        const struct brw_sampler_prog_key_data *key)
629f464c52Smaya{
639f464c52Smaya   bool found = false;
649f464c52Smaya
659f464c52Smaya   found |= check("gather channel quirk", gather_channel_quirk_mask);
669f464c52Smaya   found |= check("compressed multisample layout",
679f464c52Smaya                  compressed_multisample_layout_mask);
689f464c52Smaya   found |= check("16x msaa", msaa_16);
699f464c52Smaya   found |= check("y_uv image bound", y_uv_image_mask);
709f464c52Smaya   found |= check("y_u_v image bound", y_u_v_image_mask);
719f464c52Smaya   found |= check("yx_xuxv image bound", yx_xuxv_image_mask);
729f464c52Smaya   found |= check("xy_uxvx image bound", xy_uxvx_image_mask);
739f464c52Smaya   found |= check("ayuv image bound", ayuv_image_mask);
749f464c52Smaya   found |= check("xyuv image bound", xyuv_image_mask);
759f464c52Smaya
769f464c52Smaya   for (unsigned i = 0; i < MAX_SAMPLERS; i++) {
779f464c52Smaya      found |= check("EXT_texture_swizzle or DEPTH_TEXTURE_MODE", swizzles[i]);
787ec681f3Smrg      found |= check("textureGather workarounds", gfx6_gather_wa[i]);
799f464c52Smaya      found |= check_float("scale factor", scale_factors[i]);
809f464c52Smaya   }
819f464c52Smaya
829f464c52Smaya   for (unsigned i = 0; i < 3; i++) {
839f464c52Smaya      found |= check("GL_CLAMP enabled on any texture unit", gl_clamp_mask[i]);
849f464c52Smaya   }
859f464c52Smaya
869f464c52Smaya   return found;
879f464c52Smaya}
889f464c52Smaya
897ec681f3Smrgstatic bool
907ec681f3Smrgdebug_base_recompile(const struct brw_compiler *c, void *log,
917ec681f3Smrg                     const struct brw_base_prog_key *old_key,
927ec681f3Smrg                     const struct brw_base_prog_key *key)
937ec681f3Smrg{
947ec681f3Smrg   return debug_sampler_recompile(c, log, &old_key->tex, &key->tex);
957ec681f3Smrg}
967ec681f3Smrg
979f464c52Smayastatic void
989f464c52Smayadebug_vs_recompile(const struct brw_compiler *c, void *log,
999f464c52Smaya                   const struct brw_vs_prog_key *old_key,
1009f464c52Smaya                   const struct brw_vs_prog_key *key)
1019f464c52Smaya{
1027ec681f3Smrg   bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
1039f464c52Smaya
1049f464c52Smaya   for (unsigned i = 0; i < VERT_ATTRIB_MAX; i++) {
1059f464c52Smaya      found |= check("vertex attrib w/a flags", gl_attrib_wa_flags[i]);
1069f464c52Smaya   }
1079f464c52Smaya
1089f464c52Smaya   found |= check("legacy user clipping", nr_userclip_plane_consts);
1099f464c52Smaya   found |= check("copy edgeflag", copy_edgeflag);
1109f464c52Smaya   found |= check("pointcoord replace", point_coord_replace);
1119f464c52Smaya   found |= check("vertex color clamping", clamp_vertex_color);
1129f464c52Smaya
1139f464c52Smaya   if (!found) {
1147ec681f3Smrg      brw_shader_perf_log(c, log, "  something else\n");
1159f464c52Smaya   }
1169f464c52Smaya}
1179f464c52Smaya
1189f464c52Smayastatic void
1199f464c52Smayadebug_tcs_recompile(const struct brw_compiler *c, void *log,
1209f464c52Smaya                    const struct brw_tcs_prog_key *old_key,
1219f464c52Smaya                    const struct brw_tcs_prog_key *key)
1229f464c52Smaya{
1237ec681f3Smrg   bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
1249f464c52Smaya
1259f464c52Smaya   found |= check("input vertices", input_vertices);
1269f464c52Smaya   found |= check("outputs written", outputs_written);
1279f464c52Smaya   found |= check("patch outputs written", patch_outputs_written);
1289f464c52Smaya   found |= check("tes primitive mode", tes_primitive_mode);
1299f464c52Smaya   found |= check("quads and equal_spacing workaround", quads_workaround);
1309f464c52Smaya
1319f464c52Smaya   if (!found) {
1327ec681f3Smrg      brw_shader_perf_log(c, log, "  something else\n");
1339f464c52Smaya   }
1349f464c52Smaya}
1359f464c52Smaya
1369f464c52Smayastatic void
1379f464c52Smayadebug_tes_recompile(const struct brw_compiler *c, void *log,
1389f464c52Smaya                    const struct brw_tes_prog_key *old_key,
1399f464c52Smaya                    const struct brw_tes_prog_key *key)
1409f464c52Smaya{
1417ec681f3Smrg   bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
1429f464c52Smaya
1439f464c52Smaya   found |= check("inputs read", inputs_read);
1449f464c52Smaya   found |= check("patch inputs read", patch_inputs_read);
1459f464c52Smaya
1469f464c52Smaya   if (!found) {
1477ec681f3Smrg      brw_shader_perf_log(c, log, "  something else\n");
1489f464c52Smaya   }
1499f464c52Smaya}
1509f464c52Smaya
1519f464c52Smayastatic void
1529f464c52Smayadebug_gs_recompile(const struct brw_compiler *c, void *log,
1539f464c52Smaya                   const struct brw_gs_prog_key *old_key,
1549f464c52Smaya                   const struct brw_gs_prog_key *key)
1559f464c52Smaya{
1567ec681f3Smrg   bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
1579f464c52Smaya
1589f464c52Smaya   if (!found) {
1597ec681f3Smrg      brw_shader_perf_log(c, log, "  something else\n");
1609f464c52Smaya   }
1619f464c52Smaya}
1629f464c52Smaya
1639f464c52Smayastatic void
1649f464c52Smayadebug_fs_recompile(const struct brw_compiler *c, void *log,
1659f464c52Smaya                   const struct brw_wm_prog_key *old_key,
1669f464c52Smaya                   const struct brw_wm_prog_key *key)
1679f464c52Smaya{
1689f464c52Smaya   bool found = false;
1699f464c52Smaya
1709f464c52Smaya   found |= check("alphatest, computed depth, depth test, or depth write",
1719f464c52Smaya                  iz_lookup);
1729f464c52Smaya   found |= check("depth statistics", stats_wm);
1739f464c52Smaya   found |= check("flat shading", flat_shade);
1749f464c52Smaya   found |= check("number of color buffers", nr_color_regions);
1759f464c52Smaya   found |= check("MRT alpha test", alpha_test_replicate_alpha);
1769f464c52Smaya   found |= check("alpha to coverage", alpha_to_coverage);
1779f464c52Smaya   found |= check("fragment color clamping", clamp_fragment_color);
1789f464c52Smaya   found |= check("per-sample interpolation", persample_interp);
1799f464c52Smaya   found |= check("multisampled FBO", multisample_fbo);
1809f464c52Smaya   found |= check("frag coord adds sample pos", frag_coord_adds_sample_pos);
1819f464c52Smaya   found |= check("line smoothing", line_aa);
1829f464c52Smaya   found |= check("high quality derivatives", high_quality_derivatives);
1839f464c52Smaya   found |= check("force dual color blending", force_dual_color_blend);
1849f464c52Smaya   found |= check("coherent fb fetch", coherent_fb_fetch);
1859f464c52Smaya
1869f464c52Smaya   found |= check("input slots valid", input_slots_valid);
1879f464c52Smaya   found |= check("mrt alpha test function", alpha_test_func);
1889f464c52Smaya   found |= check("mrt alpha test reference value", alpha_test_ref);
1899f464c52Smaya
1907ec681f3Smrg   found |= debug_base_recompile(c, log, &old_key->base, &key->base);
1919f464c52Smaya
1929f464c52Smaya   if (!found) {
1937ec681f3Smrg      brw_shader_perf_log(c, log, "  something else\n");
1949f464c52Smaya   }
1959f464c52Smaya}
1969f464c52Smaya
1979f464c52Smayastatic void
1989f464c52Smayadebug_cs_recompile(const struct brw_compiler *c, void *log,
1999f464c52Smaya                   const struct brw_cs_prog_key *old_key,
2009f464c52Smaya                   const struct brw_cs_prog_key *key)
2019f464c52Smaya{
2027ec681f3Smrg   bool found = debug_base_recompile(c, log, &old_key->base, &key->base);
2039f464c52Smaya
2049f464c52Smaya   if (!found) {
2057ec681f3Smrg      brw_shader_perf_log(c, log, "  something else\n");
2069f464c52Smaya   }
2079f464c52Smaya}
2089f464c52Smaya
2099f464c52Smayavoid
2109f464c52Smayabrw_debug_key_recompile(const struct brw_compiler *c, void *log,
2119f464c52Smaya                        gl_shader_stage stage,
2127ec681f3Smrg                        const struct brw_base_prog_key *old_key,
2137ec681f3Smrg                        const struct brw_base_prog_key *key)
2149f464c52Smaya{
2159f464c52Smaya   if (!old_key) {
2167ec681f3Smrg      brw_shader_perf_log(c, log, "  No previous compile found...\n");
2179f464c52Smaya      return;
2189f464c52Smaya   }
2199f464c52Smaya
2209f464c52Smaya   switch (stage) {
2219f464c52Smaya   case MESA_SHADER_VERTEX:
2227ec681f3Smrg      debug_vs_recompile(c, log, (const struct brw_vs_prog_key *)old_key,
2237ec681f3Smrg                                 (const struct brw_vs_prog_key *)key);
2249f464c52Smaya      break;
2259f464c52Smaya   case MESA_SHADER_TESS_CTRL:
2267ec681f3Smrg      debug_tcs_recompile(c, log, (const struct brw_tcs_prog_key *)old_key,
2277ec681f3Smrg                                  (const struct brw_tcs_prog_key *)key);
2289f464c52Smaya      break;
2299f464c52Smaya   case MESA_SHADER_TESS_EVAL:
2307ec681f3Smrg      debug_tes_recompile(c, log, (const struct brw_tes_prog_key *)old_key,
2317ec681f3Smrg                                  (const struct brw_tes_prog_key *)key);
2329f464c52Smaya      break;
2339f464c52Smaya   case MESA_SHADER_GEOMETRY:
2347ec681f3Smrg      debug_gs_recompile(c, log, (const struct brw_gs_prog_key *)old_key,
2357ec681f3Smrg                                 (const struct brw_gs_prog_key *)key);
2369f464c52Smaya      break;
2379f464c52Smaya   case MESA_SHADER_FRAGMENT:
2387ec681f3Smrg      debug_fs_recompile(c, log, (const struct brw_wm_prog_key *)old_key,
2397ec681f3Smrg                                 (const struct brw_wm_prog_key *)key);
2409f464c52Smaya      break;
2419f464c52Smaya   case MESA_SHADER_COMPUTE:
2427ec681f3Smrg      debug_cs_recompile(c, log, (const struct brw_cs_prog_key *)old_key,
2437ec681f3Smrg                                 (const struct brw_cs_prog_key *)key);
2449f464c52Smaya      break;
2459f464c52Smaya   default:
2469f464c52Smaya      break;
2479f464c52Smaya   }
2489f464c52Smaya}
249