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

Closed
opened 2026-11-26 20:18:18 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/517
Author: @VibeClauding
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: cont-4444-target


📝 Commits (1)

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

📊 Changes

3 files changed (+262 additions, -1 deletions)

View changed files

📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+29 -1)
➕ runtime/test/d3d12_b4g4r4a4_target_test.cpp (+226 -0)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/517 **Author:** [@VibeClauding](https://github.com/VibeClauding) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `cont-4444-target` --- ### 📝 Commits (1) - [`28052ac`](https://github.com/ubiquitarianism/leonida/commit/28052acd70fa90b0bb793730974321f9d3a13793) d3d12: B4G4R4A4 render targets are RGBA8 images where no 4444 format is a colour attachment (RT-4444-TARGET) ### 📊 Changes **3 files changed** (+262 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+29 -1) ➕ `runtime/test/d3d12_b4g4r4a4_target_test.cpp` (+226 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:18 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#566
No description provided.