Module: Mesa
Branch: staging/22.1
Commit: a8a4f91d0980acc9a49717dd1343a2313b6321d9
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a8a4f91d0980acc9a49717dd1343a2313b6321d9

Author: Charmaine Lee <[email protected]>
Date:   Mon Aug  8 18:02:30 2022 -0700

mesa/st: fix reference to nir->info after nir_to_tgsi

The nir shader memory is freed in nir_to_tgsi(), but the already
freed shader info is referenced later when create compute state.
To avoid referencing the freed memory, copy the shader info first before
calling nir_to_tgsi.

Fixes vmx crash running aztec on SVGA driver.
Fixes: 580f1ac4736 ("nir: Extract shader_info->cs.shared_size out of union")

Reviewed-by: Roland Scheidegger <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17999>
(cherry picked from commit 4393be8291ff3f39ff37a61133b6e5b0fa3e9698)

---

 .pick_status.json                   | 4 ++--
 src/mesa/state_tracker/st_program.c | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 8e473cac970..1465844f9c5 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -400,7 +400,7 @@
         "description": "mesa/st: fix reference to nir->info after nir_to_tgsi",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "580f1ac4736eec90e2e7dbe67ba76cac4d0e5319"
     },
@@ -8320,7 +8320,7 @@
         "description": "panfrost: Clear the GENERAL varying buffer field if 
unused",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "2e6d94c198e4d10c82ed3ffd59e85f460bd58950"
     },
diff --git a/src/mesa/state_tracker/st_program.c 
b/src/mesa/state_tracker/st_program.c
index 46b44550a86..b27a73bc649 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -514,6 +514,7 @@ st_create_nir_shader(struct st_context *st, struct 
pipe_shader_state *state)
 
    assert(state->type == PIPE_SHADER_IR_NIR);
    nir_shader *nir = state->ir.nir;
+   struct shader_info info = nir->info;
    gl_shader_stage stage = nir->info.stage;
    enum pipe_shader_type sh = pipe_shader_type_from_mesa(stage);
 
@@ -560,7 +561,7 @@ st_create_nir_shader(struct st_context *st, struct 
pipe_shader_state *state)
    case MESA_SHADER_COMPUTE: {
       struct pipe_compute_state cs = {0};
       cs.ir_type = state->type;
-      cs.req_local_mem = nir->info.shared_size;
+      cs.req_local_mem = info.shared_size;
 
       if (state->type == PIPE_SHADER_IR_NIR)
          cs.prog = state->ir.nir;

Reply via email to