Tracking DX12 Heaps and VRAM Defragmentation in PIX

PIX for Windows provides low-level diagnostics for DirectX 12 resource management through its dedicated Memory Capture tools. By monitoring API calls and virtual address allocations, PIX visualizes how memory heaps are segmented, tracks committed and placed resources, and exposes VRAM fragmentation in real time. This article breaks down how developers use PIX to inspect heap structures, evaluate memory layout efficiency, and monitor VRAM defragmentation routines.

Visualizing DirectX 12 Heaps in PIX

DirectX 12 shifts memory management to the developer, requiring explicit creation of ID3D12Heap instances and the manual placement of resources. PIX for Windows tracks these operations through programmatic memory captures or live capture sessions.

When inspecting a captured frame or memory trace, PIX organizes memory using visual layout views:

  • Heap Mapping: PIX generates a linear representation of each ID3D12Heap, mapping the full virtual address range allocated via CreateHeap or CreateCommittedResource.
  • Resource Placement: Individual buffers and textures created with CreatePlacedResource appear as color-coded blocks within the heap's boundaries. This visual breakdown shows exact offsets, resource sizes, and alignment padding (such as default 64KB alignments or 4MB alignments for multi-sample textures).
  • Resource Aliasing: When multiple resources share the same physical memory space across different passes (via Aliasing Barriers), PIX displays overlapping blocks. This allows developers to verify that aliased render targets, depth buffers, and UAVs do not unintentionally overwrite active data.

Identifying Memory Fragmentation

Because custom engine allocators often carve up large heaps into smaller sub-allocations, fragmentation quickly becomes an issue. PIX visualizes fragmentation through two key metrics:

  1. Internal Fragmentation (Alignment Overhead): Unused padding within a resource block required by GPU hardware specifications. PIX highlights this slack space between the actual resource size and its aligned allocation boundary.
  2. External Fragmentation (Free Space Gaps): Scattered gaps between live placed resources where free memory exists but is too small or poorly situated to host new allocations. PIX renders these gaps as unallocated voids inside the heap map, alongside statistics detailing total allocated capacity versus active usage.

Tracking VRAM Defragmentation

DirectX 12 does not provide an automated garbage collection or compaction mechanism; defragmentation must be implemented by the application. Developers accomplish this by allocating new contiguous space, copying live resources via the GPU timeline (CopyResource or CopyBufferRegion), updating descriptors, and releasing the fragmented heap.

PIX facilitates tracking and validating this process through several analytical capabilities:

  • Memory Capture Diffing: Developers can take snapshots before and after a defragmentation pass. PIX compares the two states, highlighting consolidated allocations, relocated base addresses, and freed memory segments.
  • Lifetime Tracking: By inspecting the allocation timeline, developers can confirm that fragmented source heaps are fully released once copies finish, ensuring that temporary duplicate memory is quickly reclaimed.
  • Footprint Analysis: The Memory Summary view calculates the reduction in total reserved virtual address space and committed physical VRAM, providing immediate feedback on whether a defragmentation algorithm successfully lowered peak VRAM consumption.