Shaders: lower buffer descriptors built around computed and root-constant addresses #2154

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/2156 into main
fuzeofficlal commented 2026-11-25 06:27:04 +00:00 (Migrated from github.com)

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


Problem

resource::track (Tracer::classify) already classifies 4-dword V# buffer descriptors assembled in shader code around root-constant 64-bit pointer pairs or computed addresses as Source::Built { address: Address { param: MEMORY, .. }, bits, words }, whereas Lower::handle (crates/victory-shader/src/emit/lower.rs) still rejects them with Err("a buffer descriptor built around a computed address") (and indexed MUBUF operations fall through to Err("a structured buffer of unknown stride")).

Changes

  • Include Source::Built over MEMORY (including uniform Phi / Select joins with matching (bits, words)) in Lower::new's root_memory scan.
  • Extract the 48-bit base address from dwords 0..=1 of the descriptor SGPR operand (s[code] and s[code + 1] & 0xFFFF), fold structured element strides on idxen, and enforce GFX10 OOB_SELECT (0..=3) and NUM_RECORDS limits via raw_view_bounded — routing out-of-range lanes to the null viewpair (0 reads, dropped writes) without setting false unmapped-page misses or dirty bits in memory_dirty.
  • Lower s_buffer_load_dword*, raw/structured buffer_load_* and buffer_store_*, sub-dword byte/short loads and stores (preserving sub-dword base alignment), buffer_atomic_*, and tbuffer_load_format_* / buffer_load_format_* (refusing swizzled or ADD_TID_ENABLE descriptors).

Verification

  • emit::memory_tests::buffer_descriptors_built_around_root_constant_addresses_read_and_write_title_memory and built_computed_address_descriptors_with_swizzling_or_tid_are_refused validated with dxil.dll and executed across RTX 5090, AMD Radeon Graphics, and D3D12 WARP.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6598626530 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2156). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T06:27:04Z. --- ### Problem `resource::track` (`Tracer::classify`) already classifies 4-dword `V#` buffer descriptors assembled in shader code around root-constant 64-bit pointer pairs or computed addresses as `Source::Built { address: Address { param: MEMORY, .. }, bits, words }`, whereas `Lower::handle` (`crates/victory-shader/src/emit/lower.rs`) still rejects them with `Err("a buffer descriptor built around a computed address")` (and indexed MUBUF operations fall through to `Err("a structured buffer of unknown stride")`). ### Changes - Include `Source::Built` over `MEMORY` (including uniform `Phi` / `Select` joins with matching `(bits, words)`) in `Lower::new`'s `root_memory` scan. - Extract the 48-bit base address from dwords `0..=1` of the descriptor SGPR operand (`s[code]` and `s[code + 1] & 0xFFFF`), fold structured element strides on `idxen`, and enforce GFX10 `OOB_SELECT` (`0..=3`) and `NUM_RECORDS` limits via `raw_view_bounded` — routing out-of-range lanes to the null viewpair (`0` reads, dropped writes) without setting false unmapped-page misses or dirty bits in `memory_dirty`. - Lower `s_buffer_load_dword*`, raw/structured `buffer_load_*` and `buffer_store_*`, sub-dword byte/short loads and stores (preserving sub-dword base alignment), `buffer_atomic_*`, and `tbuffer_load_format_*` / `buffer_load_format_*` (refusing swizzled or `ADD_TID_ENABLE` descriptors). ### Verification - `emit::memory_tests::buffer_descriptors_built_around_root_constant_addresses_read_and_write_title_memory` and `built_computed_address_descriptors_with_swizzling_or_tid_are_refused` validated with `dxil.dll` and executed across RTX 5090, AMD Radeon Graphics, and D3D12 WARP.
DenRakEiw commented 2026-11-25 07:02:57 +00:00 (Migrated from github.com)

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

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib emit::memory_tests:: — 5 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean lowering of buffer descriptors built around computed and root-constant addresses, verified end-to-end on hardware and WARP. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053037505 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2156#pullrequestreview-6053037505). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T06:46:00Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib emit::memory_tests::` — **5 passed, 0 failed** on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean lowering of buffer descriptors built around computed and root-constant addresses, verified end-to-end on hardware and WARP. Looks great. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 07:02:57 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

144 passed / 0 failed / 2 ignored. Buffer descriptors built around computed and root... — descriptor-building coverage for computed/root bases.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053076133 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2156#pullrequestreview-6053076133). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T06:49:57Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. Buffer descriptors built around computed and root... — descriptor-building coverage for computed/root bases.
upipibi commented 2026-11-25 08:06:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T07:19:29Z.


One question on the raw case (OOB_SELECT 3, or 0 with stride 0). built_bounds checks the whole access, off <= NUM_RECORDS - access_bytes, so a buffer_load_dwordx2/x4 or s_buffer_load_dwordx* that straddles NUM_RECORDS reads 0 in every dword. XCL checks each dword separately and pins it in a GPU test: gpu_grouped_loads_bounds_and_inactive_lanes (crates/xcl/src/gpu/recomp/tests.rs). There, an s_buffer_load_dwordx2 across NUM_RECORDS gives (in-range dword, 0), and a buffer_load_dwordx2 (offen) keeps the dwords with off + 4 <= NUM_RECORDS. If that is the RDNA2 behaviour, a straddling load here loses its in-range dwords, and a straddling store drops them.

I haven't found a hardware measurement of this case in XCL or AnyPS5, only XCL's test. If you have an RDNA2 reading for a straddling raw load, it would settle which one is right. The OOB_SELECT 0/1/2 branches match the rules I know.

AI-assisted (Claude Code); source read only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155734460 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7155734460). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T07:19:29Z. --- One question on the raw case (`OOB_SELECT` 3, or 0 with stride 0). `built_bounds` checks the whole access, `off <= NUM_RECORDS - access_bytes`, so a `buffer_load_dwordx2/x4` or `s_buffer_load_dwordx*` that straddles NUM_RECORDS reads 0 in every dword. XCL checks each dword separately and pins it in a GPU test: `gpu_grouped_loads_bounds_and_inactive_lanes` (`crates/xcl/src/gpu/recomp/tests.rs`). There, an `s_buffer_load_dwordx2` across NUM_RECORDS gives `(in-range dword, 0)`, and a `buffer_load_dwordx2` (offen) keeps the dwords with `off + 4 <= NUM_RECORDS`. If that is the RDNA2 behaviour, a straddling load here loses its in-range dwords, and a straddling store drops them. I haven't found a hardware measurement of this case in XCL or AnyPS5, only XCL's test. If you have an RDNA2 reading for a straddling raw load, it would settle which one is right. The `OOB_SELECT` 0/1/2 branches match the rules I know. AI-assisted (Claude Code); source read only.
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:11:31Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 1bb33665 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:7156722881 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7156722881). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T08:11:31Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 1bb33665 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:14Z.


Automated triage for the maintainers.

Needs work. In crates/victory-shader/src/emit/lower.rs, Lower::handle's refusal "a buffer descriptor built around a computed address" is replaced by lowering through the title-memory page table. The new built_memory_desc and built_memory_base read the base from the descriptor SGPRs, and raw_view_bounded applies NUM_RECORDS/OOB_SELECT bounds for SMEM, raw/structured MUBUF, sub-dword, atomic and format accesses. The tests run on hardware and WARP, and the plumbing reads coherently. CI: passing (check).

What it needs:

  • A title case. @sinan-cmyk's offline run over the title's shader pack found 23,918 validated programs on main and 23,918 with this PR, and no program changed its failure reason. So nothing in the title currently reaches this refusal, or it stops earlier for another reason. Please show a program that this PR makes translate, or the refusal from a run. Without one, this is about 300 lines of new emulation logic for a case the title does not show.
  • Evidence for the bounds rules. The OOB_SELECT handling is emulation behaviour and cites no source. One concrete open point, raised by @upipibi and still unanswered: for raw descriptors (OOB_SELECT 3, or 0 with stride 0), the MUBUF paths gate the whole access with off <= NUM_RECORDS - access_bytes. A buffer_load_dwordx2/x4 that straddles NUM_RECORDS therefore reads 0 in every dword, and a straddling store drops all of them. Your own s_buffer_load path checks each dword separately, which also matches the reference he cites. Please make the two consistent and cite the RDNA2 ISA or a hardware reading for the rule you choose. The same applies to OOB_SELECT 0 with a stride, where only off < stride is checked, not off + bytes <= stride.

Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161045113 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7161045113). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T11:26:14Z. --- <!-- victory-triage v1 head=1bb3366540e67534cd684066adf7691ffeed7401 verdict=needs-work at=2026-11-25T11:26:14Z --> Automated triage for the maintainers. **Needs work.** In `crates/victory-shader/src/emit/lower.rs`, `Lower::handle`'s refusal "a buffer descriptor built around a computed address" is replaced by lowering through the title-memory page table. The new `built_memory_desc` and `built_memory_base` read the base from the descriptor SGPRs, and `raw_view_bounded` applies `NUM_RECORDS`/`OOB_SELECT` bounds for SMEM, raw/structured MUBUF, sub-dword, atomic and format accesses. The tests run on hardware and WARP, and the plumbing reads coherently. CI: passing (`check`). What it needs: - **A title case.** @sinan-cmyk's offline run over the title's shader pack found 23,918 validated programs on `main` and 23,918 with this PR, and no program changed its failure reason. So nothing in the title currently reaches this refusal, or it stops earlier for another reason. Please show a program that this PR makes translate, or the refusal from a run. Without one, this is about 300 lines of new emulation logic for a case the title does not show. - **Evidence for the bounds rules.** The `OOB_SELECT` handling is emulation behaviour and cites no source. One concrete open point, raised by @upipibi and still unanswered: for raw descriptors (`OOB_SELECT` 3, or 0 with stride 0), the MUBUF paths gate the whole access with `off <= NUM_RECORDS - access_bytes`. A `buffer_load_dwordx2/x4` that straddles `NUM_RECORDS` therefore reads 0 in every dword, and a straddling store drops all of them. Your own `s_buffer_load` path checks each dword separately, which also matches the reference he cites. Please make the two consistent and cite the RDNA2 ISA or a hardware reading for the rule you choose. The same applies to `OOB_SELECT` 0 with a stride, where only `off < stride` is checked, not `off + bytes <= stride`. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 13:01:55 +00:00
fuzeofficlal commented 2026-11-25 13:02:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T12:05:09Z.


Thanks for the triage review and @sinan-cmyk / @upipibi for the offline check and per-dword OOB_SELECT note.

Re-checking #614 and the world-run failure breakdowns (#815, #1481) confirms that the root-constant pointer shaders in #614 use global_load / global_store / s_load_dword* directly on the 64-bit address (already served via MEMORY on main), rather than constructing 4-dword V# buffer descriptors around computed addresses — so no title program currently reaches "a buffer descriptor built around a computed address".

Closing this PR to avoid adding ~300 lines of unexercised emulation logic; if a future shader reaches this refusal, we can revisit with per-dword OOB_SELECT bounds.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161899071 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7161899071). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T12:05:09Z. --- Thanks for the triage review and @sinan-cmyk / @upipibi for the offline check and per-dword `OOB_SELECT` note. Re-checking #614 and the world-run failure breakdowns (#815, #1481) confirms that the root-constant pointer shaders in #614 use `global_load` / `global_store` / `s_load_dword*` directly on the 64-bit address (already served via `MEMORY` on `main`), rather than constructing 4-dword `V#` buffer descriptors around computed addresses — so no title program currently reaches `"a buffer descriptor built around a computed address"`. Closing this PR to avoid adding ~300 lines of unexercised emulation logic; if a future shader reaches this refusal, we can revisit with per-dword `OOB_SELECT` bounds.

Pull request closed

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