Skip to content

Shaders, GPU: read through addresses passed in two root constants (stacked on #489) - #710

Closed
itsRevela wants to merge 5 commits into
Marvisak:mainfrom
itsRevela:shaders/root-constant-addresses
Closed

itsRevela wants to merge 5 commits into
Marvisak:mainfrom
itsRevela:shaders/root-constant-addresses

Conversation

@itsRevela

Copy link
Copy Markdown
Contributor

Depends on: #302 and #489 (this branch is on top of #489, which carries #302). The measured programs also need #294 and #709 to translate all the way.

What

Reads through a 64-bit address that the title passes as two root constants (low half, high half). This is the an address from a root parameter that is no address case from #614.

  • victory-shader, resource.rs
    • The tracker recognises the constant pair from its high half. It handles a pair at any dword, a pair across two parameters, and a pair with an added offset carried into the high half.
    • Nothing that's accepted today is diverted, and a constant used as an index is never taken for a pair.
  • victory-shader, emit
    • A global_load_*, an s_load_dword*, or an s_buffer_load_* on a descriptor built around the pair reads a raw root SRV, t<n> in a new ROOT_ADDRESS_SPACE. The list is HostShader::address_srvs.
    • Writes and typed views through such an address stop with specific reasons.
  • victory-gpu
    • One SRV root parameter per view. At every draw and dispatch, bind composes the address from the two constants' current values and binds it with root_view.
    • If the address is unset or below 0x10000, the draw is dropped: counted, noted and warned once. That's today's outcome for these programs.
    • The shader cache encodes the new list.

Why

In the opening cutscene, 8 compute programs stop at an address from a root parameter that is no address once #302 rewrites their spill-table loads. On main they stop earlier. None writes through the address: 7 first use it in a global_load, the others in s_load_dword.

I measured with the title, cutscene, in local builds:

build those 8 programs
#302 #489 all 8 stop at no address
+ this 0 stop at no address; 3 at root UAVs, 2 at typed root views, 2 at an address from a phi, 1 at another non-root address
+ this + #294 + #709 3 of the 8 translate (the scalar-load ones), with their pipelines accepted by the host; the rest stop at an address from a phi (2), another non-root address (1) and an LDS operation (1)

The GPU bound the views without errors in those runs.

Tested

Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088), Rust 1.98.1.

  • New tests (13, synthetic code words only):
    • pair layouts and negative cases in resource.rs;
    • the read routes and the stop reasons in lower.rs;
    • two GPU tests, a global_load and an s_load_dword through a pair, in valu_tests.rs, each checking the dword read on the hardware GPU and on WARP;
    • pair_address tests in draw.rs.
  • The fix matters. With pair detection disabled, the pair tests fail.
  • Crate checks:
    • cargo test -p victory-shader: 81 passed.
    • -p victory-gpu: 46 passed, 1 ignored; with diagnostics, 48 passed, 1 ignored.
    • cargo test --workspace: 278 passed (on the first commit).
    • cargo clippy -p victory-shader -p victory-gpu --tests: nothing in the changed files.
    • cargo fmt --check: victory-shader clean; victory-gpu 79, the same as main.
    • cargo xtask policy: ok.

Overlap with #294: this touches the same files (draw.rs, pipeline/host.rs, shader_cache.rs, the emit structs). I merged the two locally for the measurements above. The conflicts are parallel additions, except shader_cache decode, which must read the lists in the order encode writes them. Whichever lands second rebases.

Known limits:

  • A root view has no size, so only the 1 MiB from the address is refreshed.
  • An offset below the start of the address can't be reached.
  • There's no fallback address yet; an unset address drops the draw.

AI-assisted (Claude Code). The design was reviewed before implementation, and the title runs used my own copy; no game data is in this PR.

🤖 Generated with Claude Code

dadou000 and others added 5 commits November 24, 2026 03:10
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 <noreply@anthropic.com>
The spill-table rewrite turned each load into `s_mov_b32 sK, s(16+k)`,
which reads what the register holds at that point. A program that has
already written SGPRs 16 and up (the destination of an earlier table
load, say) then reads the wrong root argument, with no refusal.

The program now first copies the user SGPRs its table loads stand for
into a block of SGPRs it never reads or writes, and the loads read that
block. Without such a block below VCC, or when a branch can return to
the program's entry, nothing is rewritten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title can pass a 64-bit buffer address as two root-constant dwords, low
half first in consecutive user SGPRs (within one parameter or across two).
Resource tracking only knew addresses from tables, heaps, root descriptors
and the code, so programs reading through such an address failed with "an
address from a root parameter that is no address" (or, for a pair past
dword 0, "an address in an SGPR that is no root parameter"). Once the
spill-table rewrite exposes their arguments, several compute programs stop
there.

The tracker now recognises a pair from its high half: a root constant
(possibly plus a carry) whose user SGPR below holds a root constant that
the low half's sum starts from. Nothing else has a root constant as its
high half, so no existing address is reclassified. Addresses get the
dword of their base and Resources lists the pairs.

Reads through a pair (global_load_*, s_buffer_load_* on a descriptor built
around it) become a raw root SRV t<n> in a new ROOT_ADDRESS_SPACE, listed
in HostShader::address_srvs with the two constants. Writes, typed views and
plain scalar loads through a pair stop with a specific reason.

The GPU layer declares one SRV root parameter per view, composes the
address from the constants' current values at every draw and dispatch
(pair_address) and binds it through root_view. An unset half or an
address below 0x10000 drops the draw or dispatch with a warning. The
shader cache encodes the new list; the test host binds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s_load_dword* through an address the title passes as two root constants reads the root SRV bound at that address, as s_buffer_load_dword* on a descriptor built around one does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Windows 11 MSVC (Rust 1.98.1).

  • All 10 shader pair tests (\scalar_loads_through_a_root_constant_pair_read_its_root_srv, \global_loads_through_a_root_constant_pair_read_its_root_srv, root constant pair tracker tests) pass.
  • All \�ictory-gpu\ tests (\�ddresses_in_root_constants_are_composed_from_both_halves,
    ull_and_low_addresses_are_unset, \shader_cache\ encode/decode) pass.
  • Correctly lowers 64-bit addresses passed via root constant pairs into raw root SRVs (\ \ in \ROOT_ADDRESS_SPACE), dropping dispatches cleanly if the address is unset or below \MIN_ADDRESS\ (0x10000).
  • Fully compliant with asset policy (\cargo xtask policy\ clean: 151 files).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up: no longer merges cleanly with current main (7374bfb) — conflicts in victory-gpu/src/draw.rs, victory-shader/src/emit/lower.rs and valu_tests.rs. Needs a rebase.

For the record, the shader crate on the head passes on macOS 26 arm64 / rustc 1.98.1: cargo test -p victory-shader --locked → 66 passed / 0 failed (+2 ungated vs its base). The GPU-side behavior (two-root-constant buffer reads) still needs the Windows run.

.ok_or("a descriptor built around a table in the code")?;
if rp.root == RootType::Constants {
return match props.0 {
11 => self.address_srv(address),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a shader adds an offset to the address pair before a buffer load (such as pair + 0x100), the translation drops the offset

I would add the offset there too or refuse as non-zero offset

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the PR's tests only use an offset of zero so they miss this

}
for (n, &view) in t.address_srvs.iter().enumerate() {
stage.address_srvs.push((view, params.len() as u32));
params.push(D3D12_ROOT_PARAMETER1 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check D3D12's limit of 64.

Count the u32s you're pushing. Consider using descriptor tables as fallback but tables have extra cost in the form of heap space on every draw so more work for the CPU.

Make sure to log the fallback i.e "root signature over 64 DWORDs" in the code for debugging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the limit is never reached maybe a hard cap and error instead

@MartinIndra02

Copy link
Copy Markdown

Windows native D3D12 verification for a5a40bc (since @catminou4 noted the Windows GPU run was still needed):

  • Setup: Windows 11 Pro 26200, NVIDIA GeForce RTX 3080 (10 GB, driver 621.24), Ryzen 7 5800X3D, Rust 1.98.1 (x86_64-pc-windows-msvc).
  • cargo test -p victory-shader --lib -- --test-threads=1: 81 passed, 0 failed (including both root-constant-pair GPU tests).
  • cargo test -p victory-gpu --lib -- --test-threads=1: 46 passed, 0 failed, 1 ignored (including addresses_in_root_constants_are_composed_from_both_halves, an_address_with_a_missing_half_is_unset, and null_and_low_addresses_are_unset).

No game data used. AI-assisted; tests run on my machine.

@LAKSHYA-cmd-tech

Copy link
Copy Markdown

Verified and resolved cleanly against the latest dynamic slot reclaim and root signature fallbacks in LAKSHYA-cmd-tech@44aec54 (branch eature/root-constant-addresses).

@Zilumz1

Zilumz1 commented Nov 24, 2026

Copy link
Copy Markdown

Rebase check against current main (AI-assisted, no game files)

This branch no longer merges cleanly into main at 8e79c80: 8 conflicts in draw.rs, lower.rs and valu_tests.rs. I resolved them and have a version that applies cleanly. The resolutions were:

draw.rs: kept main's bind -> bool, added this PR's bound flag and note_drop.
lower.rs and valu_tests.rs: both sides added tests in the same spot, so I kept both.

Results:

cargo test -p victory-shader (Linux, Rust 1.100.0): 80 passed, 0 failed, 1 ignored. Plain main gives 70 passed.
victory-gpu and the Windows-only GPU tests don't build on Linux, so those are unchecked there.
On my machine (Windows 10, RX 580)

@Zilumz1

Zilumz1 commented Nov 24, 2026

Copy link
Copy Markdown

Test Results – victory-shader

I ran the following command locally:

cargo test -p victory-shader 2>&1 | Tee-Object with-patch.log

Results:

  • Passed: 105
  • Failed: 15
  • Ignored: 1
  • Total: 121

Failure analysis:

Most of the failures appear to be related to the test environment rather than immediately indicating regressions in the shader implementation.

The 13 failures under emit::valu_tests consistently report:

no SM 6.6 hardware device; skipped
no SM 6.6 warp device; skipped

neither hardware nor WARP SM 6.6 device available

This suggests that the environment does not currently expose a compatible Direct3D 12 Shader Model 6.6 hardware device or WARP fallback.

There are also two failures in emit::waterfall_tests:

  • lanes_sample_the_entry_their_offset_names_in_the_console_waterfall
  • lanes_sample_their_own_texture_in_a_waterfall_narrowed_by_v_cmpx

Both fail because their expected execution results are empty:

assertion failed: !results.is_empty()

These may be consequences of the same missing graphics execution environment, but that needs to be verified.

Conclusion:

The remaining 105 tests pass successfully. I would not classify these 15 failures as confirmed implementation regressions without first reproducing them in an environment with working SM 6.6 support.

It would be useful to determine whether these tests should gracefully skip when neither hardware nor WARP is available, rather than report environment-dependent failures.

I haven't established whether the two waterfall failures are exclusively environment-related, so those still warrant investigation.

Full test output is available in with-patch.log.

@DaviTostes

DaviTostes commented Nov 24, 2026 •

Copy link
Copy Markdown

A/B tested a5a40bc on the full 1.0.2.1 dump (RX 9060 XT, RDNA4/RADV 26.3.1, Arch, Wine 11.22 + vkd3d-proton 3.2 + DXVK 3.1.1 dxgi, WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n"). Base main ffe310e.

Both sides are actual title runs with the game (menus → intro → loading → world), not synthetic shader tests.

Before (main): 81 unique untranslated shaders in the first ~2 minutes of the world. Top reason exactly the one this targets:

35x  an address in an SGPR that is no root parameter
 8x  a structured buffer of unknown stride
 6x  an address from a phi
 5x  a 64-bit image atomic

After (this branch): 82 unique untranslated shaders, but:

 0x  an address in an SGPR that is no root parameter
16x  a root UAV or typed root view
15x  an address not from a root parameter
 9x  an address from a phi
 8x  a structured buffer of unknown stride
 8x  a 64-bit image atomic

So the #1 reason from #293 is gone, and what remains matches your table's “+ this” row (root UAVs, typed root views, phi). The mesh pipeline still builds (host mesh pipeline shaders=[mesh d4111a6e…, pixel c0a7fe77…]) and the title reaches the world, but it is still the dark frozen background at 0.2–0.3 fps, so no visible change yet.

Later in the same run: RtlReleaseSRWLockExclusive … not owned exclusive! on several threads, then host GPU device removed … 0x887A0005 after a 7-list submission (the #774/#714 signature), ~3 minutes in.
Build details (per the report template): branch head a5a40bc on base main ffe310e, release build (cargo xwin build --release -p victory, MSVC); victory run prints build unknown (b99f876b…b5c35a79d5decd9f716504239e93), package 1.0.2.1. Same command as above.

Not tested: Windows, other GPUs, the #193/#539 stacks, and a full world session — the device was removed after ~3 minutes.

Next things worth stacking here: #193 (stride), #539/#305 (64-bit atomics), and whatever covers root UAVs/typed root views; I can A/B those on this dump if useful.

@erLCoder

Copy link
Copy Markdown

Independent root-constant address tests on GTX 1660 Ti, NVIDIA 581.42, Windows 10 22H2 build 19045.6466, Ryzen 5 3600, Rust 1.98.1 MSVC and Agility SDK 1.620.2. PR a5a40bc on #489 279eac1, which includes #302; #294 and #709 were not combined. Local SDK exports were added to the test executable and the fixture was restricted to the NVIDIA device, LUID 00000000:00017c52.

cargo test --offline --locked -p victory-shader --features host --lib through_a_root_constant_pair_read_its_root_srv -- --nocapture --test-threads=1 — 2 passed, 0 failed, 0 ignored, 79 filtered out. Both global and scalar load fixtures read the expected dword at byte offset 12. The fixture binds the buffer directly, so host address reconstruction during title dispatch remains untested, as do title shader recovery and composition.

Codex prepared the worktree, ran the tests and drafted this report.

Machad3x pushed a commit to Machad3x/VIctory that referenced this pull request Nov 24, 2026
…UAV raw view)

Targets the 'emit: a typed root view' group: 41 -> 40 failing containers
in the offline translate (the typed-root-view program now translates);
prerequisite for Marvisak#710.

Conflicts with the V_DYNAMIC stride path in lower.rs: kept V_DYNAMIC (no
stride check) inside the PR's new structured() helper. The new-tree
bounds check from Marvisak#650 only covered the in-element offset, so for a root
view the index*stride is now folded into the byte offset before the
check, and the PR's GPU test passes the view size in root constant 0 as
Marvisak#650 requires. resource::track gained a parameter in Marvisak#294; one test call
updated for it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@qntic

qntic commented Nov 24, 2026

Copy link
Copy Markdown

found a register space conflict while integrating this with main ffe310e. ROOT_ADDRESS_SPACE and STRIDE_SPACE both use register space 2.

moved ROOT_ADDRESS_SPACE to space 3 in my integration branch. clippy and workspace tests pass with the combined changes.

integration:
https://github.com/qntic/VIctory/tree/exp4/main-stack

giritsu pushed a commit to giritsu/VIctory that referenced this pull request Nov 24, 2026
…arvisak#710 part 1)

Recognize 64-bit buffer addresses passed in two root-constant dwords,
emit root SRVs in ROOT_ADDRESS_SPACE (3, distinct from STRIDE_SPACE 2),
and bind them via bounded root_srv_table when enabled (Marvisak#493).
giritsu pushed a commit to giritsu/VIctory that referenced this pull request Nov 24, 2026
cybx added a commit to cybx/VIctory that referenced this pull request Nov 24, 2026
Port of upstream PR Marvisak#710 (b1faa34, ac1bc81, a5a40bc). XboxBvhBuilder's
compute programs pass a 64-bit buffer address as two root-constant
dwords and read it with global, scalar and buffer loads; translation
stopped on them with "an address from a root parameter that is no
address".

The resource tracer pairs the two halves. The lowering binds the address
as a root SRV t<n> in ROOT_ADDRESS_SPACE; the GPU side composes it from
the constants' current values at every draw and dispatch, and drops one
whose address is unset or below 64 KiB. Writes and typed views through
such an address still stop the translation with a reason.

Unlike Marvisak#710, reads are bounded as Marvisak#650's root views are: the host
passes the bytes it maps from the address in a user-data dword past the
console dwords and the heap guard slots (AddressView::size), and reads
past it return 0. A root view has no bounds on the host, and a read past
the host copy is a page fault NVIDIA can hang the GPU on.

Census rv709 -> rv710: 21751 -> 21756 validated (compute 1428 -> 1433),
no program regressed; the 10 "no address" refusals are gone.
@fiestorra

Copy link
Copy Markdown
Contributor

Heads-up for anyone measuring this PR offline. On my own copy of the package (build b99f876b74d4a77f03af5f878223b27bd647b5c35a79d5decd9f716504239e93), whole-pack victory translate <shaders.rpf> --validate --list, clean worktrees and release builds:

  • at your head a5a40bc every count matches its merge base d2a4bae exactly: 21,971 programs validate, 185 are refused by the validator, 2,932 stop at emission, 594 stop during resource tracking;
  • no program moves to a different refusal and none newly validates;
  • the 195 programs stopped with an address in an SGPR that is no root parameter are 195 before and after, and all of them are GS_VoxelizeGeneric_* geometry programs — 0 of the 196 Gs programs validate in either build.

So this pack does not appear to contain whatever your commits change, and it contains 195 cases of the reason this row is usually described by, in a stage the row is not usually associated with. Table, method and the comparison against today's main in my comment here: #293 (comment)

Written with an AI assistant.

@luisaugustz

Copy link
Copy Markdown

In-game test on AMD (RX 9070 XT), #302 + #489 + #710: the runtime refusals of this class go from 34 programs to 1

Machine: RX 9070 XT (native 64-lane waves), Adrenalin 32.0.32029.2010, Ryzen 7 5800X, Windows 11 build 26300. Title 1.0.2.1, diag build, prologue world, VICTORY_SHADER_LOOP_LIMIT=256.

Tree: r4tedx integration/testers (92bc27b) + #638 for the drop accounting. Then this PR's diff, which carries #302 and #489, applied on top. It conflicted in 11 places with that tree (#493's bounded root SRV tables in draw.rs, and the waterfall proof in resource.rs). I resolved those by hand: bind() returns bound next to the root SRV tables, and resource tracking keeps both the waterfall proof and the root-constant pairs.

Runtime result (same scene, before and after; per-frame drops summed over the programs that do not translate, peak per program):

without with #302/#489/#710
programs that do not translate (world) 107 101
an address in an SGPR that is no root parameter 34 programs, ~7,390 dropped/frame 1 program, ~150/frame
total dropped/frame from untranslated programs ~9,140 ~4,890

As @Brazlucas measured on #489, most of the 34 now stop one step later:

Stability: several world runs with this stack, up to 25 minutes, with no device removal from it. The world is still black on this card, for other reasons (see #71).

Note: offline victory translate --validate shows no change for this class, as expected. The rewrite depends on the root layout the title binds at run time.

AI-assisted (Claude Code): measured in-game on this machine with a diag build. Counts and hashes only.

This was referenced Nov 24, 2026
mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…ithout the per-lane form

Marvisak#710 collected them at the end of track(); the fork returns early without
`lanes`, which left pairs empty ("an address in root constants without its
high half").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak

Copy link
Copy Markdown
Owner

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

Stacked on #489/#302. Addresses passed in two root constants are served in main by the raw-address page table (27c3dc9, Lower::memory), builder programs included.

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 Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.