zink: fix legacy depth texture rewriting for single component reads
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 18 Oct 2023 16:21:02 +0000 (12:21 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 19 Oct 2023 00:09:59 +0000 (00:09 +0000)
if only a single component is read, this instruction can (and must) be
rewritten to use that component since depth sampling in vulkan is single-component

cc: mesa-stable

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

src/gallium/drivers/zink/zink_compiler.c

index 9193a93..38ff2ef 100644 (file)
@@ -3358,18 +3358,21 @@ rewrite_tex_dest(nir_builder *b, nir_tex_instr *tex, nir_variable *var, struct z
       return NULL;
    nir_def *dest = &tex->def;
    if (rewrite_depth && zs) {
-      /* 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_def_components_read(dest) & ~1) {
+         /* this needs recompiles */
          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;
       }
-      return NULL;
+      /* 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.
+       */
+      tex->def.num_components = 1;
+      tex->is_new_style_shadow = true;
    }
    if (bit_size != dest_size) {
       tex->def.bit_size = bit_size;