d3d12: B4G4R4A4 render targets are RGBA8 images where no 4444 format is a colour attachment (RT-4444-TARGET) #517

Manually merged
github merged 1 commit from gh-pr/517/head into gh-pr/517/base 2026-11-26 09:05:29 +00:00
Owner

@⁠VibeClauding on GitHub · 2026-11-24 06:50 UTC · original
VibeClauding:cont-4444-target → main · +262 −1 · 3 files · 1 commits · merged 2026-11-24 20:43 UTC

Claimed in #14 as RT-4444-TARGET.

What and why

DXGI_FORMAT_B4G4R4A4_UNORM maps to VK_FORMAT_A4R4G4B4_UNORM_PACK16, which NVIDIA does not offer as a colour attachment, and neither are R4G4B4A4/B4G4R4A4 (all sampled only; RTX 3070, driver 610.88, vulkaninfo --show-formats). So a B4G4R4A4 texture with ALLOW_RENDER_TARGET was refused: GetResourceAllocationInfo answered UINT64_MAX and creation failed. The retail title asks for one during boot and asserts on the answer (seen on a forge-based branch on Windows; this is the same fix onto main).

Now, only where no 4444 format renders:

  • Resource: an RGBA8 image (DeviceState's texture format choice, next to the B5G5R5A1 and sRGB UAV cases). Every 4-bit value is exact in 8 bits.
  • RTVs need nothing: a typed resource's RTV already uses the image's format. PSOs with a B4G4R4A4 RTVFormats entry get R8G8B8A8_UNORM as the attachment format.
  • SRV T#s still name 4_4_4_4 (136), as the console's do. bind_image views a 4444 T# on an RGBA8 image as RGBA8 with A4R4G4B4's channels (the lookup would otherwise pick A4B4G4R4 by channel order, a 16-bit view of a 32-bit image, which Vulkan validation rejects).

Not covered, and said in the code: CopyTextureRegion between such a texture and a buffer footprint moves 4-byte RGBA8 texels, not packed 16-bit ones. Replay's footprint bounds checks still hold, so nothing is written outside the buffer. Converting would need the footprint's format in CopyLocation, which is not recorded today.

Tests

  • New d3d12_b4g4r4a4_target (modelled on d3d12_b5g5r5a1_uav, exits 77 where A4R4G4B4 renders): a size and a committed resource for a 1920x1080 target; whole and rectangle RTV clears with 4-bit-exact colours read back as RGBA8; the SRV T# format is 4_4_4_4; a non-render-target B4G4R4A4 texture still gets a size. Passes on RTX 3070 with LEONIDA_VK_VALIDATION=1, 0 validation errors.
  • Full ctest (Windows 11, MSVC, RTX 3070): 302/304. d3d12_execute_indirect_validation fails the same way on unchanged main here; xmem failed once under -j 4 and passes alone (3 of 3).
  • scripts/check_no_game_data.py on the changed files: clean.

AI-assisted (Claude Code); built and tested on the machine above.

**@⁠VibeClauding** on GitHub · 2026-11-24 06:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/517) `VibeClauding:cont-4444-target` → `main` · +262 −1 · 3 files · 1 commits · merged 2026-11-24 20:43 UTC Claimed in #14 as `RT-4444-TARGET`. ### What and why `DXGI_FORMAT_B4G4R4A4_UNORM` maps to `VK_FORMAT_A4R4G4B4_UNORM_PACK16`, which NVIDIA does not offer as a colour attachment, and neither are `R4G4B4A4`/`B4G4R4A4` (all sampled only; RTX 3070, driver 610.88, `vulkaninfo --show-formats`). So a B4G4R4A4 texture with `ALLOW_RENDER_TARGET` was refused: `GetResourceAllocationInfo` answered `UINT64_MAX` and creation failed. The retail title asks for one during boot and asserts on the answer (seen on a forge-based branch on Windows; this is the same fix onto `main`). Now, only where no 4444 format renders: - **Resource:** an RGBA8 image (`DeviceState`'s texture format choice, next to the B5G5R5A1 and sRGB UAV cases). Every 4-bit value is exact in 8 bits. - **RTVs** need nothing: a typed resource's RTV already uses the image's format. **PSOs** with a B4G4R4A4 `RTVFormats` entry get `R8G8B8A8_UNORM` as the attachment format. - **SRV T#s** still name `4_4_4_4` (136), as the console's do. **`bind_image`** views a 4444 T# on an RGBA8 image as RGBA8 with `A4R4G4B4`'s channels (the lookup would otherwise pick `A4B4G4R4` by channel order, a 16-bit view of a 32-bit image, which Vulkan validation rejects). Not covered, and said in the code: `CopyTextureRegion` between such a texture and a buffer footprint moves 4-byte RGBA8 texels, not packed 16-bit ones. Replay's footprint bounds checks still hold, so nothing is written outside the buffer. Converting would need the footprint's format in `CopyLocation`, which is not recorded today. ### Tests - New `d3d12_b4g4r4a4_target` (modelled on `d3d12_b5g5r5a1_uav`, exits 77 where A4R4G4B4 renders): a size and a committed resource for a 1920x1080 target; whole and rectangle RTV clears with 4-bit-exact colours read back as RGBA8; the SRV T# format is 4_4_4_4; a non-render-target B4G4R4A4 texture still gets a size. Passes on RTX 3070 with `LEONIDA_VK_VALIDATION=1`, 0 validation errors. - Full `ctest` (Windows 11, MSVC, RTX 3070): 302/304. `d3d12_execute_indirect_validation` fails the same way on unchanged `main` here; `xmem` failed once under `-j 4` and passes alone (3 of 3). - `scripts/check_no_game_data.py` on the changed files: clean. AI-assisted (Claude Code); built and tested on the machine above.
NVIDIA has no renderable 4444 Vulkan format (A4R4G4B4, R4G4B4A4, B4G4R4A4 are sampled only), so a B4G4R4A4_UNORM
texture with ALLOW_RENDER_TARGET was refused and GetResourceAllocationInfo answered UINT64_MAX. Such a texture is now
an RGBA8 image, which holds every 4-bit value exactly: RTVs and PSO target formats follow the image, SRV T#s still
name 4_4_4_4, and bind_image views the RGBA8 image with A4R4G4B4's channels. Not covered: buffer copies of it move
4-byte texels.

Test: d3d12_b4g4r4a4_target (size and creation, RTV clears read back, SRV T# format; 0 validation errors).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:05:28 +00:00
github manually merged commit 28052acd70 into gh-pr/517/base 2026-11-26 09:05:29 +00:00
Author
Owner

@⁠sodove on GitHub · 2026-11-24 07:16 UTC · original

Independent Windows test on RTX 5070 Ti (610.74), Windows 11 26100.7623, MSVC 19.44.35220 Release. I applied 28052acd70 to main d42773d073. The PR's stock target test fails the allocation-size check with the main implementation and passes on this head with Vulkan validation enabled.

I also compared full and rectangle clears with colors that need 4-bit quantization. I normalized WARP's packed 4444 readback into RGBA8 values for the comparison.

Backend Full clear outside the rectangle Rectangle clear
Native D3D12 WARP 1920/1920 matched the 4-bit oracle 128/128 matched
Vulkan RGBA8 fallback 0/1920 matched 0/128 matched

The fallback stored the colors at 8-bit precision. The default native hardware D3D12 adapter reported no 4444 render-target support, so WARP was the native reference here. This is a clear precision difference in addition to the documented footprint difference. Draw and sample precision were outside this test.

Synthetic fixtures only. AI-assisted verification.

**@⁠sodove** on GitHub · 2026-11-24 07:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/517#issuecomment-7124817881) Independent Windows test on RTX 5070 Ti (610.74), Windows 11 26100.7623, MSVC 19.44.35220 Release. I applied 28052acd70fa90b0bb793730974321f9d3a13793 to main d42773d0734d5fd7b3a32a1bfd536f61186322a5. The PR's stock target test fails the allocation-size check with the main implementation and passes on this head with Vulkan validation enabled. I also compared full and rectangle clears with colors that need 4-bit quantization. I normalized WARP's packed 4444 readback into RGBA8 values for the comparison. | Backend | Full clear outside the rectangle | Rectangle clear | | --- | --- | --- | | Native D3D12 WARP | 1920/1920 matched the 4-bit oracle | 128/128 matched | | Vulkan RGBA8 fallback | 0/1920 matched | 0/128 matched | The fallback stored the colors at 8-bit precision. The default native hardware D3D12 adapter reported no 4444 render-target support, so WARP was the native reference here. This is a clear precision difference in addition to the documented footprint difference. Draw and sample precision were outside this test. Synthetic fixtures only. AI-assisted verification.
Author
Owner

@⁠SweatierKey on GitHub · 2026-11-24 16:52 UTC · original · approved these changes

Independently verified on Windows 11 + NVIDIA GeForce RTX 5070 Ti (driver 616.92, clean origin/main at 3ed8e50b7, no game files, VK_LAYER_KHRONOS_validation not installed on host).

  • python3 -I scripts/check_no_game_data.py: PASS
  • Built and ran d3d12_b4g4r4a4_target_test.exe:
    d3d12_b4g4r4a4_target_test: OK (RGBA8 image, render-target clears 64x32 matched, SRV T# format 136, 0 validation errors)
  • Audited all 3 changed files: cleanly falls back to VK_FORMAT_R8G8B8A8_UNORM when VK_FORMAT_A4R4G4B4_UNORM_PACK16 lacks color-attachment support (NVIDIA), while preserving GFX10 4_4_4_4 T# format codes and channel mapping in bind_image.

AI-assisted: yes

**@⁠SweatierKey** on GitHub · 2026-11-24 16:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/517#pullrequestreview-6043628541) · **approved these changes** Independently verified on Windows 11 + NVIDIA GeForce RTX 5070 Ti (driver 616.92, clean `origin/main` at `3ed8e50b7`, no game files, `VK_LAYER_KHRONOS_validation` not installed on host). - `python3 -I scripts/check_no_game_data.py`: PASS - Built and ran `d3d12_b4g4r4a4_target_test.exe`: `d3d12_b4g4r4a4_target_test: OK (RGBA8 image, render-target clears 64x32 matched, SRV T# format 136, 0 validation errors)` - Audited all 3 changed files: cleanly falls back to `VK_FORMAT_R8G8B8A8_UNORM` when `VK_FORMAT_A4R4G4B4_UNORM_PACK16` lacks color-attachment support (NVIDIA), while preserving GFX10 `4_4_4_4` T# format codes and channel mapping in `bind_image`. AI-assisted: yes
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 20:43 UTC · original

Merging.

Why merged: RT-4444-TARGET: where the device can't use a 4444 format as a colour attachment (NVIDIA), a B4G4R4A4 render target becomes an RGBA8 image. Its T#s keep the 4_4_4_4 format, and PSO RTV formats follow the image. Before this, the render target couldn't be created at all (size UINT64_MAX). sodove (5070 Ti) and SweatierKey approved.

Why it's good: The new d3d12_b4g4r4a4_target really runs here (not skipped): "B4G4R4A4_UNORM ... using RGBA8", OK, 0 validation errors. b5g5r5a1_uav, srgb_uav and vulkan_device also pass. Follow-up, not a blocker: sodove measured that the RGBA8 fallback stores clears at 8-bit precision instead of quantising to 4 bits (0/1920 texels matched WARP's 4-bit result), and buffer-footprint copies from it move 4-byte texels (documented in the code). Quantising on clear and store would close that gap.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #517, #907, #927, #954 and #1074 merged onto main 32a5d9698 (after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain 32a5d9698 too: a regression from #510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-24 20:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/517#issuecomment-7143981059) Merging. **Why merged:** RT-4444-TARGET: where the device can't use a 4444 format as a colour attachment (NVIDIA), a B4G4R4A4 render target becomes an RGBA8 image. Its T#s keep the 4_4_4_4 format, and PSO RTV formats follow the image. Before this, the render target couldn't be created at all (size UINT64_MAX). sodove (5070 Ti) and SweatierKey approved. **Why it's good:** The new d3d12_b4g4r4a4_target really runs here (not skipped): "B4G4R4A4_UNORM ... using RGBA8", OK, 0 validation errors. b5g5r5a1_uav, srgb_uav and vulkan_device also pass. **Follow-up, not a blocker:** sodove measured that the RGBA8 fallback stores clears at 8-bit precision instead of quantising to 4 bits (0/1920 texels matched WARP's 4-bit result), and buffer-footprint copies from it move 4-byte texels (documented in the code). Quantising on clear and store would close that gap. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #517, #907, #927, #954 and #1074 merged onto main 32a5d9698 (after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain 32a5d9698 too: a regression from #510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.