GPU: validate ByteStride alignment and root signature in signature::create #3315

Open
mgunes1311-lab wants to merge 1 commit from upstream-pr/3315 into main
mgunes1311-lab commented 2026-11-26 17:18:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-26T17:18:11Z.


Coordination

Claimed in https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7197202703 (GPU: validate 4-byte ByteStride alignment and required root signature for binding arguments in signature::create). Checked STATUS.md, CLAIMS.md, and forge/main — zero overlapping PRs or diff in crates/victory-gpu/src/signature.rs.

Problem

Per Microsoft's D3D12_COMMAND_SIGNATURE_DESC and ID3D12Device::CreateCommandSignature specification:

  1. ByteStride must be a multiple of 4 bytes (E_INVALIDARG otherwise).
  2. pRootSignature is required whenever any D3D12_INDIRECT_ARGUMENT_DESC updates root bindings (CONSTANT = 5, CONSTANT_BUFFER_VIEW = 6, SHADER_RESOURCE_VIEW = 7, UNORDERED_ACCESS_VIEW = 8, INCREMENTING_CONSTANT = 11), and optional only for non-binding arguments (DRAW, DRAW_INDEXED, DISPATCH, VERTEX_BUFFER_VIEW, INDEX_BUFFER_VIEW, DISPATCH_RAYS, DISPATCH_MESH).
  3. Early E_INVALIDARG paths did not clear a non-null _COM_Outptr_opt_ ppvCommandSignature slot.

signature::create accepted unaligned ByteStride values and rootless binding signatures, deferring failure or silently misinterpreting indirect argument buffers at execution time.

Fix

  • Reject !desc.stride.is_multiple_of(4) with E_INVALIDARG in signature::create.
  • Reject root.is_null() when any indirect argument has type 5..=8 | 11 (binds_root) with E_INVALIDARG.
  • Clear *out = null on all early E_INVALIDARG returns when out is non-null.

Verification

  • Added signature::tests::misaligned_strides_and_rootless_binding_arguments_are_rejected_and_clear_out covering unaligned strides, all five root-binding argument types with and without a root signature, all non-binding argument types with a null root signature, and _COM_Outptr_opt_ clearing on early failure.
  • Added signature::tests::host_device_agrees_on_stride_alignment_and_root_requirement verifying live D3D12 ID3D12Device::CreateCommandSignature returns E_INVALIDARG on both cases.
  • Ran cargo test -p victory-gpu --locked signature::tests:: (7/7 passed), cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, and cargo xtask policy on Windows 11 (x86_64-pc-windows-msvc).

AI-assisted contribution (Google Antigravity); all code, D3D12 validation, and tests were locally executed and verified.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5514386942 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3315). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-26T17:18:11Z. --- ## Coordination Claimed in https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7197202703 (`GPU: validate 4-byte ByteStride alignment and required root signature for binding arguments in signature::create`). Checked `STATUS.md`, `CLAIMS.md`, and `forge/main` — zero overlapping PRs or diff in `crates/victory-gpu/src/signature.rs`. ## Problem Per Microsoft's `D3D12_COMMAND_SIGNATURE_DESC` and `ID3D12Device::CreateCommandSignature` specification: 1. `ByteStride` must be a multiple of 4 bytes (`E_INVALIDARG` otherwise). 2. `pRootSignature` is required whenever any `D3D12_INDIRECT_ARGUMENT_DESC` updates root bindings (`CONSTANT = 5`, `CONSTANT_BUFFER_VIEW = 6`, `SHADER_RESOURCE_VIEW = 7`, `UNORDERED_ACCESS_VIEW = 8`, `INCREMENTING_CONSTANT = 11`), and optional only for non-binding arguments (`DRAW`, `DRAW_INDEXED`, `DISPATCH`, `VERTEX_BUFFER_VIEW`, `INDEX_BUFFER_VIEW`, `DISPATCH_RAYS`, `DISPATCH_MESH`). 3. Early `E_INVALIDARG` paths did not clear a non-null `_COM_Outptr_opt_` `ppvCommandSignature` slot. `signature::create` accepted unaligned `ByteStride` values and rootless binding signatures, deferring failure or silently misinterpreting indirect argument buffers at execution time. ## Fix - Reject `!desc.stride.is_multiple_of(4)` with `E_INVALIDARG` in `signature::create`. - Reject `root.is_null()` when any indirect argument has type `5..=8 | 11` (`binds_root`) with `E_INVALIDARG`. - Clear `*out = null` on all early `E_INVALIDARG` returns when `out` is non-null. ## Verification - Added `signature::tests::misaligned_strides_and_rootless_binding_arguments_are_rejected_and_clear_out` covering unaligned strides, all five root-binding argument types with and without a root signature, all non-binding argument types with a null root signature, and `_COM_Outptr_opt_` clearing on early failure. - Added `signature::tests::host_device_agrees_on_stride_alignment_and_root_requirement` verifying live D3D12 `ID3D12Device::CreateCommandSignature` returns `E_INVALIDARG` on both cases. - Ran `cargo test -p victory-gpu --locked signature::tests::` (7/7 passed), `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`, and `cargo xtask policy` on Windows 11 (`x86_64-pc-windows-msvc`). AI-assisted contribution (Google Antigravity); all code, D3D12 validation, and tests were locally executed and verified.
Dukestar69 commented 2026-11-26 17:28:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:28:37Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Rejecting non-4-byte-aligned ByteStride and root-binding indirect arguments (CONSTANT / CBV / SRV / UAV / INCREMENTING_CONSTANT) without a root signature while clearing non-null _COM_Outptr_opt_ slots on E_INVALIDARG matches native D3D12 behavior.
  • cargo test -p victory-gpu --lib signature:: -- --test-threads=1 (RTX 5090): 7 passed, 0 failed (including host_device_agrees_on_stride_alignment_and_root_requirement and misaligned_strides_and_rootless_binding_arguments_are_rejected_and_clear_out).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6078372902 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3315#pullrequestreview-6078372902). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T17:28:37Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Rejecting non-4-byte-aligned `ByteStride` and root-binding indirect arguments (`CONSTANT` / `CBV` / `SRV` / `UAV` / `INCREMENTING_CONSTANT`) without a root signature while clearing non-null `_COM_Outptr_opt_` slots on `E_INVALIDARG` matches native D3D12 behavior. - `cargo test -p victory-gpu --lib signature:: -- --test-threads=1` (RTX 5090): 7 passed, 0 failed (including `host_device_agrees_on_stride_alignment_and_root_requirement` and `misaligned_strides_and_rootless_binding_arguments_are_rejected_and_clear_out`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Jackster commented 2026-11-26 22:34:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:34:22Z.


Windows 11, 63bcca4 + this PR:

  • signature::tests::misaligned_strides_and_rootless_binding_arguments_are_rejected_and_clear_out and signature::tests::host_device_agrees_on_stride_alignment_and_root_requirement by name: 2 passed.
  • cargo test -p victory-gpu --lib: 233 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

The second test asks the real device, so it is exercising this card's own CreateRootSignature/alignment answer rather than only our copy of the rule. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204797626 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3315#issuecomment-7204797626). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:34:22Z. --- Windows 11, `63bcca4` + this PR: - `signature::tests::misaligned_strides_and_rootless_binding_arguments_are_rejected_and_clear_out` and `signature::tests::host_device_agrees_on_stride_alignment_and_root_requirement` by name: 2 passed. - `cargo test -p victory-gpu --lib`: 233 passed / 0 failed / 1 ignored (unpatched `63bcca4` here: 231). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. The second test asks the real device, so it is exercising this card's own `CreateRootSignature`/alignment answer rather than only our copy of the rule. Synthetic only. AI-assisted.
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/3315:upstream-pr/3315'
git switch 'upstream-pr/3315'

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