Shader: read the dwords of one console load four per call (VICTORY_SHADER_OPT bit 64, off by default) #35

Closed
github-bot wants to merge 2 commits from gh-pr/35/head into gh-pr/35/base
Owner

@⁠64bitMango on GitHub · 2026-11-26 10:46 UTC · original
64bitMango:four-dword-scalar-loads → main · +506 −16 · 9 files · 2 commits · closed without merging

What. With VICTORY_SHADER_OPT=64, a multi-dword console load becomes one rawBufferLoad per four dwords instead of one per dword (s_buffer_load_dwordx2-x16 from a raw view, global_load_dwordx2-x4). Off by default: unset (or 0) keeps one call per dword. The D3D12 shader cache and the pipeline-library tag key on it.

When it applies. A group of four becomes one call only when its start offset (added in 32 bits, as the per-dword path adds it) is a compile-time constant and every byte of the group lies below 2^32. A group that could wrap, or whose offset is computed at run time, is read one dword per call at exactly the per-dword offsets. x4, x8 and x16 groups decide the same way.

Why it's exact there. The console reads dwords past a view's end as zero and keeps the ones before. A native test shows Metal (bounds-checked pool views) answers the same, [7,8,0,0]; a D3D12 test shows D3DMetal does too.

Measured. On the Wine route (recorded frame, medians, both orders, before the wrap guard): −19 to −29 ms of GPU time out of about 150, mostly three indirect dispatches (one goes 12.4 → 3.1 ms alone); the picture within the noise of two unchanged runs. Translating a 19,105-shader capture through the native host's path: unset, every shader's DXIL is byte-identical to main; with bit 64, every shader translates or is refused as without it, and 16,958 use the wider calls (17,002 before the wrap guard).

Not covered yet: per-dword zeroing is shown for page-table pool views; table/heap views are untested on Metal, which is why it is off by default. The native-only memory_smem and computed_buffer paths are not widened.

Credit: after fxceless/victory-fork (c36971b2, 16849898) and darkworldhm/victory-fork-darkworldhm.

Tests: call counts per four dwords for x4/x8/x16 with the bit on and off; a load at 0xffff_fffc read per dword at the scalar offsets; the addr_tests GPU test passed on an M5 Pro (macOS 27.3) unset, at 0 and at 64. victory-shader 222 passed, victory-gpu 145 passed; Windows clippy and xtask policy clean.

**@⁠64bitMango** on GitHub · 2026-11-26 10:46 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35) `64bitMango:four-dword-scalar-loads` → `main` · +506 −16 · 9 files · 2 commits · closed without merging **What.** With `VICTORY_SHADER_OPT=64`, a multi-dword console load becomes one `rawBufferLoad` per four dwords instead of one per dword (`s_buffer_load_dwordx2`-`x16` from a raw view, `global_load_dwordx2`-`x4`). **Off by default**: unset (or `0`) keeps one call per dword. The D3D12 shader cache and the pipeline-library tag key on it. **When it applies.** A group of four becomes one call only when its start offset (added in 32 bits, as the per-dword path adds it) is a compile-time constant and every byte of the group lies below 2^32. A group that could wrap, or whose offset is computed at run time, is read one dword per call at exactly the per-dword offsets. x4, x8 and x16 groups decide the same way. **Why it's exact there.** The console reads dwords past a view's end as zero and keeps the ones before. A native test shows Metal (bounds-checked pool views) answers the same, `[7,8,0,0]`; a D3D12 test shows D3DMetal does too. **Measured.** On the Wine route (recorded frame, medians, both orders, before the wrap guard): −19 to −29 ms of GPU time out of about 150, mostly three indirect dispatches (one goes 12.4 → 3.1 ms alone); the picture within the noise of two unchanged runs. Translating a 19,105-shader capture through the native host's path: unset, every shader's DXIL is byte-identical to main; with bit 64, every shader translates or is refused as without it, and 16,958 use the wider calls (17,002 before the wrap guard). **Not covered yet:** per-dword zeroing is shown for page-table pool views; table/heap views are untested on Metal, which is why it is off by default. The native-only `memory_smem` and `computed_buffer` paths are not widened. **Credit:** after fxceless/victory-fork (c36971b2, 16849898) and darkworldhm/victory-fork-darkworldhm. **Tests:** call counts per four dwords for x4/x8/x16 with the bit on and off; a load at `0xffff_fffc` read per dword at the scalar offsets; the `addr_tests` GPU test passed on an M5 Pro (macOS 27.3) unset, at 0 and at 64. victory-shader 222 passed, victory-gpu 145 passed; Windows clippy and `xtask policy` clean.
**What.** With `VICTORY_SHADER_OPT=64`, a multi-dword console load becomes one `rawBufferLoad` per four dwords instead of one per dword (`s_buffer_load_dwordx2`-`x16` from a raw view, `global_load_dwordx2`-`x4`). **Off by default**: unset (or `0`) keeps one call per dword. The D3D12 shader cache and the pipeline-library tag key on it.

**When it applies.** A group of four becomes one call only when its start offset (added in 32 bits, as the per-dword path adds it) is a compile-time constant and every byte of the group lies below 2^32. A group that could wrap, or whose offset is computed at run time, is read one dword per call at exactly the per-dword offsets. x4, x8 and x16 groups decide the same way.

**Why it's exact there.** The console reads dwords past a view's end as zero and keeps the ones before. A native test shows Metal (bounds-checked pool views) answers the same, `[7,8,0,0]`; a D3D12 test shows D3DMetal does too.

**Measured.** On the Wine route (recorded frame, medians, both orders, before the wrap guard): −19 to −29 ms of GPU time out of about 150, mostly three indirect dispatches (one goes 12.4 → 3.1 ms alone); the picture within the noise of two unchanged runs. Translating a 19,105-shader capture through the native host's path: unset, every shader's DXIL is byte-identical to main; with bit 64, every shader translates or is refused as without it, and 16,958 use the wider calls (17,002 before the wrap guard).

**Not covered yet:** per-dword zeroing is shown for page-table pool views; table/heap views are untested on Metal, which is why it is off by default. The native-only `memory_smem` and `computed_buffer` paths are not widened.

**Credit:** after fxceless/victory-fork (c36971b2, 16849898) and darkworldhm/victory-fork-darkworldhm.

**Tests:** call counts per four dwords for x4/x8/x16 with the bit on and off; a load at `0xffff_fffc` read per dword at the scalar offsets; the `addr_tests` GPU test passed on an M5 Pro (macOS 27.3) unset, at 0 and at 64. victory-shader 222 passed, victory-gpu 145 passed; Windows clippy and `xtask policy` clean.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:43:23 +00:00
github-bot closed this pull request 2026-11-26 14:43:23 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 11:01 UTC · original · requested changes

The logic reads right. Widening stays inside one console instruction; offsets, mask and alignment match the old per-dword path; and the cache key and library tag now include the setting. Tests, Windows clippy and policy pass merged with current main. Before this goes in:

  1. Please make bit 64 default-off. The default-on case rests on one recorded frame. Partially out-of-bounds four-dword raw loads were only confirmed on D3DMetal and Metal pool views; table and heap views are untested, and you note the fork saw all-zero on one host. Flip the default in a later PR once there's more evidence.
  2. The tests don't catch a regression. The two new GPU tests pass with VICTORY_SHADER_OPT=0 too, and addr_tests silently returns when MSC is missing. Please add a lowering unit test asserting one rawBufferLoad per four dwords for dwordx4/x8/x16, and say which hosts the GPU tests ran on.

Heads-up on ordering: #35 and #36 merge cleanly together. #33, #34 and #37 conflict with each other (native/shaders.rs, shader_cache.rs, emit/mod.rs), so expect to rebase those as others land.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 11:01 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6072961391) · **requested changes** The logic reads right. Widening stays inside one console instruction; offsets, mask and alignment match the old per-dword path; and the cache key and library tag now include the setting. Tests, Windows clippy and policy pass merged with current main. Before this goes in: 1. **Please make bit 64 default-off.** The default-on case rests on one recorded frame. Partially out-of-bounds four-dword raw loads were only confirmed on D3DMetal and Metal pool views; table and heap views are untested, and you note the fork saw all-zero on one host. Flip the default in a later PR once there's more evidence. 2. **The tests don't catch a regression.** The two new GPU tests pass with `VICTORY_SHADER_OPT=0` too, and `addr_tests` silently returns when MSC is missing. Please add a lowering unit test asserting one rawBufferLoad per four dwords for dwordx4/x8/x16, and say which hosts the GPU tests ran on. Heads-up on ordering: #35 and #36 merge cleanly together. #33, #34 and #37 conflict with each other (`native/shaders.rs`, `shader_cache.rs`, `emit/mod.rs`), so expect to rebase those as others land.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 11:22 UTC · original · requested changes

Still open from the last review:

  1. Default. Please make bit 64 opt-in. The scalar lowering also reaches raw table and heap views, and their native bounds behaviour is unverified.
  2. A lowering test. It should force wide mode and assert 1, 2 and 4 rawBufferLoad calls for dwordx4, x8 and x16. Please keep the boundary-value checks, and record which GPU backends actually ran them, including any MSC skip.
**@⁠LakshanSivakumar** on GitHub · 2026-11-26 11:22 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6073282372) · **requested changes** Still open from the last review: 1. **Default.** Please make bit 64 opt-in. The scalar lowering also reaches raw table and heap views, and their native bounds behaviour is unverified. 2. **A lowering test.** It should force wide mode and assert 1, 2 and 4 `rawBufferLoad` calls for dwordx4, x8 and x16. Please keep the boundary-value checks, and record which GPU backends actually ran them, including any MSC skip.
Author
Owner

@⁠64bitMango on GitHub · 2026-11-26 11:53 UTC · original

Thanks. (1) Bit 64 is now off by default; VICTORY_SHADER_OPT=64 turns it on, and the docs list table and heap views on Metal as untested. (2) New lowering test the_dwords_of_one_scalar_load_are_read_four_a_call_with_bit_64: one rawBufferLoad per four dwords for dwordx4/x8/x16 with the bit on, one per dword without it. It fails when the optimisation is disabled. The addr_tests GPU test ran and passed on an M5 Pro (macOS 27.3) with the variable unset, at 0 and at 64; stride_tests is Windows-only and didn't run here. Over a 19,106-shader capture, the default now produces DXIL byte-identical to main for every shader.

**@⁠64bitMango** on GitHub · 2026-11-26 11:53 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7191299537) Thanks. (1) Bit 64 is now off by default; `VICTORY_SHADER_OPT=64` turns it on, and the docs list table and heap views on Metal as untested. (2) New lowering test `the_dwords_of_one_scalar_load_are_read_four_a_call_with_bit_64`: one `rawBufferLoad` per four dwords for dwordx4/x8/x16 with the bit on, one per dword without it. It fails when the optimisation is disabled. The `addr_tests` GPU test ran and passed on an M5 Pro (macOS 27.3) with the variable unset, at 0 and at 64; `stride_tests` is Windows-only and didn't run here. Over a 19,106-shader capture, the default now produces DXIL byte-identical to main for every shader.
Author
Owner

@⁠64bitMango on GitHub · 2026-11-26 11:56 UTC · original

@⁠LakshanSivakumar ready for another look when you have time. The review points are addressed above.

**@⁠64bitMango** on GitHub · 2026-11-26 11:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7191368498) @⁠LakshanSivakumar ready for another look when you have time. The review points are addressed above.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:10 UTC · original · requested changes

Thanks for making bit 64 opt-in and adding the call-count test. One edge case remains: an x4 load at 0xffff_fffc wraps to offsets 0, 4, and 8 in the scalar path, while the wide call leaves that behavior to the host (and the x8/x16 group starts still wrap in i32, so the groups are inconsistent too). See lower.rs ~5312 and ~5449. Please keep scalar lowering wherever the offset can wrap, add a synthetic regression case, and update the PR body to say the switch is off by default. Heads-up: this conflicts with #37 in pipeline/library.rs tag(); whichever lands second needs both inputs in the tag.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:10 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6073893526) · **requested changes** Thanks for making bit 64 opt-in and adding the call-count test. One edge case remains: an x4 load at `0xffff_fffc` wraps to offsets `0`, `4`, and `8` in the scalar path, while the wide call leaves that behavior to the host (and the x8/x16 group starts still wrap in `i32`, so the groups are inconsistent too). See `lower.rs` ~5312 and ~5449. Please keep scalar lowering wherever the offset can wrap, add a synthetic regression case, and update the PR body to say the switch is off by default. Heads-up: this conflicts with #37 in `pipeline/library.rs` `tag()`; whichever lands second needs both inputs in the tag.
Author
Owner

@⁠64bitMango on GitHub · 2026-11-26 12:36 UTC · original

Thanks. A group of four now becomes one call only when its start offset, added in 32 bits as the per-dword path adds it, is a constant whose bytes all lie below 2^32. Otherwise (wrapping, or computed at run time) it's read one dword per call at the scalar offsets, and x4/x8/x16 groups all use the same rule. New lowering test a_scalar_load_wrapping_past_32_bits_is_read_a_dword_a_call: x4, x8 and x16 at 0xffff_fffc read every dword at the scalar path's offsets with the wrapping group split, and x4 at 0xffff_fff0 still takes one call. It fails without the fix. On a 19,105-shader capture the guard costs little: with bit 64, 16,958 shaders use the wider calls (17,002 before). Unset, all are byte-identical to main. The PR body now says the switch is off by default. On the tag() conflict with #37: noted, whichever lands second will carry both inputs. Squashed to one commit.

**@⁠64bitMango** on GitHub · 2026-11-26 12:36 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7192230431) Thanks. A group of four now becomes one call only when its start offset, added in 32 bits as the per-dword path adds it, is a constant whose bytes all lie below 2^32. Otherwise (wrapping, or computed at run time) it's read one dword per call at the scalar offsets, and x4/x8/x16 groups all use the same rule. New lowering test `a_scalar_load_wrapping_past_32_bits_is_read_a_dword_a_call`: x4, x8 and x16 at `0xffff_fffc` read every dword at the scalar path's offsets with the wrapping group split, and x4 at `0xffff_fff0` still takes one call. It fails without the fix. On a 19,105-shader capture the guard costs little: with bit 64, 16,958 shaders use the wider calls (17,002 before). Unset, all are byte-identical to main. The PR body now says the switch is off by default. On the `tag()` conflict with #37: noted, whichever lands second will carry both inputs. Squashed to one commit.
Author
Owner

@⁠64bitMango on GitHub · 2026-11-26 12:38 UTC · original

@⁠LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.

**@⁠64bitMango** on GitHub · 2026-11-26 12:38 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7192273662) @⁠LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:47 UTC · original · approved these changes

Thanks. The wrap guard is right: a group of four is one call only when its offset is constant and all bytes lie below 2^32, group starts wrap like the per-dword adds, and x4/x8/x16 decide the same way. The wrap regression fails without the guard, the PR body says off by default, and the setting is in the cache key and tag. Approved. (Optional follow-up: a wrap test for the global_load path.)

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:47 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6074371534) · **approved these changes** Thanks. The wrap guard is right: a group of four is one call only when its offset is constant and all bytes lie below 2^32, group starts wrap like the per-dword adds, and x4/x8/x16 decide the same way. The wrap regression fails without the guard, the PR body says off by default, and the setting is in the cache key and tag. Approved. (Optional follow-up: a wrap test for the `global_load` path.)
Author
Owner

@⁠64bitMango on GitHub · 2026-11-26 13:17 UTC · original

Closing this: I'm continuing this work on my fork, 64bitMango/Native-Victory-macOS, where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.

**@⁠64bitMango** on GitHub · 2026-11-26 13:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7193135791) Closing this: I'm continuing this work on my fork, [64bitMango/Native-Victory-macOS](https://github.com/64bitMango/Native-Victory-macOS), where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.