Module: Mesa
Branch: main
Commit: 9b7d4376533bd5923535cffeae5e5c5890d9d6d6
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9b7d4376533bd5923535cffeae5e5c5890d9d6d6

Author: Karmjit Mahil <[email protected]>
Date:   Mon Oct  9 10:01:05 2023 +0100

vulkan: Add `vk_subpass_dependency_is_fb_local()` helper

Some tilers check for framebuffer local dependancy to determine if
they can rearrange or merge some sub-passes without breaking
their dependencies. Adding a helper for that.

Signed-off-by: Karmjit Mahil <[email protected]>
Reviewed-by: Connor Abbott <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25612>

---

 src/vulkan/runtime/vk_render_pass.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/vulkan/runtime/vk_render_pass.h 
b/src/vulkan/runtime/vk_render_pass.h
index f5e8d114930..3c028be898c 100644
--- a/src/vulkan/runtime/vk_render_pass.h
+++ b/src/vulkan/runtime/vk_render_pass.h
@@ -399,6 +399,41 @@ vk_get_command_buffer_inheritance_as_rendering_resume(
    const VkCommandBufferBeginInfo *pBeginInfo,
    void *stack_data);
 
+/**
+ * Return true if the subpass dependency is framebuffer-local.
+ */
+static bool
+vk_subpass_dependency_is_fb_local(const VkSubpassDependency2 *dep,
+                                  VkPipelineStageFlags2 src_stage_mask,
+                                  VkPipelineStageFlags2 dst_stage_mask)
+{
+   if (dep->srcSubpass == VK_SUBPASS_EXTERNAL ||
+       dep->dstSubpass == VK_SUBPASS_EXTERNAL)
+      return true;
+
+  /* This is straight from the Vulkan 1.2 spec, section 7.1.4 "Framebuffer
+   * Region Dependencies":
+   */
+   const VkPipelineStageFlags2 framebuffer_space_stages =
+      VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT |
+      VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT |
+      VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT |
+      VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
+
+   const VkPipelineStageFlags2 src_framebuffer_space_stages = 
+      framebuffer_space_stages | VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT;
+   const VkPipelineStageFlags2 dst_framebuffer_space_stages = 
+      framebuffer_space_stages | VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT;
+
+   /* Check for frambuffer-space dependency. */
+   if ((src_stage_mask & ~src_framebuffer_space_stages) ||
+       (dst_stage_mask & ~dst_framebuffer_space_stages))
+      return false;
+
+   /* Check for framebuffer-local dependency. */
+   return dep->dependencyFlags & VK_DEPENDENCY_BY_REGION_BIT;
+}
+
 #ifdef __cplusplus
 }
 #endif

Reply via email to