Repository navigation
startup: opt-in table lock so resource and heap lookups stop queueing on note_lock - #3391
Open
lukaslw-lab wants to merge 1 commit into
Open
lukaslw-lab wants to merge 1 commit into
lukaslw-lab wants to merge 1 commit into
Conversation
… on note_lock X2W_D3D12_TABLE_LOCK=1 gives resource_infos, the slot 133 placement index and heap_infos their own lock. resource_info, placed_buffer_range, memory_srv_destination and resolve_title_table read only those tables and take table_lock shared; every table writer takes note_lock, then table_lock. Without the switch nothing changes. startup_table_lock checks that the lookups return while note_lock is held exclusive, with the expected answers, that a heap creation waits for table_lock, and that lookups racing heap and texture creation find every new entry; the control variants run without the switch and must see the opposite waits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Change
Fixes #3390 (resource and heap lookups queue on
note_lockbehind every view creation and descriptor copy).X2W_D3D12_TABLE_LOCK=1(opt-in): the resource table (resource_infos), the slot 133 placement index and thedescriptor heap table (
heap_infos) get their own reader-writer lock,table_lock.note_lockguards the view records and descriptor shadows as well as these tables. View creation anddescriptor copies take it exclusively on every call (about 1.8·10^5 per second late in a startup run). Four lookups
read only the tables:
resource_info,placed_buffer_range,memory_srv_destination,resolve_title_table(about 5·10^5 shared takes per second). Measured with local lock counters, they spent ~0.42 threads waiting on
note_lock, out of ~1.18 threads waiting in total.table_lockshared. Every table writer (note_resource,note_heap,retire_placement,publish_placed_buffer) takesnote_lockand thentable_lock, both exclusive, so code thatalready holds
note_lockstill sees fixed tables and needs no change. The lock order is the same everywhere.retire_placement(a writer) changes.resource_infokeeps returning a pointer into the map as before (entries arenever removed).
publish_placement(placement_publish.h) takesnote_lockitself;table_lockis taken in its record getter,which it calls first with
note_lockheld, and released after it returns. The header is unchanged.note_lockshared and the writers take no second lock.x2w_d3d12_table_lock_probeandx2w_d3d12_table_lock_hold; switch row and section "D3D12 table lock" indocs/startup-runtime.md.Verification
Windows 10 22H2, i7-4790K, RTX 3080 Ti (NVIDIA 32.0.16.1047) and WARP; release; commit
008720e4onmaind418f70e.startup_table_lock_{warp,hardware}:note_lockexclusive, with the expected answers;table_lockwhilex2w_d3d12_table_lock_holdholds it shared for 2 s (measured2000 ms);
entry is found afterwards.
startup_table_lock_control_{warp,hardware}(switch unset): the lookups must wait fornote_lockand the heap creation must return at once (measured 0 ms); every other expectation is the same.
table_lock→startup_table_lock_{warp,hardware}fail witha heap creation did not wait for table_lock. The race part alone did not catch it (five passes out of five), so it is described as asmoke test.
startup_table_lock_*, no skips.startup_view_,placed_,resource_,address_buffer_srv_,table_alias_,memory_srv,formatted_view,direct_index_,stream_draw_,copied_vertex_srv_,frame_copy_,descriptor_), switch unsetand set, with the new fixture: 114/114 each (one capability skip in both,
startup_view_heap_warp).tests/docs_links_check.py: passed.Startup run of the main executable (#870), this head, release, warm shader cache, scripted input, the merged switches
(#2949, #2977, #3028, #3313) in every run, 250 s, four pairs (order off/on/on/off, then on/off/off/on). Means of four
runs per cell (three where one run did not reach 200k), range in brackets:
run is faster than every unset run (+11 % fps, −10 % CPU per frame). The lock waits grow as the load goes on, so the
gain shows only late.
than both unset runs in every block from 100k to 200k, fps +6 to +21 %, CPU per frame −8 to −19 %. That tree is not
this head; the numbers are given for context only.
Lock counters (local measurement build on the tree with #3097 and #3377, one run each, ~100k–175k blocks):
What remains is view creation and descriptor copies waiting on each other (~0.65 threads). Not covered: other
adapters, hosts with more cores, Wine.
AI-assisted: the change, tests and this description were written with Claude; I ran the startup comparison.
🤖 Generated with Claude Code