From 86cd0320438613b207f7e16c6db34a427b940797 Mon Sep 17 00:00:00 2001 From: Valdi320 <61891540+Valdi320@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:53:56 +0100 Subject: [PATCH 1/5] verify: render translated NGG shared-count mesh shaders --- tests/test_translated_mesh_gpu.py | 20 +++ tools/check_translated_mesh_gpu.py | 134 +++++++++++++++ tools/check_translator_gpu.py | 1 + tools/reference/mesh/README.md | 5 + tools/reference/mesh/translated_guest.cpp | 160 ++++++++++++++++++ .../reference/mesh/translated_shared_count.s | 73 ++++++++ 6 files changed, 393 insertions(+) create mode 100644 tests/test_translated_mesh_gpu.py create mode 100644 tools/check_translated_mesh_gpu.py create mode 100644 tools/reference/mesh/README.md create mode 100644 tools/reference/mesh/translated_guest.cpp create mode 100644 tools/reference/mesh/translated_shared_count.s diff --git a/tests/test_translated_mesh_gpu.py b/tests/test_translated_mesh_gpu.py new file mode 100644 index 00000000..68629130 --- /dev/null +++ b/tests/test_translated_mesh_gpu.py @@ -0,0 +1,20 @@ +import unittest +from tools.check_translated_mesh_gpu import CASES, program, validate + +class TranslatedMeshControlTests(unittest.TestCase): + def test_cross_wave_triangle_and_invalid_index(self): + self.assertIn("v_mov_b32 v27, 0x4210440", program(67)) + self.assertIn("v_cmp_eq_u32 vcc, 127, v26", program(128, True)) + self.assertIn("ds_swizzle_b32 v26, v25 offset:0x41f", program(128, True)) + self.assertIn("v_mov_b32 v27, 0x300400", program(3, bad_index=True)) + + def test_every_case_and_adapter_required(self): + fields = {f"{case}_{clip}{suffix}": "10de:2704" if suffix else "64" + for case in CASES for clip in ("full", "clipped") for suffix in ("", "_adapter")} + self.assertTrue(validate(0, fields, "10de:2704")) + self.assertFalse(validate(1, fields, "10de:2704")) + fields["swizzle-67_full"] = "63" + self.assertFalse(validate(0, fields, "10de:2704")) + fields["swizzle-67_full"] = "64" + fields.pop("plain-3_full_adapter") + self.assertFalse(validate(0, fields, "10de:2704")) diff --git a/tools/check_translated_mesh_gpu.py b/tools/check_translated_mesh_gpu.py new file mode 100644 index 00000000..76b46ca7 --- /dev/null +++ b/tools/check_translated_mesh_gpu.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +"""GPU readback of synthetic console NGG mesh programs on desktop D3D12. + +Checks translator output, not the Xbox command-list or root replacement ABI. +The independently written pixel stage writes a constant to covered pixels. +""" +import argparse +import hashlib +import json +from pathlib import Path +import re +import struct +import subprocess +import sys +from tempfile import TemporaryDirectory + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT)) +from examples.lanes.raster_fixture import container, image, signature, pack +from tools.frosty_gpu_guest import run_gpu_guest + +SRC = ROOT / "tools/reference/mesh" +COUNTS = (3, 67, 128, 0, 129) +CASES = tuple(f"{name}-{count}" for count in COUNTS for name in ("plain", "swizzle")) + ("bad-index",) + + +def program(count, swizzle=False, bad_index=False): + first = {67: 64, 128: 125}.get(count, 0) + src = (SRC / "translated_shared_count.s").read_text() + src = "\n".join(line for line in src.splitlines() if not line.startswith("//")) + third = first + (3 if bad_index else 2) + packed = first | ((first + 1) << 10) | (third << 20) + src = src.replace("s_mov_b32 s20, 3", f"s_mov_b32 s20, {count}") + src = src.replace("v_mov_b32 v27, 0x00200400", f"v_mov_b32 v27, {packed:#x}") + src = src.replace("v_cmp_eq_u32 vcc, 2, v1", f"v_cmp_eq_u32 vcc, {first + 2}, v1") + src = src.replace("v_cmp_eq_u32 vcc, 1, v1", f"v_cmp_eq_u32 vcc, {first + 1}, v1") + if swizzle: + # XOR1 before XOR1 exchange restores the group index. An identity + # exchange instead makes the first triangle degenerate. + src = src.replace(f"v_cmp_eq_u32 vcc, {first + 2}, v1", + "v_xor_b32 v25, 1, v1\nds_swizzle_b32 v26, v25 offset:0x41f\n" + f"s_waitcnt lgkmcnt(0)\nv_cmp_eq_u32 vcc, {first + 2}, v26") + src = src.replace(f"v_cmp_eq_u32 vcc, {first + 1}, v1", + f"v_cmp_eq_u32 vcc, {first + 1}, v26") + return src + "\n" + + +def assemble(llvm, src): + run = subprocess.run([llvm, "-triple=amdgcn-amd-amdhsa", "-mcpu=gfx1030", + "-mattr=+wavefrontsize64,-wavefrontsize32", "-show-encoding"], + input=src, text=True, capture_output=True, check=True, timeout=30) + raw = bytes(int(x, 16) for row in re.findall(r"encoding: \[([^\]]+)\]", run.stdout) + for x in row.split(",")) + words = list(struct.unpack("<" + "I" * (len(raw) // 4), raw)) + # LLVM encodes the unused third VOP3 compare operand as inline zero; + # the console recognizer's admitted form uses s0. It is not read. + compares = [i for i, word in enumerate(words) if word in (0xd4c30000, 0xd4c30002)] + if len(compares) != 2: + raise ValueError("unexpected compare encoding") + for i in compares: + words[i + 1] &= ~(0x1ff << 18) + return words + + +def shader(words): + info = bytearray(48) + info[24], info[27] = 13, 2 + struct.pack_into(" +#include +#include +using frame_abi::check; +using frame_abi::ComPtr; + +using Stream = frame_abi::MeshPipelineStream; + +static ComPtr buffer(ID3D12Device* d, D3D12_HEAP_TYPE type) { + D3D12_HEAP_PROPERTIES heap{}; + heap.Type = type; + heap.CreationNodeMask = heap.VisibleNodeMask = 1; + D3D12_RESOURCE_DESC desc{}; + desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; + desc.Width = 8 * 8 * 4; + desc.Height = desc.DepthOrArraySize = desc.MipLevels = desc.SampleDesc.Count = 1; + desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; + if (type == D3D12_HEAP_TYPE_DEFAULT) + desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + ComPtr result; + check(d->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, + type == D3D12_HEAP_TYPE_UPLOAD ? D3D12_RESOURCE_STATE_GENERIC_READ + : D3D12_RESOURCE_STATE_COPY_DEST, + nullptr, IID_PPV_ARGS(&result)), + "create buffer"); + return result; +} + +static std::vector load(const char* path) { + std::ifstream stream(path, std::ios::binary | std::ios::ate); + const auto size = stream.tellg(); + if (size <= 0 || size > 16 * 1024 * 1024) + throw std::runtime_error("invalid shader file"); + std::vector data(static_cast(size)); + stream.seekg(0); + if (!stream.read(data.data(), size)) + throw std::runtime_error("shader read"); + return data; +} + +static void run(const char* name, bool draw, bool clipped, FILE* file) { + const auto mesh = load((std::string(name) + ".cso").c_str()); + const auto pixel = load("pixel.cso"); + ComPtr provider; + check(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&provider)), "desktop device"); + D3D12_ROOT_PARAMETER parameter{}; + parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV; + D3D12_ROOT_SIGNATURE_DESC desc{1, ¶meter, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE}; + ComPtr blob; + check(D3D12SerializeRootSignature(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr), "serialize root"); + ComPtr root; + check(provider->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&root)), + "create root"); + ComPtr owner; + check(root->GetDevice(IID_PPV_ARGS(&owner)), "get owning device"); + ComPtr factory; + ComPtr adapter; + DXGI_ADAPTER_DESC1 gpu{}; + check(CreateDXGIFactory1(IID_PPV_ARGS(&factory)), "DXGI factory"); + check(factory->EnumAdapterByLuid(owner->GetAdapterLuid(), IID_PPV_ARGS(&adapter)), "DXGI adapter"); + check(adapter->GetDesc1(&gpu), "GPU description"); + std::fprintf(file, "%s_%s_adapter=%04x:%04x\n", name, clipped ? "clipped" : "full", gpu.VendorId, gpu.DeviceId); + Stream stream; + stream.root.payload = root.Get(); + stream.ms.payload = {mesh.data(), mesh.size()}; + stream.ps.payload = {pixel.data(), pixel.size()}; + stream.raster.payload.FillMode = D3D12_FILL_MODE_SOLID; + stream.raster.payload.CullMode = D3D12_CULL_MODE_NONE; + stream.raster.payload.DepthClipEnable = TRUE; + stream.ms.tag = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS; + stream.as.tag = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS; + D3D12_PIPELINE_STATE_STREAM_DESC pipelineDesc{offsetof(Stream, extension), &stream}; + ComPtr pso; + check(owner->CreatePipelineState(&pipelineDesc, IID_PPV_ARGS(&pso)), "desktop mesh pipeline"); + ComPtr queue; + ComPtr allocator; + ComPtr list; + D3D12_COMMAND_QUEUE_DESC q{}; + check(owner->CreateCommandQueue(&q, IID_PPV_ARGS(&queue)), "queue"); + check(owner->CreateCommandAllocator(q.Type, IID_PPV_ARGS(&allocator)), "allocator"); + check(owner->CreateCommandList(0, q.Type, allocator.Get(), pso.Get(), IID_PPV_ARGS(&list)), "list6"); + auto output = buffer(owner.Get(), D3D12_HEAP_TYPE_DEFAULT); + auto readback = buffer(owner.Get(), D3D12_HEAP_TYPE_READBACK); + auto upload = buffer(owner.Get(), D3D12_HEAP_TYPE_UPLOAD); + constexpr UINT seed = 0x13572468; + void* mapped{}; + D3D12_RANGE none{}; + check(upload->Map(0, &none, &mapped), "map seed"); + for (UINT i = 0; i < 64; ++i) static_cast(mapped)[i] = seed; + upload->Unmap(0, nullptr); + list->CopyResource(output.Get(), upload.Get()); + D3D12_RESOURCE_BARRIER before{}; + before.Transition = {output.Get(), 0, D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS}; + list->ResourceBarrier(1, &before); + list->SetGraphicsRootSignature(root.Get()); + list->SetGraphicsRootUnorderedAccessView(0, output->GetGPUVirtualAddress()); + D3D12_VIEWPORT viewport{0, 0, 8, 8, 0, 1}; + D3D12_RECT scissor = clipped ? D3D12_RECT{2, 1, 6, 5} : D3D12_RECT{0, 0, 8, 8}; + list->RSSetViewports(1, &viewport); + list->RSSetScissorRects(1, &scissor); + list->DispatchMesh(1, 1, 1); + D3D12_RESOURCE_BARRIER barrier{}; + barrier.Transition = {output.Get(), 0, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, + D3D12_RESOURCE_STATE_COPY_SOURCE}; + list->ResourceBarrier(1, &barrier); + list->CopyResource(readback.Get(), output.Get()); + check(list->Close(), "close"); + ID3D12CommandList* lists[] = {list.Get()}; + queue->ExecuteCommandLists(1, lists); + ComPtr fence; + check(owner->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), "fence"); + check(queue->Signal(fence.Get(), 1), "signal"); + HANDLE event = CreateEventW(nullptr, FALSE, FALSE, nullptr); + if (!event) + throw std::runtime_error("event"); + HRESULT hr = fence->SetEventOnCompletion(1, event); + DWORD wait = SUCCEEDED(hr) ? WaitForSingleObject(event, 15000) : WAIT_FAILED; + CloseHandle(event); + check(hr, "signal event"); + if (wait != WAIT_OBJECT_0 || fence->GetCompletedValue() != 1) + throw std::runtime_error("GPU fence"); + void* data{}; + D3D12_RANGE range{0, 256}; + check(readback->Map(0, &range, &data), "readback"); + UINT matched = 0; + for (UINT i = 0; i < 64; ++i) { + const UINT x = i % 8, y = i / 8; + const bool covered = draw && (!clipped || (x >= 2 && x < 6 && y >= 1 && y < 5)); + const UINT expected = covered ? 0x2468ace0 : seed; + matched += static_cast(data)[i] == expected; + } + readback->Unmap(0, &none); + std::fprintf(file, "%s_%s=%u\n", name, clipped ? "clipped" : "full", matched); + std::fflush(file); + if (matched != 64) + throw std::runtime_error("mesh/pixel readback mismatch"); +} + +int main() { + FILE* file{}; + if (fopen_s(&file, "result.txt", "wb")) return 2; + int exit = 0; + try { + for (const char* name : {"plain-3", "swizzle-3", "plain-67", "swizzle-67", + "plain-128", "swizzle-128", "plain-0", "swizzle-0", + "plain-129", "swizzle-129", "bad-index"}) { + const std::string id(name); + const bool draw = id != "bad-index" && id.find("-0") == std::string::npos + && id.find("-129") == std::string::npos; + run(name, draw, false, file); + run(name, draw, true, file); + } + } catch (const std::exception& e) { + std::fprintf(file, "error=%s\n", e.what()); + exit = 1; + } + return fclose(file) ? 2 : exit; +} diff --git a/tools/reference/mesh/translated_shared_count.s b/tools/reference/mesh/translated_shared_count.s new file mode 100644 index 00000000..0435d29d --- /dev/null +++ b/tools/reference/mesh/translated_shared_count.s @@ -0,0 +1,73 @@ +// Synthetic gfx1030 NGG allocation with shared output count. +// Branch immediates are in dwords; only lane 0 emits a live triangle. +v_mbcnt_lo_u32_b32 v0, -1, 0 +v_readfirstlane_b32 s0, v5 +s_bfe_u32 s1, s3, 0x00040018 +v_mbcnt_hi_u32_b32 v0, -1, v0 +s_lshr_b32 s10, s0, 7 +v_lshl_add_u32 v1, s1, 6, v0 +s_mov_b32 s20, 3 +v_mov_b32 v20, 0x80000000 +v_mov_b32 v27, 0x00200400 +v_cmp_eq_u32 vcc, 0, v1 +v_cndmask_b32 v20, v20, v27, vcc +v_cmp_eq_u32 vcc, 2, v1 +v_cndmask_b32 v21, -1.0, 3.0, vcc +v_cmp_eq_u32 vcc, 1, v1 +v_cndmask_b32 v22, -1.0, 3.0, vcc +v_mov_b32 v23, 0.5 +v_mov_b32 v24, 1.0 +s_cmp_eq_u32 s20, 0 +s_cselect_b64 s[0:1], exec, 0 +s_cmpk_gt_u32 s20, 128 +s_cselect_b64 s[2:3], exec, 0 +s_or_b64 s[0:1], s[0:1], s[0:1] +s_or_b64 s[2:3], s[2:3], s[2:3] +s_or_b64 s[0:1], s[2:3], s[0:1] +v_cndmask_b32_e64 v10, 0, 1, s[0:1] +v_readfirstlane_b32 s0, v10 +s_and_b32 s0, 1, s0 +s_cmp_eq_u32 s0, 1 +s_mov_b64 s[0:1], exec +s_cselect_b64 s[2:3], exec, 0 +v_cndmask_b32_e64 v11, s20, 1, s[2:3] +s_xor_b64 s[4:5], s[2:3], -1 +v_readfirstlane_b32 s6, v11 +v_cmpx_eq_u32 0, v1 +s_cbranch_execz 13 +s_lshl_b32 s7, s6, 12 +s_andn2_b64 vcc, exec, s[2:3] +s_or_b32 s6, s7, s6 +s_mov_b32 m0, s6 +s_sendmsg sendmsg(MSG_GS_ALLOC_REQ) +s_waitcnt 0 +s_cbranch_vccnz 6 +s_barrier +v_bfrev_b32 v10, 1 +exp pos0 off, off, off, off done +exp prim v10, off, off, off done +s_waitcnt 0xff0f +s_mov_b64 exec, s[0:1] +s_barrier +v_cmp_gt_u32 vcc, s20, v1 +s_and_b64 s[0:1], vcc, s[4:5] +s_and_saveexec_b64 s[6:7], s[0:1] +s_cbranch_execz 18 +v_bfe_u32 v12, v20, 10, 10 +v_bfe_u32 v13, v20, 20, 10 +v_and_b32 v14, 0x3ff, v20 +v_cmp_le_u32 vcc, s20, v12 +v_cmp_le_u32_e64 s[2:3], s20, v13 +v_cmp_le_u32_e64 s[0:1], s20, v14 +s_or_b64 s[2:3], vcc, s[2:3] +s_or_b64 s[0:1], s[0:1], s[2:3] +v_cndmask_b32_e64 v15, v20, 0x80000000, s[0:1] +exp prim v15, off, off, off done +s_waitcnt 0xff0f +s_mov_b64 exec, s[6:7] +v_cmp_gt_u32 vcc, s20, v1 +s_and_b64 s[0:1], vcc, s[4:5] +s_and_saveexec_b64 s[0:1], s[0:1] +s_cbranch_execz 2 +exp pos0 v21,v22,v23,v24 done +s_endpgm From f07e19500f5fa39a16c2b145ef1562423e653769 Mon Sep 17 00:00:00 2001 From: Valdi320 <61891540+Valdi320@users.noreply.github.com> Date: Thu, 26 Nov 2026 22:33:05 +0100 Subject: [PATCH 2/5] verify: isolate the deliberate compute stand-in policy --- project_tuxbox/verify.py | 6 ++++-- tests/test_lanes_compute_root.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/project_tuxbox/verify.py b/project_tuxbox/verify.py index 76e00913..883ae699 100644 --- a/project_tuxbox/verify.py +++ b/project_tuxbox/verify.py @@ -460,9 +460,11 @@ def expect_root_translations(output): return "the provider substituted a stand-in for the program its root can bind" return None - names = ("TUXBOX_LOG", "WINEDEBUG", "TUXBOX_SHADER_SESSION") + # This gate deliberately checks one refused program's stand-in. Do not + # inherit the caller's policy for the real game or another verification gate. + names = ("TUXBOX_LOG", "WINEDEBUG", "TUXBOX_SHADER_SESSION", "TUXBOX_NULL_PIPELINES") saved = {name: host.env.get(name) for name in names} - host.env.update(TUXBOX_LOG="1", WINEDEBUG="-all,+debugstr") + host.env.update(TUXBOX_LOG="1", WINEDEBUG="-all,+debugstr", TUXBOX_NULL_PIPELINES="1") host.env.pop("TUXBOX_SHADER_SESSION", None) try: forget(rootless) diff --git a/tests/test_lanes_compute_root.py b/tests/test_lanes_compute_root.py index d1d72ef8..96a87999 100644 --- a/tests/test_lanes_compute_root.py +++ b/tests/test_lanes_compute_root.py @@ -68,7 +68,7 @@ class ComputeRootGateTests(unittest.TestCase): STAND_IN = "substituted null compute pipeline for an untranslated shader (1 so far)\n" REFUSAL = "unmapped descriptor at s5 + 0xa0" - def run_gate(self, output, compiled, refused): + def run_gate(self, output, compiled, refused, null_policy=None): rootless = [hashlib.sha256(shader_fixture.root_shader(offset)).hexdigest() for offset in (0x40, 0xA0)] with TemporaryDirectory() as prefix: sources = Path(prefix) / SOURCE_CACHE @@ -80,6 +80,8 @@ def run_gate(self, output, compiled, refused): for path in (*stale, kept): path.write_bytes(b"") env = {"WINEPREFIX": prefix, "TUXBOX_SHADER_SESSION": "1", "TUXBOX_LOG": "stderr"} + if null_policy is not None: + env["TUXBOX_NULL_PIPELINES"] = null_policy seen = {} @contextmanager @@ -118,6 +120,14 @@ def test_root_translations_pass_and_clean_their_entries(self): self.assertEqual(seen["env_after"]["TUXBOX_SHADER_SESSION"], "1") self.assertEqual(seen["env_after"]["TUXBOX_LOG"], "stderr") + def test_null_policy_is_explicit_and_restored(self): + for policy in (None, "0", "1"): + with self.subTest(policy=policy): + seen, _ = self.run_gate(self.STAND_IN, ["a"*64], [("b"*64, self.REFUSAL)], policy) + self.assertEqual(seen["env"]["TUXBOX_NULL_PIPELINES"], "1") + self.assertEqual(seen["env_after"].get("TUXBOX_NULL_PIPELINES"), policy) + self.assertIsNone(seen["problem"]) + def test_rootless_fallback_fails(self): rootless = self.run_gate(self.STAND_IN, [], [])[1] refusal = [("b" * 64, self.REFUSAL)] From ee9b6a65522d222c31d8c91467d7fa8f6d4bddb1 Mon Sep 17 00:00:00 2001 From: Valdi320 <61891540+Valdi320@users.noreply.github.com> Date: Thu, 26 Nov 2026 22:06:04 +0100 Subject: [PATCH 3/5] verify: exercise guarded mesh half-register position exports --- tests/test_translated_mesh_gpu.py | 9 +++++++++ tools/check_translated_mesh_gpu.py | 14 +++++++++++--- tools/reference/mesh/translated_guest.cpp | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/test_translated_mesh_gpu.py b/tests/test_translated_mesh_gpu.py index 68629130..22d13cd3 100644 --- a/tests/test_translated_mesh_gpu.py +++ b/tests/test_translated_mesh_gpu.py @@ -8,6 +8,15 @@ def test_cross_wave_triangle_and_invalid_index(self): self.assertIn("ds_swizzle_b32 v26, v25 offset:0x41f", program(128, True)) self.assertIn("v_mov_b32 v27, 0x300400", program(3, bad_index=True)) + def test_guarded_half_position(self): + for count in (3, 67, 128): + src = program(count, half=True) + self.assertIn("v_cmpx_gt_u32 s20, v1", src) + self.assertIn("v_cvt_f16_f32 v7, v21", src) + self.assertIn("v_cvt_f32_f16 v7, v7", src) + self.assertIn("exp pos0 v7,v22,v23,v24 done", src) + self.assertNotIn("v_cvt_f16_f32", program(count)) + def test_every_case_and_adapter_required(self): fields = {f"{case}_{clip}{suffix}": "10de:2704" if suffix else "64" for case in CASES for clip in ("full", "clipped") for suffix in ("", "_adapter")} diff --git a/tools/check_translated_mesh_gpu.py b/tools/check_translated_mesh_gpu.py index 76b46ca7..f7ca71ea 100644 --- a/tools/check_translated_mesh_gpu.py +++ b/tools/check_translated_mesh_gpu.py @@ -21,10 +21,10 @@ SRC = ROOT / "tools/reference/mesh" COUNTS = (3, 67, 128, 0, 129) -CASES = tuple(f"{name}-{count}" for count in COUNTS for name in ("plain", "swizzle")) + ("bad-index",) +CASES = tuple(f"{name}-{count}" for count in COUNTS for name in ("plain", "swizzle")) + ("bad-index", "half-3", "half-67", "half-128") -def program(count, swizzle=False, bad_index=False): +def program(count, swizzle=False, bad_index=False, half=False): first = {67: 64, 128: 125}.get(count, 0) src = (SRC / "translated_shared_count.s").read_text() src = "\n".join(line for line in src.splitlines() if not line.startswith("//")) @@ -42,6 +42,14 @@ def program(count, swizzle=False, bad_index=False): f"s_waitcnt lgkmcnt(0)\nv_cmp_eq_u32 vcc, {first + 2}, v26") src = src.replace(f"v_cmp_eq_u32 vcc, {first + 1}, v1", f"v_cmp_eq_u32 vcc, {first + 1}, v26") + if half: + # Keep the launch value's high half only until a guarded widening. + src = src.replace("s_cmp_eq_u32 s20, 0", + "s_mov_b64 s[44:45], exec\nv_cmpx_gt_u32 s20, v1\n" + "s_cbranch_execz 2\nv_cvt_f16_f32 v7, v21\n" + "v_cvt_f32_f16 v7, v7\ns_mov_b64 exec, s[44:45]\n" + "s_cmp_eq_u32 s20, 0") + src = src.replace("exp pos0 v21,v22,v23,v24 done", "exp pos0 v7,v22,v23,v24 done") return src + "\n" @@ -97,7 +105,7 @@ def main(): bad = case == "bad-index" count = 3 if bad else int(case.split("-")[1]) source = trial / (case + ".dxbc") - source.write_bytes(shader(assemble(a.llvm_mc, program(count, case.startswith("swizzle"), bad)))) + source.write_bytes(shader(assemble(a.llvm_mc, program(count, case.startswith("swizzle"), bad, case.startswith("half"))))) hlsl = trial / (case + ".hlsl") profile = trial / (case + ".profile") dxil = trial / (case + ".cso") diff --git a/tools/reference/mesh/translated_guest.cpp b/tools/reference/mesh/translated_guest.cpp index 4952f0c9..128894c3 100644 --- a/tools/reference/mesh/translated_guest.cpp +++ b/tools/reference/mesh/translated_guest.cpp @@ -145,7 +145,7 @@ int main() { try { for (const char* name : {"plain-3", "swizzle-3", "plain-67", "swizzle-67", "plain-128", "swizzle-128", "plain-0", "swizzle-0", - "plain-129", "swizzle-129", "bad-index"}) { + "plain-129", "swizzle-129", "bad-index", "half-3", "half-67", "half-128"}) { const std::string id(name); const bool draw = id != "bad-index" && id.find("-0") == std::string::npos && id.find("-129") == std::string::npos; From 4dfd0089383458877095170d85aaba7125c50209 Mon Sep 17 00:00:00 2001 From: Valdi320 <61891540+Valdi320@users.noreply.github.com> Date: Thu, 26 Nov 2026 22:27:46 +0100 Subject: [PATCH 4/5] verify: require root-aware translated mesh shaders in Lanes --- examples/lanes/raster_fixture.py | 31 ++++++++++++++++++++++++++++--- examples/lanes/selftest.cpp | 4 ++-- project_tuxbox/verify.py | 30 ++++++++++++++++++++---------- tests/test_lanes_raster.py | 32 +++++++++++++++++--------------- tests/test_verify.py | 14 ++++++++++++++ 5 files changed, 81 insertions(+), 30 deletions(-) diff --git a/examples/lanes/raster_fixture.py b/examples/lanes/raster_fixture.py index 172ea095..2047218c 100644 --- a/examples/lanes/raster_fixture.py +++ b/examples/lanes/raster_fixture.py @@ -89,7 +89,28 @@ MESH_USER = ([0, 0, 1, 501, 0x200],) MESH_USED = ([2, 0, 501, 0, 0x2_0004],) MESH_RESOURCES = ([2, 0, 501, 501],) -MESH_CODE = (0xBF810000,) # s_endpgm: the desktop replacement runs instead +# Synthetic RDNA2 NGG, 67 vertices, a guarded FP16-to-FP32 position export. +# Assembled from tools.check_translated_mesh_gpu.program(67, half=True). +MESH_CODE = ( + 0xd7650000, 0x020100c1, 0x7e000505, 0x9381ff03, 0x00040018, 0xd7660000, + 0x020200c1, 0x900a8700, 0xd7460001, 0x04010c01, 0xbe9403ff, 0x00000043, + 0x7e2802ff, 0x80000000, 0x7e3602ff, 0x04210440, 0x7d840280, 0x02283714, + 0x7d8402ff, 0x00000042, 0xd5010015, 0x01a9fef3, 0x40400000, 0x7d8402ff, + 0x00000041, 0xd5010016, 0x01a9fef3, 0x40400000, 0x7e2e02f0, 0x7e3002f2, + 0xbeac047e, 0x7da80214, 0xbf880002, 0x7e0e1515, 0x7e0e1707, 0xbefe042c, + 0xbf068014, 0x8580807e, 0xb5940080, 0x8582807e, 0x88800000, 0x88820202, + 0x88800002, 0xd501000a, 0x00010280, 0x7e00050a, 0x87000081, 0xbf068100, + 0xbe80047e, 0x8582807e, 0xd501000b, 0x00090214, 0x8984c102, 0x7e0c050b, + 0x7da40280, 0xbf88000d, 0x8f078c06, 0x8aea027e, 0x88060607, 0xbefc0306, + 0xbf900009, 0xbf8c0000, 0xbf870006, 0xbf8a0000, 0x7e147081, 0xf80008c0, + 0x00000000, 0xf8000941, 0x0000000a, 0xbf8cff0f, 0xbefe0400, 0xbf8a0000, + 0x7d880214, 0x8780046a, 0xbe862400, 0xbf880012, 0xd548000c, 0x02291514, + 0xd548000d, 0x02292914, 0x361c28ff, 0x000003ff, 0x7d861814, 0xd4c30002, + 0x00021a14, 0xd4c30000, 0x00021c14, 0x8882026a, 0x88800200, 0xd501000f, + 0x0001ff14, 0x80000000, 0xf8000941, 0x0000000f, 0xbf8cff0f, 0xbefe0406, + 0x7d880214, 0x8780046a, 0xbe802400, 0xbf880002, 0xf80008cf, 0x18171607, + 0xbf810000, +) ABSENT = 0xDEADBEEFDEADBEEF ROWS_AT, CODE_AT = 0x240, 0x280 @@ -183,10 +204,14 @@ def mesh_sampler_pixel(): def mesh(): - """The records-only console mesh program (shader model 6.5, stage 13).""" + """Synthetic NGG mesh program with guarded FP16 position (stage 13).""" + info = bytearray(validation(13, MESH_RESOURCES)) + info[31] = 2 + struct.pack_into("> 16, 13) self.assertEqual(mesh[b"PSV0"][28], 13) + self.assertEqual(mesh[b"PSV0"][31], 2) + self.assertEqual(struct.unpack_from(" Date: Thu, 26 Nov 2026 22:40:12 +0100 Subject: [PATCH 5/5] verify: isolate raster gate null policy and document translated mesh fixture --- examples/lanes/README.md | 2 +- project_tuxbox/verify.py | 13 +++++++------ tests/test_lanes_raster.py | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/lanes/README.md b/examples/lanes/README.md index 912b1c7b..b6ab44c3 100644 --- a/examples/lanes/README.md +++ b/examples/lanes/README.md @@ -120,7 +120,7 @@ The `raster-tables` scenario draws a fullscreen triangle with two hand-written c The `raster-samplers` scenario draws with the same vertex program and a third hand-written pixel program. It samples a 2x1 texture of 1.0 and 3.0, at table 1 slot 0, with a linear clamped sampler it builds from literal words, as the console compiles a static sampler into a program. It declares that sampler as `s0`, where the title's root has a point-filtered static sampler. The provider has to give the literal state a static sampler of its own in the reflected root, so every texel reads 1.5. Bound to the root's `s0`, the texels read the point-filtered 1.0. -The `mesh-samplers` scenario samples the same way through a mesh pipeline. Its pixel program declares `s0` and `s1`, which the title's root has as point-filtered static samplers, so neither register can stand in for the literal state and the program does not translate against that root. Its mesh program is a console container with FSSM records only: they name the root constant `b501` where the root declares `b500`, so the provider builds the mesh stage a root of its own. The provider has to add the literal state to that root as a private static sampler and translate the pixel program against it, so every texel reads 1.5. Without that it falls back to the pixel program's translation without a root, whose private sampler the pipeline's root lacks, and the pipeline becomes a stand-in. The mesh program's desktop translation (`mesh_samplers.hlsl`, a fullscreen triangle) is compiled into the prepared cache under its digest before launch. +The `mesh-samplers` scenario samples the same way through a mesh pipeline. Its pixel program declares `s0` and `s1`, which the title's root has as point-filtered static samplers, so neither register can stand in for the literal state and the program does not translate against that root. Its synthetic console mesh program names the root constant `b501` where the title root declares `b500`, so the provider builds the mesh stage a root of its own. It emits guarded half-to-float positions for a 67-vertex NGG program. The provider has to add the literal state to the reflected root as a private static sampler and translate both stages against it, so every texel reads 1.5. The verification gate matches the loaded mesh and pixel digests against fresh shader-worker receipts, forbids rootless translations and stand-ins, and does not prepare a desktop mesh shader. The separate translated-mesh GPU control tests 3, 67 and 128 vertices, including clipped draws. These roots are made while the game runs, so the pixel programs cannot be prepared before launch. `verify` runs the three scenarios with the host worker, requires the provider to report the reflected root (for the vertex pipelines) or the mesh pipeline and its descriptor slots, and fails if a pixel or vertex program was translated without a root. diff --git a/project_tuxbox/verify.py b/project_tuxbox/verify.py index f1994b79..2ea67a5b 100644 --- a/project_tuxbox/verify.py +++ b/project_tuxbox/verify.py @@ -561,10 +561,9 @@ def lanes_raster_tables(host, check, gpu_args, pci, memory_symbols): adds to the reflected root. That root is serialized while the game runs, so nothing is prepared before launch: the host worker translates both programs against it. `mesh-samplers`: the same pixel program, declaring two samplers - the root has in another state, in a mesh pipeline. Only its records-only - mesh program's desktop translation (`mesh_samplers.hlsl`) is prepared; the - provider must add the literal state to the mesh root it builds and have the - worker translate the pixel program against that root. + the root has in another state, in a mesh pipeline. Both stages are + translated by the worker against the reflected root; the mesh program + exports guarded FP16-to-FP32 positions. No desktop shader is prepared. """ from examples.lanes.raster_fixture import mesh, mesh_sampler_pixel, pixel, sampler_pixel, vertex from .runtime_shaders import shader_session @@ -610,9 +609,11 @@ def problem(output): return None return problem - names = ("TUXBOX_LOG", "WINEDEBUG", "TUXBOX_TRACE_RASTER_ROOTS", "TUXBOX_SHADER_SESSION", "TUXBOX_RASTER_ROOT_FALLBACK") + names = ("TUXBOX_LOG", "WINEDEBUG", "TUXBOX_TRACE_RASTER_ROOTS", "TUXBOX_SHADER_SESSION", + "TUXBOX_RASTER_ROOT_FALLBACK", "TUXBOX_NULL_PIPELINES") saved = {name: host.env.get(name) for name in names} - host.env.update(TUXBOX_LOG="1", WINEDEBUG="-all,+debugstr", TUXBOX_TRACE_RASTER_ROOTS="1") + host.env.update(TUXBOX_LOG="1", WINEDEBUG="-all,+debugstr", TUXBOX_TRACE_RASTER_ROOTS="1", + TUXBOX_NULL_PIPELINES="0") # The fallback translates against the title's root and would hide a missing reflection. for name in ("TUXBOX_SHADER_SESSION", "TUXBOX_RASTER_ROOT_FALLBACK"): host.env.pop(name, None) diff --git a/tests/test_lanes_raster.py b/tests/test_lanes_raster.py index f5978b91..538de4d1 100644 --- a/tests/test_lanes_raster.py +++ b/tests/test_lanes_raster.py @@ -134,7 +134,7 @@ def run_gate(self, output, compiled, scenario="raster-tables"): kept = sources / "title.cso" for path in (*stale, kept): path.write_bytes(b"") - env = {"WINEPREFIX": prefix, "TUXBOX_RASTER_ROOT_FALLBACK": "1", "TUXBOX_LOG": "stderr"} + env = {"WINEPREFIX": prefix, "TUXBOX_RASTER_ROOT_FALLBACK": "1", "TUXBOX_LOG": "stderr", "TUXBOX_NULL_PIPELINES": "1"} seen = {} @contextmanager @@ -172,6 +172,8 @@ def test_reflected_draw_passes_and_cleans_its_entries(self): self.assertEqual(seen["stale"], [False, False]) self.assertNotIn("TUXBOX_RASTER_ROOT_FALLBACK", seen["env"]) self.assertEqual(seen["env"]["TUXBOX_TRACE_RASTER_ROOTS"], "1") + self.assertEqual(seen["env"]["TUXBOX_NULL_PIPELINES"], "0") + self.assertEqual(seen["env_after"]["TUXBOX_NULL_PIPELINES"], "1") self.assertIsNone(seen["problem"]) self.assertEqual(seen["left"], ["title.cso"]) self.assertEqual(seen["env_after"]["TUXBOX_RASTER_ROOT_FALLBACK"], "1")