Each draw's indices are now a range of its own and its task records too, reserved by an allocation shader (one
invocation, mesh_emu_alloc_spirv) for the run of draw records queued: before the task stages the task records and the
index ranges of draws without a task stage, after them the index ranges of the others (mesh workgroups with output,
which the task stage now counts in the record, times OutputPrimitives x vertices per primitive). The mesh stage takes
its indices from the draw's range with an atomic in its record; vertex slots stay the arena's, as the indices name
them. So no draw's stages need another's, and the queue (MEQ) records the fills as the draws come, then at the
pre-pass command buffer's end (vk_sync.c pre_end -> vk_exec_mesh_flush): allocation, every task stage, allocation,
every mesh stage, a barrier between each. One by one each draw took three barriers and copied the arena's counters
after the draw before it: an RX 580 spent 5.5 ms of a frame's GPU time on 69 draws' stages in Kokiri Forest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On 0.9.1 this is the release's own mirror capture (NX2NAVI_MIRROR_CAPTURE_KB) turned on: with
NX2NAVI_MIRROR_STAGE=1 (the default) the pages the CPU wrote are copied out of guest memory, up to 64 MiB a
part, when the part is handed to the queue. A submission whose prologue copied everything that way reads no
guest memory late, so the game's wait after a frame's first submission ends once the replay has submitted it
(vk_sync_recorded_wait). One with a range left to the GPU-time copy (a pool with a write-back in flight or a
twin) or a draw that reads a pool without a mirror is noted (vk_mem_note_live), and its wait is the GPU's.
Also 8 texture pool sets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The perf line's "idle with it queued" was the gap before each replay part handed over before the previous one ended:
13-17 ms a frame on an RX 580 in Kokiri Forest on 0.7.1, unexplained. Uploads and presents were not timed, a held
submission (submit batching) counted as handed over while it still waited in vk_sync, and with cuts and pre-pass
command buffers a submission closed more than the four timestamp pairs ts_unsent had room for: the rest went to the
completion queue without a submit time and out of the GPU's order. Now every timed piece of GPU work (replay parts,
mirror prologues, pre-pass command buffers, upload batches, presents) is noted with when it was handed to vk_sync, when
it really went to the queue and its GPU start and end, and every 60 frames two lines split the idle time: starved
(nothing in the queue, and how much of that a held submission waited in the batching) or with work in the queue, by
the kind of piece that started after the gap, with the average delay from hand-over to start on an idle GPU per kind.
ts_unsent has room for every command buffer of a submission, and the pairs are read in queue order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
queue_submit copies a held submission's command buffer infos into H.cbi[i], two entries each, the mirror prologue
and the part. Since the mesh emulation's pre-pass command buffers and cuts (vk_sync_pre, vk_sync_cut) a submission
carries up to three plus the cut parts, and the copy ran into the next held submission's entries and past the array:
the next held submission's copy then overwrote them, so a submission could go to the queue without its own last
command buffers and with another's twice. The buffer now has room for SUB_CBS (CHAIN_MAX + 3), and a larger count
stops the run with a message instead of overrunning.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The replay's GPU time covers only its own parts. Upload batches are submissions of their own, the ASTC decoder's
dispatches in them, so their time showed only as GPU idle "with it queued (untimed work or waits)": 10-16 ms a frame on
an RX 580 in Kokiri Forest on 0.7.1 while the game streamed in about 7 textures a frame, against 0.6-1.2 ms where it
streamed none. Each batch now writes a timestamp at its start and end, read when it retires; every 60 frames a perf line
gives the batches per frame and their GPU time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A split hands the part to the queue and seals its texture pool set; the next part takes another set of the ring and
refreshes its entries first. The splits for the mesh stages made 5 parts a submission and 6 set switches a frame at
2.3 ms of replay each (Kokiri Forest on 0.7.1, an RX 580: replay 32-38 ms a frame, the replay thread blocked on fences
26-35% of the time, 79 waits for a set the GPU still used). A cut (vk_sync_cut) ends the command buffer without
submitting it: the part and its pre-pass command buffer wait in a chain and go to the queue, in order, with the next
part that does, so the set is the same one throughout.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each emulated mesh draw ended the pass, ran its stages between four barriers and began the pass again: a pass of 20
emulated draws became 20 passes, and on an RX 580 6 to 7 ms of a frame's 30 ms of GPU time went to the gaps between
passes (gpu_passes in Kokiri Forest: 8.7-10 ms per frame outside the game's passes and dispatches, 6.3-7.7 ms of it in
273-306 gaps with barriers only; 71 emulated draws a frame, 36 of them indirect). Now the first emulated draw of a pass
ends the part there (vk_exec_split_now), so the pass begins a new part, and the stages of every emulated draw of that
pass, the indirect ones' ring entries included, go into the part's pre-pass command buffer (vk_sync_pre), which the
queue runs after the mirror prologue and before the part; the pass is not split again. NX2NAVI_MESH_EMU_BATCH=0 (Lama
patches: Mesh emulation before the pass) brings the split back.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On AMD's driver for Polaris (RX 580, 23.10) a store between a pool texture's access chain and its sample left the
quad's helper lanes out of the code in between: derivatives at a triangle's edge were garbage and edge pixels came out
dark, the dotted lines along the paths' triangles since 0.7.0 (frame dump f1714: the colour pass covers every pixel,
the depth test is not what drops them). Each access now notes its slot in a Private variable; before each return of
the entry function and before a kill, terminate or demote every noted slot is marked, an unset one going to a spare
slot past the pool. Accesses in loops or outside the entry function note theirs in a ring of 8, marked in a loop at
the way out. Checked with spirv-val on the 45 marked shaders of the dump.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Released textures kept, top texture levels left out, hot pools in system memory, the heap limit, the upload batch
limit, the kept ASTC buffer, mesh emulation and its arena and task records (greyed where the GPU has mesh shaders),
the overwritten-texture fix, the vector index fix, -O2 game code, pass times and the frame dump key. Each key gets a
row in the settings table; make_game.py reads guest_opt from nx2navi.ini when the environment does not set it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since 0.6.0 a task payload is 32 bytes longer than the program header's size (b6b76b7): Ocarina's foliage task payload
is 776 words, which 32 threads do not divide. The emulation refused those programs ("payload not a multiple of the
workgroup size"), their pipelines failed, and the task draws (grass on the moss, the door) went undrawn again. The
copies of the payload into and out of the task record take a last, partial round, where threads past the payload idle.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since 0.6.0 the translator sizes a task payload 32 bytes past the program header's size, for the header before the
program's data (b6b76b7): Ocarina's foliage task, 3072 bytes, now declares 3104. A record held 768 payload words, so
the emulation refused those programs ("payload too large") and the foliage went undrawn. Records are 780 words.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The emulation's barriers named only synchronization2's SHADER_STORAGE_READ/WRITE bits (above bit 31). With AMD's
driver for the RX 580 (23.10.01) the indirect dispatch of the mesh stage, which reads the {groups, task workgroups, 1}
the task stage had just written, launched no workgroup: mesh.txt showed 0 mesh groups started for every draw with a
task stage while its record held 32 x 12 x 1, and Kokiri's moss foliage and Link's door were missing. The masks now
also carry MEMORY_WRITE and MEMORY_READ, as the replay's general barrier does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Draws with a task stage drew nothing on an RX 580 although their task records ask for mesh groups (mesh.txt), and the
same converted stages produce vertices on lavapipe. Header words 4-7 now count, per submission, the emulated mesh
workgroups that started, those whose task record covers them, those that reached the output copy and the primitives
those declared; mesh.txt prints them after each draw.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c0_info keeps the last bank per stage and reuses it when the inputs (storage and uniform bindings, base instance) are
equal, but task and mesh shared the compute entry and the inputs do not name the stage, while the storage table sits at
0x670 for the task stage and at 0x770 for the mesh stage. When a program's task and mesh stages bind the same storage
buffers, the second stage got the first one's bank and read zero storage addresses. In a Kokiri Forest frame every
draw with a task stage (moss foliage, Link's house door) launched mesh groups that made no vertices, while mesh draws
without a task stage drew.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The game renders through one descriptor and samples through another that differs only in swizzle, and both read the
same pool memory. When one of them got memory of its own (read after an overwrite), the other kept reading the pool
bytes, which the first no longer updated. Now the image and its swizzle siblings become one image in memory of its own:
entry_of hands that image out for any swizzle of its key. If a live descriptor of another format or geometry reads the
same storage, the image stays in pool memory as before. The perf line counts both outcomes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The game overlaps transient render targets in its memory pools, and the replay binds their images into that memory.
An image of another format or size drawn over an image's memory leaves the GPU's tiled, compressed texels of the
other image there. Ocarina's volumetric fog reads its 360x202 RGBA32F fog-volume texture at the start of a frame,
before drawing it again, and the 1440x810 R11G11B10F bloom target had been drawn over that memory at the end of the
previous frame: the fog lighting took those texels as volume distances and types (values from 1e-12 to 3e33 in a
frame dump where the texture holds 9 to 50000), and drew teal splotches in Kokiri Forest's fog on AMD and NVIDIA.
Each pool-bound image the GPU writes marks the pool-bound images of another layout that overlap it; one read while
marked is dropped and comes back with memory of its own from then on, so it keeps what it last drew (the read that
found it gets an empty image once). NX2NAVI_TEX_CLOBBER=0 keeps such images in pool memory.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AMD's Windows drivers can read the wrong component through an access chain into a uniform block vector whose
component index is computed (the translator's c[n][i >> 2][i & 3] for an LDC with a register offset), the bug Ryujinx
works around with HasVectorIndexingBug. With NX2NAVI_VEC_INDEX_FIX=1 (or auto: AMD's own drivers) each shader is
patched in memory as it loads: the chain without its last index loads the whole vector, CompositeExtract takes each
component and OpSelect picks the indexed one. Off by default: it did not change the volumetric fog's teal blotches on an
RX 580, whose per-volume extinction reads its colour this way.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
F10 is the performance overlay's key, so a press dumped a frame and changed the overlay. dump_key = 1 or pause now
means the Pause key; scrolllock, insert, home, end, pageup, pagedown, f2-f7, f9 and f12 can be chosen instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A frame dump needed its frame number in advance (NX2NAVI_DUMP) or a depth target address (NX2NAVI_DUMP_AFTER); with
dump_key = 1 each press of F10 in the game window dumps the next frame to <dump dir>/f<frame>, as often as wanted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vk_pass_mark_cmd runs on the recorder thread for a pass mark packet; through vk.h's macro its vkCmdWriteTimestamp
became a packet of its own, put into the ring by the recorder thread while the replay thread was writing it. The ring
broke ("FATAL: vk_rec: unknown packet") on NVIDIA GPUs, where the recorder is on by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generated vertex shader wrote one vector per location. A fragment shader that packs two inputs into one location
(Component decorations: a vec2 at component 0 and another at component 2) then had nothing matching its second input,
whose value is undefined: wrong colours on the emulated foliage. The vertex shader now declares an output for every
input variable of the fragment shader, with its Location, Component, type and Flat, filled from those components of
the mesh stage's vector at that location (zero where the mesh stage writes none).
(cherry picked from commit c38eb31889314ebfb164ff9dffad5796eba46ed4)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 8 point-list mesh programs of Ocarina 1.1.1 (32 points, position and point size) were left unemulated. Their
indices are single uints and the point size goes to an extra vertex slot, which the generated vertex shader writes to
PointSize; the draw asks for a point list (the pipeline key's topology class follows the draw's primitive for mesh
draws), chosen from the mesh stage's OutputPoints. A mesh draw from a nonzero first workgroup is drawn from 0 as
before, now with a warning in the emulated path too. All 1016 programs convert and pass spirv-val.
(cherry picked from commit 8900aeaffa3264e4cc655ffd487cb2d2f3e3dd17)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The task records were a fixed 4096 per submission (3 KiB each): a dense patch of grass that launches more task
workgroups in one submission lost the rest silently. Their count is now a push constant (NX2NAVI_MESH_EMU_TASKS,
default 16384) and the arena defaults to 256 MiB. The header counts what the stages asked for past the capacities too;
before the counters start over they go to a readback ring, and the perf line reports the most one submission used of
the vertex slots, indices and task records, and the mesh workgroups that did not fit. The first draws the emulation
skips are logged with the reason.
(cherry picked from commit 81cfd91bf468f13e4debf287d080f96637a4c382)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without the extension every mesh draw was skipped ("mesh draws need VK_EXT_mesh_shader: skipped"): on an RX 580 the
game's grass and foliage were missing. The translator already builds each task and mesh program as compute code that
MeshSpirv.cs wraps into TaskEXT / MeshEXT modules; runtime/mesh_emu_spirv.c turns those modules into GLCompute ones:
outputs and payload move to workgroup memory, SetMeshOutputsEXT's counts are kept, and the entry function's end
reserves vertex slots and indices in an arena with atomics and copies the vertices and triangles out (task: the payload
and the mesh group count go to a task record, and the mesh dispatch to the draw record). A generated vertex shader
reads the vertices back for the game's fragment shader. Checked with spirv-val (Vulkan 1.3) on the 1016 task and mesh
programs of Ocarina of Time 1.1.1: 1008 convert and validate; the 8 point-list meshes stay unemulated.
vk_pipeline.c gives an emulated mesh pipeline a layout whose task and mesh bindings are visible to compute, with push
constants and a compute-side descriptor template, builds the generated vertex shader's graphics pipeline and the two
compute pipelines; vk_exec_draw.c prepares each mesh draw as before, then outside the pass zeroes the arena counters
(first emulated draw of a submission), fills a draw record, pushes the same descriptors to the compute bind point,
dispatches the task and mesh stages (direct, or from the indirect ring entry) and draws DrawIndexedIndirect from the
record. mesh_emulation = 1 turns it on; mesh_emu_mb sizes the arena (160 MiB).
(cherry picked from commit efc43b177694d8f8ce5700fcf28d80e889a45589)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A NX2NAVI_PROFILE profile needed the link map to name its Rips, and the launcher's builds keep none. A MinGW link keeps
the COFF symbol table in the exe, so prof_sampler_write now reads it (runtime/prof_syms.c, plain file reads) and appends
`sym <address> <function>+<offset>` for every exe address in the Rip and chain lists. NX2NAVI_PROFILE_REPLAY=1 samples
only the replay thread: with NX2NAVI_REPLAY_ASYNC=1 the render thread spends 98% of a 37 ms frame waiting, and the
replay thread (22 ms a frame recording Vulkan commands) is the one to look at.
(cherry picked from commit 9d3126ca780d7f0f0b91468d42b8ee70572747c8)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On an RX 580 with the scene at 854x480 the render passes take 11 ms of a 32 ms frame. The rest is the mirrors: 66 MiB
of CPU-written pages up and 76 MiB of compute-shader writes back each frame, mostly through six 6-16 MiB pools the game
refills every frame, with the GPU idle 7.8 ms a frame while those copies wait. With mirror_hot = N a mirrored pool whose
uploads, write-backs and merges average N percent of its size (and at least 1 MiB) a frame over 120 frames leaves the
mirror at the start of a submission: it comes off the mirrored list, the device address table points at the imported
buffer again, and the mirror buffer is freed after the next submission. Default 0, off.
(cherry picked from commit 82e5dcb682375fa48bbaffa1d61f825272544e36)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A dynamic resolution that keeps its targets at the largest size and draws the scene into part of them shows up as a
viewport smaller than the pass; one that resizes its targets shows up in the pass size. NX2NAVI_SCENE_SCALE=33 left
the handheld scene pass at 1440x810, so this tells which of the two the game does there.
(cherry picked from commit af7abe36b0b15c5a63b354d2870543987d1f4b1a)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Switch can present its Joy-Con over USB from its boot menu's tools as a plain HID joystick, "Nyx Joy-Con" (VID
0x11EC, PID 0xA7E1): X, Y, Z, Rz for the sticks, a hat for the D-pad and twelve buttons. SDL has no gamepad mapping for
it, so it was a joystick only and input.c, which opens gamepads, did not see it ("input: no gamepad"). scan_pads now
gives every known joystick without a mapping one built from its own GUID (buttons 1-4 B, A, Y, X as south, east, west,
north, then L, R, ZL, ZR, Minus, Plus and the stick clicks), and logs any other unmapped joystick once with its name,
ids and GUID.
(cherry picked from commit ed4c68c3e8460e247bab3ad4f3f02e2672868ddf)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On 0.6.1 the mirror sync already leaves flush ranges of write-watched pools uncopied (0101a87), which covers what this
did; the key stays known and does nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No vendor profiler covers an RX 580 (RGP supports RDNA only) and RenderDoc cannot capture this program, so nothing
showed where 38 ms of GPU time per frame went. With NX2NAVI_PASS_TIMES=1 every pass mark also writes a timestamp at
its two points into a query slot pair of its ring slot. The replay thread takes in the marks whose submission has
finished, resets their slots on the host (hostQueryReset) and sums their time per kind of pass (size, attachment
formats, first fragment or compute shader); every 600 frames the log lists the 15 with the most GPU time per frame.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An RX 580 (8 GiB, AMD 23.10) shows its memory as a 6 GiB device-local heap and a 2 GiB device-local, host-visible
one, and Windows granted the game 5.1 GiB of the first. A save load put 5.6 GiB of textures, VRAM mirrors and pools
into the first heap while the second held 69 MiB, and the next submit failed with VK_ERROR_OUT_OF_DEVICE_MEMORY;
budget flags on the texture allocations alone did not change that. VMA now gets heap limits (pHeapSizeLimit) when
the device has two or more device-local heaps: each heap's budget at device creation less a tenth (at least 256 MiB)
for memory VMA does not see. Every allocation past a limit goes to the next memory type that allows it.
NX2NAVI_VRAM_HEAP_LIMIT: auto, 0 (off) or MiB for the largest heap. A physical pool that finds no video memory left
takes any memory type it may live in instead of failing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An RX 580 (8 GiB, AMD 23.10) shows its memory as a 6 GiB device-local heap and a 2 GiB device-local, host-visible
one. Asked for device-local memory without a budget, VMA chose the first heap every time: a save load put 5.6 GiB
there against a budget of 5.1 GiB while the second heap held 69 MiB, and the next submit failed with
VK_ERROR_OUT_OF_DEVICE_MEMORY. create_tex now allocates with VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT: device-local
memory of any heap first, then any memory type the image allows, and only then past the budget as before. The log
names images placed outside the first device-local heap.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A save load made thousands of textures between two replay submissions, and all of them went into one upload batch:
about 1.5 GB of raw ASTC blocks plus the decoder's work in a single submission, which AMD's 23.10 driver on an RX 580
refused with VK_ERROR_OUT_OF_DEVICE_MEMORY ("vk: upload submit failed (-2)"). The outermost vk_upload_end now submits
the open batch once its staging holds NX2NAVI_UPLOAD_BATCH_MB (256 by default; 0 = no limit). The batch still precedes
the replay submission that uses its textures, and its staging goes as it retires.
When a submit fails for lack of memory, vk_mem_oom_report logs each heap's use and budget as the driver counts them,
VMA's blocks and allocations there, the open and in-flight upload batches, the VRAM mirrors and pending releases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_stripes started NSTRIPES - 1 threads for each of its two phases, about 300 new threads a second while a movie
played. Every DLL in the process sets itself up for each new thread; on an RX 580 with AMD's 23.10 driver the process
commit grew by about 300 MB a second during the title movie until Windows ran out of commit (45.7 GB, FATAL "movie:
out of memory for a 1920x1080 frame"). The helpers now start once and wait for each batch; one caller at a time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>