Mesa (staging/22.0): anv: Handle the null FS optimization after compiling shaders

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 1 20:58:19 UTC 2022


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

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Fri May 13 17:06:50 2022 -0500

anv: Handle the null FS optimization after compiling shaders

Actually compile and cache the no-op fragment shader but remove it from
the pipeline if we determine it's a no-op.  This way we always have it
even if it's not strictly needed.

Fixes: 36ee2fd61c8f ("anv: Implement the basic form of VK_EXT_transform_feedback")
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16506>
(cherry picked from commit 73b3efcd59ade6b9dc8c4cce994d7fbe5c1f0cac)

---

 .pick_status.json               |  2 +-
 src/intel/vulkan/anv_pipeline.c | 39 ++++++++++++++++-----------------------
 2 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index c59919d7edd..8b331b9bd43 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1412,7 +1412,7 @@
         "description": "anv: Handle the null FS optimization after compiling shaders",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "because_sha": "36ee2fd61c8f943be1d1e2b0354f7a121ffef28f"
     },
     {
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 7c4bb052a43..c3fa0b1ecab 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -1352,20 +1352,6 @@ anv_pipeline_compile_fs(const struct brw_compiler *compiler,
    fs_stage->num_stats = (uint32_t)fs_stage->prog_data.wm.dispatch_8 +
                          (uint32_t)fs_stage->prog_data.wm.dispatch_16 +
                          (uint32_t)fs_stage->prog_data.wm.dispatch_32;
-
-   if (fs_stage->key.wm.color_outputs_valid == 0 &&
-       !fs_stage->prog_data.wm.has_side_effects &&
-       !fs_stage->prog_data.wm.uses_omask &&
-       !fs_stage->prog_data.wm.uses_kill &&
-       fs_stage->prog_data.wm.computed_depth_mode == BRW_PSCDEPTH_OFF &&
-       !fs_stage->prog_data.wm.computed_stencil) {
-      /* This fragment shader has no outputs and no side effects.  Go ahead
-       * and return the code pointer so we don't accidentally think the
-       * compile failed but zero out prog_data which will set program_size to
-       * zero and disable the stage.
-       */
-      memset(&fs_stage->prog_data, 0, sizeof(fs_stage->prog_data));
-   }
 }
 
 static void
@@ -2014,15 +2000,22 @@ anv_pipeline_compile_graphics(struct anv_graphics_pipeline *pipeline,
 
 done:
 
-   if (pipeline->shaders[MESA_SHADER_FRAGMENT] &&
-       pipeline->shaders[MESA_SHADER_FRAGMENT]->prog_data->program_size == 0) {
-      /* This can happen if we decided to implicitly disable the fragment
-       * shader.  See anv_pipeline_compile_fs().
-       */
-      anv_shader_bin_unref(pipeline->base.device,
-                           pipeline->shaders[MESA_SHADER_FRAGMENT]);
-      pipeline->shaders[MESA_SHADER_FRAGMENT] = NULL;
-      pipeline->active_stages &= ~VK_SHADER_STAGE_FRAGMENT_BIT;
+   if (pipeline->shaders[MESA_SHADER_FRAGMENT] != NULL) {
+      const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
+      if (wm_prog_data->color_outputs_written == 0 &&
+          !wm_prog_data->has_side_effects &&
+          !wm_prog_data->uses_omask &&
+          !wm_prog_data->uses_kill &&
+          wm_prog_data->computed_depth_mode == BRW_PSCDEPTH_OFF &&
+          !wm_prog_data->computed_stencil) {
+         /* This can happen if we decided to implicitly disable the fragment
+          * shader.  See anv_pipeline_compile_fs().
+          */
+         anv_shader_bin_unref(pipeline->base.device,
+                              pipeline->shaders[MESA_SHADER_FRAGMENT]);
+         pipeline->shaders[MESA_SHADER_FRAGMENT] = NULL;
+         pipeline->active_stages &= ~VK_SHADER_STAGE_FRAGMENT_BIT;
+      }
    }
 
    pipeline_feedback.duration = os_time_get_nano() - pipeline_start;



More information about the mesa-commit mailing list