startup: forward occlusion queries on command-list slots 28 to 30 #2139

Merged
NiiRoZz merged 2 commits from upstream-pr/2147 into main 2026-11-25 02:09:53 +00:00
NiiRoZz commented 2026-11-25 01:39:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T01:39:41Z.


Change

Command-list slots 28, 29 and 30 are no-ops in the d3d12_xs stand-in. This adds a diagnostic opt-in,
X2W_D3D12_QUERY_SLOTS=1 (render mode), that binds them as BeginQuery(heap, type, index),
EndQuery(heap, type, index) and ResolveQueryData(heap, type, start, count, buffer, offset) on the desktop list.
Without the switch the three slots stay no-ops, exactly as before. Refs #870.

Which console methods sit at slots 28 to 30 is not established by any fixture here, so the bindings stay opt-in
until independent ABI evidence is available. The repository shows only that four console methods sit in 26 to 31
(32 is SetDescriptorHeaps, desktop 28 plus four) and that the plus-four run has ended by 61 (ExecuteIndirect,
desktop 59 plus two). The fixture calls those slots directly, so it checks the forwarding, the refusals and the end
at Close, not the numbering. The local observation below supports the numbering but cannot be reproduced from this
PR.

With the opt-in:

  • Device slot 39 (CreateQueryHeap) keeps forwarding the desc unchanged, and the desc is now kept on the heap
    wrapper (with or without the switch).
  • Only occlusion and binary-occlusion queries on an occlusion heap, on a DIRECT list, are forwarded.
  • A resolve is forwarded only if every index in its range has an observed EndQuery of the same type on the
    current recording. A new BeginQuery on an index clears its completion, and Close clears all of them.
  • Refused and logged (x2w-render ... refused, the first 16 of each method):
    • another command-list type;
    • an index or range outside the heap's count;
    • a second BeginQuery on an open index;
    • an EndQuery without its BeginQuery on the same list;
    • a resolve over any index not so ended: never begun, a hole in the range, ended with the other occlusion type,
      or still open;
    • a resolve to anything but a committed readback buffer without title memory, at an unaligned offset, or past
      the buffer's end.
  • A query still open at Close is ended there. Otherwise the desktop Close fails and the whole list is dropped.
  • The readback buffer stays in COPY_DEST and is not moved through the list's COMMON state tracking.

Scope:

  • A readback destination placed in title memory is refused, because the console Map returns that memory and a
    desktop resolve never reaches it. Only committed readback buffers work.
  • Pipeline-statistics queries are refused.

Known limit of this first slice: a resolve recorded on a later list than the EndQuery calls it covers is
refused. Whether a caller resolves on the same recording as its EndQuery calls has not been observed. The local
observation below was taken before this rule and counted calls only, not which recording they were on. If a caller
resolves on a later list, every resolve is refused and its buffer is left as the default leaves it.

Overlap: open PR #2048 places SetPredication at slot 59 "inside the shifted run", while this branch's hypothesis
would put the run's end before that. command_list_slot_names.h still names 56 to 58 as the query methods
(unchanged here; only its comment now says the plus-four rule is unchecked past 52).

Verification

Commit 859e3e8d (on 05f3e6cc, main 8e8b0621). Windows 11 Pro 10.0.26300, MSVC x64, dev preset, D3D12 debug
layer enabled. Run on a separate, never-shown desktop.

ctest --preset dev --no-tests=error -R startup_list_queries -V
ctest --preset dev --no-tests=error -R startup_command_list_slot_names -V

5 of 5 passed (startup_list_queries_{warp,hardware}, startup_list_queries_default_{warp,hardware}_control, startup_command_list_slot_names); no skips.

  • startup_list_queries_{warp,hardware} set X2W_D3D12_QUERY_SLOTS=1. Results:
    • query 0 = 64 and query 1 = 0 (both successful readbacks);
    • the untouched-sentinel cases are each refused and their words keep 0xa5: never begun (query 3), a range with
      a hole (5 to 7, 6 never begun), the wrong type (query 4 ended as binary occlusion, resolved as occlusion), a
      range over a still-open query, past the heap's count, and past the buffer's end;
    • no debug-layer errors.
  • WARP: Microsoft Basic Render Driver. Hardware: NVIDIA GeForce RTX 5090, driver 32.0.16.2135.
  • startup_list_queries_default_{warp,hardware}_control run without the switch: the stand-in logs the three slots
    as no-ops, and the probe reports word 0: got 0xa5a5a5a5a5a5a5a5, which the test requires. This shows the
    default keeps the previous slot behaviour.
  • By hand, mutants that each fail the probe:
    • dropping the resolve-completion check: exit 1, word 2: got 0x0000000000000000 on WARP and hardware;
    • forwarding an EndQuery without its BeginQuery: exit 3, the desktop Close fails;
    • not ending open queries at Close: exit 3, the desktop Close fails.

Evidence and follow-up

tests/startup_list_queries.cpp is source-built:

  • an HLSL full-target triangle compiled with D3DCompile;
  • an 8x8 RGBA8 target;
  • an occlusion heap of 8;
  • a 96-byte readback buffer prefilled with 0xa5.

It mixes console slots (device 8, 9, 27, 36, 39, 73; list 9, 28-30, 139; queue 10, 14; fence 8; resource 8) with
desktop calls for the draw.

Local observation, not reproducible from this PR: one local startup run of a console executable with the stand-ins,
with the earlier revision of this change (before the completion rule) plus a local counter that is not part of the
PR. Totals over about 5 minutes:

  • slots 28 and 29: 90,876 calls each, all forwarded;
  • slot 30: 5,451 calls, all forwarded;
  • query type 0 on every call;
  • highest index 40;
  • device slot 39: 4 occlusion heaps and 1 pipeline-statistics heap, largest count 2,460;
  • every resolve went to a committed readback buffer;
  • no refusals.

That is the call shape the hypothesis predicts. The resolved results were all zero, because no translated draw ran
in that run, so the values say nothing either way.

Not verified:

  • which console methods sit at slots 28 to 30, beyond that observation;
  • whether resolves arrive on the recording that ended their queries;
  • non-zero results in a run.

Follow-up: settle the numbering of 26 to 31 and of the shifted run past 52 (this branch, #2048 and #1972 depend on
it). If resolves turn out to arrive on a later recording, track completion per submitted recording.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted; the commands listed were run locally.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6595152957 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2147). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T01:39:41Z. --- ## Change Command-list slots 28, 29 and 30 are no-ops in the `d3d12_xs` stand-in. This adds a diagnostic opt-in, `X2W_D3D12_QUERY_SLOTS=1` (render mode), that binds them as `BeginQuery(heap, type, index)`, `EndQuery(heap, type, index)` and `ResolveQueryData(heap, type, start, count, buffer, offset)` on the desktop list. Without the switch the three slots stay no-ops, exactly as before. Refs #870. Which console methods sit at slots 28 to 30 is not established by any fixture here, so the bindings stay opt-in until independent ABI evidence is available. The repository shows only that four console methods sit in 26 to 31 (32 is `SetDescriptorHeaps`, desktop 28 plus four) and that the plus-four run has ended by 61 (`ExecuteIndirect`, desktop 59 plus two). The fixture calls those slots directly, so it checks the forwarding, the refusals and the end at Close, not the numbering. The local observation below supports the numbering but cannot be reproduced from this PR. With the opt-in: - Device slot 39 (`CreateQueryHeap`) keeps forwarding the desc unchanged, and the desc is now kept on the heap wrapper (with or without the switch). - Only occlusion and binary-occlusion queries on an occlusion heap, on a DIRECT list, are forwarded. - A resolve is forwarded only if every index in its range has an observed `EndQuery` of the same type on the current recording. A new `BeginQuery` on an index clears its completion, and Close clears all of them. - Refused and logged (`x2w-render ... refused`, the first 16 of each method): - another command-list type; - an index or range outside the heap's count; - a second `BeginQuery` on an open index; - an `EndQuery` without its `BeginQuery` on the same list; - a resolve over any index not so ended: never begun, a hole in the range, ended with the other occlusion type, or still open; - a resolve to anything but a committed readback buffer without title memory, at an unaligned offset, or past the buffer's end. - A query still open at Close is ended there. Otherwise the desktop Close fails and the whole list is dropped. - The readback buffer stays in `COPY_DEST` and is not moved through the list's COMMON state tracking. Scope: - A readback destination placed in title memory is refused, because the console `Map` returns that memory and a desktop resolve never reaches it. Only committed readback buffers work. - Pipeline-statistics queries are refused. Known limit of this first slice: a resolve recorded on a later list than the `EndQuery` calls it covers is refused. Whether a caller resolves on the same recording as its `EndQuery` calls has not been observed. The local observation below was taken before this rule and counted calls only, not which recording they were on. If a caller resolves on a later list, every resolve is refused and its buffer is left as the default leaves it. Overlap: open PR #2048 places `SetPredication` at slot 59 "inside the shifted run", while this branch's hypothesis would put the run's end before that. `command_list_slot_names.h` still names 56 to 58 as the query methods (unchanged here; only its comment now says the plus-four rule is unchecked past 52). ## Verification Commit 859e3e8d (on 05f3e6cc, main 8e8b0621). Windows 11 Pro 10.0.26300, MSVC x64, `dev` preset, D3D12 debug layer enabled. Run on a separate, never-shown desktop. ``` ctest --preset dev --no-tests=error -R startup_list_queries -V ctest --preset dev --no-tests=error -R startup_command_list_slot_names -V ``` 5 of 5 passed (`startup_list_queries_{warp,hardware}`, `startup_list_queries_default_{warp,hardware}_control`, `startup_command_list_slot_names`); no skips. - `startup_list_queries_{warp,hardware}` set `X2W_D3D12_QUERY_SLOTS=1`. Results: - query 0 = 64 and query 1 = 0 (both successful readbacks); - the untouched-sentinel cases are each refused and their words keep `0xa5`: never begun (query 3), a range with a hole (5 to 7, 6 never begun), the wrong type (query 4 ended as binary occlusion, resolved as occlusion), a range over a still-open query, past the heap's count, and past the buffer's end; - no debug-layer errors. - WARP: Microsoft Basic Render Driver. Hardware: NVIDIA GeForce RTX 5090, driver 32.0.16.2135. - `startup_list_queries_default_{warp,hardware}_control` run without the switch: the stand-in logs the three slots as no-ops, and the probe reports `word 0: got 0xa5a5a5a5a5a5a5a5`, which the test requires. This shows the default keeps the previous slot behaviour. - By hand, mutants that each fail the probe: - dropping the resolve-completion check: exit 1, `word 2: got 0x0000000000000000` on WARP and hardware; - forwarding an `EndQuery` without its `BeginQuery`: exit 3, the desktop Close fails; - not ending open queries at Close: exit 3, the desktop Close fails. ## Evidence and follow-up `tests/startup_list_queries.cpp` is source-built: - an HLSL full-target triangle compiled with D3DCompile; - an 8x8 RGBA8 target; - an occlusion heap of 8; - a 96-byte readback buffer prefilled with `0xa5`. It mixes console slots (device 8, 9, 27, 36, 39, 73; list 9, 28-30, 139; queue 10, 14; fence 8; resource 8) with desktop calls for the draw. Local observation, not reproducible from this PR: one local startup run of a console executable with the stand-ins, with the earlier revision of this change (before the completion rule) plus a local counter that is not part of the PR. Totals over about 5 minutes: - slots 28 and 29: 90,876 calls each, all forwarded; - slot 30: 5,451 calls, all forwarded; - query type 0 on every call; - highest index 40; - device slot 39: 4 occlusion heaps and 1 pipeline-statistics heap, largest count 2,460; - every resolve went to a committed readback buffer; - no refusals. That is the call shape the hypothesis predicts. The resolved results were all zero, because no translated draw ran in that run, so the values say nothing either way. Not verified: - which console methods sit at slots 28 to 30, beyond that observation; - whether resolves arrive on the recording that ended their queries; - non-zero results in a run. Follow-up: settle the numbering of 26 to 31 and of the shifted run past 52 (this branch, #2048 and #1972 depend on it). If resolves turn out to arrive on a later recording, track completion per submitted recording. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted; the commands listed were run locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
R0Y00 commented 2026-11-25 02:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T01:46:51Z.

Review: CHANGES_REQUESTED


list_resolve_query excludes indices still in open_queries, so a never-begun index or one ended with the other occlusion type can reach ResolveQueryData. An uninitialized resolve can remove the device. Please require an observed matching End for every index and type in the range. The first slice can limit this to Begin/End on the current DIRECT recording, clear the tracked completion on re-Begin/Reset, and refuse unsupported command-list types. Keep both successful result readbacks. Add untouched-sentinel controls for never begun, a range with a hole, and the wrong type. Microsoft ResolveQueryData contract

The test chooses slots 28–30 by construction. Since the console ABI is still a hypothesis explicitly called out in the PR, keep these bindings behind an explicit diagnostic opt-in until independent ABI evidence is available. The source-built readback can exercise that opt-in and demonstrate the default preserves the previous slot behavior.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050359444 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2147#pullrequestreview-6050359444). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T01:46:51Z. **Review:** CHANGES_REQUESTED --- `list_resolve_query` excludes indices still in `open_queries`, so a never-begun index or one ended with the other occlusion type can reach `ResolveQueryData`. An uninitialized resolve can remove the device. Please require an observed matching End for every index and type in the range. The first slice can limit this to Begin/End on the current DIRECT recording, clear the tracked completion on re-Begin/Reset, and refuse unsupported command-list types. Keep both successful result readbacks. Add untouched-sentinel controls for never begun, a range with a hole, and the wrong type. [Microsoft ResolveQueryData contract](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-resolvequerydata) The test chooses slots 28–30 by construction. Since the console ABI is still a hypothesis explicitly called out in the PR, keep these bindings behind an explicit diagnostic opt-in until independent ABI evidence is available. The source-built readback can exercise that opt-in and demonstrate the default preserves the previous slot behavior.
upstream-sync closed this pull request 2026-11-25 03:01:05 +00:00
R0Y00 commented 2026-11-25 03:01:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T02:09:41Z.

Review: APPROVED


Rechecked 859e3e8d. Resolution now requires an ended query of the same type for every index on the current DIRECT recording. The candidate keeps the uncertain slots opt-in. Local Windows Release passed the WARP and RTX 4060 Laptop query cases and the two default-off controls (4/4, no skips). The source-built slot tests establish forwarding and refusal behavior.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050603105 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2147#pullrequestreview-6050603105). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T02:09:41Z. **Review:** APPROVED --- Rechecked 859e3e8d. Resolution now requires an ended query of the same type for every index on the current DIRECT recording. The candidate keeps the uncertain slots opt-in. Local Windows Release passed the WARP and RTX 4060 Laptop query cases and the two default-off controls (4/4, no skips). The source-built slot tests establish forwarding and refusal behavior.
tedin7 commented 2026-11-25 03:01:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:10:14Z.

Review: COMMENTED


Review of head 859e3e8d8f4d50a55649f887eb78dc36da54fa25 (comment only, no approval).

Result: no P1, no P2. Two nits.

What I checked

  • Diff: 5 files, +489/-6 (CMakeLists.txt, docs/startup-runtime.md, command_list_slot_names.h, d3d12_xs_device.cpp, tests/startup_list_queries.cpp).
  • Opt-in only: slots 28 to 30 are bound only with X2W_D3D12_QUERY_SLOTS=1 (d3d12_xs_device.cpp:3933). The default path is unchanged, and a negative-control CTest (startup_list_queries_default_*_control) pins that.
  • D3D12 semantics, read against the code:
    • occlusion_heap (2010-2023) checks DIRECT list, heap kind, heap type, query type and range (count > Count - index has no overflow).
    • BeginQuery refuses a double begin and clears the ended entry for that index.
    • EndQuery requires a matching open query of the same type.
    • end_open_queries runs before release_targets in list_close, so a dangling Begin cannot fail the desktop Close. release_targets resets Pass{}, so ended_queries does not outlive a recording.
    • ResolveQueryData requires every index in range to be ended with the same type. It also checks for a readback buffer, 8-byte offset alignment, bounds and no title memory.
  • Title is neutral. The PR is mergeable. CI is green: Windows build and test, Python checks on Linux, gfx1013 fixtures.

Commands executed locally (Linux worktree at the head SHA)

  • python3 tests/docs_links_check.py -> self-test passed, 18 files, 399 links OK
  • python3 tests/bidi_controls_check.py -> self-test passed, 1440 files, no bidi controls
  • git diff --check origin/main...HEAD -> clean
  • gh pr checks 2147 -> all required jobs pass

Not run

  • startup_list_queries needs D3D12 (Windows only), so I did not run it or a source mutation on Linux. I read the test cases: they cover refused type, an End without a Begin, a Begin without an End (ended at Close), a resolve of a never-ended index, and an out-of-range offset. I relied on the green Windows CI job for execution. I did not request a separate Win2025 run.

Nits (non-blocking)

  1. d3d12_xs_device.cpp:2071: a ResolveQueryData with count == 0 passes the end-check loop (empty range) and is forwarded as a zero-length resolve. Consider refusing it, or add a test that pins the intended behavior.
  2. The slot numbering 28/29/30 is stated as a hypothesis, and the PR says so clearly. Keep the opt-in until ABI evidence exists. The docs/startup-runtime.md wording is consistent with this.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050609906 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2147#pullrequestreview-6050609906). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:10:14Z. **Review:** COMMENTED --- Review of head `859e3e8d8f4d50a55649f887eb78dc36da54fa25` (comment only, no approval). **Result: no P1, no P2. Two nits.** What I checked - Diff: 5 files, +489/-6 (`CMakeLists.txt`, `docs/startup-runtime.md`, `command_list_slot_names.h`, `d3d12_xs_device.cpp`, `tests/startup_list_queries.cpp`). - Opt-in only: slots 28 to 30 are bound only with `X2W_D3D12_QUERY_SLOTS=1` (`d3d12_xs_device.cpp:3933`). The default path is unchanged, and a negative-control CTest (`startup_list_queries_default_*_control`) pins that. - D3D12 semantics, read against the code: - `occlusion_heap` (2010-2023) checks DIRECT list, heap kind, heap type, query type and range (`count > Count - index` has no overflow). - `BeginQuery` refuses a double begin and clears the ended entry for that index. - `EndQuery` requires a matching open query of the same type. - `end_open_queries` runs before `release_targets` in `list_close`, so a dangling Begin cannot fail the desktop Close. `release_targets` resets `Pass{}`, so `ended_queries` does not outlive a recording. - `ResolveQueryData` requires every index in range to be ended with the same type. It also checks for a readback buffer, 8-byte offset alignment, bounds and no title memory. - Title is neutral. The PR is mergeable. CI is green: Windows build and test, Python checks on Linux, gfx1013 fixtures. Commands executed locally (Linux worktree at the head SHA) - `python3 tests/docs_links_check.py` -> self-test passed, 18 files, 399 links OK - `python3 tests/bidi_controls_check.py` -> self-test passed, 1440 files, no bidi controls - `git diff --check origin/main...HEAD` -> clean - `gh pr checks 2147` -> all required jobs pass Not run - `startup_list_queries` needs D3D12 (Windows only), so I did not run it or a source mutation on Linux. I read the test cases: they cover refused type, an End without a Begin, a Begin without an End (ended at Close), a resolve of a never-ended index, and an out-of-range offset. I relied on the green Windows CI job for execution. I did not request a separate Win2025 run. Nits (non-blocking) 1. `d3d12_xs_device.cpp:2071`: a `ResolveQueryData` with `count == 0` passes the end-check loop (empty range) and is forwarded as a zero-length resolve. Consider refusing it, or add a test that pins the intended behavior. 2. The slot numbering 28/29/30 is stated as a hypothesis, and the PR says so clearly. Keep the opt-in until ABI evidence exists. The `docs/startup-runtime.md` wording is consistent with this. AI-assisted; commands listed were executed locally.
NiiRoZz commented 2026-11-25 03:01:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T02:02:24Z.


Thanks. New commit 859e3e8d (on top of 05f3e6cc, no force-push): a resolve is forwarded only if every index in its range has an observed EndQuery of the same type on the current DIRECT recording. Re-Begin clears an index's completion, Close clears all of them, and other list types are refused.

The 28–30 bindings are now behind the diagnostic opt-in X2W_D3D12_QUERY_SLOTS=1. Unset, the slots stay no-ops as on main, and startup_list_queries_default_{warp,hardware}_control checks that (untouched sentinel, pinned by PASS_REGULAR_EXPRESSION).

The fixture keeps both readbacks (64 and 0) and adds untouched-sentinel cases for never begun, a range with a hole, and the wrong type. 5/5 pass on WARP and an RTX 5090 with the debug layer on.

Known limit, stated in the docs: a resolve recorded on a later list than its EndQuery calls is refused. Whether callers resolve on the same recording is not yet observed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7150246382 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2147#issuecomment-7150246382). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T02:02:24Z. --- Thanks. New commit 859e3e8d (on top of 05f3e6cc, no force-push): a resolve is forwarded only if every index in its range has an observed EndQuery of the same type on the current DIRECT recording. Re-Begin clears an index's completion, Close clears all of them, and other list types are refused. The 28–30 bindings are now behind the diagnostic opt-in `X2W_D3D12_QUERY_SLOTS=1`. Unset, the slots stay no-ops as on main, and `startup_list_queries_default_{warp,hardware}_control` checks that (untouched sentinel, pinned by PASS_REGULAR_EXPRESSION). The fixture keeps both readbacks (64 and 0) and adds untouched-sentinel cases for never begun, a range with a hole, and the wrong type. 5/5 pass on WARP and an RTX 5090 with the debug layer on. Known limit, stated in the docs: a resolve recorded on a later list than its EndQuery calls is refused. Whether callers resolve on the same recording is not yet observed. AI-assisted (Claude Code).
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!2139
No description provided.