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. |
|
AI-assisted A/B on Wine 11.22, RTX 4070 (NVIDIA 620.73.04), with 00551ba on a local boot stack. The zlib path was reached and the baseline DirectStorage E_NOTIMPL disappeared from the boot log. shader_library_test passed. dstorage_test passed 327/329, with the two previously reported guard-page timing failures under Wine. |
|
Measured on Windows 11, RTX 3090 and the pinned ladder-frame integration. With the same 40 main-archive programs, 10 embedded programs and 52 BVH programs, the earlier runtime refused compressed DirectStorage requests with E_NOTIMPL. With the inflater from this PR, the first 4,096 completed requests delivered 256 MiB in total, with zero failures at that observation. At completion 8,192 the counter showed 525,316,348 bytes and zero failures. The title continued to request additional render resources. The local DirectStorage fixture passed 329 checks and the shader-library inflater fixture passed. The source patch, counter definition and build base are in the RTX 3090 handoff. AI-assisted measurement with OpenAI Codex. |
|
Tested Local integration tree: the shared
What the title does with a refused request, measured with #7555's probe: its read still reports the full size, but the buffer holds the first bytes of the file it read before, so its chunk parser fails on a missing chunk and the creator returns null. That is the assert. All 400 logged requests before it were zlib into 64 KiB destinations. The stop after it here is |
|
checked: #7180 | with: clang-cl cross-build (xwin SDK, ninja, ccache) of runtime target dstorage_test, run under Wine | on: Ubuntu, Wine 9.0 (x86_64 prefix), main@867d922f0 + #7180 (merge needed, see below) | result: dstorage_test builds and runs, 329 checks, 327 pass, 2 FAIL ("the copy reached the guard page" and "a running request is pending", both in test_stats_timing); all zlib checks pass; negative control: with runtime/shims/dstorage.cpp put back to the parent commit ac1843d (no zlib path) the same test shows 31 failures, 29 of them zlib checks (E_NOTIMPL 0x80004001 instead of the expected inflate result or E_DSTORAGE_ZLIB_BAD_HEADER/BAD_DATA/PARITY_FAIL/DECOMPRESSION_ERROR/INVALID_FILE_OFFSET/INVALID_DESTINATION_SIZE) plus the same 2 guard-page failures; NOT tested: real Windows, a real GPU, any game data, BCPack/swizzle/pages (still E_NOTIMPL by design), device_proxy/other tests Details:
agent: yes |
throny
left a comment
There was a problem hiding this comment.
Tested 00551ba merged onto main 867d922 on Windows 11, RTX 4080 610.88: pass; whole diff read, no defect found in the shim, the inflater change or the tests.
- Build: MSVC 14.44, Ninja, RelWithDebInfo;
dstorage.cppanddstorage_test.cppcompile with 0 warnings under/W4.dstorage_test: 329 checks, 0 failures, so the twotest_stats_timingchecks that fail under Wine pass on Windows.shader_library_testpasses,unimplemented_policy_test98 checks, 0 failed;gta6rtlinks. - Read: all 13 files. Checked by hand:
zlib_inflatereturns the same true/false as before for every path (only the reason is new), the request check order againstdocs/directstorage.md, the file/status-array lifetime underlive_mutex,Closewith entries in flight, and that a failed inflate cannot write the destination. The embedded zlib streams are the test's own text (it rebuilds and compares them). - Needs a rebase before it can merge: #4348 is closed and #8461 took it over. The merge into main conflicts in
docs/README.md,docs/runtime_imports.mdandruntime/CMakeLists.txt(three unions; theadd_test(NAME dstorage ...)block has to go after theendif()of the XTaskQueue block).Depends on:should name #8461. - With #7556 (first-touch commit of XMem pages): a plain file request calls
ReadFilestraight intoDestination(read_file_range), and the kernel does not fault an uncommitted page in, so it would fail withE_DSTORAGE_ACCESS_VIOLATIONthere. The zlib path is fine (guarded_moveruns in user mode). Whichever lands second needsrt::xmem::commit_physical_range(r.Destination, r.SourceSize)before the read. - Three small notes inline (two with suggestions). My earlier comment review has the retail boot result for this head.
AI-assisted (Claude Code). No game data.
| | [DirectStorage overview (GDK)](https://learn.microsoft.com/en-us/gaming/gdk/docs/features/console/storage/directstorage/directstorage-overview) | Queue, auto-submit, cancellation, notification order, file sharing, decode order | Same terms; paraphrased | | ||
| | `dstorage.h`, `dstorageerr.h` in the public `Microsoft.Direct3D.DirectStorage` 1.3.0 NuGet package | PC method order, interface ids (to refuse them), capacity and name-length constants, `E_DSTORAGE_*` values | Read for facts only; not vendored. `runtime/shims/dstorage_xs_abi.h` is Leonida's own declaration | | ||
| | [DirectStorage constants](https://learn.microsoft.com/en-us/windows/win32/dstorage/dstorage-constants) (Win32 reference) | `E_DSTORAGE_DECOMPRESSION_ERROR` = `0x89240030`; `E_DSTORAGE_INVALID_DESTINATION_SIZE`: equal to the length without decompression, larger with it; `E_DSTORAGE_INVALID_FILE_OFFSET` is the offset invalid for a decompression mode | [Microsoft Learn Terms of Use](https://learn.microsoft.com/en-us/legal/termsofuse); paraphrased | | ||
| | [`direct-storage` crate](https://docs.rs/direct-storage/0.5.1/src/direct_storage/bindings.rs.html) 0.5.1 (bindings generated by `windows-bindgen` from the DirectStorage headers; 0.2.0's `errors.rs` has the same values) | `E_DSTORAGE_ZLIB_BAD_HEADER` `0x89240031`, `E_DSTORAGE_ZLIB_BAD_DATA` `0x89240032`, `E_DSTORAGE_ZLIB_PARITY_FAIL` `0x89240033` (names and values only) | MIT/Apache-2.0; two constants' names and values, no code copied | |
There was a problem hiding this comment.
Three codes are listed in this row.
| | [`direct-storage` crate](https://docs.rs/direct-storage/0.5.1/src/direct_storage/bindings.rs.html) 0.5.1 (bindings generated by `windows-bindgen` from the DirectStorage headers; 0.2.0's `errors.rs` has the same values) | `E_DSTORAGE_ZLIB_BAD_HEADER` `0x89240031`, `E_DSTORAGE_ZLIB_BAD_DATA` `0x89240032`, `E_DSTORAGE_ZLIB_PARITY_FAIL` `0x89240033` (names and values only) | MIT/Apache-2.0; two constants' names and values, no code copied | | |
| | [`direct-storage` crate](https://docs.rs/direct-storage/0.5.1/src/direct_storage/bindings.rs.html) 0.5.1 (bindings generated by `windows-bindgen` from the DirectStorage headers; 0.2.0's `errors.rs` has the same values) | `E_DSTORAGE_ZLIB_BAD_HEADER` `0x89240031`, `E_DSTORAGE_ZLIB_BAD_DATA` `0x89240032`, `E_DSTORAGE_ZLIB_PARITY_FAIL` `0x89240033` (names and values only) | MIT/Apache-2.0; three constants' names and values, no code copied | |
| ## Which DLL and which ABI: the evidence | ||
|
|
||
| The game executable is not in the package available here, so its import table is unmeasured | ||
| ([runtime_imports.md](runtime_imports.md)). What is known: |
There was a problem hiding this comment.
Stale against current main: docs/runtime_imports.md there lists the executable's imports, with XCRDAPI.dll importing exactly one function, DStorageGetFactory. So this paragraph and the xcrdapi.dll row below ("low", "only a name in a library list") can say it is measured, and dstorage_xs.dll / dstorage.dll become the unmeasured aliases. Fine to do in the rebase.
| } | ||
| std::memset(hold.page, 0x5A, 4096); | ||
| DWORD old = 0; | ||
| VirtualProtect(hold.page, 4096, PAGE_READWRITE | PAGE_GUARD, &old); |
There was a problem hiding this comment.
If the guard is not set, the test waits 10 s and then reports "the copy reached the guard page" and "a running request is pending", the two checks that fail under Wine. Checking the call would tell the two cases apart.
| VirtualProtect(hold.page, 4096, PAGE_READWRITE | PAGE_GUARD, &old); | |
| check(VirtualProtect(hold.page, 4096, PAGE_READWRITE | PAGE_GUARD, &old) != FALSE, "the guard page is armed"); |
|
✅ Automated security review: CLEAN (commit
Scope: static analysis of added diff lines only; no code was executed. Please review findings manually. |
…eGetFactory) with file-to-memory reads Squashed from ItsNotRexed#4348 by mariuslozo-boop, head 45c39cf (security scan PASS). Conflicts: runtime/CMakeLists.txt kept main's XTaskQueue/wait_registration test block with its closing endif() (a plain union drops it) and put the dstorage test in its own if(). docs/README.md keeps main's rows and adds the directstorage.md row (main's gameinput.md row kept). registry.cpp's comment merges main's note that the retail executable imports xcrdapi.dll!DStorageGetFactory (ItsNotRexed#6715) with the PR's note that dstorage.cpp serves it; the HRESULT classification was already on the branch (ItsNotRexed#7175). ItsNotRexed#7180 (zlib) not pulled.
…ile and memory sources) Squashed from ItsNotRexed#7180 by its author, head 00551ba (the one commit on top of ItsNotRexed#4348's 45c39cf, already in main). Security scan PASS: prescan flags were doc links, a doc mention of zlib.decompress and a test's guard page; three Haiku reads of the whole 3,334-line diff, PASS each. The inflater is the in-tree leonida::zlib_inflate; nothing is downloaded. Conflict resolution: shader_library.h keeps main's constexpr fixed Huffman tables (no function-local static) with ItsNotRexed#7180's ZlibError return; docs/README.md keeps main's index.
LaugeM
left a comment
There was a problem hiding this comment.
This should merge second, right after #8461. The retail runs in the comments show it clears a real stop on integration stacks that are past device slot 26: the zlib reads of shaders.rpf and the slot 67 programs. On main plus #8461 alone the run stops at slot 26 (#6964) before any zlib request, so this is the next DirectStorage step, not the next stop on main.
The shim base is #4348's 45c39cf6f, not #8461's head. #8461 has one more commit, 077606cb4 (Close and CurrentOpenFileCount). A merge of this head onto #8461 (git merge-tree) conflicts only in docs/README.md (the directstorage.md row); dstorage.cpp and dstorage_test.cpp auto-merge. Onto main it also conflicts in docs/runtime_imports.md and runtime/CMakeLists.txt, so it should rebase onto #8461 and say Depends on: #8461.
Checked against the GDK DSTORAGE_REQUEST page
- With decompression
DestinationSizemust be larger thanSourceSize, and equal without it.dstorage.cpp:791-792enforces that. FileOffsetmust be 16-byte aligned ifZlibDecompressorBcpackModeis set.dstorage.cpp:801checks it for zlib. BCPack is refused earlier (line 777), so nothing is missed today, but the check has to coverBcpackMode != 0when BCPack lands.
Findings
- Confirmed (code):
dstorage.cpp:799keeps #8461's 32 MiB cap on address destinations, so a zlib read that inflates to more than 32 MiB is refused withE_DSTORAGE_REQUEST_TOO_LARGE, where the console allows it on 64 KiB or 2 MiB pages. The same note is on #8461. Whichever PR drops the cap, the zlib staging buffers stay bounded by the 1 GiB check at line 795. - Order: this changes
leonida::zlib_inflate's failure returns (runtime/src/shader_library.h). #8682, #8942 and #9566 edit the same inflater, and #8942 already depends on this PR. Land this one first, then those, since every zlib request now runs through it on the queue worker.
Tested
MSVC (VS 2026, x64, /W4 /permissive-), Windows 11, CPU only: dstorage_test from this head, 329 checks, 0 failures.
AI-assisted review (Opus 5.5). Read the diff against main; built dstorage_test with MSVC and ran it (329 checks, 0 failures), and merged this head onto #8461 with git merge-tree.
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