A request with ZlibDecompress alone now reads SourceSize bytes of the file or of memory into a staging buffer,
inflates them with the runtime's RFC 1950 inflater (leonida::zlib_inflate in src/shader_library.h) and copies the
result to Destination only when it is exactly DestinationSize bytes. A failed stream leaves the destination
untouched, and a memory source inside its own destination inflates correctly.
Checks follow DSTORAGE_REQUEST and dstorageerr.h: DestinationSize must be larger than SourceSize with zlib
(E_DSTORAGE_INVALID_DESTINATION_SIZE), a zlib FileOffset must be 16-byte aligned (E_DSTORAGE_INVALID_FILE_OFFSET),
IntermediateSize stays 0 without BCPack. Stream failures map to E_DSTORAGE_ZLIB_BAD_HEADER, _ZLIB_BAD_DATA,
_ZLIB_PARITY_FAIL (Adler-32) and E_DSTORAGE_DECOMPRESSION_ERROR (a result of another size). GetStats counts
the inflates, the pending ones and the decompression errors.
zlib_inflate gains an optional failure reason (header, data, checksum, limit); its existing callers are unchanged.
BCPack, swizzle and physical-page requests still fail with E_NOTIMPL.
dstorage_test: synthetic streams only (Python zlib levels 9 and 1, stored blocks built by the test), from a file
and from memory, with every failure code; shader_library_test checks the new failure reasons.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes for #4348 (Flyander, AirKyzzZ):
- DSTORAGE_REQUEST allows a buffer over 32 MiB only with 64 KiB or 2 MiB
pages, which are not implemented yet, so such a request now fails with
E_DSTORAGE_REQUEST_TOO_LARGE before any memory is touched.
- TotalRequestCount and the byte totals grow when a request is submitted,
not when it is enqueued, and PendingRequestCount counts the request the
worker is processing (DSTORAGE_PRIORITY_STATS).
- dstorage.cpp is built with /EHa under clang-cl, so guarded_move's __try
catches an access violation in a title's buffer there too.
Tests: an over-limit and an at-limit 32 MiB copy, and stats checked
before Submit and while a copy is held on a guard page. The three new
failing checks fail with the previous shim.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Serve the Xbox DirectStorage API (IDStorageFactoryX2, IDStorageQueueX2,
IDStorageFileX, IDStorageStatusArrayX) under dstorage_xs.dll, xcrdapi.dll and
dstorage.dll. Declarations are our own (shims/dstorage_xs_abi.h), written from
the public GDK reference; layouts are pinned with static_asserts.
- OpenFile goes through the registry's kernel32!CreateFileW, so GAME: paths use
the console path mapping and the write overlay. GetHandle returns a ReOpenFile
handle with its own file position.
- One worker thread per queue runs submitted entries in order: file and memory
requests, status arrays, ID3D12Fence::Signal, EnqueueSetEvent (on a duplicate
of the title's handle taken at enqueue).
- Auto-submit at half the capacity (or disabled through DSTORAGE_QUEUE_OPTIONS),
enqueue into a full queue waits, CancelRequestsWithTag (a cancelled request is
a success and not a failure), error record and error event, Close and the last
Release drain the queue, IDStorageFileX::Close waits for the file's submitted
reads.
- Request checks: reserved bits, source type, BCPack/swizzle ranges, sizes,
1 GiB limit, null and foreign objects and closed files (also for zero-size
requests), end of file, inaccessible memory.
- zlib, BCPack, swizzle and physical pages return E_NOTIMPL (later PRs).
- Interface ids of the X interfaces are not public: a creating call accepts and
logs a new id per object kind, but refuses system COM ids (IMarshal,
IAgileObject, ...) and the PC DirectStorage ids; QueryInterface accepts only
IUnknown, the PC IDStorageStatusArray id (same shape) and the ids creating
calls accepted for that kind. Bad arguments are logged once per method.
- registry.cpp classifies xcrdapi.dll!DStorageGetFactory as HRESULT; the cl.exe
fallback in build_runtime.ps1 builds the new shim too.
ctest dstorage: 258 checks over synthetic files in %TEMP%, no GPU, no game data.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>