shader: read a buffer descriptor with its stride cleared as the raw view (found on a game run) #157

Merged
Olima34 merged 3 commits from upstream-pr/157 into main 2026-11-26 22:39:26 +00:00
Olima34 commented 2026-11-26 22:03:27 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T22:03:27Z.


Found and verified on a real game run (Apple M5 Pro, 48 GB, --console series-s): the dominant form of "a descriptor changed after loading" (#131), and its lowering. Two commits, the diagnostic first.

1. shader: name the operation and constants of a descriptor dword masked after loading. For a dword masked by a SOP instruction, the refusal now names the operation and its constant operands: ... dword 1 masked or merged (s_and_b32 with 0xc000ffff), or (s_xor_b32 with computed values). The prefix is unchanged, so tallies still group them. The refusal type is &'static str everywhere, so the formatted texts are interned once each (resource::interned, a marked shortcut: a handful per title).

On the game run, it showed:

count form
7 dword 1 masked or merged (s_and_b32 with 0xc000ffff)
2 dword 0 masked or merged (s_xor_b32 with computed values)
1 dword 0 masked or merged (s_xor_b64 with computed values)
1 dword 2 masked or merged (s_xor_b64 with computed values)

0xc000ffff on buffer V# dword 1 keeps base_address[47:32] (bits 15:0) and the swizzle bits (31:30), and clears the stride (29:16): the title turns a structured view into a raw one.

2. shader: read a loaded buffer descriptor with its stride cleared as the raw view.

  • RDNA2 ISA §8.1.5: the address is base + sgpr_offset + inst_offset + vgpr_offset + index × stride, so with stride 0 the index adds nothing. Table 33: with stride 0, num_records counts bytes.
  • Tracer::stride_cleared matches a non-typed buffer access whose descriptor is 4 dwords of one load, except dword 1 = s_and_b32(loaded dword 1, c), where c only clears stride bits.
  • The descriptor then classifies as the loaded view, and the access site is marked unstrided. lower.rs drops its index, so it takes the existing raw path: the loaded view read at byte offsets.
  • Guess, marked in code and docs: the bounds stay the host view's size. That matches a V# with OOB_SELECT 3 (num_records in bytes); OOB_SELECT 0 with stride 0 would make every access out of range on the console.
  • Still refused: typed (format) accesses, masks that touch base-address or swizzle bits, and the xor forms.

Tests.

  • gfx_refusal_tests::a_descriptor_with_its_stride_cleared_reads_the_loaded_view_raw: 0xc000ffff translates with idxen and with offen, and so does 0xc03fffff. 0xc000fffe (a base bit) and a format load stay refused. It fails on main.
  • victory-gpu addr_tests::a_descriptor_with_its_stride_cleared_reads_the_view_raw_on_the_gpu, on Metal: a structured SRV with 16-byte elements and a raw UAV, read with idxen+offen through the cleared descriptor; each lane gets dword lane. It fails without the fix, and with the index kept it fails on values ([3, 38, 73, …]).
  • The two existing resource.rs tests are updated to the new texts. No other test or doc used them.

In game, same Mac, same setup, before and after: the s_and_b32 … 0xc000ffff refusals went from 7 to 1. The one left is in a guessed vertex+pixel pipeline (vertex a2217fcc62753463 pixel 7e3f953d03860288, code at 0x4e0c), most likely a typed load, which stays refused by design. The run still ends at the known image+0x55e56f8 crash.

victory-shader (261) and victory-gpu (224, arm64, Metal) tests, Windows clippy and cargo xtask policy pass.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5517755976 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/157). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T22:03:27Z. --- Found and verified on a real game run (Apple M5 Pro, 48 GB, `--console series-s`): the dominant form of "a descriptor changed after loading" (#131), and its lowering. Two commits, the diagnostic first. **1. `shader: name the operation and constants of a descriptor dword masked after loading`.** For a dword masked by a SOP instruction, the refusal now names the operation and its constant operands: `... dword 1 masked or merged (s_and_b32 with 0xc000ffff)`, or `(s_xor_b32 with computed values)`. The prefix is unchanged, so tallies still group them. The refusal type is `&'static str` everywhere, so the formatted texts are interned once each (`resource::interned`, a marked shortcut: a handful per title). On the game run, it showed: | count | form | |---|---| | 7 | `dword 1 masked or merged (s_and_b32 with 0xc000ffff)` | | 2 | `dword 0 masked or merged (s_xor_b32 with computed values)` | | 1 | `dword 0 masked or merged (s_xor_b64 with computed values)` | | 1 | `dword 2 masked or merged (s_xor_b64 with computed values)` | `0xc000ffff` on buffer V# dword 1 keeps base_address[47:32] (bits 15:0) and the swizzle bits (31:30), and **clears the stride** (29:16): the title turns a structured view into a raw one. **2. `shader: read a loaded buffer descriptor with its stride cleared as the raw view`.** - RDNA2 ISA §8.1.5: the address is `base + sgpr_offset + inst_offset + vgpr_offset + index × stride`, so with stride 0 the index adds nothing. Table 33: with stride 0, num_records counts bytes. - `Tracer::stride_cleared` matches a non-typed buffer access whose descriptor is 4 dwords of one load, except dword 1 = `s_and_b32(loaded dword 1, c)`, where `c` only clears stride bits. - The descriptor then classifies as the loaded view, and the access site is marked `unstrided`. `lower.rs` drops its index, so it takes the existing raw path: the loaded view read at byte offsets. - Guess, marked in code and docs: the bounds stay the host view's size. That matches a V# with OOB_SELECT 3 (num_records in bytes); OOB_SELECT 0 with stride 0 would make every access out of range on the console. - Still refused: typed (format) accesses, masks that touch base-address or swizzle bits, and the xor forms. **Tests.** - `gfx_refusal_tests::a_descriptor_with_its_stride_cleared_reads_the_loaded_view_raw`: `0xc000ffff` translates with idxen and with offen, and so does `0xc03fffff`. `0xc000fffe` (a base bit) and a format load stay refused. It fails on main. - victory-gpu `addr_tests::a_descriptor_with_its_stride_cleared_reads_the_view_raw_on_the_gpu`, on Metal: a structured SRV with 16-byte elements and a raw UAV, read with idxen+offen through the cleared descriptor; each lane gets dword `lane`. It fails without the fix, and with the index kept it fails on values (`[3, 38, 73, …]`). - The two existing `resource.rs` tests are updated to the new texts. No other test or doc used them. **In game, same Mac, same setup, before and after:** the `s_and_b32 … 0xc000ffff` refusals went from 7 to **1**. The one left is in a guessed vertex+pixel pipeline (`vertex a2217fcc62753463 pixel 7e3f953d03860288`, code at 0x4e0c), most likely a typed load, which stays refused by design. The run still ends at the known `image+0x55e56f8` crash. victory-shader (261) and victory-gpu (224, arm64, Metal) tests, Windows clippy and `cargo xtask policy` pass.
Olima34 commented 2026-11-26 22:08:32 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T22:08:32Z.


Pushed 597ad90e after a review pass: only a mask that clears the whole stride field (bits 29:16) lowers. A partial clear such as 0xc03fffff could leave a non-zero stride (16 survives it), and dropping the index would then read the wrong element. It is refused now, and the test pins it (it fails on the previous commit). The docs also note that the dropped index skips the console's OOB_SELECT 1 index check, under the same marked bounds guess. The in-game form 0xc000ffff is unaffected.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7204401634 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/157#issuecomment-7204401634). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T22:08:32Z. --- Pushed 597ad90e after a review pass: only a mask that clears the **whole** stride field (bits 29:16) lowers. A partial clear such as 0xc03fffff could leave a non-zero stride (16 survives it), and dropping the index would then read the wrong element. It is refused now, and the test pins it (it fails on the previous commit). The docs also note that the dropped index skips the console's OOB_SELECT 1 index check, under the same marked bounds guess. The in-game form 0xc000ffff is unaffected.
LakshanSivakumar commented 2026-11-26 22:39:23 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T22:39:23Z.

Review: APPROVED


Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6081189113 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/157#pullrequestreview-6081189113). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T22:39:23Z. **Review:** APPROVED --- Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
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
LakshanSivakumar/Native-Victory-macOS!157
No description provided.