Repository navigation
Shaders: bindless through pointer chasing, bias means only the pointer's own adds - #1333
MagiccConch wants to merge 3 commits into
Conversation
… the pointer's own adds A descriptor can live behind a pointer that the shader itself computes: load the pointer's halves from the root constants, mask them, add a constant, then load through it. resource.rs now follows that chase: s_load_dwordx2 pairs the halves into a pointer Address (deref), s_and_b32 keeps the bias through the masks, s_add_u32 and friends fold into it, and a dereference records where it lands. The recorded bias means only the pointer's own adds — an instruction's flat offset is re-added by the lowering (lower.rs) at both the scalar and the flat site, so it never counts twice. Co-authored-by: openhands <openhands@all-hands.dev>
|
This branch does not compile at head and Cause: Two fixes I checked locally:
With those two, more errors appear that they were hiding:
The shader cache matters most here. I did not get as far as running the new tests. A |
…chase The compiler adds a constant to a 64-bit pointer as s_add_u32 on the low half plus s_addc_u32 on the high one; the deref of the pair took only the raw load dword for the high half, so the chase fell through to "an address loaded from memory". The carry adds nothing but the carry (the bias is below 4 GB), so pointer_high takes the load's high half through the masks and such an s_addc_u32, and refuses one that adds a constant (a 4 GB shift the root view cannot follow). Co-authored-by: openhands <openhands@all-hands.dev>
|
The newer head |
Review on Marvisak#1333 reported the branch does not compile on Windows (Rust 1.98.1 MSVC): the u8-to-u16 widening of root_srvs missed readers, a test helper swallowed v_cmp_class_f16_matches_rdna2's closing brace, and the owned Root variants broke the dispatch patch-up code. - emit/host.rs: the cbv/srv chain maps both to (u16, bool); Root derives Clone so dispatch can patch pointer addresses on a copy. - emit/mod.rs, diff_tests.rs, valu_tests.rs: restored the test imports, root_views hold (u16, bool), the track call passes the lanes, and the missing closing brace is back. - victory-gpu pipeline: stage root-view lists hold u16 slots. - shader_cache: the second format (VSH2) writes root registers as u32 words so a 0x500 pointer register survives, and first-format entries are refused instead of misread; the round-trip test now covers a pointer register. Co-authored-by: openhands <openhands@all-hands.dev>
catminou4
left a comment
There was a problem hiding this comment.
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 108 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.
Bindless through pointer chasing: pointer_handle/pointer_smem chase the pointer's own descriptor, bias applies only to the pointer, and root_srv_handle binds the pointed buffer as a root view. Tests cover plain, masked-biased and high-half-carrying bias. The victory-gpu side is Windows-only — please make sure the Windows CI leg covers it.
|
At 2901bb6 on main ffe310e, victory-shader builds on Windows, but the two new GPU tests fail at the same assert in Failing tests: Unit tests only, no game files. AI-assisted (Claude; I ran it on my machine). |
|
Same two failures at The lowering looks right and the assert looks off by one. |
|
Automated triage for the maintainers. Closing because this change is already in Built on an Address.bias field main does not have; pointer-chased loads are served in main by USER_DATA and MEMORY addresses (27c3dc9, resource.rs address()). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution. |
Offline measurement on a retail dump, and the shader tests on AdaResult: +310 programs over Offline. I merged head 2901bb6 onto
295 of the 310 are among the programs that #1402 gains (through #1067). 15 are new, and neither #1402 nor #1597 gains them. Tests.
So the off-by-one comes from the PR itself, not from a merge or a driver. The other tests pass. No shader names or data are included, per the asset policy. AI-assisted (Claude Code). |
What and why
A descriptor can live behind a pointer that the shader itself computes: load the pointer's halves from the root constants, mask them, add a constant, then load through it. Until now
resource.rsonly recognized descriptors loaded directly from the root parameter area, so such shaders fell back to descriptor binding instead of the cheaper root view.This change teaches the tracer to follow the chase, and makes the recorded address honest about which adds belong to the pointer itself.
The change
Address.biasredefined: only the pointer's own adds. Previously an instruction's flat offset could reach the recorded bias, and the lowering added it again from the instruction — double-counting. Fixed inresource.rs: the bias now folds onlys_add_u32-style adds applied to the pointer, while flat offsets stay out and are re-added by the lowering at both the scalar and flat sites.Pointer-chase tracing in
resource.rs:s_load_dwordx2pairs its halves into a deref'd pointerAddresss_and_b32masks (the 48-bit VA mask) keep the bias flowing through the derefLowering (
emit/lower.rs):pointer_smemand the flat-deref path computea.bias + instruction_imm, so the recorded bias and the instruction's own offset compose exactly once.Testing
resource.rs: masked pointer keeps its bias through the deref; non-zero flat offset stays out of the bias (a_flat_offsets_stay_out_of_the_bias— assertsbias == 8, would be28if double-counted)emit/lower.rs: pointer chase binds the pointed buffer as a root view; masked + biased variant binds the same root viewmain(upstream waterfall/per-lane suite included),cargo clippy --all-targetscleanwindows-2025; the known Linux-onlyvictory-gpuhost_resourceissue does not affect these crates