Repository navigation
startup: opt-in inline descriptors (X2W_D3D12_INLINE_DESCRIPTORS) - #3429
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
…review) With X2W_D3D12_INLINE_DESCRIPTORS=1 a descriptor no longer keeps its texture, so the drain can free a retired texture while a draw, mesh or compute call that reached it through a descriptor is between reading own().real and taking the list's hold. Each of them now takes the hold right after the read, before any use: retire_hold returns false when the drain already cleared real, and the read then binds null (draw) or refuses (mesh, compute). Compute took no hold before. - Late reads are counted and logged and no longer mark retire_hold_missed on a drained wrapper. - A repeated hold by the same recording skips retire_lock and the search (per-recording stamp on the resource). - X2W_D3D12_RETIRE_REASONS no longer reports view_refs with the switch. - startup_resource_retire_title inline mode, case 11: a translated draw through a stale descriptor holds a released texture (also from a second list and after its own list's reset) and binds null once it is freed. - pr preset: builds startup_inline_retire and startup_resource_retire_title and runs their warp cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks — confirmed by reading. Fixed in
New fixture
|
Leyukaka
left a comment
There was a problem hiding this comment.
Approving at 2130dce. Read the diff 9d49b8c..2130dce and the surrounding code at that head; nothing built or run.
Race. Closed, as far as reading shows:
- Draw: the hold now sits right after the read and ahead of every use. d3d12_draw.inl:3114 read, :3116
retire_hold, thenGetDesc(:3124),upload_texture(:3153),require_state(:3154) andCreateShaderResourceView(:3194). retire_holdreadsown().realunderretire_lock, the lock the drain clears it under (d3d12_xs_device.cpp:6326). Ifrealis null it returns false (:6144-6149) without settingretire_hold_missed. The draw then binds null (:3194 withtexture == nullptr), and an indirect draw refuses (:3174-3178). If the hold wins, the AddRef happens before the drain's clear, and the drain's ownRelease()(:6364) leaves the list's reference.realof a resource wrapper is set once at creation (:534) and afterwards only cleared, and a wrapper handed to the caller is never freed (the only free, :5792, is on the publish-failure path). So a non-nullrealunder the lock is the object the caller read.- Mesh: hold at native_mesh57.inl:124, right after the read at :122. On false the call refuses (:125-126). The old hold after
require_state(:189) is removed. - Compute: hold at d3d12_compute_dispatch.inl:693, right after the read at :689-690 and before
GetDesc(:694). - The fast path (:6136-6138) skips the lock only when the resource carries the stamp of this list's current hold set. That set is dropped only by
retire_discard_holds(:6182 clears the stamp), reached from Reset or destruction of that list (:3308), which D3D12 does not allow while another thread records on it. So the object the caller read is still referenced. - The one remaining unheld read,
d16_srvs_ready(d3d12_draw.inl:2251), uses the pointer forGetDescand a stand-in lookup and has no list to record on. It runs underdraw_lock(called at :2896, lock at :2883), and the drain takesdraw_lock(:6361) after clearingrealand before itsRelease()(:6364).
Remaining limit: fixture case 11. It runs on one thread, as its comment says, so it never reaches the read-to-hold window or the !real branch: in 11b the draw reads real as already null and does not call retire_hold. It would also pass with the old read, use, hold order, so it does not tell the fix apart. What it covers: a draw takes a hold, the stamp is per recording (second list, and the same list after a reset), and a freed texture binds null. Mesh and compute holds are not exercised.
Smaller points.
X2W_D3D12_RETIRE_REASONS:view_refsis now reported only without the switch (:6503), which matches the drain (:6315).x2w_d3d12_token_texturestill uses thewords[1] < view_records().size()decode (:6638). #3377 is still open, and the author has said they will convert it in whichever of the two PRs merges second.- The PR now also adds its tests to the
prpreset:CMakePresets.jsongains two build targets and three alternatives in the test filter (startup_indirect_(dispatch|constants|count)_inline_warp,startup_inline_retire_(on|control)_warp, and the warp debug0 run of the new retire test); it removes nothing. The 11 lines added totests/cmake/startup_inline_retire.cmakeareforeach/set/add_test/set_tests_propertiesonly. - CI on 2130dce: "Build and test on Windows" passed; the gfx1013 and Python jobs pass, /O2 and coverage are skipped.
Keeps both sets of fixture exports; x2w_d3d12_token_texture now decodes through token_view, as the draw texture path does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps both PRs' pr preset entries (build targets and test filter). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ches to the shared run presets X2W_D3D12_INLINE_DESCRIPTORS (R0Y00#3429), X2W_D3D12_VIEW_CONTENT_TOKENS (R0Y00#3377) and X2W_D3D12_TABLE_LOCK (R0Y00#3391) join base.env. The base why gives the 360 s A/B runs with native shaders only and with -Translate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ches to the shared run presets X2W_D3D12_INLINE_DESCRIPTORS (R0Y00#3429), X2W_D3D12_VIEW_CONTENT_TOKENS (R0Y00#3377) and X2W_D3D12_TABLE_LOCK (R0Y00#3391) join base.env. The base why gives the 360 s A/B runs with native shaders only and with -Translate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ches to the shared run presets (#3550) X2W_D3D12_INLINE_DESCRIPTORS (#3429), X2W_D3D12_VIEW_CONTENT_TOKENS (#3377) and X2W_D3D12_TABLE_LOCK (#3391) join base.env. The base why gives the 360 s A/B runs with native shaders only and with -Translate. Co-authored-by: lukaslw-lab <291379150+lukaslw-lab@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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