Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3D11_USAGE_STAGING, what kind of GPU/CPU memory is used?

I read the D3D11 Usage page and coming from a CUDA background I'm wondering what kind of memory would a texture marked as D3D11_USAGE_STAGING be stored into.

I suppose in CUDA it would be pinned page-locked zero-copy memory. I measured the transfer time from a ID3D11Texture2D with D3D11_USAGE_STAGING to a host buffer allocated with malloc and it took almost 7 milliseconds (quite a lot in streaming/gaming) and I thought this would be the time required from GPU global memory to that memory area.

Is any of my suppositions correct? What is D3D11_USAGE_STAGING using as GPU memory?

like image 355
Dean Avatar asked Oct 27 '25 09:10

Dean


1 Answers

The primary use for D3D11_USAGE_STAGING is as a way to load data into other D3D11_USAGE_DEFAULT pool resources. Another common usage is for 'readback' of a render target to CPU accessible memory. You can use CopySubResourceRegion to move data between DEFAULT and STAGING resources (discrete hardware often uses Direct Memory Access to handle the moving of data between system memory and VRAM).

This is a generalization because it depends on the architecture and driver choices, but in short::

  • D3D11_USAGE_STAGING means put it in system memory, and the GPU can't access it.

  • D3D11_USAGE_DEFAULT put it in the VRAM, the CPU can't access it. To put data into it requires copying data from a STAGING resource. You can think of UpdateSubresource as a convenience function that creates a STAGING resource, copies the data to it, copies from STAGING to DEFAULT, then releases the STAGING copy.

    • There is an optional feature in DirectX 11.2 or later than can be implemented by the driver if they choose to allow CPU access even to D3D11_USAGE_DEFAULT pool stuff. This depends on how they have their memory system setup (i.e. in Unified Memory Architectures, system RAM and VRAM are the same thing).
  • D3D11_USAGE_IMMUTABLE is basically the same as D3D11_USAGE_DEFAULT, but you are saying you are only going to initialize it once in the creation call.

  • D3D11_USAGE_DYNAMIC means put it in shared system memory, the CPU & GPU both need access to it. There's usually a performance hit for the GPU to read from this compared to DEFAULT, so you want to use it sparingly. It's really for stuff you generate every frame on the CPU and then need to render (such as terrain systems or procedural geometry).

Games that use content streaming typically have a set of STAGING textures they load data into in the background, and then copy it to DEFAULT textures as they become available for efficient rendering. This lets them reuse both STAGING and DEFAULT textures without the overhead of destroying/creating resources every frame.

See this somewhat dated article on Microsoft Docs: Resource Management Best Practices

like image 62
Chuck Walbourn Avatar answered Oct 29 '25 01:10

Chuck Walbourn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!