Shaders: read root arguments the console spills to memory #302

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

@⁠dadou000 on GitHub · 2026-11-24 02:10 UTC · original
dadou000:spill-table-user-data → main · +214 −2 · 2 files · 1 commits · closed without merging

What

Compute programs whose root signature does not fit the 16 user SGPRs read their arguments through a spill table: s[0:1] holds a pointer (high dword masked to 40 bits, usually copied to s2/s3 first) to a table of user data, and the program s_loads descriptors and constants from it. Table dword k is user SGPR 16 + k. The translator only knew addresses that come from the declared root layout, so all of these failed with an address in an SGPR that is no root parameter.

For a compute program whose root layout lies entirely at user SGPR 16 and above, loads from that pointer with a constant offset become s_mov_b32 copies of the user SGPRs the dwords stand for. This happens before the SSA is built, so resource tracking and lowering see ordinary root arguments.

Only straight-line code from the pointer's set-up is rewritten. Tags are dropped at branch targets and whenever a pointer register is overwritten. Any other load stays a load.

Evidence

Example from the world shaders (a 64-thread group; layout is two constants then two descriptors, user data 16 to 23):

s_mov_b32 s2, s0 ; s_and_b32 s3, s1, 0xff
s_load_dwordx4 s[8:11], s[2:3], 0x10      ; table dwords 4..7 = Descriptor(20,2), Descriptor(22,2)
s_load_dwordx4 s[12:15], s[2:3], null     ; table dwords 0..3 = Constants(16,2), Constants(18,2)
s_or_b32 s5, s11, 0x10000 ; s_mov_b32 s6, -1 ...   ; buffer descriptor built from the root descriptor's address

One 64-thread-group dispatch in the title sets nine root parameters (about 35 dwords), and its shader loads at offsets 0x0, 0x20 and 0x4c, which is what a spill table of those arguments would look like.

On the world's compute shaders, an address in an SGPR that is no root parameter went from 34 programs to 4 in one run (RTX 4090, Windows 11). Failures that were hidden behind it now show: an address not from a root parameter, a root UAV or typed root view, an address from a phi, a descriptor read only as data.

Not verified

  • I only measured how many programs translate. I have not confirmed that the resulting images are right.
  • The rule that decides a program uses the spill table (every root parameter at user SGPR 16 or above, compute only) is what fits the programs I looked at. I don't know whether another program uses the same pointer with a different layout.
  • Two unit tests cover the rewrite and a load that must stay a load. cargo test -p victory-shader --lib passes (71 tests).

🤖 Generated with Claude Code

**@⁠dadou000** on GitHub · 2026-11-24 02:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/302) `dadou000:spill-table-user-data` → `main` · +214 −2 · 2 files · 1 commits · closed without merging ## What Compute programs whose root signature does not fit the 16 user SGPRs read their arguments through a spill table: `s[0:1]` holds a pointer (high dword masked to 40 bits, usually copied to `s2`/`s3` first) to a table of user data, and the program `s_load`s descriptors and constants from it. Table dword *k* is user SGPR `16 + k`. The translator only knew addresses that come from the declared root layout, so all of these failed with `an address in an SGPR that is no root parameter`. For a compute program whose root layout lies entirely at user SGPR 16 and above, loads from that pointer with a constant offset become `s_mov_b32` copies of the user SGPRs the dwords stand for. This happens before the SSA is built, so resource tracking and lowering see ordinary root arguments. Only straight-line code from the pointer's set-up is rewritten. Tags are dropped at branch targets and whenever a pointer register is overwritten. Any other load stays a load. ## Evidence Example from the world shaders (a 64-thread group; layout is two constants then two descriptors, user data 16 to 23): ``` s_mov_b32 s2, s0 ; s_and_b32 s3, s1, 0xff s_load_dwordx4 s[8:11], s[2:3], 0x10 ; table dwords 4..7 = Descriptor(20,2), Descriptor(22,2) s_load_dwordx4 s[12:15], s[2:3], null ; table dwords 0..3 = Constants(16,2), Constants(18,2) s_or_b32 s5, s11, 0x10000 ; s_mov_b32 s6, -1 ... ; buffer descriptor built from the root descriptor's address ``` One 64-thread-group dispatch in the title sets nine root parameters (about 35 dwords), and its shader loads at offsets 0x0, 0x20 and 0x4c, which is what a spill table of those arguments would look like. On the world's compute shaders, `an address in an SGPR that is no root parameter` went from **34 programs to 4** in one run (RTX 4090, Windows 11). Failures that were hidden behind it now show: `an address not from a root parameter`, `a root UAV or typed root view`, `an address from a phi`, `a descriptor read only as data`. ## Not verified - I only measured how many programs translate. I have not confirmed that the resulting images are right. - The rule that decides a program uses the spill table (every root parameter at user SGPR 16 or above, compute only) is what fits the programs I looked at. I don't know whether another program uses the same pointer with a different layout. - Two unit tests cover the rewrite and a load that must stay a load. `cargo test -p victory-shader --lib` passes (71 tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A compute program whose root signature does not fit the 16 user SGPRs
finds its arguments through a spill table: s[0:1] holds a pointer (high
dword masked to 40 bits, usually copied to s2/s3 first) to a table of
the user data, and the program s_loads descriptors and constants from
it. Table dword k is user SGPR 16 + k. The translator only knew
addresses that come from the declared root layout, so every such
program failed with "an address in an SGPR that is no root parameter".

For compute programs whose root layout lies entirely at user SGPR 16 and
above, loads from that pointer with a constant offset become s_mov_b32
copies of the user SGPRs the dwords stand for, before the SSA is built,
so resource tracking and lowering see what they see for ordinary root
arguments. Only straight-line code from the pointer's set-up is
rewritten (tags are dropped at branch targets and on any overwrite of
the pointer registers); other loads stay loads.

On the title's world shaders this took the "SGPR that is no root
parameter" failures from 34 programs to 4 in one run. Other failures
that were hidden behind it now show (address not from a root parameter,
root UAV or typed root view, an address from a phi...). Whether the
translated programs render correctly has not been checked beyond that.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:31 +00:00
github-bot closed this pull request 2026-11-26 03:58:31 +00:00
Author
Owner

@⁠gw1337x on GitHub · 2026-11-24 02:26 UTC · original

In-game test on an RX 7800 XT (Windows 11 26200), diag build. Build: main d2a4bae + #135 + #242 + #230 + #124 + #130 + this PR (clean merge). One run into the world, measured with the drop summary the same way as in #293.

The targeted reason drops a lot:

Reason Before (#293) With this PR
an address in an SGPR that is no root parameter 31 shaders, ~600 per frame 3 shaders, ~206 per frame
a root UAV or typed root view – 7 shaders, ~156 per frame
an address not from a root parameter 1 shader, ~63 per frame 10 shaders, ~93 per frame

The two growing rows look like shaders that now get past the spill table and stop at the next unsupported construct. Draws and dispatches lost per frame went from about 1,770 to about 1,340 in total (rates averaged over the run, menus included).

The rates are not strictly comparable: this run was shorter, so the menus weigh less. It ended at 67 s on the known page fault inside freed textures (#135's remaining case); comparable builds reached 113–177 s. That is one run, and it may just be that more draws now reach those textures sooner. No world frame was captured, so I can't say whether the picture changed.

**@⁠gw1337x** on GitHub · 2026-11-24 02:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7120141954) In-game test on an RX 7800 XT (Windows 11 26200), `diag` build. Build: `main` `d2a4bae` + #135 + #242 + #230 + #124 + #130 + this PR (clean merge). One run into the world, measured with the drop summary the same way as in #293. **The targeted reason drops a lot:** | Reason | Before (#293) | With this PR | |---|---|---| | an address in an SGPR that is no root parameter | 31 shaders, ~600 per frame | **3 shaders**, ~206 per frame | | a root UAV or typed root view | – | 7 shaders, ~156 per frame | | an address not from a root parameter | 1 shader, ~63 per frame | 10 shaders, ~93 per frame | The two growing rows look like shaders that now get past the spill table and stop at the next unsupported construct. Draws and dispatches lost per frame went from about 1,770 to about 1,340 in total (rates averaged over the run, menus included). The rates are not strictly comparable: this run was shorter, so the menus weigh less. It ended at 67 s on the known page fault inside freed textures (#135's remaining case); comparable builds reached 113–177 s. That is one run, and it may just be that more draws now reach those textures sooner. No world frame was captured, so I can't say whether the picture changed.
Author
Owner

@⁠matheushagedorn on GitHub · 2026-11-24 03:05 UTC · original

Tested on top of d2a4bae (+ #177, #151, #55, #189), cross-built on Linux and run under Wine.

victory translate does not apply the rule. apps/victory/src/translate.rs builds the IR with ir::build(&p.patched_code(), p.wave64, p.vgprs), so the CLI statistics never see the rewrite, only the runtime path through emit::translate_with does. Anyone measuring with the tool sees no change. Locally I used the same condition there:

let spilled = p.stage == victory_shader::HwStage::Cs
    && !p.layout.is_empty()
    && p.layout.iter().all(|r| p.stage.user_sgpr(r.user_data) >= 16);
match ir::build_with(&p.patched_code(), p.wave64, p.vgprs, spilled) {

Maybe worth exposing one helper for that rule so the two call sites cannot drift.

XboxBvhBuilder.dll's 52 containers (victory translate <game dir>\XboxBvhBuilder.dll), which matter for the world on NVIDIA: every builder program the title uses failed with an address in an SGPR that is no root parameter before this PR. The one I disassembled has exactly the pattern described here (copy of s[0:1] with the high dword masked to 0xff, s0 reused for a literal right after, then s_load_dwordx4 at offset 0 and s_load_dwordx16 at 0x10; two root descriptors and 16 constants at user data 16, 18 and 20).

before with this PR (CLI patched as above)
resources tracked 0 of 52 19 of 52
DXIL emitted 0 0

What blocks them now:

Programs First failure
18 resources: an address not from a root parameter
12 emit: a root UAV or typed root view
7 emit: a select on an untracked mask
7 resources: an address in an SGPR that is no root parameter
6 resources: an address from a root parameter that is no address
2 resources: an address from a phi

The second row comes from the Source::Built arm in lower.rs, which handles root CBVs and raw root SRVs; the builder's root descriptors are UAVs (in the program I disassembled, both are), so they fall through. I haven't checked each of the 12.

For context on why this matters: on Linux (RTX 5060 Ti, vkd3d-proton 3.2.0) the world's Xid 13 MMU fault (#71) goes away when one compute program of the BVH-preparation pass is skipped (48426bae580a080c, see my comment there), and since the builder never runs, my guess is that the title's ray-tracing shaders walk memory that was never built (see #274 on the console node format); I have not confirmed that part. This PR is the first step towards that builder translating.

No game data attached.

**@⁠matheushagedorn** on GitHub · 2026-11-24 03:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7120761345) Tested on top of `d2a4bae` (+ #177, #151, #55, #189), cross-built on Linux and run under Wine. **`victory translate` does not apply the rule.** `apps/victory/src/translate.rs` builds the IR with `ir::build(&p.patched_code(), p.wave64, p.vgprs)`, so the CLI statistics never see the rewrite, only the runtime path through `emit::translate_with` does. Anyone measuring with the tool sees no change. Locally I used the same condition there: ```rust let spilled = p.stage == victory_shader::HwStage::Cs && !p.layout.is_empty() && p.layout.iter().all(|r| p.stage.user_sgpr(r.user_data) >= 16); match ir::build_with(&p.patched_code(), p.wave64, p.vgprs, spilled) { ``` Maybe worth exposing one helper for that rule so the two call sites cannot drift. **`XboxBvhBuilder.dll`'s 52 containers** (`victory translate <game dir>\XboxBvhBuilder.dll`), which matter for the world on NVIDIA: every builder program the title uses failed with `an address in an SGPR that is no root parameter` before this PR. The one I disassembled has exactly the pattern described here (copy of `s[0:1]` with the high dword masked to `0xff`, `s0` reused for a literal right after, then `s_load_dwordx4` at offset 0 and `s_load_dwordx16` at `0x10`; two root descriptors and 16 constants at user data 16, 18 and 20). | | before | with this PR (CLI patched as above) | |---|---|---| | resources tracked | 0 of 52 | 19 of 52 | | DXIL emitted | 0 | 0 | What blocks them now: | Programs | First failure | |---|---| | 18 | `resources: an address not from a root parameter` | | 12 | `emit: a root UAV or typed root view` | | 7 | `emit: a select on an untracked mask` | | 7 | `resources: an address in an SGPR that is no root parameter` | | 6 | `resources: an address from a root parameter that is no address` | | 2 | `resources: an address from a phi` | The second row comes from the `Source::Built` arm in `lower.rs`, which handles root CBVs and raw root SRVs; the builder's root descriptors are UAVs (in the program I disassembled, both are), so they fall through. I haven't checked each of the 12. For context on why this matters: on Linux (RTX 5060 Ti, vkd3d-proton 3.2.0) the world's `Xid 13` MMU fault (#71) goes away when one compute program of the BVH-preparation pass is skipped (`48426bae580a080c`, see my comment there), and since the builder never runs, my guess is that the title's ray-tracing shaders walk memory that was never built (see #274 on the console node format); I have not confirmed that part. This PR is the first step towards that builder translating. No game data attached.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 03:08 UTC · original

Review note, with a small repro. The rewrite turns a spill-table load into s_mov_b32 sK, s(16+k), which reads whatever that register holds at that point in the program, not the entry value. If the program has already written s16 and up (as the destination of an earlier load, say), a later load reads the wrong root argument, with no refusal.

With this PR on main (d2a4bae), ir::build_with(.., spilled = true) on

s_load_dwordx8 s[16:23], s[0:1], 0x20   ; table dwords 8..15
s_load_dwordx4 s[8:11],  s[0:1], 0x0    ; table dwords 0..3

gives

s_mov_b32 reads=[S(24)] writes=[S(16)]   ... S(31) -> S(23)
s_mov_b32 reads=[(S(16), Value(8))] writes=[S(8)]   ... S(19) -> S(11)

The second load's moves read the values the first load just wrote (Value(8..11)), so s[8:11] become user data 24..27 instead of 16..19, and p.inputs never contains s16.

The example in the description loads into s8..s15, so it does not hit this, and the 34 to 4 count may well be unaffected. But nothing stops a program from loading into s16+. Could the rewrite read the entry values directly (the program's inputs for user SGPR 16+k) rather than the live registers, or be skipped once any of those registers has been written earlier in the scan?

This is the PR for the top row of #293, so it matters that it cannot bind the wrong argument silently. From a synthetic test only; I have no copy of the title.

**@⁠r4tedx** on GitHub · 2026-11-24 03:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7120814089) Review note, with a small repro. The rewrite turns a spill-table load into `s_mov_b32 sK, s(16+k)`, which reads whatever that register holds at that point in the program, not the entry value. If the program has already written s16 and up (as the destination of an earlier load, say), a later load reads the wrong root argument, with no refusal. With this PR on `main` (`d2a4bae`), `ir::build_with(.., spilled = true)` on ``` s_load_dwordx8 s[16:23], s[0:1], 0x20 ; table dwords 8..15 s_load_dwordx4 s[8:11], s[0:1], 0x0 ; table dwords 0..3 ``` gives ``` s_mov_b32 reads=[S(24)] writes=[S(16)] ... S(31) -> S(23) s_mov_b32 reads=[(S(16), Value(8))] writes=[S(8)] ... S(19) -> S(11) ``` The second load's moves read the values the first load just wrote (`Value(8..11)`), so s[8:11] become user data 24..27 instead of 16..19, and `p.inputs` never contains s16. The example in the description loads into s8..s15, so it does not hit this, and the 34 to 4 count may well be unaffected. But nothing stops a program from loading into s16+. Could the rewrite read the entry values directly (the program's inputs for user SGPR 16+k) rather than the live registers, or be skipped once any of those registers has been written earlier in the scan? This is the PR for the top row of #293, so it matters that it cannot bind the wrong argument silently. From a synthetic test only; I have no copy of the title.
Author
Owner

@⁠louketa on GitHub · 2026-11-24 03:46 UTC · original

Measured this PR against the title's own world shaders (v1.0.2.1). Summary: it clears the first failure of every program it targets, but none of them translate fully yet. The next stop for most is an address that comes out of the spill table.

How

  • Windows 11, RTX 3080, main d2a4bae + #346 #333 #307 #329 #309 #135 #160 #205 #352, then this PR on top.
  • In a local build, every container whose translation fails at run time is written to a folder outside the repo. I entered the world once (opening cutscene) and got 276 failing containers, then translated those offline with and without this PR. Nothing from them is attached here.
  • In that world run, an address in an SGPR that is no root parameter was the largest drop reason: 28 compute programs, about 55% of the draws and dispatches dropped per frame (for example 3b90165a77d95cdf, f6e47efa50226beb, 5552dac6a2b7a1fd).

Merge note

This PR conflicts with #309 in emit::translate. I kept both: ir::build_with(..., spilled) followed by sgpr_spill::forward(&mut p).

Result: 34 programs that fail with an address in an SGPR that is no root parameter without this PR

Next failure with this PR Programs
an address not from a root parameter 12
a root UAV or typed root view (emit) 8
an address from a root parameter that is no address 6
an address in an SGPR that is no root parameter (at a later instruction) 4
an address from a phi 2
a select on an untracked mask (emit) 2
fully translated 0

The smallest case

3b90165a77d95cdf is a 22-instruction compute program. Its layout is two root descriptors and one root-constant block, all at user data 16 or above, so spilled is true. It reads the constants from the spill table, which this PR now resolves. It also loads the address of its root UAV from the table (the 64-bit value at that parameter's offset) and builds a buffer descriptor around it for a buffer_store. That address is still reported as an address in an SGPR that is no root parameter at the store. Treating a 64-bit spill-table load at a root-descriptor parameter's offset as that parameter's address looks like the natural next step. Most of the rows above look like the same case.

Side note

victory translate (apps/victory/src/translate.rs) still calls ir::build, so static scans do not apply the spill rule and show none of these programs failing the way they do at run time. With the same spilled condition there, the CLI matches the runtime.

No game data attached.

**@⁠louketa** on GitHub · 2026-11-24 03:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7121407497) Measured this PR against the title's own world shaders (v1.0.2.1). Summary: it clears the first failure of every program it targets, but none of them translate fully yet. The next stop for most is an address that comes **out of** the spill table. ### How - Windows 11, RTX 3080, `main` `d2a4bae` + #346 #333 #307 #329 #309 #135 #160 #205 #352, then this PR on top. - In a local build, every container whose translation fails at run time is written to a folder outside the repo. I entered the world once (opening cutscene) and got 276 failing containers, then translated those offline with and without this PR. Nothing from them is attached here. - In that world run, `an address in an SGPR that is no root parameter` was the largest drop reason: 28 compute programs, about 55% of the draws and dispatches dropped per frame (for example `3b90165a77d95cdf`, `f6e47efa50226beb`, `5552dac6a2b7a1fd`). ### Merge note This PR conflicts with #309 in `emit::translate`. I kept both: `ir::build_with(..., spilled)` followed by `sgpr_spill::forward(&mut p)`. ### Result: 34 programs that fail with `an address in an SGPR that is no root parameter` without this PR | Next failure with this PR | Programs | |---|---| | `an address not from a root parameter` | 12 | | `a root UAV or typed root view` (emit) | 8 | | `an address from a root parameter that is no address` | 6 | | `an address in an SGPR that is no root parameter` (at a later instruction) | 4 | | `an address from a phi` | 2 | | `a select on an untracked mask` (emit) | 2 | | fully translated | 0 | ### The smallest case `3b90165a77d95cdf` is a 22-instruction compute program. Its layout is two root descriptors and one root-constant block, all at user data 16 or above, so `spilled` is true. It reads the constants from the spill table, which this PR now resolves. It also loads the **address** of its root UAV from the table (the 64-bit value at that parameter's offset) and builds a buffer descriptor around it for a `buffer_store`. That address is still reported as `an address in an SGPR that is no root parameter` at the store. Treating a 64-bit spill-table load at a root-descriptor parameter's offset as that parameter's address looks like the natural next step. Most of the rows above look like the same case. ### Side note `victory translate` (`apps/victory/src/translate.rs`) still calls `ir::build`, so static scans do not apply the spill rule and show none of these programs failing the way they do at run time. With the same `spilled` condition there, the CLI matches the runtime. No game data attached.
Author
Owner

@⁠louketa on GitHub · 2026-11-24 04:00 UTC · original

@⁠dadou000 @⁠r4tedx I opened #489 on top of this PR. It fixes the entry-value issue r4tedx reported: the user SGPRs the table loads stand for are copied into an unused SGPR block on entry, and the loads read that block.

It does show up in the title's shaders. 3b90165a77d95cdf (the largest drop in my world run) hits exactly that case, and with the fix it gets through resource tracking. Numbers over the 34 programs and a regression test that fails on this PR alone are in #489. dadou000, feel free to pull the commit into this branch if you'd rather keep it in one PR.

**@⁠louketa** on GitHub · 2026-11-24 04:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7121621446) @⁠dadou000 @⁠r4tedx I opened #489 on top of this PR. It fixes the entry-value issue r4tedx reported: the user SGPRs the table loads stand for are copied into an unused SGPR block on entry, and the loads read that block. It does show up in the title's shaders. `3b90165a77d95cdf` (the largest drop in my world run) hits exactly that case, and with the fix it gets through resource tracking. Numbers over the 34 programs and a regression test that fails on this PR alone are in #489. dadou000, feel free to pull the commit into this branch if you'd rather keep it in one PR.
Author
Owner

@⁠etcetera-yt on GitHub · 2026-11-24 05:36 UTC · original

translate_for now builds compute programs whose root arguments all sit past the 16 user SGPRs with
ir::build_with(..., spilled), but victory translate still calls ir::build (apps/victory/src/translate.rs,
the per-program loop), so the CLI never applies the spill rewrite. Checking this PR from the command line therefore
shows no change for such programs, while the runtime path does use it.

Example: the ray-tracing builder's DLL (XboxBvhBuilder.dll) holds 52 compute programs whose layout entries all
start at user-data dword 16 with 4 user SGPRs. victory translate <dll> --list reports all 52 failing with
"an address in an SGPR that is no root parameter" with this PR merged, while in a title run only 1 of the 35 used
ones still fails for that reason (the others fail later, on root UAVs and addresses in root constants).

Building the CLI's programs the way translate_for does (same spilled test, ir::build_with) would make the two
agree. Tested on Windows 10 19045, RTX 5060 Ti, with this PR on d2a4bae plus other open PRs.

AI use: Claude Code, Claude Opus 5.5.

**@⁠etcetera-yt** on GitHub · 2026-11-24 05:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7123105732) `translate_for` now builds compute programs whose root arguments all sit past the 16 user SGPRs with `ir::build_with(..., spilled)`, but `victory translate` still calls `ir::build` (`apps/victory/src/translate.rs`, the per-program loop), so the CLI never applies the spill rewrite. Checking this PR from the command line therefore shows no change for such programs, while the runtime path does use it. Example: the ray-tracing builder's DLL (`XboxBvhBuilder.dll`) holds 52 compute programs whose layout entries all start at user-data dword 16 with 4 user SGPRs. `victory translate <dll> --list` reports all 52 failing with "an address in an SGPR that is no root parameter" with this PR merged, while in a title run only 1 of the 35 used ones still fails for that reason (the others fail later, on root UAVs and addresses in root constants). Building the CLI's programs the way `translate_for` does (same `spilled` test, `ir::build_with`) would make the two agree. Tested on Windows 10 19045, RTX 5060 Ti, with this PR on `d2a4bae` plus other open PRs. AI use: Claude Code, Claude Opus 5.5.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 05:51 UTC · original

Independent check of head 815178d on main d2a4bae, read together with #489, which is stacked on it. I read the comments above first. The entry-value problem (@⁠r4tedx, and the overlap case @⁠marquezinii added on #489) is real and #489 fixes it; my run below is one more confirmation, with a shape that ends in a refusal rather than a wrong value. I found nothing else wrong in this commit; the details of what I checked in the rewrite itself are in my note on #489, since that is the version that should go in.

Read against the RDNA2 ISA (30-November-2020)

  • 7.2.1 "S_LOAD_DWORD", p. 52: ADDR = SGPR[base] + inst_offset + { M0 or SGPR[offset] or zero }, the two LSBs ignored. The rewrite takes loads with a constant, non-negative, dword-aligned offset and no SGPR offset; the rest stay loads. Narrower than the hardware, never wrong.
  • That s[0:1] holds the table pointer and table dword k is user SGPR 16 + k is the console compiler's convention, not ISA; the title counts above are the evidence for it.

Run on hardware. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, dxil.dll from the Windows SDK 10.0.26100 validating; cargo test -p victory-shader -- --test-threads=1:

  • this PR on main: 71 passed, 0 failed (main: 69).

  • A local end-to-end probe (not pushed): a compute program whose whole layout is in the table (8 root constants at user data 16..23 holding 100..107, a UAV table at 24), which stores the constants it sees, on the GPU and on WARP:

    loads this PR #489
    s_load_dwordx8 s[40:47] 100..107 100..107
    s_load_dwordx8 s[16:23] first, then the same dwords into s[40:47] 100..107 (each s_mov_b32 of the first load is s16+k <- s16+k, so nothing is lost) 100..107
    s_load_dwordx16 s[12:27], then the table descriptor from dword 8 and the constants refused: an address in an SGPR that is no root parameter at the descriptor load, because s24 then holds what stood for table dword 12 100..107

    The third row is the shape described for 3b90165a77d95cdf above: a wide load over s16 and up, then a load of an address from the table. Here it ends in the old refusal; with other registers it binds the wrong argument, as shown above.

  • IR probes with spilled = true: a load at a branch target (forward, and a loop header), a pointer copy overwritten by s_movk_i32, a pointer copied with s_mov_b64, and a load whose destination covers the pointer copy all leave the affected load a load. Correct, and conservative.

Not raised above, small

  • The rewritten s_mov_b32 run shares the load's offset. In build_with that makes each of them "end" its block when that offset is a leader, setting a self-jump exit that the block's real last instruction then overwrites. It comes out right, but only through that overwrite.
  • apps/victory/src/translate.rs still calls ir::build (already noted above); one helper for the spilled condition would keep the CLI and emit::translate from drifting.

Verdict from here: correct only together with #489's commit; I would merge them as one.

Not checked: the title (no game files here), AMD hardware, the 16-or-more user SGPR case discussed on #489.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 05:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7123337535) Independent check of head `815178d` on `main` `d2a4bae`, read together with #489, which is stacked on it. I read the comments above first. The entry-value problem (@⁠r4tedx, and the overlap case @⁠marquezinii added on #489) is real and #489 fixes it; my run below is one more confirmation, with a shape that ends in a refusal rather than a wrong value. I found nothing else wrong in this commit; the details of what I checked in the rewrite itself are in my note on #489, since that is the version that should go in. **Read against the RDNA2 ISA (30-November-2020)** - 7.2.1 "S_LOAD_DWORD", p. 52: `ADDR = SGPR[base] + inst_offset + { M0 or SGPR[offset] or zero }`, the two LSBs ignored. The rewrite takes loads with a constant, non-negative, dword-aligned offset and no SGPR offset; the rest stay loads. Narrower than the hardware, never wrong. - That `s[0:1]` holds the table pointer and table dword `k` is user SGPR `16 + k` is the console compiler's convention, not ISA; the title counts above are the evidence for it. **Run on hardware.** NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, `dxil.dll` from the Windows SDK 10.0.26100 validating; `cargo test -p victory-shader -- --test-threads=1`: - this PR on `main`: **71 passed, 0 failed** (`main`: 69). - A local end-to-end probe (not pushed): a compute program whose whole layout is in the table (8 root constants at user data 16..23 holding 100..107, a UAV table at 24), which stores the constants it sees, on the GPU and on WARP: | loads | this PR | #489 | |---|---|---| | `s_load_dwordx8 s[40:47]` | 100..107 | 100..107 | | `s_load_dwordx8 s[16:23]` first, then the same dwords into `s[40:47]` | 100..107 (each `s_mov_b32` of the first load is `s16+k <- s16+k`, so nothing is lost) | 100..107 | | `s_load_dwordx16 s[12:27]`, then the table descriptor from dword 8 and the constants | **refused**: `an address in an SGPR that is no root parameter` at the descriptor load, because s24 then holds what stood for table dword 12 | 100..107 | The third row is the shape described for `3b90165a77d95cdf` above: a wide load over s16 and up, then a load of an address from the table. Here it ends in the old refusal; with other registers it binds the wrong argument, as shown above. - IR probes with `spilled = true`: a load at a branch target (forward, and a loop header), a pointer copy overwritten by `s_movk_i32`, a pointer copied with `s_mov_b64`, and a load whose destination covers the pointer copy all leave the affected load a load. Correct, and conservative. **Not raised above, small** - The rewritten `s_mov_b32` run shares the load's offset. In `build_with` that makes each of them "end" its block when that offset is a leader, setting a self-jump exit that the block's real last instruction then overwrites. It comes out right, but only through that overwrite. - `apps/victory/src/translate.rs` still calls `ir::build` (already noted above); one helper for the `spilled` condition would keep the CLI and `emit::translate` from drifting. Verdict from here: correct only together with #489's commit; I would merge them as one. Not checked: the title (no game files here), AMD hardware, the 16-or-more user SGPR case discussed on #489. AI-assisted (Claude Code).
Author
Owner

@⁠cybx on GitHub · 2026-11-24 11:22 UTC · original

The offline census (victory translate) still builds every program with ir::build, so it keeps counting spill-table compute programs under "an address in an SGPR that is no root parameter" even though translate_for rewrites their table loads. On a fork branch I moved the spill condition into one place, emit::build_ir(&NativeProgram), which both translate_for and apps/victory/src/translate.rs now call: github.com/cybx/VIctory@255e7cb3f2 (8 lines, applies on top of this PR + #489; that branch also carries #645). Feel free to fold it in here so the census numbers match the runtime.

**@⁠cybx** on GitHub · 2026-11-24 11:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7130016468) The offline census (`victory translate`) still builds every program with `ir::build`, so it keeps counting spill-table compute programs under "an address in an SGPR that is no root parameter" even though `translate_for` rewrites their table loads. On a fork branch I moved the spill condition into one place, `emit::build_ir(&NativeProgram)`, which both `translate_for` and `apps/victory/src/translate.rs` now call: https://github.com/cybx/VIctory/commit/255e7cb3f25c79e0d5f455fadcf268934d0fa5ed (8 lines, applies on top of this PR + #489; that branch also carries #645). Feel free to fold it in here so the census numbers match the runtime.
Author
Owner

@⁠justlovett0 on GitHub · 2026-11-24 17:32 UTC · original

Runtime data point (Win10/RTX 3080, driver 621.24): on the actual world containers, this PR's spill-table rewrite does not clear the "an address in an SGPR that is no root parameter" class. We dumped the runtime failing containers and censused them: the XboxBvhBuilder computes (e.g. 3b90165a77d95cdf, f6e47efa50226beb) still fail with this reason after the PR is applied — the spilled detection (layout entirely at user SGPR ≥ 16) doesn't fire for them, so their root arguments aren't rewritten.

This matches the #1247 offline benchmark (#302/#489 gain 0 on the 195-program class). The runtime containers are "Wrapped" (root layout patched at runtime) and differ from the archive bytes, so the offline census understates the class; the runtime dump+census is the way to see it.

These few shaders are high-impact: XboxBvhBuilder builds the ray-tracing BVH, so without them the lighting has no BVH (a major part of the black final image). The detection needs to handle their actual spill pattern — happy to share the dumped containers (compute-3b90165a77d95cdf.bin etc.) for analysis.

AI use: Qwen Code (underlying model name not disclosed by the tool); counts from a victory translate census of captured runtime containers.

**@⁠justlovett0** on GitHub · 2026-11-24 17:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7139347628) Runtime data point (Win10/RTX 3080, driver 621.24): on the actual world containers, this PR's spill-table rewrite **does not clear the "an address in an SGPR that is no root parameter" class**. We dumped the runtime failing containers and censused them: the XboxBvhBuilder computes (e.g. `3b90165a77d95cdf`, `f6e47efa50226beb`) still fail with this reason after the PR is applied — the `spilled` detection (layout entirely at user SGPR ≥ 16) doesn't fire for them, so their root arguments aren't rewritten. This matches the #1247 offline benchmark (#302/#489 gain 0 on the 195-program class). The runtime containers are "Wrapped" (root layout patched at runtime) and differ from the archive bytes, so the offline census understates the class; the runtime dump+census is the way to see it. These few shaders are high-impact: XboxBvhBuilder builds the ray-tracing BVH, so without them the lighting has no BVH (a major part of the black final image). The detection needs to handle their actual spill pattern — happy to share the dumped containers (`compute-3b90165a77d95cdf.bin` etc.) for analysis. AI use: Qwen Code (underlying model name not disclosed by the tool); counts from a `victory translate` census of captured runtime containers.
Author
Owner

@⁠YaBulochka on GitHub · 2026-11-24 20:19 UTC · original

Retail-run confirmation on Linux/RADV: this is the change that turned a black screen into a visible, coloured 3D scene here.

Title 1.0.2.1, Series X dump
OS Linux, Wine 11.22 in a Proton 11.0 prefix, vkd3d-proton master
GPU RX 7600 XT, RADV from Mesa 26.3.1
Tree ffe310e + #994 + #491 + #1548 + #1583 + #1319 + #1402 + this PR

Before, the run logged 27 GFX10 code at 0x30: an address in an SGPR that is no root parameter is not supported lines (and more at 0x40/0x2c), and those programs' draws were dropped.

After this PR: 4 such lines left, the scene reaches 3,770-3,881 draws/frame and, with VICTORY_DEBUG_PS=1, a coloured 3D frame renders at 1.5 fps (menus at 2 fps). Without the debug pixel shader the same tree gets to the prologue and then the GPU is removed (0x887A0005) at 0.2 fps, which I read as the normal pixel path being far heavier, not as a fault of this PR.

Merge note, in case someone stacks it the same way: on top of #1402 this PR conflicts in crates/victory-shader/src/emit/mod.rs. I resolved it as ir::build_with(..., spilled) from this PR, then structure::structure(&p), then resource::track(&p, &native.layout, native.stage, st.as_ref().ok()) (the four-argument track), and it builds and runs.

Remaining in the log: 4 x a descriptor read only as data, and a structured buffer of unknown stride - the compute side, unrelated to this PR.

**@⁠YaBulochka** on GitHub · 2026-11-24 20:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7143358213) Retail-run confirmation on Linux/RADV: this is the change that turned a black screen into a visible, coloured 3D scene here. | | | |---|---| | Title | `1.0.2.1`, Series X dump | | OS | Linux, Wine 11.22 in a Proton 11.0 prefix, vkd3d-proton master | | GPU | RX 7600 XT, RADV from Mesa 26.3.1 | | Tree | `ffe310e` + #994 + #491 + #1548 + #1583 + #1319 + #1402 + this PR | Before, the run logged **27** `GFX10 code at 0x30: an address in an SGPR that is no root parameter is not supported` lines (and more at 0x40/0x2c), and those programs' draws were dropped. After this PR: **4** such lines left, the scene reaches **3,770-3,881 draws/frame** and, with `VICTORY_DEBUG_PS=1`, a coloured 3D frame renders at 1.5 fps (menus at 2 fps). Without the debug pixel shader the same tree gets to the prologue and then the GPU is removed (`0x887A0005`) at 0.2 fps, which I read as the normal pixel path being far heavier, not as a fault of this PR. Merge note, in case someone stacks it the same way: on top of #1402 this PR conflicts in `crates/victory-shader/src/emit/mod.rs`. I resolved it as `ir::build_with(..., spilled)` from this PR, then `structure::structure(&p)`, then `resource::track(&p, &native.layout, native.stage, st.as_ref().ok())` (the four-argument `track`), and it builds and runs. Remaining in the log: 4 x `a descriptor read only as data`, and `a structured buffer of unknown stride` - the compute side, unrelated to this PR.
Author
Owner

@⁠KevinPratap on GitHub · 2026-11-24 22:14 UTC · original

A note for when this lands: victory translate (apps/victory/src/translate.rs) builds programs with ir::build, without the spill rewrite that translate_for applies through build_with. So the offline report still counts these programs as an address in an SGPR that is no root parameter, although they translate in the title.

Measured on a full shader pack, --host-lanes 32-32, with the same decision shared (a NativeProgram::spills_roots() used by both emit and translate.rs): that refusal goes from 247 to 197 programs, and compute programs emitted go from 2,425 to 2,445. It's a few lines; happy to send it as a pull request stacked on this one if that helps. AI-assisted.

**@⁠KevinPratap** on GitHub · 2026-11-24 22:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/302#issuecomment-7145987963) A note for when this lands: `victory translate` (apps/victory/src/translate.rs) builds programs with `ir::build`, without the spill rewrite that `translate_for` applies through `build_with`. So the offline report still counts these programs as `an address in an SGPR that is no root parameter`, although they translate in the title. Measured on a full shader pack, `--host-lanes 32-32`, with the same decision shared (a `NativeProgram::spills_roots()` used by both `emit` and `translate.rs`): that refusal goes from 247 to 197 programs, and compute programs emitted go from 2,425 to 2,445. It's a few lines; happy to send it as a pull request stacked on this one if that helps. AI-assisted.

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!302
No description provided.