Repository navigation
D3D12 and residency: aliasing barriers, predication and resource creation without stalls - #357
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
d3d12_tiled3d.alias_barriers(300 aliasing barriers between draws, Starfield's pattern), ms a framepredication, ms a frameEvidence
Mac mini, Apple M6, macOS 27.3. MetalSharp Wine 8.0 (arm64 with FEX), copied with
--clone. Timings are medians oftests/perf/d3d12_perf_probeandtests/perf/d3d11_perf_probe(run-to-run noise is about 20%).-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.