1281 Commits
Author SHA1 Message Date
seedds 0293739df4 game: Guacamelee! 2 1.0.4 reaches its opening on Mac
Register the Switch update and the 425 shaders read by the DrinkBox container parser. Record the depth mode selected by the guest so the pipeline prebuild uses the same vertex entry as live rendering.

Verify the Mac opening, stereo PCM, both DLC licenses and the bundled pipeline archive. Build and integrity-check the unsigned IPA. Movement, combat, co-op, DLC gameplay and an iPhone run remain open.
2026-11-24 02:31:25 +08:00
seeddsandcrt-000 973f2d73b8 nvn/mtl: add opt-in bounded depth-write snapshot copies (DM_NVN_FB_DEPTH_RECT)
Track bounded depth/stencil writes per depth snapshot cache entry so
fb_depth_snap blits only the dirty rectangles written since the previous
snapshot instead of copying the entire attachment on every game barrier
(see #3227).

Controlled by DM_NVN_FB_DEPTH_RECT via sw_mode (default 0; 1 enables, ab
alternates under DM_AB for matched-thermal/matched-upload testing before
enabling globally):
- Keys incremental state by root MTLTexture and MTLHeap plus
  nvn_sparse_gen(), recording draw writes right before emission and
  scissored depth-stencil clears in clear_ds_tri.
- Snaps dirty rects outward to 16-pixel tile boundaries and merges any
  overlapping rects so Metal 4's concurrent copy encoder blits strictly
  disjoint tiles (falling back to a single whole copy when multiple
  rects cover at least 75% of the level).
- Skips the copy and keeps the render pass open when nothing wrote depth
  since the previous snapshot.
- Enforces full-copy fallbacks for non-Load or layered passes,
  enc_r_begin, MSAA resolveTexture, blits/uploads, heap aliases, sparse
  pools/remaps, waiting clears, DM_NVN_FB_SNAP=all, point primitives
  beyond scissor (bounded by scissor only), mesh-task draws, and
  unbounded viewports.
- Adds GPU readback tests in dm/gfx/tests/t_feedback.m covering partial
  tiles, overlapping merges, aliased serials, no-write skips, and all
  full-copy fallbacks.

Co-authored-by: crt-000 <[email protected]>
2026-11-24 02:27:26 +08:00
seeddsandEric Schaal 685d2aecf0 gfx/nvn: Metal 4 mesh pipeline bases, mesh_pairs.tsv prebuild, and prefetch
Compile and archive format-unspecialized Metal 4 mesh pipeline bases (task + mesh + pixel), specialize them across attachment/blend/depth states at draw time, proactively prefetch them on NVN program creation, and prebuild static (task, mesh, pixel) triples offline and on device via mesh_pairs.tsv.

- Reflection & chain: mark mesh shaders that emit per-primitive outputs with mesh_stage.prim in dmsh_meshstage.py / dmsh_build.py and bump DMSH_CHAIN to 3fe2e3787fdf.
- Host Metal 4 mesh bases (nvn_geometry.inc, nvn_mtl.m): build, deduplicate, archive, compact, and specialize Metal 4 mesh bases (preserving mtk_spill payload clamping and tagging dm_mesh_nop); fall back to whole pipelines for mesh_stage.prim and reads_prim_id as a workaround for an Apple Metal 4 compiler/driver bug (verified on Apple M6, macOS 27.2.1 / Metal 32023.922) that non-deterministically zeroes per-primitive outputs and [[primitive_id]] on specialized mesh bases; skip recording M manifest rows when a base hits archive; prefetch mesh bases from mtl_prog_prefetch() on a bounded background queue (DM_NVN_MESH_PREFETCH=0 disables).
- Static mesh triples & prebuild (shader_split.py, pso_offline.py, pack_app.py, build_ipa_from_nsp.py, build_ipa.sh, regress.py, nvn_mtl.m): emit mesh_pairs.tsv (M\t<task or ->\t<mesh>\t<pixel or ->), compile eligible mesh bases into MTL4Archive via metal-tt, route depth-only / non-default-constant triples to rest_pairs.tsv, and load mesh_pairs.tsv / DM_MESH_PAIRS in pso_prebuild().
- Tests & docs: extend t_pso_archive, t_pso_bundle, test_pso_offline, test_dmsh_meshstage, test_dmsh_pairs, and test_nsp_incremental; update env_switches.tsv, docs/reference/shaders.md, and Ocarina of Time's note.

Checked: Mac host build, Metal 4 GPU tests (t_pso_archive 441/441 + 15/15 restarts, t_pso_bundle 118/118, t_mesh_first_use, t_pso_stall 124/124), Python suites (test_pso_offline, test_nsp_incremental, test_nsp_mac_app, test_docs, test_env_switches, test_nsp_chain, test_game_profile, test_dmsh_pairs, test_dmsh_meshstage prim checks), regress.py on Fast Fusion (PASS), and regress.py + 3-way cold-start A/B/C on Ocarina of Time (mesh stall 15,847.5 ms -> 6,056.4 ms with prefetch -> 2.6 ms with offline mesh bundle).

Front-ends: break: shader libraries must be rebuilt for chain 3fe2e3787fdf.
Co-authored-by: Eric Schaal <[email protected]>
2026-11-24 02:17:20 +08:00
seeddsandThomas Liu 61e97458d2 nvn/latch: gate on GPU deadline and exit on late GPU or skipped ticks
On the 60 Hz display link at frame latency 1, games whose CPU present
arrives early (< room / 2) while their GPU rendering plus MetalFX
present exceeds update.targetTimestamp (~16.6 ms) locked to 30.0 fps
immediately after a drain into the late latch (Fire Emblem Fortune's
Weave on M5 Max and Xenoblade Chronicles: Definitive Edition on M5,
#3251): 300 latched presents across 300 callbacks with 0 timeouts at
33.34 ms p50, while DM_PRESENT_LATCH=0 held 60 fps.

CAMetalDisplayLink's targetTimestamp is the GPU completion deadline for
signalDrawable:, not just CPU commit. Missing it at latency 1 skips the
next 60 Hz callback (33.34 ms gap); while the game sleeps in
mtl_link_wait_ticks, the queue stays empty so the next callback latches
again into the same miss, and because CPU arrival stays inside the wait
(0 timeouts, age < 0), nvn_link_drain_next never saw a fallback.

Two general host fixes in nvn_link_drain.h, nvn_link_latch.h, and
nvn_mtl.m:
- Entry gate (nvn_link_latch_spare, link_gpu_lead): when NVN per-frame
  GPU completion timing (g_gpu[frame % GRING]) is available, include it
  plus smoothed present-pass GPU time (g_present_gpu_s) and require
  gpu_lead < room - tick / 8 alongside the CPU lead limit. Heavy scenes
  keep the queue's 1-frame slack instead of draining into a 30 fps lock,
  while light games and 33 ms ProMotion windows keep latching.
- Runtime exit (nvn_link_latch_check, present_now): check f.GPUEndTime
  against update.targetTimestamp in present_now's MTL4CommitOptions
  feedback handler (covering NVN, Vulkan, and GL) and watch for skipped
  callbacks right after a latched present (cb_gap > 1.35 * tick_period,
  < 0.25 s). Exit immediately on any late-GPU miss, a single skipped
  tick right after entering a drain, or 2 skipped ticks without
  LINK_LATCH_GIVE_UP clean latched ticks between them, skipping the
  wait for one tick to restore a standing frame and trigger backoff.

Checked on Apple M6 / macOS 27.2.1: t_link_latch (32/32), t_link_drain
(99/99), t_link_latch_cb (26/26, including NVN g_gpu gating, real Metal
4 GPUEndTime > targetTimestamp exit + backoff, and skipped-tick exit),
t_present_alloc (13/13), t_present_rescue (167/167), t_link_ticks
(95/95), dmhost build + --check-tables for 04007EF01F8AE000, test_docs
(7/7), and regress.py check --quick on Hades (0100535012974000: PASS,
60.8 -> 60.8 fps, latch enqueue-to-target-display 41.5 -> 24.5 ms with
live late-GPU exit/backoff). Open: reporter gameplay retests on
Fortune's Weave and Xenoblade Chronicles: Definitive Edition.

Part of #3251.

Co-authored-by: Thomas Liu <[email protected]>
2026-11-24 02:02:18 +08:00
seeddsandDominique Agnes df20cc2525 packing/shader_split: parse DrinkBox SHADERS containers (PR #2810)
Add a structural reader (dbx_shaders) for DrinkBox Studios' SHADERS\0
container (shaders.dat.nx in Guacamelee! STCE and Guacamelee! 2),
verified against Guacamelee! 2's ExeFS/main (+0x62ba0 container loader,
+0x673f0 NVN blob loader) and real v0/v262144 RomFS images.

Parses the endian flag, UTF-8 string table, 127-byte uniform table,
shader data blobs (20-byte header + uniforms + code + control), and
trailing 29-byte entry table to exact EOF, validates non-overlapping
spans, graphics SPH bounds (>= 0x80), and entry-vs-SPH stage agreement,
and registers #SHDR# in SINGLE_STAGE for separable-program pairing.
Updates dm/gfx/nvn/dmsh_chain.h, adds unit tests, fuzz seed, and docs.

Co-authored-by: Dominique Agnes <[email protected]>
2026-11-24 01:59:29 +08:00
seedds f3cbbd726d game: Shredder's Revenge 1.0.9 runs offline
Return EOS_NotImplemented when the EOS SDK is unavailable. The generic
import stub had reported success, leading the game to dereference a null
platform at boot. In local character selection, function-match the game
routine that still tries two EOS lobby updates and skip those calls.

Register the game and its 88 shaders. The split uses HenWorks' MGFX v10
and ZXNB reader, already credited in 3bcf8213.

Verified the opening, character selection, save and reload, and Episode 1
at 60 fps on an Apple M6. The unsigned IPA passed archive validation.
Hades passed the offline startup regression. iPhone gameplay is untested.
2026-11-24 01:33:27 +08:00
seeddsandHenWorks 3bcf821365 gfx/tools: read MGFX v10 effects and raw-DEFLATE .zxnb assets (PR #2546)
Extend mgfx_effect to parse MonoGame MGFX version 10 structurally alongside
versions 5 and 8 (i32 effect-level counts and indices, -1 pass sentinel,
trailing MGFX signature, profile-agnostic validation, and clean truncation
errors). Add zxnb_effect to peek raw-DEFLATE .zxnb headers and inflate only
.EffectReader streams, excluding SoundEffectReader and other non-effect
assets without decompressing them in full. Update nxcx_shaders' magic list
and DMSH_CHAIN.

Validated on Teenage Mutant Ninja Turtles: Shredder's Revenge
(0100FE701475A000, update 1.0.9): baseline found 5 shaders with 11 [RED]
lines; with this change, shader_split.py finds all 88 unique shaders (64
from 6 main effects, 24 from 13 Content/Shaders/*.zxnb effects) with zero
[RED] lines, skipping all 1,534 non-effect .zxnb assets, and dmsh_build.py
translates and compiles 88/88 to Mac Metal.

Completes PR #2546 (the Vulkan entry-point rename already landed in 80075911).

Co-authored-by: HenWorks <[email protected]>
2026-11-24 00:34:16 +08:00
seedds d58f8a7954 packing/uepak: read shared v8 shaders and port Oceanhorn 2
Choose inline and shared Unreal shader sources from the pak directory for
both version 8 footer layouts. Oceanhorn 2's five-slot pak has two shared
version 1 archives. The existing reader decodes their 4,496 records into
4,442 unique shaders.

Register update 1.1. On Apple M6 the Mac run reached the first dock with
the iPhone-sized alias region and held a 33.3 ms median frame time. The Mac
app passed signature verification and the unsigned IPA passed ZIP CRC
verification. The Kakarot 1.70 pak scan plan matched the baseline. On-device
gameplay and save reload are still open.
2026-11-24 00:11:21 +08:00
seeddsandAdem Rosic 6724d64d42 host/audio_input: select and unmute matched DualSense USB mic
A DualSense or DualSense Edge connected over USB appears as a standard
CoreAudio input device, but its hardware mic mute and audio power-saving
states are controlled by Sony vendor HID output report 0x02 (SetState),
so capture can stay silent until SetState enables the built-in mic.

When AUHAL prepares a USB DualSense audio input on Mac, correlate that
AudioDeviceID to its own physical USB HID controller using CoreAudio's
ModelUID (054C:0CE6 / 054C:0DF2), AudioBox BoxUID (@locationID) or
AppleUSBAudioEngine DeviceUID, and SerialNumber, failing closed on
mismatch or ambiguity rather than grabbing the first Sony pad. Skip
synthetic GameController HID entries and non-gamepad interfaces, then
open the matched HID device shared and send SetState 0x02 with only the
mic volume, audio control, mute LED, and mute/power-save bits enabled.

Label USB DualSense / DualSense Edge inputs "(USB)" in the Mac launcher
using CoreAudio ModelUID directly (no IOKit import or link change).
Document why Bluetooth DualSense mic capture is unusable on macOS in
docs/reference/audio.md and add pure-C unit tests for the report and
USB audio-to-HID matcher.

Revises PR #2999.

Co-authored-by: Adem Rosic <[email protected]>
2026-11-23 23:20:04 +08:00
seeddsandUserDerezzed d2939c1eb4 packing/shaders: report post-compile phases through DMSH_PROGRESS (PR #2684)
After the last regular shader, dmsh_build.py wrote no more progress to DMSH_PROGRESS, leaving ShaderWatch frozen at a stale ~99% count through mesh-library compilation, library-image publishing, and the c1_guard.py and cb_extent.py table passes. ShaderWatch also mapped every step other than cache check back to compiling, hiding compiling RT library.

Have dmsh_build.py report all of its phases directly through DMSH_PROGRESS: flush the final counts of cache check and compiling, flush immediately on step changes, report compiling mesh libraries across _mesh, pass an optional on_progress callback through publish_library to shader_lib.write for writing the library image (or writing the Mac / iOS library image on dual-image builds, with file counts and bytes written), and report c1 guard and uniform read extents before unlinking DMSH_PROGRESS at exit. Simplify ShaderWatch to forward step, counts, unit, and formatted byte notes straight from DMSH_PROGRESS. Regenerate dm/gfx/nvn/dmsh_chain.h.

Checked: 159 tests across test_nsp_mac, test_shader_lib, test_shader_toolchain_cache, test_nsp_chain, test_dmsh_abi, test_dmsh_code_fp, test_pr_areas, test_usage, and test_docs; ruff check (0 new findings).

Co-authored-by: UserDerezzed <[email protected]>
2026-11-23 22:14:51 +08:00
seeddsandYubiSmart Labs 811091e72d packing/ue3: read wide chunks, small-window zlib, and control-first records (PR #2808)
Support 64-bit UE3 chunk headers and block tables, full RFC 1950 DEFLATE headers (including small windows such as 0x28 0x15), and control-first shader records with optional trailing data and headerless compute shaders, while preserving zero-padded package tails and regenerating DMSH_CHAIN.

- shader_split.py (ue3_body): select 32-bit or 64-bit chunk field widths from the tag's high word, validate block tables, per-block decoded sizes, and chunk totals, and match RFC 1950 zlib headers instead of only 0x78.
- shader_split.py (ue3_shaders): parse validated control-first records via glslc_stage alongside legacy code-first records.
- profile_guess.py (ue3_oodle_package): detect Oodle blocks for both 32-bit and 64-bit UE3 chunk headers while excluding stored uncompressed blocks and truncated headers.
- dmsh_chain.h: regenerate DMSH_CHAIN for the shader_split.py change.
- tests & docs: extend test_ue3_cache.py (11 tests), add Ue3OodlePackages tests in test_profile_guess.py, and update docs/reference/shaders.md and docs/agents/symptoms.md.

Checked: test_ue3_cache (11), test_profile_guess (42), test_nsp_chain (26), test_docs (7), test_shader_split_progress (2), and a full UE3 Oodle probe + shader_split on Borderlands: Game of the Year Edition (010064800F66A000, 922/923 .xxx packages detected, all 28,479 shader rows and 2,504 pairs byte-identical to the profile).

Co-authored-by: YubiSmart Labs <[email protected]>
2026-11-23 22:01:21 +08:00
seedds 62f65f70aa host/audio: default Mac microphone gain to 1x and guard AUHAL render buffers
Lower the default DM_MIC_GAIN from 4 (+12 dB) to 1 (unity) in both audio_input.c and dm/games/settings.tsv. In Ocarina of Time Humming mode, +12 dB of host boost raised -40 dBFS peak / -44.8 dBFS RMS room noise to -28.0 / -32.7 dBFS, keeping the game's end-of-phrase silence detector from finalizing even after matching the melody in DTW. At unity gain the same phrase triggers in-game playback and quiet -36 dBFS singing still passes, while DM_MIC_GAIN=1..8 remains available for quiet microphones.

Also restore mBuffers[i].mData before AudioUnitRender and read the rendered mData pointers afterward in audio_input_mac.m, and record in docs/reference/audio.md the confirmed overlap between the #2796 44.1 kHz output crackle report and #3059 (resolved by 2edad182).

Refs #2796

Front-ends: dm/games/settings.tsv changes DM_MIC_GAIN's default from 4 to 1; front ends reading settings.tsv or repacked launcher.json pick this up automatically.
2026-11-23 21:23:02 +08:00
seeddsandnasso 3f37dd3dce host/album: save nn::album::SaveScreenshot buffers as local PNGs
Pokémon Pokopia's in-game camera exports photos to the console album by decoding its gallery JPEG with nn::image::JpegDecoder's default PixelFormat_Rgba32 into a 1920x1080 RGBA8888 buffer (0x7e9000 bytes) and calling the 4-argument nn::album::SaveScreenshot with ImageSize = 1. Both SaveScreenshot overloads in hle_offline.c previously logged no album and returned RES_FAIL.

Move nn::album hooks to dm/host/hle_album.c and implement the 4-argument, 5-argument (with ImageOrientation 0..3), and 7-argument (with Uid list) SaveScreenshot overloads using CoreGraphics + ImageIO:
- Validate buffer pointer, ImageSize (0 = 1280x720, 1 = 1920x1080), byte length (>= w * h * 4), and orientation; rotate RGBA8888 pixels when orient != 0 and encode opaque RGB to PNG.
- Publish atomically via mkstemps + hard link/unlink (with rename fallback) into DM_ALBUM_DIR, falling back to <DM_ROOT>/album then <dirname(DM_SAVE)>/album, creating the folder lazily on first save.
- Set default DM_ALBUM_DIR to ~/Pictures/nxnative/<title ID> in dm/mac/launcher.c and Documents/album in dm/ios/Sources/main.m (both with overwrite=0), and link -framework CoreGraphics explicitly in dm/host/Makefile.
- Leave SaveCurrentScreenshot, SaveAndShareScreenshot, GetSharePostedLastUrl, and ShowAlbumFiles failing as before.

Checked: t_album (55/55 checks, plain and ASan/UBSan), t_symbols, Pokopia Mac host build (0400A3A01EE4C000), iOS gen_build.py + iphoneos clang syntax check on hle_album.c and main.m, test_nsp_mac_app.py -k test_launch (2/2), env_switches.py --check, test_docs.py (7/7), test_usage.py (6/6), and LLVM 23.1.4 clang-tidy on hle_album.c, hle_offline.c, and t_album.c (0 findings). Live in-game Pokopia camera export remains to be confirmed in play.

Fixes #3211
Co-authored-by: nasso <[email protected]>
2026-11-23 19:58:09 +08:00
seeddsandEriksrevenge1 a694f17992 host/memory: default Switch 2 to 128 GB Mac alias and pool limit (PR #3188)
Give Switch 2 (spec: Ounce) titles a 128 GB default alias region on Mac in hle_svc.c while keeping iOS on the profile's mem_alias, clear DM_ALIAS_SIZE in region_check so Switch 2 probes run in the host's console-sized alias region, and enforce Horizon's physical-pool limit (mem_map_limit) by default on Switch 2 while keeping explicit on/off overrides and Switch 1's existing default.

This resolves the Switch 2 startup allocator failures diagnosed in PR #3188 (two 60 GB reservations exceeding 64 GB and an uncapped physical-memory probe nulling the allocator) in the host without putting a 128 GB reservation into provisional iOS profiles.

Co-authored-by: Eriksrevenge1 <[email protected]>
2026-11-23 19:42:47 +08:00
seeddsandkepler1986 de5b17e8a3 game: port Oceanhorn 1.0.1
Register the update with its measured heap, one copy of the SDK, and the depth mode the game selects. Generate the 172 shader entries with the shared VFS2 reader and refresh the shader chain header for that reader.

Verified the opening and first autosave reload on an Apple M6 Mac mini, built and checked the unsigned IPA, and ran 93 focused tests.

Co-authored-by: kepler1986 <[email protected]>
2026-11-23 19:31:02 +08:00
seeddsandkepler1986 ba82ccb91d nvn, packing/shader_split: validate WriteTexels bounds and parse VFS2 archives (PR #2906)
Extract the still-missing general fixes from PR #2906 (texture-builder defaults already landed in fa2ed14d, NRO alignment in 17454fc3, and DrinkBox SHADERS is handled in PR #2810):

- Validate mip level, sign, mip dimensions, and layer bounds at the top of write_texels (including levels == 0, 1D/1D_ARRAY mip height = 1, and zero-sized regions) so out-of-range block-linear uploads cannot fall back to the unchecked whole-level scratch buffer, mutate earlier slices, or mark textures CPU-written.
- Parse Cornfox & Bros. VFS2 archives by their directory, file, and optional name tables (matching 4-byte 'VFS2' for any directory count and supporting modes 0 raw, 1 bitwise-NOT, and 2 u32-length-prefixed zlib), peeking 4 bytes to skip non-shader assets and failing loudly via red() on malformed containers or damaged shader entries.

Checked: t_cpu_tex --metal (126 checks), t_nvn (526 checks), all 211 test_split_* tests (including test_split_vfs2), test_fuzz_corpus (37 tests), test_docs (7 tests), fuzz_shader_split random engine (230,053 runs, 0 findings), lint_python/ruff (0 new findings in changed files), and Oceanhorn 1.0.1 data.vfs end-to-end (362 GLSLC records -> 172 unique shaders: 57 vertex, 115 pixel, 0 [RED] lines).

Co-authored-by: kepler1986 <[email protected]>
2026-11-23 18:49:19 +08:00
seeddsandMomo bf8d4aded1 host/friends: open the notification queue offline (PR #3224)
Beach Buggy Racing 2: Island Adventure (0100C43012344000, base v0,
SDK 10.8.2) quits 0.3 s after nnMain with "Unable to init game." and
exit(-1) because VuGameServices treats a failed
nn::friends::NotificationQueue::Initialize(const Uid&) as fatal.

On Horizon, friend:u's notification service is a local queue that opens
and clears offline while staying empty. Return RES_OK from both
NotificationQueue::Initialize overloads and NotificationQueue::Clear in
hle_friends.c, keeping Pop empty, GetSystemEvent quiet, Finalize a
no-op, and remote friends operations failing.

Update t_friends, docs/reference/services.md and docs/agents/symptoms.md.

Verified: t_friends (61 checks, plain and ASan/UBSan with -Wall -Werror),
docs_symptoms.py, test_docs.py (7 tests), Mac host build
(010015100B514000), and PR #3224 CI. Existing game callers and full
Beach Buggy Racing 2 gameplay with .apf shader support remain unverified.

Co-authored-by: Momo <[email protected]>
2026-11-23 18:40:53 +08:00
seedds 00f98d5db0 nvn/images: avoid relocking the registry for buffer writes
The argument encoder already owns the texture and sampler registration
lock when a writable buffer image schedules sparse shadow writeback.
Read the registration under that lock and keep the original writeback
range. The nested acquisition terminated Sparks of Hope before its
title screen on macOS.

Exercise the writable buffer image through the production encoder.
Checked that case, sparse shadow writeback, NVN tests, and gameplay.
2026-11-23 18:23:45 +08:00
seeddsandJoseph Hau b9a3364d5e host/nvn: guard edge-snapshot OOM and add crash/VA diagnostics
Check malloc and shared-buffer destinations in pkg_edges_take before copying.
When an edge-snapshot allocation fails (such as edge 1 returning NULL after
edge 0 succeeds under iOS virtual-address exhaustion), free any partial edge
snapshot and clear both edge lengths so pkg_edges_clean takes the conservative
re-upload path rather than dereferencing NULL or skipping modified edge bytes.

Separately add lightweight ownership and crash diagnostics to investigate the
open iOS VA exhaustion and uncaught std::bad_alloc:
- Track live/peak heap edge-snapshot allocations, sizes, and failures in
  pkg_edges_take / pkg_edges_drop / pkg_edges_gpu / NvPkg dealloc, and log the
  first failure once via RED_ONCE.
- Track lib_from_map owned shader-library count, bytes, and dispatch_data_create
  failures in the periodic memory line.
- Preserve image basename, image-relative offset, and raw PC in crash_off and
  host-thread dumps when dladdr returns <redacted> or omits the symbol name.
- Print sub-GB free gaps in MB/KB/B and list per-class region counts plus the
  four largest file and non-guard other regions in dm_vm_census.

Checked t_pkg_edges_oom (50 checks), t_library_data (658 checks), t_crash_diag
(12 checks), t_nvn, check_t_readback (335 cases x 2 with Metal validation),
Mac host build, iphoneos27.2 syntax check across all 5 modified sources, and
test_docs.py (7/7). Underlying iOS VA exhaustion remains open pending iPhone
retest.

Refs #3240

Co-authored-by: Joseph Hau <[email protected]>
2026-11-23 17:22:36 +08:00
seeddsandVertu User 65b1523b76 rewriter/spin, host/fpslock: clear decode cache per head; discover Frostbite frame regulator (PR #3234)
Rewriter (dm/tools/patch_nso.py):
- Check DATA_BLOCKS and spin_quick(T, hi) at the start of spin_region before calling spin_lock(T), guard spin_lock(a) on its first instruction's mnemonic before decoding lookahead words, and clear spin_dec in spin_region's finally block after every head.
- Bounds spin_dec to <= ~135 entries per head instead of growing with text size per worker (which passed 24 GB on EA SPORTS FC 27 1.8e's 185 MB main; full 1.8d main rewrite now peaks at 2.20 GiB RSS), while cutting spin-search decodes by 39% and time by 30% with byte-identical output.
- Add synthetic unit tests in test_spin_waits.py and drop the two fixed pyright reportOptionalSubscript entries from lint_python_baseline.tsv.

Host (dm/host/hle_fpslock.c):
- Extend fb_find() to read GameRenderSettings.Enable from Frostbite reflection and locate the unique fmov vD.2d, #30.0 / adrp+ldr / stur qD, [xR, #8] regulator store (failing closed with [RED] on ambiguity), verified on EA SPORTS FC 27 v0 (0xd9f4e18), 1.8d.310c (0xda20e38), and 1.8e.50bc disassembly (0xda5d0f8).
- Remove the build-gated FC 27 row from k_locks[] and its HOST_BINDING entry in docs_patches.py, add dynamic and negative cases in t_fpslock.c, and update docs and generated indexes (including the 1.8e.50bc iPhone 17 Pro and Mac 5K notes).

Co-authored-by: Vertu User <[email protected]>
2026-11-23 17:09:45 +08:00
seeddsandGabriel Tran 7d38c8e0a0 host/loader: restore iOS-only alias cuts on Mac (PR #3218)
Xenoblade Chronicles 3's six build-bound Monolith allocator cuts shrink
its 60 GB reservation to 4 GB and its first arena to 512 MB to fit an
iPhone's 4.375 GB alias region. Because patch_nso.py rewrites modules
once for every platform, the Mac ran that compact layout too, where the
first chapter's cutscene after the mid-scene battle returns null for a
0x217a0-byte allocation (sig=11 addr=0x8 at main+0x43060, issue #3149).

Extract the Mac restoration policy from PR #3218 without its unverified
DM_WIDE_ALIAS / wide-IPA entitlement changes or the 288 MB compact-arena
change, and generalize it to cover both build-bound CUTS and matched
MATCH_CUTS:
- Rewriter (patch_nso.py, nso_match.py): mark iOS-only alias cuts via
  ALIAS_CUTS or alias_only=True on MATCH_CUTS, assert the cut bytes
  survive later rewrite passes, and emit # ALIAS_CUT rows in fixups.tsv.
- Host (dm.h, hle_svc.c, loader.c): share dm_alias_size() in dm.h so
  standalone loader tests keep linking; on Mac, undo_alias_cuts restores
  original bytes before sealing text when the alias region is at least
  the Switch's 64 GB (DM_SWITCH_ALIAS), failing closed on byte mismatch,
  and keeps cuts when DM_ALIAS_SIZE < 64 GB or DM_KEEP_ALIAS_CUTS=1.
- Packing (scripts/build_ipa_from_nsp.py): set DM_KEEP_ALIAS_CUTS=1 in
  region_check so derived-profile checks still measure the iPhone binary.
- Profile (dm/games/010074F013262000/patches.py): list all six Monolith
  allocator cuts in ALIAS_CUTS while keeping the 512 MB iOS cut intact.

Checked: test_patches, test_nso_match, test_nsp_incremental,
test_ipa_unsigned (154/154), test_env_switches, test_docs (8/8), ruff
(0 new findings), t_nro / t_symbols / t_svc_memory (plain + ASan/UBSan
for t_nro and t_symbols), Mac host build for 010074F013262000, iOS
syntax check for loader.c and hle_svc.c, and DOOM 3 (010029D00E740000)
full-route regress.py check + live HUD gameplay.

Open: rerun Xenoblade Chronicles 3 Handheld mode (Zstd worker crash in
issue #3149) with the restored 60 GB layout before associating it with
the same cause, and fingerprint XC3's allocator functions into
MATCH_CUTS (build -> game) once XC3's main binary is mounted.

Co-authored-by: Gabriel Tran <[email protected]>
2026-11-23 17:05:56 +08:00
seedds ef8b25d2c5 nvn/vertex: supply default W=1.0 for absent attributes (PR #3237)
Splatoon Raiders' Slosher airborne ink disappeared because its alpha-tested depth vertex shader reads attribute 12.W while the draw binds only attributes 0-9. Both the native vertex-descriptor fallback and the pulling vertex fetch returned (0, 0, 0, 0) instead of NVN/Maxwell's default float vector (0, 0, 0, 1.0) in raw register bits, dropping opacity to 0 and leaving the paired depth-EQUAL color pass empty.

Root-cause fix in both NVN vertex-fetch paths:
- nvn_mtl.m: store (0, 0, 0, 1.0) at offset 16 of slot 30's 64-byte vertex_constants buffer and bind absent attributes (!ka.fmt) there in pso_desc, keeping offset 0 (zeros) for inactive shadow inputs and unknown non-zero formats; keep non-zero formats in pull_layout_fill for streams without buffers so dm_fetch distinguishes them from absent attributes.
- dmsh_pull.metal: return uint4(0u, 0u, 0u, 0x3f800000u) for format 0 in dm_fetch and uint4(0u) for invalid or unmapped streams, regenerating dmsh_chain.h.
- Tests and docs: add t_default_attrib (float/uint/int absent attributes, unknown format, and shadow-input pipelines), extend t_pull, and record the finding in docs/reference/rendering.md, docs/agents/symptoms.md, and dm/games/0400380020056000/README.md.

Checked on Apple M6 (macOS 27.2.1): t_default_attrib (12/12), t_pull (454/454), t_pull_inv (6/6), t_vbuf (143/143 x2), t_float_pad (16/16), t_vin (14/14), test_dmsh_pull.py (8/8, macOS and iOS Metal compile), test_docs.py, test_nsp_chain.py, LLVM 23.1.4 clang-tidy (0 ratchet changes), Mac host build, and regress.py check on The Binding of Isaac: Rebirth (01009BC00C38A000, CHANGED on the expected 9 pulling variants, 19/19 shaders, 0 RED, 59.4 fps). Splatoon Raiders airborne ink was confirmed by the PR author on M4 MacBook Air (macOS 27.0.1); iOS gameplay remains unchecked.

Fixes #3181
Co-authored-by: kaz3tt <[email protected]>
2026-11-23 16:59:23 +08:00
seeddsandIsaac Pateau 82cad791cd host/fs: release cache storage mount names at Unmount (PR #3217)
Taiko no Tatsujin: Rhythm Festival mounts cache storages one index at a time under one mount name, calling Unmount between indices. Host Unmount previously released only add-on content mounts, so the second MountCacheStorage returned RES_PATH_EXISTS and left storage 2 unreadable.

Generalize releasable mount handling for both add-on content and cache storage inside a single-lock mount_impl (via mount_releasable) so active-name checks, released-slot reclaim, and releasable publication happen atomically without a separate-lock window or mutating existing permanent mounts. Fold host mount lookup and release into a single-lock host_unmount in h_fs_Unmount, and unify active-name collision semantics across add-on content and cache storage (RES_PATH_EXISTS on a different target, RES_OK on the same target).

Add cache storage mount/unmount/reclaim and permanent-mount checks to t_fs, document the cache storage symptom in docs/reference/services.md, and regenerate docs/agents/symptoms.md.

Checked: t_fs (209 checks, plain and ASan/UBSan), t_fs_mutation (464 checks), t_fs_commit_list (98 checks, plain, ASan/UBSan and TSan), t_fs_case (58 checks), t_fs_directory (35 checks), hle_fs.c -Wall -Werror compile, and test_docs.py (7/7).

Co-authored-by: Isaac Pateau <[email protected]>
2026-11-23 16:52:02 +08:00
seeddsandPaolo Moretti 0b09b66d76 nvn/replay: tighten fb_view serial check, pso_get_ return type and docs
Follow-up polish on PR #3239:
- Have pso_get_ return void * directly (matching tex_mtl_resolve and rp_begin_ex_) so pso_get_ref does not rely on inlining to avoid objc_autoreleaseReturnValue.
- Pass the resolved texture serial into fb_view and verify g_treg[tid].t.serial == ser under g_rmu before calling vc_put, with a unit check in t_view_reuse.m.
- Fix two reference entry names in docs/reference/frame-rate.md (geo_mesh_encode and lists_nb).

Co-authored-by: Paolo Moretti <[email protected]>
2026-11-23 16:41:19 +08:00
Paolo Moretti 5ccb82adf8 nvn/replay: drop per-draw retain/release in the draw helpers
About 13 % of the replay thread was ARC traffic in small per-draw helpers.
The objects involved are owned elsewhere for the whole draw: shaders by
their program, programs by the serial table, pipelines by the pipeline
tables, buffers by the pool table, the zero bank or the arena.

- Locals naming a program's shaders are __unsafe_unretained in
  draw_color_writes, prog_border, draw_gs_check, fb_tile_plan, fb_prepare,
  draw_, geo_lean_pick and geo_mesh_take.
- prog_get and pso_get return plain pointers (prog_get_ref, pso_get_ref), so
  a call no longer hands its object over retained and autoreleased. A
  program with no serial is still autoreleased explicitly.
- cbuf_slot's buffer out-parameter and enc_r_pso's arguments are
  unretained.

No behaviour changes, so no new test; t_args_gen, t_feedback and
t_geometry_mesh run these helpers. The reference entry is in
docs/reference/frame-rate.md, with a line in Donkey Kong Bananza's note.
2026-11-23 16:41:18 +08:00
Paolo Moretti a7821cfe09 nvn/geometry: set the mesh argument table only for a lone mesh draw
geo_mesh_take set the mesh stage's argument table at every mesh draw,
including those drawn with a run, whose flush (geo_mesh_flush_) sets it
itself. Only a draw that draws alone needs it, so it is set there; each
mesh draw in a run records one call fewer for the encode thread.

No new test: the existing t_geometry_mesh runs both kinds of mesh draw.
The reference entry is in docs/reference/frame-rate.md, with a line in
Donkey Kong Bananza's note.
2026-11-23 16:41:18 +08:00
Paolo Moretti 3a7e53d3cb nvn/replay: cache same-pass feedback views
A draw sampling its own attachment through a level or slice range got a new
Metal texture view at every draw (fb_prepare), retired after the
submission. Mip-chain passes do this at every level, every frame: Donkey
Kong Bananza's bloom and environment chains spent about 1 % of the replay
thread creating views.

fb_view makes the same view and keeps it in the texture's view cache
(vc_get), with a key marker that keeps it apart from a registration's own
views. VC_WAYS goes from 4 to 8, so a chain's per-level views do not evict
the registrations' views.

Tested by dm/gfx/tests/t_view_reuse.m (the same view found again, its own
view per level, never a registration's view, nothing cached for an
invalid or released texture). The reference entry is in
docs/reference/frame-rate.md, with a line in Donkey Kong Bananza's note;
the view cache's entry in docs/reference/rendering.md now says 8.
2026-11-23 16:41:18 +08:00
Paolo Moretti e49e481456 nvn/replay: walk only a shader's texture and buffer bindings per draw
fb_depth_rule, fb_prepare, ubd_conflict_textures and ubd_conflict_sh walked
every reflected binding of the shader at every draw and skipped the kinds
they do not handle. A material's fragment shader has samplers and more
beside each texture: Donkey Kong Bananza's have 45 bindings at the 90th
percentile, a third of them textures, and those walks were about 7 % of the
replay thread on Layer 1400.

Each shader now keeps, once made, the indices of its texture and image
bindings and of the bindings ubd_conflict_sh looks at (sh_lists_make). The
loops walk those lists with the same conditions inside; a shader with no
texture binding skips ubd_conflict_textures' lock. The lists are
made under a lock and published by a release store of their flag
(lists_nb), read with acquire, so a shader first used by two threads at
once is never seen half made. NVN_RB_END marks the end of the binding
kinds, so a kind added later stops t_binding_lists from building until
the lists decide on it.

Tested by dm/gfx/tests/t_binding_lists.m (every kind, in order, made
once, remade for another binding count; ubd_conflict_textures run through
the list). The reference entry is in docs/reference/frame-rate.md, with a
line in Donkey Kong Bananza's note.
2026-11-23 16:41:18 +08:00
Paolo Moretti c1bd080aec nvn/replay: bind only the vertex streams the shader reads
bind_vbufs and pull_layout_fill looked up and bound every stream slot holding
an address. Games leave the streams of earlier meshes bound: Donkey Kong
Bananza had 14 of 16 slots set at every draw, each looked up and compared
draw after draw, about 9 % of the replay thread on Layer 1400.

The pipeline's vertex descriptor is built from the shader's inputs
(pso_desc), so it names no other stream; now only those streams
(vs_streams) are bound or laid out. With no vertex shader (a draw without
one, or a unit test)
every bound stream still is.

Unread streams still count in ubd_conflict and vbuf_prepare, and their
vertex-table slots keep what they held, which no pipeline of the draw
reads.

Tested by dm/gfx/tests/t_vbuf.m (bound, looked up and laid out streams,
with and without a shader). The reference entry is in
docs/reference/frame-rate.md, with a line in Donkey Kong Bananza's note.
2026-11-23 16:41:18 +08:00
Paolo Moretti a359f9e653 nvn/replay: look up pool addresses by 64 KB region first
The per-thread pool address cache was direct-mapped by 4 KB page with 1,024
slots. A pool of megabytes was found only from pages already seen and kept,
so a game binding from thousands of pools kept falling through to the
global lock and the binary search (pc_get, pool_held).

A second table keyed by 64 KB region is looked at first. Every entry is still
checked against the pool's range and pc_holds, so only the hit rate changes.

Donkey Kong Bananza binds from about 3,500 pools; on Layer 1400 these
lookups were about 5 % of the replay thread.

Tested by dm/gfx/tests/t_pool_region.m: another page of a region already
seen, a pool's bounds, and no entry kept across a change of the pools.
The reference entry is in docs/reference/frame-rate.md, with a line in
Donkey Kong Bananza's note.
2026-11-23 16:41:18 +08:00
c22289c053 packing/shader_split: unify Ubisoft Anvil and Scimitar forge readers (PR #3238)
Unify Ubisoft .forge archive support in dm/gfx/tools/forge.py and shader_split.py across Anvil v28 (Immortals Fenyx Rising) and Scimitar v25/v31 (Assassin's Creed: The Ezio Collection), with explicit version validation, bounds checking, and standard unreadable-file reporting on unknown or damaged forges.

Keep #SCIMITAR: labels in SINGLE_STAGE for AC II's separable vertex/pixel cover pairing without changing v28 #GPUCODEONLY@ pairing. Update raw_shaders to admit unaligned control sections through adjacent_shader with a moving lower bound, preserving headerless compute EXIT disambiguation and back-to-back equal-length shaders.

Add docs/reference/shaders.md entry, regenerate docs/agents/symptoms.md, and add unit and end-to-end tests in test_forge.py and test_split_adjacent.py. All 263 targeted unit tests pass; real-dump retest on The Ezio Collection remains open.

Co-authored-by: Roland Gavrilescu <[email protected]>
Co-authored-by: Faris Benhaddou <[email protected]>
2026-11-23 16:36:17 +08:00
seeddsandBoL 15a6725287 host/settings: preserve the legacy 15-language list (PR #3235)
SDK 1-3 use settings commands 1/3, whose list is fixed at 15 entries (ja through es-419), while the extensible commands 5/6 arrived in firmware 4.0.0. Returning 18 codes overflowed Xenoblade Chronicles 2 Japanese 2.0.2's 15-slot startup language container. Keep the 15-code list and count for known SDK majors 1-3 while preserving the 18-code fallback for SDK 4+ and unknown SDKs.

Checked: t_language (1,086 checks under ASan/UBSan), t_shared_font (149 checks), hle_sdk16.c host compile, and test_docs.py (7/7).

Co-authored-by: BoL <[email protected]>
2026-11-23 16:29:18 +08:00
seedds c17a549844 gfx/nvn: defer acquire pacing and present-ticket wait to nvnSyncWait
nvnWindowAcquireTexture previously blocked on display-link/pacer pacing and the slot's previous-present ticket before returning the texture index. Games that measure CPU frame time across AcquireTexture + draw recording before calling nvnSyncWait(acquire_sync, -1) (such as Super Mario Bros. Wonder - Nintendo Switch 2 Edition's sead::GameFrameworkNx) therefore saw the full present_interval vsync wait inside their CPU time and could never step back from interval 2 (30 fps) to interval 1 (60 fps).

When nvnWindowAcquireTexture is passed a non-null NVNsync, snapshot the slot's avail time and take ownership of its previous-present ticket immediately (before any parallel presentation thread can enqueue the new frame's present), attach a deferred acquire wait (fenced == 4) to the sync and win->pending_acq, and return immediately. nvnSyncWait runs the pacing and ticket waits with support for zero-timeout polls and finite timeouts; games using only nvnQueueWaitSync drain the prior pending acquire at the next AcquireTexture while nvnQueueWaitSync waits for the previous present's texture release on the queue worker.
2026-11-23 15:53:18 +08:00
seeddsandGabriel Tran c25a8670a8 chain/dual-source: move dual-source blending into main0_u and drop dual_want.tsv (PR #2736)
Dual-source blending for NVN pixel shaders relied on per-game dual_want.tsv
lists to emit a separate main0_d entry point into <key>_b. Nine profiles had
accumulated 542 keys, and PR #2736 found 7 more /gamedata/nvn/branch_shader/*.fpo
shaders drawn only during FINAL FANTASY XII limit breaks (with 45 more .fpo
shaders still unlisted).

- dmsh_abi.h / dmsh_entry.py: add DMSH_TYPED_DUAL_FC (234, dm_du) to main0_u in
  the lazily-loaded side library <key>_bx whenever colours 0 and 1 share a width
  and every colour >= 1 is typed. With dm_du on, colour 1 is returned as
  [[color(0), index(1)]] and colours 1..7 are absent, while the alpha test
  (dm_at) still composes. Remove fs_dual and DUAL_WANT / dual_want.tsv handling
  from dmsh_build.py, dmsh_chain.py, dmsh_live.py, pack_app.py and
  build_ipa_from_nsp.py.
- nvn_mtl.m: load entry_u_dual, route SRC1-blended pipelines through typed_fn
  (ignoring integer target 0 in pso_reads_src1 where blending is disabled), mark
  attachments 1..7 unwritten when dual_fn is active, simplify at_fn to fn only,
  and remove fn_d and DM_NVN_DUAL_WANT.
- Profiles and docs: delete all 9 dual_want.tsv files, add PR #2736's iPhone Duo
  validation and raw_shaders re-split bullets to FFXII's note, and update game
  notes, reference docs, env_switches.tsv and symptoms.md.

Checked: unit/ABI/packaging/docs suites (test_dmsh_abi, test_dmsh_code_fp,
test_nsp_chain, test_shader_toolchain_cache, test_shader_rewrites,
test_game_profile, test_dmsh_pairs, test_nsp_mac_app, test_dmsh_typed,
test_dmsh_alpha, test_dmsh_logic, test_dmsh_side, test_dmsh_fetch, test_docs),
GPU replay (t_typed_outputs on Metal 4 and DM_PSO_MTL4=0, t_alpha, and
t_missing_src1's dual-source checks), all 72 FFXII branch_shader/*.fpo shaders
built for Mac and iOS (72/72 entry_u_dual + entry_u_side, 0 lost), and
regress.py check on The Binding of Isaac: Rebirth (PASS).

Front-ends: break: shader libraries must be rebuilt for chain b94eb3685250.
Co-authored-by: Gabriel Tran <[email protected]>
2026-11-23 15:38:11 +08:00
seeddsandTreschQ b78d7e8e57 host/input: read unclaimed USB Xbox One (GIP) controllers on macOS (PR #2666)
Third-party wired Xbox One controllers (such as the PDP Wired Controller, 0e6f:02a8) are left unconfigured on macOS because Apple's XboxGamepad.dext matches only four Microsoft product IDs (045e:028e, 02ea, 0b00, 0b12). A GIP pad sends no input until powered on.

Add a pure GIP protocol decoder (pad_gip.h) and Mac IOUSBHost user-space transport (pad_gip_mac.h) wired into front_mac.m:
- Match unclaimed USB devices of GIP class (0xFF/0x47/0xD0) after 1.5 s, leaving pads driven by XboxGamepad.dext to GameController.
- Configure once if not already configured, open interface 0, send per-vendor xpad init packets, and read interrupt IN reports into a single reusable DMA buffer.
- Clear pad state on GIP_CMD_ANNOUNCE, gate Home-button polling on window focus, align trigger actuation to 25% (> 255), and normalize the Xbox/Home button state.
- Add t_pad_gip unit tests (24 checks), DM_GIP_PADS / DM_GIP_LOG switches, and documentation.

Co-authored-by: TreschQ <[email protected]>
2026-11-23 15:14:51 +08:00
seeddsandHector Villarreal ee63b843db packing/profiles: fix registered-update shader coverage and status; register Mario Kart World 1.8.0
Fix two assumptions in scripts/build_ipa_from_nsp.py for multi-build profiles:

1. Shader coverage (profile_derivation_reason): committed shader tables cover shader_versions plus any extra registered builds explicitly verified in shader_covers (Hades II v655360, FIFA 23 v196608). Any other registered build derives its own shader tables even when shader_versions is present, preventing a registered update with different shaders (Mario Kart World 1.8.0 beside v0) from silently packing v0's shader libraries. derive_profile strips shader_covers when deriving a single version, and dm/games/game.py validates shader_covers against registered builds and shader_versions.

2. Status reporting (report_profile_status): compare pkg_ver's module build IDs (ignoring display spelling) against reg.builds().get(pkg_ver) instead of comparing the whole build table, so registered builds packed with derived shader tables on multi-build profiles are not reported [RED] while mixed, mismatched, or unregistered modules stay [RED].

Register Mario Kart World 1.8.0 (v917504) in dm/games/0400C3F00006E000/game.tsv without shader_covers so 1.8.0 derives its own shaders whether v0 is present or not. Add unit tests in test_nsp_registered_update.py and test_game_profile.py, update profile docs and docs/reference/packing.md, and regenerate docs/agents/symptoms.md.

Checked: 262 unit tests (test_nsp_registered_update, test_game_profile, test_nsp_alias, test_nsp_incremental, test_nsp_nup, test_nsp_dump, test_nsp_chain, test_patches, test_docs), docs_patches.py --check, and ruff check (0 new findings).

Follow-up to PR #2621.

Co-authored-by: Hector Villarreal <[email protected]>
2026-11-23 15:13:19 +08:00
seeddsandSeif Ateek cac1293b45 host: load exlaunch mod code plugins (PR #3178)
Load Atmosphère exefs/subsdk<N> code plugins (such as exlaunch plugins beside a mod's romfs/) on the Mac, and answer the Horizon SVCs their start-up requires:

- Rewriter (patch_nso.py, mod_layout.py): walk raw .eh_frame when MOD0's .eh_frame_hdr range is empty (devkitA64-linked plugins), indexing CIEs by offset, supporting CIE v1/v3/v4 and all pointer formats, skipping empty (0, 0) MOD0 ranges, and relocating raw .eh_frame pointers on 16 KB data relayout.
- Offline preparation (scripts/prepare_mod.py): rewrite a mod's subsdk<N> NSOs into <mod>/exefs/nxnative/ in numeric order without DM_GAME, validating NSO0 magic and warning on exefs/main.
- Loader & shared code writes (loader.c, code_write.h, hle_cheats.c): reserve one contiguous PROT_NONE span on macOS for non-JIT startup modules (with a 3-page rtld slot below main and 1-page guards between modules) so modules sit in Horizon load order; sync open MapProcessMemory views after each module's DT_INIT; share mach_vm_remap writable alias and BUILD_ID-verified changed.tsv helpers between cheats and exlaunch plugins.
- Exlaunch HLE & SVCs (hle_exl.c, hle_svc.c, main.c): load prepared subsdk<N> plugins from DM_ROMFS_OVERLAY mods before sdk (skipped safely on iOS); populate the stand-in rtld only when mod plugins are loaded (or on a .rodata-only exlaunch signature match for manually loaded subsdks); answer GetInfo(65001) with the current-process handle; implement MapProcessMemory / UnmapProcessMemory with ASLR-only destination bounds, key_page_off source bounds, changed.tsv refusal, lock-safe sync, and guest_release on unmap; fix svcGetSystemTick (0x1E) to return the 64-bit tick in x0.
- Tests & docs: add t_exl.c and test_exl_mod.py, add dm_exl_* stubs to t_heap_size.c and t_svc_memory.c, document DM_EXL_TRACE and DM_ROMFS_OVERLAY, and update docs/reference/rewriter.md and docs/agents/symptoms.md.

Checked: Mac host build, iOS SDK -fsyntax-only -Wall -Werror on changed C files, host tests (exl, cheats, heap_size under ASan/UBSan; memory, nro, symbols), Python tool tests (23/23), clang-tidy ratchet (0 new findings), ruff/pyright ratchet (0 new findings in changed files), and quick regression check on Hades (0100535012974000, PASS).

Front-ends: new: on the Mac, a mod with exefs/subsdk<N> code plugins runs its code once scripts/prepare_mod.py <mod> has prepared it into <mod>/exefs/nxnative/; enabling the mod (its romfs in DM_ROMFS_OVERLAY) loads the plugins and disabling it leaves them out

Fixes #1133
Co-authored-by: Seif Ateek <[email protected]>
2026-11-23 15:06:24 +08:00
seeddsandcky 4add5fbb49 gfx/nvn: adopt newly prebuilt p*.mtl4a archives before frame 0
After a cold or partial prepare-step prebuild writes pulling bases to
pso_archive/p*.mtl4a, pso4_init() had already frozen g_arch_ix and
g_arch4p at startup, so the same session missed every newly prebuilt
base (draws waited on "pulling base not made yet" and hy_base_kick
recompiled them in the background until restart).

Wait briefly at the end of prepare_prebuild() for the final compiles
(bounded by g_pre_tail_ms = 10 s for hung #294 compiles, unlimited once
g_pre_flushing confirms every worker has returned and only disk flush
remains), then call arch_adopt_prebuilt() synchronously before frame 0:
- Discover p*.mtl4a files in g_arch_dir not opened in pso4_init()
  (tracked via g_arch_opened), oldest-first so newer keys win.
- Enforce arch_vm_room()'s 2 GiB runtime reserve before opening.
- Open in parallel inside arch_open_begin()/arch_open_end(), index
  .keys into g_arch_ix (keeping g_arch_ixf/g_arch4p updated with
  newest-first precedence and leaving adopted files out of g_arch_use
  so arch_sweep() does not retire them), and clear g_pbase_miss.
- Keep g_arch_ix/g_arch4p immutable and lock-free once frame 0 starts.

Add coverage in t_pso_archive (--adopt-prebuilt), t_pso_admission
(exact/ample VA-reserve checks), and t_pso_stall (prepare_prebuild
adoption and #294 tail-timeout guard), and document the symptom in
docs/reference/shaders.md, dm/games/0400569027BF4000/README.md, and
docs/agents/symptoms.md.

Refs #3030

Co-authored-by: cky <[email protected]>
2026-11-23 15:03:09 +08:00
seeddsandJiatong He 3e8f1ce578 host/haptics: drive 8BitDo Ultimate 2 Wireless through HID report 0x05 (PR #2763)
On macOS over Bluetooth LE, GameController lists the 8BitDo Ultimate 2
Wireless (2DC8:6012, firmware 1.03+) with zero haptics localities, so
Core Haptics cannot drive it.

- Add an 8BitDo HID output report 0x05 route ({0x05, low, high, 0, 0})
  in haptics_apple.m for controllers with no localities whose vendorName
  contains 8BitDo.
- Reuse hid_take (skipping kIOHIDGCSyntheticDeviceKey), filter to
  primary usage page 1 / usage 4 or 5, and probe {0x05, 0, 0, 0, 0} on
  connect to skip dead Bluetooth entries (#2237) and unsupported firmware.
- Share linear 0.85/0.15 low/high band dual-ERM mixing (erm_mix, with
  DM_RUMBLE_GAIN and DM_RUMBLE_MIN) with the DualShock 4 route.
- Pace BLE reports to 20 ms with pacing-interval peak-hold, refresh
  active levels every 50 ms, send three zero reports on normal stop,
  cancel timers on suspend/sink-switch/disconnect, and avoid spinning or
  marking failed writes as sent.
- Cover the route in t_haptics_apple and document it in services.md.

Co-authored-by: Jiatong He <[email protected]>
2026-11-23 14:58:57 +08:00
seeddsandYunzhe be3b8bf86e host/mac: automatic passive HID stick fallback for Switch Pro Controllers
Some third-party Switch Pro-compatible pads (057e:2009) send valid 12-bit stick values in Nintendo HID report 0x30 while macOS GameController reports exact zero on both GCExtendedGamepad and GCController.input.unmappedInput (#2655, #382).

Decode both sticks from report 0x30 in motion_pro_mac.h (reusing pad_pro.h) and automatically latch a stick onto passive HID once raw 0x30 stays past half tilt for 150 ms while both mapped and unmapped GameController read exact zero, returning immediately if GameController ever reports non-zero. Updates are event-driven from pro_report only when a latched stick changes, with a one-shot 300 ms staleness expiry while tilted, minimum-length packet validation before refreshing staleness, independence from DM_MOTION / DM_MOTION_HID, and DM_PRO_STICKS=0 opt-out.

Co-authored-by: Yunzhe <[email protected]>
2026-11-23 14:35:42 +08:00
seeddsandFifteenPen 2fc4e70ab8 chain/nvn: pool runtime-selected NVN2 storage images
Route all dynamic non-atomic NVN2 storage images (1D, 2D, 3D, 2DArray, Cube,
and texture_buffer) through a unified host-bound image pool (img_pool /
NVN_RB_IMGP), regardless of whether the handle comes from c2, uniform
buffers, storage buffers, or computed arithmetic:

- Translator: pool all TexOp image instructions in BindlessElimination.cs
  (keeping sampled buffer textures on tex_dyn_slots), rebuild universal
  dmsh_xlate, and bump dmsh_chain.lock and DMSH_CHAIN.
- Reflection & ABI: add DMSH_KIND_IMG_POOL / NVN_RB_IMGP, reflect all
  [a-z]+_i pools (read-only, write-only, read-write) from their element
  type, and add dm_buffer_write to the buffer-pool header rewrite with
  early_fragment_tests handling.
- NVN host: add img_pool_gpu (16-slot cache keyed by target, format class,
  rw, and base with texture_buffer leads, strict target/class/write
  filtering, silent write-sink fallback, unowned-view retirement, and
  g_psnap_gen bump), promote RegisterTexture-only BindImages IDs, scope
  image_prepare_shader to live target-compatible IMAGE IDs >= S.tex_base,
  wire NVN_RB_IMGP into hazard/argument encoding paths, and fix dummy_img
  for MTLTextureTypeTextureBuffer.
- Tests & docs: add reflection, translator, and Metal GPU tests
  (t_img_pool) and update docs/reference/shaders.md and symptoms.md.

Co-authored-by: FifteenPen <[email protected]>
2026-11-23 13:57:51 +08:00
seeddsandLudovic LEMARINEL - Adesin.fr 48781edc1b nvn/chain: sparse misaligned shadows, bounded c[0] storage buffers, and Anvil shader split (PR #3126)
Implement clean general host/chain mechanisms covering the NVN and engine gaps identified during Immortals Fenyx Rising bring-up (PR #3126):

- Sparse alias visibility: track active sparse virtual pools in resource_vis() (MTL4VisibilityOptionResourceAlias) so Metal 4 barriers keep replaced run buffers coherent.
- Handle bind splitting: split >32-handle BindTextures / BindTexturesDeferred calls into 32-handle chunks after validating slots once.
- Compressed sparse IMAGE textures: allow NVN_TEXTURE_FLAGS_IMAGE on compressed formats in tex_from_storage, matching tex_storage_ok / tex_storage_dst.
- Geometry GPU-only scratch reuse: reuse private 64 MB+ scratch blocks across geo_prep, geo_prep_gpu, and tess_draw, and trim completed blocks in mem_trim().
- Per-run misaligned sparse mappings: re-back misaligned PHYSICAL|CPU_NO_ACCESS pools on a 16 KB host page boundary (side table, keeping pool_t at 40 bytes for captures) for zero-copy vm_remap; back misaligned CPU-accessible mappings with per-run anonymous shadow pages in the reservation, zero-fault vm_remap RW physical aliases, and lazy per-host-page snapshots on GPU-written pages.
- Bounded c[0] storage buffers & clipped buffer textures: extend TranslationFlags.MetalStorageBounds (sblen) to NVN_RB_SBUFP / NVN_RB_UBOP so bindings declared past a sparse run read 0 and drop writes/atomics instead of faulting or widening host memory; keep first_store, float_add_msl, and args_cbuf_only working on bounded c[0] buffers; clip tex_buffer width to the mapped buffer.
- Ubisoft Anvil v28 .forge and loose GPUCODEONLY shader extraction in shader_split.py and profile_guess.py.

Co-authored-by: Ludovic LEMARINEL - Adesin.fr <[email protected]>
2026-11-23 13:03:09 +08:00
seeddsandEriksrevenge1 e8460ebc49 tools/cheat_anchor: bound .bss by the module's end, not the loaded image
cheat_anchor.py assumed len(img) included .bss, but dm/tools/nso.py's image stops at the end of .data and exposes bss as a size on nso.Module. Both Build.where() and Compiler.addr() therefore rejected every address in .bss—where games keep most singletons pointer cheats start from—as outside the main NSO image.

Load the NSO once through dm/tools/nso.py in Build.__init__, compute self.end from bss_start + mod.bss, and bound .bss by self.end in both Build.where() and Compiler.addr(). Add .bss boundary and import/compile roundtrip tests, document the symptom in docs/reference/cheats.md (and regenerate docs/agents/symptoms.md), and map scripts/cheat_anchor.py in dm/tools/impact_map.tsv.

Co-authored-by: Eriksrevenge1 <[email protected]>
2026-11-23 11:14:18 +08:00
seeddsandEriksrevenge1 7130d4db46 host/oe: pick default language from control.nacp when DM_LANG is unset
When DM_LANG is unset or empty, nn::oe::GetDesiredLanguage and
nn::oe::GetRegionCode previously defaulted unconditionally to en-US,
crashing games that do not ship American English (such as Xenoblade
Chronicles 3, which lists en-GB and crashed at main+0x10141ac on direct
bench.py runs).

Read SupportedLanguageFlag (+0x302C) from control.nacp via
dm_control_read and pick the first supported language in NACP bit order
(en-US, en-GB, ja..th), matching Horizon and build_ipa_from_nsp.py's
default language selection. Explicit DM_LANG overrides pass through
unchanged, and missing/truncated/zero NACP falls back to en-US.

Checked: t_oe (normal and ASan/UBSan, 97 checks), t_language (925
checks), Mac dmhost build (010074F013262000), and test_docs.

Co-authored-by: Eriksrevenge1 <[email protected]>
2026-11-23 11:12:52 +08:00
seeddsandEriksrevenge1 d9a70339a0 chain/split: read the shaders of Monolith's DMPA model packages and NDSR packs (PR #3135)
Two kinds of Monolith file kept shaders the split never saw:

- DMPA model packages (.wimdo): loose Monolith files were only dispatched to monolith_shaders when starting with HCPS, xbc1, DRSM or cmp\0zlib, dropping loose DMPA packages that keep plain HCPS programs beside the model (18 files in Xenoblade Chronicles: Definitive Edition). Dispatch DMPA to monolith_shaders in both scan_file_in and scan_blob.
- NDSR packs inside archives: monolith_shaders scanned decoded archive/XBC1 payloads only for HCPS and GLSLC, missing /monolib/shader/ndsr.pck inside Xenoblade Chronicles 2 Switch 2 Edition's bf2.ard. Forward NDSR payloads in monolith_shaders to ndsr_shaders.

Regenerated dmsh_chain.h for shader_split.py and added synthetic tests in test_monolith.py and test_split_ndsr.py plus reference docs in docs/reference/shaders.md.

Co-authored-by: Eriksrevenge1 <[email protected]>
2026-11-23 11:11:25 +08:00
seeddsandCagatay Ünlü 5fc927d5ed nvn/fstep: 40 fps in ticks of 1/120 s (Ocarina of Time)
Add 1/120 s tick-unit support to the host frame step (FRAME_STEP_120
capability, state page +0x38 unit = 120, fixed for the run) and update
Ocarina of Time's frame-ratio stub to divide by +0x38 (defaulting to 60
when unset), enabling 40 fps (3 ticks = 25 ms) on screens capable of a
multiple of 120 Hz.

- Scale vsync-based margins, limits, hold steps (q = 2 at 60/30, 1 at
  40 with fallback capped at 4 ticks = 30 fps), and GPU reference tables
  under nvn_fstep.t120.
- Select the 120 Hz display link automatically in nvn_mtl.m link_sync
  when mtl_fps_target() == 40, preserve native screen capability across
  Mac fullscreen front_screen_match switches (front_screen_capable_fps),
  and fall back to 30 fps on non-120 Hz screens, in Low Power Mode,
  under the thermal cap, or with explicit DM_PRESENT_LINK=1.
- Hide 40 fps alongside 120 fps in the iOS launcher when
  front_screen_max_fps() < 120.
- Add native ARM64 stub, loader, frame-step, display-link, and settings
  unit tests, and update reference/player docs.

Front-ends: new: DM_FPS_TARGET takes 40 for a game whose frame-step stub declares FRAME_STEP_120, on a screen at a multiple of 120 Hz.

Co-authored-by: Cagatay Ünlü <[email protected]>
2026-11-23 09:58:09 +08:00
seedds dc75d1fc81 host/hid: fix handle metadata and bring up Trails into Reverie
Vibration handle enumeration derives handles from the requested npad and
style. Device info reports actuator type and position for valid handles
before the controller is mounted. Vibration sends still check the live
controller and its output.

Register the NIS America 1.0.4 build and its Phyre shader tables. The
standalone app draws the opening Crossbell scenes on an Apple M6 Mac.
The unsigned iOS package passes archive verification. Document the high
physical footprint and the texture-ordering tradeoff.

All 566 HID checks and six documentation tests passed. The Hades smoke
comparison exercised both HID APIs and passed.
2026-11-23 08:20:21 +08:00
seeddsandEriksrevenge1 3d186f2b83 nvn/present: put a retried display link on probation
A display link retried after a rescue previously waited STALL_NS (100 ms) and then dropped frames for LINK_RESCUE_NS (500 ms) before returning to rescue if it stayed silent.

Keep a retried link on probation once link_main has attached it to its run loop (after front_screen_settling and g_classic_busy clear): 67 ms at 60/120 Hz and 134 ms at 30 Hz (4 refreshes), measured over active foreground time (honoring dm_focus_in_since). The first accepted callback or switching to mode 0 clears probation; staying silent past the probation window returns to rescue immediately.

Also start links created during DM_TEST_LINK_STALL paused so the test switch exercises persistent silence across retries.

Based on PR #3150.

Co-authored-by: Eriksrevenge1 <[email protected]>
2026-11-23 08:14:06 +08:00
seeddsandPaolo Moretti 610baa4dcd gfx/shaders: build mesh libraries for every shader variation's geometry pair (PR #3191)
The shader split writes each variation's vertex / geometry pairs to geo_pairs.tsv (kept beside the shader package, like pso_pairs.tsv), and dmsh_build.py builds a mesh library for every pair whose geometry shader has a lean passthrough kernel. Before, only pairs the game had already drawn (G rows) or a hand-kept geo_mesh.tsv got one, so new areas drew their geometry through the compute path.

A composed mesh library now undefines the vertex part's include guards before the kernel's namespace, so a guarded helper (dm_uword) exists in both parts; 20 kernels did not compile before.

Variation pairs that cannot be composed or compiled are counted, not printed as [RED]. regress.py's chain key and the NSP script's split reuse, derived profiles and shader step key include the table. Donkey Kong Bananza's geo_mesh.tsv is removed: the split names both its rows.

Co-authored-by: Paolo Moretti <[email protected]>
2026-11-23 07:26:52 +08:00
seeddsandEric Liu 033793f0ba chain/vertex: share dm_vs_body_o with capture entry main0_gs (PR #3186)
The vertex shader compile unit (dmsh_side.vs_unit, PR #2951) still left
a full copy of the body in main0_gs (dmsh_geometry.capture), duplicating
its 144-store capture epilogue at every return. Have main0_gs call the
shared out-of-line body dm_vs_body_o and write the capture epilogue once
after the call, saving 10-21% per-vertex-shader Metal compile+link CPU
and 21-27% <key>_b size on multi-return games (Breath of the Wild, Tears
of the Kingdom).

Keep main0_gs as a whole unculled copy when vs_viewport_mask culls the
raster entries, use a non-greedy capture-epilogue match for multiple
returns on one line, and validate main0_gs's parameter prefix before
rewriting.

Co-authored-by: Eric Liu <[email protected]>
2026-11-23 07:12:14 +08:00