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:
parent
757bb2bad7
commit
e5c0030f06
@ -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))
|
||||||
const bool supported = (req.memoryTypeBits & (1u << i)) != 0;
|
result = this->tryAlloc(req, flags & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
const bool adequate = (m_memProps.memoryTypes[i].propertyFlags & flags) == flags;
|
|
||||||
|
|
||||||
if (supported && adequate) {
|
|
||||||
DxvkMemory memory = m_heaps[i]->alloc(req.size, req.alignment);
|
|
||||||
|
|
||||||
if (memory.memory() != VK_NULL_HANDLE)
|
|
||||||
return memory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (result.memory() == VK_NULL_HANDLE) {
|
||||||
throw DxvkError(str::format(
|
throw DxvkError(str::format(
|
||||||
"DxvkMemoryAllocator: Failed to allocate ",
|
"DxvkMemoryAllocator: Failed to allocate ",
|
||||||
req.size, " bytes"));
|
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 adequate = (m_memProps.memoryTypes[i].propertyFlags & flags) == flags;
|
||||||
|
|
||||||
|
if (supported && adequate)
|
||||||
|
result = m_heaps[i]->alloc(req.size, req.alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user