vkd3d: Make error message more precise when failing to allocate memory.

There are situations where we cannot fallback to system memory, so don't
log that we're going to do so.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2021-10-04 17:48:45 +02:00
parent 9065f312d5
commit 4075809a91
1 changed files with 29 additions and 3 deletions

View File

@ -263,6 +263,17 @@ static HRESULT vkd3d_try_allocate_device_memory(struct d3d12_device *device,
return E_OUTOFMEMORY;
}
static bool vkd3d_memory_info_type_mask_covers_multiple_memory_heaps(
const struct VkPhysicalDeviceMemoryProperties *props, uint32_t type_mask)
{
uint32_t heap_mask = 0;
if (!type_mask)
return false;
while (type_mask)
heap_mask |= 1u << props->memoryTypes[vkd3d_bitmask_iter32(&type_mask)].heapIndex;
return !!(heap_mask & (heap_mask - 1u));
}
HRESULT vkd3d_allocate_device_memory(struct d3d12_device *device,
VkDeviceSize size, VkMemoryPropertyFlags type_flags, uint32_t type_mask,
void *pNext, struct vkd3d_device_memory_allocation *allocation)
@ -275,9 +286,24 @@ HRESULT vkd3d_allocate_device_memory(struct d3d12_device *device,
if (FAILED(hr) && (type_flags & optional_flags))
{
WARN("Memory allocation failed, falling back to system memory.\n");
hr = vkd3d_try_allocate_device_memory(device, size,
type_flags & ~optional_flags, type_mask, pNext, allocation);
if (vkd3d_memory_info_type_mask_covers_multiple_memory_heaps(&device->memory_properties, type_mask))
{
WARN("Memory allocation failed, falling back to system memory.\n");
hr = vkd3d_try_allocate_device_memory(device, size,
type_flags & ~optional_flags, type_mask, pNext, allocation);
}
else if (device->memory_properties.memoryHeapCount > 1)
{
/* It might be the case (NV with RT/DS heap) that we just cannot fall back in any meaningful way.
* E.g. there exists no memory type that is not DEVICE_LOCAL and covers both RT and DS.
* For this case, we have no choice but to not allocate,
* and defer actual memory allocation to CreatePlacedResource() time. */
WARN("Memory allocation failed, but it is not possible to fallback to system memory here. Deferring allocation.\n");
return hr;
}
/* If we fail to allocate, and only have one heap to work with (iGPU),
* falling back is meaningless, just fail. */
}
if (FAILED(hr))