diff --git a/.pick_status.json b/.pick_status.json index 6cc3e19accb..30d7a818b11 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -130,7 +130,7 @@ "description": "radv: reject binding buffer/image when the device memory is too small", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 975536acc6e..52551ba4a5a 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -5427,14 +5427,27 @@ radv_GetDeviceMemoryCommitment(VkDevice device, VkDeviceMemory memory, } VkResult -radv_BindBufferMemory2(VkDevice device, uint32_t bindInfoCount, +radv_BindBufferMemory2(VkDevice _device, uint32_t bindInfoCount, const VkBindBufferMemoryInfo *pBindInfos) { + RADV_FROM_HANDLE(radv_device, device, _device); + for (uint32_t i = 0; i < bindInfoCount; ++i) { RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory); RADV_FROM_HANDLE(radv_buffer, buffer, pBindInfos[i].buffer); if (mem) { + if (mem->alloc_size) { + VkMemoryRequirements req; + + radv_GetBufferMemoryRequirements(_device, pBindInfos[i].buffer, &req); + + if (pBindInfos[i].memoryOffset + req.size > mem->alloc_size) { + return vk_errorf(device->instance, VK_ERROR_UNKNOWN, + "Device memory object too small for the buffer.\n"); + } + } + buffer->bo = mem->bo; buffer->offset = pBindInfos[i].memoryOffset; } else { @@ -5457,14 +5470,27 @@ radv_BindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, } VkResult -radv_BindImageMemory2(VkDevice device, uint32_t bindInfoCount, +radv_BindImageMemory2(VkDevice _device, uint32_t bindInfoCount, const VkBindImageMemoryInfo *pBindInfos) { + RADV_FROM_HANDLE(radv_device, device, _device); + for (uint32_t i = 0; i < bindInfoCount; ++i) { RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory); RADV_FROM_HANDLE(radv_image, image, pBindInfos[i].image); if (mem) { + if (mem->alloc_size) { + VkMemoryRequirements req; + + radv_GetImageMemoryRequirements(_device, pBindInfos[i].image, &req); + + if (pBindInfos[i].memoryOffset + req.size > mem->alloc_size) { + return vk_errorf(device->instance, VK_ERROR_UNKNOWN, + "Device memory object too small for the image.\n"); + } + } + image->bo = mem->bo; image->offset = pBindInfos[i].memoryOffset; } else {