GPU: queries run on the host GPU #3136

Open
FoxxoOwO wants to merge 2 commits from upstream-pr/3138 into main
FoxxoOwO commented 2026-11-26 09:52:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by FoxxoOwO on 2026-11-26T09:52:52Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6624013610 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3138). Originally posted by [FoxxoOwO](https://github.com/FoxxoOwO) on 2026-11-26T09:52:52Z. --- 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.
steven-seagull27 commented 2026-11-26 11:04:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T10:40:56Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189690410 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3138#issuecomment-7189690410). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T10:40:56Z. --- 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.
Dukestar69 commented 2026-11-26 13:04:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:30:23Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6074149151 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3138#pullrequestreview-6074149151). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:30:23Z. **Review:** APPROVED --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3138:upstream-pr/3138'
git switch 'upstream-pr/3138'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3138'
git switch 'upstream-pr/3138'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3138'
git switch 'upstream-pr/3138'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3138'
git switch 'main'
git merge --squash 'upstream-pr/3138'
git switch 'main'
git merge --ff-only 'upstream-pr/3138'
git switch 'main'
git merge 'upstream-pr/3138'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3136
No description provided.