anv/image: Add anv_layout_to_aux_usage()

This function supersedes layout_to_hiz_usage().

v2:
- Don't find the optimal buffer for layout transitions (Jason Ekstrand).
- Pass the devinfo instead of the gen (Jason Ekstrand)
- Update the function documentation.

Signed-off-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
Nanley Chery
2017-02-01 11:27:58 -08:00
parent 178f9e5f29
commit 425e33bcdb
2 changed files with 139 additions and 0 deletions

View File

@@ -432,6 +432,140 @@ void anv_GetImageSubresourceLayout(
}
}
/**
* This function determines the optimal buffer to use for device
* accesses given a VkImageLayout and other pieces of information needed to
* make that determination. This does not determine the optimal buffer to
* use during a resolve operation.
*
* NOTE: Some layouts do not support device access.
*
* @param devinfo The device information of the Intel GPU.
* @param image The image that may contain a collection of buffers.
* @param aspects The aspect(s) of the image to be accessed.
* @param layout The current layout of the image aspect(s).
*
* @return The primary buffer that should be used for the given layout.
*/
enum isl_aux_usage
anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
const struct anv_image * const image,
const VkImageAspectFlags aspects,
const VkImageLayout layout)
{
/* Validate the inputs. */
/* The devinfo is needed as the optimal buffer varies across generations. */
assert(devinfo != NULL);
/* The layout of a NULL image is not properly defined. */
assert(image != NULL);
/* The aspects must be a subset of the image aspects. */
assert(aspects & image->aspects && aspects <= image->aspects);
/* Determine the optimal buffer. */
/* If there is no auxiliary surface allocated, we must use the one and only
* main buffer.
*/
if (image->aux_surface.isl.size == 0)
return ISL_AUX_USAGE_NONE;
/* All images that use an auxiliary surface are required to be tiled. */
assert(image->tiling == VK_IMAGE_TILING_OPTIMAL);
/* On BDW+, when clearing the stencil aspect of a depth stencil image,
* the HiZ buffer allows us to record the clear with a relatively small
* number of packets. Prior to BDW, the HiZ buffer provides no known benefit
* to the stencil aspect.
*/
if (devinfo->gen < 8 && aspects == VK_IMAGE_ASPECT_STENCIL_BIT)
return ISL_AUX_USAGE_NONE;
const bool has_depth = aspects & VK_IMAGE_ASPECT_DEPTH_BIT;
const bool color_aspect = aspects == VK_IMAGE_ASPECT_COLOR_BIT;
/* The following switch currently only handles depth stencil aspects.
* TODO: Handle the color aspect.
*/
if (color_aspect)
return image->aux_usage;
switch (layout) {
/* Invalid Layouts */
/* According to the Vulkan Spec, the following layouts are valid only as
* initial layouts in a layout transition and don't support device access.
*/
case VK_IMAGE_LAYOUT_UNDEFINED:
case VK_IMAGE_LAYOUT_PREINITIALIZED:
case VK_IMAGE_LAYOUT_RANGE_SIZE:
case VK_IMAGE_LAYOUT_MAX_ENUM:
unreachable("Invalid image layout for device access.");
/* Transfer Layouts
*
* This buffer could be a depth buffer used in a transfer operation. BLORP
* currently doesn't use HiZ for transfer operations so we must use the main
* buffer for this layout. TODO: Enable HiZ in BLORP.
*/
case VK_IMAGE_LAYOUT_GENERAL:
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
return ISL_AUX_USAGE_NONE;
/* Sampling Layouts */
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
assert(!color_aspect);
/* Fall-through */
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
if (has_depth && anv_can_sample_with_hiz(devinfo->gen, image->samples))
return ISL_AUX_USAGE_HIZ;
else
return ISL_AUX_USAGE_NONE;
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
assert(color_aspect);
/* On SKL+, the render buffer can be decompressed by the presentation
* engine. Support for this feature has not yet landed in the wider
* ecosystem. TODO: Update this code when support lands.
*
* From the BDW PRM, Vol 7, Render Target Resolve:
*
* If the MCS is enabled on a non-multisampled render target, the
* render target must be resolved before being used for other
* purposes (display, texture, CPU lock) The clear value from
* SURFACE_STATE is written into pixels in the render target
* indicated as clear in the MCS.
*
* Pre-SKL, the render buffer must be resolved before being used for
* presentation. We can infer that the auxiliary buffer is not used.
*/
return ISL_AUX_USAGE_NONE;
/* Rendering Layouts */
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
assert(color_aspect);
unreachable("Color images are not yet supported.");
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
assert(!color_aspect);
return ISL_AUX_USAGE_HIZ;
}
/* If the layout isn't recognized in the exhaustive switch above, the
* VkImageLayout value is not defined in vulkan.h.
*/
unreachable("layout is not a VkImageLayout enumeration member.");
}
static struct anv_state
alloc_surface_state(struct anv_device *device)
{

View File

@@ -1777,6 +1777,11 @@ anv_gen8_hiz_op_resolve(struct anv_cmd_buffer *cmd_buffer,
const struct anv_image *image,
enum blorp_hiz_op op);
enum isl_aux_usage
anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
const struct anv_image *image,
const VkImageAspectFlags aspects,
const VkImageLayout layout);
static inline uint32_t
anv_get_layerCount(const struct anv_image *image,
const VkImageSubresourceRange *range)