zink: Don't flag legacy_shadow_mask for RED-only reads in the shader.
authorEmma Anholt <emma@anholt.net>
Mon, 8 May 2023 23:37:09 +0000 (16:37 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 10 May 2023 18:37:36 +0000 (18:37 +0000)
It is very common in games to read just the .x channel of a vec4 shadow
result (since GL defaults to either LUMINANCE or RED depth mode depending
on context).  So, we can avoid shader recompiles to handle the other
components, in that case.

Fixes some recompiles in CS:GO.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22912>

src/gallium/drivers/zink/zink_compiler.c
src/gallium/drivers/zink/zink_types.h

index aa1b1a6..41a7016 100644 (file)
@@ -3367,10 +3367,17 @@ rewrite_tex_dest(nir_builder *b, nir_tex_instr *tex, nir_variable *var, struct z
       return NULL;
    nir_ssa_def *dest = &tex->dest.ssa;
    if (rewrite_depth && zs) {
-      if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
-         flag_shadow_tex(var, zs);
-      else
-         mesa_loge("unhandled old-style shadow sampler in non-fragment stage!");
+      /* If only .x is used in the NIR, then it's effectively not a legacy depth
+       * sample anyway and we don't want to ask for shader recompiles.  This is
+       * the typical path, since GL_DEPTH_TEXTURE_MODE defaults to either RED or
+       * LUMINANCE, so apps just use the first channel.
+       */
+      if (nir_ssa_def_components_read(dest) & ~1) {
+         if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
+            flag_shadow_tex(var, zs);
+         else
+            mesa_loge("unhandled old-style shadow sampler in non-fragment stage!");
+      }
       return NULL;
    }
    if (bit_size != dest_size) {
index c5a5b72..483bc3a 100644 (file)
@@ -797,7 +797,11 @@ struct zink_shader {
       } non_fs;
 
       struct {
-         uint32_t legacy_shadow_mask; //is_new_style_shadow is false for these
+         /* Bitmask of textures that have shadow sampling result components
+          * other than RED accessed. This is a subset of !is_new_style_shadow
+          * (GLSL <1.30, ARB_fp) shadow sampling usage.
+          */
+         uint32_t legacy_shadow_mask;
          nir_variable *fbfetch; //for fs output
       } fs;
    };