<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Feb 25, 2018 at 9:57 PM, Michael Schellenberger Costa <span dir="ltr"><<a href="mailto:mschellenbergercosta@googlemail.com" target="_blank">mschellenbergercosta@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">HI Jason,<br>
<br>
-----Ursprüngliche Nachricht-----<br>
Von: mesa-dev [mailto:<a href="mailto:mesa-dev-bounces@lists.freedesktop.org">mesa-dev-bounces@<wbr>lists.freedesktop.org</a>] Im Auftrag von Jason Ekstrand<br>
Gesendet: Montag, 26. Februar 2018 03:33<br>
An: <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
Cc: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
Betreff: [Mesa-dev] [PATCH] anv/cmd_buffer: Avoid unnecessary transitions before fast clears<br>
<div><div class="h5"><br>
Previously, we would always apply the layout transition at the beginning<br>
of the subpass and then do the clear whether fast or slow. This meant<br>
that there were some cases, specifically when the initial layout is<br>
VK_IMAGE_LAYOUT_UNDEFINED, where we would end up doing a fast-clear or<br>
ambiguate followed immediately by a fast-clear. This isn't usually<br>
terribly expensive, but it is a waste that we can avoid easily enough<br>
now that we're doing everything at the same time in begin_subpass.<br>
<br>
This improves the performance of the Sascha multisampling demo on my<br>
laptop by around 10% by avoiding a duplicate MCS clear.<br>
---<br>
src/intel/vulkan/genX_cmd_<wbr>buffer.c | 158 ++++++++++++++++++++++++------<wbr>-------<br>
1 file changed, 101 insertions(+), 57 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/genX_cmd_<wbr>buffer.c b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
index 98e58ca..743c25c0 100644<br>
--- a/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
+++ b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
@@ -3436,43 +3436,24 @@ cmd_buffer_begin_subpass(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
target_layout = subpass->attachments[i].<wbr>layout;<br>
}<br>
<br>
- if (image->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_<wbr>ANV) {<br>
- assert(image->aspects == VK_IMAGE_ASPECT_COLOR_BIT);<br>
-<br>
- uint32_t base_layer, layer_count;<br>
- if (image->type == VK_IMAGE_TYPE_3D) {<br>
- base_layer = 0;<br>
- layer_count = anv_minify(iview->image-><wbr>extent.depth,<br>
- iview->planes[0].isl.base_<wbr>level);<br>
- } else {<br>
- base_layer = iview->planes[0].isl.base_<wbr>array_layer;<br>
- layer_count = fb->layers;<br>
- }<br>
-<br>
- transition_color_buffer(cmd_<wbr>buffer, image, VK_IMAGE_ASPECT_COLOR_BIT,<br>
- iview->planes[0].isl.base_<wbr>level, 1,<br>
- base_layer, layer_count,<br>
- att_state->current_layout, target_layout);<br>
- } else if (image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {<br>
- transition_depth_buffer(cmd_<wbr>buffer, image,<br>
- att_state->current_layout, target_layout);<br>
- att_state->aux_usage =<br>
- anv_layout_to_aux_usage(&cmd_<wbr>buffer->device->info, image,<br>
- VK_IMAGE_ASPECT_DEPTH_BIT, target_layout);<br>
+ uint32_t base_layer, layer_count;<br>
+ if (image->type == VK_IMAGE_TYPE_3D) {<br>
+ base_layer = 0;<br>
+ layer_count = anv_minify(iview->image-><wbr>extent.depth,<br>
+ iview->planes[0].isl.base_<wbr>level);<br>
+ } else {<br>
+ base_layer = iview->planes[0].isl.base_<wbr>array_layer;<br>
+ layer_count = fb->layers;<br>
}<br>
- att_state->current_layout = target_layout;<br>
-<br>
- if (att_state->pending_clear_<wbr>aspects & VK_IMAGE_ASPECT_COLOR_BIT) {<br>
- assert(att_state->pending_<wbr>clear_aspects == VK_IMAGE_ASPECT_COLOR_BIT);<br>
-<br>
- /* Multi-planar images are not supported as attachments */<br>
- assert(image->aspects == VK_IMAGE_ASPECT_COLOR_BIT);<br>
- assert(image->n_planes == 1);<br>
<br>
- uint32_t base_clear_layer = iview->planes[0].isl.base_<wbr>array_layer;<br>
- uint32_t clear_layer_count = fb->layers;<br>
+ /* Clears are based on the image view for 3D surfaces but transitions<br>
+ * are done on an entire miplevel at a time.<br>
+ */<br>
+ uint32_t base_clear_layer = iview->planes[0].isl.base_<wbr>array_layer;<br>
+ uint32_t clear_layer_count = fb->layers;<br>
<br>
- if (att_state->fast_clear) {<br>
+ if (att_state->fast_clear) {<br>
+ if (att_state->pending_clear_<wbr>aspects & VK_IMAGE_ASPECT_COLOR_BIT) {<br>
/* We only support fast-clears on the first layer */<br>
assert(iview->planes[0].isl.<wbr>base_level == 0);<br>
assert(iview->planes[0].isl.<wbr>base_array_layer == 0);<br>
@@ -3484,9 +3465,17 @@ cmd_buffer_begin_subpass(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
anv_image_mcs_op(cmd_buffer, image, VK_IMAGE_ASPECT_COLOR_BIT,<br>
0, 1, ISL_AUX_OP_FAST_CLEAR, false);<br>
}<br>
+<br>
base_clear_layer++;<br>
clear_layer_count--;<br>
<br>
+ /* Performing a fast clear takes care of all our transition needs<br>
+ * for the first slice. Increment the base layer and layer count<br>
+ * so that later transitions don't touch layer 0.<br>
+ */<br>
+ base_layer++;<br>
+ layer_count--;<br>
</div></div>Code and Comment do not match here. Given the original code do you mean Increment base_layer and decrement layer_count?<br></blockquote><div><br></div><div>Yup. Fixed.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
--Michael<br>
<div><div class="h5">+<br>
genX(copy_fast_clear_dwords)(<wbr>cmd_buffer, att_state->color.state,<br>
image, VK_IMAGE_ASPECT_COLOR_BIT,<br>
true /* copy from ss */);<br>
@@ -3507,6 +3496,59 @@ cmd_buffer_begin_subpass(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
}<br>
}<br>
<br>
+ if ((att_state->pending_clear_<wbr>aspects & VK_IMAGE_ASPECT_DEPTH_BIT) &&<br>
+ render_area.offset.x == 0 && render_area.offset.y == 0 &&<br>
+ render_area.extent.width == iview->image->extent.width &&<br>
+ render_area.extent.height == iview->image->extent.height) {<br>
+ /* We currently only support HiZ for single-layer images */<br>
+ assert(iview->image->planes[0]<wbr>.aux_usage == ISL_AUX_USAGE_HIZ);<br>
+ assert(iview->planes[0].isl.<wbr>base_level == 0);<br>
+ assert(iview->planes[0].isl.<wbr>base_array_layer == 0);<br>
+ assert(fb->layers == 1);<br>
+<br>
+ anv_image_hiz_clear(cmd_<wbr>buffer, image,<br>
+ att_state->pending_clear_<wbr>aspects,<br>
+ iview->planes[0].isl.base_<wbr>level,<br>
+ 0, 1, render_area,<br>
+ att_state->clear_value.<wbr>depthStencil.stencil);<br>
+<br>
+ /* Performing a fast clear takes care of all our transition needs<br>
+ * for the attachment. Set clear_layer_count and layer_count to<br>
+ * indicate that no clears or transitions need to be done.<br>
+ */<br>
+ clear_layer_count = 0;<br>
+ layer_count = 0;<br>
+ }<br>
+ }<br>
+<br>
+ if (image->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_<wbr>ANV) {<br>
+ assert(image->aspects == VK_IMAGE_ASPECT_COLOR_BIT);<br>
+<br>
+ if (layer_count > 0) {<br>
+ transition_color_buffer(cmd_<wbr>buffer, image,<br>
+ VK_IMAGE_ASPECT_COLOR_BIT,<br>
+ iview->planes[0].isl.base_<wbr>level, 1,<br>
+ base_layer, layer_count,<br>
+ att_state->current_layout, target_layout);<br>
+ }<br>
+ } else if (image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {<br>
+ if (layer_count > 0) {<br>
+ transition_depth_buffer(cmd_<wbr>buffer, image,<br>
+ att_state->current_layout, target_layout);<br>
+ }<br>
+ att_state->aux_usage =<br>
+ anv_layout_to_aux_usage(&cmd_<wbr>buffer->device->info, image,<br>
+ VK_IMAGE_ASPECT_DEPTH_BIT, target_layout);<br>
+ }<br>
+ att_state->current_layout = target_layout;<br>
+<br>
+ if (att_state->pending_clear_<wbr>aspects & VK_IMAGE_ASPECT_COLOR_BIT) {<br>
+ assert(att_state->pending_<wbr>clear_aspects == VK_IMAGE_ASPECT_COLOR_BIT);<br>
+<br>
+ /* Multi-planar images are not supported as attachments */<br>
+ assert(image->aspects == VK_IMAGE_ASPECT_COLOR_BIT);<br>
+ assert(image->n_planes == 1);<br>
+<br>
if (clear_layer_count > 0) {<br>
assert(image->n_planes == 1);<br>
anv_image_clear_color(cmd_<wbr>buffer, image, VK_IMAGE_ASPECT_COLOR_BIT,<br>
@@ -3520,30 +3562,32 @@ cmd_buffer_begin_subpass(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
}<br>
} else if (att_state->pending_clear_<wbr>aspects & (VK_IMAGE_ASPECT_DEPTH_BIT |<br>
VK_IMAGE_ASPECT_STENCIL_BIT)) {<br>
- if (att_state->fast_clear) {<br>
- /* We currently only support HiZ for single-layer images */<br>
- if (att_state->pending_clear_<wbr>aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {<br>
- assert(iview->image->planes[0]<wbr>.aux_usage == ISL_AUX_USAGE_HIZ);<br>
- assert(iview->planes[0].isl.<wbr>base_level == 0);<br>
- assert(iview->planes[0].isl.<wbr>base_array_layer == 0);<br>
- assert(fb->layers == 1);<br>
- }<br>
+ if (clear_layer_count > 0) {<br>
+ if (att_state->fast_clear) {<br>
+ /* We currently only support HiZ for single-layer images */<br>
+ if (att_state->pending_clear_<wbr>aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {<br>
+ assert(iview->image->planes[0]<wbr>.aux_usage == ISL_AUX_USAGE_HIZ);<br>
+ assert(iview->planes[0].isl.<wbr>base_level == 0);<br>
+ assert(iview->planes[0].isl.<wbr>base_array_layer == 0);<br>
+ assert(fb->layers == 1);<br>
+ }<br>
<br>
- anv_image_hiz_clear(cmd_<wbr>buffer, image,<br>
- att_state->pending_clear_<wbr>aspects,<br>
- iview->planes[0].isl.base_<wbr>level,<br>
- iview->planes[0].isl.base_<wbr>array_layer,<br>
- fb->layers, render_area,<br>
- att_state->clear_value.<wbr>depthStencil.stencil);<br>
- } else {<br>
- anv_image_clear_depth_stencil(<wbr>cmd_buffer, image,<br>
- att_state->pending_clear_<wbr>aspects,<br>
- att_state->aux_usage,<br>
- iview->planes[0].isl.base_<wbr>level,<br>
- iview->planes[0].isl.base_<wbr>array_layer,<br>
- fb->layers, render_area,<br>
- att_state->clear_value.<wbr>depthStencil.depth,<br>
- att_state->clear_value.<wbr>depthStencil.stencil);<br>
+ anv_image_hiz_clear(cmd_<wbr>buffer, image,<br>
+ att_state->pending_clear_<wbr>aspects,<br>
+ iview->planes[0].isl.base_<wbr>level,<br>
+ base_clear_layer, clear_layer_count,<br>
+ render_area,<br>
+ att_state->clear_value.<wbr>depthStencil.stencil);<br>
+ } else {<br>
+ anv_image_clear_depth_stencil(<wbr>cmd_buffer, image,<br>
+ att_state->pending_clear_<wbr>aspects,<br>
+ att_state->aux_usage,<br>
+ iview->planes[0].isl.base_<wbr>level,<br>
+ base_clear_layer, clear_layer_count,<br>
+ render_area,<br>
+ att_state->clear_value.<wbr>depthStencil.depth,<br>
+ att_state->clear_value.<wbr>depthStencil.stencil);<br>
+ }<br>
}<br>
} else {<br>
assert(att_state->pending_<wbr>clear_aspects == 0);<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>
<br>
</blockquote></div><br></div></div>