fix(dstorage): read titles' requests with the Xbox dstorage_xs.h layout #25

Manually merged
github merged 3 commits from gh-pr/25/head into gh-pr/25/base 2026-11-26 19:10:59 +00:00
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-22 17:34 UTC · original
Ahmet-Dedeler:fix/xbox-dstorage-request-layout → main · +877 −174 · 14 files · 3 commits · merged 2026-11-22 18:50 UTC

What

IDStorageQueueX::EnqueueRequest declared DSTORAGE_REQUEST with the PC dstorage.h shape. A title built against Xbox dstorage_xs.h passes the 0x48-byte Xbox struct, so every field was read at the wrong offset (reported as a crash inside XCRDAPI.dll). CreateQueue had the same problem: DSTORAGE_QUEUE_DESC::SourceType is a UINT64 enum on Xbox (Capacity at +0x08, Name at +0x10), and the shim's extra Device field meant it read the title's Name from the Capacity bytes.

Layouts from the public GDK reference:

The same request layout is in Microsoft's MIT Xbox-GDK-Samples, Samples/System/SimpleDirectStorageCombo/DirectStorageWin32/dstorage_win32.h.

Changes

  • dstorage_abi.h: Xbox DSTORAGE_REQUEST, DSTORAGE_REQUEST_OPTIONS (Zlib bit 0, BcpackMode 1-4, SwizzleMode 5-20, DestinationIsPhysicalPages 21, SourceType 22, SourceIsPhysicalPages 23), DSTORAGE_QUEUE_DESC, DSTORAGE_QUEUE_INFO, DSTORAGE_ERROR_RECORD (0x290), BCPACK/SWIZZLE/COMMAND_TYPE enums. Also DSTORAGE_MAX_QUEUE_CAPACITY is now 0x2000 (it said 2000 decimal). static_asserts on every size and offset.
  • The old struct is now OpenScarlettDStorageRequestDesc, a host extension for GDeflate and D3D12 destinations, sent through a new OpenScarlettDStorageEnqueueRequestDesc export. Queue devices move to OpenScarlettDStorageSetQueueDevice.
  • EnqueueRequest decodes the option word. Zlib/BCPack requests fail with E_DSTORAGE_DECOMPRESSION_ERROR because the shim's ZLIB/BCPACK codecs are its own synthetic container, not RFC 1950 or console BCPack. Swizzle, physical-page and reserved bits fail with E_INVALIDARG. RetrieveErrorRecord fills in FirstFailure.Request.
  • Tests: the host-extension tests use the desc API. The external GDK tests and the compat dstorage_xs.h use the Xbox layout. The MS sample runner now builds on its _GAMING_XBOX_SCARLETT path.
  • New test_dstorage_xbox_request_layout: it writes each field at its documented byte offset into a raw buffer with poisoned padding, then checks memory copies, option decoding, the error record, CancelRequestsWithTag and (on Windows) file reads.

Testing

  • macOS (clang, with a local dxgiformat.h include): the new test passes. test_dstorage_audio_diag_parity and test_xg_dstorage pass. test_gdk_shims crashes the same way before and after this change.
  • MinGW-w64 cross-build: dstorage_xs, the new test, test_gdk_shims, test_xg_dstorage, test_dstorage_audio_diag_parity, test_s12_streaming_vram and gdk_system_combo all build. gdk_external_* fail under MinGW exactly as they do on main (__uuidof and XAsync).
  • Not run: MSVC /W4 and the Windows CTest suite. Please run ctest before merging.

Follow-up, not in this PR: real zlib (RFC 1950) inflate for ZlibDecompress requests. The IIDs and vtable order were not audited.

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-22 17:34 UTC · [original](https://github.com/californiaAlmonds/OpenScarlett/pull/25) `Ahmet-Dedeler:fix/xbox-dstorage-request-layout` → `main` · +877 −174 · 14 files · 3 commits · merged 2026-11-22 18:50 UTC ## What `IDStorageQueueX::EnqueueRequest` declared `DSTORAGE_REQUEST` with the PC `dstorage.h` shape. A title built against Xbox `dstorage_xs.h` passes the 0x48-byte Xbox struct, so every field was read at the wrong offset (reported as a crash inside XCRDAPI.dll). `CreateQueue` had the same problem: `DSTORAGE_QUEUE_DESC::SourceType` is a UINT64 enum on Xbox (Capacity at +0x08, Name at +0x10), and the shim's extra `Device` field meant it read the title's Name from the Capacity bytes. Layouts from the public GDK reference: - https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_request - https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_request_options - https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_queue_desc - https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/enums/dstorage_request_source_type - https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_error_record The same request layout is in Microsoft's MIT Xbox-GDK-Samples, `Samples/System/SimpleDirectStorageCombo/DirectStorageWin32/dstorage_win32.h`. ## Changes - `dstorage_abi.h`: Xbox `DSTORAGE_REQUEST`, `DSTORAGE_REQUEST_OPTIONS` (Zlib bit 0, BcpackMode 1-4, SwizzleMode 5-20, DestinationIsPhysicalPages 21, SourceType 22, SourceIsPhysicalPages 23), `DSTORAGE_QUEUE_DESC`, `DSTORAGE_QUEUE_INFO`, `DSTORAGE_ERROR_RECORD` (0x290), BCPACK/SWIZZLE/COMMAND_TYPE enums. Also `DSTORAGE_MAX_QUEUE_CAPACITY` is now 0x2000 (it said 2000 decimal). static_asserts on every size and offset. - The old struct is now `OpenScarlettDStorageRequestDesc`, a host extension for GDeflate and D3D12 destinations, sent through a new `OpenScarlettDStorageEnqueueRequestDesc` export. Queue devices move to `OpenScarlettDStorageSetQueueDevice`. - `EnqueueRequest` decodes the option word. Zlib/BCPack requests fail with `E_DSTORAGE_DECOMPRESSION_ERROR` because the shim's ZLIB/BCPACK codecs are its own synthetic container, not RFC 1950 or console BCPack. Swizzle, physical-page and reserved bits fail with `E_INVALIDARG`. `RetrieveErrorRecord` fills in `FirstFailure.Request`. - Tests: the host-extension tests use the desc API. The external GDK tests and the compat `dstorage_xs.h` use the Xbox layout. The MS sample runner now builds on its `_GAMING_XBOX_SCARLETT` path. - New `test_dstorage_xbox_request_layout`: it writes each field at its documented byte offset into a raw buffer with poisoned padding, then checks memory copies, option decoding, the error record, CancelRequestsWithTag and (on Windows) file reads. ## Testing - macOS (clang, with a local dxgiformat.h include): the new test passes. test_dstorage_audio_diag_parity and test_xg_dstorage pass. test_gdk_shims crashes the same way before and after this change. - MinGW-w64 cross-build: dstorage_xs, the new test, test_gdk_shims, test_xg_dstorage, test_dstorage_audio_diag_parity, test_s12_streaming_vram and gdk_system_combo all build. gdk_external_* fail under MinGW exactly as they do on main (`__uuidof` and XAsync). - Not run: MSVC /W4 and the Windows CTest suite. Please run `ctest` before merging. Follow-up, not in this PR: real zlib (RFC 1950) inflate for `ZlibDecompress` requests. The IIDs and vtable order were not audited.
IDStorageQueueX::EnqueueRequest declared DSTORAGE_REQUEST with the PC
dstorage.h shape (byte-sized Options, Source/Destination unions,
UncompressedSize). A title built against dstorage_xs.h passes the Xbox
0x48-byte struct instead: a 64-bit option bitfield, Destination @0x08,
DestinationSize @0x18, File/Source @0x20, FileOffset @0x28, SourceSize
@0x30, IntermediateSize @0x34, CancellationTag @0x38, Name @0x40. Every
field the shim read was at the wrong offset.

- dstorage_abi.h: Xbox DSTORAGE_REQUEST, DSTORAGE_REQUEST_OPTIONS,
  DSTORAGE_QUEUE_DESC (UINT64 SourceType, no Device), DSTORAGE_QUEUE_INFO,
  DSTORAGE_ERROR_RECORD (0x290), BCPACK/SWIZZLE/COMMAND_TYPE enums and
  DSTORAGE_MAX_QUEUE_CAPACITY 0x2000, with size/offset static_asserts.
- The old struct becomes OpenScarlettDStorageRequestDesc, a host extension
  for GDeflate/D3D12 destinations, submitted via the new
  OpenScarlettDStorageEnqueueRequestDesc export. Queue devices move to
  OpenScarlettDStorageSetQueueDevice.
- EnqueueRequest decodes the option word: zlib/BCPack requests fail with
  E_DSTORAGE_DECOMPRESSION_ERROR (the shim's ZLIB/BCPACK codecs are its
  own synthetic container), swizzle/physical-page/reserved bits with
  E_INVALIDARG. RetrieveErrorRecord fills the Xbox FirstFailure.Request.
- Tests: host-extension tests move to the desc API; external GDK tests and
  the compat dstorage_xs.h use the Xbox layout; the MS sample runner is
  built on its _GAMING_XBOX_SCARLETT path.

Refs:
https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_request
https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_request_options

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Writes each field at its documented dstorage_xs.h offset into a 0x48-byte
buffer (padding poisoned) and checks the shim: memory copies, option bit
positions, zlib/BCPack/swizzle/physical-page rejection, error record
contents, CancelRequestsWithTag on the +0x38 tag, and (Windows) file reads
at FileOffset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:10:58 +00:00
github manually merged commit 10a7531521 into gh-pr/25/base 2026-11-26 19:10:59 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-22 17:55 UTC · original

Tested 0958c5c (on current main 85e2d3d) on an RTX 5070, driver 621.24, Windows 11 26H2 (26300), VS Build Tools 18 (MSVC 14.52), SDK 10.0.26100.0:

  • Full build: 0 warnings.
  • ctest: 61/63 passed. The new test_dstorage_xbox_request_layout passes, as do test_xg_dstorage, test_dstorage_audio_diag_parity, test_gdk_shims, test_s12_streaming_vram and the GDK sample tests.
  • The two failures, test_rdna2_corpus_bench and test_rdna2_gpu_accuracy, fail the same way on main without this PR. NVIDIA's driver rejects the mem_ds_atomics pipeline (E_OUTOFMEMORY on a groupshared atomic add of a negated value), so they're unrelated to DirectStorage. Fix and reproducer in #26.
**@⁠marquezinii** on GitHub · 2026-11-22 17:55 UTC · [original](https://github.com/californiaAlmonds/OpenScarlett/pull/25#issuecomment-7083202214) Tested 0958c5c (on current main 85e2d3d) on an RTX 5070, driver 621.24, Windows 11 26H2 (26300), VS Build Tools 18 (MSVC 14.52), SDK 10.0.26100.0: - Full build: 0 warnings. - `ctest`: 61/63 passed. The new `test_dstorage_xbox_request_layout` passes, as do `test_xg_dstorage`, `test_dstorage_audio_diag_parity`, `test_gdk_shims`, `test_s12_streaming_vram` and the GDK sample tests. - The two failures, `test_rdna2_corpus_bench` and `test_rdna2_gpu_accuracy`, fail the same way on main without this PR. NVIDIA's driver rejects the `mem_ds_atomics` pipeline (`E_OUTOFMEMORY` on a groupshared atomic add of a negated value), so they're unrelated to DirectStorage. Fix and reproducer in #26.
Author
Owner

@⁠californiaAlmonds on GitHub · 2026-11-22 18:50 UTC · original · approved these changes

Huge Xbox dstorage_xs.h ABI accuracy fix with comprehensive offset static_asserts and layout tests, and 4/4 CI jobs are green. Thanks @⁠Ahmet-Dedeler!

**@⁠californiaAlmonds** on GitHub · 2026-11-22 18:50 UTC · [original](https://github.com/californiaAlmonds/OpenScarlett/pull/25#pullrequestreview-6013834154) · **approved these changes** Huge Xbox dstorage_xs.h ABI accuracy fix with comprehensive offset static_asserts and layout tests, and 4/4 CI jobs are green. Thanks @⁠Ahmet-Dedeler!
This discussion has been locked. Commenting is limited to contributors.
No description provided.