Resource Management
Resource usages
BufferUsages and TextureUsages are flag enums for declaring resource roles. Assign them to BufferDesc.Usages and TextureDesc.Usages, respectively. When a resource serves several roles, combine the required members with |.
Buffer usages
|
|
|
|---|---|
None
|
|
Vertex
|
|
Index
|
|
Indirect
|
|
Constant
|
|
StorageReadOnly
|
|
StorageReadWrite
|
|
TransferSrc
|
|
TransferDst
|
|
Texture usages
|
|
|
|---|---|
None
|
|
Sampled
|
|
Storage
|
|
ColorAttachment
|
|
DepthStencilAttachment
|
|
TransferSrc
|
|
TransferDst
|
|
CPU access and memory placement
Residency field of BufferDesc specifies the intended CPU access to the allocation:
|
|
|
|
|---|---|---|
GpuOnly
|
|
|
CpuReadOnly
|
|
|
CpuWriteOnly
|
|
|
CpuWriteOnly to initialize its small vertex buffer directly. For larger static geometry, an upload into GPU-only storage may be more suitable.
TextureDesc therefore has no residency field; the application exchanges texture data with CPU memory through uploads and downloads.
Map() provides the address through which the CPU reads or writes data. Mapping and Unmap() do not wait for GPU work: the application must wait for a GPU write before reading its result, or for outstanding GPU accesses before modifying the same bytes.
Immediate and recorded transfers
|
|
|
|---|---|
Buffer.Upload
|
CpuWriteOnly. Otherwise, submits the upload to the transfer queue and waits for it to finish. |
Buffer.Download
|
CpuReadOnly. Otherwise, submits the download to the transfer queue and waits for it to finish. |
Texture.Upload / Texture.Download |
|
CommandBuffer.Upload or CommandBuffer.Download. Upload sources and download destinations have different lifetime requirements:
-
During an upload call, the library copies the source data into temporary upload storage, called staging memory. The GPU later reads from this storage, so the application's source pointer is needed only until the call returns. -
A download first copies GPU data into internal readback storage. The library then copies it to the supplied CPU destination when it reclaims the completed command buffer. Calling Wait()on the download's submission value completes both steps. Keep the destination allocated, and managed memory pinned, until that call returns.
Heap allocation
Heap when the application needs to manage allocation itself. A heap provides storage in which resources are placed at explicit byte offsets; the application chooses those offsets and tracks the occupied regions.
context.GetSizeAndAlignment with the buffer or texture description that will be used to create it. Reserve the returned size at an offset that is a multiple of the returned alignment, within the heap's bounds and without overlapping another live allocation. Texture sizes may include backend-specific padding, so pixel count and bytes per pixel alone are insufficient to calculate their allocation size.
Views and backing resources
BufferView describes a region of a buffer and how its data is interpreted. A TextureView selects a subresource range and a compatible texture type and format. Both refer to existing storage, with the usages declared when that storage was created. View ranges describe access; they do not provide consistent shader bounds checking across backends.