Fallback to device local memory if lazily allocated memory is not available

This commit is contained in:
saschawillems 2016-03-30 20:31:51 +02:00
parent 79df037c92
commit cf1532dcc5

View file

@ -142,9 +142,14 @@ public:
vkGetImageMemoryRequirements(device, multisampleTarget.color.image, &memReqs); vkGetImageMemoryRequirements(device, multisampleTarget.color.image, &memReqs);
VkMemoryAllocateInfo memAlloc = vkTools::initializers::memoryAllocateInfo(); VkMemoryAllocateInfo memAlloc = vkTools::initializers::memoryAllocateInfo();
memAlloc.allocationSize = memReqs.size; memAlloc.allocationSize = memReqs.size;
// Try to get a lazily allocated memory type // We prefer a lazily allocated memory type
// todo : Fallback to other memory formats? // This means that the memory get allocated when the implementation sees fit, e.g. when first using the images
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &memAlloc.memoryTypeIndex); VkBool32 lazyMemType = getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &memAlloc.memoryTypeIndex);
if (!lazyMemType)
{
// If this is not available, fall back to device local memory
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memAlloc.memoryTypeIndex);
}
vkTools::checkResult(vkAllocateMemory(device, &memAlloc, nullptr, &multisampleTarget.color.memory)); vkTools::checkResult(vkAllocateMemory(device, &memAlloc, nullptr, &multisampleTarget.color.memory));
vkBindImageMemory(device, multisampleTarget.color.image, multisampleTarget.color.memory, 0); vkBindImageMemory(device, multisampleTarget.color.image, multisampleTarget.color.memory, 0);
@ -181,12 +186,14 @@ public:
vkTools::checkResult(vkCreateImage(device, &info, nullptr, &multisampleTarget.depth.image)); vkTools::checkResult(vkCreateImage(device, &info, nullptr, &multisampleTarget.depth.image));
vkGetImageMemoryRequirements(device, multisampleTarget.depth.image, &memReqs); vkGetImageMemoryRequirements(device, multisampleTarget.depth.image, &memReqs);
memAlloc = vkTools::initializers::memoryAllocateInfo(); memAlloc = vkTools::initializers::memoryAllocateInfo();
memAlloc.allocationSize = memReqs.size; memAlloc.allocationSize = memReqs.size;
// Try to get a lazily allocated memory type lazyMemType = getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &memAlloc.memoryTypeIndex);
// todo : Fallback to other memory formats? if (!lazyMemType)
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &memAlloc.memoryTypeIndex); {
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memAlloc.memoryTypeIndex);
}
vkTools::checkResult(vkAllocateMemory(device, &memAlloc, nullptr, &multisampleTarget.depth.memory)); vkTools::checkResult(vkAllocateMemory(device, &memAlloc, nullptr, &multisampleTarget.depth.memory));
vkBindImageMemory(device, multisampleTarget.depth.image, multisampleTarget.depth.memory, 0); vkBindImageMemory(device, multisampleTarget.depth.image, multisampleTarget.depth.memory, 0);