From 8116d65fbc20002886aa1a6e5de0fbfb5f8b8bf9 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Mon, 29 Jun 2020 11:56:48 +0200 Subject: [PATCH] v3dv: improve handling of too large image sizes Instead of asserting that users don't try to create images that would require 4GB+ of memory, error out with the corresponding OOM error when the user tries to actually allocate the memory for the image. Part-of: --- src/broadcom/vulkan/v3dv_device.c | 5 ++++- src/broadcom/vulkan/v3dv_private.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index 046c58c6739..800b89eb103 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -1363,10 +1363,13 @@ device_alloc(struct v3dv_device *device, VkDeviceSize size) { /* Our kernel interface is 32-bit */ - assert((size & 0xffffffff) == size); + if (size > UINT32_MAX) + return VK_ERROR_OUT_OF_DEVICE_MEMORY; + mem->bo = v3dv_bo_alloc(device, size, "device_alloc", false); if (!mem->bo) return VK_ERROR_OUT_OF_DEVICE_MEMORY; + return VK_SUCCESS; } diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 2445bad7956..5020895fd9c 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -404,7 +404,7 @@ struct v3dv_image { bool tiled; struct v3d_resource_slice slices[V3D_MAX_MIP_LEVELS]; - uint32_t size; /* Total size in bytes */ + uint64_t size; /* Total size in bytes */ uint32_t cube_map_stride; uint32_t alignment;