Shaders: bindless through pointer chasing, bias means only the pointer's own adds #1333

Closed
MagiccConch wants to merge 3 commits from upstream-pr/1333 into main
MagiccConch commented 2026-11-24 17:30:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MagiccConch on 2026-11-24T17:30:47Z.


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.rs only 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.bias redefined: 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 in resource.rs: the bias now folds only s_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_dwordx2 pairs its halves into a deref'd pointer Address
  • s_and_b32 masks (the 48-bit VA mask) keep the bias flowing through the deref
  • dereference records where the chase lands

Lowering (emit/lower.rs): pointer_smem and the flat-deref path compute a.bias + instruction_imm, so the recorded bias and the instruction's own offset compose exactly once.

Testing

  • Tracker-level tests in 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 — asserts bias == 8, would be 28 if double-counted)
  • E2E in emit/lower.rs: pointer chase binds the pointed buffer as a root view; masked + biased variant binds the same root view
  • 105/105 victory-shader tests pass on top of current main (upstream waterfall/per-lane suite included), cargo clippy --all-targets clean
  • Verified CI runs on windows-2025; the known Linux-only victory-gpu host_resource issue does not affect these crates
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587656540 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333). Originally posted by [MagiccConch](https://github.com/MagiccConch) on 2026-11-24T17:30:47Z. --- ## 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.rs` only 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.bias` redefined: 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 in `resource.rs`: the bias now folds only `s_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_dwordx2` pairs its halves into a deref'd pointer `Address` - `s_and_b32` masks (the 48-bit VA mask) keep the bias flowing through the deref - dereference records where the chase lands **Lowering (`emit/lower.rs`):** `pointer_smem` and the flat-deref path compute `a.bias + instruction_imm`, so the recorded bias and the instruction's own offset compose exactly once. ## Testing - Tracker-level tests in `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` — asserts `bias == 8`, would be `28` if double-counted) - E2E in `emit/lower.rs`: pointer chase binds the pointed buffer as a root view; masked + biased variant binds the same root view - **105/105 victory-shader tests pass** on top of current `main` (upstream waterfall/per-lane suite included), `cargo clippy --all-targets` clean - Verified CI runs on `windows-2025`; the known Linux-only `victory-gpu` `host_resource` issue does not affect these crates
shortselow-byte commented 2026-11-24 18:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T17:54:41Z.


This branch does not compile at head ae8d79d (on main ffe310e); checked on Windows 11, Rust 1.98.1 MSVC, in an isolated target directory. cargo build --workspace --locked:

error[E0271]: expected `{[email protected]:139:51}` to return `(u8, bool)`, but it returns `(u16, bool)`
   --> crates\victory-shader\src\emit\host.rs:139:56

and cargo test also stops on

error: this file contains an unclosed delimiter
    --> crates\victory-shader\src\emit\valu_tests.rs:1126:3

Cause: root_srvs was widened from u8 to u16 (for the 0x500 pointer register), but not everywhere that reads it.

Two fixes I checked locally:

  • emit/host.rs:138: s.root_cbvs.iter().map(|&r| (u16::from(r), false)), so the chain has one item type.
  • emit/valu_tests.rs: the new helpers and tests were inserted before the closing } of v_cmp_class_f16_matches_rdna2 (after its }); at line 938), and that brace is gone. One } there closes it.

With those two, more errors appear that they were hiding:

  • victory-gpu (lib): pipeline/host.rs:365, shader_cache.rs:209, shader_cache.rs:276, all the same u8/u16 mismatch.
  • victory-shader (tests): Shader and Attr not in scope in emit/mod.rs (constant_color, lines 527 and 548), diff_tests.rs:1217 (Vec<(u16, bool)> from (u8, bool)), a resource::track call with 3 arguments, and several mismatched types and derefs. 11 errors in all.

The shader cache matters most here. shader_cache.rs writes root_cbvs/root_srvs one byte per register (out.extend(slots)) and reads them back the same way, under the VSH1 magic. A 0x500 register doesn't fit, so the on-disk format needs a wider encoding and a new magic, or caches written by main would be read wrong.

I did not get as far as running the new tests. A cargo test --workspace --locked and cargo clippy --workspace --all-targets -- -D warnings before pushing would show all of the above.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139882091 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333#issuecomment-7139882091). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T17:54:41Z. --- **This branch does not compile** at head `ae8d79d` (on `main` `ffe310e`); checked on Windows 11, Rust 1.98.1 MSVC, in an isolated target directory. `cargo build --workspace --locked`: ``` error[E0271]: expected `{[email protected]:139:51}` to return `(u8, bool)`, but it returns `(u16, bool)` --> crates\victory-shader\src\emit\host.rs:139:56 ``` and `cargo test` also stops on ``` error: this file contains an unclosed delimiter --> crates\victory-shader\src\emit\valu_tests.rs:1126:3 ``` **Cause:** `root_srvs` was widened from `u8` to `u16` (for the `0x500` pointer register), but not everywhere that reads it. Two fixes I checked locally: - `emit/host.rs:138`: `s.root_cbvs.iter().map(|&r| (u16::from(r), false))`, so the chain has one item type. - `emit/valu_tests.rs`: the new helpers and tests were inserted before the closing `}` of `v_cmp_class_f16_matches_rdna2` (after its `});` at line 938), and that brace is gone. One `}` there closes it. With those two, more errors appear that they were hiding: - `victory-gpu` (lib): `pipeline/host.rs:365`, `shader_cache.rs:209`, `shader_cache.rs:276`, all the same `u8`/`u16` mismatch. - `victory-shader` (tests): `Shader` and `Attr` not in scope in `emit/mod.rs` (`constant_color`, lines 527 and 548), `diff_tests.rs:1217` (`Vec<(u16, bool)>` from `(u8, bool)`), a `resource::track` call with 3 arguments, and several mismatched types and derefs. 11 errors in all. **The shader cache matters most here.** `shader_cache.rs` writes `root_cbvs`/`root_srvs` one byte per register (`out.extend(slots)`) and reads them back the same way, under the `VSH1` magic. A `0x500` register doesn't fit, so the on-disk format needs a wider encoding and a new magic, or caches written by `main` would be read wrong. I did not get as far as running the new tests. A `cargo test --workspace --locked` and `cargo clippy --workspace --all-targets -- -D warnings` before pushing would show all of the above.
marquezinii commented 2026-11-24 19:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:48:17Z.


The newer head 55e745b still doesn't build on Windows (Rust 1.98.1 MSVC, its own target directory). cargo build -p victory-shader --features host stops at the same E0271 in emit/host.rs:139 ((u8, bool) vs (u16, bool)), plus an E0599 on the collect after it. cargo test stops earlier, at the unclosed delimiter in valu_tests.rs (v_cmp_class_f16_matches_rdna2, opened at line 872).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141174753 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333#issuecomment-7141174753). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:48:17Z. --- The newer head `55e745b` still doesn't build on Windows (Rust 1.98.1 MSVC, its own target directory). `cargo build -p victory-shader --features host` stops at the same `E0271` in `emit/host.rs:139` (`(u8, bool)` vs `(u16, bool)`), plus an `E0599` on the `collect` after it. `cargo test` stops earlier, at the unclosed delimiter in `valu_tests.rs` (`v_cmp_class_f16_matches_rdna2`, opened at line 872).
catminou4 commented 2026-11-24 21:02:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:49Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046557559 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333#pullrequestreview-6046557559). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:49Z. **Review:** APPROVED --- 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.
wwwwwwww3333333 commented 2026-11-24 21:28:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-24T21:15:40Z.


At 2901bb6 on main ffe310e, victory-shader builds on Windows, but the two new GPU tests fail at the same assert in pointer_chase_shader() (valu_tests.rs:1036): lowered.root_srvs is [0x500] (1280), and the helper expects [0x501]. The three lowering tests in lower.rs expect [0x500] for the same kind of chase and pass. So either the helper's expectation or the register numbering needs another look.

Failing tests: emit::valu_tests::a_buffer_reached_through_a_pointer_loaded_from_the_constants and emit::valu_tests::a_pointer_chase_lowers_to_a_pointer_root_view. RX 6750 XT, Windows 11, Rust 1.98.1 MSVC, cargo test -p victory-shader --lib -- --test-threads=1: 121 passed, 2 failed.

Unit tests only, no game files. AI-assisted (Claude; I ran it on my machine).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144692853 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333#issuecomment-7144692853). Originally posted by [wwwwwwww3333333](https://github.com/wwwwwwww3333333) on 2026-11-24T21:15:40Z. --- At 2901bb6 on main ffe310e, victory-shader builds on Windows, but the two new GPU tests fail at the same assert in `pointer_chase_shader()` (valu_tests.rs:1036): `lowered.root_srvs` is `[0x500]` (1280), and the helper expects `[0x501]`. The three lowering tests in lower.rs expect `[0x500]` for the same kind of chase and pass. So either the helper's expectation or the register numbering needs another look. Failing tests: `emit::valu_tests::a_buffer_reached_through_a_pointer_loaded_from_the_constants` and `emit::valu_tests::a_pointer_chase_lowers_to_a_pointer_root_view`. RX 6750 XT, Windows 11, Rust 1.98.1 MSVC, `cargo test -p victory-shader --lib -- --test-threads=1`: 121 passed, 2 failed. Unit tests only, no game files. AI-assisted (Claude; I ran it on my machine).
marquezinii commented 2026-11-24 22:02:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T22:00:50Z.


Same two failures at 2901bb6 on NVIDIA: RTX 5070, driver 621.40, Windows 11, Rust 1.98.1 MSVC, its own target directory. It now builds, thanks for the fix. cargo test -p victory-shader --lib -- --test-threads=1 gives 132 passed and 2 failed, both at valu_tests.rs:1036 with left: [1280], right: [1281].

The lowering looks right and the assert looks off by one. pointer_handle gives ((dword + 1) << 8) | slot, and the pointer here is constants dword 4 of root parameter slot 0. That is 0x500, the value the helper's own doc comment gives (((4 + 1) << 8) | 0) and the one the three lower.rs tests expect. With only that line changed to vec![0x500], both tests pass on the RTX 5070. That includes a_buffer_reached_through_a_pointer_loaded_from_the_constants, which binds Root::Pointer { slot: 0, dword: 4, .. }, runs the dispatch on the hardware device and reads back the chased dword. All 12 pointer tests pass.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145685902 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333#issuecomment-7145685902). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T22:00:50Z. --- Same two failures at `2901bb6` on NVIDIA: RTX 5070, driver 621.40, Windows 11, Rust 1.98.1 MSVC, its own target directory. It now builds, thanks for the fix. `cargo test -p victory-shader --lib -- --test-threads=1` gives 132 passed and 2 failed, both at `valu_tests.rs:1036` with `left: [1280]`, `right: [1281]`. The lowering looks right and the assert looks off by one. `pointer_handle` gives `((dword + 1) << 8) | slot`, and the pointer here is constants dword 4 of root parameter slot 0. That is `0x500`, the value the helper's own doc comment gives (`((4 + 1) << 8) | 0`) and the one the three `lower.rs` tests expect. With only that line changed to `vec![0x500]`, both tests pass on the RTX 5070. That includes `a_buffer_reached_through_a_pointer_loaded_from_the_constants`, which binds `Root::Pointer { slot: 0, dword: 4, .. }`, runs the dispatch on the hardware device and reads back the chased dword. All 12 `pointer` tests pass.
upstream-sync closed this pull request 2026-11-25 01:06:15 +00:00
Marvisak commented 2026-11-25 01:08:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:37:44Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Built on an Address.bias field main does not have; pointer-chased loads are served in main by USER_DATA and MEMORY addresses (27c3dc9d, 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148711447 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333#issuecomment-7148711447). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:37:44Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Built on an Address.bias field main does not have; pointer-chased loads are served in main by USER_DATA and MEMORY addresses (27c3dc9d, 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.
sinan-cmyk commented 2026-11-25 02:06:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:49:05Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: +310 programs over main, 0 lost. Two of this PR's own tests fail, on hardware and on WARP.

Offline. I merged head 2901bb6 onto main ffe310e (clean merge; the head is based on ffe310e) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 → 22,034.

Failure on main Gained
a descriptor read only as data 310

295 of the 310 are among the programs that #1402 gains (through #1067). 15 are new, and neither #1402 nor #1597 gains them.

Tests. cargo test --locked -p victory-shader --lib fails two of this PR's new tests:

  • a_pointer_chase_lowers_to_a_pointer_root_view
  • a_buffer_reached_through_a_pointer_loaded_from_the_constants
valu_tests.rs:1036:5
  left: [1280]
 right: [1281]
Run Result
RTX 4070 SUPER, the merge onto main 2 failed
VICTORY_WARP=1, the merge onto main 2 failed, same value
The PR head 2901bb6 alone, no merge 2 failed, same value

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149991350 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1333#issuecomment-7149991350). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T01:49:05Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: +310 programs over `main`, 0 lost. Two of this PR's own tests fail, on hardware and on WARP.** **Offline.** I merged head 2901bb6 onto `main` ffe310e (clean merge; the head is based on ffe310e) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 → 22,034. | Failure on `main` | Gained | |---|---| | a descriptor read only as data | 310 | 295 of the 310 are among the programs that #1402 gains (through #1067). **15 are new**, and neither #1402 nor #1597 gains them. **Tests.** `cargo test --locked -p victory-shader --lib` fails two of this PR's new tests: - `a_pointer_chase_lowers_to_a_pointer_root_view` - `a_buffer_reached_through_a_pointer_loaded_from_the_constants` ``` valu_tests.rs:1036:5 left: [1280] right: [1281] ``` | Run | Result | |---|---| | RTX 4070 SUPER, the merge onto `main` | 2 failed | | `VICTORY_WARP=1`, the merge onto `main` | 2 failed, same value | | The PR head 2901bb6 alone, no merge | 2 failed, same value | 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).

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
Marvisak/VIctory!1333
No description provided.