GPU: prevent overflow and enforce workload bounds in indirect execution #40
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!40
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/40/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@aycow on GitHub · 2026-11-23 23:39 UTC · original
aycow:fix/indirect-workload-validation→main· +1100 −129 · 6 files · 5 commits · closed without mergingWhat
The sanitizer introduced in
8c26061f3multiplied compute dimensions in 32-bit arithmetic before capping the result. It capped the charged cost while leaving oversized grids in the argument buffer. Its budget counter also added rejected costs, so it could wrap and admit work after the limit was reached.The original shader left
[2048, 2048, 1024]intact after the 2^32 product wrapped to zero. It also retained[1025, 1024, 1]above the 2^20 group limit. The synthetic tests run the sanitizer and inspect the resulting arguments and budget. They never execute the oversized dispatches.mainat35b054e, including its 2^27 budget and the single-pass dispatch mapping.Review changes
Tested
22b9ed1The app-local Microsoft Agility SDK 1.620.2 enabled the debug layer. The validation run checked device configuration for active GPU-based validation with resource-state tracking and failed on D3D12 InfoQueue errors. The matrix covers CPU-generated counts, shared argument/count resources, same-submission UAV and copy producers, and repeated executions across submission boundaries. With the legacy handoff deliberately omitted, a same-list negative control reported the count buffer still in COPY_DEST or UAV when ExecuteIndirect required INDIRECT_ARGUMENT. Restoring the handoff passed on AMD and WARP.
Run
cargo test -p victory-gpu --features diagnostics indirect -- --nocapture --test-threads=1with an active debug runtime. SetVICTORY_D3D12_DEBUG=1andVICTORY_TEST_D3D12_VALIDATE=1, and addVICTORY_D3D12_GBV=1for full validation. UseVICTORY_TEST_LEGACY_INDIRECT=1to force legacy barriers andVICTORY_D3D12_WARP=1for WARP. Workspace tests passed (240 passed, 3 ignored), as didcargo check --workspace --all-targets. The prior diagnostics Clippy, policy and diff checks passed on this same commit.The bounds tests reject a buffer one byte short and execute a final record at a nonzero offset with no trailing padding. A separate native D3D12 probe used explicit COPY_DEST-to-INDIRECT_ARGUMENT transitions, verified the count and recorded shader invocations. On AMD Radeon Graphics (PCI 1002:1114, driver 32.0.22042.1), a zero count still executed the first dispatch. A two-record call also executed only its first dispatch, even without a count buffer. The native probe matched 44 of 88 expectations on AMD and all 88 on WARP and NVIDIA RTX 5070 Laptop with full GPU-based validation, with no debug errors. The AMD result also reproduced with the inbox runtime. This establishes reproduction outside VIctory on the tested adapter and driver. The cause within the driver or runtime remains undetermined.
DaviTostes independently tested the exact head on Arch Linux with an RX 9060 XT, RADV 26.3.1, Wine 11.22, vkd3d-proton 3.1 and native Microsoft
d3dcompiler_47. All 13 indirect tests included by that build passed. Thevictory_gpusuite was 50 passed and two failed for the separately reported pipeline-library and mapped-memory cases. On the precedinga2ab63drevision, Wine’s built-in compiler rejectedRWByteAddressBuffer.Loadbefore the tests could exercise the indirect path. Exact-head Proton run · Compiler controlA separate composition with #178 at
f435ad1exercises its DXC fallback. In-process Windows SDK 26100 DXC returned unsigned bytecode even with its companiondxil.dllin the compiler folder. The review patch uses the existing DXIL validator to sign that output. On Windows, all 14 cases passed on AMD and WARP with enhanced and forced legacy barriers, under both FXC and forced DXC, with full GPU-based validation. The composition is available for the #178 review. Compiler proposal · Test branch · Signer patchScope
The sanitizer still scans
MaxCommandCountfor counted calls. Reading the actual GPU count before charging records is a separate follow-up. PR #24 covers the distinctDispatchMeshXentry point. The title watchdog and world rendering remain unverified.This contribution was AI-assisted with OpenAI Codex.
@DaviTostes on GitHub · 2026-11-24 01:04 UTC · original
Tested
a2ab63dunder Wine 11.22 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build withcargo xwin ... --target x86_64-pc-windows-msvc. Two environments, and the PR is fine in both — the first run's failures were a compiler gap:d3dcompiler_47: 39 passed, 13 failed. All 13 areassert!(bound(...))inindirect::tests::*(the 12 new tests plusargument_clamp_builds), because Wine's compiler rejects the clamp shader (E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'),clamp()returnsNone, andboundreturns false.d3dcompiler_47.dllon the DLL search path (WINEDLLOVERRIDES=d3dcompiler_47=n): 50 passed, 2 failed. The 12 new indirect tests andargument_clamp_buildsall pass. The two remaining failures are environment-only:a_rejected_blob_gives_an_empty_library— vkd3d-proton needs a non-empty blob forCreatePipelineLibrary;buffer_data_reaches_the_host_texture— #128 (vkd3d-proton's mapped memory is invisible toVirtualQuery).So the new indirect tests do run and pass against a real D3D12 implementation here; under Proton the native
d3dcompiler_47is the missing piece. Note that the test module adds 12 tests and is a strong addition — it exercised the bounds/barrier paths end to end.No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
@DaviTostes on GitHub · 2026-11-24 01:23 UTC · original
Re-checked the new head
22b9ed1("preserve legacy indirect count buffer handoffs") under Wine 11.22 + vkd3d-proton 3.1 (AMD RX 9060 XT, RADV 26.3.1), Windows build with a native Microsoftd3dcompiler_47: pass, no regression.victory_gpu: 50 passed, 2 failed — the two environment-only failures (a_rejected_blob_gives_an_empty_libraryand #128). The 12 indirect tests plusargument_clamp_buildspass.a2ab63dbefore this commit, so the handoff change did not disturb the suite here.No game data used.
@aycow on GitHub · 2026-11-24 04:44 UTC · original
@ifBars merge?
@raffclar on GitHub · 2026-11-23 23:54 UTC · original · edited 2026-11-23 23:56 UTC
On
crates/victory-gpu/src/indirect.rsline 217 (outdated):You need to track the count buffer's real state, or switch it from COMMON.
Before the indirect call, a barrier switches the count buffer to the state the call needs. The barrier says the buffer starts in the UAV state but the count buffer usually starts in COMMON instead because nothing in the list wrote to it as a UAV first. I'd first this before merging but verify yourself too.
@ -1193,0 +1265,4 @@/// may include other memory or padding beyond the title's buffer.fn indirect_address(buffer: Option<(*mut u8, u64)>, offset: u64, len: u64) -> Option<u64> {let (base, size) = buffer?;if !offset.is_multiple_of(4) || offset.checked_add(len)? > size {@raffclar on GitHub · 2026-11-23 23:56 UTC · original
The new size check assumes the last record in the argument buffer is a full stride long however.. it's often the buffer ends right after the last record's actual data.
I'd check against the start of the last record plus the argument size. I think byte_len already uses that rule
@aycow on GitHub · 2026-11-24 00:14 UTC · original
On
crates/victory-gpu/src/indirect.rsline 217 (outdated):Thanks for flagging the state assumption. A shadow may already have GPU reads or writes, and it does not decay between lists submitted together. The revision selects enhanced barriers at the start of each native submission, orders the producer and indirect accesses, and leaves buffers available for their next use. A shared argument/count resource is handled once. CPU, UAV and copy producers, resubmission, and split timing submissions passed on AMD and WARP. The debug layer was unavailable here.
@ -1193,0 +1265,4 @@/// may include other memory or padding beyond the title's buffer.fn indirect_address(buffer: Option<(*mut u8, u64)>, offset: u64, len: u64) -> Option<u64> {let (base, size) = buffer?;if !offset.is_multiple_of(4) || offset.checked_add(len)? > size {@aycow on GitHub · 2026-11-24 00:14 UTC · original
Thanks for catching the trailing stride. The title bounds check and shadow lookup now use the same last-record span. The regression returned 32 bytes before and now accepts 28 while rejecting 27. The native test executes the final record at a nonzero offset with zero trailing padding on AMD and WARP. I also recorded the separate AMD two-dispatch observation in the PR description.
@raffclar on GitHub · 2026-11-24 00:28 UTC · original
On
crates/victory-gpu/src/indirect.rsline 221 (outdated):If the GPU setup doesn't support enhanced barriers, this will fail.
Keep the old barrier code as a fallback when enhanced barriers are missing for our older GPUs
@raffclar on GitHub · 2026-11-24 00:29 UTC · original
On
crates/victory-gpu/src/indirect.rsline 217 (outdated):Ok good, one problem with enhanced barriers. Comment is below
@aycow on GitHub · 2026-11-24 00:32 UTC · original
On
crates/victory-gpu/src/indirect.rsline 221 (outdated):Thanks. Commit
a2ab63drestores the legacy UAV and INDIRECT_ARGUMENT transitions when enhanced barriers or command list 7 are unavailable. It also restores the buffers if pipeline preparation drops the call. The forced legacy path passed 13 focused tests on AMD and WARP, and the enhanced path passed all 14 on each.@raffclar on GitHub · 2026-11-24 00:40 UTC · original
On
crates/victory-gpu/src/indirect.rsline 282 (outdated):Remove separate_count from both legacy loops, so only buffer is switched. I think your machine is missing the original barrier fault; a wrong starting state is only reported by the D3D12 debug layer and your machine didn't have it (DXGI_ERROR_SDK_COMPONENT_MISSING) based on your PR description.
@raffclar on GitHub · 2026-11-24 00:41 UTC · original
On
crates/victory-gpu/src/indirect.rsline 282 (outdated):The argument buffer really is in the UAV state because the clamp shader just wrote it
@aycow on GitHub · 2026-11-24 01:16 UTC · original
On
crates/victory-gpu/src/indirect.rsline 282 (outdated):Thanks for catching this. In
22b9ed1, the legacy transitions apply only to the argument resource, including when it also contains the count. A separate count can promote from COMMON. For a UAV or copy write in the same native submission, the fallback now preserves the title's explicit handoff through COMMON. Decay only occurs after a native submission.AMD and WARP each passed 14 focused tests in both enhanced and forced legacy modes, including the CPU count, UAV and copy producers, shared resources, and resubmission. D3D12 debug-layer and GPU-based validation are still outstanding. The Graphics Tools install hit
CBS_E_SOURCE_MISSING, and the strict probe confirmed the layer was not active.@aycow on GitHub · 2026-11-24 02:24 UTC · original
On
crates/victory-gpu/src/indirect.rsline 282 (outdated):Thanks for pointing out the missing validation. I reran
22b9ed1on AMD and WARP with Agility SDK 1.620.2. All 14 focused tests passed on each adapter in both enhanced and forced legacy modes, with the D3D12 debug layer and full GPU-based state tracking active.I also omitted the legacy handoff in a same-list control. On both adapters, validation reported the separate count still in COPY_DEST or UAV when ExecuteIndirect required INDIRECT_ARGUMENT. Restoring the handoff cleared both errors. The separate CPU count can promote from COMMON, and the clamp-written argument resource retains its own transition.
The AMD zero-count dispatch also reproduces in a standalone native D3D12 test with explicit states and no validation errors. WARP and NVIDIA observed zero dispatches. The PR description has the adapter, driver and test details.
Pull request closed