Skip to content

d3d12: A8_UNORM textures in 1D and 3D, as the host runtime makes them - #9336

Open
tibzejoker wants to merge 2 commits into
ItsNotRexed:mainfrom
tibzejoker:a8-1d-3d
Open

tibzejoker wants to merge 2 commits into
ItsNotRexed:mainfrom
tibzejoker:a8-1d-3d

Conversation

@tibzejoker

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #9235 (comment)

What was wrong

texture_format accepted A8_UNORM only as a single-sampled 2D texture. The host runtime makes it in all three dimensions. Measured with a stand-alone D3D12 program on an RTX 4090 (617.42) and on WARP:

  • CheckFeatureSupport(FORMAT_SUPPORT) reports TEXTURE1D, TEXTURE2D and TEXTURE3D for A8_UNORM on both.
  • For a 128x1x1 texture, GetResourceAllocationInfo answers 64 KiB in every dimension, or 4 KiB when the description asks for the 4 KiB alignment, and CreateCommittedResource succeeds.

The retail title sizes a 1D 128-texel A8_UNORM texture through device slot 25, with Alignment 4096 and then 0. I measured it with a temporary log on slot 25, on my integration branch, which carries #7679 and #7009. The layer answered UINT64_MAX to both, and the title stopped on its check that the size fits in 32 bits (int3 at +0x344196, the same check #7679 hit with its depth texture).

The change

  • 1D and 3D A8_UNORM textures now take the 2D path: an R8 image read through the (0, 0, 0, A) swizzle in image_descriptor. That swizzle depends only on the resource format, not the dimension.
  • Format support reports TEXTURE1D and TEXTURE3D alongside TEXTURE2D.
  • Unchanged: render targets, depth and UAVs stay refused. So do multisampled textures.
  • Docs: docs/d3d12_vulkan.md describes the three dimensions.

Tested

On an RTX 4090 (617.42), Windows 11 26200, MSVC 2022 RelWithDebInfo, with LEONIDA_VK_VALIDATION=1 and no validation errors.

New d3d12_a8_dimensions_test:

  • It compares, against the host adapter and WARP, the format-support dimension bits and, for 1D, 1D array, 2D and 3D shapes (some with mips) with and without the 4 KiB alignment, that every description a reference sizes and creates is sized by the layer with the reference's alignment.
  • It copies a byte pattern into every subresource and back: 1,681 texels come back unchanged.
  • It checks that RT, DS and UAV stay refused in every dimension.
  • Result: 12 descriptions sized and 0 failures. Without the fix it fails 12 checks.

Other tests on the same build:

  • These pass: d3d12_descriptor (the existing 2D A8 sampling checks), d3d12_texture1d_target, d3d12_placed_dimensions, d3d12_subresource_copy, d3d12_clear_formats, device_proxy and xs_proxy_mock.
  • d3d12_vulkan_device fails, but it fails on main 867d922 as well, with output identical line for line to this branch's.

Synthetic only, no game data. The retail result with this change on my integration branch will follow as a comment.

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

The layer accepted A8_UNORM only as a single-sampled 2D texture. The host runtime reports TEXTURE1D,
TEXTURE2D and TEXTURE3D for it and sizes and creates all three (RTX 4090 617.42 and WARP). The retail
title sizes a 1D 128-texel A8_UNORM texture through device slot 25, got UINT64_MAX and stopped on its
32-bit size check.

1D and 3D A8 textures now take the same path as 2D: an R8 image read through the alpha swizzle, which
does not depend on the dimension. Format support reports the three dimension bits. Render targets,
depth and UAVs stay refused.

d3d12_a8_dimensions_test compares format support, sizes and alignments with the host adapter and WARP
(1D, 1D array, 2D, 3D, with and without the 4 KiB alignment) and round-trips a byte pattern through
every subresource. Without the fix it fails 12 checks.

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

@Grimkeh Grimkeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Independent Linux CPU review

Checked: A8_UNORM textures allowed in 1D/3D as on host; docs + d3d12_a8_dimensions_test + CMake. Windows/D3D12 harness not run here.

Looks correct from review; no game files.

@tibzejoker

Copy link
Copy Markdown
Contributor Author

Retail check on i9-13900K + RTX 4090 (617.42), own 1.0.2.1 copy, LEONIDA_D3D12=vulkan, LEONIDA_STUB_PIPELINES=1. Branch: tibzejoker:rt5-integration (about 50 open PRs, including #7679 and #7009) plus this PR. The integration branch also carries the A8 render-target path, so the hunk in texture_format needed a hand merge there. Sampled A8 is now allowed in 1D, 2D and 3D, and A8 render targets stay 2D.

  • Without this PR: slot 25 answers UINT64_MAX for the 1D 128-texel A8_UNORM texture, and the run stops at the int3 at +0x344196 with 52,557 D3D12 calls and 7 ExecuteCommandLists.
  • With it: no slot-25 refusal is logged for that texture, and the frame loop runs. In the longest run: 290 s, 71,364 D3D12 calls and 388 ExecuteCommandLists, ending on the title's own hang watchdog. The run-to-run order varies, and another run still hit the same +0x344196 check at 54 s, through a different caller.
  • Next measured gate: about half the frame lists fail Close. With a temporary line tag, the first invalid call is record_draw without a graphics pipeline, the result of the refused amplification-shader PSOs (@bobcatchris's "AS pipelines" item in Coordinating who works on what (54) (moved to #9065) #8868).

AI-assisted (Claude Code).

@egexon

egexon commented Nov 23, 2026

Copy link
Copy Markdown

Tested c31e639 (merged onto main 867d922) on RTX 5070, NVIDIA 621.24, Windows 11 (build 26200), Vulkan validation layer on (LEONIDA_VK_VALIDATION=1, VK_VALIDATION_VALIDATE_SYNC=1): pass.

  • d3d12_a8_dimensions_test: new test; passes with this PR.

Ran the tests that belong to the test files this PR changes (ctest entries, or the test program directly when it is not registered), with no game files (LEONIDA_GAME_DIR unset). AI-assisted (Claude Code).

@YordiLorenzo

Copy link
Copy Markdown

Tested c31e639 on RTX 4070 SUPER, NVIDIA 621.01, Windows 11 Pro: pass

  • Build RelWithDebInfo, MSVC + Ninja, Vulkan SDK: ok
  • ctest -R "a8|d3d12_vulkan_device|alpha" with LEONIDA_VK_VALIDATION=1: d3d12_a8_dimensions and vk_texture_cube_alpha pass, 0 validation errors
  • d3d12_a8_dimensions -V: 12 descriptions sized, 1681 texels round-tripped, 0 failures
  • d3d12_vulkan_device fails at line 6574 (tiles == 1), same on main, d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125 fixes it, so not from this PR
  • Negative control, the new test with main's d3d12_vulkan_device.cpp: 12 failures, only the 2D descriptions sized

@ikurta92-png

Copy link
Copy Markdown

Tested c31e63969 on NVIDIA GeForce RTX 3060 (Ampere), driver 617.42, Windows 11 Pro 10.0.26300, MSVC 19.51 (VS 2026), RelWithDebInfo, Vulkan SDK 1.4.363.1: pass; one size difference the test doesn't look at (3D, 4 KiB alignment).

  • This PR, LEONIDA_VK_VALIDATION off and on, 2 runs each: d3d12_a8_dimensions passes, A8_UNORM dimensions: 2 references, 12 descriptions sized, 1681 texels round-tripped, 0 failures (references: the RTX 3060 through native D3D12, and WARP). d3d12_descriptor passes. No validation messages in the output. The new test doesn't count them itself (no validation_errors() check, no FAIL_REGULAR_EXPRESSION), so a validation error would not fail it. d3d12_vulkan_device fails at line 6574: tiles == 1, the same as on main (the d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125 case).

  • Control (runtime/shims/d3d12_vulkan_device.cpp from the parent 867d922f0, validation on): exit 1 with 12 failures. A8_UNORM dimension support 0x20, NVIDIA GeForce RTX 3060 reports 0x70 (and the same for WARP), and all ten 1D/3D descriptions sized 18446744073709551615 (UINT64_MAX).

  • Sizes: the test compares Alignment with WARP, and checks only that SizeInBytes != UINT64_MAX (the doc line says it "also compares sizes"). I printed all three sizes locally (temporary printf, reverted). Every description matches, except these two with Alignment = 4096:

    description layer RTX 3060 (native) WARP
    1D 300, 3 mips 8192 8192 4096
    3D 16x8x4, 2 mips 8192 4096 4096

    So the 3D one is sized one 4 KiB page larger than both references. Larger is the safe direction, and I haven't checked whether other 8-bit formats size the same, so it may be the general 3D small-alignment sizing rather than anything A8-specific. If the test should pin sizes, the 1D case shows the host and WARP don't always agree.

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

…say alignments, not sizes, are compared

From review on ItsNotRexed#9336 (@ikurta92-png): the test counted no validation errors, and the docs said it compared sizes
where it compares only that each description is sized, with WARP's alignment. The sizes stay unpinned: the host
adapter and WARP differ on some small-alignment ones (1D 300 x3 mips at 4 KiB: 8192 vs 4096).

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

Copy link
Copy Markdown
Contributor Author

@ikurta92-png thanks, both points were right. f97ea2a0d:

  • Validation errors: the test now fails on any Vulkan validation error and prints the count (0 on the RTX 4090 with LEONIDA_VK_VALIDATION=1).
  • Docs: they now say what the test actually checks: every description a reference sizes gets a size, with WARP's alignment. The sizes stay unpinned, for the reason you showed: the host and WARP disagree on 1D 300x3 at 4 KiB.
  • The 3D 16x8x4, 2-mip size at 4 KiB alignment (8192 against 4096) comes from the layer's general small-alignment 3D sizing. It isn't specific to A8, and erring larger is the safe side, so I left it out of this PR. It's worth its own item.

@egexon @YordiLorenzo thanks for the RTX 5070 and 4070 SUPER runs. AI-assisted (Claude Code).

@MiguelMatMar

Copy link
Copy Markdown

Tested f97ea2a on NVIDIA GeForce RTX 4080 SUPER, driver 621.24 (Vulkan 1.4.357), Windows 11 Pro 26300, MSVC 14.44, Ninja RelWithDebInfo (fresh build folder), applied on main 6312c05, no game data: pass.

  • ctest -R ^d3d12_a8_dimensions$: passed.
  • Negative control: only the test-side files applied (no source change): d3d12_a8_dimensions fails.

Overlap: #7755 by @NiiRoZz (open, mergeable, head 952be9b) has the same title and edits the same four files, down to the same new test name runtime/test/d3d12_a8_dimensions_test.cpp, with a different implementation. Its own test also passes on this GPU. Whichever lands first will conflict with the other, so a maintainer should pick one. This PR doesn't mention #7755.

(AI-assisted check, Claude Code.)

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.

6 participants