DirectX 12-描述符堆 [英] DirectX 12 - Descriptor heaps

查看:459
本文介绍了DirectX 12-描述符堆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习新的DirectX 12 API.我想在dx12之上编写一种渲染引擎,并在初始化期间创建描述符堆.这样做的问题是,目前我还不知道将来会创建多少资源视图.例如如果我想包括一些需要渲染到纹理方法的后期处理效果,则必须为要渲染到的纹理创建渲染目标视图.这些RTV的数量可能会有所不同.那么,如何创建足以应付各种情况的描述符堆呢?

有什么建议吗?

解决方案

使用描述符堆的想法是要有一个可见的大gpu和一堆可见的cpu.这是因为SetDescriptorHeaps是一项昂贵的操作,您不希望一次调用一帧或两次以上.

您需要使用大的gpu可见堆作为环形缓冲区,为要准备的当前绘制或调度分配空间,并从具有此功能的各种cpu可见描述符中进行复制.您可以拥有任意数量的cpu可见描述符堆,或多或少只是将常规分配包装到d3d对象中.

该副本没有任何生命周期保护,并且由cpu立即执行,请注意不要将鼠标悬停在GPU上可能仍在使用的描述符上.

我在这里谈论SRV和采样器. RTV仅在CPU上可见,并且您可以随意创建任意数量的描述符堆,如果愿意,可以每个描述符创建一个描述符堆,而不必关心d3d对象的开销,它将对运行时的性能没有影响. >

I've just been starting to learn the new DirectX 12 API. I want to write sone kind of rendering engine on top of dx12 and during initialization I'm supposed to create descriptor heaps. The problem with that is that at this point in time I don't know how many resource views I will create in the future. e.g. if I want to include some kinds of post processing effects which require render to texture approaches I have to create render target views for the textures I'm rendering to. The amount of those RTVs can vary though. So how do you create descriptor heaps being big enough to cope with every situation?

Any advice?

解决方案

The idea with descriptor heaps is to have a big gpu visible one, and a bunch of cpu visible ones. it is because SetDescriptorHeaps is a costly operation, you do not want to call it more than once or twice a frame.

You need to use the big gpu visible heap as a ring buffer, allocating room for the current draw or dispatch you want to prepare and copy from the various cpu visible descriptors you have for it. You can have as many cpu visible descriptor heaps you want, it is more or less just a regular allocation wrap into a d3d object.

The copy does not have any life time protection and is perform instantly by the cpu, be careful to not roll over a descriptor that may still be in use on the GPU.

I am talking about SRV and samplers here. RTV are only CPU visible, and you are free to create as many descriptor heaps as you want, one per descriptor if you like and don't care much from the d3d object overhead, it will have no performance implication on the runtime.

这篇关于DirectX 12-描述符堆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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