Skip to content

d3d12: A8_UNORM render targets on VK_FORMAT_A8_UNORM_KHR (VK_KHR_maintenance5) - #7593

Closed
kapitche wants to merge 1 commit into
ProjectLeonida:mainfrom
kapitche:a8-unorm-rt
Closed

kapitche wants to merge 1 commit into
ProjectLeonida:mainfrom
kapitche:a8-unorm-rt

Conversation

@kapitche

Copy link
Copy Markdown
Collaborator

What broke. The retail boot creates a 2D A8_UNORM (DXGI 65) render target, 1 mip, 1 sample. The layer stores A8 as an R8 image read through a swizzle and has no render-target or UAV support for it, so both GetResourceAllocationInfo (UINT64_MAX) and CreateCommittedResource refuse it, while the NVIDIA host D3D12 sizes and creates it (measured in #7231 (comment)). Repro on main: d3d12_descriptor_test asserts exactly that refusal, and adding an A8_UNORM row to d3d12_clear_formats gives "not exposed".

Fix. Where the device has VK_KHR_maintenance5 and VK_FORMAT_A8_UNORM_KHR supports colour attachment, sampling and transfer, an A8_UNORM render target is a real VK_FORMAT_A8_UNORM_KHR image. Everywhere else, and for every A8 texture without ALLOW_RENDER_TARGET, the R8 + swizzle path and the old refusal stay as they were.

  • The standalone device enables VK_KHR_maintenance5 (and its feature) when present, and VulkanDeviceInfo::maintenance5 says so. Caller-owned devices default to off and keep the fallback.
  • texture_format returns the A8 image for ALLOW_RENDER_TARGET, so sizing and creation agree. DS, UAV, MSAA and non-2D A8 stay refused (UAV is out of scope: the storage path writes the T#'s X into R).
  • CheckFeatureSupport(FORMAT_SUPPORT) adds RENDER_TARGET (and BLENDABLE where the format blends) only on that path.
  • RTVs: an A8 RTV of the A8 image is accepted. An R8 RTV of it, or an A8 RTV of anything else, is still null.
  • Graphics PSOs map RTVFormats = A8_UNORM to the A8 attachment.
  • SRVs keep the same T# (8_UNORM, alpha from X). bind_image views the A8 image in its own format and moves the swizzle's R to A.
  • Replay: A8 clears quantize like UNORM8, and copies know its 1-byte block.

Tests.

  • d3d12_descriptor_test: CheckFeatureSupport, multisample levels, sizing and creation for RT / DS / UAV / RT+UAV now expect success only for RT, and only when the GPU has the A8 attachment. The same checks run on a second device over the same VkDevice with maintenance5 = false, which must refuse as before (the in-test fallback control). A new block clears an 8x8 A8 target (whole, then a rectangle), copies it to a readback buffer (153 / 51 per texel) and samples it through the default view (0,0,0,A) and a remapped one (A,0,1,0).
  • d3d12_clear_formats: an A8_UNORM row compared byte for byte with WARP.
  • vk_test_device.h: opt-in request_maintenance5, so other tests' devices are unchanged.

Native Windows 11, MSVC 14.51 (VS 18), RelWithDebInfo, cmake flags from pr_rt_full.bat, Vulkan SDK headers from that setup (no Python involved):

  • RTX 4080 SUPER: d3d12_descriptor passes, with "A8 render target: cleared and copied back, 64 texels matched" and "default and remapped views sampled, 64 texels matched each". d3d12_clear_formats: 256 matched WARP, 0 differ.
  • Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*, LEONIDA_VK_DEVICE=Intel, device line "Intel(R) UHD Graphics 770"): takes the new path, and d3d12_descriptor passes with the same lines. In d3d12_clear_formats the A8 row matches WARP. That test's SRGB and D24 stencil differences on Intel are pre-existing (see the control).
  • Full ctest on the branch (RTX 4080 SUPER): 266 of 269 pass, plus gameinput (disabled, no SDL3). The 3 failures are the known pre-existing ones on main: d3d12_vulkan_device (line 6564 tiles == 1, the GetResourceTiling finding in Coordinating who works on what (42) (moved to #7333) #7231), d3d12_indirect_dispatch_count and d3d12_indirect_rt. I didn't run the full ctest on Intel, only the two tests above.

Negative control. I checked out runtime/shims/d3d12_vulkan_device.cpp and runtime/src/vulkan_replay.h from main (511e382), kept the new tests and rebuilt, on the RTX 4080 SUPER. d3d12_descriptor_test then fails at line 517 (RENDER_TARGET support expected with the A8 attachment) and exits 1. d3d12_clear_formats reports the A8 row as "not exposed" (5 cases; WARP renders them).

VK_LAYER_KHRONOS_validation isn't installed on this machine, so the runs above were not under validation.

AI-assisted.

@skorex

skorex commented Nov 23, 2026

Copy link
Copy Markdown

Duplicate of #7403

#7403 makes the same change and was opened earlier. Topic: d3d12: A8_UNORM render targets through VK_FORMAT_A8_UNORM_KHR (VK_KHR_maintenance5).

Suggest closing this PR in favour of #7403, and porting anything this one adds that #7403 lacks there.

@gabrielcruzg3

Copy link
Copy Markdown

Tested 0646324 (merged onto main 6457efc74) on NVIDIA GeForce RTX 3060 Ti (driver 621.01), Windows 11, MSVC 19.52 (VS 18), Ninja, Vulkan SDK 1.4.363.1 (including VK_LAYER_KHRONOS_validation, which was missing from the earlier run): pass

  • d3d12_descriptor_test (both validation off and LEONIDA_VK_VALIDATION=1): exit 0, 0 validation errors (A8_UNORM render targets: VK_FORMAT_A8_UNORM_KHR (VK_KHR_maintenance5), A8 render target: cleared and copied back, 64 texels matched, A8 render target: default and remapped views sampled, 64 texels matched each).
  • d3d12_clear_formats_test (both validation off and LEONIDA_VK_VALIDATION=1): exit 0, 0 validation errors (clears: 256 matched WARP, 0 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped (WARP does not offer the format)).
  • ctest -R "^(d3d12_descriptor|d3d12_clear_formats)$": 2/2 passed with validation off, and 2/2 passed with LEONIDA_VK_VALIDATION=1.

No game files used. AI-assisted testing.

@kapitche

Copy link
Copy Markdown
Collaborator Author

Checked in a retail boot as well: own copy of the retail executable, Windows 11 / RTX 4080 SUPER (driver 617.14), commit 064632428 cherry-picked into a local integration build (current main plus open boot PRs). The title's A8_UNORM render target is now created on VK_FORMAT_A8_UNORM_KHR (the [rt] line is logged), the earlier creation refusal is gone, and the run reaches the title's frame loop (about 410k D3D12 calls in 135 s). No other changes were needed for this resource.

@airp1ane

Copy link
Copy Markdown
Contributor

Tested 064632428 on Windows 11, NVIDIA GeForce RTX 4060 Ti (driver 621.24, Vulkan 1.4.357, Vulkan SDK 1.4.363.1), MSVC 19.52 (VS 18 / CMake + Ninja, RelWithDebInfo), with LEONIDA_VK_VALIDATION=1 (no game files): pass.

  • scripts/build_runtime.ps1: clean build.
  • d3d12_clear_formats_test.exe: PASS — enabled VK_FORMAT_A8_UNORM_KHR (VK_KHR_maintenance5); clears: 256 matched WARP, 0 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped.
  • d3d12_descriptor_test.exe: PASS — A8_UNORM render targets: VK_FORMAT_A8_UNORM_KHR (VK_KHR_maintenance5), A8 render target: cleared and copied back, 64 texels matched, A8 render target: default and remapped views sampled, 64 texels matched each, plus no-maintenance5 fallback refusal path exercised cleanly; 0 Vulkan validation errors.
  • Regression suite (d3d12_clear_test, d3d12_m2_formats_test, d3d12_resource_desc_test, d3d12_typeless_rtv_test, d3d12_draw_test, d3d12_com_test, all with LEONIDA_VK_VALIDATION=1): 6/6 PASS, 0 validation errors.
  • Merge check onto main 7ef2fdd46 (git merge-tree), git diff --check, and scripts/check_no_game_data.py: all clean.

AI-assisted.

@Cryserrrrr

Copy link
Copy Markdown

This adds the missing AMD data point: AMD Radeon iGPU of a Ryzen 7 7800X3D (RDNA2 gfx1036), AMD Windows driver 25.10.36, Windows 11, MSVC 14.51 RelWithDebInfo. PR head 0646324280 merged onto main 7761680ea (clean).

  • The driver exposes VK_KHR_maintenance5, and the layer takes the new path (A8_UNORM render targets: VK_FORMAT_A8_UNORM_KHR (VK_KHR_maintenance5)).
  • ctest -R "d3d12_descriptor|d3d12_clear_formats": 2/2 pass. d3d12_descriptor prints A8 render target: cleared and copied back, 64 texels matched and default and remapped views sampled, 64 texels matched each. d3d12_clear_formats goes from 251 to 256 matched WARP, 0 differ (the 5 new A8 cases). On main both pass with the old refusal.
  • RTX 4080 SUPER (610.88), same commands: 2/2 pass, same lines, 251 -> 256 matched, 0 differ.

(I see this is marked as a duplicate of #7403; the numbers are for this head only.) Synthetic tests, no validation layer. AI-assisted (Claude Code).

@PingasMech

Copy link
Copy Markdown

I compared #7593 (06463242) and #7403 (18b0bfba) after merging each separately with main at dde82f27. On the Intel UHD 770, both drew to an ordinary A8 target and returned the expected alpha bytes. Two differences are worth preserving in the close-out decision.

Same synthetic 4×4 draw #7593 #7403
Native Intel, ordinary A8 target All 16 texels matched in each draw: 255 without blending, 64 and 191 for the two blend equations Same
Native Intel, CreateCommittedResource3 with castable={A8_UNORM} E_INVALIDARG (0x80070057), no resource S_OK, all three readbacks also matched on this target
Profile with only optimal-tiling A8 blending removed Advertised RENDER_TARGET and cleared BLENDABLE. Ordinary unblended draw returned 255 on all 16 texels Cleared both support bits
Profile with A8 colour attachment also removed Cleared both support bits Cleared both support bits

The UHD 770 physically supports both rendering and blending. I checked the reported properties for all 180 formats before running the two Khronos Profiles controls. The ordinary/explicit-list comparison used the same draw fixture on both shims. In the no-blend profile, #7593’s own descriptor test also matched all 64 texels after whole/rectangle clears and all 64 through each of the default and remapped views. The six comparison runs emitted zero Khronos validation errors.

I’d retain #7403’s explicit-list handling and draw coverage. If the layer is intended to offer partial A8 support on devices without blending, #7593 supplies a working unblended path and a separate fallback-device test. For full D3D feature level 12.0, Microsoft lists both A8 render-target and blendable render-target support as required. Microsoft format-support table

Windows 11, Intel driver 32.0.101.7088, MSVC 19.44 Release, Vulkan SDK 1.4.363.0. Both PRs added five WARP-matching A8 clear cases. The full clear-format comparison still had the same ten sRGB differences as clean main. Synthetic fixtures only. AI-assisted review.

@Etr0p

Etr0p commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 0646324 merged onto main 5e54bda, natively on Windows 11 26200, MSVC 14.44 RelWithDebInfo, with LEONIDA_VK_VALIDATION=1: pass on both GPUs, 0 validation messages. #7403 (the same change, by @mrp1no) was run in the same batch on the same main; results are in my comment there.

GPUs: NVIDIA GeForce RTX 5070 Ti Laptop GPU (Blackwell, 621.24) and AMD Radeon 610M (RDNA2 gfx1036, AMD 26.11.2, a newer driver than @Cryserrrrr's 25.10.36, whose run had no validation layer). Both expose VK_KHR_maintenance5 and VK_FORMAT_A8_UNORM with colour attachment and blend in optimal tiling, so both take the new path.

test 5070 Ti 610M main
d3d12_clear_formats 256 matched WARP, 0 differ 256, 0 differ 251 on both
d3d12_descriptor_test pass: A8 render target: cleared and copied back, 64 texels matched and default and remapped views sampled, 64 texels matched each. The in-test control prints A8_UNORM render targets not supported (no VK_KHR_maintenance5 A8 colour attachment) on its maintenance5 = false device same pass
d3d12_draw_test pass (unchanged here; its device does not request maintenance5, so it prints the not-supported line) same pass

Differences from #7403 (head 18b0bfb), read from the diffs: #7403 adds an alpha-only 8_UNORM row to gfx10_descriptors.h, where this PR moves R to A in bind_image. #7403 enables maintenance5 for every test device, where here it is opt-in with a fallback control. #7403 has a draw/blend test and the A8 castable list. This PR allows an A8 render target that cannot blend (RENDER_TARGET without BLENDABLE). @PingasMech's table above shows the castable-list and no-blend differences on Intel.

Synthetic tests only, no game files. AI-assisted (Claude Code).

zneel added a commit to zneel/Leonida that referenced this pull request Nov 23, 2026
# Conflicts:
#	runtime/test/vk_test_device.h
zneel added a commit to zneel/Leonida that referenced this pull request Nov 23, 2026
…does, on top of ItsNotRexed#7593

With ItsNotRexed#7593 merged the retail boot gets past the 2D A8_UNORM render target, then device slot 25 sizes a
128-texel 1D A8_UNORM texture with no flags and the layer answers UINT64_MAX (texture_format refused every
non-2D A8). The title asserts on the size's upper 32 bits. ItsNotRexed#7755 makes 1D and 3D A8 textures R8 images as
the host does; its change conflicts only textually with ItsNotRexed#7593's A8 block, so it is applied by hand: a
non-2D A8 render target stays refused, FORMAT_SUPPORT names TEXTURE1D and TEXTURE3D.

d3d12_descriptor_test: 1D (128) and 3D (128x8x4) A8 textures without flags are sized and created, with the
render-target flag refused (passes with LEONIDA_VK_VALIDATION=1 on an RX 9070 XT).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Stalkerino

Copy link
Copy Markdown

Linux retail and synthetic results for 064632428 on an RX 9070 XT (RADV GFX1201), Proton CachyOS 11.0-20261015 and Gamescope.

In the retail 1.0.2.1 trace, my baseline with #7880 and #7286 reports GetResourceAllocationInfo format not supported yet: 65. With this PR's changes on the same base, the runtime enables its native A8 path and that warning disappears. Around the corresponding point we now also see a successful resource creation and an RTV creation. Both runs reached two successful ExecuteCommandLists calls and the game remained at Game Init, engine frame 0, with a black window. The trace does not identify this format as the sole cause of the black screen.

I queried RADV independently. It reports maintenance5, sampled-image, color-attachment and color-attachment-blend support for A8_UNORM, and accepts the 2D sampled + color-attachment image query. Under Proton the descriptor test cleared and copied back the A8 render target with 64/64 texels matching, and sampled 64/64 texels through each of the default and remapped views. The test's maintenance5-disabled control exercised the refusal path. AI-assisted testing.

@o-psi

o-psi commented Nov 23, 2026

Copy link
Copy Markdown

Thank you for the A8 support. For the #8919 cleanup (#8919), I suggest grouping this with #740314a459b as the candidate to retain for its castable-list handling and draw/blend coverage. Before closing #75930646324, please preserve its unblended A8 path, explicit disabled-feature and RT+UAV checks, invalid-R8-RTV assertion, and rectangle-clear/copy/SRV test. The full diffs still differ in these useful ways; the side-by-side evidence is #7593 (comment). Keep #8626 slot-25 coverage as a separate dependent test. agent: yes

PR cleanup: #8919 (comment)

agent: yes

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.

10 participants