DX12 Sampler Feedback: Streaming Texture Tiles
DirectX 12 utilizes a hardware-accelerated feature called Sampler Feedback to eliminate guesswork in texture streaming by tracking exact texel and mipmap access in real time. Instead of relying on crude CPU-side distance heuristics, the GPU records the precise sub-regions (tiles) and mip levels sampled during rendering into a specialized resource known as a feedback map. The asset streaming engine subsequently reads this map, identifies non-resident or missing tiles, and orchestrates asynchronous I/O operations to load and bind only the strictly required data to reserved (tiled) resources.
The Underlying Problem: Tiled Resources
DirectX 12 implements virtual texturing using Tiled Resources (Reserved Resources). In this paradigm, large textures are partitioned into uniform, 64KB tiles of memory. Rather than loading an entire 4K or 8K texture into VRAM, the engine creates a virtual address space for the texture and only maps physical memory pages to the tiles currently visible to the camera. Traditionally, deciding which tiles to map relied on CPU-side screen-space projections and bounding box calculations, which frequently led to either over-streaming (wasting VRAM and bandwidth) or under-streaming (causing visible pop-in).
How the GPU Generates the Feedback Map
Sampler Feedback solves this by offloading tracking directly to the GPU rasterization pipeline.
- Resource Pairing: A feedback map is allocated as a paired resource to a target texture. It uses a lower spatial resolution than the texture it tracks, determined by an engine-defined downsampling factor (the mip region dimension).
- Shader Sampling: During the pixel or compute shader
pass, shaders use dedicated HLSL intrinsics—such as
WriteSamplerFeedbackorWriteSamplerFeedbackLevel—instead of standard sampling functions. - Hardware Logging: As the GPU evaluates texture filtering (like anisotropic or trilinear), the hardware automatically computes the required level of detail (LOD). Instead of discarding this LOD metric after filtering, the GPU writes the highest-detail mip level accessed for that region directly into the corresponding entry of the feedback map.
Feedback maps are typically configured as "MinMip" maps. In this configuration, each entry stores the minimum mip level index (where 0 is the highest detail) accessed across all draws during that frame or pass.
Reading and Interpreting the Map
Once the rendering pass finishes, the feedback map contains an exact footprint of all visible texture data:
- Resolution and Readback: The engine transitions the
feedback map and resolves its internal, GPU-vendor-specific layout into
a standardized layout using the
ID3D12GraphicsCommandList1::ResolveSubresourceRegionAPI. - Analysis: The resolved feedback data can either be read back to the CPU via a readback heap or processed entirely on the GPU via compute shaders. The engine inspects each entry, translating the stored mip level index back to the underlying 64KB tile grid.
Driving the Asset Streaming Engine
The streaming engine compares the feedback map’s requests against its current internal residency database:
- Delta Calculation: The engine checks the requested tiles against the physical pages currently mapped to the virtual texture. If a feedback entry requests mip 1, but only mip 3 is resident, the missing intermediate tiles are flagged as load candidates.
- Prioritization and I/O: The engine prioritizes the flagged tiles based on visual impact (e.g., proximity to camera, screen area coverage) and issues asynchronous file read requests, commonly through DirectStorage.
- Updating Tile Mappings: As the raw 64KB blocks
stream from disk into memory heaps, the engine issues
ID3D12CommandQueue::UpdateTileMappings. This call maps the newly allocated physical pages to the virtual coordinate space of the tiled resource, seamlessly bringing the higher-detail mips into residency for the next frame.