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

Merged
VibeClauding merged 1 commit from upstream-pr/517 into main 2026-11-24 20:43:57 +00:00
VibeClauding commented 2026-11-24 06:50:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by VibeClauding on 2026-11-24T06:50:45Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5467524449 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/517). Originally posted by [VibeClauding](https://github.com/VibeClauding) on 2026-11-24T06:50:45Z. --- 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.
sodove commented 2026-11-24 07:16:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-24T07:16:56Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7124817881 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/517#issuecomment-7124817881). Originally posted by [sodove](https://github.com/sodove) on 2026-11-24T07:16:56Z. --- 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.
SweatierKey commented 2026-11-24 16:52:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by SweatierKey on 2026-11-24T16:52:28Z.

Review: APPROVED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6043628541 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/517#pullrequestreview-6043628541). Originally posted by [SweatierKey](https://github.com/SweatierKey) on 2026-11-24T16:52:28Z. **Review:** APPROVED --- 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
QemmHD commented 2026-11-24 20:43:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T20:43:54Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143981059 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/517#issuecomment-7143981059). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T20:43:54Z. --- 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!517
No description provided.