About device memory and host-local memory

Hello, memory concept is very important in Vulkan
But Vulkan Spec document explains this concept somewhat confusingly

It is said
Device Memory is
Memory accessible to the device. Represented by a VkDeviceMemory object.

Memory Heap is
A region of memory from which device memory allocations can be made

This means
Device Memory is the same as Memory Heap
Or Memory Heap is a subset of Device Memory
Is this correct?? (But I guess, this may be wrong)

But in Memory Type (VkMemoryHeapFlagBits)
there is a memory type which is neither device-local nor host-visible
So then, this memory is host-local memory but not host-visible, so host cannot access this type
However, application can call VkAllocateMemory there, whose memory type will be host-local but not host-visible
so this memory belongs to outside of host-visible area inside host-local memory(RAM)

Hence, memory heap contains area outside of host-visible area in RAM

Conclusively, inside RAM, there is area which application cannot access but GPU can access,
which is so strange (GPU should access here, because this area belongs to Heap or Device Memory)

Is this correct?
Could you please explain to me about this?
Thank you

You’re confusing a bunch of different concepts. And I’m really not sure how, since you quoted part of a thing you seem to be ignoring.

Device memory are allocations of memory that the device can access. Heaps are where you allocate device memory from. Neither is a “subset” of the other.

Device local, host visible, and so forth are distinct concepts. They’re also concepts which can be applied to both heaps and device memory.

A heap with the VK_MEMORY_HEAP_DEVICE_LOCAL_BIT is a heap from which you can allocate device memory which will have the VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT property set. That is, if you want device memory to be “device local”, it must be allocated from a heap that offers that property. Similarly, if a heat offers the host visible property, then you can make allocations from it that are host visible.

There’s no such thing as “host local”. Perhaps you mean “host visible” or “host coherent”?

A device memory allocation which is “device local” only means that this allocation is presumed to be able to be used by the device quickly. That’s all it is; a hint that this is an optimal allocation for device consumption.

“Host visible” and “host coherent” (two different things) represent how the host can interact with that allocation. If it’s “host visible”, then you can map the allocation and read from or write to that memory via the mapped pointer. “Host coherent” refers to whether you need to explicitly make reads from/writes to that pointer visible to the device.

If an allocation is neither “device local” nor “host visible”, what that means is that the memory isn’t optimal for device usage, but the host cannot map the memory. You can still use transfer commands to copy bytes to/from that memory.

Hello, Alfonse
Thank you so much for your help again
It is midnight here at my home, so I will read your advise in detail tomorrow

And there is a definition of Host-Local Memory in Vulkan Spec Document’s Glossary (last part)

what I found at now from Vulkan Spec Doc. are
Host-local == RAM
Device-Local == VRAM (though, in integrated case, this may be different)

(device-local, host-visible memory) union (host-local, host-visible memory) is a subset of host-visible memory
This is very confusing

See you, Alfonse

below are written in Vulkan Spec Glossary (last part)

Host-Local Memory
Memory that is not local to the device, and may be less performant for device access than
device-local memory.

Device-Local Memory
Memory that is connected to the device, and may be more performant for device access than
host-local memory.

Host Memory
Memory not accessible to the device, used to store implementation data structures.

Device Memory
Memory accessible to the device. Represented by a VkDeviceMemory object.

Memory Heap
A region of memory from which device memory allocations can be made

Device memory is explicitly managed by the application. Each device may advertise one or more
heaps, representing different areas of memory. Memory heaps are either device-local or host-local,
but are always visible to the device. Further detail about memory heaps is exposed via memory
types available on that heap. Examples of memory areas that may be available on an
implementation include:
• device-local is memory that is physically connected to the device.
• device-local, host visible is device-local memory that is visible to the host.
• host-local, host visible is memory that is local to the host and visible to the device and host.

Host-Visible Memory
Device memory that can be mapped on the host and can be read and written by the host.

Memory properties tell you how you can interact with memory allocated from that heap. Host-visible says that you can map memory allocated from that heap.

This property is independent from the device-local property.

Thank you for your help
See you again, Alfonse