Skip to content

d3d12: B5G5R5A1 UAV textures are mutable R16_UINT images where A1R5G5B5 has no storage - #7604

Open
NiiRoZz wants to merge 1 commit into
ItsNotRexed:mainfrom
NiiRoZz:d3d12/b5g5r5a1-uav-r16uint
Open

NiiRoZz wants to merge 1 commit into
ItsNotRexed:mainfrom
NiiRoZz:d3d12/b5g5r5a1-uav-r16uint

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #7599 (comment)

Depends on: none (based on main).

What

On a GPU whose VK_FORMAT_A1R5G5B5_UNORM_PACK16 has no STORAGE_IMAGE support (an RTX 5090 here), a B5G5R5A1_UNORM texture with ALLOW_UNORDERED_ACCESS is now a mutable VK_FORMAT_R16_UINT image with {R16_UINT, A1R5G5B5_UNORM_PACK16} in its format list, instead of being refused.

  • The existing R9G9B9E5 route is generalized for this: Format::r9g9b9e5_as_r32_uint becomes Format::uint_backed, the format a UAV texture stored as a mutable unsigned image is viewed in (E5B9G9R9 for R32_UINT, A1R5G5B5 for R16_UINT). probe_r9g9b9e5_uav_emulation becomes probe_uint_backed_uav(logical, backing), used for both. R9G9B9E5 behaves as before.
  • For B5G5R5A1, the UAV's storage view is R16_UINT in the uint class. SRVs are A1R5G5B5 sampled views. Unlike R9G9B9E5, render targets are kept: RTVs and clears go through an A1R5G5B5 attachment view, and ResourceBinding::uint_backed lets replay's color_view_format take that format.
  • SRV and UAV T#s keep the texture's own format, 1_5_5_5_UNORM (134), not 16_UINT.
  • Multisampled UAV textures are still refused. CheckFeatureSupport doesn't advertise the typed UAV yet: a shader store through this view needs the translator to pack the 5-5-5-1 bits, which is a follow-up.

Why

The retail boot under LEONIDA_D3D12=vulkan asks device slot 25 for the size of a 2560×1440 B5G5R5A1_UNORM texture with ALLOW_RENDER_TARGET | ALLOW_UNORDERED_ACCESS, and asserts when the answer is UINT64_MAX. The layer refused it because the image would need storage usage in a format this GPU can't store to. Measured on my copy; reported on #7333.

Tested

Windows 11, MSVC 2022 (14.44, RelWithDebInfo, Ninja), RTX 5090, Vulkan SDK 1.4.363.0:

  • New d3d12_b5g5r5a1_uav_test, run with LEONIDA_VK_VALIDATION=1: OK, 0 validation errors. It checks the following:
    • The 2560×1440 size is answered, and the resource is created.
    • Two ClearRenderTargetViews (whole view red, a rectangle green) read back as packed 0xFC00 / 0x03E0 texels.
    • The UAV and SRV T#s carry format 134.
    • A 4× multisampled UAV texture is still refused.
    • It skips (77) on a GPU with native A1R5G5B5 storage, or without R16_UINT storage or A1R5G5B5 sampling and attachment.
  • Negative control: the same test against main's layer fails at the size check.
  • Regression: d3d12_r9g9b9e5_uav_test (with validation, 0 errors), d3d12_uav_clear_test, d3d12_descriptor_test and d3d12_clear_test pass. d3d12_vulkan_device_test exits 1 here with and without this change (its B5G5R5A1_UNORM copy case matches the host).
  • Retail boot (locally merged with the boot-path PRs): before, the size assert at 2,415 D3D12 calls. After, this texture is created and the boot goes on to the next refused description, a depth-stencil + UAV texture.

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Only public API names, formats, sizes and counts; no addresses, offsets, disassembly, strings or bytes from the executable.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…B5 has no storage

A B5G5R5A1_UNORM texture with ALLOW_UNORDERED_ACCESS was refused on a GPU whose
VK_FORMAT_A1R5G5B5_UNORM_PACK16 has no STORAGE_IMAGE (NVIDIA): GetResourceAllocationInfo answered
UINT64_MAX and creation failed. A title's boot creates a 2560x1440 render-target + UAV one and
asserts on that size.

The R9G9B9E5 route generalizes: Format::r9g9b9e5_as_r32_uint becomes Format::uint_backed, the format
a UAV texture stored as a mutable unsigned image is viewed in (E5B9G9R9 for R32_UINT, A1R5G5B5 for
R16_UINT). For B5G5R5A1 the image is R16_UINT with {R16_UINT, A1R5G5B5} listed; its storage view is
R16_UINT in the uint class, SRVs are A1R5G5B5 sampled views, and RTVs and clears go through an
A1R5G5B5 attachment view (ResourceBinding::uint_backed lets replay's color_view_format take it). The
SRV and UAV T#s keep the 1_5_5_5_UNORM format. A shader store still needs the translator to pack
the bits for that view, so CheckFeatureSupport does not advertise the typed UAV yet.

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

Copy link
Copy Markdown
Contributor

Independent check of 0dc7f58e on an RTX 4090 (driver 617.42, Windows 11 26200, MSVC 2022 RelWithDebInfo), where A1R5G5B5_UNORM_PACK16 has sampled + color-attachment but no storage image in optimal tiling (vulkaninfo), the case this PR targets. With LEONIDA_VK_VALIDATION=1:

  • d3d12_b5g5r5a1_uav_test: OK (R16_UINT image, A1R5G5B5 render-target clears 64x32 matched, UAV/SRV T# format 134, 0 validation errors).
  • d3d12_r9g9b9e5_uav_test: OK, 0 validation errors, so no regression on the route it generalizes.
  • d3d12_uav_clear_test: exit 0.
    Not run: the retail boot with it. Counts only. AI-assisted (Claude Code).

@MartinIndra02

Copy link
Copy Markdown

Independent Windows + GPU test of 0dc7f58e5: pass.

Setup: Windows 11 x64, MSVC 19.44.35220 (RelWithDebInfo, Windows SDK 10.0.26100.0), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124 / 621.24), Vulkan SDK 1.4.363.1, LEONIDA_VK_VALIDATION=1, no game files.

  • d3d12_b5g5r5a1_uav_test.exe: PASS (exit 0, 0 validation errors).

AI-assisted review/test.

@jlric

jlric commented Nov 23, 2026

Copy link
Copy Markdown

AI-assisted Wine 11.22 test, RTX 4070/NVIDIA 620.73.04. I adapted 0dc7f58 onto a local boot stack with #7403. The synthetic test passed allocation, creation, clear readback and descriptor checks (validation unavailable in this Wine sandbox). In the boot A/B, the packed color allocation went from invalid to valid. The next depth-stencil + UAV allocation is refused at the same assertion.

@airp1ane

Copy link
Copy Markdown
Contributor

Tested 0dc7f58e5 on Windows 11, NVIDIA GeForce RTX 4060 Ti (driver 621.24, Vulkan 1.4.357, Vulkan SDK 1.4.363.1), MSVC 19.52 (VS 18 / CMake + Ninja, RelWithDebInfo), with LEONIDA_VK_VALIDATION=1 (no game files): pass.

  • scripts/build_runtime.ps1: clean build.
  • d3d12_b5g5r5a1_uav_test.exe: PASS — RTX 4060 Ti exercises the fallback path (B5G5R5A1_UNORM UAV unavailable natively, using mutable R16_UINT; format 86): OK (R16_UINT image, A1R5G5B5 render-target clears 64x32 matched, UAV/SRV T# format 134, 0 validation errors).
  • Regression suite (d3d12_descriptor_test, d3d12_clear_formats_test, d3d12_stores_atomics_test, d3d12_copy_xfmt_test, d3d12_subresource_copy_test, all with LEONIDA_VK_VALIDATION=1): 5/5 PASS, 0 validation errors.
  • python -I tests/test_ctest_registration.py: 4/4 OK.
  • Merge check onto main 7ef2fdd46 (git merge-tree), git diff --check, and scripts/check_no_game_data.py: all clean.

AI-assisted.

@ramenbellic

Copy link
Copy Markdown

Tested 0dc7f58e against the retail executable under Proton (wine 11), RTX 3070 (620.70.06; no STORAGE_IMAGE on A1R5G5B5_UNORM_PACK16), on the boot chain past the frame loop (#7154; ramenbellic:boot/retail-stack). Outcomes only.

  • The B5G5R5A1 part works: B5G5R5A1_UNORM UAV unavailable natively, using mutable R16_UINT. Slot 25 sizes the title's 2560×1440 render-target+UAV texture, and the title goes on.
  • A second format needs the same fallback on this GPU: DXGI_FORMAT_R32G8X24_TYPELESS (19). With only this PR, slot 25 answers UINT64_MAX for the title's format-19 resource, and the title asserts on the size at about 4,100 D3D12 calls. A local stand-in, which only sizes the image without its storage usage, gets past it to the frame loop (53,303 calls, 11 DrawInstanced). So the storage support check fails for 19 on NVIDIA too. Whether it needs a uint_backed form (R32G32_UINT?) like 86 is for you to judge; I haven't checked what the title binds it as.
  • Merge note: on a stack that has d3d12: A8_UNORM textures in 1D and 3D, as the host makes them #7755 (A8), this PR conflicts in Format/TextureCreateInfo (a8_as_alpha and r9g9b9e5_as_r32_uint next to uint_backed) and in the RTV branch. Keeping both sides compiles and works.

AI-assisted (Claude Code); outcomes only, no game data.

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Tested 0dc7f58e5 on the retail boot: pass. Windows 11, RTX 5060 Ti (NVIDIA; A1R5G5B5_UNORM_PACK16 has no STORAGE_IMAGE feature here), MSVC RelWithDebInfo, own 1.0.2.1 copy, base ASTROWwwW:ladder-frame @ bee47186f. Without this PR, device slot 25 answers UINT64_MAX for the title's 2560x1440 B5G5R5A1 RENDER_TARGET + UNORDERED_ACCESS texture, and the title's size check stops the run (3,758 D3D12 calls). With it, the log shows B5G5R5A1_UNORM UAV unavailable natively, using mutable R16_UINT, and the run continues to 55,831 calls (and, with #7180, a 300 s run without a stop: #7154 (comment)). The one conflict against ladder-frame is d3d12_vulkan_device.cpp next to #7403's A8 fields (a8_as_alpha): keep both sides, and in the RTV branch keep #7403's A8 check followed by this PR's uint_backed branch. AI-assisted (Claude Code).

@eugen1763

Copy link
Copy Markdown

I claimed the translator-side follow-up as SHADER-1202 in #8504. For descriptor FORMAT 134, I’m planning to pack the normalized store into the R16_UINT view while leaving sampled reads on the A1R5G5B5 view. The current backing selection looks conditional on lack of native A1R5G5B5 storage. Would you prefer always selecting the uint view for FORMAT 134 storage when the paired views are supported, or identifying the backing explicitly in the translator’s resource metadata? I’ll keep this out of your device-side PR. No game data. AI-assisted (Codex).

@eugen1763

Copy link
Copy Markdown

Confirmed this is not hypothetical: RADV 26.2.6 on the Ryzen 7 9800X3D iGPU reports native optimal-tiling STORAGE_IMAGE and COLOR_ATTACHMENT for A1R5G5B5_UNORM_PACK16; RTX 5080 lacks the storage bit. Draft #8710 is intentionally not ready to merge until both paths agree on the storage class. No game data. AI-assisted (Codex).

@MarcPique

Copy link
Copy Markdown

Independent Windows 11 result on an RTX 4090 (driver 32.0.16.1656, MSVC 19.44.35228, RelWithDebInfo). I compared ASTROWwwW's ladder-frame@a1751a9f0 with the same tree plus #7604@0dc7f58e5, keeping both the A8 fields already on that branch and the changes in this PR in the five conflicting hunks.

  • The d3d12_b5g5r5a1_uav fixture passed on the RTX 4090 and exercised the mutable R16_UINT image, A1R5G5B5 RTV clear readback and the UAV/SRV descriptor format. AMD Radeon Graphics (driver 32.0.13066.12) reports native A1R5G5B5 storage and the emulation fixture correctly skipped on that adapter.
  • On the same RTX, the control hit a title breakpoint after the slot-25 allocation-size call at about 10.8 s, with 12,133 D3D12 records and zero draws.
  • With the PR integrated, the runtime chose the R16_UINT fallback and passed that point. It ran to the external 210 s test limit with no guest exception, 5,282,954 D3D12 records and 168,378 recorded draws. The window capture was white during this run. Queue slot 35 was still unforwarded on this stack, so these are recorded draws.

Same package and shader indexes for both runs, with Xbox and Rockstar services inaccessible in the test process. Counts and API names only. AI-assisted.

@username634

Copy link
Copy Markdown

Tested 0dc7f58e5 on Intel UHD Graphics 730 (Xe-LP iGPU, Intel driver 101.7092, Windows 11 Pro 26300, MSVC 14.44 RelWithDebInfo): pass. This is the first non-NVIDIA driver here. Like the RTX 5090, it reports VK_FORMAT_A1R5G5B5_UNORM_PACK16 without STORAGE_IMAGE (R16_UINT has it), so it takes the new mutable R16_UINT route:

[rt] d3d12: B5G5R5A1_UNORM UAV unavailable natively, using mutable R16_UINT; format 86
device: Intel(R) UHD Graphics 730
d3d12_b5g5r5a1_uav_test: OK (R16_UINT image, A1R5G5B5 render-target clears 64x32 matched, UAV/SRV T# format 134, 0 validation errors)

ctest -R "^(d3d12_b5g5r5a1_uav|d3d12_r9g9b9e5_uav)$" passes 2/2 on the UHD 730 and on the RTX 5060 Ti (621.01) in the same PC, which I ran as a control. d3d12_r9g9b9e5_uav also passes on main 867d922f0 on both GPUs, so the generalised R9G9B9E5 route doesn't regress.

Synthetic tests only, no game files. AI-assisted (Claude Code).

hexxone pushed a commit to hexxone/Leonida that referenced this pull request Nov 23, 2026
…storage view

Where VK_FORMAT_A1R5G5B5_UNORM_PACK16 has no storage support the D3D12 layer
backs a B5G5R5A1_UNORM UAV texture with a mutable R16_UINT image whose storage
view is in the uint class, and its T# keeps FORMAT 134 (ItsNotRexed#7604). A translated
image_store picked the float view for that format, which is then the fallback,
so the store was lost.

The T# does not say which image is behind it, so an image_store whose FORMAT is
134 at run time now stores twice at the same index: the float texel through the
float view as before (the image itself on a GPU that stores A1R5G5B5), then the
texel packed through the uint view. The view the runtime did not bind is the
1x1 fallback, as on a lookup miss. The word has the A1R5G5B5 layout (component
0 in bits 14:10, 1 in 9:5, 2 in 4:0, 3 in bit 15), each channel clamped to
[0, 1] with NMax/NMin (a NaN is 0) and rounded to nearest. Other formats keep
their single store.

- tests/semantic/test_image_store_1555.py runs the fixture image_store_1555.asm
  in spirv_mini_interp, which gains OpImageWrite on bound storage images. 8 of
  its 9 tests fail on the translator before this change.
- test_image_coherent, test_image_cube_store_glc and test_image_store_dmask
  count the writes of an image_store and now expect the packed one.
- runtime/test/d3d12_b5g5r5a1_store_test dispatches cs_b5g5r5a1_store.asm
  through the layer and reads 256 texels back as packed 16-bit values
  (RTX 4090, validation layer, 0 errors; 248 texels differ with the translator
  before this change).
- docs/design.md: contract row "Packed 1_5_5_5 image stores".

Depends on: ItsNotRexed#7604

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ef3eca6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants