<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Feb 27, 2017 at 5:20 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This function supersedes layout_to_hiz_usage().<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/anv_image.c | 149 ++++++++++++++++++++++++++++++<wbr>+++++++++++<br>
src/intel/vulkan/anv_private.h | 4 ++<br>
2 files changed, 153 insertions(+)<br>
<br>
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
index cd142938e7..716cdf3a38 100644<br>
--- a/src/intel/vulkan/anv_image.c<br>
+++ b/src/intel/vulkan/anv_image.c<br>
@@ -432,6 +432,155 @@ void anv_GetImageSubresourceLayout(<br>
}<br>
}<br>
<br>
+/**<br>
+ * @brief This function determines the optimal buffer to use for device<br>
+ * accesses given a VkImageLayout and other pieces of information needed to<br>
+ * make that determination. Device accesses may include normal sampling and<br>
+ * rendering operations or resolves.<br>
+ *<br>
+ * @param gen The generation of the Intel GPU.<br>
+ * @param image The image that may contain a collection of buffers.<br>
+ * @param aspects The aspect(s) of the image to be accessed.<br>
+ * @param layout The current layout of the image aspect(s).<br>
+ * @param future_layout The next layout of the image aspect(s), if known.<br>
+ * Otherwise this should be equal to the current layout.<br>
+ *<br>
+ * @return The primary buffer that should be used for the given layout.<br>
+ */<br>
+enum isl_aux_usage<br>
+anv_layout_to_aux_usage(const uint8_t gen, const struct anv_image * const image,<br></blockquote><div><br></div><div>Might be better to take a gen_device_info rather than just the integer. Since we're doing run-time checks anyway, the cost should be small.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ const VkImageAspectFlags aspects, VkImageLayout layout,<br>
+ const VkImageLayout future_layout)<br>
+{<br>
+ /* Validate the inputs. */<br>
+<br>
+ /* Intel GPUs prior to Gen7 are not supported in anv. */<br>
+ assert(gen >= 7);<br>
+<br>
+ /* The layout of a NULL image is not properly defined. */<br>
+ assert(image != NULL);<br>
+<br>
+ /* The aspects must be a subset of the image aspects. */<br>
+ assert(aspects & image->aspects && aspects <= image->aspects);<br>
+<br>
+ /* According to the Vulkan Spec, the following layouts are valid only as<br>
+ * initial layouts in a layout transition and don't support device access.<br>
+ * Therefore, the caller should not be setting the future layout to either.<br>
+ */<br>
+ assert(future_layout != VK_IMAGE_LAYOUT_UNDEFINED &&<br>
+ future_layout != VK_IMAGE_LAYOUT_<wbr>PREINITIALIZED);<br>
+<br>
+ /* Determine the optimal buffer. */<br>
+<br>
+ /* If there is no auxiliary surface allocated, we must use the one and only<br>
+ * main buffer.<br>
+ */<br>
+ if (image->aux_surface.isl.size == 0)<br>
+ return ISL_AUX_USAGE_NONE;<br>
+<br>
+ /* All images that use an auxiliary surface are required to be tiled. */<br>
+ assert(image->tiling == VK_IMAGE_TILING_OPTIMAL);<br>
+<br>
+ /* On BDW+, when clearing the stencil aspect of a depth stencil image,<br>
+ * the HiZ buffer allows us to record the clear with a relatively small<br>
+ * number of packets. Prior to BDW, the HiZ buffer provides no known benefit<br>
+ * to the stencil aspect.<br>
+ */<br>
+ if (gen < 8 && aspects == VK_IMAGE_ASPECT_STENCIL_BIT)<br>
+ return ISL_AUX_USAGE_NONE;<br>
+<br>
+ /* The undefined layout indicates that the user doesn't care about the data<br>
+ * that's currently in the buffer. Therefore, the optimal buffer to use is<br>
+ * the same buffer that would be used in the next layout. This avoids the<br>
+ * possibility of having to resolve in order to maintain coherency.<br>
+ *<br>
+ * The pre-initialized layout is undefined for optimally-tiled images. As<br>
+ * guaranteed by the assertion above, all images that have reached this<br>
+ * point are tiled.<br>
+ */<br>
+ if (layout == VK_IMAGE_LAYOUT_UNDEFINED ||<br>
+ layout == VK_IMAGE_LAYOUT_<wbr>PREINITIALIZED)<br>
+ layout = future_layout;<br>
+<br>
+ const bool has_depth = aspects & VK_IMAGE_ASPECT_DEPTH_BIT;<br>
+ const bool color_aspect = aspects == VK_IMAGE_ASPECT_COLOR_BIT;<br>
+<br>
+ /* The following switch currently only handles depth stencil aspects.<br>
+ * TODO: Handle the color aspect.<br>
+ */<br>
+ if (color_aspect)<br>
+ return image->aux_usage;<br>
+<br>
+ switch (layout) {<br>
+<br>
+ /* Invalid Layouts */<br>
+ case VK_IMAGE_LAYOUT_UNDEFINED:<br>
+ case VK_IMAGE_LAYOUT_<wbr>PREINITIALIZED:<br>
+ case VK_IMAGE_LAYOUT_RANGE_SIZE:<br>
+ case VK_IMAGE_LAYOUT_MAX_ENUM:<br>
+ unreachable("Invalid image layout.");<br>
+<br>
+<br>
+ /* Transfer Layouts<br>
+ *<br>
+ * This buffer could be a depth buffer used in a transfer operation. BLORP<br>
+ * currently doesn't use HiZ for transfer operations so we must use the main<br>
+ * buffer for this layout. TODO: Enable HiZ in BLORP.<br>
+ */<br>
+ case VK_IMAGE_LAYOUT_GENERAL:<br>
+ case VK_IMAGE_LAYOUT_TRANSFER_DST_<wbr>OPTIMAL:<br>
+ case VK_IMAGE_LAYOUT_TRANSFER_SRC_<wbr>OPTIMAL:<br>
+ return ISL_AUX_USAGE_NONE;<br>
+<br>
+<br>
+ /* Sampling Layouts */<br>
+ case VK_IMAGE_LAYOUT_DEPTH_STENCIL_<wbr>READ_ONLY_OPTIMAL:<br>
+ assert(!color_aspect);<br>
+ /* Fall-through */<br>
+ case VK_IMAGE_LAYOUT_SHADER_READ_<wbr>ONLY_OPTIMAL:<br>
+ if (has_depth && anv_can_sample_with_hiz(gen, image->samples))<br>
+ return ISL_AUX_USAGE_HIZ;<br>
+ else<br>
+ return ISL_AUX_USAGE_NONE;<br>
+<br>
+ case VK_IMAGE_LAYOUT_PRESENT_SRC_<wbr>KHR:<br>
+ assert(color_aspect);<br>
+<br>
+ /* On SKL+, the render buffer can be decompressed by the presentation<br>
+ * engine. Support for this feature has not yet landed in the wider<br>
+ * ecosystem. TODO: Update this code when support lands.<br>
+ *<br>
+ * From the BDW PRM, Vol 7, Render Target Resolve:<br>
+ *<br>
+ * If the MCS is enabled on a non-multisampled render target, the<br>
+ * render target must be resolved before being used for other<br>
+ * purposes (display, texture, CPU lock) The clear value from<br>
+ * SURFACE_STATE is written into pixels in the render target<br>
+ * indicated as clear in the MCS.<br>
+ *<br>
+ * Pre-SKL, the render buffer must be resolved before being used for<br>
+ * presentation. We can infer that the auxiliary buffer is not used.<br>
+ */<br>
+ return ISL_AUX_USAGE_NONE;<br>
+<br>
+<br>
+ /* Rendering Layouts */<br>
+ case VK_IMAGE_LAYOUT_COLOR_<wbr>ATTACHMENT_OPTIMAL:<br>
+ assert(color_aspect);<br>
+ unreachable("Color images are not yet supported.");<br>
+<br>
+ case VK_IMAGE_LAYOUT_DEPTH_STENCIL_<wbr>ATTACHMENT_OPTIMAL:<br>
+ assert(!color_aspect);<br>
+ return ISL_AUX_USAGE_HIZ;<br>
+ }<br>
+<br>
+ /* If the layout isn't recognized in the exhaustive switch above, the<br>
+ * VkImageLayout value is not defined in vulkan.h.<br>
+ */<br>
+ unreachable("layout is not a VkImageLayout enumeration member.");<br>
+}<br>
+<br>
+<br>
static struct anv_state<br>
alloc_surface_state(struct anv_device *device)<br>
{<br>
diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
index 2527c2cc5a..5ce9027f88 100644<br>
--- a/src/intel/vulkan/anv_<wbr>private.h<br>
+++ b/src/intel/vulkan/anv_<wbr>private.h<br>
@@ -1671,6 +1671,10 @@ anv_gen8_hiz_op_resolve(struct anv_cmd_buffer *cmd_buffer,<br>
const struct anv_image *image,<br>
enum blorp_hiz_op op);<br>
<br>
+enum isl_aux_usage<br>
+anv_layout_to_aux_usage(const uint8_t gen, const struct anv_image *image,<br>
+ const VkImageAspectFlags aspects, VkImageLayout layout,<br>
+ const VkImageLayout future_layout);<br>
static inline uint32_t<br>
anv_get_layerCount(const struct anv_image *image,<br>
const VkImageSubresourceRange *range)<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.1<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>