anv: factor out sanitizing mmap offset code

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Suggested-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24276>
This commit is contained in:
Lionel Landwerlin 2024-09-30 18:43:34 +03:00 committed by Marge Bot
parent b202f0f422
commit 3beb269721
2 changed files with 22 additions and 11 deletions

View File

@ -1792,17 +1792,8 @@ VkResult anv_MapMemory2KHR(
placed_addr = placed_info->pPlacedAddress;
}
/* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
uint64_t map_offset;
if (!device->physical->info.has_mmap_offset)
map_offset = offset & ~4095ull;
else
map_offset = 0;
assert(offset >= map_offset);
uint64_t map_size = (offset + size) - map_offset;
/* Let's map whole pages */
map_size = align64(map_size, 4096);
uint64_t map_offset, map_size;
anv_sanitize_map_params(device, offset, size, &map_offset, &map_size);
void *map;
VkResult result = anv_device_map_bo(device, mem->bo, map_offset,

View File

@ -2149,6 +2149,26 @@ anv_mocs_for_address(const struct anv_device *device,
void anv_device_init_blorp(struct anv_device *device);
void anv_device_finish_blorp(struct anv_device *device);
static inline void
anv_sanitize_map_params(struct anv_device *device,
uint64_t in_offset,
uint64_t in_size,
uint64_t *out_offset,
uint64_t *out_size)
{
/* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
if (!device->physical->info.has_mmap_offset)
*out_offset = in_offset & ~4095ull;
else
*out_offset = 0;
assert(in_offset >= *out_offset);
*out_size = (in_offset + in_size) - *out_offset;
/* Let's map whole pages */
*out_size = align64(*out_size, 4096);
}
VkResult anv_device_alloc_bo(struct anv_device *device,
const char *name, uint64_t size,
enum anv_bo_alloc_flags alloc_flags,