Skip to content

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

Closed
JurajSimicevic wants to merge 2 commits into
Marvisak:mainfrom
JurajSimicevic:gpu/real-queries
Closed

JurajSimicevic wants to merge 2 commits into
Marvisak:mainfrom
JurajSimicevic:gpu/real-queries

Conversation

@JurajSimicevic

Copy link
Copy Markdown

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

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 <noreply@anthropic.com>
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 <noreply@anthropic.com>

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified locally merged onto origin/main (70564ae, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu — all 79 passing tests (including all 3 new query/timestamp tests) pass on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (0 new failures; the 2 HEAP_VIEWS failures reproduce identically on untouched origin/main 70564ae)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean host occlusion query and calibrated timestamp implementation with solid test coverage. Looks good.

AI-assisted (Gemini 4 Neon).

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

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).

@JurajSimicevic

Copy link
Copy Markdown
Author

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; GPU: occlusion queries measure on the host instead of reporting every draw visible #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); GPU: occlusion queries measure on the host instead of reporting every draw visible #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

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

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.

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.

4 participants