GPU: align host copies for raw buffer UAVs #3073

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3075 into main
andrewpozdnakov7-jpg commented 2026-11-26 06:38:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T06:38:22Z.


Fixes #771.

The remaining RAW buffer case could use a 4-byte-aligned offset when mirroring a guest UAV to D3D12. Use D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT to select the host copy both when creating the RAW descriptor and when refreshing and copying back its data. The descriptor still covers the original range in 32-bit elements.

The synthetic guest ClearUnorderedAccessViewUint test clears four DWORDs through an odd-offset RAW view and checks all eight words, including the neighboring sentinels. It passed on Windows with app-local WARP 1.0.22 and D3D12 Agility 1.620.2. The full victory-gpu diagnostics suite passed 247 tests with one ignored. Strict GPU Clippy with all features and the asset policy passed. The title was not used.

Coordination claim

AI-assisted with Codex. Please retain the Git author when cherry-picking or rebasing. If you fold this change into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6621047348 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3075). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T06:38:22Z. --- Fixes #771. The remaining RAW buffer case could use a 4-byte-aligned offset when mirroring a guest UAV to D3D12. Use `D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT` to select the host copy both when creating the RAW descriptor and when refreshing and copying back its data. The descriptor still covers the original range in 32-bit elements. The synthetic guest `ClearUnorderedAccessViewUint` test clears four DWORDs through an odd-offset RAW view and checks all eight words, including the neighboring sentinels. It passed on Windows with app-local WARP 1.0.22 and D3D12 Agility 1.620.2. The full `victory-gpu` diagnostics suite passed 247 tests with one ignored. Strict GPU Clippy with all features and the asset policy passed. The title was not used. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7182308011) AI-assisted with Codex. Please retain the Git author when cherry-picking or rebasing. If you fold this change into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
Dukestar69 commented 2026-11-26 07:01:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:47:06Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Using D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT (16 bytes) for D3D12_BUFFER_UAV_FLAG_RAW in both buffer_uav and view_copy ensures raw buffer UAVs and their refresh/copyback paths share the same 16-byte-aligned host copy even when the title view starts at a non-16-byte-aligned offset.
  • cargo test -p victory-gpu list::tests -- --test-threads=1 (RTX 5090 & WARP): 5 passed, 0 failed on both (including a_raw_buffer_clear_keeps_words_outside_an_odd_offset_view).
  • cargo test -p victory-gpu descriptor::host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released (RTX 5090): 14 passed, 0 failed.
  • 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:6069660911 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3075#pullrequestreview-6069660911). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:47:06Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - Diff review: Using `D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT` (16 bytes) for `D3D12_BUFFER_UAV_FLAG_RAW` in both `buffer_uav` and `view_copy` ensures raw buffer UAVs and their refresh/copyback paths share the same 16-byte-aligned host copy even when the title view starts at a non-16-byte-aligned offset. - `cargo test -p victory-gpu list::tests -- --test-threads=1` (RTX 5090 & WARP): 5 passed, 0 failed on both (including `a_raw_buffer_clear_keeps_words_outside_an_odd_offset_view`). - `cargo test -p victory-gpu descriptor::host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released` (RTX 5090): 14 passed, 0 failed. - `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).
kotekompotek commented 2026-11-26 07:01:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:54:19Z.

Review: APPROVED


Verified: words[8] is D3D12_BUFFER_UAV.Flags for both Unordered and Placed(true) records (u64 FirstElement@2-3, NumElements@4, stride@5, u64 CounterOffset@6-7), and it is only read after buffer_range() confirms a buffer view. Passing alignment=16 (D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) for RAW into for_view makes the shadow's offset 16-aligned so the host descriptor satisfies the raw-UAV byte-offset rule; element stride preserved otherwise. The odd-offset clear test discriminates exactly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6069725632 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3075#pullrequestreview-6069725632). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T06:54:19Z. **Review:** APPROVED --- Verified: words[8] is D3D12_BUFFER_UAV.Flags for both Unordered and Placed(true) records (u64 FirstElement@2-3, NumElements@4, stride@5, u64 CounterOffset@6-7), and it is only read after buffer_range() confirms a buffer view. Passing alignment=16 (D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) for RAW into for_view makes the shadow's offset 16-aligned so the host descriptor satisfies the raw-UAV byte-offset rule; element stride preserved otherwise. The odd-offset clear test discriminates exactly.
fuzeofficlal commented 2026-11-26 09:05:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:12:26Z.

Review: APPROVED


Tested locally on Windows 11 x64 (rustc 1.98.1, NVIDIA GeForce RTX 5090 + WARP + D3D12 Debug Layer):

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features): clean.
  • RTX 5090: list::tests --test-threads=1 (5 passed, including a_raw_buffer_clear_keeps_words_outside_an_odd_offset_view), descriptor::host::tests --test-threads=1 --skip dynamic_slots_are_held_until_released (14 passed).
  • WARP with D3D12 Debug Layer (--features diagnostics, VICTORY_D3D12_WARP=1, VICTORY_D3D12_DEBUG=1): list::tests (5 passed) and descriptor::host::tests (15 passed) with zero debug-layer errors.
  • cargo xtask policy: 191 files ok.

Using D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT (16 bytes) consistently in both buffer_uav and view_copy ensures the host descriptor's FirstElement stays 4-DWORD (16-byte) aligned while refresh and copy-back hit the exact same shadow::for_view copy key.

Non-blocking follow-up note: buffer_srv (descriptor/host.rs:1235) and the SRV arm of view_copy still pass element (4) instead of D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT (16) for D3D12_BUFFER_SRV_FLAG_RAW, which has the same 16-byte offset rule in D3D12. Worth mirroring in a small follow-up if odd-offset raw SRVs come up.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6070505532 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3075#pullrequestreview-6070505532). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:12:26Z. **Review:** APPROVED --- Tested locally on Windows 11 x64 (`rustc 1.98.1`, NVIDIA GeForce RTX 5090 + WARP + D3D12 Debug Layer): - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default and `--all-features`): clean. - RTX 5090: `list::tests --test-threads=1` (5 passed, including `a_raw_buffer_clear_keeps_words_outside_an_odd_offset_view`), `descriptor::host::tests --test-threads=1 --skip dynamic_slots_are_held_until_released` (14 passed). - WARP with D3D12 Debug Layer (`--features diagnostics`, `VICTORY_D3D12_WARP=1`, `VICTORY_D3D12_DEBUG=1`): `list::tests` (5 passed) and `descriptor::host::tests` (15 passed) with zero debug-layer errors. - `cargo xtask policy`: 191 files ok. Using `D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT` (16 bytes) consistently in both `buffer_uav` and `view_copy` ensures the host descriptor's `FirstElement` stays 4-DWORD (16-byte) aligned while refresh and copy-back hit the exact same `shadow::for_view` copy key. Non-blocking follow-up note: `buffer_srv` (`descriptor/host.rs:1235`) and the SRV arm of `view_copy` still pass `element` (4) instead of `D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT` (16) for `D3D12_BUFFER_SRV_FLAG_RAW`, which has the same 16-byte offset rule in D3D12. Worth mirroring in a small follow-up if odd-offset raw SRVs come up. LGTM.
Marvisak commented 2026-11-26 09:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:22:09Z.


Automated triage for the maintainers.

Merge candidate. descriptor::host::buffer_uav now asks shadow::for_view for a 16-byte-aligned copy (D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) when the view is RAW, so FirstElement = shadow.offset(start) / 4 always lands on a 16-byte boundary (the arena already places exact copies on multiples of 256). view_copy reads the UAV flags from the same descriptor words (dword 8 is Flags in the host layout) and passes the same alignment, so the refresh and copy-back in draw.rs/bindless.rs find the same EXACT entry instead of a 4-aligned one. This is the odd-offset raw case the triage note on #771 asked for. The new test a_raw_buffer_clear_keeps_words_outside_an_odd_offset_view checks the neighbouring sentinels. CI: passing.

A note, not a blocker: buffer_srv still uses a 4-byte element for raw SRVs, and those have the same 16-byte rule on the host. A follow-up could share buffer_uav_alignment with that path.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186509756 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3075#issuecomment-7186509756). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:22:09Z. --- <!-- victory-triage v1 head=f4b814d8832c610509951e24a264e60922ec3e04 verdict=merge-candidate at=2026-11-26T08:18:02Z --> Automated triage for the maintainers. Merge candidate. `descriptor::host::buffer_uav` now asks `shadow::for_view` for a 16-byte-aligned copy (`D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT`) when the view is RAW, so `FirstElement = shadow.offset(start) / 4` always lands on a 16-byte boundary (the arena already places exact copies on multiples of 256). `view_copy` reads the UAV flags from the same descriptor words (dword 8 is `Flags` in the host layout) and passes the same alignment, so the refresh and copy-back in `draw.rs`/`bindless.rs` find the same `EXACT` entry instead of a 4-aligned one. This is the odd-offset raw case the triage note on #771 asked for. The new test `a_raw_buffer_clear_keeps_words_outside_an_odd_offset_view` checks the neighbouring sentinels. CI: passing. A note, not a blocker: `buffer_srv` still uses a 4-byte element for raw SRVs, and those have the same 16-byte rule on the host. A follow-up could share `buffer_uav_alignment` with that path. --- _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/3075:upstream-pr/3075'
git switch 'upstream-pr/3075'

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