Shaders: treat RootType::Constants dword 0 as an offset in Tracer::sum #2152

Merged
fuzeofficlal merged 1 commit from upstream-pr/2154 into main 2026-11-25 21:54:52 +00:00
fuzeofficlal commented 2026-11-25 06:23:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T06:23:06Z.


Problem

Tracer::sum (crates/victory-shader/src/resource.rs:670) treats param_value(v) == Some((_, 0)) as an address base regardless of RootType. When a shader uses dword 0 of a RootType::Constants parameter (either in an entry SGPR or loaded from spilled USER_DATA) as a 32-bit byte offset — whereas dword 1, 2, ... work — two cases fail:

  • Passing it as an SMEM soffset or global_* vaddr offset fails with Err("an offset from a root parameter").
  • Adding it to a RootType::Table, ResourceHeap, or Descriptor base via s_add_u32 hits x.base.is_some() && y.base.is_some() and discards the table/descriptor base.

Changes

  • Exclude RootType::Constants from the Some((p, 0)) => Sum { base: Some(v), .. } arm in Tracer::sum (64-bit pointer pairs (dword 0, dword 1) in RootType::Constants continue to route to MEMORY via Tracer::address).
  • Add root_constant_zero_offsets_tables_and_root_descriptors and root_constant_zero_offsets_emit_to_dxil covering direct and spilled dword 0 offsets on descriptor tables and root descriptors alongside 64-bit MEMORY pointer pairs (dxil.dll validated).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6598568974 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2154). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T06:23:06Z. --- ### Problem `Tracer::sum` (`crates/victory-shader/src/resource.rs:670`) treats `param_value(v) == Some((_, 0))` as an address `base` regardless of `RootType`. When a shader uses `dword 0` of a `RootType::Constants` parameter (either in an entry SGPR or loaded from spilled `USER_DATA`) as a 32-bit byte offset — whereas `dword 1, 2, ...` work — two cases fail: - Passing it as an SMEM `soffset` or `global_*` `vaddr` offset fails with `Err("an offset from a root parameter")`. - Adding it to a `RootType::Table`, `ResourceHeap`, or `Descriptor` base via `s_add_u32` hits `x.base.is_some() && y.base.is_some()` and discards the table/descriptor base. ### Changes - Exclude `RootType::Constants` from the `Some((p, 0)) => Sum { base: Some(v), .. }` arm in `Tracer::sum` (64-bit pointer pairs `(dword 0, dword 1)` in `RootType::Constants` continue to route to `MEMORY` via `Tracer::address`). - Add `root_constant_zero_offsets_tables_and_root_descriptors` and `root_constant_zero_offsets_emit_to_dxil` covering direct and spilled `dword 0` offsets on descriptor tables and root descriptors alongside 64-bit `MEMORY` pointer pairs (`dxil.dll` validated).
DenRakEiw commented 2026-11-25 07:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:46:02Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib root_constant_zero_offsets — 2 passed, 0 failed (root_constant_zero_offsets_tables_and_root_descriptors and root_constant_zero_offsets_emit_to_dxil)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fix treating RootType::Constants dword 0 as an offset in Tracer::sum with targeted unit tests. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053037691 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2154#pullrequestreview-6053037691). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T06:46:02Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib root_constant_zero_offsets` — **2 passed, 0 failed** (`root_constant_zero_offsets_tables_and_root_descriptors` and `root_constant_zero_offsets_emit_to_dxil`) - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean fix treating `RootType::Constants` dword 0 as an offset in `Tracer::sum` with targeted unit tests. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 07:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:49:56Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

146 passed / 0 failed / 2 ignored. RootType::Constants dword 0 treated as offset in Translate (+2 tests) — root-constant offset semantics fix.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053076033 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2154#pullrequestreview-6053076033). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T06:49:56Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 146 passed / 0 failed / 2 ignored. RootType::Constants dword 0 treated as offset in Translate (+2 tests) — root-constant offset semantics fix.
Dathinel commented 2026-11-25 07:03:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T06:26:45Z.


I checked the shared-address case against #139, which changes the same tracer. To reproduce, take its shared_address_keeps_its_dynamic_term_and_wraps_offsets fixture and change the layout passed to track from &[TABLE] to:

&[TABLE, RootParam { root: RootType::Constants, user_data: 9, slot: 1, ..TABLE }]

This leaves the table at s8 and makes s9 the first dword of a constants parameter. On 940d32f, with or without #139, tracking succeeds but classifies both reads as MEMORY with zero offset and no dynamic term. On 3a314c8, both resolve to table parameter 0 and retain the SSA value for s9, with offsets 0xfffffff4 and 4 after wraparound. The clean merge with #139 (tree 7b00ee15) gives the same expected result.

This covers the tracker output for those two reads. Cache-hit rates and GPU execution were outside this test. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154797576 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2154#issuecomment-7154797576). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T06:26:45Z. --- I checked the shared-address case against #139, which changes the same tracer. To reproduce, take its `shared_address_keeps_its_dynamic_term_and_wraps_offsets` fixture and change the layout passed to `track` from `&[TABLE]` to: ```rust &[TABLE, RootParam { root: RootType::Constants, user_data: 9, slot: 1, ..TABLE }] ``` This leaves the table at s8 and makes s9 the first dword of a constants parameter. On `940d32f`, with or without #139, tracking **succeeds** but classifies both reads as `MEMORY` with zero offset and no dynamic term. On `3a314c8`, both resolve to table parameter 0 and retain the SSA value for s9, with offsets `0xfffffff4` and `4` after wraparound. The clean merge with #139 (tree `7b00ee15`) gives the same expected result. This covers the tracker output for those two reads. Cache-hit rates and GPU execution were outside this test. AI-assisted.
andrewpozdnakov7-jpg commented 2026-11-25 07:03:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T07:01:56Z.


I ran your mixed table and root-descriptor fixture through an actual WARP dispatch. On 940d32f69b it fails at translation with "an offset from a root parameter". On 3a314c8845 DXIL validates, then constant dword 0 selects the expected table entry and offsets the root SRV. At byte offsets 0 and 64 the two output buffers read [103, 0] and [0, 207], respectively.

d886064 is a test-only commit on that exact head. It reuses the existing synthetic program. Run the new readback explicitly with root_constant_zero_offsets_dispatch_to_the_selected_buffer --ignored. Strict shader Clippy and staged asset policy passed. The full forced-WARP suite on your head was 246 passed, 3 failed, 4 ignored, with the three failures also present in the main comparison.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155413225 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2154#issuecomment-7155413225). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T07:01:56Z. --- I ran your mixed table and root-descriptor fixture through an actual WARP dispatch. On 940d32f69b22265690a0b5a15d6ded572ba33baf it fails at translation with "an offset from a root parameter". On 3a314c8845aabc390a82ee486e7d0f78ce90f942 DXIL validates, then constant dword 0 selects the expected table entry and offsets the root SRV. At byte offsets 0 and 64 the two output buffers read [103, 0] and [0, 207], respectively. [d886064](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/d88606416b152b6fe52a3b7370e92a19ecce581d) is a test-only commit on that exact head. It reuses the existing synthetic program. Run the new readback explicitly with root_constant_zero_offsets_dispatch_to_the_selected_buffer --ignored. Strict shader Clippy and staged asset policy passed. The full forced-WARP suite on your head was 246 passed, 3 failed, 4 ignored, with the three failures also present in the main comparison.
sinan-cmyk commented 2026-11-25 09:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:13:37Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 3a314c88 onto main 940d32f (clean merge) 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: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156766322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2154#issuecomment-7156766322). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T08:13:37Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 3a314c88 onto `main` 940d32f (clean merge) 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: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 12:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T11:26:04Z.


Automated triage for the maintainers.

Merge candidate.

Tracer::sum (crates/victory-shader/src/resource.rs) took dword 0 of any root parameter as an address base, including RootType::Constants, while dwords 1 and up of the same parameter were treated as dynamic terms. So a 32-bit constant in dword 0 used as an SMEM soffset failed with "an offset from a root parameter". Added to a table or descriptor base, it tripped the x.base.is_some() && y.base.is_some() check, and the real base was lost. The one-line guard makes dword 0 of a constants parameter a dynamic term like the other dwords.

I checked that a constants (dword 0, dword 1) pair used as a 64-bit pointer still ends at MEMORY. With no base, traced_address returns why_no_base's "an address from a root parameter that is no address", which Tracer::address maps to MEMORY as before. The tests cover direct and spilled dword 0 on tables and root descriptors, plus that pointer case.

A WARP readback and the #139 fixture check posted in the thread agree. A whole-title offline count shows no validation change, so this is a correctness fix with no measured title effect yet. CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161041422 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2154#issuecomment-7161041422). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T11:26:04Z. --- <!-- victory-triage v1 head=3a314c8845aabc390a82ee486e7d0f78ce90f942 verdict=merge-candidate at=2026-11-25T11:26:04Z --> Automated triage for the maintainers. **Merge candidate.** `Tracer::sum` (`crates/victory-shader/src/resource.rs`) took dword 0 of any root parameter as an address base, including `RootType::Constants`, while dwords 1 and up of the same parameter were treated as dynamic terms. So a 32-bit constant in dword 0 used as an SMEM `soffset` failed with "an offset from a root parameter". Added to a table or descriptor base, it tripped the `x.base.is_some() && y.base.is_some()` check, and the real base was lost. The one-line guard makes dword 0 of a constants parameter a dynamic term like the other dwords. I checked that a constants (dword 0, dword 1) pair used as a 64-bit pointer still ends at `MEMORY`. With no base, `traced_address` returns `why_no_base`'s "an address from a root parameter that is no address", which `Tracer::address` maps to `MEMORY` as before. The tests cover direct and spilled dword 0 on tables and root descriptors, plus that pointer case. A WARP readback and the #139 fixture check posted in the thread agree. A whole-title offline count shows no validation change, so this is a correctness fix with no measured title effect yet. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 22:03:28 +00:00
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!2152
No description provided.