vk: Add func anv_cmd_buffer_get_depth_stencil_view()
authorChad Versace <chad.versace@intel.com>
Fri, 28 Aug 2015 14:57:34 +0000 (07:57 -0700)
committerChad Versace <chad.versace@intel.com>
Fri, 28 Aug 2015 14:57:34 +0000 (07:57 -0700)
This function removes some duplicated code from
genN_cmd_buffer_emit_depth_stencil().

src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_private.h
src/vulkan/gen7_cmd_buffer.c
src/vulkan/gen8_cmd_buffer.c

index 963edcf06ca200acff825290918ab327f7a4a525..f8a630bece5c1d7d2f561d5561fb948f68c29b03 100644 (file)
@@ -783,3 +783,23 @@ VkResult anv_ResetCommandPool(
 
    return VK_SUCCESS;
 }
+
+/**
+ * Return NULL if the current subpass has no depthstencil attachment.
+ */
+const struct anv_depth_stencil_view *
+anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer)
+{
+   const struct anv_subpass *subpass = cmd_buffer->state.subpass;
+   const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
+
+   if (subpass->depth_stencil_attachment == VK_ATTACHMENT_UNUSED)
+      return NULL;
+
+   const struct anv_attachment_view *aview =
+      fb->attachments[subpass->depth_stencil_attachment];
+
+   assert(aview->attachment_type == ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL);
+
+   return (const struct anv_depth_stencil_view *) aview;
+}
index 5cbc67b7c2ca96f0241df28ce73344cce0cd0df4..a27b2e5ed92b5842e24a1a48747413678a131f10 100644 (file)
@@ -848,6 +848,8 @@ anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
 void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
                                       struct anv_render_pass *pass,
                                       const VkClearValue *clear_values);
+const struct anv_depth_stencil_view *
+anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
 
 void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
 
index e98fac1f4d3704a20bb1ca03d07389263a1ccd7b..8fe59bab1c883c71521abd88ba687d75d02ccb41 100644 (file)
@@ -528,17 +528,9 @@ void gen7_CmdPipelineBarrier(
 static void
 gen7_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
 {
-   const struct anv_subpass *subpass = cmd_buffer->state.subpass;
    const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
-   const struct anv_depth_stencil_view *view = NULL;
-
-   if (subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) {
-      const struct anv_attachment_view *aview =
-         fb->attachments[subpass->depth_stencil_attachment];
-      assert(aview->attachment_type == ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL);
-      view = (const struct anv_depth_stencil_view *)aview;
-   }
-
+   const struct anv_depth_stencil_view *view =
+      anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
    const struct anv_image *image = view ? view->image : NULL;
    const bool has_depth = view && view->format->depth_format;
    const bool has_stencil = view && view->format->has_stencil;
index 87ec90e18aa244dfdb146f656173108a5f88b5d3..3a7f009dc66236e3713135f49221b9d761c80867 100644 (file)
@@ -458,17 +458,9 @@ void gen8_CmdDispatchIndirect(
 static void
 gen8_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
 {
-   const struct anv_subpass *subpass = cmd_buffer->state.subpass;
    const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
-   const struct anv_depth_stencil_view *view = NULL;
-
-   if (subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) {
-      const struct anv_attachment_view *aview =
-         fb->attachments[subpass->depth_stencil_attachment];
-      assert(aview->attachment_type == ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL);
-      view = (const struct anv_depth_stencil_view *)aview;
-   }
-
+   const struct anv_depth_stencil_view *view =
+      anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
    const struct anv_image *image = view ? view->image : NULL;
    const bool has_depth = view && view->format->depth_format;
    const bool has_stencil = view && view->format->has_stencil;