Shaders: trace a code-table address read from the first lane of a uniform value #1225

Closed
github-bot wants to merge 1 commit from gh-pr/1225/head into gh-pr/1225/base
Owner

@⁠LooperSalty on GitHub · 2026-11-24 16:33 UTC · original
LooperSalty:shaders/first-lane-uniform-code-table → main · +155 −1 · 1 files · 1 commits · closed without merging

From a tester working with Claude (AI-assisted); measured on my own machine (i7-13700KF, RTX 4070 Super). No game data in the diff; test programs are synthetic words assembled with llvm-mc.

Complements ffe310e (waterfall loop over a first-lane table offset): this covers the other form of the same idiom, where the table address is a VGPR sum of s_getpc_b64 and a uniform index, read back to SGPRs with v_readfirstlane_b32 before s_load. When every lane holds the same value the first lane's read is that value, so the load is traced through the sum. A per-lane source is still refused, now naming the reason.

Measured on an integration tree: ColorDownsampleCS and InitCS now translate and validate (dxil.dll); in the shadow/luminance containers traced 70 -> 72, emitted 56 -> 58.

Two tests (uniform address traced; per-lane address refused by name). cargo test -p victory-gpu -p victory-shader is green on this branch (based on origin/main ffe310e).

**@⁠LooperSalty** on GitHub · 2026-11-24 16:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1225) `LooperSalty:shaders/first-lane-uniform-code-table` → `main` · +155 −1 · 1 files · 1 commits · closed without merging From a tester working with Claude (AI-assisted); measured on my own machine (i7-13700KF, RTX 4070 Super). No game data in the diff; test programs are synthetic words assembled with llvm-mc. Complements ffe310e (waterfall loop over a first-lane table offset): this covers the other form of the same idiom, where the table address is a VGPR sum of `s_getpc_b64` and a uniform index, read back to SGPRs with `v_readfirstlane_b32` before `s_load`. When every lane holds the same value the first lane's read is that value, so the load is traced through the sum. A per-lane source is still refused, now naming the reason. Measured on an integration tree: ColorDownsampleCS and InitCS now translate and validate (dxil.dll); in the shadow/luminance containers traced 70 -> 72, emitted 56 -> 58. Two tests (uniform address traced; per-lane address refused by name). `cargo test -p victory-gpu -p victory-shader` is green on this branch (based on `origin/main` ffe310e).
The console compiler builds the address of a table in the code in VGPRs
(s_getpc_b64 plus a uniform index through v_mov/v_lshlrev/v_add_co) and reads
it back with v_readfirstlane_b32 before the s_load. When every lane holds the
same value the first lane's read is that value, so the load is traced as if
it used the VGPR sum directly; a per-lane source is still refused, now by
name ("an address read from the first lane of a per-lane value").

Uniformity is decided from scalars, constants and first-lane reads through a
list of VALU operations (memoised per value).

Two tests: a uniform code-table address is traced (offset and computed index
checked); a per-lane one is refused by name. Measured on an integration tree:
ColorDownsampleCS and InitCS now translate and validate.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LwHrL6fhkpeG9ByE1rJxrt
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:18 +00:00
github-bot closed this pull request 2026-11-26 04:24:18 +00:00
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 17:10 UTC · original

Checked offline together with #1198 (address map), against the title's shader pack (victory translate --validate, 32-lane host, dxil.dll validator):

Tree ColorDownsampleInitCS / ColorDownsampleCS (auto exposure) CS_LaserLightShadowRaytracing
main an address not from a root parameter an address not from a root parameter
main + #1198 emit: s_getpc_b64 a lane mask holding lanes elsewhere read as data
main + #1198 + this PR emit and validate an address read from the first lane of a per-lane value
#439 stack + #1198 emit: s_getpc_b64 emits and validates
#439 stack + #1198 + this PR emit and validate an address read from the first lane of a per-lane value

So this PR fixes the exposure pair, but with #1198 it stops a program that #1198 (on the #439 stack) translated.

Why: #1198 turns an access whose address has no root parameter into a read of title memory at run time when runtime_address(why) matches one of its reasons ("an address not from a root parameter", "an address from a phi", "an address loaded from memory", ...). This PR gives a first-lane read of a non-uniform value a reason of its own, "an address read from the first lane of a per-lane value", which is not in that list, so the access is refused where #1198 would have read it. In CS_LaserLightShadowRaytracing the node address of the BVH walk is picked per lane (v_cndmask between s12 and s12 | 48) and read back with v_readfirstlane before an s_load: that case. The exposure pair is the one this PR resolves (s_getpc_b64 plus a uniform index, built in VALU and read back with v_readfirstlane).

Either side can make the two compose: #1198 can add the new reason to runtime_address (an address read from the first lane is one the translation can rebuild at run time), or this PR can keep the old reason for the first-lane reads it does not resolve.

No game data here: program names, counts and refusal messages only.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 17:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1225#issuecomment-7138794522) Checked offline together with #1198 (address map), against the title's shader pack (`victory translate --validate`, 32-lane host, `dxil.dll` validator): | Tree | `ColorDownsampleInitCS` / `ColorDownsampleCS` (auto exposure) | `CS_LaserLightShadowRaytracing` | |---|---|---| | `main` | an address not from a root parameter | an address not from a root parameter | | `main` + #1198 | `emit: s_getpc_b64` | a lane mask holding lanes elsewhere read as data | | `main` + #1198 + this PR | **emit and validate** | an address read from the first lane of a per-lane value | | #439 stack + #1198 | `emit: s_getpc_b64` | **emits and validates** | | #439 stack + #1198 + this PR | emit and validate | **an address read from the first lane of a per-lane value** | So this PR fixes the exposure pair, but with #1198 it stops a program that #1198 (on the #439 stack) translated. Why: #1198 turns an access whose address has no root parameter into a read of title memory at run time when `runtime_address(why)` matches one of its reasons ("an address not from a root parameter", "an address from a phi", "an address loaded from memory", ...). This PR gives a first-lane read of a non-uniform value a reason of its own, "an address read from the first lane of a per-lane value", which is not in that list, so the access is refused where #1198 would have read it. In `CS_LaserLightShadowRaytracing` the node address of the BVH walk is picked per lane (`v_cndmask` between `s12` and `s12 | 48`) and read back with `v_readfirstlane` before an `s_load`: that case. The exposure pair is the one this PR resolves (`s_getpc_b64` plus a uniform index, built in VALU and read back with `v_readfirstlane`). Either side can make the two compose: #1198 can add the new reason to `runtime_address` (an address read from the first lane is one the translation can rebuild at run time), or this PR can keep the old reason for the first-lane reads it does not resolve. No game data here: program names, counts and refusal messages only.
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 17:16 UTC · original

Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 (main's host build fails without it: E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 668 / 768 658 658

+2 programs translate and none is lost: "an address not from a root parameter" goes from 3 compute programs to 1, the same two the uniform-address change clears, and no other reason moves. Same 10 SPIR-V validation failures as the base.

Not tested: in-game.

**@⁠pablogonz12** on GitHub · 2026-11-24 17:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1225#issuecomment-7138948222) Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main `ffe310e` plus #1017 (main's host build fails without it: `E0425 host_resource`), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped). | | translate | valid SPIR-V | RADV pipeline | |---|---|---|---| | base | 666 / 768 | 656 | 656 | | your head | 668 / 768 | 658 | 658 | +2 programs translate and none is lost: "an address not from a root parameter" goes from 3 compute programs to 1, the same two the uniform-address change clears, and no other reason moves. Same 10 SPIR-V validation failures as the base. Not tested: in-game.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 17:59 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at b00573d: cargo test -p victory-shader passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 17:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1225#issuecomment-7140005070) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at b00573d: `cargo test -p victory-shader` passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Rezwo on GitHub · 2026-11-24 18:06 UTC · original

I reproduced the interaction with #1198 using a five-dword synthetic fixture, and found a counterexample to adding the new error string to the runtime-address allowlist unconditionally. This is resource tracking only; no game files, DXIL execution, or GPU run.

Resource-tracker input #1198 fe078c6 + #1225 b00573d + allowlist the new string
Synthetic runtime address from a first-lane read GLOBAL Refused at byte 8 GLOBAL
#1225 uniform code-table test — Pass Pass
#1225 per-lane code-table test — Refused as expected Incorrectly routed to GLOBAL

In the resource.rs test module, this is the extra fixture (generated instruction words; no title data):

#[test]
fn a_per_lane_runtime_pointer_stays_on_the_address_map() {
    let resources = track_words(
        &[0x7E04_0500, 0x7E06_0502, 0xF400_0181, 0xFA00_0000, S_ENDPGM],
        &[],
        HwStage::Cs,
    );
    assert_eq!(resources.scalar.as_slice(), &[((0, 2), at(GLOBAL, 0))]);
}

The instructions are two v_readfirstlane_b32 reads from v0 and v2 into s[2:3], then s_load_dword and s_endpgm. Run with cargo test --locked -p victory-shader --lib resource::tests::a_ on the combined tree. The two combined runs each passed 17/18, but failed different tests. A composable fix needs to distinguish the code-table case from a runtime pointer before selecting the fallback; the error text alone doesn't carry that distinction.

AI-assisted (Codex).

**@⁠Rezwo** on GitHub · 2026-11-24 18:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1225#issuecomment-7140172216) I reproduced the interaction with #1198 using a five-dword synthetic fixture, and found a counterexample to adding the new error string to the runtime-address allowlist unconditionally. This is resource tracking only; no game files, DXIL execution, or GPU run. | Resource-tracker input | #1198 `fe078c6` | + #1225 `b00573d` | + allowlist the new string | | --- | --- | --- | --- | | Synthetic runtime address from a first-lane read | `GLOBAL` | Refused at byte 8 | `GLOBAL` | | #1225 uniform code-table test | — | Pass | Pass | | #1225 per-lane code-table test | — | Refused as expected | Incorrectly routed to `GLOBAL` | In the `resource.rs` test module, this is the extra fixture (generated instruction words; no title data): ```rust #[test] fn a_per_lane_runtime_pointer_stays_on_the_address_map() { let resources = track_words( &[0x7E04_0500, 0x7E06_0502, 0xF400_0181, 0xFA00_0000, S_ENDPGM], &[], HwStage::Cs, ); assert_eq!(resources.scalar.as_slice(), &[((0, 2), at(GLOBAL, 0))]); } ``` The instructions are two `v_readfirstlane_b32` reads from `v0` and `v2` into `s[2:3]`, then `s_load_dword` and `s_endpgm`. Run with `cargo test --locked -p victory-shader --lib resource::tests::a_` on the combined tree. The two combined runs each passed 17/18, but failed different tests. A composable fix needs to distinguish the code-table case from a runtime pointer before selecting the fallback; the error text alone doesn't carry that distinction. AI-assisted (Codex).
Author
Owner

@⁠Rezwo on GitHub · 2026-11-24 18:14 UTC · original

I tested a small follow-up for the interaction with #1198: github.com/Rezwo/VIctory@2b68329a9f

The runtime-map fallback now checks the SSA dependencies of both address words and the dynamic offset. If a first-lane address depends on s_getpc_b64, it stays out of the runtime map; a uniform code-table access still uses the existing code-table path. This fallback only applies to memory instructions, not descriptor construction.

On the combined #1198 + #1225 tree, the synthetic runtime-pointer test failed before the patch. With the patch, that test and the uniform/per-lane code-table cases pass, including a new case where only the high word depends on the program counter. The locked shader library suite passed 127 tests (1 ignored) with WARP forced, and shader-crate Clippy passed with warnings denied. No title files or in-game test. This is for review or cherry-pick on the combined revisions; no new upstream PR.

AI-assisted (Codex).

**@⁠Rezwo** on GitHub · 2026-11-24 18:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1225#issuecomment-7140362726) I tested a small follow-up for the interaction with #1198: https://github.com/Rezwo/VIctory/commit/2b68329a9fa9242632f99b25cb07c12b9708682d The runtime-map fallback now checks the SSA dependencies of both address words and the dynamic offset. If a first-lane address depends on s_getpc_b64, it stays out of the runtime map; a uniform code-table access still uses the existing code-table path. This fallback only applies to memory instructions, not descriptor construction. On the combined #1198 + #1225 tree, the synthetic runtime-pointer test failed before the patch. With the patch, that test and the uniform/per-lane code-table cases pass, including a new case where only the high word depends on the program counter. The locked shader library suite passed 127 tests (1 ignored) with WARP forced, and shader-crate Clippy passed with warnings denied. No title files or in-game test. This is for review or cherry-pick on the combined revisions; no new upstream PR. AI-assisted (Codex).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:35 UTC · original

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

Code-table address read back with v_readfirstlane from a uniform VGPR sum: main traces this (resource.rs reaches_pc through lane reads, VGPR adds and phis, CODE addresses; 27c3dc9d).

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1225#issuecomment-7148665374) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Code-table address read back with v_readfirstlane from a uniform VGPR sum: main traces this (resource.rs `reaches_pc` through lane reads, VGPR adds and phis, `CODE` addresses; 27c3dc9d). 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.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1225
No description provided.