Skip to content

DirectStorage: close a queue when its last reference is released - #1675

Open
eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/dstorage-release-closes-queue
Open

eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/dstorage-release-closes-queue

Conversation

@eizispark

@eizispark eizispark commented Nov 24, 2026 •

Copy link
Copy Markdown

DirectStorage specifies that IDStorageQueue::Close (IDStorageQueueX::Close) is called automatically when the last reference on a queue is released. queue_release only dropped the channel sender without calling close(), so releasing the final queue reference without a prior Close() left closed == false: remaining submitted requests in the channel continued writing into caller destination buffers after Release() returned, Release() did not wait for in-flight worker activity or wake parallel decompression staging-budget waiters, and pending or remaining status-array entries stayed E_PENDING or completed with S_OK instead of E_QUEUE_CLOSED.

What is in it

  • crates/xcl/src/hle/dstorage.rs: move queue_close's logic (including parallel::wake_waiters(self) from DirectStorage: decode eligible file requests in parallel #819) into QueueInner::close and call it from both queue_close and queue_release when n == 0.
  • crates/xcl/src/hle/dstorage.rs (tests): add last_queue_release_closes_pending_and_submitted_work_before_returning verifying that a final Release() without Close() waits for the active worker item to finish, skips remaining submitted requests without touching caller destination buffers, and marks both submitted and unsubmitted status entries complete with E_QUEUE_CLOSED.

Tested

  • Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (driver 32.0.32015.16001), rustc 1.100.0 (0ef1bc386 2026-11-09), debug and release.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 890 passed, 0 failed, 42 ignored (SKIPPED GPU tests: 2 – shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is off); heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).
  • cargo test -p xcl --lib dstorage -- --test-threads=4 (default and XCL_DSTORAGE_PARALLEL_DECOMPRESS=1): 30 passed, 0 failed on each run (last_queue_release_closes_pending_and_submitted_work_before_returning failed before the fix because Release returned while the worker was still active and the submitted request wrote to the destination buffer afterwards).

Regression run

main:

xcl-smoke v1
commit: 85e38262ff94aecd75d6f83fa8156a8b7697bd13
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1669 (PresentX 1669)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14860 MB

PR head:

xcl-smoke v1
commit: 47ce44e4b8d7d2a016a1166c680f6c0b1cfef20f
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1673 (PresentX 1673)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14859 MB

Not tested

  • Retail titles that release a DirectStorage queue with in-flight streaming requests without calling Close() first.
  • NVIDIA and Intel GPUs, Windows 10, wave32-only adapters, and XCL_SAMPLE_* sample-data tests.

AI use

anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
…g, DirectStorage, and stream tracking

Cherry-picks upstream stabilization improvements across VRAM allocation,
pipeline caching, DirectStorage lifetime, descriptor heap indexing, Media
Foundation device bridging, and stream PSO tracking:

- D3D12.X: reclaim cooling and idle tiles on pool heap OOM (xcl-dev#1663,
  addressing xcl-dev#1585 and xcl-dev#1668). When CreateHeap returns 0x8007000E (E_OUTOFMEMORY),
  Pages::take_tile waits on Pages::fence up to 1000 ms to drain cooling tiles or
  force-evict idle pages rather than failing immediately. (by Nikita Romanovich)

- DirectStorage: close a queue when its last reference is released (xcl-dev#1675).
  Moves queue_close logic into QueueInner::close and invokes it when the final
  queue reference is released, preventing background workers from writing to freed
  caller buffers and marking pending entries complete with E_QUEUE_CLOSED. (by eizispark)

- D3D12.X: a pipeline the driver gave up on is not built again (xcl-dev#1665).
  Persists driver E_OUTOFMEMORY refusal state into used-pipelines.txt (!<key>)
  so giant compute pipelines that the host driver refuses to compile are skipped
  on subsequent runs. (by zorde23)

- Recompiler: access outside heap windows takes a null view without branching
  (xcl-dev#1669, xcl-dev#680). Replaces conditional branches in XCL_HEAP_WINDOWS=1
  (if (xcl_w >= windows)) with a branchless select pointing out-of-bounds accesses
  to a dedicated null UAV view (MEM_HEAP_NULL). (by milesah3ad)

- HLE: bridge ID3D12Device before direct ResetDevice and cache D3D11 companion
  (xcl-dev#1677). Fixes MFResetDXGIDeviceManagerX in mfplat.rs to bridge
  ID3D12Device COM pointers and caches multithreaded companion ID3D11Device
  instances per adapter LUID. (by eizispark)

- D3D12.X: route stream graphics PSOs through create_graphics_pso_tracked
  (xcl-dev#1661, finding XCL-BT-023 from xcl-dev#1489). Ensures stream-created
  graphics PSOs receive D3D12_PIPELINE_STATE_FLAG_DYNAMIC_DEPTH_BIAS and are
  tracked in device_x::note_base for CreateDerivedPipelineStateX and RSSetDepthBiasX.
  (by fixgep)

Assisted-by: Antigravity
DirectStorage specifies that IDStorageQueue::Close is invoked
automatically when the last reference on a queue is released.
queue_release only dropped the channel sender without running close(),
so releasing a queue without a prior Close() left closed == false:
submitted requests in the channel continued writing into caller buffers
after Release() returned, Release() did not wait for in-flight worker
activity or wake parallel decompression budget waiters, and pending or
remaining status-array entries stayed E_PENDING or completed with S_OK
instead of E_QUEUE_CLOSED.

Move queue_close's logic (including parallel::wake_waiters) into
QueueInner::close and call it from both queue_close and queue_release
on n == 0.

Assisted-by: Antigravity (Google DeepMind, Gemini 4 Carbon)
@eizispark
eizispark force-pushed the fix/dstorage-release-closes-queue branch from 66aaced to 47ce44e Compare November 24, 2026 20:25
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@frenziedcoder

Copy link
Copy Markdown

NVIDIA test report for 47ce44e: the full workspace and a smoke pair on the retail title, next to @DavidM1911's RTX 3060 Ti library run above. Full suite green, the PR's own test passes, and a clean smoke pair (1656 vs 1649 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 47ce44e4b8d7d2a016a1166c680f6c0b1cfef20f, no local changes.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug): 890 passed, 0 failed, 42 ignored; the PR's own test passes. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

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 (b9b6ea6, this PR's merge base with main):

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

this PR:

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

Not tested: a title releasing a DirectStorage queue with requests in flight without Close(); the world load; AMD.

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.

@JJAutoCompare

Copy link
Copy Markdown

PR #1675 · DirectStorage queue close on final release

Tested clean head 47ce44e4b8d7d2a016a1166c680f6c0b1cfef20f on STOR-WINLAB. The focused DirectStorage run passed. The full workspace run exited 101.

Tested

  • 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, and no d3d12SDKLayers.dll. DXC/DXIL 1.9.2609.5, rustc 1.100.0 (0ef1bc386 2026-11-09), unoptimized dev/test profiles with debug info disabled.
  • cargo build --workspace and cargo test --workspace --no-run succeeded. All cargo test invocations used Invoke-ArcTest.ps1 with XCL_ADAPTER=A770.
  • cargo test -p xcl hle::dstorage -- --nocapture reported 30 passed, 0 failed, 0 ignored, and 0 SKIPPED lines. last_queue_release_closes_pending_and_submitted_work_before_returning passed in both runs. It checks that final release waits for active worker work, leaves the submitted request's destination buffer untouched, and completes submitted and pending statuses with E_QUEUE_CLOSED.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 reported 872 passed, 18 failed, 42 ignored across 20 harness summaries in pr1675-suite.log. The log contains 4 SKIPPED lines, which are excluded from coverage.

Failures and skips

  • GPU unit tests had 13 CreateComputePipelineState failures (0x80070057, including FP64 cases) and four assertion failures covering fused FMA overflow, implicit-LOD sampling, FP16 high-half preservation, and pixel wave reductions.
  • The test title failed its RSSetDepthBiasX rendering check. Its DirectStorage file read, status, and D3D12 fence check passed.
  • Skip reasons were unavailable wave64 (2), unavailable heap windows (1), and the driver cache could not be disabled for PSO measurement (1).

Not tested

Retail-title smoke runs on main and the PR head, a main suite baseline for the failures, optional game-data cases (XCL_SAMPLE_* unset), D3D12 debug-layer coverage, and other adapters.

AI use

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 pr1675-suite.log and published.

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