Skip to content

Runtime: B5G6R5 render targets and packed readback (D3D-61) - #587

Merged
ItsNotRexed merged 3 commits into
ProjectLeonida:mainfrom
Vonsek:codex/bgr565-readback
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ProjectLeonida:mainfrom
Vonsek:codex/bgr565-readback

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as D3D-61, B5G6R5_UNORM.

What and why

The runtime rejects a B5G6R5 render target at resource creation. D3D12 requires render-target support for this format at feature level 12.1. Use VK_FORMAT_R5G6B5_UNORM_PACK16 because its low five bits store blue, and account for two bytes per texel in D3D12 footprints and Vulkan buffer-image copies. Microsoft format support

Tested

Windows 11, RTX 5080, driver 616.92, Vulkan validation enabled. On the unmodified base ee97b84, the added case exited 1 at CreateCommittedResource.

  • d3d12_vulkan_device_test used the runtime Xbox-ABI device proxy, RTV heap, D3D12 graphics command list and queue. A full 8×8 clear to (1, 0.25, 0, 1) followed by a 4×4 rectangle clear to (0, 0.75, 1, 0) produced 48 words of 0xfa00 outside and 16 of 0x05ff inside. All 64 matched after CopyTextureRegion and fence completion. A local control swapping the clear colors' red and blue channels failed on the first word, 0x021f instead of 0xfa00.
  • An additional local test reused the existing D3D12 clear/readback helper with the same colors on a 5×3 target. The Vulkan backend on RTX and native D3D12 WARP each returned all 15 independently predicted words.
  • ctest --test-dir build-review/runtime --no-tests=error -R "^gfx10_descriptors$" --output-on-failure passed.

AI-assisted with OpenAI Codex.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A, runtime format mapping.)

D3D12 stores blue in the low five bits of B5G6R5. Use the Vulkan packed format with the same ordering and check the two-byte words returned by full-image and rectangular clears.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

I also checked a sampled SRV independently of the RTV clears on 037c373. A local synthetic 8×8 texture contained repeated 16-bit words f800, 07e0, 001f, and 7808. Using the runtime's upload queue, SRV and sampler, the descriptor fixture's Vulkan shader returned red, green, blue, and (123,0,66,255) respectively. All 64 RGBA8 readbacks matched on RTX 5080.

The Windows runtime CI job passed. Three checks failed with the same inputs and output as their base runs on ee97b84. The seeded shift failure is v_ashrrev_i64 with x=0xf47412b2f2e132ea; s_load expects 0x7f8295f4 and gets 0x7fc295f4. The two llvmpipe failures are cs_w32_lane_wrap and cs_wqm_w32, with identical output words. The other semantic matrix job was cancelled after the first failure. Base CI · Base runtime

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Merged 22590c7 and reran the format test on RTX 5080 with Vulkan validation. With the same new test object linked against unmodified main, resource creation still fails. On 6e0d206 it succeeds. The packed render target's full and rectangular clears returned all 64 expected two-byte words.

Eight of nine CI jobs passed, including Windows runtime and both semantic suites. The only failing job, llvmpipe, returns the same words for cs_w32_lane_wrap and cs_wqm_w32 as on the unmodified base. Separately, the newly merged local d3d12_clear_test reports format 28, case 0, byte 2: Vulkan 7f, WARP 80. I reproduced that result on unmodified 22590c7.

# Conflicts:
#	runtime/test/d3d12_vulkan_device_test.cpp
@oVolkra

oVolkra commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 6e0d206 on NVIDIA GeForce RTX 3060, driver 617.14, Windows 11: pass

Setup: Windows 11 Pro 24H2 (10.0.26100), RTX 3060 (Ampere), NVIDIA 617.14, MSVC 14.44.35207 + Windows SDK 10.0.26100, Ninja RelWithDebInfo, Khronos Vulkan-Headers 1.4.369, VK_LAYER_KHRONOS_validation 1.4.357. PR head built as-is (not rebased; it conflicts with main c432cdc now).

Build: 0 errors, 0 warnings. ctest: 24/24, also with LEONIDA_VK_VALIDATION=1.
d3d12_vulkan_device_test: exit 0. The B5G6R5 case prints no line of its own when it passes, so this is the exit code only.
With LEONIDA_VK_VALIDATION=1: 0 messages from the validation layer (see below).
About the LEONIDA_VK_VALIDATION=1 exit code: on this machine the test prints "3 validation errors" and exits 1 on main c432cdc too. All three are Vulkan loader messages ("loader_get_json: Failed to open JSON file") for stale implicit-layer registry entries of uninstalled overlays, not messages from the validation layer. The validation layer itself reported 0 messages, the same as on main.

AI-assisted: the build and test runs were done with an AI coding assistant (Claude Code) on my machine; the numbers above are its unedited output.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reporting the executable result and distinguishing the loader messages from validation-layer diagnostics. 6e0d206 was the earlier head. The current head fc7e0a1 incorporates c432cdc and passes all nine checks. The RTX 5080 readback on that revision matched all 64 packed words.

@troythedecoyx

Copy link
Copy Markdown
Contributor

Tested fc7e0a1 merged onto main c432cdc on NVIDIA GeForce RTX 4060 Ti (Ada), driver 32.0.16.2124 (NVIDIA 621.24), Windows 11 Home 26300, MSVC 2022 / Ninja, Vulkan SDK 1.4.363: pass.

Besides ctest, I ran each test program this PR changes directly (several aren't registered with ctest):

  • d3d12_vulkan_device_test: exit 0

ctest: 100% tests passed, 0 tests failed out of 27.

AI-assisted.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested fc7e0a1 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

No game files used. AI-assisted run (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit fa7f38b into ProjectLeonida:main Nov 22, 2026
9 checks passed
ismailchaka1 added a commit to ismailchaka1/Leonida that referenced this pull request Nov 22, 2026
The only conflict: block_format's two-byte list, where main added
R5G6B5_UNORM_PACK16 (ProjectLeonida#587) next to this PR's A4R4G4B4_UNORM_PACK16. Both kept.
AlxcBTW added a commit to AlxcBTW/Leonida that referenced this pull request Nov 22, 2026
…n now has

ItsNotRexed#562/ItsNotRexed#587 landed the same R9G9B9E5_SHAREDEXP and B5G6R5_UNORM mappings this
branch adds. The textual merge was clean but left duplicate case labels
(MSVC C2196) in texture_format and the block-size table; keep one of each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants