Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion PEANUTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ Banana Native ships several releases a day, so this fork is kept as a **thin ove
`onCreate` that touches the last-3-played list for dynamic shortcuts (`dev.peanuts.launch.RecentGames`, `peanuts/docs/LAUNCHERS.md`); (2026-11-21) one line at the top of
`fpsTick` and one in `onDestroy` for the total play time (`dev.peanuts.launch.PlayTime`; the game page's Played row is one line in `MainActivity`'s More card); and
(2026-11-13) in `start()`'s env assembly, two lines adding `DM_ROMFS_OVERLAY`/`DM_CHEATS` for the enabled Mods (`dev.peanuts.mods.ModRuntime`,
`design/platform/DESIGN-MODS.md`); (2026-11-18) one line in `settingsEnv` after `ResScale.env`: `dev.peanuts.Companion.env(this, id, env)` adds `PN_COMPANION=off` when the title's Second screen is Off, which is the default on a device without a second display (`Companion.hasSecondDisplay`); internal shader-preparation mode (`dev.peanuts.build.ShaderCapture`) covers the game surface, isolates its save/environment, suppresses play-session hooks and input, and reports errors to Build.
`design/platform/DESIGN-MODS.md`); (2026-11-18) one line in `settingsEnv` after `ResScale.env`: `dev.peanuts.Companion.env(this, id, env)` adds `PN_COMPANION=off` when the title's Second screen is Off, which is the default on a device without a second display (`Companion.hasSecondDisplay`); (2026-11-24) one line after it: `dev.peanuts.shaders.HostWatch.env(this, id, env)` registers the Peanuts tab's Smoother next start backend (`ShaderWatch`) in the game's process and adds `PN_SHADERWATCH=1` when learning is on for the title (`peanuts/UPSTREAM-EDITS.md` "Smoother next start"); internal shader-preparation mode (`dev.peanuts.build.ShaderCapture`) covers the game surface, isolates its save/environment, suppresses play-session hooks and input, and reports errors to Build.
(2026-11-17) `hostSetup` and the active existing `fpsTick` forward the current display's presentation deadline through a marked helper. The same tick applies `dev.peanuts.display.RunningDisplayMode` before reading the deadline; pause and destruction release its window-local request. Only the running effective 30 fps cap with requested FG off selects a same-resolution 60 Hz mode; pending restart preferences are ignored.
- `android/app/src/main/cpp/nxlaunch.c` — JNI entry points forwarded to `dm/peanuts`; (2026-11-17) `Native.java`/`nxlaunch.c` weakly forward the active display's queue lead to `nxhost_presentation_deadline_set`, exported in `vk_android.h`. Nonpositive or unavailable deadlines become zero; older hosts ignore the hint.
- `android/app/src/main/java/dev/nxnative/android/Lsfg.java` — (2026-11-17) `push` releases the Activity's display request before its native FG enable call; actual display switching is asynchronous.
- `dm/gfx/vk_android/vk_android.h`, `vka_framegen.c`, `Native.java`, `nxlaunch.c` — (2026-11-17) expose initialized requested FG state independently of rendering warm-up. An unavailable interface leaves display selection unrestricted; external native changes use the existing Activity tick.
- `android/host/CMakeLists.txt`, `android/app/src/main/cpp/CMakeLists.txt` — add the `dm/peanuts` sources.
- `dm/gfx/vk_android/vka_present.c` — one call per presented frame (`peanuts_tick()`), beside `ovl_draw`; (2026-11-17) one weak declaration and one argument in `ovl_draw`'s `vko_place(...)`: `peanuts_ovl_corner(s, g_ocorner[s])` (the stats block's corner chosen in the launcher; the build tag steps aside from a top-left block).
- `dm/host/hle_audren.c` — (2026-11-20, audio follows the game's pace) in `render_main`, a weak declaration of `pn_audio_follow` and two marked lines: the rendered frame goes through `pn_audio_follow` (`dm/peanuts/peanuts_audiosync.c`; the clock's next render moves by the frames it gave out), and a call that gives nothing out yet (the stretch filling its look-ahead) appends no block. `dm/peanuts/peanuts_audiovoice.c` takes over `nn::audio::SetVoicePlayState` with its own `HLE_FORCE` (calls the SDK's own first): if upstream ever takes that symbol over too, merge the two. `peanuts_tick` feeds the game's frames (`pn_as_frame`, `nvn_game_fps` weak). `PN_AUDIO_FOLLOW` 0 / 1 (automatic, default) / 2.
- `dm/gfx/vk_android/vka_pso.c` — (2026-11-24, Smoother next start) the prewarm list's counts for the Peanuts tab (`vka_pso_watch`, read through `dm/peanuts/peanuts_shaderwatch.c`) and, with `PN_SHADERWATCH=1`, the pipelines a game's runs used made first and before the game starts, also on Qualcomm's driver before 512.800 (`sw_*` in one `PEANUTS begin`/`end` block, the file format and merge in `dm/peanuts/peanuts_swhot.h`; transform feedback capture pipelines with their layout in `dm/peanuts/peanuts_swtf.h`, made ahead by `sw_tf_make` through `vka_tf.c` `vka_tf_learned`); one-line marked hooks in `pc_open_once`, `save_now`, `vka_pso_save`, `vka_pso_prepare_launch`, `nxhost_prewarm_progress`, `pw_note`, `pw_main`, `pw_start`, `gfx_obtain`, `cs_obtain` and the entry `gval` (`swh`). Rule 2's exception, as the startup prewarm beside it. `peanuts/UPSTREAM-EDITS.md` "Smoother next start".
- `dm/gfx/vk_android/vka_dev.c` `vka_gpu_floor` — (2026-11-23, #113/#257) one weak call into `dm/peanuts/peanuts_gpufloor.c`: the KGSL clock floor's beat on kernels that apply the constraint only to flagged commands (`PN_GPU_FLOOR_BEAT`). `peanuts/UPSTREAM-EDITS.md` Round 62.
- `dm/gfx/vk_android/vka_dev.c` `vka_cap_period_clamp`, `vka_perf.c` — (2026-11-24, 0.1.8 hardening) the active frame cap's period as the shortest, one function for the GPU floor's period and the ADPF target (`dm_fps_cap_get` / `nxhost_fps_limit_get`, weak). `peanuts/UPSTREAM-EDITS.md` "0.1.8 hardening".
- `dm/gfx/vk_android/vka_tex.c` `vka_tex_b2t_mirror`, `vka_dlss.c` `dpass`, `vka_fsr3.c` `pass` — (2026-11-24, 0.1.8 hardening) one `vka_dyn_invalidate()` each after a compute pass recorded between the game's dispatches, so the next dispatch pushes its descriptors again (`vka_draw.c` `push_same`). `peanuts/UPSTREAM-EDITS.md` "0.1.8 hardening".
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// PEANUTS: a test of the fork's own classes (HostCounts: the host's numbers as the Peanuts tab shows them); upstream has no dev.peanuts tests
package dev.peanuts.shaders;

/** HostCounts on the JVM (peanuts/tests/test_shader_watch.py): the host's four numbers as the Peanuts tab's */
public final class HostCountsJvmTest {
private static int failed;

private static void check(boolean ok, String what) {
if (!ok) { failed++; System.out.println("FAIL " + what); }
}

public static void main(String[] args) {
// the host cannot say (no libnxhost of this version, or not loaded)
check(!HostCounts.available(null), "no host: not available");
check(HostCounts.learned(null) == HostCounts.UNKNOWN && HostCounts.ready(null) == HostCounts.UNKNOWN, "no host: unknown numbers");
check(!HostCounts.available(new int[3]), "a short answer is no answer");

// the list not read yet: the game has not drawn its first program (its menus, a logo); a list is still to come
int[] early = {-1, 0, 0, 0};
check(HostCounts.available(early), "not read yet: still available");
check(HostCounts.learned(early) == HostCounts.UNKNOWN && HostCounts.ready(early) == HostCounts.UNKNOWN, "not read yet: numbers unknown");

// no list at all (no DM_TEMP: the host keeps nothing)
int[] none = {0, 0, 0, 0};
check(!HostCounts.available(none), "no list: not available");
check(HostCounts.learned(none) == HostCounts.UNKNOWN, "no list: learned unknown");

// a list: this run's new pipelines and what the next start makes ahead
int[] list = {1, 12, 642, 868};
check(HostCounts.available(list), "a list: available");
check(HostCounts.learned(list) == 12, "learned this run");
check(HostCounts.ready(list) == 642, "made ahead next start on this driver, not every driver's records");

// a driver whose next start makes none ahead (prewarm off there): ready 0, learned still counts
int[] off = {1, 5, 0, 868};
check(HostCounts.ready(off) == 0 && HostCounts.learned(off) == 5, "prewarm off: 0 ready, learned counted");

// never a negative count from a host that misbehaves
check(HostCounts.learned(new int[]{1, -3, -1, 0}) == 0 && HostCounts.ready(new int[]{1, -3, -1, 0}) == 0, "no negative counts");

if (failed > 0) { System.out.println(failed + " failed"); System.exit(1); }
System.out.println("ok");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ private String settingsEnv(String id, Pack pack, List<String> env) { // PEANUT
ScreenMode.env(this, id, env); // PEANUTS: Console mode (DM_OPMODE) for a game whose Resolution does not set it
ResScale.env(this, id, env); // PEANUTS: Resolution scale (DM_RES_SCALE) when it is not 1x
dev.peanuts.Companion.env(this, id, env); // PEANUTS: companions off (PN_COMPANION=off) when the title's Second screen is Off, the default without a second display
dev.peanuts.shaders.HostWatch.env(this, id, env); // PEANUTS: Smoother next start: the Peanuts tab's backend (ShaderWatch) in the game's process
if (prof != null) env.addAll(prof.resolutionEnv(Prefs.startWindow(this, id))); // a Resolution preset's window, else Game resolution's (Prefs.startWindow, ResPresets)
// Resolution, Upscaling quality and Graphics quality (a render_cfg row: Profile.renderCfg), kept as the setting this run starts with: the loader sizes the render target
// pool for it, and the in-game panel compares a pick with it (Profile.renderRestartNote)
Expand Down
10 changes: 10 additions & 0 deletions android/app/src/main/java/dev/peanuts/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ private Bridge() {}
/** opMode(), or -1 when the host does not have it (an older libnxhost), is not loaded, or the game has not shown a frame yet (asking earlier would fix the mode) */
public static int opModeSafe() { try { return opMode(); } catch (UnsatisfiedLinkError e) { return -1; } }

/** The host's prewarm list for Smoother next start (dm/peanuts/peanuts_shaderwatch.c, vka_pso.c vka_pso_watch) into out[0..3]: the list (1 kept, 0 none, -1 not read
* yet), the pipelines new to it this run, those the next start makes ahead on this driver, its records in all; false when the host cannot say */
public static native boolean shaderWatch(int[] out);
/** shaderWatch(out), false when the host does not have it (an older libnxhost) or is not loaded */
public static boolean shaderWatchSafe(int[] out) { try { return shaderWatch(out); } catch (UnsatisfiedLinkError e) { return false; } }
/** Smoother next start's learning turned on or off while the game runs (the start reads PN_SHADERWATCH): false when the host cannot */
public static native boolean shaderWatchLearn(boolean on);
/** shaderWatchLearn(on), false when the host does not have it or is not loaded */
public static boolean shaderWatchLearnSafe(boolean on) { try { return shaderWatchLearn(on); } catch (UnsatisfiedLinkError e) { return false; } }

public static final int RT_PENDING = 0, RT_LOADED = 1, RT_NONE = 2, RT_FAILED = 3;

/** Core::Mods::HapticKind (dm/peanuts/peanuts.h): what raised a pulse. */
Expand Down
24 changes: 24 additions & 0 deletions android/app/src/main/java/dev/peanuts/shaders/HostCounts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.peanuts.shaders;

/**
* The host's four numbers (dev.peanuts.Bridge.shaderWatch, dm/gfx/vk_android/vka_pso.c vka_pso_watch) as {@link ShaderWatch}'s, for {@link HostWatch}. Pure, so
* HostCountsJvmTest checks it on the JVM. v: null when the host cannot say, else {the list: 1 kept, 0 none, -1 not read yet; pipelines new to it this run;
* pipelines the next start makes ahead on this driver; records in all}.
*/
final class HostCounts {
private HostCounts() {}

/** ShaderWatch.UNKNOWN (that class reads Android's prefs, so it is not compiled into the JVM test; HostWatch checks the two are equal) */
static final int UNKNOWN = -1;

/** Whether the host keeps a list for this game: it can say, and the list is not off (-1, not read yet, is a list still to come) */
static boolean available(int[] v) { return v != null && v.length >= 4 && v[0] != 0; }

/** The pipelines new to the list this run, UNKNOWN before the host has read the list */
static int learned(int[] v) { return read(v) ? Math.max(0, v[1]) : UNKNOWN; }

/** The pipelines the next start makes ahead on this driver, UNKNOWN before the host has read the list */
static int ready(int[] v) { return read(v) ? Math.max(0, v[2]) : UNKNOWN; }

private static boolean read(int[] v) { return v != null && v.length >= 4 && v[0] == 1; }
}
64 changes: 64 additions & 0 deletions android/app/src/main/java/dev/peanuts/shaders/HostWatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dev.peanuts.shaders;

import android.app.Activity;
import android.os.SystemClock;

import java.util.List;

/**
* The backend of {@link ShaderWatch} (Smoother next start): the Vulkan replay's prewarm list. While a game runs the host puts every pipeline it makes on the
* frame path or in the background into the game's list (DM_TEMP/vk_pipelines.keys, dm/gfx/vk_android/vka_pso.c pw_note): the shaders and the state a draw
* needed, by the shader library's keys, so the list holds for every driver and drops what a game update or a new shader library no longer has. Where the driver
* allows it the next start makes the whole list in the background; on Qualcomm's driver before 512.800 it makes none of it (a pipeline holds memory outside the
* process there), and those pipelines are made again while the game plays, at every start, their draws skipped until then.
* <p>
* Learning on (the tab's switch for this game, {@link #LINE} at the start): each run also keeps the pipelines it used, per game and driver (vka_pso.c sw_*), and
* the next start makes those first and before the game starts, behind "Preparing shaders", also on that driver, where it stops when memory runs short. Off: the
* host does as upstream's does, and nothing of this is read or written. The numbers come from the list itself through
* {@link dev.peanuts.Bridge#shaderWatch} (dm/peanuts/peanuts_shaderwatch.c, vka_pso.c vka_pso_watch).
* <p>
* Registered once in the game's process: {@link #env} runs at every start of the game (GameActivity.settingsEnv), before the host and the tab.
*/
public final class HostWatch implements ShaderWatch.Backend {
private static final HostWatch INSTANCE = new HostWatch();
/** The host is asked at most this often (the tab reads status about once a second, and the walk holds the list's lock) */
static final long READ_MS = 500;

private final int[] v = new int[4];
private boolean ok;
private long readAt = Long.MIN_VALUE / 2;

private HostWatch() {}

static { if (HostCounts.UNKNOWN != ShaderWatch.UNKNOWN) throw new AssertionError("HostCounts.UNKNOWN"); }

/** The line that turns learning on for a run (vka_pso.c sw_on); without it the host learns and prepares as upstream's does */
static final String LINE = "PN_SHADERWATCH=1";

/**
* At the start of a game, in its process: the backend registered (once is enough; again is harmless), and learning on for this run when the player turned it on
* for this game. A preparation boot of Build (dev.peanuts.build.ShaderCapture) is no play: never
*/
public static void env(Activity a, String titleId, List<String> env) {
ShaderWatch.backend(INSTANCE);
env.removeIf(s -> s.startsWith("PN_SHADERWATCH="));
if (titleId != null && ShaderWatch.on(a, titleId) && !dev.peanuts.build.ShaderCapture.active(a)) env.add(LINE);
}

private synchronized int[] read() {
long now = SystemClock.elapsedRealtime();
if (now - readAt >= READ_MS) {
int[] o = new int[4];
ok = dev.peanuts.Bridge.shaderWatchSafe(o);
if (ok) System.arraycopy(o, 0, v, 0, 4);
readAt = now;
}
return ok ? v.clone() : null;
}

@Override public boolean available(android.content.Context c, String titleId) { return HostCounts.available(read()); }
@Override public int learned() { return HostCounts.learned(read()); }
@Override public int ready(android.content.Context c, String titleId) { return HostCounts.ready(read()); }
/** The switch turned while the game runs: the host keeps (or stops keeping) this run's pipelines at once; the next start follows the switch as it is then */
@Override public void learning(android.content.Context c, String titleId, boolean on) { dev.peanuts.Bridge.shaderWatchLearnSafe(on); }
}
Loading