Skip to content

Lanterns (3/n): stage 3, compute on a second queue feeding a draw, with a cross-queue fence (TEST-1063) - #4865

Open
tedin7 wants to merge 18 commits into
ItsNotRexed:mainfrom
tedin7:lanterns-stage3
Open

tedin7 wants to merge 18 commits into
ItsNotRexed:mainfrom
tedin7:lanterns-stage3

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-1063, #4816 (comment) (the Lanterns proposal; this is piece 3)

Depends on: #4863 (Lanterns stage 1, and through it #4820). Their commits appear here until they land. This PR's commit is the last one.

Checked against #313: this stage only uses methods already on main (it passes on main with #4820 and #4863): a COMPUTE queue, Dispatch, UAV buffers, and cross-queue Wait/Signal with the wait submitted before its signal (D3D-321, #2951, is on main). It does not implement or duplicate a layer method. It signals fences only from queues and waits by polling GetCompletedValue, so the open fence items (CPU signals, fence release with pending work, rewinds) are untouched.

What and why

Stage 3 of Lanterns, the synthetic title-shaped guest from #4863: compute work on a second queue that a draw consumes, the pattern a title uses for GPU particles.

  • cs_lanterns_rise.asm (wave32) runs on a COMPUTE queue. It moves 256 points of light in integer fixed point, so the CPU can repeat each step exactly, and writes their instance records into a DEFAULT buffer with UAV access.
  • The direct queue waits on the compute fence and draws the points as a sixth DrawIndexedInstanced, whose instance V# points at that buffer.
  • Frame 1: compute (24 steps), then the frame. Frame 2: the frame is submitted first and waits for a fence value that a later compute submission (24 more steps) signals.

What it adds to stage 1: a compute PSO from an FSSM container (thread-group size and COMPUTE_PGM_RSRC2 from the FSSM header), the M4-style compute root signature (four root constants and a UAV table), Dispatch on a compute queue, cross-queue Wait/Signal with a wait submitted before its signal, and a draw reading what compute wrote.

The checks:

  1. The point states and instance records are read back and must equal the CPU's simulation word for word.
  2. Both frames are checked like stage 1: certain pixels exact, uncertain pixels one of their candidates.
  3. Between frame 1 and frame 2 the points must change exactly the certain pixels the reference predicts.
  4. Reported, not required: a third frame without the Wait, submitted before its compute work. A layer may order the queues by itself, so either result is allowed; the line says which one happened.

run_lanterns.py gets stage 3's PASS pattern (the two exact counts and the moved pixels must fit the frame) and its picture layout. Stage 1 is unchanged and prints the same line.

docs/lanterns.md gets a table of stages and a stage 3 section with its check line and control.

Tested

RunPod, RTX 5080, Linux, Wine 11.0, clang-cl 21 + xwin cross-build (runtime/cmake/clang-cl-xwin.cmake), Vulkan SDK 1.4.363, -DLEONIDA_TEST_LANTERNS=ON, targets gta6rt lanterns, run_lanterns.py --wine --stage N for every stage on the branch (each run in its own folder; the runner stops the prefix's wineserver before each launch).

  • --stage 3: exit 0:
    Lanterns stage 3: PASS, 97675 and 97664 of 98304 pixels exact, 256 points exact after 24 and 48 compute steps, points moved 14839 pixels.
    • Both frames: 256 of 256 point states and 256 of 256 instance records equal the CPU's.
    • Frame 1: 97,675 of 97,675 certain pixels exact, 629 of 629 uncertain pixels one of their candidates. Frame 2: 97,664 of 97,664 and 640 of 640.
    • Between the frames: 14,839 certain pixels changed, and the reference expects 14,839.
    • Without the Wait the result varies by run: once the previous frame's state (16,183 certain pixels differ from the new state), once a mix of the two (16,546).
  • --stage 1 on this branch: the same line as Lanterns (2/n): stage 1, a title-shaped guest through gta6rt --run with FSSM shaders, depth/stencil solids and shared edges (TEST-1063) #4863, 97926 of 98304 pixels exact, 378 edge pixels plausible, depth-off control changed 11610 pixels; shared edges through a wave64 VS/PS with the title's s8 table: 98304 of 98304 pixels exact, 673 centres on shared edges each drawn once.
  • Falsified, each reverted afterwards:
    • cs_lanterns_rise.asm repacked with one constant changed (green (5 + bits) / 8 to (6 + bits) / 8): 0 of 256 instance records equal in both frames (the states, stored before the change, stayed 256 of 256), 88,378 of 97,675 and 87,279 of 97,664 certain pixels exact. The guest printed stage 3 FAILED; the runner exited 1.
    • Frame 2 made to wait for a fence value nobody signals: the guest fails after 30 s with a fence stayed at 2 for 30000 ms, waiting for 3 (exit 1). The same change before the bounded wait hung until the runner killed it at 120 s (exit 3).
  • From the branch head, all OK under -W error: test_run_lanterns, test_fssm_pack, test_fssm_pack_chain (pytest, 6 passed), test_runtime_paths, test_ci_registration, test_docs_links, test_docs_repo_paths, test_docs_list_items, test_docs_table_rows, test_text_encoding, test_text_write_line_endings; compileall clean.

Not covered

  • Tested on one machine only: RTX 5080, Linux, Wine 11. No native Windows run, no AMD or Intel GPU yet.
  • No validation claim. Vulkan validation layers under Wine on that pod are still being looked into.
  • Offscreen frames only. No present, no frame loop.
  • The FSSM programs are synthetic. They carry only the fields the tools read, and the code is ours.
  • The reference is computed on the CPU, not by another D3D12 implementation.
  • The run without the Wait is not a test of a race: it only reports what this layer and GPU did.

Credits

AI-assisted (Claude Code). No game files.

…ssembly

runtime/test/lanterns/fssm_pack.py assembles .asm with llvm-mc and packs the code
into an FSSM program in the layout docs/design.md and tools/fssm_header.py
describe (code section at 0xC0/0xC8 with the code 0x28 in, the wave flag at
0xD4, the code end at 0xE8, the 0x120/0x12C/0x130 directory, the PS input table
or the CS thread-group header at 0x138, the binding-table tail). It wraps the
program in the container the title ships (DXBC { DXIL { XDAT { 0x0D: XBCH +
zlib(FSSM) } } }, plus an ISG1 part when a pixel shader reads SV_Position).
With --translate it runs fssm_unpack.py, shader_disasm.py and rdna2spirv.py on
the folder, as make_game.py's shaders stage does, and fails unless every shader
comes back: same blob, decoded from the header with no invalid word, and a row
in spirv/index.json keyed by the packed program's SHA-256.

It is a test helper, so it does not live in tools/: make_game.py's
translator_digest() hashes every file there, and a new one would make a resumed
shaders stage throw away its finished shards.

tests/test_fssm_pack.py (standard library, the check job) reads the packed
fields back with fssm_header.py, the code range with shader_disasm.py and the
container with fssm_unpack.py, and checks the refusals. tests/test_fssm_pack_chain.py
(pytest, the translator-tests job, which has llvm-mc 21 and spirv-tools) runs
the whole offline chain on three small programs.

The runtime workflow's path filter gains tools/rdna2_decode.py and
tools/rdna2_isa_tables.py: shader_disasm.py imports them, and
tests/test_runtime_paths.py requires every tool a runtime/ script runs to be
listed there.
…2_isa_tables.py

runtime/test/lanterns/fssm_pack.py runs shader_disasm.py, which imports them,
and tests/test_runtime_paths.py requires every tool a runtime/ script reaches
to be in the runtime workflow's path filter.
…yloads

The packer wrote one narrow container layout: every PS input's slot byte
was position + 1, the tail had no binding records, and XDAT had one 0x0D
entry. A reader that took the slot byte for the attr number, or the first
of two payloads, would still pass on what it packed.

- "; input: ... slot=N" sets byte 6 of the record; the attr number stays
  the table position.
- "; binding: W0 W1 W2 W3 W4" adds a 20-byte record to the tail
  (fssm_header.binding_table reads them back in order).
- "; first-payload: NAME" puts a second program (the same code under
  NAME, so another hash) in a first 0x0D entry, as 195 of the title's
  containers have two. fssm_unpack.py and the runtime take the last.

Tests: the slot bytes, records and both payloads read back
(test_fssm_pack.py), and through the offline chain a PS with slot 9, a
binding record and a first payload is keyed by its own blob with its flat
input at position 0 (test_fssm_pack_chain.py; the old packer fails it).
Every output is named after its shader (<name>.dxbc, fssm/<name>.fssm,
disasm/<name>.s, the SPIR-V). Two inputs such as a/ps_tile.asm and
b/ps_Tile.asm, or a native variant named like its shader in another case,
wrote one file on a case-insensitive volume (Windows, macOS) while
index.json listed two rows, and the packer exited 0. The first row then
read the second shader's container.

pack_file() now only packs; main() compares all names after casefold()
and refuses a clash, naming both inputs, before it creates the output
folder or writes any file.
…gta6rt --run

Lanterns is an x64 guest that goes through the chain a title would: its
hand-written RDNA2 shaders are packed into FSSM programs inside DXBC/XDAT/XBCH
containers (runtime/test/lanterns/fssm_pack.py) and translated by
fssm_unpack.py, shader_disasm.py and rdna2spirv.py; gta6rt --run maps it and
answers d3d12_xs.dll!D3D12XboxCreateDevice with the Vulkan device; the guest
builds its pipelines from the containers through the D3D12 API. lanterns.cpp
is the guest's checks, lanterns_gpu.cpp/.h its D3D12 side and lanterns_d3d12.h
the shared helpers, the layout later stages extend.

Stage 1: five DrawIndexedInstanced calls (prisms, cubes, octahedra, pyramids,
a checker floor) into a 384x256 RGBA32F target with D32 depth. Vertex, index
and instance buffers sit in DEFAULT heaps, filled by upload copies; the VS
fetches through two V#s in two descriptor tables, the model matrix and tint
come from root constants, the camera from a root CBV, and the floor PS reads its
colours through the code base. Interior pixels must match the CPU reference
bit for bit; edge, depth-tie and checker-border pixels must be one of their
candidate colours. A container whose FSSM program the index does not know must
be refused, and with the depth test off exactly the pixels the reference
predicts must change.

run_lanterns.py passes a run only on exit 0, the PASS line once and the shim's
complete factory line, and kills the whole process group when its timeout
expires (tests/test_run_lanterns.py, with a launcher that never ends).

Opt-in with -DLEONIDA_TEST_LANTERNS=ON; nothing is built or run by default. The
guest links tiny_frame's failing d3d12_xs stub (test/fixtures, ItsNotRexed#3488) instead of
a copy. docs/lanterns.md says what it covers, how to run it and its limits.
…cleanup fails

- The PASS line must match its stage's full pattern, with numbers that fit
  together; "PASS" followed by anything else no longer passes.
- Each run writes into a new folder under --out, so an old run's dumps or
  pictures cannot stand in for a missing one.
- On Linux the runner becomes a child subreaper and also kills descendants
  that left the launcher's session. taskkill and killpg results are
  checked; anything left alive fails the run with exit code 4.
- With --wine it stops the prefix's wineserver (-k, then -w, 10 s each)
  before the launch: a launch under a new virtual X server while the last
  run's explorer.exe is alive can hang in winevulkan's device creation.
- The docstring's Windows path no longer has an invalid escape
  (SyntaxWarning, fatal under -W error).

tests/test_run_lanterns.py: a grandchild that calls setsid() must die too,
each run gets its own folder, three malformed PASS lines are refused, and
the wineserver stop runs before the launch (fake wineserver and wine on
PATH; a hanging wineserver fails the run within its timeout).
The translator imports many files in tools/ (fssm_header, shader_ir,
shader_meta, mc_command, rdna2_decode, ...). Listing four of them let an
incremental build keep a stale spirv/index.json. Depend on the whole
tools/*.py glob, the set make_game.py's translator_digest() hashes.
…d bounds its fence waits

- Lookup control: both vertex-shader containers come from the same writer.
  The unmodified one must give a pipeline; the second differs in one byte
  of the program's name, so its FSSM hash is unknown and the layer must
  refuse it. Before, the refused container differed in padding only.
- A wave64 VS/PS pair (vs_lanterns_w64, ps_lanterns_lit_w64, "; wave: 64")
  draws the octahedra, so the native wave64 graphics path is checked too.
- The floor PS's inputs carry slot bytes 6 and 3 (the attr number is the
  table position), and vs_lanterns.asm's container has a first 0x0D
  payload before the real one.
- Reference: near an edge two faces of one solid share, one of the two
  must cover the pixel; the background is no longer a candidate there, so
  a crack along the edge fails.
- Every fence wait is bounded (30 s) and fails with a line naming it.
The lookup control, the shared-edge rule, the runner's strict line, run
folders, cleanup exit code and wineserver stop, the failures each fix was
shown to catch, output under the build folder, and which CI jobs run the
CPU tests.
… the title's s8 table

The title's VS and PS read their first table pointer at s8
(docs/d3d12_vulkan.md 3.5). The layer packs root arguments from s0 in
root-signature order, so a second draw's root signature starts with eight
32-bit constants (s0..s7) and then a table of two buffer SRVs (s[8:9]).
vs_lanterns_edges and ps_lanterns_edges are wave64 and read exactly that:
constants from s0..s3, vertices through table slot 0, the PS's alpha
through slot 1.

The draw is a fan of eight triangles around one vertex, every vertex on a
pixel centre, inner edges horizontal, vertical and at 1:1, 1:2, 3:2 and
1:4, so 673 pixel centres lie exactly on a shared edge. Each triangle has
its own flat colour from its provoking vertex; additive blending counts
the draws. lanterns_edges.h applies D3D's top-left rule in exact integers.
Every pixel must match: each shared-edge centre drawn once by the triangle
the rule names, nothing drawn twice, no gaps. The PASS line and the
runner's pattern gain this part; the sheet gains the fan.

Mutations on the RTX 5080: the PS reading slot 0 instead of 1 leaves
31884 of 98304 exact; a bottom-right reference leaves 0 of 673 (319 gaps).
rdna2spirv.py and rdna2_decode.py read tools/gfx10_formats.json, so a
change to the format table left spirv/index.json and the SPIR-V stale.
The shader rule now depends on tools/*.json as well as tools/*.py.
- wineserver -k/-w run through Popen with their output discarded; on
  overrun the process group is SIGKILLed and reaped within 5 s, and the
  run fails naming what was left. Before, a child of a hung wineserver
  survived the run.
- On Linux the runner does not launch unless prctl(PR_SET_CHILD_SUBREAPER)
  succeeds (exit 4): without it an escaped grandchild cannot be found, and
  the runner would claim a full cleanup it cannot check.
- Windows: taskkill failing for a launcher that already exited (128) is no
  longer reported as a survivor.

Tests: a wineserver that ignores SIGTERM and leaves a child (the child
must be dead after the run), and prctl mocked to fail (no launch, exit 4).
Both fail on the runner before this commit.
- cs_lanterns_rise.asm (wave32) runs on a COMPUTE queue. It moves 256
  points of light in integer fixed point and writes their instance records
  into a DEFAULT UAV buffer. The direct queue waits on the compute fence
  and draws them as a sixth DrawIndexedInstanced whose instance V# points at
  that buffer.
- Frame 1: compute, then the frame. Frame 2: the frame is submitted first
  and waits for a fence value a later compute submission signals.
- Checks: the point states and instance records equal the CPU's simulation
  word for word, both frames are exact where certain, and between the two
  frames the points change exactly the 14839 pixels the reference predicts.
  Control: a frame without the Wait is reported (not required).
- run_lanterns.py: a panel per stage; mask values for bounded pixels (used
  from stage 6).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent TEST-1063 review at adb3d50, native Windows RTX 5070 driver 616.56. Both the baseline and Vulkan API dump runs passed. Each frame matched all 256 point states, 256 instance records, and every checked pixel. Exactly 14,839 certain pixels changed as predicted; omitting the wait produced the previous state. The trace placed 72 dispatches on family 2 and 18 indexed draws on family 0. Frame 2 exercised wait-before-signal at the D3D12 interface. Synthetic offscreen guest; API dump only. AI-assisted.

The shared-edge draw read its vertices and the pixel shader's alpha word
straight from UPLOAD-heap buffers. On native Windows with an Intel UHD 770,
PingasMech found every covered pixel empty (31,884 of 98,304 exact, 0 of
673 edge centres). Both buffers now live in DEFAULT heaps, filled from one
UPLOAD staging buffer by CopyBufferRegion and moved to
NON_PIXEL_SHADER_RESOURCE / PIXEL_SHADER_RESOURCE, with the staging buffer
kept alive until the copy's fence has passed, as the main scene's buffers
already are. This is the change PingasMech tested on that machine.
@ricardotanaka

Copy link
Copy Markdown

Tested the current head 285888e2 (the rebase at 06:51 UTC; nothing has checked it yet), native Windows 11 26200, AMD Radeon RX 7600 (RDNA3, AMD 26.11.2 proprietary driver, subgroup 32..64), MSVC 19.44, CMake/Ninja RelWithDebInfo with -DLEONIDA_TEST_LANTERNS=ON, targets gta6rt lanterns, device line confirmed: pass. I built the stack once at #4871's head 4f22615b merged onto main 3faac557 (this head is an ancestor of it) and ran run_lanterns.py --stage 3 twice natively; both runs printed:

Lanterns stage 3: PASS, 97675 and 97664 of 98304 pixels exact, 256 points exact after 24 and 48 compute steps, points moved 14839 pixels

AI-assisted (Claude Code).

@memorypressure

Copy link
Copy Markdown

Verified head 285888e against main 3faac55 at check time: merges cleanly; the CPU-testable parts pass (run_lanterns 5/5 with fake wineserver stubs — no wine executed, test_fssm_pack 10/10, test_fssm_pack_chain 6/6 under pytest). The stage-3 compute-on-second-queue C++ test and shaders cannot be built or run on this CPU-only host, so the pixel-count and instance-record claims are unverified. Verified ancestry: #4863 head is a direct ancestor of this branch — it is stacked on #4863, so merge #4863 first or expect the full stage-1+3 diff. No CI checks were scheduled on this branch. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown

Tested 285888e on Windows Server 2022, CPython 3.13.12: pass

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

…layout

main's ItsNotRexed#4312 (D3D-448) gives a D3D12 compute PSO its root arguments from s4, a descriptor table as one 32-bit dword. cs_lanterns_rise.asm now count those user SGPRs in RSRC2 and start with moves that rebuild the layout the code was written for (the table as s[0:1] or s[4:5] with a zero high half).
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated for main's #4312 (D3D-448): the Lanterns compute shaders follow the console compute layout now.

  • Main merged in, then one commit here: cs_lanterns_rise.asm. Root arguments now start at s4. A descriptor table is one 32-bit dword. RSRC2's USER_SGPR counts 4 plus that span, and the thread-group ids follow it.
  • Each shader starts with a few s_mov_b32 that rebuild the layout its code was written for: the table as a 64-bit pair with a zero high half, then the constants and the group ids. The shader body itself is unchanged.
  • Without this, main's layout gave the old shaders a wrong table address, and the compute fence never signalled.
  • Checked on an RTX 5080 under Wine 11 from the top of the stack: stages 1, 3, 5, 9, 11, 20, 22, 23, 24 and 25 pass. The packer, runner and docs CPU tests pass on this branch.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants