Locking Resources (Windows CE 5.0)
Locking a resource means granting CPU access to its storage. The following locking methods (see D3DMLOCK Values) are defined for resources:
- D3DMLOCK_DISCARD
- D3DMLOCK_READONLY
- D3DMLOCK_NOOVERWRITE
- D3DMLOCK_NOSYSLOCK
- D3DMLOCK_NO_DIRTY_UPDATE
For details on locking flags and how they relate to specific resources, see the reference topics on the individual resource locking methods. Application developers should note that the D3DMLOCK_DISCARD, D3DMLOCK_READONLY, and D3DMLOCK_NOOVERWRITE flags are only hints. The run time does not check that applications are following the functionality specified by these flags. An application that specifies D3DMLOCK_READONLY but then writes to the resource should expect undefined results. An application that specifies D3DMUSAGE_WRITEONLY but then reads from the resource should expect a significant performance penalty. In general, working against locking flags, including the locking usage flags, is not guaranteed to work in the future and may incur a significant performance penalty both now and in the future.
A lock operation is followed by an unlock operation. For example, after locking a texture, the application subsequently relinquishes direct access to locked textures by unlocking them. In addition to granting processor access, any other operations involving that resource are serialized for the duration of a lock. Only a single lock for a resource is allowed, even for non-overlapping regions, and no accelerator operations on a surface can be ongoing while a lock operation is outstanding on that surface.
Each resource interface has methods for locking the contained buffers. Each texture resource can also lock a subportion of that resource. Two-dimensional resources (surfaces) allow the locking of subrectangles, and volume resources allow the locking of subvolumes or boxes. Each lock method returns a structure that contains a pointer to the storage backing the resource and values representing the distances between rows or planes of data, depending on the resource type. For details, see the method lists for the resource interfaces. The returned pointer always points to the top-left byte in the locked subregions.
When working with index and vertex buffers, you can make multiple lock calls; however, you must ensure that the number of lock calls matches the number of unlock calls.
The DXT set of compressed texture formats, which store pixels in encoded 4×4 blocks, can only be locked on 4×4 boundaries.
See Also
Common Details for Direct3D Mobile Resources
Send Feedback on this topic to the authors