Skip to content

GPU: report allocated mips from GetDesc - #933

Open
enzoduarte1 wants to merge 1 commit into
Marvisak:mainfrom
enzoduarte1:gpu/getdesc-automatic-mips
Open

enzoduarte1 wants to merge 1 commit into
Marvisak:mainfrom
enzoduarte1:gpu/getdesc-automatic-mips

Conversation

@enzoduarte1

Copy link
Copy Markdown
Contributor

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.

@MichaelSmithAI

Copy link
Copy Markdown

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.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dcastell1

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Owner

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

@andrewpozdnakov7-jpg

Copy link
Copy Markdown

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 andrewpozdnakov7-jpg@users.noreply.github.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetDesc returns zero mips for automatically sized textures

9 participants