Mesa (staging/22.1): lavapipe: ignore depth/stencil states if attachment is not present

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue May 17 17:29:03 UTC 2022


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Thu May 12 11:43:51 2022 -0400

lavapipe: ignore depth/stencil states if attachment is not present

depth and stencil states should only be set if the corresponding attachment
is present, otherwise they should be ignored. this is different from
ignoring the entire VkPipelineDepthStencilStateCreateInfo struct, as
it's possible that only depth or only stencil may be present

cc: mesa-stable

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16457>
(cherry picked from commit 0b2d383316af7efa6f970db5b8517a55a32dedf2)

---

 .pick_status.json                             |  2 +-
 src/gallium/frontends/lavapipe/lvp_pipeline.c | 38 +++++++++++++++++++++------
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index f955885e89e..88b5be3aec3 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -553,7 +553,7 @@
         "description": "lavapipe: ignore depth/stencil states if attachment is not present",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c b/src/gallium/frontends/lavapipe/lvp_pipeline.c
index 2b1b6b34010..cb0e02d54dd 100644
--- a/src/gallium/frontends/lavapipe/lvp_pipeline.c
+++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c
@@ -242,7 +242,8 @@ static VkResult
 deep_copy_dynamic_state(void *mem_ctx,
                         VkPipelineDynamicStateCreateInfo *dst,
                         const VkPipelineDynamicStateCreateInfo *src,
-                        VkGraphicsPipelineLibraryFlagsEXT stages)
+                        VkGraphicsPipelineLibraryFlagsEXT stages,
+                        bool has_depth, bool has_stencil)
 {
    dst->sType = src->sType;
    dst->pNext = NULL;
@@ -274,17 +275,21 @@ deep_copy_dynamic_state(void *mem_ctx,
 
       case VK_DYNAMIC_STATE_DEPTH_BIAS:
       case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
-      case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
-      case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
-      case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
       case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT:
       case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT:
       case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT:
       case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT:
       case VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE_EXT:
+         if (has_depth && (stages & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT))
+            states[dst->dynamicStateCount++] = src->pDynamicStates[i];
+         break;
+
+      case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
+      case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
+      case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
       case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT:
       case VK_DYNAMIC_STATE_STENCIL_OP_EXT:
-         if (stages & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT)
+         if (has_stencil && (stages & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT))
             states[dst->dynamicStateCount++] = src->pDynamicStates[i];
          break;
 
@@ -355,6 +360,12 @@ deep_copy_graphics_create_info(void *mem_ctx,
       dst->renderPass = src->renderPass;
       rp_info = vk_get_pipeline_rendering_create_info(src);
    }
+   bool has_depth = false;
+   bool has_stencil = false;
+   if (rp_info) {
+      has_depth = rp_info->depthAttachmentFormat != VK_FORMAT_UNDEFINED;
+      has_stencil = rp_info->stencilAttachmentFormat != VK_FORMAT_UNDEFINED;
+   }
    dst->basePipelineHandle = src->basePipelineHandle;
    dst->basePipelineIndex = src->basePipelineIndex;
 
@@ -440,12 +451,23 @@ deep_copy_graphics_create_info(void *mem_ctx,
       assert(rp_info);
       /* pDepthStencilState */
       if (src->pDepthStencilState && !rasterization_disabled &&
-          (rp_info->depthAttachmentFormat != VK_FORMAT_UNDEFINED ||
-           rp_info->stencilAttachmentFormat != VK_FORMAT_UNDEFINED)) {
+          (has_depth || has_stencil)) {
          LVP_PIPELINE_DUP(dst->pDepthStencilState,
                           src->pDepthStencilState,
                           VkPipelineDepthStencilStateCreateInfo,
                           1);
+         VkPipelineDepthStencilStateCreateInfo *pDepthStencilState = (void*)dst->pDepthStencilState;
+         if (!has_depth) {
+            pDepthStencilState->depthTestEnable = VK_FALSE;
+            pDepthStencilState->depthWriteEnable = VK_FALSE;
+            pDepthStencilState->depthCompareOp = VK_COMPARE_OP_ALWAYS;
+            pDepthStencilState->depthBoundsTestEnable = VK_FALSE;
+         }
+         if (!has_stencil) {
+            pDepthStencilState->stencilTestEnable = VK_FALSE;
+            memset(&pDepthStencilState->front, 0, sizeof(VkStencilOpState));
+            memset(&pDepthStencilState->back, 0, sizeof(VkStencilOpState));
+         }
       } else
          dst->pDepthStencilState = NULL;
    }
@@ -517,7 +539,7 @@ deep_copy_graphics_create_info(void *mem_ctx,
       }
       if (!dyn_state || !dyn_state->pDynamicStates)
          return VK_ERROR_OUT_OF_HOST_MEMORY;
-      deep_copy_dynamic_state(mem_ctx, dyn_state, src->pDynamicState, shaders);
+      deep_copy_dynamic_state(mem_ctx, dyn_state, src->pDynamicState, shaders, has_depth, has_stencil);
       dst->pDynamicState = dyn_state;
    } else
       dst->pDynamicState = NULL;



More information about the mesa-commit mailing list