1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-15 07:29:17 +01:00

[dxvk] Fall back to host memory if no device memory is available

This commit is contained in:
Philip Rebohle 2018-02-27 12:36:44 +01:00
parent 757bb2bad7
commit e5c0030f06
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 27 additions and 10 deletions

View File

@ -255,22 +255,35 @@ namespace dxvk {
DxvkMemory DxvkMemoryAllocator::alloc( DxvkMemory DxvkMemoryAllocator::alloc(
const VkMemoryRequirements& req, const VkMemoryRequirements& req,
const VkMemoryPropertyFlags flags) { const VkMemoryPropertyFlags flags) {
DxvkMemory result = this->tryAlloc(req, flags);
for (uint32_t i = 0; i < m_heaps.size(); i++) { if ((result.memory() == VK_NULL_HANDLE) && (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
result = this->tryAlloc(req, flags & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
if (result.memory() == VK_NULL_HANDLE) {
throw DxvkError(str::format(
"DxvkMemoryAllocator: Failed to allocate ",
req.size, " bytes"));
}
return result;
}
DxvkMemory DxvkMemoryAllocator::tryAlloc(
const VkMemoryRequirements& req,
const VkMemoryPropertyFlags flags) {
DxvkMemory result;
for (uint32_t i = 0; i < m_heaps.size() && result.memory() == VK_NULL_HANDLE; i++) {
const bool supported = (req.memoryTypeBits & (1u << i)) != 0; const bool supported = (req.memoryTypeBits & (1u << i)) != 0;
const bool adequate = (m_memProps.memoryTypes[i].propertyFlags & flags) == flags; const bool adequate = (m_memProps.memoryTypes[i].propertyFlags & flags) == flags;
if (supported && adequate) { if (supported && adequate)
DxvkMemory memory = m_heaps[i]->alloc(req.size, req.alignment); result = m_heaps[i]->alloc(req.size, req.alignment);
if (memory.memory() != VK_NULL_HANDLE)
return memory;
}
} }
throw DxvkError(str::format( return result;
"DxvkMemoryAllocator: Failed to allocate ",
req.size, " bytes"));
} }
} }

View File

@ -232,6 +232,10 @@ namespace dxvk {
std::array<Rc<DxvkMemoryHeap>, VK_MAX_MEMORY_TYPES> m_heaps; std::array<Rc<DxvkMemoryHeap>, VK_MAX_MEMORY_TYPES> m_heaps;
DxvkMemory tryAlloc(
const VkMemoryRequirements& req,
const VkMemoryPropertyFlags flags);
}; };
} }