perf(shader): reuse guest page-directory lookups across provable offsets #467
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!467
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-467"
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?
@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 UTCStandard benchmark — 2026-12-05
CPU-only Standard audit · same head
013d6a3, reuse flag off/on, four ABBA blocks.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
guest_page_offset_proof_preserves_the_full_page_numberandguest_page_lookup_survives_interleaved_loads_and_stores; external negative controls caught proof defects on prior code revision. Final-head rerun pending.cargo xtask policyon 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_LOADSpath 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=1selects 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 upstreammainat0fd7614; 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.
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 --libcheck 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 playandVICTORY_REUSE_GUEST_PAGES=1 ./run.sh playon 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
b581f7e0a8086158953a64068ba29305d5450d68into 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_dstandrejected_out_of_ordersynthetic programs against pinned head013d6a3with reuse off/on and clustering off. The fixture builders are taken from benchmark revisionb07a5a6; 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):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_orderandrejected_overlap_dstinshaders/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
013d6a3already 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 head013d6a3, 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.@Kal0s-design on GitHub · 2026-12-04 17:12 UTC · original
Checked
c3cf0a7against its base0fd7614, 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 whenstays_on_guest_page(lower.rs:39) shows that the known low bits ofloplus the signed offset stay inside one aligned band of 2^min(bits, 16) bytes. The directory page islo >> 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 intohi, and both the page and the effective address equal whataddress_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 leaveslow_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 existingk < 32guard (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 smemsoffsetregister is added intolobeforeguest_address(lower.rs:5333), andlow_bits_ofgives up on an add with a non-constant operand. That part is from reading the code only, since my random programs never setsoffset. A global access with a scalar base is still refused (lower.rs:5126). Every lookup goes to the oneSLOT_MEMORYdirectory (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=1output 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_viewpair, 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, withhivalues that include 0xFF and 0xFFFF_FFFF. For each draw it checks three things. The evaluatedlomust match the claimed (bits, residue). The PR's effective (lo, hi) must equal a plain 64-bitbase + 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'saddress_plusmatches 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.
hiis 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, ands_load_dwordx1-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.loin the top 64 KiB.lo(0 failures), which then feeds the unchangedone_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.
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=1doesn't change any lib-test lowering even on main, so the corpus says nothing about the cluster side either.Negative controls.
stays_on_guest_pageto accept offsets up to one band past the end. On 2,000 random programs the harness flagged 94,732 address/page mismatches.low_bits_ofclaim one extra known bit. That gave 309,976 claim failures and 1,145 page mismatches.guest_page_offset_proof_preserves_the_full_page_numberandguest_page_lookup_survives_interleaved_loads_and_storesboth fail on the first control, and the second test fails on the second.cargo test -p victory-shader --lib -- --test-threads=2on the clean head gives 421 passed, 1 failed, 4 ignored. The 2 new tests pass. The one failure isemit::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
shader: reuse guest page-directory lookups across provable offsetsto perf(shader): reuse guest page-directory lookups across provable offsets@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.
@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:
b581f7ewith this PR merged (head013d6a3), 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.
VICTORY_REUSE_GUEST_PAGES=1, the native pipeline folder gets its own fingerprint (24c40399…against8adbf543…with the flag off). The first run rebuilt all 109,426 known pipelines.prepared::pipelineonly links a file from another folder when its first 32 bytes match the pipeline's name. That name, fromlibrary::name, hashes the root, the state and the translated host shader code.Frame time agrees.
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:
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.