Repository navigation
startup: opt-in inline descriptors (X2W_D3D12_INLINE_DESCRIPTORS) - #3429
lukaslw-lab wants to merge 1 commit into
Conversation
With X2W_D3D12_INLINE_DESCRIPTORS=1 the stand-in leaves byte +0x18 of the guest device at 0, so the title writes constant buffer views and copies CBV/SRV/UAV descriptors itself instead of calling slots 17 and 24 (R0Y00#3211 set the byte). Copies made in title memory are not counted in retire_view_refs, so with X2W_D3D12_RELEASE_RETIRED=1 a retired resource is freed once its release fences pass and no list or submission holds it. Wrappers are never freed, so a stale token binds null and never another resource. Fixtures: startup_inline_retire_{on,control}_{warp,hardware} (fixture export x2w_d3d12_token_texture) and startup_indirect_{dispatch,constants,count}_inline_{warp,hardware}; startup_indirect_dispatch expects byte +0x18 at 0 under the switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Leyukaka
left a comment
There was a problem hiding this comment.
Changes requested at 9d49b8c. Read the diff and the surrounding code on main 212d4b5; nothing built or run, so the race below is found by reading, not reproduced.
Release vs. draw race. With the switch, the drain frees a retired texture while descriptors still name it, and a draw that reaches such a descriptor is the expected case (it should bind null). That draw can instead record the texture while the drain frees it:
drain_retired_resourcesclaims the wrapper and setsown().real = nullptrunderretire_lockonly (d3d12_xs_device.cpp:6300-6302). It takesdraw_locklater, only aroundtexture_uploads().erase(:6337-6339), and callsRelease()after dropping it (:6340).draw_translatedholdsdraw_lockfrom d3d12_draw.inl:2883 to the end of the call. It readstexture = sampled_address_texture(resource)at :3114 (a plain read ofown().real, d3d12_memory_srv.inl:583, noretire_lock), then runsupload_texture(:3151),require_state(:3153) and only thenretire_hold(:3154).- If the drain clears
realbetween :3114 and :3154,retire_holdreads null underretire_lock(:6131), holds nothing and setsretire_hold_missed(:6152) on a wrapper that already leftretired_resources. The draw keeps its localtexture: the transition is already recorded andCreateShaderResourceView(texture, ...)follows at :3195. draw_lockdoes not close the window. It only delays the drain'sRelease()until the draw call returns; the list is still open and unsubmitted, and nothing holds the desktop object unless an earlier draw of the same list did.- The drain runs at the top of
queue_execute(:4776) andqueue_present(:7568), before either takesdraw_lock, so it needs one thread recording while another submits or presents.
On main the drain skips a texture while any tracked slot names it (retire_view_refs > 0), so a draw can only get there through an uncounted descriptor. With the switch no copy is counted and the check is skipped (:6291).
Possible fix: take the hold before the first use (right after :3114, ahead of upload_texture and require_state), have retire_hold report that it found real cleared, and bind null in that case. native_mesh57.inl:122/188-189 has the same read, use, hold order. The compute path reads real at d3d12_compute_dispatch.inl:690 and takes no hold at all. startup_inline_retire does not reach any of this: it resolves tokens through x2w_d3d12_token_texture on one thread.
Smaller points:
X2W_D3D12_RETIRE_REASONS(:6479) still reports a queued resource withretire_view_refs > 0asview_refs. With the switch the drain no longer waits on view refs.- #3377 (open) replaces the
words[1] < view_records().size()decodes withtoken_view().x2w_d3d12_token_texture(:6610-6613) adds one more of the old decodes, so whichever PR merges second has to convert it. - PR CI runs none of the new tests.
startup_inline_retireis not a target of theprbuild preset, and theprtest filterstartup_indirect_(dispatch|...)_warpmatches neitherstartup_indirect_*_inline_warpnorstartup_inline_retire_*. It runsstartup_indirect_dispatch_warpwith the switch unset. They would first run in the full build on main.
Also checked by reading:
- Wrappers stay registered after the drain (
registry().eraseis only on the publish-failure path, :5784), so a stale token resolves to the dead wrapper andsampled_address_texturereturns null for a non-tiled resource. - I found no one-line mutation of the changed lines that the tests would miss:
- :6291 with the switch term removed fails the
oncases (the mutant in the description); inverted, it also fails the control (T1 freed while its slot was live); - :536 without the switch term fails the
startup_indirect_*_inlinebyte check; - startup_indirect_dispatch.cpp:386 with
==fails everystartup_indirect_dispatchcase.
- :6291 with the switch term removed fails the
Change
Fixes #3428 (every constant buffer view and descriptor copy goes through the stand-in).
X2W_D3D12_INLINE_DESCRIPTORS=1(opt-in):wrap()leaves byte +0x18 of the guest device at 0, so the title writesconstant buffer views and copies CBV/SRV/UAV descriptors itself instead of calling slots 17 and 24; sampler copies
still arrive through slot 24.
retire_view_refsno longer counts every descriptor that names aresource. Under the switch the retire drain skips that check, so a retired resource is freed once its release fences
pass and no recorded list or submission holds it. Wrappers are never freed (only the desktop object is), so a token
that names a freed resource finds the dead wrapper and binds null, never another resource.
retire_view_refs.startup_indirect_dispatchchecks the byte (runtime: route inline device descriptor creation through the shim #3211); it now expects 0 when the switch is set.x2w_d3d12_token_texture: what a draw binds for a texture token (record id,as_wrapper,sampled_address_texture). Switch row and section "D3D12 inline descriptors" indocs/startup-runtime.md.startup: opt-in skip of the graphics root SRV copy that no draw reads #3028.
Verification
Windows 10 22H2, i7-4790K, RTX 3080 Ti (NVIDIA 32.0.16.1047) and WARP; release; commit
9d49b8c2onmain212d4b5f.startup_inline_retire_{on,control}_{warp,hardware}:memcpy: with the switch it is freed at itsfences, and both descriptors then bind null; in the control the live slot holds it until overwritten, and the
copy then binds null;
startup_indirect_{dispatch,constants,count}_inline_{warp,hardware}: byte +0x18 stays 0 and the indirectdispatch cases pass.
retire_view_refscheck under the switch →startup_inline_retire_on_{warp,hardware}fail withT1 not freed at its fences with inline descriptors; thecontrols pass.
main(WARP mesh cases,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, merged switches
(#2949, #2977, #3028, #3313) and
X2W_D3D12_BUDGET=1 X2W_D3D12_RELEASE_RETIRED=1in every run, 250 s, orderoff/on/on/off:
token19.5 / 22.6 unset, 21.4 / 22.0 set;wrapper0.26 / 0.31 unset,0.36 / 0.24 set. Retained textures peak 0.25 / 0.21 GB unset, 0.31 / 0.16 GB set. Refusal lines 83 / 84 vs 85 / 85.
No device removal.
to 54.
the switch also changes the drain.
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