CopyDescriptors between different heaps

Started by
2 comments, last by Funkymunky 4 years, 11 months ago

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?

Advertisement

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?

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!

This topic is closed to new replies.

Advertisement