GPU: read UAV MipSlice from offset 8 in image_words #2599

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

@⁠fuzeofficlal on GitHub · 2026-11-25 16:33 UTC · original
fuzeofficlal:fix/gpu-image-words-uav-mip-slice → main · +25 −5 · 1 files · 1 commits · open

Summary

image_words in crates/victory-gpu/src/descriptor/host.rs read d[4] for both SRV and UAV texture views.

  • D3D12_SHADER_RESOURCE_VIEW_DESC has Format (d[0]), ViewDimension (d[1]), Shader4ComponentMapping (d[2]), and 4 bytes of union alignment padding (d[3]), placing MostDetailedMip at offset 16 (d[4]).
  • D3D12_UNORDERED_ACCESS_VIEW_DESC has Format (d[0]) and ViewDimension (d[1]), with the view union starting directly at offset 8 (d[2]), so MipSlice lives at d[2] across Texture1D, Texture1DArray, Texture2D, Texture2DArray, and Texture3D UAVs.

Reading d[4] for UAVs read 0 for a 2D UAV (PlaneSlice is at d[3], d[4] is unused/zero), and read ArraySize / WSize for 2D array and 3D UAVs, corrupting the first / last mip fields encoded into the RDNA image descriptor words.

Changes

  • crates/victory-gpu/src/descriptor/host.rs: read d[2] instead of d[4] in image_words for unordered (unordered == true) non-MSAA texture views.
  • Expanded a_texture_view_gives_its_image_descriptor_size_fields to build descriptor word arrays from actual D3D12_SHADER_RESOURCE_VIEW_DESC and D3D12_UNORDERED_ACCESS_VIEW_DESC structs (Texture2D, Texture2DArray, and Texture3D UAVs with distinct MipSlice vs d[4] values).

Verification

  • cargo test -p victory-gpu --lib descriptor::host::tests::a_texture_view_gives_its_image_descriptor_size_fields -- --exact — pass
  • cargo clippy -p victory-gpu --all-targets -- -D warnings and --features diagnostics — pass (0 warnings)
  • cargo xtask policy — pass (184 files ok)
**@⁠fuzeofficlal** on GitHub · 2026-11-25 16:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2599) `fuzeofficlal:fix/gpu-image-words-uav-mip-slice` → `main` · +25 −5 · 1 files · 1 commits · open ## Summary `image_words` in `crates/victory-gpu/src/descriptor/host.rs` read `d[4]` for both SRV and UAV texture views. - `D3D12_SHADER_RESOURCE_VIEW_DESC` has `Format` (`d[0]`), `ViewDimension` (`d[1]`), `Shader4ComponentMapping` (`d[2]`), and 4 bytes of union alignment padding (`d[3]`), placing `MostDetailedMip` at offset 16 (`d[4]`). - `D3D12_UNORDERED_ACCESS_VIEW_DESC` has `Format` (`d[0]`) and `ViewDimension` (`d[1]`), with the view union starting directly at offset 8 (`d[2]`), so `MipSlice` lives at `d[2]` across `Texture1D`, `Texture1DArray`, `Texture2D`, `Texture2DArray`, and `Texture3D` UAVs. Reading `d[4]` for UAVs read `0` for a 2D UAV (`PlaneSlice` is at `d[3]`, `d[4]` is unused/zero), and read `ArraySize` / `WSize` for 2D array and 3D UAVs, corrupting the `first` / `last` mip fields encoded into the RDNA image descriptor words. ## Changes - `crates/victory-gpu/src/descriptor/host.rs`: read `d[2]` instead of `d[4]` in `image_words` for unordered (`unordered == true`) non-MSAA texture views. - Expanded `a_texture_view_gives_its_image_descriptor_size_fields` to build descriptor word arrays from actual `D3D12_SHADER_RESOURCE_VIEW_DESC` and `D3D12_UNORDERED_ACCESS_VIEW_DESC` structs (`Texture2D`, `Texture2DArray`, and `Texture3D` UAVs with distinct `MipSlice` vs `d[4]` values). ## Verification - `cargo test -p victory-gpu --lib descriptor::host::tests::a_texture_view_gives_its_image_descriptor_size_fields -- --exact` — pass - `cargo clippy -p victory-gpu --all-targets -- -D warnings` and `--features diagnostics` — pass (0 warnings) - `cargo xtask policy` — pass (`184 files ok`)
image_words read descriptor[4] for both shader and unordered texture views, matching D3D12_SHADER_RESOURCE_VIEW_DESC (where Shader4ComponentMapping and 4-byte union alignment padding precede MostDetailedMip at dword 4), whereas D3D12_UNORDERED_ACCESS_VIEW_DESC places MipSlice directly at dword 2 (offset 8) for all 1D/2D/3D/array texture UAV variants. For Texture2DArray/Texture3D UAVs, dword 4 was ArraySize/WSize, corrupting first/last mip bounds. Read d[2] for unordered views, verify the D3D12 descriptor field offsets via compile-time offset_of! assertions, and test Texture2D, Texture2DArray, and Texture3D UAV word arrays with distinct d[2] and d[4] values.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:03 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 17:22 UTC · original

Good catch @⁠DrDarkDK — reading inactive union bytes through copy_nonoverlapping is indeed UB.

Updated (bf34b7a) to remove as_words / unsafe completely: the test now verifies all D3D12_SHADER_RESOURCE_VIEW_DESC and D3D12_UNORDERED_ACCESS_VIEW_DESC (1D/1DArray/2D/2DArray/3D) field offsets with compile-time std::mem::offset_of! assertions and passes fully initialized [u32; 10] arrays with distinct d[2] vs d[4] values. Re-verified tests, clippy (default + diagnostics), and cargo xtask policy.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 17:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2599#issuecomment-7169401438) Good catch @⁠DrDarkDK — reading inactive union bytes through `copy_nonoverlapping` is indeed UB. Updated (`bf34b7a`) to remove `as_words` / `unsafe` completely: the test now verifies all `D3D12_SHADER_RESOURCE_VIEW_DESC` and `D3D12_UNORDERED_ACCESS_VIEW_DESC` (`1D`/`1DArray`/`2D`/`2DArray`/`3D`) field offsets with compile-time `std::mem::offset_of!` assertions and passes fully initialized `[u32; 10]` arrays with distinct `d[2]` vs `d[4]` values. Re-verified tests, clippy (default + diagnostics), and `cargo xtask policy`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:18 UTC · original

Automated triage for the maintainers.

In crates/victory-gpu/src/descriptor/host.rs, image_words read d[4] as the first mip for unordered texture views. The view words use the host D3D12 layout (uav_desc casts them directly to D3D12_UNORDERED_ACCESS_VIEW_DESC), and that union starts at byte 8, so MipSlice is d[2]. d[4] holds MipSlice only in the SRV layout. The one-word fix is correct by the public D3D12 struct layout. The updated test a_texture_view_gives_its_image_descriptor_size_fields pins the offsets with offset_of! and covers 2D, 2D-array and 3D UAVs, using values that would catch the old read. The branch merges cleanly with current main. CI: passing (check). This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2599#issuecomment-7177380948) <!-- victory-triage v1 head=bf34b7a1ea8ca8a68b9d1b6fad81c76bf9d44563 verdict=merge-candidate at=2026-11-25T23:17:59Z --> Automated triage for the maintainers. In `crates/victory-gpu/src/descriptor/host.rs`, `image_words` read `d[4]` as the first mip for unordered texture views. The view words use the host D3D12 layout (`uav_desc` casts them directly to `D3D12_UNORDERED_ACCESS_VIEW_DESC`), and that union starts at byte 8, so `MipSlice` is `d[2]`. `d[4]` holds `MipSlice` only in the SRV layout. The one-word fix is correct by the public D3D12 struct layout. The updated test `a_texture_view_gives_its_image_descriptor_size_fields` pins the offsets with `offset_of!` and covers 2D, 2D-array and 3D UAVs, using values that would catch the old read. The branch merges cleanly with current `main`. CI: passing (check). This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Kajanos on GitHub · 2026-11-26 00:07 UTC · original

Windows 11 / NVIDIA test run, head bf34b7a1ea merged onto main 63bcca43c6.

Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (dxil.dll from the SDK).

  • cargo test --locked -p victory-gpu: 231 passed, 0 failed, 1 ignored (same as main).

Not run: the retail title, clippy, and other crates.

AI-assisted (Claude Code)

**@⁠Kajanos** on GitHub · 2026-11-26 00:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2599#issuecomment-7178415598) **Windows 11 / NVIDIA test run**, head `bf34b7a1ea` merged onto `main` `63bcca43c6`. Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (`dxil.dll` from the SDK). - `cargo test --locked -p victory-gpu`: 231 passed, 0 failed, 1 ignored (same as `main`). Not run: the retail title, clippy, and other crates. AI-assisted (Claude Code)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2599/head:github-bot/gh-2599'
git switch 'github-bot/gh-2599'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2599'
git switch 'github-bot/gh-2599'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2599'
git switch 'github-bot/gh-2599'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2599'
git switch 'main'
git merge --squash 'github-bot/gh-2599'
git switch 'main'
git merge --ff-only 'github-bot/gh-2599'
git switch 'main'
git merge 'github-bot/gh-2599'
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!2599
No description provided.