D3D11_USAGE enumeration (d3d11.h)
Identifies expected resource use during rendering. The usage directly reflects whether a resource is accessible by the CPU and/or the graphics processing unit (GPU).
typedef enum D3D11_USAGE {
D3D11_USAGE_DEFAULT = 0,
D3D11_USAGE_IMMUTABLE = 1,
D3D11_USAGE_DYNAMIC = 2,
D3D11_USAGE_STAGING = 3
} ;
D3D11_USAGE_DEFAULT Value: 0 A resource that requires read and write access by the GPU. This is likely to be the most common usage choice. |
D3D11_USAGE_IMMUTABLE Value: 1 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. |
D3D11_USAGE_DYNAMIC Value: 2 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. |
D3D11_USAGE_STAGING Value: 3 A resource that supports data transfer (copy) from the GPU to the CPU. |
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. |
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.
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.
Requirement | Value |
---|---|
Header | d3d11.h |