Shader: read the dwords of one console load four per call (VICTORY_SHADER_OPT bit 64, off by default) #35
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/35"
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?
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 onerawBufferLoadper four dwords instead of one per dword (s_buffer_load_dwordx2-x16from a raw view,global_load_dwordx2-x4). Off by default: unset (or0) 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_smemandcomputed_bufferpaths 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_fffcread per dword at the scalar offsets; theaddr_testsGPU 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 andxtask policyclean.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:
VICTORY_SHADER_OPT=0too, andaddr_testssilently 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.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:
rawBufferLoadcalls for dwordx4, x8 and x16. Please keep the boundary-value checks, and record which GPU backends actually ran them, including any MSC skip.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=64turns it on, and the docs list table and heap views on Metal as untested. (2) New lowering testthe_dwords_of_one_scalar_load_are_read_four_a_call_with_bit_64: onerawBufferLoadper four dwords for dwordx4/x8/x16 with the bit on, one per dword without it. It fails when the optimisation is disabled. Theaddr_testsGPU test ran and passed on an M5 Pro (macOS 27.3) with the variable unset, at 0 and at 64;stride_testsis 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.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.
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_fffcwraps to offsets0,4, and8in the scalar path, while the wide call leaves that behavior to the host (and the x8/x16 group starts still wrap ini32, so the groups are inconsistent too). Seelower.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 inpipeline/library.rstag(); whichever lands second needs both inputs in the tag.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 at0xffff_fffcread every dword at the scalar path's offsets with the wrapping group split, and x4 at0xffff_fff0still 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 thetag()conflict with #37: noted, whichever lands second will carry both inputs. Squashed to one commit.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.
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_loadpath.)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.
Pull request closed