Skip to content

Shaders: search lane conditions once and redo a lowering once - #999

Open
TG0000 wants to merge 1 commit into
Marvisak:mainfrom
TG0000:perf/shader-lane-condition-search
Open

TG0000 wants to merge 1 commit into
Marvisak:mainfrom
TG0000:perf/shader-lane-condition-search

Conversation

@TG0000

@TG0000 TG0000 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Translating the shaders the opening scene binds spent most of its time on answers it already had. Three changes, in structure.rs and emit/lower.rs only:

  1. Bools::meet remembers failed states. It split cases without remembering the ones that failed, up to 65,536 allocating steps per question; the waterfall proofs asking it were about 38% of all translation time.
  2. The diagrams' tables. The node table is an open table of node numbers and the result table a direct-mapped cache, instead of hash maps of three-word keys; an implication is decided without building nodes.
  3. Lowering restarts once. A phi reached by a value with no DXIL form restarted the whole lowering, one phi at a time. One pass now finds every such phi.

Measured (RX 6800, Ryzen 9 5900X, Windows 11)

main this PR
Title, cold VIctory caches: pipeline backlog on entering the world cleared (2 runs each) 36.8 / 36.9 s 14.4 / 12.8 s
Title: 1,000th pipeline made after world entry 28.4 / 28.1 s 11.1 / 11.4 s
The 2,061 shaders that scene binds, 8 threads (median of 3) 35.2 s 12.0 s
Whole corpus, 16 threads (one run each, other jobs running) 79.3 s 31.3 s

Runs alternated with the new build first, so driver-cache warming favoured main. Main's second title run was stopped early by a memory watchdog, after its backlog had cleared. No device removal in these runs. This helps a cold cache only: with a warm cache and in steady state, frame rate does not change.

Correctness

  • Of 25,889 distinct programs, none goes from translating to refused. 196 of the 22,081 that translate give different output: the old search gave up at its step cap and answered "yes", and now it finishes. All 536 changed results (those 196 and 340 refusal messages) match an independent exact check, conjoining the diagrams.
  • With the old search swapped back in, all 22,081 outputs are byte-identical to main.
  • Behaviour change: 340 already-refused shaders report a different reason.

Verification

Rust 1.98.1 MSVC, base ffe310e: cargo test --workspace --locked 344 passed, 0 failed; cargo clippy --workspace --all-targets --locked -- -D warnings clean with and without --all-features; policy passes.

Overlap

AI-assisted: written and measured by Claude Opus 5.5. No game data is in this PR.

🤖 Generated with Claude Code

Translating the shaders the opening scene binds spent most of its time
on answers it already had:

- `Bools::meet` split cases without remembering the ones that failed, up
  to 65,536 allocating steps per question; the waterfall proofs asking
  it were 38% of all translation time. A state that failed is not
  searched again. Where the old search gave up and said yes, it now
  finishes: 196 of 22,081 translated programs change, each to
  what conjoining the diagrams exactly gives; none is newly refused.
- The diagrams' tables were hash maps of three-word keys whose hash is
  weak in the bits that pick the bucket. The node table is now an open
  table of node numbers and the result table a direct-mapped cache; an
  implication is decided without building nodes.
- A phi reached by a value with no DXIL form restarted the lowering, one
  phi at a time. A pass now finds every phi the missing values reach.
  Which of several reasons a refused shader reports can change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 3ca9456: cargo test -p victory-shader passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lane-condition engine rewrite is verified the right way: lane_conditions_agree_with_their_truth_tables checks ite/implies/meet against brute-force truth tables over 512 lanes with 9 atoms and 1500 random diagrams (plus a uniqueness check on nodes), and conditions_that_exclude_each_other... exercises the 2^40 case-split that the old meet_in budget could never finish — the state-dedup (failed set over sorted State) is what makes it tractable, and the test proves the semantics survive. The implies rewrite building no nodes is asserted explicitly (b.nodes.len() unchanged). The lower.rs side batches Stop::Retry phis so one redo pass collects all missing joins instead of one per pass — same fixpoint, fewer passes.

Verified locally: test-merge with main clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 98 passed / 0 failed / 1 ignored, including both new structure tests. Approving.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…ng once

Head 3ca9456 (TG0000). Conflicts:
- structure.rs: #999's normalised ite and direct-mapped memo keep our
  node-overflow bail-out (no memo writes after it); our memo cap
  (MAX_MEMO) goes, the cache is bounded by itself.
- lower.rs: missing_phis judges each edge as our fill_phis does: lazy
  barycentrics first, a loop's final value on edges from outside it
  (#269), and a descriptor's dword left undefined (descriptor_dword)
  instead of a redo. fill_phis keeps its own redo arms, one phi each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…wers in pixel and vertex programs

Head 986fa6d (undeadhuman37). Conflict in fill_phis: the edge keeps our
lazy barycentrics and #269's loop finals, then #1073's ballot. #999's
missing_phis (merged before) would redo such a phi before fill_phis
ever reaches the ballot, so it now makes the ballots first and takes a
mask dword that has one as a value. #1073's test passes the host
target to emit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/structure.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

gmankab pushed a commit to gmankab/victory that referenced this pull request Nov 25, 2026
… write that the title reads on the CPU are copied back into title memory (VICTORY_TEXTURE_BACK=1; off by default)

Read whole before merging (562 lines; the graphics crate's sources only, one switch). Its claim that boats stop sinking is not proven on this machine yet.
gmankab pushed a commit to gmankab/victory that referenced this pull request Nov 25, 2026
…KB), changed_runs by masks, scalar buffer loads four dwords a call (VICTORY_SHADER_OPT bit 64), a measuring step for the copy-back (VICTORY_BACK_READS)

- VICTORY_CARD_BUFFERS_MIN_KB=64 (off by default): every title buffer's copy in the card's memory;
  measured at like draws: the title's lists 68.0 -> 49.8 ms of card time a frame, frame 114.9 ->
  109.7 ms. VICTORY_CARD_HASH_LEN=1 (off): the card's hashes cover the title buffer's own bytes.
  A log line says where copies went, by size.
- changed_runs 64 bytes at a time by a mask of differing bytes (default; =0 the walk, =alt in turn).
- Shaders: the dwords of one console load by one call for every four (bit 64, not in the default):
  with the bit off the whole pack's output is byte-identical to the build before.
- VICTORY_BACK_READS=1|2|alt (diagnostics): who touches what the copy-back stored.
- Frame shots are named with the time they began.
- README: runs 274 and 275.

Game runs: the changes ran in runs 274 and 275 (the hash switch and the read-back switch of pull
request Marvisak#999 not yet). In this tree the diagnostics build finishes; its unit tests were not run
after the merge (they passed in the tree the changes came from).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gmankab pushed a commit to gmankab/victory that referenced this pull request Nov 25, 2026
…ester got past the sinking boat; the run later lost the card, cause not known

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
…d back into title memory (VICTORY_TEXTURE_BACK, on by default)

On the console the CPU and the GPU share memory, so what a compute pass
stores into a texture is there for the title's code to read. Here it stayed
in the host copy. The title's water passes write a 256x256 height map
(R32_FLOAT), a displacement map (R32G32_FLOAT) and two smaller maps that its
CPU physics samples; it read memory nothing wrote, and boats sat in a pit in
the water (RyanCase94/victory-Rycas on an RTX 4070 Ti 12 GB: with the copy
the boat floats and drives, without it the mission fails).

A list whose shaders write a texture of a kind copied back, through any
unordered view (root or placed), copies the levels and layers those views
expose into a read-back buffer when it closes; once the list has run, the
texels are tiled into the texture's title memory in the console's layout.
Each copy holds a ticket for its allocation that a release, a new texture
in the same memory or a remap there takes away, so nothing lands in memory
that is no longer the texture's. A flight's copies count as memory it
writes, so preparing a later submission waits for them as for its shaders'
buffer writes.

The kinds: on by default with the four found reading
(256x256f41,256x256f16,64x64f16,128x128f36). Across the forks `=1` meant
either those four or none (fxceless/victory-fork issue Marvisak#1037); here unset
and `1` are the built-in list, `0` none, a plain list replaces it, `+`/`-`
entries change it, and what is not understood is named in the log. A list
that writes none of them pays one look at the written texture's size and
format. A per-second log line counts copies recorded and landed and their
bytes, and since the start those dropped, not tiled and passed over.

Textures in a pipe/bank XOR swizzle mode cannot be tiled until
victory-formats has those modes' address patterns: they are counted and
named once ("could not be tiled e=Unsupported").

Sources: Geckomacabre/vx-layer eee5667d7 (origin), as merged in
fxceless/victory-fork 895c0b8 + 04df435 (pull request Marvisak#999; tickets per
allocation), with BradRoland's pull request Marvisak#1152 (only the levels and
layers bound views expose; its WARP regression test, adapted). Marvisak
pull request Marvisak#2573 (Bebrik229) is the same port.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bebrik229 pushed a commit to Bebrik229/VIctory that referenced this pull request Nov 26, 2026
…RAM small buffers & bitmask changed_runs, water texback fence (Marvisak#999), dynamic sky ambient, screen-probe skip, watch alias/refresh fixes (Marvisak#2455/Marvisak#2377), and xgamesave fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants