Skip to content

GPU: aspect-aware concrete format resolution for typeless views (fixes #882, #876) - #970

Open
pushkarreddyy wants to merge 1 commit into
Marvisak:mainfrom
pushkarreddyy:fix/gpu-typeless-srv-aspect-aware
Open

pushkarreddyy wants to merge 1 commit into
Marvisak:mainfrom
pushkarreddyy:fix/gpu-typeless-srv-aspect-aware

Conversation

@pushkarreddyy

@pushkarreddyy pushkarreddyy commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #882, #876.

Root Cause

On main, fits() in crates/victory-gpu/src/descriptor/host.rs leaves typeless view formats (_TYPELESS) untouched when creating SRVs/UAVs on _TYPELESS host textures, and refuses views without an explicit description. D3D12 rejects _TYPELESS view formats and None view descriptions on _TYPELESS resources, causing views to fall back to null.

Implementation Details

  1. Aspect- and Usage-Aware Concrete Format Mapping (crates/victory-gpu/src/resource.rs):
    • Added is_typeless(format) with checked_add(1) overflow protection for malformed/boundary format words (e.g. u32::MAX).
    • Added concrete_view_format(format, depth, unordered) -> Option<u32> which:
      • Resolves depth typeless and attachment formats (19..=21 -> 21, 22 -> 22, 44..=46 -> 46, 47 -> 47, 39|40 -> 41, 55 -> 56) to legal D3D12 SRV formats rather than DSV attachment formats.
      • Distinguishes R16_TYPELESS (53) by ALLOW_DEPTH_STENCIL: R16_UNORM (56) for depth resources vs. R16_FLOAT (54) for non-depth color/UAV resources.
      • Resolves color typeless families (90 -> 87, 88|92 -> 88, 94 -> 95, and standard f + 1 families).
      • Returns None when unordered == true for formats without legal D3D12 UAV support (planar depth/stencil, D16_UNORM, B8G8R8X8, and block-compressed 70..=84 / 94..=99).
  2. Default Descriptor Synthesis & fits() Validation (crates/victory-gpu/src/descriptor/host.rs):
    • Added default_srv_desc and default_uav_desc to synthesize full D3D12_SHADER_RESOURCE_VIEW_DESC / D3D12_UNORDERED_ACCESS_VIEW_DESC structures (dimension, mip count, array/depth extent, seeded from view_format(resource)) when a title omits pDesc on a typeless host texture.
    • Updated fits() to track ALLOW_DEPTH_STENCIL, return false if format remains None on a typeless texture (guaranteeing None never reaches D3D12), and resolve view formats via concrete_view_format(view, depth, unordered).
    • Wired default_srv_desc and default_uav_desc into make() for View::Shader and View::Unordered.

Verification

  • Unit Tests: concrete_view_format_resolves_color_depth_uav_and_bounds in crates/victory-gpu/src/resource.rs verifies color, depth, R16_TYPELESS depth vs. color/UAV, planar depth UAV rejection, BC UAV rejection, and 0/u32::MAX bounds.
  • Hardware Testing: Community verification on RTX 4090, RX 7700 XT, and RTX 5090 / WARP (VICTORY_D3D12_DEBUG=1).
  • CI: check (build, clippy -D warnings, workspace tests) passing on d782a7d.

Scope & Limitations

  • Only view format resolution and omitted-descriptor synthesis are modified; resource allocation and depth-stencil plane selection (#651) remain unchanged.
  • No title files, captures, or proprietary assets were used.

@MichaelSmithAI

Copy link
Copy Markdown

The format-table test passed at 60222b3. A separate preparation-only check used a live R24G8_TYPELESS depth texture on RTX 4090 under Wine/vkd3d-proton 3.2. For an explicit SRV descriptor, both UNKNOWN and R24G8_TYPELESS resolved to the depth-plane format R24_UNORM_X8_TYPELESS (46).

Three cases remain relevant to #882. An explicit D24_UNORM_S8_UINT request stayed at the attachment format (45). With the descriptor absent altogether, the preparation helper returned success without supplying a concrete format. An explicit stencil format (47) stayed 47, but this helper only receives the format and cannot select the stencil plane. The comparison stopped at preparation, before host view creation or shader execution.

For integration, #651 already handles explicit depth/stencil aspect selection. Keeping the R16 depth and color cases distinct is also important: the same typeless family can back either usage.

@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 60222b3: 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).

MfDev0 pushed a commit to MfDev0/victory that referenced this pull request Nov 24, 2026
A shader or UAV view naming a typeless format (or none) of a typeless
host texture was refused or created with the typeless format, which the
host rejects: the slot stayed null and read black. Such views now read
the family's concrete format (a depth family's readable aspect, else its
main typed format). A view with no description at all is still refused.

From upstream PR Marvisak#970 (60222b3), adapted.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Thank you @Zipettte for verifying the test suite on AMD Radeon RX 7700 XT, and thank you @MichaelSmithAI for the hardware testing and valuable depth/stencil format notes on RTX 4090!

@Yaekai

Yaekai commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Code review of 60222b3 — the depth-vs-color mapping table in concrete_srv_format() is clean and avoids the DSV-format pitfall, but there are 3 edge cases worth fixing before merge:

  1. format == None on a typeless resource (crates/victory-gpu/src/descriptor/host.rs:609-617):
    When the title omits a view description (CreateShaderResourceView(tex, NULL, ...) / CreateUnorderedAccessView(tex, NULL, NULL, ...)), format is None (view == 0), so if let Some(format) = format is skipped and fits() still returns true. That lets make() pass None to D3D12 on a _TYPELESS resource, which is illegal in D3D12 (E_INVALIDARG / debug-layer error). Either return false when typeless && format.is_none() or synthesize a concrete D3D12_SHADER_RESOURCE_VIEW_DESC / D3D12_UNORDERED_ACCESS_VIEW_DESC (as in Xvania7/VIctory@2be93af).
  2. is_typeless(u32::MAX) overflow (crates/victory-gpu/src/resource.rs:278):
    family(format + 1) will overflow in debug builds if a malformed/guest format word is u32::MAX; format.checked_add(1).is_some_and(...) avoids it.
  3. R16_TYPELESS (53) color vs depth & UAVs:
    concrete_srv_format(53) unconditionally maps to R16_UNORM (56), which is right for ALLOW_DEPTH_STENCIL resources, whereas non-depth color R16_TYPELESS textures typically expect R16_FLOAT (54). Also, planar depth formats (21 / 46) are valid for SRVs but not for unordered == true (UAVs).

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Put together a follow-up commit stacked directly on 60222b3 addressing the review points above and verified with GPU pixel readbacks on RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1):

  1. Omitted pDesc (None) on typeless host textures: Synthesizes default_srv_desc / default_uav_desc from the host resource's dimension, mip count, and array/depth extent (seeded with view_format(resource) when widened from a typed console format), and returns false in fits if format is still None on a typeless resource so None never reaches D3D12 (E_INVALIDARG).
  2. is_typeless(u32::MAX) overflow: Uses format.checked_add(1).is_some_and(...).
  3. Aspect/usage-aware concrete_view_format(format, depth, unordered):
    • Maps R16_TYPELESS to R16_UNORM when ALLOW_DEPTH_STENCIL is set and R16_FLOAT for non-depth color/UAV resources (preserving explicit R16_UNORM views);
    • Translates explicit DSV formats (D32_FLOAT_S8X24_UINT, D32_FLOAT, D24_UNORM_S8_UINT, D16_UNORM) passed in SRV descriptors on typeless depth textures (#882);
    • Rejects planar depth/stencil, D16_UNORM, B8G8R8X8, and BC formats when unordered == true so unsupported UAVs fall back cleanly to null_for without device removal.

Synthetic cs_5_1 readbacks confirm 1.5 round-tripping through non-depth R16_TYPELESS null-desc UAV+SRV (R16_FLOAT), 0.5 on D16_UNORM-cleared R16_TYPELESS, and 0.75 on R24G8_TYPELESS via both null-desc and explicit D24_UNORM_S8_UINT SRVs with zero D3D12 debug errors. Feel free to cherry-pick: fuzeofficlal@3802a0a

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflict in crates/victory-gpu/src/descriptor/host.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: move default_srv_desc/default_uav_desc above the doc comment of fits, and keep refusing (or give evidence for the format) when the title's own typeless texture has no view description.


Generated by Claude Code

@pushkarreddyy
pushkarreddyy force-pushed the fix/gpu-typeless-srv-aspect-aware branch from 60222b3 to 0aab24a Compare November 25, 2026 01:47
@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto latest main (940d32f), resolving the conflict in crates/victory-gpu/src/descriptor/host.rs with merged PR #974. Also included the is_typeless(u32::MAX) overflow guard suggested by @Yaekai. Ready for maintainer review.

@pushkarreddyy
pushkarreddyy force-pushed the fix/gpu-typeless-srv-aspect-aware branch from 0aab24a to d782a7d Compare November 25, 2026 12:46
@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Updated and pushed commit d782a7d addressing all triage review points:

  1. Omitted view descriptions on typeless textures: Added synthesized default SRV/UAV descriptors (default_srv_desc / default_uav_desc), and ensured fits returns false if format remains None so null descriptions never reach D3D12.
  2. UAV format bounds & depth isolation: Introduced concrete_view_format(format, depth, unordered) which rejects planar depth/stencil formats (19..=21, 22, 44..=46, 47, 55, 88/92) and block-compressed formats when unordered == true.
  3. R16_TYPELESS handling: Dispatches based on ALLOW_DEPTH_STENCIL to R16_UNORM (56) for depth resources and R16_FLOAT (54) for color/UAVs.
  4. Clippy & CI: Cleaned up the nested conditional (collapsible_if), resolved bounds overflow with checked_add, and added comprehensive unit tests covering color, depth, UAVs, and format bounds.

Thank you to @fuzeofficlal and @Yaekai for the detailed review feedback and hardware test findings.

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Hi @Marvisak — all triage feedback points (default_srv_desc/default_uav_desc for omitted pDesc, fits returning false when format is None, UAV planar-depth/BC rejection, ALLOW_DEPTH_STENCIL-aware R16_TYPELESS resolution, and the Clippy fix) are resolved on d782a7d and CI (check) is passing. Ready for review and merge whenever convenient for #882 and #876!

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

If any testers on untested GPU models (such as NVIDIA RTX 30/40/50 series, AMD RDNA2/RDNA3/RDNA4, Intel Arc, or Linux/Wine/vkd3d-proton) can verify this build (d782a7d) in-title or with VICTORY_D3D12_DEBUG=1, test reports would be greatly appreciated!

AI-assisted: yes (Gemini 4 Neon)

@MichaelSmithAI

Copy link
Copy Markdown

I ran a guest command-list readback on d782a7d with an RTX 4090 (driver 615.78.8), Wine 11.22 and vkd3d-proton 3.2. A 1×1 guest RGBA8 sRGB texture had typeless host backing. A compute dispatch wrote red byte 128 through its linear UAV, and a second dispatch read the same texel through the SRV. The shader stored round(1000 × red). Each case ran in a fresh process.

View descriptions Expected PR head With the SRV change below
Omitted 216 216 216
Explicit 2D descriptions with Format = UNKNOWN 216 502 216

The omitted descriptor preserves the sRGB conversion. For an explicit UNKNOWN SRV, fits sees format 0 and chooses the host family's linear UNORM format. In the control I changed only the SRV path in make: before calling fits, if the descriptor format is 0 and resource::view_format(resource) is Some, copy that known guest format into the descriptor. The UAV path and shaders were identical. The authored format-table test passed in both builds.

This case starts with a known typed guest texture. It gives no evidence for choosing a format when the guest itself supplied a typeless resource. I set VICTORY_D3D12_DEBUG=1 on a diagnostics build; the evidence here is GPU readback, and I couldn't confirm a native debug layer was active under Wine. Synthetic textures and source-built shaders only. AI-assisted.

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

Projects

None yet

6 participants