shader: support verified byte-stride indexed raw SRV reads #48

Manually merged
github merged 2 commits from gh-pr/48/head into gh-pr/48/base 2026-11-26 06:27:37 +00:00
Owner

@⁠Valdi320 on GitHub · 2026-11-24 11:44 UTC · original
Valdi320:work/scarlett-verified-raw-index → main · +296 −16 · 6 files · 2 commits · merged 2026-11-24 20:14 UTC

The public ProjectScarlett log in #39 contains 43 refusals for raw IDXEN addressing. This change addresses the subset where native code proves a linear stride-one SRV descriptor (the existing direct root and mesh root SRV constructors). For direct roots, require the entire four-word construction within the same basic block and reject any intervening descriptor-word clobber. The existing mesh descriptor proof checks the exact native words. Unknown runtime strides and indexed raw writes/atomics remain rejected.

Use index plus optional second-VGPR byte offset and immediate/scalar offset. Keep one-dword loads (no Load2/3/4) and suppress reads on guest-inactive lanes for the new path.

Validation:

  • 67 compiler unit tests passed, including three new regressions for native encodings, CFG boundaries, clobbered/unknown descriptors and individual dword loads.
  • Actual translated synthetic IDXEN and IDXEN+OFFEN HLSL compiled with DXC, passed DXV, and ran on RTX 4080 with stock Proton. Separate raw SRV/UAV bindings, eight randomized aligned-address cases, 3,072 compared words (1,024 loaded results and 2,048 preserved words), zero mismatches.
  • Reproduction script and JSON receipt included.

No retail shaders were recompiled; the number of affected actual requests is not yet measured. AI-assisted contribution.

**@⁠Valdi320** on GitHub · 2026-11-24 11:44 UTC · [original](https://github.com/brcly/TuxBox/pull/48) `Valdi320:work/scarlett-verified-raw-index` → `main` · +296 −16 · 6 files · 2 commits · merged 2026-11-24 20:14 UTC The public ProjectScarlett log in #39 contains 43 refusals for raw IDXEN addressing. This change addresses the subset where native code proves a linear stride-one SRV descriptor (the existing direct root and mesh root SRV constructors). For direct roots, require the entire four-word construction within the same basic block and reject any intervening descriptor-word clobber. The existing mesh descriptor proof checks the exact native words. Unknown runtime strides and indexed raw writes/atomics remain rejected. Use index plus optional second-VGPR byte offset and immediate/scalar offset. Keep one-dword loads (no Load2/3/4) and suppress reads on guest-inactive lanes for the new path. Validation: - 67 compiler unit tests passed, including three new regressions for native encodings, CFG boundaries, clobbered/unknown descriptors and individual dword loads. - Actual translated synthetic IDXEN and IDXEN+OFFEN HLSL compiled with DXC, passed DXV, and ran on RTX 4080 with stock Proton. Separate raw SRV/UAV bindings, eight randomized aligned-address cases, 3,072 compared words (1,024 loaded results and 2,048 preserved words), zero mismatches. - Reproduction script and JSON receipt included. No retail shaders were recompiled; the number of affected actual requests is not yet measured. AI-assisted contribution.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:27:34 +00:00
github manually merged commit e7b3f2ae6b into gh-pr/48/base 2026-11-26 06:27:37 +00:00
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 11:47 UTC · original

AI-assisted: yes

Hardware/compiler validation on Linux (CachyOS x86_64, AMD Radeon RX 6900 XT / RADV Navi 21, Vulkan 1.4.333):

  1. tuxbox-xshader Rust unit tests (cargo test --target x86_64-unknown-linux-gnu --manifest-path tools/shader-compiler/Cargo.toml):

    • 67/67 passed cleanly (0 failed, 0 ignored).
    • Validated new tests:
      • hlsl::raw_width::byte_index_proof_rejects_unknown_stride_and_clobbers: pass
      • hlsl::raw_width::indexed_descriptor_proof_does_not_cross_a_basic_block: pass
      • hlsl::raw_width::proven_byte_index_emits_addresses_without_widening_loads: pass
  2. Integration & Smoke Tests (python3 -m unittest discover -s tests):

    • 125/125 tests passed.

Strict proof window checks (enforcing that direct roots prove 4-word construction within the same basic block without clobber, rejecting unknown runtime strides and raw writes/atomics, and emitting per-dword loads without widening) compile and test cleanly on Linux.

**@⁠trigger337** on GitHub · 2026-11-24 11:47 UTC · [original](https://github.com/brcly/TuxBox/pull/48#issuecomment-7130563234) AI-assisted: yes Hardware/compiler validation on Linux (CachyOS x86_64, AMD Radeon RX 6900 XT / RADV Navi 21, Vulkan 1.4.333): 1. **`tuxbox-xshader` Rust unit tests (`cargo test --target x86_64-unknown-linux-gnu --manifest-path tools/shader-compiler/Cargo.toml`)**: - **67/67 passed** cleanly (0 failed, 0 ignored). - Validated new tests: - `hlsl::raw_width::byte_index_proof_rejects_unknown_stride_and_clobbers`: pass - `hlsl::raw_width::indexed_descriptor_proof_does_not_cross_a_basic_block`: pass - `hlsl::raw_width::proven_byte_index_emits_addresses_without_widening_loads`: pass 2. **Integration & Smoke Tests (`python3 -m unittest discover -s tests`)**: - **125/125 tests passed**. Strict proof window checks (enforcing that direct roots prove 4-word construction within the same basic block without clobber, rejecting unknown runtime strides and raw writes/atomics, and emitting per-dword loads without widening) compile and test cleanly on Linux.
Author
Owner

@⁠brcly on GitHub · 2026-11-24 19:56 UTC · original

Please resolve any conflicts before I can merge

**@⁠brcly** on GitHub · 2026-11-24 19:56 UTC · [original](https://github.com/brcly/TuxBox/pull/48#issuecomment-7142817491) Please resolve any conflicts before I can merge
Author
Owner

@⁠JohnVonWells on GitHub · 2026-11-24 15:14 UTC · original · reviewed

Reviewed on Arch Linux + RX 6950 XT (RDNA2).

  • cargo test --features legacy-hlsl -p tuxbox-xshader -- raw_index byte_index indexed_descriptor proven_byte: 3/3 pass (incl. the three new raw_width cases).

The proof shape in raw_index::local_byte_descriptor is pleasantly tight:

  • Four consecutive s_mov/s_or with the exact format literal (0x11014fac) + size -1 + root low + (root+1 | 65536) for stride-1. Any deviation — missing dword, aliasing between base and root, a clobber of the base register between construction and the load, a different stride literal, or a basic-block boundary — refuses.
  • The tests cover each of those refusal paths explicitly (byte_index_proof_rejects_unknown_stride_and_clobbers, indexed_descriptor_proof_does_not_cross_a_basic_block). That's how I like proof predicates audited.

Also good:

  • raw_byte_index.remove(&ins.offset) at the start of the MUBUF case keeps the proof from surviving a second CFG visit — small detail that would bite later.
  • raw_byte_index.clear() in resolve_resources's recording pass matches the convention used by neighbouring sets (msel, bsel, …).
  • The exec_lo & 1u guard on IDXEN loads addresses the case where an inactive lane's VGPR holds garbage. Since unproven IDXEN now errors out earlier, in practice this only wraps the proven byte-stride path, which is the right place to be defensive.

Two small observations (not blockers):

  1. base + 3 is derived from base % 4 == 0 and base <= 100, so the address arithmetic can't overflow — the guards look belt-and-braces, which I'm fine with.
  2. The test's println!("BEGIN_HLSL…") comment calls out running under --nocapture. Neat trick for GPU validation without exposing a test-only API; worth keeping.

LGTM.

**@⁠JohnVonWells** on GitHub · 2026-11-24 15:14 UTC · [original](https://github.com/brcly/TuxBox/pull/48#pullrequestreview-6041947634) · **reviewed** Reviewed on Arch Linux + RX 6950 XT (RDNA2). - `cargo test --features legacy-hlsl -p tuxbox-xshader -- raw_index byte_index indexed_descriptor proven_byte`: 3/3 pass (incl. the three new `raw_width` cases). The proof shape in `raw_index::local_byte_descriptor` is pleasantly tight: - Four consecutive `s_mov`/`s_or` with the exact format literal (`0x11014fac`) + size `-1` + root low + `(root+1 | 65536)` for stride-1. Any deviation — missing dword, aliasing between base and root, a clobber of the base register between construction and the load, a different stride literal, or a basic-block boundary — refuses. - The tests cover each of those refusal paths explicitly (`byte_index_proof_rejects_unknown_stride_and_clobbers`, `indexed_descriptor_proof_does_not_cross_a_basic_block`). That's how I like proof predicates audited. Also good: - `raw_byte_index.remove(&ins.offset)` at the start of the MUBUF case keeps the proof from surviving a second CFG visit — small detail that would bite later. - `raw_byte_index.clear()` in `resolve_resources`'s recording pass matches the convention used by neighbouring sets (`msel`, `bsel`, …). - The `exec_lo & 1u` guard on IDXEN loads addresses the case where an inactive lane's VGPR holds garbage. Since unproven IDXEN now errors out earlier, in practice this only wraps the proven byte-stride path, which is the right place to be defensive. Two small observations (not blockers): 1. `base + 3` is derived from `base % 4 == 0` and `base <= 100`, so the address arithmetic can't overflow — the guards look belt-and-braces, which I'm fine with. 2. The test's `println!("BEGIN_HLSL…")` comment calls out running under `--nocapture`. Neat trick for GPU validation without exposing a test-only API; worth keeping. LGTM.
This discussion has been locked. Commenting is limited to contributors.
No description provided.