shader: lower indexed tbuffer_load_format_* and indexed subword buffer ops #527

Open
github-bot wants to merge 1 commit from github-bot/gh-523 into main AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 00:17 UTC · original
Sheffy007:feat/indexed-tbuffer-and-subword-buffers → main · +505 −32 · 5 files · 1 commits · open

Summary

  • Indexed tbuffer_load_format_* / _d16_: Fold index * stride into off for Source::Built root views (including 40/48-bit root descriptors whose high half is masked with s_and_b32 0xFF/0xFFFF) and view_stride heap/table views, and lower structured-table indexed tbuffer_load_format_* through (12 | u, stride) handles in format_load (matching getDimensions on dword 2).
  • Cleared-stride tbuffer_load_format_* / made_raw: Accept tbuffer_load_format_* in Tracer::stride_cleared and record made_raw sites in Resources::unstrided so cleared-stride descriptors drop idxen per RDNA2 ISA 8.1.5 while keeping buffer_load_format_* refused.
  • Indexed structured byte/half loads & stores: Lower buffer_load_{ubyte,sbyte,ushort,sshort} and buffer_store_{byte,short} with idxen on dword-aligned StructuredBuffer / RWStructuredBuffer views via rawBufferLoad.f32 and paired atomicBinOp.i32 (And/Or) on (12 | u, stride) handles.
  • Tests & Docs: Added positive and negative translation tests in gfx_refusal_tests.rs, an end-to-end Metal GPU value test (addr_tests::indexed_tbuffer_format_and_subword_buffer_ops_run_on_the_gpu) covering structured/heap/root/cleared-stride tbuffer_load_format_*, indexed ubyte/sbyte/ushort/sshort loads, and concurrent multi-lane indexed byte/short stores, and updated docs/native-host.md.

Verification

  • cargo xtask policy
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo test -p victory-shader -p xtask
  • cargo test -p victory-gpu --lib addr_tests

cc @⁠Olima34

Closes #524
Refs #4, #258

**@⁠Sheffy007** on GitHub · 2026-11-28 00:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/523) `Sheffy007:feat/indexed-tbuffer-and-subword-buffers` → `main` · +505 −32 · 5 files · 1 commits · open ## Summary - **Indexed `tbuffer_load_format_*` / `_d16_`:** Fold `index * stride` into `off` for `Source::Built` root views (including 40/48-bit root descriptors whose high half is masked with `s_and_b32` `0xFF`/`0xFFFF`) and `view_stride` heap/table views, and lower structured-table indexed `tbuffer_load_format_*` through `(12 | u, stride)` handles in `format_load` (matching `getDimensions` on dword 2). - **Cleared-stride `tbuffer_load_format_*` / `made_raw`:** Accept `tbuffer_load_format_*` in `Tracer::stride_cleared` and record `made_raw` sites in `Resources::unstrided` so cleared-stride descriptors drop `idxen` per RDNA2 ISA 8.1.5 while keeping `buffer_load_format_*` refused. - **Indexed structured byte/half loads & stores:** Lower `buffer_load_{ubyte,sbyte,ushort,sshort}` and `buffer_store_{byte,short}` with `idxen` on dword-aligned `StructuredBuffer` / `RWStructuredBuffer` views via `rawBufferLoad.f32` and paired `atomicBinOp.i32` (`And`/`Or`) on `(12 | u, stride)` handles. - **Tests & Docs:** Added positive and negative translation tests in `gfx_refusal_tests.rs`, an end-to-end Metal GPU value test (`addr_tests::indexed_tbuffer_format_and_subword_buffer_ops_run_on_the_gpu`) covering structured/heap/root/cleared-stride `tbuffer_load_format_*`, indexed `ubyte`/`sbyte`/`ushort`/`sshort` loads, and concurrent multi-lane indexed `byte`/`short` stores, and updated `docs/native-host.md`. ## Verification - `cargo xtask policy` - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo test -p victory-shader -p xtask` - `cargo test -p victory-gpu --lib addr_tests` cc @⁠Olima34 Closes #524 Refs #4, #258
Fold index * stride into byte offsets for tbuffer_load_format_* (and _d16_)
on built root views and view-stride heap/table views, lower structured
indexed tbuffer_load_format_* via (12 | u, stride) handles in format_load
(matching getDimensions on dword 2), drop idxen when stride_cleared or
made_raw clears a descriptor's stride, recognize s_and_b32 0xFF/0xFFFF
truncation on 40/48-bit root descriptor high halves, and lower indexed
buffer_load_{ubyte,sbyte,ushort,sshort} and buffer_store_{byte,short} on
structured buffers via rawBufferLoad and paired atomicBinOp.

Closes #520
Refs #4, #258
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 00:17:54 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 01:17 UTC · original

Thanks @⁠Sheffy007! Here's an offline check of 53e92d9f, merged onto main 86cefd22 (it merges cleanly). No game run.

Checks on the merge:

  • cargo test -p victory-shader -p victory-gpu -p victory-hle -p victory -p xtask passes. That includes victory-gpu on arm64, so your Metal value test addr_tests::indexed_tbuffer_format_and_subword_buffer_ops_run_on_the_gpu ran on the GPU.
  • Windows clippy (x86_64-pc-windows-gnullvm, -D warnings) is clean, and cargo xtask policy passes.

Corpus sweep (examples/sweep + tools/corpus/compare.sh, main → main + #527, by output fingerprint):

set newly translated output changed regressions other reason now
A (4,921 shaders) 0 0 0 0
B (4,129 refused shaders) 0 0 0 0
World (21,600 shaders) 0 0 0 0

The sweeps are byte-identical on all three sets. None of our corpora holds a shader refused for the reasons this PR lifts ("a typed-format load by index", "a byte or half buffer load/store by index"), so we can't show a gain here. The cases it covers may come from parts of the game our dumps don't reach (boot, prologue and the first world area on Series S). If you have the hashes of the shaders that motivated #524, we'll look for them in a longer run.

This also settles a side effect we wanted to rule out. made_raw_at also pushes plain (non-format) loads through a built raw descriptor into unstrided, which would drop their idxen. It changed no output in 21,600 shaders.

One small question on the code: in the new indexed subword-load path (sub with Some(index)), the guard argument isn't used, while the non-indexed path passes it to raw_view. If a guarded (EXEC-skipped) load can reach that path, should it go through begin_guarded like the indexed store does?

Note: the maintainer listed this PR among those he's holding for now, so it's his call when it lands.

**@⁠Olima34** on GitHub · 2026-11-28 01:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/523#issuecomment-7231557958) Thanks @⁠Sheffy007! Here's an offline check of 53e92d9f, merged onto main `86cefd22` (it merges cleanly). No game run. **Checks on the merge:** - `cargo test -p victory-shader -p victory-gpu -p victory-hle -p victory -p xtask` passes. That includes victory-gpu on arm64, so your Metal value test `addr_tests::indexed_tbuffer_format_and_subword_buffer_ops_run_on_the_gpu` ran on the GPU. - Windows clippy (`x86_64-pc-windows-gnullvm`, `-D warnings`) is clean, and `cargo xtask policy` passes. **Corpus sweep** (`examples/sweep` + `tools/corpus/compare.sh`, main → main + #527, by output fingerprint): | set | newly translated | output changed | regressions | other reason now | |---|---|---|---|---| | A (4,921 shaders) | 0 | 0 | 0 | 0 | | B (4,129 refused shaders) | 0 | 0 | 0 | 0 | | World (21,600 shaders) | 0 | 0 | 0 | 0 | The sweeps are byte-identical on all three sets. None of our corpora holds a shader refused for the reasons this PR lifts ("a typed-format load by index", "a byte or half buffer load/store by index"), so we can't show a gain here. The cases it covers may come from parts of the game our dumps don't reach (boot, prologue and the first world area on Series S). If you have the hashes of the shaders that motivated #524, we'll look for them in a longer run. This also settles a side effect we wanted to rule out. `made_raw_at` also pushes plain (non-format) loads through a built raw descriptor into `unstrided`, which would drop their `idxen`. It changed no output in 21,600 shaders. **One small question on the code:** in the new indexed subword-load path (`sub` with `Some(index)`), the `guard` argument isn't used, while the non-indexed path passes it to `raw_view`. If a guarded (EXEC-skipped) load can reach that path, should it go through `begin_guarded` like the indexed store does? Note: the maintainer listed this PR among those he's holding for now, so it's his call when it lands.
github-bot force-pushed github-bot/gh-523 from 53e92d9f77 to 2937858791 2026-11-28 01:48:15 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/527/head:github-bot/gh-523'
git switch 'github-bot/gh-523'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-523'
git switch 'github-bot/gh-523'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-523'
git switch 'github-bot/gh-523'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-523'
git switch 'main'
git merge --squash 'github-bot/gh-523'
git switch 'main'
git merge --ff-only 'github-bot/gh-523'
git switch 'main'
git merge 'github-bot/gh-523'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.