Skip to content

GPU: order shader writes on command list pipeline syncs (#732) - #1228

Open
Ctrl-Alt-Haze wants to merge 2 commits into
Marvisak:mainfrom
Ctrl-Alt-Haze:fix/gpu-sync-uav-barrier
Open

Ctrl-Alt-Haze wants to merge 2 commits into
Marvisak:mainfrom
Ctrl-Alt-Haze:fix/gpu-sync-uav-barrier

Conversation

@Ctrl-Alt-Haze

@Ctrl-Alt-Haze Ctrl-Alt-Haze commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Console command-list pipeline syncs (LIST_FUNCTIONS slots 129/130 and NEWER_LIST_FUNCTIONS slots 131/132/146) previously resolved to an empty no-op sync with a comment stating that host lists order their own work and every submission is waited for. While submissions are waited for between command lists, D3D12 does not implicitly synchronize dependent UAV reads/writes between consecutive Dispatch / Draw calls recorded within the same command list without an explicit UAV barrier (D3D12_RESOURCE_BARRIER_TYPE_UAV).

This PR makes sync emit a global UAV_BARRIER via the same wait_for_shader_writes(this) helper used by barrier_groups (related to #732, though not yet measured in-world).

Changes

  • crates/victory-gpu/src/list.rs:
    • Extracted wait_for_shader_writes(this) shared by sync and barrier_groups, emitting UAV_BARRIER on host_list(this) while safely no-oping when this is null, host is None, or on non-Windows targets.
    • Kept clean-room parity with barrier_groups and resource_barrier by not decoding undocumented console flags/control bitfields without title measurements.
    • Added list::tests::sync_is_safe_on_null_and_non_host_lists (verifies LIST_FUNCTIONS slots 129/130, NEWER_LIST_FUNCTIONS slots 131/132/146, null this, and host: None lists).
    • Added list::tests::sync_orders_dependent_compute_uav_dispatches (live D3D12 cs_5_1 4-stage dependent compute dispatches through sync / barrier_groups under the D3D12 Debug Layer — verifies API validity, slot wiring, and end-to-end correctness; does not force hardware overlap on drivers that serialize compute work by default).

Verification

  • Hardware / Toolchain: Windows 11 x64, NVIDIA GeForce RTX 5070 Ti + WARP (VICTORY_D3D12_WARP=1), D3D12 Debug Layer (VICTORY_D3D12_DEBUG=1), rebased onto upstream/main (940d32f) at 42b6c9e (1d05911, 42b6c9e, 0 behind / 2 ahead).
  • cargo xtask policy: passed (182 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
  • cargo test --workspace --exclude victory-gpu --exclude victory-shader --locked -- --test-threads=1: all passed (victory 12 [10 unit + 2 census], victory-core 13, victory-formats 38 / 5 ignored, victory-game 15, victory-hle 145 [143 unit + 1 fidelityfx + 1 no_dll_planting], victory-loader 38 [34 unit + 1 crash_log + 2 load_probe + 1 title_dlls], victory-pe 36, victory-pipeline 7, xtask 6)
  • cargo test -p victory-gpu --locked -- --test-threads=1 (RTX 5070 Ti): 143 passed; 2 failed; 2 ignored (pre-existing 940d32f failures: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views)
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1 (RTX 5070 Ti): 146 passed; 2 failed; 2 ignored (same 2 pre-existing failures; resolve_queries_rejects_overflowing_offset, sync_is_safe_on_null_and_non_host_lists, sync_orders_dependent_compute_uav_dispatches passed)
  • VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1: 148 passed; 0 failed; 2 ignored
  • cargo test -p victory-shader --features host --locked -- --test-threads=1 (RTX 5070 Ti): 244 passed; 3 failed; 3 ignored (pre-existing 940d32f failures: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware)
  • Not tested: in-world run or GPU capture from a live title (no runnable decrypted title binary available locally).

AI use: Written and rebased locally with AI assistance, independently audited and verified on RTX 5070 Ti + WARP.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 038503c: cargo test -p victory-gpu passes, 52 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@neonbyte1

Copy link
Copy Markdown

On Linux under Wine (vkd3d-proton, RTX 5090) the new sync_orders_dependent_compute_uav_dispatches test cannot build its shader. Wine's d3dcompiler_47 is vkd3d-shader, and it rejects RWByteAddressBuffer.Load:

D3DCompile failed (Call failed. (0x80004005)): sync_ordering_test:18:18: E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'.

#346 hit the same limit. It reads and writes RWStructuredBuffer<uint> and serializes its root signature in code instead of using [RootSignature(...)], and its compute tests then pass under Wine. The same change here would let this test run on Linux, which #1218's cargo xtask wine-test is meant to cover.

A stacking note: #190 removes Win32_Graphics_Direct3D_Fxc from victory-gpu's windows features because nothing on that branch used it any more. With both merged, the D3DCompile import here does not resolve until the feature is added back.

Locally I skip the test when Wine is detected (wine_get_version in ntdll). With that, the full workspace passes under Wine: 395 passed, 0 failed, 6 ignored.

AI-assisted (Claude).

@Ctrl-Alt-Haze

Ctrl-Alt-Haze commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

@neonbyte1 Thank you for catching that vkd3d-shader compatibility gap under Wine!

Updated sync_orders_dependent_compute_uav_dispatches in 63e6c9e to:

  • Replace RWByteAddressBuffer (.Load/.Store) with RWStructuredBuffer<uint> indexing (buf_a[idx] / buf_b[idx]).
  • Remove [RootSignature(...)] from the HLSL source and serialize the 3-parameter root signature (b0 2x32-bit constants, u0 UAV, u1 UAV) via D3D12SerializeRootSignature (D3D_ROOT_SIGNATURE_VERSION_1_0).

(Good catch on the #190 stacking note regarding Win32_Graphics_Direct3D_Fxc as well — Fxc is already enabled in crates/victory-gpu/Cargo.toml on main, so if #190 lands first this test will just need that feature kept or dxcompiler.)

@Zipettte Thanks for verifying 038503c on the RX 7700 XT as well!

Re-verified on 63e6c9e:

  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): pass
  • cargo test --workspace --locked: 344 passed, 0 failed, 6 ignored
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked (RTX 5070 Ti & VICTORY_D3D12_WARP=1): 55 passed, 0 failed, 1 ignored each (0 D3D12 debug errors)

suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ctrl-Alt-Haze
Ctrl-Alt-Haze force-pushed the fix/gpu-sync-uav-barrier branch from 63e6c9e to 5a1556e Compare November 25, 2026 00:22
@Ctrl-Alt-Haze

Copy link
Copy Markdown
Author

Rebased onto upstream main (ce2d91f) at 5a1556e (5215b2e, 5a1556e), resolving the crates/victory-gpu/src/list.rs test-module conflict cleanly while preserving resolve_queries_rejects_overflowing_offset.

Re-verified locally on 5a1556e (Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP):

  • cargo xtask policy: passed (178 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
  • cargo test --workspace --exclude victory-gpu --exclude victory-shader --locked -- --test-threads=1: all passed (victory 12 [10 unit + 2 census], victory-core 11, victory-formats 23 / 4 ignored, victory-game 15, victory-hle 126 [124 unit + 1 fidelityfx + 1 no_dll_planting], victory-loader 26 [22 unit + 1 crash_log + 2 load_probe + 1 title_dlls], victory-pe 10, victory-pipeline 4, xtask 6)
  • cargo test -p victory-gpu --locked -- --test-threads=1 (RTX 5070 Ti): 88 passed; 2 failed; 1 ignored (only the 2 pre-existing 70564ae/ce2d91f failures: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views)
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1 (RTX 5070 Ti): 91 passed; 2 failed; 1 ignored (same 2 pre-existing failures; resolve_queries_rejects_overflowing_offset, sync_is_safe_on_null_and_non_host_lists, and sync_orders_dependent_compute_uav_dispatches all passed)
  • VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1: 93 passed; 0 failed; 1 ignored
  • cargo test -p victory-shader --features host --locked -- --test-threads=1 (RTX 5070 Ti): 206 passed; 3 failed; 2 ignored (pre-existing 70564ae/ce2d91f failures: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware)

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

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


Generated by Claude Code

@Ctrl-Alt-Haze
Ctrl-Alt-Haze force-pushed the fix/gpu-sync-uav-barrier branch from 5a1556e to 42b6c9e Compare November 25, 2026 01:48
@Ctrl-Alt-Haze

Copy link
Copy Markdown
Author

Thanks for the review and clear feedback. Addressed both items and updated the PR description at 42b6c9e:

  1. Rebase onto current upstream/main (940d32f):

    • Rebased cleanly onto 940d32f with only the 2 PR commits remaining (1d05911, 42b6c9e; git rev-list --left-right --count upstream/main...HEAD is 0 2, no merge commits carried).
    • Verified locally on 42b6c9e (Windows 11 x64 / RTX 5070 Ti + WARP):
      • cargo xtask policy: passed (182 files ok)
      • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
      • Non-GPU workspace crates (--locked -- --test-threads=1): all passed (victory 12, victory-core 13, victory-formats 38 / 5 ignored, victory-game 15, victory-hle 145, victory-loader 38, victory-pe 36, victory-pipeline 7, xtask 6)
      • cargo test -p victory-gpu --locked -- --test-threads=1: 143 passed; 2 failed; 2 ignored (pre-existing 940d32f failures: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views)
      • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1: 146 passed; 2 failed; 2 ignored (same 2 pre-existing failures; all 3 list::tests::{resolve_queries_rejects_overflowing_offset, sync_is_safe_on_null_and_non_host_lists, sync_orders_dependent_compute_uav_dispatches} passed with 0 D3D12 debug errors)
      • VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1: 148 passed; 0 failed; 2 ignored
      • cargo test -p victory-shader --features host --locked -- --test-threads=1: 244 passed; 3 failed; 3 ignored (same 3 pre-existing RTX 5070 Ti 940d32f failures)
  2. Evidence & flags/control:

    • Why flags/control aren't decoded here: Under docs/asset-policy.md, list.rs avoids baking in unverified console register/cache-flush bitfields; this follows the same pattern already used by barrier_groups (which emits UAV_BARRIER whenever count > 0 without decoding _groups) and resource_barrier (which emits a global UAV_BARRIER for buffer barriers).
    • Why the previous no-op comment was incomplete: Waiting between queue submissions orders work across command lists, not within one D3D12 command list. Consecutive Dispatch/Draw calls accessing the same UAV in a single list require an explicit D3D12_RESOURCE_BARRIER_TYPE_UAV barrier under D3D12 rules.
    • Transparency on limits: I don't have a runnable decrypted title executable locally to record an in-world before/after frame time or hang capture, so I updated the PR description to frame this accurately around D3D12 intra-list correctness rather than claiming measured #732 impact, and noted that sync_orders_dependent_compute_uav_dispatches checks API validity and slot routing rather than forcing overlap on drivers that serialize dispatches by default. Happy to add a diagnostics hit counter or narrow on specific flags/control bits if someone running an in-world capture observes unwanted barrier overhead.

zhaibingye added a commit to zhaibingye/VIctory that referenced this pull request Nov 25, 2026
Forward guest syncs to an ordering barrier on the existing host command
list and preserve the original slot and D3D12 regression tests.

Linux GPU crate tests and Windows MSVC workspace test compilation passed.
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants