GPU: make fence signaling monotonic, clamp sampler enums, and add unit tests #932

Open
opened 2026-11-24 14:18:19 +00:00 by geiyiliyabumo · 2 comments
geiyiliyabumo commented 2026-11-24 14:18:19 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T14:18:19Z.


Summary

Fixes 2 real bugs in crates/victory-gpu/src/fence.rs and crates/victory-gpu/src/sampler.rs and adds 11 deterministic synthetic unit tests.

Because external PR creation is currently restricted (collaborators_only), the CI-green branch is ready on my fork for cherry-pick / review:

  • Branch: geiyiliyabumo/VIctory@test/gpu-fence-and-sampler
  • Commit: geiyiliyabumo/VIctory@370c61b (based on main ffe310e)

Changes

  • crates/victory-gpu/src/fence.rs:
    • Fixed signal using store (which allowed a lower signal value to move a D3D12 fence backwards) to use fetch_max(value, Ordering::AcqRel).
    • Added 5 unit tests (fence:: 6/6 PASS): monotonic signaling, creation flags & GPU address, COM interfaces/refcount, all 5 vtable slots, and Windows event waiters.
  • crates/victory-gpu/src/sampler.rs:
    • Clamped decoded D3D12_COMPARISON_FUNC (1..=8) and D3D12_TEXTURE_ADDRESS_MODE (1..=5) enum words so out-of-range title descriptors do not cause host CreateSampler to silently drop the descriptor.
    • Added 6 unit tests (sampler:: 7/7 PASS): filter bits, comparison/reduction encoding, comparison & anisotropy clamping, LOD/bias/border, and address modes.

Verification (Windows 11 x64 MSVC)

  • rustfmt --edition 2024 --check: PASS
  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default + --features diagnostics): PASS (0 warnings)
  • cargo test -p victory-gpu --locked -- fence:: (6/6 PASS) & -- sampler:: (7/7 PASS)

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6583844725 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/932). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T14:18:19Z. --- ### Summary Fixes 2 real bugs in `crates/victory-gpu/src/fence.rs` and `crates/victory-gpu/src/sampler.rs` and adds 11 deterministic synthetic unit tests. Because external PR creation is currently restricted (`collaborators_only`), the CI-green branch is ready on my fork for cherry-pick / review: - **Branch**: `geiyiliyabumo/VIctory@test/gpu-fence-and-sampler` - **Commit**: `geiyiliyabumo/VIctory@370c61b` (based on `main` `ffe310e`) ### Changes - **`crates/victory-gpu/src/fence.rs`**: - Fixed `signal` using `store` (which allowed a lower signal value to move a D3D12 fence backwards) to use `fetch_max(value, Ordering::AcqRel)`. - Added 5 unit tests (`fence::` **6/6 PASS**): monotonic signaling, creation flags & GPU address, COM interfaces/refcount, all 5 vtable slots, and Windows event waiters. - **`crates/victory-gpu/src/sampler.rs`**: - Clamped decoded `D3D12_COMPARISON_FUNC` (`1..=8`) and `D3D12_TEXTURE_ADDRESS_MODE` (`1..=5`) enum words so out-of-range title descriptors do not cause host `CreateSampler` to silently drop the descriptor. - Added 6 unit tests (`sampler::` **7/7 PASS**): filter bits, comparison/reduction encoding, comparison & anisotropy clamping, LOD/bias/border, and address modes. ### Verification (Windows 11 x64 MSVC) - `rustfmt --edition 2024 --check`: **PASS** - `cargo xtask policy`: **PASS** (`154 files ok`) - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default + `--features diagnostics`): **PASS** (0 warnings) - `cargo test -p victory-gpu --locked -- fence::` (**6/6 PASS**) & `-- sampler::` (**7/7 PASS**) *AI-assisted; synthetic tests only, no game files.*
andrewpozdnakov7-jpg commented 2026-11-24 15:04:01 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-24T14:25:48Z.


Native D3D12 permits fence values to decrease. With WARP on Windows 10, signals 5 → 2 left GetCompletedValue() at 2. A new event for 4 stayed pending until the next signal of 4. D3D12 fence semantics

The VIctory regression test failed on 370c61b: the same signals left the value at 5. The follow-up restores the latest signal value and checks that an event registered after a rewind waits for the next qualifying signal. Fix and regression test

The commit is directly on 370c61b. After the fix, all 6 fence tests and 64 GPU diagnostics tests passed, with 1 existing benchmark ignored. Clippy and the asset policy check passed. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134360370 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/932#issuecomment-7134360370). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-24T14:25:48Z. --- Native D3D12 permits fence values to decrease. With WARP on Windows 10, signals `5 → 2` left `GetCompletedValue()` at 2. A new event for 4 stayed pending until the next signal of 4. [D3D12 fence semantics](https://learn.microsoft.com/en-us/windows/win32/direct3d12/user-mode-heap-synchronization) The VIctory regression test failed on `370c61b`: the same signals left the value at 5. The follow-up restores the latest signal value and checks that an event registered after a rewind waits for the next qualifying signal. [Fix and regression test](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/3780ed782057f5894d7f6fb6cb956ea7cc87c02a) The commit is directly on `370c61b`. After the fix, all 6 fence tests and 64 GPU diagnostics tests passed, with 1 existing benchmark ignored. Clippy and the asset policy check passed. AI-assisted.
Marvisak commented 2026-11-25 07:03:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:57:10Z.


Automated triage for the maintainers.

Neither change is needed as described:

  • Fence: signal in crates/victory-gpu/src/fence.rs stores the value as given. That matches native D3D12, where a fence's value may go down: the comment above shows WARP leaving GetCompletedValue() at 2 after signals 5 then 2. With fetch_max the regression test there fails, so the current behaviour is the correct one.
  • Sampler: address modes outside 1..=5 already fall back to CLAMP on main (address_mode in crates/victory-gpu/src/sampler.rs, from PR #474). The comparison function is passed through only when the comparison reduction is selected. A title descriptor with an out-of-range value there hasn't been shown.

The new unit tests could still be useful. Pull requests are open to everyone again if you want to offer them on their own.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155329861 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/932#issuecomment-7155329861). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T06:57:10Z. --- <!-- victory-issue-triage v1 verdict=answered seen=2026-11-24T14:25:48Z at=2026-11-25T06:57:09Z --> Automated triage for the maintainers. Neither change is needed as described: - **Fence:** `signal` in `crates/victory-gpu/src/fence.rs` stores the value as given. That matches native D3D12, where a fence's value may go down: the comment above shows WARP leaving `GetCompletedValue()` at 2 after signals 5 then 2. With `fetch_max` the regression test there fails, so the current behaviour is the correct one. - **Sampler:** address modes outside `1..=5` already fall back to `CLAMP` on `main` (`address_mode` in `crates/victory-gpu/src/sampler.rs`, from PR #474). The comparison function is passed through only when the comparison reduction is selected. A title descriptor with an out-of-range value there hasn't been shown. The new unit tests could still be useful. Pull requests are open to everyone again if you want to offer them on their own. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
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#932
No description provided.