Default 3d [1.16] [1.15.2] [1.14.4] [1.12.2]
Constants
A resource that requires read and write access by the GPU. This is likely to be the most common usage choice. |
A resource that can only be read by the GPU. It cannot be written by the GPU, and cannot be accessed at all by the CPU. This type of resource must be initialized when it is created, since it cannot be changed after creation. |
A resource that is accessible by both the GPU (read only) and the CPU (write only). A dynamic resource is a good choice for a resource that will be updated by the CPU at least once per frame. To update a dynamic resource, use a Map method.For info about how to use dynamic resources, see How to: Use dynamic resources. |
A resource that supports data transfer (copy) from the GPU to the CPU. |
Remarks
An application identifies the way a resource is intended to be used (its usage) in a resource description. There are several structures for creating resources including: D3D11_TEXTURE1D_DESC, D3D11_TEXTURE2D_DESC, D3D11_TEXTURE3D_DESC, and D3D11_BUFFER_DESC.
Differences between Direct3D 9 and Direct3D 10/11:
In Direct3D 9, you specify the type of memory a resource should be created in at resource creation time (using D3DPOOL). It was an application’s job to decide what memory pool would provide the best combination of functionality and performance. In Direct3D 10/11, an application no longer specifies what type of memory (the pool) to create a resource in. Instead, you specify the intended usage of the resource, and let the runtime (in concert with the driver and a memory manager) choose the type of memory that will achieve the best performance. |
Resource Usage Restrictions
D3D11_USAGE_DEFAULTD3D11_USAGE_STAGINGD3D11_USAGE_DEFAULTD3D11_USAGE_STAGINGID3D11DeviceContext::CopySubresourceRegionID3D11DeviceContext::CopyResourceID3D11DeviceContext::UpdateSubresourceD3D11_USAGE_DEFAULT
D3D11_USAGE_DYNAMIC usage is a special case that optimizes the flow of data from CPU to GPU when the CPU generates that data on-the-fly and sends that data with high frequency. D3D11_USAGE_DYNAMIC is typically used on resources with vertex data and on constant buffers. Use the ID3D11DeviceContext::Map and ID3D11DeviceContext::Unmap methods to write data to these resources. To achieve the highest performance for data consumed serially, like vertex data, use the D3D11_MAP_WRITE_NO_OVERWRITE and D3D11_MAP_WRITE_DISCARD sequence. For more info about this sequence, see Common Usage of D3D11_MAP_WRITE_DISCARD with D3D11_MAP_WRITE_NO_OVERWRITE.
D3D11_USAGE_IMMUTABLE usage is another special case that causes the GPU to generate data just once when you create a resource. D3D11_USAGE_IMMUTABLE is well-suited to data such as textures because such data is typically read into memory from some file format. Therefore, when you create a texture with D3D11_USAGE_IMMUTABLE, the GPU directly reads that texture into memory.
Use the following table to choose the usage that best describes how the resource will need to be accessed by the CPU and/or the GPU. Of course, there will be performance tradeoffs.
Resource Usage | Default | Dynamic | Immutable | Staging |
---|---|---|---|---|
GPU-Read | yes | yes | yes | yes¹ |
GPU-Write | yes | yes¹ | ||
CPU-Read | yes¹ | |||
CPU-Write | yes | yes¹ |
1 — GPU read or write of a resource with the D3D11_USAGE_STAGING usage is restricted to copy operations. You use ID3D11DeviceContext::CopySubresourceRegion and ID3D11DeviceContext::CopyResource for these copy operations. Also, because depth-stencil formats and multisample layouts are implementation details of a particular GPU design, the operating system can’t expose these formats and layouts to the CPU in general. Therefore, staging resources can’t be a depth-stencil buffer or a multisampled render target.
Note You can technically use ID3D11DeviceContext::UpdateSubresource to copy to a resource with any usage except D3D11_USAGE_IMMUTABLE. However, we recommend to use ID3D11DeviceContext::UpdateSubresource to update only a resource with D3D11_USAGE_DEFAULT. We recommend to use ID3D11DeviceContext::Map and ID3D11DeviceContext::Unmap to update resources with D3D11_USAGE_DYNAMIC because that is the specific purpose of D3D11_USAGE_DYNAMIC resources, and is therefore the most optimized path.
Note D3D11_USAGE_DYNAMIC resources consume specific hardware capabilities. Therefore, use them sparingly. The display driver typically allocates memory for D3D11_USAGE_DYNAMIC resources with a caching algorithm that favors CPU writes and hinders CPU reads. Furthermore, the memory behind D3D11_USAGE_DYNAMIC resources might not even be the same for successive calls to ID3D11DeviceContext::Map. Therefore, do not expect high performance or even consistent CPU reads from D3D11_USAGE_DYNAMIC resources.
Note ID3D11DeviceContext::CopyStructureCount is a special case of GPU-to-CPU copy. Use ID3D11DeviceContext::CopyStructureCount only with unordered access views (UAVs) of buffers.
Resource Bind Options
Resource Can Be Bound As | Default | Dynamic | Immutable | Staging |
---|---|---|---|---|
Input to a Stage | yes² | yes³ | yes | |
Output from a Stage | yes² |
- 2 — If bound as an input and an output using different views, each view must use different subresources.
- 3 — The resource can only be created with a single subresource. The resource cannot be a texture array. The resource cannot be a mipmap chain.