<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 30, 2018 at 2:54 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Fri, Jan 19, 2018 at 03:47:34PM -0800, Jason Ekstrand wrote:<br>
</span><span class="gmail-">> Even though the blorp pass looks a bit on the sketchy side, the end<br>
> result in the Vulkan driver is very nice.  Instead of having this weird<br>
> case where you do a fast clear and then maybe have to resolve, we just<br>
> do the ambiguate and are done with it.  The ambiguate does exactly what<br>
> we want of setting all the CCS values to 0 which puts it inot the<br>
</span>                                                           ^<br>
                                                           in<br>
<div><div class="gmail-h5">> pass-through state.<br>
><br>
> This should also improve performance a bit in certain cases.  For<br>
> instance, if we did a transition from UNDEFINED to GENERAL for a surface<br>
> that doesn't have CCS enabled all the time, we would end up doing a<br>
> fast-clear and then a full resolve which ends up touching every byte in<br>
> the main surface as well as the CCS.  With the ambiguate pass, that<br>
> transition only touches the CCS.<br>
> ---<br>
>  src/intel/vulkan/anv_blorp.c       |  5 ++++<br>
>  src/intel/vulkan/genX_cmd_<wbr>buffer.c | 54 +++++++++---------------------<wbr>--------<br>
>  2 files changed, 17 insertions(+), 42 deletions(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c<br>
> index 05efc6d..3698543 100644<br>
> --- a/src/intel/vulkan/anv_blorp.c<br>
> +++ b/src/intel/vulkan/anv_blorp.c<br>
> @@ -1792,6 +1792,11 @@ anv_image_ccs_op(struct anv_cmd_buffer *cmd_buffer,<br>
>                          surf.surf->format, isl_to_blorp_fast_clear_op(<wbr>ccs_op));<br>
>        break;<br>
>     case ISL_AUX_OP_AMBIGUATE:<br>
> +      for (uint32_t a = 0; a < layer_count; a++) {<br>
> +         const uint32_t layer = base_layer + a;<br>
> +         blorp_ccs_ambiguate(&batch, &surf, level, layer);<br>
> +      }<br>
> +      break;<br>
>     default:<br>
>        unreachable("Unsupported CCS operation");<br>
>     }<br>
> diff --git a/src/intel/vulkan/genX_cmd_<wbr>buffer.c b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
> index 77fdadf..9e2eba3 100644<br>
> --- a/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
> +++ b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
> @@ -486,15 +486,6 @@ init_fast_clear_state_entry(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
>     uint32_t plane = anv_image_aspect_to_plane(<wbr>image->aspects, aspect);<br>
>     enum isl_aux_usage aux_usage = image->planes[plane].aux_<wbr>usage;<br>
><br>
> -   /* The resolve flag should updated to signify that fast-clear/compression<br>
> -    * data needs to be removed when leaving the undefined layout. Such data<br>
> -    * may need to be removed if it would cause accesses to the color buffer<br>
> -    * to return incorrect data. The fast clear data in CCS_D buffers should<br>
> -    * be removed because CCS_D isn't enabled all the time.<br>
> -    */<br>
> -   genX(set_image_needs_resolve)(<wbr>cmd_buffer, image, aspect, level,<br>
> -                                 aux_usage == ISL_AUX_USAGE_NONE);<br>
> -<br>
>     /* The fast clear value dword(s) will be copied into a surface state object.<br>
>      * Ensure that the restrictions of the fields in the dword(s) are followed.<br>
>      *<br>
> @@ -677,10 +668,9 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,<br>
>        for (unsigned level = base_level; level < last_level_num; level++)<br>
>           init_fast_clear_state_entry(<wbr>cmd_buffer, image, aspect, level);<br>
><br>
> -      /* Initialize the aux buffers to enable correct rendering. This operation<br>
> -       * requires up to two steps: one to rid the aux buffer of data that may<br>
> -       * cause GPU hangs, and another to ensure that writes done without aux<br>
> -       * will be visible to reads done with aux.<br>
> +      /* Initialize the aux buffers to enable correct rendering.  In order to<br>
> +       * ensure that things such as storage images work correctly, aux buffers<br>
> +       * are initialized to the pass-through state.<br>
<br>
</div></div>Only CCS is initialized to the pass-through state while MCS is<br>
fast-cleared. We may also want to update the comment below since we're<br>
no longer fast-clearing CCS.<br><div><div class="gmail-h5"></div></div></blockquote><div><br></div><div>Right.  I've replaced this entire comment with:<br><br>      /* Initialize the aux buffers to enable correct rendering.  In order to<br>       * ensure that things such as storage images work correctly, aux buffers<br>       * need to be initialized to valid data.<br>       *<br>       * Having an aux buffer with invalid data is a problem for two reasons:<br>       *<br>       *  1) Having an invalid value in the buffer can confuse the hardware.<br>       *     For instance, with CCS_E on SKL, a two-bit CCS value of 2 is<br>       *     invalid and leads to the hardware doing strange things.  It<br>       *     doesn't hang as far as we can tell but rendering corruption can<br>       *     occur.<br>       *<br>       *  2) If this transition is into the GENERAL layout and we then use the<br>       *     image as a storage image, then we must have the aux buffer in the<br>       *     pass-through state so that, if we then go to texture from the<br>       *     image, we get the results of our storage image writes and not the<br>       *     fast clear color or other random data.<br>       *<br>       * For CCS both of the problems above are real demonstrable issues.  In<br>       * that case, the only thing we can do is to perform an ambiguate to<br>       * transition the aux surface into the pass-through state.<br>       *<br>       * For MCS, (2) is never an issue because we don't support multisampled<br>       * storage images.  In theory, issue (1) is a problem with MCS but we've<br>       * never seen it in the wild.  For 4x and 16x, all bit patters could, in<br>       * theory, be interpreted as something but we don't know that all bit<br>       * patterns are actually valid.  For 2x and 8x, you could easily end up<br>       * with the MCS referring to an invalid plane because not all bits of<br>       * the MCS value are actually used.  Even though we've never seen issues<br>       * in the wild, it's best to play it safe and initialize the MCS.  We<br>       * can use a fast-clear for MCS because we only ever touch from render<br>       * and texture (no image load store).<br>       */<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-h5">
>         *<br>
>         * Having an aux buffer with invalid data is possible for CCS buffers<br>
>         * SKL+ and for MCS buffers with certain sample counts (2x and 8x). One<br>
> @@ -692,16 +682,18 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,<br>
>         * We don't have any data to show that this is a problem, but we want to<br>
>         * avoid causing difficult-to-debug problems.<br>
>         */<br>
> -      if (GEN_GEN >= 9 && image->samples == 1) {<br>
> +      if (image->samples == 1) {<br>
>           for (uint32_t l = 0; l < level_count; l++) {<br>
>              const uint32_t level = base_level + l;<br>
>              const uint32_t level_layer_count =<br>
>                 MIN2(layer_count, anv_image_aux_layers(image, aspect, level));<br>
>              anv_image_ccs_op(cmd_buffer, image, aspect, level,<br>
>                               base_layer, level_layer_count,<br>
> -                             ISL_AUX_OP_FAST_CLEAR, false);<br>
> +                             ISL_AUX_OP_AMBIGUATE, false);<br>
> +            genX(set_image_needs_resolve)(<wbr>cmd_buffer, image,<br>
> +                                          aspect, level, false);<br>
>           }<br>
> -      } else if (image->samples > 1) {<br>
> +      } else {<br>
>           if (image->samples == 4 || image->samples == 16) {<br>
>              anv_perf_warn(cmd_buffer-><wbr>device->instance, image,<br>
>                            "Doing a potentially unnecessary fast-clear to "<br>
> @@ -712,32 +704,10 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,<br>
>           anv_image_mcs_op(cmd_buffer, image, aspect,<br>
>                            base_layer, layer_count,<br>
>                            ISL_AUX_OP_FAST_CLEAR, false);<br>
> -      }<br>
> -      /* At this point, some elements of the CCS buffer may have the fast-clear<br>
> -       * bit-arrangement. As the user writes to a subresource, we need to have<br>
> -       * the associated CCS elements enter the ambiguated state. This enables<br>
> -       * reads (implicit or explicit) to reflect the user-written data instead<br>
> -       * of the clear color. The only time such elements will not change their<br>
> -       * state as described above, is in a final layout that doesn't have CCS<br>
> -       * enabled. In this case, we must force the associated CCS buffers of the<br>
> -       * specified range to enter the ambiguated state in advance.<br>
> -       */<br>
> -      if (image->samples == 1 &&<br>
> -          image->planes[plane].aux_usage != ISL_AUX_USAGE_CCS_E &&<br>
> -          final_layout != VK_IMAGE_LAYOUT_COLOR_<wbr>ATTACHMENT_OPTIMAL) {<br>
> -         /* The CCS_D buffer may not be enabled in the final layout. Call this<br>
> -          * function again with a initial layout of COLOR_ATTACHMENT_OPTIMAL<br>
> -          * to perform a resolve.<br>
> -          */<br>
> -          anv_perf_warn(cmd_buffer-><wbr>device->instance, image,<br>
> -                        "Performing an additional resolve for CCS_D layout "<br>
> -                        "transition. Consider always leaving it on or "<br>
> -                        "performing an ambiguation pass.");<br>
> -         transition_color_buffer(cmd_<wbr>buffer, image, aspect,<br>
> -                                 base_level, level_count,<br>
> -                                 base_layer, layer_count,<br>
> -                                 VK_IMAGE_LAYOUT_COLOR_<wbr>ATTACHMENT_OPTIMAL,<br>
> -                                 final_layout);<br>
<br>
</div></div>Nice to be rid of this.<span class="gmail-"><br></span></blockquote><div><br></div><div>Yup.<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-">
> +         for (unsigned level = base_level; level < last_level_num; level++) {<br>
> +            genX(set_image_needs_resolve)(<wbr>cmd_buffer, image,<br>
> +                                          aspect, level, true);<br>
> +         }<br>
<br>
</span>Why set needs resolve true here?<br></blockquote><div><br></div><div>There's no particularly good reason.  I'll delete it.  We never do MCS resolves anyway.  When the time comes for me to go hook up MCS fast-clears again, we can sort it out then.<br></div></div></div></div>