summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-01-02 07:52:22 -0800
committerJason Ekstrand <[email protected]>2016-01-02 07:52:24 -0800
commit6b0b57225cf27aa5316b6c3085fa3254f0f4b1c2 (patch)
treee31ae43ceba14f822569d0665d1b5b2b847149fc
parentf076d5330dca4b7a882de17853d6aedccb4e50ad (diff)
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.
-rw-r--r--src/vulkan/anv_device.c7
-rw-r--r--src/vulkan/anv_private.h6
2 files changed, 11 insertions, 2 deletions
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)
{