Graphics Reference
In-Depth Information
As we have seen earlier in this chapter, there are two unordered access view descrip-
tion flags that create a hidden counter for managing the contents of a buffer. The first is the
D3D11_BUFFER_UAV_FLAG_APPEND flag, which lets a buffer be used as an append/consume
buffer. The second is the D3Dll_BUFFER_UAV_FLAG_COUNTER flag, which directly adds the
hidden counter for manipulation with the IncrementCounter() and DecrementCounter()
methods in HLSL. The CopyStructureCount() method works by taking a pointer to the
UAV that contains the counter as the source and then copies that value into a destination
buffer at the offset specified in the DstAlignedByteOffset parameter.
The ability to copy the counter value into another buffer has uses in indirect rendering
operations. When a buffer is filled with vertex data by a compute or pixel shader program,
it can be used to render a model indirectly with a buffer resource that indicates how many
primitives to render. The counter value can be placed at the proper location in the buffer by
using the appropriate index when copying it. Then, the application simply passes the indi-
rect buffer to the draw call. Indirect rendering has been discussed in the "Buffer Resources"
section of this chapter, and is also covered in Chapter 3.
This functionality can also be used to stage the structure count data for eventual reading
by the CPU. This is performed in the same way we described in the "Copy Resource" section.
2.3.3 Generating Resource Contents
There is also a pair of device context methods that can be used to generate the contents of
a resource. We discuss both of these methods here.
Generate Mips
Earlier in this chapter, we saw the miscellaneous resource creation flag for indicating that a
texture resource should be able to generate the lower-resolution mip-map levels when its top
level is rendered. This is indicated with the D3D11_RES0URCE_MISC_GENERATE_MIPS flag.
The generation of the mip-map level data is initiated with the ID3DllDeviceContext::
GenerateMips() method. The method prototype is shown in Listing 2.55. The method
only takes a pointer to the shader resource view to be updated, whose attached resource
must have been created with the flag mentioned above. In addition, the number of mip-map
levels that will be generated is defined by the subresource range selected by the shader
resource view.
void GenerateMips(
ID3D11ShaderResourceView *pShaderResourceView
);
Listing 2.55. The generate mips method prototype.
Search WWH ::




Custom Search