Repository navigation
startup: write mesh pipeline requests on a background thread - #3664
Conversation
|
A package run on this branch (
So the creation no longer waits on the file writes, and the load gets past the point where it stopped. The publisher line at the end showed 19,730 queued, 574 repeated, 16,648 written, 0 failed, 5,175 dropped and 3,082 pending. The 64 MiB bound was full at its high-water mark. Once the burst was over, the writer fell behind, at about 1 to 40 requests a second, while it shared the disk with the title's own streaming. The dropped requests are asked for again in a later run. At 858 s the title then stopped itself: a deliberate write to address 0 from its own fatal path, not a fault in the stand-in. That happened with every mesh pipeline a placeholder, local video memory at 9.5 GiB against a 5.26 GiB budget, 32 desktop graphics pipeline creations returning null and 4 upload-ring buffer copies failing. That stop is a separate question and needs its own investigation. It does not come from this change: with slot 57 accepted, AI-assisted. Ready for more review |
|
Updated to
A correction to my run numbers. The runs in the description and in my previous comment were started with an older hand-written
The slot 86 finding does not depend on those settings: it is the lock around the file writes. The rate of about 7 a second was measured with the old line, though. The 858 s stop in that comment is not specific to this change. With the presets and slot 57 accepted ( AI-assisted. Ready for more review |
Leyukaka
left a comment
There was a problem hiding this comment.
Read at 3f6f4ef9.
-
SHOULD The exit drain takes blocking locks that terminated threads may hold. In
d3d12_xs.dll,~MeshRequestDrain(src/startup_stubs/d3d12_draw.inl:620-625) runs atDLL_PROCESS_DETACH, afterExitProcesshas terminated every other thread.drain()takes the publisher lock withTryAcquireSRWLockExclusive(src/startup_stubs/request_publisher.h:117), but each part then goes throughpublish_shader_request. That function callscache_absentandnote_cache_write(d3d12_draw.inl:570,:580), which acquireCacheDirectoryIndex::lock_without a try (src/startup_stubs/cache_index.h:260,:281). The writer thread (add_hash,:281) and the change-feed thread (note_key_change,:268) hold that lock exclusively. If either was terminated while holding it, the acquire can never be granted, so the drain cannot complete and the process does not exit cleanly. Two smaller points on the same path:- A writer terminated between
CreateFileWandCloseHandleleavesreq_<key><ext>.<pid>.tmpopen with share mode 0 (d3d12_draw.inl:572-574). The drain rewrites the same front request with the same name, gets a sharing violation, and counts it failed. mesh_request_publisher()allocates the publisher during the drain when no mesh request was ever queued (:612-616,:623).
An explicit flush before exit, for example
flush()from a fixture export, would avoid file and lock work at detach. So would a drain that skips the cache index. - A writer terminated between
-
SHOULD The test publishers live on the stack and are never stopped.
held_writer()andfailed_part()(tests/startup_request_publisher_check.cpp:73,:116) return while their writer thread is still inrun(), which has no exit (request_publisher.h:171-183). That thread keeps waiting onwork_andlock_in a dead frame, withcontext_pointing to a destroyedWriter. In the stand-in the publisher is leaked on purpose, so this affects only the test. A stop-and-join path, or leaked test instances, would remove the undefined behaviour. -
NIT
drain()assumes the writer thread is already gone. That holds in the DLL. It does not hold in an executable that linksd3d12_xs_device.cppdirectly (offscreen_check,CMakeLists.txt:2247): there, static destructors run fromexit()while the writer may be insidewrite_frontwith the lock released. Two threads would then pop the same queue (request_publisher.h:150-162). -
NIT A failed write is no longer retried in the same process.
seen_is set at enqueue (request_publisher.h:77), and slot 57 marks the keywrittenas soon as it is queued (d3d12_draw.inl:1136-1137). Before this change, both slots retried a failed publication on the next creation.
The branch conflicts with main on CMakePresets.json, so no CI has run at this head.
R0Y00
left a comment
There was a problem hiding this comment.
The current head conflicts with main in CMakePresets.json. Please merge or rebase onto current main and keep both the existing PR preset cases and the request publisher target and controls. Once CI can run, the review can verify that publishing stays off the creation thread and that the inline control observes the same completed request.
|
Thanks, both. Rebased onto
AI-assisted. Ready for more review |
3f6f4ef to
d6988e4
Compare
R0Y00
left a comment
There was a problem hiding this comment.
I reproduced Windows CI's C2664 on this head with MSVC 14.51. All five std::begin({RequestPublisher::Part{...}}) calls in the fixture fail to compile. Passing the address of a named const Part and a count of 1 fixes the build in an isolated probe. The normal test passed, and --mutate inline failed its held-writer assertion as expected.
Please also keep seen_ and queue_ consistent on enqueue failure. If queue_.push_back throws after seen_.insert succeeds, the catch reports a drop but leaves the key in seen_. A retry then reports success without publishing the request. Roll back the key on this failure and add a retry control.
R0Y00
left a comment
There was a problem hiding this comment.
Retested 9efad1d2 with MSVC 14.51. The named-part fix builds, the request publisher test passes, and the inline mutation fails the held-writer control as expected.
I reproduced the retry issue on this head by injecting std::bad_alloc after three successful allocations during the first enqueue. The call reported a drop, then a retry of the same key returned success with queued=0. With seen_.erase(key) in the enqueue catch under the existing lock, all 205 injected allocation-failure retries in my probe queued successfully. Please add that rollback and a retry control. The current main merge still conflicts in CMakePresets.json.
9efad1d to
9ceb1f4
Compare
|
Thanks for the probe. Pushed
Release build of Ready for more review |
R0Y00
left a comment
There was a problem hiding this comment.
The current head erases the deduplication key under the enqueue lock and adds retry coverage. The MSVC 14.51 /O2 fixture passed, its inline mutant failed the held-writer assertion, and my independent fault-injection probe queued all 205 retries. This resolves my change request.
|
Thanks for the retest and the independent fault-injection probe. Ready to merge from our side |
R0Y00
left a comment
There was a problem hiding this comment.
The enqueue rollback passes, but the full integration exposed a Slot 57 regression. startup_mesh57_runtime_warp failed on the first run twice with the async default, and passed 3/3 with X2W_SYNC_MESH_REQUESTS=1 on the same binaries. In tests/startup_indirect_draw_indexed.cpp the exchange fixture enumerates the cache immediately after the dispatches and requires exactly two requests and six files. Please make the async fixture wait for both complete request markers with a bounded timeout before checking the existing exact bytes and file counts. Keep the async default in that coverage.
9ceb1f4 to
b64d3b0
Compare
|
Thanks, reproduced. Pushed
Measured on Windows 10 19045, MSVC 2022 Build Tools, app-local WARP 1.0.22 with Agility SDK 1.620.2 (a separate build with
On this host the test then fails later, at Ready for more review |
R0Y00
left a comment
There was a problem hiding this comment.
Re-tested this exact head with X2W_SYNC_MESH_REQUESTS=0. Both startup_request_publisher tests passed. startup_mesh57_runtime_warp passed once in the integrated suite and three consecutive repeats, and startup_mesh57_runtime_hardware passed on RTX 4060 Laptop (616.56, Windows build 26300). The bounded wait covers both ready markers and preserves the existing count and byte checks.
|
Thanks for the retest on both adapters. Ready to merge from our side |
Slot 57 and slot 86 mesh pipeline creations wrote each new key's request parts (a probe, a temporary file and a rename each) under one lock before they answered. A title that creates thousands of mesh pipelines then waits on that file work one creation at a time. Creations now copy the parts into a bounded queue and return; one thread writes them in order (request_publisher.h). A key is queued once per process and at most 64 MiB wait. X2W_SYNC_MESH_REQUESTS=1 restores the inline writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he writer The unload drain writes with its own writer (a temporary name of its own, a rename, no cache index) from a directory read when the publisher is made, and only once the writer thread has ended; while it still runs the drain waits for it. Nothing is made at unload when no request was queued. stop() ends and joins the thread (the destructor calls it), and a request that could not be written forgets its key so it is accepted again. The check covers the retry, the unload writer, a drain while the thread runs and stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on a brace list
Another MSVC version resolves std::begin({...}) to the array overload and
rejects it (C2664), which failed the Windows build on CI.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…memory enqueue recorded the key before pushing the request. If the push threw, the key stayed recorded, so a retry of the same key was counted as repeated and never written. The catch now erases the key under the same lock. The publisher test fails each allocation of an enqueue in turn and checks that the drop is counted and that a retry of the same key is queued and written. Without the rollback that case fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The request fixture enumerated the shader cache right after its dispatches. With the background publisher a request can still be in flight then, so the exact count of two requests and six files failed intermittently (startup_mesh57_runtime_warp). It now waits, for at most 10 s, until both .m57 ready markers exist and no part is still under its temporary name, then runs the same byte and count checks. The async default is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Head branch was pushed to by a user without write access
b64d3b0 to
534b3ee
Compare
…ailures The Debug build (the dev preset) allocates an iterator proxy inside noexcept container constructors. The first injected failure landed there, so the test called std::terminate and the CRT's modal report waited until the CI job's 30-minute limit. Those allocations are now neither failed nor counted. Debug build, cl /Od /MDd: 0 cases failed; --mutate inline still fails (1). Release: startup_request_publisher and its inline control pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The Windows job was timing out at 30 minutes, which was a hang in the new
Checks:
Ready to merge from our side |
|
Pushed merge resolution |
|
After #3770 landed, |
Refs #870, #3541.
Problem
Slot 86. Before it answers,
try_cached_mesh86publishes the request for the key:.ps86,.root,.stream86and.m86;mesh86_cache.inl:228).A title that creates many mesh pipelines through slot 86 waits on that file work, one creation at a time.
Measured on a package run with
X2W_REFUSE_FIXED_MESH=1, where the title builds its mesh pipelines through slot 86 instead of slot 57:X2W_DUMP_AT) at 450, 700 and 950 s each showed 3 or 4 title worker threads queued on that lock, with one thread insidepublish_shader_request.Details are in #870.
Slot 57.
request_slot57_mesh(d3d12_draw.inl) does the same for each new key under itsrequest_lock:.ps57,.rootand.m57, plus.s57withX2W_MESH57_CAPTURE_STATE=1. This is the default path. A run with the shared presets (run_preset.py --console x --gpu nvidia) stopped presenting for about 45 s during the prologue load. Stall dumps at 15 s intervals showed 4 title worker threads queued on that lock, with one thread insidepublish_shader_request.Change
src/startup_stubs/request_publisher.hcopies a request's parts into a queue and returns. One background thread writes them with the existingpublish_shader_request.publish_shader_requestind3d12_draw.inl.publish_mesh_requestqueues a request, or writes it on the calling thread under the negative control.request_slot57_meshstill checks and updates itswrittenset and the pipeline's stages under its lock, but it only copies the parts into the queue there. A dropped request keeps its stages and is queued again on a later call.try_cached_mesh86queues the request and then takes its lock only for the marker check and the pipeline build. Until the translator answers, the creation reports the request pending, the same answer it gave before.x2w-render mesh request publisher:line counts queued, repeated, written, failed and dropped requests, and the bytes pending. It is printed only once something has been queued.X2W_SYNC_MESH_REQUESTS=1restores the inline writes under the locks of both paths.docs/startup-runtime.mdhas a switch row for it.Tests
startup_request_publisherchecks the header without a device:drain()startup_request_publisher_inline_control(--mutate inline) waits for each write, as creation did before. It must fail: it takes 1,531 ms to queue the three requests. Both are added to theprpreset.Verification
Release build of
3f6f4ef9. Host: GTX 1060 6 GB, driver 32.0.15.6094, Windows 10 19045, debug layer off.ctest -R '^startup_request_publisher'ctest -R 'request_publisher|mesh86|mesh57|indirect_mesh|shader_cache'ctestwith theprpreset's selectiontests/docs_links_check.py,tests/startup_run_preset_check.py,tests/bidi_controls_check.py,git diff --checkThe mesh fixtures that publish slot 57 and slot 86 requests (
startup_indirect_mesh_*) report a Mesh capability skip on this host, on both WARP and the GTX 1060. They rely on CI's WARP, which runsstartup_indirect_mesh_cache_heap(_wide)?_warpin theprpreset. Those fixtures readreq_*.m86after the process exits, so they also exercise the unload drain.Not measured yet
Whether the title's loading screen completes with
X2W_REFUSE_FIXED_MESH=1and this change. A package run on this host will follow.🤖 Generated with Claude Code