startup: async native compute with published fallback (Refs #3451) #3506
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3506"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T18:51:09Z.
Refs #3451. Replaces #3467 (takeover announced there).
The worker-thread native compute translation is by @lukaslw-lab; commit
5607594fis kept unchanged, and the commits after the merge of main are the follow-ups.What changes
5607594fa Dispatch of a key stayed untranslated until the worker had stored its result. Now, while the key's native translation is pending, the Dispatch binds an existing published translation. If there is none, it goes through the existing untranslated counter. When the worker finishes, the native result replaces the published one, once per key.draw_lock. The manifest and sidecar I/O, the parsing, and the root signature and PSO creation no longer run underdraw_lock.draw_lock, so other keys and draws are not blocked.draw_lockstill covers the per-key lookup, claiming and publishing a result, binding and recording, and the census._warpand_hardware:startup_compute_native_worker_transition: with the worker held, the first Dispatch must write the published program's marker; after the worker completes, the second must write the native output. With an empty cache, the first Dispatch must be counted as skipped.startup_compute_published_load_unlock: the census must acquiredraw_lockwhile a published load is paused.startup_compute_published_load_native_wins: the worker publishes during a paused published load; the native output is required, with no published translation line.startup_compute_published_load_concurrent: a second thread dispatches the same key during a paused load; no second load may start, and both readbacks must hold the published marker.Verification
Built with the dev preset and run in an isolated environment with the network off, on one desktop GPU and on WARP.
ctest -R '^startup_compute_(native_worker|published_load|request)'at2d3c2477: 13 passed, 2 skipped, 0 failed. The two skips arestartup_compute_native_worker_transition_warpandstartup_compute_published_load_native_wins_warp: WARP refuses the native route, so they report a capability skip.Each mutation of
src/startup_stubs/d3d12_compute_dispatch.inlwas applied alone and the affected tests rerun:native_worker_transitionandpublished_load_native_wins, WARP and hardwaredraw_lockduring the published loadpublished_load_unlockandpublished_load_concurrent, WARP and hardwarepublished_load_native_wins_hardwareonly; the WARP variant skipspublished_load_concurrent, WARP and hardwareNot covered
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-29T22:25:13Z.
Review: APPROVED
Reviewed at head
2d3c2477ce317a1da928dfede2bedf4e5c8bc865(merges cleanly into mainff9dcef0). I read the diff statically, then built it and ran the tests in an isolated Windows Sandbox with networking disabled. The PR tree was mapped read-only, and the only writable folder was one output folder.Verdict: approve. I found no blocking issues. The locking, the condition-variable wait, the order in which native and published results take effect, and the lifetimes all hold up on reading, and the sandbox run and the mutation check agree with that.
Static review
record_translated_dispatchtakesdraw_lockatd3d12_compute_dispatch.inl:996.ensure_published_computereturns with the lock held, and the lock is released at :1491 (refusal) or :1576 (recorded). Neither caller (d3d12_xs_device.cpp:3923,:4653) holds another lock across the call. The pre-checks that run before the lock is released only read state that belongs to the recording list.SleepConditionVariableSRWwaits ondraw_lock, and the predicate is rechecked in a loop. Every exit from the loading section clearspublished_in_progressand wakes all waiters, including the catch-all at :775.draw_lockand wakes the waiters. The loader checkstr.state != 1after it reacquires the lock (:783). So a published candidate never replaces a native result. Native translation runs once per key, so onesuperseded_*pair is enough.uds,srvs,uavs,heap_srvs,samplers,root,pipeline,state) is moved byinstall_compute_translation.draw_lock:cache_path, the frozen request store (which has its own mutex) and the const pack lookup.ShaderDxilCompiler. The shared compute compiler instance is serialized bycompile_lock.FreeLibraryWhenCallbackReturns) and a device reference. Map entries are never erased.~ComputeTranslationalso detaches the superseded pair during process termination.SHOULD
X2W_NATIVE_SHADERS_ONLY=1, so no published translation exists. Every Dispatch of a key that arrives before its worker finishes is skipped. That window is about 100 ms or more per key, and keys queue behind a single worker.docs/startup-runtime.md. Alternatively, report from a package run how many keys had every Dispatch skipped (the census lists keys with 0 translated).NIT
startup_compute_request_check.prepare()setsX2W_TEST_NATIVE_COMPUTE_WAIT=1(tests/startup_compute_request_check.py:78-80), and everyprepare_casecaller inherits it.startup_compute_dispatch_native_*,native_compute_pack_hardware,native_descriptor_scc_*,startup_compute_indexed_atomic_uav_*,native_image_store_exact_width_*andstartup_compute_dispatch_texture_native_*.startup_compute_native_worker_hardwarehas noSKIP_RETURN_CODE 77(tests/cmake/startup_compute_native_worker.cmake:9), unlike the other_hardwaretests. The 4 s timing margin itself looked comfortable: the consumer finished in 66–431 ms.submit_native_computefails (pool, work item or module reference), nothing is logged, and the key is never retried becausenative_attemptedis already set (:1012-1013). Please log the first failure.SetThreadpoolThreadMinimumfails (:722), the pool leaks. CallingCloseThreadpoolthere would fix it.translate_compute_nativelysays DXC "has its own lock" (:509-510). The comment at :626 says the shared instance does not. Please make them agree.open_compute_test_eventreads the environment and callsOpenEventWon every published load and every worker job. Reading each variable once, asdelay_msdoes, would keep the test hooks out of the production path.What each test proves (all observed in the sandbox run)
startup_compute_native_worker_{warp,hardware}. With a 4 s worker delay and nothing published, the single-Dispatch consumer exits in 66–431 ms. Its Dispatch is refused with "no translation" and the output is untouched, so the Dispatch does not wait for native translation.startup_compute_native_worker_wait_control_*. This is the negative control. With the wait switch on, the consumer takes 4095–4548 ms and check (a) fails as expected.startup_compute_native_worker_transition_hardware.startup_compute_published_load_unlock_*. The census takesdraw_lockwhile a published load is paused, so the load runs outside the lock.startup_compute_published_load_native_wins_hardware. A native result published during a paused load is kept, the loaded candidate is discarded, and no publishedtranslated:line appears. The WARP variant exits 77.startup_compute_published_load_concurrent_*. A second Dispatch of the same key during a paused load waits instead of starting a second load, and both readbacks hold the published marker.Sandbox run
2d3c2477ce317a1da928dfede2bedf4e5c8bc865, exported withgit archive. Base was not run, because no head test failed.cmake --preset dev -DX2W_WITH_OPUS=OFFcmake --build --preset dev --target startup_stream_consumer compile_dxil offscreen_check native_store_replay native_frozen_request_check native_compute_pack_checkctest --preset dev --no-tests=error --output-on-failure -V -R '^(startup_compute_(native_worker|published_load|request|dispatch_native|indexed_atomic_uav|dispatch_texture_native|descriptor_scc)|native_(compute_pack|frozen_request|descriptor_scc|image_store_exact_width|startup_request_cache))'native_descriptor_scc_warp,startup_compute_descriptor_scc_warpnative_image_store_exact_width_warp_{r,rg,rgb,array,volume,rgba}startup_compute_dispatch_texture_native_warp,startup_compute_dispatch_native_warp,startup_compute_indexed_atomic_uav_warpstartup_compute_native_worker_transition_warp,startup_compute_published_load_native_wins_warp_hardwarevariants and every other test in the filter.ctest ... -R '^startup_compute_(native_worker|published_load)' --repeat until-fail:5. The 10 non-skipping PR tests each passed 5 of 5 runs (50 runs, no failure). The two WARP skips ended their repeat at the first 77._warpfixtures used Microsoft Basic Render Driver.d3d12SDKLayers.dll, so the fixtures logged "debug layer: unavailable" and the sev 0/1 assertions had nothing to catch.Mutation check
I deleted the
ReleaseSRWLockExclusive(&draw_lock);before the loader call and theAcquireSRWLockExclusive(&draw_lock);after it inensure_published_compute(d3d12_compute_dispatch.inl:772and:782), which keepsdraw_lockheld during the published load. This was done in a scratch copy, not on the PR branch.startup_compute_published_load_unlock_{warp,hardware}failed with an assertion: the census was blocked until the loader's fixture gate timed out, and the key's first refusal became the gate timeout.startup_compute_published_load_concurrent_{warp,hardware}failed with "the key was not loaded exactly once".CI
The PR check passed, but its Windows job ran the
prpreset (82 tests), which includes none of this PR's tests and none of the existing native-compute fixtures. The Linux jobs run Python checks and gfx1013 assembly only. CI did not run this PR's tests; the results above come from the sandbox.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T00:29:51Z.
Review: COMMENTED
Reviewed
2d3c2477by reading the diff, plus A/B runs of the application. Reads correct, and I agree with Not-Saii's review without repeating it. Thanks for picking this up and keeping my commit.Run data for "Not covered" and Not-Saii's SHOULD 2: Windows 10 + Agility, RTX 3080 Ti, one local build (this head + #3464 + #3097), published cache (
X2W_NATIVE_SHADERS_ONLY=0), the same switches in every run.5607594flost 140 of 5,501 there.I'll close #3467 in favour of this one.