radv: add a size check in radv_create_buffer for Android
authorChia-I Wu <olvaffe@gmail.com>
Wed, 15 Feb 2023 19:11:16 +0000 (11:11 -0800)
committerMarge Bot <emma+marge@anholt.net>
Fri, 17 Feb 2023 18:14:34 +0000 (18:14 +0000)
This is to make dEQP-VK.api.buffer.basic.size_max_uint64 pass on
android.

The test creates a buffer of size UINT64_MAX and makes sure the memory
requirement for the buffer is sane.  It fails because our memory
requirement is "align64(UINT64_MAX, 16)" which is 0 after overflow.

The test checks maintenance4's maxBufferSize and is skipped normally.
But the extension can be disabled on an android build.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21346>

src/amd/vulkan/radv_device.c

index 556342e..e903c65 100644 (file)
@@ -6820,6 +6820,14 @@ radv_create_buffer(struct radv_device *device, const VkBufferCreateInfo *pCreate
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
 
+#ifdef ANDROID
+   /* reject buffers that are larger than maxBufferSize on Android, which
+    * might not have VK_KHR_maintenance4
+    */
+   if (pCreateInfo->size > RADV_MAX_MEMORY_ALLOCATION_SIZE)
+      return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+#endif
+
    buffer = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*buffer), 8,
                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (buffer == NULL)