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

Merged
raylitebull merged 1 commit from upstream-pr/21 into main 2026-11-21 22:53:28 +00:00
raylitebull commented 2026-11-21 21:57:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-21T21:57:06Z.


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).
<!-- greyfinch-sync:ivall/xcl:issue:5432840214 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/21). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-21T21:57:06Z. --- ## 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`).
upstream-sync closed this pull request 2026-11-24 06:56:47 +00:00
ivall commented 2026-11-24 07:00:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-21T22:53:26Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7070497963 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/21#issuecomment-7070497963). Originally posted by [ivall](https://github.com/ivall) on 2026-11-21T22:53:26Z. --- 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.
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!20
No description provided.