DirectStorage: submitted cancellation, intermediate_size, and physical-page destinations #21

Manually merged
github merged 1 commit from gh-pr/21/head into gh-pr/21/base 2026-11-26 04:04:38 +00:00
Owner

@⁠raylitebull on GitHub · 2026-11-21 21:57 UTC · original
raylitebull:dstorage-enhancements → main · +773 −64 · 3 files · 1 commits · merged 2026-11-21 22:53 UTC

Summary

Implements three console DirectStorage (xcrdapi.dll) enhancements in crates/xcl/src/hle/dstorage.rs:

  1. Cancellation of already-submitted requests (CancelRequestsWithTag):

    • Assigns monotonically increasing sequence numbers to enqueued requests and tracks { up_to_seq, mask, value } cancellation rules in shared queue state (pruned as the worker advances).
    • Locks worker before pending in QueueInner::submit() so concurrent submissions preserve strict FIFO ordering.
    • Skips matching pending and queued-but-unexecuted requests cleanly without affecting IDStorageStatusArrayX or DSTORAGE_ERROR_RECORD, while leaving requests enqueued after CancelRequestsWithTag unaffected.
    • Wraps Entry::Signal in an RAII FenceRef so ID3D12Fence COM references are never leaked on close or error.
  2. Multi-stage decompression / intermediate_size:

    • Decodes the full Xbox DSTORAGE_REQUEST_OPTIONS bitfield (ZlibDecompress bit 0, BcpackMode bits 1..=4, SwizzleMode bits 5..=20, DestinationIsPhysicalPages bit 21, SourceType bit 22, SourceIsPhysicalPages bit 23).
    • Supports zlib inflation into an intermediate buffer when source_size < intermediate_size <= destination_size (zero-padding any trailing destination bytes), validates two-stage bounds (E_DESTINATION_SIZE), and refuses unsupported BCPack / hardware swizzle modes with E_DECOMPRESSION.
  3. Physical-page destinations and sources (DestinationIsPhysicalPages / SourceIsPhysicalPages):

    • On Xbox Series X|S (UMA), placed D3D12 buffers and textures live at virtual/UMA addresses (tracked via MEM_WRITE_WATCH), while the non-virtual mode in the 0x48-byte DSTORAGE_REQUEST targets 64 KiB physical page arrays (DestinationPageArray + DestinationPageOffset @⁠0x10; SourcePageArray + SourcePageOffset @⁠0x28).
    • Snapshots PULONG_PTR page arrays at enqueue time and exports PHYS_PAGE_SIZE, read_physical_pages, and write_physical_pages in crates/xcl/src/hle/kernelx.rs (obeying AWAY -> PHYS_BLOCKS lock order and validating all pages before copying, including pages mapped into reserved virtual address space).

Testing

  • Unit tests in crates/xcl/src/hle/dstorage.rs: cancel_pending_and_submitted_requests_by_tag, multi_stage_intermediate_size_validation_and_zlib, physical_page_destinations_and_sources.
  • Extended tests/testtitle/src/gpu.rs::direct_storage e2e check with DestinationIsPhysicalPages + DestinationPageOffset and CancelRequestsWithTag.
  • cargo build --workspace (0 new warnings) and cargo test --workspace -- --test-threads=4 all passing (243 lib + 12 console_dlls_e2e + 1 console_shaders + 1 e2e + 6 gpu_pso_e2e + 3 xg_oracle).
**@⁠raylitebull** on GitHub · 2026-11-21 21:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/21) `raylitebull:dstorage-enhancements` → `main` · +773 −64 · 3 files · 1 commits · merged 2026-11-21 22:53 UTC ## Summary Implements three console DirectStorage (`xcrdapi.dll`) enhancements in `crates/xcl/src/hle/dstorage.rs`: 1. **Cancellation of already-submitted requests (`CancelRequestsWithTag`)**: - Assigns monotonically increasing sequence numbers to enqueued requests and tracks `{ up_to_seq, mask, value }` cancellation rules in shared queue state (pruned as the worker advances). - Locks `worker` before `pending` in `QueueInner::submit()` so concurrent submissions preserve strict FIFO ordering. - Skips matching pending and queued-but-unexecuted requests cleanly without affecting `IDStorageStatusArrayX` or `DSTORAGE_ERROR_RECORD`, while leaving requests enqueued after `CancelRequestsWithTag` unaffected. - Wraps `Entry::Signal` in an RAII `FenceRef` so `ID3D12Fence` COM references are never leaked on close or error. 2. **Multi-stage decompression / `intermediate_size`**: - Decodes the full Xbox `DSTORAGE_REQUEST_OPTIONS` bitfield (`ZlibDecompress` bit 0, `BcpackMode` bits 1..=4, `SwizzleMode` bits 5..=20, `DestinationIsPhysicalPages` bit 21, `SourceType` bit 22, `SourceIsPhysicalPages` bit 23). - Supports zlib inflation into an intermediate buffer when `source_size < intermediate_size <= destination_size` (zero-padding any trailing destination bytes), validates two-stage bounds (`E_DESTINATION_SIZE`), and refuses unsupported BCPack / hardware swizzle modes with `E_DECOMPRESSION`. 3. **Physical-page destinations and sources (`DestinationIsPhysicalPages` / `SourceIsPhysicalPages`)**: - On Xbox Series X|S (UMA), placed D3D12 buffers and textures live at virtual/UMA addresses (tracked via `MEM_WRITE_WATCH`), while the non-virtual mode in the `0x48`-byte `DSTORAGE_REQUEST` targets 64 KiB physical page arrays (`DestinationPageArray` + `DestinationPageOffset` @⁠0x10; `SourcePageArray` + `SourcePageOffset` @⁠0x28). - Snapshots `PULONG_PTR` page arrays at enqueue time and exports `PHYS_PAGE_SIZE`, `read_physical_pages`, and `write_physical_pages` in `crates/xcl/src/hle/kernelx.rs` (obeying `AWAY -> PHYS_BLOCKS` lock order and validating all pages before copying, including pages mapped into reserved virtual address space). ## Testing - Unit tests in `crates/xcl/src/hle/dstorage.rs`: `cancel_pending_and_submitted_requests_by_tag`, `multi_stage_intermediate_size_validation_and_zlib`, `physical_page_destinations_and_sources`. - Extended `tests/testtitle/src/gpu.rs::direct_storage` e2e check with `DestinationIsPhysicalPages` + `DestinationPageOffset` and `CancelRequestsWithTag`. - `cargo build --workspace` (0 new warnings) and `cargo test --workspace -- --test-threads=4` all passing (243 lib + 12 `console_dlls_e2e` + 1 `console_shaders` + 1 `e2e` + 6 `gpu_pso_e2e` + 3 `xg_oracle`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:37 +00:00
github manually merged commit 6abe17d620 into gh-pr/21/base 2026-11-26 04:04:37 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-21 22:53 UTC · original

Reviewed and merged, thanks – the physical-page reads / writes follow XCL's page model (a page is at its home or where it is mapped), and BCPack / hardware swizzle modes are refused instead of faked. Checked together with #21, #22 and #25 on top of current main: full workspace tests pass (277 lib tests, e2e, console_dlls_e2e, gpu_pso_e2e, rpf_e2e), no new build warnings.

**@⁠ivall** on GitHub · 2026-11-21 22:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/21#issuecomment-7070497963) Reviewed and merged, thanks – the physical-page reads / writes follow XCL's page model (a page is at its home or where it is mapped), and BCPack / hardware swizzle modes are refused instead of faked. Checked together with #21, #22 and #25 on top of current main: full workspace tests pass (277 lib tests, e2e, console_dlls_e2e, gpu_pso_e2e, rpf_e2e), no new build warnings.
This discussion has been locked. Commenting is limited to contributors.
No description provided.