diff --git a/dm/games/0100A00019DE0000/README.md b/dm/games/0100A00019DE0000/README.md index 9058fe3502..1f63d9c6e1 100644 --- a/dm/games/0100A00019DE0000/README.md +++ b/dm/games/0100A00019DE0000/README.md @@ -19,6 +19,7 @@ Base game v0 (the NACP's display version is 0.0.126424), SDK 19.3.9. Supergiant ## Rendering +- **Current: native render size on 1.0.131248 (Mac).** The game renders a fixed 1280x720, set by one constant in its app init: `mov x8,#0x500; movk x8,#0x2d0,lsl #32` at `main+0x2a4eb0` (v196608), stored to the app settings and the window rectangle; the swapchain and every screen-sized target follow it. A frame-step stub there takes the size from `DM_RENDER_SIZE` (the launcher's Resolution: 1280x720, 1920x1080, 2560x1440, 3840x2160). Headless on an M5 Max (macOS 26.6.2), opening into Erebus, one run per size: 45 full-size and 16 half-size targets follow the size, the HUD is laid out for it, no fault at 1600x900 to 3840x2160; GPU per frame (median of 43 windows of 300 frames, `DM_PRESENT_HZ=120`) 2.25 ms at 720p, 3.26 ms at 1080p, 4.83 ms at 1440p, 6.72 ms at 4K. The art is stored at 2/3 of its original size: the package manifests (`Packages/NVN/*.pkg_manifest`) give each sprite a scale of original / stored size, 1.5 for 3,764 of 4,797 sprites read and 1.48 to 1.52 for most others (720p-sized art if the originals were made for 1080p). A larger size sharpens the HUD, text and edges; the art is magnified 1.5x at 1080p and 3x at 4K (soft in a 4K still at 1:1). A player who applied the same change confirmed 1080p at a locked 60 fps on an M1 MacBook Air with 8 GB, version not stated ([issue 772](https://github.com/seedds/nxnative/issues/772)). v0 has no stub: PR 485 reports it crashing at 1600x900 (`main+0x48e5a4`) with the same two instructions patched at `main+0x2a6080`. - **Current: textures at fixed, sparse slots.** Its 88 shaders bind combined textures at slots 0, 1, 3, 6, 8, 11, 15, 21, 25, 26, 30, 31 and 34. Slot 34 (`SceneFade.frag`, c2 0x130; `fp_t_tcb_4C`: c2 word 0x4C = 0x20 + 8 × 34) lies past the driver's 32 combined slots, inside the image table at 0x120. With a 32-slot table, `dmsh_build.py` reported that binding as not decoded (`shaders with a binding whose slot was not decoded 1`, which prints a red line when the shader loads). The combined table now runs up to the separate textures at 0x168 (41 slots); past slot 31 it shares its words with the image table, and the replay writes a bound texture there when the image slot is unbound (`nvn_mtl.m`). The game has no image bindings, so a bound texture there wins. The census of `fp_t_*` names in the translated libraries gives the slots in use. - **Not a bug: two long lines through Melinoë.** While the staff's Omega attack charges, two thin white lines run from her to the screen edges, one forward and one back. They are that weapon's aim lines (`WeaponStaffSwing5`: `AimLineCountOverride = 2`, `AimLineAngleOffsetOverride = 180`, animation `AuraAimLineNoMovementStaff`). The sprite is a long arrow with white edges, a dark fill drawn emissive and its tip off-screen, and the game hides it while she moves. Traced with `DM_NVN_CBDUMP` vertex dumps and `DM_PROBE` on the aim-line update (`main+0x39ade0`); a scripted run that taps Y shows them often. diff --git a/dm/games/0100A00019DE0000/game.tsv b/dm/games/0100A00019DE0000/game.tsv index aca851d67f..65720df59d 100644 --- a/dm/games/0100A00019DE0000/game.tsv +++ b/dm/games/0100A00019DE0000/game.tsv @@ -17,6 +17,8 @@ pad_layout full # ---- Versions ---- build v0 0.0.126424 main=5219053e5eb156be80fbb2f303779531 sdk=d83a56a5558798414c78ec722867a7da +# 1.0.131248 (v196608): registered for its render-size stub (patches.py); its shaders are not in the tables, so the NSP script packs it from a derived profile +build v196608 1.0.131248 main=e4f736641889b26f3194847d2b9dce57 sdk=190030518b5d64e5d87b84bc54661af9 package v0 shader_versions v0 diff --git a/dm/games/0100A00019DE0000/patches.py b/dm/games/0100A00019DE0000/patches.py new file mode 100644 index 0000000000..3e111aa1da --- /dev/null +++ b/dm/games/0100A00019DE0000/patches.py @@ -0,0 +1,32 @@ +# Hades II (0100A00019DE0000): the rewriter's patches of this game's own builds. dm/tools/patch_nso.py loads every profile's patches.py and applies those of a module's NSO build ID; +# FRAME_STEP as described there ("Registered patches"). Patches of Nintendo SDK module builds are in dm/tools/sdk_patches.py +from nso_asm import ADRP, B, LDRX, NOP + +# Render size. Supergiant's engine sizes the swapchain and every screen-sized target from the app settings' width and height. On the Switch the app's init (main+0x2a4d20 in +# 1.0.131248 = v196608, the function that also runs the main loop) writes them as one constant right after nn::vi::CreateLayer: mov x8,#0x500; movk x8,#0x2d0,lsl #32 +# (1280 | 720 << 32) at main+0x2a4eb0, stored to settings +8 and to the window's rectangle {0, 0, w, h}. Next to it the init stores a pointer to the PC version's resolution +# table (main+0x6c837c: 1280x720, 1920x1080, 2560x1440, 3840x2160), which nothing reads. The stub takes the size from the state page (+0x38: u32 width, u32 height; DM_RENDER_SIZE, +# written by the loader) and keeps 1280x720 when it is 0. x8 is written by the stub before its only read. Measured headless on the Mac (M5 Max): at 1600x900, 1920x1080, 2560x1440 +# and 3840x2160 the swapchain and the 45 full-size and 16 half-size targets of a frame follow the size, the HUD is laid out for it, and the game runs the opening into Erebus +# without a fault. PR #485 reports v0 crashing at 1600x900 (main+0x48e5a4) with the same two instructions patched at main+0x2a6080; that did not happen on this build +def frame_step_v196608(ctx): + ctx.site(0x2a4eb0, '08a080d2085ac0f2') + start = ctx.here(); ctx.emit(ADRP(8, ctx.here(), ctx.state)); ctx.emit(LDRX(8, 8, 0x38 // 8)) # ldr x8,[state,#0x38] width | height << 32 + for w in (0xb5000068, # cbnz x8,back (+3) + 0xd280a008, # mov x8,#0x500 1280 (the original) + 0xf2c05a08): # movk x8,#0x2d0,lsl #32 720 + ctx.emit(w) + ctx.emit(B(ctx.here(), 0x2a4eb8)) + ctx.put(0x2a4eb0, [B(0x2a4eb0, start), NOP], 'app settings width and height: the state page\'s render size (DM_RENDER_SIZE), 1280x720 when it is 0') + ctx.capabilities.add('RENDER_SIZE') + +FRAME_STEP = {'e4f736641889b26f3194847d2b9dce57': frame_step_v196608} + +# How general each patch is and could be (dm/tools/docs_patches.py "Binding", listed in docs/agents/game-patches.md): what, its binding now, the loosest it could have (goal), +# purpose, why; blocked or kept: why the gap stays open (cannot close yet, or left open on purpose); checked: what was checked on game files (else a judgement) +BINDING = [ + {'what': 'render size: the app settings\' width and height from the state page', 'now': 'build', 'goal': 'game', 'purpose': 'rendering', + 'why': "the game's own init constant; the same two instructions sit at main+0x2a6080 in v0, so a function-matched rule could carry it over the updates", + 'kept': 'tested on 1.0.131248 only; PR #485 saw v0 crash at 1600x900 with the same change, so each build needs its own run first', + 'checked': '1.0.131248 headless at 1600x900, 1920x1080, 2560x1440 and 3840x2160 (M5 Max, macOS 26.6.2)'}, +] diff --git a/dm/games/0400486024DEC000/README.md b/dm/games/0400486024DEC000/README.md index 98e00ecae0..8328bd4607 100644 --- a/dm/games/0400486024DEC000/README.md +++ b/dm/games/0400486024DEC000/README.md @@ -52,6 +52,12 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk - With a window, the first start on a new chain runs the pipeline prebuild first: 33,190 shader pairs, 691 s on this Mac. A run with no window skips it. - The opening movie runs at the movie's own 24 fps pace during the story section and cannot be skipped: about 8 minutes on a new file. +## Render size + +- The launcher's **Resolution** (`DM_RENDER_SIZE`, v131072, docked): the game sizes its docked output and render targets from fixed 2560x1440 constants, and stubs at those sites (`patches.py`, the sites [PR 1460](https://github.com/seedds/nxnative/pull/1460) found for its ultrawide cuts) take the chosen size instead. The swapchain and every target that follows the output take it; the game still draws 80 % of the output (`nvnWindowSetCrop`, 3072x1728 at 3840x2160) and its 3D at most at its top level, ×0.75 of that. Handheld (1920x1080) is left alone. +- Measured (M5 Max, macOS 26.6.2, 2026-11-08, a 1-minute headless route from a save, n=1 each): every size held 60 fps (frame p50 16.7 ms); GPU p50 8.9 ms at the game's own size, 9.2 ms at 2560x1440 through the stubs, 9.6 ms at 3840x2160. On this Mac the frame hardly follows the size (see Dynamic resolution). In play, 2026-11-08 and 09: 2560x1440 (three sessions, 2 to 14 minutes) and 3024x1702 (a size not in the launcher's list; five sessions, up to 28 minutes), through Kakariko, Death Mountain Trail, Hyrule Field and Castle Town. +- Not checked: 1920x1080 docked (below the game's own size), handheld, other builds. + ## Dynamic resolution - The controller (v131072; found by fingerprint, so the addresses are only for reading): the parameters are `game__gfx__DynamicResolutionParam` (`LoadThreshold`, `ReduceCounterMax`, `IncreaseCounterMax`, and a list of levels, each a `ResolutionReduceScale` and a `Priority`). Once a frame the update (`main+0x805aa0`) reads the frame's GPU time, subtracts what its cost model predicts at the current size and keeps the trend of that residual. The level function (`main+0x8065e0`) adds the residual to the model's cost at each level and returns the best level under the threshold: 0, the full 1536x864, when the current size fits. The update moves down after `ReduceCounterMax` frames that ask for it and back up after `IncreaseCounterMax`. Scripted `GPULoad` hints from event data (`main+0x31c3de0`) and `OneshotSetDynamicResolutionLoadThreshold` adjust it in cutscenes. diff --git a/dm/games/0400486024DEC000/patches.py b/dm/games/0400486024DEC000/patches.py index cade577a2e..dde835329e 100644 --- a/dm/games/0400486024DEC000/patches.py +++ b/dm/games/0400486024DEC000/patches.py @@ -32,6 +32,7 @@ def frame_step(ctx): emit(0x1e201828); emit(B(here(), site + 4)) # orig: fdiv s8,s1,s0; back fs_put(site, [B(site, start)], 'frame ratio: the host\'s step × base rate / 60 instead of base rate / the game\'s frame rate (state page target fps; 0 = the game\'s ratio)') dynamic_resolution(ctx) + if base == 0x6e6be0: render_size(ctx) # v131072's main (the only build the render-size sites are known for) # The game's dynamic resolution (game__gfx__DynamicResolutionParam: LoadThreshold, ReduceCounterMax, IncreaseCounterMax and a list of levels, each a ResolutionReduceScale and a # Priority; on v131072 levels 0..9 at 0.75..0.333 of 2048x1152, 1536x864 to 683x384). Its update (main+0x805aa0) reads the frame's GPU load (about 0.2 ms a unit) into +0x8, subtracts @@ -71,6 +72,57 @@ def dynamic_resolution(ctx): fs_put(site, [B(site, start)], 'dynamic resolution level: 0 (full resolution), or with state +0x40 (DM_DYNAMIC_RESOLUTION) a climb on the load measured at each level') ctx.capabilities.add('DYNAMIC_RESOLUTION') +# Render size (DM_RENDER_SIZE, the launcher's Resolution; v131072 only, guarded by the matched frame-step function's place): the game sizes its docked output and render +# targets from fixed 2560x1440 constants (the sites upstream PR #1460 found for its ultrawide cuts); these stubs take the state page's size instead (+0x38: u32 width, +# u32 height, read as one x = width | height << 32; 0 = the game's own). Each keeps the original instructions for size 0. Handheld (1920x1080) is left alone. +# main+0x1202ee0 the graphics setup config's output size (swap chain), x8 = 2560 | 1440 << 32 (mov/movk), stored at [x21+0x14] +# main+0x31f39f4 the docked render size, the same pattern, stored at [x19+0xb68] +# main+0x112c604 the display mode's output size, read from the table at main+0x3f58540: its 2560x1440 entry becomes the size +# main+0xecbc80 / +0xecbcb4 the float copies of the output width (w9 = 2560.0f) and height (w8 = 1440.0f) in the same object's init +# The float stubs convert through s31, saved below sp and restored (no FP register is known free there) +NOP = 0xd503201f +def render_size(ctx): + here, emit, fs_site, fs_put, ST = ctx.here, ctx.emit, ctx.site, ctx.put, ctx.state + for site in (0x1202ee0, 0x31f39f4): # mov x8,#0xa00; movk x8,#0x5a0,lsl #32 + fs_site(site, '084081d208b4c0f2') + start = here(); emit(ADRP(8, here(), ST)) + for w in (0xf9401d08, # ldr x8,[x8,#0x38] width | height << 32 + 0xb5000068, # cbnz x8,+12 set: keep it + 0xd2814008, # mov x8,#0xa00 2560 + 0xf2c0b408): # movk x8,#0x5a0,lsl #32 1440 + emit(w) + emit(B(here(), site + 8)) + fs_put(site, [B(site, start), NOP], 'render size: %s from the state page (DM_RENDER_SIZE), 2560x1440 when it is 0' % ('output (swap chain) size' if site == 0x1202ee0 else 'docked render size')) + site = 0x112c604 # ldr x8,[x9,x8,lsl #3] the display mode's output size from the table + fs_site(site, '287968f8') + start = here(); emit(0xf8687928) # ldr x8,[x9,x8,lsl #3] + emit(ADRP(16, here(), ST)) + for w in (0xf9401e10, # ldr x16,[x16,#0x38] + 0xb40000b0, # cbz x16,+20 not set: the table's entry + 0xd2814011, # mov x17,#0xa00 + 0xf2c0b411, # movk x17,#0x5a0,lsl #32 + 0xeb11011f, # cmp x8,x17 the 2560x1440 entry (docked) + 0x9a880208): # csel x8,x16,x8,eq + emit(w) + emit(B(here(), site + 4)) + fs_put(site, [B(site, start)], 'render size: the display mode\'s 2560x1440 output entry becomes the state page\'s size (DM_RENDER_SIZE)') + for site, orig, ldr, cbz, fmov, name in ((0xecbc80, 0x52a8a409, 0xb9403929, 0x340000c9, 0x1e2603e9, 'width'), # mov w9,#0x45200000 (2560.0f) + (0xecbcb4, 0x52a89688, 0xb9403d08, 0x340000c8, 0x1e2603e8, 'height')): # mov w8,#0x44b40000 (1440.0f) + r = 9 if name == 'width' else 8 + fs_site(site, orig.to_bytes(4, 'little').hex()) + start = here(); emit(ADRP(r, here(), ST)) + for w in (ldr, # ldr wR,[xR,#0x38 / 0x3c] + cbz, # cbz wR,orig (+24) + 0xfc1f0fff, # str d31,[sp,#-16]! + 0x1e23001f | r << 5, # ucvtf s31,wR + fmov, # fmov wR,s31 + 0xfc4107ff): # ldr d31,[sp],#16 + emit(w) + emit(B(here(), site + 4)) + emit(orig); emit(B(here(), site + 4)) + fs_put(site, [B(site, start)], 'render size: output %s as a float from the state page (DM_RENDER_SIZE)' % name) + ctx.capabilities.add('RENDER_SIZE') + MATCH_FRAME_STEP = {'main': [ {'name': 'frame ratio from the host\'s step', 'size': 0x9b4, 'fingerprints': ['6ae2aff5344d14568e4dbaf93455e2d8278384bf892ed6c6eca87fef98fbcd1d'], 'stub': frame_step, # v131072 main+0x6e6be0 'others': {'dynamic resolution': {'size': 0x294, 'fingerprints': ['7af6ceb0aedf8e0c17dc08ce17fcd6a7cba6d394a0d09e3b504c6d668dc418e7']}, # v131072 main+0x8065e0 @@ -84,4 +136,7 @@ def dynamic_resolution(ctx): {'what': 'dynamic resolution: full size, or a climb on the load measured at each level', 'now': 'game', 'goal': 'game', 'purpose': 'rendering', 'why': "the game's own dynamic-resolution level function and update, found by their functions' fingerprints on any build that keeps both; switchable (DM_DYNAMIC_RESOLUTION)", 'checked': 'v131072 main: one function with each fingerprint (the level function a leaf, x2..x11 / x16 / x17 / s0..s2 free), its callers, the update and the controller fields read by disassembly, the fields read in play (2026-11-08); the climb run natively against a model of the update and in play to full size (2026-11-09)'}, + {'what': 'render size: the docked output and render size, the display mode\'s 2560x1440 entry and the float output size from the state page', 'now': 'build', 'goal': 'game', 'purpose': 'rendering', + 'why': "five fixed 2560x1440 constants in v131072's main (the sites PR #1460 found for its ultrawide cuts), placed by address and only when the frame-step function sits at v131072's place; a function-matched rule could carry them to other builds", + 'checked': 'v131072 headless at 2560x1440 and 3840x2160 (swapchain at the size, no crash, 60 fps held), in play at 2560x1440 and 3024x1702 (M5 Max, macOS 26.6.2, 2026-11-08 and 09)'}, ] diff --git a/dm/games/settings.tsv b/dm/games/settings.tsv index 15f4824107..2940f9276b 100644 --- a/dm/games/settings.tsv +++ b/dm/games/settings.tsv @@ -17,6 +17,7 @@ DM_FPS_TARGET choice 30=30 fps,60=60 fps,120=120 fps?DM_GAME_FPS_MAX==120&platform:mac DM_GAME_FPS_TARGET DM_GAME_FPS_TARGET!=0 Game Frame rate level=basic DM_DYNAMIC_RESOLUTION toggle - 0 fixups:DYNAMIC_RESOLUTION Game Dynamic resolution Lets the game lower its resolution under load. Turn off to keep full resolution for the selected console mode. DM_RENDER_SCALE range 0.5:1.0:0.05 1.0 fixups:RENDER_SCALE Game Render scale level=basic +DM_RENDER_SIZE choice 0=Game's own (as on the Switch),1920x1080=1920 × 1080,2560x1440=2560 × 1440,3840x2160=3840 × 2160 0 fixups:RENDER_SIZE Game Resolution Higher sizes take more GPU time per frame level=basic DM_OPMODE choice 1=Docked,0=Handheld DM_GAME_OPMODE always Game Console mode level=basic DM_PRESENT_UPSCALE choice off=Standard,metalfx=MetalFX off always Game Upscaling Uses more GPU time and can increase heat. DM_UPSCALER choice game=Game's own,metalfx=MetalFX game DM_GAME_UPSCALER_N!=0 Game Game's upscaler diff --git a/dm/host/loader.c b/dm/host/loader.c index da3a970c9e..1ba2825098 100644 --- a/dm/host/loader.c +++ b/dm/host/loader.c @@ -326,6 +326,16 @@ void dm_fps_state_apply(void) { const char *dr = getenv("DM_DYNAMIC_RESOLUTION"); uint32_t dyn = dr && !strcmp(dr, "1"); if (dr && strcmp(dr, "0") && strcmp(dr, "1")) LOG("[RED] DM_DYNAMIC_RESOLUTION=%s: must be 0 or 1; keeping full resolution", dr); memcpy(dm_fps_state + 0x40, &dyn, sizeof dyn); + // Render size, for builds whose stub reads it (the RENDER_SIZE capability: Hades II 1.0.131248's app init): DM_RENDER_SIZE=x, 16:9 from 1280x720 to 3840x2160, sets the + // game's own swapchain and screen-sized targets; unset or 0 keeps the game's size. Builds without such a stub ignore the field + const char *rz = getenv("DM_RENDER_SIZE"); uint32_t wh[2] = {0, 0}; + if (rz && strcmp(rz, "0")) { + unsigned w = 0, h = 0; char tail = 0; + if (sscanf(rz, "%ux%u%c", &w, &h, &tail) != 2 || w * 9 != h * 16 || w < 1280 || w > 3840) + LOG("[RED] DM_RENDER_SIZE=%s: must be x, 16:9, from 1280x720 to 3840x2160; keeping the game's size", rz); + else { wh[0] = w; wh[1] = h; LOG("%s: render size %ux%u (DM_RENDER_SIZE)", g_fps_mod, w, h); } + } + memcpy(dm_fps_state + 0x38, wh, sizeof wh); // Screen shape: DM_SCREEN_ASPECT, the screen's width / height between 1.3 and 1.77, makes the builds with screen-shape stubs // (Breath of the Wild 1.9.0's patches.py) render that shape: the output keeps its width (1920) and takes the height that gives the ratio, a multiple of 48 so the // 2/3-size layout space (1280 wide) stays whole: 1.43 → 1920x1344 and 1280x896. State +0x48 u32 output height, +0x4c u32 layout height, +0x50 its float; 0 = 16:9 diff --git a/dm/tools/patch_nso.py b/dm/tools/patch_nso.py index c0594bb86a..17481dcc4f 100644 --- a/dm/tools/patch_nso.py +++ b/dm/tools/patch_nso.py @@ -246,6 +246,9 @@ def load_patches(): print(f'{NAME}: {ue_ring_why}') elif ue_ring_why.startswith('[RED] '): print(f'[RED] {NAME}: {ue_ring_why[6:]}: its dynamic buffers keep 3 copies') +# A main with frame step stubs takes the page after the key page as its state page ("Frame step in whole vsyncs"). The appended layout rounds the patch area up to 64 KB, which leaves +# that page free unless the key page ends on a 64 KB boundary (Hades II 1.0.131248: key page 0x590c000, patch area 0x5910000); the patch area then starts 64 KB later +if not FAR and NAME == 'main' and (BUILD_ID in PATCHES['FRAME_STEP'] or FS_MATCH) and KEY_PAGE_OFF + 0x8000 > PATCH_OFF: PATCH_OFF += 0x10000 md = Cs(CS_ARCH_ARM64, CS_MODE_ARM); md.detail = True patch = bytearray(); fix = []; gates = []; stats = {} patch_front, patch_back, PATCH_BASE = patch, bytearray(), PATCH_OFF # the area emit() writes into and its offset: the front one unless TWO puts a site in the back one @@ -1554,7 +1557,8 @@ def stdalloc_gates(): # runs the original instructions), +4 30 fps movie/cinematic flag, +8 double lead (TOTK), +0x10 float render scale (TOTK, BotW), +0x18 double game seconds (TOTK), # +0x20 u32 step in vsyncs (host; 0 = not decided yet), +0x24 u32 a step the game fixes itself (BotW's VFR override; 0 = none), +0x28 u32 AoC's vsyncs per update, marked by # its first stub (0 = off), +0x30 u64 vsyncs stepped (the stubs; logged by the host to check the game's speed), +0x40 u32 1 = the game's own dynamic resolution runs, 0 = its -# stub holds full resolution (DM_DYNAMIC_RESOLUTION, written by the loader; the stub declares the DYNAMIC_RESOLUTION capability). Stub bodies assembled with clang +# stub holds full resolution (DM_DYNAMIC_RESOLUTION, written by the loader; the stub declares the DYNAMIC_RESOLUTION capability), +0x38 u32 width, u32 height of the game's render size +# (Hades II 1.0.131248, Ocarina of Time v131072; DM_RENDER_SIZE, written by the loader, 0 = the game's own; the stub declares the RENDER_SIZE capability). Stub bodies assembled with clang # A build's stubs are FRAME_STEP[build ID](ctx) in its patches.py: ctx.here() / ctx.emit(word) assemble into the patch area, ctx.site(offset, original bytes) asserts a site and that it is # no rewrite site, ctx.put(offset, words, reason) writes it (listed with the cuts), ctx.state is the state page's offset, ctx.render_scale = 1 marks a render-scale stub, # ctx.others the other functions a MATCH_FRAME_STEP rule names, ctx.address(offset) the data address an adrp there and the add / load / store after it make (in the original diff --git a/dm/tools/tests/test_frame_step_page.py b/dm/tools/tests/test_frame_step_page.py new file mode 100644 index 0000000000..27b55aa4b6 --- /dev/null +++ b/dm/tools/tests/test_frame_step_page.py @@ -0,0 +1,55 @@ +"""dm/tools/patch_nso.py: the frame step state page (the page after the key page) stays free when the key page ends on a 64 KB boundary, where the appended patch area would start +right after it (Hades II 1.0.131248: key page 0x590c000, patch area 0x5910000, and the rewrite stopped with 'frame step state page'); modules without frame step stubs keep their layout""" +import os +from pathlib import Path +import struct +import subprocess +import sys +import tempfile +import unittest + +REPO = Path(__file__).resolve().parents[3] +sys.path.insert(0, str(REPO / 'dm/tools/tests')) +from test_nso import make_nso + +BUILD_ID = bytes(range(0x10)).hex() # make_nso's build ID + + +def module(bss): + """A main of 0x1000 of NOPs, an empty eh_frame_hdr in ro and 0x1000 of data: image 0x3000, then bss""" + text = bytearray(struct.pack('`: writes player 1's physical input (keyboard, mouse touches, controllers; never `DM_KEYS` / `DM_CTL`) to the file as `DM_KEYS` steps in presented frames, for replaying a run (`DM_KEYS=@`) DM_REGIONS diagnostic `=` writes the table of the SDK's address regions every 2 s (alias offset, size, where the request returns to in the game, bytes mapped, the part opened, the SDK offset the request came through; `hle_svc.c` "Address regions"); the NSP script's address region check sets it DM_RENDER_SCALE player `0.5` to `1.0`: fixes the game's 3D views at that fraction of their size and turns its dynamic resolution off, for builds with a render scale stub; `1.0` (the default) keeps it +DM_RENDER_SIZE player `x` (16:9, `1280x720` to `3840x2160`): the size the game renders at, its swapchain and screen-sized targets, for builds with a render-size stub (the RENDER_SIZE capability: Hades II 1.0.131248; Ocarina of Time v131072, docked); `0` or unset keeps the game's own DM_RESOURCE_AOC path The add-on content folder the iOS build copies into the app's `aoc/` (empty for none); written by `gen_resources.py`, read by `stage_resources.sh` DM_RESOURCE_BUILD switch Package version (for example `v327680`), written to `Gen/resources.env` by `gen_resources.py`; with `DM_COPY_ROMFS=NO` the copy phase puts it in the `build=` field of the app's `romfs.id` DM_RESOURCE_CHAIN_H path Path of `dm/gfx/nvn/dmsh_chain.h`, written to `Gen/resources.env` by `build_ipa.sh`; the Xcode copy phase (`stage_resources.sh`) stops when the prepared shaders are not of its chain version diff --git a/docs/reference/rewriter.md b/docs/reference/rewriter.md index a403848c98..5da91b6597 100644 --- a/docs/reference/rewriter.md +++ b/docs/reference/rewriter.md @@ -315,6 +315,13 @@ To enroll a cut for any game's own module: - **Fix:** for a front patch area, reserve a zero-filled 16 KB state page immediately after the key page by extending `IMAGE_SIZE`. The existing Mac and iOS loaders map it with the BSS; no padding is added to the game binary. Ordinary modules retain their existing layout. - **Found on:** [ASTRAL CHAIN](../../dm/games/01007300020FA000/README.md#frame-rate). +### Frame-step state when the key page ends on 64 KB + +- **Symptom:** `frame step state page` assertion when a `FRAME_STEP` (or `MATCH_FRAME_STEP`) stub is added to a module whose patch area is appended after the image. +- **Cause:** the state page is the page after the key page, and the appended patch area starts at the next 64 KB boundary after the key page. When the key page itself ends on a 64 KB boundary, the patch area starts exactly where the state page has to go. +- **Fix:** in that case the patch area starts 64 KB later. Modules without frame-step stubs, and those whose rounding already leaves the page free, keep their layout (`dm/tools/tests/test_frame_step_page.py`). +- **Found on:** [Hades II](../../dm/games/0100A00019DE0000/README.md) 1.0.131248 `main` (key page `0x590c000`, patch area `0x5910000`). + ### Patch area right before the base for a long text - **Symptom:** `B()` range assertion, then `patch area of … bytes does not fit in the … before the base`. diff --git a/docs/settings.md b/docs/settings.md index a826eeeacf..c0ba5925ad 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -3,7 +3,7 @@ The screen before the game starts shows the settings the game supports. A setting that only matters while another is on appears under it and disappears when that one is turned off. Tap **Play** to start; the app remembers your choices for the next start. All settings are on one scrollable screen, under **Game**, **Controls** and **Performance**. Tap a menu or move a slider there; no settings page needs opening. **Upscaling** is in **Game**, beside **Console mode**. A Mac app shows the same settings in a [window of its own](#the-mac-settings-window). - [Tested defaults](#tested-defaults) -- [Game](#game): [Frame rate](#frame-rate), [Render scale](#render-scale), [Console mode](#console-mode), [Upscaling](#upscaling), [Game's upscaler](#games-upscaler), [Game language](#game-language), [Picture](#picture), [Frame-rate counter](#frame-rate-counter) +- [Game](#game): [Frame rate](#frame-rate), [Render scale](#render-scale), [Resolution](#resolution), [Console mode](#console-mode), [Upscaling](#upscaling), [Game's upscaler](#games-upscaler), [Game language](#game-language), [Picture](#picture), [Frame-rate counter](#frame-rate-counter) - [Controls](#controls): [Touch feedback](#touch-feedback), [Game rumble](#game-rumble), [Rumble strength](#rumble-strength), [Rumble cutoff](#rumble-cutoff), [Press a button to join](#press-a-button-to-join) - [Performance](#performance): [Frame buffering](#frame-buffering), [Metal 4 pipelines](#metal-4-pipelines), [Pipeline prebuild](#pipeline-prebuild), [Encode thread](#encode-thread), [Hold frames when late](#hold-frames-when-late), [Performance HUD](#performance-hud), [Reset to tested defaults](#reset-to-tested-defaults) - [The Mac settings window](#the-mac-settings-window): [Display mode](#display-mode) @@ -35,6 +35,10 @@ Off, the default, keeps the 3D picture at full size. On lets the game lower its The size of the 3D picture, from 50 to 100 %. Below 100 % the size is fixed there and the game's own dynamic resolution is off; 100 % keeps the game's own. Lower can be lighter on the GPU but is blurrier; the HUD and text keep their sharpness. Only games the app can scale offer it. +### Resolution + +The size the game renders at, for games the app can resize (Hades II 1.0.131248; Ocarina of Time v131072, docked): **Game's own**, the size it renders on the Switch (Hades II 1280 × 720, Ocarina of Time 2560 × 1440, of which it draws 80 % and scales up), **1920 × 1080**, **2560 × 1440** or **3840 × 2160**. A larger size is sharper on a larger screen and takes more GPU time per frame; the HUD and text are laid out for the size. + ### Console mode **Docked** renders at the Switch's TV resolution, **Handheld** at its lower handheld resolution, which is lighter on the phone and can give a higher frame rate.