Resource Aliasing in DirectX 12 for Memory Reuse
Resource aliasing in DirectX 12 is a memory management technique that
allows multiple distinct GPU resources—such as textures, render targets,
or buffers—to share the exact same physical memory allocation within a
single ID3D12Heap. When render passes do not execute
concurrently, their transient resources do not need to coexist in memory
simultaneously. By binding different resources to the same physical
memory offsets and coordinating their execution via aliasing barriers,
developers can drastically reduce peak video memory (VRAM) consumption
without sacrificing visual fidelity or performance.
Placed Resources and Heaps
In standard DirectX 12 usage, calling
CreateCommittedResource allocates both the virtual resource
descriptor and its dedicated physical GPU memory in a single step. This
approach isolates memory, preventing reuse across passes.
Resource aliasing relies instead on
CreatePlacedResource. With placed resources, physical
memory is decoupled from resource definitions:
- A single large
ID3D12Heapis allocated with sufficient capacity to house the largest mutually exclusive resource. - Multiple resources are instantiated within that heap using identical or overlapping byte offsets.
- The GPU treats the memory as one resource format during one phase of rendering, and reinterprets that same underlying memory as a completely different format during a subsequent phase.
Execution Across Non-Overlapping Passes
In modern graphics pipelines, many intermediate resources have short, well-defined lifetimes. For example:
- Pass 1 (Shadow Mapping): Requires a 4K depth render target. Once the main lighting pass reads this depth map, the data is discarded.
- Pass 2 (Screen-Space Ambient Occlusion): Requires full-resolution intermediate floating-point textures later in the frame.
- Pass 3 (Post-Processing Bloom): Requires downscaled ping-pong blur targets toward the end of the frame.
Because these passes execute sequentially and the outputs of earlier passes are not needed by later stages, allocating unique VRAM for each target results in wasted memory. By aliasing, the memory allocated for the early shadow depth map can be reused by the SSAO texture, and subsequently reused by the bloom buffers.
Aliasing Barriers and Synchronization
Because aliased resources share the same physical memory, write
operations from an earlier resource must be fully flushed before a new
resource can write to or read from that memory. DirectX 12 handles this
through the aliasing barrier
(D3D12_RESOURCE_BARRIER_TYPE_ALIASING).
An aliasing barrier explicitly informs the driver and GPU pipeline of a transition between two overlapping resources:
pResourceBefore: The resource currently occupying the memory whose usage has ended. This parameter can benullptr, indicating that any prior resource using that memory is now invalid.pResourceAfter: The new resource that will now occupy and interpret the memory.
When an aliasing barrier is issued on the command list:
- Any outstanding writes to
pResourceBeforeare completed, and relevant caches are invalidated or flushed. - The GPU ensures that access hazards (read-after-write or
write-after-write) are resolved before
pResourceAfteris accessed. - The previous contents of the memory are treated as uninitialized
garbage for
pResourceAfter. Render targets or depth buffers bound this way typically require an explicitClearorDiscardResourcecall prior to use.
Alignment and Footprint Requirements
To successfully alias resources within an ID3D12Heap,
resources must adhere to DirectX 12 alignment rules:
- Standard buffers and non-MSAA textures generally require 64 KB
alignment
(
D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT). - Multi-sample anti-aliasing (MSAA) textures require 4 MB alignment
(
D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT).
The backing heap must be sized to accommodate the resource with the largest total memory footprint and strictest alignment requirement. By scheduling transient resources efficiently across the frame graph and resolving hazards with aliasing barriers, DirectX 12 applications can fit complex rendering pipelines into significantly smaller memory budgets.