Skip to content

d3d12: A8_UNORM render targets through VK_FORMAT_A8_UNORM_KHR, again (RT-A8-TARGET) - #428

Closed
Mumogg wants to merge 2 commits into
ProjectLeonida:mainfrom
Mumogg:a8-render-target
Closed

Mumogg wants to merge 2 commits into
ProjectLeonida:mainfrom
Mumogg:a8-render-target

Conversation

@Mumogg

@Mumogg Mumogg commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Claimed in #14 as RT-A8-TARGET. Independent of my other open pull requests: it is based on main alone and touches the Vulkan layer, not the proxy.

What and why

The retail title's first native pipelines name an A8_UNORM render target, and it sizes one at 3840 x 2160 through device slot 25. main stores every A8_UNORM texture as R8_UNORM and refuses it as a render target: the log says GetResourceAllocationInfo format not supported yet: 65, slot 25 answers UINT64_MAX, and a worker thread of the title stops on its own int3.

Two commits by mrp1no (-x, authorship kept; ancestors of main whose content is not in the tree):

  • 67950a8d5: where the GPU has VK_KHR_maintenance5 and can sample VK_FORMAT_A8_UNORM_KHR and blend it as a colour attachment, an A8_UNORM texture created with ALLOW_RENDER_TARGET is stored in that format; its views, the format support answers and the copy paths follow. Other A8_UNORM textures stay R8_UNORM, and a device without the format refuses A8 render targets as before.
  • 18b0bfbaf: an A8 render target's castable list takes its own format and refuses the others.

The first commit conflicted in two places. In d3d12_vulkan_device.cpp it was written against the older r9g9b9e5_as_r32_uint member that main has since replaced with uint_backed: I kept main's member and added only the commit's a8_as_alpha next to it, and in the render-target-view code the A8 case goes before main's uint_backed cases. In vk_test_device.h both extensions are enabled.

Measured

Linux (Nobara 44, kernel 7.3), Wine 11.21 staging, RTX 5070 Ti (driver 615.78.08, has VK_KHR_maintenance5), clang-cl 22.1.8 + xwin SDK 10.0.26100, own 1.0.2.1 copy, network off. The boot runs are on main ece4ba5b3 with my stacked pull requests and #142, #219, #328 and #387, because the stop is only reached that far in.

--run Traced calls CreatePipelineState ok Ends with
without this 12,043 6 the worker thread's int3 on the refused size
with this 62,596 50,450 a call through a null pointer, during the pipeline creations

So this is what lets the title go on to create its pipelines on this path. The null call that ends the run is a queue method forwarded to the wrong PC method; that is my pull request for RT-QUEUE-SIGNAL.

Tests under Wine, the four the first commit touches:

Test Result
d3d12_descriptor passed
d3d12_draw passed
gfx10_descriptors passed
d3d12_clear_formats failed, as it does on plain main under this Wine

Not built with MSVC and not run on Windows, and not run on a GPU without VK_KHR_maintenance5.

AI-assisted (Claude Code); built and run on the machine above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt

mrp1no and others added 2 commits November 23, 2026 22:55
…_maintenance5)

The retail title's first native pipelines name an A8_UNORM render target
(@KkelebekK's RT-5 measurements). The layer stored every A8_UNORM texture as
R8_UNORM with a swizzled SRV and refused render targets.

Where the GPU has VK_KHR_maintenance5 and can sample VK_FORMAT_A8_UNORM_KHR and
blend it as a colour attachment, gta6rt enables the extension and its feature
(VulkanDeviceInfo::a8_render_target), and an A8_UNORM texture created with
ALLOW_RENDER_TARGET is stored in that format:
- its RTVs and the PSO's RTVFormats use it, so draws, blends and clears write
  the alpha channel (the clear quantizes alpha like the other UNORM formats);
- its SRVs view the image in the same format. Vulkan puts A8 in a compatibility
  class of its own, so it cannot share an image with an R8 view: gfx10's format
  table gains an 8_UNORM row for it whose one channel X is alpha (channels_a),
  and the T#'s (0, 0, 0, X) becomes (ZERO, ZERO, ZERO, A) on that view;
- CheckFeatureSupport adds RENDER_TARGET and BLENDABLE for A8_UNORM;
- the copy paths know its one-byte texel.
Other A8_UNORM textures stay R8_UNORM, and devices without the format refuse
A8 render targets as before. Depth-stencil and UAV stay refused.

Tests (both on an RTX 3060 and an Intel UHD 750, with Vulkan validation):
- d3d12_clear_formats: A8_UNORM joins the WARP comparison (was "not exposed");
- d3d12_descriptor_test: format support and creation follow the device; an A8
  render target's default and remapped SRVs sample like the R8-backed ones;
- d3d12_draw_test: a full-screen draw and two alpha blends into an A8 target;
- gfx10_descriptors_test: the A8 row and its view mapping.
vk_test_device.h enables maintenance5 like gta6rt, so the whole suite runs
with it: ctest gives the same failures as main on both GPUs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 67950a8)
…efuses the others

castable_view_formats() mapped every castable format through vulkan_format(), which has no
A8_UNORM case, so CreateCommittedResource3/CreatePlacedResource2 with castable={A8_UNORM}
failed with E_INVALIDARG ("castable format not supported yet: 65"). The resource's own format
is always viewable (create_texture adds the image's format), so naming A8_UNORM on an A8
texture is now a no-op.

An A8 render target's VK_FORMAT_A8_UNORM_KHR image is in a compatibility class of its own,
so an R8_UNORM castable entry (same texel size) would have reached its
VkImageFormatListCreateInfo. Any format other than A8_UNORM is now refused with E_INVALIDARG
before Vulkan.

The A8 gate (runtime and vk_test_device.h) also requires TRANSFER_SRC/DST, since every
texture is created with transfer usage.

d3d12_draw_test runs the A8 clear/draw/blend cases on a second target made through
CreateCommittedResource3 with castable={A8_UNORM}, and checks castable={R8_UNORM} returns
E_INVALIDARG. Without the shim change it fails with the reported message.

Reported by tupacfan04 on #7403.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 18b0bfb)
@moffington

Copy link
Copy Markdown
Contributor

Reviewed 49b750a and tested under Wine on Linux with an RTX 3060. I found two Vulkan validation issues:

  • CopyResource and CopyTextureRegion between a renderable A8 texture and an ordinary A8 texture issue A8↔R8 Vulkan image copies. The bytes matched on my driver, but validation reported errors; a same-backing control removed them.
  • Building against Vulkan-Headers 1.4.304, the standalone runtime advertises and uses A8 without enabling maintenance5. Moving the extension enable outside the maintenance8 guard removed the validation errors.

Eight of nine focused tests passed on both the PR and baseline. d3d12_clear_formats failed on both: the PR also had five A8 differences against Wine's hardware reference. An independent readback showed Leonida writing alpha and the Wine reference writing red, so I can't treat those differences as a confirmed Leonida defect.

A red-for-alpha mutation failed the checked-in draw test. I did not test the stacked retail boot path.

AI-assisted review and validation.

@Tyrannys

Copy link
Copy Markdown
Contributor

A 1D A8_UNORM texture is refused. On native Windows, with this PR stacked on main and the other carved pieces (details in #321), the title's GetResourceAllocationInfo gets a TEXTURE1D A8_UNORM, 128x1, 1 mip, 1 sample, flags 0. texture_format() returns {} for any A8 that isn't TEXTURE2D (GetResourceAllocationInfo format not supported yet: 65). The title then stops on an int3.

Only the alpha render target needs single-sampled 2D. A sampled-only A8 texture already falls through to texture_storage_format() as R8_UNORM, and its views select X into alpha whatever the dimension. With this change the run got past that stop and was still in its frame loop at 300 s:

         if (desc.Format == DXGI_FORMAT_A8_UNORM) {
-            if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count != 1 ||
-                (desc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)))
+            if (desc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
+                return {};
+            // Only the alpha render target is limited to single-sampled 2D. A sampled-only A8 texture is an R8 image
+            // of any dimension (the retail title asks for a 128x1 TEXTURE1D one); its views select X into alpha.
+            if ((desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) &&
+                (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count != 1))
                 return {};

This is checked only by the title getting past that stop. There's no unit test for 1D A8 sampling yet, and I haven't checked the sampled values. AI-assisted (Claude Code).

demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…_UNORM render targets through VK_FORMAT_A8_UNORM_KHR, again (RT-A8-TARGET) [Mumogg]
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…da#441 and ProjectLeonida#444 to the repository's own checks

Four standard-library tests that pass on upstream main failed after merging:
- test_sad_diff: its harness canary expected `v_sad_u8 ... clamp` to be rejected;
  ProjectLeonida#275 translates clamp on the SAD ops now, so that canary is dropped (the qsad
  clamp and the two quad-operand canaries still reject).
- test_gfx10_descriptors: ProjectLeonida#428's A8_UNORM row carried a note after the format
  name; the note moves to its own comment line so the row parses.
- test_docs_env_vars: ProjectLeonida#441's LEONIDA_TITLE_MEMORY_MB is documented in
  docs/retail_boot_intel_host.md section 2 (the commit-limit stop it is for).
- test_cmake_translator_deps: ProjectLeonida#444's cs_upload_read rule runs build.py, so it
  depends on ${LEONIDA_TRANSLATOR_DEPS} like the other build.py rules.

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

Copy link
Copy Markdown
Contributor

A small addition for this PR, found booting the retail executable on top of it: the title also asks for a sampled-only A8_UNORM TEXTURE1D (128x1), and texture_format refuses every A8 that is not single-sampled 2D, so its GetResourceAllocationInfo fails. Only the render-target case needs that limit; a sampled A8 is an R8 image of any dimension whose views swizzle X into alpha:

        if (desc.Format == DXGI_FORMAT_A8_UNORM) {
            if (desc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
                return {};
            // Only the alpha render target is limited to single-sampled 2D. A sampled-only A8 texture is an R8 image
            // of any dimension (the retail title asks for a 128x1 TEXTURE1D one); its views select X into alpha.
            if ((desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) &&
                (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count != 1))
                return {};

With it the allocation succeeds and boot goes on (Windows 11, RTX 4070 SUPER). Feel free to fold it in; I can open a separate PR instead if you prefer.

AI-assisted (Claude Code).

@Dezmonius

Copy link
Copy Markdown
Contributor

Confirmed the mixed-backing copy issue from the earlier review on native Windows 10 22H2 (19045), RTX 5070 / NVIDIA 610.88, and MSVC 19.51.36256. Tested #428 head 49b750a95 with Khronos validation layer 1.4.369 enabled.

The synthetic probe uses two 4x4 D3D12 DXGI_FORMAT_A8_UNORM textures. The render target is backed by VK_FORMAT_A8_UNORM_KHR; the ordinary texture is backed by VK_FORMAT_R8_UNORM. It uploads a known pattern, copies either the whole texture or a 3x3 region with a nonzero source offset, then reads the destination back.

D3D12 copy A8→R8 and R8→A8 A8→A8 and R8→R8
CopyResource 16/16 texels matched in each direction; one VUID-vkCmdCopyImage-srcImage-01548 per run 16/16 matched; zero validation errors
CopyTextureRegion 9/9 texels matched in each direction; same VUID once per run 9/9 matched; zero validation errors

The checked-in d3d12_descriptor, d3d12_draw and d3d12_clear_formats tests also passed with validation enabled. This check covers mixed-format copying. The separate maintenance5 extension-enable finding was outside this run.

Synthetic data only; no game files or retail boot. AI-assisted (Codex).

@Dezmonius

Copy link
Copy Markdown
Contributor

Follow-up to my Windows validation report above: I tested a local proof of concept on 49b750a95 that routes the two mixed A8/R8 backing directions through the existing image → transfer scratch buffer → image path in runtime/src/vulkan_replay.h. Same-format copies still take the existing path.

On Windows 10 22H2, RTX 5070 / NVIDIA 610.88 and Khronos validation 1.4.369, the four previously failing synthetic copy runs now produce zero validation errors and all texels match (16/16 for CopyResource, 9/9 for the offset CopyTextureRegion, in both directions). All four same-backing controls are still clean.

Five checked-in tests passed with validation enabled: d3d12_descriptor, d3d12_draw, d3d12_clear_formats, d3d12_copy_xfmt and d3d12_subresource_copy. The proof of concept covers single-sampled textures and the copy finding. The separate maintenance5 enablement finding was outside the experiment.

Synthetic results only. AI-assisted (Codex).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 24, 2026
@Daolyap

Daolyap commented Nov 24, 2026

Copy link
Copy Markdown

Measured a case this PR refuses that it should accept, on the retail 1.0.2.1 title (native Windows, RTX 3070, driver 32.0.16.1692, with the #432 stack this PR is part of).

DeviceState::texture_format applies the render-target limits (single-sample TEXTURE2D, no depth-stencil, no UAV) to every A8_UNORM texture before it checks ALLOW_RENDER_TARGET. The title creates a plain 128×1 TEXTURE1D A8_UNORM with no flags, which this returns {} for. Slot 25 then answers UINT64_MAX (GetResourceAllocationInfo format not supported yet: 65), and the title stops on an int3 at game_scarlett_master.exe+0x344196. It looks like the same assert RT-A8-TARGET describes, but for a texture that isn't a render target. The struct comment and texture_storage_format already say non-render-target A8 textures are R8_UNORM images; this early return just keeps them from getting there.

Moving the limits into the render-target branch fixes it:

         if (desc.Format == DXGI_FORMAT_A8_UNORM) {
-            if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count != 1 ||
-                (desc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)))
-                return {};
+            // Only the render-target form has limits of its own (a single-sample 2D VK_FORMAT_A8_UNORM_KHR image).
+            // Any other A8_UNORM texture is an R8_UNORM image below, whatever its dimension.
+            if (desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) return {};
             if (desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) {
+                if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count != 1 ||
+                    (desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
+                    return {};
                 if (!info.a8_render_target) {

With that change, plus the runtime-device pipeline cache from #1308, the boot runs its frame loop for the whole 10-minute window I gave it: 13,838 PresentX ok, 55,353 ExecuteCommandLists, no exception. One thing I haven't checked: whether a non-render-target A8 texture with ALLOW_UNORDERED_ACCESS should also go to R8 (this patch lets it, since R8_UNORM has storage support). Happy for you to take it into this PR, or I can open a follow-up once this lands. AI-assisted (Claude Code).

@Mouad-Scriptz-0

Copy link
Copy Markdown

This conflicts with main, and it's on the path to the frame loop, so here's a rebase to save a step: rebased/pr428 (f02056610). It has the same 2 commits and authors on main 4a50cafc7. git range-diff against this branch shows no commit's own change was altered.

Both conflicts were add/add. I kept both sides:

  • runtime/shims/d3d12_vulkan_device.cpp, render-target loop: this PR's A8 choice (VK_FORMAT_A8_UNORM_KHR when a8_render_target), then main's B4G4R4A4 → RGBA8 fallback, then the existing VK_FORMAT_UNDEFINED refusal, unchanged.
  • runtime/test/vk_test_device.h: main's request_depth_range_unrestricted / depth_range_unrestricted, then this PR's a8_render_target.

Not compiled or run here: I have no Windows SDK on this machine, so CI is the first build.

To take it (maintainer edits are on):

git fetch https://github.com/Mouad-Scriptz-0/leonida rebased/pr428
git push --force-with-lease=a8-render-target:49b750a95 https://github.com/Mumogg/leonida-continued FETCH_HEAD:a8-render-target

AI-assisted.

@aslan2142

Copy link
Copy Markdown
Collaborator

Closing as carried: main has A8_UNORM render targets since #984's integration, so there is nothing left to merge.

  • An A8 render target is a VK_FORMAT_A8_UNORM_KHR image under VK_KHR_maintenance5 (runtime/shims/d3d12_vulkan_device.cpp), with the castable-list rule, and the GFX10 8_UNORM descriptor row for it is in runtime/src/gfx10_descriptors.h.
  • Both review findings are fixed there: copies between the A8 and R8 backings go through a buffer (d3d12_a8_copy_test), and maintenance5 is enabled under its own guard.
  • A line-by-line check against current main finds 287 of the 293 lines this adds; the rest are comment wording.

Thanks to mrp1no, and to moffington and Dezmonius for the reviews.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142 aslan2142 closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants