GPU: refuse raw buffer views that do not start on 16 bytes #123

Open
9hvn9yt2vk-netizen wants to merge 2 commits from upstream-pr/123 into main
9hvn9yt2vk-netizen commented 2026-11-24 00:41:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 9hvn9yt2vk-netizen on 2026-11-24T00:41:27Z.


A raw buffer view on the host must start on a multiple of 16 bytes; the console needs only 4. buffer_srv and buffer_uav move a view's first element by where its memory sits in the host copy, so a title's raw view could land on 4, 8 or 12 bytes past a 16-byte boundary. The host then refuses CreateShaderResourceView (or CreateUnorderedAccessView), and the device is removed (0x887A0001). A user report from the world:

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 (42261210) must be a multiple
of 4 since each element is 4 bytes.

Such a view is now refused like one that is not on an element: the slot gets a null view of its kind (reads zeros) and a warning is logged once. Starting the view 16 bytes lower would need the shader to add the difference.

Type-checked and clippy-clean for x86_64-pc-windows-msvc (cross-checked from Linux with -Zbuild-std); not run against the title.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571941883 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/123). Originally posted by [9hvn9yt2vk-netizen](https://github.com/9hvn9yt2vk-netizen) on 2026-11-24T00:41:27Z. --- A raw buffer view on the host must start on a multiple of 16 bytes; the console needs only 4. buffer_srv and buffer_uav move a view's first element by where its memory sits in the host copy, so a title's raw view could land on 4, 8 or 12 bytes past a 16-byte boundary. The host then refuses CreateShaderResourceView (or CreateUnorderedAccessView), and the device is removed (0x887A0001). A user report from the world: 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 (42261210) must be a multiple of 4 since each element is 4 bytes. Such a view is now refused like one that is not on an element: the slot gets a null view of its kind (reads zeros) and a warning is logged once. Starting the view 16 bytes lower would need the shader to add the difference. Type-checked and clippy-clean for x86_64-pc-windows-msvc (cross-checked from Linux with -Zbuild-std); not run against the title.
DaviTostes commented 2026-11-24 06:54:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:49:19Z.


Tested 828e3cd under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with cargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.

  • victory_gpu: 36 passed, 3 failed — the same count and the same three environment-only failures as main (argument_clamp_builds, a_rejected_blob_gives_an_empty_library, #128's VirtualQuery upload skip). The diff adds no test for the new 16-byte check, so this run only shows nothing else broke; a synthetic CreateShaderResourceView with a non-16-byte-aligned raw offset would cover it (vkd3d-proton is strict about that alignment too).

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118467908 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/123#issuecomment-7118467908). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:49:19Z. --- Tested `828e3cd` under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with `cargo xwin ... --target x86_64-pc-windows-msvc`: **pass, no regression**. - `victory_gpu`: **36 passed, 3 failed** — the same count and the same three environment-only failures as `main` (`argument_clamp_builds`, `a_rejected_blob_gives_an_empty_library`, #128's `VirtualQuery` upload skip). The diff adds no test for the new 16-byte check, so this run only shows nothing else broke; a synthetic `CreateShaderResourceView` with a non-16-byte-aligned raw offset would cover it (vkd3d-proton is strict about that alignment too). No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
oVolkra commented 2026-11-24 06:54:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oVolkra on 2026-11-24T01:03:57Z.


Tested 828e3cd6 (merged onto main d2a4bae1) on RTX 3060, driver 617.14, Windows 11: pass

  • cargo test --workspace: 264 passed, 0 failed, 4 ignored (same counts as main d2a4bae1)
  • cargo clippy --workspace --all-targets: no new warnings (the same 2 as main)
  • cargo xtask policy: clean

Not tested: the game was not run, so the 16-byte guard is not exercised on a GPU. The PR adds no unit test for raw_start_fits, so a passing suite only shows that it builds and breaks nothing else.

AI-assisted: this test was run and written up with Claude Code; the numbers above are its unedited output.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118717055 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/123#issuecomment-7118717055). Originally posted by [oVolkra](https://github.com/oVolkra) on 2026-11-24T01:03:57Z. --- Tested 828e3cd6 (merged onto main d2a4bae1) on RTX 3060, driver 617.14, Windows 11: pass - `cargo test --workspace`: 264 passed, 0 failed, 4 ignored (same counts as main d2a4bae1) - `cargo clippy --workspace --all-targets`: no new warnings (the same 2 as main) - `cargo xtask policy`: clean Not tested: the game was not run, so the 16-byte guard is not exercised on a GPU. The PR adds no unit test for `raw_start_fits`, so a passing suite only shows that it builds and breaks nothing else. AI-assisted: this test was run and written up with Claude Code; the numbers above are its unedited output.
ChruutvoLuzi commented 2026-11-24 06:55:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ChruutvoLuzi on 2026-11-24T03:00:52Z.


In-game data for the guard, which the comment above says wasn't exercised. RTX 4090, driver 621.01, Windows 11. 828e3cd merged onto d2a4bae together with #189, #205, #206, #134 and #89 (it conflicts with #206 in buffer_srv and buffer_uav; I kept #206's code and ran this check after it). Diag build, the first mission's opening each time.

Across 13 runs that reached the world, raw buffer view not on 16 bytes of its host copy and its unordered-view twin never fired. Three of those runs did end in 0x887A0001, but that was #55 at the time: a check of the device around every descriptor call traced it to CreateRenderTargetView on a texture #55 had made without render-target use, the case discussed in #55, not to a raw view. The others ended in the 0x887A0006 hang from #71. So on this card the guard costs nothing in this part of the game, and the raw-view invalid call it prevents didn't come up here.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120689345 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/123#issuecomment-7120689345). Originally posted by [ChruutvoLuzi](https://github.com/ChruutvoLuzi) on 2026-11-24T03:00:52Z. --- In-game data for the guard, which the comment above says wasn't exercised. RTX 4090, driver 621.01, Windows 11. `828e3cd` merged onto `d2a4bae` together with #189, #205, #206, #134 and #89 (it conflicts with #206 in `buffer_srv` and `buffer_uav`; I kept #206's code and ran this check after it). Diag build, the first mission's opening each time. Across 13 runs that reached the world, `raw buffer view not on 16 bytes of its host copy` and its unordered-view twin never fired. Three of those runs did end in `0x887A0001`, but that was #55 at the time: a check of the device around every descriptor call traced it to `CreateRenderTargetView` on a texture #55 had made without render-target use, the case discussed in #55, not to a raw view. The others ended in the `0x887A0006` hang from #71. So on this card the guard costs nothing in this part of the game, and the raw-view invalid call it prevents didn't come up here. AI-assisted (Claude Code).
mercuryVM commented 2026-11-24 07:42:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T07:42:40Z.

Review: APPROVED


Tested 828e3cd on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (254 passed, 0 failed; the branch is based on an older main). Not tested in game.

  • D3D12 requires a RAW buffer view's byte offset to be a multiple of 16, so with 4-byte elements FirstElement % 4 == 0 is exactly the rule from the quoted debug-layer message. Checking before CreateShaderResourceView/CreateUnorderedAccessView turns a device removal into a null view plus a one-time warning, which is clearly better.
  • Trade-off: a null view reads zeros, so the shader runs with wrong data, quietly apart from that one warning. The real fix is in the comment: start the view up to 12 bytes lower and add the difference in the translated shader's address math. That can be a follow-up.
  • The check only fires when the RAW flag is set. Structured and typed views keep their own rules.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035406902 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/123#pullrequestreview-6035406902). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T07:42:40Z. **Review:** APPROVED --- Tested 828e3cd on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (254 passed, 0 failed; the branch is based on an older main). Not tested in game. - D3D12 requires a RAW buffer view's byte offset to be a multiple of 16, so with 4-byte elements `FirstElement % 4 == 0` is exactly the rule from the quoted debug-layer message. Checking before `CreateShaderResourceView`/`CreateUnorderedAccessView` turns a device removal into a null view plus a one-time warning, which is clearly better. - Trade-off: a null view reads zeros, so the shader runs with wrong data, quietly apart from that one warning. The real fix is in the comment: start the view up to 12 bytes lower and add the difference in the translated shader's address math. That can be a follow-up. - The check only fires when the RAW flag is set. Structured and typed views keep their own rules. AI-assisted (Claude Code).
9hvn9yt2vk-netizen commented 2026-11-24 10:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 9hvn9yt2vk-netizen on 2026-11-24T09:46:41Z.


Thanks for testing and reviewing! Rebased onto current main (8e79c80) and added the tests you asked for: raw_views_start_on_16_bytes (which starts the check lets through and refuses, the reported FirstElement 42261210 included) and raw_views_that_fit_are_accepted_by_the_device (every start the check lets through is made as a raw SRV and UAV on the real device, which stays alive). Passes locally on an RTX 4060 with your new CI commands. Agreed that the full fix is the follow-up where the shader adds the offset difference.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7127874525 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/123#issuecomment-7127874525). Originally posted by [9hvn9yt2vk-netizen](https://github.com/9hvn9yt2vk-netizen) on 2026-11-24T09:46:41Z. --- Thanks for testing and reviewing! Rebased onto current main (8e79c80) and added the tests you asked for: raw_views_start_on_16_bytes (which starts the check lets through and refuses, the reported FirstElement 42261210 included) and raw_views_that_fit_are_accepted_by_the_device (every start the check lets through is made as a raw SRV and UAV on the real device, which stays alive). Passes locally on an RTX 4060 with your new CI commands. Agreed that the full fix is the follow-up where the shader adds the offset difference.
Marvisak commented 2026-11-25 01:07:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:17:28Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/descriptor/host.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148354850 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/123#issuecomment-7148354850). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:17:28Z. --- <!-- victory-triage v1 head=bc747281dcd62bccfd36f4692755a12378b32e0d verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/descriptor/host.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/123:upstream-pr/123'
git switch 'upstream-pr/123'

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