perf(shader): reuse guest page-directory lookups across provable offsets #467

Manually merged
github merged 4 commits from github-bot/gh-467 into main 2026-12-05 17:30:43 +00:00 AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-04 14:30 UTC · original
tommiehansen:codex/reuse-guest-pages → main · +179 −15 · 7 files · 4 commits · merged 2026-12-05 17:28 UTC

Standard benchmark — 2026-12-05

CPU-only Standard audit · same head 013d6a3, reuse flag off/on, four ABBA blocks.

Workload Baseline (ms) Candidate (ms) Time change Verification
Guest-load clusters 19.607 17.095 −13.45% Byte parity failed; timing not qualified
Translate corpus 7.115 6.579 −7.43% Structurally valid; semantics unverified
Uniform SMEM/wide loads 12.092 11.441 −6.12% Structurally valid; semantics unverified

CPU comparison exits with failure (2). Do not interpret these timings as a passed optimization benchmark. Separate exact Vulkan audit verifies both known divergent fixtures (overlap and out-of-order), 8/8 raw arms exact. This resolves the semantic question for those fixtures, not the general CPU equivalence gate. No physical GPU timing.


What this does

reuse guest page-directory lookups across provable offsets.

Checks

  • Off-by-default and main parity: Off by default; external default-path comparison covered 20,000 generated programs. Existing opt-in clustering can change because known-bit analysis is shared.
  • Docs move with code: Documented switch and added menu entry with default 0.
  • No unrelated cleanup: Address proof, lowering, cache identity, tests and docs only.
  • A test must exercise the change: guest_page_offset_proof_preserves_the_full_page_number and guest_page_lookup_survives_interleaved_loads_and_stores; external negative controls caught proof defects on prior code revision. Final-head rerun pending.
  • Queue checked on 2026-12-04: #351/#352 share known-bit/lowering/cache paths, #469 shares lowering/cache, #518 changes existing defaults. Reconcile overlap before landing.
  • Run cargo xtask policy on the final revision; no new game assets or build output intended.

Verified

Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.

Cost

Fewer directory reads in synthetic DXIL; no AMD GPU timings or FPS.


Detailed implementation and historical validation

Problem

A guest raw-memory access resolves the guest page through an immutable directory before it can address the payload. Separate accesses to the same aligned record can generate separate directory reads because each access adds its own byte offset before deriving the page key. The existing VICTORY_CLUSTER_GUEST_LOADS path groups eligible consecutive loads. A store between loads prevents that grouping.

Change and correctness

This change uses the base page key when the translator can prove that the signed offset stays in the same aligned band, at most 64 KiB wide. The effective byte address remains identical, including for probes. Neither the directory's bounds check nor the access masks change. Payload loads, stores, atomics, permissions and missing-page notifications retain their original ordering. The existing dominance pass can reuse the immutable directory read across writes to guest payload memory.

The feature is off by default. VICTORY_REUSE_GUEST_PAGES=1 selects it and uses a separate shader cache key. The shared known-bit analysis now also recognizes constant shift amounts before their hardware shift masks are folded. The cache key for the existing opt-in load cluster has been updated accordingly. This PR is based directly on upstream main at 0fd7614; it does not depend on the mesh experiments.

Synthetic comparison

The test sends GFX10 compute code through production lowering and counts surviving directory reads after the normal DXIL optimization passes. Each thread accesses fields of a 64-byte record, with a guest store between loads. The consecutive-load experiment is disabled in both variants.

Access pattern Directory reads, baseline → candidate DXIL container bytes, baseline → candidate
2 fields with interleaved writes 2 → 1 3,060 → 2,892
4 fields with interleaved writes 4 → 1 3,704 → 3,208
8 fields with interleaved writes 8 → 1 4,988 → 3,840
Offset can leave the proven page 2 → 2 Byte-identical
cargo test --locked -p victory-shader --lib guest_ -- --nocapture
cargo check --locked -p victory-shader --target x86_64-pc-windows-msvc --lib --tests --examples --features blake3/pure

All six targeted tests and the Windows-target shader check passed. The address proof includes signed offsets and carry/wrap boundaries. The Windows-target victory-gpu --lib check also passed using the local mimalloc build shim. These results count generated operations. Hardware benchmarking was unavailable. Workload coverage, AMD ISA, register pressure, GPU timing and gameplay FPS are still unknown.

AMD validation requested

Please compare VICTORY_REUSE_GUEST_PAGES=0 ./run.sh play and VICTORY_REUSE_GUEST_PAGES=1 ./run.sh play on RX 9060 XT 16 GB and RX 9070 XT under Linux with ray tracing enabled. Use the same game save, native resolution, settings, driver build and streaming route. Warm each mode's shader cache before alternating repeated runs. Report median and p99 frame times, 1% lows, missing-page faults, and any rendering mismatch or hang. An RDNA ISA dump or RGP capture of an affected dispatch would show whether the reduced lookup count survives driver compilation and whether VGPR usage changes.

Queue refresh — 2026-12-05

Merged upstream main b581f7e0a8086158953a64068ba29305d5450d68 into the existing branch without rewriting history. New head: 013d6a3cb133ded9996f8c6011aff3349dbfa26e. The address proof now asserts both accepted and rejected cases against a band-relative reference. The earlier independent negative controls and M5 production fixture results remain scoped to their tested revisions.

Fresh pinned CI audit is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.

Benchmark Suite follow-up

The refreshed pinned diagnosis (b581f7e → 013d6a3) passed off/off. Switch-only still changes the rejected out-of-order and overlapping-destination fixtures. The existing failure gate stays active while semantic parity is unverified. Separate Apple M5 paging fixtures verified all recorded Quick and Standard bytes and 3 → 1 static directory sites.

Exact rejected-fixture semantic audit

Separate software Vulkan audit is running the original rejected_overlap_dst and rejected_out_of_order synthetic programs against pinned head 013d6a3 with reuse off/on and clustering off. The fixture builders are taken from benchmark revision b07a5a6; the production translator source remains unchanged. The independent oracle checks the expected register overwrite/sum, all payload/output bytes, unchanged guards, directory and fault buffers. Unexpected ABI or incomplete execution fails the diagnostic. This is not a GPU performance test; the existing semantic gate remains unresolved until real execution evidence is available.

Exact fixture audit — descriptor compatibility follow-up

First execution attempt compiled the pinned production translator and exported the two fixtures, but stopped before Vulkan execution at the conservative duplicate-binding inspector. This establishes neither a shader correctness failure nor a pass. dxil-spirv maps global SRV/UAV heaps to the same set/binding; Vulkan permits compatible descriptor aliases. The portable inspector now supports identical storage-array shapes while retaining external validation and the independent byte oracle. Retry is pending. No production code change; no waiver of the semantic gate.

Exact fixture audit — scalar directory aliases

Second attempt stopped at two scalar storage views of set 1, binding 254 (the page directory), before execution. Inspector follow-up accepts matching scalar storage aliases as well as matching array shapes; mixed descriptor types/shapes still fail. External validation and exact byte oracles remain mandatory. New audit pending. No new correctness or performance claim.

Exact fixture semantic verification — PASS

Completed software Vulkan audit at pinned production head 013d6a3 (reuse off/on, clustering off):

Original fixture Expected value per lane Verified raw arms Result
rejected_overlap_dst 19 4/4 Exact bytes
rejected_out_of_order 26 4/4 Exact bytes

Both fixtures reproduce different DXIL and SPIR-V, yet all eight execution arms match the independent oracle, including unchanged memory, guard, directory and fault buffers. The earlier byte-identity discrepancy is therefore semantically verified for these two fixtures on software Vulkan. No performance claim, no physical AMD/D3D12/RADV validation, and no blanket proof for other shaders. Numeric report artifact.

Vulkan audit follow-up (2026-12-05)

The Quick production paging fixture passes exact-byte verification against the independent oracle; direct SPIR-V directory load sites decrease 3 → 1. However, the separate CPU shader-corpus gate rejects changed fallback DXIL for rejected_out_of_order and rejected_overlap_dst in shaders/guest_load_clusters (a9ac81b77608ac69 → ba0a12fb3a09c48f). This is an unresolved equivalence check, not a proven gameplay regression; Standard was not run. Need isolate the paging and cluster switches and independently validate both affected fallback cases before claiming equivalence or performance. Audit job and artifacts.

Clarification of rejected-fixture evidence

The exact same head 013d6a3 already passed independent software-Vulkan byte oracles for the two affected rejected-cluster cases in 47503537144. Their code changes when paging reuse is enabled independently of clustering. The CPU comparator currently requires identical rejected code regardless of which feature is toggled. Keep the strict gate until exact per-case evidence can be connected to the comparison; this is a benchmark equivalence issue, not established faulty shader output. No change to production behavior.

Isolated switch control (2026-12-05)

Off/off passes with identical shader digests and no detected regression. Same-head reuse 0→1, cluster disabled again fails the rejected-cluster DXIL identity gate; guest-load clustering −12.45% timing is not qualified. Corpus −6.94% and uniform SMEM/wide −4.94% are structurally valid but semantically unverified for the corpus as a whole. The two specific rejected fixtures already have exact software Vulkan byte parity; do not waive the generic comparison gate or call this a demonstrated shader output regression.

Exact revision- and binary-bound rejection gate — PASS

Audit 47534475497, audit revision aa7c61e: all 32 original Standard checkpoint arms (8 ABBA blocks, same head 013d6a3, cluster=0, reuse=0/1) match the pinned per-case DXIL BLAKE3 digests. Both changed rejected cases reproduce precisely the original benchmark binaries and execute with independent exact-byte Vulkan software oracles in all 8 raw arms; the other two rejected cases are binary-identical. Guest, fixture manifest, oracle data, full DXIL and executed SPIR-V digests are bound to the evidence. The specific rejected-case semantic blocker is resolved; the generic identity comparator remains unchanged and still reports the expected binary difference. The remaining corpus is not thereby semantically verified. CPU translation (not GPU time): 13.812 → 12.082 ms, −12.45%; 95% paired CI −13.12% to −11.78%. No physical GPU or gameplay claim.

**@⁠tommiehansen** on GitHub · 2026-12-04 14:30 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/467) `tommiehansen:codex/reuse-guest-pages` → `main` · +179 −15 · 7 files · 4 commits · merged 2026-12-05 17:28 UTC ## Standard benchmark — 2026-12-05 [CPU-only Standard audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974535) · same head `013d6a3`, reuse flag off/on, four ABBA blocks. | Workload | Baseline (ms) | Candidate (ms) | Time change | Verification | |---|---:|---:|---:|---| | Guest-load clusters | 19.607 | 17.095 | −13.45% | Byte parity failed; timing not qualified | | Translate corpus | 7.115 | 6.579 | −7.43% | Structurally valid; semantics unverified | | Uniform SMEM/wide loads | 12.092 | 11.441 | −6.12% | Structurally valid; semantics unverified | **CPU comparison exits with failure (2).** Do not interpret these timings as a passed optimization benchmark. Separate [exact Vulkan audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503537144/job/145622646938) verifies both known divergent fixtures (overlap and out-of-order), 8/8 raw arms exact. This resolves the semantic question for those fixtures, not the general CPU equivalence gate. No physical GPU timing. --- ## What this does reuse guest page-directory lookups across provable offsets. ## Checks - [ ] Off-by-default and main parity: Off by default; external default-path comparison covered 20,000 generated programs. Existing opt-in clustering can change because known-bit analysis is shared. - [x] Docs move with code: Documented switch and added menu entry with default 0. - [x] No unrelated cleanup: Address proof, lowering, cache identity, tests and docs only. - [ ] A test must exercise the change: `guest_page_offset_proof_preserves_the_full_page_number` and `guest_page_lookup_survives_interleaved_loads_and_stores`; external negative controls caught proof defects on prior code revision. Final-head rerun pending. - [x] Queue checked on 2026-12-04: #351/#352 share known-bit/lowering/cache paths, #469 shares lowering/cache, #518 changes existing defaults. Reconcile overlap before landing. - [ ] Run `cargo xtask policy` on the final revision; no new game assets or build output intended. ## Verified Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review. ## Cost Fewer directory reads in synthetic DXIL; no AMD GPU timings or FPS. --- ## Detailed implementation and historical validation ## Problem A guest raw-memory access resolves the guest page through an immutable directory before it can address the payload. Separate accesses to the same aligned record can generate separate directory reads because each access adds its own byte offset before deriving the page key. The existing `VICTORY_CLUSTER_GUEST_LOADS` path groups eligible consecutive loads. A store between loads prevents that grouping. ## Change and correctness This change uses the base page key when the translator can prove that the signed offset stays in the same aligned band, at most 64 KiB wide. The effective byte address remains identical, including for probes. Neither the directory's bounds check nor the access masks change. Payload loads, stores, atomics, permissions and missing-page notifications retain their original ordering. The existing dominance pass can reuse the immutable directory read across writes to guest payload memory. The feature is off by default. `VICTORY_REUSE_GUEST_PAGES=1` selects it and uses a separate shader cache key. The shared known-bit analysis now also recognizes constant shift amounts before their hardware shift masks are folded. The cache key for the existing opt-in load cluster has been updated accordingly. This PR is based directly on upstream `main` at `0fd7614`; it does not depend on the mesh experiments. ## Synthetic comparison The test sends GFX10 compute code through production lowering and counts surviving directory reads after the normal DXIL optimization passes. Each thread accesses fields of a 64-byte record, with a guest store between loads. The consecutive-load experiment is disabled in both variants. | Access pattern | Directory reads, baseline → candidate | DXIL container bytes, baseline → candidate | | --- | ---: | ---: | | 2 fields with interleaved writes | 2 → 1 | 3,060 → 2,892 | | 4 fields with interleaved writes | 4 → 1 | 3,704 → 3,208 | | 8 fields with interleaved writes | 8 → 1 | 4,988 → 3,840 | | Offset can leave the proven page | 2 → 2 | Byte-identical | ```sh cargo test --locked -p victory-shader --lib guest_ -- --nocapture cargo check --locked -p victory-shader --target x86_64-pc-windows-msvc --lib --tests --examples --features blake3/pure ``` All six targeted tests and the Windows-target shader check passed. The address proof includes signed offsets and carry/wrap boundaries. The Windows-target `victory-gpu --lib` check also passed using the local mimalloc build shim. These results count generated operations. Hardware benchmarking was unavailable. Workload coverage, AMD ISA, register pressure, GPU timing and gameplay FPS are still unknown. ## AMD validation requested Please compare `VICTORY_REUSE_GUEST_PAGES=0 ./run.sh play` and `VICTORY_REUSE_GUEST_PAGES=1 ./run.sh play` on RX 9060 XT 16 GB and RX 9070 XT under Linux with ray tracing enabled. Use the same game save, native resolution, settings, driver build and streaming route. Warm each mode's shader cache before alternating repeated runs. Report median and p99 frame times, 1% lows, missing-page faults, and any rendering mismatch or hang. An RDNA ISA dump or RGP capture of an affected dispatch would show whether the reduced lookup count survives driver compilation and whether VGPR usage changes. ### Queue refresh — 2026-12-05 Merged upstream main `b581f7e0a8086158953a64068ba29305d5450d68` into the existing branch without rewriting history. New head: `013d6a3cb133ded9996f8c6011aff3349dbfa26e`. The address proof now asserts both accepted and rejected cases against a band-relative reference. The earlier independent negative controls and M5 production fixture results remain scoped to their tested revisions. [Fresh pinned CI audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636) is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim. ### Benchmark Suite follow-up The refreshed pinned diagnosis (b581f7e → 013d6a3) passed off/off. Switch-only still changes the rejected out-of-order and overlapping-destination fixtures. The existing failure gate stays active while semantic parity is unverified. Separate Apple M5 paging fixtures verified all recorded Quick and Standard bytes and 3 → 1 static directory sites. ### Exact rejected-fixture semantic audit [Separate software Vulkan audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47502042660) is running the original `rejected_overlap_dst` and `rejected_out_of_order` synthetic programs against pinned head `013d6a3` with reuse off/on and clustering off. The fixture builders are taken from benchmark revision `b07a5a6`; the production translator source remains unchanged. The independent oracle checks the expected register overwrite/sum, all payload/output bytes, unchanged guards, directory and fault buffers. Unexpected ABI or incomplete execution fails the diagnostic. This is not a GPU performance test; the existing semantic gate remains unresolved until real execution evidence is available. ### Exact fixture audit — descriptor compatibility follow-up [First execution attempt](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47502042660) compiled the pinned production translator and exported the two fixtures, but stopped before Vulkan execution at the conservative duplicate-binding inspector. This establishes neither a shader correctness failure nor a pass. dxil-spirv maps global SRV/UAV heaps to the same set/binding; Vulkan permits compatible descriptor aliases. The portable inspector now supports identical storage-array shapes while retaining external validation and the independent byte oracle. [Retry](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47502667060) is pending. No production code change; no waiver of the semantic gate. ### Exact fixture audit — scalar directory aliases [Second attempt](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47502667060) stopped at two scalar storage views of set 1, binding 254 (the page directory), before execution. [Inspector follow-up](https://github.com/tommiehansen/VIctory-xmem/commit/cf40ea3f3a4e0de75a1161c960fc30856dd883e7) accepts matching scalar storage aliases as well as matching array shapes; mixed descriptor types/shapes still fail. External validation and exact byte oracles remain mandatory. [New audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503537144) pending. No new correctness or performance claim. ### Exact fixture semantic verification — PASS [Completed software Vulkan audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503537144/job/145622646938) at pinned production head `013d6a3` (reuse off/on, clustering off): | Original fixture | Expected value per lane | Verified raw arms | Result | | --- | ---: | ---: | --- | | rejected_overlap_dst | 19 | 4/4 | Exact bytes | | rejected_out_of_order | 26 | 4/4 | Exact bytes | Both fixtures reproduce different DXIL and SPIR-V, yet all eight execution arms match the independent oracle, including unchanged memory, guard, directory and fault buffers. The earlier byte-identity discrepancy is therefore semantically verified for these two fixtures on software Vulkan. No performance claim, no physical AMD/D3D12/RADV validation, and no blanket proof for other shaders. [Numeric report artifact](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503537144/artifacts/15926181789). ### Vulkan audit follow-up (2026-12-05) The Quick production paging fixture passes exact-byte verification against the independent oracle; direct SPIR-V directory load sites decrease **3 → 1**. However, the separate CPU shader-corpus gate rejects changed fallback DXIL for `rejected_out_of_order` and `rejected_overlap_dst` in `shaders/guest_load_clusters` (`a9ac81b77608ac69` → `ba0a12fb3a09c48f`). This is an unresolved equivalence check, not a proven gameplay regression; Standard was not run. Need isolate the paging and cluster switches and independently validate both affected fallback cases before claiming equivalence or performance. [Audit job and artifacts](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47512649200/job/145651188689). ### Clarification of rejected-fixture evidence The exact same head `013d6a3` already passed independent software-Vulkan byte oracles for the two affected rejected-cluster cases in [47503537144](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503537144). Their code changes when paging reuse is enabled independently of clustering. The CPU comparator currently requires identical rejected code regardless of which feature is toggled. Keep the strict gate until exact per-case evidence can be connected to the comparison; this is a benchmark equivalence issue, not established faulty shader output. No change to production behavior. ### Isolated switch control (2026-12-05) [Off/off](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47517950486/job/145667597989) passes with identical shader digests and no detected regression. [Same-head reuse 0→1, cluster disabled](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47517950486/job/145667598100) again fails the rejected-cluster DXIL identity gate; guest-load clustering −12.45% timing is not qualified. Corpus −6.94% and uniform SMEM/wide −4.94% are structurally valid but semantically unverified for the corpus as a whole. The two specific rejected fixtures already have exact software Vulkan byte parity; do not waive the generic comparison gate or call this a demonstrated shader output regression. ### Exact revision- and binary-bound rejection gate — PASS [Audit 47534475497](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47534475497), audit revision `aa7c61e`: all 32 original Standard checkpoint arms (8 ABBA blocks, same head `013d6a3`, cluster=0, reuse=0/1) match the pinned per-case DXIL BLAKE3 digests. Both changed rejected cases reproduce precisely the original benchmark binaries and execute with independent exact-byte Vulkan software oracles in all 8 raw arms; the other two rejected cases are binary-identical. Guest, fixture manifest, oracle data, full DXIL and executed SPIR-V digests are bound to the evidence. The specific rejected-case semantic blocker is resolved; the generic identity comparator remains unchanged and still reports the expected binary difference. The remaining corpus is not thereby semantically verified. CPU translation (not GPU time): 13.812 → 12.082 ms, −12.45%; 95% paired CI −13.12% to −11.78%. No physical GPU or gameplay claim.
Prove from the base address low bits that an immediate offset stays in the same 64 KiB page. Use the original page key for the immutable directory read while keeping the effective byte address, original payload operations, access rights and fault guards. This lets dominance-based reuse share one directory lookup across interleaved loads and stores. Keep the experiment opt-in and separate cached translations. Verify page-edge fallback and count directory loads in the generated code.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 14:31:09 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 17:12 UTC · original

Checked c3cf0a7 against its base 0fd7614, natively on Windows 11 with MSVC, not Wine.

How I read the proof. The reuse decision is made per access and never compares two accesses. guest_address (lower.rs:4728) keeps the unmodified base (lo, hi) as the directory key only when stays_on_guest_page (lower.rs:39) shows that the known low bits of lo plus the signed offset stay inside one aligned band of 2^min(bits, 16) bytes. The directory page is lo >> 16 | (hi & 0xFF) << 16 (lower.rs:4776-4779). So if the access stays inside a band of at most 64 KiB, nothing can carry or borrow into bit 16 or into hi, and both the page and the effective address equal what address_plus (lower.rs:4706) gives. The offset is added in i64, so negative offsets and i32::MIN/MAX can't overflow the check. A base register written between two accesses is a different SSA value, so it gets its own lookup. Sharing across stores, guards and branches is the existing pure-load reuse (bitcode/opt.rs:738 on the entry marked at lower.rs:4805), which this PR doesn't touch. That leaves low_bits_of (bitcode.rs:503) as the only thing the proof depends on. The new Shl case (bitcode.rs:523) only fires when the shift amount is fully known (bits == 32), and the existing k < 32 guard (bitcode.rs:540) still applies. I don't see a hole in it.

Dynamic offsets never take the fast path unless they are constant. A VGPR offset is already part of lo. The smem soffset register is added into lo before guest_address (lower.rs:5333), and low_bits_of gives up on an add with a non-constant operand. That part is from reading the code only, since my random programs never set soffset. A global access with a scalar base is still refused (lower.rs:5126). Every lookup goes to the one SLOT_MEMORY directory (lower.rs:4789), so two accesses can't share a key across different resources.

The Shl change also feeds the existing cluster path (lower.rs:5002) when reuse is off, which is why the cluster cache key moved to v3. That's correct, it just means VICTORY_CLUSTER_GUEST_LOADS=1 output changes too.

To check this by running it, I added local-only hooks that were never pushed. They are a concrete evaluator over the lowered module (integer Bin/Cast/Cmp/Select computed, everything else a free leaf) and a check on every guest_address -> memory_view pair, made before the clean-up passes. For each call it draws 64 sets of leaf values. These are biased toward 0, 2^n, 2^n-1, the last bytes below a 4 KiB and a 64 KiB boundary, 0xFFFF_FFxx and u64 wrap, with hi values that include 0xFF and 0xFFFF_FFFF. For each draw it checks three things. The evaluated lo must match the claimed (bits, residue). The PR's effective (lo, hi) must equal a plain 64-bit base + offset. The emitted directory page must equal the page of that sum. The same check runs on the slow path, so it also confirms that main's address_plus matches the reference.

Random programs. 20,000 GFX10 compute programs, built the way the PR's own test builds them but varied. The base is made from shifts (inline or through a register holding a constant), and/or/xor/add/sub/mul chains, constants and unknown operands. hi is set to 0, 4, 0xFF, 0xFFFFFFFF and so on. The accesses are global load/store x1-x4, atomics with and without return, runs of consecutive loads, accesses inside an exec-masked branch arm followed by one after the join, the base rewritten between accesses, and s_load_dword x1-x16 with offsets up to plus or minus 1 MiB. Each program was lowered with reuse off and on, and with clustering off and on.

  • All 20,000 lowered in every configuration. The reuse setting never changed whether a program lowered.
  • Reuse changed the DXIL of 1,945 programs (clustering off) and 1,815 (clustering on).
  • 576,740 address computations were checked with 64 draws each. There were 0 address or page mismatches and 0 known-bit claim failures.
  • 38,248 of those calls took the reuse path. 27,388 had a fully constant base, where every draw gives the same value. The other 10,860 had partly known bases, with 3 to 22 known low bits, and those are the interesting ones. 12,641 of the reuse-path calls had negative offsets. 1.28M draws put the access within 256 bytes of a 64 KiB band edge or put lo in the top 64 KiB.
  • The 538,492 slow-path calls also matched the reference, so the reference agrees with main's carry handling.
  • With both flags off, all 20,000 programs give byte-identical DXIL on main and on the PR. With only clustering on, 1,677 differ, because the Shl change lets more clusters form. There I checked the head address of each cluster and the known-bit claim on its lo (0 failures), which then feeds the unchanged one_guest_page. I didn't evaluate the addresses of the other loads in each cluster.

Test corpus. I hashed the DXIL of every lowering in the lib tests on both trees.

  • Flags off, main and PR are identical over 915 lowerings (789 distinct programs). The PR adds 8 lowerings, all from its new test.
  • With VICTORY_REUSE_GUEST_PAGES=1 (alone or with clustering), no lowering outside the new test changed its DXIL. The 36 extra reuse-path calls all had constant bases, which fold to the same code anyway, and all passed the address check. So the existing tests give the flag almost no coverage. The random programs above are where it actually gets exercised.
  • VICTORY_CLUSTER_GUEST_LOADS=1 doesn't change any lib-test lowering even on main, so the corpus says nothing about the cluster side either.

Negative controls.

  • I widened stays_on_guest_page to accept offsets up to one band past the end. On 2,000 random programs the harness flagged 94,732 address/page mismatches.
  • I made the Shl case in low_bits_of claim one extra known bit. That gave 309,976 claim failures and 1,145 page mismatches.
  • The PR's own tests catch both. guest_page_offset_proof_preserves_the_full_page_number and guest_page_lookup_survives_interleaved_loads_and_stores both fail on the first control, and the second test fails on the second.

cargo test -p victory-shader --lib -- --test-threads=2 on the clean head gives 421 passed, 1 failed, 4 ignored. The 2 new tests pass. The one failure is emit::size_tests::a_reused_descriptor_register_read_only_behind_its_flag, which fails the same way on main here (WARP runs 4-lane waves). On main, with my hashing hook in, it gave 419 passed and the same 1 failure.

I didn't measure GPU timing or anything on AMD hardware. This only covers whether the addresses stay the same.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 17:12 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/467#issuecomment-7418592066) Checked c3cf0a7 against its base 0fd7614, natively on Windows 11 with MSVC, not Wine. How I read the proof. The reuse decision is made per access and never compares two accesses. `guest_address` (lower.rs:4728) keeps the unmodified base `(lo, hi)` as the directory key only when `stays_on_guest_page` (lower.rs:39) shows that the known low bits of `lo` plus the signed offset stay inside one aligned band of 2^min(bits, 16) bytes. The directory page is `lo >> 16 | (hi & 0xFF) << 16` (lower.rs:4776-4779). So if the access stays inside a band of at most 64 KiB, nothing can carry or borrow into bit 16 or into `hi`, and both the page and the effective address equal what `address_plus` (lower.rs:4706) gives. The offset is added in i64, so negative offsets and i32::MIN/MAX can't overflow the check. A base register written between two accesses is a different SSA value, so it gets its own lookup. Sharing across stores, guards and branches is the existing pure-load reuse (bitcode/opt.rs:738 on the entry marked at lower.rs:4805), which this PR doesn't touch. That leaves `low_bits_of` (bitcode.rs:503) as the only thing the proof depends on. The new Shl case (bitcode.rs:523) only fires when the shift amount is fully known (bits == 32), and the existing `k < 32` guard (bitcode.rs:540) still applies. I don't see a hole in it. Dynamic offsets never take the fast path unless they are constant. A VGPR offset is already part of `lo`. The smem `soffset` register is added into `lo` before `guest_address` (lower.rs:5333), and `low_bits_of` gives up on an add with a non-constant operand. That part is from reading the code only, since my random programs never set `soffset`. A global access with a scalar base is still refused (lower.rs:5126). Every lookup goes to the one `SLOT_MEMORY` directory (lower.rs:4789), so two accesses can't share a key across different resources. The Shl change also feeds the existing cluster path (lower.rs:5002) when reuse is off, which is why the cluster cache key moved to v3. That's correct, it just means `VICTORY_CLUSTER_GUEST_LOADS=1` output changes too. To check this by running it, I added local-only hooks that were never pushed. They are a concrete evaluator over the lowered module (integer Bin/Cast/Cmp/Select computed, everything else a free leaf) and a check on every `guest_address` -> `memory_view` pair, made before the clean-up passes. For each call it draws 64 sets of leaf values. These are biased toward 0, 2^n, 2^n-1, the last bytes below a 4 KiB and a 64 KiB boundary, 0xFFFF_FFxx and u64 wrap, with `hi` values that include 0xFF and 0xFFFF_FFFF. For each draw it checks three things. The evaluated `lo` must match the claimed (bits, residue). The PR's effective (lo, hi) must equal a plain 64-bit `base + offset`. The emitted directory page must equal the page of that sum. The same check runs on the slow path, so it also confirms that main's `address_plus` matches the reference. Random programs. 20,000 GFX10 compute programs, built the way the PR's own test builds them but varied. The base is made from shifts (inline or through a register holding a constant), and/or/xor/add/sub/mul chains, constants and unknown operands. `hi` is set to 0, 4, 0xFF, 0xFFFFFFFF and so on. The accesses are global load/store x1-x4, atomics with and without return, runs of consecutive loads, accesses inside an exec-masked branch arm followed by one after the join, the base rewritten between accesses, and `s_load_dword` x1-x16 with offsets up to plus or minus 1 MiB. Each program was lowered with reuse off and on, and with clustering off and on. - All 20,000 lowered in every configuration. The reuse setting never changed whether a program lowered. - Reuse changed the DXIL of 1,945 programs (clustering off) and 1,815 (clustering on). - 576,740 address computations were checked with 64 draws each. There were 0 address or page mismatches and 0 known-bit claim failures. - 38,248 of those calls took the reuse path. 27,388 had a fully constant base, where every draw gives the same value. The other 10,860 had partly known bases, with 3 to 22 known low bits, and those are the interesting ones. 12,641 of the reuse-path calls had negative offsets. 1.28M draws put the access within 256 bytes of a 64 KiB band edge or put `lo` in the top 64 KiB. - The 538,492 slow-path calls also matched the reference, so the reference agrees with main's carry handling. - With both flags off, all 20,000 programs give byte-identical DXIL on main and on the PR. With only clustering on, 1,677 differ, because the Shl change lets more clusters form. There I checked the head address of each cluster and the known-bit claim on its `lo` (0 failures), which then feeds the unchanged `one_guest_page`. I didn't evaluate the addresses of the other loads in each cluster. Test corpus. I hashed the DXIL of every lowering in the lib tests on both trees. - Flags off, main and PR are identical over 915 lowerings (789 distinct programs). The PR adds 8 lowerings, all from its new test. - With `VICTORY_REUSE_GUEST_PAGES=1` (alone or with clustering), no lowering outside the new test changed its DXIL. The 36 extra reuse-path calls all had constant bases, which fold to the same code anyway, and all passed the address check. So the existing tests give the flag almost no coverage. The random programs above are where it actually gets exercised. - `VICTORY_CLUSTER_GUEST_LOADS=1` doesn't change any lib-test lowering even on main, so the corpus says nothing about the cluster side either. Negative controls. - I widened `stays_on_guest_page` to accept offsets up to one band past the end. On 2,000 random programs the harness flagged 94,732 address/page mismatches. - I made the Shl case in `low_bits_of` claim one extra known bit. That gave 309,976 claim failures and 1,145 page mismatches. - The PR's own tests catch both. `guest_page_offset_proof_preserves_the_full_page_number` and `guest_page_lookup_survives_interleaved_loads_and_stores` both fail on the first control, and the second test fails on the second. `cargo test -p victory-shader --lib -- --test-threads=2` on the clean head gives 421 passed, 1 failed, 4 ignored. The 2 new tests pass. The one failure is `emit::size_tests::a_reused_descriptor_register_read_only_behind_its_flag`, which fails the same way on main here (WARP runs 4-lane waves). On main, with my hashing hook in, it gave 419 passed and the same 1 failure. I didn't measure GPU timing or anything on AMD hardware. This only covers whether the addresses stay the same. AI-assisted: yes
github-bot changed title from shader: reuse guest page-directory lookups across provable offsets to perf(shader): reuse guest page-directory lookups across provable offsets 2026-12-04 22:19:56 +00:00
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:18 UTC · original

Thanks @⁠Kal0s-design for the address-proof testing. New execution coverage at the current head: software Vulkan audit runs the two divergent overlap/out-of-order fixtures with reuse off/on. All eight arms match independent expected bytes, including guards and fault buffers. The generic CPU byte-parity gate remains unchanged; this establishes semantics for those two fixtures only, not physical AMD timing.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:18 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/467#issuecomment-7436355996) Thanks @⁠Kal0s-design for the address-proof testing. New execution coverage at the current head: [software Vulkan audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503537144/job/145622646938) runs the two divergent overlap/out-of-order fixtures with reuse off/on. All eight arms match independent expected bytes, including guards and fault buffers. The generic CPU byte-parity gate remains unchanged; this establishes semantics for those two fixtures only, not physical AMD timing.
github manually merged commit 83ccd7fd8a into main 2026-12-05 17:30:43 +00:00
Author
Owner

@⁠El-Biiscuit on GitHub · 2026-12-05 18:56 UTC · original

Physical GPU run on AMD, since the description notes there is no physical GPU timing yet.

Setup. RX 6700 XT 12 GB (RDNA 2), Fedora 45, GE-Proton11-16, the repo's patched Mesa/RADV. One binary: b581f7e with this PR merged (head 013d6a3), diagnostics build. Series X profile, low preset base at 1920x1080 with FSR performance, a fixed city save with the camera turning. 4-minute runs, the last 3 measured with MangoHud, ABBA order, flag off and on in the same binary. 0 amdgpu faults in the kernel log.

The flag changes no host shader code for this title.

  • With VICTORY_REUSE_GUEST_PAGES=1, the native pipeline folder gets its own fingerprint (24c40399… against 8adbf543… with the flag off). The first run rebuilt all 109,426 known pipelines.
  • Every one of the 109,426 files in the new folder ended up hard-linked to the file of the same pipeline in the flag-off folder.
  • prepared::pipeline only links a file from another folder when its first 32 bytes match the pipeline's name. That name, from library::name, hashes the root, the state and the translated host shader code.
  • So, for every known pipeline of this title, the output is byte-identical with the flag on and off.

Frame time agrees.

flag runs median frame time, ms [range]
off 3 44.3 [44.1–44.8]
on 4 44.0 [43.7–44.2]

The ranges overlap. One flag-off run fell into a slower GPU state (lower clock and load) and is left out of the off row; with it, the off median is 44.6.

I can't tell from this which of two things happens:

  • the in-page proof never holds for this title's real accesses;
  • or the lookups it would share were already merged by the existing pure-load reuse.

A count of the sites where the reuse fires during translation would tell them apart. I'm happy to run it here if you add one.

**@⁠El-Biiscuit** on GitHub · 2026-12-05 18:56 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/467#issuecomment-7443570347) Physical GPU run on AMD, since the description notes there is no physical GPU timing yet. **Setup.** RX 6700 XT 12 GB (RDNA 2), Fedora 45, GE-Proton11-16, the repo's patched Mesa/RADV. One binary: `b581f7e` with this PR merged (head `013d6a3`), diagnostics build. Series X profile, low preset base at 1920x1080 with FSR performance, a fixed city save with the camera turning. 4-minute runs, the last 3 measured with MangoHud, ABBA order, flag off and on in the same binary. 0 amdgpu faults in the kernel log. **The flag changes no host shader code for this title.** - With `VICTORY_REUSE_GUEST_PAGES=1`, the native pipeline folder gets its own fingerprint (`24c40399…` against `8adbf543…` with the flag off). The first run rebuilt all 109,426 known pipelines. - Every one of the 109,426 files in the new folder ended up hard-linked to the file of the same pipeline in the flag-off folder. - `prepared::pipeline` only links a file from another folder when its first 32 bytes match the pipeline's name. That name, from `library::name`, hashes the root, the state and the translated host shader code. - So, for every known pipeline of this title, the output is byte-identical with the flag on and off. **Frame time agrees.** | flag | runs | median frame time, ms [range] | |---|---|---| | off | 3 | 44.3 [44.1–44.8] | | on | 4 | 44.0 [43.7–44.2] | The ranges overlap. One flag-off run fell into a slower GPU state (lower clock and load) and is left out of the off row; with it, the off median is 44.6. I can't tell from this which of two things happens: - the in-page proof never holds for this title's real accesses; - or the lookups it would share were already merged by the existing pure-load reuse. A count of the sites where the reuse fires during translation would tell them apart. I'm happy to run it here if you add one.
This discussion has been locked. Commenting is limited to contributors.
No description provided.