startup: wait on the GPU for console queue Wait (slot 17) #1341

Merged
Jess-Doit merged 2 commits from upstream-pr/1348 into main 2026-11-24 09:09:04 +00:00
Jess-Doit commented 2026-11-24 08:52:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T08:52:28Z.


Change

The D3D12 stand-in (src/startup_stubs/d3d12_xs_device.cpp) sends unknown console queue slots to queue_dynamic, which picks an action from the argument shape. A (fence, value) call always became a desktop Signal. The comment there already noted that a Wait has the same shape, so a Wait completed its fence at once instead of waiting.

The stand-in already handles two queue slots from the title's calls: slot 18 is GetTimestampFrequency and slot 32 is the console present. On the desktop queue, Signal, Wait and GetTimestampFrequency are slots 14, 15 and 16. Slot 18 means the console queue has two more methods before them, which puts Signal at 16 and Wait at 17. That is an inference from the layout: no title call to slot 17 has been logged yet.

Now:

  • Slot 17: with a fence, it calls the desktop ID3D12CommandQueue::Wait(fence, value). Any other argument shape still goes through the shape dispatch.
  • Signals after a Wait: once a queue has waited, its Signals complete when the GPU reaches them, as they already do in X2W_D3D12_RENDER=1 mode. Outside render mode a Signal used to complete on the CPU at once, so the wait would have had no visible effect.
  • Other queue slots given a fence are unchanged and are still treated as Signals.

Fixture

tests/startup_queue_wait.cpp creates a device with D3D12XboxCreateDevice, then two queues and four fences through the stand-in, and calls the console queue slots directly.

Case Calls Must read
wait slot 17 Wait(F, 1), slot 16 Signal(G, 1) G = 0 after 250 ms and F still 0; after the CPU signals F (fence slot 10), G reaches 1
control the same calls with the wait on slot 15 G = 1 before F is signalled (the shape dispatch signals)

The control checks that the probe can detect a wait that signals. Against the stand-in on main, the wait case fails with exit 10 on both adapters (wait: slot 17, G=1 before F is signalled).

Verification

Tested b5804f60 (on d6cbd5d7) on Windows 10 22H2 19045.6456 with a GTX 1060 6 GB (10de:1c03, driver 32.0.15.6094) and in-box WARP (10.0.19041.5794). The D3D12 debug layer was enabled (X2W_D3D12_DEBUG=1).

. .\tools\dev.ps1
$env:XBOX2WINDOWS_ADAPTER = '1060'
cmake --preset dev
cmake --build --preset dev --target startup_queue_wait d3d12_xs_shim startup_stream_consumer xmem_shim startup_stub_xg_xs -j 2
ctest --preset dev --no-tests=error -R '^startup_(queue_wait_|stream_|mrt_|xg_bc7_draw_|address_srv_|xg_bc_chain_)' -V
cmake --preset release
cmake --build --preset release --target startup_queue_wait d3d12_xs_shim startup_stream_consumer xmem_shim startup_stub_xg_xs -j 2
ctest --preset release --no-tests=error -R '^startup_(queue_wait_|stream_)' -V
  • Debug: the 13 existing stream, MRT, BC7 draw, address SRV and BC chain tests passed on both adapters. In that run both startup_queue_wait_* tests failed at device creation, because their CMake tests did not set X2W_D3D12_PERMISSIVE=1 yet. With it set, which changed only CMakeLists.txt, they were rerun and passed 2/2.
  • Release: 5/5 passed: startup_queue_wait_* and startup_stream_*.
  • tests/docs_links_check.py: passed.

Probe output, the same on both adapters:

control: slot 15 as the wait, G=1 before F is signalled (shape dispatch signals)
wait: slot 17, G=0 before F is signalled
wait: after F=1 on the CPU, G=1

CI runs startup_queue_wait_warp in the Debug and Release Windows jobs; the _hardware test is local only.

Not covered

  • The console's 64-bit memory waits and writes on queues and command lists (Wait64BitValueX, Write64BitValueX) are not handled.
  • Signals that arrive on any other slot still complete their fence on the CPU at once outside render mode, as before.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6578090175 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1348). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T08:52:28Z. --- ## Change The D3D12 stand-in (`src/startup_stubs/d3d12_xs_device.cpp`) sends unknown console queue slots to `queue_dynamic`, which picks an action from the argument shape. A (fence, value) call always became a desktop `Signal`. The comment there already noted that a Wait has the same shape, so a Wait completed its fence at once instead of waiting. The stand-in already handles two queue slots from the title's calls: slot 18 is `GetTimestampFrequency` and slot 32 is the console present. On the desktop queue, `Signal`, `Wait` and `GetTimestampFrequency` are slots 14, 15 and 16. Slot 18 means the console queue has two more methods before them, which puts Signal at 16 and Wait at 17. That is an inference from the layout: no title call to slot 17 has been logged yet. Now: - **Slot 17:** with a fence, it calls the desktop `ID3D12CommandQueue::Wait(fence, value)`. Any other argument shape still goes through the shape dispatch. - **Signals after a Wait:** once a queue has waited, its Signals complete when the GPU reaches them, as they already do in `X2W_D3D12_RENDER=1` mode. Outside render mode a Signal used to complete on the CPU at once, so the wait would have had no visible effect. - **Other queue slots** given a fence are unchanged and are still treated as Signals. ## Fixture `tests/startup_queue_wait.cpp` creates a device with `D3D12XboxCreateDevice`, then two queues and four fences through the stand-in, and calls the console queue slots directly. | Case | Calls | Must read | |---|---|---| | wait | slot 17 `Wait(F, 1)`, slot 16 `Signal(G, 1)` | G = 0 after 250 ms and F still 0; after the CPU signals F (fence slot 10), G reaches 1 | | control | the same calls with the wait on slot 15 | G = 1 before F is signalled (the shape dispatch signals) | The control checks that the probe can detect a wait that signals. Against the stand-in on `main`, the wait case fails with exit 10 on both adapters (`wait: slot 17, G=1 before F is signalled`). ## Verification Tested `b5804f60` (on `d6cbd5d7`) on Windows 10 22H2 `19045.6456` with a GTX 1060 6 GB (`10de:1c03`, driver `32.0.15.6094`) and in-box WARP (`10.0.19041.5794`). The D3D12 debug layer was enabled (`X2W_D3D12_DEBUG=1`). ```powershell . .\tools\dev.ps1 $env:XBOX2WINDOWS_ADAPTER = '1060' cmake --preset dev cmake --build --preset dev --target startup_queue_wait d3d12_xs_shim startup_stream_consumer xmem_shim startup_stub_xg_xs -j 2 ctest --preset dev --no-tests=error -R '^startup_(queue_wait_|stream_|mrt_|xg_bc7_draw_|address_srv_|xg_bc_chain_)' -V cmake --preset release cmake --build --preset release --target startup_queue_wait d3d12_xs_shim startup_stream_consumer xmem_shim startup_stub_xg_xs -j 2 ctest --preset release --no-tests=error -R '^startup_(queue_wait_|stream_)' -V ``` - **Debug:** the 13 existing stream, MRT, BC7 draw, address SRV and BC chain tests passed on both adapters. In that run both `startup_queue_wait_*` tests failed at device creation, because their CMake tests did not set `X2W_D3D12_PERMISSIVE=1` yet. With it set, which changed only `CMakeLists.txt`, they were rerun and passed 2/2. - **Release:** 5/5 passed: `startup_queue_wait_*` and `startup_stream_*`. - **`tests/docs_links_check.py`:** passed. Probe output, the same on both adapters: ```text control: slot 15 as the wait, G=1 before F is signalled (shape dispatch signals) wait: slot 17, G=0 before F is signalled wait: after F=1 on the CPU, G=1 ``` CI runs `startup_queue_wait_warp` in the Debug and Release Windows jobs; the `_hardware` test is local only. ## Not covered - The console's 64-bit memory waits and writes on queues and command lists (`Wait64BitValueX`, `Write64BitValueX`) are not handled. - Signals that arrive on any other slot still complete their fence on the CPU at once outside render mode, as before. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 10:02:25 +00:00
tedin7 commented 2026-11-24 10:02:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:06:40Z.

Review: COMMENTED


Technical peer-review at commit b5804f60c91f65318e31ed646bd30fbc60db9ebb:

Verification

  • Linux:
    • git diff --check origin/main...HEAD: clean.
    • tests/docs_links_check.py: passed (16 Markdown files, 299 links).
    • tests/bidi_controls_check.py: passed (1120 tracked files).
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): cmake --build --preset dev --target startup_queue_wait succeeded (23.80s); ctest --preset dev -R '^startup_queue_wait_warp$' 1/1 passed (0.64s).
    • Release /O2 (--preset release): build succeeded (35.58s); ctest --preset release -R '^startup_queue_wait_warp$' 1/1 passed (0.64s).

Code & Test Notes

  • src/startup_stubs/d3d12_xs_device.cpp: queue_wait at tables[queue_kind][17] delegates non-fence arguments back to queue_dynamic<17>, records the queue in waiting_queues under waiting_queues_lock, and forwards to ID3D12CommandQueue::Wait. queue_dynamic checks queue_has_waited(self) so later Signals on that queue complete via complete_when_reached instead of immediate fence_reached.
  • tests/startup_queue_wait.cpp: covers both the slot-15 control (shape-dispatched immediate signal) and slot-17 GPU wait (verifying G stays 0 and F stays 0 until CPU F->Signal(1), after which G reaches 1).
  • Minor note: waiting_queues stores raw Wrapper* pointers without erasing on queue release; if a destroyed queue's address is later reused by a new queue wrapper, queue_has_waited would conservatively use complete_when_reached for its signals.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6036393220 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1348#pullrequestreview-6036393220). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:06:40Z. **Review:** COMMENTED --- Technical peer-review at commit `b5804f60c91f65318e31ed646bd30fbc60db9ebb`: ### Verification - **Linux**: - `git diff --check origin/main...HEAD`: clean. - `tests/docs_links_check.py`: passed (16 Markdown files, 299 links). - `tests/bidi_controls_check.py`: passed (1120 tracked files). - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: `cmake --build --preset dev --target startup_queue_wait` succeeded (`23.80s`); `ctest --preset dev -R '^startup_queue_wait_warp$'` **1/1 passed** (`0.64s`). - **Release `/O2` (`--preset release`)**: build succeeded (`35.58s`); `ctest --preset release -R '^startup_queue_wait_warp$'` **1/1 passed** (`0.64s`). ### Code & Test Notes - `src/startup_stubs/d3d12_xs_device.cpp`: `queue_wait` at `tables[queue_kind][17]` delegates non-fence arguments back to `queue_dynamic<17>`, records the queue in `waiting_queues` under `waiting_queues_lock`, and forwards to `ID3D12CommandQueue::Wait`. `queue_dynamic` checks `queue_has_waited(self)` so later `Signal`s on that queue complete via `complete_when_reached` instead of immediate `fence_reached`. - `tests/startup_queue_wait.cpp`: covers both the slot-15 control (shape-dispatched immediate signal) and slot-17 GPU wait (verifying `G` stays 0 and `F` stays 0 until CPU `F->Signal(1)`, after which `G` reaches 1). - Minor note: `waiting_queues` stores raw `Wrapper*` pointers without erasing on queue release; if a destroyed queue's address is later reused by a new queue wrapper, `queue_has_waited` would conservatively use `complete_when_reached` for its signals.
R0Y00 commented 2026-11-24 10:02:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:05:45Z.


I pushed a small follow-up to the same branch. The wait flag now lives on the queue wrapper, so recording the wait takes no allocation or global pointer registry. A failed desktop Signal also no longer updates the visible fence value. On f8ae5eb2, the queue-wait and stream-draw tests passed on RTX 4060 Laptop and WARP in Release (4/4). Waiting for CI on that exact head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126951855 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1348#issuecomment-7126951855). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T09:05:45Z. --- I pushed a small follow-up to the same branch. The wait flag now lives on the queue wrapper, so recording the wait takes no allocation or global pointer registry. A failed desktop Signal also no longer updates the visible fence value. On f8ae5eb2, the queue-wait and stream-draw tests passed on RTX 4060 Laptop and WARP in Release (4/4). Waiting for CI on that exact head.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1341
No description provided.