Direct DXIL: enforce byte-buffer bounds across memory windows #1727

Open
Ariyo31 wants to merge 1 commit from upstream-pr/1737 into main
Ariyo31 commented 2026-11-24 20:03:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Ariyo31 on 2026-11-24T20:03:48Z.


Improve direct DXIL buffer bounds checking and reduce the cost of narrow buffer loads.

Part of #1269.

What is in it

  • Added offset and access-width overflow checks for buffer loads, stores and atomics.
  • Optimized byte and halfword loads.
  • Added GPU regression tests for root-bound and heap-bound buffers.
  • Updated the shader cache version.

Tested

  • GPU: NVIDIA RTX 5070 Ti Laptop GPU
  • Driver: 621.14
  • CPU: Intel Core Ultra 9 275HX
  • OS: Windows 11
  • Rust: 1.100.0
  • Build: Release

Both targeted regression cases failed before the patch and passed after it. All 251,904 synthetic output checks matched the CPU reference.

Benchmark Before After
Compilation time 1.44 ms 0.95 ms
Compiler memory 0.47 MiB 0.26 MiB
DXIL size 9,292 bytes 4,740 bytes
GPU dispatch 1.28 µs 1.23 µs

Test command: cargo test --release --workspace --no-fail-fast -- --nocapture --test-threads=1

  • HLSL: 858 passed, 0 failed, 42 ignored.
  • Direct DXIL: 857 passed, 1 existing upstream cache-test failure, 42 ignored.
  • Five explicit GPU test skips in each mode.

Regression run

Main: Pending.

PR: Pending.

Known limitations

The OOB_SELECT and SOFFSET concerns raised during review remain under investigation. This patch does not yet implement complete descriptor-correct bounds checking.

Not tested

  • Retail game regression runs.
  • AMD hardware.
  • Full test suite on the rebased branch.

AI use

OpenAI Codex (GPT-6.2-Astra and GPT-6.2-Sol) assisted with implementation, regression testing, benchmarking, upstream compatibility checks and PR preparation.

<!-- greyfinch-sync:ivall/xcl:issue:5479428992 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737). Originally posted by [Ariyo31](https://github.com/Ariyo31) on 2026-11-24T20:03:48Z. --- Improve direct DXIL buffer bounds checking and reduce the cost of narrow buffer loads. Part of #1269. **What is in it** - Added offset and access-width overflow checks for buffer loads, stores and atomics. - Optimized byte and halfword loads. - Added GPU regression tests for root-bound and heap-bound buffers. - Updated the shader cache version. **Tested** - GPU: NVIDIA RTX 5070 Ti Laptop GPU - Driver: 621.14 - CPU: Intel Core Ultra 9 275HX - OS: Windows 11 - Rust: 1.100.0 - Build: Release Both targeted regression cases failed before the patch and passed after it. All 251,904 synthetic output checks matched the CPU reference. | Benchmark | Before | After | |---|---:|---:| | Compilation time | 1.44 ms | 0.95 ms | | Compiler memory | 0.47 MiB | 0.26 MiB | | DXIL size | 9,292 bytes | 4,740 bytes | | GPU dispatch | 1.28 µs | 1.23 µs | Test command: `cargo test --release --workspace --no-fail-fast -- --nocapture --test-threads=1` - HLSL: 858 passed, 0 failed, 42 ignored. - Direct DXIL: 857 passed, 1 existing upstream cache-test failure, 42 ignored. - Five explicit GPU test skips in each mode. **Regression run** Main: Pending. PR: Pending. **Known limitations** The OOB_SELECT and SOFFSET concerns raised during review remain under investigation. This patch does not yet implement complete descriptor-correct bounds checking. **Not tested** - Retail game regression runs. - AMD hardware. - Full test suite on the rebased branch. **AI use** OpenAI Codex (GPT-6.2-Astra and GPT-6.2-Sol) assisted with implementation, regression testing, benchmarking, upstream compatibility checks and PR preparation.
ddaikodaiko commented 2026-11-24 21:09:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ddaikodaiko on 2026-11-24T20:11:51Z.


One thing to decide before this lands: buffer_bytes_in_range is applied inside the old stride == 0 choice, and that choice is not the rule the console descriptor gives:

let szero = self.cmpc(Pred::Eq, stride, 0);
let idx_ok = self.cmp(Pred::ULt, index, d2);
let in_range = |lw: &mut Lw, bytes: Value| -> Value {
    let ok = lw.buffer_bytes_in_range(voff, off, bytes, d2);
    lw.sel(szero, ok, idx_ok)
};

The HLSL path already reads OOB_SELECT from V# word 3 [29:28] (BT-002, merged): mode 0 is index < N && offset + bytes <= STRIDE, mode 1 index < N, mode 2 N != 0, mode 3 (raw) offset + soffset + bytes <= N. With stride == 0 as the selector, a descriptor in mode 0/1/2 is judged by a bound that is not its own, and in raw mode the check here still misses soffset: off is voff + OFFSET, so a carry from soffset (which is added into the address but not into this check) is invisible even on one window. Your 64-bit carry check catches the off/bytes overflow but not that one.

So either:

  • buffer_bytes_in_range takes soff and the OOB_SELECT value and picks the four checks, or
  • the PR stays a window-carry fix and says that the mode is still the old heuristic (the direct translator is behind the HLSL path on BT-002).

If it helps: an unverified fork branch has the BT-002 port for the direct translator (ddaikodaiko/xcl contrib/mubuf-oob 0643c46), and it rewrites this same closure, so the two will conflict when both exist; the measured rule and the 732 native cases behind it are in the BT-002 report on #1488.

AI use: written with OpenCode (DeepSeek V4.1 Flash); a person submitting any of this is responsible for running it.

<!-- greyfinch-sync:ivall/xcl:comment:7143176588 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7143176588). Originally posted by [ddaikodaiko](https://github.com/ddaikodaiko) on 2026-11-24T20:11:51Z. --- One thing to decide before this lands: `buffer_bytes_in_range` is applied inside the old `stride == 0` choice, and that choice is not the rule the console descriptor gives: ```rust let szero = self.cmpc(Pred::Eq, stride, 0); let idx_ok = self.cmp(Pred::ULt, index, d2); let in_range = |lw: &mut Lw, bytes: Value| -> Value { let ok = lw.buffer_bytes_in_range(voff, off, bytes, d2); lw.sel(szero, ok, idx_ok) }; ``` The HLSL path already reads `OOB_SELECT` from V# word 3 [29:28] (BT-002, merged): mode 0 is `index < N && offset + bytes <= STRIDE`, mode 1 `index < N`, mode 2 `N != 0`, mode 3 (raw) `offset + soffset + bytes <= N`. With `stride == 0` as the selector, a descriptor in mode 0/1/2 is judged by a bound that is not its own, and in raw mode the check here still misses `soffset`: `off` is `voff + OFFSET`, so a carry from `soffset` (which is added into the address but not into this check) is invisible even on one window. Your 64-bit carry check catches the `off`/`bytes` overflow but not that one. So either: - `buffer_bytes_in_range` takes `soff` and the `OOB_SELECT` value and picks the four checks, or - the PR stays a window-carry fix and says that the mode is still the old heuristic (the direct translator is behind the HLSL path on BT-002). If it helps: an unverified fork branch has the BT-002 port for the direct translator (`ddaikodaiko/xcl` `contrib/mubuf-oob` `0643c46`), and it rewrites this same closure, so the two will conflict when both exist; the measured rule and the 732 native cases behind it are in the BT-002 report on #1488. AI use: written with OpenCode (DeepSeek V4.1 Flash); a person submitting any of this is responsible for running it.
Ariyo31 commented 2026-11-24 21:09:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Ariyo31 on 2026-11-24T20:16:13Z.


Review the new comment from ddaikodaiko on xcl-dev/xcl PR #1737.

Investigate the OOB_SELECT and SOFFSET concerns against the merged BT-002 behavior in the HLSL backend and issue #1488.

Decide whether to:

  1. Implement complete descriptor-correct bounds checking in our direct DXIL branch, or
  2. Keep this PR narrowly scoped to window-carry safety and document the remaining limitation.

Inspect the suggested fork branch for context, but independently verify the logic. Avoid copying unverified implementation.

Add targeted tests for each OOB_SELECT mode, SOFFSET carry and 32-bit overflow. Preserve our existing regressions and benchmarks.

Report your recommended solution and test results before pushing further changes. Do not reply on GitHub or push without my permission.

<!-- greyfinch-sync:ivall/xcl:comment:7143280659 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7143280659). Originally posted by [Ariyo31](https://github.com/Ariyo31) on 2026-11-24T20:16:13Z. --- Review the new comment from ddaikodaiko on xcl-dev/xcl PR #1737. Investigate the OOB_SELECT and SOFFSET concerns against the merged BT-002 behavior in the HLSL backend and issue #1488. Decide whether to: 1. Implement complete descriptor-correct bounds checking in our direct DXIL branch, or 2. Keep this PR narrowly scoped to window-carry safety and document the remaining limitation. Inspect the suggested fork branch for context, but independently verify the logic. Avoid copying unverified implementation. Add targeted tests for each OOB_SELECT mode, SOFFSET carry and 32-bit overflow. Preserve our existing regressions and benchmarks. Report your recommended solution and test results before pushing further changes. Do not reply on GitHub or push without my permission.
Raghav314 commented 2026-11-24 21:09:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Raghav314 on 2026-11-24T20:48:20Z.


Retail-pack A/B of #1737 on NVIDIA Windows: −2 % DXIL, −9 % driver time on the direct form, no failures. Counts and timings only.

Setup: RTX 4090 24 GB, driver 617.14, Windows 11, DXC 1.8.2502.11, release. Two binaries that differ only by this PR: main 6c89285 (this PR's base) and this PR's head 0c6b681, each with the same timing harness (xcl shaders --time-forms, branch, described on #1745). Retail 1.0.2.1 pack: 40 compute programs spread over the size range plus the 10 largest, split wave64, 4 windows. #1426's per-instruction form translated, then made into a compute pipeline one at a time, with the driver's shader cache off for the process (ShaderCacheControl). Driver builds capped at 1 MB of DXIL, so the largest programs give sizes only. First row dropped as driver warm-up.

#1426 form main #1737
DXIL, 39 programs 81.2 MB 80.7 MB (median ratio 0.979)
translation 10.8 s 10.8 s
driver, 22 programs under the cap 25.5 s 23.2 s
translation or driver failures 0 0
  • Driver time per program: median ratio 0.912 (p10 0.85, p90 0.93), so the gain is consistent, not a few outliers.
  • Size: far less than the synthetic −49 % on these programs; the narrow loads are a small part of them.

Not tested: correctness of the output on the GPU (no title run, no output comparison), the bounds-check behaviour itself, AMD, the full suite.

AI use: Claude Code (Claude Opus 5.5) built both binaries, ran the measurements and drafted this.

<!-- greyfinch-sync:ivall/xcl:comment:7144079470 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7144079470). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-11-24T20:48:20Z. --- **Retail-pack A/B of #1737 on NVIDIA Windows: −2 % DXIL, −9 % driver time on the direct form, no failures.** Counts and timings only. **Setup:** RTX 4090 24 GB, driver 617.14, Windows 11, DXC 1.8.2502.11, release. Two binaries that differ only by this PR: `main` `6c89285` (this PR's base) and this PR's head `0c6b681`, each with the same timing harness (`xcl shaders --time-forms`, [branch](https://github.com/Raghav314/xcl/tree/shaders/time-forms), described on #1745). Retail 1.0.2.1 pack: 40 compute programs spread over the size range plus the 10 largest, split wave64, 4 windows. #1426's per-instruction form translated, then made into a compute pipeline one at a time, with the driver's shader cache off for the process (`ShaderCacheControl`). Driver builds capped at 1 MB of DXIL, so the largest programs give sizes only. First row dropped as driver warm-up. | #1426 form | `main` | #1737 | |---|---|---| | DXIL, 39 programs | 81.2 MB | 80.7 MB (median ratio 0.979) | | translation | 10.8 s | 10.8 s | | driver, 22 programs under the cap | 25.5 s | 23.2 s | | translation or driver failures | 0 | 0 | - **Driver time** per program: median ratio 0.912 (p10 0.85, p90 0.93), so the gain is consistent, not a few outliers. - **Size:** far less than the synthetic −49 % on these programs; the narrow loads are a small part of them. **Not tested:** correctness of the output on the GPU (no title run, no output comparison), the bounds-check behaviour itself, AMD, the full suite. AI use: Claude Code (Claude Opus 5.5) built both binaries, ran the measurements and drafted this.
Ariyo31 commented 2026-11-24 21:09:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Ariyo31 on 2026-11-24T20:52:39Z.


Thank you for taking the time to benchmark my PR on real retail shaders! It's great to see a consistent 9% reduction in driver compilation time.

I'm still looking into the bounds-checking concerns raised earlier. I really appreciate the independent testing and feedback.

<!-- greyfinch-sync:ivall/xcl:comment:7144175765 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7144175765). Originally posted by [Ariyo31](https://github.com/Ariyo31) on 2026-11-24T20:52:39Z. --- Thank you for taking the time to benchmark my PR on real retail shaders! It's great to see a consistent 9% reduction in driver compilation time. I'm still looking into the bounds-checking concerns raised earlier. I really appreciate the independent testing and feedback.
alexmircea1299 commented 2026-11-24 21:29:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by alexmircea1299 on 2026-11-24T21:11:42Z.


Working fine on 5070.

  • PR / Commit: #1737 (0c6b681)
  • Hardware: AMD Ryzen 5 9600X, NVIDIA GeForce RTX 5070 (12 GB), 32 GB DDR5
  • Environment: Windows 11, rustc 1.100.0, debug build
  • Command: .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4)
  • Results: 814 passed; 0 failed; 22 ignored (14.07s)
  • Total workspace: 822 passed; 0 failed; 34 ignored
<!-- greyfinch-sync:ivall/xcl:comment:7144604282 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7144604282). Originally posted by [alexmircea1299](https://github.com/alexmircea1299) on 2026-11-24T21:11:42Z. --- Working fine on 5070. * **PR / Commit:** #1737 (`0c6b681`) * **Hardware:** AMD Ryzen 5 9600X, NVIDIA GeForce RTX 5070 (12 GB), 32 GB DDR5 * **Environment:** Windows 11, `rustc 1.100.0`, debug build * **Command:** `.\scripts\test.ps1` (`cargo test --workspace -- --test-threads=4`) * **Results:** `814 passed; 0 failed; 22 ignored` (14.07s) * **Total workspace:** `822 passed; 0 failed; 34 ignored`
DavidM1911 commented 2026-11-24 23:08:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T22:43:55Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7146578441 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7146578441). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T22:43:55Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Toons29 commented 2026-11-25 04:10:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:35:57Z.


Regression run of 0c6b681a on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 0c6b681a130842800a61e927a64498b141abce30
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14815 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7152064213 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7152064213). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:35:57Z. --- Regression run of `0c6b681a` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: 0c6b681a130842800a61e927a64498b141abce30 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1631 (PresentX 1631) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14815 MB ``` Against the limits in CONTRIBUTING.md: 101 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
Foniass commented 2026-12-01 06:37:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:37:56Z.


Triage (#1607) – head 0c6b681

The core of this PR is on main in other code. cb7fe9b (#1893) rejects voff + OFFSET and off + bytes 32-bit wraparound in Lw::mubuf and buffer_atomic, so a large voff can no longer pass the d2 check while buffer_window carries into the next window. 0b64aa0 hoists uma_base into the entry block (uma_base_val) and replaces the sub-dword loads with ld_raw_u32_guarded, which reads the next word for a crossing halfword.
The branch conflicts with those rewrites. What remains, the window/window_hi constant-zero shortcuts and the multi-window atomic test, would need a new PR against current main.
Recommendation: close (superseded by main commits cb7fe9b and 0b64aa0).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303093983 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1737#issuecomment-7303093983). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:37:56Z. --- **Triage (#1607)** – head 0c6b681 The core of this PR is on main in other code. cb7fe9b (#1893) rejects `voff + OFFSET` and `off + bytes` 32-bit wraparound in `Lw::mubuf` and `buffer_atomic`, so a large `voff` can no longer pass the `d2` check while `buffer_window` carries into the next window. 0b64aa0 hoists `uma_base` into the entry block (`uma_base_val`) and replaces the sub-dword loads with `ld_raw_u32_guarded`, which reads the next word for a crossing halfword. The branch conflicts with those rewrites. What remains, the `window`/`window_hi` constant-zero shortcuts and the multi-window atomic test, would need a new PR against current main. Recommendation: close (superseded by main commits cb7fe9b and 0b64aa0). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1737:upstream-pr/1737'
git switch 'upstream-pr/1737'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1737'
git switch 'upstream-pr/1737'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1737'
git switch 'upstream-pr/1737'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1737'
git switch 'main'
git merge --squash 'upstream-pr/1737'
git switch 'main'
git merge --ff-only 'upstream-pr/1737'
git switch 'main'
git merge 'upstream-pr/1737'
git push origin 'main'
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
xcl-dev/xcl!1727
No description provided.