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

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

@⁠fuzeofficlal on GitHub · 2026-11-25 06:27 UTC · original
fuzeofficlal:feat/shader-built-computed-address-descriptors → main · +781 −23 · 2 files · 1 commits · closed without merging

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 06:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2156) `fuzeofficlal:feat/shader-built-computed-address-descriptors` → `main` · +781 −23 · 2 files · 1 commits · closed without merging ### 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.
Resource tracking already classifies 4-dword buffer descriptors assembled around root-constant pointer pairs or computed 64-bit addresses as Source::Built over MEMORY, while Lower::handle still refused them with "a buffer descriptor built around a computed address" (and indexed MUBUF fell through to "a structured buffer of unknown stride").

Include built MEMORY descriptors in Lower::new's root_memory scan, extract the 48-bit base address from dwords 0-1 of the instruction's descriptor SGPRs, fold structured element strides and honor RDNA2 OOB_SELECT / NUM_RECORDS bounds (addressing the null viewpair without marking false title-memory misses or writes when out of range), and lower s_buffer_load_dword*, raw and structured buffer_load_*/buffer_store_*, sub-dword accesses, buffer_atomic_*, and format loads through Lower::memory.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:34 +00:00
github-bot closed this pull request 2026-11-26 04:56:34 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 07:19 UTC · original

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.

**@⁠upipibi** on GitHub · 2026-11-25 07:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7155734460) 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.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 08:11 UTC · original

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7156722881) ### 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 11:26 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 11:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7161045113) <!-- 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)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 12:05 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 12:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2156#issuecomment-7161899071) 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

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