Skip to content

D3D-81: sample A8_UNORM textures through the alpha channel - #674

Merged
ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
VictorJulianiR:codex/sample-a8-unorm-textures
Nov 22, 2026
Merged

ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
VictorJulianiR:codex/sample-a8-unorm-textures

Conversation

@VictorJulianiR

@VictorJulianiR VictorJulianiR commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

D3D-81, claimed on #634.

Single-sampled A8 textures use one byte per texel in a Vulkan R8_UNORM image. The SRV places that byte in alpha before applying the caller's component mapping. Ordinary R8 retains its red channel. The layer rejects incompatible typed views and unsupported A8 attachment, multisample and UAV requests. A separate descriptor heap holds the four A8/R8 channel-mapping views and a fifth view starting at A8 mip 1. The format query reports MIP when the Vulkan physical device supports multiple levels for the backing image.

Resource Default SRV, RGBA Custom SRV (alpha, red, one, zero)
A8_UNORM (0, 0, 0, a) (a, 0, 255, 0)
R8_UNORM (a, 0, 0, 255) (255, a, 255, 0)

Current revision e9a8203 against main 8df277f. The merge keeps the shared HRESULT tracing and the 3D volume mip tests. On Windows Server 2022 with MSVC, Mesa 26.3.1 llvmpipe and Khronos validation, the descriptor test matched all 320 A8/R8 samples, the 128 volume samples and 64 samples each for B4 and B5. Native D3D12 WARP independently matched all 320 A8/R8 samples. Vulkan descriptor test · Native WARP readback.

All 16 A8 footprint records matched WARP (eight subresources at two base offsets). Selecting mip 0 instead of mip 1 and removing the MIP capability each failed its respective assertion. The full device test on this runner exits 1 at the same three feature-query comparisons on the candidate and unmodified main: shader models 6.8 and 6.9, and root signature 1.2. Footprints and controls · Stock main comparison.

Earlier revisions

  • Native D3D12 WARP and the refreshed head be283d1 on Mesa llvmpipe 26.3.1 / LLVM 23.1.5 produced the same result for all four views, 64 texels each. The Vulkan run used Khronos validation. Removing the A8 swizzle and removing the original null-descriptor write each failed its intended check. Native WARP · Standalone shim and controls.

  • An automatic merge with D3D-68: verify B5G5R5A1 shader sampling and odd-width footprints #617 passed all 256 A8/R8 texels plus the existing and packed format readbacks. Native D3D12 footprint and tiling comparisons returned zero mismatches. The full device executable still exits 1 at the same resolve comparison as main because the host command list on this runner lacks ID3D12GraphicsCommandList7. Combined run · Unmodified main.

  • On ff354a5, an 8×8 A8 texture carries different alpha values in mip 0 and mip 1. A view starting at mip 1 matched 64 samples across all 16 texels. The other four views still matched their 256 expected RGBA samples. Forcing the fifth view back to mip 0 or removing the MIP feature bit failed the corresponding assertion. A native D3D12 WARP reference independently matched all 320 samples. Validated Vulkan shim · Native D3D12 WARP.

Supplemental Windows integration. A scratch merge of #617, #674, #700, #736, #757 and #758 with the independent #713 dependency pin and #717 host resolve comparison change produced tree 73e526ac. On Windows Server 2022 with llvmpipe and validation, all 29 registered CTest entries passed. The descriptor test matched the 64 B5 samples, the four original A8/R8 views and all 64 A8 mip-1 samples. The device test compared 10 supported resolve cases with the host, skipped 45 unavailable cases and found zero mismatches. Eight-PR integration run.

AI-assisted. Tested with synthetic 2D textures on GitHub-hosted Windows Server 2022, MSVC, native WARP and software Vulkan.

@VictorJulianiR VictorJulianiR changed the title D3D-61: sample A8_UNORM textures through the alpha channel D3D-81: sample A8_UNORM textures through the alpha channel Nov 22, 2026
@Derpbeat

Copy link
Copy Markdown
Contributor

Tested 3dde44e (and before it ed7e1ea; the shim change is the same in both) on an NVIDIA GeForce RTX 4090 (driver 617.14), Windows 10 22H2, MSVC 19.39, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1: pass, with one question about format support. (D3D-81.)

  • Build: no new warnings. ctest: 28/28 with validation at 3dde44e (27/27 at ed7e1ea).
  • d3d12_descriptor_test: pass, 0 validation messages. d3d12_vulkan_device_test passes too, including the new A8 footprint case (its two host comparisons made non-fatal locally for Windows 10, see Coordinating who works on what (3) (moved to #1006) #634).
  • Negative control (at ed7e1ea): with the shim put back to c432cdc, d3d12_descriptor_test fails at line 336: SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, ...)).

Format support compared with the host runtime. On the same RTX 4090, the native D3D12 runtime reports for A8_UNORM: TEXTURE1D TEXTURE2D TEXTURE3D TEXTURECUBE SHADER_LOAD SHADER_SAMPLE SHADER_GATHER MIP RENDER_TARGET BLENDABLE MS_RENDERTARGET MS_LOAD MS_RESOLVE TYPED_UAV (Support1 = 0x02e4d3f0). This PR reports TEXTURE2D | TEXTURECUBE | SHADER_LOAD | SHADER_SAMPLE. Leaving out render target, UAV, multisample, 1D and 3D matches what the PR refuses, so that's consistent. But:

  • MIP is missing, although mipped A8 textures are accepted, and the footprint case uses four mips. An app that checks MIP before creating a mipped A8 texture would think it can't.
  • SHADER_GATHER is missing. I didn't test whether a gather through the (0, 0, 0, R) swizzle returns alpha, so this may be deliberate.

Since render targets are refused, a short note in docs/d3d12_vulkan.md saying A8 RTVs are a known gap might also help (the native runtime does support A8 RTVs on this GPU).

AI-assisted (Claude Code); repository tests and a small native CheckFeatureSupport probe only, no game files.

@matheuskshn

Copy link
Copy Markdown
Contributor

Code review at 3dde44e. The A8 path composes (0,0,0,R) before applying the view swizzle and keeps the R8 typed-view guard. To resolve the MIP feature-query gap noted above, I suggest an A8 texture with two distinct alpha values in separate mips. Sampling mip 1 through an SRV would verify that the feature bit reflects an actual view and sampling path, beyond footprint support alone. AI-assisted code review.

@VictorJulianiR

Copy link
Copy Markdown
Contributor Author

@Derpbeat and @matheuskshn, ff354a5 now queries how many mip levels the backing R8 image supports and exposes MIP when multiple levels are available. The fifth SRV selects mip 1 of an A8 texture. Its 16 distinct alpha values all appeared in the readback, and redirecting just that view to mip 0 failed the test. Both the shim and native WARP matched 320/320 RGBA samples across the five views. The advertised gather and render-target capabilities are unchanged. Thanks for identifying the query gap and suggesting a test that distinguishes the levels. Shim and controls · Native reference.

@quackottu

Copy link
Copy Markdown
Contributor

Tested e9a8203 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

@VictorJulianiR

Copy link
Copy Markdown
Contributor Author

Could a maintainer rerun just the failed Wine job on e9a8203? The required run_tiny_game_exit_code case printed exit code 1, but Wine returned 0. @ayozetr previously observed the same symptom on unmodified main in two of three full runs. Original finding.

I reran the exact Windows artifacts from this PR, main and #736 on GitHub-hosted Ubuntu 24.04 with Wine 9, twice per artifact. Each full suite used a fresh prefix and the original six required tests. All six requirements passed in all six suites, including both runs of the previously failing artifact. Each reported 26 of 32 registered tests passing, with the same six non-required failures. The two runners used opposite orders. Main-first results · PR-first results.

@ItsNotRexed
ItsNotRexed merged commit afda786 into ItsNotRexed:main Nov 22, 2026
9 of 10 checks passed
@JavierBlanco23

Copy link
Copy Markdown
Contributor

Tested #674 at e9a8203 on Windows 11, RTX 5080 (Blackwell), driver 616.56, Vulkan 1.4.x, MSVC 19.44.

d3d12_vulkan_device_test: All host comparisons match

  • Copy comparison: 0/69 cases differ (known BC mip differences documented)
  • MSAA quality: 12 compared, 8 skipped, 0 mismatches
  • Resolve: 60/60 matched, 10 skipped
  • WriteToSubresource/ReadFromSubresource: both paths matched

ctest: 31/31 PASS with LEONIDA_VK_VALIDATION=1

Note: Exit code 1 from d3d12_vulkan_device_test with validation due to 1 pre-existing ReShade layer load error, not from this PR.

AI-assisted.

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