0

I have used the Vulkan function vkGetPhysicalDeviceMemoryProperties to obtain the memory properties of a specific physical device, i.e. GPU.

I have printed out the returned values from this function (1st column from the left is their enumerated values. Based on this output, I can see there are 2 memory heaps and 11 memoryTypes.

  Memory:
  -memoryTypeCount: 11
  -memoryTypes[VK_MAX_MEMORY_TYPES]:
    -0, propertyFlags: 0, heapIndex: 1
    -1, propertyFlags: 0, heapIndex: 1
    -2, propertyFlags: 0, heapIndex: 1
    -3, propertyFlags: 0, heapIndex: 1
    -4, propertyFlags: 0, heapIndex: 1
    -5, propertyFlags: 0, heapIndex: 1
    -6, propertyFlags: 0, heapIndex: 1
    -7, propertyFlags: 1, heapIndex: 0
    -8, propertyFlags: 1, heapIndex: 0
    -9, propertyFlags: 6, heapIndex: 1
    -10, propertyFlags: 14, heapIndex: 1
  -memoryHeapCount: 2
  -memoryHeaps[VK_MAX_MEMORY_HEAPS]:
    -0, size: 6442450944, flags: 1
    -1, size: 25186016256, flags: 0

Questions:

  1. What does propertyFlags=0 mean ? I can't find it in Vulkan specification.
  2. Does heapIndex=0 and 1 refer to the 1st or 2nd element of memoryHeaps?
  3. What is the advantage of having multiple memoryTypes element? How do I use them in a Vulkan application?
Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
Sun Bear
  • 7,594
  • 11
  • 56
  • 102

1 Answers1

1

What does propertyFlags=0 means? I can't find it in Vulkan specification.

It means exactly what the Vulkan specification says that it means. This memory type:

  • is not DEVICE_LOCAL, so it doesn't represent fast device access.
  • is not HOST_VISIBLE, so you cannot read from/write to it directly from the CPU.

It's a memory type that represents a memory allocation that you cannot directly access, and the GPU won't have the fastest access to either.

Does heapIndex=0 and 1 refers to the 1st or 2nd element of memoryHeaps?

Vulkan is built on C and/or C++. All arrays are zero-based. So heapIndex 0 refers to the initial element in the memoryHeap array.

What is the advantage of having multiple memoryTypes element? How do I use them in a Vulkan application?

Vulkan is an explicit, low-level API. That means you need to make informed decisions about how your application handles things. You ask the hardware what is available, and you adjust your application to the hardware's various features.

The various memory types tell you the ways in which you can allocate memory from various heaps. These control how you can access that memory, as well as describe whether the GPU can access it fast or slow. For a specific use of memory, you must select the memory type most appropriate to that use.

Of course, there's also the fact that buffers and images have restrictions on which memory types they can be allocated from. These restrictions are based on the usage types for those objects (as well as the image format). So you need to check up-front which memory types the buffers and images you intend to use can be allocated through.

Now, why your implementation has multiple copies of the same memory type (memory types with the same flag and memory heap fields), I have no idea.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Thanks. I could not find the definition for propertyFlags=0 in "[typedef enum VkMemoryPropertyFlagBits](https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkMemoryType)" in Vulkan specification. You explanation make sense. Can you tell me where to find your explanation in Vulkan spec? – Sun Bear Jun 05 '17 at 15:03
  • Also, given your explanation on heapIndex, am I correct to say that heapIndex: 1 refers to the memoryHeaps with size: 25186016256, flags : 0, and there are 9 memoryTypes associated to it. I could not find the meaning of flags=0 in [typedef enum VkMemoryHeapFlagBits](https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkMemoryHeapFlagBits) in Vulkan Spec either. Does a CPU RAM explanation concur with your explanation for propertyFlags=0, i.e. GPU cannot directly access the CPU RAM, and the GPU won't have the fastest access to CPU RAM either"? – Sun Bear Jun 05 '17 at 15:13
  • @SunBear: "*Can you tell me where to find your explanation in Vulkan spec?*" I linked right to it. It's a *bit field*: the presence of a bit means that the capability referred to by that bit is available. The absence of a bit means that it is *not* available. 0 means that *none* of the capabilities are available. The specification lists what all the capabilities are. And "device local" doesn't mean that the device cannot access it; it means the device cannot access it *as quickly* as memory that is device local. – Nicol Bolas Jun 05 '17 at 15:29
  • Thanks for your explanations. Really helpful. FYI, your link just points to "Section 10.2. Device Memory" but not to your explanation. I recommend KHR incorporate your explanations to the Spec. Got it, so because a GPU does not have direct access to CPU RAM, the GPU access to CPU RAM will be slower than when the GPU accesses it's own memory. – Sun Bear Jun 05 '17 at 15:50
  • You wrote "A heap represents a specific piece of RAM." in your [answer](https://stackoverflow.com/a/36437023/5722359). For my system, my 4xDDR4 CPU RAM slots were all filled up to provide ~32GB RAM. However, memoryHeaps reported only 25186016256 bytes, i.e. it reported the available RAM, and only 1 heap was used to represent this storage capacity. Hence, is your description that a heap represent a specific piece of RAM still relevant or should it mean the accumulated RAM available in a physical device? – Sun Bear Jun 05 '17 at 16:17
  • On Question 3, Vulkan Spec wrote "More than one memory type may share each heap, and the heaps and memory types provide a mechanism to advertise an accurate size of the physical memory resources while allowing the memory to be used with a variety of different properties." I interpret this to mean that it is reasonable for a VKMemoryHeap to be associate with several VkMemoryTypes, however, the VkmemoryPropertyFlag of each VkMemoryType must be different. Is this interpretation correct? – Sun Bear Jun 05 '17 at 16:33
  • @SunBear: "*the VkmemoryPropertyFlag of each VkMemoryType must be different*" Specifications are not particularly ambiguous. Unless they *explicitly* rule something out (using keywords "must", "must not", etc), then it is possible. So if the specification does not say that the implementation **must not** provide multiple memory types that have the same property flags and heap, then it may. – Nicol Bolas Jun 05 '17 at 16:51
  • @SunBear: Also, Stack Overflow is not a forum. If you have genuine followup questions, you use the "Ask Question" button to ask them. Comments are for clarification. – Nicol Bolas Jun 05 '17 at 16:52