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

Closed
64bitMango wants to merge 2 commits from upstream-pr/35 into main
64bitMango commented 2026-11-26 10:46:46 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T10:46:46Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6624951982 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T10:46:46Z. --- **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.
LakshanSivakumar commented 2026-11-26 11:01:02 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:01:02Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6072961391 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6072961391). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:01:02Z. **Review:** CHANGES_REQUESTED --- 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 commented 2026-11-26 11:22:22 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:22:22Z.

Review: CHANGES_REQUESTED


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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073282372 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6073282372). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:22:22Z. **Review:** CHANGES_REQUESTED --- 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.
64bitMango commented 2026-11-26 11:53:34 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:53:34Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7191299537 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7191299537). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T11:53:34Z. --- 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 commented 2026-11-26 11:56:49 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:56:49Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7191368498 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7191368498). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T11:56:49Z. --- @LakshanSivakumar ready for another look when you have time. The review points are addressed above.
LakshanSivakumar commented 2026-11-26 12:10:05 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:10:05Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073893526 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6073893526). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:10:05Z. **Review:** CHANGES_REQUESTED --- 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.
64bitMango commented 2026-11-26 12:36:51 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:36:51Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192230431 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7192230431). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T12:36:51Z. --- 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 commented 2026-11-26 12:38:47 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:38:47Z.


@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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192273662 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7192273662). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T12:38:47Z. --- @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.
LakshanSivakumar commented 2026-11-26 12:47:20 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:47:20Z.

Review: APPROVED


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.)

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074371534 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#pullrequestreview-6074371534). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:47:20Z. **Review:** APPROVED --- 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.)
64bitMango commented 2026-11-26 13:17:24 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T13:17:24Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7193135791 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/35#issuecomment-7193135791). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T13:17:24Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!35
No description provided.