Skip to content

Runtime: refuse a native wave64 compute PSO on a 32-lane GPU (E_NOTIMPL, use --wave64-emulate) instead of building one that computes wrong results - #5282

Open
tedin7 wants to merge 2 commits into
ItsNotRexed:mainfrom
tedin7:wave64-pso-gate
Open

tedin7 wants to merge 2 commits into
ItsNotRexed:mainfrom
tedin7:wave64-pso-gate

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #5256 (comment).

What

A compute PSO whose shader was translated for 64 lanes without --wave64-emulate is now refused on a GPU that cannot give a compute stage 64 lanes (NVIDIA: minSubgroupSize = maxSubgroupSize = 32). CreateComputePipelineState returns E_NOTIMPL and logs one line:

[rt] d3d12: cs_w64x_readlane (cs) is a native wave64 shader and this device has no 64-wide subgroup for the stage (device sizes 32..32, default 32): pipeline refused, it would give wrong results; translate with --wave64-emulate (make_game.py --wave64-emulate auto does)

The line is rate-limited like the existing one: the first shader of the stage, then again at 10, 100, 1000... Refused shaders are counted apart from the built-but-inexact ones, so the first refusal always prints its line.

Why

On main this PSO is built with S_OK. It runs at 32 lanes and reads lanes 32-63 that do not exist, so the results are wrong. The only sign is a log line. Measured on an RTX 5080 (Linux, driver 580.65.06, Wine 11.0), with d3d12_subgroup_test at main 3faac557:

result words
expected (ISA) 121 121 16 97 16 100 100 121
native wave64 PSO on main (S_OK) 25 121 112 1 112 4 100 121
same shader with --wave64-emulate 121 121 16 97 16 100 100 121

#94 settled how wave64 runs on 32-wide GPUs: compute and mesh are translated with --wave64-emulate, which is exact at any subgroup size, and make_game.py --wave64-emulate auto picks it for such a GPU. So a native wave64 compute module on such a GPU always comes from a build made for another GPU or with --wave64-emulate off. Refusing the PSO makes that build mistake visible at pipeline creation. Before, it only showed up as wrong data further down the frame.

What does not change

  • Vertex, geometry and pixel shaders. These stages have no emulation (SHADER-10), and wave64_halves tiers A and B are exact at 32. They are still built and logged as before.
  • Wave32 shaders, emulated shaders, and devices that can give 64 (AMD, old RADV with compute-only size control). A device whose default is 64 but cannot require it (device_default) is also unchanged. Only decide_subgroup_size = unavailable with wanted size 64 on a compute stage is refused (subgroup_refused in runtime/src/subgroup_size.h).
  • Mesh: no mesh PSO exists on main. The mesh PSO PRs (Runtime: mesh-shader PSOs from pipeline state streams and DispatchMesh (D3D-29) #1712, Runtime: ExecuteIndirect with DISPATCH_MESH signatures and the M5 mesh gate (translated mesh shader) #3777) can call subgroup_refused the same way. It is left as compute-only here so the log line never says "refused" for a pipeline that was built.
  • Selecting an emulated module instead: the shader pack never holds both forms of one program. make_game.py translates each shader once, natively or emulated, so the layer has nothing to choose from.

Tests

  • d3d12_subgroup_test (GPU):
    • On a device without 64-wide compute subgroups, the native cs_w64x_readlane PSO must be E_NOTIMPL. On main the test let it pass with "not judged".
    • On every GPU, the layer is told the device has 32-wide subgroups only, and the native PSO must be refused. The refusal happens before any Vulkan object is made, so this is valid usage on AMD too.
    • The native wave64 compute probe follows the same rule.
  • subgroup_size_test (CPU): on NVIDIA-like properties, a native wave64 cs is refused. ps/vs/gs wave64, wave32 cs and emulated cs are not. On AMD-like properties, a native wave64 cs is not refused.

Runs (RTX 5080, Linux driver 580.65.06, Wine 11.0, clang-cl + xwin build):

  • d3d12_subgroup_test with this change: passes, and the native PSO is refused (0x80004001).
  • Negative control: the new d3d12_subgroup_test against main's layer fails at the refusal check, because the PSO is built.
  • ctest -R d3d12 -j4 under Wine, with and without this change: the only difference is d3d12_subgroup. 7 tests fail the same way on main and here: d3d12_fence_timing, d3d12_private_data, d3d12_descriptor, d3d12_indirect_dispatch_count, d3d12_subresource_copy, d3d12_residency, d3d12_heap_properties. 13 tests skip on both. d3d12_xdxr_rt timed out once on each side and passed on the final run.
  • subgroup_size_test passes.
  • An AMD GPU: RX 7600 (Windows, LLPC) by @ricardotanaka and an AMD iGPU by @shdann: native wave64 is still built and exact. RTX 4090 (Windows) by @shdann: refused, same wrong words on main.

No game data. AI-assisted.

…bgroups

A compute shader translated for 64 lanes without --wave64-emulate was built on a
device that cannot give it 64 lanes (NVIDIA: 32..32) and read lanes 32-63 that
are not there: on an RTX 5080, cs_w64x_readlane gave 25 121 112 1 112 4 100 121
instead of 121 121 16 97 16 100 100 121, with S_OK and a log line. Compute has an
exact translation for any size (--wave64-emulate, picked by make_game.py
--wave64-emulate auto, ItsNotRexed#94), so CreateComputePipelineState now returns E_NOTIMPL
with one line naming that build, before any Vulkan object is made.
Vertex, geometry and pixel shaders have no emulation and are built as before.

d3d12_subgroup_test expects the refusal on such a GPU, and on every GPU when the
layer is told the device has 32-wide subgroups only; subgroup_size_test checks
which pipelines are refused (no GPU).
…probe check follows the refusal rule

Review fixes on the wave64 refusal:
- report_subgroup_unavailable counted refused and built shaders of a stage
  together, so a refusal after an inexact wave32 compute shader could be
  silent. They are counted apart now.
- d3d12_subgroup_test's compute probe expected a refusal only where
  maxSubgroupSize < 64; it now expects one exactly where the decision for the
  native wave64 probe is unavailable, and S_OK everywhere else. The native
  case prints BUILT when the layer builds it (main), refused otherwise.
@ricardotanaka

ricardotanaka commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested e720a87c (merged on main 3faac557) on AMD Radeon RX 7600 (RDNA3), AMD driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11 Pro 26200, MSVC 19.44 build: pass. This covers the open "An AMD GPU" box.

  • ctest -R subgroup (d3d12_subgroup, subgroup_size): 2/2, with and without LEONIDA_VK_VALIDATION=1 (validation on: 0 messages).
  • The device reports subgroup sizes 32..64 (default 64), size control on, full subgroups on.
  • Native wave64 cs_w64x_readlane is still built: outcome 1, required size 64, full subgroups yes, result exact (121 121 16 97 16 100 100 121); the emulated module is exact too.
  • Faked 32-only device: the native wave64 PSO is refused, with the new log line (device sizes 32..32).
  • Wave32 cs, the compute/pixel probes and ps_w64x_readlane (4096/4096 pixels exact) behave as expected; the test ends with "4 shaders judged exact".

AI-assisted (Claude Code).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted. Tested e720a87 on Windows 11 with Vulkan validation on. The RTX 4090 refuses the native wave64 compute pipeline with E_NOTIMPL (0x80004001). The emulated shader returns all eight expected words: 121 121 16 97 16 100 100 121.

I rebuilt main 3faac55 separately. On the same RTX 4090, main builds the native pipeline and returns 25 121 112 1 112 4 100 121. Its test exits 0 even though it prints DIFFERS. This comparison checks the actual shader output.

On the AMD Radeon(TM) Graphics iGPU, the head selects a 64-wide subgroup for the native pipeline. Native and emulated runs both return all eight expected words.

I built d3d12_subgroup_test and subgroup_size_test in RelWithDebInfo. I set LEONIDA_VK_VALIDATION=1 and ran ctest -C RelWithDebInfo -V -R "^(subgroup_size|d3d12_subgroup)$" in the head build with each device filter (LEONIDA_VK_DEVICE=4090 and Radeon). Both tests pass on each adapter. Each test log names the selected device.

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

Reviewed head e720a87cc (worktree detached from pr/5282, diff vs origin/main).

  • Configured with LLVM_MC='wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc', Ninja, RelWithDebInfo, BUILD_TESTING=ON, LEONIDA_BUILD_WINDOWS_RUNTIME=ON, Vulkan 1.4.363; cmake --build build-5282 --target subgroup_size_test d3d12_subgroup_test → built.
  • LEONIDA_VK_DEVICE='RTX 5070 Ti' ctest --test-dir build-5282 -R "^(subgroup_size|d3d12_subgroup)$" → 2/2 passed.
  • GPU run on NVIDIA RTX 5070 Ti (sizes 32..32): native w64 cs PSO refused (0x80004001), emulated exact, forced 32-only caps refused; 2 shaders judged exact.
  • Control with main's d3d12_vulkan_device.cpp and subgroup_size.h plus this test: PSO BUILT (0x00000000), exit 1 at line 556: result.pso == E_NOTIMPL.
  • git diff --check clean; git merge-tree origin/main pr/5282 clean.

Verdict: pass on NVIDIA; no blockers. AMD remains unverified, as the body says: the AMD-like CPU case and the forced-32 refusal check cover the decision logic, not a real AMD driver.

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

Summary: The runtime adds subgroup_refused in runtime/src/subgroup_size.h and refuses native wave64 compute PSOs on devices without 64-wide subgroups with E_NOTIMPL and a one-line --wave64-emulate hint. Refused pipelines are logged separately; docs and D3D12/subgroup tests cover real and forced-32 devices.

Why merge: It prevents silent wrong results from reading missing lanes while keeping report-only behavior for graphics stages without emulation.

Verdict: Approve

@larpinguser

Copy link
Copy Markdown

Summary: The runtime adds subgroup_refused in runtime/src/subgroup_size.h and refuses native wave64 compute PSOs on devices without 64-wide subgroups with E_NOTIMPL and a one-line --wave64-emulate hint. Refused pipelines are logged separately; docs and D3D12/subgroup tests cover real and forced-32 devices.

Why merge: It prevents silent wrong results from reading missing lanes while keeping report-only behavior for graphics stages without emulation.

Verdict: Approve

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.

5 participants