Mesa (main): zink: error when trying to allocate a bo larger than heap size
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Nov 1 01:14:22 UTC 2021
Module: Mesa
Branch: main
Commit: fd2b47281f1b63312a58c2f7e77ee39f0858ba95
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd2b47281f1b63312a58c2f7e77ee39f0858ba95
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Thu Oct 28 09:48:15 2021 -0400
zink: error when trying to allocate a bo larger than heap size
this is illegal and would fail anyway
cc: mesa-stable
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13584>
---
src/gallium/drivers/zink/zink_bo.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_bo.c b/src/gallium/drivers/zink/zink_bo.c
index 6a554ec91f2..ad4282dc2d8 100644
--- a/src/gallium/drivers/zink/zink_bo.c
+++ b/src/gallium/drivers/zink/zink_bo.c
@@ -243,6 +243,21 @@ bo_create_internal(struct zink_screen *screen,
alignment = get_optimal_alignment(screen, size, alignment);
+ VkMemoryAllocateInfo mai;
+ mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ mai.pNext = pNext;
+ mai.allocationSize = size;
+ mai.memoryTypeIndex = screen->heap_map[heap];
+ if (screen->info.mem_props.memoryTypes[mai.memoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
+ alignment = MAX2(alignment, screen->info.props.limits.minMemoryMapAlignment);
+ mai.allocationSize = align64(mai.allocationSize, screen->info.props.limits.minMemoryMapAlignment);
+ }
+ unsigned heap_idx = screen->info.mem_props.memoryTypes[screen->heap_map[heap]].heapIndex;
+ if (mai.allocationSize > screen->info.mem_props.memoryHeaps[heap_idx].size) {
+ mesa_loge("zink: can't allocate %"PRIu64" bytes from heap that's only %"PRIu64" bytes!\n", mai.allocationSize, screen->info.mem_props.memoryHeaps[heap_idx].size);
+ return NULL;
+ }
+
/* all non-suballocated bo can cache */
init_pb_cache = true;
@@ -256,15 +271,6 @@ bo_create_internal(struct zink_screen *screen,
pb_cache_init_entry(&screen->pb.bo_cache, bo->cache_entry, &bo->base, heap);
}
- VkMemoryAllocateInfo mai;
- mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- mai.pNext = pNext;
- mai.allocationSize = size;
- mai.memoryTypeIndex = screen->heap_map[heap];
- if (screen->info.mem_props.memoryTypes[mai.memoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
- alignment = MAX2(alignment, screen->info.props.limits.minMemoryMapAlignment);
- mai.allocationSize = align64(mai.allocationSize, screen->info.props.limits.minMemoryMapAlignment);
- }
VkResult ret = VKSCR(AllocateMemory)(screen->dev, &mai, NULL, &bo->mem);
if (!zink_screen_handle_vkresult(screen, ret))
goto fail;
More information about the mesa-commit
mailing list