diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index e082cdce09f..1252ad70cc7 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -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, diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index a42d2d3bdb5..b1d8a5df1ae 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -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,