Skip to content

GPU: enforce logical indirect buffer spans - #1817

Open
aycow wants to merge 5 commits into
Marvisak:mainfrom
aycow:fix/indirect-logical-span-current
Open

aycow wants to merge 5 commits into
Marvisak:mainfrom
aycow:fix/indirect-logical-span-current

Conversation

@aycow

@aycow aycow commented Nov 24, 2026

Copy link
Copy Markdown

What changed

Validate the argument payload and count word against their logical guest resources before selecting native shadow backing. Stock could accept a span ending four bytes past a 28-byte resource when a 64-byte enclosing shadow existed. The guard accepts a final record ending exactly after its payload, checks offsets and overflow, and skips zero-record calls before resource resolution.

Thanks to @raffclar for identifying the final-record payload rule during review of #40. This check runs at the list entry point. The native clamp, count-aware scheduling, and resource-state changes remain separate in #242. Original review · #242 coordination

Verification

On stock 70564ae, the test overlay accepted both out-of-range spans. The candidate refused both and preserved three valid controls, including exact-end spans, on AMD Radeon Graphics and WARP. The fixture ends at address resolution, with no invalid native draw or dispatch recorded. The probe ran without GPU-based validation.

cargo test -p victory-gpu --features diagnostics --locked indirect_span -- --include-ignored --test-threads=1
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --features diagnostics --locked indirect_span -- --include-ignored --test-threads=1

The exact head also passed the workspace suite with DXIL validator 1.9.2609.5, both strict workspace Clippy configurations, and the asset policy. Reproduction details

AI-assisted using Codex. Generated test data only.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Logical indirect buffer spans enforced: 8K gpu diff — bounds the indirect argument buffer reads. Pairs with #1813's tests.

@DesertGamer

Copy link
Copy Markdown

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

@Melow-code Melow-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logical span check and zero-record early-out are correct. One question: when a span exceeds the logical size, is it clamped or rejected? If rejected, a title that intentionally over-reads (relying on the native clamp in #242) would regress.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

@ruipedro-pinheiro It rejects the call before native recording when the span implied by the requested maximum exceeds the logical argument buffer. An out-of-range count word is also rejected. The native D3D12 contract validates the entire range implied by MaxCommandCount, even when a GPU count buffer can later select fewer records. Our AMD/WARP control confirmed that a larger native shadow no longer makes the invalid logical span pass.

The current #242 code limits how many records it processes using the GPU count, and it still requests source backing for the maximum span. It cannot establish the size of the logical guest resource from that backing. A D3D12.X title that demonstrably accepts a smaller logical span would need a separate compatibility case backed by console behavior or an authorized trace. Safe support would have to bound both the clamp’s source reads and the native call. This PR keeps the entry-point check. Review · D3D12 contract · #242

AI-assisted using Codex.

@aycow

aycow commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Merged upstream 42363ab into the PR at 77dfdf2. Both upstream’s buffer test helper and the placed-shadow regression are preserved. Strict diagnostics Clippy and both logical-span tests passed on the default hardware adapter and WARP. GitHub reports a clean merge.

The GitHub workspace run hit the same gather and wave-32 permute test failures as upstream at 42363ab. Upstream CI

@Melow-code

Copy link
Copy Markdown

The gather and wave-32 permute failures on the workspace run are upstream's, not this PR's: the hardware-only shader checks ran on WARP on the GPU-less CI runner. Marvis fixed them in 42363ab ("Tests: hardware-only shader checks skip on a machine without a GPU"), which refuses a software default adapter and skips the permute test when only WARP is there. Rebase it in and those two failures disappear. The logical-span work itself is clean per your report; nothing else from my side. (Reply written with DeepSeek V4 Pro, OpenCode.)

@Melow-code

Copy link
Copy Markdown

Reviewed the PR's own commits (b1b05ca and its follow-ups, above the merge of main).

The fix is the right one at the right layer: the logical span of the last record is checked against the logical resource before any native shadow can widen the extent, which is exactly what the D3D12 contract validates. The checked arithmetic is everywhere (checked_add, checked_sub), the count-buffer span is a constant 4, and an unknown indirect kind drops the execution rather than guessing.

One point to confirm, non-blocking:

  1. The payload table gives kind 105 (single-pass mesh dispatch) 12 bytes, like a plain dispatch. If the RDNA2 argument record for 105 is the same three dwords, this is right — but a citation (the ISA section, or a signature dump from the title) would pin it, since a wrong payload undercounts the last record's span and re-introduces the very hole this PR closes.

The unit tests cover the span arithmetic for all five kinds, the stride/alignment refusals, and both overflow edges; the GPU-shadow test is properly gated behind a real device. The zero-record skip is a nice touch.

Nothing blocking. (Review written with DeepSeek V4 Pro, OpenCode.)

@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown
Author

Reviewed the PR's own commits (b1b05ca and its follow-ups, above the merge of main).

The fix is the right one at the right layer: the logical span of the last record is checked against the logical resource before any native shadow can widen the extent, which is exactly what the D3D12 contract validates. The checked arithmetic is everywhere (checked_add, checked_sub), the count-buffer span is a constant 4, and an unknown indirect kind drops the execution rather than guessing.

One point to confirm, non-blocking:

  1. The payload table gives kind 105 (single-pass mesh dispatch) 12 bytes, like a plain dispatch. If the RDNA2 argument record for 105 is the same three dwords, this is right — but a citation (the ISA section, or a signature dump from the title) would pin it, since a wrong payload undercounts the last record's span and re-introduces the very hole this PR closes.

The unit tests cover the span arithmetic for all five kinds, the stride/alignment refusals, and both overflow edges; the GPU-shadow test is properly gated behind a real device. The zero-record skip is a nice touch.

Nothing blocking. (Review written with DeepSeek V4 Pro, OpenCode.)

The 12-byte payload for kind 105 follows the existing upstream documentation in [list.rs](

/// offset)`. Grand Theft Auto VI's signatures (title+0x2479466, 2026-11-24)
/// hold one argument each: draw (stride 16), indexed draw (20), dispatch
/// (12), mesh dispatch (12), and the console's single-pass dispatch, type
/// 105 (stride 12: the three group counts; its flags live in the
/// signature, the title passes none), run as a plain dispatch. They run
/// through the host's indirect execution (`State::execute_indirect`).
/// shortcut: signatures that change root arguments are dropped (logged
), which specifies three group counts with the flags stored in the signature.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. execute_indirect in crates/victory-gpu/src/list.rs now checks the argument and count offsets against the title resource's own size, through indirect_argument_span/indirect_offset, before a larger overlapping shadow can be picked. Checking against the logical resource is a reasonable idea, and the pure tests are good. Three things to change:

  • The span uses max, not the count. With a count buffer, titles often pass a generous max and a smaller argument buffer, relying on the count. Requiring (max - 1) * stride + payload to fit drops those indirect calls entirely. Please give evidence that the console requires the argument buffer to fit max records (its documented contract, or a title call that shows it). Otherwise, bound the span on the GPU by the count, which the argument clamp in indirect.rs already reads.
  • The new doc. docs/indirect-logical-resource-span.md is a design note with thanks, PR cross-references and test commands. Repo docs stay short and do not carry rationale, so please move it into the PR description and keep at most a code comment.
  • #[cfg(not(windows))] let _ = count_offset; while counter exists only on Windows is fine, but a short comment would help.

CI: check passing.


Generated by Claude Code

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.

5 participants