Hello,
In D3D12 we have SetGraphicsRootDescriptorTable/SetComputeRootDescriptorTable on command list to bind a range of descriptors from the descriptor heap. Very often descriptors are scattered in the descriptor heap. Potentially, you will end up with multiple calls to SetGraphicsRootDescriptorTable and SetGraphicsRootDescriptorTable to bind them.
Recently, MJP has published his DeferredTextureing sample https://github.com/TheRealMJP/DeferredTexturing, where he is following this principle to manage resources:
1.SRVs, CBVs, UAVs, Samplers are created in shader invisible descriptor heap by default. Thus, they have CPU read/write access but not GPU access. I know that you need to have your descriptors in this descriptor heap to be able to execute CopyDescriptors and ClearUnorderedAccessView. Maybe, there are more use cases.
2.During the shader resource binding stage, he copies their descriptors into shader visible descriptor heap, by calling CopyDescriptors on D3D12 device. This allows to have GPU access to the resources and to group them in one range to have only one call to SetGraphicsRootDescriptorTable/SetComputeRootDescriptorTable.
This approach, by placing your descriptors at the creation stage into shader invisible descriptor heap and then copying them into shader visible descriptor heap during binding stage, seems like a good idea to handle operations, requiring CPU read/write access on your resource and grouping your resources in one descriptor table. I am wondering if this is the recommended way to manage resources?
I also had a quick look at the source code in Unreal Engine. They seem to be using the same CopyDescriptors principle while binding resources.
Microsoft D3D12 samples, I had a chance to go through, I find not very representative when it comes to demonstrating this.
Usually, they have a few render passes, where they manage to place descriptors grouped together in the descriptor heap.
In the app with multiple render passes, it is very unlikely to have grouped descriptors for each draw/dispatch call in advance.
CopyDescriptors feels like the way to overcome that.
There is an article from Intel where they talk about D3D12 resource binding model advantages over D3D11 one https://software.intel.com/en-us/blogs/2014/08/07/direct3d-12-overview-part-4-heaps-and-tables. I am interested in Redundant Resource Binding section, where they describe the need for the driver to copy resource bindings to a new location to bind them for the draw call. Isn't explicit CopyDescriptors does what actually is handled by the driver in their case? Is it really advantage of the resource management in D3D12 then? I am not really sure if we can compare this two copy operations.
I would be really appreciative to hear your input on this.
Thanks