Skip to content

d3d12: the runtime's own Vulkan device enables fragmentStoresAndAtomics; a PSO that needs it elsewhere is refused - #3780

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
kotorvr:fix/standalone-stores-atomics
Nov 23, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
kotorvr:fix/standalone-stores-atomics

Conversation

@kotorvr

@kotorvr kotorvr commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claim: #3574 (comment) (overlap note for #2058 in the comment after it)

The problem

The runtime's own Vulkan device (create_vulkan_device_standalone, the one D3D12XboxCreateDevice hands a title with LEONIDA_D3D12=vulkan) copies about twenty features from the chosen GPU and never enables fragmentStoresAndAtomics or vertexPipelineStoresAndAtomics.

A translated pixel shader that stores to an image or does an image atomic declares that storage image without NonWritable. Outside a compute shader Vulkan allows that only with the feature (VUID-RuntimeSpirv-NonWritable-06340 for the fragment stage, -06341 for vertex, tessellation and geometry). So on that device every such PSO was invalid, and CreateGraphicsPipelineState still answered S_OK. How many shaders this is: closed #1578 counted 1,018 of the corpus's 1,038 image-atomic shaders as pixel shaders. That was recounted for this PR on a locally translated 1.0.2.1 corpus (26,503 index entries, 2 of them without a module in that folder): modules containing an OpImageTexelPointer (what every image atomic goes through), split by the stage in index.json, give 1,038 = 1,018 pixel + 20 compute, none in a vertex, geometry or mesh shader. The translator commit of that folder was not recorded, so read it as a recount of #1578's figure, not a new measurement.

Reproduced here before the fix, under the validation layer on an RTX 4090: VUID-RuntimeSpirv-NonWritable-06340 at pipeline creation, S_OK returned.

The change

  • The standalone device enables both features where the GPU has them, and reports them in VulkanDeviceInfo::features like the others.
  • A graphics PSO whose stage needs a feature the device does not have is refused (this is new for every caller's device, not only the standalone one: a device that leaves the feature off now answers E_NOTIMPL for such a PSO where it answered S_OK; the full suite shows no existing test relied on the old answer) with E_NOTIMPL and a line naming the shader, the stage and the feature, in the place that already refuses a geometry shader without geometryShader. Before, the pipeline was created anyway.
  • "Needs" is read off the module's declarations by a small header, runtime/src/spirv_stores.h: a storage image or storage texel buffer variable, or a storage buffer (either SPIR-V form), that is not NonWritable (on the variable, or on every member of the block). An input attachment (Sampled 2 with Dim SubpassData) is not counted, and NonWritable applied through a decoration group (OpGroupDecorate, OpGroupMemberDecorate) counts like a direct one (third commit, c1fe863; both found by @kacper-serewis). That is the rule the VUID states; it does not look at whether an instruction writes. The translator's descriptor map is NonWritable on the variable, so shaders that only sample are unaffected.
  • docs/d3d12_vulkan.md §3.2: one bullet next to the other feature notes.

Not changed: compute pipelines (compute needs no feature), and the index's features list is still not read.

Overlap with #2058 (@opit80, D3D-251, 64-bit image atomics): #2058 sets the same two features in create_vulkan_device_standalone, but only inside if (info.image_int64_atomics), for its 64-bit path, and checks them for shaders that use 64-bit atomics. This PR sets them wherever the GPU reports them, which the 32-bit image atomics need on a GPU without 64-bit image atomics as well, and its refusal covers any writable storage declaration. The two conflict on those two assignment lines; whichever lands second rebases.

Tests

Windows 11, MSVC 14.44 (VS 2022), the CMake and Ninja that Visual Studio ships (3.31.6), SDK 10.0.26100, Vulkan SDK 1.4.363.0, RelWithDebInfo, NVIDIA RTX 4090 (driver 621.14). No game files.

Check Result
New spirv_stores_test (CPU, hand-built SPIR-V): a storage image, sized and runtime arrays of them, NonWritable ones, sampled images; storage buffers as StorageBuffer + Block and Uniform + BufferBlock, with none, one and all members read-only and with the variable read-only; a uniform buffer; a wrong magic, a truncated instruction, a zero-length instruction; an array type that names itself (the walk through array types is bounded); an input attachment and an array of them; NonWritable through OpGroupDecorate (and a group aimed at another id) and through OpGroupMemberDecorate pass (26 checks)
New d3d12_stores_atomics_test, device 1: the test's own Vulkan device, which leaves fragmentStoresAndAtomics off. A VS+PS PSO whose pixel shader does imageAtomicMax on set 0 binding 4 refused, E_NOTIMPL; the same PSO with a pixel shader that has no storage image is created; validation errors: 0
The same test, device 2: create_vulkan_device_standalone. Its features.fragmentStoresAndAtomics and vertexPipelineStoresAndAtomics equal the GPU's; the PSO with the atomic pixel shader both enabled; PSO created, S_OK; validation errors: 0
Negative control: the two enables and the refusal removed (what main does) VUID-RuntimeSpirv-NonWritable-06340 is reported and the test fails
Negative control: the header of the second commit with the third commit's test cases spirv_stores_test fails the four new cases (two input-attachment, two decoration-group)
Full ctest after the rebase onto main 4c52ce2 (head cbdbafa, 156 tests) 2 of 155 enabled tests fail, 144 pass and 9 skip (package- or feature-gated); gameinput is disabled (no SDL3). The two failures are not this change: winhttp_offline (TEST-721, the known flake; passed 3 of 3 alone) and d3d12_fence_timing, which segfaults now and then when it runs in parallel with other GPU tests (passed 10 of 10 alone; in six parallel rounds with four other GPU tests it failed once on main 4c52ce2 itself and once on this branch).
python -I tests/test_docs_links.py, test_docs_list_items.py, test_docs_repo_paths.py, test_docs_design_rows.py OK

Unlike the other tests, the GPU test turns the validation layer on for itself when VK_LAYER_KHRONOS_validation is installed and LEONIDA_VK_VALIDATION is not set. With LEONIDA_VK_VALIDATION=0, or without the layer, it checks the HRESULTs and the feature bits only and says so. Run here both ways: variable unset (layer on, 0 errors) and =0 (layer off); both pass. A machine with no layer installed was not available.

Not tested:

  • A GPU without fragmentStoresAndAtomics: the standalone half then expects the refusal, but I have no such GPU.
  • The vertex and geometry stage refusal on a real device (the CPU test covers the rule; no fixture has a vertex shader with a storage image).
  • A translated corpus shader: the pixel shader is GLSL written to the translator's contract, with the storage image declared the way the translator declares it.
  • Nothing is drawn with the pipeline.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@kacper-serewis kacper-serewis 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.

At 422009e two valid read-only fragment modules can spuriously require fragmentStoresAndAtomics. A subpassInput has Sampled=2 but Dim=SubpassData; exclude input attachments from storage-image classification. Also honor NonWritable supplied through OpGroupDecorate. Both synthetic modules passed Vulkan 1.0 spirv-val. CPU suite and 108 stage/feature combinations passed. No GPU execution; standalone negotiation and COM HRESULT propagation inspected in source. AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 422009e on Windows 11, RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1): ctest -R "^(spirv_stores|d3d12_stores_atomics|d3d12_vulkan_device|d3d12_draw|d3d12_buffer_uav)$" (MSVC, RelWithDebInfo, LEONIDA_VK_DEVICE set per run, device line confirmed, VK_LOADER_LAYERS_DISABLE=~implicit~) — pass on both, 5/5 each.

  • spirv_stores_test: OK on both.
  • d3d12_stores_atomics on both: without fragmentStoresAndAtomics: the PSO with the atomic pixel shader is refused (E_NOTIMPL), the plain one is created; the runtime's own device: fragmentStoresAndAtomics enabled, vertexPipelineStoresAndAtomics enabled; the PSO with the atomic pixel shader is created; 2 device(s) passed.
  • No Vulkan validation layer is installed here, so the test printed no validation layer: errors not checked.

No negative control run.

AI-assisted.

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested 422009e (based on main f847748) on Windows 11 build 26300, MSVC 19.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, with two GPUs picked by LEONIDA_VK_DEVICE: RTX 4070 SUPER (NVIDIA 616.64) and Intel UHD 770 (101.7092): pass. This adds an Intel GPU to the RTX 4090 run in the description.

4070 SUPER UHD 770
d3d12_stores_atomics_test exit 0, 2 device(s) passed: the atomic PSO is refused (E_NOTIMPL) without the feature and created on the runtime's own device, which enables both features the same
spirv_stores_test OK OK
both under VK_LAYER_KHRONOS_validation 0 messages 0 messages
full ctest 142/142 140/142: d3d12_descriptor and d3d12_subgroup, the same two as on main (#2948, #2934)

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

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@kacper-serewis thank you, both are real false positives. Fixed in c1fe863:

  • an OpTypeImage with Sampled 2 and Dim SubpassData (a subpassInput) is no longer counted as a storage image;
  • NonWritable applied through a decoration group is resolved like a direct decoration, for OpGroupDecorate (variables) and OpGroupMemberDecorate (block members); the groups are resolved after the scan, so the order of the annotations does not matter.

spirv_stores_test gains an input attachment, an array of them, a group-decorated storage image, a group aimed at another id (still writable), and a block whose members are read-only through a group; with the previous header those four new "does not need it" cases fail. d3d12_stores_atomics_test still passes on the RTX 4090 under the validation layer (0 errors), and the full ctest at c1fe863 with Visual Studio's CMake 3.31.6 is 142/142.

@Vonsek, thank you for the RTX 5080 and gfx1036 runs.

kotorvr and others added 3 commits November 22, 2026 22:04
…cs; a PSO that needs it elsewhere is refused

create_vulkan_device_standalone never enabled fragmentStoresAndAtomics or
vertexPipelineStoresAndAtomics, so a pixel shader with a writable storage
image (an image atomic: 1,018 corpus pixel shaders) broke
VUID-RuntimeSpirv-NonWritable-06340 while CreateGraphicsPipelineState
answered S_OK.

The device enables both where the GPU has them. A graphics PSO whose stage
declares writable storage (src/spirv_stores.h reads the declarations) on a
device without the feature is refused with E_NOTIMPL and a log line.

spirv_stores_test checks the rule on hand-built SPIR-V; d3d12_stores_atomics_test
checks the refusal and the standalone device under the validation layer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s LEONIDA_VK_VALIDATION=0

A malformed module whose array type names itself made the element walk spin
inside CreateGraphicsPipelineState; it now stops after 16 levels, with a case in
spirv_stores_test. d3d12_stores_atomics_test turns the validation layer on for
itself only when the variable is unset. The docs say how the 1,018 of 1,038
figure is counted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…decoration group counts

An OpTypeImage with Sampled 2 and Dim SubpassData is a subpassInput, not a
storage image, so a pixel shader reading an input attachment no longer
needs fragmentStoresAndAtomics. NonWritable applied through
OpDecorationGroup / OpGroupDecorate / OpGroupMemberDecorate is resolved like
a direct decoration. spirv_stores_test covers both. Found in review.

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

Copy link
Copy Markdown

Tested c1fe863b (head, base main f847748c; it no longer merges cleanly onto current main 4c52ce27: conflict in runtime/CMakeLists.txt) on NVIDIA GeForce RTX 3060, driver 32.0.16.1714, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0: pass.

  • With LEONIDA_VK_VALIDATION=1: spirv_stores ..................... Passed 0.15 sec; d3d12_stores_atomics ............. Passed 1.30 sec, output the runtime's own device: fragmentStoresAndAtomics enabled, vertexPipelineStoresAndAtomics enabled; the PSO with the atomic pixel shader is created; validation errors: 0 and d3d12_stores_atomics_test: 2 device(s) passed (the other device logs, as intended, ps_image_atomic (ps) writes a storage image or buffer, which needs the Vulkan feature fragmentStoresAndAtomics; the device does not have it enabled, so the pipeline is refused).
  • Full ctest (-E "present|swapchain|frame_pacer", llvm-mc build): 100% tests passed, 0 tests failed out of 137 (8 skipped/disabled, same set as main: shader_library_corpus, bink_decode, fsr_dispatch, bvh_builder, bink_audio, gameinput, d3d12_rgb9e5_rtv, d3d12_first_light).
  • Needs a rebase for the CMakeLists.txt conflict.

AI-assisted (Claude). No game files.

@kotorvr
kotorvr force-pushed the fix/standalone-stores-atomics branch from c1fe863 to cbdbafa Compare November 22, 2026 22:22
@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@requiemsnkrp thank you for the RTX 3060 run. The CMakeLists.txt conflict you hit is resolved: the branch is rebased onto main 4c52ce2 (head cbdbafa; both test blocks kept), and GitHub reports it mergeable.

@Ingenioeren

Copy link
Copy Markdown
Contributor

128-byte software-device check of cbdbafa applied to aa2988cc on Windows 11, clang-cl/lld 23.1.5 and Vulkan validation 1.4.341.1. spirv_stores passed. The SwiftShader GPU test reached the plain PSO and failed before it could validate the feature-gating behavior: the fixture requests 144 push-constant bytes and the device exposes 128. The attached test-only patch uses the same existing size check as the other 144-byte D3D12 fixtures, so CTest records an explicit skip on SwiftShader. A 128-byte version of these fixtures can exercise the full path once the uniform-tail support lands.

On Radeon RX 6750 XT (256 bytes), both tests passed before and after the patch. The external Vulkan device without fragmentStoresAndAtomics refused the atomic PSO and successfully created the plain one. The runtime-owned device enabled the supported features and created the atomic PSO. Both paths reported zero validation errors. Synthetic fixtures only. AI-assisted.
d3d12-stores-atoms-128-skip.patch.txt

@lunisahdidouch

Copy link
Copy Markdown

Tested cbdbafa on an RX 9070 (RDNA4), AMD 26.11.1, Windows 11 (26300), VS 2022 Build Tools, RelWithDebInfo with SDL3: pass

  • d3d12_stores_atomics with the validation layer on, on both devices: the test's own device refuses the atomic PS with E_NOTIMPL and creates the plain one. The runtime's own device has fragmentStoresAndAtomics and vertexPipelineStoresAndAtomics enabled and creates the atomic PSO. 0 validation errors on either.
  • The same test with LEONIDA_VK_VALIDATION=0: same results, and it says it isn't checking errors.
  • Full ctest: 156 tests, 0 failed, including spirv_stores. The 8 skips are the package-gated ones plus vk_sync_validation and d3d12_first_light.
  • The docs tests are OK.

AI-assisted

@ItsNotRexed
ItsNotRexed merged commit 0177e62 into ItsNotRexed:main Nov 23, 2026
3 of 10 checks passed
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.

8 participants