<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 12, 2016 at 2:26 AM, Pohjolainen, Topi <span dir="ltr"><<a href="mailto:topi.pohjolainen@gmail.com" target="_blank">topi.pohjolainen@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="HOEnZb"><div class="h5">On Fri, Oct 07, 2016 at 09:41:15PM -0700, Jason Ekstrand wrote:<br>
> Signed-off-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
> ---<br>
>  src/intel/vulkan/anv_blorp.c      | 113 ++++++++++++++++++++++++++++++<wbr>++++++++<br>
>  src/intel/vulkan/anv_meta_<wbr>clear.c |  24 --------<br>
>  2 files changed, 113 insertions(+), 24 deletions(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c<br>
> index 546737b..4279f62 100644<br>
> --- a/src/intel/vulkan/anv_blorp.c<br>
> +++ b/src/intel/vulkan/anv_blorp.c<br>
> @@ -870,6 +870,119 @@ void anv_CmdClearDepthStencilImage(<br>
>  }<br>
><br>
>  static void<br>
> +clear_color_attachment(struct anv_cmd_buffer *cmd_buffer,<br>
> +                       struct blorp_batch *batch,<br>
> +                       const VkClearAttachment *attachment,<br>
> +                       uint32_t rectCount, const VkClearRect *pRects)<br>
> +{<br>
> +   const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;<br>
> +   const struct anv_subpass *subpass = cmd_buffer->state.subpass;<br>
> +   const uint32_t att = attachment->colorAttachment;<br>
> +   const struct anv_image_view *iview =<br>
> +      fb->attachments[subpass-><wbr>color_attachments[att]];<br>
> +   const struct anv_image *image = iview->image;<br>
> +<br>
> +   struct blorp_surf surf;<br>
> +   get_blorp_surf_for_anv_image(<wbr>image, VK_IMAGE_ASPECT_COLOR_BIT, &surf);<br>
> +<br>
> +   union isl_color_value clear_color;<br>
> +   memcpy(clear_color.u32, attachment->clearValue.color.<wbr>uint32,<br>
> +          sizeof(clear_color.u32));<br>
> +<br>
> +   static const bool color_write_disable[4] = { false, false, false, false };<br>
> +<br>
> +   for (uint32_t r = 0; r < rectCount; ++r) {<br>
> +      const VkOffset2D offset = pRects[r].rect.offset;<br>
> +      const VkExtent2D extent = pRects[r].rect.extent;<br>
> +      blorp_clear(batch, &surf, iview->isl.format, iview->isl.swizzle,<br>
> +                  iview->isl.base_level,<br>
> +                  iview->isl.base_array_layer + pRects[r].baseArrayLayer,<br>
<br>
</div></div>I'm not that familiar with vulkan yet and looking emit_color_clear() does not<br>
directly tell me if "pRects[r].baseArrayLayer" is relative to the view base<br>
layer. If that is the case then this patch looks good to me:<br></blockquote><div><br></div><div>It is.  Took me by surprise too.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Reviewed-by: Topi Pohjolainen <<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a>><br></blockquote><div><br></div><div>Thanks!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
> +                  pRects[r].layerCount,<br>
> +                  offset.x, offset.y,<br>
> +                  offset.x + extent.width, offset.y + extent.height,<br>
> +                  clear_color, color_write_disable);<br>
> +   }<br>
> +}<br>
> +<br>
> +static void<br>
> +clear_depth_stencil_<wbr>attachment(struct anv_cmd_buffer *cmd_buffer,<br>
> +                               struct blorp_batch *batch,<br>
> +                               const VkClearAttachment *attachment,<br>
> +                               uint32_t rectCount, const VkClearRect *pRects)<br>
> +{<br>
> +   const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;<br>
> +   const struct anv_subpass *subpass = cmd_buffer->state.subpass;<br>
> +   const struct anv_image_view *iview =<br>
> +      fb->attachments[subpass-><wbr>depth_stencil_attachment];<br>
> +   const struct anv_image *image = iview->image;<br>
> +<br>
> +   bool clear_depth = attachment->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT;<br>
> +   bool clear_stencil = attachment->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT;<br>
<br>
</span>These two could be const.<br>
<div><div class="h5"><br>
> +<br>
> +   struct blorp_surf depth, stencil;<br>
> +   if (clear_depth) {<br>
> +      get_blorp_surf_for_anv_image(<wbr>image, VK_IMAGE_ASPECT_DEPTH_BIT,<br>
> +                                   &depth);<br>
> +   } else {<br>
> +      memset(&depth, 0, sizeof(depth));<br>
> +   }<br>
> +<br>
> +   if (clear_stencil) {<br>
> +      get_blorp_surf_for_anv_image(<wbr>image, VK_IMAGE_ASPECT_STENCIL_BIT,<br>
> +                                   &stencil);<br>
> +   } else {<br>
> +      memset(&stencil, 0, sizeof(stencil));<br>
> +   }<br>
> +<br>
> +   for (uint32_t r = 0; r < rectCount; ++r) {<br>
> +      const VkOffset2D offset = pRects[r].rect.offset;<br>
> +      const VkExtent2D extent = pRects[r].rect.extent;<br>
> +      VkClearDepthStencilValue value = attachment->clearValue.<wbr>depthStencil;<br>
> +      blorp_clear_depth_stencil(<wbr>batch, &depth, &stencil,<br>
> +                                iview->isl.base_level,<br>
> +                                iview->isl.base_array_layer +<br>
> +                                   pRects[r].baseArrayLayer,<br>
> +                                pRects[r].layerCount,<br>
> +                                offset.x, offset.y,<br>
> +                                offset.x + extent.width,<br>
> +                                offset.y + extent.height,<br>
> +                                clear_depth, value.depth,<br>
> +                                clear_stencil, value.stencil);<br>
> +   }<br>
> +}<br>
> +<br>
> +void anv_CmdClearAttachments(<br>
> +    VkCommandBuffer                             commandBuffer,<br>
> +    uint32_t                                    attachmentCount,<br>
> +    const VkClearAttachment*                    pAttachments,<br>
> +    uint32_t                                    rectCount,<br>
> +    const VkClearRect*                          pRects)<br>
> +{<br>
> +   ANV_FROM_HANDLE(anv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
> +<br>
> +   /* Because this gets called within a render pass, we tell blorp not to<br>
> +    * trash our depth and stencil buffers.<br>
> +    */<br>
> +   struct blorp_batch batch;<br>
> +   blorp_batch_init(&cmd_buffer-><wbr>device->blorp, &batch, cmd_buffer,<br>
> +                    BLORP_BATCH_NO_EMIT_DEPTH_<wbr>STENCIL);<br>
> +<br>
> +   for (uint32_t a = 0; a < attachmentCount; ++a) {<br>
> +      if (pAttachments[a].aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) {<br>
> +         clear_color_attachment(cmd_<wbr>buffer, &batch,<br>
> +                                &pAttachments[a],<br>
> +                                rectCount, pRects);<br>
> +      } else {<br>
> +         clear_depth_stencil_<wbr>attachment(cmd_buffer, &batch,<br>
> +                                        &pAttachments[a],<br>
> +                                        rectCount, pRects);<br>
> +      }<br>
> +   }<br>
> +<br>
> +   blorp_batch_finish(&batch);<br>
> +}<br>
> +<br>
> +static void<br>
>  resolve_image(struct blorp_batch *batch,<br>
>                const struct anv_image *src_image,<br>
>                uint32_t src_level, uint32_t src_layer,<br>
> diff --git a/src/intel/vulkan/anv_meta_<wbr>clear.c b/src/intel/vulkan/anv_meta_<wbr>clear.c<br>
> index ce7f8a7..6802229 100644<br>
> --- a/src/intel/vulkan/anv_meta_<wbr>clear.c<br>
> +++ b/src/intel/vulkan/anv_meta_<wbr>clear.c<br>
> @@ -751,27 +751,3 @@ anv_cmd_buffer_clear_subpass(<wbr>struct anv_cmd_buffer *cmd_buffer)<br>
><br>
>     meta_clear_end(&saved_state, cmd_buffer);<br>
>  }<br>
> -<br>
> -void anv_CmdClearAttachments(<br>
> -    VkCommandBuffer                             commandBuffer,<br>
> -    uint32_t                                    attachmentCount,<br>
> -    const VkClearAttachment*                    pAttachments,<br>
> -    uint32_t                                    rectCount,<br>
> -    const VkClearRect*                          pRects)<br>
> -{<br>
> -   ANV_FROM_HANDLE(anv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
> -   struct anv_meta_saved_state saved_state;<br>
> -<br>
> -   meta_clear_begin(&saved_state, cmd_buffer);<br>
> -<br>
> -   /* FINISHME: We can do better than this dumb loop. It thrashes too much<br>
> -    * state.<br>
> -    */<br>
> -   for (uint32_t a = 0; a < attachmentCount; ++a) {<br>
> -      for (uint32_t r = 0; r < rectCount; ++r) {<br>
> -         emit_clear(cmd_buffer, &pAttachments[a], &pRects[r]);<br>
> -      }<br>
> -   }<br>
> -<br>
> -   meta_clear_end(&saved_state, cmd_buffer);<br>
> -}<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">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>