Graphics Reference
In-Depth Information
to perform the copying. We will examine each of these methods and then present a few
situations they can be employed in. These methods are distinct from those presented in the
"Manipulating Resources" section, in that all of the data that is being moved is already
located within a resource, while the previous methods were used to read or write data with
the CPU.
Copy Resource
To copy the complete contents of one resource to another resource, the device context's
copy resource method would be used. The prototype of this method is shown in Listing 2.52.
void CopyResource(
ID3DllResource *pDstResource,
ID3DllResource *pSrcResource
);
Listing 2.52. The copy resource method prototype.
This is a fairly simple method, which only takes pointers to the source and destina-
tion resource. The resources must be the same type and size and have compatible formats.
Neither immutable resources nor depth stencil resources can serve as the destination. In ad-
dition, multisampled resources cannot be used as either the source or destination (we will
see later in this section how to retrieve the contents of a multisampled resource).
Since this method copies the complete resource, it is most likely to be used to copy
data to the second resource with the desired usage configuration. For example, if a compute
shader is used to generate a data buffer and the application needs to save that buffer to the
hard disk, it cannot directly map and read the buffer. This is because a buffer used for the
unordered access view must have the default usage, which means it cannot be read by the
CPU. This is true of all output from the pipeline—only resources with the default usage
can receive output from the pipeline, and the CPU cannot directly read resources that have
default usage. Instead, a second buffer resource would be created with the staging usage,
and the contents of the default buffer would be copied to the staging buffer. Resources with
the staging usage can be read by the CPU, which solves the problem of getting the data to
the application.
An example of using the copy resource method would be to retrieve the contents of
an append structured buffer that has been filled with data from the compute shader. Since
the append structured buffer has the default usage flags, its contents would need to be cop-
ied to a secondary staging buffer using the CopyResource() method. The staging buffer
could then be used by the CPU to read the contents using the map/unmap methods.
Search WWH ::




Custom Search