<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, May 10, 2017 at 11:30 AM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On Wed, May 03, 2017 at 02:24:19PM -0700, Jason Ekstrand wrote:<br>
> On Thu, Apr 27, 2017 at 11:32 AM, Nanley Chery <<a href="mailto:nanleychery@gmail.com">nanleychery@gmail.com</a>><br>
> wrote:<br>
><br>
> > Signed-off-by: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
> > ---<br>
> >  src/intel/vulkan/genX_cmd_<wbr>buffer.c | 93 ++++++++++++++++++++++++++++++<br>
> > ++++++++<br>
> >  1 file changed, 93 insertions(+)<br>
> ><br>
> > diff --git a/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
> > b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
> > index d5cc358aec..1ae0c3256e 100644<br>
> > --- a/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
> > +++ b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
> > @@ -454,6 +454,99 @@ genX(transfer_clear_value)(<wbr>struct anv_cmd_buffer *<br>
> > const cmd_buffer,<br>
> >     }<br>
> >  }<br>
> ><br>
> > +/* Transitions a color buffer from one layout to another. */<br>
> > +static void<br>
> > +transition_color_buffer(<wbr>struct anv_cmd_buffer * const cmd_buffer,<br>
> > +                        const struct anv_image * const image,<br>
> > +                        const uint32_t base_level, uint32_t level_count,<br>
> > +                        const uint32_t base_layer, uint32_t layer_count,<br>
> > +                        const VkImageLayout initial_layout,<br>
> > +                        const VkImageLayout final_layout)<br>
> > +{<br>
> > +   assert(cmd_buffer && image);<br>
> > +<br>
> > +   /* This must be a color image. */<br>
> > +   assert(image->aspects == VK_IMAGE_ASPECT_COLOR_BIT);<br>
> > +<br>
> > +   /* Only color buffers with CCS need resolving.  */<br>
> > +   if (image->aux_surface.isl.size == 0 || image->samples > 1)<br>
> > +      return;<br>
> > +<br>
> > +   /* Don't transition this subresource range if it lacks auxiliary data.<br>
> > */<br>
> > +   if (base_level >= anv_color_aux_levels(image) ||<br>
> > +       base_layer >= anv_color_aux_layers(image, base_level))<br>
> > +      return;<br>
> > +<br>
> > +   /* The undefined layout indicates that the user doesn't care about the<br>
> > +    * data that's currently in the buffer. The pre-initialized layout is<br>
> > +    * equivalent to the undefined layout for optimally-tiled images.<br>
> > +    *<br>
> > +    * We can only skip the resolve for CCS_E images in this layout<br>
> > because it<br>
> > +    * is enabled outside of render passes. This allows previously<br>
> > fast-cleared<br>
> > +    * and undefined buffers to be defined with transfer operations.<br>
> > +    */<br>
> > +   const bool is_ccs_e = image->aux_usage == ISL_AUX_USAGE_CCS_E;<br>
> > +   const bool undef_layout = initial_layout == VK_IMAGE_LAYOUT_UNDEFINED<br>
> > ||<br>
> > +                             initial_layout == VK_IMAGE_LAYOUT_<br>
> > PREINITIALIZED;<br>
> > +   if (is_ccs_e && undef_layout)<br>
> > +      return;<br>
> > +<br>
> > +   /* A resolve isn't necessary when transitioning from a layout that<br>
> > doesn't<br>
> > +    * have fast-clear data or to a layout that will be aware of the<br>
> > fast-clear<br>
> > +    * value.<br>
> > +    */<br>
> > +   const bool maybe_fast_cleared = undef_layout || initial_layout ==<br>
> > +                                   VK_IMAGE_LAYOUT_COLOR_<br>
> > ATTACHMENT_OPTIMAL;<br>
> > +   if (!maybe_fast_cleared || final_layout ==<br>
> > +       VK_IMAGE_LAYOUT_COLOR_<wbr>ATTACHMENT_OPTIMAL)<br>
> > +      return;<br>
> > +<br>
> > +   /* Determine the optimal resolve operation. For now we only need to<br>
> > resolve<br>
> > +    * the clear color.<br>
> > +    */<br>
> > +   const enum blorp_fast_clear_op op = is_ccs_e ?<br>
> > +                                       BLORP_FAST_CLEAR_OP_RESOLVE_<wbr>PARTIAL<br>
> > :<br>
> > +                                       BLORP_FAST_CLEAR_OP_RESOLVE_<wbr>FULL;<br>
> > +<br>
> > +   /* The actual range that will be transitioned is limited by the number<br>
> > of<br>
> > +    * subresources that have auxiliary data.<br>
> > +    */<br>
> > +   level_count = MIN2(level_count, anv_color_aux_levels(image));<br>
> > +<br>
> > +   /* A write cache flush with an end-of-pipe sync is required between<br>
> > +    * rendering, clearing, and resolving operations. Perform a flush of<br>
> > the<br>
> > +    * write cache before and after the resolve operation to meet this<br>
> > +    * requirement.<br>
> > +    */<br>
> ><br>
><br>
> anv_blorp.c has a more detailed comment about this.  I think I'd rather we<br>
> copy it here so that it doesn't get lost when we delete<br>
> ccs_resolve_attachments.<br>
><br>
> Also, I have no idea whether we need to do it per-fast-clear-op or once<br>
> before we do fast-clear ops and once afterwards.  I think this is probably<br>
> fine.<br>
><br>
><br>
<br>
</div></div>Contrary to the comment in anv_blorp, I found documentation that<br>
provides us more information as to what's needed. How about I rewrite my<br>
comment to this instead?<br>
<br>
   From the Sky Lake PRM Vol. 7, "MCS Buffer for Render Target(s)":<br>
<br>
      Any transition from any value in {Clear, Render, Resolve} to a<br>
      different value in {Clear, Render, Resolve} requires end of pipe<br>
      synchronization.<br>
<br>
   Perform a flush of the write cache before and after the resolve<br>
   operation to meet this requirement.<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>That PRM citation is fine and maybe better than the one I used (though they say about the same thing).  The part I was hoping to preserve is<br><br>    * This comment is a bit cryptic and doesn't really tell you what's going<br>    * or what's really needed.  It appears that fast clear ops are not<br>    * properly synchronized with other drawing.  We need to use a PIPE_CONTROL<br>    * to ensure that the contents of the previous draw hit the render target<br>    * before we resolve and then use a second PIPE_CONTROL after the resolve<br>    * to ensure that it is completed before any additional drawing occurs.<br><br></div><div>Yes, the PRM text tells you that an end of pipe sync is needed, but it doesn't tell you where.  It's empirical evidence from hunting down bugs that tells us we need it on both sides.<br><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-HOEnZb"><font color="#888888">
-Nanley<br>
</font></span><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
> > +   cmd_buffer->state.pending_<wbr>pipe_bits |=<br>
> > +      ANV_PIPE_RENDER_TARGET_CACHE_<wbr>FLUSH_BIT | ANV_PIPE_CS_STALL_BIT;<br>
> > +<br>
> > +   for (uint32_t level = base_level; level < base_level + level_count;<br>
> > level++) {<br>
> > +<br>
> > +      layer_count = MIN2(layer_count, anv_color_aux_layers(image, level));<br>
> > +      for (uint32_t layer = base_layer; layer < base_layer + layer_count;<br>
> > layer++) {<br>
> > +<br>
> > +         /* Create a surface state with the right clear color and perform<br>
> > the<br>
> > +          * resolve.<br>
> > +          */<br>
> > +         struct anv_state surface_state =<br>
> > +            anv_cmd_buffer_alloc_surface_<wbr>state(cmd_buffer);<br>
> > +         anv_fill_ccs_resolve_ss(cmd_<wbr>buffer->device, surface_state.map,<br>
> > image,<br>
> > +                                 level, layer);<br>
> > +         add_image_relocs(cmd_buffer, image, VK_IMAGE_ASPECT_COLOR_BIT,<br>
> > +                          is_ccs_e ?  ISL_AUX_USAGE_CCS_E :<br>
> > ISL_AUX_USAGE_CCS_D,<br>
> > +                          surface_state);<br>
> > +         anv_state_flush(cmd_buffer-><wbr>device, surface_state);<br>
> > +         genX(transfer_clear_value)(<wbr>cmd_buffer, surface_state, image,<br>
> > level,<br>
> > +                                    false);<br>
> > +         anv_ccs_resolve(cmd_buffer, surface_state, image, level, layer,<br>
> > op);<br>
> > +      }<br>
> > +   }<br>
> > +<br>
> > +   cmd_buffer->state.pending_<wbr>pipe_bits |=<br>
> > +      ANV_PIPE_RENDER_TARGET_CACHE_<wbr>FLUSH_BIT | ANV_PIPE_CS_STALL_BIT;<br>
> > +}<br>
> > +<br>
> >  /**<br>
> >   * Setup anv_cmd_state::attachments for vkCmdBeginRenderPass.<br>
> >   */<br>
> > --<br>
> > 2.12.2<br>
> ><br>
> > ______________________________<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>
> ><br>
</div></div></blockquote></div><br></div></div>