2
votes

For the purpose of this question, we'll say vkMapMemory for all allocations on such a device cannot fail; they are trivially host-visible, and the result is a direct pointer to some other region of host memory (no work needs to be done).

Is there some way to detect this situation?

The purpose in mind is an arena-based allocator that aggressively maps any host-visible memory, and an objective is to avoid redundant allocations on such hardware.

2
"no work needs to be done" Could you explain what "work" would "need to be done" on some other kind of device? It's not clear what this kind of situation avoids. - Nicol Bolas
It's a bit pedantic, but vkMapMemory can still fail for host allocations, due to CPU virtual address space fragmentation for example. - Jesse Hall
The "device" I had in mind might have been better described as a software rasterizer. Though, implementations for UMA-based systems described by @krOoze have little reason to not expose direct pointers to buffer data. - defube

2 Answers

3
votes

Yes, it can be detected relatively reliably.

If vkGetPhysicalDeviceMemoryProperties has only one Memory Heap (which would be labeled VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) then it is certain it is the same memory as host.

In words of the authors:
https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#memory-device

In a unified memory architecture (UMA) system, there is often only a single memory heap which is considered to be equally “local” to the host and to the device, and such an implementation must advertise the heap as device-local.

In other cases you know trivially if the memory is on the host (i.e. the given Memory Heap on dGPU would not have VK_MEMORY_HEAP_DEVICE_LOCAL_BIT set)

1
votes

Though, implementations for UMA-based systems described by @krOoze have little reason to not expose direct pointers to buffer data.

Your question seems to proceed from a false assumption.

Vulkan is not OpenGL. Generally speaking, it does not try to hide things from you. If a memory heap cannot be accessed directly by the CPU, then the Vulkan implementation will not expose a memory type for that heap that is host-visible. Conversely, if a memory heap can be accessed directly by the CPU, then the Vulkan implementation will expose a memory type for that heap that is host-visible.

Therefore, if you can map a device allocation at all in Vulkan, then you should assume that you have a "direct pointer to buffer data".