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.
One thing to keep in mind is that descriptor memory is nearly unlimited, most projects I know have descriptor heaps that are up to 1024 descriptors in size. Not to mention directx 11 would allocate up to 128 descriptors for each individual shader. So feel no worries to just allocate a bunch of descriptors up front. However if you really want to budget every aspect of the memory I would recommend structuring your engine in a way that can know the individual parameters of every mesh and shader that is going to be rendered in a scene.
来源:https://stackoverflow.com/questions/37277332/directx-12-descriptor-heaps