GPU: report allocated mips from GetDesc #933

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

@⁠enzoduarte1 on GitHub · 2026-11-24 14:18 UTC · original
enzoduarte1:gpu/getdesc-automatic-mips → main · +50 −3 · 1 files · 1 commits · open

What

CreateCommittedResource with MipLevels = 0 allocates a full mip chain, but the guest GetDesc (slot 0x50) returned the description verbatim, so titles saw zero levels. Native D3D12 reports the allocated count. This patch reuses the existing mip_count helper when filling the output description, leaving explicit mip counts untouched.

Fixes #773.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-gpu --lib -- --test-threads=1: 51 passed, 1 ignored (existing benchmark).
  • New test get_desc_reports_the_allocated_mip_chain covers a 4x4 automatic chain (3 levels), an explicit 2-level texture and a buffer (1 level).
  • git diff --check clean; rustfmt --edition 2024 --check shows only a pre-existing formatting diff at resource.rs:867, untouched by this change.
  • cargo xtask policy: 154 files ok. No game files or data taken from them were added.

Checklist

  • cargo fmt --all --check and cargo test --workspace pass — this workspace has pre-existing formatting diffs and the loader fixture needs MSVC /DELAYLOAD, which MinGW rejects here; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
**@⁠enzoduarte1** on GitHub · 2026-11-24 14:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/933) `enzoduarte1:gpu/getdesc-automatic-mips` → `main` · +50 −3 · 1 files · 1 commits · open ## What `CreateCommittedResource` with `MipLevels = 0` allocates a full mip chain, but the guest `GetDesc` (slot `0x50`) returned the description verbatim, so titles saw zero levels. Native D3D12 reports the allocated count. This patch reuses the existing `mip_count` helper when filling the output description, leaving explicit mip counts untouched. Fixes #773. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-gpu --lib -- --test-threads=1`: 51 passed, 1 ignored (existing benchmark). - New test `get_desc_reports_the_allocated_mip_chain` covers a 4x4 automatic chain (3 levels), an explicit 2-level texture and a buffer (1 level). - `git diff --check` clean; `rustfmt --edition 2024 --check` shows only a pre-existing formatting diff at `resource.rs:867`, untouched by this change. - `cargo xtask policy`: 154 files ok. No game files or data taken from them were added. ## Checklist - [ ] `cargo fmt --all --check` and `cargo test --workspace` pass — this workspace has pre-existing formatting diffs and the loader fixture needs MSVC `/DELAYLOAD`, which MinGW rejects here; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:24 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 14:22 UTC · original

The author’s GetDesc test passed on exact 9914ea4 under RTX 4090 Wine/GE 3.2. An additional guest-vtable test checked committed 4×2 textures with nine array slices or volume depth nine. Guest and host both reported three automatic levels for the array and four for the volume. Both reported two for an explicit request of two.

I submitted a follow-up that uses a raw write into the caller’s potentially uninitialized output storage and includes the additional test. Both GetDesc tests passed on that head.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7134263831) The author’s GetDesc test passed on exact 9914ea4 under RTX 4090 Wine/GE 3.2. An additional guest-vtable test checked committed 4×2 textures with nine array slices or volume depth nine. Guest and host both reported three automatic levels for the array and four for the volume. Both reported two for an explicit request of two. I submitted a [follow-up](https://github.com/enzoduarte1/VIctory/pull/1) that uses a raw write into the caller’s potentially uninitialized output storage and includes the additional test. Both GetDesc tests passed on that head.
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 14:28 UTC · original

Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build. main@ffe310e baseline on this box: 342 passed, 0 failed, 6 ignored.

cargo test --workspace
343 passed; 0 failed; 6 ignored   (exit 0)

One more than the baseline; reporting allocated mips from GetDesc is covered and green.

Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran cargo test --workspace, reverted it.

**@⁠dcastell1** on GitHub · 2026-11-24 14:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7134437296) Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build. `main@ffe310e` baseline on this box: **342 passed, 0 failed, 6 ignored**. ``` cargo test --workspace 343 passed; 0 failed; 6 ignored (exit 0) ``` One more than the baseline; reporting allocated mips from `GetDesc` is covered and green. Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran `cargo test --workspace`, reverted it.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9914ea4: cargo test -p victory-gpu passes, 51 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7136433195) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9914ea4: `cargo test -p victory-gpu` passes, 51 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

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

Verified the GetDesc expanded mip-count fix on NVIDIA GeForce RTX 5090 (D3D12 Debug Layer) and D3D12 WARP (D3D12 Debug Layer) (0 debug errors), including MaybeUninit<ResourceDesc> out-pointer calls across 1D / 2D / 2D Array / 3D MipLevels == 0 textures and per-mip RTV clear + readback across all expanded levels: fuzeofficlal/VIctory@519f91e.

Confirming the two items blocking CI / soundness in 9914ea4:

  1. Keep if !out.is_null() + // SAFETY: + unsafe { out.write(desc) }; rather than unsafe { out.as_mut() }: callers of ID3D12Resource::GetDesc pass an uninitialized stack slot for the C++ out-return struct, so materializing &mut ResourceDesc via as_mut() is immediate UB in Rust, and omitting // SAFETY: fails -D clippy::undocumented_unsafe_blocks in CI.
  2. Guarding if desc.dimension != BUFFER && desc.mip_levels == 0 { desc.mip_levels = mip_count(&desc) as u16; } before out.write(desc) is 4 lines and passes Clippy cleanly.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7139147815) Verified the `GetDesc` expanded mip-count fix on **NVIDIA GeForce RTX 5090 (D3D12 Debug Layer)** and **D3D12 WARP (D3D12 Debug Layer)** (`0` debug errors), including `MaybeUninit<ResourceDesc>` out-pointer calls across 1D / 2D / 2D Array / 3D `MipLevels == 0` textures and per-mip RTV clear + readback across all expanded levels: [`fuzeofficlal/VIctory@519f91e`](https://github.com/fuzeofficlal/VIctory/commit/519f91ef9146e64f76bc83eace208183458c2c02). Confirming the two items blocking CI / soundness in `9914ea4`: 1. Keep `if !out.is_null()` + `// SAFETY:` + `unsafe { out.write(desc) };` rather than `unsafe { out.as_mut() }`: callers of `ID3D12Resource::GetDesc` pass an uninitialized stack slot for the C++ out-return struct, so materializing `&mut ResourceDesc` via `as_mut()` is immediate UB in Rust, and omitting `// SAFETY:` fails `-D clippy::undocumented_unsafe_blocks` in CI. 2. Guarding `if desc.dimension != BUFFER && desc.mip_levels == 0 { desc.mip_levels = mip_count(&desc) as u16; }` before `out.write(desc)` is 4 lines and passes Clippy cleanly.
Author
Owner

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

Automated triage for the maintainers.

Needs work. The change is right, but CI is red because of how it is written.

resource_desc (guest GetDesc, slot 0x50, in crates/victory-gpu/src/resource.rs) now fills in MipLevels = 0 with mip_count(&desc), the chain create_committed actually allocates. Explicit counts are left as they are. This matches what native D3D12 reports. Testers in the thread confirmed it on NVIDIA, AMD and Wine.

What it needs:

  • CI fails clippy: unsafe block missing a safety comment at resource.rs:1250.
  • Do not use as_mut() here. The title passes the C++ out-return slot, which can be uninitialized, and turning it into &mut ResourceDesc is unsound. Keep main's if !out.is_null() with the // SAFETY: comment and unsafe { out.write(desc) }, and adjust desc before the write.
  • Optional: skip the fix-up for dimension == BUFFER, so a buffer described with MipLevels = 0 does not get a chain computed from its width.

With those changes this is a merge candidate.

CI: check fails (the clippy error above).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7149529481) <!-- victory-triage v1 head=9914ea4be88aaad665e26e43eaec768f3a3a77dd verdict=needs-work at=2026-11-25T01:25:22Z --> Automated triage for the maintainers. **Needs work.** The change is right, but CI is red because of how it is written. `resource_desc` (guest `GetDesc`, slot `0x50`, in `crates/victory-gpu/src/resource.rs`) now fills in `MipLevels = 0` with `mip_count(&desc)`, the chain `create_committed` actually allocates. Explicit counts are left as they are. This matches what native D3D12 reports. Testers in the thread confirmed it on NVIDIA, AMD and Wine. What it needs: - **CI fails clippy:** `unsafe block missing a safety comment` at `resource.rs:1250`. - **Do not use `as_mut()` here.** The title passes the C++ out-return slot, which can be uninitialized, and turning it into `&mut ResourceDesc` is unsound. Keep `main`'s `if !out.is_null()` with the `// SAFETY:` comment and `unsafe { out.write(desc) }`, and adjust `desc` before the write. - Optional: skip the fix-up for `dimension == BUFFER`, so a buffer described with `MipLevels = 0` does not get a chain computed from its width. With those changes this is a merge candidate. CI: `check` fails (the clippy error above). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 07:53 UTC · original

I addressed the two review points in 625ed94, directly on 9914ea4be88aaad665e26e43eaec768f3a3a77dd. It retains main's checked pointer write and computes an automatic count only for textures.

The same guest GetDesc test returned 9 for a 256-byte buffer whose stored count was zero before the change, and returns the stored zero afterward. The automatic 4×4 texture still reports 3, the explicit 2-mip texture reports 2, and the normal buffer reports 1. The WARP GPU suite went from 53 passed / 1 failed / 1 ignored to 54 passed / 0 failed / 1 ignored. Strict GPU Clippy reproduced the existing missing safety comment failure before and passed afterward with and without diagnostics. A local merge into 940d32f69b22265690a0b5a15d6ded572ba33baf was clean and passed 147 GPU tests on WARP, with 2 ignored.

Thanks to @⁠fuzeofficlal for the verification and review. If you include the follow-up, please preserve its Git author. If you fold it into your commit, please add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 07:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7156368450) I addressed the two review points in [625ed94](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/625ed940d17d5f4c68e1ef26128bae46f89fa3fb), directly on `9914ea4be88aaad665e26e43eaec768f3a3a77dd`. It retains main's checked pointer write and computes an automatic count only for textures. The same guest `GetDesc` test returned 9 for a 256-byte buffer whose stored count was zero before the change, and returns the stored zero afterward. The automatic 4×4 texture still reports 3, the explicit 2-mip texture reports 2, and the normal buffer reports 1. The WARP GPU suite went from 53 passed / 1 failed / 1 ignored to 54 passed / 0 failed / 1 ignored. Strict GPU Clippy reproduced the existing missing safety comment failure before and passed afterward with and without diagnostics. A local merge into `940d32f69b22265690a0b5a15d6ded572ba33baf` was clean and passed 147 GPU tests on WARP, with 2 ignored. Thanks to @⁠fuzeofficlal for the verification and review. If you include the follow-up, please preserve its Git author. If you fold it into your commit, please add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
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/933/head:github-bot/gh-933'
git switch 'github-bot/gh-933'

Merge

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