<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 13, 2018 at 3:18 PM, Nanley Chery <span dir="ltr"><<a href="mailto:nanleychery@gmail.com" target="_blank">nanleychery@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_8274797247009232337HOEnZb"><div class="m_8274797247009232337h5">On Mon, Feb 05, 2018 at 02:34:59PM -0800, Jason Ekstrand wrote:<br>
> This requires us to ditch the VkAttachmentReference struct in favor of<br>
> an anv-specific struct.  However, we can now easily identify from just<br>
> the subpass attachment what kind of an attachment it is.  This will make<br>
> iteration over anv_subpass::attachments a little easier in some case.<br>
> ---<br>
>  src/intel/vulkan/anv_pass.c        | 35 +++++++++++++++++++++++++++---<wbr>-----<br>
>  src/intel/vulkan/anv_private.<wbr>h     | 16 +++++++++++-----<br>
>  src/intel/vulkan/genX_cmd_buff<wbr>er.c |  2 +-<br>
>  3 files changed, 39 insertions(+), 14 deletions(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c<br>
> index a77e52b..5b8b138 100644<br>
> --- a/src/intel/vulkan/anv_pass.c<br>
> +++ b/src/intel/vulkan/anv_pass.c<br>
> @@ -65,7 +65,7 @@ VkResult anv_CreateRenderPass(<br>
>     anv_multialloc_add(&ma, &attachments, pCreateInfo->attachmentCount);<br>
>     anv_multialloc_add(&ma, &subpass_flushes, pCreateInfo->subpassCount + 1);<br>
><br>
> -   VkAttachmentReference *subpass_attachments;<br>
> +   struct anv_subpass_attachment *subpass_attachments;<br>
>     uint32_t subpass_attachment_count = 0;<br>
>     for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {<br>
>        subpass_attachment_count +=<br>
> @@ -117,7 +117,11 @@ VkResult anv_CreateRenderPass(<br>
><br>
>           for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {<br>
>              uint32_t a = desc->pInputAttachments[j].att<wbr>achment;<br>
> -            subpass->input_attachments[j] = desc->pInputAttachments[j];<br>
> +            subpass->input_attachments[j] = (struct anv_subpass_attachment) {<br>
> +               .usage =       VK_IMAGE_USAGE_INPUT_ATTACHME<wbr>NT_BIT,<br>
> +               .attachment =  desc->pInputAttachments[j].att<wbr>achment,<br>
> +               .layout =      desc->pInputAttachments[j].lay<wbr>out,<br>
> +            };<br>
>              if (a != VK_ATTACHMENT_UNUSED) {<br>
>                 has_input = true;<br>
>                 pass->attachments[a].usage |= VK_IMAGE_USAGE_INPUT_ATTACHMEN<wbr>T_BIT;<br>
> @@ -138,7 +142,11 @@ VkResult anv_CreateRenderPass(<br>
><br>
>           for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {<br>
>              uint32_t a = desc->pColorAttachments[j].att<wbr>achment;<br>
> -            subpass->color_attachments[j] = desc->pColorAttachments[j];<br>
> +            subpass->color_attachments[j] = (struct anv_subpass_attachment) {<br>
> +               .usage =       VK_IMAGE_USAGE_COLOR_ATTACHME<wbr>NT_BIT,<br>
> +               .attachment =  desc->pColorAttachments[j].att<wbr>achment,<br>
> +               .layout =      desc->pColorAttachments[j].lay<wbr>out,<br>
> +            };<br>
<br>
</div></div>I kind of liked reusing the VkAttachmentReference struct instead of<br>
having to roll our own.</blockquote><div><br></div><div>I used to think that way.  However, as we extend stuff, it tends to stop being practical.  There are a number of cases where we started off with Vulkan structures and then ended up no longer using them.  This is especially prone to happen with extensions.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">What do you think about creating helper<br>
functions, like the following instead:<br>
<br>
static bool is_color_attachment(struct anv_subpass* subpass,<br>
                                VkAttachmentReference* att_ref)<br>
{<br>
   return att_ref >= subpass->color_attachments &&<br>
          att_ref < subpass->color_attachments + subpass->color_count;<br>
}<br></blockquote><div><br></div><div>I did exactly that in earlier versions of this series.  However, when I found myself trying to write an is_depth_attachment function it got messy and I decided it was easier to just stash the usage.  It's actually rather convenient.<br><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-Nanley<br>
<div><div class="m_8274797247009232337h5"><br>
<br>
>              if (a != VK_ATTACHMENT_UNUSED) {<br>
>                 has_color = true;<br>
>                 pass->attachments[a].usage |= VK_IMAGE_USAGE_COLOR_ATTACHMEN<wbr>T_BIT;<br>
> @@ -157,7 +165,11 @@ VkResult anv_CreateRenderPass(<br>
><br>
>           for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {<br>
>              uint32_t a = desc->pResolveAttachments[j].a<wbr>ttachment;<br>
> -            subpass->resolve_attachments[j<wbr>] = desc->pResolveAttachments[j];<br>
> +            subpass->resolve_attachments[j<wbr>] = (struct anv_subpass_attachment) {<br>
> +               .usage =       VK_IMAGE_USAGE_TRANSFER_DST_B<wbr>IT,<br>
> +               .attachment =  desc->pResolveAttachments[j].a<wbr>ttachment,<br>
> +               .layout =      desc->pResolveAttachments[j].l<wbr>ayout,<br>
> +            };<br>
>              if (a != VK_ATTACHMENT_UNUSED) {<br>
>                 subpass->has_resolve = true;<br>
>                 uint32_t color_att = desc->pColorAttachments[j].att<wbr>achment;<br>
> @@ -174,8 +186,12 @@ VkResult anv_CreateRenderPass(<br>
><br>
>        if (desc->pDepthStencilAttachment<wbr>) {<br>
>           uint32_t a = desc->pDepthStencilAttachment-<wbr>>attachment;<br>
> -         *subpass_attachments++ = subpass->depth_stencil_attachm<wbr>ent =<br>
> -            *desc->pDepthStencilAttachment<wbr>;<br>
> +         subpass->depth_stencil_attach<wbr>ment = (struct anv_subpass_attachment) {<br>
> +            .usage =       VK_IMAGE_USAGE_DEPTH_STENCIL_<wbr>ATTACHMENT_BIT,<br>
> +            .attachment =  desc->pDepthStencilAttachment-<wbr>>attachment,<br>
> +            .layout =      desc->pDepthStencilAttachment-<wbr>>layout,<br>
> +         };<br>
> +         *subpass_attachments++ = subpass->depth_stencil_attachm<wbr>ent;<br>
>           if (a != VK_ATTACHMENT_UNUSED) {<br>
>              has_depth = true;<br>
>              pass->attachments[a].usage |=<br>
> @@ -186,8 +202,11 @@ VkResult anv_CreateRenderPass(<br>
>                                        *desc->pDepthStencilAttachment<wbr>);<br>
>           }<br>
>        } else {<br>
> -         subpass->depth_stencil_attach<wbr>ment.attachment = VK_ATTACHMENT_UNUSED;<br>
> -         subpass->depth_stencil_attach<wbr>ment.layout = VK_IMAGE_LAYOUT_UNDEFINED;<br>
> +         subpass->depth_stencil_attach<wbr>ment = (struct anv_subpass_attachment) {<br>
> +            .usage =       VK_IMAGE_USAGE_DEPTH_STENCIL_<wbr>ATTACHMENT_BIT,<br>
> +            .attachment =  VK_ATTACHMENT_UNUSED,<br>
> +            .layout =   VK_IMAGE_LAYOUT_UNDEFINED,<br>
> +         };<br>
>        }<br>
>     }<br>
><br>
> diff --git a/src/intel/vulkan/anv_private<wbr>.h b/src/intel/vulkan/anv_private<wbr>.h<br>
> index d424498..9a8da2b 100644<br>
> --- a/src/intel/vulkan/anv_private<wbr>.h<br>
> +++ b/src/intel/vulkan/anv_private<wbr>.h<br>
> @@ -2865,6 +2865,12 @@ struct anv_framebuffer {<br>
>     struct anv_image_view *                      attachments[0];<br>
>  };<br>
><br>
> +struct anv_subpass_attachment {<br>
> +   VkImageUsageFlagBits usage;<br>
> +   uint32_t attachment;<br>
> +   VkImageLayout layout;<br>
> +};<br>
> +<br>
>  struct anv_subpass {<br>
>     uint32_t                                     attachment_count;<br>
><br>
> @@ -2872,14 +2878,14 @@ struct anv_subpass {<br>
>      * A pointer to all attachment references used in this subpass.<br>
>      * Only valid if ::attachment_count > 0.<br>
>      */<br>
> -   VkAttachmentReference *                      attachments;<br>
> +   struct anv_subpass_attachment *              attachments;<br>
>     uint32_t                                     input_count;<br>
> -   VkAttachmentReference *                      input_attachments;<br>
> +   struct anv_subpass_attachment *              input_attachments;<br>
>     uint32_t                                     color_count;<br>
> -   VkAttachmentReference *                      color_attachments;<br>
> -   VkAttachmentReference *                      resolve_attachments;<br>
> +   struct anv_subpass_attachment *              color_attachments;<br>
> +   struct anv_subpass_attachment *              resolve_attachments;<br>
><br>
> -   VkAttachmentReference                        depth_stencil_attachment;<br>
> +   struct anv_subpass_attachment                depth_stencil_attachment;<br>
><br>
>     uint32_t                                     view_mask;<br>
><br>
> diff --git a/src/intel/vulkan/genX_cmd_bu<wbr>ffer.c b/src/intel/vulkan/genX_cmd_bu<wbr>ffer.c<br>
> index 2590ea3..f92e86f 100644<br>
> --- a/src/intel/vulkan/genX_cmd_bu<wbr>ffer.c<br>
> +++ b/src/intel/vulkan/genX_cmd_bu<wbr>ffer.c<br>
> @@ -3310,7 +3310,7 @@ cmd_buffer_subpass_transition_<wbr>layouts(struct anv_cmd_buffer * const cmd_buffer,<br>
>        assert(subpass->attachments);<br>
><br>
>     /* Iterate over the array of attachment references. */<br>
> -   for (const VkAttachmentReference *att_ref = subpass->attachments;<br>
> +   for (const struct anv_subpass_attachment *att_ref = subpass->attachments;<br>
>          att_ref < subpass->attachments + subpass->attachment_count; att_ref++) {<br>
><br>
>        /* If the attachment is unused, we can't perform a layout transition. */<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>