有人可以帮助我了解VkPhysicalDeviceMemoryProperties吗? [英] Could someone help me understand VkPhysicalDeviceMemoryProperties?

查看:664
本文介绍了有人可以帮助我了解VkPhysicalDeviceMemoryProperties吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚,但是有点卡住了.

I'm trying to figure it out, but I'm getting a little stuck.

类型和堆之间的关联方式很简单,如果有些奇怪的话. (为什么不给VkMemoryHeap一个VkMemoryType成员?)

The way the types and heaps are related is simple, if a bit strange. (why not just give VkMemoryHeap a VkMemoryType member?)

我想我理解所有VkMemoryPropertyFlags的含义,它们看起来非常简单.

I think I understand what all the VkMemoryPropertyFlags mean, they seem fairly straightforward.

但是VkMemoryHeap.flags成员怎么了?它显然只有一个非零的有效值VkMemoryHeapFlagBits.VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,尽管它本身并不太奇怪,但是堆的内存类型上可能还存在一个VkMemoryPropertyFlagBits.VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT.

But what's with the VkMemoryHeap.flags member? It apparently only has one non-zero valid value, VkMemoryHeapFlagBits.VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, and though that wouldn't be too odd on it's own, but there's also a VkMemoryPropertyFlagBits.VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT that could be present on the memory type of the heap.

VkMemoryHeap.flags成员是什么意思,它与VkMemoryType.flags成员有什么关系?

What does the VkMemoryHeap.flags member mean and how does it relate to the VkMemoryType.flags member?

推荐答案

当涉及到内存时,Vulkan可以识别两个不同的概念.设备可以与之通信的是实际的物理RAM.然后,有方法从那些RAM池之一分配内存.

Vulkan recognizes two distinct concepts when it comes to memory. There are the actual physical pieces of RAM that the device can talk to. Then there are ways to allocate memory from one of those pools of RAM.

堆代表特定的RAM. VkMemoryHeap是描述设备可以与之交谈的可用RAM堆之一的对象.实际上,定义特定堆的东西并不多.仅两个:该RAM存储的字节数以及该存储相对于Vulkan设备的位置(本地与非本地).

A heap represents a specific piece of RAM. VkMemoryHeap is the object that describes one of the available heaps of RAM that the device can talk to. There really aren't that many things that define a particular heap. Just two: the number of bytes of that RAMs storage and the storage's location relative to the Vulkan device (local vs. non-local).

内存类型是从特定堆分配内存的特定手段. VkMemoryType是描述分配内存的特定方式的对象.还有更多关于如何从堆中分配内存的描述性标志.

A memory type is a particular means of allocating memory from a specific heap. VkMemoryType is the object that describes a particular way of allocating memory. And there are a lot more descriptive flags for how you can allocate memory from a heap.

对于更具体的示例,请考虑具有独立GPU的标准PC设置.该设备具有自己的本地RAM,但独立的GPU也可以访问CPU内存.因此,Vulkan设备将有两个堆:其中一个堆是本地的,另一个是非本地的.

For a more concrete example, consider a standard PC setup with a discrete GPU. The device has its own local RAM, but the discrete GPU can also access CPU memory. So a Vulkan device will have two heaps: one of them will be local, the other non-local.

但是,通常会有两种以上的内存类型.通常,您有一种表示本地内存的内存类型,没有设置VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT.这意味着您无法映射内存.您只能通过其他某种内存类型(或渲染操作等)的传输操作来访问它.

However, there will usually be more than two memory types. You usually have one memory type that represents local memory, which does not have the VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set. That means you can't map the memory; you can only access it via transfer operations from some other memory type (or from rendering operations or whatever).

但是您经常会遇到两种都使用相同非本地堆的内存类型.它们都将是VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,因此允许映射.但是,其中一个可能设置了VK_MEMORY_PROPERTY_HOST_CACHED_BIT标志,而另一个将设置为VK_MEMORY_PROPERTY_HOST_COHERENT_BIT.这样,您可以选择是要缓存的CPU访问权限(因此需要显式刷新修改后的内存范围)还是未缓存的CPU访问权限.

But you will often have two memory types that both use the same non-local heap. They will both be VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, thus allowing mapping. However, one of them will likely have the VK_MEMORY_PROPERTY_HOST_CACHED_BIT flag set, while the other will be VK_MEMORY_PROPERTY_HOST_COHERENT_BIT. This allows you to choose whether you want cached CPU access (thus requiring an explicit flush of ranges of modified memory) or uncached CPU access.

但是,尽管它们是两种不同的内存类型,但是它们都从同一个 heap 中分配.这就是为什么VkMemoryType的索引指向要为其分配内存的堆的原因.

But while they are two separate memory types, they both allocate from the same heap. Which is why VkMemoryType has an index that refers to the heap who's memory it is allocating from.

我唯一不了解的是两个DEVICE_LOCAL标志如何相互作用.

Only thing I'm not getting is how the two DEVICE_LOCAL flags interact.

您看过规格吗?它并没有完全隐藏它的工作原理:

Did you look at the specification? It's not exactly hiding how this works:

如果propertyFlags设置了VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT位,则使用此类型分配的内存对于设备访问而言是最有效的.此属性仅针对具有VK_MEMORY_HEAP_DEVICE_LOCAL_BIT设置的堆的内存类型设置.

if propertyFlags has the VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT bit set, memory allocated with this type is the most efficient for device access. This property will only be set for memory types belonging to heaps with the VK_MEMORY_HEAP_DEVICE_LOCAL_BIT set.

是说如果内存是本地的,那么对应于该内存的所有类型都是本地的,或者它们可以是本地的?

Is it saying that if the memory is local then all types corresponding to that memory are local, or that they can be local?

您似乎正在试图将错误的含义强加给这些东西.只需看看规格说明中的内容,并以其面值为准即可.

You seem to be trying to impose the wrong meaning to these things. Just look at what the specification says and take it at face value.

PROPERTY_DEVICE_LOCAL表示将实现最佳设备访问性能的内存类型.与MEMORY_DEVICE_LOCAL之间的唯一联系是,带有PROPERTY_DEVICE_LOCAL的内存类型将仅与使用MEMORY_DEVICE_LOCAL的内存堆关联.

PROPERTY_DEVICE_LOCAL denotes a memory type which will achieve the best device access performance. The only connection between this and MEMORY_DEVICE_LOCAL is that memory types with PROPERTY_DEVICE_LOCAL will only be associated with memory heaps that use MEMORY_DEVICE_LOCAL.

这是这里唯一的相关含义.

That's the only relevant meaning here.

如果您想获得一个内存堆何时位于设备本地,而内存类型却并非本地的示例,请考虑一个不具有自己内存的GPU.只有一个堆,因此是MEMORY_DEVICE_LOCAL.

If you want an example of when a memory heap would be device local, yet have memory types that aren't, consider a GPU that has no memory of its own. There's only one heap, which is therefore MEMORY_DEVICE_LOCAL.

但是,以一种使主机可见的方式从该池中分配内存可能会降低设备对该内存的访问性能.因此,对于此类硬件,同一堆的主机可见内存类型将不要使用PROPERTY_DEVICE_LOCAL.

However, allocating memory from that pool in a way that makes it host-visible may decrease the performance of device access to that memory. Therefore, for such hardware, the host-visible memory types for the same heap will not use PROPERTY_DEVICE_LOCAL.

然后,其他硬件不会因为制造内存主机而损失性能-可见的.因此,它们只有一种内存类型,它具有所有可用的属性.对于英特尔来说,他们的片上GPU显然可以访问CPU的某些级别的缓存.

Then again, other hardware doesn't lose performance from making memory host-visible. So they only have one memory type, which has all of the available properties. For Intel, their on-chip GPUs apparently have access to some level of the CPU's caches.

这篇关于有人可以帮助我了解VkPhysicalDeviceMemoryProperties吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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