Repository navigation
runtime: console DirectStorage (DStorageGetFactory) with file-to-memory reads (takeover of #4348) - #8461
runtime: console DirectStorage (DStorageGetFactory) with file-to-memory reads (takeover of #4348)#8461KevinPratap wants to merge 12 commits into
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
…torage # Conflicts: # docs/README.md # runtime/CMakeLists.txt
|
Independent Wine check of
Wine can deliver the worker-thread guard exception in the control. The difference in the full queue path is still unresolved. All inputs were synthetic. AI-assisted with Codex. |
…es xg_xs.dll and the DirectStorage modules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent Windows check of this PR's
The stop is the last AI-assisted. |
|
Independent Windows Sandbox integration check of the code/test hunks from The synthetic |
|
Follow-up control in the same network-disabled Sandbox: the instrumented synthetic |
… guard counts file objects IDStorageFileX::Close closes the file whatever its reference count (GDK reference), and DSTORAGE_STATS::CurrentOpenFileCount counts open files, so the count now drops at Close, once, and not again when the object is released. The staging-size guard depends on file objects existing, closed or not, so it counts them separately (live_files). Reported by @ryotdev on ItsNotRexed#8461: open / Close / Release read 1 / 1 / 0 instead of 1 / 0 / 0. test_close_counts_and_staging pins it: Close, a second Close and Release keep the count right, and the staging size stays locked until the release. With the dstorage.cpp change set aside it fails 2 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@ryotdev, thanks, confirmed and fixed in
|
|
Retested I also ran a synthetic concurrency probe: eight threads called |
|
Follow-up to the RT-5 measurement claimed in #9522. Tested #8461 at
The first breakpoint on the reduced input is therefore not a failed DirectStorage OpenFile. The later breakpoint is unresolved and the VM had a reduced archive set. No game files, raw logs, or addresses attached. AI-assisted (Codex). |
|
RT-5 read-only full-package follow-up. Debian 13.6 / Wine 10.0, offline QEMU/KVM VM with no physical GPU, same comparison build as my preceding test (#7216
This confirms progress past the reduced-input stop and successful DirectStorage opens. The test guest has no working Vulkan configuration for this run. The precise trigger of the later breakpoint is still unconfirmed. No game bytes or raw logs attached. AI-assisted (Codex). |
|
Boot-level verification of this head, with the retail executable. This is the end-to-end test the shim tests can't do, and it is a clean before/after. Environment. Own Xbox 1.0.2.1 copy (the manifest under This head (
i.e. the factory comes back null and the title asserts 16 bytes later, and if you step over the assert it null-derefs 8 bytes after that. That is stop 5 of With #8461 merged, So the title now: creates the storage factory and opens a file through it, asks for HDR, calls The new first failure is stop 7 of that chain — device slot 26 — and here is exactly where it lands. After device creation the trace ends with: Symbolising the host frame against this build's own PDB,
Reproducible: the same fault address and stack with the RTSS/OBS layers explicitly disabled, so it is not a hook artifact. What I did not do: I did not run No game data was extracted, dumped or quoted. AI-assisted (OpenCode). |
|
Retail-boot evidence on the real 1.0.2.1 executable, with this takeover merged on origin/main 5d74c27 (local merge b3e6f604b): DStorageGetFactory is served; the console file interface is learned and OpenFile succeeds; 0 E_NOTIMPL requests (zlib/BCPack/swizzle/physical-page); D3D12XboxCreateDevice succeeds on the Vulkan RTX 3060; XMemAllocatePhysicalPages is served; the next stop is the documented slot-26 ABI swap (open #6964/#8930). Full ctest at that merge: 226 passed, 12 skipped, 1 disabled, only the 2 pre-existing GPU failures (d3d12_vulkan_device, d3d12_depth_resolve). Direct evidence the takeover works on the real image. |
|
One more data point, since it is about this PR's place in the chain rather than its code. With the retail title, this head already reaches stop 7 of So this PR is the first half of that chain: it clears storage (stops 5–6) and hands the run to the device path. Detail in my comment on #9171. No game data. AI-assisted (OpenCode). |
|
Tested Boot integration datapoint (base
Control: without the audio shims the same build stops earlier at a deterministic AV in the audio-object initialization ( |
|
Closing the gap I left in my earlier comment ("I did not run Head It passes: It is self-contained — it links Control (so the green run means something): forcing One optional nit, from the control, not a blocker. With the factory broken, the test does not stop at the assertion: Tree restored to |
LaugeM
left a comment
There was a problem hiding this comment.
This should be the first DirectStorage PR to merge. #7180, #7652 and #7924 build on its shim, and 077606cb4 merges cleanly into current main (5d74c2723). Line numbers below are at 077606cb4.
ABI against the GDK reference
DSTORAGE_REQUEST(runtime/shims/dstorage_xs_abi.h:154-185) matches the GDK declaration member for member, including theDestination/DestinationPageArray+DestinationPageOffsetunion, theFile+FileOffset/Source/SourcePageArrayunion andNamelast. Thestatic_asserts after it pin the offsets.DSTORAGE_REQUEST_OPTIONS(dstorage_xs_abi.h:118-130) has the GDK widths in the GDK order (1, 4, 16, 1, 1, 1, 40), so the bit positions the shim reads are right.- The status entry reports the first failure since the previous status entry or fence (
dstorage.cpp:748-758,since_notify_is reset by both), as theIDStorageStatusArrayXpage says. - Factory slots 6-8 (
SetCpuAffinity,SetDebugFlags,SetStagingBufferSize) are still a guess. The GDK lists the methods alphabetically, and no retail run has reached them yet.
Findings
- Confirmed (code), plausible retail impact:
dstorage.cpp:794refuses every address destination over 32 MiB withE_DSTORAGE_REQUEST_TOO_LARGE. The GDK allows a larger one when the buffer is on 64 KiB or 2 MiB pages, which is how the title's largeXMemAllocbuffers are made, so the console accepts reads the shim refuses. @seblessa reports reads of up to 128 MiB above. No retail run reported here has hit it yet. On the host the 4 KiB page limit protects nothing: keep the 1 GiB check at line 791 and drop line 794, or ask the xmem shim whether the range is a large-page allocation. - Confirmed:
docs/directstorage.mdpredates the import measurement. Main'sdocs/runtime_imports.md(RT-5 table, line 159) anddocs/audio_hal_exe_calls.md(XCRDAPI.dllsection) measure the import asXCRDAPI.dll!DStorageGetFactory, so line 11 ("its import table is unmeasured"), the "low" rating forxcrdapi.dllat line 29 and "The first boot ... settles most of this" at line 53 are out of date.docs/retail_boot_chain.md:21still names #4348 for stop 5 (#9193 fixes the same reference inaudio_hal_exe_calls.md:63), and theXCRDAPI.dllrow inruntime_imports.mdneeds the "served now" note thexg_xs.dllparagraph (lines 164-171) has. - Confirmed (built): #7343's commit
bc2e03estill merges onto this head with no conflict after077606cb4, and the mergeddstorage_testpasses on MSVC (280 checks, 0 failures). It only changestest_stats_timing, the fixture that fails 2 checks under Wine in the reports here. I would fold it in so this does not land with a test that fails under Wine. - Confirmed (code), minor:
EnqueueStatussets the entry toE_PENDING(dstorage.cpp:537) beforeenqueue. On a closing queueenqueuedrops the entry (dstorage.cpp:670-682, the log says "it never completes"), so that index staysE_PENDINGand a title pollingIsCompleteduring shutdown spins. Completing the entry withE_DSTORAGE_QUEUE_CLOSEDin that path ends the wait. - Plausible:
accept_query(dstorage.cpp:149-157) accepts only ids a creating call handed out for that kind. A title that getsIDStorageFactoryXand then asksQueryInterfacefor the X1 or X2 id (or a queue for X1 to callEnqueueSetEvent) getsE_NOINTERFACEalthough the object implements them. A retail log line "not an id a ... was created with" would be this case.
Tested
MSVC (VS 2026, x64, /W4 /permissive-), Windows 11, CPU only: dstorage_test from 077606cb4, 280 checks, 0 failures; the same with bc2e03e merged on top, 280, 0.
AI-assisted review (Opus 5.5). Read the diff against main; built dstorage_test with MSVC at 077606c and with #7343 merged on top (280 checks, 0 failures each).
|
Tested on the retail executable ( Finding: After H0 fixes the /GA TLS index 0 crash, the boot gets past the TLS callbacks and reaches the first unimplemented import:
This is the blocker that #8461 is implementing. I can confirm: with H0 on, all 5 runs consistently reach I cannot fetch PR #8461's branch to build and test it myself (remotes disabled on this checkout), but I can verify any build you provide on the retail executable with No game data in this report — module+RVA addresses only. |
|
Tested 077606c merged onto main 5d74c27 on Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4070 (driver 621.24), with the retail 1.0.2.1 executable (
No game data is quoted here. AI-assisted (Claude Code). |
…me.ps1 keeps main's list plus dstorage.cpp Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… new shims beside dstorage.cpp Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sks for
# What and why
Device slot 73 (`CreateCommandListX`) is handed the title's own command-list interface, measured on the retail
1.0.2.1 executable as `{c3827890-4024-474c-98cf-645b51dc4874}` — same first word as `ID3D12GraphicsCommandList6`
(`{c3827890-e548-4cfa-…}`) but not that interface, and no PC list answers it.
The proxy passed that IID straight down to the layer, which answered `E_NOINTERFACE` (`0x80004002`). Every
`CreateCommandList` therefore failed, the title received a null list, and it read through the null.
Three changes, all in `runtime/shims/d3d12_xs_device.cpp`:
- `kConsoleListIID` holds the measured GUID; `is_list_iid()` accepts it.
- `list_query_interface()` skips the PC `supports_iid` check for it: no PC list can answer an Xbox IID, and the
proxy answers it with itself.
- `proxy_create_command_list_x()` creates the list with `__uuidof(ID3D12GraphicsCommandList)` and lets `wrap_list()`
answer the console IID, instead of forwarding the title's IID to the layer.
## Tested
Retail 1.0.2.1 executable, Wine 11.22, `LEONIDA_D3D12=vulkan`, NVIDIA RTX 3060 Ti (GA103), `gta6rt --run`:
| | before | after |
|---|---|---|
| D3D12 calls | 13 | **1,181** |
| `CreateCommandList` | fails, `0x80004002` | 581 created and closed |
| last call reached | — | `XboxIDXGIDevice::GetAdapter` (ok) |
The run still stops later, in guest code (`read 0x18` inside a static initialiser), which is a separate stop.
Depends on: ProjectLeonida#8461
Depends on: ProjectLeonida#6964
Measured on top of those two and of the one-line `gameinput.dll!ProjectLeonida#1` ordinal alias (not a PR; the retail executable
imports GameInput by ordinal, so the registry never matched the shim). `main` alone stops earlier, at the DStorage
assert, so this change cannot show its effect without them.
## Item
New item. The `claiming:` line for the coordination issue could not be posted: this account is not a collaborator,
and the repository restricts interactions to collaborators. Whoever lands this should list it there.
## Note
`main` at this commit does not compile for clang-cl: `DescriptorHeap`/`identity()` in
`d3d12_vulkan_device.cpp` and the `SHAPE_*` static asserts in `acphal.cpp`. Those are unrelated to this change and
reported separately.
AI-assisted.
Takeover of #4348 by @mariuslozo-boop, who closed it today while stepping away and invited anyone to take it over. Claimed in the coordination issue: takeover claim. @aslan2142 released their DirectStorage finding to this.
This branch is their last head,
45c39cf6, with every original commit and author kept, plus one merge of currentmainthat resolves the two conflicts #4348 had. No other code changes. The design, the ABI evidence and its confidence, and the "not yet" list are in #4348's description and indocs/directstorage.md. In short:DStorageGetFactoryis served underdstorage_xs.dll,xcrdapi.dllanddstorage.dllwith the console ABI, with file-to-memory and memory-to-memory reads, status arrays, fences, events, cancel and errors. zlib, BCPack, swizzle and physical-page requests returnE_NOTIMPL.The merge
runtime/CMakeLists.txt: thedstoragetest registration came right after main'sif(WIN32 AND TARGET gta6rt_xtaskqueue)block. Main'sendif()for that block is kept, andif(WIN32 AND TARGET dstorage_test)follows it, as @0klavair noted.docs/README.md: main's rows are kept as they are, and only thedirectstorage.mdrow is added, beforegameinput.md. runtime: console DirectStorage (DStorageGetFactory) with file-to-memory reads #4348's older wording of thegameinput.mdrow is dropped.Why it matters now
It is retail boot stop 5 in
docs/retail_boot_chain.md. Measured on my own 1.0.2.1 copy (outbound network blocked,LEONIDA_D3D12=vulkan, RTX 4050 Laptop, NVIDIA 592.82, Windows 11). The runs usedmaindde82f27eplus #4313 (now #8379) and #6582, which clear stops 4 and 3, and #4348 at this same head45c39cf6:xcrdapi.dll!DStorageGetFactoryis unimplemented, and the title asserts on the null factory.IDStorageFactoryX::OpenFilegets the file interface, and the run goes on to a successfulD3D12XboxCreateDeviceon the Vulkan device. The next stop is device slot 26 (d3d12_xs: device slot 26 takes the return buffer in RCX and the device in RDX, as the retail executable calls it (RT-5) #6964).Tested on this head
Windows 11, RTX 4050 Laptop (NVIDIA 592.82), MSVC 14.44, RelWithDebInfo + Ninja:
ctest -R "dstorage|unimplemented_policy|xgameruntime|context_|wait_registration": 34/34 pass,dstorageincluded.ctest -j 8: 256 of 263 pass (22 of them are the usual skips for game data, SDL3 or GPU tools), 7 fail. They are the same 7 D3D12-layer tests that fail on this laptop without this branch (Loader: the mapped game executable owns module TLS index 0 (RT-259, takeover of #4313) #8379 lists them: six fail on a plainmainbuild, andd3d12_depth_resolvehits theExecuteCommandListscheck from d3d12: reject null arrays and invalid lists in ExecuteCommandLists #6610). This branch changes no D3D12 file.Open
dstoragechecks on45c39cf6(CachyOS, Wine 11.22, clang-cl/xwin): the guard-page timing fixture intest_stats_timingnever signals entry, and its pending-count check then fails. The copy and completion checks pass. I can't run Wine here, so this is not fixed or skipped. A Wine run of this head would help to tell whether Wine delivers the worker thread'sSTATUS_GUARD_PAGE_VIOLATIONto the vectored handler.AI-assisted (Claude Code). No game data: the boot results above are outcomes only.
🤖 Generated with Claude Code