Repository navigation
startup: totals for native shader compiles and refusals - #3494
Conversation
Not-Saii
left a comment
There was a problem hiding this comment.
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_SHADERS is set. Nothing is translated or
refused differently.
Verified by reading:
- Every compute refusal is counted.
translate_compute_nativelyrefuses in two places, the pack
unsupportedreturn and thecatch. Both go throughrefuse_native, which now calls
count_native_compute_refusalbefore the 16-line log cap (d3d12_compute_dispatch.inl:487). A
cache_pathfailure returns before the lambda; it was never a refusal. - No double counting per key.
load_compute_translationsetstr.state = 2first
(d3d12_compute_dispatch.inl:279), so thetr->state || !translate_compute_natively(*tr)guard at:814
tries native translation once per key. Manifest retries don't re-enter it. The totals count keys, not
Dispatches. - Thread safety holds today. Every writer runs under exclusive
draw_lock. That covers
record_translated_dispatch(:798, then:814) andtranslation_for_targets, which is reached from
d3d12_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) each
have one writer at a time. The presenter reads with acquire oncompilesand oncount, and the reason
bytes are written before the release store. A reader sees either nothing or a complete reason. - The line fits the buffer. Worst case with 12 reasons of 71 bytes and 20-digit counts is about 1,480
characters, under both the 1,534-byte local buffer and the 1,533 characterslogkeeps.
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 three
compile sites skipcompile_native_shader:- the rectangle geometry stage at
src/startup_stubs/d3d12_draw.inl:1438-1440(gs_6_6, under
X2W_NATIVE_SHADERS); - the mesh and pixel stages at
src/startup_stubs/native_mesh57.inl:410-412. Their tests set
X2W_NATIVE_SHADERS; seeCMakeLists.txt:1957.
A run that uses these paths would report
graphics compiles=0even though DXC ran. Either route the
three calls throughcompile_native_shader(the GS stage intonative_graphics_totals, mesh into
graphics or a third group), or narrow the line and the "Not covered" list to the two paths it measures. - the rectangle geometry stage at
-
Merge order with #3467. That open PR moves
translate_compute_nativelyonto a worker thread without
draw_lock(one worker). Afterwards compute still has one writer, so the counters stay correct. But the
comment atd3d12_xs_device.cpp:432("Both native translation paths already hold draw_lock") and the
draw_lock_msfield name would be wrong for compute. The merge-order section names #3491 only. Please
add #3467 and say what the second PR to land should rename, or describe the invariant as one writer per
totals group rather thandraw_lock. -
Document the new line. Its neighbours are documented in
docs/experiments.md:17267-17274(upload
ring, compute dispatches) anddocs/startup-runtime.md:1133-1135(the 16 refusal lines). One sentence
there 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 docs
to 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 for9fcfe0de; the head is now the merge
commit8989155b. Please add the environment and say whether the run was repeated on the merge head.
NIT
- A long or 13th reason is counted but never named. A reason of 72 bytes or more falls into
refusal_overflow(d3d12_xs_device.cpp:479). Storing the first 71 bytes would keep the reason
recognisable 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 the
12 × 72 sizing. A(std::min)(used, sizeof(line) - 1)after eachsnprintf, or astatic_asserton the
sizes, would turn the comment at:469into a check.size_tunderflow is the failure mode if the
table grows.- The test never groups one reason across different PCs. The
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 with
a 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 the
wave-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 and
exits 77 after checking that output is untouched andcompiles=0, which proves only the skip path. With
WARP 1.0.22 it fails instead; see the sandbox results below.- Not proved: graphics counts (0 in every fixture), the 5 s path,
refusal_overflow > 0. The PR lists all
three as not covered.
CI
Run 46306948144 on 8989155b passed. The Windows job runs only the pr ctest preset: 82 smoke tests, no
native_* tests, none of this PR's three tests and none of the regression tests it names
(startup_compute_dispatch_native_*, startup_native_graphics_draw_*). The pr build preset compiled
d3d12_xs_device.cpp into d3d12_xs_shim with X2W_NATIVE_SHADERS, but it did not build
startup_stream_consumer, so the consumer changes were not compiled in CI. The Linux job runs no test
this PR touches.
Sandbox run (isolated, network off)
- Commit: head
8989155b53d6677c694a6fb5365a32dc26f04c58, baseff9dcef0. - Environment: Windows 11 Enterprise 10.0.26100 (Windows Sandbox), MSVC 14.44, CMake 3.31.6, Python 3.14.
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). - Debug layer: available.
D3D12GetDebugInterfacereturned0x00000000withd3d12SDKLayers.dll
10.0.26100.9818. The fixtures that print it report it enabled:
startup_native_graphics_draw_*print "debug layer: 0x00000000 enabled", and
startup_compute_dispatch_native_hardwareprints "debug layer: enabled, no error message". The three new
tests print no debug-layer line, so their status isn't reported. - Commands:
cmake --preset dev -DX2W_WITH_OPUS=OFF, then
cmake --build --preset dev --target startup_stream_consumer compile_dxil, then
ctest --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):
- Passed (5):
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. - Failed (2), both on WARP 1.0.22 and not caused by this PR:
startup_compute_dispatch_native_warpfails on baseff9dcef0too (word 0c5c5c5c5, expected
00000400; 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.
- Skipped (77): none.
- The new totals lines on head:
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"=10
Repeat (--repeat until-fail:5): the five passing tests passed 5/5, including refusals_warp and
compile_hardware. The two WARP failures failed again.
Mutation: removed count_native_compute_refusal(reason); from refuse_native
(d3d12_compute_dispatch.inl:487). The rebuild recompiled d3d12_xs_device.cpp and relinked d3d12_xs.dll.
startup_native_shader_totals_refusals_warp then failed at the reasons assertion: the totals line
ended at compute refusal_overflow=0 with no reason entries. The other results were unchanged. After
restoring 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.
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.