Skip to content

Lanterns (15/n): stage 25, a title-shaped 4K frame at scale: 6,880 draws, 88 dispatches, three queues (TEST-1063) - #5185

Open
tedin7 wants to merge 79 commits into
ItsNotRexed:mainfrom
tedin7:lanterns-stage25
Open

tedin7 wants to merge 79 commits into
ItsNotRexed:mainfrom
tedin7:lanterns-stage25

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

Depends on: #5117 (Lanterns stage 23, and through it #5099, #5098, #5097, #5096, #5095, #5093, #4873, #4871, #4869, #4865, #4863 and #4820). Their commits appear here until they land. This PR's commits are the last six: the stage, then five fixes on top (cross-queue order, resource states through the aux and top passes, the PASS pattern, a CPU gate, and two staggered gates so that each missing Wait shows on its own).

Checked against #313: this stage only uses methods already on main (it passes on main with the pieces before it): three queues (direct, compute, copy) with fences, Wait before the matching Signal, command lists recorded on worker threads, CopyDescriptorsSimple into a shader-visible ring, 58 graphics pipelines over 4 root signatures, a 4x MSAA target with ResolveSubresource, and readback by CopyTextureRegion. It does not implement or duplicate a layer method.

What and why

Stage 25 of Lanterns: a title-shaped frame at scale. The other stages each test one feature on a small frame; a title's frame has thousands of draws, dozens of pipelines, several queues and worker threads, every frame.

  • A 3840x2160 R16G16B16A16_FLOAT main pass with D32: about 5,000 draws (some instanced) through 58 pipelines and 4 root signatures, one descriptor copy and table per draw, recorded by 4 worker threads; a 4x MSAA pass, resolved; an RGBA8 pass. 6,880 draws and 88 dispatches per frame.
  • Particles stepped on a COMPUTE queue (drawn by the main pass) and between the passes on the direct queue; a COPY queue streams the instanced draws' records and 16 MiB of filler. Two frames in flight.
  • Cross-queue order: the direct queue's part of frame f goes first, with Wait(copy, f) and Wait(compute, f) before those Signals; the copy and compute parts follow, each after Wait(direct, f - 2) and a Wait on one of two CPU gate fences: the early gate opens when the CPU starts frame f + 1; the late gate opens when the CPU then waits for frame f, but only after the direct queue signals the end of frame f's main pass, or after 100 ms. The copy part takes the late gate on even frames, the compute part on odd frames. With every Wait in place the main pass waits for the late producer, so each frame pays the 100 ms (60 frames take about 15 s on the test machine instead of 7 s). The CPU waits for the direct queue's frame f - 2 before recording frame f. After use, the direct queue zeroes what it took from the other two queues, so a direct queue that skipped its Waits reads those zeros in every frame. Every Wait and Signal's HRESULT is checked. The streamed records and particle set A stay in NON_PIXEL_SHADER_RESOURCE through the aux and top passes, which read them too.
  • Checks: every frame's readback (three targets, both particle sets) byte for byte the first; frame 1 against the CPU reference at every pixel and both particle sets against the CPU's simulation; every 20th frame at a moving quarter-density lattice. A differing frame is dumped with the queue-level log; a frame past the timeout stops the run as a hang. Every D3D12 call is timed by class.
  • The default run is 60 frames (ctest, about 17 s on the test machine); the runner requires the frame's fixed shape (6,880 draws, 88 dispatches), at least 60 frames and at least 3 lattice checks. run_lanterns.py --stage 25 --soak runs 10,000 frames with a lattice check every 1,000. --jitter-us adds random delays before each queue's submission and each recording thread; scale_report.py turns the dumps into PNGs and profiler samples into hot spots.

docs/lanterns.md gets the stage 25 section and its row in the stages table, and stage 25 is a ctest (lanterns_stage25).

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 25: exit 0:
    Lanterns stage 25: PASS, 60 frames at 3840x2160 identical to the first (hash 99f8df1bea376593), 6880 draws and 88 dispatches per frame on 3 queues, frame 1 exact against the CPU reference at every certain pixel, 3 lattice checks exact.
    • Frame 1 against the CPU reference: 8,194,322 of 8,194,322 certain pixels exact, 100,078 of 100,078 uncertain pixels one of their candidates; particle sets A and B exact.
  • Falsified (each three runs of the default 60 frames, no jitter; each reverted afterwards):
    • only the direct queue's Wait(copy, f) removed: 30 of 59 frames differ from frame 1 (every frame where the copy part has the late gate) in each run; stage 25 FAILED, exit 1.
    • only Wait(compute, f) removed: 30 of 59 frames differ in each run, and frame 1 itself has 7,771,372 of 8,194,322 certain pixels exact; FAILED.
    • both removed: 59 of 59 frames differ in each run, frame 1 7,294,981 to 7,296,112 of 8,194,322 exact; FAILED.
    • control, nothing removed, three runs: 60 of 60 frames identical, PASS.
    • Before the two staggered gates, removing only one Wait passed (found by a reviewer on an RTX 5070, and reproduced here: only the compute Wait removed differed in 4, 4 and 0 of 59 frames).
    • The runner refuses a lighter or unchecked run: the guest's default --ref-every set to 0 (0 lattice checks) and --draws 4000 (5,505 draws a frame) each print the guest's PASS line, and the runner fails them (the PASS line is not stage 25's line with numbers that fit), exit 1.
  • The hash in the PASS line is the frame on the GPU that ran it, not a constant: blended and resolved pixels may differ between vendors within what the reference allows (an RX 6700 XT gave a8371b071d4b392c). What must hold is that every frame matches that run's frame 1, and frame 1 the CPU reference.
  • --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.
  • The earlier stages on this branch pass with their own lines (stage 3: 97675 and 97664 of 98304 pixels exact ... points moved 14839 pixels; stage 5: fp16 scene 97664 of 97664 ...; stage 6: 98144 of 98144 ...; stage 8: 95699 of 95699 ...; stage 9: 75462 of 75462 single-colour pixels exact ...; stage 10: 97438 of 97438 certain pixels exact ...; stage 11: 97452 of 97452 single-colour pixels exact ...; stage 20: POINT 32 of 32 probes exact ...; stage 22: byte IDs 196608 of 196608 pixels exact ...; stage 23: 96750 of 96750 single-colour pixels exact ...; stage 24: 768 of 768 positions exact ...).
  • 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 machine 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 copy and compute queues' Wait(direct, f - 2) cannot be falsified here: the CPU already waits for that frame before it records frame f.
  • The cameras' root CBVs are read from an UPLOAD heap, as titles commonly do.
  • Frame timings are printed, not gated.

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).
- lanterns_bc.h makes two patterns from integer formulas (a 256x256 mosaic,
  64x64 nested squares), box-filters them down to 1x1 and compresses them
  with its own encoders: BC1 four-colour, and BC7 mode 6. It decodes them
  back for the reference.
- The textures go up the D3D12 way: GetCopyableFootprints, an upload
  buffer, one CopyTextureRegion per level (lanterns_textures_gpu.cpp). No
  tiled layout is written or assumed.
- ps_lanterns_tex_floor samples the mosaic with image_sample (trilinear,
  implicit LOD). ps_lanterns_tex_solid samples the squares with
  image_sample_l at the mip level in each draw's tint.a. The root signature
  gains an SRV table and a sampler table (s[22:23], s[24:25]).
- lanterns_sampling.h bounds every pixel: the exact bilinear sample +-4/255
  on the solids; on the floor the trilinear sample over the whole LOD range
  Vulkan allows, +-4/255. lanterns_reference.h's rasterizer is split into
  fragments() and a shading function; stages 1 and 3 keep their shading.
- Control: the solids two mips down must leave the main bounds wherever the
  two references cannot overlap (10221 of 10221 pixels).
- A depth-only pass (vs_lanterns, no pixel shader, no render target,
  DepthBias 1000 and SlopeScaledDepthBias 3 in the PSO) draws the solids
  from a directional light into a 512x512 R32_TYPELESS map: a D32_FLOAT
  DSV, an R32_FLOAT SRV.
- ps_lanterns_shadow moves the world position into light space (three rows
  after the camera matrix in the root CBV). It takes four comparison taps
  half a texel apart with image_sample_c (LESS_EQUAL, point; translated
  since ItsNotRexed#2965) and scales the face colour by 3/8 + 5/32 per lit tap.
- lanterns_shadow.h rasterizes the map on the CPU (fragments() now takes a
  target size). It bounds each texel's stored depth (coverage, tolerance,
  bias anywhere D3D12/Vulkan allow) and each tap's texel (1/64 texel). A
  pixel whose four taps are all certain has one exact colour.
- Checks: 95699 of 95699 single-colour pixels exact, 98144 of 98144 certain
  pixels within bounds, each pixel within one surface's own bounds. Control:
  the map left cleared to 1 changes exactly the predicted 9539 pixels.
…cess

- The stage-3 scene (the points after two rounds of compute steps, drawn
  with the direct DrawIndexedInstanced calls of stage 3) is drawn into an
  R16G16B16A16_FLOAT target. A Post object then records on the same queue:
  - cs_lanterns_bloom_h and cs_lanterns_bloom_v: wave64, 128 lanes in two
    waves sharing LDS (ds_write_b128 / ds_read_b128 across s_barrier, halos
    under s_and_saveexec_b64). They read the scene through a T#
    (image_load), threshold and quantize it, and run a 9-tap binomial blur
    along rows, then along columns.
  - ps_lanterns_composite (with vs_lanterns_full): reads SV_Position, the
    scene texel and the blur, and writes into an R32G32B32A32_FLOAT target.
- lanterns_post.h is the CPU reference. It works in exact integer steps,
  checked against double. Where the scene is uncertain it carries per-pixel
  bounds through the monotone blur.
- Checks: the points equal the CPU's after 48 steps; the fp16 scene is
  exact; the final frame is exact on certain pixels and inside the bounds
  elsewhere. Control: with the blur skipped, exactly the predicted pixels
  change. The row pass without s_barrier is measured and reported.
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.
KubickNubick ran the stack on an RTX 4080 and an AMD Radeon RDNA2 iGPU
under Windows and found that the row pass without its s_barrier changed
0 certain pixels on both: the stage could not catch a missing barrier.

Two reasons, both fixed in cs_lanterns_bloom_h:
- Each lane summed mostly samples its own wave had loaded. Now lane i
  loads sample (i + 64) mod 128 of the segment and the halos come from
  the other half too, so every sample a lane sums was written by another
  wave. The second half also walks four dependent fetches (each adding 0)
  before its write, so that write lands late.
- As a wave64 program translated with --wave64-emulate, the pass ran in
  rounds that already put every LDS write before a later LDS read, so
  the barrier could not matter. The row pass is now wave32 (four waves),
  where s_barrier is the workgroup barrier and nothing else orders them.

RTX 5080: stage 5 passes with the same line; the measured no-barrier
variant now changes 8,449 to 14,849 certain pixels (five runs, was 0),
and the row pass with its s_barrier deleted fails the stage in 3 of 3
runs. The column pass stays wave64.
… LDS

- G-buffer pass with three render targets in one RTV range: RGBA8_UNORM
  albedo, R10G10B10A2_UNORM normal and R32_FLOAT view depth.
  vs_lanterns_gbuf exports the face normal packed into the vertex's shade
  word as an exact integer float; ps_lanterns_gbuf unpacks it with v_bfe.
  The wave64 pair of stage 1 is not used in this pass.
- cs_lanterns_tiled: one 256-lane workgroup (8 wave32 waves) per 16x16
  tile. It rebuilds each pixel's world position from the depth, forms the
  tile's box with ds_min_i32/ds_max_i32 on order-preserving float keys,
  lists the lights whose sphere meets the box (ds_add_rtn_u32 slots) and
  shades with 256 point lights in integers, in a scalar loop over the list.
- lanterns_deferred.h: the lights, the root constants and the CPU
  reference. Light terms are intervals from the depth's snapping slack.
- Checks: albedo exact, G-buffer probes within bounds, single-colour pixels
  exact, each tile's list the exact light set, output and lists start
  poisoned and culling off gives the same image bit for bit. Control: one
  light moved changes exactly the predicted pixels.
- run_lanterns.py: stage 9's PASS pattern (decimal counts allowed) and its
  pictures.
- Gpu gains a sample count and a sample mask: the frame is drawn into a 4x
  R32G32B32A32_FLOAT target at the standard sample positions and resolved
  into the single-sample target with ResolveSubresource.
- The reference rasterizes each sample's frame (coverage and depth at the
  sample, shading at the pixel centre, as a pixel shader run once per pixel
  interpolates). lanterns_msaa.h averages them and enumerates, for an
  uncertain pixel, every average its sample candidates can give.
- Checks: certain pixels exact at the standard positions, including the
  edge pixels whose samples blend; uncertain pixels one of their enumerated
  averages; the 1x render differs on exactly the predicted edge pixels and
  nowhere else certain; and four runs with SampleMask 1 << s each match
  sample s's own frame, with pixels only that sample's position explains.
- run_lanterns.py: stage 10's PASS pattern and its pictures.
…ge_bvh_intersect_ray

- RtShadows builds the acceleration structures through the D3D12 API
  (GetRaytracingAccelerationStructurePrebuildInfo and
  BuildRaytracingAccelerationStructure): one BLAS per traced mesh (prisms
  and square columns) and TLASes over their instances: the main one, one
  with an instance's mask at 0, and one where two instances swap BLAS
  references.
- cs_lanterns_rt_shadow traces one shadow ray per pixel of a stage-9
  G-buffer with image_bvh_intersect_ray: a per-lane stack in LDS, TLAS
  boxes with the world ray, instance records read through a raw V# over
  the TLAS (mask, BLAS pointer, world-to-object), BLAS boxes and triangles
  in object space. Each instance's BLAS comes from its record. Every push
  checks the stack; the loop stops at a step cap, and a ray still tracing
  or overflowed is drawn magenta, which no reference allows.
- lanterns_rt.h: the instance transforms and a CPU tracer (Moller-Trumbore
  in double with a barycentric margin and the position slack).
- Checks: every single-colour pixel exact, every certain pixel within
  bounds. Controls: masking one instance and swapping two BLAS references
  each change exactly the predicted pixels; a BVH whose root is its own
  only child stops every traced ray at the cap, and a four-child cycle
  stops every one as overflowed; background lanes report 0 steps; output
  and step buffers start poisoned.
- run_lanterns.py: stage 11's PASS pattern and its pictures.
The console's compiler turns a root signature's static samplers into
literal S#s (four s_mov_b32 immediates, then image_sample), which no heap
slot or root argument names; the layer registers the words it finds in the
shader at pipeline creation.

- cs_lanterns_samplers (wave32, one probe per lane) builds three: POINT,
  LINEAR and a LESS_EQUAL comparison, all clamping, MIP_FILTER point and
  MIP_POINT_PRECLAMP set as the title's literals have them. The root
  signature declares the same three as static samplers.
- It samples a 4x4 R32_FLOAT colour texture through POINT and LINEAR, and
  a 4x4 depth texture (R32_TYPELESS, cleared per quadrant with rectangle
  clears, R32_FLOAT view) through the comparison and through POINT.
- lanterns_samplers.h: the probes sit 1/4 or 3/4 of a texel from the
  edges, so every expected value is exact. Every sample must match
  bit for bit; LINEAR must differ from POINT where predicted; the
  comparison gives 0 and 1, the plain sample the depth; the output starts
  poisoned.
- run_lanterns.py: stage 20's PASS pattern and its probe card.
Every earlier Lanterns compute shader had a 1-D local size, while the
title's compute shaders enable both local IDs and read local Y in v1.

- cs_lanterns_xy: a 16x8 local size (four wave32 waves, TIDIG_COMP_CNT 1)
  on a 2x3 grid. Each lane writes gx + 1000 gy to LDS at its (X, Y),
  meets the group at s_barrier, reads the entry of its point mirror in
  the group (written by another wave), and stores both words.
- lanterns_xy.h: both words for every grid position. All 768 positions
  must hold exactly their two words; the output starts poisoned.
- run_lanterns.py: stage 24's PASS pattern and its grid picture.
…ports

The title's deferred pixel shaders write five or six targets with every
colour export packed as half floats, and a lighting pass reads them back.

- ps_lanterns_gbuf6 (fullscreen) writes six targets from the pixel's
  integer position, all through v_cvt_pkrtz_f16_f32 and exp ... compr:
  RGBA8 byte IDs, RGB10A2 codes, RG16F signed motion, sRGB albedo,
  RGBA16F emissive and more RGBA8 IDs. It runs with 6 targets bound and
  with a 5-target pipeline.
- cs_lanterns_gbuf_decode reads the targets back through T#s and decodes
  them: IDs by x255 and truncation, codes by rounding, and a lighting
  term from the decoded values.
- lanterns_gbuf6.h: every target's bytes and the decode's output, from
  the f16 values rounded toward zero. IDs, codes, motion, emissive and
  lighting must be exact, the sRGB albedo within one code, and the sixth
  target must stay clear with 5 bound. The IDs survive only in RGBA8: a
  binary16 target loses one in 254 of 256 under the truncating decode.
- run_lanterns.py: stage 22's PASS pattern and the albedo picture.
…et tolerance

From a review of stages 9 to 11:

- The lookup control pipelines (the guest's own vs_lanterns container,
  and the one with a name byte changed) reused the last draw pipeline's
  description. In stage 9 that pairs vs_lanterns with the G-buffer PS,
  which reads an attribute vs_lanterns does not export: not a valid
  pipeline, accepted only because the layer does not check the link.
  Both control pipelines now take stage 1's pairing (ps_lanterns_lit,
  one target) in every stage.
- The lights were read through a V# straight from an UPLOAD heap, which
  is outside what the layer maps for the guest. They now live in a
  DEFAULT buffer, copied from an UPLOAD one before each pass.
- Only stage 1 was a ctest. Stages 3, 5, 6, 8 and 9 are now too, and the
  docs say how to run any stage.
- "The exact set" of lights per tile skipped light-tile pairs within 2e-3
  of the box test without saying how many. The PASS line now gives that
  count, more than 32 fails, and the docs state the tolerance.
# Conflicts:
#	runtime/test/lanterns/run_lanterns.py
…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).
…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_bloom_h.asm, cs_lanterns_bloom_h_nobarrier.asm, cs_lanterns_bloom_v.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).
…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_tiled.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).
… 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_rt_shadow.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).
… 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_samplers.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).
… 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_xy.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).
… 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_gbuf_decode.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).
… 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_rt_alpha.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).
@TheAirborneCoder

Copy link
Copy Markdown
Contributor

Tested 3b07716 on AMD Radeon Graphics iGPU (gfx1036, RDNA2, Ryzen 9 9950X3D), Windows AMD driver 32.0.21042.62, Windows 11, MSVC RelWithDebInfo, LEONIDA_VK_DEVICE=radeon (each run's log: Vulkan device: AMD Radeon(TM) Graphics), -DLEONIDA_TEST_LANTERNS=ON: FAIL.

  • ctest -R ^lanterns_stage: 2/13 pass (stages 1 and 10). Stage 25: frame 1 has 7,771,372 of 8,194,322 certain pixels exact, the particle sets differ, and later frames differ from frame 1. Stage 24: 0 of 768 words written (all still the 0xdeadbeef fill).
  • scripts/run_gpu_tests.py --require-pass: 214/232 pass, 17 skip, 1 fail (ms_wave_info_s3).
  • Other ctest: 242/247; the 4 failures (d3d12_indirect_dispatch_count, d3d12_m2_textured, d3d12_m2_formats, d3d12_m3_frame) fail identically on main 561b65a on this iGPU.

Caveat: main already fails D3D12-layer graphics tests on this iGPU and driver, and Lanterns has no baseline on main, so this may be the driver rather than the PR. A recheck of this head on the RX 6700 XT that passed 8199b73 would separate the two. Since this head includes #5117, #5099 and #5098, the same applies to them; I did not test those separately. AI-assisted (Claude Code).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @TheAirborneCoder. 3b07716a is the head from before the D3D-448 adaptation. After today's merge of main, #4312 changed the compute root-argument layout (tables from s4, one dword each). Lanterns' hand-written compute shaders still read the old layout, so the compute stages failed. You saw exactly that: stage 24 wrote 0 of 768 words, and stage 25's particle compute differed. The current head is 163ea5cb. In it the Lanterns compute shaders follow D3D-448, and under Wine on an RTX 5080 stages 1, 3, 5, 9, 11, 20, 22, 23, 24 and 25 pass. Could you rerun ctest -R ^lanterns_stage on 163ea5cb? Separately, d3d12_m2_textured, d3d12_m2_formats and d3d12_m3_frame failing on main on your iGPU matches SHADER-1016, the #4225 regression on AMD, which I'm looking into. AI-assisted.

@nullmarsh

Copy link
Copy Markdown

Tested 163ea5cb (base 561b65a8, so it includes the D3D-448 / #4312 adaptation) natively on Windows 11 26200 with an AMD Radeon RX 9060 XT (RDNA4, AMD 26.11.2 / 32.0.32029.2010, subgroups 32..64), MSVC 14.44 RelWithDebInfo, -DLEONIDA_TEST_LANTERNS=ON, llvm-mc 23.1.6: pass.

  • ctest -R lanterns_stage: 13/13 passed (stages 1, 3, 5, 6, 8, 9, 10, 11, 20, 22, 23, 24, 25).
  • The same 13/13 with LEONIDA_VK_VALIDATION=1.
  • Stage 25: PASS, 60 frames at 3840x2160 identical to the first (hash 1a27af63eb48dba8), 6880 draws and 88 dispatches per frame on 3 queues, frame 1 exact against the CPU reference at every certain pixel, 3 lattice checks exact. It takes 18 s, or 40 s under validation.

As far as I can see, this is the first discrete-AMD and first RDNA4 run of the stack since the rebase. Since this tip contains the whole chain (#4820, #4863 … #5117), the result covers those heads too, as far as their stages go.

Synthetic guest only, no game files. AI-assisted (Claude Code).

@lunarminus

Copy link
Copy Markdown

Tested 163ea5cb merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass for what runs here. The Lanterns stages themselves were not run (see the last bullet).

  • Merge: the merge was a fast-forward. d0835dd9 is already in the branch, and its merge-base with main is now 561b65a8. So the tree tested is the PR head, including main up to 561b65a8. Against 561b65a8, the PR's diff is 78 files: Lanterns, docs, tests and CI, plus the opt-in include(test/lanterns/lanterns.cmake) in runtime/CMakeLists.txt.
  • Build: runtime/ on Linux, RelWithDebInfo, default options (LEONIDA_TEST_LANTERNS off). It built with no warnings or errors in the log.
  • The PR's own tests:
    • pytest -W error over test_fssm_pack_chain, test_fssm_pack and test_run_lanterns: 21 passed (llvm-mc 23.1.5 with AMDGPU).
    • Standalone python -I -W error: test_run_lanterns 5 OK and test_fssm_pack 10 OK.
    • test_runtime_paths, test_ci_registration, test_docs_links, test_docs_repo_paths, test_docs_list_items, test_docs_table_rows, test_text_encoding and test_text_write_line_endings all OK; compileall clean.
  • Lanterns shaders, CPU only: I ran fssm_pack.py --translate --wave64-emulate over all 25 shaders/*.asm, as lanterns.cmake does, with the D3D-448 compute changes. All 25 translated, and spirv-val --target-env vulkan1.3 passed 25 of 25. No GPU was involved in this step.
  • scripts/run_gpu_tests.py:
    • LEONIDA_W64_EMULATE unset: 216/232 passed, 16 skipped, 0 failed.
    • LEONIDA_W64_EMULATE=1: 216/232 passed, 16 skipped, 0 failed, with the same result per test as the run without it.
    • rdna2spirv: 238 of 238 translated, all spirv-val-valid.
  • Per-test comparison with d0835dd9 without the PR (196/210 passed, 14 skipped in both modes): all 210 baseline tests have the same result on the PR head, in both modes. The 22 extra tests are fixtures that main added between d0835dd9 and 561b65a8, not this PR:
    • 20 of them PASS.
    • ps_live_width is SKIP ("run by w64_graphics.py").
    • ps_m2_literal is SKIP ("run by d3d12_m2_textured_test").
  • Not run here: ctest -R ^lanterns_stage / run_lanterns.py, the rerun on 163ea5cb asked for above. lanterns.exe and d3d12_xs_stub are only built with gta6rt, in the Windows (MSVC/clang-cl) part of runtime/CMakeLists.txt, and this machine has no xwin/Windows SDK sysroot. So this report is no evidence about stage 25 on AMD / 32-wide hardware.

AI-assisted (Claude Code).

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit 163ea5cb)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

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.

9 participants