<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 27, 2017 at 11:32 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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 ++++++++++++++++++++++++++++++<wbr>++++++++<br>
1 file changed, 93 insertions(+)<br>
<br>
diff --git a/src/intel/vulkan/genX_cmd_<wbr>buffer.c 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 * 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>
+ 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 because it<br>
+ * is enabled outside of render passes. This allows previously 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>
+ initial_layout == VK_IMAGE_LAYOUT_<wbr>PREINITIALIZED;<br>
+ if (is_ccs_e && undef_layout)<br>
+ return;<br>
+<br>
+ /* A resolve isn't necessary when transitioning from a layout that doesn't<br>
+ * have fast-clear data or to a layout that will be aware of the fast-clear<br>
+ * value.<br>
+ */<br>
+ const bool maybe_fast_cleared = undef_layout || initial_layout ==<br>
+ VK_IMAGE_LAYOUT_COLOR_<wbr>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 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>
+ BLORP_FAST_CLEAR_OP_RESOLVE_<wbr>FULL;<br>
+<br>
+ /* The actual range that will be transitioned is limited by the number 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 the<br>
+ * write cache before and after the resolve operation to meet this<br>
+ * requirement.<br>
+ */<br></blockquote><div><br></div><div>anv_blorp.c has a more detailed comment about this. I think I'd rather we copy it here so that it doesn't get lost when we delete ccs_resolve_attachments.<br><br></div><div>Also, I have no idea whether we need to do it per-fast-clear-op or once before we do fast-clear ops and once afterwards. I think this is probably fine.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ 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; 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; layer++) {<br>
+<br>
+ /* Create a surface state with the right clear color and perform 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, 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 : 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, level,<br>
+ false);<br>
+ anv_ccs_resolve(cmd_buffer, surface_state, image, level, layer, 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>
<span class="HOEnZb"><font color="#888888">--<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>
</font></span></blockquote></div><br></div></div>