Skip to content

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

Draft
Ariyo31 wants to merge 1 commit into
xcl-dev:mainfrom
Ariyo31:fix/direct-dxil-buffer-bounds
Draft

Ariyo31 wants to merge 1 commit into
xcl-dev:mainfrom
Ariyo31:fix/direct-dxil-buffer-bounds

Conversation

@Ariyo31

@Ariyo31 Ariyo31 commented Nov 24, 2026 •

Copy link
Copy Markdown

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.

Reject offset and access-width overflow in multi-window buffer operations. Reduce narrow loads and cover root and heap bindings in GPU regressions.

AI assistance: OpenAI Codex helped implement, test, and benchmark the change. Codex (GPT-6.2-sol) prepared the branch.
@ddaikodaiko

Copy link
Copy Markdown

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.

@Ariyo31

Ariyo31 commented Nov 24, 2026

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown

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.

@Ariyo31

Ariyo31 commented Nov 24, 2026

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown

Working fine on 5070.

  • PR / Commit: Direct DXIL: enforce byte-buffer bounds across memory windows #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

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

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

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants