Skip to content

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

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
VibeClauding:cont-4444-target
Nov 24, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
VibeClauding:cont-4444-target

Conversation

@VibeClauding

Copy link
Copy Markdown
Contributor

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.

…is a colour attachment (RT-4444-TARGET)

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 <noreply@anthropic.com>
@sodove

sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Independent Windows test on RTX 5070 Ti (610.74), Windows 11 26100.7623, MSVC 19.44.35220 Release. I applied 28052ac to main d42773d. 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.

demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
… images where no 4444 format is a colour attachment (RT-4444-TARGET)

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp

@SweatierKey SweatierKey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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 32a5d96 (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 32a5d96 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
QemmHD merged commit 5bf12d8 into ProjectLeonida:main Nov 24, 2026
1 check passed
QemmHD added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** VK-UAV-CLEAR-PACK16: B5G6R5, B5G5R5A1 and B4G4R4A4 join the UAV-clear layout table, with conversion checks and an exhaustive 65,536-word round trip. Timon360SB (2060S and 5070, 60/60) and SweatierKey approved. The current head b67109e is a content-identical rebase of the reviewed one.

**Why it's good:** uav_clear, short_uav_clear, b5g5r5a1_uav and replay_uav_clear_offset all pass both plain and under validation.

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 32a5d96 (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 32a5d96 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 added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** RT-TITLE-HOST-REGION: a test-only probe that imports a 185 MiB host region as a BDA buffer through VK_EXT_external_memory_host and checks coherence both ways. A machine that can't import exits 77 (skip). No runtime source changes. Timon360SB, madhyn (3060 Ti/Wine) and SweatierKey approved.

**Why it's good:** vk_host_region_import and its _validation variant: "185 MiB imported ... cpu-gpu-coherence=ok", 0 validation errors. Nit for a follow-up: the _validation test sets VK_VALIDATE_SYNC=1, which nothing in the tree reads; if sync validation is the goal, the Khronos layer setting is spelled differently, so that variant probably runs core validation only.

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 32a5d96 (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 32a5d96 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 added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** TEST-INDIRECT-RT-ARENA: d3d12_indirect_rt_test replaces a nested std::max with an initializer-list std::max to work around an MSVC 19.52 miscompile. It's 6 lines. sodove passed both revisions, and the current head is a content-identical rebase.

**Why it's good:** indirect_rt and indirect_rt_upload_sysmem: PASS with 0 validation errors, and the RayQuery got hit=1 here under validation. Timon360SB's hit=0 on a 5070 with GPU-assisted validation shows up on the base too, so it isn't this PR.

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 32a5d96 (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 32a5d96 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 added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** RT-INPUT-SCRIPT-LENGTH: the shim's env() reader now handles values of any length (64 characters or more used to read as unset). The PR also adds the LEONIDA_INPUT_SCRIPT keyboard-pad scheduler (`button@seconds`, 300 ms presses), documented in docs/gameinput.md. That's a second topic, but the body says so, and both parts were reviewed. sodove checked 14/14 runs across lengths, with the control failing 12/12, and kawaii-shakal's harness follow-ups were addressed.

**Why it's good:** gameinput_host, gameinput and the new gameinput_script pass; with validation, gameinput_script passes and logs "8 accepted / 11 rejected". The parsing is bounded (strtod with end-pointer and finiteness checks) and reads only its own env var.

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 32a5d96 (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 32a5d96 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 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.

4 participants