问题
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:
- What does propertyFlags=0 mean ? I can't find it in Vulkan specification.
- Does heapIndex=0 and 1 refer to the 1st or 2nd element of memoryHeaps?
- What is the advantage of having multiple memoryTypes element? How do I use them in a Vulkan application?
回答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.
来源:https://stackoverflow.com/questions/44366839/meaning-of-memorytypes-in-vulkan