From 8c0773b6600b905867f20740d76060c10b2ef15c Mon Sep 17 00:00:00 2001 From: Jeffrey C <990135+JeffreyBytes@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:59:28 -0600 Subject: [PATCH 1/2] d3d12: recover a mesh pixel program's literal samplers under a root with no static samplers A console pixel program builds its samplers from literal words, so a title's root can leave them out entirely. Against a root with no static samplers the translation reads each literal state from a private sampler (space 32765). The vertex and pixel roots add those samplers when they are reflected (inline_sampler::pixel, then inline_sampler::private), but the mesh path asked only inline_sampler::unmatched, which leaves a root without static samplers to those two. The mesh root then lacked the sampler the pixel translation names, and vkd3d-proton rejected the pipeline with "Failed to remap sampler 32765:0" (E_INVALIDARG). When the root the pixel stage is translated against has no static samplers, build the mesh table again with the samplers the vertex and pixel roots recover: the program's one declared sampler at its own register, or else its private samplers from register 0, which is where the translation against a root holding exactly those reads them. As before, the extended root is kept only if the pixel program translates against it. --- runtime/d3d12/src/device/compute_table.rs | 15 +++++++++++---- runtime/d3d12/src/device/stream.rs | 8 +++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/runtime/d3d12/src/device/compute_table.rs b/runtime/d3d12/src/device/compute_table.rs index bd741958..e2840365 100644 --- a/runtime/d3d12/src/device/compute_table.rs +++ b/runtime/d3d12/src/device/compute_table.rs @@ -73,6 +73,16 @@ fn missing_literal_samplers(shader: &[u8], stage: u32, existing: &[[u32; 13]]) - if private.iter().all(covered) { Vec::new() } else { private } } +/// The literal samplers of a pixel program under a root with no static samplers, +/// which `inline_sampler::unmatched` leaves alone. One declared sampler keeps its +/// register; otherwise each state takes a private register (space 32765) from 0, +/// where the translation against a root with only those samplers reads them. +pub(super) fn rootless_pixel_samplers(pixel: &[u8]) -> Option> { + tuxbox_dxbc::inline_sampler::pixel(pixel) + .map(|s| vec![s]) + .or_else(|| tuxbox_dxbc::inline_sampler::private(pixel, 0)) +} + /// Private static samplers for each literal state no static sampler of the root /// visible to the stage has (`inline_sampler::unmatched`). They take registers /// after every sampler register the root uses: the translator names a sampler by @@ -293,10 +303,7 @@ fn reflected_root( return Ok(TableLayout::Unsupported); }; if signature.static_samplers.is_empty() && ordinary { - recovered_samplers = tuxbox_dxbc::inline_sampler::pixel(pixel) - .map(|s| vec![s]) - .or_else(|| tuxbox_dxbc::inline_sampler::private(pixel, 0)) - .unwrap_or_default(); + recovered_samplers = rootless_pixel_samplers(pixel).unwrap_or_default(); } else if !signature.static_samplers.is_empty() { recovered_samplers = literal_samplers(pixel, 0, &signature); diff --git a/runtime/d3d12/src/device/stream.rs b/runtime/d3d12/src/device/stream.rs index 3d1cbc58..ee818205 100644 --- a/runtime/d3d12/src/device/stream.rs +++ b/runtime/d3d12/src/device/stream.rs @@ -281,11 +281,17 @@ unsafe fn create( // to that register whatever its state. Build the mesh table again with the // missing states as private static samplers, as the vertex/pixel roots do, // and keep the root as declared only if the program does not translate then. + // Against a root with no static samplers the translation names private + // samplers instead, which the root needs just the same. if original[0].is_none() && let (Some(root), Some((pixel, _)), Some((mesh, _)), Some(field), Some(table)) = (guest_root, original[1], original[7], root_record, pipeline.raster_table.as_ref()) && let Ok(signature) = tuxbox_dxbc::rootsig::parse_rts0(table.pixel_root.as_ref().unwrap_or(root).payload()) - && let Some(samplers) = tuxbox_dxbc::inline_sampler::unmatched(pixel, 0, &signature) + && let Some(samplers) = if signature.static_samplers.is_empty() { + super::compute_table::rootless_pixel_samplers(pixel) + } else { + tuxbox_dxbc::inline_sampler::unmatched(pixel, 0, &signature) + } && let Ok(Some(extended)) = super::mesh_table::reflected(&device.native, root, mesh, Some(pixel), node_mask, &samplers) && let Some(variant) = extended.pixel_root.as_ref().and_then(|r| shader_cache::raster_with_root(pixel, r.payload())) From f3ed82503216bc7a7e6b7739cac7862cb68e0746 Mon Sep 17 00:00:00 2001 From: Jeffrey C <990135+JeffreyBytes@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:59:28 -0600 Subject: [PATCH 2/2] lanes: draw through mesh pipelines whose root has no static samplers Add the `mesh-sampler-rootless` scenario. It draws through the `mesh-samplers` mesh program under the two-table root without its static samplers, with two pixel programs that sample with the literal linear state: the `raster-samplers` program, which declares only s0, and the two-sampler program with an empty feature part (SFI0), which shows it reads no sampler from the heap. The provider recovers the first program's sampler at its declared register and the second's at a private register, so the scenario covers both. The provider has to add those samplers to the mesh root it builds, so every texel reads the linear 1.5. Without that the pixel translation names a private sampler the root lacks, the host rejects the pipeline (0x80070057) and the target keeps its clear value. The `lanes-raster-tables` verify suite runs it after `mesh-sampler-single` under the same gate: the mesh pipeline and its one reflected descriptor slot, no stand-in, and no translation of a pixel program without a root. Like the other mesh scenarios it stays out of `all`. --- examples/lanes/README.md | 3 +++ examples/lanes/raster_fixture.py | 18 +++++++++++++++++- examples/lanes/selftest.cpp | 16 +++++++++++++++- project_tuxbox/verify.py | 15 +++++++++++---- tests/test_lanes_raster.py | 25 +++++++++++++++++++++---- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/examples/lanes/README.md b/examples/lanes/README.md index c71fb870..b095e181 100644 --- a/examples/lanes/README.md +++ b/examples/lanes/README.md @@ -60,6 +60,7 @@ The game also imports Windows core API sets for services such as files, timing a | `lane-spill-interp` | A console pixel program whose f16 interpolator's attribute selector matches the number of its lane-spill register ([raster tables](#raster-tables)) | | `compute-root` | Two root-less console compute programs under a root with three descriptor tables that the provider cannot reflect ([compute roots](#compute-roots)) | | `mesh-samplers` | The same literal sampler in a mesh pipeline, whose mesh root the provider builds ([raster tables](#raster-tables)); not part of `all` | +| `mesh-sampler-rootless` | The literal sampler programs in mesh pipelines whose root has no static samplers ([raster tables](#raster-tables)); not part of `all` | ```sh python tuxbox.py verify --only lanes-selftest --output build/lanes-selftest.json @@ -126,6 +127,8 @@ The `lane-spill-interp` scenario draws the same fullscreen triangle with a third 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-sampler-rootless` scenario draws through that mesh program under the same root without its static samplers, with the `raster-samplers` pixel program and with the two-sampler one carrying an empty feature part. The translation against a root with no static samplers reads a literal state from a private sampler, so the provider has to add each program's samplers to the mesh root: the declared `s0` for the program with one sampler, a private register for the program with two. Without them the host rejects both pipelines, which become stand-ins. + 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. ```sh diff --git a/examples/lanes/raster_fixture.py b/examples/lanes/raster_fixture.py index 172ea095..b9c6f586 100644 --- a/examples/lanes/raster_fixture.py +++ b/examples/lanes/raster_fixture.py @@ -21,6 +21,11 @@ records name root constant `b501` where the root declares `b500`, so the provider rewrites the root for the mesh stage, and its translation is a desktop mesh shader (`mesh_samplers.hlsl`) prepared under its digest. + +`mesh-sampler-rootless` draws through that mesh program under a root with no +static samplers, first with the `raster-samplers` pixel program and then with the +two-sampler one carrying an empty feature part (`SFI0`), which shows that it +reads no sampler from the heap. """ from pathlib import Path import struct @@ -182,6 +187,16 @@ def mesh_sampler_pixel(): ]) +def rootless_sampler_pixel(): + """The two-sampler pixel program with a feature part that names no heap indexing.""" + return container(0x60, image(5, SAMPLER_PIXEL_CODE, SAMPLER_PIXEL_USER, MESH_SAMPLER_PIXEL_USED, inputs=2), [ + (b"SFI0", bytes(8)), + (b"ISGN", signature([("SV_Position", 0, 1, 3, 0, 15, 0)])), + (b"OSGN", signature([("SV_Target", 0, 64, 3, 0, 1, 0)])), + (b"PSV0", validation(0, MESH_SAMPLER_PIXEL_RESOURCES)), + ]) + + def mesh(): """The records-only console mesh program (shader model 6.5, stage 13).""" return container(0xD0065, image(2, MESH_CODE, MESH_USER, MESH_USED), [ @@ -201,7 +216,8 @@ def array(name, data): + array("raster_sampler_pixel", sampler_data) + f"constexpr float raster_sampler_texels[] = {{{texels}}};\n" + f"constexpr float raster_sampler_linear = {SAMPLER_LINEAR!r}f, raster_sampler_point = {SAMPLER_POINT!r}f;\n" - + array("mesh_sampler_mesh", mesh()) + array("mesh_sampler_pixel", mesh_sampler_pixel())) + + array("mesh_sampler_mesh", mesh()) + array("mesh_sampler_pixel", mesh_sampler_pixel()) + + array("mesh_rootless_pixel", rootless_sampler_pixel())) if __name__ == "__main__": diff --git a/examples/lanes/selftest.cpp b/examples/lanes/selftest.cpp index a00112f6..f4614b24 100644 --- a/examples/lanes/selftest.cpp +++ b/examples/lanes/selftest.cpp @@ -853,6 +853,19 @@ void mesh_sampler_single(ID3D12Device* device) { {mesh_sampler_mesh, sizeof(mesh_sampler_mesh)}); } +// Two pixel programs in mesh pipelines under a root with no static samplers, +// as a title leaves out the samplers the console compiles into its programs. +// The translation against such a root reads the literal state from a private +// sampler, so the provider must add each program's samplers to the mesh root it +// builds: the declared s0 for the program with one sampler, a private register +// for the one that declares two. Without them the host rejects the pipeline, +// which becomes a stand-in, and the target keeps its clear value. +void mesh_sampler_rootless(ID3D12Device* device) { + auto root = two_table_root(device, nullptr); + for (const D3D12_SHADER_BYTECODE pixel : {D3D12_SHADER_BYTECODE{raster_sampler_pixel, sizeof(raster_sampler_pixel)}, + D3D12_SHADER_BYTECODE{mesh_rootless_pixel, sizeof(mesh_rootless_pixel)}}) + draw_linear_sample(device, root.Get(), pixel, {mesh_sampler_mesh, sizeof(mesh_sampler_mesh)}); +} // A console shader whose wave32 masked DPP exclusive prefix the translator must // lower to `WavePrefixSum`. The old translator rejects it with "unrecognized @@ -2319,6 +2332,7 @@ constexpr Scenario scenarios[] = { {L"compute-root", compute_root}, {L"mesh-samplers", mesh_samplers}, {L"mesh-sampler-single", mesh_sampler_single}, + {L"mesh-sampler-rootless", mesh_sampler_rootless}, {L"compute-root-recovery", compute_root_recovery}, {L"bindless-compute", bindless_compute}, {L"bindless-sampler", bindless_sampler}, @@ -2375,7 +2389,7 @@ const wchar_t* const selftest_scenarios[] = {L"labels", L"cross-queue L"thread-dimensions", L"descriptor-reclaim", L"xbox-shader", L"wave64-shader", L"raster-tables", L"lane-spill-interp", L"wave-alloc", L"raster-samplers", L"compute-root", - L"mesh-samplers", L"mesh-sampler-single", + L"mesh-samplers", L"mesh-sampler-single", L"mesh-sampler-rootless", L"compute-root-recovery", L"bindless-compute", L"bindless-sampler"}; const unsigned selftest_scenario_count = static_cast(std::size(selftest_scenarios)); diff --git a/project_tuxbox/verify.py b/project_tuxbox/verify.py index 96b33928..c0dc5fb4 100644 --- a/project_tuxbox/verify.py +++ b/project_tuxbox/verify.py @@ -614,16 +614,21 @@ def lanes_raster_tables(host, check, gpu_args, pci, memory_symbols): 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. + worker translate the pixel program against that root. `mesh-sampler-single`: + the one-sampler pixel program in that mesh pipeline. `mesh-sampler-rootless`: + two pixel programs in mesh pipelines under a root with no static samplers, + whose literal samplers the provider must add to the mesh root whole. """ - from examples.lanes.raster_fixture import mesh, mesh_sampler_pixel, pixel, sampler_pixel, vertex + from examples.lanes.raster_fixture import (mesh, mesh_sampler_pixel, pixel, rootless_sampler_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 sources = Path(host.env["WINEPREFIX"]) / SOURCE_CACHE rootless = {hashlib.sha256(data).hexdigest() - for data in (vertex(), pixel(), sampler_pixel(), mesh_sampler_pixel(), spill_pixel())} + for data in (vertex(), pixel(), sampler_pixel(), mesh_sampler_pixel(), rootless_sampler_pixel(), + spill_pixel())} mesh_key = hashlib.sha256(mesh()).hexdigest() messages = [] @@ -676,7 +681,8 @@ def expect_translated(output): 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)): + ("mesh-samplers", MESH_SAMPLER_SLOTS), ("mesh-sampler-single", MESH_SAMPLER_SLOTS), + ("mesh-sampler-rootless", MESH_SAMPLER_SLOTS)): forget(rootless | {mesh_key}) if scenario.startswith("mesh-"): prepare_mesh() @@ -1161,6 +1167,7 @@ def exports_receipt(_imports): "lanes-raster-samplers": "A console pixel program's literal linear sampler, which the title's root names in another state", "lanes-compute-root": "Root-less console compute programs translated only against a three-table root", "lanes-mesh-samplers": "The same literal sampler in a mesh pipeline, added to the mesh root the provider builds", + "lanes-mesh-sampler-rootless": "Literal samplers in mesh pipelines whose root has no static samplers", "lanes-compute-root-recovery": "Partially reflected compute root with an appended descriptor range and paging", "lanes-bindless-compute-wide": "A direct-indexed compute program's heap UAV through the paged index map", "lanes-bindless-compute-constrained": "The same with fewer resident descriptors than the index it uses", diff --git a/tests/test_lanes_raster.py b/tests/test_lanes_raster.py index 3e1942eb..aec588cb 100644 --- a/tests/test_lanes_raster.py +++ b/tests/test_lanes_raster.py @@ -67,7 +67,8 @@ def test_header_carries_both_programs_and_the_expected_value(self): self.assertIn("raster_sampler_texels[] = {1.0f, 3.0f};", text) self.assertIn("raster_sampler_linear = 1.5f, raster_sampler_point = 1.0f;", text) for name, data in (("mesh_sampler_mesh", raster_fixture.mesh()), - ("mesh_sampler_pixel", raster_fixture.mesh_sampler_pixel())): + ("mesh_sampler_pixel", raster_fixture.mesh_sampler_pixel()), + ("mesh_rootless_pixel", raster_fixture.rootless_sampler_pixel())): values = re.search(rf"{name}\[\] = \{{([0-9,]+)\}};", text).group(1) self.assertEqual(bytes(int(value) for value in values.split(",")), data) @@ -107,6 +108,11 @@ def test_mesh_programs_name_a_second_sampler_and_a_moved_root_constant(self): self.assertEqual(rows(program, 0xe8, 0xf8), [[0, 0, 1, 501, 0x200]]) self.assertEqual(rows(program, 0xf0, 0xfc), [[2, 0, 501, 0, 0x2_0004]]) + def test_rootless_program_adds_only_an_empty_feature_part(self): + found, base = parts(raster_fixture.rootless_sampler_pixel()), parts(raster_fixture.mesh_sampler_pixel()) + self.assertEqual(found.pop(b"SFI0"), bytes(8)) + self.assertEqual(found, base) + def trace(slots): return ('multi-table raster roots after 1 pipelines: {"reflected": 1}\n' @@ -119,7 +125,7 @@ class RasterGateTests(unittest.TestCase): def run_gate(self, output, compiled, scenario="raster-tables"): rootless = [hashlib.sha256(data).hexdigest() for data in (raster_fixture.vertex(), raster_fixture.pixel(), raster_fixture.sampler_pixel(), - raster_fixture.mesh_sampler_pixel())] + raster_fixture.mesh_sampler_pixel(), raster_fixture.rootless_sampler_pixel())] mesh_key = hashlib.sha256(raster_fixture.mesh()).hexdigest() with TemporaryDirectory() as prefix: sources = Path(prefix) / SOURCE_CACHE @@ -169,7 +175,8 @@ def run_tool(command, **_): def test_reflected_draw_passes_and_cleans_its_entries(self): seen, _ = self.run_gate(self.TRACE, ["a" * 64, "b" * 64]) - self.assertEqual(seen["calls"], ["lanes-raster-tables", "lanes-lane-spill-interp", "lanes-raster-samplers", "lanes-mesh-samplers", "lanes-mesh-sampler-single"]) + self.assertEqual(seen["calls"], ["lanes-raster-tables", "lanes-lane-spill-interp", "lanes-raster-samplers", "lanes-mesh-samplers", "lanes-mesh-sampler-single", + "lanes-mesh-sampler-rootless"]) self.assertEqual(seen["arguments"][:2], ["--selftest", "raster-tables"]) self.assertEqual(seen["stale"], [False, False]) self.assertNotIn("TUXBOX_RASTER_ROOT_FALLBACK", seen["env"]) @@ -208,7 +215,8 @@ def test_mesh_draw_prepares_its_mesh_and_needs_the_mesh_pipeline(self): self.assertIsNone(seen["problem"]) # Only this scenario has the prepared mesh translation, and it is removed after. self.assertEqual(seen["mesh"], True) - self.assertEqual(seen["calls"], ["lanes-raster-tables", "lanes-lane-spill-interp", "lanes-raster-samplers", "lanes-mesh-samplers", "lanes-mesh-sampler-single"]) + self.assertEqual(seen["calls"], ["lanes-raster-tables", "lanes-lane-spill-interp", "lanes-raster-samplers", "lanes-mesh-samplers", "lanes-mesh-sampler-single", + "lanes-mesh-sampler-rootless"]) self.assertEqual(seen["mesh_command"][1:5], ["-T", "ms_6_5", "-E", "main"]) self.assertTrue(seen["mesh_command"][-1].endswith("examples/lanes/mesh_samplers.hlsl")) self.assertEqual(seen["left"], ["title.cso"]) @@ -217,6 +225,15 @@ def test_mesh_draw_prepares_its_mesh_and_needs_the_mesh_pipeline(self): self.assertIn("stand-in", self.run_gate(mesh_trace + "substituted null raster stream pipeline\n", [], "mesh-samplers")[0]["problem"]) self.assertIn("without its root", self.run_gate(mesh_trace, [rootless[3]], "mesh-samplers")[0]["problem"]) + # The root with no static samplers runs the same gate, with the mesh translation prepared. + seen, _ = self.run_gate(mesh_trace, [], "mesh-sampler-rootless") + self.assertEqual(seen["arguments"][:2], ["--selftest", "mesh-sampler-rootless"]) + self.assertEqual(seen["mesh"], True) + self.assertIsNone(seen["problem"]) + self.assertIn("stand-in", self.run_gate(mesh_trace + "substituted null raster stream pipeline\n", [], + "mesh-sampler-rootless")[0]["problem"]) + self.assertIn("without its root", self.run_gate(mesh_trace, [rootless[4]], + "mesh-sampler-rootless")[0]["problem"]) def test_scenario_runs_only_under_the_worker(self): self.assertNotIn("raster-tables", LANES_SCENARIOS)