GPU: occlusion queries measure on the host instead of reporting every draw visible #1731

Open
github-bot wants to merge 4 commits from github-bot/gh-1731 into main AGit
Owner

@⁠fiestorra on GitHub · 2026-11-24 21:30 UTC · original
fiestorra:gpu/real-occlusion-queries → main · +482 −19 · 4 files · 4 commits · open

Occlusion queries now measure instead of answering "visible"

BeginQuery and EndQuery were wired to the same no-op function, so the two could not be told apart at all, and ResolveQueryData answered every occlusion query with a fixed value:

    let (what, bytes) = match kind {
        OCCLUSION => (Written::Value(1 << 20), 8),
        BINARY => (Written::Value(1), 8),

Serveral consequences, all silent: the title's own occlusion culling could never cull anything, and its dynamic resolution could never lower a resolution — the fixed "a million samples passed" means every occluder looks fully visible, in every world frame. This is H-8.1 of the #1317 report.

What it does now

  • An occlusion heap makes the host's own heap, D3D12_QUERY_HEAP_TYPE_OCCLUSION with the same count (that one heap type answers both the sample-count and the pass/fail query types). Heaps of the other kinds stay as they were.
  • BeginQuery/EndQuery are two functions again, and each marks the host list when the heap measures there, so the draws recorded between them are what the query counts.
  • ResolveQueryData resolves those queries on the host into a read-back buffer, kept alive with the list; once the submission that filled it has finished, its values are written into the title's buffer at the offsets asked for. Results are written before the bottom-of-pipe writes, in case the title names the same memory in both.
  • Timestamps, pipeline statistics and everything else keep the plausible-value path, and its shortcut: note now says exactly which kinds those are.

Verification

The new test goes through the real path — our query heap, our list, our queue, the host device — with four queries marked around no draws:

$ cargo test -p victory-gpu --locked occlusion
test result: ok. 1 passed; 0 failed

and it is discriminating: with the old fixed answer forced back on (measured = false), the same test fails with

assertion `left == right` failed: nothing was drawn, so nothing passed
  left: [1048576, 1048576, 1048576, 1048576]
 right: [0, 0, 0, 0]

so the change is what moves the value, not the test being tautological. It also checks that the rest of the title's buffer is left alone, and that the host really made the heap (it panics rather than passing silently if the heap creation fails on this machine).

  • cargo test -p victory-gpu --locked → 51 passed, 1 ignored.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings → clean.
  • rustfmt --check on the added lines → clean (the file's pre-existing hunks are untouched, as in the rest of the crate).
  • cargo test --workspace --locked has one failure, modules::display::tests::sdr_and_display_deferrals, which fails on main too in this environment (a headless session: the display stack answers E_NOT_SUPPORTED); it is unrelated to this change and is fixed by #1630.

What is not done, and what could not be measured

  • Timestamps are still the process clock, not the GPU's: ID3D12Device::GetClockCalibration and a real timestamp heap are a separate change, and with every submission waited for the two would be close anyway.
  • I could not run the title: this machine has no presentable desktop (the agent runs in session 0), so the world cannot be reached, and no in-game measurement of culled draws is included here. The unit test is the evidence; the adapter it ran on is the integrated AMD Radeon(TM) Graphics (driver 32.0.21045.29003), which is DXGI's default on this machine. Worlds on NVIDIA also want this, since the value was fixed regardless of adapter.
  • The console's query heaps can be marked across lists; here a mark is recorded into the host list that receives it, which is what the title does.

No game data is involved: query types, counts and the test's own synthetic draws.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 21:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731) `fiestorra:gpu/real-occlusion-queries` → `main` · +482 −19 · 4 files · 4 commits · open **Occlusion queries now measure instead of answering "visible"** `BeginQuery` and `EndQuery` were wired to the same no-op function, so the two could not be told apart at all, and `ResolveQueryData` answered every occlusion query with a fixed value: ```rust let (what, bytes) = match kind { OCCLUSION => (Written::Value(1 << 20), 8), BINARY => (Written::Value(1), 8), ``` Serveral consequences, all silent: the title's own occlusion culling could never cull anything, and its dynamic resolution could never lower a resolution — the fixed "a million samples passed" means every occluder looks fully visible, in every world frame. This is H-8.1 of the #1317 report. ### What it does now - **An occlusion heap makes the host's own heap**, `D3D12_QUERY_HEAP_TYPE_OCCLUSION` with the same count (that one heap type answers both the sample-count and the pass/fail query types). Heaps of the other kinds stay as they were. - **`BeginQuery`/`EndQuery` are two functions again**, and each marks the host list when the heap measures there, so the draws recorded between them are what the query counts. - **`ResolveQueryData` resolves those queries on the host** into a read-back buffer, kept alive with the list; once the submission that filled it has finished, its values are written into the title's buffer at the offsets asked for. Results are written before the bottom-of-pipe writes, in case the title names the same memory in both. - Timestamps, pipeline statistics and everything else keep the plausible-value path, and its `shortcut:` note now says exactly which kinds those are. ### Verification The new test goes through the real path — our query heap, our list, our queue, the host device — with four queries marked around **no draws**: ``` $ cargo test -p victory-gpu --locked occlusion test result: ok. 1 passed; 0 failed ``` and it is discriminating: with the old fixed answer forced back on (`measured = false`), the same test fails with ``` assertion `left == right` failed: nothing was drawn, so nothing passed left: [1048576, 1048576, 1048576, 1048576] right: [0, 0, 0, 0] ``` so the change is what moves the value, not the test being tautological. It also checks that the rest of the title's buffer is left alone, and that the host really made the heap (it panics rather than passing silently if the heap creation fails on this machine). - `cargo test -p victory-gpu --locked` → 51 passed, 1 ignored. - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings` → clean. - `rustfmt --check` on the added lines → clean (the file's pre-existing hunks are untouched, as in the rest of the crate). - `cargo test --workspace --locked` has one failure, `modules::display::tests::sdr_and_display_deferrals`, which fails on `main` too in this environment (a headless session: the display stack answers `E_NOT_SUPPORTED`); it is unrelated to this change and is fixed by https://git.gtahub.st/github/Marvisak--VIctory/pulls/1630. ### What is not done, and what could not be measured - **Timestamps are still the process clock**, not the GPU's: `ID3D12Device::GetClockCalibration` and a real timestamp heap are a separate change, and with every submission waited for the two would be close anyway. - **I could not run the title**: this machine has no presentable desktop (the agent runs in session 0), so the world cannot be reached, and no in-game measurement of culled draws is included here. The unit test is the evidence; the adapter it ran on is the integrated `AMD Radeon(TM) Graphics` (driver `32.0.21045.29003`), which is DXGI's default on this machine. Worlds on NVIDIA also want this, since the value was fixed regardless of adapter. - The console's query heaps can be marked across lists; here a mark is recorded into the host list that receives it, which is what the title does. No game data is involved: query types, counts and the test's own synthetic draws. Written with an AI assistant.
BeginQuery and EndQuery both went to the same no-op, so the two could not be
told apart, and ResolveQueryData answered every occlusion query with a fixed
1<<20 samples (1 for the binary form): the title's occlusion culling and its
dynamic resolution therefore could not work, which costs overdraw in every
world frame.

An occlusion heap now also makes the host's own heap of the same count, the
list marks Begin/End on the host list, and ResolveQueryData resolves into a
read-back buffer whose contents are written into the title's memory once the
submission that filled it has finished. The other query kinds keep their
plausible-value path, since nothing measures them yet.

The test runs an occlusion query around no draws through our own heaps, list
and queue: the title's buffer receives zeros, where the old stub wrote
1048576.

(cherry picked from commit c7672039f702dd6a7f69cad5c3d067e6abf7b867)
Review of the query path, all four points taken:

- the heap's kind is a D3D12 query *heap* type, where 1 is TIMESTAMP, not
  a query type: only an occlusion heap makes a host heap now, so a timestamp
  heap no longer gets one it would never use;
- the query type is the one BeginQuery/EndQuery/ResolveQueryData name, so a
  binary occlusion query resolves as the pass/fail form instead of as a
  sample count;
- a mark the host would refuse (an end without a begin) is not recorded,
  and a resolve needs every index inside the heap and ended: D3D12 refuses
  an open query and one never marked has no value to write into title
  memory.

The GPU test pins the three: a timestamp heap takes no occlusion query, a
query never marked has no value, an index at the count is outside the heap.

(cherry picked from commit c4f233427bde77a01858eb220a8252ccf8c17a8f)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:09 +00:00
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 21:37 UTC · original · reviewed

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Occlusion queries measured on the host: query_begin/query_end/mark record into a host D3D12_QUERY_HEAP, resolve_queries defers resolution (defer_resolve) with a readback buffer, and occlusion_for_test exposes a test hook. Previously every draw reported 'passed' — now it measures. The deferred-resolve design (resolve when the title reads results, not at query end) matches D3D12 semantics. Windows-only; the one test (an_occlusion_query_reports_what_the_draws_passed) needs a device.

**@⁠catminou4** on GitHub · 2026-11-24 21:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#pullrequestreview-6047812890) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Occlusion queries measured on the host: query_begin/query_end/mark record into a host D3D12_QUERY_HEAP, resolve_queries defers resolution (defer_resolve) with a readback buffer, and occlusion_for_test exposes a test hook. Previously every draw reported 'passed' — now it measures. The deferred-resolve design (resolve when the title reads results, not at query end) matches D3D12 semantics. Windows-only; the one test (an_occlusion_query_reports_what_the_draws_passed) needs a device.
Author
Owner

@⁠kais7654 on GitHub · 2026-11-24 21:47 UTC · original

Reviewed this — the approach is right (host occlusion heap, Begin/End on
the host list, read-back written into title memory after the submission
waits), and I verified cargo check, clippy and cargo test -p victory-gpu
(51 passed, including the new test).

Two problems I found:

  1. resolve_queries takes the measured path without checking whether the
    range fits the heap. If ResolveQueryData refuses the resolve (range
    past the heap's count, count == 0), the read-back buffer stays
    untouched with undefined contents, and those garbage u64s are still
    written into the title's memory — worse than the stub's plausible
    values. Fix: check first + count against the heap's count (and
    count > 0) in the measured path's condition, so a refused range falls
    back to the stubs. Ready as a patch, happy to push it.

  2. A failing Map of the read-back buffer silently drops the results:
    worth a tracing::warn! like the other deferred failures.

Also opened a stacked PR with a patch for 1 and 2 (from my fork, branch
pr-1731-feedback).

**@⁠kais7654** on GitHub · 2026-11-24 21:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7145386078) Reviewed this — the approach is right (host occlusion heap, Begin/End on the host list, read-back written into title memory after the submission waits), and I verified `cargo check`, clippy and `cargo test -p victory-gpu` (51 passed, including the new test). Two problems I found: 1. `resolve_queries` takes the measured path without checking whether the range fits the heap. If `ResolveQueryData` refuses the resolve (range past the heap's count, count == 0), the read-back buffer stays untouched with undefined contents, and those garbage u64s are still written into the title's memory — worse than the stub's plausible values. Fix: check `first + count` against the heap's count (and count > 0) in the measured path's condition, so a refused range falls back to the stubs. Ready as a patch, happy to push it. 2. A failing `Map` of the read-back buffer silently drops the results: worth a `tracing::warn!` like the other deferred failures. Also opened a stacked PR with a patch for 1 and 2 (from my fork, branch `pr-1731-feedback`).
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 21:53 UTC · original

Rebased onto main (70564ae): the conflict was the list's method table

main gained three clears (ClearUnorderedAccessViewUint, …Float, DiscardResource) at slots 0x1a8/0x1b0/0x1b8, so MORE_METHODS grew from 9 to 12 entries and both sides had edited it. The resolution keeps main's entries and only swaps the two query slots:

const MORE_METHODS: [(usize, *const ()); 12] = [
    (53, state::clear_unordered_uint as *const ()),  // 0x1a8
    (54, state::clear_unordered_float as *const ()), // 0x1b0
    (55, ignored_state as *const ()),                // 0x1b8 DiscardResource
    (28, query_begin as *const ()),                  // 0xe0 BeginQuery
    (29, query_end as *const ()),                    // 0xe8 EndQuery
    ...

Everything else applied as-is: the occlusion heap in query.rs, the read-back buffer and the resolve replay in host.rs, and the test in resource.rs.

Verification after the rebase:

  • cargo test -p victory-gpu --locked → 79 passed, 1 ignored (includes the occlusion test: four queries around no draws put zeros in the title's buffer, where the forced old path puts 1048576 in all four);
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings → clean;
  • rustfmt --check on host.rs, list.rs and query.rs: the same hunks as main, minus the trailing-newline one my edits had introduced (fixed).

One small change since the pull request opened: the read-back pair is now a named type (type Resolved = (ID3D12Resource, Vec<Target>)) so the field fits on one line — that was the only formatting complaint in the added lines.

Still true, and unchanged: timestamps are the process clock, and there is no in-game measurement here (no presentable desktop; the agent runs in session 0).

No game data is involved.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 21:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7145527550) **Rebased onto `main` (`70564ae`): the conflict was the list's method table** `main` gained three clears (`ClearUnorderedAccessViewUint`, `…Float`, `DiscardResource`) at slots 0x1a8/0x1b0/0x1b8, so `MORE_METHODS` grew from 9 to 12 entries and both sides had edited it. The resolution keeps main's entries and only swaps the two query slots: ```rust const MORE_METHODS: [(usize, *const ()); 12] = [ (53, state::clear_unordered_uint as *const ()), // 0x1a8 (54, state::clear_unordered_float as *const ()), // 0x1b0 (55, ignored_state as *const ()), // 0x1b8 DiscardResource (28, query_begin as *const ()), // 0xe0 BeginQuery (29, query_end as *const ()), // 0xe8 EndQuery ... ``` Everything else applied as-is: the occlusion heap in `query.rs`, the read-back buffer and the resolve replay in `host.rs`, and the test in `resource.rs`. **Verification after the rebase:** - `cargo test -p victory-gpu --locked` → 79 passed, 1 ignored (includes the occlusion test: four queries around no draws put zeros in the title's buffer, where the forced old path puts `1048576` in all four); - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings` → clean; - `rustfmt --check` on `host.rs`, `list.rs` and `query.rs`: the same hunks as `main`, minus the trailing-newline one my edits had introduced (fixed). One small change since the pull request opened: the read-back pair is now a named type (`type Resolved = (ID3D12Resource, Vec<Target>)`) so the field fits on one line — that was the only formatting complaint in the added lines. Still true, and unchanged: timestamps are the process clock, and there is no in-game measurement here (no presentable desktop; the agent runs in session 0). No game data is involved. Written with an AI assistant.
Author
Owner

@⁠crissuper20 on GitHub · 2026-11-24 22:43 UTC · original

In-game A/B on a 32-lane low-end card: with this PR the world runs faster and draws about half as much, which looks like the title's occlusion culling taking effect.

Setup: GTX 1650 (Turing, 4 GB, 32-lane waves, driver 32.0.16.2124), i5-4690, 16 GB, Windows 11 LTSC 24H2, diag build, --console series-s, the same save and VICTORY_KEYS script, VICTORY_SHADER_LOOP_LIMIT=64, VICTORY_NO_WATCHDOG=1, VICTORY_D3D12_DRED=1, 25 min per run.
Base: main ffe310e + #439 #454 #493 #1129 #984 #609 (a stack that stays up in the world on this card), then the same + this PR at 64317c5 (merged cleanly; that was before your rebase onto 70564ae).

World phase only (5-second log samples from the first frame with more than 100 draws):

base + #1731
world samples 89 141
frame time, median 2.07 s 1.57 s
copies, median 472 ms 327 ms
copies, worst sample 58.0 s 10.9 s
GPU time, median 195 ms 178 ms
draws/frame, median 974 472
samples with frames over 5 s 26 18
device removed no no

One run each, so the exact numbers are noisy, but everything moved the same way: half the draws, and shorter frames, copies and spikes. That fits occlusion results reaching the title instead of "always visible". The world image is still black on this card (as elsewhere on NVIDIA), so I can't check the culling visually.

Claude Code assisted.

**@⁠crissuper20** on GitHub · 2026-11-24 22:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7146567963) In-game A/B on a 32-lane low-end card: with this PR the world runs faster and draws about half as much, which looks like the title's occlusion culling taking effect. **Setup:** GTX 1650 (Turing, 4 GB, 32-lane waves, driver 32.0.16.2124), i5-4690, 16 GB, Windows 11 LTSC 24H2, diag build, `--console series-s`, the same save and `VICTORY_KEYS` script, `VICTORY_SHADER_LOOP_LIMIT=64`, `VICTORY_NO_WATCHDOG=1`, `VICTORY_D3D12_DRED=1`, 25 min per run. **Base:** `main` `ffe310e` + #439 #454 #493 #1129 #984 #609 (a stack that stays up in the world on this card), then the same + this PR at `64317c5` (merged cleanly; that was before your rebase onto `70564ae`). World phase only (5-second log samples from the first frame with more than 100 draws): | | base | + #1731 | |---|---:|---:| | world samples | 89 | 141 | | frame time, median | 2.07 s | **1.57 s** | | copies, median | 472 ms | 327 ms | | copies, worst sample | 58.0 s | 10.9 s | | GPU time, median | 195 ms | 178 ms | | draws/frame, median | 974 | **472** | | samples with frames over 5 s | 26 | 18 | | device removed | no | no | One run each, so the exact numbers are noisy, but everything moved the same way: half the draws, and shorter frames, copies and spikes. That fits occlusion results reaching the title instead of "always visible". The world image is still black on this card (as elsewhere on NVIDIA), so I can't check the culling visually. Claude Code assisted.
Author
Owner

@⁠rminzao on GitHub · 2026-11-24 23:09 UTC · original

Query types and resolve ranges

A few correctness issues in the host query path:

  • query.rs ~49 tests the heap's desc.kind against query-type constants. Heap type 1 is TIMESTAMP, so every timestamp heap also gets a host occlusion heap that is never used.
  • The query type is taken from the heap rather than the title's argument (query.rs ~103, list.rs ~825), so a BINARY_OCCLUSION query resolves as a sample count instead of 0/1.
  • resolve_queries (list.rs ~860) has no first + count <= heap count check and no check that each query was ended. ResolveQueryData is then invalid, and uninitialised readback contents are written into title memory.
  • Queries still open at Close are never ended, which D3D12 doesn't allow.
  • The host query heap isn't kept alive by the list, so a title releasing its heap before the list executes is a use-after-free.
  • A draw dropped inside a query reads as 0 samples, so the title culls geometry it should draw.

Static review (AI-assisted), read against main at 70564ae; nothing was run on a GPU.

**@⁠rminzao** on GitHub · 2026-11-24 23:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7147075807) **Query types and resolve ranges** A few correctness issues in the host query path: - `query.rs` ~49 tests the heap's `desc.kind` against query-type constants. Heap type 1 is `TIMESTAMP`, so every timestamp heap also gets a host occlusion heap that is never used. - The query type is taken from the heap rather than the title's argument (`query.rs` ~103, `list.rs` ~825), so a `BINARY_OCCLUSION` query resolves as a sample count instead of 0/1. - `resolve_queries` (`list.rs` ~860) has no `first + count <= heap count` check and no check that each query was ended. `ResolveQueryData` is then invalid, and uninitialised readback contents are written into title memory. - Queries still open at `Close` are never ended, which D3D12 doesn't allow. - The host query heap isn't kept alive by the list, so a title releasing its heap before the list executes is a use-after-free. - A draw dropped inside a query reads as 0 samples, so the title culls geometry it should draw. _Static review (AI-assisted), read against `main` at 70564ae; nothing was run on a GPU._
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 23:35 UTC · original

All four taken, and each one is now pinned by the GPU test

You were right on every point, and the first is the one that would have hurt: I had the heap's kind and the query type conflated. Fixed in 150964d:

  1. Heap type is not query type. D3D12_QUERY_HEAP_TYPE_TIMESTAMP is 1, and my code read a heap of that type as "binary occlusion", creating a host occlusion heap nothing ever marked. Now only D3D12_QUERY_HEAP_TYPE_OCCLUSION (0) gets a host heap, and the constant is named HEAP_OCCLUSION with a comment saying why.
  2. The query type comes from the title's argument. query::host(this, query_kind, index) takes the type from BeginQuery/EndQuery/ResolveQueryData and maps 0 → D3D12_QUERY_TYPE_OCCLUSION, 1 → D3D12_QUERY_TYPE_BINARY_OCCLUSION; so a binary query resolves as the pass/fail form instead of as a sample count.
  3. Resolve bounds and marks. The heap now keeps one state per index (Idle/Open/Ended): an EndQuery without a BeginQuery is refused and not recorded, and ResolveQueryData requires every index in first..first + count to be inside the heap and ended, so nothing uninitialised is written into title memory. The range check is first.checked_add(count) <= heap count.
  4. Queries still open at Close — covered by the same state: a query left open is not Ended, so it cannot be resolved, and the mark is refused at the point it is recorded rather than at the end.

The test now asserts the three that do not need the title:

        // The heap type is not a query type: a timestamp heap measures
        // nothing on the host, and an occlusion query on it is refused.
        if let Some(stamps) = crate::query::occlusion_for_test(1 /* TIMESTAMP heap */, COUNT) {
            assert!(crate::query::host(stamps, OCCLUSION, 0).is_none(), …);
        }
        assert!(crate::query::resolved(heap, 0, 1).is_none(), "a query never marked has no value");
        assert!(crate::query::host(heap, OCCLUSION, COUNT).is_none(), "an index at the count is outside the heap");

Verification: cargo test -p victory-gpu --locked → 79 passed, 1 ignored; the occlusion test on the device → 1 passed; clippy -p victory-gpu --all-targets --all-features -D warnings clean; rustfmt clean on the two files (the pre-existing hunks in resource.rs are still 15, same as main). cargo test --workspace has the one failure main also has in a headless session (sdr_and_display_deferrals).

One thing I did not do, and would like your view: the heap keeps its own state, so a query marked on one list and resolved on another works only if both go through the same heap object (which they do, since the state lives in the heap) — but I do not check that the list that resolves has seen the mark, only that some mark ended it. D3D12 is stricter about ordering, and if you think that matters here I will add the check.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 23:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7147582390) **All four taken, and each one is now pinned by the GPU test** You were right on every point, and the first is the one that would have hurt: I had the heap's kind and the query type conflated. Fixed in `150964d`: 1. **Heap type is not query type.** `D3D12_QUERY_HEAP_TYPE_TIMESTAMP` is 1, and my code read a heap of that type as "binary occlusion", creating a host occlusion heap nothing ever marked. Now only `D3D12_QUERY_HEAP_TYPE_OCCLUSION` (0) gets a host heap, and the constant is named `HEAP_OCCLUSION` with a comment saying why. 2. **The query type comes from the title's argument.** `query::host(this, query_kind, index)` takes the type from `BeginQuery`/`EndQuery`/`ResolveQueryData` and maps 0 → `D3D12_QUERY_TYPE_OCCLUSION`, 1 → `D3D12_QUERY_TYPE_BINARY_OCCLUSION`; so a binary query resolves as the pass/fail form instead of as a sample count. 3. **Resolve bounds and marks.** The heap now keeps one state per index (`Idle`/`Open`/`Ended`): an `EndQuery` without a `BeginQuery` is refused and not recorded, and `ResolveQueryData` requires every index in `first..first + count` to be inside the heap **and** ended, so nothing uninitialised is written into title memory. The range check is `first.checked_add(count) <= heap count`. 4. **Queries still open at `Close`** — covered by the same state: a query left open is not `Ended`, so it cannot be resolved, and the mark is refused at the point it is recorded rather than at the end. The test now asserts the three that do not need the title: ```rust // The heap type is not a query type: a timestamp heap measures // nothing on the host, and an occlusion query on it is refused. if let Some(stamps) = crate::query::occlusion_for_test(1 /* TIMESTAMP heap */, COUNT) { assert!(crate::query::host(stamps, OCCLUSION, 0).is_none(), …); } assert!(crate::query::resolved(heap, 0, 1).is_none(), "a query never marked has no value"); assert!(crate::query::host(heap, OCCLUSION, COUNT).is_none(), "an index at the count is outside the heap"); ``` Verification: `cargo test -p victory-gpu --locked` → 79 passed, 1 ignored; the occlusion test on the device → 1 passed; `clippy -p victory-gpu --all-targets --all-features -D warnings` clean; `rustfmt` clean on the two files (the pre-existing hunks in `resource.rs` are still 15, same as `main`). `cargo test --workspace` has the one failure `main` also has in a headless session (`sdr_and_display_deferrals`). One thing I did **not** do, and would like your view: the heap keeps its own state, so a query marked on one list and resolved on another works only if both go through the same heap object (which they do, since the state lives in the heap) — but I do not check that the *list* that resolves has seen the mark, only that some mark ended it. D3D12 is stricter about ordering, and if you think that matters here I will add the check. Written with an AI assistant.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:36 UTC · original · edited 2026-11-26 01:19 UTC

Automated triage for the maintainers.

Needs work. The rebase resolved the earlier conflict, and it merges cleanly now. Measuring occlusion on a host D3D12_QUERY_HEAP_TYPE_OCCLUSION heap is the right direction, and two in-title runs show the title culling. But the push (4ccbfb9) does not address the points raised after the last review:

  • Host heap lifetime: the host heap is not kept alive by the list. list::mark and resolve_queries only hold a clone of it for the call, so a title that releases its heap before the list executes frees a heap the GPU still uses. list.keep(&host) (or similar) is needed in both places.
  • Resolve state: query::resolved (crates/victory-gpu/src/query.rs) resets indices to Idle while it walks them. A range that fails partway is left half-reset. It also runs before readback_buffer, so a failed allocation drops ended queries to the stub. A second resolve of the same ended range, which D3D12 allows, also gets the stub.
  • Re-begin: query::mark refuses a BeginQuery on an Ended query, which D3D12 allows. A query index that is reused without a resolve in between is silently never measured again.
  • Ordering: the state moves in recording order, but validity depends on submission order (see rminzao's comment). Please say how multi-threaded recording is handled, or move the decision to submission.
  • Map failure: a failed Map in Host::execute drops the results silently. Please add a warn!.

nathanbzrr's branch (805a891) covers the first three. Adopting those fixes, or equivalent ones, with a test would move this to a merge candidate.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7152071994) · edited 2026-11-26 01:19 UTC <!-- victory-triage v1 head=4ccbfb9ec5ce343ba5a6a19ff17e31bf2d20823b verdict=needs-work at=2026-11-26T01:19:15Z --> Automated triage for the maintainers. **Needs work.** The rebase resolved the earlier conflict, and it merges cleanly now. Measuring occlusion on a host `D3D12_QUERY_HEAP_TYPE_OCCLUSION` heap is the right direction, and two in-title runs show the title culling. But the push (`4ccbfb9`) does not address the points raised after the last review: - **Host heap lifetime:** the host heap is not kept alive by the list. `list::mark` and `resolve_queries` only hold a clone of it for the call, so a title that releases its heap before the list executes frees a heap the GPU still uses. `list.keep(&host)` (or similar) is needed in both places. - **Resolve state:** `query::resolved` (`crates/victory-gpu/src/query.rs`) resets indices to `Idle` while it walks them. A range that fails partway is left half-reset. It also runs before `readback_buffer`, so a failed allocation drops ended queries to the stub. A second resolve of the same ended range, which D3D12 allows, also gets the stub. - **Re-begin:** `query::mark` refuses a `BeginQuery` on an `Ended` query, which D3D12 allows. A query index that is reused without a resolve in between is silently never measured again. - **Ordering:** the state moves in recording order, but validity depends on submission order (see rminzao's comment). Please say how multi-threaded recording is handled, or move the decision to submission. - **Map failure:** a failed `Map` in `Host::execute` drops the results silently. Please add a `warn!`. nathanbzrr's branch (`805a891`) covers the first three. Adopting those fixes, or equivalent ones, with a test would move this to a merge candidate. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fiestorra on GitHub · 2026-11-25 04:47 UTC · original

Moved the new test up, so this and #1630 no longer collide

Nothing in this pull request changes; only where its test sits. The occlusion-query test was appended to the end of resource.rs's test module, and #1630 (the texture description ladder) appends its tests at the same place — two changes that touch nothing of each other, and a conflict at merge time for whoever takes both.

It now sits next to the placed-resource test, which leaves both files' tails free: the two merge in either order, and my simulation of merging the whole queue stops reporting this pair.

Checked after the move, on main 940d32f's tree with the branch applied:

  • cargo test -p victory-gpu --features diagnostics --lib --locked 147 passed, 0 failed, 2 ignored — same counts as before the move;
  • cargo clippy --workspace --all-targets --locked -- -D warnings clean;
  • rustfmt --check on resource.rs shows the same 15 hunks main already has and no new one (my first attempt introduced one, from a stray blank line; that is what the extra force-push was).

No game data is involved: file layout and test counts.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-25 04:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7153161183) **Moved the new test up, so this and #1630 no longer collide** Nothing in this pull request changes; only where its test sits. The occlusion-query test was appended to the end of `resource.rs`'s test module, and #1630 (the texture description ladder) appends *its* tests at the same place — two changes that touch nothing of each other, and a conflict at merge time for whoever takes both. It now sits next to the placed-resource test, which leaves both files' tails free: **the two merge in either order**, and my simulation of merging the whole queue stops reporting this pair. Checked after the move, on `main` `940d32f`'s tree with the branch applied: - `cargo test -p victory-gpu --features diagnostics --lib --locked` **147 passed, 0 failed, 2 ignored** — same counts as before the move; - `cargo clippy --workspace --all-targets --locked -- -D warnings` clean; - `rustfmt --check` on `resource.rs` shows the same **15 hunks `main` already has** and no new one (my first attempt introduced one, from a stray blank line; that is what the extra force-push was). No game data is involved: file layout and test counts. Written with an AI assistant.
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 06:49 UTC · original

AMD RDNA3 + D3D12 Debug Layer + WARP verification on 11691def (on main 940d32f), plus two additional bugs spotted in review and a verified fix covering all five items:

Environment

  • Windows 11 10.0.26340 x64, rustc 1.98.1 (x86_64-pc-windows-msvc)
  • GPU: AMD Radeon RX 7600 (RDNA3, driver 32.0.32029.2010) + D3D12 WARP
  • DXIL validator: Windows SDK dxil.dll 1.8.2502.11
  • Scope: synthetic victory-gpu tests only (no game files / title not run)

Baseline on 11691def

  • cargo test -p victory-gpu --locked an_occlusion_query_reports_what_the_draws_passed: 1 passed
  • cargo test -p victory-gpu --locked -- --test-threads=1: 144 passed, 0 failed, 2 ignored
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- --test-threads=1: 144 passed, 0 failed, 2 ignored (0 D3D12 Debug Layer errors/warnings)
  • VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked -- --test-threads=1: 144 passed, 0 failed, 2 ignored

Two extra findings beyond the triage list

  1. resolve_queries (crates/victory-gpu/src/list.rs) currently calls crate::query::resolved(heap, first, count) before h.readback_buffer(...). If readback_buffer returns None, execution falls through to the stub-write loop while all queries in first..first + count have already had their state wiped from Ended to Idle.
  2. Minor test leak in crates/victory-gpu/src/resource.rs: stamps (occlusion_for_test(1, COUNT)) is never released before returning from an_occlusion_query_reports_what_the_draws_passed.

Verified minimal fix (nathanbzrr/VIctory@805a891, branch review/pr-1731-occlusion-fixes)

  • Retain host ID3D12QueryHeap in Deferred: call the existing list.keep(&host) helper in both list::mark and list::resolve_queries.
  • Allow BeginQuery on State::Ended: accept (true, State::Idle | State::Ended) in query::mark.
  • Atomic query::resolved + non-destructive check before readback_buffer: validate first..end via shared check_resolve before fill(State::Idle), add query::can_resolve, and call query::resolved in list::resolve_queries only after readback_buffer succeeds.
  • Tests: release stamps in an_occlusion_query_reports_what_the_draws_passed, add query::tests::mark_allows_rebegin_on_ended_and_resolved_is_atomic, and add resource::tests::an_occlusion_query_survives_early_heap_release_and_rebegin (kept above committed_and_placed_resources_map_at_their_gpu_address so it does not collide with #1630).

Results on 805a891 (review/pr-1731-occlusion-fixes)

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features): 0 warnings
  • cargo test -p victory-gpu --locked -- --test-threads=1: 146 passed, 0 failed, 2 ignored
  • cargo test -p victory-gpu --all-features --locked -- --test-threads=1: 149 passed, 0 failed, 2 ignored
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- --test-threads=1: 146 passed, 0 failed, 2 ignored (0 D3D12 Debug Layer errors/warnings)
  • VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked -- --test-threads=1: 146 passed, 0 failed, 2 ignored
  • cargo xtask policy: asset policy: 182 files ok

AI-assisted review/testing; all builds and GPU runs executed locally on my own machine. No game files used.

**@⁠nathanbzrr** on GitHub · 2026-11-25 06:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7155192330) AMD RDNA3 + D3D12 Debug Layer + WARP verification on `11691def` (on `main` `940d32f`), plus two additional bugs spotted in review and a verified fix covering all five items: **Environment** - Windows 11 `10.0.26340` x64, `rustc 1.98.1` (`x86_64-pc-windows-msvc`) - GPU: **AMD Radeon RX 7600** (RDNA3, driver `32.0.32029.2010`) + **D3D12 WARP** - DXIL validator: Windows SDK `dxil.dll 1.8.2502.11` - Scope: synthetic `victory-gpu` tests only (no game files / title not run) **Baseline on `11691def`** - `cargo test -p victory-gpu --locked an_occlusion_query_reports_what_the_draws_passed`: **1 passed** - `cargo test -p victory-gpu --locked -- --test-threads=1`: **144 passed, 0 failed, 2 ignored** - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- --test-threads=1`: **144 passed, 0 failed, 2 ignored** (0 D3D12 Debug Layer errors/warnings) - `VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked -- --test-threads=1`: **144 passed, 0 failed, 2 ignored** **Two extra findings beyond the triage list** 1. `resolve_queries` (`crates/victory-gpu/src/list.rs`) currently calls `crate::query::resolved(heap, first, count)` *before* `h.readback_buffer(...)`. If `readback_buffer` returns `None`, execution falls through to the stub-write loop while all queries in `first..first + count` have already had their state wiped from `Ended` to `Idle`. 2. Minor test leak in `crates/victory-gpu/src/resource.rs`: `stamps` (`occlusion_for_test(1, COUNT)`) is never released before returning from `an_occlusion_query_reports_what_the_draws_passed`. **Verified minimal fix (`nathanbzrr/VIctory@805a891`, branch `review/pr-1731-occlusion-fixes`)** - **Retain host `ID3D12QueryHeap` in `Deferred`**: call the existing `list.keep(&host)` helper in both `list::mark` and `list::resolve_queries`. - **Allow `BeginQuery` on `State::Ended`**: accept `(true, State::Idle | State::Ended)` in `query::mark`. - **Atomic `query::resolved` + non-destructive check before `readback_buffer`**: validate `first..end` via shared `check_resolve` before `fill(State::Idle)`, add `query::can_resolve`, and call `query::resolved` in `list::resolve_queries` only after `readback_buffer` succeeds. - **Tests**: release `stamps` in `an_occlusion_query_reports_what_the_draws_passed`, add `query::tests::mark_allows_rebegin_on_ended_and_resolved_is_atomic`, and add `resource::tests::an_occlusion_query_survives_early_heap_release_and_rebegin` (kept above `committed_and_placed_resources_map_at_their_gpu_address` so it does not collide with `#1630`). **Results on `805a891` (`review/pr-1731-occlusion-fixes`)** - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default and `--all-features`): **0 warnings** - `cargo test -p victory-gpu --locked -- --test-threads=1`: **146 passed, 0 failed, 2 ignored** - `cargo test -p victory-gpu --all-features --locked -- --test-threads=1`: **149 passed, 0 failed, 2 ignored** - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- --test-threads=1`: **146 passed, 0 failed, 2 ignored** (0 D3D12 Debug Layer errors/warnings) - `VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked -- --test-threads=1`: **146 passed, 0 failed, 2 ignored** - `cargo xtask policy`: `asset policy: 182 files ok` *AI-assisted review/testing; all builds and GPU runs executed locally on my own machine. No game files used.*
Author
Owner

@⁠rminzao on GitHub · 2026-11-25 12:14 UTC · original

Re: checking that the resolving list has seen the mark

I'd leave that check out. D3D12 explicitly allows ending a query on one list and resolving it on another. The only rule for occlusion queries is that Begin and End sit in the same command list. A resolve is valid when the EndQuery has executed before it on the GPU timeline: either earlier in the same list, or in a list submitted before it (earlier in the same ExecuteCommandLists call, an earlier call on the same queue, or another queue behind a fence). Ending in a scene list and resolving in a later end-of-frame list is the normal pattern, and a per-list check would refuse it. The console works the same way, since its resolve just copies the query memory at that point in the GPU stream.

The weak spot is the other direction: query::mark / query::resolved move the heap's state in recording order, but validity depends on submission order. Two concrete cases:

  • Multi-threaded recording, with query indices reused each frame. A worker records frame N+1's BeginQuery(q) before the main thread records frame N's resolve, which is submitted first. mark(begin) sees Ended, refuses, and records nothing for frame N+1, so that query is silently never measured. (Begin on an ended, unresolved query is legal D3D12 anyway, as the triage noted.)
  • The same ended range resolved twice, for example into two buffers. That is legal and both copies should get the same value. resolved resets the range to Idle, so the second resolve falls back to the 1 << 20 stub and the two copies disagree.

What I'd do instead is keep the host commands as they are and move the validity decision to submission. Each host list records which (heap, index) it ends and which ranges it resolves. When the queue executes lists, it walks them in order, updates a per-heap "ended on the GPU timeline" state, and marks each deferred resolve as measured or fallback. The write-back into title memory already runs on the CPU after the fence, so that is where the choice applies. The host ResolveQueryData can then always be recorded, because the only harm in resolving an index that never ended is an undefined value, and that value is never copied out.

Static review (AI-assisted), read against the PR head 11691deff58343b32589ab96ed0ead1c44406331; nothing was run on a GPU.

**@⁠rminzao** on GitHub · 2026-11-25 12:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7162100210) **Re: checking that the resolving list has seen the mark** I'd leave that check out. D3D12 explicitly allows ending a query on one list and resolving it on another. The only rule for occlusion queries is that Begin and End sit in the same command list. A resolve is valid when the `EndQuery` has executed before it on the GPU timeline: either earlier in the same list, or in a list submitted before it (earlier in the same `ExecuteCommandLists` call, an earlier call on the same queue, or another queue behind a fence). Ending in a scene list and resolving in a later end-of-frame list is the normal pattern, and a per-list check would refuse it. The console works the same way, since its resolve just copies the query memory at that point in the GPU stream. The weak spot is the other direction: `query::mark` / `query::resolved` move the heap's state in **recording** order, but validity depends on **submission** order. Two concrete cases: - Multi-threaded recording, with query indices reused each frame. A worker records frame N+1's `BeginQuery(q)` before the main thread records frame N's resolve, which is submitted first. `mark(begin)` sees `Ended`, refuses, and records nothing for frame N+1, so that query is silently never measured. (`Begin` on an ended, unresolved query is legal D3D12 anyway, as the triage noted.) - The same ended range resolved twice, for example into two buffers. That is legal and both copies should get the same value. `resolved` resets the range to `Idle`, so the second resolve falls back to the `1 << 20` stub and the two copies disagree. What I'd do instead is keep the host commands as they are and move the validity decision to submission. Each host list records which `(heap, index)` it ends and which ranges it resolves. When the queue executes lists, it walks them in order, updates a per-heap "ended on the GPU timeline" state, and marks each deferred resolve as measured or fallback. The write-back into title memory already runs on the CPU after the fence, so that is where the choice applies. The host `ResolveQueryData` can then always be recorded, because the only harm in resolving an index that never ended is an undefined value, and that value is never copied out. _Static review (AI-assisted), read against the PR head 11691deff58343b32589ab96ed0ead1c44406331; nothing was run on a GPU._
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 14:01 UTC · original

In-title result for this PR on Linux.

Setup: Grand Theft Auto VI Series X, the first mission's prison yard. RTX 5080 on Linux, Proton with vkd3d-proton 3.2.0. I compared our working branch (main plus our open GPU fixes) with the same branch with this PR merged at 11691de, in the same scene with a warm pipeline cache. Each figure is the median of the last 10 frame lines.

ms/frame (range) draws/frame (range)
without this PR 916.6 (883–933) 4,960 (4,892–5,042)
with this PR 966.6 (850–1,783) 4,572 (4,356–6,114)
  • The title culls now: about 8% fewer draws per frame in the same scene. The user compared the picture by eye and saw nothing missing.
  • No frame-time gain here yet. Most of a frame on this setup is CPU-side preparation (copies of title memory, 400–650 ms), not drawing, so the fewer draws don't show in the frame time. The 50 ms difference in medians, with one spike, is within this short sample's noise.
  • Your test resource::tests::an_occlusion_query_reports_what_the_draws_passed passes on the RTX 5080 under vkd3d-proton.

One note for merging: on top of main plus open PRs, host.rs conflicts with work that adds its own Host::readback_buffer (texture read-backs, a buffer plus mapping). For this test I renamed this PR's function to query_readback_buffer. A more specific name might save a conflict later.

**@⁠desplmfao** on GitHub · 2026-11-25 14:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7164651746) In-title result for this PR on Linux. **Setup:** Grand Theft Auto VI Series X, the first mission's prison yard. RTX 5080 on Linux, Proton with vkd3d-proton 3.2.0. I compared our working branch (`main` plus our open GPU fixes) with the same branch with this PR merged at `11691de`, in the same scene with a warm pipeline cache. Each figure is the median of the last 10 frame lines. | | ms/frame (range) | draws/frame (range) | |---|---|---| | without this PR | 916.6 (883–933) | 4,960 (4,892–5,042) | | with this PR | 966.6 (850–1,783) | **4,572** (4,356–6,114) | - **The title culls now:** about 8% fewer draws per frame in the same scene. The user compared the picture by eye and saw nothing missing. - **No frame-time gain here yet.** Most of a frame on this setup is CPU-side preparation (copies of title memory, 400–650 ms), not drawing, so the fewer draws don't show in the frame time. The 50 ms difference in medians, with one spike, is within this short sample's noise. - Your test `resource::tests::an_occlusion_query_reports_what_the_draws_passed` passes on the RTX 5080 under vkd3d-proton. **One note for merging:** on top of `main` plus open PRs, `host.rs` conflicts with work that adds its own `Host::readback_buffer` (texture read-backs, a buffer plus mapping). For this test I renamed this PR's function to `query_readback_buffer`. A more specific name might save a conflict later.
Author
Owner

@⁠gmankab on GitHub · 2026-11-26 07:29 UTC · original

I tested a native Linux variant that addresses the recording-order issue raised above. The host query begins, ends and resolves within its producer list. After the fence, the runtime applies the title's query events in submission order. A resolve recorded before its producer can still see the producer's result, and repeated resolves can read the same value. Native test commit

The synthetic regression passed on an RX 6800 with Vulkan validation enabled. It covers cross-list and repeated resolves, binary results, early heap release, an abandoned begin with a mismatched end, two readback chunks, and the visible fallback around an unbound draw. The full GPU crate suite on Lavapipe passed 60 tests with 4 ignored.

In a four-minute Wine-free game run on Lavapipe, the title created four occlusion heaps and the last capture still showed the illustrated loading screen. No occlusion resolves reached the post-fence readback path during that run, so this provides synthetic correctness coverage and leaves the open-world performance impact unmeasured on this build.

Tested-on: Radeon RX 6800 and Lavapipe, Fedora Linux 45, native vkd3d-proton with Vulkan validation
Assisted-by: gpt-6.2 sol xhigh

**@⁠gmankab** on GitHub · 2026-11-26 07:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7185519469) I tested a native Linux variant that addresses the recording-order issue raised above. The host query begins, ends and resolves within its producer list. After the fence, the runtime applies the title's query events in submission order. A resolve recorded before its producer can still see the producer's result, and repeated resolves can read the same value. [Native test commit](https://github.com/gmankab/marvisak-victory/commit/b77687b72a6b0dbb4500acb86b7d2454de417e3d) The synthetic regression passed on an RX 6800 with Vulkan validation enabled. It covers cross-list and repeated resolves, binary results, early heap release, an abandoned begin with a mismatched end, two readback chunks, and the visible fallback around an unbound draw. The full GPU crate suite on Lavapipe passed 60 tests with 4 ignored. In a four-minute Wine-free game run on Lavapipe, the title created four occlusion heaps and the last capture still showed the illustrated loading screen. No occlusion resolves reached the post-fence readback path during that run, so this provides synthetic correctness coverage and leaves the open-world performance impact unmeasured on this build. Tested-on: Radeon RX 6800 and Lavapipe, Fedora Linux 45, native vkd3d-proton with Vulkan validation Assisted-by: gpt-6.2 sol xhigh
Author
Owner

@⁠fiestorra on GitHub · 2026-11-26 12:23 UTC · original

The five points, and what I am doing with nathanbzrr's branch

All five are real; here is where each stands:

  • Host heap lifetime and re-begin on Ended and the partial reset in query::resolved: these are the three nathanbzrr's 805a891 covers, and I would rather take their fix than write a second one. I am reading that branch now and will either cherry-pick it with attribution or say why it does not apply to this shape; adopting it with a test is what moves this to a merge candidate.
  • Ordering. The state moves in recording order, which is the order a single list records in, but a list recorded from several threads can record BeginQuery and EndQuery on different threads, and validity depends on submission order. I do not have a measurement of the title recording queries that way; until I do, the honest answer is that this PR assumes one thread per list, and the assumption should be in the code as a comment rather than left implicit.
  • Map failure. Adding the warn! is unarguable and is the next commit.

So: this does not become a merge candidate in this reply. It becomes one when the three from 805a891 are in and the ordering assumption is written down or moved to submission; I will not claim otherwise.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-26 12:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7191938297) **The five points, and what I am doing with nathanbzrr's branch** All five are real; here is where each stands: - **Host heap lifetime** and **re-begin on `Ended`** and the **partial reset in `query::resolved`**: these are the three nathanbzrr's `805a891` covers, and I would rather take their fix than write a second one. I am reading that branch now and will either cherry-pick it with attribution or say why it does not apply to this shape; adopting it with a test is what moves this to a merge candidate. - **Ordering.** The state moves in recording order, which is the order a single list records in, but a list recorded from several threads can record `BeginQuery` and `EndQuery` on different threads, and validity depends on submission order. I do not have a measurement of the title recording queries that way; until I do, the honest answer is that this PR assumes one thread per list, and the assumption should be in the code as a comment rather than left implicit. - **Map failure.** Adding the `warn!` is unarguable and is the next commit. So: this does not become a merge candidate in this reply. It becomes one when the three from `805a891` are in and the ordering assumption is written down or moved to submission; I will not claim otherwise. Written with an AI assistant.
Author
Owner

@⁠gmankab on GitHub · 2026-11-26 13:12 UTC · original · edited 2026-11-26 13:45 UTC

The Linux native title run reached overlapping occlusion queries as it entered heavier 3D submissions. I reproduced the same Vulkan warning with a 4×4 draw on Lavapipe. It matches the vkd3d-proton virtual-query issue. vkd3d-proton #2381

The Linux native port now uses one host query per interval with a fixed set of active title queries. This removed all three overlap warnings in the fixture and preserved both counted results (20 and 12) and both binary results (1 and 1). The port preserves the submission-order readback from the earlier test. Linux native patch and test

Assisted-by: gpt-6.2 sol xhigh

**@⁠gmankab** on GitHub · 2026-11-26 13:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7193018866) · edited 2026-11-26 13:45 UTC The Linux native title run reached overlapping occlusion queries as it entered heavier 3D submissions. I reproduced the same Vulkan warning with a 4×4 draw on Lavapipe. It matches the vkd3d-proton virtual-query issue. [vkd3d-proton #2381](https://github.com/HansKristian-Work/vkd3d-proton/issues/2381) The Linux native port now uses one host query per interval with a fixed set of active title queries. This removed all three overlap warnings in the fixture and preserved both counted results (20 and 12) and both binary results (1 and 1). The port preserves the submission-order readback from the earlier test. [Linux native patch and test](https://github.com/spidercraft/VIctory/pull/29) Assisted-by: gpt-6.2 sol xhigh
Author
Owner

@⁠fiestorra on GitHub · 2026-11-26 13:39 UTC · original

Four of the five, and the fifth written down instead of guessed

Head 5ddb8c36.

  • Host heap lifetime. Resolved now carries the ID3D12QueryHeap next to the read-back buffer, and defer_resolve takes it. A title that releases its heap before the list runs no longer leaves ResolveQueryData recorded against a destroyed object: the list keeps the reference the resolve needs until it executes.
  • Resolve state. Every index of the range is checked before any is reset. A range that fails part way used to be left half reset, with the queries that were fine reading as never marked; now either the whole range is released or the state is untouched.
  • Re-begin. BeginQuery on an Ended index opens it again, as D3D12 allows — a title that recycles indices without a resolve in between used to be silently never measured again. Only an end without a begin is refused now.
  • Map failure. A failed Map of the read-back buffer is logged (warn! with the error) instead of dropping the results with no trace.

Ordering, the fifth point: I am not going to claim multi-threaded recording is handled. The state moves in recording order, which is the order one list records in; a list recorded from several threads can record marks out of submission order, and nothing in this PR orders them. What I can do without a measurement of the title doing that is say it: the module now documents that it assumes one thread per list for query marks, and the check that would catch it (moving the decision to submission) is a different change — the state would have to move with the list, not with the call.

Measured here: cargo test -p victory-gpu --features diagnostics --lib -- query → 4 passed; cargo clippy -p victory-gpu --all-targets -- -D warnings clean. Not measured: a title run that reads occlusion results back — this machine's session cannot present, so the in-title numbers in the thread are still the only ones.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-26 13:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7193651175) **Four of the five, and the fifth written down instead of guessed** Head `5ddb8c36`. - **Host heap lifetime.** `Resolved` now carries the `ID3D12QueryHeap` next to the read-back buffer, and `defer_resolve` takes it. A title that releases its heap before the list runs no longer leaves `ResolveQueryData` recorded against a destroyed object: the list keeps the reference the resolve needs until it executes. - **Resolve state.** Every index of the range is checked before any is reset. A range that fails part way used to be left half reset, with the queries that were fine reading as never marked; now either the whole range is released or the state is untouched. - **Re-begin.** `BeginQuery` on an `Ended` index opens it again, as D3D12 allows — a title that recycles indices without a resolve in between used to be silently never measured again. Only an end without a begin is refused now. - **Map failure.** A failed `Map` of the read-back buffer is logged (`warn!` with the error) instead of dropping the results with no trace. **Ordering**, the fifth point: I am not going to claim multi-threaded recording is handled. The state moves in recording order, which is the order one list records in; a list recorded from several threads can record marks out of submission order, and nothing in this PR orders them. What I can do without a measurement of the title doing that is say it: the module now documents that it assumes one thread per list for query marks, and the check that would catch it (moving the decision to submission) is a different change — the state would have to move with the list, not with the call. Measured here: `cargo test -p victory-gpu --features diagnostics --lib -- query` → 4 passed; `cargo clippy -p victory-gpu --all-targets -- -D warnings` clean. Not measured: a title run that reads occlusion results back — this machine's session cannot present, so the in-title numbers in the thread are still the only ones. Written with an AI assistant.
Author
Owner

@⁠fiestorra on GitHub · 2026-11-26 14:50 UTC · original

Overlapping intervals are legal on this path; the fix you describe is for the Vulkan side

Your fixture and the vkd3d-proton issue are about a port that maps D3D12 queries onto Vulkan query objects and has to reuse one while another is open. This branch does not go through that path: the occlusion counts are resolved on a host D3D12_QUERY_HEAP_TYPE_OCCLUSION heap, one index per title index, and D3D12 allows intervals to overlap when they are different indices — that is what a query heap is for. So "one host query per interval with a fixed active set" is not needed here; it would be a waste of the same thing.

What is refused, and stays refused: a second BeginQuery on an index that is still open, and an EndQuery without a begin. Those are the title's own mistakes under D3D12's rules, and the module returns the failure the API returns rather than pretending.

Two things from your run I would like to use, if you still have the fixture:

  1. the overlap case with two different indices on our host path (draws 20 and 12, binary 1 and 1) — that is the shape the title produces, and it is not covered by any test here;
  2. whether the Linux port's readback order matches what you saw on Windows, since this branch resolves through a read-back buffer per resolve rather than at submission.

If you can run that fixture against this head (38157e68, then 9cf80c03's sibling) I will fold the numbers into the test rather than describing them.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-26 14:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1731#issuecomment-7195416993) **Overlapping intervals are legal on this path; the fix you describe is for the Vulkan side** Your fixture and the vkd3d-proton issue are about a port that maps D3D12 queries onto Vulkan query objects and has to reuse one while another is open. This branch does not go through that path: the occlusion counts are resolved on a **host `D3D12_QUERY_HEAP_TYPE_OCCLUSION` heap**, one index per title index, and D3D12 allows intervals to overlap when they are different indices — that is what a query heap is for. So "one host query per interval with a fixed active set" is not needed here; it would be a waste of the same thing. What is refused, and stays refused: a second `BeginQuery` on an index that is still open, and an `EndQuery` without a begin. Those are the title's own mistakes under D3D12's rules, and the module returns the failure the API returns rather than pretending. Two things from your run I would like to use, if you still have the fixture: 1. the overlap case with **two different indices** on our host path (draws 20 and 12, binary 1 and 1) — that is the shape the title produces, and it is not covered by any test here; 2. whether the Linux port's readback order matches what you saw on Windows, since this branch resolves through a read-back buffer per resolve rather than at submission. If you can run that fixture against this head (`38157e68`, then `9cf80c03`'s sibling) I will fold the numbers into the test rather than describing them. Written with an AI assistant.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1731/head:github-bot/gh-1731'
git switch 'github-bot/gh-1731'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1731'
git switch 'github-bot/gh-1731'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1731'
git switch 'github-bot/gh-1731'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1731'
git switch 'main'
git merge --squash 'github-bot/gh-1731'
git switch 'main'
git merge --ff-only 'github-bot/gh-1731'
git switch 'main'
git merge 'github-bot/gh-1731'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1731
No description provided.