Skip to content

Runtime: RTVs in a castable-format list's other channel order - #3781

Open
SpositoDouglas wants to merge 4 commits into
ItsNotRexed:mainfrom
SpositoDouglas:castable-rtv
Open

SpositoDouglas wants to merge 4 commits into
ItsNotRexed:mainfrom
SpositoDouglas:castable-rtv

Conversation

@SpositoDouglas

@SpositoDouglas SpositoDouglas commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RTVs through a castable-format list in another channel order or family (the RTV half BUILD-768 left out; no item ID in the table yet), claim: #3381 (comment)

Depends on: #3252 (merged); this branch is rebased on main.

What and why

A castable-format list may name an R8G8B8A8 texture's B8G8R8A8 formats, or the reverse, or cross B8G8R8X8 and B8G8R8A8. WARP and AMD's D3D12 driver store a clear or a draw through an RTV in a listed format in the view's channel order and encoding. The layer got this wrong in two ways:

  • On an R8G8B8A8 texture, CreateRenderTargetView refused an RTV in a listed B8G8R8A8, B8G8R8A8_SRGB or B8G8R8X8 format: the clear made Close fail, and draws through it were dropped without an error.
  • On a typed B8G8R8A8 texture, the RTV kept the image's format whatever the view named, so a clear through a listed R8G8B8A8 or sRGB RTV came out in BGRA order and without the sRGB encoding. Draws were already right, because the attachment view takes the PSO's format.

Now an RGBA8 or BGRA8 UNORM/SRGB texture (B8G8R8X8 included) gets an RTV in another of these formats when its castable list, as the application gave it (lists_castable_format from #3252), names that format. color_view_format lets a castable image's clear cross between the two channel orders. A format the list doesn't name is refused, on typed B8G8R8A8 and B8G8R8X8 textures as on R8G8B8A8 ones (the BGRA8 ones kept the image's format before), and UINT, SNORM and the other families are unchanged.

A typed B8G8R8A8 texture without a list still ignores the RTV's format, as before. Refusing it would also refuse, for example, sRGB RTVs of swap-chain buffers.

Measured on the host before changing anything (WARP and an RX 9060 XT with AMD's D3D12 driver; both agree): a 4x4 texture cleared to (0.2, 0.4, 0.6, 0.25), then its 2x2 centre cleared to (0.9, 0.7, 0.5, 0.75) or drawn with (0.8, 0.6, 0.4, 0.3).

Texture {castable list} RTV Clear, bytes in memory Rectangle clear Draw
R8G8B8A8_UNORM {B8G8R8A8_UNORM} B8G8R8A8_UNORM 153, 102, 51, 64 128, 178, 230/229, 191 102, 153, 204, 76
B8G8R8A8_UNORM {R8G8B8A8_UNORM} R8G8B8A8_UNORM 51, 102, 153, 64 230/229, 178, 128, 191 204, 153, 102, 76
R8G8B8A8_UNORM {B8G8R8A8_UNORM_SRGB} B8G8R8A8_UNORM_SRGB 203, 170, 124, 64 188, 218, 243, 191 170, 203, 231, 76
B8G8R8A8_UNORM {R8G8B8A8_UNORM_SRGB} R8G8B8A8_UNORM_SRGB 124, 170, 203, 64 243, 218, 188, 191 231, 203, 170, 76
B8G8R8X8_UNORM {B8G8R8A8_UNORM} B8G8R8A8_UNORM 153, 102, 51, 64 128, 178, 230/229, 191 102, 153, 204, 76
B8G8R8A8_UNORM {B8G8R8X8_UNORM} B8G8R8X8_UNORM 153, 102, 51, X 128, 178, 230/229, X 102, 153, 204, X

Where two values are given, WARP stores 230 and AMD 229. The X byte after a clear or a draw through an X8 RTV differs between the two (WARP 64 after a clear and 0 after a draw, AMD 0 and 76), so no test compares it.

Tested

  • Windows 11 Pro 26H2 (10.0.26300.9974), AMD Radeon RX 9060 XT (RDNA4), AMD Software 26.11.2 (32.0.32029.2010, Vulkan driver 2.0.416), Vulkan 1.4.359; MSVC 19.44 (VS 2022 Build Tools), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; on main 4c52ce27 + this PR.
  • d3d12_clear_test: 8 textures with a castable list (the cases above plus B8G8R8A8_UNORM {B8G8R8A8_UNORM_SRGB}) are cleared through the listed RTV, full and with a rectangle, and compared with WARP within 1 (drivers round the 0.5 tie differently, and Intel's encodes sRGB 1 off WARP in places; a wrong channel order is many steps off), the X byte of an X8 view left out. A new check makes R8G8B8A8_UNORM {B8G8R8A8_UNORM}, B8G8R8A8_UNORM {R8G8B8A8_UNORM} and B8G8R8X8_UNORM {B8G8R8A8_UNORM} textures: each takes an RTV in its own and its listed format, and 3 formats its list doesn't name leave the descriptor empty. With that shim change reverted, the B8G8R8A8 one takes an RTV in its unlisted B8G8R8A8_UNORM_SRGB. 229/229 readbacks matched WARP.
  • d3d12_draw_test: an opaque full-screen draw through the same 8 views; each must store (0.8, 0.6, 0, 1) in the view's order and encoding (within 1). 3/3 runs pass, and 3/3 with validation.
  • typeless_rtv_test: the replay clears a castable RGBA8 image through BGRA8 UNORM/SRGB views and the reverse through attachment views. It refuses the other order for a typed image without a list, a typeless RGBA8 image and a castable RGBA8_UINT image.
  • Negative control: with the shim and replay changes reverted, all three fail. typeless_rtv_test fails at the first crossing, d3d12_clear_test at the listed RTV, and d3d12_draw_test reads 0, 0, 0, 0 for R8G8B8A8 {B8G8R8A8}.
  • d3d12_descriptor_test, d3d12_uav_clear_test, d3d12_vulkan_device_test: pass. They and d3d12_clear_test pass with LEONIDA_VK_VALIDATION=1 too (0 validation errors).
  • ctest --test-dir runtime\build -C RelWithDebInfo: 153/153, the same with LEONIDA_VK_VALIDATION=1.
  • Also tested by others on an RTX 5070 Ti, an RTX 4070 SUPER, an Intel UHD 770, an RTX 5080 and an AMD gfx1036 iGPU (comments below).
  • No Python or translator file changes, so the Python checks and run_gpu_tests.py were not rerun for this PR (they passed on BUILD-768: views across B8G8R8X8 and B8G8R8A8 through castable-format lists #3252's head).

Not in this PR: a typed B8G8R8X8 texture with ALLOW_UNORDERED_ACCESS and a list naming B8G8R8A8, which the host accepts and the layer still refuses (the other follow-up #3252 names).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

AI-assisted: written with Claude Code; reviewed and tested by me.
No game data, keys or decryption involved.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 22, 2026 21:35

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Kam471 Kam471 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.

Tested ce95df0d on Windows 11, MSVC 19.44.35228, RTX 5070 Ti, Vulkan SDK 1.4.363.0. Build needed -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON; all four targets linked cleanly.

  • ctest ^(d3d12_clear|d3d12_descriptor|d3d12_draw|typeless_rtv)$ -> 3/3 matched, 3 passed, 0 failed. At this commit the d3d12_clear entry is d3d12_rgb9e5_rtv (d3d12_clear_test --rgb9e5), which skipped (exit 77) because RGB9E5 render targets are unavailable on this adapter.
  • typeless_rtv_test -> exit 0, 100 scenarios passed, including the new cross-order accepts and the 3 rejects.
  • d3d12_descriptor_test -> exit 0, 20/20 checks, including B8G8R8X8 alpha 1 through a castable-format list (64 texels each).
  • d3d12_draw_test -> exit 0, castable RTVs 8 draws in the view's channel order/encoding; MSAA 4096/4096 and M1 4096/4096.
  • d3d12_clear_test with no args -> exit 1, 13 formats differ from WARP vs 5 on base 16282101 (same build/config): all are the pre-existing NVIDIA 0.5-UNORM tie at case-0 byte 0/2 (7f vs 80), plus one depth ff/00; the PR adds 8 instances of the same tie, no new failure class. CMake keeps this differential test out of ctest until the tie lands.

The castable-order behavior is positively covered by the typeless/draw/descriptor tests; no blocker from me.

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested ce95df0 merged onto main f847748 (clean merge) on Windows 11 build 26300, MSVC 19.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, on two GPUs picked by LEONIDA_VK_DEVICE: RTX 4070 SUPER (NVIDIA 616.64) and Intel UHD 770 (101.7092). The new castable cases pass everywhere except one: the sRGB cases fail byte for byte on Intel, because Intel's own D3D12 driver encodes sRGB differently from WARP.

4070 SUPER UHD 770
typeless_rtv_test 100 scenarios passed 100 scenarios passed
d3d12_draw_test (castable draws, within 1) exit 0 exit 0
d3d12_descriptor_test exit 0 line 2728: lod_mismatches == 0, the same min-LOD failure as main (line 2659 there, #2948)
d3d12_clear_test, main exit 1: 5 formats, all the 0.5 tie (7f vs 80, 3f vs 40, D16 3fff vs 4000) exit 0
d3d12_clear_test, this PR exit 1: those 5 plus the 8 castable cases, every one the same tie (7f vs 80) exit 1: the 3 castable sRGB cases, Vulkan bb, WARP bc
full ctest 140/140 138/140, the same two as main
VK_LAYER_KHRONOS_validation on all of these 0 messages 0 messages

On NVIDIA, the castable cases hit the tie rounding that #521 handles; I didn't merge the two to check that its rounding reaches the castable views. The listed-RTV check (the listed format is taken, 3 formats the list doesn't name are refused) passes on both GPUs.

The UHD 770 sRGB cases. 0xbb is 187: Vulkan stores sRGB(0.5) as 187, where WARP stores 188. I cleared typed sRGB textures (no castable list) through native D3D12 on the same machine:

clear WARP NVIDIA D3D12 Intel D3D12 (UHD 770)
R8G8B8A8_UNORM_SRGB (0, 0.25, 0.5, 1) 0, 137, 188, 255 0, 137, 188, 255 0, 137, 187, 255
R8G8B8A8_UNORM_SRGB (0.2, 0.4, 0.6, 0.25) 124, 170, 203, 64 124, 170, 203, 64 123, 169, 203, 64
R8G8B8A8_UNORM_SRGB (0.9, 0.7, 0.5, 0.75) 243, 218, 188, 191 243, 218, 188, 191 244, 218, 187, 191

So on this GPU the layer writes what Intel's own driver writes. A byte-for-byte comparison of sRGB colour channels against WARP can't pass on Intel. float_values already leaves SRGB out for this reason (the comment above it). The castable sRGB cases could take the ±1 that d3d12_draw_test uses, or compare only the alpha byte exactly. Intel's native D3D12 has no castable lists here (RelaxedFormatCastingSupported = 0 on 101.7092), so the cast itself can't be compared on that GPU.

NVIDIA's native D3D12 with castable lists (CreateCommittedResource3, RelaxedFormatCasting and enhanced barriers both supported), your protocol: same channel order and encoding as your table on all eight cases, clears, rectangle clears and draws. The only differences are the tie (rectangle 0.5 → 127 where WARP stores 128; 0.9 → 229, as AMD) and the X byte of an X8 view: 0 after a clear and after a draw, a third answer next to WARP's and AMD's. WARP on the same probe gives your table byte for byte.

AI-assisted (Claude Code). Native probes made with CreateDXGIFactory1, D3D12CreateDevice and synthetic 4x4 and 1x1 textures. No game files.

SpositoDouglas and others added 2 commits November 22, 2026 19:02
A castable-format list may name an R8G8B8A8 texture's B8G8R8A8 formats,
or the reverse, or cross B8G8R8X8 and B8G8R8A8. WARP and AMD's D3D12
driver store a clear or a draw through an RTV in a listed format in the
view's channel order and encoding: an R8G8B8A8 texture cleared to
(0.2, 0.4, 0.6, 0.25) through a B8G8R8A8 RTV holds 153, 102, 51, 64.
CreateRenderTargetView refused such an RTV on an R8G8B8A8 texture, so
the clear failed Close and draws were dropped, and a typed B8G8R8A8
texture's RTV kept the image's format whatever the view named, so its
clears came out in BGRA order and without the sRGB encoding.

An RGBA8 or BGRA8 UNORM/SRGB texture (B8G8R8X8 included) now gets an
RTV in another of these formats when its list, as the application gave
it, names that format, and color_view_format lets a castable image's
clear cross between the two channel orders. Draws already used the
PSO's format for the attachment view. A format the list doesn't name
stays refused; a typed B8G8R8A8 texture without a list keeps ignoring
the RTV's format, as before.

d3d12_clear_test compares 8 such textures with WARP in full and
rectangle clears (the X byte of an X8 view left out: WARP and AMD write
different values there) and checks that 3 unlisted formats get no RTV;
d3d12_draw_test draws through the same views; typeless_rtv_test checks
the replay's crossing and its refusals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Say that an RGBA8 or BGRA8 texture whose castable-format list names the
RTV's format in the other channel order, or across B8G8R8X8 and
B8G8R8A8, gets an RTV in that format and stores clears and draws in the
view's order and encoding, as the host does; what was wrong before; and
that a typed B8G8R8A8 texture without a list still ignores the RTV's
format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The castable cases in d3d12_clear_test compared each byte with WARP
exactly. Drivers round the 0.5 tie differently (WARP stores 128, NVIDIA
127), and Intel's driver encodes sRGB 1 off WARP in places, where its
own D3D12 driver stores the same bytes as the layer (measured on a UHD
770 and an RTX 4070 SUPER in the review of this change). Compare within
1, as the castable draws in d3d12_draw_test do: a wrong channel order or
a missing sRGB encoding is many steps off, so the cases still catch what
they test.

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

Copy link
Copy Markdown
Contributor Author

Thanks @CowBoYdu76 and @Kam471 for testing on NVIDIA and Intel.

Retested at the new head on an RX 9060 XT (AMD 26.11.2): ctest 153/153, the same with LEONIDA_VK_VALIDATION=1. d3d12_clear_test (229 readbacks), d3d12_descriptor_test, d3d12_uav_clear_test, d3d12_vulkan_device_test and typeless_rtv_test pass with validation, 0 messages. d3d12_draw_test 3/3 with validation.

@tupacfan04

Copy link
Copy Markdown
Contributor

PASS, with one pre-existing gap now left asymmetric.

The remap covers RGBA8/BGRA8/B8G8R8X8 in UNORM and SRGB, both directions; UINT/SNORM/typeless are untouched; a replay crossing requires castable_view_formats (vulkan_replay.h:1104); non-castable views are unchanged; and 89 tests pass with compileall clean and a clean merge.

The gap: a typed B8G8R8A8/B8G8R8X8 texture with a list silently keeps the resource format for an RTV format the list does not name (e.g. unlisted sRGB) instead of refusing - d3d12_vulkan_device.cpp:5078 falls through, unlike RGBA8's :5127. That contradicts docs/d3d12_vulkan.md:2065+ ("stays refused"), and the negative test only covers R8G8B8A8 (d3d12_clear_test.cpp:84-122). Worth either matching RGBA8's refusal or correcting the doc and adding the BGRA/BGRX negative case.

AI-assisted review, no game files, no GPU.

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 9c2eaaa on AMD Radeon(TM) Graphics (gfx1036, driver 26.10.1) and NVIDIA GeForce RTX 5080 (driver 616.92), Windows 11, MSVC RelWithDebInfo: d3d12_clear_test, d3d12_draw_test and typeless_rtv_test, each run with LEONIDA_VK_DEVICE=radeon and =5080 (device line confirmed). Radeon: all three pass (229 clear readbacks match WARP, castable RTVs: the listed format is taken and 3 unlisted formats are refused, 8 castable draws stored in the view's channel order, typeless_rtv 100 scenarios). RTX 5080: d3d12_draw_test and typeless_rtv_test pass; d3d12_clear_test exits 1 with the same 5 differences from WARP that main (aa2988c) has on this card (R8G8B8A8_UNORM/SNORM and B8G8R8A8/X8 0.5 clears 0x7f vs 0x80, D16_UNORM case 1 byte 12); the new castable-RTV lines pass there. AI-assisted.

A typed B8G8R8A8 or B8G8R8X8 texture with a castable-format list took
an RTV in a format the list doesn't name (its own sRGB format, say) and
silently kept the image's format, where a typed R8G8B8A8 texture with a
list refuses it. CreateRenderTargetView now refuses it for these
textures too; without a list they keep the image's format, as before.

d3d12_clear_test's negative check covers a B8G8R8A8 texture listing
R8G8B8A8 and a B8G8R8X8 one listing B8G8R8A8 next to the R8G8B8A8 one:
each takes its own and its listed format and refuses 3 formats its list
doesn't name. Without the shim change it fails on the B8G8R8A8 texture's
unlisted B8G8R8A8_UNORM_SRGB.

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

Copy link
Copy Markdown
Contributor Author

Thanks @tupacfan04, you're right: a typed B8G8R8A8 or B8G8R8X8 texture with a list kept the image's format for an RTV format the list doesn't name, so the doc's "stays refused" was only true for R8G8B8A8 textures.

New commit: CreateRenderTargetView refuses those formats on typed B8G8R8A8 and B8G8R8X8 textures that have a castable list, as it does on R8G8B8A8 ones. Without a list they keep the image's format, as before (refusing there would also refuse, for example, sRGB RTVs of swap-chain buffers). The negative check in d3d12_clear_test now has three textures: R8G8B8A8 {B8G8R8A8}, B8G8R8A8 {R8G8B8A8} and B8G8R8X8 {B8G8R8A8}. Each takes its own and its listed format and refuses 3 formats its list doesn't name. With the shim change reverted, it fails on B8G8R8A8 {R8G8B8A8}'s unlisted B8G8R8A8_UNORM_SRGB. The doc sentence now says this.

Thanks @Vonsek too for running 9c2eaaa on the Radeon (gfx1036) and the RTX 5080. The castable lines passing on the 5080, next to the 5 tie failures main has there, is what the within-1 comparison was for.

Retested on an RX 9060 XT (AMD 26.11.2): ctest 153/153, the same with LEONIDA_VK_VALIDATION=1. d3d12_clear_test, d3d12_descriptor_test, d3d12_uav_clear_test, d3d12_vulkan_device_test and typeless_rtv_test pass with validation, 0 messages. d3d12_draw_test 3/3 with validation.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 1e0b4cd on NVIDIA RTX 4080, driver 610.88, Windows 11: pass

This is the head after 9c2eaaa, with the typed-BGRA8 refusal commit. Ran (MSVC 19.44 / VS 2022 BuildTools, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0; branch as it stands, merge base 4c52ce27):

  • Full ctest: 153/153 passed.
  • Run directly with LEONIDA_VK_VALIDATION off and on:
    • d3d12_draw_test: exit 0.
    • typeless_rtv_test: exit 0, 100 scenarios passed.
    • d3d12_clear_test: the new castable-RTV check passes, 3 textures take their own and the listed format, and refuse 9 formats their lists don't name, as does 3D RTVs: 648 RGBA texels match WARP.

d3d12_clear_test itself exits 1 here, but the cause predates this PR: it prints the same 5 differences from WARP at the merge base 4c52ce27 built without the PR. R8G8B8A8_UNORM/SNORM, B8G8R8A8_UNORM and B8G8R8X8_UNORM case 0 come out one step below WARP (0x7f vs 0x80, 0x3f vs 0x40), and depth format 55 (D16_UNORM) case 1 differs in one byte. ctest doesn't see this because the plain d3d12_clear_test run isn't registered as a test; only --rgb9e5 is (d3d12_rgb9e5_rtv, skipped here).

Review: no findings. typed_bgra8_listed only applies when the texture has a castable list (has_castable_formats()), so a typed BGRA8 texture without a list keeps the image's format as before.

AI-assisted.

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 1e0b4cd on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "d3d12_draw|typeless_rtv" (the tests this PR changes): pass on both GPUs (2/2 each). No game files.

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.

7 participants