Skip to content

gpu: packed 16-bit render targets are R8G8B8A8 where the GPU cannot render to them - #89

Open
HenriqueSBueno wants to merge 2 commits into
Marvisak:mainfrom
HenriqueSBueno:nvidia-packed-targets
Open

HenriqueSBueno wants to merge 2 commits into
Marvisak:mainfrom
HenriqueSBueno:nvidia-packed-targets

Conversation

@HenriqueSBueno

@HenriqueSBueno HenriqueSBueno commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

On a GPU that can't render to the console's packed 16-bit colour formats, or can't write them as typed UAVs, render-target and unordered-access textures in those formats are made as R8G8B8A8_UNORM. The formats are B5G5R5A1_UNORM (86) and B4G4R4A4_UNORM (115). Textures that are only sampled keep their format.

Why

On NVIDIA (RTX 3080, driver 616.92) the title asks for two 2560x1440 targets the driver refuses:

WARN victory_gpu::resource: no host texture error=E_INVALIDARG ... format: 86, ... flags: 5
WARN victory_gpu::resource: no host texture error=E_INVALIDARG ... format: 115, ... flags: 1

NVIDIA has no render-target support for B4G4R4A4 and no typed UAV for B5G5R5A1. AMD has both, so this doesn't show on an RX 6700 XT.

How

  • resource::target_format stands the R8G8B8A8_UNORM format in for 86/115. It applies only when CheckFeatureSupport(FORMAT_SUPPORT) lacks RENDER_TARGET or TYPED_UNORDERED_ACCESS_VIEW, asked once per format, so AMD keeps the native formats. Each channel keeps its value, with more precision.
  • Texture creation: a texture with render-target or unordered access uses target_format, and so does its optimized clear value.
  • Render-target views and pipeline RTV formats use target_format, so views, PSOs and resources agree.
  • fits: a shader-resource or unordered-access view naming 86/115 on such a texture takes the texture's format.

Tested

Windows 11, RTX 3080 (NVIDIA 616.92), i5-10400F:

  • cargo test -p victory-gpu: 39 pass. cargo clippy -p victory-gpu: clean. cargo xtask policy: ok.
  • Before: the two warnings above.
  • After: the log says packed 16-bit render targets are R8G8B8A8_UNORM on this GPU for format 86 and format 115, and there are no no host texture warnings.
  • The menus look the same with and without this change. I compared captured frames up to the account prompt and the legal screens, so the textures matter later. Untested on AMD; there the feature check keeps the old path.

AI-assisted (Claude Code)

@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Confirmed the two allocation cases on an RTX 3060 Ti, Windows 10 22H2, NVIDIA 610.88. A synthetic hardware test of the patch created both 2560×1440 resources with the original flags and optimized clear values. Guest format 86 (flags 5) and 115 (flags 1) both became host format 28. Sampled-only textures retained their packed formats.

One integration detail for transfers: a guest buffer footprint in either packed format still describes two bytes per pixel. Directly forwarding that footprint to a widened RGBA8 texture, or copying between a sampled-only packed texture and a widened render target, can record incompatible host copies. Resolves between widened targets also need the effective host format. In the downstream test we allowed transfers with matching representations and declined unsupported mixed transfers before recording barriers or marking the destination written.

This was a native resource test. It did not run the title or establish an effect on the world hang. AI-assisted with Codex.

@lordon1a

Copy link
Copy Markdown
Contributor

Verified 85ea36da5 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@35b054ec0): pass (no regression on host D3D12).

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-gpu: 39 passed, 0 failed.

AI-assisted.

@DaviTostes

Copy link
Copy Markdown

Tested da580e4 under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with cargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.

  • victory_gpu: 36 passed, 3 failed — the same three environment-only failures as main (argument_clamp_builds, a_rejected_blob_gives_an_empty_library, Wine/vkd3d: deferred uploads are skipped because VirtualQuery() reports mapped memory as MEM_FREE #128's VirtualQuery upload skip).
  • The diff adds no test, so this only shows nothing else broke. vkd3d-proton does honour the feature-level check this PR relies on for the fallback, so a synthetic case that creates a packed 16-bit target and queries the fallback format would be worth adding.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

…argets

- Buffer-to-texture CopyTextureRegion: widen packed 16-bit (86/115) placed footprints to R8G8B8A8_UNORM and expand texels on the CPU at submission (packed <-> RGBA8 helpers and unit tests added for uploads and readbacks).
- texture::upload: detile widened packed 16-bit textures into a tight 2-byte buffer before expanding rows into the 4-byte host staging footprint.
- GPU-to-GPU CopyResource, CopyTextureRegion, and ResolveSubresource: skip mixed native-packed <-> widened copies once per format before barriers or host_written, and map resolve formats through target_format.
- view_format: return None for typed widened targets so null view descriptions inherit the host resource dimension.

AI-assisted (Claude Code)
@HenriqueSBueno

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews and the numbers on three more cards. 081afbd covers the transfer paths @ifBars and @martingouv pointed out:

  • Buffer-to-texture CopyTextureRegion into a widened target: the 2-byte footprint becomes an R8G8B8A8 footprint (row pitch rounded to 256). The texels are expanded on the CPU at submission.
  • texture::upload: a widened texture is detiled into a tight 2-byte buffer, then expanded row by row into the 4-byte staging footprint.
  • GPU copies and resolves: CopyResource, texture-to-texture CopyTextureRegion and resolves between a native packed texture and a widened one are skipped. Each format logs one warning, and the skip happens before any barrier or host_written, so no invalid host command is recorded. Resolves between two widened targets use target_format.
  • Conversion: B5G5R5A1 is B in bits 0–4, G 5–9, R 10–14, A bit 15. B4G4R4A4 is 4 bits each, B to A from the low bits. Channels are expanded by bit replication.
  • Tests:
    • an exhaustive round trip over all 65,536 values of both formats;
    • bit layouts and pitched rows;
    • target_format is the identity for other formats;
    • detiling a widened texture into RGBA8 staging;
    • a host-GPU test that the copies run, or are skipped where the formats are mixed.
  • Not wired: the readback direction (RGBA8 to packed, for texture-to-buffer copies) is implemented and tested but not used yet. It's for when GPU: implement CopyTextureRegion texture-to-buffer readbacks #67 lands; until then texture-to-buffer copies return early on main as before.

Checks on Windows 11, RTX 3080 (616.92): cargo test -p victory-gpu 43 passed, cargo clippy -p victory-gpu --all-targets clean, cargo xtask policy ok.

AI-assisted (Claude Code)

@yuniskh

yuniskh commented Nov 24, 2026 •

Copy link
Copy Markdown

I tested the packed texture fallback on a desktop RTX 5090 (621.24) and the integrated AMD Radeon GPU in the same PC. This builds on martingouv's note about one-bit alpha.

The 5090 can't write formats 86 and 115 as typed UAVs, but the AMD GPU can. I compared the actual AMD writes against a widened RGBA8 shader running on the 5090. Rounding at each store and using the nearest expanded byte on the dependent read matched all 262,144 packed results across both formats. A different rule matched native format 86 render-target draws on the 5090. Overlapping triangles showed why converting only after a draw can still give wrong colors.

For format 115 unblended draws, two inputs could become the same RTX byte but different native AMD packed values. I tried correcting the original shader output before storing it to RGBA8. That matched all 196,608 pixels across two random input sets and a rounding-boundary test.

The ZIP has the shaders, a standalone GPU-to-packed-buffer readback prototype, raw logs and separate texture-layout patches. The patches apply to main at d2a4bae and PR #89 at 081afbd. All 17 standalone test programs passed locally. I haven't compiled the patched VIctory crate or tested gameplay.

AI-assisted with Codex.

VIctory-RTX5090-graphics-tests.zip

Complete outputs folder — includes the DirectX test report, the project test results, and the graphics-test package linked above.

VIctory-complete-outputs.zip

@miniongk

Copy link
Copy Markdown

Tested 081afbd applied onto #320 (a5ba4a4) plus #483 (65a161d) on an RTX 5080, driver 621.24, Windows 11 26300, with a local Xbox Series 1.0.2.1 copy.

  • cargo test --workspace: 286 passed, 0 failed, 4 ignored.
  • The two packed-format host-texture creation failures present before this patch became zero; the expected compatibility substitutions were logged for both formats.
  • The world still ends in DXGI_ERROR_DEVICE_HUNG. In this run DRED implicated mesh dispatch, with no indirect-execution stop recorded.

This confirms the texture compatibility work on the real title path, but not a fix for #97. Only aggregate counts and error classes shared. AI-assisted (Kimi Code).

@NuraadGit

Copy link
Copy Markdown

Two corrections to my comment above.

  1. "NVIDIA has neither for 86" is wrong. My own log says so: the fallback dropped only the UAV use of the B5G5R5A1 texture (flags: 5, dropped=4) and kept the render target. That matches @martingouv's and @fuzeofficlal's CheckFeatureSupport results for 86 (render target yes, typed UAV no).
  2. The UAV case I asked for is already in this PR: target_format covers a format whose typed UAV is missing.

What the measurement does say about @fuzeofficlal's case (an RTV-only 86 is widened without need): these are the only two textures the host refuses in my RTX 2080 world run.

format size flags refused use
115 B4G4R4A4_UNORM 2560x1440 RT RT
86 B5G5R5A1_UNORM 2560x1440 RT + UAV UAV

So choosing by use (widen 86 only when it also needs the UAV, and 115 when it needs the RT) covers both refused textures. My log only names refused textures, so it can't say whether the title also makes an RTV-only 86.

AI-assisted (Claude Code): the runs and log analysis were automated. The hardware, title copy and runs are the user's.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Rebased and extended this work on top of current main (ffe310e) in fuzeofficlal/VIctory (fix/packed-16-targets) (head 15124e9).

Summary of Changes

  1. Usage- & MSAA-aware format selection + lazy PSO variants:
    • Query D3D12_FEATURE_FORMAT_SUPPORT (RENDER_TARGET, TYPED_UNORDERED_ACCESS_VIEW, UAV_TYPED_STORE) and D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS so DXGI_FORMAT_B5G5R5A1_UNORM (86) and DXGI_FORMAT_B4G4R4A4_UNORM (115) remain native where supported (e.g., 86 RTV-only/MSAA on RTX 5090, and native 86/115 on AMD/WARP) and widen to RGBA8_UNORM (28) only when required by the requested usage or sample count.
    • Track widened render targets per graphics state and lazily cache per-physical-format RTV PSO variants while preserving is_skipped and bind() -> bool.
  2. Same-command-list GPU compute pack/unpack & MSAA resolve (packed_copy.rs, list.rs):
    • Added packed_copy.rs (cs_5_1 with an inline root signature and odd-width 4-byte alignment) for bidirectional 86/115 <-> RGBA8_UNORM conversion on the same command list across CopyResource, CopyTextureRegion (including source_box, offsets, mips, arrays, and 3D slices), and mixed-format ResolveSubresource / ResolveSubresourceRegion (1-mip/1-slice RESOLVE_DEST temporary target -> COPY_SOURCE barrier -> packed_copy::record_region, with no redundant destination barrier).
    • Resolved the list.rs rebase conflicts against main, preserving defer_fill in prepare_footprint_upload, title_written uploads before packed_transfer, and host_written tracking.
  3. Synthetic verification:
    • Added synthetic pixel-readback tests covering bidirectional CopyResource roundtrips, CopyTextureRegion with source_box and neighbor preservation, RTV PSO variant switching, and mixed-format MSAA resolves (capability-gated on native vs widened adapters).

Verification Results

  • cargo xtask policy: pass (155 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): 0 warnings
  • cargo test --workspace --locked: 351 passed, 0 failed, 6 ignored
  • Synthetic packed/resolve suite with VICTORY_D3D12_DEBUG=1 (--features diagnostics, 0 debug-layer errors):
    • NVIDIA GeForce RTX 5090: 9 passed, 0 failed (86 native RTV/MSAA + 86 UAV/115 widened)
    • AMD Radeon integrated graphics: 9 passed, 0 failed (native 86/115 + MSAA)
    • D3D12 WARP (VICTORY_D3D12_WARP=1): 9 passed, 0 failed

Branch compare link for review / cherry-pick:
main...fuzeofficlal:VIctory:fix/packed-16-targets

@jeremygold02

Copy link
Copy Markdown
Contributor

I verified the guest texture-to-buffer case raised above on a physical RTX 5070. The local integration uses this PR at 081afbd5 with #67 and #137. Both guest formats (86 and 115) had actual RGBA8 host textures on this adapter.

I uploaded a nonuniform 4×4 array of 16-bit texels and copied it back through the guest CopyTextureRegion entry point. For each format, a whole-surface copy matched all 16 original texels. An interior 2×2 box copied to (2, 1) in a larger footprint with a 32-byte offset and 16-byte row pitch also matched. I compared the complete destination buffer, including the sentinel in its padding and untouched pixels.

The integration checks the guest source format against the packed destination and reads the actual host texture format. D3D12 gets an RGBA8 staging footprint. After the queue completes, the existing pack_rgba8_to_16 helper packs only the copied texels in each row, retaining the guest pitch and write notifications. The existing unconverted readback test passed alongside the new coverage. This was a synthetic round trip using the open PR head, with no mission test of this change.

fornorharry pushed a commit to NitricAcidDev/VIctory-Omega-Fork that referenced this pull request Nov 24, 2026
# Conflicts:
#	crates/victory-gpu/src/list.rs
cyudev added a commit to cyudev/VIctory that referenced this pull request Nov 24, 2026
…izing

Marvisak#89 (open since before this PR) already makes packed 16-bit render
targets R8G8B8A8 where the host cannot render to them or store to them,
and converts copies instead of skipping them. In the title on an RTX 3060
Ti, a tree with Marvisak#89 creates both 2560x1440 targets (no `no host texture`).
This PR now only sizes the capped view heap to the host's limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omeyasawant

omeyasawant commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Independent integration test of both packed-target commits through 081afbd5382bb6aabaec5b28864c11cf00a15725 on an RTX 5090.

Why this was tested
On this host, dropping unsupported resource flags alone lets video render but later world submissions hit D3D12 messages 36 (B4G4R4A4 cannot be an RTV on this driver) and 42 (resource lacks RENDER_TARGET), followed by DXGI_ERROR_INVALID_CALL. This reproduces the need to keep resource, view and pipeline formats consistent rather than only dropping flags.

Integration and tests

Limits
This tests a combination of pending fixes, not a clean A/B of this PR alone. No working world or controllable gameplay is verified; further runtime testing is ongoing. AMD/Intel execution was not tested. This is evidence of build/test compatibility and observed promotion, not a claim that all rendering problems are fixed.

AI assistance: OpenAI Codex resolved the integration conflicts, ran checks and drafted this report at the account owner's request. Exact runtime model identifier unavailable.

Runtime-measurement correction: A subsequent idle-GPU check, after the title exited, found a competing local CUDA workload with GPU utilization near 98% and about 31 GB of the 32 GB VRAM occupied. The game runs above were not performed with GPU resources isolated. Their FPS, presentation counts and memory/latency observations must not be treated as clean performance benchmarks or evidence of a project-specific stall. The reported test pass/fail counts are the actual observed results; the explicit texture-format/debug-layer errors and local frame-content observations are still observations, but causality of remaining slowdowns/crashes is not established. A clean rerun is needed. No details of the unrelated workload are included.

1984742628 added a commit to 1984742628/VIctory that referenced this pull request Nov 24, 2026
… PresentX planes

Merges https://github.com/fxceless/victory-fork (main, 4e17478) into this
fork. The two rewrote the same GPU and shader code (20 files, 80 conflicts),
so the merged tree is fxceless's tree, with two additions it does not have,
re-applied on top:

- The FidelityFX upscaler answered by AMD's PC FidelityFX SDK when
  VICTORY_FFX_DIR is set (the pc-fsr branch, f96ad82): applied unchanged.
- PR Marvisak#211's multi-plane PresentX compositing (Series S menus): several
  planes are composited in a list of their own; a single plane keeps
  fxceless's present path, including presents sent ahead.

Dropped in favour of fxceless's own implementations: this fork's lazy host
textures and VRAM report, bounds root constants, rectangle geometry shader,
mesh index/position changes, the diagnostics switches added with them, and
PRs Marvisak#89, Marvisak#492 and Marvisak#578 (fxceless has its own target formats and wave64
handling; Marvisak#578 refused every wave64 compute program on 32-lane GPUs). That
work stays reachable on the try/pr-211-578 branch at 575a4ee.

Builds with and without the diagnostics feature; the workspace tests pass.
Not run in the game yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/texture.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

arnoudstorm pushed a commit to arnoudstorm/VIctory that referenced this pull request Nov 25, 2026
arnoudstorm pushed a commit to arnoudstorm/VIctory that referenced this pull request Nov 25, 2026
Marvisak#168, Marvisak#89)

Under `VICTORY_LATE_WAIT` and `VICTORY_RELAY`, `Shadow::stale_under_writes`
and `Shadow::merge_under_writes` (`crates/victory-gpu/src/shadow.rs`) only
iterated pages returned by the write-watch delta (`written`). Any page inside
a pending shader `GpuWrite` range whose `copied` timestamp was still `0`
(never copied into the host copy yet) and that did not appear in `written`
was silently skipped, leaving it zeroed on the GPU while `Shadow::update`
also skipped the pending range.

Mirror `Shadow::copy_stale` by extracting `stale_pages_in` and scanning every
page in `[a, e)` for `copied == 0 || write > copied` in both
`stale_under_writes` and `merge_under_writes`. Add
`shadow::relay_tests::stale_pages_include_uncopied_pages_absent_from_write_watch`.
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.