<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/anv_image.c | 67 ++++++++++++++++++++++++++++++<wbr>++++++++++++++<br>
 1 file changed, 67 insertions(+)<br>
<br>
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
index cf34dbe3b0..8d946e8e93 100644<br>
--- a/src/intel/vulkan/anv_image.c<br>
+++ b/src/intel/vulkan/anv_image.c<br>
@@ -114,6 +114,71 @@ add_surface(struct anv_image *image, struct anv_surface *surf)<br>
    image->alignment = MAX2(image->alignment, surf->isl.alignment);<br>
 }<br>
<br>
+<br>
+/**<br>
+ * For color buffers that have an auxiliary buffer enabled, there is an<br>
+ * additional buffer that keeps track of fast clear values. Using this<br>
+ * buffer allows us to access image subresources while being aware of their<br>
+ * fast clear values in non-trivial cases.<br>
+ *<br>
+ * The clear values in this buffer are updated when a fast clear is performed<br>
+ * on a subresource. Two synchronization operations can be performed in order<br>
+ * for the next memory access to use the fast-clear value:<br>
+ *   a. Copy the value from the buffer to the surface state object used for<br>
+ *      reading (if different).<br>
+ *   b. Do (a) onto a surface state object and use it to resolve the<br>
+ *      subresource.<br>
+ *<br>
+ * The synchronization approach currently taken is as follows. We place<br>
+ * resolves in the hands of the user via layout transitions. We also sometimes<br>
+ * skip resolves when a clear value predetermined to be the default in other<br>
+ * surface state objects is used in a fast clear.<br>
+ *<br>
+ * We fast-clear (and so cause things to get temporarily unsynchronized)<br>
+ * whenever the hardware allows except for two cases: when in the GENERAL<br>
+ * layout and when clearing a proper subset of a layered image. The exception<br>
+ * is made for the former because a layout transition isn't required before<br>
+ * sampling from an image in that layout. The exception is made for the latter<br>
+ * because a layout transition isn't required between a render pass that<br>
+ * renders to a proper subset of a layered image and another render pass that<br>
+ * renders to every layer in the layered image.<br>
+ */<br>
+static void<br>
+add_clear_value_buffer(struct anv_image * const image,<br>
+                       const struct anv_device * const device)<br>
+{<br>
+   assert(image && device);<br>
+<br>
+   /* Only color auxiliary buffers have use for this. */<br>
+   assert(anv_image_has_color_<wbr>aux(image));<br>
+<br>
+   /* The offset to the buffer of clear values must be dword-aligned for GPU<br>
+    * memcpy operations. It is located immediately after the auxiliary surface.<br>
+    */<br>
+<br>
+   /* Tiled images are guaranteed to be 4K aligned, so the image alignment<br>
+    * should also be dword-aligned.<br>
+    */<br>
+   assert(image->alignment % 4 == 0);<br>
+<br>
+   /* Auxiliary buffers should be a multiple of 4K, so the start of the clear<br>
+    * values buffer should already be dword-aligned.<br>
+    */<br>
+   assert(image->aux_surface.isl.<wbr>size % 4 == 0);<br>
+<br>
+   /* This surface should be at the very end of the image. */<br>
+   assert(image->size ==<br>
+          image->aux_surface.offset + image->aux_surface.isl.size);<br>
+<br>
+   /* Entire surface state objects are stored instead of just clear colors for<br>
+    * two reasons:<br>
+    *   1. Pre-SKL, we must compute some state fields that lie in the same<br>
+    *      dword as the clear value.<br>
+    *   2. Storing either set of objects requires less than a page of memory.<br></blockquote><div><br></div><div>In the not-too-distant future, we're going to start sharing fast-cleared images with the display server and with scanout.  (We can do this today on SKL for the non-scanout case.  The scanout case will have to wait for new hardware.)  When we do, there will be a clear color in a "metadata page" which will just be 4 dwords.  We don't necessarily need to change anything now to accommodate but be advised that we will probably want to drop to just 1 or 4 dwords in the future.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    */<br>
+   image->size += device->isl_dev.ss.size * anv_color_aux_levels(image);<br>
+}<br>
+<br>
 /**<br>
  * Initialize the anv_image::*_surface selected by \a aspect. Then update the<br>
  * image's memory requirements (that is, the image's size and alignment).<br>
@@ -213,6 +278,7 @@ make_surface(const struct anv_device *dev,<br>
                                     &image->aux_surface.isl);<br>
          if (ok) {<br>
             add_surface(image, &image->aux_surface);<br>
+            add_clear_value_buffer(image, dev);<br>
<br>
             /* For images created without MUTABLE_FORMAT_BIT set, we know that<br>
              * they will always be used with the original format.  In<br>
@@ -236,6 +302,7 @@ make_surface(const struct anv_device *dev,<br>
                                  &image->aux_surface.isl);<br>
       if (ok) {<br>
          add_surface(image, &image->aux_surface);<br>
+         add_clear_value_buffer(image, dev);<br>
          image->aux_usage = ISL_AUX_USAGE_MCS;<br>
       }<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>