From a4e8365063be7cf2d68c7c9b8fff8276cc603db6 Mon Sep 17 00:00:00 2001 From: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> Date: Fri, 13 Nov 2026 09:39:59 -0800 Subject: [PATCH 1/4] test: run WrongGPU's D3D12 tests under Proton on Linux 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 #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 #12, rr-leak +2636 MiB with a runtime from before pull request #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 Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> --- clean/linux/README.md | 58 +++++ clean/linux/ags_layout.hlsl | 49 ++++ clean/linux/ags_layout_host.cpp | 158 ++++++++++++ clean/linux/run_wine_tests.py | 293 +++++++++++++++++++++++ clean/linux/wine_env.py | 83 +++++++ clean/runtime/interop/tests/run-tests.sh | 4 +- 6 files changed, 644 insertions(+), 1 deletion(-) create mode 100644 clean/linux/README.md create mode 100644 clean/linux/ags_layout.hlsl create mode 100644 clean/linux/ags_layout_host.cpp create mode 100644 clean/linux/run_wine_tests.py create mode 100644 clean/linux/wine_env.py diff --git a/clean/linux/README.md b/clean/linux/README.md new file mode 100644 index 00000000..54fd9d10 --- /dev/null +++ b/clean/linux/README.md @@ -0,0 +1,58 @@ +# WrongGPU on Linux: D3D12 tests under Proton + +Players on Linux run WrongGPU's Windows DLLs inside Proton. There, Direct3D 12 is vkd3d-proton on top of RADV, +`d3dcompiler_47.dll` is Wine's own (vkd3d-shader), and the driver channel that the D3D12 kernels use for WMMA +(`clean/dx12/hlsl/wg_ags.hlsli`) is translated by vkd3d-proton's dxil-spirv instead of AMD's driver. These tests run +WrongGPU's D3D12 code on that stack, so a release can be checked for Linux players before it ships. + +```sh +python3 clean/linux/run_wine_tests.py --proton [--vkd3d ] [--runtime ] +``` + +The tests use WrongGPU's own synthetic data only: no model converted from a DLSS file, no game files. + +## What it checks + +| Test | What runs | What it would catch | +|---|---|---| +| `interop` | `clean/runtime/interop/tests/run-tests.sh` (31 tests): MinGW build of the runtime with the `d3d12-test` executor | interop shaders that Wine's `d3dcompiler_47` rejects (`globallycoherent` in `PASS_SPIN` failed all 31), copy / convert / split regressions on vkd3d-proton | +| `rr-leak` | the RR runtime test host's `tagloop` job against `--runtime`, with a synthetic RR model (`pack_model --synthetic 5100`) | RR input copies retained and released every frame with no RR instance piling up in video memory (+2,635 MiB in 200 frames before the fix in `release_transient_locked`, +37 MiB after) | +| `ags-layout` | `ags_layout.hlsl`: `wg_ags_mma` (FP16, FP8), `wg_ags_convert` (F32 accumulator to F16 accumulator and FP8 B, FP8 B to F32 for all 256 codes), the F16 `FloatConversion` call, a wave64 conversion | a translation of the driver channel that does not keep the gfx12 register semantics the kernels rely on; checked against a CPU reference (multiplies within 1e-5, everything else bit-exact) | + +The `--runtime` DLL is the one to be released: the MSVC release build works as it is. `interop` builds its own +development runtime with MinGW, and the hosts of `rr-leak` and `ags-layout` are MinGW builds too. They are test +programs only, never shipped (the release rule in `clean/fsr/build-mingw.sh`). + +## What you need + +- Linux with an AMD RDNA 4 GPU (RX 9070 or RX 9060 family) and Mesa's RADV driver. +- A Proton install: `--proton`, or the environment variable `WG_PROTON`. For example, a GE-Proton folder in + `~/.local/share/Steam/compatibilitytools.d/`, or Steam's `steamapps/common/Proton - Experimental`. +- A MinGW-w64 C++ compiler: `MINGW_CXX`, otherwise `x86_64-w64-mingw32-g++-posix` or `x86_64-w64-mingw32-g++` + on `PATH`. llvm-mingw works too. The tests add `-fms-extensions` for clang. +- For `ags-layout`: the Linux `dxc` from the DXC release named in BUILDING.md, in `WG_DXC` or on `PATH`. +- Python 3 with NumPy. + +## vkd3d-proton + +`rr-leak` and `ags-layout` need the WMMA channel. Released vkd3d-proton cannot translate it yet: dxil-spirv accepts only +WMMA operands that come from AGS matrix loads, and WrongGPU's kernels pack their fragments themselves. The support is in +https://github.com/HansKristian-Work/dxil-spirv/pull/362. Until a Proton release ships it, build vkd3d-proton with +that change. Use the vkd3d-proton commit your Proton ships, for example `0bb64c5` in GE-Proton 11-11. Then pass the +folder that holds the resulting `d3d12.dll` and `d3d12core.dll` with `--vkd3d`. Without it these two tests fail at +`CreateComputePipelineState` (`0x80070057`). On the player's side, the same patched DLLs next to the game exe make +Model M and Ray Reconstruction run. + +## Reading the result + +Each test prints `PASS`, `FAIL` or `SKIP` with a reason, and a summary follows at the end. The exit status is 1 when a +test failed. Everything a test writes goes to `--work`, by default `build/linux-tests/`: + +- `interop/result.txt`: the 31 tests' output; +- `rr-leak/host.log`, and `rr-leak/stage/wronggpu-rr.log` for the runtime's own log; +- `ags-layout/host.log`, `inputs.bin` and `outputs.bin`. + +Each failure was checked to show up in this suite. Run on the unfixed `convert.cpp`, `interop` fails 29 of 31 with +`Unknown modifier "globallycoherent"`. With the 0.6.0 RR runtime, `rr-leak` reports +2,635 MiB. On stock +vkd3d-proton, `ags-layout` stops at `CreateComputePipelineState`. Fed results with lanes in the wrong order or F16 +halves swapped, its comparison fails. diff --git a/clean/linux/ags_layout.hlsl b/clean/linux/ags_layout.hlsl new file mode 100644 index 00000000..0a72d514 --- /dev/null +++ b/clean/linux/ags_layout.hlsl @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MIT +// WrongGPU's driver-channel helpers (clean/dx12/hlsl/wg_ags.hlsli) on fixed register dwords, for the Linux test of +// the D3D12 translation layer (clean/linux/run_wine_tests.py, test ags-layout). Under Proton the channel is translated +// by vkd3d-proton's dxil-spirv; this checks that the results are the gfx12 register semantics the kernels rely on. +// Buffer io (u1): inputs at 0 (A16, B16, C, A8, B8, all FP8 codes: 1 KiB each, 32 lanes x 8 dwords), outputs from 6 KiB +// (one 1 KiB slot per case; slot 6 is the wave64 case). +#include "wg_ags.hlsli" +RWByteAddressBuffer io : register(u1); + +wg_frag load_frag(uint base, uint lane, uint n) +{ + wg_frag f; + [unroll] for (uint i = 0; i < 8; ++i) f.v[i] = i < n ? io.Load(base + (lane * 8 + i) * 4) : 0u; + return f; +} + +void store_frag(uint slot, uint lane, wg_frag f) +{ + [unroll] for (uint i = 0; i < 8; ++i) io.Store(6 * 1024 + slot * 1024 + (lane * 8 + i) * 4, f.v[i]); +} + +[WaveSize(32)] +[numthreads(32, 1, 1)] +void main32(uint lane : SV_GroupThreadID) +{ + wg_frag a16 = load_frag(0, lane, 4), b16 = load_frag(1024, lane, 4), c = load_frag(2048, lane, 8); + wg_frag a8 = load_frag(3072, lane, 2), b8 = load_frag(4096, lane, 2); + store_frag(0, lane, wg_ags_mma(WG_AGS_F16_F32, a16, b16, c)); + store_frag(1, lane, wg_ags_mma(WG_AGS_FP8_F32, a8, b8, c)); + store_frag(2, lane, wg_ags_convert(c, WG_AGS_T_F32_ACC, WG_AGS_T_F16_ACC)); + store_frag(3, lane, wg_ags_convert(c, WG_AGS_T_F32_ACC, WG_AGS_T_FP8_B)); + wg_frag h; + [unroll] for (uint i = 0; i < 8; ++i) h.v[i] = wg_ags_call(0x1cu, 0u, 1u, c.v[i], 0u); // FloatConversion, F16 near + store_frag(4, lane, h); + store_frag(5, lane, wg_ags_convert(load_frag(5 * 1024, lane, 2), WG_AGS_T_FP8_B, WG_AGS_T_F32_ACC)); +} + +// post.hlsl's cvt3_f16 in a wave64 kernel: lane l converts C values 3l .. 3l+2 (mod 256). +[WaveSize(64)] +[numthreads(64, 1, 1)] +void main64(uint lane : SV_GroupThreadID) +{ + wg_frag f; + [unroll] for (uint i = 0; i < 3; ++i) f.v[i] = io.Load(2048 + ((3 * lane + i) % 256) * 4); + [unroll] for (uint i = 3; i < 8; ++i) f.v[i] = 0u; + wg_frag r = wg_ags_convert(f, WG_AGS_T_F32_ACC, WG_AGS_T_F16_ACC); + io.Store(6 * 1024 + 6 * 1024 + (2 * lane) * 4, r.v[0]); + io.Store(6 * 1024 + 6 * 1024 + (2 * lane + 1) * 4, r.v[1] & 0xffffu); +} diff --git a/clean/linux/ags_layout_host.cpp b/clean/linux/ags_layout_host.cpp new file mode 100644 index 00000000..50da38b5 --- /dev/null +++ b/clean/linux/ags_layout_host.cpp @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +// D3D12 host of the ags-layout test (clean/linux/run_wine_tests.py): runs the wave32 and the wave64 entry point of +// ags_layout.hlsl once each and writes the output slots. Root signature as the runtime's kernels bind the driver +// channel: a descriptor table with one raw UAV at u0, space 0x7FFF0ADE, and a root UAV (u1) for the data. +// ags_layout_host +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include + +static void need(HRESULT hr, const char* what) { + if (FAILED(hr)) { + std::printf("FAIL %s 0x%08lx\n", what, (unsigned long)hr); + std::exit(1); + } +} + +static std::vector read_file(const char* path) { + std::vector d; + FILE* f = std::fopen(path, "rb"); + if (!f) return d; + std::fseek(f, 0, SEEK_END); + d.resize(std::ftell(f)); + std::fseek(f, 0, SEEK_SET); + if (std::fread(d.data(), 1, d.size(), f) != d.size()) d.clear(); + std::fclose(f); + return d; +} + +static ID3D12Resource* buffer(ID3D12Device* dev, D3D12_HEAP_TYPE type, UINT64 size, D3D12_RESOURCE_STATES state, + D3D12_RESOURCE_FLAGS flags) { + D3D12_HEAP_PROPERTIES hp = {}; + hp.Type = type; + D3D12_RESOURCE_DESC rd = {}; + rd.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; + rd.Width = size; + rd.Height = 1; + rd.DepthOrArraySize = 1; + rd.MipLevels = 1; + rd.SampleDesc.Count = 1; + rd.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; + rd.Flags = flags; + ID3D12Resource* r = nullptr; + need(dev->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &rd, state, nullptr, IID_PPV_ARGS(&r)), "buffer"); + return r; +} + +int main(int argc, char** argv) { + if (argc != 5) { + std::puts("usage: ags_layout_host "); + return 2; + } + const std::vector cs32 = read_file(argv[1]), cs64 = read_file(argv[2]), in = read_file(argv[3]); + const size_t in_size = 6 * 1024, out_size = 7 * 1024, io_size = in_size + out_size; + if (cs32.empty() || cs64.empty() || in.size() != in_size) { + std::puts("FAIL inputs"); + return 2; + } + + ID3D12Device* dev = nullptr; + need(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&dev)), "D3D12CreateDevice"); + + D3D12_DESCRIPTOR_RANGE range = {D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0x7FFF0ADE, 0}; + D3D12_ROOT_PARAMETER params[2] = {}; + params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + params[0].DescriptorTable = {1, &range}; + params[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV; + params[1].Descriptor = {1, 0}; + D3D12_ROOT_SIGNATURE_DESC rsd = {2, params, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE}; + ID3DBlob *blob = nullptr, *err = nullptr; + need(D3D12SerializeRootSignature(&rsd, D3D_ROOT_SIGNATURE_VERSION_1, &blob, &err), "serialize root signature"); + ID3D12RootSignature* rs = nullptr; + need(dev->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&rs)), + "root signature"); + + D3D12_COMPUTE_PIPELINE_STATE_DESC pd = {}; + pd.pRootSignature = rs; + ID3D12PipelineState *pso32 = nullptr, *pso64 = nullptr; + pd.CS = {cs32.data(), cs32.size()}; + need(dev->CreateComputePipelineState(&pd, IID_PPV_ARGS(&pso32)), "CreateComputePipelineState wave32"); + pd.CS = {cs64.data(), cs64.size()}; + need(dev->CreateComputePipelineState(&pd, IID_PPV_ARGS(&pso64)), "CreateComputePipelineState wave64"); + + D3D12_DESCRIPTOR_HEAP_DESC hd = {D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1, + D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, 0}; + ID3D12DescriptorHeap* heap = nullptr; + need(dev->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&heap)), "descriptor heap"); + ID3D12Resource* channel = buffer(dev, D3D12_HEAP_TYPE_DEFAULT, 256, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); + D3D12_UNORDERED_ACCESS_VIEW_DESC ud = {}; + ud.Format = DXGI_FORMAT_R32_TYPELESS; + ud.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; + ud.Buffer.NumElements = 64; + ud.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; + dev->CreateUnorderedAccessView(channel, nullptr, &ud, heap->GetCPUDescriptorHandleForHeapStart()); + + ID3D12Resource* io = buffer(dev, D3D12_HEAP_TYPE_DEFAULT, io_size, D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); + ID3D12Resource* up = buffer(dev, D3D12_HEAP_TYPE_UPLOAD, io_size, D3D12_RESOURCE_STATE_GENERIC_READ, + D3D12_RESOURCE_FLAG_NONE); + ID3D12Resource* rb = buffer(dev, D3D12_HEAP_TYPE_READBACK, io_size, D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_FLAG_NONE); + void* p = nullptr; + need(up->Map(0, nullptr, &p), "map upload"); + std::memset(p, 0, io_size); + std::memcpy(p, in.data(), in.size()); + up->Unmap(0, nullptr); + + D3D12_COMMAND_QUEUE_DESC qd = {D3D12_COMMAND_LIST_TYPE_DIRECT, 0, D3D12_COMMAND_QUEUE_FLAG_NONE, 0}; + ID3D12CommandQueue* q = nullptr; + need(dev->CreateCommandQueue(&qd, IID_PPV_ARGS(&q)), "queue"); + ID3D12CommandAllocator* ca = nullptr; + need(dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&ca)), "allocator"); + ID3D12GraphicsCommandList* cl = nullptr; + need(dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, ca, pso32, IID_PPV_ARGS(&cl)), "command list"); + cl->CopyResource(io, up); + D3D12_RESOURCE_BARRIER b = {}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition = {io, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS}; + cl->ResourceBarrier(1, &b); + cl->SetComputeRootSignature(rs); + cl->SetDescriptorHeaps(1, &heap); + cl->SetComputeRootDescriptorTable(0, heap->GetGPUDescriptorHandleForHeapStart()); + cl->SetComputeRootUnorderedAccessView(1, io->GetGPUVirtualAddress()); + cl->Dispatch(1, 1, 1); + cl->SetPipelineState(pso64); + cl->Dispatch(1, 1, 1); + b.Transition = {io, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, + D3D12_RESOURCE_STATE_COPY_SOURCE}; + cl->ResourceBarrier(1, &b); + cl->CopyResource(rb, io); + need(cl->Close(), "close"); + ID3D12CommandList* lists[] = {cl}; + q->ExecuteCommandLists(1, lists); + ID3D12Fence* fence = nullptr; + need(dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), "fence"); + need(q->Signal(fence, 1), "signal"); + HANDLE ev = CreateEventW(nullptr, FALSE, FALSE, nullptr); + need(fence->SetEventOnCompletion(1, ev), "event"); + if (WaitForSingleObject(ev, 10000) != WAIT_OBJECT_0) { + std::puts("FAIL GPU timeout"); + return 3; + } + need(dev->GetDeviceRemovedReason(), "device removed"); + need(rb->Map(0, nullptr, &p), "map readback"); + FILE* f = std::fopen(argv[4], "wb"); + if (!f || std::fwrite(static_cast(p) + in_size, 1, out_size, f) != out_size) { + std::puts("FAIL writing outputs"); + return 4; + } + std::fclose(f); + std::puts("ags-layout outputs written"); + return 0; +} diff --git a/clean/linux/run_wine_tests.py b/clean/linux/run_wine_tests.py new file mode 100644 index 00000000..6cd67272 --- /dev/null +++ b/clean/linux/run_wine_tests.py @@ -0,0 +1,293 @@ +# SPDX-License-Identifier: MIT +"""WrongGPU's D3D12 tests on Linux, under Wine with the D3D12 stack of a Proton install (vkd3d-proton, DXVK's dxgi, +vkd3d-shader), the stack a game runs on in Steam. + + python3 clean/linux/run_wine_tests.py --proton [--vkd3d ] [--runtime ] + [--tests interop,rr-leak,ags-layout] [--work ] + +Tests (all run by default; each prints PASS, FAIL or SKIP with the reason; the exit status is 1 when one fails): + interop clean/runtime/interop/tests/run-tests.sh: MinGW build of the runtime with the d3d12-test executor, run + in the prefix (copy / convert passes, split protocol, failure paths; the interop shaders compiled by + Wine's d3dcompiler_47). + rr-leak the RR runtime test host's `tagloop` job against --runtime (a wronggpu_runtime.dll with the RR runtime, + e.g. the release build) and a synthetic RR model (pack_model --synthetic): RR input copies retained and + released every frame with no instance must not pile up in video memory. + ags-layout WrongGPU's driver-channel helpers (wg_ags.hlsli: FP16 and FP8 WMMA, matrix conversions, the F16 + conversion, a wave64 conversion) on fixed register values, against a CPU reference of the gfx12 register + semantics. Under Proton the channel is translated by vkd3d-proton's dxil-spirv. +rr-leak and ags-layout need the WMMA channel, i.e. a vkd3d-proton with dxil-spirv's shader-packed fragment support +(https://github.com/HansKristian-Work/dxil-spirv/pull/362): pass a self-built one with --vkd3d until Proton ships it. + +Tools (environment): MINGW_CXX (default x86_64-w64-mingw32-g++-posix, then x86_64-w64-mingw32-g++), WG_DXC (a Linux +dxc binary of the DXC release, default `dxc` on PATH). Python with NumPy. Needs an AMD RDNA 4 GPU with RADV. +""" +import argparse +import os +import re +import shutil +import subprocess +import sys +from pathlib import Path + +import numpy as np + +HERE = Path(__file__).resolve().parent +REPO = HERE.parents[1] +sys.path.insert(0, str(HERE)) +import wine_env # noqa: E402 + + +def log(msg): + print(msg, flush=True) + + +def mingw_cxx(): + for c in (os.environ.get("MINGW_CXX"), "x86_64-w64-mingw32-g++-posix", "x86_64-w64-mingw32-g++"): + if c and shutil.which(c): + return shutil.which(c) + return None + + +def build_exe(cxx, sources, out, includes=(), libs=()): + cmd = [cxx, "-std=c++17", "-O2", "-static", *sources, "-o", str(out), *[f"-I{i}" for i in includes], *libs] + if "clang" in subprocess.run([cxx, "--version"], capture_output=True, text=True).stdout.lower(): + cmd.insert(1, "-fms-extensions") + r = subprocess.run(cmd, capture_output=True, text=True) + if r.returncode != 0: + raise RuntimeError(f"building {out.name} failed:\n{r.stderr[-3000:]}") + + +def run_wine(env, args, cwd, timeout): + r = subprocess.run([env["WG_WINE"], *args], cwd=cwd, env=env, capture_output=True, text=True, errors="replace", + timeout=timeout) + return r.returncode, r.stdout.replace("\r", "") + r.stderr.replace("\r", "") + + +# ---- interop -------------------------------------------------------------------------------------------------------- +def test_interop(a, env, work): + cxx = mingw_cxx() + if not cxx: + return "SKIP", "no MinGW-w64 C++ compiler (MINGW_CXX)" + out = work / "interop" + e = dict(env, MINGW_CXX=cxx, WG_TEST_DIR=str(out)) + # run-tests.sh makes its own prefix under WG_TEST_DIR unless WINEPREFIX is set: use the prepared one + r = subprocess.run(["bash", str(REPO / "clean/runtime/interop/tests/run-tests.sh")], env=e, capture_output=True, + text=True, errors="replace", timeout=3600) + (out / "run.log").write_text(r.stdout + r.stderr) + text = (out / "result.txt").read_text(errors="replace") if (out / "result.txt").exists() else "" + passed = len(re.findall(r": passed$", text, re.M)) + failed = re.findall(r"^(\S+): FAILED$", text, re.M) + if "ALL TESTS PASSED" in text and r.returncode == 0: + return "PASS", f"{passed} tests passed" + if text.startswith("SKIP") or "SKIP:" in text: + return "FAIL", "the test skipped itself: " + text.strip().splitlines()[-1] + " (no D3D12 device in the prefix?)" + return "FAIL", f"{passed} passed, {len(failed)} failed ({', '.join(failed[:6])}); see {out / 'result.txt'}" + + +# ---- rr-leak -------------------------------------------------------------------------------------------------------- +def test_rr_leak(a, env, work): + if not a.runtime: + return "SKIP", "needs --runtime with the RR runtime linked in" + cxx = mingw_cxx() + if not cxx: + return "SKIP", "no MinGW-w64 C++ compiler (MINGW_CXX)" + out = work / "rr-leak" + stage, run = out / "stage", out / "run" + for d in (stage, run): + d.mkdir(parents=True, exist_ok=True) + host = out / "rr_test_host.exe" + rr = REPO / "clean/rr_f" + build_exe(cxx, [str(rr / "runtime/tests/rr_test_host.cpp")], host, + includes=[rr / "runtime/src", rr / "proxy/include", rr / "proxy/src"], libs=["-ld3d12", "-ldxgi"]) + model = stage / "wronggpu_rr_model.bin" # original synthetic model (no learned weights) + if not model.exists(): + subprocess.run([sys.executable, "-m", "clean.rr_f.runtime.tools.pack_model", "--synthetic", "5100", "--out", + str(model)], cwd=REPO, check=True, capture_output=True) + shutil.copyfile(a.runtime, stage / "wronggpu_runtime.dll") + job = out / "job.txt" + # the limit of the Windows end-to-end test (clean/rr_f/runtime/tests/e2e.py, TAGLOOP_LIMIT_MIB) + job.write_text(f"outdir {wine_env.windows_path(out)}\nruntime {wine_env.windows_path(stage / 'wronggpu_runtime.dll')}\n" + f"tagloop 200 1706 960 256\nend\n") + rc, text = run_wine(env, [str(host), str(job)], run, 1800) + (out / "host.log").write_text(text) + m = re.search(r"^tagloop: .*$", text, re.M) + if not m: + sd = re.search(r"set_device (\d+)", text) + why = f"runtime set_device returned {sd.group(1)}" if sd and sd.group(1) != "0" else "no tagloop line" + return "FAIL", (f"{why}; RR could not start (stock vkd3d-proton without dxil-spirv #362? use --vkd3d); " + f"see {out / 'host.log'} and {stage / 'wronggpu-rr.log'}") + return ("PASS" if rc == 0 and m.group(0).endswith(": ok") else "FAIL"), m.group(0) + + +# ---- ags-layout ----------------------------------------------------------------------------------------------------- +E4M3 = np.array([(-1.0 if b & 0x80 else 1.0) * ((b & 7) / 8.0 * 2.0 ** -6 if (b >> 3) & 15 == 0 + else (1 + (b & 7) / 8.0) * 2.0 ** (((b >> 3) & 15) - 7)) for b in range(256)]) +E4M3[[0x7f, 0xff]] = np.nan + + +def e4m3_rne(x): + """FP32 -> E4M3FN byte, round to nearest even, no saturation (inputs stay within +-448).""" + mag = E4M3[:0x7f] + i = int(np.argmin(np.abs(mag - abs(x)))) + if i + 1 < 0x7f and abs(mag[i + 1] - abs(x)) == abs(mag[i] - abs(x)) and (i & 1): + i += 1 + return i | (0x80 if np.signbit(x) else 0) + + +def f16_bits(x): + return int(np.float32(x).astype(np.float16).view(np.uint16)) + + +def ags_inputs(): + rng = np.random.default_rng(20261112) + lanes = 32 + + def f16_regs(): + h = rng.uniform(-4.0, 4.0, size=(lanes, 8)).astype(np.float16) + return np.concatenate([h.view(np.uint32)[:, :4], np.zeros((lanes, 4), np.uint32)], axis=1) + + def fp8_regs(): + b = rng.integers(0, 256, size=(lanes, 8), dtype=np.uint8) + b[(b & 0x7f) == 0x7f] ^= 0x01 # no NaN codes in the WMMA operands + return np.concatenate([b.view(np.uint32), np.zeros((lanes, 6), np.uint32)], axis=1) + + c = rng.uniform(-400.0, 400.0, size=(lanes, 8)).astype(np.float32) + ties = np.array([1.0625, -1.0625, 1.1875, 2.125, 0.0, -0.0, 448.0, 1.0 + 2.0 ** -11, 1.0 + 3 * 2.0 ** -11, + 6.103515625e-05, 3.0517578125e-05, -2.384185791015625e-07], np.float32) + c.reshape(-1)[:ties.size] = ties + every = np.zeros((lanes, 8), np.uint32) + every[:, :2] = np.arange(256, dtype=np.uint8).reshape(lanes, 8).view(np.uint32) + return np.stack([f16_regs(), f16_regs(), c.view(np.uint32), fp8_regs(), fp8_regs(), every]) + + +def ags_expected(inp): + """Expected output slots (7 x 32 x 8 dwords; slot 6: 64 lanes x 2 dwords) and the per-slot comparison kind.""" + c = inp[2].view(np.float32) + exp = np.zeros((7, 32, 8), np.uint32) + + def mma(a, b): # gfx12 wave32 16x16x16: A lane l = row l%16, k 8(l//16)+e; B col l%16; C/D col l%16, row 8(l//16)+e + A = np.zeros((16, 16)); B = np.zeros((16, 16)); C = np.zeros((16, 16)) + for l in range(32): + for e in range(8): + A[l % 16, 8 * (l // 16) + e] = a[l, e] + B[8 * (l // 16) + e, l % 16] = b[l, e] + C[8 * (l // 16) + e, l % 16] = c[l, e] + D = A @ B + C + return np.array([[D[8 * (l // 16) + e, l % 16] for e in range(8)] for l in range(32)], np.float32) + + exp[0] = mma(inp[0][:, :4].copy().view(np.float16).astype(np.float64), + inp[1][:, :4].copy().view(np.float16).astype(np.float64)).view(np.uint32) + exp[1] = mma(E4M3[inp[3][:, :2].copy().view(np.uint8)], E4M3[inp[4][:, :2].copy().view(np.uint8)]).view(np.uint32) + for l in range(32): + for i in range(4): + exp[2, l, i] = f16_bits(c[l, 2 * i]) | f16_bits(c[l, 2 * i + 1]) << 16 + q = [e4m3_rne(float(v)) for v in c[l]] + exp[3, l, 0] = q[0] | q[1] << 8 | q[2] << 16 | q[3] << 24 + exp[3, l, 1] = q[4] | q[5] << 8 | q[6] << 16 | q[7] << 24 + exp[4, l] = [f16_bits(v) for v in c[l]] + exp[5, l] = np.float32(E4M3[inp[5][l, :2].copy().view(np.uint8)]).view(np.uint32) + flat = c.reshape(-1) + w64 = exp[6].reshape(-1) + for l in range(64): + h = [f16_bits(flat[(3 * l + i) % 256]) for i in range(3)] + w64[2 * l], w64[2 * l + 1] = h[0] | h[1] << 16, h[2] + return exp + + +AGS_CASES = ("mma f16->f32", "mma fp8->f32", "convert f32 acc->f16", "convert f32 acc->fp8 B", + "FloatConversion f32->f16", "convert fp8 B->f32 (all 256 codes)", "wave64 cvt3_f16") + + +def ags_compare(got, exp): + lines, ok = [], True + for s, name in enumerate(AGS_CASES): + g, e = got[s].reshape(-1), exp[s].reshape(-1) + if s == 6: + g, e = g[:128], e[:128] + if s < 2: # the hardware accumulates in f32 in its own order: compare against the f64 product with a tolerance + gf, ef = g.view(np.float32).astype(np.float64), e.view(np.float32).astype(np.float64) + err = float(np.max(np.abs(gf - ef) / np.maximum(1.0, np.abs(ef)))) + good = err < 1e-5 + lines.append(f" {name:36s} {'ok ' if good else 'BAD'} max rel err {err:.2e}") + else: + if s == 5: # NaN codes: any NaN + gn, en = np.isnan(g.view(np.float32)), np.isnan(e.view(np.float32)) + bad = int(np.sum((g != e) & ~(gn & en))) + else: + bad = int(np.sum(g != e)) + good = bad == 0 + lines.append(f" {name:36s} {'ok ' if good else 'BAD'} {bad} of {g.size} dwords differ") + ok &= good + return ok, lines + + +def test_ags_layout(a, env, work): + cxx = mingw_cxx() + if not cxx: + return "SKIP", "no MinGW-w64 C++ compiler (MINGW_CXX)" + dxc = shutil.which(os.environ.get("WG_DXC", "dxc")) + if not dxc: + return "SKIP", "no dxc (WG_DXC: the DXC release's Linux dxc)" + out = work / "ags-layout" + out.mkdir(parents=True, exist_ok=True) + for entry in ("main32", "main64"): + r = subprocess.run([dxc, "-T", "cs_6_6", "-E", entry, "-O3", "-HV", "2021", "-enable-16bit-types", + "-I", str(REPO / "clean/dx12/hlsl"), str(HERE / "ags_layout.hlsl"), + "-Fo", str(out / f"{entry}.dxil")], capture_output=True, text=True) + if r.returncode != 0: + return "FAIL", f"dxc {entry}: {r.stderr.strip()[-500:]}" + host = out / "ags_layout_host.exe" + build_exe(cxx, [str(HERE / "ags_layout_host.cpp")], host, libs=["-ld3d12"]) + inp = ags_inputs() + inp.astype("/files/lib*/ so that Proton's own layout changes +# (lib, lib64, lib/wine/...) do not need a code change +# Wine's builtin d3dcompiler_47 compiles through vkd3d-utils, which needs vkd3d and vkd3d-shader. +_PROTON_FILES = (("d3d12.dll", "vkd3d-proton"), ("d3d12core.dll", "vkd3d-proton"), ("dxgi.dll", "dxvk"), + ("libvkd3d-utils-1.dll", "vkd3d"), ("libvkd3d-1.dll", "vkd3d"), ("libvkd3d-shader-1.dll", "vkd3d")) +DLL_OVERRIDES = "d3d12,d3d12core,dxgi=n,b" + + +def _find(files_dir, name, folder): + for p in sorted(files_dir.glob(f"lib*/**/x86_64-windows/{name}")): + if folder in p.parts and not (folder == "vkd3d" and "vkd3d-proton" in p.parts): + return p + return None + + +def proton_dlls(proton_dir): + """{file name: path} of the DLLs a game prefix gets from this Proton install; raises if one is missing.""" + files_dir = Path(proton_dir) / "files" + found = {} + for name, folder in _PROTON_FILES: + p = _find(files_dir, name, folder) + if not p: + raise SystemExit(f"{proton_dir}: no {folder}/.../x86_64-windows/{name}; is this a Proton install?") + found[name] = p + return found + + +def prepare(proton_dir, prefix_dir, vkd3d_dir=None, log=print): + """Create (once) the prefix with Proton's wine, copy the DLLs into its system32 (every call, so a changed vkd3d_dir + takes effect) and return the environment: WINEPREFIX, WINEDLLOVERRIDES, WINEDEBUG, PATH with Proton's bin first, + and WG_WINE (Proton's wine executable).""" + proton_dir = Path(proton_dir).resolve() + prefix_dir = Path(prefix_dir).resolve() + wine = proton_dir / "files" / "bin" / "wine" + if not wine.is_file(): + raise SystemExit(f"{proton_dir}: no files/bin/wine; is this a Proton install?") + dlls = proton_dlls(proton_dir) + if vkd3d_dir: + for name in ("d3d12.dll", "d3d12core.dll"): + p = Path(vkd3d_dir) / name + if not p.is_file(): + raise SystemExit(f"--vkd3d {vkd3d_dir}: {name} missing") + dlls[name] = p + env = dict(os.environ) + env.update(WINEPREFIX=str(prefix_dir), WINEDLLOVERRIDES=DLL_OVERRIDES, WINEDEBUG="-all", + PATH=f"{wine.parent}{os.pathsep}{env.get('PATH', '')}", WG_WINE=str(wine)) + if not (prefix_dir / "system.reg").is_file(): + log(f"creating Wine prefix {prefix_dir} with {proton_dir.name}") + prefix_dir.mkdir(parents=True, exist_ok=True) + subprocess.run([str(wine), "wineboot", "-i"], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + check=True) + subprocess.run([str(wine.parent / "wineserver"), "-w"], env=env, check=True) + system32 = prefix_dir / "drive_c" / "windows" / "system32" + for name, src in dlls.items(): + shutil.copyfile(src, system32 / name) + log(f"prefix DLLs from {proton_dir.name}" + (f"; d3d12 / d3d12core from {vkd3d_dir}" if vkd3d_dir else "")) + return env + + +def windows_path(path): + """Wine's Z: path of a Linux path (Z: maps the Linux root).""" + return "Z:" + str(Path(path).resolve()).replace("/", "\\") diff --git a/clean/runtime/interop/tests/run-tests.sh b/clean/runtime/interop/tests/run-tests.sh index 1c87b0d1..8bac37b7 100755 --- a/clean/runtime/interop/tests/run-tests.sh +++ b/clean/runtime/interop/tests/run-tests.sh @@ -16,6 +16,8 @@ if ! command -v "$cxx" >/dev/null; then echo "SKIP: $cxx not installed"; exit 0; rt="$repo/clean/runtime" flags=(-std=c++17 -O2 -Wall -Wextra -static -static-libgcc -static-libstdc++ -D_CRT_SECURE_NO_WARNINGS) +# clang-based MinGW (llvm-mingw) accepts the SEH __try in interop/descriptor_publish.h only with MS extensions +if "$cxx" --version 2>/dev/null | grep -qi clang; then flags+=(-fms-extensions); fi echo "== MinGW build" "$cxx" "${flags[@]}" -shared -o "$work/wronggpu_runtime.dll" \ "$rt/device.cpp" "$rt/embedded.cpp" "$rt/model.cpp" "$rt/runtime.cpp" "$repo/clean/k/runtime/model_k.cpp" \ @@ -27,7 +29,7 @@ echo "== MinGW build" "$cxx" "${flags[@]}" -o "$work/test_interop_d3d12.exe" "$here/tests/test_interop_d3d12.cpp" || exit 1 x86_64-w64-mingw32-objdump -p "$work/wronggpu_runtime.dll" | grep -E "DLL Name|wgGetUpscalerBackend" | sed 's/^/ /' -wine=$(command -v wine64 || command -v wine || true) +wine=${WG_WINE:-$(command -v wine64 || command -v wine || true)} # WG_WINE: a Proton's wine (clean/linux/wine_env.py) if [ -z "$wine" ]; then echo "== Wine tests skipped (no Wine)"; exit 0; fi echo "== Wine tests" export WINEDEBUG=${WINEDEBUG:--all} WINEPREFIX=${WINEPREFIX:-$work/wineprefix} From b81f607894f9db87686e00d49449492b5d735531 Mon Sep 17 00:00:00 2001 From: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> Date: Fri, 13 Nov 2026 09:39:59 -0800 Subject: [PATCH 2/4] test: run the launcher's unit tests under Wine on Linux run_wine_tests.py gains a `launcher` test: a WRONGGPU_TESTING MinGW build of clean/installer with the installer suite's generated payload and test map, its four unit-test programs (wg-core-tests, launcher-core-tests, coexist-core-tests, wizard-policy-tests) run in the Proton prefix, the way Linux players run the launcher. Verified with llvm-mingw and GE-Proton 11-11 on main: PASS (73, 230, 186, 18 checks). With one wg-core check broken on purpose, the test reported FAIL (exit 1) naming that check; restored, PASS. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> --- clean/linux/README.md | 8 ++++-- clean/linux/run_wine_tests.py | 50 ++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/clean/linux/README.md b/clean/linux/README.md index 54fd9d10..58a8a3ff 100644 --- a/clean/linux/README.md +++ b/clean/linux/README.md @@ -17,6 +17,7 @@ The tests use WrongGPU's own synthetic data only: no model converted from a DLSS |---|---|---| | `interop` | `clean/runtime/interop/tests/run-tests.sh` (31 tests): MinGW build of the runtime with the `d3d12-test` executor | interop shaders that Wine's `d3dcompiler_47` rejects (`globallycoherent` in `PASS_SPIN` failed all 31), copy / convert / split regressions on vkd3d-proton | | `rr-leak` | the RR runtime test host's `tagloop` job against `--runtime`, with a synthetic RR model (`pack_model --synthetic 5100`) | RR input copies retained and released every frame with no RR instance piling up in video memory (+2,635 MiB in 200 frames before the fix in `release_transient_locked`, +37 MiB after) | +| `launcher` | the launcher's unit tests (`wg-core-tests`, `launcher-core-tests`, `coexist-core-tests`, `wizard-policy-tests`): a `WRONGGPU_TESTING` MinGW build of `clean/installer` with the installer suite's generated payload and test map | launcher code that breaks under Wine, the way Linux players run the launcher: the same unit tests as on Windows, run with Wine's DLLs and Proton's Direct3D 12 | | `ags-layout` | `ags_layout.hlsl`: `wg_ags_mma` (FP16, FP8), `wg_ags_convert` (F32 accumulator to F16 accumulator and FP8 B, FP8 B to F32 for all 256 codes), the F16 `FloatConversion` call, a wave64 conversion | a translation of the driver channel that does not keep the gfx12 register semantics the kernels rely on; checked against a CPU reference (multiplies within 1e-5, everything else bit-exact) | The `--runtime` DLL is the one to be released: the MSVC release build works as it is. `interop` builds its own @@ -32,6 +33,7 @@ programs only, never shipped (the release rule in `clean/fsr/build-mingw.sh`). on `PATH`. llvm-mingw works too. The tests add `-fms-extensions` for clang. - For `ags-layout`: the Linux `dxc` from the DXC release named in BUILDING.md, in `WG_DXC` or on `PATH`. - Python 3 with NumPy. +- For `launcher`: CMake, Ninja, and the MinGW-w64 `windres` in the same folder as `MINGW_CXX`. ## vkd3d-proton @@ -50,9 +52,11 @@ test failed. Everything a test writes goes to `--work`, by default `build/linux- - `interop/result.txt`: the 31 tests' output; - `rr-leak/host.log`, and `rr-leak/stage/wronggpu-rr.log` for the runtime's own log; -- `ags-layout/host.log`, `inputs.bin` and `outputs.bin`. +- `ags-layout/host.log`, `inputs.bin` and `outputs.bin`; +- `launcher-build/`: the launcher's test build (each test's output is in the run's own output). Each failure was checked to show up in this suite. Run on the unfixed `convert.cpp`, `interop` fails 29 of 31 with `Unknown modifier "globallycoherent"`. With the 0.6.0 RR runtime, `rr-leak` reports +2,635 MiB. On stock vkd3d-proton, `ags-layout` stops at `CreateComputePipelineState`. Fed results with lanes in the wrong order or F16 -halves swapped, its comparison fails. +halves swapped, its comparison fails. With the vkd3d-proton rule of `coexist.cpp` taken back to the Windows refusal, +`launcher` fails in `coexist-core-tests`. diff --git a/clean/linux/run_wine_tests.py b/clean/linux/run_wine_tests.py index 6cd67272..9970118f 100644 --- a/clean/linux/run_wine_tests.py +++ b/clean/linux/run_wine_tests.py @@ -3,7 +3,7 @@ vkd3d-shader), the stack a game runs on in Steam. python3 clean/linux/run_wine_tests.py --proton [--vkd3d ] [--runtime ] - [--tests interop,rr-leak,ags-layout] [--work ] + [--tests interop,rr-leak,ags-layout,launcher] [--work ] Tests (all run by default; each prints PASS, FAIL or SKIP with the reason; the exit status is 1 when one fails): interop clean/runtime/interop/tests/run-tests.sh: MinGW build of the runtime with the d3d12-test executor, run @@ -15,11 +15,15 @@ ags-layout WrongGPU's driver-channel helpers (wg_ags.hlsli: FP16 and FP8 WMMA, matrix conversions, the F16 conversion, a wave64 conversion) on fixed register values, against a CPU reference of the gfx12 register semantics. Under Proton the channel is translated by vkd3d-proton's dxil-spirv. + launcher the launcher's unit tests (clean/installer: wg-core-tests, launcher-core-tests, coexist-core-tests, + wizard-policy-tests), a WRONGGPU_TESTING MinGW build with the installer suite's generated payload, run in + the prefix: the launcher as Linux players run it, under Wine. rr-leak and ags-layout need the WMMA channel, i.e. a vkd3d-proton with dxil-spirv's shader-packed fragment support (https://github.com/HansKristian-Work/dxil-spirv/pull/362): pass a self-built one with --vkd3d until Proton ships it. Tools (environment): MINGW_CXX (default x86_64-w64-mingw32-g++-posix, then x86_64-w64-mingw32-g++), WG_DXC (a Linux -dxc binary of the DXC release, default `dxc` on PATH). Python with NumPy. Needs an AMD RDNA 4 GPU with RADV. +dxc binary of the DXC release, default `dxc` on PATH). Python with NumPy. Needs an AMD RDNA 4 GPU with RADV. The +launcher test also needs CMake, Ninja and the MinGW-w64 windres beside MINGW_CXX. """ import argparse import os @@ -255,7 +259,47 @@ def test_ags_layout(a, env, work): "results differ from the gfx12 register semantics (see above)") -TESTS = {"interop": test_interop, "rr-leak": test_rr_leak, "ags-layout": test_ags_layout} +# ---- launcher ------------------------------------------------------------------------------------------------------- +LAUNCHER_TESTS = ("wg-core-tests", "launcher-core-tests", "coexist-core-tests", "wizard-policy-tests") + + +def test_launcher(a, env, work): + cxx = mingw_cxx() + if not cxx: + return "SKIP", "no MinGW-w64 C++ compiler (MINGW_CXX)" + windres = Path(cxx).with_name(Path(cxx).name.split("-g++")[0].split("-clang++")[0] + "-windres") + missing = [t for t in ("cmake", "ninja") if not shutil.which(t)] + ([] if windres.is_file() else [str(windres)]) + if missing: + return "SKIP", "missing " + ", ".join(missing) + installer = REPO / "clean" / "installer" + prep, build = work / "launcher-prep", work / "launcher-build" + # the installer suite's payload and test map (generated: names and synthetic bytes only) + r = subprocess.run([sys.executable, str(installer / "tests" / "run_installer_tests.py"), "--work", str(prep), "--prepare-only"], + capture_output=True, text=True) + if r.returncode != 0: + raise RuntimeError("run_installer_tests.py --prepare-only failed:\n" + (r.stdout + r.stderr)[-3000:]) + r = subprocess.run(["cmake", "-S", str(installer), "-B", str(build), "-G", "Ninja", "-DCMAKE_SYSTEM_NAME=Windows", + f"-DCMAKE_CXX_COMPILER={cxx}", f"-DCMAKE_RC_COMPILER={windres}", "-DCMAKE_EXE_LINKER_FLAGS=-static", + "-DWRONGGPU_TESTING=ON", f"-DWRONGGPU_PAYLOAD_DIR={prep / 'prepared' / 'payload'}", + f"-DWRONGGPU_MAP={prep / 'prepared' / 'test-map.json'}"], capture_output=True, text=True) + if r.returncode != 0: + raise RuntimeError("configuring clean/installer failed:\n" + (r.stdout + r.stderr)[-3000:]) + r = subprocess.run(["cmake", "--build", str(build), "--target", *LAUNCHER_TESTS], capture_output=True, text=True) + if r.returncode != 0: + raise RuntimeError("building the launcher's unit tests failed:\n" + (r.stdout + r.stderr)[-3000:]) + passed, failed = [], [] + for t in LAUNCHER_TESTS: + rc, text = run_wine(env, [str(build / (t + ".exe"))], build, 600) + # the test's own summary line (Wine's messages are mixed into the output) + last = [line.strip() for line in text.splitlines() if "checks passed" in line or "FAILED" in line][-1:] or ["(no summary line)"] + log(f" {t}: exit {rc}, {last[0]}") + (passed if rc == 0 and "checks passed" in last[0] else failed).append(f"{t} ({last[0]})") + if failed: + return "FAIL", "; ".join(failed) + return "PASS", "; ".join(passed) + + +TESTS = {"interop": test_interop, "rr-leak": test_rr_leak, "ags-layout": test_ags_layout, "launcher": test_launcher} def main(argv=None): From 1ac667219dbddb88b1336fecaf0c2182c41e014f Mon Sep 17 00:00:00 2001 From: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> Date: Fri, 13 Nov 2026 16:09:38 -0800 Subject: [PATCH 3/4] test: Linux runner README and checks from review From the review of #52: - README: the globallycoherent count now agrees (29 of 31, before #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 #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 Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> --- clean/linux/README.md | 36 +++++++++++++++++++---------------- clean/linux/ags_layout.hlsl | 3 ++- clean/linux/run_wine_tests.py | 6 ++++++ clean/linux/wine_env.py | 4 +++- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/clean/linux/README.md b/clean/linux/README.md index 58a8a3ff..2c2b0b31 100644 --- a/clean/linux/README.md +++ b/clean/linux/README.md @@ -1,9 +1,9 @@ # WrongGPU on Linux: D3D12 tests under Proton -Players on Linux run WrongGPU's Windows DLLs inside Proton. There, Direct3D 12 is vkd3d-proton on top of RADV, -`d3dcompiler_47.dll` is Wine's own (vkd3d-shader), and the driver channel that the D3D12 kernels use for WMMA -(`clean/dx12/hlsl/wg_ags.hlsli`) is translated by vkd3d-proton's dxil-spirv instead of AMD's driver. These tests run -WrongGPU's D3D12 code on that stack, so a release can be checked for Linux players before it ships. +Under Proton, WrongGPU's Windows DLLs meet a different Direct3D 12 stack: Direct3D 12 is vkd3d-proton on top of +RADV, `d3dcompiler_47.dll` is Wine's own (vkd3d-shader), and the driver channel that the D3D12 kernels use for WMMA +(`clean/dx12/hlsl/wg_ags.hlsli`) is translated by vkd3d-proton's dxil-spirv instead of AMD's driver. These tests check +WrongGPU's D3D12 code on that stack. They don't make Linux a supported platform. ```sh python3 clean/linux/run_wine_tests.py --proton [--vkd3d ] [--runtime ] @@ -15,8 +15,8 @@ The tests use WrongGPU's own synthetic data only: no model converted from a DLSS | Test | What runs | What it would catch | |---|---|---| -| `interop` | `clean/runtime/interop/tests/run-tests.sh` (31 tests): MinGW build of the runtime with the `d3d12-test` executor | interop shaders that Wine's `d3dcompiler_47` rejects (`globallycoherent` in `PASS_SPIN` failed all 31), copy / convert / split regressions on vkd3d-proton | -| `rr-leak` | the RR runtime test host's `tagloop` job against `--runtime`, with a synthetic RR model (`pack_model --synthetic 5100`) | RR input copies retained and released every frame with no RR instance piling up in video memory (+2,635 MiB in 200 frames before the fix in `release_transient_locked`, +37 MiB after) | +| `interop` | `clean/runtime/interop/tests/run-tests.sh` (31 tests): MinGW build of the runtime with the `d3d12-test` executor | interop shaders that Wine's `d3dcompiler_47` rejects (before #12, `globallycoherent` in `PASS_SPIN` made 29 of the 31 fail), copy / convert / split regressions on vkd3d-proton | +| `rr-leak` | the RR runtime test host's `tagloop` job against `--runtime`, with a synthetic RR model (`pack_model --synthetic 5100`) | RR input copies retained and released every frame with no RR instance piling up in video memory (the fix is #11; see "Reading the result") | | `launcher` | the launcher's unit tests (`wg-core-tests`, `launcher-core-tests`, `coexist-core-tests`, `wizard-policy-tests`): a `WRONGGPU_TESTING` MinGW build of `clean/installer` with the installer suite's generated payload and test map | launcher code that breaks under Wine, the way Linux players run the launcher: the same unit tests as on Windows, run with Wine's DLLs and Proton's Direct3D 12 | | `ags-layout` | `ags_layout.hlsl`: `wg_ags_mma` (FP16, FP8), `wg_ags_convert` (F32 accumulator to F16 accumulator and FP8 B, FP8 B to F32 for all 256 codes), the F16 `FloatConversion` call, a wave64 conversion | a translation of the driver channel that does not keep the gfx12 register semantics the kernels rely on; checked against a CPU reference (multiplies within 1e-5, everything else bit-exact) | @@ -40,23 +40,27 @@ programs only, never shipped (the release rule in `clean/fsr/build-mingw.sh`). `rr-leak` and `ags-layout` need the WMMA channel. Released vkd3d-proton cannot translate it yet: dxil-spirv accepts only WMMA operands that come from AGS matrix loads, and WrongGPU's kernels pack their fragments themselves. The support is in https://github.com/HansKristian-Work/dxil-spirv/pull/362. Until a Proton release ships it, build vkd3d-proton with -that change. Use the vkd3d-proton commit your Proton ships, for example `0bb64c5` in GE-Proton 11-11. Then pass the -folder that holds the resulting `d3d12.dll` and `d3d12core.dll` with `--vkd3d`. Without it these two tests fail at -`CreateComputePipelineState` (`0x80070057`). On the player's side, the same patched DLLs next to the game exe make -Model M and Ray Reconstruction run. +that change; the tests were run with vkd3d-proton `5b1089c8` plus that pull request's three code commits. Then pass +the folder that holds the resulting `d3d12.dll` and `d3d12core.dll` with `--vkd3d`. Without it these two tests fail +at `CreateComputePipelineState` (`0x80070057`). ## Reading the result Each test prints `PASS`, `FAIL` or `SKIP` with a reason, and a summary follows at the end. The exit status is 1 when a -test failed. Everything a test writes goes to `--work`, by default `build/linux-tests/`: +test failed. Everything a test writes goes to `--work`, by default `build/linux-tests/` (the path must not contain +spaces). Its Wine prefix is `--work/prefix`: if that already is a Wine prefix, it is reused and its `d3d12`, `d3d12core` +and `dxgi` DLLs are overwritten, so point `--work` at a folder of its own: - `interop/result.txt`: the 31 tests' output; - `rr-leak/host.log`, and `rr-leak/stage/wronggpu-rr.log` for the runtime's own log; - `ags-layout/host.log`, `inputs.bin` and `outputs.bin`; - `launcher-build/`: the launcher's test build (each test's output is in the run's own output). -Each failure was checked to show up in this suite. Run on the unfixed `convert.cpp`, `interop` fails 29 of 31 with -`Unknown modifier "globallycoherent"`. With the 0.6.0 RR runtime, `rr-leak` reports +2,635 MiB. On stock -vkd3d-proton, `ags-layout` stops at `CreateComputePipelineState`. Fed results with lanes in the wrong order or F16 -halves swapped, its comparison fails. With the vkd3d-proton rule of `coexist.cpp` taken back to the Windows refusal, -`launcher` fails in `coexist-core-tests`. +Each failure was checked to show up in this suite, in one run each on an RX 9070 XT with RADV, GE-Proton 11-11 and +vkd3d-proton `5b1089c8` plus dxil-spirv #362: + +- on `convert.cpp` from before #12, `interop` fails 29 of 31 with `Unknown modifier "globallycoherent"`; +- with a runtime built from source before #11, `rr-leak` reports +2636 MiB over 200 frames (+37.2 MiB with the fix); +- on stock vkd3d-proton, `ags-layout` stops at `CreateComputePipelineState`; fed results with lanes in the wrong order + or F16 halves swapped, its comparison fails; +- with one `wg-core-tests` check broken on purpose, `launcher` reports FAIL naming that check. diff --git a/clean/linux/ags_layout.hlsl b/clean/linux/ags_layout.hlsl index 0a72d514..0a22e7c0 100644 --- a/clean/linux/ags_layout.hlsl +++ b/clean/linux/ags_layout.hlsl @@ -30,7 +30,8 @@ void main32(uint lane : SV_GroupThreadID) store_frag(2, lane, wg_ags_convert(c, WG_AGS_T_F32_ACC, WG_AGS_T_F16_ACC)); store_frag(3, lane, wg_ags_convert(c, WG_AGS_T_F32_ACC, WG_AGS_T_FP8_B)); wg_frag h; - [unroll] for (uint i = 0; i < 8; ++i) h.v[i] = wg_ags_call(0x1cu, 0u, 1u, c.v[i], 0u); // FloatConversion, F16 near + // FloatConversion, F16 near: opcode 0x1c with the arguments of f2h_hw in clean/rr_f/kernels/rr_fast.hlsli + [unroll] for (uint i = 0; i < 8; ++i) h.v[i] = wg_ags_call(0x1cu, 0u, 1u, c.v[i], 0u); store_frag(4, lane, h); store_frag(5, lane, wg_ags_convert(load_frag(5 * 1024, lane, 2), WG_AGS_T_FP8_B, WG_AGS_T_F32_ACC)); } diff --git a/clean/linux/run_wine_tests.py b/clean/linux/run_wine_tests.py index 9970118f..7aad4d58 100644 --- a/clean/linux/run_wine_tests.py +++ b/clean/linux/run_wine_tests.py @@ -120,6 +120,10 @@ def test_rr_leak(a, env, work): why = f"runtime set_device returned {sd.group(1)}" if sd and sd.group(1) != "0" else "no tagloop line" return "FAIL", (f"{why}; RR could not start (stock vkd3d-proton without dxil-spirv #362? use --vkd3d); " f"see {out / 'host.log'} and {stage / 'wronggpu-rr.log'}") + # a stack that reports a constant CurrentUsage would let any leak pass: no change at all counts as a failure + vm = re.search(r"video memory (\d+) -> (\d+) bytes \([^,]*, peak ([+-][0-9.]+) MiB", m.group(0)) + if vm and vm.group(1) == vm.group(2) and float(vm.group(3)) == 0.0: + return "FAIL", m.group(0) + " (video memory did not change at all: usage may not be reported)" return ("PASS" if rc == 0 and m.group(0).endswith(": ok") else "FAIL"), m.group(0) @@ -317,6 +321,8 @@ def main(argv=None): if unknown: ap.error(f"unknown test(s): {', '.join(unknown)}") work = Path(a.work).resolve() + if " " in str(work): + ap.error("--work must not contain spaces (the RR test host's job file is split on spaces)") work.mkdir(parents=True, exist_ok=True) env = wine_env.prepare(a.proton, work / "prefix", a.vkd3d, log=log) results = {} diff --git a/clean/linux/wine_env.py b/clean/linux/wine_env.py index 71a2247f..9869f695 100644 --- a/clean/linux/wine_env.py +++ b/clean/linux/wine_env.py @@ -24,7 +24,9 @@ # Wine's builtin d3dcompiler_47 compiles through vkd3d-utils, which needs vkd3d and vkd3d-shader. _PROTON_FILES = (("d3d12.dll", "vkd3d-proton"), ("d3d12core.dll", "vkd3d-proton"), ("dxgi.dll", "dxvk"), ("libvkd3d-utils-1.dll", "vkd3d"), ("libvkd3d-1.dll", "vkd3d"), ("libvkd3d-shader-1.dll", "vkd3d")) -DLL_OVERRIDES = "d3d12,d3d12core,dxgi=n,b" +# mscoree / mshtml off and winemenubuilder disabled: a new prefix's wineboot shows no Mono / Gecko dialog and +# writes no menu entries under ~/.local/share +DLL_OVERRIDES = "d3d12,d3d12core,dxgi=n,b;mscoree,mshtml=;winemenubuilder.exe=d" def _find(files_dir, name, folder): From 16c1d172ee8ea31a0d4de3cd6513d9fd6696011d Mon Sep 17 00:00:00 2001 From: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:39:51 -0800 Subject: [PATCH 4/4] REUSE: add the runner author's copyright line on clean/linux The maintainer offered it in the review of #52. Files under clean/linux now carry both "2026 phantoslayer21" and "2026 j0nsh1n"; every other file is unchanged. Verified with reuse 5.0.2 (the CI's version): reuse lint compliant, and reuse spdx shows both lines on clean/linux files and only the project's line elsewhere. tools/ci/check_line_endings.py: 0 problems. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com> --- REUSE.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/REUSE.toml b/REUSE.toml index df2040c3..536697a8 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -68,3 +68,10 @@ path = ["clean/third_party/fidelityfx-sdk-1.1.4/README.md", "clean/third_party/f precedence = "override" SPDX-FileCopyrightText = "2026 phantoslayer21" SPDX-License-Identifier = "MIT" + +# The Linux test runner (clean/linux): its author's copyright line as well as the project's +[[annotations]] +path = "clean/linux/**" +precedence = "aggregate" +SPDX-FileCopyrightText = ["2026 phantoslayer21", "2026 j0nsh1n"] +SPDX-License-Identifier = "MIT"