GPU: blocking fence waits, feature queries, device methods, private interfaces #1957

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

@⁠RaghavVijayanand on GitHub · 2026-11-25 01:45 UTC · original
RaghavVijayanand:gpu/fences-and-features → main · +849 −92 · 5 files · 4 commits · open

Four runtime gaps in victory-gpu, one commit each.

  • Fences: blocking wait. SetEventOnCompletion with a null event returned E_NOTIMPL. It now blocks on a condition variable until the fence reaches the value, rechecking every 1 ms in case the title stores to the fence address from the CPU.
    • Bug fixed along the way: bottom-of-pipe writes to a fence's GPU address changed its value without the fence knowing, so events and waits for that value never fired. Live fences are now registered by the address of their value, and Written::write wakes them.
  • Device: feature queries. Before, only ids 0-4 were answered and everything else returned E_NOTIMPL; format support also claimed every use of every format.
    • Upstream's local console answers for shader model (7), options 1 (8) and options 4 (23) are kept, and now also get size checks.
    • Answered locally: ids 0-2 as before, GPU virtual address bits (id 6), and architecture 1 (id 16).
    • Format queries (ids 3-5) go to the host. The console's 16-bit depth formats are asked as the PC formats that stand in for them.
    • Every other id goes to the host unchanged.
    • Locally answered ids return E_INVALIDARG on a wrong size, as D3D12 does.
  • Device methods at their PC slots: MakeResident, Evict and SetStablePowerState now succeed as on PC. (Upstream already answers GetDeviceRemovedReason from the host, so that part was dropped in the rebase.)
  • SetPrivateDataInterface: stores the interface with a reference, which is handed out by GetPrivateData and released on replace, removal or free.

Tests: 14 new tests (7 for fences, 5 for the device, 2 for objects). The blocked-wait tests run on threads with a timeout, so a bug fails the test instead of hanging it. Each fix was broken on purpose to confirm its tests fail. root::tests::the_table_has_the_object_and_device_child_slots asserted that SetPrivateDataInterface returns E_NOTIMPL; it now checks the implemented behaviour instead.

Left alone on purpose: Queue Wait still never blocks. Submissions are synchronous on the calling thread, so blocking there could deadlock.

Unrelated observation: frame::tests::waits_end_on_ticks_and_count_frames failed once on its elapsed <= 50ms check under load and passed in later runs. It looks timing-sensitive.

Rebased onto current main (940d32f). On this machine, 5 tests fail on main itself, with or without this change: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views, the two stride_tests::a_heap_buffer_read_* tests, and synthetic_tests::gathers_at_a_level_match_the_hardware. Everything else passes, and clippy passes with -D warnings, with and without --all-features.

**@⁠RaghavVijayanand** on GitHub · 2026-11-25 01:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1957) `RaghavVijayanand:gpu/fences-and-features` → `main` · +849 −92 · 5 files · 4 commits · open Four runtime gaps in victory-gpu, one commit each. - **Fences: blocking wait.** `SetEventOnCompletion` with a null event returned E_NOTIMPL. It now blocks on a condition variable until the fence reaches the value, rechecking every 1 ms in case the title stores to the fence address from the CPU. - **Bug fixed along the way:** bottom-of-pipe writes to a fence's GPU address changed its value without the fence knowing, so events and waits for that value never fired. Live fences are now registered by the address of their value, and `Written::write` wakes them. - **Device: feature queries.** Before, only ids 0-4 were answered and everything else returned E_NOTIMPL; format support also claimed every use of every format. - Upstream's local console answers for shader model (7), options 1 (8) and options 4 (23) are kept, and now also get size checks. - Answered locally: ids 0-2 as before, GPU virtual address bits (id 6), and architecture 1 (id 16). - Format queries (ids 3-5) go to the host. The console's 16-bit depth formats are asked as the PC formats that stand in for them. - Every other id goes to the host unchanged. - Locally answered ids return E_INVALIDARG on a wrong size, as D3D12 does. - **Device methods at their PC slots:** MakeResident, Evict and SetStablePowerState now succeed as on PC. (Upstream already answers GetDeviceRemovedReason from the host, so that part was dropped in the rebase.) - **SetPrivateDataInterface:** stores the interface with a reference, which is handed out by GetPrivateData and released on replace, removal or free. **Tests:** 14 new tests (7 for fences, 5 for the device, 2 for objects). The blocked-wait tests run on threads with a timeout, so a bug fails the test instead of hanging it. Each fix was broken on purpose to confirm its tests fail. `root::tests::the_table_has_the_object_and_device_child_slots` asserted that SetPrivateDataInterface returns E_NOTIMPL; it now checks the implemented behaviour instead. Left alone on purpose: Queue Wait still never blocks. Submissions are synchronous on the calling thread, so blocking there could deadlock. Unrelated observation: `frame::tests::waits_end_on_ticks_and_count_frames` failed once on its `elapsed <= 50ms` check under load and passed in later runs. It looks timing-sensitive. **Rebased onto current main (940d32f).** On this machine, 5 tests fail on main itself, with or without this change: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`, the two `stride_tests::a_heap_buffer_read_*` tests, and `synthetic_tests::gathers_at_a_level_match_the_hardware`. Everything else passes, and clippy passes with `-D warnings`, with and without `--all-features`.
A null event asks the calling thread to block until the fence reaches
the value. That returned E_NOTIMPL, so a title waiting on the CPU for
work another thread signals got a failure instead of the wait. It now
blocks on a condition variable that every change of the value notifies,
letting the waiters lock go while it sleeps, so signals from other
threads (the title's, or a queue's) get through. Values already reached
return at once, as before. Nothing gives up on a wait: a removed host
device ends the process, and our submissions are done when they return.

Bottom-of-pipe writes never reached a fence's events: titles point them
at a fence's GPU address, and the write landed in the value behind the
fence's back, so an event or a wait for that value was never woken.
Live fences are now registered by the address of their value (dropped
from the registry when the fence is freed, under the registry's lock),
and a write that touches one sets its events and wakes its waits. A
blocked wait also looks at the value again every millisecond, for a
title that stores it from the CPU.

Tests: threads blocked for different values wake at the first signal
reaching theirs and not before, from another thread or a queue; waits
for reached values return at once; events are set once, in order, and
not again by later signals; 64- and 32-bit bottom-of-pipe writes at the
fence's address wake its event and waits, and a write elsewhere does
not; a plain store ends a blocked wait; a freed fence leaves the
registry. Each fails with its fix broken: the old E_NOTIMPL return
fails the four blocked-wait tests, no notification with no recheck fails
them too, no recheck alone fails the store test, no hook in the
bottom-of-pipe write fails its test, events kept after firing fail the
once-only test, and no unregistering fails the registry test. Clippy
(default and all features) is clean and the workspace's tests pass.
CheckFeatureSupport answered the options, architecture, feature levels,
format support, multisample levels, shader model and options 1 and 4
(ids 0-4, 7, 8, 23) and failed every other query with E_NOTIMPL. Format
support also claimed every use of every format, a shortcut whose comment
asked for the host's answer.

The device now also answers what the console or our memory model
decides: GPU address bits (6: 40 per resource, as the options say, and
all of user space per process, since GPU addresses are CPU addresses) and
the first architecture extension (16: as the architecture, with the
host's answer for whether the GPU honours the CPU's page protections).
The shader model and options 1 and 4 keep their console answers. Format
queries (format support, multisample levels, format info: 3-5) go to the
host, which makes and samples the textures, with the console's own
16-bit depth formats asked as the PC formats standing in for them and
the title's format left in the structure; without a host the old
answers stay (format info has none). Every other query goes to the host
unchanged, which checks its size as D3D12 does. The ids are taken to be
PC's, as the existing answers took them, and those structures to be
PC's: only the options are known to differ, and they are not passed on.
Sizes of the structures answered here are checked, null data included,
and fail with E_INVALIDARG.

Tests: each query answered here fails on a size four bytes short or
long, on zero and on null data without touching the structure; the
local answers are the console's; options 3, options 5 and root
signature queries match the host's own answers and fail on a wrong
size; format support for RGBA8 has no depth bit, and the console's
16-bit depth with stencil gets the host's answer for D24S8 with its own
format kept; multisample and plane count queries likewise. Without the
format translation, without passing other queries to the host, with the
old format shortcut, and without the size check for address bits, a
test fails in each case. Clippy (default and all features) is clean.
The device's table follows PC's order up to GetAdapterLuid (CreateFence,
GetDeviceRemovedReason, GetCopyableFootprints, CreateQueryHeap and
CreateCommandSignature are already at their PC slots), but MakeResident,
Evict (0x110, 0x118) and SetStablePowerState (0x140) were the logging
stubs that return E_NOTIMPL.

They now succeed as on PC: residency calls accept any objects (ours
stay where the title left them, and the host pages its own) and refuse
a null list of a non-zero count; power state requests are accepted and
ignored.

Tests: each is called through its slot with the PC arguments. With
Evict or SetStablePowerState left unwritten, the test fails with
E_NOTIMPL. Clippy (default and all features) is clean and the
workspace's tests pass.
Every D3D12 object's table had GetPrivateData, SetPrivateData and
SetName, but SetPrivateDataInterface (0x28) was the logging stub that
returns E_NOTIMPL, so a title attaching an interface to an object got a
failure.

It now stores the interface's address under the id and holds a
reference to it, as PC does: GetPrivateData hands the address out with
a new reference (none when only the size is asked or the buffer is too
small), and the reference is let go when the entry is replaced (by
bytes or another interface), removed (a null interface) or the object
is freed. References are let go only once the private data is unlocked,
since releasing one of our own objects frees it and locks the private
data again.

Tests: a stand-in COM object counts its references through setting,
reading, short reads, replacing, removing and freeing the holder, and
one of our fences held by another is released with it without a
deadlock. Without the release when the holder is freed, without the
reference handed out by GetPrivateData, or without the release of a
replaced entry, the counting test fails. The root signature's table
test, which expected the stub, now checks that the method needs an id
and takes a null interface. Clippy (default and all features) is clean.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:01 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 02:19 UTC · original · edited 2026-11-25 16:03 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/fence.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1957#issuecomment-7150576182) · edited 2026-11-25 16:03 UTC <!-- victory-triage v1 head=7fb320fe477f358742bb31d0f252e8760355ebbe verdict=needs-rebase at=2026-11-25T16:15:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/fence.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
github-bot force-pushed github-bot/gh-1957 from 7fb320fe47 to d4d878f6e4 2026-11-26 11:11:09 +00:00 Compare
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 01:45 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 01:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1957#pullrequestreview-6050344700) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 02:10 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.

Blocking fence waits + feature queries: fence-wait implementation — pairs with #1734's fence tests.

**@⁠catminou4** on GitHub · 2026-11-25 02:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1957#pullrequestreview-6050613375) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Blocking fence waits + feature queries: fence-wait implementation — pairs with #1734's fence tests.
Author
Owner

@⁠RaghavVijayanand on GitHub · 2026-11-26 10:58 UTC · original

Rebased onto main 63bcca4. fence.rs merged with main's held-work changes: waiters keep the time they started waiting, and reached() (shared by queue/title signals and bottom-of-pipe writes) adds to WAITED as set did. main's rewind check (#2164) is kept in signals_set_waiting_events, using this branch's test helpers. On an RTX 5060 Laptop: the fence/device/object/queue tests pass (45), and clippy is clean with and without features. Two victory-gpu tests fail, but they fail the same way on unmodified main there (NVIDIA's 1M-view heap cap): dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views.

**@⁠RaghavVijayanand** on GitHub · 2026-11-26 10:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1957#issuecomment-7190080510) Rebased onto `main` 63bcca4. `fence.rs` merged with `main`'s held-work changes: waiters keep the time they started waiting, and `reached()` (shared by queue/title signals and bottom-of-pipe writes) adds to `WAITED` as `set` did. `main`'s rewind check (#2164) is kept in `signals_set_waiting_events`, using this branch's test helpers. On an RTX 5060 Laptop: the fence/device/object/queue tests pass (45), and clippy is clean with and without features. Two `victory-gpu` tests fail, but they fail the same way on unmodified `main` there (NVIDIA's 1M-view heap cap): `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`.
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/1957/head:github-bot/gh-1957'
git switch 'github-bot/gh-1957'

Merge

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