Vulkan 中 memoryTypes 的含义 [英] Meaning of memoryTypes in Vulkan

查看:40
本文介绍了Vulkan 中 memoryTypes 的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 Vulkan 函数 vkGetPhysicalDeviceMemoryProperties 来获取特定物理设备(即 GPU)的内存属性.

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

我已经打印出这个函数的返回值(左起第一列是它们的枚举值.根据这个输出,我可以看到有 2 个内存堆和 11 个内存类型.

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

问题:

  1. propertyFlags=0 是什么意思?我在 Vulkan 规范中找不到它.
  2. heapIndex=0 和 1 是指内存堆的第一个元素还是第二个元素?
  3. 拥有多个 memoryTypes 元素有什么好处?如何在 Vulkan 应用程序中使用它们?

推荐答案

propertyFlags=0 是什么意思?我在 Vulkan 规范中找不到.

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

这正是Vulkan 规范的意思说这意味着.这种内存类型:

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

  • 不是 DEVICE_LOCAL,因此不代表快速设备访问.
  • 不是 HOST_VISIBLE,因此您无法直接从 CPU 读取/写入它.

这是一种内存类型,表示您无法直接访问的内存分配,GPU 也不会以最快的速度访问.

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.

heapIndex=0 和 1 是指内存堆的第一个元素还是第二个元素?

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

Vulkan 基于 C 和/或 C++ 构建.所有数组都是从零开始的.所以heapIndex 0 指的是memoryHeap 数组中的初始元素.

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.

拥有多个 memoryTypes 元素有什么好处?如何在 Vulkan 应用程序中使用它们?

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

Vulkan 是一个显式的低级 API.这意味着您需要就应用程序如何处理事情做出明智的决定.您询问硬件有什么可用,然后根据硬件的各种功能调整您的应用程序.

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.

各种内存类型告诉您从各种堆分配内存的方式.这些控制您如何访问该内存,以及描述 GPU 是否可以快速或慢速访问它.对于内存的特定用途,您必须选择最适合该用途的内存类型.

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.

这篇关于Vulkan 中 memoryTypes 的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆