fix(gpu): serialize pipeline compilation, add VEH fast copy, and reduce lock contention #240

Open
amiltonjr wants to merge 6 commits from upstream-pr/240 into main
amiltonjr commented 2026-11-30 02:56:42 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by amiltonjr on 2026-11-30T02:56:42Z.


Summary

This pull request resolves startup crashes, reduces host memory copy overhead, mitigates frame-time latency spikes, and improves process lifecycle reliability on Windows.

Problems Solved

  1. AMD Driver Startup Crash (0xc0000005 in amdxc64.dll)
    Concurrent D3D12 pipeline state object (PSO) compilation across multiple worker threads caused race conditions inside host vendor drivers (specifically AMD's compiler DLL).

    • Fix: Added driver_compile_lock in library.rs to serialize D3D12 compilation calls into the driver by default. Can be bypassed via VICTORY_PARALLEL_COMPILE=1. Worker count is now configurable through VICTORY_PIPELINE_WORKERS.
  2. Host Buffer Copy Overhead and Safety
    Mapped host buffer copies previously relied on ReadProcessMemory syscalls on every buffer pass, which added kernel transition overhead. Direct user-space pointer copies crashed when hitting reserved but uncommitted sparse virtual pages.

    • Fix: Implemented read_fast using an x86_64 SSE2 user-space copy routine paired with a Vectored Exception Handler (VEH). Access violations (0xc0000005) within the copy routine's address bounds are caught and redirected cleanly to safe sparse reading without terminating the process.
  3. Lock Contention and Descriptor Table Latency Spikes
    In watch.rs, holding the global JOURNAL lock while calling guard() caused contention across render passes. Furthermore, descriptor tables rescanned every 16 passes in draw.rs, generating periodic frame-time stalls.

    • Fix: Dropped the JOURNAL lock before guarding view memory, added a known_view check to bypass doomed GetWriteWatch syscalls on protected blocks, and made the descriptor rescan interval configurable via VICTORY_BUFFER_RESCAN_INTERVAL (defaulting to 64).
  4. Launcher Lock Sharing Violation (os error 32) and Asset Policy Compliance
    Restarting the launcher quickly could fail when opening launcher.lock with exclusive sharing mode before the terminating process released the file handle. In addition, storing state in the binary directory could trigger asset policy errors when running from a repository build.

    • Fix: Added a 50-iteration retry loop with 100 ms sleep on launcher.lock. Defaulted the runtime folder to %LOCALAPPDATA%\DexNom Runtime to keep state and logs outside the source tree. Added percentage and timing metrics to victory warm.

Commits Included

  • fe72bb8: fix(gpu): serialize pipeline compilation and tune worker parallelism
  • 17fe85a: perf(gpu): implement fast user-space buffer copies with VEH recovery
  • afa194c: perf(gpu): reduce write-watch lock contention and configure descriptor rescans
  • 1004f4e: fix(play): handle launcher lock contention and sanitize runtime folder
  • 48c1071: fix(gpu): handle zero rescan interval, atomic watch publication, and VEH fallback
  • b2c7b3f: fix(play): preserve custom install path and runtime folder discovery

Verification & Testing

  • cargo clippy --workspace --all-targets --locked -- -D warnings: Passed with zero warnings or errors.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: Passed with zero warnings or errors.
  • cargo test --workspace --locked: 689 tests passed (12 ignored across 26 suites), including regression tests for zero rescan intervals, concurrent watch publication, VEH registration fallback, and custom launcher install discovery.
  • cargo run -p xtask -- policy: Passed (210 files ok, strictly adheres to Rule #1 asset policy).

Test System & Live Metrics

Component Specification / Baseline
CPU Intel Core i9-13900K, 24 cores (32 threads)
GPU AMD Radeon RX 6900 XT LC (Sapphire Liquid Cooled), 16 GB GDDR6
System Memory 32 GB DDR5
OS Windows 11 Pro x64 (Direct3D 12)
Live Gameplay Performance ~5 FPS average (3 to 11 FPS in heavy draw scenes), running stably with no crashes, memory leaks, or descriptor stalls
<!-- greyfinch-sync:DexNom/VIctory:issue:5558150131 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/240). Originally posted by [amiltonjr](https://github.com/amiltonjr) on 2026-11-30T02:56:42Z. --- ### Summary This pull request resolves startup crashes, reduces host memory copy overhead, mitigates frame-time latency spikes, and improves process lifecycle reliability on Windows. ### Problems Solved 1. **AMD Driver Startup Crash (`0xc0000005` in `amdxc64.dll`)** Concurrent D3D12 pipeline state object (PSO) compilation across multiple worker threads caused race conditions inside host vendor drivers (specifically AMD's compiler DLL). * **Fix:** Added `driver_compile_lock` in `library.rs` to serialize D3D12 compilation calls into the driver by default. Can be bypassed via `VICTORY_PARALLEL_COMPILE=1`. Worker count is now configurable through `VICTORY_PIPELINE_WORKERS`. 2. **Host Buffer Copy Overhead and Safety** Mapped host buffer copies previously relied on `ReadProcessMemory` syscalls on every buffer pass, which added kernel transition overhead. Direct user-space pointer copies crashed when hitting reserved but uncommitted sparse virtual pages. * **Fix:** Implemented `read_fast` using an x86_64 SSE2 user-space copy routine paired with a Vectored Exception Handler (VEH). Access violations (`0xc0000005`) within the copy routine's address bounds are caught and redirected cleanly to safe sparse reading without terminating the process. 3. **Lock Contention and Descriptor Table Latency Spikes** In `watch.rs`, holding the global `JOURNAL` lock while calling `guard()` caused contention across render passes. Furthermore, descriptor tables rescanned every 16 passes in `draw.rs`, generating periodic frame-time stalls. * **Fix:** Dropped the `JOURNAL` lock before guarding view memory, added a `known_view` check to bypass doomed `GetWriteWatch` syscalls on protected blocks, and made the descriptor rescan interval configurable via `VICTORY_BUFFER_RESCAN_INTERVAL` (defaulting to 64). 4. **Launcher Lock Sharing Violation (`os error 32`) and Asset Policy Compliance** Restarting the launcher quickly could fail when opening `launcher.lock` with exclusive sharing mode before the terminating process released the file handle. In addition, storing state in the binary directory could trigger asset policy errors when running from a repository build. * **Fix:** Added a 50-iteration retry loop with 100 ms sleep on `launcher.lock`. Defaulted the runtime folder to `%LOCALAPPDATA%\DexNom Runtime` to keep state and logs outside the source tree. Added percentage and timing metrics to `victory warm`. ### Commits Included - `fe72bb8`: fix(gpu): serialize pipeline compilation and tune worker parallelism - `17fe85a`: perf(gpu): implement fast user-space buffer copies with VEH recovery - `afa194c`: perf(gpu): reduce write-watch lock contention and configure descriptor rescans - `1004f4e`: fix(play): handle launcher lock contention and sanitize runtime folder - `48c1071`: fix(gpu): handle zero rescan interval, atomic watch publication, and VEH fallback - `b2c7b3f`: fix(play): preserve custom install path and runtime folder discovery ### Verification & Testing - `cargo clippy --workspace --all-targets --locked -- -D warnings`: Passed with zero warnings or errors. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: Passed with zero warnings or errors. - `cargo test --workspace --locked`: 689 tests passed (12 ignored across 26 suites), including regression tests for zero rescan intervals, concurrent watch publication, VEH registration fallback, and custom launcher install discovery. - `cargo run -p xtask -- policy`: Passed (210 files ok, strictly adheres to Rule #1 asset policy). #### Test System & Live Metrics | Component | Specification / Baseline | | --- | --- | | CPU | Intel Core i9-13900K, 24 cores (32 threads) | | GPU | AMD Radeon RX 6900 XT LC (Sapphire Liquid Cooled), 16 GB GDDR6 | | System Memory | 32 GB DDR5 | | OS | Windows 11 Pro x64 (Direct3D 12) | | Live Gameplay Performance | ~5 FPS average (3 to 11 FPS in heavy draw scenes), running stably with no crashes, memory leaks, or descriptor stalls |
Zippp69 commented 2026-11-30 16:07:59 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T16:07:59Z.


Review of 1004f4e

  1. [P1] Reject a zero buffer rescan interval. 0 parses and the first remainder operation panics. Add .filter(|&interval| interval != 0) before .unwrap_or(64). I reproduced the panic in a standalone Rust harness and verified the change on unset, zero, invalid, overflowing, and positive values. draw.rs
  2. [P1] Publish guarded writes before readers can observe a clean range. guard() can mark a range clean before dirty pages reach JOURNAL. An overlapping writes() call can then return old entries and skip changed bytes. Make the clean transition and publication atomic to readers, including in the failed-GetWriteWatch fallback. watch.rs
  3. [P1] Fall back if VEH registration fails. AddVectoredExceptionHandler can return null. The initializer still records the bounds and enables fast copy. Enable fast copy only after successful registration and fall back to read() otherwise. host.rs
  4. [P2] Preserve custom install discovery. Setup writes game-path.txt under -InstallDir and creates shortcuts that rely on discovery. Reading from the default installation can fail or select a different installation's game path. Resolve the configuration relative to the launcher executable. play_launcher.rs
  5. Driver lock coverage. Host::card_compare_pipeline still calls the driver directly and can overlap a background compile. Library loads can also overlap creation. Their relationship to the reported AMD crash remains unverified. library.rs · host.rs

On the locally patched Windows tree, the sparse fast-copy test and 14 watch tests passed. One watch performance test was ignored.

<!-- greyfinch-sync:DexNom/VIctory:comment:7284166564 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/240#issuecomment-7284166564). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T16:07:59Z. --- Review of `1004f4e` 1. **[P1] Reject a zero buffer rescan interval.** `0` parses and the first remainder operation panics. Add `.filter(|&interval| interval != 0)` before `.unwrap_or(64)`. I reproduced the panic in a standalone Rust harness and verified the change on unset, zero, invalid, overflowing, and positive values. [draw.rs](https://github.com/DexNom/VIctory/blob/1004f4e97b0f2cca57205dcd8b06102b43fd1ca4/crates/victory-gpu/src/draw.rs#L1676-L1683) 2. **[P1] Publish guarded writes before readers can observe a clean range.** `guard()` can mark a range clean before dirty pages reach `JOURNAL`. An overlapping `writes()` call can then return old entries and skip changed bytes. Make the clean transition and publication atomic to readers, including in the failed-`GetWriteWatch` fallback. [watch.rs](https://github.com/DexNom/VIctory/blob/1004f4e97b0f2cca57205dcd8b06102b43fd1ca4/crates/victory-gpu/src/watch.rs#L349-L405) 3. **[P1] Fall back if VEH registration fails.** `AddVectoredExceptionHandler` can return null. The initializer still records the bounds and enables fast copy. Enable fast copy only after successful registration and fall back to `read()` otherwise. [host.rs](https://github.com/DexNom/VIctory/blob/1004f4e97b0f2cca57205dcd8b06102b43fd1ca4/crates/victory-gpu/src/host.rs#L7472-L7480) 4. **[P2] Preserve custom install discovery.** Setup writes `game-path.txt` under `-InstallDir` and creates shortcuts that rely on discovery. Reading from the default installation can fail or select a different installation's game path. Resolve the configuration relative to the launcher executable. [play_launcher.rs](https://github.com/DexNom/VIctory/blob/1004f4e97b0f2cca57205dcd8b06102b43fd1ca4/apps/victory/src/play_launcher.rs#L115-L134) 5. **Driver lock coverage.** `Host::card_compare_pipeline` still calls the driver directly and can overlap a background compile. Library loads can also overlap creation. Their relationship to the reported AMD crash remains unverified. [library.rs](https://github.com/DexNom/VIctory/blob/1004f4e97b0f2cca57205dcd8b06102b43fd1ca4/crates/victory-gpu/src/pipeline/library.rs#L537-L563) · [host.rs](https://github.com/DexNom/VIctory/blob/1004f4e97b0f2cca57205dcd8b06102b43fd1ca4/crates/victory-gpu/src/host.rs#L4253) On the locally patched Windows tree, the sparse fast-copy test and 14 watch tests passed. One watch performance test was ignored.
Zippp69 commented 2026-11-30 18:04:36 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T18:04:36Z.


Tested launcher fix for custom installation paths. Follow-up to the launcher finding at 1004f4e. In the no-argument path, read the installation config with exe_folder.join("game-path.txt") and resolve a relative game path with exe_folder.join(value.trim()). The runtime profile still owns logs, state, and cache. Five launcher unit tests passed. I ran the built launcher against a stub runtime with different game paths in the custom install and the default profile. It selected the custom install's game and created logs and the lock under the profile.

<!-- greyfinch-sync:DexNom/VIctory:comment:7287308001 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/240#issuecomment-7287308001). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T18:04:36Z. --- **Tested launcher fix for custom installation paths.** Follow-up to [the launcher finding](https://github.com/DexNom/VIctory/pull/240#issuecomment-7284166564) at `1004f4e`. In the no-argument path, read the installation config with `exe_folder.join("game-path.txt")` and resolve a relative game path with `exe_folder.join(value.trim())`. The runtime profile still owns logs, state, and cache. Five launcher unit tests passed. I ran the built launcher against a stub runtime with different game paths in the custom install and the default profile. It selected the custom install's game and created logs and the lock under the profile.
Zippp69 commented 2026-11-30 19:05:58 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T19:05:58Z.


Tested fallback for failed VEH registration. Follow-up to the review on 1004f4e. Cache the registration result in a OnceLock<Option<(usize, usize)>> and publish bounds only when AddVectoredExceptionHandler returns a non-null handle. The callback reads a successful registration with let Some(&Some((start, fail))) = FAST_COPY_BOUNDS.get() else { return EXCEPTION_CONTINUE_SEARCH; };. Have the initializer return whether the cached bounds are present and guard the fast path with:

if !install_fast_copy_handler() {
    return read(src, dst, len);
}

The existing sparse-copy test passed with normal registration. It also passed in a separate test run that initialized the cell to None before any copy, simulating failed registration and exercising the ReadProcessMemory and sparse-copy fallbacks. host.rs

<!-- greyfinch-sync:DexNom/VIctory:comment:7288840866 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/240#issuecomment-7288840866). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T19:05:58Z. --- **Tested fallback for failed VEH registration.** Follow-up to [the review](https://github.com/DexNom/VIctory/pull/240#issuecomment-7284166564) on `1004f4e`. Cache the registration result in a `OnceLock<Option<(usize, usize)>>` and publish bounds only when `AddVectoredExceptionHandler` returns a non-null handle. The callback reads a successful registration with `let Some(&Some((start, fail))) = FAST_COPY_BOUNDS.get() else { return EXCEPTION_CONTINUE_SEARCH; };`. Have the initializer return whether the cached bounds are present and guard the fast path with: ```rust if !install_fast_copy_handler() { return read(src, dst, len); } ``` The existing sparse-copy test passed with normal registration. It also passed in a separate test run that initialized the cell to `None` before any copy, simulating failed registration and exercising the `ReadProcessMemory` and sparse-copy fallbacks. [host.rs](https://github.com/DexNom/VIctory/blob/1004f4e97b0f2cca57205dcd8b06102b43fd1ca4/crates/victory-gpu/src/host.rs#L7423-L7481)
amiltonjr commented 2026-12-01 16:08:00 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by amiltonjr on 2026-12-01T16:08:00Z.


Thank you for the thorough review, @Zippp69. I addressed these findings in 48c1071 and b2c7b3f:

  1. [P1] Reject zero buffer rescan interval (draw.rs): Added parse_rescan_interval with .filter(|&interval| interval != 0) before defaulting to 64. Covered by draw::tests::rescan_interval_rejects_zero_and_invalid_values.
  2. [P1] Atomic watch publication (watch.rs): Kept JOURNAL locked across guard() in both known_view and the GetWriteWatch failure fallback so clean-block updates in GUARDS and write timestamps in JOURNAL stay atomic to concurrent writes() readers. Added watch::tests::concurrent_writes_on_view_never_misses_guarded_pages, which reproduced the stale write race before the fix and passes after.
  3. [P1] VEH registration fallback (host.rs): Changed FAST_COPY_BOUNDS to OnceLock<Option<(usize, usize)>> so fast copy activates only when AddVectoredExceptionHandler returns a non-null handle, falling back to read() otherwise. Covered by fast_copy_tests::veh_registration_failure_disables_fast_copy_and_uses_read_fallback across committed memory and an uncommitted reservation.
  4. [P2] Custom install discovery (play_launcher.rs): Kept exe_folder as the runtime root whenever victory_core::ensure_outside_repo(exe_folder) succeeds so -InstallDir deployments remain isolated (game-path.txt, state, logs, cache, and fidelityfx). Redirected runtime data to %LOCALAPPDATA%\DexNom Runtime only when launched from inside a source checkout, while still checking exe_folder/game-path.txt (and resolving relative paths against it) first. Covered by custom_install_discovery_uses_exe_folder_when_outside_repo.
  5. Driver lock coverage (host.rs, library.rs): Acquired driver_compile_lock around CreateComputePipelineState in Host::card_compare_pipeline. LoadPipeline remains outside the compile lock so warm cache loads stay parallel (synchronized per pipeline name by same_name, or globally when VICTORY_LIBRARY_LOCK=1 is set).

Verification run after the final edit:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings, 0 errors
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings, 0 errors
  • cargo test --workspace --locked: 689 passed, 12 ignored (26 suites)
  • cargo run -p xtask -- policy: asset policy: 210 files ok
  • cargo build --locked --release --target x86_64-pc-windows-msvc -p victory --bins: clean build
<!-- greyfinch-sync:DexNom/VIctory:comment:7317088819 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/240#issuecomment-7317088819). Originally posted by [amiltonjr](https://github.com/amiltonjr) on 2026-12-01T16:08:00Z. --- Thank you for the thorough review, @Zippp69. I addressed these findings in `48c1071` and `b2c7b3f`: 1. **[P1] Reject zero buffer rescan interval (`draw.rs`):** Added `parse_rescan_interval` with `.filter(|&interval| interval != 0)` before defaulting to `64`. Covered by `draw::tests::rescan_interval_rejects_zero_and_invalid_values`. 2. **[P1] Atomic watch publication (`watch.rs`):** Kept `JOURNAL` locked across `guard()` in both `known_view` and the `GetWriteWatch` failure fallback so clean-block updates in `GUARDS` and write timestamps in `JOURNAL` stay atomic to concurrent `writes()` readers. Added `watch::tests::concurrent_writes_on_view_never_misses_guarded_pages`, which reproduced the stale write race before the fix and passes after. 3. **[P1] VEH registration fallback (`host.rs`):** Changed `FAST_COPY_BOUNDS` to `OnceLock<Option<(usize, usize)>>` so fast copy activates only when `AddVectoredExceptionHandler` returns a non-null handle, falling back to `read()` otherwise. Covered by `fast_copy_tests::veh_registration_failure_disables_fast_copy_and_uses_read_fallback` across committed memory and an uncommitted reservation. 4. **[P2] Custom install discovery (`play_launcher.rs`):** Kept `exe_folder` as the runtime root whenever `victory_core::ensure_outside_repo(exe_folder)` succeeds so `-InstallDir` deployments remain isolated (`game-path.txt`, `state`, `logs`, `cache`, and `fidelityfx`). Redirected runtime data to `%LOCALAPPDATA%\DexNom Runtime` only when launched from inside a source checkout, while still checking `exe_folder/game-path.txt` (and resolving relative paths against it) first. Covered by `custom_install_discovery_uses_exe_folder_when_outside_repo`. 5. **Driver lock coverage (`host.rs`, `library.rs`):** Acquired `driver_compile_lock` around `CreateComputePipelineState` in `Host::card_compare_pipeline`. `LoadPipeline` remains outside the compile lock so warm cache loads stay parallel (synchronized per pipeline name by `same_name`, or globally when `VICTORY_LIBRARY_LOCK=1` is set). Verification run after the final edit: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: 0 warnings, 0 errors - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: 0 warnings, 0 errors - `cargo test --workspace --locked`: 689 passed, 12 ignored (26 suites) - `cargo run -p xtask -- policy`: asset policy: 210 files ok - `cargo build --locked --release --target x86_64-pc-windows-msvc -p victory --bins`: clean build
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/240:upstream-pr/240'
git switch 'upstream-pr/240'

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/240'
git switch 'upstream-pr/240'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/240'
git switch 'upstream-pr/240'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/240'
git switch 'main'
git merge --squash 'upstream-pr/240'
git switch 'main'
git merge --ff-only 'upstream-pr/240'
git switch 'main'
git merge 'upstream-pr/240'
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
DexNom/VIctory!240
No description provided.