Skip to content

D3D12 and residency: aliasing barriers, predication and resource creation without stalls - #357

Merged
dttdrv merged 9 commits into
dttdrv:mainfrom
aaf2tbz:split/d3d12-pass-stalls
Nov 26, 2026
Merged

dttdrv merged 9 commits into
dttdrv:mainfrom
aaf2tbz:split/d3d12-pass-stalls

Conversation

@aaf2tbz

@aaf2tbz aaf2tbz commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Four places where Mullion drained the GPU, ended a render pass or waited on another thread when it did not need to. On an M6 the probe scenes for them run 8x to 74x faster.

What changes

  1. d3d12: an aliasing barrier no longer ends the render pass when the pass's draws do not write what it names. It orders the aliased memory on the GPU.
  2. d3d12: a predicate's kernel is encoded before the open render pass, which keeps going.
  3. d3d12: making a resource waits for no queue's residency commit.
  4. mullion: keeping a D3D11 allocation of a MiB or more waits for no residency heartbeat commit.
  5. mullion: a texture's views are looked up without its lock. Each lookup took a shared lock, two calls into ntdll.
  6. tests: faults that these changes moved are written again over the code; the residency fault belongs to d3d12_tiled3d.
Change Measure Before After Speedup Time saved
Aliasing barriers keep the pass alias_barriers (300 aliasing barriers between draws, Starfield's pattern), ms a frame 9.29 0.125 74x 99%
Predicate kernel before the pass predication, ms a frame 5.03 0.617 8.2x 88%
No wait on residency commits resource creation, ms a texture 1.088 0.018 60x 98%
Texture views without the lock encoding thread, draw per texture about 15%

Evidence

Mac mini, Apple M6, macOS 27.3. MetalSharp Wine 8.0 (arm64 with FEX), copied with --clone. Timings are medians of tests/perf/d3d12_perf_probe and tests/perf/d3d11_perf_probe (run-to-run noise is about 20%).

  • The tests ran on our fork, where these commits sit on top of more work: the native D3D10, D3D11 and D3D12 suites and the D3D12 suite on every GPU family show only failures that are there without them, and every fault patch these commits add is caught.
  • This branch, cherry-picked onto main, builds (ARM64EC, -Denable_nvngx=true -Denable_nvapi=true -Denable_tests=true). It merges cleanly with the other two branches of this set (split/d3d12-pass-stalls, split/d3d11-redundant-state, split/texture-compression) in any order.
  • Fault patches that this change moves are made again over main's code; each keeps its changed lines.

aaf2tbz and others added 9 commits November 25, 2026 17:18
…aws' writes do not reach

an aliasing barrier ended the open render pass, and, once a reserved buffer existed, added a Settle after it: 300
barriers between draws (Starfield's frame, dttdrv#32) were 300 passes, each loading and storing its targets. one inside a
render pass whose draws wrote nothing but its targets, naming none of them (KeptByAliasing), now keeps the pass: a
resource it activates is none of the targets, which the draws after it go on writing, and the memory it hands over was
written by work before the pass, which the barrier's ordering point now orders the whole pass after, or is a target's,
stored when the pass ends. with a reserved buffer, one Settle goes before the pass and one after it, however many
barriers it has (SettleAround). one that names a target, or follows a draw's UAV or stream output writes, ends the pass
as before. MULLION_D3D12_ALIAS_KEEPS_PASS=0 gives the old behaviour.

d3d12_alias_open_pass: a slow dispatch writes heap memory, then in one list a draw writes the target, the barrier,
and a draw reads the memory through another placed buffer or a reserved buffer whose tiles map it in another order;
every pixel is what the dispatch wrote, with one, 50 or named barriers and lists of several passes, encoded on one
thread and on several. its fault leaves the kept pass unordered and adds no Settle: every reserved case is wrong.
d3d12_alias_submissions, _enhanced, _chain, d3d12_submission, d3d12_sparse_remap pass on native and native-metal3.

d3d12_perf_probe alias_barriers (M6): 9.29 ms to 0.131 ms a frame, 71x.
…eeps going

SetPredication ran its region's kernel, which zeroes the region's draws' arguments when the predicate skips them, in
a compute pass of its own, ending the open render pass: 100 regions of a frame were 100 render passes, each loading
and storing its targets. a region that begins in a render pass whose draws wrote nothing but its targets now has its
kernel's pass linked before the render pass, which keeps going: nothing in the pass can have written the predicate,
and the pass is ordered after the kernel as after the work before it (the region's ordering point).
MULLION_D3D12_HOIST_PREDICATES=0 gives the old passes.

d3d12_predication's new fault dispatches no thread of a kernel that goes before the pass: d3d12_predication (2 wrong)
and d3d12_occlusion_replay (256 wrong) catch it. the 10 tests that predicate (d3d12_predication, _long,
d3d12_occlusion_replay, d3d12_recorded, d3d12_bundle_queries, d3d12_pipeline_statistics, d3d12_streamout_arguments,
d3d12_tessellation, d3d12_submission, d3d12_atomic64_parts) pass on native and native-metal3.

d3d12_perf_probe predication (M6): 5.03 ms to 0.616 ms a frame, 8.2x.
a resource's allocation joined the device's residency set under residency_lock_, which a queue holds across the set's
commit before each command buffer: a kernel call that makes the new memory resident, about 1 ms for a 64 MiB texture.
a thread making resources while a queue committed waited for it, so streaming textures in stalled the application's
thread for as long as the GPU's memory took to wire. additions are now a list of their own, each allocation kept until
the next commit, which adds them before committing; RegisterResidency, RegisterResidencyAndVA and the spare tile take
only the list's lock. a removal takes back an addition still listed, or leaves the set at once as before, so nothing
released is kept for a later commit.

d3d12_released_memory's new fault commits the set without the additions since the last commit (24 wrong). the
residency, resource lifetime, heap, placement and tiled tests pass on native and native-metal3. d3d11_idle_residency
and d3d12_idle_residency end at memory pressure level 2 on this Mac with and without this (6 GiB of buffers).

d3d12_perf_probe (M6): big_resources 1.088 to 0.014 ms a 64 MiB texture's creation (its frame stays bound by the
queue's commits); resource_churn 0.602 to 0.352 ms a frame, creation 8.0 to 4.7 us a resource.
…idency heartbeat commit

the residency heartbeat's set of D3D11 allocations (Keep) took the lock Settle holds across the set's commit, a kernel
call that makes new memory resident: a texture made while the heartbeat committed waited for it. Keep now lists its
additions, each allocation kept until Settle adds them before committing, and knows the set exists from a flag set
once; Release takes back an addition still listed, or takes the allocation out of the set at once as before.

d3d11_resource_creation, d3d11_texture_updates, d3d11_map_contract, d3d11_resource_usage and d3d11_draws pass on
native and native-metal3; d3d11_idle_residency ends at memory pressure level 2 on this Mac with and without this.
every view an encoder or a context looks up (Texture::view) took the texture's shared lock, two calls into ntdll's
SRW lock: 15% of D3D11's encoding thread for draws that each bind a texture. an allocation's views are now also an
array readers use without the lock: a view is added under the lock as before, written past the count readers use and
then counted (release), and read below the count (acquire); a longer array is made by doubling, and the ones before
it are kept until the allocation goes, so a reader never reads freed memory. a renamed allocation's count is reset
with its views. a view not counted yet is looked up under the lock as before.

98 runs of texture view, dynamic and default texture, discard, planar, on12, sampling and swap chain tests pass on
native and native-metal3.

d3d11_perf_probe (M6): draws_srvs 1.411 to 1.092 ms a frame (recording 0.672 to 0.362 ms); its encoding thread is
now Metal's own work but for 2%.
…their lines

d3d11_default_updates.7 and d3d11_raster_samples.9 (d3d11_context_impl.cpp) and d3d11_swapchain_buffers.19
(mullion_texture.cpp) make the same changes as before, at the lines they are on now.
with removals leaving the set at once, the residency heartbeat adds a skipped addition a moment later, and
d3d12_released_memory no longer catches the fault; d3d12_tiled3d (524288 mismatches) and d3d12_tiled do.
# Conflicts:
#	tests/d3d12/meson.build
@dttdrv
dttdrv merged commit 9276e49 into dttdrv:main Nov 26, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants