Skip to content

D3D-85: accept castable formats on committed textures - #693

Closed
Ayinaki wants to merge 1 commit into
ItsNotRexed:mainfrom
Ayinaki:d3d85-castable-formats
Closed

Ayinaki wants to merge 1 commit into
ItsNotRexed:mainfrom
Ayinaki:d3d85-castable-formats

Conversation

@Ayinaki

@Ayinaki Ayinaki commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Part of D3D-85 / #634.

  • Answers D3D12_OPTIONS12: RelaxedFormatCastingSupported = TRUE, EnhancedBarriersSupported = TRUE, and MSPrimitivesPipelineStatisticIncludesCulledPrimitives = UNKNOWN.
  • CreateCommittedResource3 maps a castable-format list to a mutable Vulkan image with VkImageFormatListCreateInfo; unmapped formats are E_INVALIDARG.
  • Castable lists remain texture-only; a nonzero count with a null list is still no list.
  • Scope: committed-resource path only. CreatePlacedResource2 and CreateHeap remain absent and wait on Runtime: CreateHeap and CreatePlacedResource on the Vulkan layer (D3D-16) #286 (D3D-16).
  • Tests on Windows 11, RTX 5070, validation on: d3d12_method_variants_test, d3d12_vulkan_device_test, d3d12_descriptor_test, and d3d12_typeless_rtv_test pass. d3d12_clear_test has an unrelated pre-existing format-28 WARP mismatch that also fails on the d3d12: create 1D textures and 1D arrays #561 worktree.

No game files.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Listed UNORM and sRGB SRVs return distinct, correct pixels. I found two gaps at view creation. Tested 1fc723c0e44bdb3ebe4b1b71aa4cd181d32b0381 on RTX 5080 / 616.92, Windows 11, Vulkan validation enabled. Both checked-in method-variants and descriptor tests passed.

I created one 8×8 committed R8G8B8A8_UNORM texture through runtime CreateCommittedResource3, explicitly listed UNORM and UNORM_SRGB, and uploaded a checkerboard via the D3D12 queue. Two SRVs of the same subresource went into separate shader-visible heap slots. The descriptor fixture's Vulkan compute shader sampled through the actual T#/S# lookup. All 64 pixels per view matched a CPU sRGB transfer-function oracle with unchanged alpha:

Uploaded RGBA8 UNORM readback sRGB readback, repacked to RGBA8
64, 128, 192, 85 64, 128, 192, 85 13, 55, 134, 85
192, 64, 128, 170 192, 64, 128, 170 134, 13, 55, 170

Rebinding the second slot to a UNORM view of that image produced exactly 64 mismatches against the same oracle, all in the second view. Both runs had zero validation errors.

  1. An omitted format still reaches Vulkan. With the creation list containing only UNORM, asking for UNORM_SRGB wrote a nonzero T# and produced VUID-VkImageViewCreateInfo-pNext-01585 during view creation. I stopped before dispatching that descriptor. Keep the creation-time list on the resource and reject an unlisted view before writing its heap entry or calling Vulkan.
  2. A listed same-size, cross-family view can be refused. CreateCommittedResource3 for R8G8B8A8_UINT, with both that format and R32_UINT explicitly listed, returned S_OK. Creating the listed R32_UINT SRV wrote all zeros and logged “view format not supported for this texture: 42”. The current Vulkan-view chooser requires matching component order for a different GFX10 code, so it drops this four-channel to single-channel cast. This exact cast is a D3D12 format-list use case. Format-list rules · Microsoft's R32_UINT / R8G8B8A8_UINT example

@Ayinaki

Ayinaki commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Both gaps are fixed in 5f786b5, rebased onto current main.

  • The creation-time castable list is now kept on the resource. CreateShaderResourceView rejects a format that is neither the resource format nor listed before writing the heap entry or creating the Vulkan view; the slot stays null.
  • The view chooser now allows a listed same-size cross-family cast when no matching channel order exists, so R8G8B8A8_UINT to R32_UINT creates a descriptor instead of logging the view format as unsupported.

I added coverage for the unlisted SRGB view and the listed UINT-to-R32 cast. Local gfx10_descriptors_test, d3d12_method_variants_test, and d3d12_descriptor_test pass with Vulkan validation enabled.

@Ayinaki

Ayinaki commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

One CI note: the remaining red check job is not from this PR. It fails while building rpf9dump because main pins third_party/rpf9-explorer at 48557ea, whose ArchiveEntry lacks ResourceDrawableOffset, while tools/rpf9dump/Program.cs expects it. Main's own check run 44974310144 fails with the same two errors.

5f786b5 changes only the D3D-85 files: docs, d3d12_vulkan_device.cpp, gfx10_descriptors.h, and the two tests. The PR is conflict-free and the other eight checks pass.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Retested both reported SRV cases at 5f786b5fc5fb5719641b103edcfb2246264402a5 on Windows 11, RTX 5080, driver 616.92, with Khronos Vulkan validation enabled. I reused the synthetic 8×8 checkerboard and added full-width UINT readback through the runtime bindless set.

  • Unlisted sRGB. I copied a valid UNORM descriptor into the second slot, then requested an sRGB SRV in that slot with only UNORM on the creation list. The entire slot was cleared. All 64 reads from it returned the zero fallback, while the original UNORM slot still returned the 64 uploaded texels. Zero validation errors, including the previously reported image-view VUID.
  • Listed cross-family UINT. With both R8G8B8A8_UINT and R32_UINT on the list, the same shader returned its sampled red component as an unmodified 32-bit word. The R32 view returned 0x55c08040 and 0xaa8040c0 in the expected checkerboard positions, 64/64. Switching only the descriptor to the base UINT view returned 0x40 and 0xc0, different at all 64 positions. Zero validation errors.
  • Listed sRGB control. The two sRGB checker colors repacked to RGBA8 were (13,55,134,85) and (134,13,55,170). Both the base and sRGB views matched the CPU oracle at all 64 positions. Substituting the base descriptor for the sRGB view produced exactly 64 mismatches with zero validation errors.

The checked-in gfx10_descriptors_test, d3d12_method_variants_test, and d3d12_descriptor_test executables also passed on this head.

AI-assisted verification with Codex.

@Derpbeat

Copy link
Copy Markdown
Contributor

Tested 5f786b5 on an NVIDIA GeForce RTX 4090 (driver 617.14, Vulkan 1.4.351), Windows 10 Home 22H2 (19045), MSVC 19.39, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo, LEONIDA_VK_VALIDATION=1: pass. (D3D-85.)

  • Build: no new warnings. ctest: 28/28 with validation.
  • d3d12_method_variants_test, d3d12_descriptor_test, d3d12_com_test, vk_command_replay_test: pass, 0 validation messages. d3d12_vulkan_device_test passes too (its two host comparisons made non-fatal locally for Windows 10, see TEST-97 in Coordinating who works on what (3) (moved to #1006) #634).
  • Negative control: with d3d12_vulkan_device.cpp put back to 762893f (keeping the new gfx10_descriptors.h, which gfx10_descriptors_test needs), d3d12_method_variants_test fails at line 329: SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, ...)).

One question I couldn't settle by test: every castable list in the test includes the resource's own format. D3D12 doesn't require that, but Vulkan does once a VkImageFormatListCreateInfo with a nonzero count is chained: an image view's format must be one of pViewFormats (VUID-VkImageViewCreateInfo-pNext-01585). create_texture hands the D3D12 list over as-is, and allows_view_format accepts format_ itself. So an R8G8B8A8_UNORM texture created with castable {R8G8B8A8_UNORM_SRGB}, then given a default SRV or RTV in its own format, would seem to create a view outside the list. I tried to probe it: CreateCommittedResource3 succeeds with that list in d3d12_method_variants_test, and the default SRV raised no validation error there. But I'm not sure that test's device creates the Vulkan view at all (bindless), and through d3d12_descriptor_test's device CreateCommittedResource3 returned E_POINTER, so I couldn't reach it. Adding format_ to view_formats_ when it's missing (or a test with a list that leaves it out) would settle it.

AI-assisted (Claude Code); repository tests only, no game files.

@Ayinaki

Ayinaki commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed at d318dc8, rebased onto 67204bf. create_texture now adds the resource's own format to the Vulkan format list when the D3D12 castable list omits it. The view allow-list already accepted the resource format, so a default SRV or RTV no longer creates a view outside pViewFormats.

Added a validation-run case: an R8G8B8A8_UNORM texture created with castable {R8G8B8A8_UNORM_SRGB} only, then a default UNORM SRV must write a nonzero descriptor.

With Vulkan validation enabled, d3d12_method_variants_test, gfx10_descriptors_test, and d3d12_descriptor_test pass. The branch is rebased and conflict-free.

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 1f36c85 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass (no regression against main).

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest: 32/32 pass.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and the Khronos validation layer: d3d12_com_test, d3d12_descriptor_test, d3d12_gcl8_test, d3d12_method_variants_test, d3d12_resource_desc_test, d3d12_sampler2_test, d3d12_state_map_test, d3d12_typeless_rtv_test, d3d12_uav_clear_test, d3d12_vulkan_device_test, vk_command_replay_test pass, with 0 validation messages (no VUIDs).
  • d3d12_clear_test fails, the same as on plain main 4a36bb1 on this GPU (NVIDIA rounds the 0.5 clear on 8-bit UNORM/SNORM down: Vulkan 7f, WARP 80, plus one depth-format-55 case that main shows too). This is not caused by this PR; Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) #521 fixes the rounding.

The vk_* harness tests that need translated SPIR-V weren't run. No game files used. AI-assisted run (Claude Code).

Keep the creation-time castable list on the resource, reject an SRV format
that is neither the resource format nor listed, and allow listed same-size
cross-family casts such as R8G8B8A8_UINT to R32_UINT.
@Ayinaki
Ayinaki force-pushed the d3d85-castable-formats branch from 1f36c85 to 67407d6 Compare November 22, 2026 04:22
@JavierBlanco23

Copy link
Copy Markdown
Contributor

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

d3d12_vulkan_device_test: All host comparisons match

  • FORMAT_INFO: 195 queries, 0 mismatches
  • CheckFeatureSupport options: 15 queries, 0 mismatches
  • 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
  • GetCopyableFootprints, GetResourceTiling: matched

ctest: 32/33 PASS with LEONIDA_VK_VALIDATION=1 (gameinput disabled)

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.

@nschlaepfer

Copy link
Copy Markdown
Contributor

@Ayinaki, I tested the committed-texture format-list path at 67407d65 on Windows 11 with an RTX 5090, driver 621.14. A shader sampled all 64 expected texels through an explicitly listed RGBA8_UINT view of an R32_UINT texture. The same-format reserved-texture control also matched all 64.

I’d like to build a small follow-up on your change once it lands. Today CreateReservedResource2 discards its castable-format list. A valid reserved R32_UINT texture with the same listed RGBA8_UINT view worked on native D3D12, while the layer returned a null SRV. I tested forwarding the list to the existing backing allocation in your branch. That produced the same 256 output bytes as native D3D12 and preserved both controls.

Do you already have this reserved-resource case in progress? I can contribute the forwarding change and synthetic regression separately after #693. The scope is the existing backed reserved-texture path and SRV readback. Sparse residency and the placed-resource implementation remain separate. AI-assisted, synthetic data only.

@quackottu quackottu 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 67407d6 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

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 32
  • d3d12_method_variants_test (changed here): exit=0 validation=0 | [rt] d3d12: view format not in the resource's castable list: 29
  • gfx10_descriptors_test (changed here): exit=0 validation=0 | GFX10 descriptors: T#, S# and V# fields, round trips, 93 format rows and the Vulkan mappings OK
  • 33 test programs in the build pass with 0 validation errors
  • Not run (they take an input file, not covered here): vk_binary_occlusion_test
  • d3d12_clear_test fails (R8G8B8A8_UNORM/SNORM 0.5 ties and a D16 clear byte differ from WARP) exactly as on main 4a36bb1 here, so not from this PR; #521 addresses it

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

@Ayinaki

Ayinaki commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing as already on main: this work landed as 01c0a564 ("d3d12: accept castable formats on committed textures"), same author and same five files, merged locally in a batch. The docs lines differ from this branch only because D3D-90's placed-resource work (9c7e223a) landed around them.

Checked against current main: CreateCommittedResource3 takes the castable list, castable_view_formats() is in runtime/shims/d3d12_vulkan_device.cpp, D3D12_OPTIONS12 reports RelaxedFormatCastingSupported = TRUE, and CreatePlacedResource2 reaches the same rules through D3D-90. Rebasing this branch onto main leaves an empty commit, so there is nothing to merge — closing it keeps it out of the rebase list.

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