From: Jason Ekstrand Date: Sat, 2 Jan 2016 15:52:22 +0000 (-0800) Subject: anv/device: Only allocate whole pages in AllocateMemory X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6b0b57225cf27aa5316b6c3085fa3254f0f4b1c2;p=mesa.git anv/device: Only allocate whole pages in AllocateMemory The kernel is going to give us whole pages anyway, so allocating part of a page doesn't help. And this ensures that we can always work with whole pages. --- diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index 9a56d9b7de0..c070aaf2125 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -1020,7 +1020,10 @@ VkResult anv_AllocateMemory( if (mem == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - result = anv_bo_init_new(&mem->bo, device, pAllocateInfo->allocationSize); + /* The kernel is going to give us whole pages anyway */ + uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096); + + result = anv_bo_init_new(&mem->bo, device, alloc_size); if (result != VK_SUCCESS) goto fail; @@ -1088,7 +1091,7 @@ VkResult anv_MapMemory( uint64_t map_size = (offset + size) - map_offset; /* Let's map whole pages */ - map_size = (map_size + 4095) & ~4095ull; + map_size = align_u64(map_size, 4096); mem->map = anv_gem_mmap(device, mem->bo.gem_handle, map_offset, map_size, gem_flags); diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 44d537ac5a8..cc9e139c034 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -86,6 +86,12 @@ align_u32(uint32_t v, uint32_t a) return (v + a - 1) & ~(a - 1); } +static inline uint64_t +align_u64(uint64_t v, uint64_t a) +{ + return (v + a - 1) & ~(a - 1); +} + static inline int32_t align_i32(int32_t v, int32_t a) {