DirectStorage: validate request sizes before allocation #1785

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

@⁠yaxis1 on GitHub · 2026-11-24 20:37 UTC · original
yaxis1:fix/dstorage-request-allocation → main · +81 −18 · 3 files · 1 commits · open

Summary

  • Validate DirectStorage request sizes before allocation.
  • Use fallible allocations for source, zlib, and BCPack buffers.
  • Propagate allocation failures as E_OUTOFMEMORY.
  • Validate file bounds before reading.

Tested

  • git diff --check passed.

Not tested

  • Targeted Cargo tests were blocked by Windows Application Control
    (error 4551).
  • GPU validation and real-title regression testing were not run.
  • The proposed 256 MiB request ceiling needs compatibility review.

AI use

AI assistance was used to implement and review these changes.

**@⁠yaxis1** on GitHub · 2026-11-24 20:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/1785) `yaxis1:fix/dstorage-request-allocation` → `main` · +81 −18 · 3 files · 1 commits · open ## Summary - Validate DirectStorage request sizes before allocation. - Use fallible allocations for source, zlib, and BCPack buffers. - Propagate allocation failures as `E_OUTOFMEMORY`. - Validate file bounds before reading. ## Tested - `git diff --check` passed. ## Not tested - Targeted Cargo tests were blocked by Windows Application Control (error 4551). - GPU validation and real-title regression testing were not run. - The proposed 256 MiB request ceiling needs compatibility review. ## AI use AI assistance was used to implement and review these changes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:09 +00:00
Author
Owner

@⁠frenziedcoder on GitHub · 2026-11-24 20:55 UTC · original

NVIDIA test report for 73a6454: the description has no test run (Application Control), so here is one. Full suite green, the PR's own test passing, and a clean smoke pair (1654 vs 1654 frames).

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head 73a645459971606375a9f8191771253039a49aa7, no local changes.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug): 864 passed, 0 failed, 42 ignored; all 18 hle::dstorage::tests pass. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The 256 MiB ceiling against this title: across my earlier runs of it, XCL logged a sample of 479 DirectStorage requests (its first ones and every power-of-two request number, world load included). The largest destination and source in them was 922,384 B, about 300 times below the cap. This is a sample, not every request.

Regression run (scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen; XCL_PSO_PRELOAD=0 for both builds, because this machine's preload list holds the program of #1307)

base (4178e88, this PR's base; the same base run as in my report on #1747):

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: NVIDIA GeForce RTX 5080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14604 MB

this PR:

xcl-smoke v1
commit: 73a645459971606375a9f8191771253039a49aa7
gpu: NVIDIA GeForce RTX 5080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14600 MB

Not tested: the world load (where this title's DirectStorage traffic is: thousands of requests per 2 s with BCPack) on this head, so the change is not exercised on retail requests beyond the start screen; AMD; Wine.

AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.

**@⁠frenziedcoder** on GitHub · 2026-11-24 20:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1785#issuecomment-7144244220) **NVIDIA test report for `73a6454`: the description has no test run (Application Control), so here is one. Full suite green, the PR's own test passing, and a clean smoke pair (1654 vs 1654 frames).** **Tested** - NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 `stable-x86_64-pc-windows-msvc`, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head `73a645459971606375a9f8191771253039a49aa7`, no local changes. - `cargo build --workspace && cargo test --workspace -- --test-threads=4` (debug): **864 passed, 0 failed, 42 ignored**; all 18 `hle::dstorage::tests` pass. SKIPPED: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - The 256 MiB ceiling against this title: across my earlier runs of it, XCL logged a sample of 479 DirectStorage requests (its first ones and every power-of-two request number, world load included). The largest destination and source in them was **922,384 B**, about 300 times below the cap. This is a sample, not every request. **Regression run** (`scripts/smoke.ps1 -Seconds 60`, release, the retail title of #505 at its start screen; `XCL_PSO_PRELOAD=0` for both builds, because this machine's preload list holds the program of #1307) base (`4178e88`, this PR's base; the same base run as in my report on #1747): ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: NVIDIA GeForce RTX 5080 title: RetailTitle seconds: 60 exit: 0x0 frames shown: 1654 (PresentX 1654) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14604 MB ``` this PR: ``` xcl-smoke v1 commit: 73a645459971606375a9f8191771253039a49aa7 gpu: NVIDIA GeForce RTX 5080 title: RetailTitle seconds: 60 exit: 0x0 frames shown: 1654 (PresentX 1654) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14600 MB ``` **Not tested:** the world load (where this title's DirectStorage traffic is: thousands of requests per 2 s with BCPack) on this head, so the change is not exercised on retail requests beyond the start screen; AMD; Wine. *AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.*
Author
Owner

@⁠LocranKing on GitHub · 2026-11-24 22:24 UTC · original

Independent Windows 11 + 8 GB Ampere (RTX 3060 Ti) --release verification of exact head 73a645459971606375a9f8191771253039a49aa7 (merge-base 6c89285): full suite green (including the new DirectStorage allocation test) and clean 60 s retail smoke.

Tested

  • Hardware / toolchain: Windows 11 Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, Ampere, wave32 only), driver 32.0.16.2101 (621.01), rustc 1.100.0 (0ef1bc386 2026-11-09) (x86_64-pc-windows-msvc), DXC 1.9.2602.17 (21d28f72), --release.
  • cargo build --release -p xcl: exit 0.
  • Full workspace suite (cargo test --workspace --release --no-fail-fast -- --test-threads=4 --nocapture): 864 passed, 0 failed, 42 ignored. All hle::dstorage::tests and hle::bcpack::tests pass, including the new hle::dstorage::tests::zeroed_buffer_rejects_impossible_allocation. Expected host SKIPPED lines: 2 wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), 2 D3D12 debug layer (test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state), 1 heap windows (heap_window_out_of_memory_falls_back_to_the_switch_form).

Regression run (scripts/smoke.ps1 -Seconds 60, --release)

Reference main (4178e88; exact merge-base 6c89285 was not smoked separately):

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1559 (PresentX 1559)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15961 MB

PR #1785 (73a6454):

xcl-smoke v1
commit: 73a645459971606375a9f8191771253039a49aa7
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1597 (PresentX 1597)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15224 MB

Not tested: exact merge-base 6c89285 smoke, AMD/Intel GPUs, D3D12 debug layer, or extended world streaming past 60 s.

AI use: Antigravity (Gemini 4 Neon) built and ran the --release test suite and 60 s smoke locally and drafted this report from the captured outputs.

**@⁠LocranKing** on GitHub · 2026-11-24 22:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/1785#issuecomment-7146187192) Independent Windows 11 + 8 GB Ampere (RTX 3060 Ti) `--release` verification of exact head `73a645459971606375a9f8191771253039a49aa7` (merge-base `6c89285`): **full suite green (including the new DirectStorage allocation test) and clean 60 s retail smoke**. **Tested** - **Hardware / toolchain:** Windows 11 Build `26200`, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, Ampere, wave32 only), driver `32.0.16.2101` (`621.01`), `rustc 1.100.0 (0ef1bc386 2026-11-09)` (`x86_64-pc-windows-msvc`), DXC `1.9.2602.17 (21d28f72)`, `--release`. - **`cargo build --release -p xcl`:** exit `0`. - **Full workspace suite (`cargo test --workspace --release --no-fail-fast -- --test-threads=4 --nocapture`):** **864 passed, 0 failed, 42 ignored**. All `hle::dstorage::tests` and `hle::bcpack::tests` pass, including the new `hle::dstorage::tests::zeroed_buffer_rejects_impossible_allocation`. Expected host `SKIPPED` lines: `2` wave64 (`gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`), `2` D3D12 debug layer (`test_title_draws_with_a_root_signature_under_the_debug_layer`, `uploads_start_from_each_subresources_state`), `1` heap windows (`heap_window_out_of_memory_falls_back_to_the_switch_form`). **Regression run (`scripts/smoke.ps1 -Seconds 60`, `--release`)** Reference `main` (`4178e88`; exact merge-base `6c89285` was not smoked separately): ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: NVIDIA GeForce RTX 3060 Ti title: retail-1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1559 (PresentX 1559) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15961 MB ``` PR `#1785` (`73a6454`): ``` xcl-smoke v1 commit: 73a645459971606375a9f8191771253039a49aa7 gpu: NVIDIA GeForce RTX 3060 Ti title: retail-1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1597 (PresentX 1597) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15224 MB ``` **Not tested:** exact merge-base `6c89285` smoke, AMD/Intel GPUs, D3D12 debug layer, or extended world streaming past 60 s. **AI use:** Antigravity (`Gemini 4 Neon`) built and ran the `--release` test suite and 60 s smoke locally and drafted this report from the captured outputs.
Author
Owner

@⁠throny on GitHub · 2026-11-25 00:27 UTC · original

Two contributors checked independently and found that #1381 #1438 solves the same problem (for #1392) in a different way: #1607, group D54. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-25 00:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1785#issuecomment-7148522033) <!-- xcl-1607-hint:D54 --> Two contributors checked independently and found that #1381 #1438 solves the same problem (for #1392) in a different way: #1607, group D54. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 03:21 UTC · original

PR #1785 - DirectStorage request-size validation

Tested commit 73a645459971606375a9f8191771253039a49aa7 (clean detached checkout).

Environment STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave range 8-32, DoublePrecisionFloatShaderOps=0). DXC/DXIL 1.9.2609.5, rustc 1.100.0 (0ef1bc386 2026-11-09). Used unoptimized dev/test profiles with debug info disabled and selected the A770. The D3D12 SDK debug layer was unavailable.

Tested

  • cargo build --workspace and cargo test --workspace --no-run both succeeded outside the GPU lock.
  • cargo test -p xcl hle::dstorage::tests -- --nocapture reported 18 passed, 0 failed, 0 ignored, with zero explicit skips. The new test verifies that an impossible buffer reservation returns E_OUTOFMEMORY. Existing tests passed for zlib output sizing, BC1 queue decoding, and error recording on a request past EOF. The PR caps source, destination and intermediate sizes at 256 MiB each and checks the file range before allocating.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the shared Arc lock. The 20 target summaries total 846 passed, 18 failed, 42 ignored (exit 101). All 18 DirectStorage tests passed again. The pass total includes 3 explicit SKIPPED lines (two no wave64, one no heap windows). Those paths provide no coverage.

Failures The library had 13 compute pipeline creation failures (0x80070057, including FP64 cases) and four output mismatches (FMA overflow control, pixel sampling with implicit LOD, f16 high-half preservation, and wave64 pixel reductions). The end-to-end test title failed its RSSetDepthBiasX dynamic depth-bias check (blue pixel, expected green).

Not tested A main baseline or retail-title smoke comparison, other GPU adapters, retail sample inputs (XCL_SAMPLE_* unset), request sizes at and above the 256 MiB boundary, and real memory pressure.

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1785-suite.log and published this report.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 03:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/1785#issuecomment-7151837006) # PR #1785 - DirectStorage request-size validation **Tested commit** `73a645459971606375a9f8191771253039a49aa7` (clean detached checkout). **Environment** STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave range 8-32, DoublePrecisionFloatShaderOps=0). DXC/DXIL 1.9.2609.5, rustc 1.100.0 (0ef1bc386 2026-11-09). Used unoptimized dev/test profiles with debug info disabled and selected the A770. The D3D12 SDK debug layer was unavailable. **Tested** - `cargo build --workspace` and `cargo test --workspace --no-run` both succeeded outside the GPU lock. - `cargo test -p xcl hle::dstorage::tests -- --nocapture` reported **18 passed, 0 failed, 0 ignored**, with zero explicit skips. The new test verifies that an impossible buffer reservation returns E_OUTOFMEMORY. Existing tests passed for zlib output sizing, BC1 queue decoding, and error recording on a request past EOF. The PR caps source, destination and intermediate sizes at 256 MiB each and checks the file range before allocating. - `cargo test --workspace --no-fail-fast -- --test-threads=4` ran once under the shared Arc lock. The 20 target summaries total **846 passed, 18 failed, 42 ignored** (exit 101). All 18 DirectStorage tests passed again. The pass total includes **3 explicit SKIPPED lines** (two no wave64, one no heap windows). Those paths provide no coverage. **Failures** The library had 13 compute pipeline creation failures (0x80070057, including FP64 cases) and four output mismatches (FMA overflow control, pixel sampling with implicit LOD, f16 high-half preservation, and wave64 pixel reductions). The end-to-end test title failed its RSSetDepthBiasX dynamic depth-bias check (blue pixel, expected green). **Not tested** A main baseline or retail-title smoke comparison, other GPU adapters, retail sample inputs (XCL_SAMPLE_* unset), request sizes at and above the 256 MiB boundary, and real memory pressure. T3 Code / Codex (`gpt-6.2-sol`, `reasoningEffort: high`) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, `gemini-4-neon`) verified counts against `pr1785-suite.log` and published this report.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 10:48 UTC · original · reviewed

On 73a645459971606375a9f8191771253039a49aa7, the zlib-only path still has an infallible allocation after the new fallible buffers: zeroed_buffer(stage1_len)? allocates the intermediate size, then d.truncate(written) retains only that capacity, and d.resize(n, 0) can grow it to destination_size without returning E_OUTOFMEMORY. Request::check permits source_size < intermediate_size <= destination_size up to 256 MiB, so a small valid zlib stream with a 1 KiB intermediate size and a 256 MiB destination reaches this growth. If that reserve fails, Vec::resize cannot propagate the request error that this PR aims to provide. Could the padding path call try_reserve_exact(n - d.len()).map_err(|_| E_OUTOFMEMORY)? before resize, with a focused failure-path check? I verified the path from source and the size constraints; I did not induce a real OOM.

AI use: OpenAI Codex (GPT-6.2 Sol) found and checked the path; OpenAI Codex (GPT-6.2 Astra) independently verified it and wrote this review.

**@⁠luckyteagirl** on GitHub · 2026-11-26 10:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/1785#pullrequestreview-6072763528) · **reviewed** On `73a645459971606375a9f8191771253039a49aa7`, the zlib-only path still has an infallible allocation after the new fallible buffers: `zeroed_buffer(stage1_len)?` allocates the intermediate size, then `d.truncate(written)` retains only that capacity, and `d.resize(n, 0)` can grow it to `destination_size` without returning `E_OUTOFMEMORY`. `Request::check` permits `source_size < intermediate_size <= destination_size` up to 256 MiB, so a small valid zlib stream with a 1 KiB intermediate size and a 256 MiB destination reaches this growth. If that reserve fails, `Vec::resize` cannot propagate the request error that this PR aims to provide. Could the padding path call `try_reserve_exact(n - d.len()).map_err(|_| E_OUTOFMEMORY)?` before `resize`, with a focused failure-path check? I verified the path from source and the size constraints; I did not induce a real OOM. AI use: OpenAI Codex (GPT-6.2 Sol) found and checked the path; OpenAI Codex (GPT-6.2 Astra) independently verified it and wrote this review.
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/1785/head:github-bot/gh-1785'
git switch 'github-bot/gh-1785'

Merge

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