Skip to content

Interop: declare the spin pass's buffer without globallycoherent - #12

Merged
phantoslayer21 merged 1 commit into
mainfrom
fix/interop-spin-no-globallycoherent
Nov 13, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
fix/interop-spin-no-globallycoherent

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Reported by @j0nsh1n in #7.

What changed and why

The done_mode=spin pass (PASS_SPIN in clean/runtime/interop/convert.cpp) declared its buffer as
globallycoherent RWBuffer<uint> spinBuf. The report in #7 says Wine's d3dcompiler_47 rejects that modifier under
Proton (E5030: Unknown modifier "globallycoherent"). The spin pass is one of the seven passes compiled when a context
is created, so the create failed. This change drops the modifier and adds a comment saying why that's correct.

Why the modifier isn't needed:

  • The spin pass touches spinBuf only through InterlockedAdd. The poll is InterlockedAdd(spinBuf[0], 0, o) and the
    timeout count is InterlockedAdd(spinBuf[1], 1, o). There is no plain load or store, and no other pass declares this
    buffer. The done flag it polls is written by the HIP stream (hipStreamWriteValue32) or by the rescue queue
    (WriteBufferImmediate), not by a shader.
  • The Direct3D 11.3 functional specification, section 7.14.4 "Global vs Group/Local Coherency on Non-Atomic UAV Reads"
    (https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm), restricts the "globally coherent"
    tag to non-atomic loads: "Atomic read-modify-write operations do not have this constraint [...] atomic operations are
    implemented by all hardware in a globally coherent way, regardless of whether the UAV has been tagged as "globally
    coherent" or not." The spec speaks of shader atomics and loads in other thread groups. A write from another queue or
    from the HIP stream is outside that rule with or without the tag, so removing the tag takes no documented guarantee
    away.
  • The UAV barrier after the spin dispatch still orders the work that follows it. That part is unchanged.

How it was tested

Tested: FXC, and Windows (the system's d3dcompiler_47, through the runtime and through a small harness).

Not tested: Wine / Proton, and done_mode=spin end to end. The mode needs the HIP executor, which was not run, so
the normal writer of the done flag (hipStreamWriteValue32) was never exercised against a running spin. done_mode
defaults to fence.

#7 asked to check that cs_5_0 still compiles and that done_mode=spin behaves as before. cs_5_0 compiles with FXC
and with Windows' compiler (not checked with Wine's). For done_mode=spin, the spin shader's bytecode differs only in
its UAV declaration (below); the mode itself was not run.

  • FXC (Windows SDK 10.0.26100 fxc.exe): each of the nine interop passes was compiled as cs_5_0 with the
    runtime's flags, entry points and defines (/O3, /E <entry>, /D PASS_X=1):

    • All 9 compile before and after the change, with no warnings. Seven are built when a context is created; motionpt
      and outtex are built on first use.
    • Only the spin pass's bytecode changes. Its disassembly differs in one line, the UAV declaration
      (dcl_uav_typed_buffer_glc becomes dcl_uav_typed_buffer). The atomic instructions are unchanged. The bytecode of
      the other eight passes is byte-identical before and after.
  • Interop test (clean/runtime/interop/tests/test_interop_d3d12.cpp) on an RX 9070 XT under Windows. The runtime
    DLL was built with clean/runner/build.py --runtime-only --no-embed --no-model-k, before and after the change:

    • 30 of 30 cases pass in both builds. The nohip case was left out because it loads the HIP runtime.
    • The suite's test executor has no done flag, so done_mode=spin falls back to the fence there (the runtime logs
      "done_mode=spin not available ..."). The suite does compile the spin shader at every context create.
  • Spin pass on the device: a small harness (not part of this PR) ran Converter::record_spin directly, with the
    same results before and after the change. It exited with a failure in both builds, because one case failed:

    • Polling a flag that never arrives ends in one counted timeout.
    • A flag already set ends the spin at once.
    • A flag written by a shader store on another queue about 50 ms later is seen by the running spin: 5 of 5 runs, no
      timeout. This is a stand-in writer; the product does not write the done flag with a shader.
    • A flag written with WriteBufferImmediate from another queue about 50 ms later (the rescue path's writer) was not
      seen by the running spin: 0 of 5 runs, one timeout each, the flag stayed at 0.
      This is the same before and after
      the change, so it does not depend on the modifier and is not caused by it. It is not addressed here.

    Neither writer of the done flag was shown to be seen by a running spin: the rescue writer fails as above, and the HIP
    stream writer was not run.

Refs #7.

The done_mode=spin pass (PASS_SPIN in clean/runtime/interop/convert.cpp)
reads and writes spinBuf only through InterlockedAdd. UAV atomics are
coherent across thread groups and the device whether or not the UAV is
declared globallycoherent; the tag only matters for non-atomic loads
(Direct3D 11.3 functional spec, 7.14.4 "Global vs Group/Local Coherency
on Non-Atomic UAV Reads"). Dropping it leaves the shader's behaviour
unchanged and lets HLSL compilers that reject the modifier, as reported
for Wine's d3dcompiler_47 in #7, build the interop shaders. Wine and
Proton were not tested.

With the Windows SDK's fxc (cs_5_0, /O3, the runtime's defines and
entry points) all nine interop passes compile before and after (seven
are built at context create, motionpt and outtex on first use). Only
the spin pass's bytecode changes, and its only difference is the UAV
declaration (dcl_uav_typed_buffer_glc -> dcl_uav_typed_buffer).

Reported-by: j0nsh1n
Refs: #7
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 15:31
@phantoslayer21
phantoslayer21 force-pushed the fix/interop-spin-no-globallycoherent branch from 4be4a40 to 2e71577 Compare November 13, 2026 15:31
@phantoslayer21
phantoslayer21 merged commit a8500cb into main Nov 13, 2026
2 checks passed
@phantoslayer21
phantoslayer21 deleted the fix/interop-spin-no-globallycoherent branch November 13, 2026 15:59
j0nsh1n added a commit to j0nsh1n/wronggpu that referenced this pull request Nov 13, 2026
clean/linux/run_wine_tests.py runs three tests in a Wine prefix set up
the way Proton sets up a game's (clean/linux/wine_env.py: vkd3d-proton
d3d12 / d3d12core, DXVK dxgi, Wine's vkd3d libraries for its builtin
d3dcompiler_47), with an optional self-built vkd3d-proton (--vkd3d):

- interop: the existing run-tests.sh (31 tests);
- rr-leak: the RR test host's tagloop job (pull request phantoslayer21#11) against a
  given wronggpu_runtime.dll with a synthetic RR model, with the 256 MiB
  limit of the Windows end-to-end test;
- ags-layout: wg_ags.hlsli's WMMA and conversion helpers on fixed
  register values against a CPU reference of the gfx12 semantics
  (new: ags_layout.hlsl, ags_layout_host.cpp).

run-tests.sh: -fms-extensions for clang-based MinGW (the __try in
descriptor_publish.h), and WG_WINE to pick Proton's wine over a system
wine64.

Verified on an RX 9070 XT, RADV, GE-Proton 11-11, with a vkd3d-proton
built with dxil-spirv PR #362: interop 31/31, rr-leak +37 MiB (limit
256), ags-layout 7/7. Each test fails on the bug it targets: interop
29/31 with "Unknown modifier globallycoherent" before pull request phantoslayer21#12,
rr-leak +2636 MiB with a runtime from before pull request phantoslayer21#11,
ags-layout at CreateComputePipelineState on stock vkd3d-proton; its
comparison rejects lane-swapped and half-swapped results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com>
j0nsh1n added a commit to j0nsh1n/wronggpu that referenced this pull request Nov 14, 2026
From the review of phantoslayer21#52:

- README: the globallycoherent count now agrees (29 of 31, before
  phantoslayer21#12). The leak figures are named as one run on an RX 9070 XT, RADV,
  GE-Proton 11-11 and vkd3d-proton 5b1089c8 + dxil-spirv #362: +2636 MiB
  with a runtime built before phantoslayer21#11, +37.2 MiB with the fix. The launcher
  red check describes what was run (a wg-core check broken on purpose).
  The player advice about DLLs next to the game exe is gone, and the
  opening says the tests don't make Linux a supported platform. The
  vkd3d-proton commit named is the one tested (5b1089c8). It also says
  that --work/prefix is reused if it already is a Wine prefix.
- ags_layout.hlsl: the FloatConversion opcode 0x1c names its source in
  this repository (f2h_hw in clean/rr_f/kernels/rr_fast.hlsli).
- wine_env.py: mscoree / mshtml off and winemenubuilder disabled, so a
  new prefix shows no Mono / Gecko dialog and writes no menu entries.
- run_wine_tests.py: rr-leak fails when video memory does not change at
  all (a stack reporting a constant CurrentUsage), and --work with a
  space is refused (the RR host's job file is split on spaces).

Verified on main c793823 + this branch, GE-Proton 11-11 with a fresh
--work: interop 31/31, rr-leak +37.2 MiB, ags-layout 7/7, launcher
73/230/186/18 checks. No new entries under ~/.local/share/applications.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com>
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.

1 participant