victory-gpu: raw buffer views start on 16 bytes of their host copy (an invalid raw SRV removed the device) #3540

Open
github-bot wants to merge 1 commit from github-bot/gh-3540 into main AGit
Owner

@⁠pes7 on GitHub · 2026-11-27 15:47 UTC · original
pes7:fix/raw-view-alignment → main · +77 −3 · 1 files · 1 commits · open

Correction (hardware): the title runs below ran on the machine's integrated AMD Radeon (RDNA, shared memory), not on its NVIDIA RTX 5070 Ti as I first wrote. Windows picked the integrated GPU for the build's path, which had no per-app GPU preference. The failing call is a D3D12 runtime rule that the debug layer checks the same way on any vendor, but the runs are AMD-iGPU runs. NVIDIA runs are to follow.

The host refuses a raw buffer view (SRV or UAV) whose first byte is not 16-byte aligned in its buffer. D3D12 treats the call as invalid and removes the device (DXGI_ERROR_INVALID_CALL, logged as 0x887A0004 with no breadcrumbs). The console accepts a raw view at any dword.

In a title run the debug layer (VICTORY_D3D12_DEBUG=1) named the call, about 200 s in, in the prison yard:

ID3D12Device::CreateShaderResourceView: When creating a RAW Shader Resource View, the offset of the first element
from the start of the buffer must be a multiple of 16 bytes.  Thus, FirstElement (2) must be a multiple of 4 since
each element is 4 bytes.
ID3D12Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_INVALID_CALL ...

Change

buffer_srv and buffer_uav asked shadow::for_view for a copy that the view starts on an element (4 bytes) of. A raw view, and a constant buffer (made raw), now asks for 16 bytes instead. A view 4, 8 or 12 bytes past a boundary then gets a copy of its own bytes. That copy starts on 256 (exact), so the view reads the right data instead of a null view. view_copy asks for the same alignment, so the copy that is refreshed and copied back for a view is the one its slot reads.

This is the same idea as #3075, which does it for raw UAVs. This change also covers SRVs and constant buffers, and the same views in view_copy. #123 refuses such views instead, which reads zeros, and needs a rebase.

Tested

Windows 11, on main 63bcca4 (tests on the default adapter, the integrated AMD Radeon):

  • cargo clippy -p victory-gpu --all-targets -- -D warnings clean, also with --all-features.
  • cargo test -p victory-gpu --lib: 232 passed, 0 failed, including the new raw_views_start_on_16_bytes_of_their_copy. The test checks which views count as raw and which alignment each gets. It deliberately does not register fake buffers in the global shadow registry.

In the title, on the tested set in #3409 (main plus about 40 open PRs, where this showed up), release + diagnostics, 300 s runs:

runs device removed
without this change 4 3 (each the invalid raw SRV above; the one with the debug layer named it)
with this change 3 0, and no raw-view message from the debug layer

The same set, cargo test --workspace with this change: 930 passed, 0 failed.

Not checked: AMD/Intel hosts, and main alone in the title. On main the faulting view depends on which copies exist, so it may be rarer there.

🤖 Generated with Claude Code

**@⁠pes7** on GitHub · 2026-11-27 15:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3540) `pes7:fix/raw-view-alignment` → `main` · +77 −3 · 1 files · 1 commits · open > **Correction (hardware):** the title runs below ran on the machine's **integrated AMD Radeon** (RDNA, shared memory), not on its NVIDIA RTX 5070 Ti as I first wrote. Windows picked the integrated GPU for the build's path, which had no per-app GPU preference. The failing call is a D3D12 runtime rule that the debug layer checks the same way on any vendor, but the runs are AMD-iGPU runs. NVIDIA runs are to follow. The host refuses a raw buffer view (SRV or UAV) whose first byte is not 16-byte aligned in its buffer. D3D12 treats the call as invalid and removes the device (`DXGI_ERROR_INVALID_CALL`, logged as `0x887A0004` with no breadcrumbs). The console accepts a raw view at any dword. In a title run the debug layer (`VICTORY_D3D12_DEBUG=1`) named the call, about 200 s in, in the prison yard: ``` ID3D12Device::CreateShaderResourceView: When creating a RAW Shader Resource View, the offset of the first element from the start of the buffer must be a multiple of 16 bytes. Thus, FirstElement (2) must be a multiple of 4 since each element is 4 bytes. ID3D12Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_INVALID_CALL ... ``` ## Change `buffer_srv` and `buffer_uav` asked `shadow::for_view` for a copy that the view starts on an element (4 bytes) of. A raw view, and a constant buffer (made raw), now asks for 16 bytes instead. A view 4, 8 or 12 bytes past a boundary then gets a copy of its own bytes. That copy starts on 256 (`exact`), so the view reads the right data instead of a null view. `view_copy` asks for the same alignment, so the copy that is refreshed and copied back for a view is the one its slot reads. This is the same idea as #3075, which does it for raw UAVs. This change also covers SRVs and constant buffers, and the same views in `view_copy`. #123 refuses such views instead, which reads zeros, and needs a rebase. ## Tested Windows 11, on `main` `63bcca4` (tests on the default adapter, the integrated AMD Radeon): - `cargo clippy -p victory-gpu --all-targets -- -D warnings` clean, also with `--all-features`. - `cargo test -p victory-gpu --lib`: 232 passed, 0 failed, including the new `raw_views_start_on_16_bytes_of_their_copy`. The test checks which views count as raw and which alignment each gets. It deliberately does not register fake buffers in the global shadow registry. In the title, on the tested set in #3409 (`main` plus about 40 open PRs, where this showed up), release + `diagnostics`, 300 s runs: | | runs | device removed | |---|---|---| | without this change | 4 | 3 (each the invalid raw SRV above; the one with the debug layer named it) | | with this change | 3 | 0, and no raw-view message from the debug layer | The same set, `cargo test --workspace` with this change: 930 passed, 0 failed. Not checked: AMD/Intel hosts, and `main` alone in the title. On `main` the faulting view depends on which copies exist, so it may be rarer there. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The host refuses a raw SRV or UAV whose first byte is not 16-byte aligned in
its buffer: the call is invalid and the device is removed. The console takes
a raw view at any dword, and a title run ended so, about 200 s in, with the
debug layer naming it:

    CreateShaderResourceView: When creating a RAW Shader Resource View, the
    offset of the first element from the start of the buffer must be a
    multiple of 16 bytes. Thus, FirstElement (2) must be a multiple of 4

buffer_srv and buffer_uav asked shadow::for_view for a copy the view starts
on an element (4 bytes) of. A raw view (and a constant buffer, made raw) now
asks for 16 bytes instead, so a view 4, 8 or 12 bytes past a boundary gets
its own copy, which starts on 256. view_copy asks the same, so the copy
refreshed and copied back for a view is the one its slot reads.

#3075 does this for raw UAVs; this covers SRVs and constant buffers too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 16:00:28 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 16:20 UTC · original

Independent verification of #3540 at ee3d12dc, base main 63bcca43. Verification only, no code pushed, no game data. AI-assisted (Claude Sonnet 5.5).

Setup: Windows 11 26200, Windows SDK 26100 dxil.dll, cargo test -p victory-gpu --lib --features diagnostics, cargo clippy -p victory-gpu --all-targets -- -D warnings (with and without diagnostics).

Run base 63bcca43 head ee3d12dc
WARP (VICTORY_WARP=1, VICTORY_D3D12_WARP=1) lib 246 passed, 0 failed, 1 ignored 247 passed, 0 failed, 1 ignored
Native AMD RX 7800 XT, driver 32.0.31035.1003, WARP unset, lib 246 passed, 0 failed, 1 ignored 247 passed, 0 failed, 1 ignored
clippy -D warnings (WARP box) clean clean

The extra test on the head is raw_views_start_on_16_bytes_of_their_copy, which passes on both WARP and the RX 7800 XT. This covers the AMD case the description marked unchecked, but only as the existing lib suite: there is no title or invalid-raw-SRV reproduction here, so I did not independently confirm the device removal itself.

Diff reading: buffer_srv, buffer_uav and view_copy all go through the same copy_alignment, so they agree for shader, unordered and placed buffer views. I found no other raw buffer view creation that goes through for_view.

Non-blocking question (unproven): view_raw has a View::Constant branch, but view_copy never sees one, because buffer_range returns None for constants. make now gives a constant slot a 16-aligned exact copy when the address is off 16 within its shadow, while seen() (bindless.rs) and readable() (draw.rs) still refresh shadow::find(address, len), the base copy. If a constant buffer can start off 16 bytes inside its copy, would its slot read a copy nothing refreshes? Likely rare, since the console wants 16-byte-aligned constants, and I did not construct a case.

**@⁠oni-swr** on GitHub · 2026-11-27 16:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/3540#issuecomment-7223151868) Independent verification of #3540 at ee3d12dc, base main 63bcca43. Verification only, no code pushed, no game data. AI-assisted (Claude Sonnet 5.5). **Setup:** Windows 11 26200, Windows SDK 26100 `dxil.dll`, `cargo test -p victory-gpu --lib --features diagnostics`, `cargo clippy -p victory-gpu --all-targets -- -D warnings` (with and without `diagnostics`). | Run | base 63bcca43 | head ee3d12dc | |---|---|---| | WARP (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`) lib | 246 passed, 0 failed, 1 ignored | 247 passed, 0 failed, 1 ignored | | Native AMD RX 7800 XT, driver 32.0.31035.1003, WARP unset, lib | 246 passed, 0 failed, 1 ignored | 247 passed, 0 failed, 1 ignored | | clippy `-D warnings` (WARP box) | clean | clean | The extra test on the head is `raw_views_start_on_16_bytes_of_their_copy`, which passes on both WARP and the RX 7800 XT. This covers the AMD case the description marked unchecked, but only as the existing lib suite: there is no title or invalid-raw-SRV reproduction here, so I did not independently confirm the device removal itself. **Diff reading:** `buffer_srv`, `buffer_uav` and `view_copy` all go through the same `copy_alignment`, so they agree for shader, unordered and placed buffer views. I found no other raw buffer view creation that goes through `for_view`. **Non-blocking question (unproven):** `view_raw` has a `View::Constant` branch, but `view_copy` never sees one, because `buffer_range` returns `None` for constants. `make` now gives a constant slot a 16-aligned exact copy when the address is off 16 within its shadow, while `seen()` (bindless.rs) and `readable()` (draw.rs) still refresh `shadow::find(address, len)`, the base copy. If a constant buffer can start off 16 bytes inside its copy, would its slot read a copy nothing refreshes? Likely rare, since the console wants 16-byte-aligned constants, and I did not construct a case.
Author
Owner

@⁠pickles976 on GitHub · 2026-11-27 16:55 UTC · original

Verified exact production head ee3d12dc356df92a2da49133f11a5f0c98b0291f on Linux6.17 / Wine11 / RTX4060 Laptop8GiB / NVIDIA590.48.1 /16GiB host RAM. Diagnostic-relaxed vkd3d 2576c0b4adfae4a+, vendor masking disabled; not stock/native-Windows certification.

A local test-only descriptor::host::tests::misaligned_raw_srv_uav_views_are_gpu_coherent passes 1/1, eight real GPU dispatch/readback cases: byte offsets4/8/12 and aligned16 control, each across two CPU-update rounds. It uses production placed SRV/UAV construction, heap mirroring, shadow refresh, execution and GPU-write copy-back. Four transformed output words per case, untouched neighbors and unchanged source words are asserted. Backing is fixture-owned VirtualAlloc memory retained through GPU completion; the real NVIDIA device and compiler are mandatory. This checks data, not just descriptor creation or retained shadow identity.

Fresh intended-worktree compilation7.97s; test0.67s, zero ignored. Windows-MSVC target, one test thread. Evidence retained locally: .compat-runtime/logs/verify-pr3540-raw-view-win32-20261127T163417Z/. Production unchanged; local fixture retained. Earlier local harness attempts failed before execution (COFF over-aligned-static LLVM trap, then missing windows-crate feature); replacing only the fixture backing/import resolved those, not a PR production workaround.

No CBV coverage, debug-layer certification, title rendering, memory-saving or frame-time claim. This clears the exercised misaligned raw SRV/UAV coherence cases on this Wine/NVIDIA stack.

**@⁠pickles976** on GitHub · 2026-11-27 16:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/3540#issuecomment-7223827085) Verified exact production head `ee3d12dc356df92a2da49133f11a5f0c98b0291f` on Linux6.17 / Wine11 / RTX4060 Laptop8GiB / NVIDIA590.48.1 /16GiB host RAM. Diagnostic-relaxed vkd3d `2576c0b4adfae4a+`, vendor masking disabled; not stock/native-Windows certification. A local test-only `descriptor::host::tests::misaligned_raw_srv_uav_views_are_gpu_coherent` passes **1/1**, eight real GPU dispatch/readback cases: byte offsets4/8/12 and aligned16 control, each across two CPU-update rounds. It uses production placed SRV/UAV construction, heap mirroring, shadow refresh, execution and GPU-write copy-back. Four transformed output words per case, untouched neighbors and unchanged source words are asserted. Backing is fixture-owned VirtualAlloc memory retained through GPU completion; the real NVIDIA device and compiler are mandatory. This checks data, not just descriptor creation or retained shadow identity. Fresh intended-worktree compilation7.97s; test0.67s, zero ignored. Windows-MSVC target, one test thread. Evidence retained locally: `.compat-runtime/logs/verify-pr3540-raw-view-win32-20261127T163417Z/`. Production unchanged; local fixture retained. Earlier local harness attempts failed before execution (COFF over-aligned-static LLVM trap, then missing windows-crate feature); replacing only the fixture backing/import resolved those, not a PR production workaround. No CBV coverage, debug-layer certification, title rendering, memory-saving or frame-time claim. This clears the exercised misaligned raw SRV/UAV coherence cases on this Wine/NVIDIA stack.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-27 17:36 UTC · original

Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC.

  • PR head: ee3d12dc356df92a2da49133f11a5f0c98b0291f, merge base 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • Command: cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::raw_views_start_on_16_bytes_of_their_copy --exact --test-threads=1 --quiet
  • Result: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 232 filtered out, exit 0.
  • Negative control: git grep -F -c raw_views_start_on_16_bytes_of_their_copy 63bcca43 -- . → exit 1 / 0 hits (test genuinely new); present on PR head.
  • git diff --check 63bcca43 HEAD → exit 0.
  • Caveat: only the synthetic enum/alignment test was replayed; no host GPU and no full crate suite.
  • GPU/driver: N/A (CPU-only test). No game data, assets, extracted shaders or DRM involved.
  • AI-assisted: Hy4 flash.
**@⁠cloph-dsp** on GitHub · 2026-11-27 17:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/3540#issuecomment-7224589917) Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC. - PR head: `ee3d12dc356df92a2da49133f11a5f0c98b0291f`, merge base `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - Command: `cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::raw_views_start_on_16_bytes_of_their_copy --exact --test-threads=1 --quiet` - Result: `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 232 filtered out`, exit 0. - Negative control: `git grep -F -c raw_views_start_on_16_bytes_of_their_copy 63bcca43 -- .` → exit 1 / 0 hits (test genuinely new); present on PR head. - `git diff --check 63bcca43 HEAD` → exit 0. - Caveat: only the synthetic enum/alignment test was replayed; no host GPU and no full crate suite. - GPU/driver: N/A (CPU-only test). No game data, assets, extracted shaders or DRM involved. - AI-assisted: Hy4 flash.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3540/head:github-bot/gh-3540'
git switch 'github-bot/gh-3540'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3540'
git switch 'github-bot/gh-3540'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3540'
git switch 'github-bot/gh-3540'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3540'
git switch 'main'
git merge --squash 'github-bot/gh-3540'
git switch 'main'
git merge --ff-only 'github-bot/gh-3540'
git switch 'main'
git merge 'github-bot/gh-3540'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3540
No description provided.