Skip to content

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

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
NiiRoZz:startup/list-occlusion-queries
Nov 25, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
NiiRoZz:startup/list-occlusion-queries

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 859e3e8 (on 05f3e6c, main 8e8b062). 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

Command-list slots 28, 29 and 30 were no-ops in the d3d12_xs stand-in. As a
hypothesis they are now implemented as BeginQuery(heap, type, index),
EndQuery(heap, type, index) and ResolveQueryData(heap, type, start, count,
buffer, offset) on the desktop list. Which console methods sit at those
slots is not established by any fixture here: 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 the slots directly, so it checks the
forwarding, the refusals and the end at Close, not the numbering.

Device slot 39 (CreateQueryHeap) keeps the desktop desc on the heap wrapper.
Only occlusion and binary-occlusion queries on an occlusion heap are
forwarded. Refused and logged (the first 16 of each method): a call outside
the heap's count, an EndQuery without its BeginQuery on the same list, and a
resolve over a query still open on the list, to anything but a committed
readback buffer without title memory, or past its end. A query still open at
Close is ended there, because the desktop Close would otherwise fail and
drop the whole list. The readback buffer stays in COPY_DEST and is not moved
through the list's COMMON state tracking.

startup_list_queries_{warp,hardware} resolves a query around a draw over an
8x8 target and an empty one into a sentinel-filled readback buffer, reads it
through the console Map (64 and 0, sentinel elsewhere), checks that six
mismatched calls reach no desktop validation, and leaves one query open at
Close. The startup_list_queries_ignored_*_control cases set
X2W_TEST_QUERY_IGNORE=1, which leaves the slots as no-ops, and must report
the untouched sentinel in the first word.

The comment in command_list_slot_names.h now says that the plus-four names
past slot 52 are unchecked; the 56 to 58 names are unchanged.

Refs R0Y00#870

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

…opt-in

Review follow-up. A resolve that covered a never-begun index, or one ended
with the other occlusion type, could reach ResolveQueryData and read
uninitialized query data.

- 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
  the index clears its completion; Close clears all of them with the rest of
  the recording state.
- The query slots refuse every command-list type other than DIRECT.
- Which console methods sit at slots 28 to 30 is still a hypothesis, so the
  bindings are now a diagnostic opt-in, X2W_D3D12_QUERY_SLOTS=1 (render
  mode). Unset, the three slots stay no-ops as before. The test-only
  X2W_TEST_QUERY_IGNORE is removed.
- startup_list_queries sets the opt-in and keeps both successful readbacks.
  New untouched-sentinel cases cover a never-begun index, a range with a
  hole and the wrong type. The control is now
  startup_list_queries_default_{warp,hardware}_control: it runs without the
  switch and must report the untouched sentinel in the first word.
- Known limit: a resolve recorded on a later list than the EndQuery calls it
  covers is refused.

Refs R0Y00#870

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@NiiRoZz

NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. New commit 859e3e8 (on top of 05f3e6c, 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).

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked 859e3e8. 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.

@R0Y00
R0Y00 merged commit bfe8a17 into R0Y00:main Nov 25, 2026
5 checks passed

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants