From 9ff1f30d4508b44795f80b1ca2ec4dc833ac4e77 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Jun 2022 15:50:53 -0700 Subject: [PATCH] anv: Remove FS executables when applying the null FS optimization If the executables are still hanging out, anv_GetPipelineExecutableStatisticsKHR will try to dereference NULL pointers in pipeline->shaders[MESA_SHADER_FRAGMENT]. At least in terms of fossil-db output, this matches the behavior from before 73b3efcd59a. Fixes: 73b3efcd59a ("anv: Handle the null FS optimization after compiling shaders") Closes: #6590 Reviewed-by: Lionel Landwerlin Reviewed-by: Jason Ekstrand Part-of: (cherry picked from commit 65d6708bc33694b662d1195fd65842b85b7afc99) --- .pick_status.json | 2 +- src/intel/vulkan/anv_pipeline.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 49073cda8ed..1ab54e97a2d 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1147,7 +1147,7 @@ "description": "anv: Remove FS executables when applying the null FS optimization", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "73b3efcd59ade6b9dc8c4cce994d7fbe5c1f0cac" }, diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 51fc1c774aa..95bc1fe3c54 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -1868,6 +1868,25 @@ done: anv_shader_bin_unref(pipeline->base.device, fs); pipeline->shaders[MESA_SHADER_FRAGMENT] = NULL; pipeline->active_stages &= ~VK_SHADER_STAGE_FRAGMENT_BIT; + + /* The per-SIMD size fragment shaders should be last in the + * executables array. Remove all of them. + */ + ASSERTED unsigned removed = 0; + + util_dynarray_foreach_reverse(&pipeline->base.executables, + struct anv_pipeline_executable, + tail) { + /* There must be at least one fragment shader. */ + assert(removed > 0 || tail->stage == MESA_SHADER_FRAGMENT); + + if (tail->stage != MESA_SHADER_FRAGMENT) + break; + + (void) util_dynarray_pop(&pipeline->base.executables, + struct anv_pipeline_executable); + removed++; + } } }