Mesa (main): zink: do not try to dereference null-key
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Aug 27 18:42:40 UTC 2021
Module: Mesa
Branch: main
Commit: 3fde1c42422a814bdd9ca15e02ef57888f53f378
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=3fde1c42422a814bdd9ca15e02ef57888f53f378
Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date: Thu Aug 26 00:02:11 2021 +0200
zink: do not try to dereference null-key
We can't do any of this logic if key is NULL, because that means we'll
dereference memory close to a NULL-pointer.
While we're at it, add some asserts to the zink_fs_key and zink_vs_key
functions who would otherwise be responsible for giving us invalid
non-null pointers out of null-pointers.
CID: 1475973, 1475983
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12559>
---
src/gallium/drivers/zink/zink_compiler.c | 74 ++++++++++++++---------------
src/gallium/drivers/zink/zink_shader_keys.h | 2 +
2 files changed, 39 insertions(+), 37 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index 7b436dbdb89..68d67f631e3 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -676,48 +676,48 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, nir_shad
NIR_PASS_V(nir, nir_io_add_const_offset_to_base, nir_var_shader_in |
nir_var_shader_out);
}
- }
- /* TODO: use a separate mem ctx here for ralloc */
- switch (zs->nir->info.stage) {
- case MESA_SHADER_VERTEX:
- case MESA_SHADER_TESS_EVAL:
- case MESA_SHADER_GEOMETRY:
- if (zink_vs_key(key)->last_vertex_stage) {
- if (zs->streamout.have_xfb)
- streamout = &zs->streamout;
-
- if (!zink_vs_key(key)->clip_halfz) {
- NIR_PASS_V(nir, nir_lower_clip_halfz);
+ /* TODO: use a separate mem ctx here for ralloc */
+ switch (zs->nir->info.stage) {
+ case MESA_SHADER_VERTEX:
+ case MESA_SHADER_TESS_EVAL:
+ case MESA_SHADER_GEOMETRY:
+ if (zink_vs_key(key)->last_vertex_stage) {
+ if (zs->streamout.have_xfb)
+ streamout = &zs->streamout;
+
+ if (!zink_vs_key(key)->clip_halfz) {
+ NIR_PASS_V(nir, nir_lower_clip_halfz);
+ }
+ if (zink_vs_key(key)->push_drawid) {
+ NIR_PASS_V(nir, lower_drawid);
+ }
}
- if (zink_vs_key(key)->push_drawid) {
- NIR_PASS_V(nir, lower_drawid);
+ break;
+ case MESA_SHADER_FRAGMENT:
+ if (!zink_fs_key(key)->samples &&
+ nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)) {
+ /* VK will always use gl_SampleMask[] values even if sample count is 0,
+ * so we need to skip this write here to mimic GL's behavior of ignoring it
+ */
+ nir_foreach_shader_out_variable(var, nir) {
+ if (var->data.location == FRAG_RESULT_SAMPLE_MASK)
+ var->data.mode = nir_var_shader_temp;
+ }
+ nir_fixup_deref_modes(nir);
+ NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_temp, NULL);
+ optimize_nir(nir);
}
- }
- break;
- case MESA_SHADER_FRAGMENT:
- if (!zink_fs_key(key)->samples &&
- nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)) {
- /* VK will always use gl_SampleMask[] values even if sample count is 0,
- * so we need to skip this write here to mimic GL's behavior of ignoring it
- */
- nir_foreach_shader_out_variable(var, nir) {
- if (var->data.location == FRAG_RESULT_SAMPLE_MASK)
- var->data.mode = nir_var_shader_temp;
+ if (zink_fs_key(key)->force_dual_color_blend && nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DATA1)) {
+ NIR_PASS_V(nir, lower_dual_blend);
}
- nir_fixup_deref_modes(nir);
- NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_temp, NULL);
- optimize_nir(nir);
- }
- if (zink_fs_key(key)->force_dual_color_blend && nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DATA1)) {
- NIR_PASS_V(nir, lower_dual_blend);
- }
- if (zink_fs_key(key)->coord_replace_bits) {
- NIR_PASS_V(nir, nir_lower_texcoord_replace, zink_fs_key(key)->coord_replace_bits,
- false, zink_fs_key(key)->coord_replace_yinvert);
+ if (zink_fs_key(key)->coord_replace_bits) {
+ NIR_PASS_V(nir, nir_lower_texcoord_replace, zink_fs_key(key)->coord_replace_bits,
+ false, zink_fs_key(key)->coord_replace_yinvert);
+ }
+ break;
+ default: break;
}
- break;
- default: break;
}
NIR_PASS_V(nir, nir_convert_from_ssa, true);
diff --git a/src/gallium/drivers/zink/zink_shader_keys.h b/src/gallium/drivers/zink/zink_shader_keys.h
index 867a0bff85f..110c6624642 100644
--- a/src/gallium/drivers/zink/zink_shader_keys.h
+++ b/src/gallium/drivers/zink/zink_shader_keys.h
@@ -69,12 +69,14 @@ struct zink_shader_key {
static inline const struct zink_fs_key *
zink_fs_key(const struct zink_shader_key *key)
{
+ assert(key);
return &key->key.fs;
}
static inline const struct zink_vs_key *
zink_vs_key(const struct zink_shader_key *key)
{
+ assert(key);
return &key->key.vs;
}
More information about the mesa-commit
mailing list