startup: totals for native shader compiles and refusals #3494
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3494"
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-29T17:54:34Z.
Refs #3477 (item 6).
Why
In one long local run of the application with native shaders enabled, 84 compute programs were translated natively and about 270 were refused. 16 of the refusals were logged (the cap in
refuse_native), the rest were counted nowhere by reason, and neither native path recorded a duration. See also #3451 (watchdog).What changes
Counting and timing only. Nothing is translated or refused differently, and no locking changes: both native paths hold
draw_lockas before, and the presenter reads the counters with atomic loads.One new line, printed with the periodic render lines (every 300 frames or when the 5 s report is due) in render mode when
X2W_NATIVE_SHADERSis set:compiles,total_ms,max_ms: calls to the DXIL compiler, cache lookups and failures included. Graphics counts one per stage.draw_lock_ms: time spent in the native translation function, which runs underdraw_lock.native compute +0x...:prefix is stripped so one reason groups across PCs. The table holds 12 reasons; a 13th distinct reason, or a reason of 72 bytes or more, adds torefusal_overflow.d3d12_draw.inl: the early return intry_native_graphicsis split in two so the timer starts after the environment check; the returns are the same. The stage compile goes throughcompile_native_shader, which forwards the same arguments.Tests
Three new tests reuse
startup_compute_dispatch_native_check.py:startup_native_shader_totals_refusals_warp: 21 pipelines refused for two reasons. 16 detail lines, and the totals line carries all 21:compute compiles=0 ... compute refusal_overflow=0 "unaligned descriptor table entry"=11 "compute state block A is not 28 bytes"=10startup_native_shader_totals_compile_{warp,hardware}: one native compile, output equal to the CPU reference,compute compiles=1with0 < total_ms == max_ms <= draw_lock_ms.Base
26df1826, head9fcfe0de:startup_native_graphics_draw_warp,startup_native_graphics_draw_hardware,startup_compute_dispatch_native_hardware,startup_native_shader_totals_compile_hardware,startup_native_shader_totals_refusals_warp.startup_compute_dispatch_native_warp,startup_native_shader_totals_compile_warp.Mutations:
refusals_warpfails (counts 8 and 8).compilesincrement:compile_hardwarefails (compute compiles=0).Not covered
refusal_overflow> 0.Merge order
Merges cleanly with #3480, #3482, #3481 and
main. Conflicts with #3491 at the 5 s block ind3d12_xs_device.cpp, where #3491 makeslast_reportatomic. Whichever lands second takesnow - last_report.load(std::memory_order_relaxed) >= 5000in the totals condition.Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-29T23:39:37Z.
Review: APPROVED
Approve. The fix holds up in an isolated sandbox build: the mutation that reverts it is caught, and the new tests pass five times in a row. No MUST. The four SHOULDs below are follow-ups that can land here or in a later PR.
Summary
Counting and timing only: compute and graphics native compiles (count, total, max), time in the native
translation functions, and compute refusals per reason, printed as one
x2w-render native shader totals:line with the 300-frame / 5 s render reports when
X2W_NATIVE_SHADERSis set. Nothing is translated orrefused differently.
Verified by reading:
translate_compute_nativelyrefuses in two places, the packunsupportedreturn and thecatch. Both go throughrefuse_native, which now callscount_native_compute_refusalbefore the 16-line log cap (d3d12_compute_dispatch.inl:487). Acache_pathfailure returns before the lambda; it was never a refusal.load_compute_translationsetstr.state = 2first(
d3d12_compute_dispatch.inl:279), so thetr->state || !translate_compute_natively(*tr)guard at:814tries native translation once per key. Manifest retries don't re-enter it. The totals count keys, not
Dispatches.
draw_lock. That coversrecord_translated_dispatch(:798, then:814) andtranslation_for_targets, which is reached fromd3d12_draw.inl:3126after the exclusive acquire at:3124. So the non-atomicmax_ticksload and store(
d3d12_xs_device.cpp:448-449) and the slot claim incount_native_compute_refusal(:479-483) eachhave one writer at a time. The presenter reads with acquire on
compilesand oncount, and the reasonbytes are written before the release store. A reader sees either nothing or a complete reason.
characters, under both the 1,534-byte local buffer and the 1,533 characters
logkeeps.Findings
SHOULD
The totals miss three DXIL compiles that run under the same switch. The line calls itself
native shader totals, and the body sayscompilescounts calls to the DXIL compiler, yet threecompile sites skip
compile_native_shader:src/startup_stubs/d3d12_draw.inl:1438-1440(gs_6_6, underX2W_NATIVE_SHADERS);src/startup_stubs/native_mesh57.inl:410-412. Their tests setX2W_NATIVE_SHADERS; seeCMakeLists.txt:1957.A run that uses these paths would report
graphics compiles=0even though DXC ran. Either route thethree calls through
compile_native_shader(the GS stage intonative_graphics_totals, mesh intographics or a third group), or narrow the line and the "Not covered" list to the two paths it measures.
Merge order with #3467. That open PR moves
translate_compute_nativelyonto a worker thread withoutdraw_lock(one worker). Afterwards compute still has one writer, so the counters stay correct. But thecomment at
d3d12_xs_device.cpp:432("Both native translation paths already hold draw_lock") and thedraw_lock_msfield name would be wrong for compute. The merge-order section names #3491 only. Pleaseadd #3467 and say what the second PR to land should rename, or describe the invariant as one writer per
totals group rather than
draw_lock.Document the new line. Its neighbours are documented in
docs/experiments.md:17267-17274(uploadring, compute dispatches) and
docs/startup-runtime.md:1133-1135(the 16 refusal lines). One sentencethere with the field meanings would cover it: compiles counts cache hits and failures, graphics counts
one per stage,
draw_lock_mscontainstotal_ms, and what overflow means. AGENTS.md asks for the docsto change when a reproduction or diagnostic changes.
Evidence fields (AGENTS.md "Evidence"). The
_hardwarepasses in the body don't name the adapter,driver, Windows build or debug-layer status. The results are for
9fcfe0de; the head is now the mergecommit
8989155b. Please add the environment and say whether the run was repeated on the merge head.NIT
refusal_overflow(d3d12_xs_device.cpp:479). Storing the first 71 bytes would keep the reasonrecognisable in the census. Refusal reasons that end with a view-kind number or a PC are the ones most
likely to run long.
used +=is not clamped (d3d12_xs_device.cpp:498-521). The line fits today only because of the12 × 72 sizing. A
(std::min)(used, sizeof(line) - 1)after eachsnprintf, or astatic_asserton thesizes, would turn the comment at
:469into a check.size_tunderflow is the failure mode if thetable grows.
unaligned descriptor table entryrefusals carry thenative compute +0x…:prefix(
src/gfx1013_compute_native.cpp:39,:1063), so the expected string proves the prefix is stripped.All 11 come from the same PC, though. "Grouped across PCs" is untested; a fixture with two programs
refusing at different PCs would cover it. Not blocking, and in line with the PR's "Not covered" list.
What each PR test proves
startup_native_shader_totals_refusals_warp: runs 21 keys that each fail native translation, 11 witha frontend reason (prefixed, then stripped) and 10 with a request-shape reason (not prefixed). It checks
that 16 detail lines appear while the totals count all 21, by reason, with zero compiles and
draw_lock_ms > 0. The output buffer is untouched. It runs on WARP, and both refusals happen before thewave-capability check, so it cannot skip 77.
startup_native_shader_totals_compile_hardware: one native compile, output equal to the CPU reference,compute compiles=1,0 < total_ms == max_ms <= draw_lock_ms, no refusal entries.startup_native_shader_totals_compile_warp: with the in-box WARP (no 32-lane waves) it is refused andexits 77 after checking that output is untouched and
compiles=0, which proves only the skip path. WithWARP 1.0.22 it fails instead; see the sandbox results below.
refusal_overflow > 0. The PR lists allthree as not covered.
CI
Run 46306948144 on
8989155bpassed. The Windows job runs only theprctest preset: 82 smoke tests, nonative_*tests, none of this PR's three tests and none of the regression tests it names(
startup_compute_dispatch_native_*,startup_native_graphics_draw_*). Theprbuild preset compiledd3d12_xs_device.cppintod3d12_xs_shimwithX2W_NATIVE_SHADERS, but it did not buildstartup_stream_consumer, so the consumer changes were not compiled in CI. The Linux job runs no testthis PR touches.
Sandbox run (isolated, network off)
8989155b53d6677c694a6fb5365a32dc26f04c58, baseff9dcef0.Hardware adapter as the fixtures print it: NVIDIA GeForce RTX 4090, driver 32.0.16.1088 (sandbox vGPU).
WARP: Microsoft Basic Render Driver 1.0.22.0 (
OFFSCREEN_WARP_DIR).D3D12GetDebugInterfacereturned0x00000000withd3d12SDKLayers.dll10.0.26100.9818. The fixtures that print it report it enabled:
startup_native_graphics_draw_*print "debug layer: 0x00000000 enabled", andstartup_compute_dispatch_native_hardwareprints "debug layer: enabled, no error message". The three newtests print no debug-layer line, so their status isn't reported.
cmake --preset dev -DX2W_WITH_OPUS=OFF, thencmake --build --preset dev --target startup_stream_consumer compile_dxil, thenctest --preset dev --no-tests=error --output-on-failure -V -R '^(startup_native_shader_totals_.*|startup_compute_dispatch_native_.*|startup_native_graphics_draw_(warp|hardware))$'Head (7 tests):
startup_native_shader_totals_refusals_warp,startup_native_shader_totals_compile_hardware,startup_compute_dispatch_native_hardware,startup_native_graphics_draw_warp,startup_native_graphics_draw_hardware.startup_compute_dispatch_native_warpfails on baseff9dcef0too (word 0c5c5c5c5, expected00000400; 288 words differ). This WARP reports 32-lane waves, so the program is translated natively,but the output stays at the sentinel.
startup_native_shader_totals_compile_warpis new, so it has no base result. It fails the same way("native Dispatch output differed from the CPU reference"). It reuses the same Dispatch, so it inherits
the WARP problem above. On the in-box WARP it skips 77, as your body says.
compile_hardware:compute compiles=1 total_ms=7.159 max_ms=7.159 draw_lock_ms=77.512; graphics compiles=0 ...; compute refusal_overflow=0refusals_warp:compute compiles=0 total_ms=0.000 max_ms=0.000 draw_lock_ms=10.690; ... refusal_overflow=0 "unaligned descriptor table entry"=11 "compute state block A is not 28 bytes"=10Repeat (
--repeat until-fail:5): the five passing tests passed 5/5, includingrefusals_warpandcompile_hardware. The two WARP failures failed again.Mutation: removed
count_native_compute_refusal(reason);fromrefuse_native(
d3d12_compute_dispatch.inl:487). The rebuild recompiledd3d12_xs_device.cppand relinkedd3d12_xs.dll.startup_native_shader_totals_refusals_warpthen failed at the reasons assertion: the totals lineended at
compute refusal_overflow=0with no reason entries. The other results were unchanged. Afterrestoring the file and rebuilding, it passed again.
CI coverage, restated: none of the three new tests and none of the four regression tests above run in
the PR job. This sandbox run is the only execution of them in this review.