Skip to content

Shaders: trace a geometry program's signature memory - #3222

Open
kotekompotek wants to merge 1 commit into
Marvisak:mainfrom
kotekompotek:shader/geometry-signature-memory
Open

kotekompotek wants to merge 1 commit into
Marvisak:mainfrom
kotekompotek:shader/geometry-signature-memory

Conversation

@kotekompotek

Copy link
Copy Markdown

Grand Theft Auto VI's GS_VoxelizeGeneric programs (all 195 of them - the single biggest refusal bucket in victory translate --list shaders.rpf) keep the pointer to their root signature memory in user data 0-1 - their first user SGPRs, s[8:9] - and load through it like a compute program does through s[0:1]:

s_mov_b32 s0, s8                ; pointer low
s_and_b32 s1, s9, 0xff          ; high masked to 40 bits
s_load_dword s0, s[0:1], 0xb8   ; the load at 0x44

spill_loads was gated on HwStage::Cs, so the base address wasn't recognized as USER_DATA memory and the program was refused with "an address in an SGPR that is no root parameter".

Now spill_loads and param_word's spilled path admit HwStage::Gs, reading the pointer from stage.user_sgpr(0..1) instead of hardcoding s[0:1]. A geometry program's signature memory is there whenever user data 0-1 holds no parameter (it doesn't need the >16-dwords overflow condition compute has).

Verified on six real GS_VoxelizeGeneric programs extracted from shaders.rpf (v1.0.2.1) - all six now trace to USER_DATA addresses instead of failing. Regression test synthesizes the prologue + load.

Grand Theft Auto VI's GS_VoxelizeGeneric programs (all 195 of them)
keep the pointer to their root signature memory in user data 0-1 —
their first user SGPRs (s[8:9]) — and load through it like a compute
program's s[0:1]. spill_loads only ran for compute, so the very first
s_load at 0x44 failed with "an SGPR that is no root parameter" and
every one of them was refused.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@Venom2054

Copy link
Copy Markdown

I repeated the resource-tracking test on all 195 distinct GS_VoxelizeGeneric geometry shader containers in my local index, using the same inputs on the parent 63bcca43 and PR head 879f2126.

  • On the parent, resource::track refused all 195 at instruction 0x44 because it could not identify the address in the scalar register pair.
  • On the PR head, resource::track succeeded for all 195. In each case it identified one load from USER_DATA at that instruction.
  • At the full emit::translate entry point, both revisions still refused all 195 at stage selection, before producing DXIL. A separate compute control emitted 2,160 bytes of DXIL and passed the Windows SDK validator on both revisions.

This confirms the signature-memory fix across the whole family. It leaves geometry-stage translation and in-game rendering as separate checks. Codex assisted with the offline comparison.

@Dukestar69 Dukestar69 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 against origin/main (63bcca4):

  • cargo test -p victory-shader --lib resource::tests:: -- --test-threads=1: 36/36 passed (including a_geometry_programs_signature_memory_loads_through_its_pointer).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly traces a geometry program's signature memory loads through its pointer.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@kotekompotek

Copy link
Copy Markdown
Author

Full-pack verification, victory translate --list on the shipped shaders.rpf (v1.0.2.1, 26 503 containers, 26 084 programs):

main this change
resources tracked 25 889 / 26 084 26 084 / 26 084
SGPR-no-root-parameter refusals 195 (all GS_VoxelizeGeneric) 0

The 195 programs do not just track now — they emit: mesh programs stay 8 765 / 8 765 emitted. Every remaining refusal in the pack is a different, already-accounted bucket (13 lane-mask join — FIND-6; 5 v_cvt_f32_f64 — #1262; 4 lane mask read as data — FIND-6; 1 descriptor read only as data — #329; 1 barycentrics; 1 v_permlanex16_b32).

@futurepro62

Copy link
Copy Markdown

NVIDIA full-suite run, to go with the reports above by Dukestar69, since none of them names a GPU run. Tested exact head 879f212 (on its base 63bcca4).

Tested

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@fuzeofficlal fuzeofficlal 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.

Thanks for extending signature memory tracking to HwStage::Gs! One regression against main came up in param_word:

  • GS register-backed root descriptors at user_data >= 16 lose their high half (crates/victory-shader/src/resource.rs:488, 546, 641, 941-943):
    Line 546 now routes all user_data >= 16 lookups on HwStage::Cs | HwStage::Gs exclusively to self.first_spilled. However, spill_loads() explicitly skips spill scanning whenever self.layout.iter().any(|p| p.user_data < 2 && p.sgprs > 0) (line 488), leaving self.first_spilled empty. Because merged GS stages have up to 32 user SGPRs (s[8 + user_data]), if a GS layout occupies user_data < 2 and also passes a RootType::Descriptor in entry SGPRs at user_data >= 16, param_of (line 641) matches the incoming SGPR, but param_word(param, 1) now returns None instead of reading the incoming high SGPR (as main did), causing line 943 to fail with "a root descriptor without its high half".

Gating line 546 on whether signature memory is active for GS (e.g. if self.stage == HwStage::Cs || !self.layout.iter().any(|p| p.user_data < 2 && p.sgprs > 0), or falling back to entry SGPRs when self.first_spilled is empty on HwStage::Gs) preserves register-backed GS descriptors cleanly.

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.

5 participants