vk/dma: Initialize COW DMA block contents to avoid leaks

- It is possible to lose data when uploading since the result of map_dma can change types and handles.
- Consider sync-on-exit for inherited spans

Not a problem when using passthrough DMA, but this extension does not work properly on NVIDIA + windows
This commit is contained in:
kd-11 2022-02-16 00:35:40 +03:00 committed by kd-11
parent abd8bd6f36
commit 254ddcad51

View file

@ -70,6 +70,14 @@ namespace vk
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, 0,
VMM_ALLOCATION_POOL_UNDEFINED);
// Initialize memory contents. This isn't something that happens often.
// Pre-loading the contents helps to avoid leakage when mixed types of allocations are in use (NVIDIA)
// TODO: Fix memory lost when old object goes out of use with in-flight data.
auto dst = allocated_memory->map(0, size);
auto src = vm::get_super_ptr(base_address);
std::memcpy(dst, src, size);
allocated_memory->unmap();
s_allocated_dma_pool_size += allocated_memory->size();
}