A diagnostic, off by default: a timestamp at the start and one at the end
of each list of ours in the card's queue (the sends to copies in the
card's memory with their hash passes, the copies between copies, the
compares behind a submission's lists), resolved into memory the PC reads
and read when the submission has run (Host::card_done); the frame-rate
line gives the milliseconds per frame by kind. Of the card's 75 ms a frame
standing the title's commands are 50 to 55 in a timing run: this tells how
much of the rest is ours.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: cargo
check of leonida-gpu with and without diagnostics.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the up-copy check on the game's own path for landed pages (run d259)
whole-page sends still put older values over some 66,000 card words a
second, in the same buffers as before; with LEONIDA_FETCH_CHECK=1 (run
d260: 13 to 17 fetched pieces a frame caught while a later flight was at
them) 61,000. What else puts card bytes there that never come back is not
found yet.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: runs
d259 and d260.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fuzzed sNaN through v_fmamk_f32 into v_cmp_class_f32 flipped a result
bit on both Vulkan GPUs against the reference model. The model returns a
canonical quiet NaN for v_fmamk_f32, but on gfx1036 under the game's MODE
the hardware mostly returns the NaN source's word and only sometimes
quiets a signalling one (f32_hw_s5.log), so whether the result tests as
signalling or quiet is not something the model can know. Track registers
holding such a computed NaN (st["nanf"], set by v_fmamk_f32 with a
signalling or already-fuzzy NaN operand and propagated through the
pass-through ops and register moves) and raise Uncertain when
v_cmp_class_f32 reads one, instead of reporting a mismatch that is a
model gap, not a translator bug.
Co-Authored-By: Devin <noreply@cognition.ai>
Check offset zero and width 16 on the product and the value stored by the signed sum. Ignore unrelated extracts in the fragment.
AI-assisted with OpenAI Codex (GPT-6).
The literal pipe in the NVIDIA workaround row made tests/test_docs_design_rows.py
read the row as having more cells than the contract table header.
Co-Authored-By: SWE-2.1 Max <noreply@google.com>
The review of 97535ad found three more OpBitwiseAnd & 0xFFFF sites whose
operand is an %int-derived bitcast feeding a preserve-high-half merge,
the same shape NVIDIA's shader compiler miscompiles:
- v_cvt_i16_f16: OpConvertFToS %int -> Bitcast -> And, then write_lo16
or the op_sel merge (the u16 sibling is %uint and safe)
- v_cvt_norm_i16_f16: the snorm path has the same structure (unorm safe)
- saturate_int16 signed path: SClamp %int -> Bitcast -> And reaches the
preserve merges through the d16 image/buffer stores
All emit OpBitFieldUExtract %uint x, 0, 16 instead, spec-identical.
Audited every remaining And & 0xFFFF site: the rest are %uint-derived,
operand-side, packed-Or consumers, or constant masks.
RTX 4070 SUPER spot-checks of v_cvt_i16_f16/v_cvt_norm_i16_f16 (VOP2
form; llvm-mc rejects op_sel on these) produce the right words on both
the old and new modules, so the bug does not reproduce on this shape;
the extract removes the risky pattern regardless. Full semantic suite:
487 files, 6279 tests, 0 failures.
Co-Authored-By: Devin <noreply@cognition.ai>
NVIDIA's shader compiler (RTX 4070 SUPER, wave32) corrupts the preserved
high half of a 16-bit VOP3 result when OpBitwiseAnd & 0xFFFF consumes a
value that passed through %int ops and the result merges with
(old & 0xFFFF0000): v_add_nc_i16 v14, v3, v12 op_sel:[1,1,0] clamp wrote
0x1113AAA8 for 0x0002AAA8. BitFieldUExtract reads the same low 16 bits
and dodges the peephole; SClamp on %int and select-based clamps do not.
AMD (gfx1036, Vulkan and hw_oracle) and the CPU interpreter are
unaffected.
Co-Authored-By: Devin <noreply@cognition.ai>
VK_FUZZ_SKIP_CRASH treats every vk_compute_test exit outside 0/1/2/77 as a
driver crash skip, including the negative return codes Python uses for signal
deaths on POSIX. Spell that out in the module contract and cover it beside the
Windows access-violation case so exits 1/2 staying fatal is unambiguous.
Co-Authored-By: Devin <noreply@cognition.ai>
Translate with rdna2spirv.py --pc-tail-ubo when LEONIDA_PC_TAIL_UBO asks for it
(the 1/true/yes/on convention image_fuzz, lds_fuzz and valu_fuzz already use), so
the modules fit a device's 128-byte push-constant range; the variable also
reaches vk_compute_test through the inherited environment.
VK_FUZZ_SKIP_CRASH=1 records a vk_compute_test crash (the AMD Windows shader
compiler's access violation and the like) as a per-program skip instead of
aborting the batch; exit 1 (CHECK failures) and 2 (usage errors) stay fatal,
as does every non-zero exit without the variable.
Co-Authored-By: Devin <noreply@cognition.ai>
Restore both depth-compare gather opcodes. Pass the current wave mode when a writelane mask operand checks an already parked lane, matching the slot analysis and the read/write paths.
Refs #1397. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
A lane mask in an SGPR, EXEC or VCC is one wave-wide word on hardware.
The EXEC-coverage gate added earlier in this pull request could not prove
the independent-SGPR restore idioms crosslane_fuzz uses, so it fell back
to this lane's 0 / ~0 bit for exactly the programs the read is meant to
fix. It also encoded the wrong control-flow model: EXEC narrowing is a
per-lane value here, not a SPIR-V edge. Mask-data readers are already
kept out of lane-local `if (active)` runs, and the eager wave-mask store
keeps lowering from moving the subgroup gather into an EXEC-selected
arm, so lanes EXEC has off still contribute their mask bits.
Remove the gate and the CFG EXEC provenance analysis it needed, gather
the mask word for every lane-mask data read, and cover narrowed SGPR and
VCC reads, an independent all-ones SGPR EXEC restore, and the composed
vector-bitwise mask words. The vector-bitwise expectations now check the
uniform mask words and the resulting per-lane cndmask bits and popcounts
rather than the old fallback artifact.
Co-Authored-By: SWE-2.1 Max <noreply@google.com>
A register holds this lane's bit of a lane mask; v_mbcnt, s_bcnt1 and
s_ff1 gather the other lanes' bits with a subgroup operation
(Gen.wave_mask). v_mbcnt writes a VGPR, so its result is selected on the
lane's EXEC, and MoltenVK's SPIRV-Cross inlined the single-use gather
into the taken arm of that ternary:
v6 = active ? popcount(simd_or(mine ? bit : 0) & below) + acc : v6;
A lane that is off never ran the gather, so its bit was missing from
every other lane's count. Gen.wave_mask now stores the gather to a
variable of its own with Gen.eager, as SHADER-529 did for DPP's ballot
and shuffle.
On an Apple M5 (MoltenVK 1.4.2), tools/crosslane_fuzz.py with wave 32,
native and no maskdata goes from 92 of 100 programs matching to 100 of
100, and from 193 to 200 of 200 with DPP at seed 7.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: SWE-2.1 Max <noreply@google.com>
Review follow-up on the mask-word gather gate (#1397): `s_mov_b32 s4,
exec_lo` under an unknown EXEC narrowing recorded nothing for s4, so the
later `s_mov_b32 exec_lo, s4` restore minted a fresh ("n", id) tag in
_exec_src_ex. mask_exec_sigs coverage then failed and the read kept this
lane's 0 / ~0 bit, while the equivalent literal `s_mov_b32 exec_lo, -1`
resolved to a constant half-state and gathered — register and literal
restores of the same runtime value disagreed.
_mov_sgpr_vals now returns an ("al", halves) alias for an EXEC source
whose half-state is an unknown narrowing, the same scheme saveexec uses:
exec_lo gives (state, None), exec_hi (None, state), exec gives each half
in its own register for b64 moves. _exec_src_ex already resolves those
aliases, so the restore reproduces the original tag and the gather stays
exact; untracked SGPR sources still mint a fresh narrowing and stay
conservative.
Tests: two semantic cases (wave32 and wave64) assert the register
round-trip gathers OpGroupNonUniformBitwiseOr identically to the literal
-1 restore; cs_exec_copy.asm (+ fixture, check.py/run_gpu_tests.py dump
entries) stores the mask word, exec_lo's own word and the literal-restore
word side by side on real hardware — PASS on RTX 4070 and Radeon
(64-wide), wave64 exec filters 9/9 on AMD.
Co-Authored-By: Devin <noreply@cognition.ai>
Review fixes for the mask-as-data change:
- The wave-mask gather is a group op over the lanes EXEC leaves active,
and drivers differ on whether lanes EXEC has off still vote: NVIDIA,
AMD and KosmicKrisp return the whole subgroup's bits, MoltenVK's
ballot/reduce saw only the lanes a narrowed EXEC left on and produced
the EXEC value instead of the frozen mask word (cs_mask_vgpr_exec).
mask_word_read_ok now gathers only when a CFG must-analysis
(mark_exec_state) proves every lane that can hold a set bit of the
mask is EXEC-active at the read: each EXEC half is tracked as clean,
a constant mask, or an unknown narrowing (s_mov/s_cselect resolve
constants, saved-EXEC aliases and unchanged EXEC, so the common
restore idioms still gather), and mask_exec_sigs records every EXEC
state seen while each mask register held a mask. Unproven reads keep
this lane's 0 / ~0 bit, the pre-change answer.
- Scalar number ops read a lane mask operand as data too
(MASK_NUMBER_READERS, #1043's NUMBER_READERS): s_add_u32 s20, s10, K
after v_cmp wrote s10 yields the wave's mask word, while mask moves
and mask logic ops keep this lane's bit for the saveexec idioms.
- wave64_emulate_opt treats ins["mask_words"] (a mask read that will
gather) as a cross-lane exchange for the lane-local fold planner and
barrier scheduler, covering the scalar readers as well.
- test_slot67_operand_forms' expectedFailure comes off: the packed
vcc_hi word now reaches the data read.
Co-Authored-By: Devin <noreply@cognition.ai>
A lane mask (EXEC/VCC or a mask-tracked SGPR) that a VALU op reads as a
32-bit value — v_mov_b32 of it into a plain VGPR, or any VALU source
where the mask is data rather than a mask operand — materialized each
lane's own 0 / ~0 bit. Hardware holds the whole wave's mask word there
(tools/crosslane_fuzz.py's op_maskdata model: the uniform word written
to the active lanes), so every lane gets the word, the same in each.
- src_u materializes the wave mask word (lane_mask_word) for SGPR and
EXEC/VCC operands when the instruction's VGPR destination makes the
read a data read (mask_read_is_data); SGPR/EXEC/VCC destinations keep
this lane's bit, which mask_src readers rely on. Mask-holding VGPRs
already store the word, so their reads are plain loads.
- mask_src extracts this lane's bit back out of a mask-holding VGPR
(_vgpr_mask_lane_bit), half-aware in wave64 via mask_half.
- mask_data_src keeps instructions that materialize the word out of
EXEC-gated active runs (a subgroup op can't sit inside if (active)).
- v_readfirstlane_b32 of a mask VGPR broadcasts the first active lane's
copy — the only lane guaranteed fresh after an EXEC-gated v_mov_b32 —
as the word itself into a VGPR destination (VGPR writes are never
mask-tracked), or this lane's bit for a mask-tracked SGPR/special
one; fixes cs_wavemask lanes 48-63.
Found by tools/crosslane_fuzz.py (#293). docs/design.md's whole-wave
mask contract updated.
Co-Authored-By: Devin <noreply@cognition.ai>
What run d254's up-copy check showed (the merge's own conflicts few; some
280 refreshes a second crossing a flight's writes through another copy;
whole-page sends over the card's words), what the crossing copies cost
(runs d255, d257, d258: none in the frame, 1.56 ms of the submitting
thread), and the full driver cache that the launcher did not tell once it
was moved aside (run d256). switches.md regenerated.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: the runs
named.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"B faster" or "B slower" needs the interval to leave 0 out and all pairs but at most one to agree
in sign. No test caught removing the sign part (the verification of #2783 found it): the odd-run
test's interval already held 0. Eight pairs, two against the rest, now give no verdict, and one
against the rest still does.
The precompile notes which of NVIDIA's cache files it wrote, and makes
every pipeline again when one of them is gone. After the full files were
moved aside, the driver made files of the same names anew, small, before
the precompile looked: nothing was made again, and the game compiled in the
world (run d256, frames of up to 5.9 s). The files are noted with their
sizes now, and one smaller than noted counts as emptied as well (lines
without a size, from before, are looked at by name as before).
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: the
launcher's next start in run d257.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run d255 left 25 to 47 crossings a frame alone against 0.6 mended: the
refreshed copies were nearly all in the PC's memory. Their buffers are of
the kind shaders write (a custom heap the CPU maps), so the same copy on
the card serves them; the reader may not be title memory itself (a copy in
place), and LEONIDA_CROSS_PC=0 keeps to copies in the card's memory.
Such a copy takes refreshes from the CPU at once, not in the queue's order,
so a copy recorded for an earlier submission may land after a later
refresh of the same bytes. It does not put older bytes over newer ones:
what a later refresh brings there is title memory from before the flight
or what its landing put there; the title's own bytes there come only after
it waited for the flight, and it is told of a flight after the landing,
which comes after the card ran the next submission's copies (they stand in
front of its lists). The copies take each copy's offset of the address
(Shadow::offset), which holds a placed writer's bias.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: cargo
check of leonida-gpu with and without diagnostics.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comment still claimed an absent invocation in a partial non-fragment
quad gave an undefined value natively, while the non-fragment branch
reads every lane's activity with OpGroupNonUniformBallot. Wording only.
DOC-QUAD-ANY-PARTIAL.
install_runtime() removed every .runtime-staging-* folder before it
started, including the folder an IncompleteRollback kept as the only
copies of the previous runtime. If the retry also failed, those copies
were already gone. Clean the stale folders only after a successful
publish, so a failed retry leaves the recovery folder in place.
RT-INSTALL-KEEP-RECOVERY.
The search for refreshes that cross a flight's writes held a copy of every
declared write of every flight in the air, each submission: the submitting
thread worked 2.07 +-0.32 ms a frame more with LEONIDA_CROSS_COPY on (run
d255, by turns of 4 s standing; the frame's median -0.20 +-0.30 ms, the
card held the frame). It now looks first at what the submission refreshes
where flights may write (Line::written, which holds the flights being
landed too), and only then at the declared writes that meet that, holding
copies only of those. The frame-rate line tells the crossings left alone by
why: the reader in the PC's memory (most of them in run d255: 25 to 47 a
frame against 0.6 mended), the writer there, or another reason.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: cargo
check of leonida-gpu with diagnostics; host::cross::tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Register write-combined sub-ranges (`asked & 0x400 != 0`) in
`XMemVirtualAlloc`'s `MEM_REPLACE_PLACEHOLDER` path (so split
placeholders such as the 32-bit graphics heap's `0x1404`/`0x8404`/
`0x2404` parts are tracked), resolve allocation span on `MEM_RELEASE`
(`len == 0`) in `watch::title_memory_freed` so split sub-ranges are
forgotten on release, and add opt-in `LEONIDA_WC_SUBRANGE_NO_BACK`
(off by default; `LEONIDA_AB`-switchable) in `Shadow::gpu_writes` to
subtract qualifying write-combined sub-ranges after `GPU_READ_ONLY`
on mixed card copies without hot-path heap allocations.
With LEONIDA_UPCOPY_CHECK=1 a refresh of pages a landing was noted in went
up whole (Shadow::copy) instead of by the 4 KiB pages that differ
(Shadow::take_landed), so the check counted older values the game itself
never sends. The landed pages that go up are now noted like any other
refresh, and the check runs the path the game runs.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: cargo
check of leonida-gpu with diagnostics.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two host copies can hold the same title memory: a big buffer the title
draws from (a ring of 4 MiB) and a small one inside it that a compute pass
writes. A submission prepared while a flight writes the small one's card
side refreshed the big one from title memory as it was before the flight,
and its draws read those bytes: a frame of old vertices or records under
whatever moves (the torn cars and people voidopcode/vilocity ccb27fd traced
to the merge under flights' writes, whose settling lands the flights first
as a side effect). The up-copy check counted some 280 such refreshes a
second standing (run d254).
Now (LEONIDA_CROSS_COPY, on; 0 off; LEONIDA_AB can name it) the bytes of a
refreshed range whose last writer among the flights in the air or being
landed is another copy go from that copy's card side to the refreshed
one's, in a list of their own behind the submission's sends; the writers'
card sides take the title's changes there first
(Shadow::merge_under_writes), and where that cannot be done the flights
are settled as before. Copies in the PC's memory, and a copy both read and
written by one submission's crossings, are left alone and counted. The
frame-rate line says how many.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: cargo
check of leonida-gpu with and without diagnostics; host::cross::tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run.json's dirty leaves untracked files out; a new untracked count says how many there are. The first
second under 2 frames counted from the world's first second, so the arrival's streaming dip was the
run's; it now counts from 60 s in the world, like the median. The longest gap with no frame stays
from the world on: a freeze on pipeline compiles comes right after arrival. The docs say both, and
that world_at_s counts from the gate's start, the precompile included.
`Bools::unique` was a HashMap<(u32, Bool, Bool), Bool>: 17 bytes a slot at 44-87 %
load and 19-39 bytes per node, and 11 % of the CPU time of the 500 slowest programs
(the diagrams there hold about 1 M nodes and do not fit the cache).
Replace it with open addressing over node numbers: a 4-byte slot (21-bit node
number, 11-bit tag), load at most 1/2, linear probing, equality checked on the node
itself. Nodes are made in the same order, so the structuriser's output is the same.
The new test makes 400 000 random nodes over 40 variables, with the table growing
from 1 024 slots to at least 262 144, and checks every one against a HashMap: the same triple gives the same
node, a new triple the next number, and a second pass asks for them all again and
gets no new node. Skipping the equality check on the node makes it fail.
AI-assisted: Claude Sonnet 5.5
Co-authored-by: Cursor <cursoragent@cursor.com>
Green is current main with the pull request merged. Red is current main plus only the pull request's
tests: its test files, and the hunks of other Rust files that change only #[cfg(test)] items,
committed on the merge base and cherry-picked with a 3-way merge. It runs the touched D3D12 crates'
cargo test and the changed tests/**/test*.py on both sides, in one worktree and one target dir under
the git common dir, and prints per test: red then green, pass on red and fail on green, fail on both,
on one side only, with a verdict and an exit code. docs/testing.md has it next to the fork-CI recipe.
A probe that showed no move pressed Enter at once, and the menus then probed again at once: Enter came
every 3 to 5 s (68 times in 6 min on a cold cache), with no press_every and no check that frames had
moved on. It now asks the menus for one press at their pace, and a probe waits for Enter to be up.
The docs say what idle cannot tell (a held player) and what a cold cache does to CONTROL.
Commit be7690805, Release build, 284 shaders translated and 284 pass
spirv-val. native 217/275 passed 58 skipped 0 failed; with LEONIDA_W64_EMULATE=1
255/275 passed 20 skipped 0 failed. The 38 wave64-compute skips of the native
run are the ones the emulation makes run. cs_imgatomic_ext, which RTX4090.txt
reports failing on driver 591.86, passes here.
LEONIDA_UPCOPY_CHECK=1 looked at whether a send puts an older value over a
word the card wrote; a piece merged under flights' writes
(Shadow::merge_under_writes) sends only the words the title changed, so
its unchanged words the card wrote were counted wrongly there, and a word
both the title and a flight wrote was not counted at all. Merged pieces are
now noted as such; for every piece the look also counts the words the
title changed whose card value is neither the old one nor the title's (the
card wrote it since the two were alike), merged and not apart, with the
first few named.
AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: cargo
check of leonida-gpu with and without diagnostics.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/test_tool_stdout_encoding.py (on main since this branch started) wants every tool's __main__
block to do it: under -I a redirected stdout is strict in the console's code page.
tests/test_tool_stdout_encoding.py (on main since this branch started) wants every tool's __main__
block to do it: under -I a redirected stdout is strict in the console's code page.
AI-assisted (Claude). Tested on an RTX 4060 Ti (driver 616.64), Ryzen 5 7600X: runs d252, d253.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>