Jump to content
  • Advertisement

DX12 CopyDescriptors between different heaps

Recommended Posts

How does CopyDescriptors work when copying from a CPU-only heap to a Shader-Visible one?  The D3D12_CPU_DESCRIPTOR_HANDLE structure is just a size_t, but if I use CD3DX12_CPU_DESCRIPTOR_HANDLE to create it then it uses the result of GetCPUDescriptorHandleForHeapStart() to offset those size_t's to be specific to that heap.  Is CopyDescriptors from one heap to another going to make all the descriptors be specific to that new heap?

Also, calls like CreateConstantBufferView and CreateShaderResourceView take a descriptor as one of their parameters (which points to a specific location in a heap).  How is that going to get updated for the new heap location?

Share this post

Link to post
Share on other sites

Some terminology:

  • A descriptor is a block of memory, which usually contains descriptions of how to access resources.
  • A descriptor heap is a large block of memory, consisting of multiple descriptors.
  • A CPU descriptor handle is an opaque pointer into one of these heaps. I say "opaque pointer" because each handle is enough to fully address a descriptor in a heap, even though it might not be plainly dereferenceable like a pointer.
  • A GPU descriptor handle is also an opaque pointer, but might not necessarily be enough to fully address a descriptor -- it might only address a specific descriptor when given the context of a heap, which is why command lists have the SetDescriptorHeaps method.

The act of creating a view (CreateConstantBufferView, CreateShaderResourceView, etc) will write some data into a descriptor, which initializes it so it describes the resource. Think of it like placement new.

CopyDescriptors will take the contents from the CPU-only heap and write it into the shader-visible heap. It reads from the descriptors starting at the source handle you specified, and writes into the destination. If you write the same descriptor into multiple destinations, you can then use any of those destination descriptors to refer to the same resource.

Does that answer your question?

Share this post

Link to post
Share on other sites

Ah okay.  So when I call CreateConstantBufferView and pass it a descriptor, I'm really writing that View into the descriptor heap.  Then when I call CopyDescriptors, I'm copying that View into a different heap.  Which means I can copy to a different location in that heap.  Thanks!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!