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

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`.
mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 25, 2026
…nder targets are R8G8B8A8 where the GPU cannot render to them

Conflicts resolved against the upstream resync (f0df6a5): skip_mixed_packed_copy runs before the title_written upload in CopyResource and CopyTextureRegion; the footprint upload keeps defer_fill; texture staging keeps both the watch tracking and widened_from and uses footprint_len; fits() checks widened views before the castable rule; RENDER_TARGET defined where make_texture reads the clear value; both test sets kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 25, 2026
…er targets are R8G8B8A8 where the GPU cannot render to them

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

@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 081afbd ported onto our fork's main (upstream 70564ae plus our merges) on Windows 11, RTX 5070, MSVC: builds, clippy -D warnings clean with and without --all-features, and the diagnostics build compiles. cargo test --workspace --no-fail-fast: 716 passed. The 7 failures are the same 7 that fail on our main without this PR (stride, rect, gather4-at-a-level, row order, memory table, dynamic slots), so none comes from it. The 4 new tests pass on the hardware device:

  • packed_16_conversion_matches_dxgi_layout (including the exhaustive 65,536-value round trip);
  • target_format_is_identity_for_non_packed_formats;
  • packed_16_targets_copy_and_skip_mixed_transfers;
  • detile_widened_packed16_expands_into_rgba8_staging.

On reading:

  • Widening only when CheckFeatureSupport lacks RT or typed-UAV support (asked once per format) is the right gate. The RTX 5070 here is one of the cards that lacks them, and AMD keeps its native formats.
  • The format follows the texture everywhere it has to: creation, clear value, RTV and PSO formats, fits() for views, and resolves. The unpack layout (B in the low bits, bit replication) matches DXGI, and so does the decode.
  • The transfer paths raised in review are handled:
    • buffer-to-texture footprints are widened and expanded at submission;
    • title-written uploads are detiled tight and then expanded;
    • mixed native/widened GPU copies are skipped before any barrier or host_written, with one warning per format.

Things to know (not blockers):

  1. Precision differs from the console for B5G5R5A1/B4G4R4A4 targets. A shader writing alpha 0.3 into a B5G5R5A1 target now keeps 0.3 instead of 0, and colour channels keep 8 bits instead of 5 or 4. A later pass that reads the target (alpha tests, masks) can see different values. yuniskh's measurements show store-time quantization can match the native results, and that's worth a follow-up.
  2. Memory sharing in current upstream. Since the resync, host textures are shared by memory, and takes requires the format family or the castable list to match. If the title later describes the same memory as a sampled-only 86/115 texture, it gets a separate host texture instead of the widened one, with no sync between them. Same class as the skipped mixed copies, just through aliasing.
  3. Readback (RGBA8 to packed) is implemented but unused until texture-to-buffer copies land, as the PR says.

Porting notes for upstream (this conflicts with current main):

  • In CopyResource/CopyTextureRegion, skip_mixed_packed_copy has to run before the new title_written upload.
  • The footprint upload should keep defer_fill (the Wine fix) instead of defer_copy.
  • Texture staging keeps both tracked and widened_from, and footprint_len already covers the widened slice length.
  • fits() checks the widened view before the new castable rule.
  • RENDER_TARGET must be defined where make_texture now reads the clear value.

Merged into our fork's main as a port.

AI-assisted (Claude Code).

@JurajSimicevic

Copy link
Copy Markdown

@HenriqueSBueno, both commits of this PR on today's main (ccfb029), you as the author, in case it saves you the rebase: https://github.com/JurajSimicevic/VIctory/tree/port/packed-16-targets-89 (use it or ignore it). It follows the porting notes in mercuryVM's review above point for point; the second commit's message lists them.

Checks on an RTX 5080 (driver 32.0.16.1742): both clippy configurations clean; cargo test -p victory-gpu 143 passed, 2 failed (the HEAP_VIEWS tests that fail on main too, #1751); the four new tests pass on the hardware device.

In the game (diag, DRED; one run without and one with the debug layer), main + this PR only, no typed-UAV fix:

AI-assisted.

@RDGzin7 RDGzin7 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.

RTX 3050 8GB – PR #89 reaches intro cutscene, crashes before gameplay

Hi! I tested PR #89 on my PC, and the results were impressive!

My specs:

  • GPU: NVIDIA RTX 3050 8GB
  • CPU: AMD Ryzen 5 5600GT
  • RAM: 16GB DDR4
  • OS: Windows 11 (Build 26200)
  • VIctory: PR #89, commit 081afbd
  • Build: Diagnostics enabled

Results:

  • The previous B5G5R5A1_UNORM error was resolved.
  • The game successfully displayed its menus.
  • I reached the opening cutscene.
  • When transitioning into gameplay, the GPU crashed.

Error:
DXGI_ERROR_DEVICE_HUNG (0x887A0006)

D3D12 debugging and DRED were enabled.

This is a huge improvement over the previous build, which crashed before displaying the menus.

I've attached a screenshot of the error. Hopefully this helps with further NVIDIA compatibility improvements!

Thanks for your work!
(Report written with AI assistance. All hardware specifications and test results are from my own testing)

VIctory-PR89-diagnostico.txt

@Venom2054

Copy link
Copy Markdown

Tested a locally adapted version of 081afbd5382bb6aabaec5b28864c11cf00a15725 on RTX 5070 Ti 16 GB, NVIDIA 621.01, Windows 11 Pro 26200, i7-14700, 32 GB RAM.

Base: main 940d32f69b22265690a0b5a15d6ded572ba33baf, with these pre-existing changes:

Before #89, format 115 still failed to create its 2560x1440 host render target. After #89, both 86 and 115 logged RGBA8 widening, with zero no host texture messages. No mixed packed-copy skip messages appeared in this run.

With D3D12 debug enabled, the title reached ongoing 3D intro rendering and was manually stopped after 300.4 seconds, without reported device removal. No pipeline skips or reduced loop limit; GPU timing off. The preceding integration already survived a 321.1-second run, so I am not attributing improved stability to #89.

Rendering remains badly malformed/dark/overexposed at roughly 0.5–0.65 seconds per frame. There were 171 distinct refused host pipeline records; remaining D3D12 errors include Wave64 requested on a 32-lane device (ID 622), blending on R8_UINT (676), and resource-state mismatches (527/538). This is not a validation-clean or playable run.

Validation:

  • GPU suite with D3D12 debug: 157 passed, 0 failed, 3 ignored, including conversion, detile/upload and GPU readback tests.
  • Explicit ignored UAV hardware test: 1 passed.
  • Full workspace: 719 passed, 0 failed, 11 ignored (nested subprocess result excluded).
  • Build, all-target/all-feature Clippy with -D warnings, and asset policy: passed.

Adapting to newer main preserved castable-format and typed-UAV checks, tracked texture uploads, staging bounds and defer_fill. The render-target flag constant was moved to shared scope for host_desc/make_texture, and the old ignored UAV test now checks the effective host format. These results concern that adapted integration, not the unmodified PR head.

No game assets or raw dumps attached. Integration and testing were assisted by OpenAI Codex; credit for the upstream changes remains with their authors.

Venom

@artor410

Copy link
Copy Markdown
Contributor

Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main 13f91ca. Does not merge into main (conflicts), so only the head 081afbd was tested.

(Claude Code, Claude Opus 5.5.)

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.