anv: Meet CCS alignment reqs with dedicated allocs

At image bind time, we require BOs to meet aux-map alignment
requirements in order to enable CCS on images. This is a heuristic
controlled by anv_bo_allows_aux_map().

To improve the chances of getting a properly aligned BO, we make use of
the dedicated allocation extension. Firstly, we report to applications a
preference for dedicated memory if an image would like to use the aux
map. Secondly, we align the VMA for dedicated allocations to meet
aux-map requirements.

To make enabling modifiers much easier on integrated gfx12, report
dedicated allocations as a requirement for modifiers which specify CCS.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> (v1)
Reviewed-by: Jianxun Zhang <jianxun.zhang@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25003>
This commit is contained in:
Nanley Chery 2023-08-25 16:10:29 -04:00 committed by Marge Bot
parent 2cbec81041
commit 4cdd3178fb
4 changed files with 36 additions and 1 deletions

View file

@ -1375,7 +1375,7 @@ anv_bo_vma_alloc_or_close(struct anv_device *device,
/* If we're using the AUX map, make sure we follow the required
* alignment.
*/
if (device->info->has_aux_map && (alloc_flags & ANV_BO_ALLOC_IMPLICIT_CCS))
if (device->info->has_aux_map && (alloc_flags & ANV_BO_ALLOC_DEDICATED))
align = MAX2(intel_aux_map_get_alignment(device->aux_map_ctx), align);
/* Opportunistically align addresses to 2Mb when above 1Mb. We do this
@ -1563,6 +1563,7 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device,
{
assert(!(alloc_flags & (ANV_BO_ALLOC_MAPPED |
ANV_BO_ALLOC_SNOOPED |
ANV_BO_ALLOC_DEDICATED |
ANV_BO_ALLOC_FIXED_ADDRESS)));
assert(!(alloc_flags & ANV_BO_ALLOC_IMPLICIT_CCS) ||

View file

@ -3942,6 +3942,7 @@ VkResult anv_AllocateMemory(
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO:
dedicated_info = (void *)ext;
alloc_flags |= ANV_BO_ALLOC_DEDICATED;
break;
case VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO: {

View file

@ -1898,6 +1898,24 @@ anv_image_get_memory_requirements(struct anv_device *device,
*/
requirements->prefersDedicatedAllocation = true;
requirements->requiresDedicatedAllocation = true;
} else if (anv_image_uses_aux_map(device, image)) {
/* We request a dedicated allocation to guarantee that the BO will
* be aux-map compatible (see anv_bo_vma_alloc_or_close and
* anv_bo_allows_aux_map).
*
* TODO: This is an untested heuristic. It's not known if this
* guarantee is worth losing suballocation.
*
* If we don't have an aux-map compatible BO at the time we bind
* this image to device memory, we'll change the aux usage.
*
* It may be possible to handle an image using a modifier in the
* same way. However, we choose to keep things simple and require
* a dedicated allocation for that case.
*/
requirements->prefersDedicatedAllocation = true;
requirements->requiresDedicatedAllocation =
isl_drm_modifier_has_aux(image->vk.drm_format_mod);
} else {
requirements->prefersDedicatedAllocation = false;
requirements->requiresDedicatedAllocation = false;

View file

@ -400,6 +400,9 @@ enum anv_bo_alloc_flags {
/** For descriptor pools */
ANV_BO_ALLOC_DESCRIPTOR_POOL = (1 << 13),
/** This BO will be dedicated to a buffer or an image */
ANV_BO_ALLOC_DEDICATED = (1 << 14),
};
struct anv_bo {
@ -4919,6 +4922,18 @@ anv_image_plane_uses_aux_map(const struct anv_device *device,
isl_aux_usage_has_ccs(image->planes[plane].aux_usage);
}
static inline bool
anv_image_uses_aux_map(const struct anv_device *device,
const struct anv_image *image)
{
for (uint32_t p = 0; p < image->n_planes; ++p) {
if (anv_image_plane_uses_aux_map(device, image, p))
return true;
}
return false;
}
static inline bool
anv_bo_allows_aux_map(const struct anv_device *device,
const struct anv_bo *bo)