Repository navigation
GPU: refuse raw buffer views that do not start on 16 bytes - #123
9hvn9yt2vk-netizen wants to merge 2 commits into
Conversation
|
Tested
No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
Tested 828e3cd (merged onto main d2a4bae) on RTX 3060, driver 617.14, Windows 11: pass
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 AI-assisted: this test was run and written up with Claude Code; the numbers above are its unedited output. |
|
In-game data for the guard, which the comment above says wasn't exercised. RTX 4090, driver 621.01, Windows 11. Across 13 runs that reached the world, AI-assisted (Claude Code). |
…ytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # crates/victory-gpu/src/descriptor/host.rs
…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
left a comment
There was a problem hiding this comment.
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 == 0is exactly the rule from the quoted debug-layer message. Checking beforeCreateShaderResourceView/CreateUnorderedAccessViewturns 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).
…not start on 16 bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
828e3cd to
bc74728
Compare
|
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. |
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
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>
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.