Repository navigation
Conversation
…ry reads 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>
docs/directstorage.md records which DLL and ABI the console title is expected to use (dstorage_xs.dll medium, xcrdapi.dll and dstorage.dll low confidence), what is not public (vtable order, interface ids, some constants) and the choice made for each, what owning the modules shadows at run time, what the shim does (including the order of its request checks), and what later PRs add (zlib, BCPack, swizzle, physical pages, GPU-backed destinations, parallel reads). Index row in docs/README.md; the owned-module list in runtime_imports.md and the shim list in runtime/README.md name the new modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # scripts/build_runtime.ps1
…mit, /EHa under clang-cl Review fixes for ItsNotRexed#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>
# Conflicts: # scripts/build_runtime.ps1
# Conflicts: # scripts/build_runtime.ps1
# Conflicts: # scripts/build_runtime.ps1
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>
|
Tested 00551ba on Windows 11, CPU only: pass. I built the For the control, I built the same DirectStorage test with the implementation from parent 45c39cf. I used the four new error constants from the PR so the test could compile. The control fails 29 of 329 checks. For example, the dynamic Huffman file request returns AI-assisted. |
|
Tested on Windows 11, RTX 5070, Vulkan, own 1.0.2.1 copy, merged onto Pipodi's |
|
Tested the same idea on the retail boot: pass. Own 1.0.2.1 copy, Windows 11, RTX 4090 / 617.42,
AI-assisted (Claude Code). |
|
Independent native Windows clang-cl/xwin check at 00551ba. The dstorage and shader_library CTests both passed, with 329 checks and 0 failures in dstorage, including the CPU zlib request path. Synthetic files and temporary output were on E:. AI-assisted testing. |
Claimed in the coordination issue as: #7049 (comment) (item 2)
Depends on: #4348.
runtime/shims/dstorage.cpponly exists there, so this branch is based on its head (45c39cf6f). This PR's own diff is the one commit on top,00551ba00("DirectStorage: inflate zlib requests (file and memory sources)"). Until #4348 lands, GitHub shows #4348's commits here too.What and why
#4348 answers every DirectStorage request with the zlib option with
E_NOTIMPL. The retail executable reads its pipeline and state data through DirectStorage zlib requests. With those requests refused, the title's native pipeline descriptions arrive zero-filled. On my own copy, a local inflate in this path made those reads succeed and the data come back non-zero. This PR does that work properly.zlib requests (file and memory sources). A request with
ZlibDecompressalone reads itsSourceSizebytes into a staging buffer and inflates them on the queue's worker. The inflater is the runtime's existing RFC 1950 one,leonida::zlib_inflateinruntime/src/shader_library.h(the XBCH one); no second inflater is added. The result is copied toDestinationonly when it is exactlyDestinationSizebytes. So a failed stream leaves the destination untouched, and a memory source inside its own destination (in-place loading) inflates correctly. Both buffers are at most 32 MiB (the existing unpaged-buffer limit), so staging is bounded.Checks from the public docs:
DestinationSizemust be larger thanSourceSize. This isE_DSTORAGE_INVALID_DESTINATION_SIZE's documented rule, andDSTORAGE_REQUESTsays the same aboutDestinationSize.FileOffsetmust be 16-byte aligned (DSTORAGE_REQUEST), elseE_DSTORAGE_INVALID_FILE_OFFSET. That constant was already declared but never used.IntermediateSizeis only for zlib + BCPack, so it stays 0.DSTORAGE_REQUESThas noUncompressedSizefield (that is the PC struct's);DestinationSizeplays that role.Errors, all from
dstorageerr.h:E_DSTORAGE_ZLIB_BAD_HEADER0x89240031E_DSTORAGE_ZLIB_BAD_DATA0x89240032E_DSTORAGE_ZLIB_PARITY_FAIL0x89240033DestinationSizeE_DSTORAGE_DECOMPRESSION_ERROR0x892400300x89240030is on Microsoft's public DirectStorage constants page ("a generic error ... during decompression"); no code names a size mismatch, so this generic one is used. The three zlib codes have no public description. Their names and values come from thewindows-bindgen-generated bindings of thedirect-storagecrate 0.5.1, which agree with its 0.2.0errors.rs. That they map to header / data / Adler-32 is my reading of their names (see "Not verified").RFC 1950 strictness. The header and the Adler-32 are checked. Bytes after the Adler-32 are not read, so a
SourceSizerounded up over padding works. The game's own data supports a strict zlib reading: the texture pools' codec-8 chunks, laid out for this decompression (docs/textures.md), inflate with Python'szlib.decompressintools/ttpf_mips.py, which checks both the header and the Adler-32.GetStats:TotalDecompressionRequestCount,PendingDecompressionRequestCountandDecompressionErrorsare now kept.zlib_inflategets an optionalZlibError* why(header, data, checksum, limit). Its existing callers are unchanged, andshader_library_testchecks the new reasons.Out of scope: BCPack and swizzle (with or without zlib) and physical pages still return
E_NOTIMPL, as in runtime: console DirectStorage (DStorageGetFactory) with file-to-memory reads #4348. Nothing is accepted silently.Docs:
docs/directstorage.md(request checks, a zlib section with the error table, tests, sources),docs/README.md,runtime/README.mdand the comment at the top ofdstorage.cppno longer say that zlib isE_NOTIMPL.The inflater decodes one bit at a time: correct, not fast. A table-driven decoder can replace it behind
zlib_inflatelater without touching the request path (noted in the doc).How tested
Linux, Wine 11.21, clang-cl/lld-link 23.1.4 cross build against the MSVC CRT and Windows SDK from xwin, RelWithDebInfo. No GPU and no game data needed.
dstorage_testgets a newtest_zlib. It uses synthetic streams only:zlib.compress(text, 9);zlib.compress(text, 1);zlib.compress(data, 0)gives), one of them a stored block followed by the dynamic stream's blocks.The test rebuilds the plain text itself, and checks the block types (BTYPE 2, 1 and 0).
It covers:
DestinationSize;IntermediateSize, a source past the end of the file;E_NOTIMPL), plus swizzle alone;The old case "zlib is not implemented yet" is now "zlib with DestinationSize equal to SourceSize" (
E_DSTORAGE_INVALID_DESTINATION_SIZE).dstorage_testunder Winea zlib file request: dynamic Huffman (got 0x80004001, want 0x00000000), plus the 2 below)The 2 failures in every row are the same and come from #4348's
test_stats_timing:the copy reached the guard pageanda running request is pending. Under Wine thePAGE_GUARDvectored handler that holds the copy never fires. They are unrelated to this change, and I expect them to pass on Windows, but I have not run it there.shader_library_testpasses under Wine (inflate stored/fixed/dynamic, plus the new failure reasons).ctest -R "^(dstorage|shader_library)$"gives the same results.gta6rtbuilds, with no warnings fromdstorage.cpp.Not verified
E_DSTORAGE_ZLIB_BAD_HEADER/_BAD_DATA/_PARITY_FAIL. The values come from the crate's header-generated bindings; Microsoft's public pages do not describe them. Mapping "parity" to the Adler-32 check is an inference.DestinationSizerule.AI-assisted.
🤖 Generated with Claude Code