[Mesa-dev] [RFC v2 11/23] anv/image: Refactor creation of aux surfaces
Louis-Francis Ratté-Boulianne
lfrb at collabora.com
Thu Aug 31 04:24:15 UTC 2017
From: Chad Versace <chadversary at chromium.org>
Creation of hiz, ccs, and mcs surfaces was encoded by a giant 'if' tree
at the tail of make_surface(). This patch extracts that 'if' tree into
the new functions:
make_hiz_surface_maybe()
make_ccs_surface_maybe()
make_mcs_surface_maybe()
For clarity, also rename make_surface() to make_main_surface().
---
src/intel/vulkan/anv_image.c | 211 ++++++++++++++++++++++++++-----------------
1 file changed, 126 insertions(+), 85 deletions(-)
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 3d1b3f1e73..c225113987 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -209,6 +209,125 @@ add_fast_clear_state_buffer(struct anv_image *image,
image->size += entry_size * anv_image_aux_levels(image);
}
+static void
+make_hiz_surface_maybe(const struct anv_device *dev,
+ const VkImageCreateInfo *base_info,
+ struct anv_image *image)
+{
+ bool ok;
+
+ assert(image->aux_surface.isl.size == 0);
+ assert(!(image->usage & VK_IMAGE_USAGE_STORAGE_BIT));
+
+ if (unlikely(INTEL_DEBUG & DEBUG_NO_HIZ))
+ return;
+
+ /* Allow the user to control HiZ enabling through environment variables.
+ * Disable by default on gen7 because resolves are not currently
+ * implemented pre-BDW.
+ */
+ if (!(image->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
+ /* It will never be used as an attachment, HiZ is pointless. */
+ } else if (dev->info.gen == 7) {
+ anv_perf_warn("Implement gen7 HiZ");
+ } else if (base_info->mipLevels > 1) {
+ anv_finishme("Enable multi-LOD HiZ");
+ } else if (base_info->arrayLayers > 1) {
+ anv_finishme("Implement multi-arrayLayer HiZ clears and resolves");
+ } else if (dev->info.gen == 8 && base_info->samples > 1) {
+ anv_finishme("Test gen8 multisampled HiZ");
+ } else {
+ ok = isl_surf_get_hiz_surf(&dev->isl_dev, &image->depth_surface.isl,
+ &image->aux_surface.isl);
+ assert(ok);
+ add_surface(image, &image->aux_surface);
+ image->aux_usage = ISL_AUX_USAGE_HIZ;
+ }
+}
+
+static void
+make_ccs_surface_maybe(const struct anv_device *dev,
+ const VkImageCreateInfo *base_info,
+ struct anv_image *image)
+{
+ bool ok;
+
+ assert(image->aux_surface.isl.size == 0);
+
+ if (unlikely(INTEL_DEBUG & DEBUG_NO_RBC))
+ return;
+
+ ok = isl_surf_get_ccs_surf(&dev->isl_dev, &image->color_surface.isl,
+ &image->aux_surface.isl, 0);
+ if (!ok)
+ return;
+
+ /* Disable CCS when it is not useful (i.e., when you can't render
+ * to the image with CCS enabled).
+ */
+ if (!isl_format_supports_rendering(&dev->info, image->color_surface.isl.format)) {
+ /* While it may be technically possible to enable CCS for this
+ * image, we currently don't have things hooked up to get it
+ * working.
+ */
+ anv_perf_warn("This image format doesn't support rendering. "
+ "Not allocating an CCS buffer.");
+ image->aux_surface.isl.size = 0;
+ return;
+ }
+
+ add_surface(image, &image->aux_surface);
+ add_fast_clear_state_buffer(image, dev);
+
+ /* For images created without MUTABLE_FORMAT_BIT set, we know that they will
+ * always be used with the original format. In particular, they will always
+ * be used with a format that supports color compression. If it's never
+ * used as a storage image, then it will only be used through the sampler or
+ * the as a render target. This means that it's safe to just leave
+ * compression on at all times for these formats.
+ */
+ if (!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&
+ !(base_info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) &&
+ isl_format_supports_ccs_e(&dev->info, image->color_surface.isl.format)) {
+ image->aux_usage = ISL_AUX_USAGE_CCS_E;
+ }
+}
+
+static void
+make_mcs_surface_maybe(const struct anv_device *dev,
+ const VkImageCreateInfo *base_info,
+ struct anv_image *image)
+{
+ bool ok;
+
+ assert(image->aux_surface.isl.size == 0);
+ assert(!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT));
+
+ ok = isl_surf_get_mcs_surf(&dev->isl_dev, &image->color_surface.isl,
+ &image->aux_surface.isl);
+ if (!ok)
+ return;
+
+ add_surface(image, &image->aux_surface);
+ add_fast_clear_state_buffer(image, dev);
+ image->aux_usage = ISL_AUX_USAGE_MCS;
+}
+
+static void
+make_aux_surface_maybe(const struct anv_device *dev,
+ const VkImageCreateInfo *base_info,
+ VkImageAspectFlags aspect,
+ struct anv_image *image)
+{
+ if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) {
+ make_hiz_surface_maybe(dev, base_info, image);
+ } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples == 1) {
+ make_ccs_surface_maybe(dev, base_info, image);
+ } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples > 1) {
+ make_mcs_surface_maybe(dev, base_info, image);
+ }
+}
+
/**
* Initialize the anv_image::*_surface selected by \a aspect. Then update the
* image's memory requirements (that is, the image's size and alignment).
@@ -216,10 +335,10 @@ add_fast_clear_state_buffer(struct anv_image *image,
* Exactly one bit must be set in \a aspect.
*/
static void
-make_surface(const struct anv_device *dev,
- struct anv_image *image,
- const struct anv_image_create_info *anv_info,
- VkImageAspectFlags aspect)
+make_main_surface(const struct anv_device *dev,
+ const struct anv_image_create_info *anv_info,
+ VkImageAspectFlags aspect,
+ struct anv_image *image)
{
const VkImageCreateInfo *base_info = anv_info->vk_info;
bool ok UNUSED;
@@ -260,86 +379,6 @@ make_surface(const struct anv_device *dev,
assert(ok);
add_surface(image, anv_surf);
-
- /* Add a HiZ surface to a depth buffer that will be used for rendering.
- */
- if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) {
- /* We don't advertise that depth buffers could be used as storage
- * images.
- */
- assert(!(image->usage & VK_IMAGE_USAGE_STORAGE_BIT));
-
- /* Allow the user to control HiZ enabling. Disable by default on gen7
- * because resolves are not currently implemented pre-BDW.
- */
- if (!(image->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
- /* It will never be used as an attachment, HiZ is pointless. */
- } else if (dev->info.gen == 7) {
- anv_perf_warn("Implement gen7 HiZ");
- } else if (base_info->mipLevels > 1) {
- anv_perf_warn("Enable multi-LOD HiZ");
- } else if (base_info->arrayLayers > 1) {
- anv_perf_warn("Implement multi-arrayLayer HiZ clears and resolves");
- } else if (dev->info.gen == 8 && base_info->samples > 1) {
- anv_perf_warn("Enable gen8 multisampled HiZ");
- } else if (!unlikely(INTEL_DEBUG & DEBUG_NO_HIZ)) {
- assert(image->aux_surface.isl.size == 0);
- ok = isl_surf_get_hiz_surf(&dev->isl_dev, &image->depth_surface.isl,
- &image->aux_surface.isl);
- assert(ok);
- add_surface(image, &image->aux_surface);
- image->aux_usage = ISL_AUX_USAGE_HIZ;
- }
- } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples == 1) {
- if (!unlikely(INTEL_DEBUG & DEBUG_NO_RBC)) {
- assert(image->aux_surface.isl.size == 0);
- ok = isl_surf_get_ccs_surf(&dev->isl_dev, &anv_surf->isl,
- &image->aux_surface.isl, 0);
- if (ok) {
-
- /* Disable CCS when it is not useful (i.e., when you can't render
- * to the image with CCS enabled).
- */
- if (!isl_format_supports_rendering(&dev->info, format)) {
- /* While it may be technically possible to enable CCS for this
- * image, we currently don't have things hooked up to get it
- * working.
- */
- anv_perf_warn("This image format doesn't support rendering. "
- "Not allocating an CCS buffer.");
- image->aux_surface.isl.size = 0;
- return VK_SUCCESS;
- }
-
- add_surface(image, &image->aux_surface);
- add_fast_clear_state_buffer(image, dev);
-
- /* For images created without MUTABLE_FORMAT_BIT set, we know that
- * they will always be used with the original format. In
- * particular, they will always be used with a format that
- * supports color compression. If it's never used as a storage
- * image, then it will only be used through the sampler or the as
- * a render target. This means that it's safe to just leave
- * compression on at all times for these formats.
- */
- if (!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&
- !(base_info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) &&
- isl_format_supports_ccs_e(&dev->info, format)) {
- image->aux_usage = ISL_AUX_USAGE_CCS_E;
- }
- }
- }
- } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples > 1) {
- assert(image->aux_surface.isl.size == 0);
- assert(!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT));
- ok = isl_surf_get_mcs_surf(&dev->isl_dev, &anv_surf->isl,
- &image->aux_surface.isl);
- if (ok) {
- add_surface(image, &image->aux_surface);
- add_fast_clear_state_buffer(image, dev);
- image->aux_usage = ISL_AUX_USAGE_MCS;
- }
- }
}
VkResult
@@ -379,7 +418,9 @@ anv_image_create(VkDevice _device,
uint32_t b;
for_each_bit(b, image->aspects) {
- make_surface(device, image, anv_info, (1 << b));
+ VkImageAspectFlagBits aspect = 1 << b;
+ make_main_surface(device, anv_info, aspect, image);
+ make_aux_surface_maybe(device, base_info, aspect, image);
}
*pImage = anv_image_to_handle(image);
--
2.13.0
More information about the mesa-dev
mailing list