summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmma Anholt <emma@anholt.net>2023-05-08 16:37:09 -0700
committerMarge Bot <emma+marge@anholt.net>2023-05-10 18:37:36 +0000
commitdeb064d98ddd7ee38b5dc3bc11f4ccf81b848461 (patch)
tree7c420d8a8b6b6898eb9f959e848f17605c07cc33
parentdd426964124313d94fe038618bbade902f1fc4a3 (diff)
zink: Don't flag legacy_shadow_mask for RED-only reads in the shader.
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>
-rw-r--r--src/gallium/drivers/zink/zink_compiler.c15
-rw-r--r--src/gallium/drivers/zink/zink_types.h6
2 files changed, 16 insertions, 5 deletions
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index aa1b1a6509c..41a7016e1bf 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -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) {
diff --git a/src/gallium/drivers/zink/zink_types.h b/src/gallium/drivers/zink/zink_types.h
index c5a5b72e104..483bc3af160 100644
--- a/src/gallium/drivers/zink/zink_types.h
+++ b/src/gallium/drivers/zink/zink_types.h
@@ -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;
};