Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
66 changes: 66 additions & 0 deletions clean/linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# WrongGPU on Linux: D3D12 tests under Proton

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 <Proton install> [--vkd3d <dir>] [--runtime <wronggpu_runtime.dll>]
```

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 (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) |

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.
- For `launcher`: CMake, Ninja, and the MinGW-w64 `windres` in the same folder as `MINGW_CXX`.

## 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; 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/` (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, 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.
50 changes: 50 additions & 0 deletions clean/linux/ags_layout.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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;
// 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));
}

// 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);
}
158 changes: 158 additions & 0 deletions clean/linux/ags_layout_host.cpp
Original file line number Diff line number Diff line change
@@ -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 <main32.dxil> <main64.dxil> <inputs.bin> <outputs.bin>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d12.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>

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<char> read_file(const char* path) {
std::vector<char> 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 <main32.dxil> <main64.dxil> <inputs.bin> <outputs.bin>");
return 2;
}
const std::vector<char> 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<char*>(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;
}
Loading
Loading