anv: Change params of anv_can_fast_clear_color_view

Expand the scope to more than just image views.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31167>
This commit is contained in:
Nanley Chery
2024-09-09 15:51:50 -04:00
committed by Marge Bot
parent 83fdbf8772
commit 44351d67f8
4 changed files with 76 additions and 73 deletions

View File

@@ -1485,21 +1485,20 @@ can_fast_clear_color_att(struct anv_cmd_buffer *cmd_buffer,
return false; return false;
} }
/* We only support fast-clears on the first layer */ /* We only support fast-clearing a single layer */
if (pRects[0].layerCount > 1 || pRects[0].baseArrayLayer > 0) if (pRects[0].layerCount > 1)
return false; return false;
bool is_multiview = cmd_buffer->state.gfx.view_mask != 0; bool is_multiview = cmd_buffer->state.gfx.view_mask != 0;
if (is_multiview && (cmd_buffer->state.gfx.view_mask != 1)) if (is_multiview && (cmd_buffer->state.gfx.view_mask != 1))
return false; return false;
return anv_can_fast_clear_color_view(cmd_buffer->device, return anv_can_fast_clear_color_view(cmd_buffer, att->iview->image,
(struct anv_image_view *)att->iview, att->iview->vk.base_mip_level,
att->layout, pRects, att->layout,
clear_color, att->iview->planes[0].isl.format,
pRects->layerCount, att->iview->planes[0].isl.swizzle,
pRects->rect, clear_color);
cmd_buffer->queue_family->queueFlags);
} }
static void static void

View File

@@ -247,9 +247,10 @@ anv_can_hiz_clear_ds_view(struct anv_device *device,
static bool static bool
isl_color_value_requires_conversion(union isl_color_value color, isl_color_value_requires_conversion(union isl_color_value color,
const struct isl_surf *surf, const struct isl_surf *surf,
const struct isl_view *view) enum isl_format view_format,
struct isl_swizzle view_swizzle)
{ {
if (surf->format == view->format && isl_swizzle_is_identity(view->swizzle)) if (surf->format == view_format && isl_swizzle_is_identity(view_swizzle))
return false; return false;
uint32_t surf_pack[4] = { 0, 0, 0, 0 }; uint32_t surf_pack[4] = { 0, 0, 0, 0 };
@@ -257,42 +258,38 @@ isl_color_value_requires_conversion(union isl_color_value color,
uint32_t view_pack[4] = { 0, 0, 0, 0 }; uint32_t view_pack[4] = { 0, 0, 0, 0 };
union isl_color_value swiz_color = union isl_color_value swiz_color =
isl_color_value_swizzle_inv(color, view->swizzle); isl_color_value_swizzle_inv(color, view_swizzle);
isl_color_value_pack(&swiz_color, view->format, view_pack); isl_color_value_pack(&swiz_color, view_format, view_pack);
return memcmp(surf_pack, view_pack, sizeof(surf_pack)) != 0; return memcmp(surf_pack, view_pack, sizeof(surf_pack)) != 0;
} }
bool bool
anv_can_fast_clear_color_view(struct anv_device *device, anv_can_fast_clear_color_view(const struct anv_cmd_buffer *cmd_buffer,
struct anv_image_view *iview, const struct anv_image *image,
unsigned level,
const struct VkClearRect *clear_rect,
VkImageLayout layout, VkImageLayout layout,
union isl_color_value clear_color, enum isl_format view_format,
uint32_t num_layers, struct isl_swizzle view_swizzle,
VkRect2D render_area, union isl_color_value clear_color)
const VkQueueFlagBits queue_flags)
{ {
if (INTEL_DEBUG(DEBUG_NO_FAST_CLEAR)) if (INTEL_DEBUG(DEBUG_NO_FAST_CLEAR))
return false; return false;
if (iview->planes[0].isl.base_array_layer >=
anv_image_aux_layers(iview->image, VK_IMAGE_ASPECT_COLOR_BIT,
iview->planes[0].isl.base_level))
return false;
/* Start by getting the fast clear type. We use the first subpass /* Start by getting the fast clear type. We use the first subpass
* layout here because we don't want to fast-clear if the first subpass * layout here because we don't want to fast-clear if the first subpass
* to use the attachment can't handle fast-clears. * to use the attachment can't handle fast-clears.
*/ */
enum anv_fast_clear_type fast_clear_type = enum anv_fast_clear_type fast_clear_type =
anv_layout_to_fast_clear_type(device->info, iview->image, anv_layout_to_fast_clear_type(cmd_buffer->device->info, image,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT, layout,
layout, queue_flags); cmd_buffer->queue_family->queueFlags);
switch (fast_clear_type) { switch (fast_clear_type) {
case ANV_FAST_CLEAR_NONE: case ANV_FAST_CLEAR_NONE:
return false; return false;
case ANV_FAST_CLEAR_DEFAULT_VALUE: case ANV_FAST_CLEAR_DEFAULT_VALUE:
if (!isl_color_value_is_zero(clear_color, iview->planes[0].isl.format)) if (!isl_color_value_is_zero(clear_color, view_format))
return false; return false;
break; break;
case ANV_FAST_CLEAR_ANY: case ANV_FAST_CLEAR_ANY:
@@ -303,10 +300,10 @@ anv_can_fast_clear_color_view(struct anv_device *device,
* alignment restrictions. It's easier to just restrict to full size * alignment restrictions. It's easier to just restrict to full size
* fast clears for now. * fast clears for now.
*/ */
if (render_area.offset.x != 0 || if (clear_rect->rect.offset.x != 0 ||
render_area.offset.y != 0 || clear_rect->rect.offset.y != 0 ||
render_area.extent.width != iview->vk.extent.width || clear_rect->rect.extent.width != image->vk.extent.width ||
render_area.extent.height != iview->vk.extent.height) clear_rect->rect.extent.height != image->vk.extent.height)
return false; return false;
/* If the clear color is one that would require non-trivial format /* If the clear color is one that would require non-trivial format
@@ -315,9 +312,9 @@ anv_can_fast_clear_color_view(struct anv_device *device,
* format re-interpretation is for sRGB. * format re-interpretation is for sRGB.
*/ */
if (isl_color_value_requires_conversion(clear_color, if (isl_color_value_requires_conversion(clear_color,
&iview->image->planes[0].primary_surface.isl, &image->planes[0].primary_surface.isl,
&iview->planes[0].isl)) { view_format, view_swizzle)) {
anv_perf_warn(VK_LOG_OBJS(&iview->vk.base), anv_perf_warn(VK_LOG_OBJS(&image->vk.base),
"Cannot fast-clear to colors which would require " "Cannot fast-clear to colors which would require "
"format conversion on resolve"); "format conversion on resolve");
return false; return false;
@@ -330,25 +327,26 @@ anv_can_fast_clear_color_view(struct anv_device *device,
* were no known applications which would benefit from fast-clearing * were no known applications which would benefit from fast-clearing
* more than just the first slice. * more than just the first slice.
*/ */
if (iview->planes[0].isl.base_level > 0 || if (level > 0) {
iview->planes[0].isl.base_array_layer > 0) { anv_perf_warn(VK_LOG_OBJS(&image->vk.base),
anv_perf_warn(VK_LOG_OBJS(&iview->image->vk.base), "level > 0. Not fast clearing.");
"Rendering with multi-lod or multi-layer framebuffer " return false;
"with LOAD_OP_LOAD and baseMipLevel > 0 or " }
if (clear_rect->baseArrayLayer > 0) {
anv_perf_warn(VK_LOG_OBJS(&image->vk.base),
"baseArrayLayer > 0. Not fast clearing."); "baseArrayLayer > 0. Not fast clearing.");
return false; return false;
} }
if (num_layers > 1) { if (clear_rect->layerCount > 1) {
anv_perf_warn(VK_LOG_OBJS(&iview->image->vk.base), anv_perf_warn(VK_LOG_OBJS(&image->vk.base),
"Rendering to a multi-layer framebuffer with " "layerCount > 1. Only fast-clearing the first slice");
"LOAD_OP_CLEAR. Only fast-clearing the first slice");
} }
/* Wa_18020603990 - slow clear surfaces up to 256x256, 32bpp. */ /* Wa_18020603990 - slow clear surfaces up to 256x256, 32bpp. */
if (intel_needs_workaround(device->info, 18020603990)) { if (intel_needs_workaround(cmd_buffer->device->info, 18020603990)) {
const struct anv_surface *anv_surf = const struct anv_surface *anv_surf = &image->planes->primary_surface;
&iview->image->planes->primary_surface;
if (isl_format_get_layout(anv_surf->isl.format)->bpb <= 32 && if (isl_format_get_layout(anv_surf->isl.format)->bpb <= 32 &&
anv_surf->isl.logical_level0_px.w <= 256 && anv_surf->isl.logical_level0_px.w <= 256 &&
anv_surf->isl.logical_level0_px.h <= 256) anv_surf->isl.logical_level0_px.h <= 256)
@@ -358,10 +356,10 @@ anv_can_fast_clear_color_view(struct anv_device *device,
/* On gfx12.0, CCS fast clears don't seem to cover the correct portion of /* On gfx12.0, CCS fast clears don't seem to cover the correct portion of
* the aux buffer when the pitch is not 512B-aligned. * the aux buffer when the pitch is not 512B-aligned.
*/ */
if (device->info->verx10 == 120 && if (cmd_buffer->device->info->verx10 == 120 &&
iview->image->planes->primary_surface.isl.samples == 1 && image->planes->primary_surface.isl.samples == 1 &&
iview->image->planes->primary_surface.isl.row_pitch_B % 512) { image->planes->primary_surface.isl.row_pitch_B % 512) {
anv_perf_warn(VK_LOG_OBJS(&iview->image->vk.base), anv_perf_warn(VK_LOG_OBJS(&image->vk.base),
"Pitch not 512B-aligned. Slow clearing surface."); "Pitch not 512B-aligned. Slow clearing surface.");
return false; return false;
} }
@@ -376,15 +374,14 @@ anv_can_fast_clear_color_view(struct anv_device *device,
* address, raw & converted such that all fixed functions can find the * address, raw & converted such that all fixed functions can find the
* value they need. * value they need.
*/ */
if (device->info->ver == 9 && if (cmd_buffer->device->info->ver == 9 &&
isl_format_is_srgb(iview->planes[0].isl.format) && isl_format_is_srgb(view_format) &&
!isl_color_value_is_zero_one(clear_color, !isl_color_value_is_zero_one(clear_color, view_format))
iview->planes[0].isl.format))
return false; return false;
/* Wa_16021232440: Disable fast clear when height is 16k */ /* Wa_16021232440: Disable fast clear when height is 16k */
if (intel_needs_workaround(device->info, 16021232440) && if (intel_needs_workaround(cmd_buffer->device->info, 16021232440) &&
iview->vk.extent.height == 16 * 1024) { image->vk.extent.height == 16 * 1024) {
return false; return false;
} }

View File

@@ -5780,13 +5780,14 @@ anv_can_hiz_clear_ds_view(struct anv_device *device,
const VkQueueFlagBits queue_flags); const VkQueueFlagBits queue_flags);
bool bool
anv_can_fast_clear_color_view(struct anv_device *device, anv_can_fast_clear_color_view(const struct anv_cmd_buffer *cmd_buffer,
struct anv_image_view *iview, const struct anv_image *image,
unsigned level,
const struct VkClearRect *clear_rect,
VkImageLayout layout, VkImageLayout layout,
union isl_color_value clear_color, enum isl_format view_format,
uint32_t num_layers, struct isl_swizzle view_swizzle,
VkRect2D render_area, union isl_color_value clear_color);
const VkQueueFlagBits queue_flags);
enum isl_aux_state ATTRIBUTE_PURE enum isl_aux_state ATTRIBUTE_PURE
anv_layout_to_aux_state(const struct intel_device_info * const devinfo, anv_layout_to_aux_state(const struct intel_device_info * const devinfo,

View File

@@ -5215,6 +5215,12 @@ void genX(CmdBeginRendering)(
if (att->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR && if (att->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR &&
!(gfx->rendering_flags & VK_RENDERING_RESUMING_BIT)) { !(gfx->rendering_flags & VK_RENDERING_RESUMING_BIT)) {
uint32_t clear_view_mask = pRenderingInfo->viewMask;
VkClearRect clear_rect = {
.rect = render_area,
.baseArrayLayer = iview->vk.base_array_layer,
.layerCount = layers,
};
const union isl_color_value clear_color = const union isl_color_value clear_color =
vk_to_isl_color_with_format(att->clearValue.color, vk_to_isl_color_with_format(att->clearValue.color,
iview->planes[0].isl.format); iview->planes[0].isl.format);
@@ -5222,10 +5228,12 @@ void genX(CmdBeginRendering)(
/* We only support fast-clears on the first layer */ /* We only support fast-clears on the first layer */
const bool fast_clear = const bool fast_clear =
(!is_multiview || (gfx->view_mask & 1)) && (!is_multiview || (gfx->view_mask & 1)) &&
anv_can_fast_clear_color_view(cmd_buffer->device, iview, anv_can_fast_clear_color_view(cmd_buffer, iview->image,
att->imageLayout, clear_color, iview->vk.base_mip_level,
layers, render_area, &clear_rect, att->imageLayout,
cmd_buffer->queue_family->queueFlags); iview->planes[0].isl.format,
iview->planes[0].isl.swizzle,
clear_color);
if (att->imageLayout != initial_layout) { if (att->imageLayout != initial_layout) {
assert(render_area.offset.x == 0 && render_area.offset.y == 0 && assert(render_area.offset.x == 0 && render_area.offset.y == 0 &&
@@ -5256,9 +5264,6 @@ void genX(CmdBeginRendering)(
} }
} }
uint32_t clear_view_mask = pRenderingInfo->viewMask;
uint32_t base_clear_layer = iview->vk.base_array_layer;
uint32_t clear_layer_count = gfx->layer_count;
if (fast_clear) { if (fast_clear) {
/* We only support fast-clears on the first layer */ /* We only support fast-clears on the first layer */
assert(iview->vk.base_mip_level == 0 && assert(iview->vk.base_mip_level == 0 &&
@@ -5284,8 +5289,8 @@ void genX(CmdBeginRendering)(
false); false);
} }
clear_view_mask &= ~1u; clear_view_mask &= ~1u;
base_clear_layer++; clear_rect.baseArrayLayer++;
clear_layer_count--; clear_rect.layerCount--;
#if GFX_VER < 20 #if GFX_VER < 20
genX(set_fast_clear_state)(cmd_buffer, iview->image, genX(set_fast_clear_state)(cmd_buffer, iview->image,
iview->planes[0].isl.format, iview->planes[0].isl.format,
@@ -5311,7 +5316,8 @@ void genX(CmdBeginRendering)(
iview->planes[0].isl.format, iview->planes[0].isl.format,
iview->planes[0].isl.swizzle, iview->planes[0].isl.swizzle,
iview->vk.base_mip_level, iview->vk.base_mip_level,
base_clear_layer, clear_layer_count, clear_rect.baseArrayLayer,
clear_rect.layerCount,
render_area, clear_color); render_area, clear_color);
} }
} else { } else {