Skip to content

D3D12.X: guard truncated, null, and unreadable mesh pipeline streams - #2015

Draft
GustavoEllwanger wants to merge 1 commit into
xcl-dev:mainfrom
GustavoEllwanger:fix/mesh-stream-bounds-and-null-guard
Draft

GustavoEllwanger wants to merge 1 commit into
xcl-dev:mainfrom
GustavoEllwanger:fix/mesh-stream-bounds-and-null-guard

Conversation

@GustavoEllwanger

Copy link
Copy Markdown

Related to #1968 and #1833 (hardens the mesh pipeline stream path audited for #1968; does not claim to resolve the unconfirmed ntdll.dll+0x1ff2a crash from #1968's local build).

What is in it
Fixes three concrete memory-safety / panic gaps in the CreatePipelineState mesh-stream path (crates/xcl/src/hle/d3d12x/real.rs), plus unit and GPU integration tests that run on any D3D12 adapter (AMD, NVIDIA, Intel, or WARP):

  • own_stream: check readable(desc, 16) before dereferencing desc; check at + psize <= size before indexing subobject payloads (previously panicked on truncated tail subobjects); clear zero-length shader entries and return None when a non-null, non-empty shader pointer is unreadable instead of handing a dangling title pointer to the background PSO worker.
  • finish_two_pass: check ppv.is_null() || (*ppv).is_null() right after finish_pso succeeds, returning E_INVALIDARG before compiling the compute pass or dereferencing *ppv during error cleanup / registration.
  • dev_create_pipeline_state: guard the direct finish_pso fallback with stream_has_unreadable_shader(desc) so a stream carrying an unreadable shader bytecode pointer returns E_INVALIDARG instead of access-violating (0xC0000005) inside D3D12Core.dll.
  • Tests (mesh_stream_tests in real.rs and crates/xcl/tests/d3d12_mesh_stream.rs): cover null/truncated/unreadable streams in own_stream, null out-pointer handling in finish_two_pass, console MS in the AS slot (E_INVALIDARG), console MS + AS together, malformed/unreadable streams through ID3D12Device2::CreatePipelineState, and 5-thread concurrent stream refusals.

Tested

  • Adapter: AMD Radeon RX 7600 (8133 MiB VRAM, RDNA3, Adrenalin 26.11.2 / driver 32.0.32029.2010), AMD Ryzen 5 5600T, Windows 11 Home build 26200, Rust 1.100.0 MSVC x64, DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0), debug profile.
  • cargo test -p xcl --lib mesh_stream_tests -- --nocapture: 2 passed, 0 failed, 0 ignored.
  • cargo test -p xcl --test d3d12_mesh_stream -- --nocapture: 3 passed, 0 failed, 0 ignored (RX 7600).
  • XCL_ADAPTER=warp cargo test -p xcl --test d3d12_mesh_stream -- --nocapture: 3 passed, 0 failed, 0 ignored (WARP).
  • XCL_HEAP_WINDOWS=1 cargo test -p xcl --test gpu_compute_e2e heap_window_out_of_memory_falls_back_to_the_switch_form -- --nocapture: 1 passed, 0 failed (RX 7600).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --skip fuzz_validate_and_gpu_1: 997 passed, 0 failed, 45 ignored, 1 filtered out, 0 wave64/mesh capability skips (8 SKIPPED lines: 6 per-lane #1426 refusals, 1 driver cache / no Windows Developer Mode, 1 no heap windows verified separately above).
  • XCL_ADAPTER=warp cargo test -p xcl --lib fuzz_validate_and_gpu_1 -- --nocapture: 1 passed (validated 500/500 modules 500..1000, GPU-compared 0).
  • git diff --check: passed.

Not tested

  • Retail-title scripts/smoke.ps1 regression runs (xcl-smoke v1 blocks for main and PR head): no retail Xbox title is available on this machine. Opened as Draft awaiting a paired community xcl-smoke v1 run.
  • Non-AMD hardware GPUs (NVIDIA / Intel) and XCL_SAMPLE_* game-data tests.

AI use
Written and verified with Antigravity (Gemini 4 Neon); all builds and tests were run locally on this machine's RX 7600 and WARP adapter.

@raylitebull

Copy link
Copy Markdown
Member

Code review on 3705368:

  • own_stream in crates/xcl/src/hle/d3d12x/real.rs cleanly validates descriptor/stream readability, uses checked_add for subobject offsets/sizes, zeroes stale pointers when p == 0 || n == 0, and fails closed when a non-empty shader pointer is unreadable.
  • finish_two_pass checks ppv.is_null() || (*ppv).is_null() before entering the compute pass, and stream_has_unreadable_shader avoids handing invalid bytecode pointers to D3D12Core.
  • mesh_stream_tests and crates/xcl/tests/d3d12_mesh_stream.rs cover empty/truncated/unknown/unreadable streams and concurrent refusals cleanly.
  • Diff audited and CI workflow approved (currently running).

Remaining before merge:

  1. Fix the failing PR description check.
  2. Confirm Build and test (Windows, no GPU) finishes green.
  3. AMD and NVIDIA test verification on 3705368.

@GustavoEllwanger

GustavoEllwanger commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review @raylitebull!

  • Build and test (Windows, no GPU) has finished green.
  • AMD RDNA3 (RX 7600) test results for 3705368 are already listed under Tested in the PR description (mesh_stream_tests 2/2, d3d12_mesh_stream 3/3, full suite 997 passed, 0 failed).
  • I don't have an NVIDIA GPU or a retail title on this machine, so I'm keeping this as a Draft for now. If anyone with an NVIDIA card and/or a retail title can test 3705368 and share the paired xcl-smoke v1 blocks (main + 3705368), I'll add them to the PR description right away.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

NVIDIA test of 3705368 with a retail title, as asked above, on native Windows and on Linux (Wine + vkd3d-proton); 80f4819 is the commit of main it branches from. No run crashed or lost the device.

Setup: Windows: Windows 11 Pro 26300, RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, 32 GB RAM, rustc 1.99.1, release. Linux: Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, RTX 4070 12 GB (driver 615.71.09); release, cross-compiled to x86_64-pc-windows-gnu (rustc 1.98.0). Retail title 1.0.2.1, the first-run screens completed once and no story progress.

Regression run (scripts/smoke.ps1, unchanged, 60 s, start screen; one run each)

Windows (the run of 3705368 was made first), main and then this pull request:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1633 (PresentX 1633)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16520 MB
xcl-smoke v1
commit: 37053687bd669a844946af8c09ad3d99e7408c62
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1633 (PresentX 1633)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17021 MB

Linux, the same two commits (main ran first): 1363 frames on 80f4819 and 1575 on 3705368, 0 device removals and 0 crashes on both; each ran beside a title run on the machine's second card (the end of one, then the start of the next).

Tested

Linux, 100 s, A pressed at 16 s, XCL_PSO_PRELOAD=0 main 2bdf047 + #684 the same + 3705368
frames 1400 1352
last 2 s with a present 78.4 s 80.2 s
compute pipelines built 257 250
failed pipelines / faults / device removals 0 / 0 / 0 0 / 0 / 0

Read

  • real.rs:5575: a stream with an unreadable shader now returns E_INVALIDARG before finish_pso and note_fallback, so nothing is logged or counted. The run with the change cannot show whether the title sent one. Would an xlog_warn! there be worth it?

Not tested: a truncated stream or an unreadable shader in a title run; the tests, and the title past the start screen, on Windows; the rest of the suite; AMD and Intel; past 100 s.

AI use: Claude Code (Claude Fable 5.2) read the diff, built the trees, ran the title, the regression pairs and the tests, and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants