GPU: queries run on the host GPU #3138

Open
github-bot wants to merge 2 commits from github-bot/gh-3138 into main AGit
Owner

@⁠FoxxoOwO on GitHub · 2026-11-26 09:52 UTC · original
FoxxoOwO:gpu/queries-host-2 → main · +267 −25 · 5 files · 2 commits · open

Replaces #2354, which no longer merges (conflict in crates/victory-gpu/src/host.rs) and had the timestamp overflow from its review. Rebased onto main 63bcca4.

Rebase. Both sides added a field to Deferred (waits from main, resolves here), so both are kept.

Timestamp fix (the review's finding). crates/victory-gpu/src/host.rs scaled with at.saturating_mul(TIMESTAMP_FREQUENCY) / host, and both reviewed tick counts overflow u64 before the division, so every guest timestamp came out identical. Scaling now goes through title_ticks(at, host_hz) in u128:

let title_hz = u128::from(crate::queue::TIMESTAMP_FREQUENCY);
(u128::from(at) * title_hz / u128::from(host_hz.max(1))) as u64

timestamps_scale_to_the_title_clock pins both intervals from the review: 26,509,312 ticks on a 1 GHz host → 2,650,931, and 254,637 on a 10 MHz host → 2,546,370, plus a zero frequency.

The README row no longer lists real queries as missing.

**@⁠FoxxoOwO** on GitHub · 2026-11-26 09:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3138) `FoxxoOwO:gpu/queries-host-2` → `main` · +267 −25 · 5 files · 2 commits · open Replaces #2354, which no longer merges (conflict in `crates/victory-gpu/src/host.rs`) and had the timestamp overflow from its review. Rebased onto `main` 63bcca4. **Rebase.** Both sides added a field to `Deferred` (`waits` from main, `resolves` here), so both are kept. **Timestamp fix** (the review's finding). `crates/victory-gpu/src/host.rs` scaled with `at.saturating_mul(TIMESTAMP_FREQUENCY) / host`, and both reviewed tick counts overflow u64 before the division, so every guest timestamp came out identical. Scaling now goes through `title_ticks(at, host_hz)` in u128: ```rust let title_hz = u128::from(crate::queue::TIMESTAMP_FREQUENCY); (u128::from(at) * title_hz / u128::from(host_hz.max(1))) as u64 ``` `timestamps_scale_to_the_title_clock` pins both intervals from the review: 26,509,312 ticks on a 1 GHz host → 2,650,931, and 254,637 on a 10 MHz host → 2,546,370, plus a zero frequency. The README row no longer lists real queries as missing.
BeginQuery, EndQuery and ResolveQueryData now record into the host list:
a console query heap gets a host heap on first use, of the matching type
(occlusion kinds share one, timestamps their own, pipeline statistics
theirs). Resolutions land in a read-back buffer the list maps once it has
run and copies into title memory.

Timestamps are the host GPU's clock, so they are rescaled to the title's
TICKS (100 MHz) on the way out; the queue's frequency comes from
GetTimestampFrequency. D3D12 has no BeginQuery for timestamps, so
begin_query skips them and only EndQuery marks them, as the API requires.

A heap whose kind or device cannot give a host heap keeps the previous
plausible answers, marked as a shortcut.
The copy-back multiplied in u64, so a tick count times 100 MHz saturated to
u64::MAX before the division and every guest timestamp came out identical:
a 1 GHz host passes u64::MAX / 100_000_000 with a 26.5 ms interval, and a
10 MHz host with 0.25 s. The product is now taken in u128; both of the
reviewed intervals scale correctly, which the test pins.

Rebased onto main 63bcca4 to resolve the conflict in host.rs (both sides
add a Deferred field, so both are kept), and the README row no longer lists
real queries as missing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:20 +00:00
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 10:40 UTC · original · edited 2026-11-26 10:47 UTC

I ran a guest timestamp heap through EndQuery and ResolveQueryData on native Windows. Both the RTX 5080 and inbox WARP rejected the command list at Close on 1a7750b7 in two runs each. With the D3D12 debug layer enabled, the error was 0x80070057, “Query type does not match query heap type.” The test stopped before submitting that list.

Host::query_heap receives the guest heap descriptor’s kind. A timestamp heap is 1, while an EndQuery timestamp operation is 2. At this revision heap kind 1 creates an occlusion heap. I corrected the three supported heap mappings and kept the operation mapping intact. The test resolves the same two native slots through the guest path and directly on the same queue, and checks the words on either side of the guest destination. Heap enum · Operation enum

With that correction, the new timestamp scaling on this PR agrees with the native readback. Two runs per adapter gave exact timestamps and preserved both guard words. One interval per adapter is shown below. Guest deltas are in the title’s 100 MHz clock.

Adapter Native frequency Native delta Guest delta
RTX 5080, 621.40 1 GHz 7,223,328 722,332
Windows inbox WARP 10 MHz 70,417 704,170

For comparison, with the same heap correction on parent eed5cb69, both RTX timestamps saturated to 18446744073, giving a zero interval. WARP’s absolute ticks in these runs were still below the old overflow threshold and matched on the parent. Heap fix and opt-in GPU regression

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3138-query-heap-kind
git cherry-pick 4a47605a66f47dec0d9cdd9074e26f5a5a853108
$env:VICTORY_D3D12_DEBUG = '1'
$env:VICTORY_D3D12_WARP = '0'
cargo test --locked -p victory-gpu --features diagnostics --lib query::timestamp_readback::timestamp_heap_resolves_the_same_slots_as_native_d3d12 -- --exact --ignored --nocapture

Set VICTORY_D3D12_WARP=1 for the software comparison.

I also checked the other affected mapping using empty query intervals. The unmodified head refused a pipeline-statistics heap (kind 2, operation 3) on both adapters with the same debug-layer error. With the patch, all 88 bytes of the guest statistics matched the native result on each device, and both neighboring guards stayed intact. Ordinary and binary occlusion queries (heap 0, operations 0 and 1) matched the native results before and after the patch on both adapters.

AI-assisted implementation and verification using synthetic queries.

**@⁠steven-seagull27** on GitHub · 2026-11-26 10:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3138#issuecomment-7189690410) · edited 2026-11-26 10:47 UTC I ran a guest timestamp heap through `EndQuery` and `ResolveQueryData` on native Windows. Both the RTX 5080 and inbox WARP rejected the command list at `Close` on `1a7750b7` in two runs each. With the D3D12 debug layer enabled, the error was `0x80070057`, “Query type does not match query heap type.” The test stopped before submitting that list. `Host::query_heap` receives the guest heap descriptor’s kind. A timestamp **heap** is 1, while an `EndQuery` timestamp **operation** is 2. At this revision heap kind 1 creates an occlusion heap. I corrected the three supported heap mappings and kept the operation mapping intact. The test resolves the same two native slots through the guest path and directly on the same queue, and checks the words on either side of the guest destination. [Heap enum](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_query_heap_type) · [Operation enum](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_query_type) With that correction, the new timestamp scaling on this PR agrees with the native readback. Two runs per adapter gave exact timestamps and preserved both guard words. One interval per adapter is shown below. Guest deltas are in the title’s 100 MHz clock. | Adapter | Native frequency | Native delta | Guest delta | |---|---:|---:|---:| | RTX 5080, 621.40 | 1 GHz | 7,223,328 | 722,332 | | Windows inbox WARP | 10 MHz | 70,417 | 704,170 | For comparison, with the same heap correction on parent `eed5cb69`, both RTX timestamps saturated to `18446744073`, giving a zero interval. WARP’s absolute ticks in these runs were still below the old overflow threshold and matched on the parent. [Heap fix and opt-in GPU regression](https://github.com/steven-seagull27/VIctory/commit/4a47605a66f47dec0d9cdd9074e26f5a5a853108) ```powershell git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3138-query-heap-kind git cherry-pick 4a47605a66f47dec0d9cdd9074e26f5a5a853108 $env:VICTORY_D3D12_DEBUG = '1' $env:VICTORY_D3D12_WARP = '0' cargo test --locked -p victory-gpu --features diagnostics --lib query::timestamp_readback::timestamp_heap_resolves_the_same_slots_as_native_d3d12 -- --exact --ignored --nocapture ``` Set `VICTORY_D3D12_WARP=1` for the software comparison. I also checked the other affected mapping using empty query intervals. The unmodified head refused a pipeline-statistics heap (kind 2, operation 3) on both adapters with the same debug-layer error. With the patch, all 88 bytes of the guest statistics matched the native result on each device, and both neighboring guards stayed intact. Ordinary and binary occlusion queries (heap 0, operations 0 and 1) matched the native results before and after the patch on both adapters. AI-assisted implementation and verification using synthetic queries.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 12:30 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib query:: -- --test-threads=1: 3/3 passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: 4/4 passed; queue::: passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly executes timestamp/occlusion queries on the host GPU and resolves them back to title memory.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 12:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/3138#pullrequestreview-6074149151) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib query:: -- --test-threads=1`: 3/3 passed on RTX 5090 and WARP. - `cargo test -p victory-gpu --lib list:: -- --test-threads=1`: 4/4 passed; `queue::`: passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly executes timestamp/occlusion queries on the host GPU and resolves them back to title memory. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/3138/head:github-bot/gh-3138'
git switch 'github-bot/gh-3138'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3138'
git switch 'github-bot/gh-3138'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3138'
git switch 'github-bot/gh-3138'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3138'
git switch 'main'
git merge --squash 'github-bot/gh-3138'
git switch 'main'
git merge --ff-only 'github-bot/gh-3138'
git switch 'main'
git merge 'github-bot/gh-3138'
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!3138
No description provided.