GPU: report allocated mips from GetDesc #933

Open
enzoduarte1 wants to merge 1 commit from upstream-pr/933 into main
enzoduarte1 commented 2026-11-24 14:18:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T14:18:56Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6583856816 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T14:18:56Z. --- ## 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.
mercuryVM commented 2026-11-24 15:03:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T14:23:48Z.

Review: APPROVED


Tested 9914ea4 on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu -- --test-threads=1 51 passed, including get_desc_reports_the_allocated_mip_chain. Clippy's 1 warning is the existing undocumented_unsafe_blocks in host.rs.

  • Filling in mip_levels only when the title asked for 0 matches native GetDesc, which reports what was allocated, and leaves explicit counts and buffers alone. Reusing mip_count keeps it consistent with what create_committed actually made.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6040959073 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#pullrequestreview-6040959073). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T14:23:48Z. **Review:** APPROVED --- Tested 9914ea4 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-gpu -- --test-threads=1` 51 passed, including `get_desc_reports_the_allocated_mip_chain`. Clippy's 1 warning is the existing `undocumented_unsafe_blocks` in host.rs. - Filling in `mip_levels` only when the title asked for 0 matches native `GetDesc`, which reports what was allocated, and leaves explicit counts and buffers alone. Reusing `mip_count` keeps it consistent with what `create_committed` actually made. AI-assisted (Claude Code).
DenRakEiw commented 2026-11-24 15:03:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T14:24:12Z.

Review: COMMENTED


Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP (VICTORY_D3D12_WARP=1):

  • cargo test -p victory-gpu (RTX 5090): 51 passed, 0 failed, 1 ignored (including resource::tests::get_desc_reports_the_allocated_mip_chain)
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu (WARP): 51 passed, 0 failed, 1 ignored
  • cargo xtask policy: ok
  • cargo clippy -p victory-gpu --all-targets: 1 clippy::undocumented_unsafe_blocks warning (which will fail CI's -D warnings):
    • crates/victory-gpu/src/resource.rs:1250: if let Some(out) = unsafe { out.as_mut() } is missing a preceding // SAFETY: comment.

Tests and runtime behavior look good — adding the // SAFETY: comment on resource.rs:1250 will make clippy/CI clean.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6040966974 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#pullrequestreview-6040966974). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T14:24:12Z. **Review:** COMMENTED --- Tested merged cleanly onto `main` (`ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC) with **NVIDIA GeForce RTX 5090** (Blackwell) and **WARP** (`VICTORY_D3D12_WARP=1`): - `cargo test -p victory-gpu` (RTX 5090): **51 passed, 0 failed, 1 ignored** (including `resource::tests::get_desc_reports_the_allocated_mip_chain`) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu` (WARP): **51 passed, 0 failed, 1 ignored** - `cargo xtask policy`: ok - **`cargo clippy -p victory-gpu --all-targets`:** 1 `clippy::undocumented_unsafe_blocks` warning (which will fail CI's `-D warnings`): - `crates/victory-gpu/src/resource.rs:1250`: `if let Some(out) = unsafe { out.as_mut() }` is missing a preceding `// SAFETY:` comment. Tests and runtime behavior look good — adding the `// SAFETY:` comment on `resource.rs:1250` will make clippy/CI clean. AI-assisted (Gemini 4 Neon).
MichaelSmithAI commented 2026-11-24 15:03:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T14:22:16Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134263831 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7134263831). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T14:22:16Z. --- 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.
dcastell1 commented 2026-11-24 15:04:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by dcastell1 on 2026-11-24T14:28:37Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134437296 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7134437296). Originally posted by [dcastell1](https://github.com/dcastell1) on 2026-11-24T14:28:37Z. --- 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.
Zipettte commented 2026-11-24 16:05:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:40:53Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136433195 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7136433195). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:40:53Z. --- 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)._
fuzeofficlal commented 2026-11-24 18:05:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:24:28Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7139147815 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7139147815). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:24:28Z. --- 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.
Marvisak commented 2026-11-25 02:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:25:23Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149529481 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7149529481). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:25:23Z. --- <!-- 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)_
andrewpozdnakov7-jpg commented 2026-11-25 08:06:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T07:53:32Z.


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]

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156368450 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/933#issuecomment-7156368450). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T07:53:32Z. --- 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 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/933:upstream-pr/933'
git switch 'upstream-pr/933'

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