Skip to content
Draft
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
4 changes: 2 additions & 2 deletions examples/lanes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ The `raster-samplers` scenario draws with the same vertex program and a third ha

The `lane-spill-interp` scenario draws the same fullscreen triangle with a third hand-written pixel program under an empty root. It writes a lane-spill area in v128, then runs an f16 interpolator whose attribute selector is encoded like v128. The selector is not a register read, so every texel must hold the program's constant. Under a refused translation the pipeline becomes a stand-in and every texel keeps its clear value.

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.
These roots are made while the game runs, so the pixel programs cannot be prepared before launch. `verify` runs the five 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.

```sh
python tuxbox.py verify --only lanes-raster-tables --output build/lanes-raster-tables.json
Expand Down
31 changes: 28 additions & 3 deletions examples/lanes/raster_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("<HH", info, 16, 128, 128)
struct.pack_into("<3I", info, 40, 128, 1, 1)
return container(0xD0065, image(2, MESH_CODE, MESH_USER, MESH_USED), [
(b"OSGN", signature([("SV_Position", 0, 1, 3, 0, 15, 0)])),
(b"PSV0", validation(13, MESH_RESOURCES)),
(b"PSV0", info),
])


Expand Down
4 changes: 2 additions & 2 deletions examples/lanes/selftest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ void raster_samplers(ID3D12Device* device) {
// pixel program against it. Without that the provider falls back to the pixel
// program's root-less translation, whose private sampler the root lacks: the
// pipeline becomes a stand-in and the target keeps its clear value. The mesh
// program's desktop translation is prepared before launch (`mesh_samplers.hlsl`).
// program is translated by the same runtime shader worker.
void mesh_samplers(ID3D12Device* device) {
const D3D12_STATIC_SAMPLER_DESC points[]{point_sampler(0), point_sampler(1)};
auto root = two_table_root(device, points, UINT(std::size(points)));
Expand Down Expand Up @@ -2388,7 +2388,7 @@ std::string run_selftest(const wchar_t* requested, const wchar_t* adapter) {
for (const auto& scenario : scenarios) {
if (!all && std::wcscmp(requested, scenario.name)) continue;
// This one writes nothing until the launcher's compiler has translated it,
// and mesh-samplers needs its mesh program's translation prepared first.
// and mesh-samplers needs its root-aware runtime shader worker.
if (all && (!std::wcscmp(scenario.name, L"wave64-shader") || !std::wcsncmp(scenario.name, L"mesh-sampler", 12) || !std::wcsncmp(scenario.name, L"bindless-", 9)))
continue;
const auto name = narrow(scenario.name);
Expand Down
49 changes: 31 additions & 18 deletions project_tuxbox/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -600,6 +602,17 @@ def expect_root_translations(output):
MESH_SAMPLER_SLOTS = 1


def missing_mesh_worker_receipt(output, compiled):
"""Require the exact mesh/pixel binaries loaded by the provider to be worker results."""
for stage in ("mesh", "pixel"):
loaded = set(re.findall(
rf"prepared {stage} shader loaded, source SHA-256 ([0-9a-f]{{64}})(?![0-9a-f])",
output))
if not loaded or not loaded.issubset(compiled):
return f"missing worker receipt for loaded {stage}: {loaded}"
return None


def lanes_raster_tables(host, check, gpu_args, pci, memory_symbols):
"""Draw with the Lanes console raster programs under a root with two tables.

Expand All @@ -611,15 +624,14 @@ 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 examples.lanes.spill_fixture import pixel as spill_pixel
from .runtime_shaders import shader_session
from .shader_prep import SOURCE_CACHE, compiler_tools, run_tool
from .shader_prep import SOURCE_CACHE

sources = Path(host.env["WINEPREFIX"]) / SOURCE_CACHE
rootless = {hashlib.sha256(data).hexdigest()
Expand All @@ -637,12 +649,6 @@ def forget(keys):
for path in [*sources.glob(f"{key}.*"), *sources.parent.glob(f"runtime/*/{key}.*")]:
path.unlink()

def prepare_mesh():
# The console mesh program has records only; its translation is this desktop shader.
sources.mkdir(parents=True, exist_ok=True)
hlsl = Path(__file__).resolve().parents[1] / "examples/lanes/mesh_samplers.hlsl"
run_tool([compiler_tools()[1], "-T", "ms_6_5", "-E", "main", "-O3", "-Fo", sources / f"{mesh_key}.cso", hlsl])

def expect_reflected(slots, mesh_pipeline=False):
def problem(output):
if "substituted null " in output:
Expand All @@ -655,8 +661,15 @@ def problem(output):
return "the provider did not reflect the two-table root"
if f"created raster pipeline with {slots} reflected FSSM descriptor slots" not in output:
return "the provider did not create the pipeline under the reflected root"
if compiled() & rootless:
if compiled() & (rootless | {mesh_key}):
return f"the worker translated a program without its root: {messages}"
if mesh_pipeline:
# A draw alone could pass with a prebuilt desktop mesh shader.
# Require the exact loaded binaries to have been requested from
# the Xbox shader worker during this scenario.
problem = missing_mesh_worker_receipt(output, compiled())
if problem:
return f"{problem}; {messages}"
return None
return problem

Expand All @@ -668,18 +681,18 @@ def expect_translated(output):
return f"the worker translated nothing: {messages}"
return None

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)
try:
for scenario, slots in (("raster-tables", 3), ("lane-spill-interp", None), ("raster-samplers", RASTER_SAMPLER_SLOTS),
("mesh-samplers", MESH_SAMPLER_SLOTS), ("mesh-sampler-single", MESH_SAMPLER_SLOTS)):
forget(rootless | {mesh_key})
if scenario.startswith("mesh-"):
prepare_mesh()
messages.clear()
with shader_session(sources.parent, host.env, messages.append):
check(f"lanes-{scenario}", "lanes/lanes.exe", ["--selftest", scenario, *gpu_args, "--report"],
Expand Down
12 changes: 11 additions & 1 deletion tests/test_lanes_compute_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
Loading
Loading