Skip to content

GPU: the console's packed 4-bit colour target stands in as B5G5R5A1 - #2332

Open
fiestorra wants to merge 4 commits into
Marvisak:mainfrom
fiestorra:gpu/b4g4r4a4-stands-in
Open

fiestorra wants to merge 4 commits into
Marvisak:mainfrom
fiestorra:gpu/b4g4r4a4-stands-in

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

The console's packed 4-bit colour target has no PC render target on NVIDIA; it stands in as the same two bytes

Format 115 (B4G4R4A4_UNORM) is what the title asks for its 2560×1440 target, and NVIDIA reports it as a render target and then refuses the view — an illegal call that removes the device (issue #1952, with the debug layer naming it). pc_format maps the console's 16-bit depth formats (118/119/120) to PC ones and leaves everything else alone, so 115 reached the host as itself.

Change: pc_format(115) = 86 (B5G5R5A1_UNORM), and the choice is not aesthetic:

  • same element size — two bytes per texel both, so no ladder step, no copy size and no footprint changes. The obvious alternative, R8G8B8A8_UNORM (28), would double the resource and every copy of it;
  • a format PC does take as a target, which is the thing that was killing the run;
  • the mapping is applied by every path that names the format — host_desc, view_format, the descriptor tables, the twin path, the pipeline's render-target formats — because they all call pc_format, so the stand-in cannot be applied to the resource but not to a view of it (which would move the illegal call to the sampling view instead of removing it).

The cost, stated plainly: the title writes 4-4-4-4 and reads 5-5-5-1, so colours through that target are reinterpreted. A shifted picture instead of no picture, and the step to take before R8G8B8A8 precision would be needed. If 86 ever turns out to be refused on another vendor, 85 (B5G6R5_UNORM) is the next two-byte candidate.

Measured (RTX 4090, 32.0.16.2124, diag build with the debug layer, session 1, empty cache, 330 s, this change with #1630 + #1832 + #1778):

no host texture                  0        (before: 1, the 2560x1440 format 115 target)
CreateRenderTargetView   …        0 layer errors
RemoveDevice             …        0
GPU failure                       0
last frame presented              frame=8192 draws=53248

So the target is created, the illegal call is gone, and the run survives to 8,192 frames. What is not verified: that the world now draws. The run stayed on the setup screens (no keys scripted), and "the world is no longer black" is a claim I am not making — it needs a run that reaches the world, which is the next measurement.

No game data is involved: format numbers, counts and log text.

Written with an AI assistant.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

B4G4R4A4_UNORM stands in as B5G5R5A1_UNORM on hosts where NVIDIA's view creation removes the device (#1952); colors shift rather than vanish. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same #1952 cluster as #2305/#2319.

@JAEdotUK

Copy link
Copy Markdown

Tested on Windows 11 with an AMD RX 9070 XT — cargo test --workspace (including victory-gpu and victory-shader) compiled cleanly and passed with 0 failures!

@steven-seagull27

Copy link
Copy Markdown

Tested the format-86 fallback on an RTX 5080 (621.40) and built-in Microsoft WARP (10.0.26100.10068), Windows 11 build 26300.10075. On 0e350ab1 both adapters created the 5-5-5-1 render target, cleared a 4×4 grid to 16 known colors, and read all 16 pixels back through a shader. The D3D12 debug layer reported no errors in that test.

4×4 test RTX 5080 pixels differing from the original RGBA4 colors WARP pixels differing
Parent 940d32f6, upload the packed words and sample format 115 0/16 0/16
PR, upload the same words and sample format 86 14/16 14/16
PR, clear format 86 to the original colors and sample it 11/16 11/16
RGBA8 control, either revision 0/16 0/16

Alpha changed in 10/16 pixels on each adapter in both format-86 cases. The distinction between uploaded bytes and rendered colors is visible on 0xFF00. The original word was opaque red. Reinterpreting it on the PR gave (1, 0.7765, 0, 1) on RTX and (1, 0.7742, 0, 1) on WARP. Clearing the fallback target to opaque red still produced exact red on both.

For anyone adding a test, all 16 cleared pixels on WARP matched the 5-bit RGB code divided by 31. The RTX readbacks matched expanding each 5-bit code to 8 bits with (n << 3) | (n >> 2) and dividing by 255. That small precision difference is separate from the channel and alpha changes above. This was a synthetic grid. Whether gameplay reaches and displays the world remains open.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Thanks for the rebase. Reviewed at 44638a8, which merges cleanly. CI: passing.

The change maps format 115 (B4G4R4A4_UNORM) to 86 (B5G5R5A1_UNORM) in resource.rs pc_format, for every resource, view and pipeline on every adapter. The testers' runs confirm it stops the render-target-view device removal on NVIDIA. Thanks, @Bladureau and @KainanP. But:

To move forward, gate the stand-in on the host's format support (render target and typed UAV), and show it beats widening. Otherwise, consider joining one of the widening PRs.

Verdict: needs work. CI: passing.


Generated by Claude Code

@Bladureau

Copy link
Copy Markdown

RTX 4060 Laptop: in the world, this removes the format-115 device removal (render-target path only; colours not checked)

Machine: RTX 4060 Laptop 8 GB (driver 617.14, 32-lane waves), i7-13650HX, 32 GB RAM, Windows 11 26300. Series X mode, title 1.0.2.1. Diagnostics build, shader cache filled with translate --cache first.

Tree: main 940d32f + #2121 (40bd210) + #1763 (50d91b1) + #1630 (3c036f7) + #2176 (3feadc6) + #579 (rebased, from the patch in its thread). That is the tree from #965 that shows a lit world on this GPU model. Then this PR (0e350ab) on top. VICTORY_SKIP_WAVE64=mesh,compute, VICTORY_D3D12_DEBUG=1 (except run 1), VICTORY_D3D12_DRED=1.

without this PR with this PR
End of run device removed (0x887A0001), 39 s after world entry (run 1); before world entry (run 2) stopped by hand after about 11 min in the world, frame 3,995
Debug layer at the removal ID3D12Device::CreateRenderTargetView: The format (0x73, B4G4R4A4_UNORM) cannot be used with a RenderTarget view because this particular graphics implementation doesn't support this format. that message 0 times
ERROR lines 1 (the removal) 0

The message also stayed at 0 in five more runs with this PR that reached the world with other wave64 settings. Those runs ended for other reasons: once on a hang in the BVH builder, once stopped by hand, three times on the title's watchdog (#1118).

The other debug-layer messages in the run with this PR come from elsewhere: ID 527 (497 times, buffer states, see #334), ID 971 (pipeline library misses), and a few IDs 538, 599, 645, 679, 680, 820 and 1419.

What this does not show:

  • Colours. The picture on this tree is black on this card for other reasons (the depth buffer stays empty with wave64 mesh skipped), so this run says nothing about the 5-5-5-1 reinterpretation raised in the triage.
  • The triage's gating suggestion. GPU: no render target view of a format the driver refuses while reporting support #2305 reports that on an RTX 4090 the format-support query answers RENDER_TARGET for format 115 and then the view is refused. If that holds on this card too, a gate on CheckFeatureSupport alone would not trigger on NVIDIA. I have not measured the query on this card.

Happy to run a narrowed version (render targets only, or a colour-keeping stand-in) on this card in the same world scene.

One run per configuration. Counts and messages only, no game data. AI-assisted (Claude Code).

@KainanP

KainanP commented Nov 25, 2026

Copy link
Copy Markdown

RTX 4060 Laptop (610.47), merged onto main 13f91ca (adjacent-line conflict in pc_format): B4G4R4A4 target half renders (as B5G5R5A1, with the bits reinterpreted), B5G5R5A1 UAV half still removes the device; your own test fails on main, which now maps 118 to 20 rather than 45. Note: this RTX reports RENDER_TARGET = no for 115 (it does not report support and then refuse). Details and the side-by-side table with the other #1753 PRs: #1753 (comment). Tested with the help of an AI assistant (Claude Code).

@fiestorra
fiestorra force-pushed the gpu/b4g4r4a4-stands-in branch from 44638a8 to 3184820 Compare November 26, 2026 12:22
@fiestorra

Copy link
Copy Markdown
Contributor Author

The stand-in is now conditional on the host, and it carries the view guard with it

Head 31848207, rebased onto 63bcca43. The three points are answered, and the second one is why this branch now also contains what was #2305.

  • It is no longer unconditional. pc_format maps nothing for 115 again. The choice lives where the host is known: stand_in_for(115) asks the adapter (host.vendor, plus CheckFeatureSupport for the format and for B5G5R5A1_UNORM) and returns the stand-in only when the host refuses B4G4R4A4_UNORM and takes B5G5R5A1. A host that renders to 4-4-4-4 keeps its colours; an adapter that takes neither keeps the format and gets a null view (below) instead of a removed device. stand_in_decision is the pure part and its four cases are pinned in the test.
  • KainanP's UAV half. Right, and it is why the view side matters: Host::rtv keeps a view of a format the host refuses off entirely — vendor refused, or the support query says no — with one warn! and a null descriptor, so the UAV path that still removes the device on an RTX 4060 no longer does it through a render target. I am not claiming that fixes the UAV half; #1763 refusing the UAV view is the fix there.
  • Widening (GPU: packed 16-bit colour targets the host cannot write are RGBA8 there #2626, gpu: widen unsupported 16-bit render targets and UAVs to R8G8B8A8_UNORM #2767, victory-gpu: 16-bit packed colour widens for the host (the second crash between the account screen and gameplay), and the two tools it took #2936). Widening to R8G8B8A8 changes the element from 2 to 4 bytes: every ladder step, placed footprint and copy that assumes two bytes would have to change with it, and the title's memory is mapped by those sizes. The stand-in is the only option that keeps the byte layout, which is what a render target the title writes and reads through the same memory needs. That is the argument for this over widening, and it is why I did not join those branches — but where a host takes 4-4-4-4 natively, neither is needed and this now does nothing.

Consolidation: #2305 was the same cluster and is closed into this branch, so there is one place that decides what a refused target is made as (stand_in_for) and one that decides how a view of it is bound (Host::rtv).

Measured: cargo test -p victory-gpu --lib → 232 passed, 0 failed; cargo clippy -p victory-gpu --all-targets -- -D warnings clean. On this machine (RTX 4090, driver 32.0.16.2124) stand_in_for(115) returns the stand-in, and a boot reaches the title's 2560x1440 target without a device removal.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

KainanP's UAV half is now handled where it belongs: the stand-in is skipped for textures written through a UAV

Head 9ada995b. The report you relayed — the UAV half of the same texture still removes the device on an RTX 4060 Laptop because B5G5R5A1 is not a typed-UAV format there either — changes the decision, and it should: B4G4R4A4 is refused as a render target and B5G5R5A1 is refused as a typed UAV, so standing one in for the other trades a removed device for lost writes on any texture that is both.

  • stand_in_for(format, flags) now takes the description's flags. A texture with the unordered-access flag keeps its own format: stand_in_decision(115, refused, stand_in_taken, unordered_use) returns None for it, with a debug line saying why. The render-target case (no UAV flag) still stands in as before.
  • The test's cases are extended with that fourth argument, including the new one: a UAV texture never takes the stand-in.
  • What happens to such a texture now is the layered answer rather than a silent swap: the description keeps B4G4R4A4, the render-target view of it is refused (this is what Host::rtv handles with a null view and a warning, and what GPU: drop the unordered-access permission a format cannot carry, before any call names it #1832 handles on the UAV side by dropping a permission the element cannot carry) instead of the whole device being removed at CreateRenderTargetView.

Measured: cargo test -p victory-gpu --lib -- packed_four_bit → 1 passed; cargo clippy -p victory-gpu --all-targets -- -D warnings clean.

Still true from before: where a host renders to 4-4-4-4 natively, none of this runs and the colours are unchanged.

Written with an AI assistant.

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.

7 participants