Skip to content

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

Open
9hvn9yt2vk-netizen wants to merge 2 commits into
Marvisak:mainfrom
9hvn9yt2vk-netizen:raw-view-alignment
Open

9hvn9yt2vk-netizen wants to merge 2 commits into
Marvisak:mainfrom
9hvn9yt2vk-netizen:raw-view-alignment

Conversation

@9hvn9yt2vk-netizen

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

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, Wine/vkd3d: deferred uploads are skipped because VirtualQuery() reports mapped memory as MEM_FREE #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

oVolkra commented Nov 24, 2026

Copy link
Copy Markdown

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

  • cargo test --workspace: 264 passed, 0 failed, 4 ignored (same counts as main d2a4bae)
  • 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

ChruutvoLuzi commented Nov 24, 2026 •

Copy link
Copy Markdown

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).

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…ytes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	crates/victory-gpu/src/descriptor/host.rs
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…ent become raw views)

AnoHunted's Marvisak#206: a structured buffer view whose start in its host copy
is not on an element, which stayed null, is made as the raw view of the
same bytes where those start on 16 bytes.

Conflict resolution, crates/victory-gpu/src/descriptor/host.rs:
- buffer_srv and buffer_uav: Marvisak#206's three-way choice (on an element,
  raw view of the same bytes, refused) is kept, and Marvisak#123's refusal of a
  raw view that does not start on 16 bytes of the host copy follows it,
  as it followed the old test. Marvisak#206 moved `FirstElement += offset /
  element` into its first arm and `CounterOffsetInBytes = 0` before the
  choice; the copies of those lines on this tree's side are dropped.
- tests: this tree's and Marvisak#206's are all kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@mercuryVM mercuryVM 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.

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).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…not start on 16 bytes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9hvn9yt2vk-netizen and others added 2 commits November 24, 2026 10:39
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.
As the reviews of this change asked: raw_views_start_on_16_bytes checks
which starts the check lets through (elements 0, 4, 8...) and refuses
(4, 8 and 12 bytes past a boundary, the user report's FirstElement
42261210 included); raw_views_that_fit_are_accepted_by_the_device makes
every start the check lets through below 64 as a raw SRV and UAV of a
real buffer and checks the device stays alive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@9hvn9yt2vk-netizen

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Owner

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

github-actions Bot pushed a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Title buffer views reached CreateShaderResourceView and
CreateUnorderedAccessView with the title's own format. The title's heap
holds views the host refuses: made for its own runtime, or old ones in
slots it does not use. On WARP with the debug layer:

  - a raw view of R32_UINT: "When creating a RAW Shader Resource View,
    the format must be DXGI_FORMAT_R32_TYPELESS", then device removal
    (DXGI_ERROR_INVALID_CALL) for the shader resource view;
  - a structured view with a format: "it must be DXGI_FORMAT_UNKNOWN";
  - a typed view of a typeless format: "cannot be used when creating a
    typed View of a Buffer".

A raw or structured view reads its bytes whatever its format says, so it
is now made in the format the host wants (R32_TYPELESS, UNKNOWN); a raw
view with a structure stride, or a typed view of no format or a typeless
one, has none and stays null, with a warning once. Structure strides are
left as they are (2, 6 and 4096 are taken by the debug layer).

Test: buffer_views_take_a_format_the_host_takes.

From DexNom/VIctory@570a941
(buffer_view_ok in descriptor/host.rs), reworked: views are corrected
where their bytes do not depend on the format instead of refused, and
the stride limits and the raw 16-byte start, which the debug layer does
not ask for or which Marvisak#123 covers, are left out.

Co-authored-by: DexNom <29156494+DexNom@users.noreply.github.com>
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.

6 participants