Graphics Reference
In-Depth Information
of the constant buffer. Instead, we will just write the new data into the buffer. Once the data
has been written to the system memory provided with the pMappedResource structure, the
resource would be unmapped and could then be bound to the pipeline for use.
Update Subresource
The other mechanism that can be used to modify the contents of a resource is the device
context's UpdateSubresource() method. This method differs from mapping of resources
in that it only writes to the resource and does not allow reading its contents. The prototype
of this method is shown in Listing 2.51.
void UpdateSubresource(
ID3D11Resource *pDstResource,
UINT DstSubresource,
const D3D11_B0X *pDstBox,
const void *pSrcData,
UINT SrcRowPitch,
UINT SrcDepthPitch
);
Listing 2.51. The update subresource method prototype.
In Listing 2.50 we can see that data to be written to the resource is given a pointer
to its memory location. This is accompanied by the row pitch and depth pitch of the data
block, measured in bytes. The destination is identified with a pointer to the resource and
a subresource index. It is possible to write to only a portion of a subresource, by identify-
ing it within a D3D11_B0X. While the source data is provided in terms of bytes and is thus
format dependent, the destination is provided in indices and is not dependent on the format
of the resource.
In contrast to methods for mapping a resource, the update subresource method can
write to only a portion of a subresource. If only a small part of a large resource needs to be
updated, the update subresource method can perform better under some conditions, since
it would use less bandwidth.
An example of such a resource update could be changing the contents of a texture based
on an action taken by the user. If the user selects an option that requires modifying a small
portion of a texture, this can easily be performed using the update subresource method.
2.3.2 Copying Resources
There are many situations when the contents of one resource must be copied to another.
This can be done for the needs of a particular algorithm, or to copy data to a second re-
source that has different access capabilities. In both cases, multiple methods are available
Search WWH ::




Custom Search