Mesa (master): freedreno: Remove uniform variables after finalizing NIR.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Feb 24 22:06:17 UTC 2021


Module: Mesa
Branch: master
Commit: de17b4aab568aca2fcf243bfb5871fc465b0ccee
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=de17b4aab568aca2fcf243bfb5871fc465b0ccee

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 18 14:19:38 2021 -0800

freedreno: Remove uniform variables after finalizing NIR.

mesa/st optimizes the uniform storage if you have the finalize hook in
place, causing the uniforms declared to potentially not have storage in
the ParameterValues list any more.  If you leave your uniforms around in
the NIR, then a later finalization after variant creation will re-add the
uniforms to parameters, defeating the optimization and likely reallocating
the uniform storage (causing use-after-free).  So, we have to do this
before we can start using variants in mesa/st.

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

---

 src/freedreno/ir3/ir3_nir.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c
index 9ce26829a25..35bcad20412 100644
--- a/src/freedreno/ir3/ir3_nir.c
+++ b/src/freedreno/ir3/ir3_nir.c
@@ -332,6 +332,11 @@ ir3_finalize_nir(struct ir3_compiler *compiler, nir_shader *s)
 		debug_printf("----------------------\n");
 	}
 
+	nir_foreach_uniform_variable_safe(var, s) {
+		exec_node_remove(&var->node);
+	}
+	nir_validate_shader(s, "after uniform var removal");
+
 	nir_sweep(s);
 }
 



More information about the mesa-commit mailing list