]> git.sesse.net Git - ffmpeg/commitdiff
hwcontext_vulkan: check for memory size before choosing type
authorLynne <dev@lynne.ee>
Tue, 24 Nov 2020 22:36:08 +0000 (23:36 +0100)
committerLynne <dev@lynne.ee>
Wed, 25 Nov 2020 22:06:36 +0000 (23:06 +0100)
It makes allocation a bit more robust in case some weird device with
weird drivers which segments memory in weird ways appears.

libavutil/hwcontext_vulkan.c

index 7156952339e0d97b48e83a5b2b68b65bc2fb1e07..d13e6a26ba8d6f0093922cbe636965567464dcb2 100644 (file)
@@ -1270,12 +1270,18 @@ static int alloc_mem(AVHWDeviceContext *ctx, VkMemoryRequirements *req,
     /* The vulkan spec requires memory types to be sorted in the "optimal"
      * order, so the first matching type we find will be the best/fastest one */
     for (int i = 0; i < p->mprops.memoryTypeCount; i++) {
+        const VkMemoryType *type = &p->mprops.memoryTypes[i];
+
         /* The memory type must be supported by the requirements (bitfield) */
         if (!(req->memoryTypeBits & (1 << i)))
             continue;
 
         /* The memory type flags must include our properties */
-        if ((p->mprops.memoryTypes[i].propertyFlags & req_flags) != req_flags)
+        if ((type->propertyFlags & req_flags) != req_flags)
+            continue;
+
+        /* The memory type must be large enough */
+        if (req->size > p->mprops.memoryHeaps[type->heapIndex].size)
             continue;
 
         /* Found a suitable memory type */