startup: start DirectStorage status-array slots complete with S_OK #1847

Manually merged
github merged 2 commits from gh-pr/1847/head into gh-pr/1847/base 2026-11-26 23:37:22 +00:00
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 19:29 UTC · original
Jess-Doit:startup/dstorage-status-initial → main · +89 −1 · 4 files · 2 commits · merged 2026-11-24 19:52 UTC

Refs #1843 (slice 1)

Change

factory_create_status_array in src/startup_stubs/xcrdapi.cpp used to set every new slot to E_PENDING. So IsComplete(i) was false, and GetHResult(i) returned E_PENDING, for a slot nothing had been enqueued into. A caller that polls a ring slot before its first use would wait forever.

New slots now start complete with S_OK. EnqueueStatus still marks its slot E_PENDING until the entries before it have run. Completion and out-of-range handling are unchanged.

Source: Microsoft's Win32 implementation of the API, in Xbox-GDK-Samples (MIT), Samples/System/SimpleDirectStorageCombo/DirectStorageWin32/DirectStorageWin32WrapperStatusArray.cpp:

m_completeFlags.resize(capacity, true);
m_resultCodes.resize(capacity, HRESULT_FROM_WIN32(S_OK));

There, only EnqueueStatus marks a slot not complete. docs/startup-runtime.md records the behaviour and the source.

Fixture

startup_stub_consumer dstorage-status-initial runs from the startup_stubs check:

  1. Fresh array: a new array of 4 has every slot complete with S_OK. Index 4 stays refused: not complete, E_INVALIDARG.
  2. Pending behind a fence: the queue's worker is held inside a fence signal, then EnqueueStatus puts slot 2 behind it. While held, slot 2 reads not complete with E_PENDING, and slots 0, 1 and 3 keep S_OK.
  3. Release: after the worker is released, slot 2 completes with S_OK.

Control: restoring the E_PENDING initialization makes the check fail at the first fresh slot: dstorage-status-initial: fresh slot 0 complete=0 hr=0x8000000a, exit 10.

Verification

Tested f8101db1 on main 82749f0f. Windows 10 22H2 build 19045.6456, MSVC from tools/dev.ps1. No GPU is involved.

. .\tools\dev.ps1
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset
    cmake --build --preset $preset --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim
    ctest --preset $preset --no-tests=error -R '^(startup_stubs|startup_storage_directory_batch|docs_links)$'
}
  • Debug and Release: 3/3 each. The existing DirectStorage controls in startup_stubs (the BCPack summary, dstorage and dstorage-pages) still pass, and so does startup_storage_directory_batch.
  • CI: the pull-request preset's smoke subset doesn't include startup_stubs, so this check runs locally (#1149 tracks running the stand-in checks in CI).

Slice 2 (RetrieveErrorRecord and the error event) will be a separate PR.

AI-assisted (Claude Code).

**@⁠Jess-Doit** on GitHub · 2026-11-24 19:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1847) `Jess-Doit:startup/dstorage-status-initial` → `main` · +89 −1 · 4 files · 2 commits · merged 2026-11-24 19:52 UTC Refs #1843 (slice 1) ### Change `factory_create_status_array` in `src/startup_stubs/xcrdapi.cpp` used to set every new slot to `E_PENDING`. So `IsComplete(i)` was false, and `GetHResult(i)` returned `E_PENDING`, for a slot nothing had been enqueued into. A caller that polls a ring slot before its first use would wait forever. New slots now start complete with `S_OK`. `EnqueueStatus` still marks its slot `E_PENDING` until the entries before it have run. Completion and out-of-range handling are unchanged. **Source:** Microsoft's Win32 implementation of the API, in Xbox-GDK-Samples (MIT), `Samples/System/SimpleDirectStorageCombo/DirectStorageWin32/DirectStorageWin32WrapperStatusArray.cpp`: ```cpp m_completeFlags.resize(capacity, true); m_resultCodes.resize(capacity, HRESULT_FROM_WIN32(S_OK)); ``` There, only `EnqueueStatus` marks a slot not complete. `docs/startup-runtime.md` records the behaviour and the source. ### Fixture `startup_stub_consumer dstorage-status-initial` runs from the `startup_stubs` check: 1. **Fresh array:** a new array of 4 has every slot complete with `S_OK`. Index 4 stays refused: not complete, `E_INVALIDARG`. 2. **Pending behind a fence:** the queue's worker is held inside a fence signal, then `EnqueueStatus` puts slot 2 behind it. While held, slot 2 reads not complete with `E_PENDING`, and slots 0, 1 and 3 keep `S_OK`. 3. **Release:** after the worker is released, slot 2 completes with `S_OK`. **Control:** restoring the `E_PENDING` initialization makes the check fail at the first fresh slot: `dstorage-status-initial: fresh slot 0 complete=0 hr=0x8000000a`, exit 10. ### Verification Tested `f8101db1` on main `82749f0f`. Windows 10 22H2 build 19045.6456, MSVC from `tools/dev.ps1`. No GPU is involved. ```powershell . .\tools\dev.ps1 foreach ($preset in 'dev', 'release') { cmake --preset $preset cmake --build --preset $preset --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim ctest --preset $preset --no-tests=error -R '^(startup_stubs|startup_storage_directory_batch|docs_links)$' } ``` - **Debug and Release:** 3/3 each. The existing DirectStorage controls in `startup_stubs` (the BCPack summary, `dstorage` and `dstorage-pages`) still pass, and so does `startup_storage_directory_batch`. - **CI:** the pull-request preset's smoke subset doesn't include `startup_stubs`, so this check runs locally (#1149 tracks running the stand-in checks in CI). Slice 2 (`RetrieveErrorRecord` and the error event) will be a separate PR. AI-assisted (Claude Code).
A new status array's slots were E_PENDING, so IsComplete was false for a
slot nothing had been enqueued into. Microsoft's Win32 implementation of
the API (Xbox-GDK-Samples) starts every slot complete with S_OK, and only
EnqueueStatus marks a slot pending. The consumer check covers a fresh
array, a slot held pending behind a fence signal while the others stay
complete, and its completion (#1843).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:37:20 +00:00
github manually merged commit 7e13965bf2 into gh-pr/1847/base 2026-11-26 23:37:22 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 19:49 UTC · original

I kept the initial/pending/completed status checks and widened only the new fixture's synthetic queue descriptor. The shim records 40 bytes at CreateQueue, so the former 32-byte array let the diagnostic read eight bytes outside the fixture. With the 40-byte aligned array, Release rebuilt and dstorage-status-initial passed, including the held pending slot and completion. The production status change is unchanged.

**@⁠R0Y00** on GitHub · 2026-11-24 19:49 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1847#issuecomment-7142639429) I kept the initial/pending/completed status checks and widened only the new fixture's synthetic queue descriptor. The shim records 40 bytes at CreateQueue, so the former 32-byte array let the diagnostic read eight bytes outside the fixture. With the 40-byte aligned array, Release rebuilt and dstorage-status-initial passed, including the held pending slot and completion. The production status change is unchanged.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:36 UTC · original · reviewed

Peer review of head f8101db16f67169544cd89cf140f225f05129923.

Result: no P1/P2 defects found in the diff and the Linux checks. This head was not built or run on Windows in this review: the C++ change and the new consumer check (dstorage-status-initial) are verified by reading only.

Read in full: the diff (src/startup_stubs/xcrdapi.cpp, tests/startup_stub_consumer.cpp, tests/startup_stub_check.py, docs/startup-runtime.md) and the status-array code around it.

  • factory_create_status_array now starts every slot at S_OK. status_is_complete is results[i] != E_PENDING and status_get_hresult returns the slot, so a slot nothing was enqueued into reads complete with S_OK. An index past the capacity still reports not complete and E_INVALIDARG.
  • The only writer of E_PENDING is now queue_enqueue_status (xcrdapi.cpp:1188), which sets it when the entry is enqueued, before Submit. The worker completes the slot in order (:756), and fail_unstarted (:918) completes it on the failure path, so a status entry that is recorded or deferred never stays pending. Every existing consumer check that polls a slot does so after EnqueueStatus on that slot (for example lines 551-553, 581-583, 750-755, 1151-1154, 1299-1300, 1570-1584), so none of them can now see the slot complete before its turn.
  • New check: a fresh array of four slots, all complete with S_OK, plus the out-of-range index; then a fence-signal entry that holds the worker, EnqueueStatus on slot 2 behind it, and a check that slot 2 is E_PENDING while slots 0, 1 and 3 stay S_OK; after releasing the worker, slot 2 completes with S_OK and the gate records the resume. The hold uses the same SubmitGate and hold_worker pattern as the existing check at line 1290, and every symbol it uses is declared above it. The pending state is set at enqueue time, so the "held" assertion does not depend on timing.

Non-blocking notes (P3):

  • src/startup_stubs/xcrdapi.cpp:55 still says "E_PENDING until a status is enqueued" for results, which now describes the old initial state. docs/startup-runtime.md:729 ("nothing is left at E_PENDING") still holds.
  • In tests/startup_stub_check.py the new block was inserted between the comment "# Page arrays changed between EnqueueRequest and Submit..." and the dstorage-pages run it describes, so that comment now sits above the wrong block.

Linux checks run locally in a clean worktree at this head:

  • git diff --check origin/main...HEAD: clean
  • tests/docs_links_check.py: passed (18 files, 370 links)
  • tests/bidi_controls_check.py: passed (1322 files)
  • tests/startup_stub_check.py: not runnable on Linux (it needs the Windows consumer executable and loads DLLs through ctypes.WinDLL).

No local mutation was possible: the behavior lives in the Windows-only consumer and stub DLL. Suggested mutation for a Windows run: change the initial value back to E_PENDING in factory_create_status_array; dstorage-status-initial should then fail on its first fresh-slot check.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 19:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1847#pullrequestreview-6046046109) · **reviewed** Peer review of head `f8101db16f67169544cd89cf140f225f05129923`. **Result: no P1/P2 defects found in the diff and the Linux checks. This head was not built or run on Windows in this review: the C++ change and the new consumer check (`dstorage-status-initial`) are verified by reading only.** Read in full: the diff (`src/startup_stubs/xcrdapi.cpp`, `tests/startup_stub_consumer.cpp`, `tests/startup_stub_check.py`, `docs/startup-runtime.md`) and the status-array code around it. - `factory_create_status_array` now starts every slot at `S_OK`. `status_is_complete` is `results[i] != E_PENDING` and `status_get_hresult` returns the slot, so a slot nothing was enqueued into reads complete with `S_OK`. An index past the capacity still reports not complete and `E_INVALIDARG`. - The only writer of `E_PENDING` is now `queue_enqueue_status` (`xcrdapi.cpp:1188`), which sets it when the entry is enqueued, before Submit. The worker completes the slot in order (`:756`), and `fail_unstarted` (`:918`) completes it on the failure path, so a status entry that is recorded or deferred never stays pending. Every existing consumer check that polls a slot does so after `EnqueueStatus` on that slot (for example lines 551-553, 581-583, 750-755, 1151-1154, 1299-1300, 1570-1584), so none of them can now see the slot complete before its turn. - New check: a fresh array of four slots, all complete with `S_OK`, plus the out-of-range index; then a fence-signal entry that holds the worker, `EnqueueStatus` on slot 2 behind it, and a check that slot 2 is `E_PENDING` while slots 0, 1 and 3 stay `S_OK`; after releasing the worker, slot 2 completes with `S_OK` and the gate records the resume. The hold uses the same `SubmitGate` and `hold_worker` pattern as the existing check at line 1290, and every symbol it uses is declared above it. The pending state is set at enqueue time, so the "held" assertion does not depend on timing. Non-blocking notes (P3): - `src/startup_stubs/xcrdapi.cpp:55` still says "E_PENDING until a status is enqueued" for `results`, which now describes the old initial state. `docs/startup-runtime.md:729` ("nothing is left at `E_PENDING`") still holds. - In `tests/startup_stub_check.py` the new block was inserted between the comment "# Page arrays changed between EnqueueRequest and Submit..." and the `dstorage-pages` run it describes, so that comment now sits above the wrong block. Linux checks run locally in a clean worktree at this head: - `git diff --check origin/main...HEAD`: clean - `tests/docs_links_check.py`: passed (18 files, 370 links) - `tests/bidi_controls_check.py`: passed (1322 files) - `tests/startup_stub_check.py`: not runnable on Linux (it needs the Windows consumer executable and loads DLLs through `ctypes.WinDLL`). No local mutation was possible: the behavior lives in the Windows-only consumer and stub DLL. Suggested mutation for a Windows run: change the initial value back to `E_PENDING` in `factory_create_status_array`; `dstorage-status-initial` should then fail on its first fresh-slot check. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.