Skip to content

Runtime: typed RTVs of every TYPELESS family clear in the view's format - #621

Closed
NWX10 wants to merge 3 commits into
ProjectLeonida:mainfrom
NWX10:rtv-view-format-v2
Closed

NWX10 wants to merge 3 commits into
ProjectLeonida:mainfrom
NWX10:rtv-view-format-v2

Conversation

@NWX10

@NWX10 NWX10 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #374 as: new item (D3D), the RTV's format ignored on typed views of TYPELESS resources.

Depends on #521 and #589. Their two commits (a7b9ea1, 23827fe) come first here; review the third, da1ff40. All three are rebased on main c432cdc (after #600).

What and why

Main's typed-RTV support (fbffbce) covers R8G8B8A8_TYPELESS with UNORM, sRGB and UINT views. Every other case is still wrong:

  • Other TYPELESS families (R8, R8G8, R16G16, R32G32, R16G16B16A16, R10G10B10A2, B8G8R8A8, R32G32B32A32): CreateRenderTargetView drops the view's format. A clear through a UINT, SINT, SNORM or sRGB view converts the colour for the class the layer creates the resource as (UNORM or float) and writes that.
  • SINT and SNORM views of R8G8B8A8_TYPELESS are rejected.

This builds on main's design instead of replacing it:

  • ColorViewFormat (command_list.h) gets a vulkan value. TargetView gets a vulkan_format field with the view's VkFormat, and still fits the descriptor slot. The three named RGBA8 values are unchanged.
  • CreateRenderTargetView accepts a typed view of a TYPELESS resource when the view's format is in the resource's TYPELESS family (new typeless_family). It uses the same single-2D-subresource limit and color-attachment check as the RGBA8 views. A view in the resource's own format keeps ColorViewFormat::resource, so those clears are unchanged.
  • color_view_format (vulkan_replay.h) accepts a vulkan view of any mutable-format resource (new ResourceBinding::mutable_format) with the same texel size. From there main's code path takes over: the clear converts for the view's format and clears through a view of it, including whole-view clears.
  • The backend gives those views only color-attachment usage, as main already does for RGBA8.

Tested

  • RTX 3060 Ti (Ampere), NVIDIA 621.24, Windows 11 Pro 10.0.26300, MSVC 14.44, Vulkan SDK 1.4.363.1, with WARP as the reference.
  • d3d12_clear_formats_test: 359 cases match WARP, with and without LEONIDA_VK_VALIDATION=1, and no validation errors. 19 new rows clear TYPELESS resources through UINT, SINT, SNORM, UNORM and sRGB views.
  • Without the source changes, the same test has 82 cases that differ from WARP and 9 that fail (RGBA8 SINT and SNORM views rejected).
  • d3d12_typeless_rtv_test: 13 WARP readbacks match, and 12 invalid views are rejected, with and without validation. The SINT and SNORM entries in its rejection list are now supported, so they became views from another family with the same texel size (R16G16_UINT and R32_FLOAT on R8G8B8A8_TYPELESS).
  • typeless_rtv_test (CPU only): 32 scenarios, up from 22:
    • a vulkan UINT view of R16G16_SFLOAT and a SINT view of RGBA8, whole and rectangle;
    • the resource's own format staying a single vkCmdClearColorImage;
    • rejections: not mutable, another texel size, undefined, a named RGBA8 view of another family, and mips.
  • d3d12_clear_test 59 and d3d12_vulkan_device_test pass. ctest: 27/27.
  • Not tested: AMD and Intel GPUs. Mip, array and plane slices stay out of scope, as in main's RGBA8 slice. Depth-stencil views are unchanged.

AI-assisted (Claude Code).

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. (n/a: no translator change)

🤖 Generated with Claude Code

NWX10 and others added 3 commits November 22, 2026 04:20
…D-45)

Rebased onto main after ItsNotRexed#525, which added SNORM/SINT render targets for four formats.
This keeps ItsNotRexed#525's formats and adds what it leaves out:

- Normalised clears round to nearest even like D3D, so 0.5 on an 8-bit channel is 128
  (NVIDIA's clears write 127). The layer hands Vulkan the exact fraction; NaN is 0 and
  out-of-range values clamp. Covers UNORM, SNORM (scale 127 or 32767, -1.0 is -127), the
  alpha of the sRGB formats, R10G10B10A2_UNORM and D16_UNORM depth.
- More formats: R8/R8G8/R16/R16G16/R16G16B16A16 SNORM, R8/R16 SINT, R8/R16 UINT,
  R16_UNORM and R16G16_UNORM, with their copy sizes; SINT and UINT of every width clamp to
  the component range and truncate toward zero.
- d3d12_clear_formats_test: 178 cases against WARP over UNORM, SNORM, sRGB, FLOAT, UINT,
  SINT and the four depth formats. typeless_rtv_test now expects the rounded UNORM value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ProjectLeonida#600 mapped R8G8, R16G16 and R32G32 UINT/SINT, R16G16B16A16 UINT/SINT
and R10G10B10A2_UINT, but render_target_clear_color still treats them
as float formats: a ClearRenderTargetView writes the float's bits
(255.0 becomes 0x437f0000). They now clamp to the component range and
truncate toward zero like WARP, with per-channel limits for
R10G10B10A2_UINT (10, 10, 10 and 2 bits). R8_TYPELESS, the last
two-channel/one-channel TYPELESS form still refused, is mapped as
R8_UNORM with the mutable-format flag.

d3d12_clear_formats_test goes from 178 to 251 cases against WARP, all
matching on an RTX 3060 Ti; without this change 54 differ and R8_TYPELESS
is not exposed. clear_color_test checks the integer conversions on the CPU.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CreateRenderTargetView only kept the view format for R8G8B8A8_TYPELESS
(UNORM, sRGB and UINT views). For every other TYPELESS resource, and
for SINT and SNORM views of R8G8B8A8_TYPELESS, the format was dropped or
the view was rejected. A clear through a UINT, SINT, SNORM or sRGB view
then converted the colour for the class the layer creates the resource
as (UNORM or float) and wrote that.

Extend main's ColorViewFormat with a vulkan value. The TargetView then
carries the view's VkFormat, accepted when the view is in the resource's
TYPELESS family. The replay accepts it for any mutable-format resource
with the same texel size and the same single-subresource limits as the
RGBA8 views. d3d12_clear_formats_test gets 19 class-changing TYPELESS
rows: 359 cases match WARP; without the source change 82 differ and 9
fail.

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

Copy link
Copy Markdown
Contributor

Tested da1ff40 merged onto main c432cdc on NVIDIA GeForce RTX 4060 Ti (Ada), driver 32.0.16.2124 (NVIDIA 621.24), Windows 11 Home 26300, MSVC 2022 / Ninja, Vulkan SDK 1.4.363: pass.

Besides ctest, I ran each test program this PR changes directly (several aren't registered with ctest):

  • clear_color_test: exit 0 (clear_color_test: 120 full/rectangle UINT, SINT, normalised and float replay checks passed)
  • d3d12_clear_formats_test: exit 0 (clears: 359 matched WARP, 0 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped (WARP does not offer the format))
  • d3d12_typeless_rtv_test: exit 0
  • typeless_rtv_test: exit 0 (typeless_rtv_test: 32 format, snapshot, whole/rectangle and rejection scenarios passed)

ctest: 100% tests passed, 0 tests failed out of 27.

AI-assisted.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested da1ff40 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 27/27 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_clear_formats_test, d3d12_clear_test, d3d12_com_test, d3d12_descriptor_test, d3d12_method_variants_test, d3d12_sampler2_test, d3d12_typeless_rtv_test, d3d12_vulkan_device_test, vk_command_replay_test all exit 0, with 0 validation messages.

d3d12_clear_formats_test, d3d12_clear_test and d3d12_typeless_rtv_test pass. With the tie rounding from #521, main's NVIDIA d3d12_clear_test failure is gone here too.

No game files used. AI-assisted run (Claude Code).

@matheuskshn

Copy link
Copy Markdown
Contributor

Code review at da1ff40. For non-RGBA8 typeless resources, the compatibility branch is entered only when the requested VkFormat differs from the backing VkFormat. The DXGI-family check is inside that branch. It would be safer to validate the requested DXGI family before comparing Vulkan formats, so distinct DXGI names sharing a backing format cannot silently take the default view path. AI-assisted code review.

@NWX10

NWX10 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #2103 (D3D-275, "typed RTVs of every typeless color family"), now on main as c48a39d and 88215f9. It does what this PR did, for every typeless color family and for mip, array and MSAA views as well.

It also covers matheuskshn's review point. Main checks the view's family (typeless_view_family, plus alpha_unused for B8G8R8X8 vs B8G8R8A8) on every typeless-resource RTV, not only when the requested VkFormat differs from the backing one. So two DXGI formats from different families that share a backing format can no longer fall through to the default view.

Thanks to troythedecoyx and kotorvr for the GPU runs.

AI-assisted (Claude Code).

@NWX10 NWX10 closed this Nov 22, 2026
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.

4 participants