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

Merged
Valdi320 merged 2 commits from upstream-pr/48 into main 2026-11-24 20:14:13 +00:00
Valdi320 commented 2026-11-24 11:44:23 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Valdi320 on 2026-11-24T11:44:23Z.


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.

<!-- greyfinch-sync:brcly/TuxBox:issue:6581003349 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/48). Originally posted by [Valdi320](https://github.com/Valdi320) on 2026-11-24T11:44:23Z. --- 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.
trigger337 commented 2026-11-24 11:47:52 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by trigger337 on 2026-11-24T11:47:52Z.


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.

<!-- greyfinch-sync:brcly/TuxBox:comment:7130563234 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/48#issuecomment-7130563234). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T11:47:52Z. --- 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.
JohnVonWells commented 2026-11-24 15:14:40 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JohnVonWells on 2026-11-24T15:14:40Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:brcly/TuxBox:review:6041947634 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/48#pullrequestreview-6041947634). Originally posted by [JohnVonWells](https://github.com/JohnVonWells) on 2026-11-24T15:14:40Z. **Review:** COMMENTED --- 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.
brcly commented 2026-11-24 19:56:38 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-24T19:56:38Z.


Please resolve any conflicts before I can merge

<!-- greyfinch-sync:brcly/TuxBox:comment:7142817491 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/48#issuecomment-7142817491). Originally posted by [brcly](https://github.com/brcly) on 2026-11-24T19:56:38Z. --- Please resolve any conflicts before I can merge
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
brcly/TuxBox!48
No description provided.