WIP: build(asm): hand-written x86-64 kernels have a common header, a check kit and the build's jobs, and the GPU-visible ranges' sort is the first #1947

Draft
siantm wants to merge 17 commits from siantm/Longshot:build/asm-kit into main
Contributor

Summary

Longshot has no hand-written assembly yet: every hot loop is C or C++ with intrinsics. A few loops of the capture, the
texture uploads, the hashes and the write marks run faster written by hand for x86-64 (the follow-up pull requests,
one per kernel, each with its own check and numbers). Each of them needs the same ground, so it comes first, with
the first kernel on it, so that the ground is exercised by a caller the game runs:

  • gpu/asm/lsasm.h: a kernel is written once, in Intel syntax against the System V registers (arguments in rdi,
    rsi, rdx, rcx, r8, r9). Its macros (LSASM_FUNC, LSASM_ARGS, LSASM_PUSH, LSASM_SAVE_XMM, LSASM_ALLOC,
    LSASM_RET ...) make the Win64 convention around it on Windows, with the SEH unwind data Windows needs to unwind a
    fault inside a kernel (a capture copy's guarded_copy in gpu/vk/vk_memory.cpp catches one) and to walk a stack
    stopped in one (the samplers' walk in host/mkw_glue.c), and the DWARF CFI on Linux. The epilogue is laid out as
    Windows' unwinder recognises one (the vzeroupper and the frees before the pops), so a thread stopped in it unwinds
    to its caller too. The body runs with rsp 16-byte aligned (the macros count the pushes and pad where needed, in the
    unwind data too); a frame over 4096 bytes stops the assembly, as the macros probe no stack page; LSASM_ARGS takes
    the kernel's count of integer or pointer arguments and reads only the stack slots a caller passed. In C and C++ it
    gives LSASM_ABI for the declarations.
  • tests/asm_kit.py: what every kernel's check shares. It builds the check's fixture (the C the kernel stands
    for, as the reference) with the kernels at SSE2 and at AVX2 (where this CPU has it), on Windows also the System V
    body (what Linux runs) called through sysv_abi, so a Linux-only register mix-up fails on Windows too; and it
    assembles every kernel with clang for ELF and for COFF (the clang given, beside the compiler, or on PATH; none fails
    the check). Its AVX2 run is gated on the whole x86-64-v3 level and the OS's ymm state, and each kernel is its own
    object even when two folders hold the same name.
  • tests/test_asm_abi.py with tests/asm_abi_probe.S: probes that use every part of a frame and clobber every
    register they may. Six arguments arrive; a one-argument call on a stack that ends at its home area reads no other
    slot; every callee-saved register comes back; the body's rsp is 16-byte aligned; a table in LSASM_RODATA is read.
    On Windows a fault inside a probe unwinds to its caller with the registers restored, by hand and through Windows'
    own dispatch to a caller's __except, and every single step of each probe (the trap flag) is unwound by Windows'
    own unwinder to its caller with the whole nonvolatile state, the epilogue's steps included. On Linux a probe stopped
    in its body is unwound through its DWARF CFI by the system's unwinder.
  • The build (plan_modules and asm_jobs in nx2/build.py): every .S in host/asm goes into the game, in
    gpu/vk/asm into the renderer, in gpu/asm into both (an object each), preprocessed with the build's CPU flags
    (which pick each kernel's AVX2 or SSE2 body) and keyed, like the host's and the renderer's own files, by the headers
    its depfile says it read (every header of its folder and gpu/asm before it has one). A shared kernel's second
    job leaves the cache entry the first published, and a kernel compiled again is written to a new file (compile_one
    removes the object first: clang's assembler writes in place, and the object is a hard link into the cache); gpu/asm's headers key the renderer's own files. No folder, no
    job. The AppImage carries gpu/asm; dev.py pack takes a
    .S as a source of its module, a host/asm one building the game alone (scripts/devtools/packs.py), and the
    sources' fingerprint (nx2/version.py) counts it.
  • The first kernel, lsasm_sort_ranges (host/asm/ranges.S, 588159c4): hos_gpu_guest_ranges
    (host/nvdrv.c) sorts every GPU mapping's and native NVN pool's guest range by start before it merges them, each
    time the mappings change (at boot, at area loads, when pools come and go). It sorted with qsort and a comparison
    call per compare; on x86-64 it now sorts with a merge sort written on lsasm.h (runs of 16 pairs by insertion, then
    merges of runs twice as long, two runs already in order copied, not merged; one body for both CPU levels). Other
    CPUs keep qsort with cmp_range (#if defined(__x86_64__)). The sort is stable where qsort is not; the merge
    after it makes the same ranges from any order of ranges that start together, so the result is the same. Both
    lists now grow through hos_xrealloc (where realloc's NULL was used as the list before).
    scripts/profiling/cpu_functions.json names the kernel. No switch: the ranges are the same.

Read first: gpu/asm/lsasm.h, tests/asm_kit.py, plan_modules and asm_jobs in nx2/build.py, then
host/asm/ranges.S and hos_gpu_guest_ranges in host/nvdrv.c.

Testing

Tested: Windows 11, i7-9700, llvm-mingw clang 23.1.5. Every check ran through the PC's job queue. Head db3d91f1,
rebased onto main 7c23d2be. It has NOT run in the game on this PC at this head: the only game run was on df88c325,
before the review's fixes and without a kernel (below).

  • All checks below ran in one build job of the queue (fb3-1947-1), on 3bf51a69, these same commits on main e6196f0f (rebased since onto 7c23d2be with no conflict, git range-diff all =):
    • tests/test_asm_end_to_end.py --cxx clang++ (5 tests, pass). It writes one kernel of both modules (gpu/asm) and
      one kernel of each module alone (host/asm, gpu/vk/asm) in a tree of its own, on the real lsasm.h. It runs the
      build's own code on them with clang: plan_modules, plan_jobs, compile_one on four threads, rekey_depfiles, and
      main()'s link-list statements. It links and runs each module's link list with a caller. It covers:

      • a cold build, then a rebuild that compiles nothing, then a new work folder made from the first's cache;
      • an include renamed while its kernel still names it: the kernel compiles and fails, as a clean build would. With the
        new name it compiles again, alone;
      • an include edited and then reverted: the revert compiles nothing and links the cold build's objects;
      • three developer packs on one base, through scripts/devtools/packs.py's decisions as cmd_pack makes them: the
        game alone, the renderer alone, then both. The base's objects stay as they were;
      • the AppImage's source-copy block run with bash, then a cold build of the staged tree.

      At its test commit 1fefe953 (b21224ff now) it failed 4 checks: a reverted edit linked the edited kernel, and a pack rewrote the
      base's objects. These pass with the fix, db3d91f1 (Summary, the build).

    • The PR's own checks pass: tests/test_asm_abi.py --cxx clang++ (both levels, both conventions, the clang
      assemblies, the frame bound), tests/test_asm_build.py (15), tests/test_asm_kit.py, tests/test_asm_ranges.py --cxx clang++ (SSE2 and AVX2, both conventions), tests/test_appimage_source_headers.py (3) and
      tests/test_appimage_headers.py.

    • tests/run_all.py --strict --changed origin/main ran every check, because a shared test file changed. RX_CPM was
      set, so the renderer checks compiled against the Vulkan headers. 866 checks: 786 passed, 80 failed, 48 skipped; no check stopped for want of the Vulkan headers. 78 of the 80 fail on main e6196f0f too, rerun by name there with RX_CPM set. Run again by name at db3d91f1 (fb3-1947-2), the same 79 fail and tests/test_present_semaphores.py passes; it failed in the run above (no output, 10.9 s, 8 at once) and passes alone at db3d91f1 and on main 7c23d2be. tests/test_vbytes.py times out (600 s) here and on main alike, alone too (db3d91f1, main 7c23d2be).

    • Four checks timed out under load in the whole-suite run on 8f5c08c6: tests/test_host_alloc_wait.py,
      test_mesh_args_cleanup.py, test_oot_wide_bubble.py and test_oot_wide_save_picture.py. Each passes when run
      alone, at 3bf51a69 and on main e6196f0f.

  • Earlier, on 4cf7de04 (main 6e1521a7): tests/test_dev_packs.py was run one check at a time, because its script stops
    at the first failing check; the kernel routing passed. The earlier --changed figures are replaced by the run above:
    those runs had no Vulkan headers, so their renderer checks did not run.
  • In the game, earlier (df88c325, before the fixes): built as a pack over main's base (dev.py packs, 56 s), started in
    Kokiri Forest from the scene's save, 60 s standing and turning. It played (41 to 52 fps lines), did not crash, and
    stopped cleanly.

Still to test:

  • Linux (any GPU): python3 -I -B tests/test_asm_abi.py --cxx g++ and --cxx clang++, expecting PASS at both levels
    (the System V body natively, the ELF unwind from a probe's body) and the clang assemblies (by hand: the Test Farm
    plays the game and times builds, it runs no test file)
  • Linux (any GPU): python3 -I -B tests/test_asm_ranges.py with gcc and with clang, expecting PASS (the kernel's
    System V body natively against qsort) (by hand)
  • Clean build time and output size of this head against main 7c23d2be on the same PC, and the update rebuild cost (by hand)
  • The real build of this head with lsasm_sort_ranges: a clean build against main (its time and output size), this head built
    as an update over main's stores, and a rebuild after renaming gpu/asm/lsasm.h; a real dev.py packs pack of a kernel
    change; a Linux AppImage build. tests/test_asm_end_to_end.py runs the build's code on authored kernels, not these
    (by hand: the build pair is queued on this PC)
  • Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest from the scene's save, then a load into Hyrule Field and back,
    main 7c23d2be against this head, warmed, interleaved, expecting the same play (no crash, no stale or flickering
    texture, the same frame times within their spread) (by hand)
  • Linux with NVIDIA and with AMD, Windows with AMD and with Intel, the Steam Deck: the game built from this PR and from
    main on the same PC, started in Kokiri Forest for a minute, expecting it to play as on main (no crash, no hang,
    frame time and VRAM as on main); the build timed against main's, expecting the lifted C to be the same (the Test
    Farm, requested in a comment)

Measurements

Verdict: not measured: no micro-benchmark of the ported kernel and no run in the game on this PC at this head. On
the branch it comes from (971f8074, exp/x86-asm-sync) a micro-benchmark on this PC found the kernel faster than
qsort, more so in near order; the sort runs only when the mappings change, so a frame-time difference in play is not
expected to show. The build's one cost, the runtime's C files compiled again once after updating (their key counts
the headers under gpu/, and gpu/asm/lsasm.h is a new one: 80 files, 26 s of compiling in the pack of df88c325), is
in Risks; the clean build's time and size against main are in Still to test.

Risks

The game now runs a hand-written kernel on x86-64: a wrong sort would merge the GPU-visible ranges wrongly, and the
renderer would miss or over-track guest writes in GPU memory (stale or flickering textures, more CPU in change
tracking) from boot on; a fault in it is unwound as any kernel's (lsasm.h). The test compares it with qsort on
every size around its runs and merges. Other CPUs keep qsort. The build's flags are as before; the runtime's C
files compile once more after updating (Measurements). A revert of 588159c4 gives back qsort; no switch.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. Not yet at this head: the game run was on df88c325 (Testing).
  • mise run test passes (any failure that also fails on main is named). Not yet: 79 checks fail here and on main alike (Testing).
  • Measured against main, or Measurements says why there is nothing to measure. Not yet: the kernel is not measured (Measurements).
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • Docs updated.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows only so far: the Linux build is in Still to test.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary Longshot has no hand-written assembly yet: every hot loop is C or C++ with intrinsics. A few loops of the capture, the texture uploads, the hashes and the write marks run faster written by hand for x86-64 (the follow-up pull requests, one per kernel, each with its own check and numbers). Each of them needs the same ground, so it comes first, with the first kernel on it, so that the ground is exercised by a caller the game runs: - **`gpu/asm/lsasm.h`**: a kernel is written once, in Intel syntax against the System V registers (arguments in rdi, rsi, rdx, rcx, r8, r9). Its macros (`LSASM_FUNC`, `LSASM_ARGS`, `LSASM_PUSH`, `LSASM_SAVE_XMM`, `LSASM_ALLOC`, `LSASM_RET` ...) make the Win64 convention around it on Windows, with the SEH unwind data Windows needs to unwind a fault inside a kernel (a capture copy's `guarded_copy` in `gpu/vk/vk_memory.cpp` catches one) and to walk a stack stopped in one (the samplers' walk in `host/mkw_glue.c`), and the DWARF CFI on Linux. The epilogue is laid out as Windows' unwinder recognises one (the `vzeroupper` and the frees before the pops), so a thread stopped in it unwinds to its caller too. The body runs with rsp 16-byte aligned (the macros count the pushes and pad where needed, in the unwind data too); a frame over 4096 bytes stops the assembly, as the macros probe no stack page; `LSASM_ARGS` takes the kernel's count of integer or pointer arguments and reads only the stack slots a caller passed. In C and C++ it gives `LSASM_ABI` for the declarations. - **`tests/asm_kit.py`**: what every kernel's check shares. It builds the check's fixture (the C the kernel stands for, as the reference) with the kernels at SSE2 and at AVX2 (where this CPU has it), on Windows also the System V body (what Linux runs) called through `sysv_abi`, so a Linux-only register mix-up fails on Windows too; and it assembles every kernel with clang for ELF and for COFF (the clang given, beside the compiler, or on PATH; none fails the check). Its AVX2 run is gated on the whole x86-64-v3 level and the OS's ymm state, and each kernel is its own object even when two folders hold the same name. - **`tests/test_asm_abi.py`** with `tests/asm_abi_probe.S`: probes that use every part of a frame and clobber every register they may. Six arguments arrive; a one-argument call on a stack that ends at its home area reads no other slot; every callee-saved register comes back; the body's rsp is 16-byte aligned; a table in `LSASM_RODATA` is read. On Windows a fault inside a probe unwinds to its caller with the registers restored, by hand and through Windows' own dispatch to a caller's `__except`, and every single step of each probe (the trap flag) is unwound by Windows' own unwinder to its caller with the whole nonvolatile state, the epilogue's steps included. On Linux a probe stopped in its body is unwound through its DWARF CFI by the system's unwinder. - **The build** (`plan_modules` and `asm_jobs` in `nx2/build.py`): every `.S` in `host/asm` goes into the game, in `gpu/vk/asm` into the renderer, in `gpu/asm` into both (an object each), preprocessed with the build's CPU flags (which pick each kernel's AVX2 or SSE2 body) and keyed, like the host's and the renderer's own files, by the headers its depfile says it read (every header of its folder and `gpu/asm` before it has one). A shared kernel's second job leaves the cache entry the first published, and a kernel compiled again is written to a new file (`compile_one` removes the object first: clang's assembler writes in place, and the object is a hard link into the cache); `gpu/asm`'s headers key the renderer's own files. No folder, no job. The AppImage carries `gpu/asm`; `dev.py pack` takes a `.S` as a source of its module, a `host/asm` one building the game alone (`scripts/devtools/packs.py`), and the sources' fingerprint (`nx2/version.py`) counts it. - **The first kernel, `lsasm_sort_ranges`** (`host/asm/ranges.S`, 588159c4): `hos_gpu_guest_ranges` (`host/nvdrv.c`) sorts every GPU mapping's and native NVN pool's guest range by start before it merges them, each time the mappings change (at boot, at area loads, when pools come and go). It sorted with `qsort` and a comparison call per compare; on x86-64 it now sorts with a merge sort written on `lsasm.h` (runs of 16 pairs by insertion, then merges of runs twice as long, two runs already in order copied, not merged; one body for both CPU levels). Other CPUs keep `qsort` with `cmp_range` (`#if defined(__x86_64__)`). The sort is stable where `qsort` is not; the merge after it makes the same ranges from any order of ranges that start together, so the result is the same. Both lists now grow through `hos_xrealloc` (where `realloc`'s NULL was used as the list before). `scripts/profiling/cpu_functions.json` names the kernel. No switch: the ranges are the same. Read first: `gpu/asm/lsasm.h`, `tests/asm_kit.py`, `plan_modules` and `asm_jobs` in `nx2/build.py`, then `host/asm/ranges.S` and `hos_gpu_guest_ranges` in `host/nvdrv.c`. ## Testing **Tested:** Windows 11, i7-9700, llvm-mingw clang 23.1.5. Every check ran through the PC's job queue. Head db3d91f1, rebased onto main 7c23d2be. **It has NOT run in the game on this PC at this head**: the only game run was on df88c325, before the review's fixes and without a kernel (below). - All checks below ran in one build job of the queue (fb3-1947-1), on 3bf51a69, these same commits on main e6196f0f (rebased since onto 7c23d2be with no conflict, `git range-diff` all `=`): - `tests/test_asm_end_to_end.py --cxx clang++` (5 tests, pass). It writes one kernel of both modules (`gpu/asm`) and one kernel of each module alone (`host/asm`, `gpu/vk/asm`) in a tree of its own, on the real `lsasm.h`. It runs the build's own code on them with clang: `plan_modules`, `plan_jobs`, `compile_one` on four threads, `rekey_depfiles`, and `main()`'s link-list statements. It links and runs each module's link list with a caller. It covers: - a cold build, then a rebuild that compiles nothing, then a new work folder made from the first's cache; - an include renamed while its kernel still names it: the kernel compiles and fails, as a clean build would. With the new name it compiles again, alone; - an include edited and then reverted: the revert compiles nothing and links the cold build's objects; - three developer packs on one base, through `scripts/devtools/packs.py`'s decisions as `cmd_pack` makes them: the game alone, the renderer alone, then both. The base's objects stay as they were; - the AppImage's source-copy block run with bash, then a cold build of the staged tree. At its test commit 1fefe953 (b21224ff now) it failed 4 checks: a reverted edit linked the edited kernel, and a pack rewrote the base's objects. These pass with the fix, db3d91f1 (Summary, the build). - The PR's own checks pass: `tests/test_asm_abi.py --cxx clang++` (both levels, both conventions, the clang assemblies, the frame bound), `tests/test_asm_build.py` (15), `tests/test_asm_kit.py`, `tests/test_asm_ranges.py --cxx clang++` (SSE2 and AVX2, both conventions), `tests/test_appimage_source_headers.py` (3) and `tests/test_appimage_headers.py`. - `tests/run_all.py --strict --changed origin/main` ran every check, because a shared test file changed. `RX_CPM` was set, so the renderer checks compiled against the Vulkan headers. 866 checks: 786 passed, 80 failed, 48 skipped; no check stopped for want of the Vulkan headers. 78 of the 80 fail on main e6196f0f too, rerun by name there with `RX_CPM` set. Run again by name at db3d91f1 (fb3-1947-2), the same 79 fail and `tests/test_present_semaphores.py` passes; it failed in the run above (no output, 10.9 s, 8 at once) and passes alone at db3d91f1 and on main 7c23d2be. `tests/test_vbytes.py` times out (600 s) here and on main alike, alone too (db3d91f1, main 7c23d2be). - Four checks timed out under load in the whole-suite run on 8f5c08c6: `tests/test_host_alloc_wait.py`, `test_mesh_args_cleanup.py`, `test_oot_wide_bubble.py` and `test_oot_wide_save_picture.py`. Each passes when run alone, at 3bf51a69 and on main e6196f0f. - Earlier, on 4cf7de04 (main 6e1521a7): `tests/test_dev_packs.py` was run one check at a time, because its script stops at the first failing check; the kernel routing passed. The earlier `--changed` figures are replaced by the run above: those runs had no Vulkan headers, so their renderer checks did not run. - In the game, earlier (df88c325, before the fixes): built as a pack over main's base (`dev.py packs`, 56 s), started in Kokiri Forest from the scene's save, 60 s standing and turning. It played (41 to 52 fps lines), did not crash, and stopped cleanly. **Still to test:** - Linux (any GPU): `python3 -I -B tests/test_asm_abi.py --cxx g++` and `--cxx clang++`, expecting PASS at both levels (the System V body natively, the ELF unwind from a probe's body) and the clang assemblies (by hand: the Test Farm plays the game and times builds, it runs no test file) - Linux (any GPU): `python3 -I -B tests/test_asm_ranges.py` with gcc and with clang, expecting PASS (the kernel's System V body natively against `qsort`) (by hand) - Clean build time and output size of this head against main 7c23d2be on the same PC, and the update rebuild cost (by hand) - The real build of this head with `lsasm_sort_ranges`: a clean build against main (its time and output size), this head built as an update over main's stores, and a rebuild after renaming `gpu/asm/lsasm.h`; a real `dev.py packs` pack of a kernel change; a Linux AppImage build. `tests/test_asm_end_to_end.py` runs the build's code on authored kernels, not these (by hand: the build pair is queued on this PC) - Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest from the scene's save, then a load into Hyrule Field and back, main 7c23d2be against this head, warmed, interleaved, expecting the same play (no crash, no stale or flickering texture, the same frame times within their spread) (by hand) - Linux with NVIDIA and with AMD, Windows with AMD and with Intel, the Steam Deck: the game built from this PR and from `main` on the same PC, started in Kokiri Forest for a minute, expecting it to play as on `main` (no crash, no hang, frame time and VRAM as on `main`); the build timed against `main`'s, expecting the lifted C to be the same (the Test Farm, requested in a comment) ## Measurements **Verdict:** not measured: no micro-benchmark of the ported kernel and no run in the game on this PC at this head. On the branch it comes from (971f8074, `exp/x86-asm-sync`) a micro-benchmark on this PC found the kernel faster than `qsort`, more so in near order; the sort runs only when the mappings change, so a frame-time difference in play is not expected to show. The build's one cost, the runtime's C files compiled again once after updating (their key counts the headers under `gpu/`, and `gpu/asm/lsasm.h` is a new one: 80 files, 26 s of compiling in the pack of df88c325), is in Risks; the clean build's time and size against main are in Still to test. ## Risks The game now runs a hand-written kernel on x86-64: a wrong sort would merge the GPU-visible ranges wrongly, and the renderer would miss or over-track guest writes in GPU memory (stale or flickering textures, more CPU in change tracking) from boot on; a fault in it is unwound as any kernel's (`lsasm.h`). The test compares it with `qsort` on every size around its runs and merges. Other CPUs keep `qsort`. The build's flags are as before; the runtime's C files compile once more after updating (Measurements). A revert of 588159c4 gives back `qsort`; no switch. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. Not yet at this head: the game run was on df88c325 (Testing). - [ ] `mise run test` passes (any failure that also fails on `main` is named). Not yet: 79 checks fail here and on main alike (Testing). - [ ] Measured against `main`, or Measurements says why there is nothing to measure. Not yet: the kernel is not measured (Measurements). - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] Docs updated. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows only so far: the Linux build is in Still to test. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
build(asm): hand-written x86-64 kernels have a common header, a check kit, and the build's jobs
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 9s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
10d5d0de15
The ground the hand-written kernels stand on, without any kernel yet:

- gpu/asm/lsasm.h: a kernel is written once, in Intel syntax against the System V registers; the macros make the
  Win64 convention with its SEH unwind data on Windows (an epilogue laid out as Windows' unwinder recognises one:
  the vzeroupper and the frees before the pops) and the DWARF CFI on Linux, and LSASM_ABI for the declarations.
- tests/asm_kit.py: a kernel's check builds its fixture with the kernels at SSE2 and AVX2 (where the CPU has it),
  on Windows also the System V body through sysv_abi, and assembles every kernel with clang for ELF and COFF.
- tests/test_asm_abi.py with tests/asm_abi_probe.S: probes that use every part of the frame: six arguments arrive,
  every callee-saved register comes back, a fault inside one unwinds to the caller (Windows), and every single step
  of each probe is unwound by Windows' own unwinder to its caller.
- nx2/build.py asm_jobs: every .S of host/asm goes into the game, of gpu/vk/asm into the renderer, of gpu/asm into
  both, preprocessed with the build's CPU flags and keyed by the headers beside them and lsasm.h. No folder, no job.
- scripts/devtools/packs.py takes a .S as a source (it shows in its module's objects) and nx2/version.py counts it in
  the sources' fingerprint.
- tests/test_asm_build.py, tests/test_dev_packs.py: the jobs, their keys, the fingerprint and the packs' rules.

Assisted-by: Claude Code
Author
Contributor

Tested in game: Windows 11, RTX 4060 (NVIDIA 610.88), i7-9700: this change (df88c325, the same commit before its rebase) built as a pack over main's base and started in Kokiri Forest from the scene's save, 60 s standing and turning: it played (41-52 fps lines), no crash, clean stop; the version line named the commit. It adds no kernel, so nothing the game runs differs.

Tested in game: Windows 11, RTX 4060 (NVIDIA 610.88), i7-9700: this change (df88c325, the same commit before its rebase) built as a pack over main's base and started in Kokiri Forest from the scene's save, 60 s standing and turning: it played (41-52 fps lines), no crash, clean stop; the version line named the commit. It adds no kernel, so nothing the game runs differs.
Author
Contributor

@Beanstalk This adds the build's jobs for hand-written x86-64 assembly (asm_jobs in nx2/build.py) and a shared header, gpu/asm/lsasm.h, with no kernel yet: no code the game runs should change, and it has not run in the game on Linux, AMD or Intel yet. Please build this PR and main and time the build against main's (a warm build), checking the lifted C is the same, then start the game in Kokiri Forest for a minute on each side. On Linux with NVIDIA, Linux with AMD, Windows with AMD, Windows with Intel, and the Steam Deck. It must not crash or hang, and frame time p99 and peak VRAM must be as on main.

@Beanstalk This adds the build's jobs for hand-written x86-64 assembly (`asm_jobs` in `nx2/build.py`) and a shared header, `gpu/asm/lsasm.h`, with no kernel yet: no code the game runs should change, and it has not run in the game on Linux, AMD or Intel yet. Please build this PR and main and time the build against main's (a warm build), checking the lifted C is the same, then start the game in Kokiri Forest for a minute on each side. On Linux with NVIDIA, Linux with AMD, Windows with AMD, Windows with Intel, and the Steam Deck. It must not crash or hang, and frame time p99 and peak VRAM must be as on main.
Member

@siantm only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for 10d5d0d, and the PR has changed since (4cf7de0), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@siantm only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `10d5d0d`, and the PR has changed since (`4cf7de0`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
BeanBot left a comment

Recommendation: Request changes. The shared assembly layer would reduce duplicated kernels, but it can misalign Win64 frames, reuse stale objects, and break AppImage builds as soon as a kernel is added. The new checks leave key unwind and build paths unverified.

Adds a common x86-64 ABI header, a game-free test kit, and build, pack, and version support for assembly sources. There are no game kernels in this PR. The author reported a one-time rebuild of 80 runtime C files taking 26 seconds in a 56-second Windows pack.

Does it help: Not a perf change. The author reports a passing 9.3-second Windows ABI check and a passing build helper check on df88c325 before rebase. The 60-second Kokiri Forest run at 41–52 fps is a smoke test. Clean build time and size against 8d56b59d and Linux ABI results are missing.
Other systems: Windows and Linux share the job planner and object cache but use different unwind formats. The Linux AppImage stages a narrower source tree than the Windows Builder. Developer packs can choose to rebuild either module, so dependency tracking matters independently of the full build. No kernel enters capture, graphics, audio, input, or save paths in this PR. The only reported game run was Windows on NVIDIA. Linux, Steam Deck, Windows AMD and Intel, and the full suite on this head remain unverified.
Switches: LSASM_TEST_SYSV is a test-only preprocessor define, unset by default. The Windows fixture sets it for its second ABI variant. That default is right for shipping builds. Assembly jobs inherit the existing RX_MARCH choice and its automatic CPU default. No player switch or switch-table change.

Reviewed: 10d5d0de15 against 8d56b59d47: Read all ten changed-file diffs and the full new header, assembly probe, three Python files, build reference, and version module. Read the changed sections and relevant callers in nx2/build.py, packs.py, and test_dev_packs.py. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, and docs/dev/standards.md. There is no docs/review-checklist.md in the checkout. Traced the relevant compile, link, cache, package, CPU detection, sampler, guarded-copy, lint, and test-runner paths. Read the author’s testing report and sole comment. Unrelated sections of the large modules and historical recorded runs were outside the review scope. No generated files, translations, or recorded-run files changed.; nothing run (a code review).
Checked and fine:

  • The commit has the required Assisted-by trailer. The WIP prefix is allowed and the underlying title is a Conventional Commit.
  • The diff contains authored fixtures and no game-derived files, vendor SDKs, generated files, shader changes, or third-party edits.
  • The renderer interface is unchanged, so no MKWVK_API_VERSION bump is needed.
  • The Win64 fifth and sixth stack offsets are correct for six integer or pointer arguments after the two pushes. The Windows epilogue puts XMM restores and vzeroupper ahead of the add, pops, and ret.
  • The build uses the existing long-path wrappers and passes compiler paths as separate arguments. The fingerprint test changes assembly contents and checks the resulting fingerprint.
  • The renderer response file takes the renderer jobs, and the game response file excludes those objects. The per-module prefixes distinguish same-stem private and shared assembly sources in the production job list.

Blocking (to change before merge)

  1. gpu/asm/lsasm.h:22: The Win64 ABI still requires 16-byte stack alignment in the body of a function that makes a frame. The six-argument probe pushes eight registers and subtracts 160, so its body runs with RSP at 8 modulo 16. A kernel following the header can fault on an aligned stack access. Track the pushes and add any needed padding in the prologue, describe it in SEH, and fold its removal into the epilogue adjustment. Check alignment with both odd and even push counts.
  2. gpu/asm/lsasm.h:171: LSASM_ARGS reads both stack argument slots on every call. A one-argument Win64 caller owes only the home area, so these reads can fault if the caller's frame is at the top of a small stack. Give LSASM_ARGS an argument count, load only the supplied fifth and sixth arguments, and state that the mapping supports integer and pointer arguments.
  3. gpu/asm/lsasm.h:86: LSASM_ALLOC accepts arbitrary scratch sizes but subtracts RSP without probing stack pages. A Windows kernel using 8 KiB of scratch can skip the guard page and fault at its first store. Enforce a conservative assembly-time bound on the total frame or implement stack probing with matching unwind data.
  4. nx2/build.py:2134: A shared kernel is queued twice with the same source, flags, dependencies, and cache key. On a cold parallel build both workers can enter cache_put. The loser of the hard-link race falls back to copyfile over the winner's cache entry, which is already linked to an output object. Compile each shared object once for both link lists, or make cache publication atomic and treat an existing entry as success.
  5. nx2/build.py:666: The assembly key hashes only the concatenated bytes of immediate .h files. Renaming an included a.h to b.h with the same contents can keep the key and return a cached object even though a clean compile fails. A changed .inc is ignored entirely. Reuse the build's dependency tracking for preprocessed assembly and key the paths and contents of the files actually included. Test a rename or removal as well as a content edit.
  6. nx2/build.py:2133: The renderer's C++ dependency roots omit gpu/asm. If a Vulkan caller includes a shared kernel declaration from there, changing its signature can rebuild the assembly while retaining the caller with the old signature. Add gpu/asm to the renderer's dependency roots and check that a declaration edit invalidates the including caller.
  7. nx2/build.py:669: scripts/linux/appimage.sh copies host and gpu/vk but omits gpu/asm. A player build with a host or renderer kernel then fails while listing the missing common directory. A shared kernel is silently omitted instead. Stage gpu/asm and extend the AppImage coverage to check the assembly sources and their includes.
  8. scripts/devtools/packs.py:103: Adding .S to SOURCES changes the link-input classification, but renderer_untouched still recognizes only host C files. A pack with only a host/asm kernel edit rebuilds and relinks the renderer although the renderer cannot use that kernel. Include host/asm .S in the game-only route and test all three assembly folders through the routing decision.
  9. tests/asm_kit.py:38: The runtime probe checks three features and then runs an entire fixture compiled for x86-64-v3. A VM can expose AVX2, BMI2, and FMA while masking MOVBE or LZCNT, which the compiler can still emit. Check the full level, including OS AVX support, using a baseline executable. Distinguish an unsupported CPU from a crashed probe.
  10. tests/asm_kit.py:66: Fixture object filenames use only the source stem. A fixture using both gpu/asm/hash.S and gpu/vk/asm/hash.S overwrites the first object and passes the second to the linker twice. Use a unique per-source filename for both the native and cross-assembly outputs.
  11. tests/asm_kit.py:82: A strict run with GCC and no clang on PATH silently omits both cross-assembly checks. On a baseline CPU it then claims the AVX2 bodies were assembled anyway. Require a resolved Clang for the strict check, allow an explicit compiler path, and report only the variants that ran. The standalone ABI check should also honor CXX when --cxx is omitted, so a Windows llvm-mingw setup does not default to g++.
  12. tests/asm_kit.py:14: The unused os import triggers Ruff F401 under the repository's lint configuration. Remove it.
  13. tests/test_asm_abi.py:124: The Linux fixture never consumes the DWARF unwind state or calls the scratch-frame probe. Removing the CFA adjustment after LSASM_ALLOC would still pass Linux and COFF. Add a native ELF unwind check that verifies the caller and saved registers with the scratch frame active, and exercise LSASM_RODATA with a table load so that macro is assembled on both targets.
  14. tests/test_asm_abi.py:81: Single-step unwinding checks six GPRs but omits Win64 RDI, RSI, and XMM6–15. The fault handler manually unwinds one frame and resumes, so it never tests exception dispatch to a caller's __except. Check the full nonvolatile state for the Win64 steps and add a direct trip through a guarded caller built with the game's SEH flags.
  15. tests/test_asm_build.py:23: Importing build.py inherits machine and build settings and can run pkg-config or Clang during a check advertised as compiler-free. RX_MARCH=native with no working Clang can abort before unittest starts. Isolate the import with controlled build settings and stub discovery, or move the job planner behind an import-safe interface.
  16. tests/test_asm_build.py:74: The module test looks for call text. It passes if a guard prevents a call from running or if the result never reaches a link list. Exercise the production job planner with synthetic sources and check the actual game and renderer inputs in full, game-only, and renderer-only modes.

Waiting on the author (a run, a measurement or a decision; no edit does it)

  • The standards ask for clean build time and output size on build changes. The single Windows pack reports a 26-second recompilation but gives no comparable base or clean-build result. Record clean build time and size on the same setup for the base and the revised PR, and verify the update rebuild cost.
  • The only ABI result is from Windows before the rebase. The Linux GCC and Clang fixtures, AppImage and applicable hardware runs, full strict suite, and CI on the revised head still need results. Recheck the pack test against the current base, since its only reported failure was against the old base.
  • The standards group a track's steps into one PR. The stated plan splits this foundation from all its callers, leaving the actual assembly build path unexercised by the smoke test. Put the first kernel and its verification on this branch, or record the maintainer's decision to land the infrastructure separately.

Testing: Read-only review. git diff --check passed. No project scripts, builds, or tests were run. The author reported the Windows ABI and build helper passes and a clean game exit on df88c325. The changed-test run stopped after 356 checks and the pack test was last tried on the older base.
Overlaps and merge order: No overlapping PR found in local history. The planned kernel PRs depend on this work. Open Forgejo PRs could not be checked from the offline checkout.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The shared assembly layer would reduce duplicated kernels, but it can misalign Win64 frames, reuse stale objects, and break AppImage builds as soon as a kernel is added. The new checks leave key unwind and build paths unverified. Adds a common x86-64 ABI header, a game-free test kit, and build, pack, and version support for assembly sources. There are no game kernels in this PR. The author reported a one-time rebuild of 80 runtime C files taking 26 seconds in a 56-second Windows pack. **Does it help:** Not a perf change. The author reports a passing 9.3-second Windows ABI check and a passing build helper check on df88c325 before rebase. The 60-second Kokiri Forest run at 41–52 fps is a smoke test. Clean build time and size against 8d56b59d and Linux ABI results are missing. **Other systems:** Windows and Linux share the job planner and object cache but use different unwind formats. The Linux AppImage stages a narrower source tree than the Windows Builder. Developer packs can choose to rebuild either module, so dependency tracking matters independently of the full build. No kernel enters capture, graphics, audio, input, or save paths in this PR. The only reported game run was Windows on NVIDIA. Linux, Steam Deck, Windows AMD and Intel, and the full suite on this head remain unverified. **Switches:** LSASM_TEST_SYSV is a test-only preprocessor define, unset by default. The Windows fixture sets it for its second ABI variant. That default is right for shipping builds. Assembly jobs inherit the existing RX_MARCH choice and its automatic CPU default. No player switch or switch-table change. **Reviewed:** 10d5d0de1595 against 8d56b59d4766: Read all ten changed-file diffs and the full new header, assembly probe, three Python files, build reference, and version module. Read the changed sections and relevant callers in nx2/build.py, packs.py, and test_dev_packs.py. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, and docs/dev/standards.md. There is no docs/review-checklist.md in the checkout. Traced the relevant compile, link, cache, package, CPU detection, sampler, guarded-copy, lint, and test-runner paths. Read the author’s testing report and sole comment. Unrelated sections of the large modules and historical recorded runs were outside the review scope. No generated files, translations, or recorded-run files changed.; nothing run (a code review). **Checked and fine:** - The commit has the required Assisted-by trailer. The WIP prefix is allowed and the underlying title is a Conventional Commit. - The diff contains authored fixtures and no game-derived files, vendor SDKs, generated files, shader changes, or third-party edits. - The renderer interface is unchanged, so no MKWVK_API_VERSION bump is needed. - The Win64 fifth and sixth stack offsets are correct for six integer or pointer arguments after the two pushes. The Windows epilogue puts XMM restores and vzeroupper ahead of the add, pops, and ret. - The build uses the existing long-path wrappers and passes compiler paths as separate arguments. The fingerprint test changes assembly contents and checks the resulting fingerprint. - The renderer response file takes the renderer jobs, and the game response file excludes those objects. The per-module prefixes distinguish same-stem private and shared assembly sources in the production job list. **Blocking** (to change before merge) 1. gpu/asm/lsasm.h:22: The Win64 ABI still requires 16-byte stack alignment in the body of a function that makes a frame. The six-argument probe pushes eight registers and subtracts 160, so its body runs with RSP at 8 modulo 16. A kernel following the header can fault on an aligned stack access. Track the pushes and add any needed padding in the prologue, describe it in SEH, and fold its removal into the epilogue adjustment. Check alignment with both odd and even push counts. 2. gpu/asm/lsasm.h:171: LSASM_ARGS reads both stack argument slots on every call. A one-argument Win64 caller owes only the home area, so these reads can fault if the caller's frame is at the top of a small stack. Give LSASM_ARGS an argument count, load only the supplied fifth and sixth arguments, and state that the mapping supports integer and pointer arguments. 3. gpu/asm/lsasm.h:86: LSASM_ALLOC accepts arbitrary scratch sizes but subtracts RSP without probing stack pages. A Windows kernel using 8 KiB of scratch can skip the guard page and fault at its first store. Enforce a conservative assembly-time bound on the total frame or implement stack probing with matching unwind data. 4. nx2/build.py:2134: A shared kernel is queued twice with the same source, flags, dependencies, and cache key. On a cold parallel build both workers can enter cache_put. The loser of the hard-link race falls back to copyfile over the winner's cache entry, which is already linked to an output object. Compile each shared object once for both link lists, or make cache publication atomic and treat an existing entry as success. 5. nx2/build.py:666: The assembly key hashes only the concatenated bytes of immediate .h files. Renaming an included a.h to b.h with the same contents can keep the key and return a cached object even though a clean compile fails. A changed .inc is ignored entirely. Reuse the build's dependency tracking for preprocessed assembly and key the paths and contents of the files actually included. Test a rename or removal as well as a content edit. 6. nx2/build.py:2133: The renderer's C++ dependency roots omit gpu/asm. If a Vulkan caller includes a shared kernel declaration from there, changing its signature can rebuild the assembly while retaining the caller with the old signature. Add gpu/asm to the renderer's dependency roots and check that a declaration edit invalidates the including caller. 7. nx2/build.py:669: scripts/linux/appimage.sh copies host and gpu/vk but omits gpu/asm. A player build with a host or renderer kernel then fails while listing the missing common directory. A shared kernel is silently omitted instead. Stage gpu/asm and extend the AppImage coverage to check the assembly sources and their includes. 8. scripts/devtools/packs.py:103: Adding .S to SOURCES changes the link-input classification, but renderer_untouched still recognizes only host C files. A pack with only a host/asm kernel edit rebuilds and relinks the renderer although the renderer cannot use that kernel. Include host/asm .S in the game-only route and test all three assembly folders through the routing decision. 9. tests/asm_kit.py:38: The runtime probe checks three features and then runs an entire fixture compiled for x86-64-v3. A VM can expose AVX2, BMI2, and FMA while masking MOVBE or LZCNT, which the compiler can still emit. Check the full level, including OS AVX support, using a baseline executable. Distinguish an unsupported CPU from a crashed probe. 10. tests/asm_kit.py:66: Fixture object filenames use only the source stem. A fixture using both gpu/asm/hash.S and gpu/vk/asm/hash.S overwrites the first object and passes the second to the linker twice. Use a unique per-source filename for both the native and cross-assembly outputs. 11. tests/asm_kit.py:82: A strict run with GCC and no clang on PATH silently omits both cross-assembly checks. On a baseline CPU it then claims the AVX2 bodies were assembled anyway. Require a resolved Clang for the strict check, allow an explicit compiler path, and report only the variants that ran. The standalone ABI check should also honor CXX when --cxx is omitted, so a Windows llvm-mingw setup does not default to g++. 12. tests/asm_kit.py:14: The unused os import triggers Ruff F401 under the repository's lint configuration. Remove it. 13. tests/test_asm_abi.py:124: The Linux fixture never consumes the DWARF unwind state or calls the scratch-frame probe. Removing the CFA adjustment after LSASM_ALLOC would still pass Linux and COFF. Add a native ELF unwind check that verifies the caller and saved registers with the scratch frame active, and exercise LSASM_RODATA with a table load so that macro is assembled on both targets. 14. tests/test_asm_abi.py:81: Single-step unwinding checks six GPRs but omits Win64 RDI, RSI, and XMM6–15. The fault handler manually unwinds one frame and resumes, so it never tests exception dispatch to a caller's __except. Check the full nonvolatile state for the Win64 steps and add a direct trip through a guarded caller built with the game's SEH flags. 15. tests/test_asm_build.py:23: Importing build.py inherits machine and build settings and can run pkg-config or Clang during a check advertised as compiler-free. RX_MARCH=native with no working Clang can abort before unittest starts. Isolate the import with controlled build settings and stub discovery, or move the job planner behind an import-safe interface. 16. tests/test_asm_build.py:74: The module test looks for call text. It passes if a guard prevents a call from running or if the result never reaches a link list. Exercise the production job planner with synthetic sources and check the actual game and renderer inputs in full, game-only, and renderer-only modes. **Waiting on the author** (a run, a measurement or a decision; no edit does it) - The standards ask for clean build time and output size on build changes. The single Windows pack reports a 26-second recompilation but gives no comparable base or clean-build result. Record clean build time and size on the same setup for the base and the revised PR, and verify the update rebuild cost. - The only ABI result is from Windows before the rebase. The Linux GCC and Clang fixtures, AppImage and applicable hardware runs, full strict suite, and CI on the revised head still need results. Recheck the pack test against the current base, since its only reported failure was against the old base. - The standards group a track's steps into one PR. The stated plan splits this foundation from all its callers, leaving the actual assembly build path unexercised by the smoke test. Put the first kernel and its verification on this branch, or record the maintainer's decision to land the infrastructure separately. **Testing:** Read-only review. git diff --check passed. No project scripts, builds, or tests were run. The author reported the Windows ABI and build helper passes and a clean game exit on df88c325. The changed-test run stopped after 356 checks and the pack test was last tried on the older base. **Overlaps and merge order:** No overlapping PR found in local history. The planned kernel PRs depend on this work. Open Forgejo PRs could not be checked from the offline checkout. --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
gpu/asm/lsasm.h Outdated
@ -0,0 +19,4 @@
LSASM_ENDFUNC lsasm_example
The rules a kernel keeps:
- a leaf: it calls nothing, so the stack needs no alignment and nothing above it needs to know its frame;
Member

Win64 frame functions need aligned RSP in the body. The six-argument probe pushes eight registers and stays misaligned. Account for padding in the unwind data and epilogue.

Win64 frame functions need aligned RSP in the body. The six-argument probe pushes eight registers and stays misaligned. Account for padding in the unwind data and epilogue.
gpu/asm/lsasm.h Outdated
@ -0,0 +83,4 @@
pop \reg
.endm
.macro LSASM_ALLOC n
sub rsp, (\n + 15) / 16 * 16 /* (16s: Windows' xmm save offsets above it must stay multiples of 16) */
Member

A large scratch allocation can skip the Windows stack guard page. Bound the total frame or probe it.

A large scratch allocation can skip the Windows stack guard page. Bound the total frame or probe it.
gpu/asm/lsasm.h Outdated
@ -0,0 +168,4 @@
mov rsi, rdx
mov rdx, r8
mov rcx, r9
mov r8, [rsp + 56] /* (the fifth and sixth: above the two pushes, the return address and the 32-byte home area) */
Member

A short call owes only the home area. Use an argument count so LSASM_ARGS reads stack slots only when the caller supplied them.

A short call owes only the home area. Use an argument count so LSASM_ARGS reads stack slots only when the caller supplied them.
nx2/build.py Outdated
@ -659,0 +663,4 @@
if not os.path.isdir(folder):
return []
common = os.path.join(GPU, "asm")
deps = b"".join(open(os.path.join(d, f), "rb").read() for d in sorted({common, folder}) for f in sorted(os.listdir(d))
Member

Renaming an included header can leave this key unchanged, and .inc edits are invisible. Key the assembly object's actual include paths and contents.

Renaming an included header can leave this key unchanged, and .inc edits are invisible. Key the assembly object's actual include paths and contents.
nx2/build.py Outdated
@ -659,0 +666,4 @@
deps = b"".join(open(os.path.join(d, f), "rb").read() for d in sorted({common, folder}) for f in sorted(os.listdir(d))
if f.endswith(".h"))
return [(cc, os.path.join(folder, f), os.path.join(obj_dir, prefix + f[:-2] + ".o"),
target() + CPU + ["-x", "assembler-with-cpp"], deps)
Member

The AppImage omits gpu/asm. A private kernel triggers a missing-directory error here, and shared kernels are omitted. Stage the common sources and cover them in the package check.

The AppImage omits gpu/asm. A private kernel triggers a missing-directory error here, and shared kernels are omitted. Stage the common sources and cover them in the package check.
nx2/build.py Outdated
@ -2113,6 +2130,8 @@ def main():
vk_jobs.append((cc, zstd_src, os.path.join(obj_dir, "vk_zstd.o"),
target() + THIRD_PARTY_CPU + (["-fPIC"] if LINUX else []) +
["-O2", "-g0", "-DNDEBUG", "-Wno-everything", "-fvisibility=hidden", "-I" + zbic], zstd_deps + tp_deps))
vk_jobs += asm_jobs(cc, os.path.join(vk, "asm"), obj_dir, "vk_asm_") + \
Member

The renderer's C++ dependency roots omit gpu/asm. A shared declaration edit can leave a Vulkan caller using the old signature.

The renderer's C++ dependency roots omit gpu/asm. A shared declaration edit can leave a Vulkan caller using the old signature.
nx2/build.py Outdated
@ -2114,2 +2131,4 @@
target() + THIRD_PARTY_CPU + (["-fPIC"] if LINUX else []) +
["-O2", "-g0", "-DNDEBUG", "-Wno-everything", "-fvisibility=hidden", "-I" + zbic], zstd_deps + tp_deps))
vk_jobs += asm_jobs(cc, os.path.join(vk, "asm"), obj_dir, "vk_asm_") + \
asm_jobs(cc, os.path.join(GPU, "asm"), obj_dir, "vk_lsasm_") # (the renderer's hand-written x86-64 kernels)
Member

Both jobs for a shared kernel have the same cache key. Concurrent cache_put calls can copy over an already linked object. Compile once or publish atomically.

Both jobs for a shared kernel have the same cache key. Concurrent cache_put calls can copy over an already linked object. Compile once or publish atomically.
@ -101,3 +101,3 @@
"scripts/check_windows_files.py", "scripts/run-vk.ps1", "scripts/fetch_commit.sh", "scripts/release_keys.json")
HEADERS = (".h", ".hpp", ".hh", ".inc", ".inl")
SOURCES = (".c", ".cc", ".cpp") + HEADERS
SOURCES = (".c", ".cc", ".cpp", ".S") + HEADERS # (.S: the hand-written x86-64 kernels, nx2/build.py asm_jobs)
Member

A host/asm-only edit still rebuilds the renderer. Teach renderer_untouched about host assembly and test routing for all three folders.

A host/asm-only edit still rebuilds the renderer. Teach renderer_untouched about host assembly and test routing for all three folders.
tests/asm_kit.py Outdated
@ -0,0 +11,4 @@
import asm_kit
asm_kit.run_fixture(cxx, "name", fixture_cpp_text, [ROOT / "gpu/vk/asm/hash.S"], work_dir)
"""
import os
Member

Remove the unused os import. Ruff F401 is enabled.

Remove the unused os import. Ruff F401 is enabled.
tests/asm_kit.py Outdated
@ -0,0 +35,4 @@
def has_avx2(cxx, work):
"""Whether this CPU runs x86-64-v3 code (AVX2, BMI2, FMA)"""
probe = Path(work) / "cpu_probe.cpp"
exe = Path(work) / ("cpu_probe" + (".exe" if WINDOWS else ""))
Member

Gate the optimized fixture on the full x86-64-v3 level, including OS AVX support. Fail if the CPU probe itself crashes.

Gate the optimized fixture on the full x86-64-v3 level, including OS AVX support. Fail if the CPU probe itself crashes.
tests/asm_kit.py Outdated
@ -0,0 +63,4 @@
out = Path(out)
objs = []
for s in sources:
obj = out.with_name(out.stem + "_" + s.stem + ".o")
Member

Same-stem sources from different folders overwrite the fixture object. Give each source its own output name.

Same-stem sources from different folders overwrite the fixture object. Give each source its own output name.
tests/asm_kit.py Outdated
@ -0,0 +79,4 @@
work.mkdir(parents=True, exist_ok=True)
fixture = work / (name + ".cpp")
fixture.write_text(fixture_text, encoding="utf-8")
clang = clang if clang is not None else shutil.which("clang")
Member

Strict runs can skip both cross targets silently and still claim AVX2 was assembled. Resolve Clang explicitly and report the checks that ran.

Strict runs can skip both cross targets silently and still claim AVX2 was assembled. Resolve Clang explicitly and report the checks that ran.
@ -0,0 +78,4 @@
DWORD64 frame = 0;
RtlVirtualUnwind(UNW_FLAG_NHANDLER, base, u.Rip, f, &u, &data, &frame, nullptr);
const uint64_t r[6] = {u.Rbx, u.Rbp, u.R12, u.R13, u.R14, u.R15};
ok = u.Rip == step_ret && u.Rsp == step_rsp && !std::memcmp(r, step_regs, sizeof r);
Member

Check RDI, RSI, and XMM6–15 during Win64 stepping. Add a fault through a real __except caller to check Windows exception dispatch.

Check RDI, RSI, and XMM6–15 during Win64 stepping. Add a fault through a real __except caller to check Windows exception dispatch.
@ -0,0 +121,4 @@
const uint64_t changed = lsasm_probe_harness(lsasm_probe_clobber, 41, &r);
if (changed) std::fprintf(stderr, "callee-saved registers changed: %#llx\n", (unsigned long long)changed);
CHECK(changed == 0 && r == 42);
#ifdef _WIN32
Member

Deleting the CFA adjustment leaves the Linux fixture green. Exercise ELF unwinding from the scratch frame and use LSASM_RODATA in a probe.

Deleting the CFA adjustment leaves the Linux fixture green. Exercise ELF unwinding from the scratch frame and use LSASM_RODATA in a probe.
@ -0,0 +20,4 @@
sys.path[:0] = [str(ROOT / "nx2"), str(ROOT / "third_party" / "a64-kit" / "tools")]
spec = importlib.util.spec_from_file_location("build_asm_jobs", ROOT / "nx2" / "build.py")
build = importlib.util.module_from_spec(spec)
spec.loader.exec_module(build)
Member

Importing build.py inherits RX_MARCH and can invoke native compiler discovery before the tests run. Isolate the test settings and stub discovery.

Importing build.py inherits RX_MARCH and can invoke native compiler discovery before the tests run. Isolate the test settings and stub discovery.
@ -0,0 +71,4 @@
def test_no_folder_no_job(self):
self.assertEqual(self.jobs(self.kernels.parent / "missing"), [])
def test_the_modules_take_their_folders(self):
Member

These string checks can pass with missing link inputs. Assert the production planner's outputs in full, game-only, and renderer-only builds.

These string checks can pass with missing link inputs. Assert the production planner's outputs in full, game-only, and renderer-only builds.
futondestroyer left a comment

Recommendation: Request changes. The assembly kit needs a correct Win64 frame contract and an exercised path from source packaging through both link lists before kernels can use it. I independently confirmed the central blockers in the existing same-head review. Existing review

Does it help: Build infrastructure. The author reports a 9.3 s Windows ABI pass and a passing job-planner fixture on df88c325 before rebase. The reported 56 s development pack included 26 s recompiling 80 runtime C files. Those results show the proposed checks and the one-time update cost on that setup. Neither the gameplay smoke nor that pack compiled a new production kernel. Author's smoke

Reviewed: 10d5d0de159563c22b11a13cf7e6a8bd4bd91409 against merge base 8d56b59d4766034b42ffe306d19a5eaf0487c989. Read all ten file diffs, the new assembly macros and probes, and the compile, object-cache, pack, AppImage, Windows Builder and exception callers. Both exact Graphify maps validated. Graphify did not extract symbols from the assembly macro header, which I read directly. No PR source was executed. LSASM_TEST_SYSV is fixture-only. Production continues to use the existing CPU selection.

Checked and fine: The Win64 offsets for six supplied integer or pointer arguments account for both saved registers and the shadow space. The shared and private jobs have separate output names and the production linker separates game and renderer inputs. Windows Builder stages tracked gpu/ and host/ files, which includes the new sources. The AppImage uses a separate staging list.

Blocking:

  • The Win64 frame is active even for a function that never calls another function. For example, the six-argument probe saves eight GPRs and subtracts 160 bytes from an entry stack at 8 modulo 16. Its body remains misaligned. Make stack padding part of the described prologue and the single epilogue adjustment, and check both parities. Limit argument-slot reads to the declared arity. Include a guard-boundary case so an integer-only one-argument kernel cannot read optional stack slots. Microsoft x64 ABI
  • A shared .S reaches both concurrent job lists with the same object key. If both cache publishers observe the key missing, the losing hard-link attempt can fall back to copying over the winner's cache file. Also, the AppImage leaves out gpu/asm. A private kernel then reaches os.listdir(common) on a missing directory, while a shared kernel disappears from the packaged inputs. I would check one shared kernel and one private kernel per module end to end through a cold build, a cached rebuild after an included-file rename, developer packs, and the Linux AppImage staging.

Testing and farm: Full exact-head suite and native Linux GCC/Clang ABI and DWARF unwind results are outstanding. The existing author request is pending. Its Kokiri smoke can check basic compatibility once the above is fixed. The current head has no production kernel, so that smoke cannot cover the disputed ABI, rebuild or packaging paths. Do the ABI fixtures by hand on Windows and Linux, including an application-style SEH handler and saved-register checks. Reuse the author's request after the revised head is pinned and the plan says which real build path will exercise .S. Author's request

Overlap: The sampler is a consumer of the unwind metadata. The sampler change can be reviewed independently. This kit needs to satisfy the OS ABI used by both the sampler and guarded copy. Build-profile changes in the same review batch also edit nx2/build.py and should be rechecked when rebased.

**Recommendation: Request changes.** The assembly kit needs a correct Win64 frame contract and an exercised path from source packaging through both link lists before kernels can use it. I independently confirmed the central blockers in the existing same-head review. [Existing review](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61742) **Does it help:** Build infrastructure. The author reports a 9.3 s Windows ABI pass and a passing job-planner fixture on `df88c325` before rebase. The reported 56 s development pack included 26 s recompiling 80 runtime C files. Those results show the proposed checks and the one-time update cost on that setup. Neither the gameplay smoke nor that pack compiled a new production kernel. [Author's smoke](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61702) **Reviewed:** `10d5d0de159563c22b11a13cf7e6a8bd4bd91409` against merge base `8d56b59d4766034b42ffe306d19a5eaf0487c989`. Read all ten file diffs, the new assembly macros and probes, and the compile, object-cache, pack, AppImage, Windows Builder and exception callers. Both exact Graphify maps validated. Graphify did not extract symbols from the assembly macro header, which I read directly. No PR source was executed. `LSASM_TEST_SYSV` is fixture-only. Production continues to use the existing CPU selection. **Checked and fine:** The Win64 offsets for *six supplied integer or pointer arguments* account for both saved registers and the shadow space. The shared and private jobs have separate output names and the production linker separates game and renderer inputs. Windows Builder stages tracked `gpu/` and `host/` files, which includes the new sources. The AppImage uses a separate staging list. **Blocking:** - The Win64 frame is active even for a function that never calls another function. For example, the six-argument probe saves eight GPRs and subtracts 160 bytes from an entry stack at 8 modulo 16. Its body remains misaligned. Make stack padding part of the described prologue and the single epilogue adjustment, and check both parities. Limit argument-slot reads to the declared arity. Include a guard-boundary case so an integer-only one-argument kernel cannot read optional stack slots. [Microsoft x64 ABI](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#unwindability) - A shared `.S` reaches both concurrent job lists with the same object key. If both cache publishers observe the key missing, the losing hard-link attempt can fall back to copying over the winner's cache file. Also, the AppImage leaves out `gpu/asm`. A private kernel then reaches `os.listdir(common)` on a missing directory, while a shared kernel disappears from the packaged inputs. I would check one shared kernel and one private kernel per module end to end through a cold build, a cached rebuild after an included-file rename, developer packs, and the Linux AppImage staging. **Testing and farm:** Full exact-head suite and native Linux GCC/Clang ABI and DWARF unwind results are outstanding. The existing author request is pending. Its Kokiri smoke can check basic compatibility once the above is fixed. The current head has no production kernel, so that smoke cannot cover the disputed ABI, rebuild or packaging paths. Do the ABI fixtures by hand on Windows and Linux, including an application-style SEH handler and saved-register checks. Reuse the author's request after the revised head is pinned and the plan says which real build path will exercise `.S`. [Author's request](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61714) **Overlap:** The sampler is a consumer of the unwind metadata. The sampler change can be reviewed independently. This kit needs to satisfy the OS ABI used by both the sampler and guarded copy. Build-profile changes in the same review batch also edit `nx2/build.py` and should be rechecked when rebased.
siantm force-pushed build/asm-kit from 10d5d0de15
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 9s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 4cf7de0482
Some checks failed
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-21 03:25:59 +00:00
Compare
Author
Contributor

Thank you for the review. The branch is now 4cf7de04, rebased onto main 6e1521a7 with no conflicts; git range-diff shows the PR's own commit as =. Each behaviour fix is two commits: the test first, then the fix. Every check below ran through this PC's job queue (Windows 11, i7-9700, llvm-mingw clang 23.1.5, jobs fb-1947-b3, -c1, -d1 and -e1). Every fix's test failed at its test commit and passed at its fix. The game has not run at this head.

  1. #issuecomment-61726 (body alignment): fixed in 7ff1ed9b (test 5eb2e659). The macros count the pushes. When rsp would be 8 modulo 16 after them, they take 8 more bytes before the first xmm save or scratch, recorded in both the SEH codes and the CFI. The epilogue gives the 8 bytes back in its single add. Three probes return rsp % 16 from their bodies: scratch only, an odd count of pushes and an even count. On Windows each one is also single-stepped and unwound. At 5eb2e659 the check failed (rsp % 16 was 8); at 7ff1ed9b it passes.
  2. #issuecomment-61727 (argument count): fixed in 61011b0b (test 52672716). LSASM_ARGS now takes the kernel's argument count, 0 to 6; any other count stops the assembly. It moves only those registers, and it loads the fifth and sixth from the stack only when they were passed. The header states that the mapping covers integer and pointer arguments. The test calls one-argument probes on a stack that ends at their 32-byte home area, with the page above it unreadable. At 52672716 the fixture crashed with an access violation (0xC0000005); at 61011b0b it passes.
  3. #issuecomment-61728 (no stack probe): fixed in 7ff1ed9b (test 5eb2e659). LSASM_END_PROLOGUE stops the assembly when a frame is larger than 4096 bytes (pushes, padding, xmm saves and scratch together). In both conventions, 3072 bytes of scratch assemble and 4096 bytes are rejected. At the test commit, the run stopped at point 1's failure before it reached this check.
  4. #issuecomment-61729 (cache race): fixed in bd9564da (test 95432bfd). cache_put no longer writes over an entry that is already there (FileExistsError). A copy across volumes is written under a temporary name and renamed into place. The test replays the race. At the test commit the second publication wrote into the first job's object; at the fix both the first object and the cache entry stay intact.
  5. #issuecomment-61730 (include keys): fixed in bd9564da (test 95432bfd). A kernel is now compiled with -MD and keyed the same way as the host's and the renderer's own files (renderer_deps, DEPFILE_JOBS, rekey_depfiles): by the names and contents of the headers its depfile lists, .inc included. Until a kernel has a depfile, every header in its folder and in gpu/asm keys it. A rename, a removal and a .inc edit each change the key, and an edit to a header the kernel does not read keeps it.
  6. #issuecomment-61731 (renderer roots): fixed in bd9564da (test 95432bfd). gpu/asm is now one of the renderer's dependency roots. The test edits a gpu/asm declaration that a renderer file's depfile lists, and that file's key changes.
  7. #issuecomment-61732 (AppImage): fixed in 8fcc2519 (test c8f8692b). The AppImage script now stages gpu/asm whole. tests/test_appimage_source_headers.py runs the script's copy block and checks two things: that every file of gpu/asm is staged, and that every include of the kernels in host/asm, gpu/asm and gpu/vk/asm is staged. At the test commit, gpu/asm/lsasm.h was missing.
  8. #issuecomment-61733 (pack routing): fixed in 8fcc2519 (test c8f8692b). A host/asm .S file now builds the game alone. gpu/vk/asm and gpu/asm kernels, and a header next to a host/asm kernel, still build the renderer. tests/test_dev_packs.py stops at a check that also fails on main 6e1521a7 (longshot_fsr4_pipelines.bin is unclassified), so I ran each of its checks on its own. test_renderer_untouched failed at c8f8692b and passes at 8fcc2519 and at the head. Three other checks fail on main alike: test_caches_named_in_renderer, test_inputs_beside_the_objects and test_stamp_matches_build. Because test_inputs_beside_the_objects stops on main's failure, its new kernel line has not run.
  9. #issuecomment-61734 (v3 probe): fixed in b9536c12 (test 896a42d6). The CPU probe is now built for the baseline. It reads the whole x86-64-v3 level from CPUID (leaves 1 and 7, and the extended leaf for LZCNT) and the OS's ymm state through xgetbv. Any exit other than 0 or 1 now fails the check, so a crashed probe no longer counts as a CPU without AVX2.
  10. #issuecomment-61735 (object names): fixed in b9536c12 (test 896a42d6). Each object name now includes its source's index, in the native build and in the cross assembly. Two kernels with the same stem become two objects, each linked once.
  11. #issuecomment-61736 (strict clang): fixed in b9536c12 (test 896a42d6). The cross assembly uses --clang if given, otherwise the clang next to the compiler, otherwise the one on PATH. With no clang at all the check fails, and the PASS line names the clang it used. tests/test_asm_abi.py now reads CXX when --cxx is not given.
  12. #issuecomment-61737 (unused import): fixed in b9536c12; the import is removed. I did not run Ruff, because it is not installed in this PC's Builder Python.
  13. #issuecomment-61738 (ELF unwind, RODATA): test added in fa359ec4. A Linux probe with scratch and padding calls out from its body, and the fixture unwinds from there with _Unwind_Backtrace. It checks the probe's and the harness's return addresses, and rbx, rbp and r12-r15. A probe also reads a table in LSASM_RODATA RIP-relative. That probe is assembled for ELF and COFF and runs on Windows, where it passes. The Linux run has not been done on this PC (see below).
  14. #issuecomment-61739 (Win64 state, __except): test added in fa359ec4. Each single step's unwind is now compared with the whole nonvolatile state at entry: rsi, rdi and xmm6-xmm15 too, in Win64. A fault in a probe is also caught through Windows' own dispatch to a caller's __except, built with -fms-extensions as guarded_copy is. It passes at fa359ec4 with the macros as they were, so no fix was needed.
  15. #issuecomment-61740 (import isolation): fixed in 4cf7de04. tests/test_asm_build.py now imports nx2/build.py with RX_*, LONGSHOT_* and OOT_* cleared and RX_MARCH=x86-64-v3 set. While the import runs, subprocess.Popen and os.system raise, so any process the import starts fails it. I ran it with RX_MARCH=native and no clang reachable: at 5853d097 the import aborted before unittest started; at 4cf7de04 all 15 tests pass.
  16. #issuecomment-61741 (planner outputs): fixed in 5853d097. main() now plans through a new function, plan_modules, in nx2/build.py. It joins each module's kernels to its jobs, applies RX_VK_ONLY, and returns the jobs plus the two lists that objs.rsp and vk_objs.rsp are written from. The test runs it on synthetic kernels: two in host/asm, one in gpu/asm, and one with the same name in gpu/vk/asm. It checks the compiled jobs and both modules' full link inputs for a full build, a game-only build and a renderer-only build. Three tests anchored on lines that no longer exist, and now anchor on the planner's line.

At the head: tests/test_asm_abi.py passes at both levels and in both conventions, including the clang assemblies and the frame bound. tests/test_asm_build.py (15 tests), tests/test_asm_kit.py (6), tests/test_appimage_source_headers.py and tests/test_appimage_headers.py pass, and git diff --check is clean. The --strict --changed run covered every check, because a shared test file changed. I reran the checks it failed at main 6e1521a7 and at this head: the same 126 fail on both. The one difference was tests/test_audio_wave_buffer_release.py, which hit a compile timeout here and passed when run alone.

Waiting on the author (no code change, listed for the owner):

  • Clean build time and output size against main 6e1521a7, and the update rebuild cost: not measured yet.
  • Linux GCC and Clang runs of tests/test_asm_abi.py (including point 13's ELF unwind), the AppImage, the hardware runs, the full strict suite and CI on this head: not run yet.
  • Split versus first kernel: the first kernel joins this PR as a later commit, so the assembly build path runs end to end here.
Thank you for the review. The branch is now 4cf7de04, rebased onto main 6e1521a7 with no conflicts; `git range-diff` shows the PR's own commit as `=`. Each behaviour fix is two commits: the test first, then the fix. Every check below ran through this PC's job queue (Windows 11, i7-9700, llvm-mingw clang 23.1.5, jobs fb-1947-b3, -c1, -d1 and -e1). Every fix's test failed at its test commit and passed at its fix. The game has not run at this head. 1. [#issuecomment-61726](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61726) (body alignment): **fixed** in 7ff1ed9b (test 5eb2e659). The macros count the pushes. When rsp would be 8 modulo 16 after them, they take 8 more bytes before the first xmm save or scratch, recorded in both the SEH codes and the CFI. The epilogue gives the 8 bytes back in its single add. Three probes return rsp % 16 from their bodies: scratch only, an odd count of pushes and an even count. On Windows each one is also single-stepped and unwound. At 5eb2e659 the check failed (`rsp % 16` was 8); at 7ff1ed9b it passes. 2. [#issuecomment-61727](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61727) (argument count): **fixed** in 61011b0b (test 52672716). `LSASM_ARGS` now takes the kernel's argument count, 0 to 6; any other count stops the assembly. It moves only those registers, and it loads the fifth and sixth from the stack only when they were passed. The header states that the mapping covers integer and pointer arguments. The test calls one-argument probes on a stack that ends at their 32-byte home area, with the page above it unreadable. At 52672716 the fixture crashed with an access violation (0xC0000005); at 61011b0b it passes. 3. [#issuecomment-61728](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61728) (no stack probe): **fixed** in 7ff1ed9b (test 5eb2e659). `LSASM_END_PROLOGUE` stops the assembly when a frame is larger than 4096 bytes (pushes, padding, xmm saves and scratch together). In both conventions, 3072 bytes of scratch assemble and 4096 bytes are rejected. At the test commit, the run stopped at point 1's failure before it reached this check. 4. [#issuecomment-61729](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61729) (cache race): **fixed** in bd9564da (test 95432bfd). `cache_put` no longer writes over an entry that is already there (`FileExistsError`). A copy across volumes is written under a temporary name and renamed into place. The test replays the race. At the test commit the second publication wrote into the first job's object; at the fix both the first object and the cache entry stay intact. 5. [#issuecomment-61730](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61730) (include keys): **fixed** in bd9564da (test 95432bfd). A kernel is now compiled with `-MD` and keyed the same way as the host's and the renderer's own files (`renderer_deps`, `DEPFILE_JOBS`, `rekey_depfiles`): by the names and contents of the headers its depfile lists, `.inc` included. Until a kernel has a depfile, every header in its folder and in `gpu/asm` keys it. A rename, a removal and a `.inc` edit each change the key, and an edit to a header the kernel does not read keeps it. 6. [#issuecomment-61731](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61731) (renderer roots): **fixed** in bd9564da (test 95432bfd). `gpu/asm` is now one of the renderer's dependency roots. The test edits a `gpu/asm` declaration that a renderer file's depfile lists, and that file's key changes. 7. [#issuecomment-61732](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61732) (AppImage): **fixed** in 8fcc2519 (test c8f8692b). The AppImage script now stages `gpu/asm` whole. `tests/test_appimage_source_headers.py` runs the script's copy block and checks two things: that every file of `gpu/asm` is staged, and that every include of the kernels in `host/asm`, `gpu/asm` and `gpu/vk/asm` is staged. At the test commit, `gpu/asm/lsasm.h` was missing. 8. [#issuecomment-61733](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61733) (pack routing): **fixed** in 8fcc2519 (test c8f8692b). A `host/asm` `.S` file now builds the game alone. `gpu/vk/asm` and `gpu/asm` kernels, and a header next to a `host/asm` kernel, still build the renderer. `tests/test_dev_packs.py` stops at a check that also fails on main 6e1521a7 (`longshot_fsr4_pipelines.bin` is unclassified), so I ran each of its checks on its own. `test_renderer_untouched` failed at c8f8692b and passes at 8fcc2519 and at the head. Three other checks fail on main alike: `test_caches_named_in_renderer`, `test_inputs_beside_the_objects` and `test_stamp_matches_build`. Because `test_inputs_beside_the_objects` stops on main's failure, its new kernel line has not run. 9. [#issuecomment-61734](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61734) (v3 probe): **fixed** in b9536c12 (test 896a42d6). The CPU probe is now built for the baseline. It reads the whole x86-64-v3 level from CPUID (leaves 1 and 7, and the extended leaf for LZCNT) and the OS's ymm state through xgetbv. Any exit other than 0 or 1 now fails the check, so a crashed probe no longer counts as a CPU without AVX2. 10. [#issuecomment-61735](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61735) (object names): **fixed** in b9536c12 (test 896a42d6). Each object name now includes its source's index, in the native build and in the cross assembly. Two kernels with the same stem become two objects, each linked once. 11. [#issuecomment-61736](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61736) (strict clang): **fixed** in b9536c12 (test 896a42d6). The cross assembly uses `--clang` if given, otherwise the clang next to the compiler, otherwise the one on PATH. With no clang at all the check fails, and the PASS line names the clang it used. `tests/test_asm_abi.py` now reads `CXX` when `--cxx` is not given. 12. [#issuecomment-61737](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61737) (unused import): **fixed** in b9536c12; the import is removed. I did not run Ruff, because it is not installed in this PC's Builder Python. 13. [#issuecomment-61738](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61738) (ELF unwind, RODATA): **test added** in fa359ec4. A Linux probe with scratch and padding calls out from its body, and the fixture unwinds from there with `_Unwind_Backtrace`. It checks the probe's and the harness's return addresses, and rbx, rbp and r12-r15. A probe also reads a table in `LSASM_RODATA` RIP-relative. That probe is assembled for ELF and COFF and runs on Windows, where it passes. The Linux run has not been done on this PC (see below). 14. [#issuecomment-61739](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61739) (Win64 state, `__except`): **test added** in fa359ec4. Each single step's unwind is now compared with the whole nonvolatile state at entry: rsi, rdi and xmm6-xmm15 too, in Win64. A fault in a probe is also caught through Windows' own dispatch to a caller's `__except`, built with `-fms-extensions` as `guarded_copy` is. It passes at fa359ec4 with the macros as they were, so no fix was needed. 15. [#issuecomment-61740](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61740) (import isolation): **fixed** in 4cf7de04. `tests/test_asm_build.py` now imports `nx2/build.py` with `RX_*`, `LONGSHOT_*` and `OOT_*` cleared and `RX_MARCH=x86-64-v3` set. While the import runs, `subprocess.Popen` and `os.system` raise, so any process the import starts fails it. I ran it with `RX_MARCH=native` and no clang reachable: at 5853d097 the import aborted before unittest started; at 4cf7de04 all 15 tests pass. 16. [#issuecomment-61741](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-61741) (planner outputs): **fixed** in 5853d097. `main()` now plans through a new function, `plan_modules`, in `nx2/build.py`. It joins each module's kernels to its jobs, applies `RX_VK_ONLY`, and returns the jobs plus the two lists that `objs.rsp` and `vk_objs.rsp` are written from. The test runs it on synthetic kernels: two in `host/asm`, one in `gpu/asm`, and one with the same name in `gpu/vk/asm`. It checks the compiled jobs and both modules' full link inputs for a full build, a game-only build and a renderer-only build. Three tests anchored on lines that no longer exist, and now anchor on the planner's line. At the head: `tests/test_asm_abi.py` passes at both levels and in both conventions, including the clang assemblies and the frame bound. `tests/test_asm_build.py` (15 tests), `tests/test_asm_kit.py` (6), `tests/test_appimage_source_headers.py` and `tests/test_appimage_headers.py` pass, and `git diff --check` is clean. The `--strict --changed` run covered every check, because a shared test file changed. I reran the checks it failed at main 6e1521a7 and at this head: the same 126 fail on both. The one difference was `tests/test_audio_wave_buffer_release.py`, which hit a compile timeout here and passed when run alone. Waiting on the author (no code change, listed for the owner): - Clean build time and output size against main 6e1521a7, and the update rebuild cost: not measured yet. - Linux GCC and Clang runs of `tests/test_asm_abi.py` (including point 13's ELF unwind), the AppImage, the hardware runs, the full strict suite and CI on this head: not run yet. - Split versus first kernel: the first kernel joins this PR as a later commit, so the assembly build path runs end to end here.
Author
Contributor

@futondestroyer thank you for the review (#issuecomment-62705). Everything below is in head 4cf7de04, rebased onto main 6e1521a7. The point-by-point reply to BeanBot's review (#issuecomment-63062) lists the test runs. Each test failed at its test commit and passed at its fix.

  • Win64 frame: fixed in 7ff1ed9b (test 5eb2e659). The body now runs with rsp 16-byte aligned for both an odd and an even count of pushes. The padding is recorded in the SEH codes and the CFI and released in the epilogue's single add. A frame over 4096 bytes stops the assembly. LSASM_ARGS now takes the declared arity (61011b0b, test 52672716). Your guard-boundary case is the test: one-argument probes run on a stack that ends at their 32-byte home area, with the page above it unreadable. Before the fix, that test crashed with an access violation.
  • Shared-kernel cache race and AppImage: fixed in bd9564da (test 95432bfd). cache_put leaves an entry that is already there, and a cross-volume copy is renamed into place. A kernel is now keyed by the headers its depfile lists, so renaming or removing one changes the key. 8fcc2519 (test c8f8692b) stages gpu/asm in the AppImage and routes a host/asm pack to the game alone. 5853d097 runs the production planner on one private kernel per module plus a shared one, and checks both link lists for full, game-only and renderer-only builds. These are unit-level checks. The end-to-end run you describe (cold build, cached rebuild after an include rename, a pack, AppImage staging) needs a real kernel. The first kernel joins this PR as a later commit, and that run is listed as pending.
  • SEH handler and saved registers: fa359ec4 adds a fault caught by a caller's __except, built with -fms-extensions as guarded_copy is. It also checks the whole Win64 nonvolatile state (rsi, rdi, xmm6-xmm15) at every single step. Both pass on Windows. The native ELF unwind from a probe's body is in the fixture but has not run here. The Linux GCC/Clang runs are pending, along with the full suite on this head.
@futondestroyer thank you for the review ([#issuecomment-62705](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-62705)). Everything below is in head 4cf7de04, rebased onto main 6e1521a7. The point-by-point reply to BeanBot's review ([#issuecomment-63062](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-63062)) lists the test runs. Each test failed at its test commit and passed at its fix. - **Win64 frame**: fixed in 7ff1ed9b (test 5eb2e659). The body now runs with rsp 16-byte aligned for both an odd and an even count of pushes. The padding is recorded in the SEH codes and the CFI and released in the epilogue's single add. A frame over 4096 bytes stops the assembly. `LSASM_ARGS` now takes the declared arity (61011b0b, test 52672716). Your guard-boundary case is the test: one-argument probes run on a stack that ends at their 32-byte home area, with the page above it unreadable. Before the fix, that test crashed with an access violation. - **Shared-kernel cache race and AppImage**: fixed in bd9564da (test 95432bfd). `cache_put` leaves an entry that is already there, and a cross-volume copy is renamed into place. A kernel is now keyed by the headers its depfile lists, so renaming or removing one changes the key. 8fcc2519 (test c8f8692b) stages `gpu/asm` in the AppImage and routes a `host/asm` pack to the game alone. 5853d097 runs the production planner on one private kernel per module plus a shared one, and checks both link lists for full, game-only and renderer-only builds. These are unit-level checks. The end-to-end run you describe (cold build, cached rebuild after an include rename, a pack, AppImage staging) needs a real kernel. The first kernel joins this PR as a later commit, and that run is listed as pending. - **SEH handler and saved registers**: fa359ec4 adds a fault caught by a caller's `__except`, built with `-fms-extensions` as `guarded_copy` is. It also checks the whole Win64 nonvolatile state (rsi, rdi, xmm6-xmm15) at every single step. Both pass on Windows. The native ELF unwind from a probe's body is in the fixture but has not run here. The Linux GCC/Clang runs are pending, along with the full suite on this head.
perf(asm): the GPU-visible ranges are sorted by an x86-64 merge sort (lsasm_sort_ranges)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 16s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
8f5c08c6ec
hos_gpu_guest_ranges (host/nvdrv.c) sorts every GPU mapping's and native NVN pool's guest range by start before it
merges them, each time the mappings change: qsort with a comparison function call per compare. On x86-64 it now sorts
with host/asm/ranges.S's lsasm_sort_ranges, a hand-written merge sort on gpu/asm/lsasm.h: runs of 16 pairs by
insertion, then merges of runs twice as long a pass between the list and a second one (kept beside merged, grown with
it); two runs already in order (the mappings come mostly in address order) are copied, not merged, and the merge picks
its side with cmov, no branch. One body for both CPU levels: the pairs move in xmm registers. Other CPUs keep qsort
with cmp_range, under #if defined(__x86_64__). Both lists grow through hos_xrealloc (an allocation refused for 5 s
ends the run with the out-of-memory notice), where realloc's NULL was used as the list before.

It is stable where qsort is not: ranges that start together come out of qsort in any order, and the merge after the
sort makes the same ranges from any such order (one starts the merged range, the others only reach to their ends), so
the result is the same. No switch: the ranges merged are the same.

From 971f8074 on exp/x86-asm-sync, where the sort was collect.S's second kernel; here it is its own file. A
micro-benchmark there (i7-9700) found the kernel faster than qsort, more so in near order; not measured on this commit,
nor in play.

Test: tests/test_asm_ranges.py, through tests/asm_kit.py at SSE2 and AVX2, both conventions, clang ELF/COFF assembly:
the kernel against qsort with cmp_range (cut from the source) for 22 sizes around its runs and merges up to 10000 pairs
and 8 key patterns, between faulting pages: same order, stable, and hos_gpu_guest_ranges' merge makes the same ranges
from either order. The whole hos_gpu_guest_ranges, cut from the source, is compiled with its x86-64 test taken both
ways: the two give the same ranges for every case, one sorting with the kernel and the other with qsort, once a call.
scripts/profiling/cpu_functions.json describes lsasm_sort_ranges, and cmp_range as the other CPUs' comparison.

Assisted-by: Claude Code
siantm changed title from WIP: build(asm): hand-written x86-64 kernels have a common header, a check kit and the build's jobs to WIP: build(asm): hand-written x86-64 kernels have a common header, a check kit and the build's jobs, and the GPU-visible ranges' sort is the first 2026-11-21 06:27:32 +00:00
Author
Contributor

Pushed 8f5c08c6, one commit on 4cf7de04 (a fast-forward): the first kernel joins this pull request, as BeanBot's review asked (the ground and its first caller together). lsasm_sort_ranges (host/asm/ranges.S) sorts the GPU-visible ranges in hos_gpu_guest_ranges (host/nvdrv.c) on x86-64; other CPUs keep qsort. tests/test_asm_ranges.py and the kit's checks pass on this head through the queue; tests/test_host_guest_writes.py fails here and on main 75317e1f alike. It has not run in the game on this PC yet; the clean build's time and size against main, the cold and rename rebuilds and the whole suite are queued. Title and description updated.

Pushed 8f5c08c6, one commit on 4cf7de04 (a fast-forward): the first kernel joins this pull request, as BeanBot's review asked (the ground and its first caller together). `lsasm_sort_ranges` (`host/asm/ranges.S`) sorts the GPU-visible ranges in `hos_gpu_guest_ranges` (`host/nvdrv.c`) on x86-64; other CPUs keep `qsort`. `tests/test_asm_ranges.py` and the kit's checks pass on this head through the queue; `tests/test_host_guest_writes.py` fails here and on main 75317e1f alike. It has not run in the game on this PC yet; the clean build's time and size against main, the cold and rename rebuilds and the whole suite are queued. Title and description updated.
Author
Contributor

@Beanstalk This adds the build's jobs for hand-written x86-64 assembly (asm_jobs in nx2/build.py, the shared header gpu/asm/lsasm.h) and the first kernel, lsasm_sort_ranges, which replaces the qsort of the GPU-visible guest ranges in host/nvdrv.c (hos_gpu_guest_ranges): it runs at boot, at each area load and whenever the game maps or unmaps GPU memory. It has not run in the game on Linux, AMD or Intel yet. Please build this PR and main, time the build against main's (a warm build) and check the lifted C is the same; then start a new game in Kokiri Forest, play a minute, and go through three area loads by teleport (Hyrule Field, Castle Town Market, Kakariko; if a teleport does not arrive, the three area loads from Kokiri Forest's own exits), on each side. On Linux with NVIDIA, Linux with AMD, Windows with AMD, Windows with Intel, and the Steam Deck. It must not crash or hang at a load; frame time p99, load times and peak VRAM must be within main's run-to-run spread.

@Beanstalk This adds the build's jobs for hand-written x86-64 assembly (asm_jobs in nx2/build.py, the shared header gpu/asm/lsasm.h) and the first kernel, lsasm_sort_ranges, which replaces the qsort of the GPU-visible guest ranges in host/nvdrv.c (hos_gpu_guest_ranges): it runs at boot, at each area load and whenever the game maps or unmaps GPU memory. It has not run in the game on Linux, AMD or Intel yet. Please build this PR and main, time the build against main's (a warm build) and check the lifted C is the same; then start a new game in Kokiri Forest, play a minute, and go through three area loads by teleport (Hyrule Field, Castle Town Market, Kakariko; if a teleport does not arrive, the three area loads from Kokiri Forest's own exits), on each side. On Linux with NVIDIA, Linux with AMD, Windows with AMD, Windows with Intel, and the Steam Deck. It must not crash or hang at a load; frame time p99, load times and peak VRAM must be within main's run-to-run spread.
Member

@siantm only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for 8f5c08c, and the PR has changed since (db3d91f), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@siantm only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `8f5c08c`, and the PR has changed since (`db3d91f`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
siantm force-pushed build/asm-kit from 8f5c08c6ec
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 16s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to db3d91f148
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 4s
2026-11-21 07:42:11 +00:00
Compare
Author
Contributor

@Beanstalk This adds the build's jobs for hand-written x86-64 assembly (asm_jobs in nx2/build.py, the shared header gpu/asm/lsasm.h) and the first kernel, lsasm_sort_ranges, which replaces the qsort of the GPU-visible guest ranges in host/nvdrv.c (hos_gpu_guest_ranges): it runs at boot, at each area load and whenever the game maps or unmaps GPU memory. It has not run in the game on Linux, AMD or Intel yet. Please build this PR and main, time the build against main's (a warm build) and check the lifted C is the same; then start a new game in Kokiri Forest, play a minute, and go through three area loads by teleport (Hyrule Field, Castle Town Market, Kakariko; if a teleport does not arrive, the three area loads from Kokiri Forest's own exits), on each side. On Linux with NVIDIA, Linux with AMD, Windows with AMD, Windows with Intel, and the Steam Deck. It must not crash or hang at a load; frame time p99, load times and peak VRAM must be within main's run-to-run spread.

@Beanstalk This adds the build's jobs for hand-written x86-64 assembly (asm_jobs in nx2/build.py, the shared header gpu/asm/lsasm.h) and the first kernel, lsasm_sort_ranges, which replaces the qsort of the GPU-visible guest ranges in host/nvdrv.c (hos_gpu_guest_ranges): it runs at boot, at each area load and whenever the game maps or unmaps GPU memory. It has not run in the game on Linux, AMD or Intel yet. Please build this PR and main, time the build against main's (a warm build) and check the lifted C is the same; then start a new game in Kokiri Forest, play a minute, and go through three area loads by teleport (Hyrule Field, Castle Town Market, Kakariko; if a teleport does not arrive, the three area loads from Kokiri Forest's own exits), on each side. On Linux with NVIDIA, Linux with AMD, Windows with AMD, Windows with Intel, and the Steam Deck. It must not crash or hang at a load; frame time p99, load times and peak VRAM must be within main's run-to-run spread.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

@futondestroyer on the last open part of your review (#issuecomment-62705, Blocking, second point: one shared kernel and one private kernel per module end to end through a cold build, a cached rebuild after an included-file rename, developer packs and the Linux AppImage staging). The branch is now db3d91f1, rebased onto main 7c23d2be. git range-diff shows every earlier commit as =, except that 5653f5da and 5853d097 differ only in a hunk header of docs/dev/reference/build.md. There were no conflicts. Two commits are new:

  • Test (b21224ff, tests/test_asm_end_to_end.py). It writes three kernels in a temporary tree on the real gpu/asm/lsasm.h: a shared one in gpu/asm, one in host/asm and one in gpu/vk/asm, each with its own include. It runs the build's own code on them with clang: plan_modules, plan_jobs with the hash record, compile_one on four threads (so the shared kernel's two jobs run at once), rekey_depfiles, and main()'s own statements that write objs.rsp and vk_objs.rsp. Each module's link list is then linked with a caller and run.
    • Cold build and cached rebuild: a cold build compiles every kernel. A second build compiles nothing. A new work folder made from the first build's object cache (as a pack's is) also compiles nothing, and its modules are the first build's.
    • Rename: renaming an include while the kernel still names it makes the build compile that kernel again, and the compile fails as a clean build would. Once the kernel names the new file, only that kernel compiles.
    • Edit and revert: editing an include compiles only the kernels that read it. Reverting the edit compiles nothing and must link the cold build's objects.
    • Developer packs: three packs on one base go through route, link_inputs_changed, renderer_untouched, link_objects and module_changed, as cmd_pack runs them. A game kernel builds the game alone, a renderer kernel the renderer alone, and the shared kernel both. Each pack compiles what changed, its modules differ from the base's, and the base's objects and cache must not change.
    • AppImage staging: scripts/linux/appimage.sh's source-copy block runs with bash on the tree, and a cold build of the staged tree compiles and links the three kernels.
  • Fix (db3d91f1). The test found a defect that a real kernel would hit. clang's assembler writes its object in place: cc1as opens the -o path itself, while clang's C and C++ compiles write a temporary file and rename it. compile_one hard-links each object into the cache, so assembling a kernel again wrote through the link. The cache entry under the old key became the new object, and in a pack's work folder the base's cache entry and object changed too. At the test commit, a reverted include edit linked the edited kernel: the caller returned 1055 where the cold build returned 1022. A shared kernel's pack also rewrote the base's objects, so its game module compared equal to the base's. The renderer pack that followed then compiled the shared kernel again, though that pack had not changed it. compile_one now removes the object before it starts the compiler, so the compiler writes a new file and the old entries keep their objects.

Test runs, all in one queue job (fb3-1947-1; Windows 11, i7-9700, llvm-mingw clang 23.1.5). The job ran on 3bf51a69, these same commits on main e6196f0f, before main moved; the rebase onto 7c23d2be changed none of them:

  • New test: tests/test_asm_end_to_end.py --cxx clang++ failed at the test commit (1fefe953 then) with 4 failures (the edit-and-revert test and three of the pack checks). At the head all 5 tests pass, including the AppImage staging through Git for Windows' bash.
  • The PR's own checks pass at the head: tests/test_asm_abi.py, test_asm_build.py (15 tests), test_asm_kit.py, test_asm_ranges.py, test_appimage_source_headers.py and test_appimage_headers.py.
  • tests/run_all.py --strict --changed origin/main ran every check, with RX_CPM set so the renderer checks compile against the Vulkan headers: 866 checks: 786 passed, 80 failed, 48 skipped, and none stopped for want of the headers. Rerun by name on main e6196f0f with RX_CPM, 78 of the 80 fail there too. tests/test_present_semaphores.py failed here with no output in 10.9 s (8 checks at once) and passed on main. tests/test_vbytes.py timed out here at 600 s and was not rerun on main. Neither one reads a file this PR changes. Both are queued to run alone, at the head and on main (fb3-1947-2), and I will post the result.
  • Four timeouts from the whole-suite run on 8f5c08c6: those checks pass when run alone, at 3bf51a69 and on main e6196f0f.

Still pending (not covered by this test, which runs the build's code on authored kernels): the real build of this head with lsasm_sort_ranges. That means a clean build against main (its time and size), the head built as an update, and a rebuild after renaming gpu/asm/lsasm.h; this job is queued on this PC. Also pending: a real dev.py packs pack, a Linux AppImage build, and the Linux GCC/Clang runs of tests/test_asm_abi.py and tests/test_asm_ranges.py. The game has not run at this head.

@futondestroyer on the last open part of your review ([#issuecomment-62705](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947#issuecomment-62705), Blocking, second point: one shared kernel and one private kernel per module end to end through a cold build, a cached rebuild after an included-file rename, developer packs and the Linux AppImage staging). The branch is now db3d91f1, rebased onto main 7c23d2be. `git range-diff` shows every earlier commit as `=`, except that 5653f5da and 5853d097 differ only in a hunk header of `docs/dev/reference/build.md`. There were no conflicts. Two commits are new: - **Test** (b21224ff, `tests/test_asm_end_to_end.py`). It writes three kernels in a temporary tree on the real `gpu/asm/lsasm.h`: a shared one in `gpu/asm`, one in `host/asm` and one in `gpu/vk/asm`, each with its own include. It runs the build's own code on them with clang: `plan_modules`, `plan_jobs` with the hash record, `compile_one` on four threads (so the shared kernel's two jobs run at once), `rekey_depfiles`, and `main()`'s own statements that write `objs.rsp` and `vk_objs.rsp`. Each module's link list is then linked with a caller and run. - **Cold build and cached rebuild:** a cold build compiles every kernel. A second build compiles nothing. A new work folder made from the first build's object cache (as a pack's is) also compiles nothing, and its modules are the first build's. - **Rename:** renaming an include while the kernel still names it makes the build compile that kernel again, and the compile fails as a clean build would. Once the kernel names the new file, only that kernel compiles. - **Edit and revert:** editing an include compiles only the kernels that read it. Reverting the edit compiles nothing and must link the cold build's objects. - **Developer packs:** three packs on one base go through `route`, `link_inputs_changed`, `renderer_untouched`, `link_objects` and `module_changed`, as `cmd_pack` runs them. A game kernel builds the game alone, a renderer kernel the renderer alone, and the shared kernel both. Each pack compiles what changed, its modules differ from the base's, and the base's objects and cache must not change. - **AppImage staging:** `scripts/linux/appimage.sh`'s source-copy block runs with bash on the tree, and a cold build of the staged tree compiles and links the three kernels. - **Fix** (db3d91f1). The test found a defect that a real kernel would hit. clang's assembler writes its object in place: cc1as opens the `-o` path itself, while clang's C and C++ compiles write a temporary file and rename it. `compile_one` hard-links each object into the cache, so assembling a kernel again wrote through the link. The cache entry under the old key became the new object, and in a pack's work folder the base's cache entry and object changed too. At the test commit, a reverted include edit linked the edited kernel: the caller returned 1055 where the cold build returned 1022. A shared kernel's pack also rewrote the base's objects, so its game module compared equal to the base's. The renderer pack that followed then compiled the shared kernel again, though that pack had not changed it. `compile_one` now removes the object before it starts the compiler, so the compiler writes a new file and the old entries keep their objects. Test runs, all in one queue job (fb3-1947-1; Windows 11, i7-9700, llvm-mingw clang 23.1.5). The job ran on 3bf51a69, these same commits on main e6196f0f, before main moved; the rebase onto 7c23d2be changed none of them: - **New test:** `tests/test_asm_end_to_end.py --cxx clang++` failed at the test commit (1fefe953 then) with 4 failures (the edit-and-revert test and three of the pack checks). At the head all 5 tests pass, including the AppImage staging through Git for Windows' bash. - **The PR's own checks** pass at the head: `tests/test_asm_abi.py`, `test_asm_build.py` (15 tests), `test_asm_kit.py`, `test_asm_ranges.py`, `test_appimage_source_headers.py` and `test_appimage_headers.py`. - **`tests/run_all.py --strict --changed origin/main`** ran every check, with `RX_CPM` set so the renderer checks compile against the Vulkan headers: 866 checks: 786 passed, 80 failed, 48 skipped, and none stopped for want of the headers. Rerun by name on main e6196f0f with `RX_CPM`, 78 of the 80 fail there too. `tests/test_present_semaphores.py` failed here with no output in 10.9 s (8 checks at once) and passed on main. `tests/test_vbytes.py` timed out here at 600 s and was not rerun on main. Neither one reads a file this PR changes. Both are queued to run alone, at the head and on main (fb3-1947-2), and I will post the result. - **Four timeouts from the whole-suite run on 8f5c08c6:** those checks pass when run alone, at 3bf51a69 and on main e6196f0f. Still pending (not covered by this test, which runs the build's code on authored kernels): the real build of this head with `lsasm_sort_ranges`. That means a clean build against main (its time and size), the head built as an update, and a rebuild after renaming `gpu/asm/lsasm.h`; this job is queued on this PC. Also pending: a real `dev.py packs` pack, a Linux AppImage build, and the Linux GCC/Clang runs of `tests/test_asm_abi.py` and `tests/test_asm_ranges.py`. The game has not run at this head.
Author
Contributor

The description now names head db3d91f1 on main 7c23d2be. Testing covers this round's job: the new end-to-end test, which failed at its test commit and passes with the fix, the PR's own checks, and the --changed run with the Vulkan headers. That run's 78 failures that fail on main too replace the earlier figures, whose runs had no Vulkan headers. Two checks are being rerun alone. The Summary's build bullet names the fix: compile_one gives a recompiled object a new file. Still to test now lists the real build pair, a real pack and a Linux AppImage build.

The description now names head db3d91f1 on main 7c23d2be. Testing covers this round's job: the new end-to-end test, which failed at its test commit and passes with the fix, the PR's own checks, and the `--changed` run with the Vulkan headers. That run's 78 failures that fail on main too replace the earlier figures, whose runs had no Vulkan headers. Two checks are being rerun alone. The Summary's build bullet names the fix: `compile_one` gives a recompiled object a new file. Still to test now lists the real build pair, a real pack and a Linux AppImage build.
Author
Contributor

The two checks from the --changed run have been rerun (job fb3-1947-2, RX_CPM set). tests/test_present_semaphores.py passes alone, at db3d91f1 and on main 7c23d2be. tests/test_vbytes.py times out at 600 s when run alone, at db3d91f1 and on main 7c23d2be alike. The 80 checks that failed in the --changed run were rerun by name at db3d91f1: the same 79 fail as on main, and tests/test_present_semaphores.py passes. No check fails at this head alone. Testing is updated to match.

The two checks from the `--changed` run have been rerun (job fb3-1947-2, `RX_CPM` set). `tests/test_present_semaphores.py` passes alone, at db3d91f1 and on main 7c23d2be. `tests/test_vbytes.py` times out at 600 s when run alone, at db3d91f1 and on main 7c23d2be alike. The 80 checks that failed in the `--changed` run were rerun by name at db3d91f1: the same 79 fail as on main, and `tests/test_present_semaphores.py` passes. No check fails at this head alone. Testing is updated to match.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 4s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'build/asm-kit:siantm-build/asm-kit'
git switch 'siantm-build/asm-kit'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1947
No description provided.