Skip to content

gpu: widen unsupported 16-bit render targets and UAVs to R8G8B8A8_UNORM - #2767

Open
narishaa wants to merge 1 commit into
Marvisak:mainfrom
narishaa:fix/nvidia-packed-16bit-targets
Open

narishaa wants to merge 1 commit into
Marvisak:mainfrom
narishaa:fix/nvidia-packed-16bit-targets

Conversation

@narishaa

@narishaa narishaa commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

Rebased adaptation onto main (13f91ca) of #89 (by @HenriqueSBueno, currently marked triage: needs rebase), addressing the DXGI_ERROR_INVALID_CALL (0x887A0001) device removal on NVIDIA GPUs reported in #2725 and #1753.

On NVIDIA (tested on RTX 3050, driver 32.0.16.2101), B4G4R4A4_UNORM (115) fails render-target creation and B5G5R5A1_UNORM (86) fails typed UAV creation/allocation queries:

  • CreateCommittedResource3 / CreateCommittedResource: D3D12_CLEAR_VALUE::Format / D3D12_RESOURCE_DESC::Format is B4G4R4A4_UNORM (id=817, id=599)
  • GetResourceAllocationInfo / CreateUnorderedAccessView: B5G5R5A1_UNORM (0x56) does not support typed UAVs (id=599, id=342)

Changes

  • Query CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT) once per packed 16-bit format (86, 115) via resource::target_format, widening render-target and unordered-access textures (and their clear values, RTVs, pipeline RT formats, and ResolveSubresource formats) to R8G8B8A8_UNORM (28) when unsupported. Sampled-only textures keep their native format.
  • Re-apply target_format in shared_texture after merging flags from aliased title textures at the same address so a sampled texture promoted to RENDER_TARGET/UNORDERED does not keep format 115/86.
  • Update descriptor::host::fits and resource::view_format so views of widened targets resolve to R8G8B8A8_UNORM.
  • Widen packed 16-bit buffer-to-texture CopyTextureRegion uploads in prepare_footprint_upload (while preserving list.defer_fill for unchanged footprints) and skip mixed packed/widened GPU-to-GPU copies/resolves.
  • Add unit tests for B5G5R5A1_UNORM / B4G4R4A4_UNORM row expansion.

Verification

Tested on Windows 10 (build 26200), Intel Core i7-9700KF, NVIDIA GeForce RTX 3050 (driver 32.0.16.2101), diagnostics build with VICTORY_D3D12_DEBUG=1:

  • Before (13f91ca): host GPU device removed (0x887A0001) ~12 s after the heap loop at frame ~52 with the 4 D3D12 errors above.
  • After: Both formats log packed 16-bit render targets are R8G8B8A8_UNORM on this GPU; title boots and runs past frame 1,024 at ~30 fps with zero no host texture or RemoveDevice errors.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass
  • cargo xtask policy: pass (184 files ok)
  • cargo test -p victory-gpu --locked: 194 passed, 2 failed (the pre-existing NVIDIA 1,000,000-view heap-cap assertions dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views from NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835), 1 ignored.

Related: #2725, #1753, #89.

@narishaa
narishaa force-pushed the fix/nvidia-packed-16bit-targets branch from b437a17 to f307c7f Compare November 25, 2026 20:10
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and tested f307c7fc on Windows 11 + NVIDIA GeForce RTX 5090 + WARP against main (13f91ca).

Hardware check & code review

On RTX 5090, B5G5R5A1_UNORM (86) reports RT = true, UAV = false and B4G4R4A4_UNORM (115) reports RT = false, UAV = false, so both hit the widening path to R8G8B8A8_UNORM (28) when RENDER_TARGET | UNORDERED is set (prepare_footprint_upload, expand_packed16_rows, descriptor::host::fits, RtvRecord, PSO RTFormats, clear values, and ResolveSubresource format all line up cleanly).

Three remaining gaps worth noting on mixed widened/native paths:

  1. read_back (list.rs:941-980): copying from a widened R8G8B8A8_UNORM target back to a 115/86 (2-byte/texel) FOOTPRINT buffer still issues a direct CopyTextureRegion with mismatched texture/footprint formats (28 vs 115/86), which D3D12 rejects.
  2. alias_copy (texture.rs:253-332): alias_source (resource.rs:1974) compares guest r.desc element sizes (both (2, 1)), so copying between a widened target (28, 4B/texel) and a native 16-bit sampled alias (115/86, 2B/texel) copies through a 2B/texel footprint and corrupts data/dimensions.
  3. Mixed texture copies/resolves (skip_mixed_packed_copy) & B5G5R5A1 RT-only: CopyResource / CopyTextureRegion / ResolveSubresource between a native 16-bit sampled texture and a widened 28 target are silently dropped; and because host_lacks_target requires both RENDER_TARGET and TYPED_UNORDERED_ACCESS_VIEW, even RT-only B5G5R5A1 textures are widened on RTX 5090 despite native RT support (compare #89 for companion/compute conversion on mixed copies).

Verification (Windows 11, RTX 5090 + WARP)

  • RTX 5090 (--features diagnostics): resource::tests 18/18 passed (including packed_16_expansion_matches_dxgi_layout); full --test-threads=1 197 passed, 2 failed (only the 2 pre-existing RTX 5090 >1M heap-cap baselines).
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics --test-threads=1): 199 passed, 0 failed, 1 ignored.
  • cargo clippy (default & diagnostics): 0 warnings; cargo xtask policy: 184 files ok.
  • Merge-tree: clean vs 13f91ca and #2773 (semantically mutually exclusive); conflicts with #89 and #2679.

@kotekompotek

Copy link
Copy Markdown

Correct bit-replication expansion (5->8 as v<<3|v>>2, 4->8 as v<<4|v, A1 -> 0/255) and the widening is applied at every seam that names a format: RTV record, view fits(), resolve formats, and both copy entry points guarded by skip_mixed_packed_copy for cross-element cases. Relates to #2442 (which drops UNORDERED on unviewable formats): this widens 86/115 to RGBA8 so the views become legal - complementary, and once both land the flag survives where it can.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent WARP/CPU verification of f307c7fc (#2767).

Review: Packed 16-bit render targets and UAVs become R8G8B8A8_UNORM only where the host lacks support (host_lacks_target, queried once per format). The change is applied consistently in host_desc, shared_texture, clear values, RTVs, pipeline RT formats, view-format checks, and resolve. Copies mixing a native packed texture with a widened one are skipped with a once-only warning. Buffer-to-texture footprint copies expand texels on the CPU into a widened upload buffer with a 256-byte pitch. The bit replication for B5G5R5A1 and B4G4R4A4 is right (hand-checked 0xffff and the mixed value). Two notes, neither blocking:

  • A source comment in resource.rs names the specific title. Coordinating who works on what #1633 rule 7 is about files, dumps, shader names and hashes, so this is probably fine, but you may prefer a generic wording.
  • The tests only cover the CPU expansion. Nothing exercises the widened upload path, the format-selection logic or the mixed-copy skip. On this WARP setup I did not confirm that host_lacks_target ever returns true, so the GPU-side behaviour is unverified here and needs a GPU that lacks the formats.

Results (WARP/CPU):

  • origin/main: cargo test -p victory-gpu --lib: 195 passed, 0 failed.
  • PR: 196 passed, 0 failed.
  • cargo clippy --locked -p victory-gpu --all-targets [--all-features] -- -D warnings: clean. cargo test -p xtask (policy): 6 passed.

Negative control (mutating the PR head): removing the bit replication for the 5-bit channels, or the alpha replication in the 4-bit format, makes packed_16_expansion_matches_dxgi_layout fail. The expansion test catches those.

Method: no physical GPU. VICTORY_WARP=1, VICTORY_D3D12_WARP=1, Windows SDK 10.0.26100 dxil.dll on PATH, Windows 11, rustc 1.98.1 MSVC, --locked. Compared origin/main (13f91ca) with the PR head. The PR merges cleanly onto that main. No game files, dumps, shader names or retail hashes were used or are needed.

AI disclosure: this verification was done by Claude Code / Claude Sonnet 5.5.

@artor410

Copy link
Copy Markdown
Contributor

Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main 13f91ca. Head f307c7f (fast-forward on main).

  • cargo test -p victory-gpu (main: 193 passed, 2 failed: the known heap-cap pair dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). With this PR: 194 passed, same 2 failed. New packed_16_expansion_matches_dxgi_layout passes.
  • Probe (temporary test, not committed): 256x256 texture via create_placed with the UAV and/or RT flag, then descriptor::host::make_view(View::Unordered(..)) and Host::rtv(texture, None), then GetDeviceRemovedReason, one process per case. On main: UAV view of 86 or 115 crashes the test process (0xc0000005 inside the driver); RTV of 115 removes the device (0x887A0001); 115 with RT|UAV gets no host texture. CheckFeatureSupport here: 86 RT yes, typed UAV no; 115 RT no, typed UAV no.
  • With this PR: every case safe and the views are made. 86 and 115 textures become R8G8B8A8 (28); UAV views made for 86 (UAV, RT|UAV) and 115 (RT|UAV); RTVs of 115 made; device not removed.

Covers both formats and both uses, and keeps the writes. Same approach as #89 and as the VItoriaBr fork, which reaches the world on an RTX 5060 Ti. Probe calls Host::rtv directly, not set_targets; untested in-game here.

(Claude Code, Claude Opus 5.5.)

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The approach is sound and well evidenced (debug-layer errors and CheckFeatureSupport results on NVIDIA, plus hardware reports in the thread): resource::target_format widens B5G5R5A1/B4G4R4A4 render-target and UAV textures to R8G8B8A8_UNORM where the GPU lacks the support, and the format is applied consistently in host_desc, shared_texture, clear values, RtvRecord::host_desc, pipeline RT formats, descriptor::host::fits and resolve. Buffer-to-texture copies are expanded in list.rs prepare_footprint_upload, and the bit replication in unpack_16 is right. Some paths that now reach a widened texture still assume 2 bytes per texel:

  • list.rs read_back: a texture-to-footprint copy from a widened texture into a B5G5R5A1/B4G4R4A4 footprint calls CopyTextureRegion with a 4-byte texture and a 2-byte footprint format. D3D12 rejects that, so it needs packing on the way back or a refusal.
  • texture.rs staging/upload: footprints come from the host description (RGBA8) while the detiled title memory is 2 bytes per texel, so a title-written widened texture would be uploaded with the wrong layout.
  • texture.rs alias_copy (via resource::alias_source) compares the guest element sizes, which are equal, so a widened target and a native sampled alias of the same memory are copied as if they had the same layout.
  • host_lacks_target widens when either support bit is missing, so on NVIDIA a B5G5R5A1 texture that is only a render target is widened even though the GPU renders to it natively. Checking only the support each texture's flags need would keep more textures native.

This also overlaps #89 (the original of this change, credited in the description) and takes a different approach from #2773 (drop the uses the device refuses). A maintainer should choose one direction. Minor: the host_lacks_target doc comment could describe the targets generically. CI (check) passes. Handling or explicitly refusing the three copy paths above would make this a merge candidate.


Generated by Claude Code

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.

6 participants