DirectStorage: allow 0-byte memory-source requests instead of E_ACCESS_VIOLATION #1302

Open
b3IKK wants to merge 1 commit from upstream-pr/1312 into main
b3IKK commented 2026-11-24 14:36:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T14:36:42Z.


execute() called gpu::shader::readable(r.source, r.source_size) before checking !b.is_empty(). Because readable(ptr, 0) unconditionally returns false, valid 0-byte virtual-memory-source requests (which pass Request::check and writable(dst, 0), and succeed for file and physical-page sources) failed with E_ACCESS_VIOLATION.

This guards the readable() check and copy under else if !b.is_empty().

What is in it

  • crates/xcl/src/hle/dstorage.rs: skip readable() and copy_nonoverlapping when b.is_empty() on virtual-memory-source requests; add unit test zero_byte_memory_source_request_succeeds (verified failing with E_ACCESS_VIOLATION before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib zero_byte_memory_source_request_succeeds: 1 passed, 0 failed (failed with E_ACCESS_VIOLATION before the fix)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 23934893023b45ff20e4bd85a9ff71948f835c50
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1641 (PresentX 1641)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14601 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited dstorage.rs, wrote the fix and unit test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
<!-- greyfinch-sync:ivall/xcl:issue:5474228324 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1312). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T14:36:42Z. --- `execute()` called `gpu::shader::readable(r.source, r.source_size)` before checking `!b.is_empty()`. Because `readable(ptr, 0)` unconditionally returns `false`, valid 0-byte virtual-memory-source requests (which pass `Request::check` and `writable(dst, 0)`, and succeed for file and physical-page sources) failed with `E_ACCESS_VIOLATION`. This guards the `readable()` check and copy under `else if !b.is_empty()`. **What is in it** - `crates/xcl/src/hle/dstorage.rs`: skip `readable()` and `copy_nonoverlapping` when `b.is_empty()` on virtual-memory-source requests; add unit test `zero_byte_memory_source_request_succeeds` (verified failing with `E_ACCESS_VIOLATION` before the fix). **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`) - `cargo test -p xcl --lib zero_byte_memory_source_request_succeeds`: 1 passed, 0 failed (failed with `E_ACCESS_VIOLATION` before the fix) **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 23934893023b45ff20e4bd85a9ff71948f835c50 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1641 (PresentX 1641) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14601 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `dstorage.rs`, wrote the fix and unit test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
futurepro62 commented 2026-11-24 15:06:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T14:46:15Z.


Full-suite run, since this PR has no test report yet. Tested exact head 2393489 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: zero_byte_memory_source_request_succeeds.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7134918789 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1312#issuecomment-7134918789). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T14:46:15Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `2393489` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `zero_byte_memory_source_request_succeeds`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-24 16:07:10 +00:00 (Migrated from github.com)

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


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib -- --test-threads=1: all passed, 0 failed, ~21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7136373720 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1312#issuecomment-7136373720). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T15:38:43Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib -- --test-threads=1`: all passed, 0 failed, ~21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified `main`.) Thanks!
thehollowedone commented 2026-11-25 10:10:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-25T10:04:46Z.


Independent Windows run on 2393489. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC.

cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 752 passed, 0 failed, 41 ignored. The pass count includes two wave64 runtime skips.

The scratch fixture local_zero_byte_request_preserves_queue_status_and_following_copy passed 1 of 1 with cargo test --offline --locked -j 4 -p xcl --lib local_zero_byte_request_preserves_queue_status_and_following_copy -- --nocapture --test-threads=1. I submitted an empty request and a 16-byte copy on the same DirectStorage memory queue, with a status slot after each. Both returned S_OK, the error record counted zero failures, all 16 bytes of the empty request's destination stayed unchanged, and the following copy matched all 16 source bytes. With the original length check restored in the scratch copy, the first status returned E_ACCESS_VIOLATION and the error record counted one failure. The second status still returned S_OK. I restored the edit. Synthetic CPU queue coverage.

AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran the tests and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7159193385 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1312#issuecomment-7159193385). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-25T10:04:46Z. --- Independent Windows run on [2393489](https://github.com/xcl-dev/xcl/commit/23934893023b45ff20e4bd85a9ff71948f835c50). Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC. `cargo build --workspace --offline --locked -j 4` passed. `cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4` finished with **752 passed, 0 failed, 41 ignored**. The pass count includes two wave64 runtime skips. The scratch fixture `local_zero_byte_request_preserves_queue_status_and_following_copy` passed 1 of 1 with `cargo test --offline --locked -j 4 -p xcl --lib local_zero_byte_request_preserves_queue_status_and_following_copy -- --nocapture --test-threads=1`. I submitted an empty request and a 16-byte copy on the same DirectStorage memory queue, with a status slot after each. Both returned `S_OK`, the error record counted zero failures, all 16 bytes of the empty request's destination stayed unchanged, and the following copy matched all 16 source bytes. With the original length check restored in the scratch copy, the first status returned `E_ACCESS_VIOLATION` and the error record counted one failure. The second status still returned `S_OK`. I restored the edit. Synthetic CPU queue coverage. AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran the tests and drafted this report.
oni-swr commented 2026-11-25 19:09:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T18:33:52Z.


RX 7800 XT (RDNA3, wave32/wave64) report on exact head 23934893023b45ff20e4bd85a9ff71948f835c50 (as is, on its base 930e8b49; no merge with current main, which merges cleanly).

Tested

  • AMD Radeon RX 7800 XT, driver 32.0.31035.1003; Ryzen 7 5700X3D; Windows 11 build 26200; Rust 1.100.0 MSVC; debug profile; dxc.exe from Windows SDK 10.0.26100.0.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on this head: 752 passed, 0 failed, 41 ignored (19 targets); lib: 708 passed, 0 failed, 21 ignored.
  • Baseline, same machine and command, unmodified main at c9ee916a: 1330 passed, 2 failed, 46 ignored (24 targets). The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: CPU 0x7fffffff, GPU 0x1) and gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier.
  • Note: this older head does not contain either of the two baseline-failing tests (grep finds no fuzz_validate_and_gpu_1 in its output), so the 0 failures here say nothing about them.
  • Relevant tests, all passing: hle::dstorage::tests::zero_byte_memory_source_request_succeeds
  • SKIPPED: none printed on this older head (the f16 and heap-window tests that skip on main are not in its output).

Not tested

  • No title and no scripts/smoke.ps1 run (no xcl-smoke blocks): I did not run an untrusted retail executable. This is a test-suite report only, not the regression run the PR needs.
  • Release profile, NVIDIA, Intel, Wine, RDNA2/RDNA4.

AI use

  • This run and report were done by Claude Code (Claude Sonnet 5.5): it fetched the head, ran the commands above and wrote this comment. Nothing was reviewed line by line for correctness here.
<!-- greyfinch-sync:ivall/xcl:comment:7171080943 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1312#issuecomment-7171080943). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T18:33:52Z. --- **RX 7800 XT (RDNA3, wave32/wave64) report on exact head `23934893023b45ff20e4bd85a9ff71948f835c50`** (as is, on its base `930e8b49`; no merge with current `main`, which merges cleanly). **Tested** - AMD Radeon RX 7800 XT, driver 32.0.31035.1003; Ryzen 7 5700X3D; Windows 11 build 26200; Rust 1.100.0 MSVC; debug profile; `dxc.exe` from Windows SDK 10.0.26100.0. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on this head: 752 passed, 0 failed, 41 ignored (19 targets); lib: 708 passed, 0 failed, 21 ignored. - Baseline, same machine and command, unmodified `main` at `c9ee916a`: 1330 passed, 2 failed, 46 ignored (24 targets). The 2 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` (seed 722: CPU `0x7fffffff`, GPU `0x1`) and `gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`. - Note: this older head does not contain either of the two baseline-failing tests (grep finds no `fuzz_validate_and_gpu_1` in its output), so the 0 failures here say nothing about them. - Relevant tests, all passing: `hle::dstorage::tests::zero_byte_memory_source_request_succeeds` - `SKIPPED`: none printed on this older head (the f16 and heap-window tests that skip on `main` are not in its output). **Not tested** - No title and no `scripts/smoke.ps1` run (no `xcl-smoke` blocks): I did not run an untrusted retail executable. This is a test-suite report only, not the regression run the PR needs. - Release profile, NVIDIA, Intel, Wine, RDNA2/RDNA4. **AI use** - This run and report were done by Claude Code (Claude Sonnet 5.5): it fetched the head, ran the commands above and wrote this comment. Nothing was reviewed line by line for correctness here.
bmjask commented 2026-11-25 21:49:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T21:49:38Z.

Review: COMMENTED


No concrete correctness/lifetime defect found. Zero source bypasses only validation/copy; normal uncompressed size equality gives zero destination too, and empty physical pages are handled safely. The test reproduces old failure/no-write behavior. Add a queue-level zero-byte request/status-path test to protect external async semantics; exact-head Windows suite evidence is strong. I found no blocker.

<!-- greyfinch-sync:ivall/xcl:review:6065451103 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1312#pullrequestreview-6065451103). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T21:49:38Z. **Review:** COMMENTED --- No concrete correctness/lifetime defect found. Zero source bypasses only validation/copy; normal uncompressed size equality gives zero destination too, and empty physical pages are handled safely. The test reproduces old failure/no-write behavior. Add a queue-level zero-byte request/status-path test to protect external async semantics; exact-head Windows suite evidence is strong. I found no blocker.
Foniass commented 2026-12-01 05:24:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:24:26Z.


Triage (#1607) – head 2393489

No open or merged PR makes the same change. On main, execute in dstorage.rs still calls gpu::shader::readable(at, r.source_size) before the empty check, and readable returns false for len == 0. So a 0-byte memory-source request still fails with E_ACCESS_VIOLATION, and the new test covers exactly that.
The PR conflicts with main: the source address now goes through cpu_range, and execute takes more arguments, so both the fix and the test's execute(...) call need a rebase.
Recommendation: keep open.

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:7301737224 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1312#issuecomment-7301737224). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:24:26Z. --- **Triage (#1607)** – head 2393489 No open or merged PR makes the same change. On main, `execute` in `dstorage.rs` still calls `gpu::shader::readable(at, r.source_size)` before the empty check, and `readable` returns false for `len == 0`. So a 0-byte memory-source request still fails with E_ACCESS_VIOLATION, and the new test covers exactly that. The PR conflicts with main: the source address now goes through `cpu_range`, and `execute` takes more arguments, so both the fix and the test's `execute(...)` call need a rebase. Recommendation: keep open. 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/1312:upstream-pr/1312'
git switch 'upstream-pr/1312'

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/1312'
git switch 'upstream-pr/1312'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1312'
git switch 'upstream-pr/1312'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1312'
git switch 'main'
git merge --squash 'upstream-pr/1312'
git switch 'main'
git merge --ff-only 'upstream-pr/1312'
git switch 'main'
git merge 'upstream-pr/1312'
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!1302
No description provided.