GPU: occlusion queries and timestamps run on the host (FIND-8) #1740

Closed
github-bot wants to merge 2 commits from gh-pr/1740/head into gh-pr/1740/base
Owner

@⁠JurajSimicevic on GitHub · 2026-11-24 21:41 UTC · original
JurajSimicevic:gpu/real-queries → main · +604 −23 · 5 files · 2 commits · closed without merging

Closes FIND-8 in #1633 (from #1317, H-8.1/H-8.2).

What

Until now every query was answered with a plausible value: occlusion said a million samples passed, binary occlusion said visible, and timestamps were CPU time taken after the submission's wait. The title's own occlusion culling and its GPU timing could not work.

  • query.rs: an occlusion or timestamp heap now has a host ID3D12QueryHeap behind it. BeginQuery/EndQuery (separate methods now, slots 28 and 29) run on the host list. ResolveQueryData resolves into a per-list read-back buffer, and the bottom-of-pipe writes copy the results into the title's buffer once the list has run, as the other deferred writes already do.
  • Dropped work never culls: each host list counts the draws and dispatches it did not run (no host pipeline, dropped indirect, skipped). A query whose span saw that count grow resolves to the old "visible" value, so a missing shader can never make the title cull geometry it should draw. Queries still open when a list closes are ended there and treated the same way.
  • Fallbacks stay: queries never ended on the host, pipeline statistics, other heap types and hosts without a heap keep the old plausible values.
  • Timestamps on the title's clock: host GPU ticks go through GetClockCalibration to the CPU's performance counter, then to the 100 MHz clock Written::GpuTimestamp already reports, so resolved timestamps and bottom-of-pipe timestamps can be compared.
  • Query heaps are kept alive by the list (HostList::keep) until it is reset, since the title may release a heap before the list runs.

Tests

Three new GPU tests in query::tests (they skip without a host GPU):

  • an occlusion query with no draws resolves to 0 from the host; one with a dropped draw, and one left open at close, resolve to the fallback;
  • queries never ended, of a type the heap doesn't hold, or past its end fall back;
  • two resolved timestamps are ordered, non-zero, and within a second of Written::GpuTimestamp read right after.

They also pass with --features diagnostics and VICTORY_D3D12_DEBUG=1 (a deliberately invalid query call ends the same test with a debug-layer stop, so the layer is active there). cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings and cargo test --workspace --locked pass.

In the game

RTX 5080 (driver 32.0.16.1742), Windows 11 26200, diag build with the debug layer and DRED, on main with only this change. Menus and loading stay at 30 fps. The title resolves occlusion queries on the host as soon as it is in the world (queries resolved on the host kind=0). The debug layer reports nothing about queries or read-back buffers; its only errors are the known title-buffer state mismatch (#548, fixed by #1691). The run ends in the known NVIDIA world hang (#71), as it does without this change.

Not measured yet: how much overdraw this saves, since the world still hangs on NVIDIA before it renders fully. With more of the world rendering, the title's culling should start to show.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠JurajSimicevic** on GitHub · 2026-11-24 21:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1740) `JurajSimicevic:gpu/real-queries` → `main` · +604 −23 · 5 files · 2 commits · closed without merging Closes FIND-8 in #1633 (from #1317, H-8.1/H-8.2). ## What Until now every query was answered with a plausible value: occlusion said a million samples passed, binary occlusion said visible, and timestamps were CPU time taken after the submission's wait. The title's own occlusion culling and its GPU timing could not work. - **`query.rs`:** an occlusion or timestamp heap now has a host `ID3D12QueryHeap` behind it. `BeginQuery`/`EndQuery` (separate methods now, slots 28 and 29) run on the host list. `ResolveQueryData` resolves into a per-list read-back buffer, and the bottom-of-pipe writes copy the results into the title's buffer once the list has run, as the other deferred writes already do. - **Dropped work never culls:** each host list counts the draws and dispatches it did not run (no host pipeline, dropped indirect, skipped). A query whose span saw that count grow resolves to the old "visible" value, so a missing shader can never make the title cull geometry it should draw. Queries still open when a list closes are ended there and treated the same way. - **Fallbacks stay:** queries never ended on the host, pipeline statistics, other heap types and hosts without a heap keep the old plausible values. - **Timestamps on the title's clock:** host GPU ticks go through `GetClockCalibration` to the CPU's performance counter, then to the 100 MHz clock `Written::GpuTimestamp` already reports, so resolved timestamps and bottom-of-pipe timestamps can be compared. - Query heaps are kept alive by the list (`HostList::keep`) until it is reset, since the title may release a heap before the list runs. ## Tests Three new GPU tests in `query::tests` (they skip without a host GPU): - an occlusion query with no draws resolves to 0 from the host; one with a dropped draw, and one left open at close, resolve to the fallback; - queries never ended, of a type the heap doesn't hold, or past its end fall back; - two resolved timestamps are ordered, non-zero, and within a second of `Written::GpuTimestamp` read right after. They also pass with `--features diagnostics` and `VICTORY_D3D12_DEBUG=1` (a deliberately invalid query call ends the same test with a debug-layer stop, so the layer is active there). `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` and `cargo test --workspace --locked` pass. ## In the game RTX 5080 (driver 32.0.16.1742), Windows 11 26200, diag build with the debug layer and DRED, on `main` with only this change. Menus and loading stay at 30 fps. The title resolves occlusion queries on the host as soon as it is in the world (`queries resolved on the host kind=0`). The debug layer reports nothing about queries or read-back buffers; its only errors are the known title-buffer state mismatch (#548, fixed by #1691). The run ends in the known NVIDIA world hang (#71), as it does without this change. Not measured yet: how much overdraw this saves, since the world still hangs on NVIDIA before it renders fully. With more of the world rendering, the title's culling should start to show. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Occlusion and timestamp heaps get a host query heap. BeginQuery and
EndQuery run on the host list, and ResolveQueryData resolves into a
read-back buffer whose results the bottom-of-pipe writes copy into the
title's buffer once the list has run. A query whose span saw a draw or
dispatch dropped on the host, or that was left open at list close, still
reports visible, so missing shaders never make the title cull geometry.
Host timestamps are put on the title's 100 MHz clock through the queue's
clock calibration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps the new drop reporting and twin-state clearing from main beside
the query changes; the BeginQuery/EndQuery slots move into main's larger
method table. Query tests drain earlier debug-layer messages first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:24 +00:00
github-bot closed this pull request 2026-11-26 04:43:24 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:21 UTC · original

Overlap for the reviewers: #1731 (opened 11 minutes earlier, rebased onto 70564ae, reviewed by kais7654) also gives occlusion queries a host ID3D12QueryHeap. Its BeginQuery / EndQuery run on the host list, and the results are read back into title memory after the submission waits. The difference: this PR also does timestamps (queue.rs, draw.rs) and is larger in query.rs (+391 against +74). Both edit host.rs, list.rs and query.rs, so only one of the occlusion paths can merge as is. From reading the file lists and descriptions; nothing built.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 22:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1740#issuecomment-7146134350) Overlap for the reviewers: #1731 (opened 11 minutes earlier, rebased onto `70564ae`, reviewed by kais7654) also gives occlusion queries a host `ID3D12QueryHeap`. Its `BeginQuery` / `EndQuery` run on the host list, and the results are read back into title memory after the submission waits. The difference: this PR also does timestamps (`queue.rs`, `draw.rs`) and is larger in `query.rs` (+391 against +74). Both edit `host.rs`, `list.rs` and `query.rs`, so only one of the occlusion paths can merge as is. From reading the file lists and descriptions; nothing built. AI-assisted (Claude Code).
Author
Owner

@⁠JurajSimicevic on GitHub · 2026-11-24 22:42 UTC · original

For the reviewers, on the overlap with #1731 noted above: FIND-8 was claimed for this PR in #1633 at 21:24 (#1731's claim followed at 21:31), and the two differ in a few ways that matter for choosing one:

  • Dropped work: here a query whose span had a draw or dispatch not run on the host (no host pipeline, dropped indirect), or that was left open at list close, still resolves to "visible". With missing shaders, a measured count would make the title cull geometry it should draw.
  • Timestamps: resolved from a host timestamp heap and put on the title's clock through GetClockCalibration; #1731 keeps the process clock.
  • Lifetime: query heaps are kept alive by the list until it is reset, since the title may release a heap before the list runs.
  • In the game: checked on an RTX 5080 (occlusion queries resolved on the host from the world's first frames, no debug-layer messages about queries); #1731 notes it couldn't run the title.

Both edit the same functions, so only one can merge as is; happy to take anything from #1731 that this one lacks.

AI-assisted.

**@⁠JurajSimicevic** on GitHub · 2026-11-24 22:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1740#issuecomment-7146544724) For the reviewers, on the overlap with #1731 noted above: FIND-8 was claimed for this PR in #1633 at 21:24 (#1731's claim followed at 21:31), and the two differ in a few ways that matter for choosing one: - **Dropped work:** here a query whose span had a draw or dispatch not run on the host (no host pipeline, dropped indirect), or that was left open at list close, still resolves to "visible". With missing shaders, a measured count would make the title cull geometry it should draw. - **Timestamps:** resolved from a host timestamp heap and put on the title's clock through `GetClockCalibration`; #1731 keeps the process clock. - **Lifetime:** query heaps are kept alive by the list until it is reset, since the title may release a heap before the list runs. - **In the game:** checked on an RTX 5080 (occlusion queries resolved on the host from the world's first frames, no debug-layer messages about queries); #1731 notes it couldn't run the title. Both edit the same functions, so only one can merge as is; happy to take anything from #1731 that this one lacks. AI-assisted.
Author
Owner

@⁠JurajSimicevic on GitHub · 2026-11-24 22:58 UTC · original

A correction to my comparison above: this PR also overlaps #159 by r4tedx, opened this morning (01:01), which I missed. #159 already runs occlusion, pipeline statistics and timestamp queries on the host, puts timestamps on the title's clock through the queue's clock calibration, and ends queries left open at close. It came first and covers more (statistics too); it conflicts with main now.

What this one adds over #159, if useful for whichever goes in: it is on today's main (70564ae), a query whose span had a draw or dispatch dropped on the host still reports visible (so missing shaders can't make the title cull geometry), and it was checked in the game on an RTX 5080. Happy to close this in favour of #159, or to fold the dropped-work part into it.

AI-assisted.

**@⁠JurajSimicevic** on GitHub · 2026-11-24 22:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1740#issuecomment-7146869621) A correction to my comparison above: this PR also overlaps #159 by r4tedx, opened this morning (01:01), which I missed. #159 already runs occlusion, pipeline statistics and timestamp queries on the host, puts timestamps on the title's clock through the queue's clock calibration, and ends queries left open at close. It came first and covers more (statistics too); it conflicts with `main` now. What this one adds over #159, if useful for whichever goes in: it is on today's `main` (70564ae), a query whose span had a draw or dispatch dropped on the host still reports visible (so missing shaders can't make the title cull geometry), and it was checked in the game on an RTX 5080. Happy to close this in favour of #159, or to fold the dropped-work part into it. AI-assisted.
Author
Owner

@⁠JurajSimicevic on GitHub · 2026-11-25 00:34 UTC · original

Closing in favour of #159, which came first (01:01) and covers everything here and more (pipeline statistics too).

A correction to my comment above: I wrote that this PR adds a guard for queries around dropped draws over #159. That's wrong: #159's second commit ("an occlusion query around a draw the host skipped keeps its stand-in") already does it. The only differences were being on a newer main and an in-game check.

@⁠r4tedx, once #159 is rebased onto current main, I can run it in the game on an RTX 5080 (diag build, debug layer and DRED) and report there.

AI-assisted.

**@⁠JurajSimicevic** on GitHub · 2026-11-25 00:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1740#issuecomment-7148662375) Closing in favour of #159, which came first (01:01) and covers everything here and more (pipeline statistics too). A correction to my comment above: I wrote that this PR adds a guard for queries around dropped draws over #159. That's wrong: #159's second commit ("an occlusion query around a draw the host skipped keeps its stand-in") already does it. The only differences were being on a newer `main` and an in-game check. @⁠r4tedx, once #159 is rebased onto current `main`, I can run it in the game on an RTX 5080 (diag build, debug layer and DRED) and report there. AI-assisted.

Pull request closed

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!1740
No description provided.