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 31static bool 32key_debug(const struct brw_compiler *c, void *log, 33 const char *name, int a, int b) 34{ 35 if (a != b) { 36 c->shader_perf_log(log, " %s %d->%d\n", name, a, b); 37 return true; 38 } 39 return false; 40} 41 42static bool 43key_debug_float(const struct brw_compiler *c, void *log, 44 const char *name, float a, float b) 45{ 46 if (a != b) { 47 c->shader_perf_log(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 58static bool 59debug_sampler_recompile(const struct brw_compiler *c, void *log, 60 const struct brw_sampler_prog_key_data *old_key, 61 const struct brw_sampler_prog_key_data *key) 62{ 63 bool found = false; 64 65 found |= check("gather channel quirk", gather_channel_quirk_mask); 66 found |= check("compressed multisample layout", 67 compressed_multisample_layout_mask); 68 found |= check("16x msaa", msaa_16); 69 found |= check("y_uv image bound", y_uv_image_mask); 70 found |= check("y_u_v image bound", y_u_v_image_mask); 71 found |= check("yx_xuxv image bound", yx_xuxv_image_mask); 72 found |= check("xy_uxvx image bound", xy_uxvx_image_mask); 73 found |= check("ayuv image bound", ayuv_image_mask); 74 found |= check("xyuv image bound", xyuv_image_mask); 75 76 for (unsigned i = 0; i < MAX_SAMPLERS; i++) { 77 found |= check("EXT_texture_swizzle or DEPTH_TEXTURE_MODE", swizzles[i]); 78 found |= check("textureGather workarounds", gen6_gather_wa[i]); 79 found |= check_float("scale factor", scale_factors[i]); 80 } 81 82 for (unsigned i = 0; i < 3; i++) { 83 found |= check("GL_CLAMP enabled on any texture unit", gl_clamp_mask[i]); 84 } 85 86 return found; 87} 88 89static void 90debug_vs_recompile(const struct brw_compiler *c, void *log, 91 const struct brw_vs_prog_key *old_key, 92 const struct brw_vs_prog_key *key) 93{ 94 bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex); 95 96 for (unsigned i = 0; i < VERT_ATTRIB_MAX; i++) { 97 found |= check("vertex attrib w/a flags", gl_attrib_wa_flags[i]); 98 } 99 100 found |= check("legacy user clipping", nr_userclip_plane_consts); 101 found |= check("copy edgeflag", copy_edgeflag); 102 found |= check("pointcoord replace", point_coord_replace); 103 found |= check("vertex color clamping", clamp_vertex_color); 104 105 if (!found) { 106 c->shader_perf_log(log, " something else\n"); 107 } 108} 109 110static void 111debug_tcs_recompile(const struct brw_compiler *c, void *log, 112 const struct brw_tcs_prog_key *old_key, 113 const struct brw_tcs_prog_key *key) 114{ 115 bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex); 116 117 found |= check("input vertices", input_vertices); 118 found |= check("outputs written", outputs_written); 119 found |= check("patch outputs written", patch_outputs_written); 120 found |= check("tes primitive mode", tes_primitive_mode); 121 found |= check("quads and equal_spacing workaround", quads_workaround); 122 123 if (!found) { 124 c->shader_perf_log(log, " something else\n"); 125 } 126} 127 128static void 129debug_tes_recompile(const struct brw_compiler *c, void *log, 130 const struct brw_tes_prog_key *old_key, 131 const struct brw_tes_prog_key *key) 132{ 133 bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex); 134 135 found |= check("inputs read", inputs_read); 136 found |= check("patch inputs read", patch_inputs_read); 137 138 if (!found) { 139 c->shader_perf_log(log, " something else\n"); 140 } 141} 142 143static void 144debug_gs_recompile(const struct brw_compiler *c, void *log, 145 const struct brw_gs_prog_key *old_key, 146 const struct brw_gs_prog_key *key) 147{ 148 bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex); 149 150 if (!found) { 151 c->shader_perf_log(log, " something else\n"); 152 } 153} 154 155static void 156debug_fs_recompile(const struct brw_compiler *c, void *log, 157 const struct brw_wm_prog_key *old_key, 158 const struct brw_wm_prog_key *key) 159{ 160 bool found = false; 161 162 found |= check("alphatest, computed depth, depth test, or depth write", 163 iz_lookup); 164 found |= check("depth statistics", stats_wm); 165 found |= check("flat shading", flat_shade); 166 found |= check("number of color buffers", nr_color_regions); 167 found |= check("MRT alpha test", alpha_test_replicate_alpha); 168 found |= check("alpha to coverage", alpha_to_coverage); 169 found |= check("fragment color clamping", clamp_fragment_color); 170 found |= check("per-sample interpolation", persample_interp); 171 found |= check("multisampled FBO", multisample_fbo); 172 found |= check("frag coord adds sample pos", frag_coord_adds_sample_pos); 173 found |= check("line smoothing", line_aa); 174 found |= check("high quality derivatives", high_quality_derivatives); 175 found |= check("force dual color blending", force_dual_color_blend); 176 found |= check("coherent fb fetch", coherent_fb_fetch); 177 178 found |= check("input slots valid", input_slots_valid); 179 found |= check("mrt alpha test function", alpha_test_func); 180 found |= check("mrt alpha test reference value", alpha_test_ref); 181 182 found |= debug_sampler_recompile(c, log, &old_key->tex, &key->tex); 183 184 if (!found) { 185 c->shader_perf_log(log, " something else\n"); 186 } 187} 188 189static void 190debug_cs_recompile(const struct brw_compiler *c, void *log, 191 const struct brw_cs_prog_key *old_key, 192 const struct brw_cs_prog_key *key) 193{ 194 bool found = debug_sampler_recompile(c, log, &old_key->tex, &key->tex); 195 196 if (!found) { 197 c->shader_perf_log(log, " something else\n"); 198 } 199} 200 201void 202brw_debug_key_recompile(const struct brw_compiler *c, void *log, 203 gl_shader_stage stage, 204 const void *old_key, const void *key) 205{ 206 if (!old_key) { 207 c->shader_perf_log(log, " No previous compile found...\n"); 208 return; 209 } 210 211 switch (stage) { 212 case MESA_SHADER_VERTEX: 213 debug_vs_recompile(c, log, old_key, key); 214 break; 215 case MESA_SHADER_TESS_CTRL: 216 debug_tcs_recompile(c, log, old_key, key); 217 break; 218 case MESA_SHADER_TESS_EVAL: 219 debug_tes_recompile(c, log, old_key, key); 220 break; 221 case MESA_SHADER_GEOMETRY: 222 debug_gs_recompile(c, log, old_key, key); 223 break; 224 case MESA_SHADER_FRAGMENT: 225 debug_fs_recompile(c, log, old_key, key); 226 break; 227 case MESA_SHADER_COMPUTE: 228 debug_cs_recompile(c, log, old_key, key); 229 break; 230 default: 231 break; 232 } 233} 234