From 515bbf1748e71753f7bd4892fe5eec28d430c36e Mon Sep 17 00:00:00 2001 From: dpadr Date: Thu, 5 Nov 2026 10:37:35 -0800 Subject: [PATCH 1/3] A charter for agent-driven work: one aim, look before you build, judge on the base Macs Most of nxnative is written by agents started by people who don't see each other's sessions: several people on the same game at once, work done twice or undone, and changes measured on a Pro or Max that nobody checks on the base Macs most players own. docs/charter.md says what the project is for (games that play as on the console, correctness including pacing, time and controllers), the goals (Switch games on an 8 GB M1, Switch 2 games on a 16 GB M2 with a 10-core GPU; benchmarks Tears of the Kingdom and Ocarina of Time), the priorities, and a bar for pull requests that rises with reach. AGENTS.md, CONTRIBUTING.md, docs/agents/README.md and the pull request template carry the same rules: start from the latest main, look for existing work by label and title, make your own work findable with an early draft pull request, never work on your local main. 06-dev-loop.md gets the search commands (with and without gh), the branch cycle and a guide to judging a pull request's tier; the shader-chain and per-build rules move there from AGENTS.md unchanged. docs/decisions.md starts a log of choices every game gets. A "Test request on a low-spec device" issue form is labelled automatically (issue_areas.py, pr_areas.py, with tests). This is a proposal for the maintainers to accept, change or reject. Co-Authored-By: Claude Opus 5.5 --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- .github/ISSUE_TEMPLATE/test_request.yml | 76 ++++++++++++ .github/pull_request_template.md | 5 +- AGENTS.md | 24 ++-- CONTRIBUTING.md | 10 +- dm/tools/issue_areas.py | 2 +- dm/tools/pr_areas.py | 3 +- dm/tools/tests/test_issue_areas.py | 3 +- docs/agents/06-dev-loop.md | 72 +++++++++++ docs/agents/README.md | 1 + docs/charter.md | 157 ++++++++++++++++++++++++ docs/decisions.md | 13 ++ 12 files changed, 350 insertions(+), 18 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/test_request.yml create mode 100644 docs/charter.md create mode 100644 docs/decisions.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4f6c725f0f..099e479fea 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -31,7 +31,7 @@ body: id: commit attributes: label: nxnative commit - description: "`git rev-parse --short HEAD` in the checkout you built from (or the date you downloaded it)." + description: "`git rev-parse --short HEAD` in the checkout you built from (or the date you downloaded it). Try the latest `main` first (`git fetch origin`, rebuild from `origin/main`): the problem may be fixed already." placeholder: 4639c511 validations: required: true diff --git a/.github/ISSUE_TEMPLATE/test_request.yml b/.github/ISSUE_TEMPLATE/test_request.yml new file mode 100644 index 0000000000..4784bafc55 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/test_request.yml @@ -0,0 +1,76 @@ +name: Test request on a low-spec device +description: Ask someone with one of the lowest supported devices to run a change or a build and report how it plays +body: + - type: markdown + attributes: + value: | + Most contributors measure on the device they have, often a fast Mac. The [charter](https://github.com/seedds/nxnative/blob/main/docs/charter.md#devices) judges a change on the lowest supported device of each platform it reaches. Use this form to ask someone who owns one to try a change: a quick played check, before and after. + A tester needs their own copy of the game. Never attach or ask for game files, keys or anything extracted from a game. + - type: input + id: change + attributes: + label: What to test + description: The pull request, branch or commit, and the revision to compare it with (usually `main` or the merge base). + placeholder: "PR #1234 against main at 7bccfc88" + validations: + required: true + - type: textarea + id: why + attributes: + label: Why it needs a low-spec test + description: What the change does and what could get better or worse there (memory, CPU per frame, pacing, load time, power). + validations: + required: true + - type: dropdown + id: device + attributes: + label: Device needed + description: The device class the result matters on. Pick every one that applies. + multiple: true + options: + - Mac M1, 8 GB (the Switch game floor) + - Mac M2, 16 GB, 10-core GPU (the Switch 2 game floor) + - Another 8 GB or 16 GB base-chip Mac (M1 to M4) + - iPhone 15 Pro or Pro Max (8 GB) + - M1 iPad + validations: + required: true + - type: input + id: games + attributes: + label: Games, title IDs and versions + description: The games to try. Several are fine; say which matters most. + placeholder: "Splatoon Raiders, 0400380020056000, v65536" + validations: + required: true + - type: textarea + id: steps + attributes: + label: What to do + description: Where in the game, for how long, and which settings. A save point or a smoke route (`dm/games//smoke.tsv`) makes the two runs comparable. Keep it under about 15 minutes. + placeholder: | + From the first boss fight's third stage, play 2 minutes, docked, MetalFX, render scale 1.0. + Once on main, once on the change, same place and settings. + validations: + required: true + - type: textarea + id: report + attributes: + label: What to report + description: The numbers that answer the question. Defaults are filled in; remove what does not apply. + value: | + - Device, chip, GPU cores, memory, macOS or iOS version: + - Commit of each build (`DMCommit` in the Mac app's Info.plist): + - How it played on each build (smooth, stutters, paging, crashes): + - The `[nvn] timing` and `power` lines of the scene from each log (`~/Library/Logs/nxnative/.log`; `log.txt` on iOS): + - Memory: Activity Monitor's memory pressure and the game's Memory column, or a `DM_MEMSTAT` file: + - Screenshots where the picture differs: + validations: + required: true + - type: checkboxes + id: no-game-files + attributes: + label: No game files + options: + - label: Nothing here asks for or contains game files, keys or data extracted from a game. + required: true diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6e6f316afd..70d78be2e9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,4 @@ +<!-- Title: name the game and its title ID when it is about one game ("Star Fox (0400E88025B1A000): …"), so searches and labels find it. Open it as a draft early. --> <!-- Keep a PR to one change. AGENTS.md and CONTRIBUTING.md say where findings go; link to them instead of repeating them here. --> ## What and why @@ -9,7 +10,9 @@ <!-- Delete what does not apply. Say what was not checked too. --> - Tests: <!-- e.g. make -C dm/host/tests GAME=<id> run; make -C dm/gfx/tests GAME=<id> run (Apple silicon, Metal); the dm/tools/tests that apply --> - Games run, with title ID and version: <!-- what was played, for how long, and what was compared (log lines, frame times, screenshots) --> -- Devices and OS: <!-- e.g. M2 Max, macOS 26.1; iPhone 17 Pro Max, iOS 26.1 --> +- Existing work: <!-- the issues, pull requests and branches searched for the same area or game, and how this relates to them (docs/charter.md, Before starting work) --> +- Devices and OS: <!-- e.g. M2 Max, macOS 26.1; iPhone 17 Pro Max, iOS 26.1. Say whether the lowest supported device of each platform the change reaches was among them (docs/charter.md, Devices) --> +- Reach and risk: <!-- narrow, shared or wide (docs/charter.md, The bar rises with reach and risk), and what that tier asks for. For a default changed for every game: the devices it was measured on (a test request issue for the lowest), the switch that restores the old behaviour, and the docs/decisions.md entry --> - For a change to the shader chain, the host or a tool that every game uses: the `scripts/regress.py check --games` report on the games it most likely reaches (`regress.py impact` helps), or why none ([06-dev-loop.md](https://github.com/seedds/nxnative/blob/main/docs/agents/06-dev-loop.md)) - Measurements before and after, where the change is about speed, memory or power diff --git a/AGENTS.md b/AGENTS.md index 94b0630937..fd50623ad5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,8 @@ # Notes for agents -- This repository runs Nintendo Switch games natively on Apple platforms: the game's own code runs, rewritten only where Apple's kernel requires it (`dm/tools/patch_nso.py`), on a host that answers Horizon's SVCs and the SDK's services (`dm/host`) and implements NVN, Vulkan and NVIDIA's desktop OpenGL on Metal (`dm/gfx/nvn`, `dm/gfx/vk`, `dm/gfx/gl`). Every game in the [games table](dm/games/README.md#games) is playable, tested on the Mac or the iPhone (a Mac gameplay test is enough to count); the table lists each with its build, SDK, engine and graphics API, and links its note, `dm/games/<id>/README.md`: what its profile needs and why, what was found on it, how to drive it on the Mac, what is open. [README.md](README.md) is the player-facing page (games, packing, playing); [docs/development.md](docs/development.md) has the internals, the script's options, building by hand, prewarm lists and power. +- This repository runs Nintendo Switch games natively on Apple platforms, to play as they do on the console: the game's own code runs, rewritten only where Apple's kernel requires it (`dm/tools/patch_nso.py`), on a host that answers Horizon's SVCs and the SDK's services (`dm/host`) and implements NVN, Vulkan and NVIDIA's desktop OpenGL on Metal (`dm/gfx/nvn`, `dm/gfx/vk`, `dm/gfx/gl`). Every game in the [games table](dm/games/README.md#games) is playable, tested on the Mac or the iPhone (a Mac gameplay test is enough to count); the table links each game's note, `dm/games/<id>/README.md`. [README.md](README.md) is the player-facing page (games, packing, playing); [docs/development.md](docs/development.md) has the internals, the script's options, building by hand, prewarm lists and power. +- Before any work, read [docs/charter.md](docs/charter.md): the project's aim and priorities, the devices a change is judged on, what counts as a regression, the checks before starting (existing issues, pull requests and branches; the change's reach), how much a pull request must show for its reach and risk, and the rule for defaults every game gets ([docs/decisions.md](docs/decisions.md)). +- **Fetch the latest `main` and check for existing work before starting anything or filing an issue, every time:** pull requests and issues by game and area label (`gh pr list --label "game: <title ID>"`) and by title ID or name, active branches, recent commits to the same files ([06-dev-loop.md](docs/agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). Build on it, or ask its author. **Make yours findable too:** a draft pull request early, the game's name and title ID in its title. - Where to start: | Task | Read first | @@ -12,21 +14,19 @@ | Another Switch title | the NSP script (below), then [docs/agents](docs/agents/README.md) | | Packing, building, prewarm lists, power | [docs/development.md](docs/development.md) | | Checking a change before a pull request | [06-dev-loop.md](docs/agents/06-dev-loop.md) | -- Where a new finding goes, once: a fact about one game (its passes, shader keys, measurements, why its profile needs a key or a cut, its status) in that game's note, in the section it belongs to and marked current or resolved; a general mechanism (a host or tool change that holds for other games) as an entry in its `docs/reference/<subsystem>.md` section (Symptom, Cause, Fix, Found on with the game's note linked), then `python3 dm/tools/docs_symptoms.py` to update the symptom index, and a line under the game note's "Found on this game". Link to a finding instead of repeating it. Adding a game takes its note and its row in the games table. Once Mac gameplay testing passes, add it to README's regular games gallery with a screenshot (`docs/images/gallery.tsv`, then `dm/tools/docs_gallery.py`); Mac testing is sufficient for inclusion. Add caption notes only for noteworthy features or limitations (such as a 60 fps upgrade or controller requirement); otherwise show only the name. Keep testing milestones, platform and remaining validation in the game note. This file changes only when a rule does; it states no game count (the games table is the count). `dm/tools/tests/test_docs.py` checks the links and anchors, the notes and their table rows, the symptom index, and the length of this file (1,500 words) and of each guide in `docs/agents` (6,000). +- Where a new finding goes, once: a fact about one game (its passes, shader keys, measurements, why its profile needs a key or a cut, its status) in that game's note, in the section it belongs to and marked current or resolved; a general mechanism (a host or tool change that holds for other games) as an entry in its `docs/reference/<subsystem>.md` section (Symptom, Cause, Fix, Found on with the game's note linked), then `python3 dm/tools/docs_symptoms.py` to update the symptom index, and a line under the game note's "Found on this game". Link to a finding instead of repeating it. Adding a game takes its note and its row in the games table. Once Mac gameplay testing passes, it joins README's gallery ([CONTRIBUTING.md](CONTRIBUTING.md)); testing milestones and remaining validation stay in the game note. This file changes only when a rule does; it states no game count (the games table is the count). `dm/tools/tests/test_docs.py` checks the links and anchors, the notes and their table rows, the symptom index, and the length of this file (1,500 words) and of each guide in `docs/agents` (6,000). - Each game's constants and shader tables form a game profile in `dm/games/<id>/`, where `<id>` is the base game's title ID: `game.tsv` plus the tables (and `patches.py` when the rewriter has patches for its builds). Mario's profile is `010015100B514000`. Tools pick the profile with `DM_GAME`; `make -C dm/host` and `build_ipa.sh` pick it with `GAME`. There is no default game: set it every time (the tools stop and list the profiles otherwise). Put per-game values in the profile, not in code ([dm/games/README.md](dm/games/README.md)). -- Prefer general optimizations and fixes to game-specific rules. Performance work (frame pacing, power, caches, load times) counts here as much as correctness. First look for a change that holds for every game: Horizon / NVN / Vulkan semantics, or what the binary, its SDK version, its imports or its files show. Use a game-specific rule (a profile key, a rewriter cut, a build-ID gate, a per-game branch in the host) only when it is absolutely necessary, that is, when no general rule can do it. +- Prefer general optimizations and fixes to game-specific rules. Performance (frame pacing, memory, power, load times) is a goal on every device, after correctness and no regressions; a gain on one class of Mac must not cost another ([charter](docs/charter.md#priorities)). First look for a change that holds for every game: Horizon / NVN / Vulkan semantics, or what the binary, its SDK version, its imports or its files show. Use a game-specific rule (a profile key, a rewriter cut, a build-ID gate, a per-game branch in the host) only when it is absolutely necessary, that is, when no general rule can do it. - Find a bug's root cause and fix it there; do not just work around it. Before changing code, find why it happens: the faulting instruction and its decompilation, the value that went wrong and who wrote it, the Horizon / NVN / Vulkan / Metal semantics the host or the translator gets wrong. Then fix that place. A change that only hides the symptom (a stub, a skipped call, a clamp, a retry, a sleep or a longer timeout, a cache flush, a profile key that turns a feature off) is a workaround: use one only when the cause is known and lies where it cannot be fixed (the game's own code, which a rewriter cut changes deliberately, or a platform limit), or when the user asks for a stopgap. Then say so in the code comment and in the game note or reference entry: the cause, or what is still unknown, marked open. -- Per-build knowledge is keyed by the NSO build ID: rewriter cuts, observation gates and frame-step stubs in the profile's `patches.py` (a game's own modules) or `dm/tools/sdk_patches.py` (Nintendo's `sdk` modules, which several games ship), which `dm/tools/patch_nso.py` (the general rewriter) loads, the profile's `build` rows (the builds the game was brought up on, and their display versions; the NSP script packs any other version from a derived profile, without those builds' fixes), and host behaviour that uses fixed module addresses checks `module_t.build_id` (from `fixups.tsv`; `dm_main_build()`). When a new game build appears, carry addresses over with `dm/tools/nso_fnmap.py` and check them by disassembly; never let fixed addresses run on a build they were not found in. For automatic cuts across updates, opt individual patches into `MATCH_CUTS` only after verifying their function fingerprints and assumptions; follow [Function-matched cuts](docs/reference/rewriter.md#function-matched-cuts-for-unregistered-builds). The shared matcher derives addresses from code; fixed addresses remain build-gated. +- Per-build knowledge (rewriter cuts, observation gates, frame-step stubs, host code at fixed module addresses) is keyed by the NSO build ID: never let fixed addresses run on a build they were not found in ([06-dev-loop.md](docs/agents/06-dev-loop.md#9-per-build-knowledge)). - To analyse or port **another** Switch title, first run `scripts/build_ipa_from_nsp.py` on its NSP folder. With no matching profile, it writes a survey to `<NSP folder>/<title ID>_survey/survey.md`, then a provisional profile guessed from the game files (`dm/games/profile_guess.py`; `<build folder>/profile/<title ID>/`; found by the tools through `DM_GAMES_DIR`), with a short heap check on the Mac when the game has virtual address memory, and a best-effort IPA that may not boot. Then follow [docs/agents](docs/agents/README.md) (extraction, binary survey, host bring-up, graphics specifics, debugging recipes; the [symptom index](docs/agents/symptoms.md) for each failure) and add a profile with its note. - Scripts the user runs live in `scripts/` at the repository root. Each one runs from a terminal (non-zero exit on error). `build_ipa_from_nsp.py` also runs in Spyder (F5, configured by the settings block at its top; command-line options override those settings). Tools that only agents or other scripts call stay under `dm/`. - Game files, keys and anything extracted from them live in the game's NSP folder, never in this repository and never in the home folder (it is nearly full): the work folder `<NSP folder>/<id>-work` for extraction, runs and analysis, beside the NSP script's `<id>_build/`. One tool venv serves every game (`<drive>/venv`); other large scratch data goes there too. Do not print key values. - Language: everything is in English. Red log lines (something unimplemented or wrong) start with `[RED] `. Text that must match a game's own Chinese data is written as escapes (`"\xE8\xB5\xB7"`), never as characters. -- The shader translation chain has one version for every game, `DMSH_CHAIN` in `dm/gfx/nvn/dmsh_chain.h`, which the host is compiled with and loads only libraries of. It covers the chain's tools: `dm/gfx/tools/dmsh_*` (`dmsh_build.py`, `dmsh_chain.py`, `dmsh_fetch.py`, `dmsh_vin.py`, `dmsh_pull.py` with its decoder `dmsh_pull.metal`, `dmsh_geometry.py`, `dmsh_facts.py`), `Program.cs`, `ios_metal.py`, `dm/gfx/nvn/dmsh_abi.h` and `dmsh_chain.lock`. A profile's own inputs (`shader_map.tsv`, `shader_facts.tsv`, `shader_pairs.tsv`, `bf_want.tsv`, its `shader_*` / `nvn_*` keys) are not part of it: they are in each shader's cache key, and their digest stamps the libraries (`b-<V>/inputs.tsv`). The procedure: - 1. After changing a chain tool, run `dmsh_chain.py --header` once and commit `dm/gfx/nvn/dmsh_chain.h` with the change (`dm/tools/tests/test_nsp_chain.py` fails on a stale one). - 2. After that, or after changing a profile's inputs, rebuild that profile's shaders: a full `dmsh_build.py` run (Mac and, with `IOSOUT`, iOS) stamps its libraries and writes the profile's `c1_full.tsv` and `cb_extent.tsv` from its Mac outputs (git ignores them; the host takes them only beside the stamp they name). Give each game its own output directory. - 3. Rebuild the host. - - The translator is `dm/gfx/tools/dmsh_xlate_bin`, which matches `dmsh_chain.lock`; a fresh `dotnet publish` does not. -- A change to the chain, host or tools runs `scripts/regress.py check --games` on the five local games it is most likely to reach (`regress.py impact` helps): more only when truly needed, fewer when its reach is narrow and clear. Its report, naming the games and why, goes into the PR ([06-dev-loop.md](docs/agents/06-dev-loop.md)). +- The shader translation chain has one version for every game (`DMSH_CHAIN` in `dm/gfx/nvn/dmsh_chain.h`): after changing a chain tool, run `dmsh_chain.py --header` and commit the header with the change, then rebuild each affected profile's shaders and the host ([06-dev-loop.md](docs/agents/06-dev-loop.md#8-the-shader-chain-version)). +- What a change must show grows with its reach and risk ([charter](docs/charter.md#pull-requests); judge the tier with [Which tier](docs/agents/06-dev-loop.md#which-tier) before starting): for the chain, host or tools, `regress.py impact` names the games it reaches and `scripts/regress.py check --games` runs those you have; its report, naming the games and why, goes into the PR ([06-dev-loop.md](docs/agents/06-dev-loop.md)). +- Measure on the device a claim is about and name it ([charter](docs/charter.md#devices)). The log's `GPU p50` is each frame's GPU span, idle gaps included, not busy time: judge whether the GPU or the CPU limits a frame from `DM_NVN_GPUPROF` busy time or an Instruments trace. +- Never work on your local `main`, which only mirrors `origin/main`: one effort per branch or worktree, from current `main` and merged back often: a game's bring-up and an optimization apart (docs go with the change they describe); a general fix found during a bring-up gets its own branch and pull request as soon as it works. Leave nothing uncommitted on `main`; name stashes, apply them by SHA, drop them once applied ([06-dev-loop.md](docs/agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). +- Ask the user before anything long or destructive they did not ask for: a build or shader rebuild of more than a few minutes, a run that replaces an app they play, deleting build, work or game folders, changing their `env.txt` or launcher settings. - iOS builds are unsigned IPAs that the user sideloads and tests; diagnostics come back as the app's `Documents/log.txt`. Do not sign or install builds on the user's devices. -- Commit only when asked, with `git -c user.name=seedds -c user.email=seedds@gmail.com commit`. A change a front end must act on takes a `Front-ends:` line ([Following main](docs/frontends.md#following-main)). +- Commit only when asked, with `git -c user.name=seedds -c user.email=seedds@gmail.com commit`. Commit and pull request conventions (titles, `Front-ends:` lines): [CONTRIBUTING.md](CONTRIBUTING.md). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 02909ab5d3..d07912d25f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,8 +4,12 @@ Issues and pull requests are welcome. This page says how a change gets in; what ## Reporting a problem +**First, update to the latest `main`** (`git fetch origin` and rebuild from `origin/main`) and try again: the problem may already be fixed, and a report against an old commit is often traced to something that changed since. Then search the open and closed issues for the game and the symptom. + Open an issue with the bug report form. It asks for what a problem is traced with: the nxnative commit, the shader chain version, the game's title ID and version, the device and OS, how the game was built and run, environment overrides, and the whole log of the run. [Playing](docs/playing.md) says where the iPhone app's log is; a Mac app writes `~/Library/Logs/nxnative/<title ID>.log`. +**Tag it through its title.** Labels are added automatically from an issue's title (and a pull request's changed files): put the game's name and title ID in it, and the area in plain words (`Star Fox (0400E88025B1A000): black screen on Mac after the title`, `NVN: …`, `iOS: …`). Check the labels it gets, and fix the title if they are wrong; that is how others working on the same game or area find it. + `python3 scripts/bug_report.py <title ID | path to the .app | NSP folder>` collects most of this into one zip to attach: `report.md` with the game, commit, chain version, device, settings and the list of files, plus the Mac app's logs, the NSP script's logs under `<title ID>_build/logs` and recent crash reports. Add `--ios-log log.txt` for an iPhone log. It reads only text logs and settings, never game files or keys; it writes your home folder as `~` and drops lines that look like key material. Look at the zip before you attach it. ## Never game files or keys @@ -14,6 +18,9 @@ Never commit or attach game files, keys, title keys or anything extracted from a ## Before you start +- **Read the [charter](docs/charter.md)**, at least its five-line summary: what the project is for, the base Macs a change is judged on, and what counts as a regression. +- **Look for existing work first, every time**: open and merged pull requests and issues by the game's label (`game: <title ID>`) and area label, by the game's name and title ID in titles, and the active branches ([how, with or without `gh`](docs/agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). Many people work on the same games, mostly through agents that don't see each other: build on what is there, or ask its author. +- **Make your work findable**: open a draft pull request early, with the game's name and title ID in its title (`Star Fox (0400E88025B1A000): …`), and link the issue it belongs to. - Read [AGENTS.md](AGENTS.md): it lists where to start for each kind of task, and the rules for profiles, per-build knowledge and the shader translation chain. - A crash, a hang or a wrong picture: search the [symptom index](docs/agents/symptoms.md) for the text in the log first. - Another game: run `scripts/build_ipa_from_nsp.py` on its NSP folder and follow [Port another game](docs/development.md#port-another-game). @@ -21,7 +28,8 @@ Never commit or attach game files, keys, title keys or anything extracted from a ## A pull request -- **One change per PR, off `main`.** Rebase on `main` rather than merging it in. +- **One change per PR, on its own branch off `main`** (in your fork if you have no write access), never on your local `main` ([the cycle](docs/agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). Rebase on `main` rather than merging it in. A general fix found while bringing up a game is its own PR, opened as soon as it works. +- **Its tier.** Say whether it is narrow, shared or wide, and show what that tier asks for ([charter](docs/charter.md#pull-requests), [which tier](docs/agents/06-dev-loop.md#which-tier)). - **Commits.** Each commit message says what changed and why, in plain English sentences, as the history does: the symptom, the cause, the fix, and what was measured or checked. - **Front ends.** A change a front end has to act on takes a `Front-ends:` line in the commit message and the PR text, unless git already shows it ([Following main](docs/frontends.md#following-main)). A change that makes the host read saves or other kept data differently also carries the old form forward. - **Where findings go.** A fact about one game goes in its note (`dm/games/<id>/README.md`). A general mechanism gets an entry in `docs/reference/<subsystem>.md` (Symptom, Cause, Fix, Found on), followed by `python3 dm/tools/docs_symptoms.py`. A new game takes its profile, its note and its row in the games table ([dm/games/README.md](dm/games/README.md)). diff --git a/dm/tools/issue_areas.py b/dm/tools/issue_areas.py index 0bbe566a5b..d0a604192a 100644 --- a/dm/tools/issue_areas.py +++ b/dm/tools/issue_areas.py @@ -29,7 +29,7 @@ } AREA_LABELS = {a[0]: a[1:3] for a in pr_areas.AREAS} | {pr_areas.CHAIN[0]: pr_areas.CHAIN[1:]} KIND_LABELS = pr_areas.KINDS | {pr_areas.NEW_GAME[0]: pr_areas.NEW_GAME[1:]} -FORMS = {'What happened': 'bug', 'What is missing': 'enhancement', 'Survey and what happened': 'new game'} # a heading only that form has (.github/ISSUE_TEMPLATE) → its kind +FORMS = {'What happened': 'bug', 'What is missing': 'enhancement', 'Survey and what happened': 'new game', 'What to test': 'test request'} # a heading only that form has (.github/ISSUE_TEMPLATE) → its kind TITLE_KINDS = { # kind → how a title without a form starts (regular expression, any case) 'enhancement': r'^((scope )?proposal|feature request|suggestion|design|roadmap)\s*:|^feat\(', 'new game': r'^(request:|\[patch\]|\[bring-?up\])', diff --git a/dm/tools/pr_areas.py b/dm/tools/pr_areas.py index 87309a1767..f28c314629 100644 --- a/dm/tools/pr_areas.py +++ b/dm/tools/pr_areas.py @@ -22,7 +22,8 @@ ] CHAIN = ('shader chain', 'b60205', "The shader translation chain (DMSH_CHAIN): a change rebuilds every game's shaders") # its files: chain_paths() GAME_COLOR, NEW_GAME = 'f9d0c4', ('new game', 'd93f0b', 'A game main has no profile for yet: a pull request adding one, or an issue about one') -KINDS = {'bug': ('d73a4a', "Something isn't working"), 'enhancement': ('a2eeef', 'New feature or request')} # issue_areas.py only, with NEW_GAME +KINDS = {'bug': ('d73a4a', "Something isn't working"), 'enhancement': ('a2eeef', 'New feature or request'), + 'test request': ('5319e7', 'A request to play a change on one of the lowest supported devices (docs/charter.md)')} # issue_areas.py only, with NEW_GAME def automatic(name): # a label this file or issue_areas.py adds, so it says nothing about whether someone has read the issue (triage_report.py) diff --git a/dm/tools/tests/test_issue_areas.py b/dm/tools/tests/test_issue_areas.py index 44e12a8abd..fa7987c8ab 100644 --- a/dm/tools/tests/test_issue_areas.py +++ b/dm/tools/tests/test_issue_areas.py @@ -96,6 +96,7 @@ def test_kind_from_the_form(self): self.assertEqual(self.names('Black screen', '### What happened\n\nIt is black.\n'), {'bug'}) self.assertEqual(self.names('More', '### What is missing\n\nA thing.\n'), {'enhancement'}) self.assertEqual(self.names('A game', '### Survey and what happened\n\n_No response_\n'), {'new game'}) + self.assertEqual(self.names('Memory on an 8 GB M1', '### What to test\n\nPR #1234 against main\n'), {'test request'}) self.assertEqual(self.names('Black screen', 'What happened: ### What happened in the text'), set()) self.assertEqual(self.names('Proposal: more', '### What happened\n\nIt is black.\n'), {'bug'}) # the form beats the title @@ -108,7 +109,7 @@ def test_kind_from_the_title(self): self.assertEqual(self.names(title), set(), title) def test_forms_have_their_headings(self): - for form, heading, name in (('bug_report.yml', 'What happened', 'bug'), ('feature_request.yml', 'What is missing', 'enhancement'), ('game_request.yml', 'Survey and what happened', 'new game')): + for form, heading, name in (('bug_report.yml', 'What happened', 'bug'), ('feature_request.yml', 'What is missing', 'enhancement'), ('game_request.yml', 'Survey and what happened', 'new game'), ('test_request.yml', 'What to test', 'test request')): self.assertIn(f'label: {heading}\n', (TEMPLATES / form).read_text(encoding='utf-8')) self.assertEqual(issue_areas.FORMS[heading], name) others = {f.name: f.read_text(encoding='utf-8') for f in TEMPLATES.glob('*_*.yml')} diff --git a/docs/agents/06-dev-loop.md b/docs/agents/06-dev-loop.md index cebfe0a13e..6c7c6ba38e 100644 --- a/docs/agents/06-dev-loop.md +++ b/docs/agents/06-dev-loop.md @@ -2,6 +2,48 @@ One page for people and agents: the tools this repository has for building, running, debugging, measuring and checking a change, when to use which, and what a pull request needs. It links to where each tool is described instead of repeating it. Game files, keys, builds and runs stay outside the repository ([AGENTS.md](../../AGENTS.md)). +## 0. Before you start: existing work, then a branch + +Most work here is done by agents, started by different people who do not see each other's sessions. A look at what already exists is what lets each session build on the others: it finds the fix that is half done, the design being replaced, the person to ask. Look first, every time, also when picking a task back up after a few days: `main` and the open work move daily. Fetch first (`git fetch origin`), so that the searches and your branch see today's `main`; before filing an issue, rebuild from it and try again, since the problem may be fixed already. + +**What to search**, with the names a change would touch (the game's name and title ID, the SDK function or service, the source file, the shader opcode, the log text): + +| Where | How | +|---|---| +| Work on the same game or area, by label | The workflows label every pull request by the files it changes (`dm/tools/pr_areas.py`) and every issue by its text (`issue_areas.py`): a game as `game: <title ID>`, an area as `nvn`, `host`, `shader chain`, `rewriter`, `packing`, `mac`, `ios`… `gh pr list --repo seedds/nxnative --label "game: 040074A01BF12000"` lists the open work on one game, `--label nvn --label "shader chain"` on an area, `gh issue list` the same for issues. Labels miss a pull request whose game shows only in its title, and an issue whose labels were never added | +| The same game or area, by title | `gh pr list --repo seedds/nxnative --state all --search "0400486024DEC000 in:title"` and `--search "Ocarina in:title"`: the title ID and the game's name (titles drop "The Legend of Zelda:", and use the base game's ID), the same for `gh issue list`; for an area, the function, service or file name | +| Open pull requests, drafts included | `gh pr list --repo seedds/nxnative --state open --search "<term>"`; also `--state merged` for work that landed under another name | +| Issues | `gh issue list --repo seedds/nxnative --search "<term>"`, and the labels for the area and game | +| Branches | `git fetch origin`, then `git branch -r --sort=-committerdate \| head -30` for what is active, and `git log --all --oneline -i --grep "<term>"` for commits not on `main` | +| Recent changes to the files | `git log origin/main --since=2.weeks --oneline -- <paths>`: a file changed this week may be in the middle of a redesign | +| The repository's own record | the game's note (its Open list), the [symptom index](symptoms.md), [decisions.md](../decisions.md), and `grep` over `docs/reference` and the code for the function or service | + +Contributors' forks are seen only through their pull requests, and these searches find only what is labelled and titled well. When the search finds related work: build on it, comment on it, or ask its author before starting something parallel; one service built once, together, is worth more than two built apart. + +Without `gh`, the same searches run on the web: the [pull requests](https://github.com/seedds/nxnative/pulls) and [issues](https://github.com/seedds/nxnative/issues) pages take the same query in their search box, for example `is:pr is:open label:"game: 040074A01BF12000"`, `is:pr 0400486024DEC000 in:title` or `is:issue label:nvn`; the [branches page](https://github.com/seedds/nxnative/branches/active) lists the active branches. + +**Make your own work findable**, the other half of the same rule: + +- **Open a draft pull request early**, as soon as there is a branch worth showing. Its labels come from the files it changes, so it is labelled as it grows. +- **Name the game and its title ID in the title** of every pull request and issue about one game (`Star Fox (0400E88025B1A000): …`), and the area in words the labels match (NVN, host, shader chain, rewriter, iOS, Mac). An issue is labelled from its title alone. +- **Link the issue** the work belongs to (`Fixes #…` or `Part of #…`), and say in the description what it does and does not cover yet. + +**Then one branch per effort**, from current `main`: + +- **A game's bring-up** (`<game>-bringup`) holds what only that game needs: its profile, note, patches and shader tables. It merges when the game plays. +- **Each general fix the bring-up turns up** (an SDK call taken over, a shader opcode, an NVN feature) goes into a short branch and pull request of its own as soon as it works, judged at its own reach ([charter](../charter.md#pull-requests)). The game's branch then rebases onto `main` and gets the fix from there. Waiting to merge it with the game is how the same service ends up written twice. +- **An optimization or a change to a shared path** is its own branch from the start, with the evidence its tier asks for. +- **Docs** go with the change they describe: a game's note with its bring-up, a reference entry with its fix. Only a docs-only change, such as a process or guide edit, is a pull request of its own. + +**The cycle.** `main` is the one trunk everyone starts from and merges back into, in small pieces, often. Nobody works on it directly: your local `main` only mirrors `origin/main`. Contributors without write access do the same in their fork, and open the pull request against `seedds/nxnative`'s `main`. + +1. **Start** from the newest `main`: `git fetch origin && git switch -c <short-name> origin/main`, or `git worktree add ../nxnative-<short-name> -b <short-name> origin/main` to keep it apart from other work in progress. +2. **Show it early:** push the branch and open a draft pull request as soon as there is something worth showing (`git push -u origin <short-name>`, then `gh pr create --draft` or the web page), titled with the game and title ID. +3. **Keep up:** `git fetch origin && git rebase origin/main`, at least daily; resolve conflicts while they are small. +4. **Finish:** checks for its tier ([which tier](#which-tier)), mark it ready, and once merged delete the branch and fast-forward your `main` (`git switch main && git merge --ff-only origin/main`). + +Keep branches short-lived: rebase onto `main` at least daily, and merge or close within days. `main` takes dozens of commits a day, and a branch that waits for weeks meets a different codebase: the merge then costs more than the work, and its tests no longer say much about what it will do on `main`. Leave nothing uncommitted on `main`: work that sits in a working tree is invisible to everyone else and gets mixed up with the next task. The stash stack is shared by every worktree of a checkout, and another session can push or pop it at any time; `stash@{0}` may not be yours by the time you use it. So name each stash (`git stash push -u -m <tag>`), apply it by its SHA (`git stash list --format='%H %gs'`), and drop it once applied. + ## 1. Build and run on the Mac | Step | Tool | Details | @@ -64,9 +106,39 @@ Reading the report (`report.md` beside `report.json` in `<root>/reports/`): one ## 7. Before you open a pull request +### Which tier + +The [charter](../charter.md#pull-requests) asks more of a pull request the more it can break. Judge the tier before starting, and again before opening the pull request; when in doubt, take the higher one. + +1. **Read its labels** (they come from the files it changes; `python3 dm/tools/pr_areas.py < <(git diff --name-only main...HEAD)` prints them before you push): only `game: …`, `docs`, or `tools` for a tool few games use is **narrow**; `host`, `nvn`, `vulkan`, `opengl`, `textures`, `rewriter` or `packing` is **shared**; `shader chain` is **wide**. +2. **Then ask what it changes, not only where.** A change in a shared file is **wide** when it touches: + - the order of GPU work, barriers or synchronization (the replay's submission, encoders, fences, `DM_NVN_BARRIER`); + - threads, priorities or waits (`hle_thread.c`, the submit and encode threads, spin waits); + - the guest memory layout, pools or allocators, or anything that grows memory for every game; + - a default every game gets (a setting, a switch's default, a platform key such as Game Mode); + - several of the shared areas at once, or about a thousand lines or more. +3. **And who it reaches:** `python3 scripts/regress.py impact main..HEAD`. A change it maps to many games, or to "every game of the API", is at least shared; one that reaches the benchmarks' paths is wide. +4. **Game-specific code can still be wide:** a profile key that turns off a host feature, or a rewriter cut shared through `sdk_patches.py`, reaches every game that ships that SDK. + +State the tier and the reason in the pull request ("Shared: `nvn`, a new texture format; `impact` names 6 games, checked 3"). + By what the change touches (the largest that applies): - **Docs only:** `python3 -m unittest dm/tools/tests/test_docs.py`; after a change to `docs/reference`, `python3 dm/tools/docs_symptoms.py`; after editing `docs/images/gallery.tsv`, `python3 dm/tools/docs_gallery.py` (also resolves conflicts inside README's generated gallery). - **A Python tool or script** (`scripts/`, the tools under `dm/`): the ratchet `lint-python.yml` runs, ruff and pyright with no new finding: `<venv>/bin/python3 dm/tools/lint_python.py`, from a venv with `.github/requirements/lint.txt` installed, kept on the drive of the NSP folders, not in the home folder ([Continuous integration](../development.md#continuous-integration)). The system Python has neither tool, and the check stops at a `[RED]` line there: that is not a pass. A generated page (`docs_*.py`) is compared in CI on a clean checkout, so it must not read untracked or git-ignored files such as `dm/host/gen`. - **One game's profile or note** (`dm/games/<id>/`): the Python tool tests; a full shader build of that game after a change to its shader inputs; the game on the Mac (or the iPhone) along its route, with `scripts/bench.py` numbers when the change is about speed; the finding in the game's note ([AGENTS.md](../../AGENTS.md)). - **The host, the chain or the tools** (`dm/host`, `dm/gfx`, `dm/tools`, `dm/gfx/tools`, `dm/ios`, `scripts`): everything above, `make -C dm/gfx/tests GAME=<id> run`, `dmsh_chain.py --header` after a chain change, `python3 scripts/regress.py impact main..HEAD` to see which games it reaches, then `python3 scripts/regress.py check --games <ids>` (`--quick` while iterating, the full run before the pull request), and its `report.md` pasted into the pull request with a word on every `CHANGED`, `NEW-FAIL` or `REGRESSION`. Choose the games, not every local one: the five the change is most likely to reach or break (those `impact` names, then games that cover the APIs, engines and paths it touches). Take more than five only when the change truly needs them (a broad chain or host change no five games cover), and fewer when its reach is narrow and clear (a fix on one game's path, a tool only some games use). Name the games the report covers and why you chose them: the others are unchecked. After a change to C or Objective-C in `dm/host` or `dm/gfx`, `dm/tools/lint_c.py compdb` and `tidy` with LLVM's release run what the `lint-c` workflow runs: no new finding (fix it, or `// NOLINT(<check>)` with a reason on a false positive), and `tidy --update` after fixing one ([Continuous integration](../development.md#continuous-integration)). + +## 8. The shader chain version + +The shader translation chain has one version for every game, `DMSH_CHAIN` in `dm/gfx/nvn/dmsh_chain.h`, which the host is compiled with and loads only libraries of. It covers the chain's tools: `dm/gfx/tools/dmsh_*` (`dmsh_build.py`, `dmsh_chain.py`, `dmsh_fetch.py`, `dmsh_vin.py`, `dmsh_pull.py` with its decoder `dmsh_pull.metal`, `dmsh_geometry.py`, `dmsh_facts.py`), `Program.cs`, `ios_metal.py`, `dm/gfx/nvn/dmsh_abi.h` and `dmsh_chain.lock`. A profile's own inputs (`shader_map.tsv`, `shader_facts.tsv`, `shader_pairs.tsv`, `bf_want.tsv`, its `shader_*` / `nvn_*` keys) are not part of it: they are in each shader's cache key, and their digest stamps the libraries (`b-<V>/inputs.tsv`). The procedure: + +1. After changing a chain tool, run `dmsh_chain.py --header` once and commit `dm/gfx/nvn/dmsh_chain.h` with the change (`dm/tools/tests/test_nsp_chain.py` fails on a stale one). +2. After that, or after changing a profile's inputs, rebuild that profile's shaders: a full `dmsh_build.py` run (Mac and, with `IOSOUT`, iOS) stamps its libraries and writes the profile's `c1_full.tsv` and `cb_extent.tsv` from its Mac outputs (git ignores them; the host takes them only beside the stamp they name). Give each game its own output directory. +3. Rebuild the host. + +The translator is `dm/gfx/tools/dmsh_xlate_bin`, which matches `dmsh_chain.lock`; a fresh `dotnet publish` does not. + +## 9. Per-build knowledge + +Per-build knowledge is keyed by the NSO build ID: rewriter cuts, observation gates and frame-step stubs in the profile's `patches.py` (a game's own modules) or `dm/tools/sdk_patches.py` (Nintendo's `sdk` modules, which several games ship), which `dm/tools/patch_nso.py` (the general rewriter) loads, the profile's `build` rows (the builds the game was brought up on, and their display versions; the NSP script packs any other version from a derived profile, without those builds' fixes), and host behaviour that uses fixed module addresses checks `module_t.build_id` (from `fixups.tsv`; `dm_main_build()`). When a new game build appears, carry addresses over with `dm/tools/nso_fnmap.py` and check them by disassembly; never let fixed addresses run on a build they were not found in. For automatic cuts across updates, opt individual patches into `MATCH_CUTS` only after verifying their function fingerprints and assumptions; follow [Function-matched cuts](../reference/rewriter.md#function-matched-cuts-for-unregistered-builds). The shared matcher derives addresses from code; fixed addresses remain build-gated. diff --git a/docs/agents/README.md b/docs/agents/README.md index b43f8ba68a..3e977b9c8d 100644 --- a/docs/agents/README.md +++ b/docs/agents/README.md @@ -17,6 +17,7 @@ Everything here was learned on Diablo II: Resurrected (SDK ~12, NVN 53, the orig ## Ground rules +- **Check for existing work first.** Before surveying, porting or fixing anything, search the open and merged pull requests, issues, active branches and recent commits for the game and the subsystem ([06](06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). Someone may already be bringing up the same game or taking over the same service; build on their work instead of beside it. Each general fix a bring-up needs goes upstream as its own pull request as soon as it works, not at the end with the game. - **Bring your own files.** Keys, NSPs and anything extracted from them stay in the game's work folder (`$W` = `<NSP folder>/<title>-work`, next to the NSPs on the user's external drive; the home folder is nearly full), never in the repository, never in a commit, never printed. Print key *names* and lengths only. - **Measure, then change.** Each fix in this repository started from a concrete observation (a crash address and its decompilation, a census over all shaders, a memory profile). Write the evidence into the code comment next to the fix, the way the existing code does; the next title will need it. - **Find the root cause; don't just work around it.** A crash, hang or wrong picture is finished when its root cause is found and fixed there, not when it stops showing. Follow the bad value back to where it was written and the call back to the semantics the host gets wrong; a stub, skip, clamp, retry or timeout that only makes the symptom go away is a workaround, kept only when the root cause cannot be fixed and recorded as open ([AGENTS.md](../../AGENTS.md)). diff --git a/docs/charter.md b/docs/charter.md new file mode 100644 index 0000000000..d06dd0f4e4 --- /dev/null +++ b/docs/charter.md @@ -0,0 +1,157 @@ +# Charter + +> **If you read nothing else** +> 1. **Start from the latest `main`, and look for existing work first**, every time: `git fetch` before a new branch or an issue (it may be fixed already), then pull requests and issues by game and area label and by title, active branches ([how](agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). +> 2. **Make your own work findable:** a draft pull request early, with the game's name and title ID in its title. +> 3. **The base Macs decide:** a change is judged on an 8 GB M1 for Switch games and a 16 GB M2 for Switch 2 games, not on the Mac it was made on. +> 4. **No regressions:** a gain on one Mac paid for by another is not a gain. +> 5. **The bar rises with reach:** a change to one game shows that game; a change to a shared path shows more ([tiers](#pull-requests)). + +Many people work on nxnative, mostly through agents, usually on one game or subsystem at a time. This page says what the project is for, what a change must not break, and what to check first, so that work on one part does not cost another. [AGENTS.md](../AGENTS.md) links here; [06-dev-loop.md](agents/06-dev-loop.md) has the commands. + +Most of the work is agentic, which makes it cheap to start and easy to multiply. That is a strength when the sessions add up: each one knows what exists and what is under way, picks the piece that moves a goal, builds on what others have done, and leaves a record the next one can find. + +## Aim + +Play your own Switch and Switch 2 games on the iPhone, iPad and Mac by running the game's own code natively ([README](../README.md)), **as they play on the console**: same picture and sound, same feel in the hands, same pacing, same relation to real time. + +The project is the host, the rewriter, the shader chain and the tools that serve every game. A game is how a part of them is found and tested, not a goal of its own: a fix is done when it holds for every game it reaches. + +## Correctness + +A game is correct when it plays as on the console, not only when it looks right: + +- **Picture and sound** as the console gives them. +- **Smoothness:** even frame pacing at the game's own rate beats a higher average; a steady 30 beats a stuttering 30 to 60. The game's frame-rate controller and dynamic resolution behave as on the console. +- **Time:** games that follow the real clock (Animal Crossing's days and seasons, timed events) see the real date and time, through sleep and suspension too. +- **Input:** the console's own controllers (Joy-Con, Pro Controller, the Switch 2's) work with their buttons, motion and rumble, as do other controllers. +- **Gameplay** at the console's speed: no fast-forward, no slow motion. + +## Goals + +Challenging on purpose: they name the Macs the project is built for, so a change that helps a fast Mac and costs a slow one is seen as a cost. + +- **Every Switch game playable on an M1 Mac with 8 GB.** Benchmark: [Tears of the Kingdom](../dm/games/0100F2C0115B6000/README.md), recent and among the console's heaviest. +- **Every Switch 2 game playable on an M2 Mac with 16 GB and a 10-core GPU**, settings lowered where needed (render scale, console mode, upscaler). Benchmark, once it plays: Ocarina of Time (Switch 2, `0400486024DEC000`), the most demanding Switch 2 game brought up so far. + +Where each game stands, and what holds it back on these Macs, is in its note ([games table](../dm/games/README.md#games)). + +**Playable:** correct as above from the start through normal play, no crash or hang, at the game's intended frame rate most of the time and evenly paced, no paging that stalls play, with settings the launcher offers. A game not there yet lists what stands in the way in its note; a change that moves a game away from it is a regression. + +**Why it pays everywhere:** less CPU and GPU time a frame is longer battery life on every MacBook, iPhone and iPad; on Pro and Max Macs it is headroom for higher frame rates (120 fps where a game allows) and better upscaling; and what fits an 8 GB Mac is close to what fits a phone. + +## Devices + +A change is judged on the lowest device of each platform it reaches, not on the device it was developed on. + +| Platform | Lowest supported | +|---|---| +| iPhone | iPhone 15 Pro (A17 Pro, 8 GB), the README's floor | +| iPad | M1 iPad | +| Mac, Switch games | M1, 8 GB (a Switch has 4 GB) | +| Mac, Switch 2 games | M2, 16 GB, 10-core GPU (a Switch 2 has 12 GB). An M1 with 16 GB or more may also get there, with fewer GPU cores | + +Most Macs people play on are base chips with 8 or 16 GB: about two thirds of Apple silicon Macs on Steam, and a third or more likely still 8 GB ([appendix](#appendix-the-macs-people-play-on)). CPU and GPU share that memory, so memory is the limit these Macs meet first. + +A change about speed, memory or power measured only above the floor says so, and is not called a gain for everyone. + +## Priorities + +When goals conflict, the earlier wins: + +1. **Correctness**, in every sense above, in a game that worked. +2. **No regressions:** what worked keeps working, as smoothly and in as little memory, on every supported device. +3. **Performance on the lowest devices:** pacing, frame rate, memory, load time, power. +4. **New games**, through general fixes ([AGENTS.md](../AGENTS.md)). + +Performance is a goal in itself, not only for the lowest devices. Settings let each device find its own balance: a base Mac lowers the render scale, plays in handheld mode or turns off an extra, while a Pro or Max Mac uses the headroom for higher resolution, better upscaling or 120 fps. So a feature for faster Macs is welcome **when it leaves the slower ones as they were**: behind a setting or a switch, or scaled to the device. What is not acceptable is a gain on one class of Mac paid for by another, for example: + +- a cache or buffer sized for a 24 GB Mac that pushes every 16 GB Mac into paging; +- a path tuned on a Pro or Max chip that drops every base chip from 60 to 30 fps; +- a default that helps one chip's GPU clock and costs the others' battery. + +Not goals unless the maintainers decide otherwise: features a console lacks (save states, rewind), 32-bit ARM games, online play. + +## Contributions wanted + +Game support is welcome; everyone wants their favourite game working. The project also asks for work that serves every game: + +- **Optimization:** CPU per frame on the submit path, memory, pacing, load times, power, measured on the lowest devices. +- **Shared correctness:** a host service, translator instruction or replay rule fixed for every game that uses it. +- **Measurement:** smoke routes and baselines for your games, and regression reports on games other than your own. +- **Testing on a low-spec device:** no code needed (below). +- **Tooling and docs** that make the next game, or the next agent, cheaper. + +When you bring up a game, the general part of each fix is what lasts; say which other games it reaches. + +## Testing on the lowest devices + +Few contributors own the lowest device of each platform. A pull request whose result depends on one asks with a **Test request on a low-spec device** issue (the form in `.github/ISSUE_TEMPLATE`): what to run, where, and what to report. Anyone who owns such a device can answer in a few minutes. + +A request does not hold a pull request forever: if no report has come after a week, the pull request goes ahead saying it was measured only above the floor, and the maintainers decide. The same holds for a review the tier asks for. + +## What counts as a regression + +Whatever `scripts/regress.py check` reports as `NEW-FAIL` or `REGRESSION` against the merge base (shaders, crashes, hangs, the route's frame, new `[RED]` lines, screenshots, frame time, memory, prepare time), and beyond what it sees: + +- **Smoothness:** frame-time p95 or late frames worse in a played scene, even when the median holds. +- **Memory:** resident memory higher in a played scene on the lowest Mac or iPhone. +- **CPU per frame:** time added to the submit thread, the limit of several Switch 2 games on base Macs, even when a faster Mac hides it. +- **Time, input, gameplay:** a game's clock, a controller's buttons, motion or rumble, or its speed changed from the console's. +- **A default changed for every game** without the evidence below. + +A regression accepted on purpose is stated in the pull request with its cost and reason; the maintainers decide. + +## Before starting work + +1. **Look for work already going on, every time:** pull requests and issues by game label (`game: <title ID>`) and area label (`nvn`, `host`, `shader chain`…), then by title ID and name in their titles; active branches and recent commits to the same files; the game's note and the [symptom index](agents/symptoms.md). The commands, and their web equivalents, are in [06-dev-loop.md](agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch). When related work exists, build on it or talk to its author first. +2. **Make your work findable**, as much as finding others': open a draft pull request early, with the game's name and title ID in its title and the issue it belongs to linked. Comment on the issue that covers it before writing much code. +3. **One branch per effort:** a game's bring-up apart from the general fixes it turns up, each of which gets its own short pull request as soon as it works; optimizations apart from both. Docs go with the change they describe. Merge often. +4. **Know the reach**, and so the tier ([below](#pull-requests)): `python3 scripts/regress.py impact`, or by hand for a design. +5. **Find the root cause** first ([AGENTS.md](../AGENTS.md)); a workaround is the exception, stated as one. + +## Changes that apply to every game + +A new or removed default, or behaviour switched for every game (Game Mode, a timing source, barriers, a cache size, a thread priority), needs: + +- evidence from more than the device it was developed on: a report from another device class, at best the lowest ([test request](#testing-on-the-lowest-devices)), or a statement that only one device was measured and a default that can be changed back per game; +- a switch that restores the old behaviour, listed in [env_switches.tsv](env_switches.tsv), unless the old behaviour was wrong; +- an entry in [decisions.md](decisions.md): the choice, evidence, cost, and what would reverse it. A decision is reversed by a new entry with evidence, not by a commit that flips it back. + +## Pull requests + +[06-dev-loop.md](agents/06-dev-loop.md#7-before-you-open-a-pull-request) lists the checks by what a change touches. Every pull request also states: one change and its reach; the devices measured on, and whether the lowest was among them; before and after numbers from the same device and scene for a change about speed, memory or power (p95 with the median); what was not checked. + +The bar rises with reach and risk. The pull request's labels say most of it; [06-dev-loop.md](agents/06-dev-loop.md#which-tier) has the full guide to judging it: + +| Tier | Typically labelled | Shows | +|---|---|---| +| **Narrow** | only `game: …`, `docs`, or a tool few games use | the game played; the tests that apply | +| **Shared** | `host`, `nvn`, `vulkan`, `opengl`, `textures`, `rewriter`, `packing` | `regress.py impact`, and `regress.py check` on the games it names that the author has | +| **Wide or risky** | `shader chain`; or a change to replay ordering and barriers, threads and synchronization, memory layout, a default for every game; or several areas at once | the above on more games (each API and engine family it reaches, and the benchmarks), a test request on the lowest devices, a maintainer's review, and a switch to turn the new path off | + +When in doubt, take the higher tier. A wide pull request that can be split is split. One that cannot lands off by default behind a switch, and is turned on in a pull request of its own once played on the benchmarks and the lowest devices. + +## Future work + +**Regression runs on the base Macs, every day.** Most of the machinery exists: 21 games have a scripted smoke route (`dm/games/<id>/smoke.tsv`), Tears of the Kingdom among them, and `scripts/regress.py check` plays them, comparing frame time, memory, `[RED]` lines and screenshots with a baseline. What is missing is running it where it matters and keeping the result: an 8 GB M1 and a 16 GB M2 that run the benchmarks' routes nightly on `main` and on each wide pull request, a route for Ocarina of Time once it plays, and somewhere to publish the numbers so that "it feels slower" becomes a dated line to bisect. + +## Appendix: the Macs people play on + +Apple publishes no figures. The Steam Hardware Survey lists Mac chips and is the only regularly updated sample; it leans towards people who play games and undercounts Pro and Max Macs used for work. The figures below are as reported by the linked articles, not checked against Steam's own page. + +| Chip class | Share of all Macs on Steam, December 2025 | +|---|---| +| Base: M4 19.60 %, M1 18.06 %, M2 13.08 %, M3 7.31 %, M5 1.09 % | about 59 % | +| Pro: M1 Pro 6.89 %, M4 Pro 5.61 %, M3 Pro 3.64 %, M2 Pro 3.04 % | about 19 % | +| Max: M1 Max 2.61 %, M4 Max 1.95 %, M3 Max 1.45 %, M2 Max 1.31 % | about 7 % | +| Ultra | not listed | +| Intel | 14.36 % | + +Of Apple silicon Macs alone, that is about 69 % base, 22 % Pro and 9 % Max. Earlier surveys split similarly: in February 2024, M1 27.36 %, M2 15.56 %, M1 Pro 11.33 %. + +Memory: the last Mac breakdown reported, from late 2024, had about 45.2 % with 8 GB and 34.2 % with 16 GB, the rest 24 GB or more. 16 GB became the base memory across the line with the M4 in late 2024 and M4 Macs are now the largest group, so the 8 GB share has likely fallen since; the many M1 to M3 Macs keep it at perhaps a third or more. On Apple silicon the CPU and GPU share memory, so an 8 GB Mac leaves a game roughly 3 to 5 GB. + +Sales: CIRP reported the MacBook Pro at 53 % of Macs sold in 2024 and the MacBook Air at 33 %; MacBook Pros also ship with base chips. + +Sources: [MacTrast](https://www.mactrast.com/?p=171337), [iDrop News](https://www.idropnews.com/?p=258210), [AppleInsider](https://appleinsider.com/articles/26/01/12/forget-m1-m4-is-the-dominant-apple-silicon-chip-on-steam) (December 2025 chips); [MacRumors forums](https://spy.macrumors.com/threads/in-3-years-50-of-all-computers-capable-of-playing-aaa-games-will-be-macs.2275962/page-66) (February 2024); [Digital Press](https://procyberian.digitalpress.blog/windows-11-overtakes-windows-10-as-the-most-popular-os-among-steam-gamers) (memory, late 2024); [Apple World Today](https://appleworld.today/?p=111254) (CIRP sales). The [Steam Hardware Survey](https://store.steampowered.com/hwsurvey) itself shows the current month. diff --git a/docs/decisions.md b/docs/decisions.md new file mode 100644 index 0000000000..e4fa706ee2 --- /dev/null +++ b/docs/decisions.md @@ -0,0 +1,13 @@ +# Decisions + +Choices that apply to every game: a default, a platform setting, a policy. One entry each, newest first, written with the change that makes it ([charter](charter.md#changes-that-apply-to-every-game)). A later entry reverses an earlier one by linking it, with its own evidence; entries are not edited away. + +Each entry: **Decision**, **Evidence** (devices, games, numbers, links), **Cost** (what it gives up, and what was not measured), **Switch** (how to get the old behaviour), **Would reverse it** (what evidence would). + +## 2026-11-04: Mac apps opt out of Game Mode + +- **Decision:** `dm/mac/pack_app.py` writes `LSSupportsGameMode` false in every Mac app (`cb59a672`, GitHub issue #349). It reverses `f3d8cf33` of the same day, which had declared it, as the iOS app does. +- **Evidence:** two reporters on M4 Pro Macs: Tears of the Kingdom in fullscreen fell from 60 to 30 fps after 45 s to 3 minutes, its GPU time 10.5 → 19.7 ms, with the GPU at its lowest clock (338 MHz) while 72–98 % busy. A 100-line Metal app with no host code did the same in Game Mode and not without it (one run each, M4 Pro on AC power). [macOS Game Mode holds the GPU at its lowest clock](reference/frame-rate.md#macos-game-mode-holds-the-gpu-at-its-lowest-clock). +- **Cost:** what else Game Mode does is lost for every game and Mac: doubled Bluetooth sampling for controllers and AirPods, lower priority for background tasks. Not measured. Not checked on an M1 or M2, nor on games limited by the CPU rather than the GPU. +- **Switch:** none. A player turns Game Mode on per game from the Game Overlay in full screen; macOS keeps that choice, and keeps Game Mode on for a bundle ID it has already labelled a game whatever the key says. +- **Would reverse it:** the clock drop not reproducing on other device classes, or a measured cost to input or audio latency with Game Mode off. From 115b9792710224955778680c9666266617a51959 Mon Sep 17 00:00:00 2001 From: seedds <seedds@gmail.com> Date: Thu, 5 Nov 2026 12:55:30 -0800 Subject: [PATCH 2/3] Charter: it asks shared code not to get worse on the base Macs, not that everyone work for them The first review read the charter as assigning the base-Mac targets to every contributor. The rules were narrower than the wording: - the summary's third point and Devices say a cost on the base Macs is a regression, not that a change is judged only there; - a paragraph says what the page does not ask: no base Mac needed, no low-spec work required, bring-ups and fast-Mac features welcome; - Goals become targets for the shared code, and "playable" is per Mac, with the base Mac a separate fact in a game's note; - a game is no longer "not a goal of its own"; - the priority list keeps its order for conflicts and drops new games, which people do regardless. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- docs/charter.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/charter.md b/docs/charter.md index d06dd0f4e4..98677c9c8c 100644 --- a/docs/charter.md +++ b/docs/charter.md @@ -3,19 +3,21 @@ > **If you read nothing else** > 1. **Start from the latest `main`, and look for existing work first**, every time: `git fetch` before a new branch or an issue (it may be fixed already), then pull requests and issues by game and area label and by title, active branches ([how](agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). > 2. **Make your own work findable:** a draft pull request early, with the game's name and title ID in its title. -> 3. **The base Macs decide:** a change is judged on an 8 GB M1 for Switch games and a 16 GB M2 for Switch 2 games, not on the Mac it was made on. +> 3. **Don't make the base Macs worse:** a change that costs an 8 GB M1 (Switch games) or a 16 GB M2 (Switch 2 games) is a regression, even when it helps the Mac it was made on. > 4. **No regressions:** a gain on one Mac paid for by another is not a gain. > 5. **The bar rises with reach:** a change to one game shows that game; a change to a shared path shows more ([tiers](#pull-requests)). Many people work on nxnative, mostly through agents, usually on one game or subsystem at a time. This page says what the project is for, what a change must not break, and what to check first, so that work on one part does not cost another. [AGENTS.md](../AGENTS.md) links here; [06-dev-loop.md](agents/06-dev-loop.md) has the commands. +**What this page does not ask.** You do not need a base Mac, and you do not need to work on low-spec performance. Bringing up games on whatever Mac you have, and features that use a fast Mac's headroom, are welcome. What is asked is narrower: shared code does not get worse on the base Macs, and a measurement names the Mac it was made on. + Most of the work is agentic, which makes it cheap to start and easy to multiply. That is a strength when the sessions add up: each one knows what exists and what is under way, picks the piece that moves a goal, builds on what others have done, and leaves a record the next one can find. ## Aim Play your own Switch and Switch 2 games on the iPhone, iPad and Mac by running the game's own code natively ([README](../README.md)), **as they play on the console**: same picture and sound, same feel in the hands, same pacing, same relation to real time. -The project is the host, the rewriter, the shader chain and the tools that serve every game. A game is how a part of them is found and tested, not a goal of its own: a fix is done when it holds for every game it reaches. +The project is the host, the rewriter, the shader chain and the tools that serve every game. Each game brought up finds and tests a part of them, and the general part of its fixes is what other games inherit: a fix is done when it holds for every game it reaches. ## Correctness @@ -27,22 +29,22 @@ A game is correct when it plays as on the console, not only when it looks right: - **Input:** the console's own controllers (Joy-Con, Pro Controller, the Switch 2's) work with their buttons, motion and rumble, as do other controllers. - **Gameplay** at the console's speed: no fast-forward, no slow motion. -## Goals +## Targets for the shared code -Challenging on purpose: they name the Macs the project is built for, so a change that helps a fast Mac and costs a slow one is seen as a cost. +The bars the host, the translator, the tools and the defaults every game gets are measured against. They are not what each contributor must work on: they name the Macs most people play on, so that a shared change that helps a fast Mac and costs a slow one is seen as a cost. - **Every Switch game playable on an M1 Mac with 8 GB.** Benchmark: [Tears of the Kingdom](../dm/games/0100F2C0115B6000/README.md), recent and among the console's heaviest. - **Every Switch 2 game playable on an M2 Mac with 16 GB and a 10-core GPU**, settings lowered where needed (render scale, console mode, upscaler). Benchmark, once it plays: Ocarina of Time (Switch 2, `0400486024DEC000`), the most demanding Switch 2 game brought up so far. Where each game stands, and what holds it back on these Macs, is in its note ([games table](../dm/games/README.md#games)). -**Playable:** correct as above from the start through normal play, no crash or hang, at the game's intended frame rate most of the time and evenly paced, no paging that stalls play, with settings the launcher offers. A game not there yet lists what stands in the way in its note; a change that moves a game away from it is a regression. +**Playable** on a given Mac: correct as above from the start through normal play, no crash or hang, at the game's intended frame rate most of the time and evenly paced, no paging that stalls play, with settings the launcher offers. A game in the [games table](../dm/games/README.md#games) is playable on the Mac it was tested on; whether it is playable on the base Mac, and what stands in the way, goes in its note when known. A change that moves a game away from either is a regression. **Why it pays everywhere:** less CPU and GPU time a frame is longer battery life on every MacBook, iPhone and iPad; on Pro and Max Macs it is headroom for higher frame rates (120 fps where a game allows) and better upscaling; and what fits an 8 GB Mac is close to what fits a phone. ## Devices -A change is judged on the lowest device of each platform it reaches, not on the device it was developed on. +A change is judged by what it does on the lowest device of each platform it reaches, as well as on the device it was developed on: a gain there does not make up for a cost on the lowest. | Platform | Lowest supported | |---|---| @@ -57,12 +59,11 @@ A change about speed, memory or power measured only above the floor says so, and ## Priorities -When goals conflict, the earlier wins: +When these conflict, the earlier wins. This is the order a conflict is decided in, not an order of whose work matters: 1. **Correctness**, in every sense above, in a game that worked. 2. **No regressions:** what worked keeps working, as smoothly and in as little memory, on every supported device. 3. **Performance on the lowest devices:** pacing, frame rate, memory, load time, power. -4. **New games**, through general fixes ([AGENTS.md](../AGENTS.md)). Performance is a goal in itself, not only for the lowest devices. Settings let each device find its own balance: a base Mac lowers the render scale, plays in handheld mode or turns off an extra, while a Pro or Max Mac uses the headroom for higher resolution, better upscaling or 120 fps. So a feature for faster Macs is welcome **when it leaves the slower ones as they were**: behind a setting or a switch, or scaled to the device. What is not acceptable is a gain on one class of Mac paid for by another, for example: From d4c5271bf83e0018325c7ebf62bd369296f7094d Mon Sep 17 00:00:00 2001 From: seedds <seedds@gmail.com> Date: Thu, 5 Nov 2026 19:56:39 -0800 Subject: [PATCH 3/3] Charter: for agent-driven work; correctness wins over speed, a regression is breakage or a cost for nothing, the base Macs are reference points, the iPhone and iPad are not fast Macs From crghofficial's review: a change that makes a game more correct is not a regression because it is slower; it states its cost. A slowdown that buys nothing is still one. The 8 GB M1 and 16 GB M2 are where low-spec work aims and testers report, not a bar every game or change must clear, and no author owes a test on one. Better than the console where a device has the headroom joins the aim. The page now opens by saying it is for agent sessions, which know only what they read. The iPhone and iPad get their own paragraph: iOS ends an app past its memory limit, and the host, translator and tools run there as on the Mac, so a shared change's memory or CPU cost reaches them whatever Mac it was made on. Co-authored-by: crghofficial <344215673+crghofficial@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- .github/ISSUE_TEMPLATE/test_request.yml | 8 +-- .github/pull_request_template.md | 4 +- AGENTS.md | 4 +- CONTRIBUTING.md | 2 +- docs/charter.md | 77 ++++++++++++------------- 5 files changed, 45 insertions(+), 50 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/test_request.yml b/.github/ISSUE_TEMPLATE/test_request.yml index 4784bafc55..c23a1ba936 100644 --- a/.github/ISSUE_TEMPLATE/test_request.yml +++ b/.github/ISSUE_TEMPLATE/test_request.yml @@ -1,10 +1,10 @@ name: Test request on a low-spec device -description: Ask someone with one of the lowest supported devices to run a change or a build and report how it plays +description: Ask someone with a base Mac or another low-spec device to run a change or a build and report how it plays body: - type: markdown attributes: value: | - Most contributors measure on the device they have, often a fast Mac. The [charter](https://github.com/seedds/nxnative/blob/main/docs/charter.md#devices) judges a change on the lowest supported device of each platform it reaches. Use this form to ask someone who owns one to try a change: a quick played check, before and after. + Most contributors measure on the device they have, often a fast Mac. No one has to own a base Mac ([charter](https://github.com/seedds/nxnative/blob/main/docs/charter.md#devices)); this form asks someone who owns one, and wants to help, to try a change: a quick played check, before and after. A pull request does not wait for an answer. A tester needs their own copy of the game. Never attach or ask for game files, keys or anything extracted from a game. - type: input id: change @@ -28,8 +28,8 @@ body: description: The device class the result matters on. Pick every one that applies. multiple: true options: - - Mac M1, 8 GB (the Switch game floor) - - Mac M2, 16 GB, 10-core GPU (the Switch 2 game floor) + - Mac M1, 8 GB (Switch game reference) + - Mac M2, 16 GB, 10-core GPU (Switch 2 game reference) - Another 8 GB or 16 GB base-chip Mac (M1 to M4) - iPhone 15 Pro or Pro Max (8 GB) - M1 iPad diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 70d78be2e9..2c64562c96 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -11,8 +11,8 @@ - Tests: <!-- e.g. make -C dm/host/tests GAME=<id> run; make -C dm/gfx/tests GAME=<id> run (Apple silicon, Metal); the dm/tools/tests that apply --> - Games run, with title ID and version: <!-- what was played, for how long, and what was compared (log lines, frame times, screenshots) --> - Existing work: <!-- the issues, pull requests and branches searched for the same area or game, and how this relates to them (docs/charter.md, Before starting work) --> -- Devices and OS: <!-- e.g. M2 Max, macOS 26.1; iPhone 17 Pro Max, iOS 26.1. Say whether the lowest supported device of each platform the change reaches was among them (docs/charter.md, Devices) --> -- Reach and risk: <!-- narrow, shared or wide (docs/charter.md, The bar rises with reach and risk), and what that tier asks for. For a default changed for every game: the devices it was measured on (a test request issue for the lowest), the switch that restores the old behaviour, and the docs/decisions.md entry --> +- Devices and OS: <!-- e.g. M2 Max, macOS 26.1; iPhone 17 Pro Max, iOS 26.1. A cost you know of on other devices, the base Macs especially, goes here too (docs/charter.md, Devices) --> +- Reach and risk: <!-- narrow, shared or wide (docs/charter.md, The bar rises with reach and risk), and what that tier asks for. For a default changed for every game: the devices it was measured on (a test request issue can ask for another), the switch that restores the old behaviour, and the docs/decisions.md entry --> - For a change to the shader chain, the host or a tool that every game uses: the `scripts/regress.py check --games` report on the games it most likely reaches (`regress.py impact` helps), or why none ([06-dev-loop.md](https://github.com/seedds/nxnative/blob/main/docs/agents/06-dev-loop.md)) - Measurements before and after, where the change is about speed, memory or power diff --git a/AGENTS.md b/AGENTS.md index fd50623ad5..d75f2ae67e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,7 @@ # Notes for agents - This repository runs Nintendo Switch games natively on Apple platforms, to play as they do on the console: the game's own code runs, rewritten only where Apple's kernel requires it (`dm/tools/patch_nso.py`), on a host that answers Horizon's SVCs and the SDK's services (`dm/host`) and implements NVN, Vulkan and NVIDIA's desktop OpenGL on Metal (`dm/gfx/nvn`, `dm/gfx/vk`, `dm/gfx/gl`). Every game in the [games table](dm/games/README.md#games) is playable, tested on the Mac or the iPhone (a Mac gameplay test is enough to count); the table links each game's note, `dm/games/<id>/README.md`. [README.md](README.md) is the player-facing page (games, packing, playing); [docs/development.md](docs/development.md) has the internals, the script's options, building by hand, prewarm lists and power. -- Before any work, read [docs/charter.md](docs/charter.md): the project's aim and priorities, the devices a change is judged on, what counts as a regression, the checks before starting (existing issues, pull requests and branches; the change's reach), how much a pull request must show for its reach and risk, and the rule for defaults every game gets ([docs/decisions.md](docs/decisions.md)). +- Before any work, read [docs/charter.md](docs/charter.md): the project's aim and priorities, the reference devices, what counts as a regression, the checks before starting (existing issues, pull requests and branches; the change's reach), how much a pull request must show for its reach and risk, and the rule for defaults every game gets ([docs/decisions.md](docs/decisions.md)). - **Fetch the latest `main` and check for existing work before starting anything or filing an issue, every time:** pull requests and issues by game and area label (`gh pr list --label "game: <title ID>"`) and by title ID or name, active branches, recent commits to the same files ([06-dev-loop.md](docs/agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). Build on it, or ask its author. **Make yours findable too:** a draft pull request early, the game's name and title ID in its title. - Where to start: @@ -16,7 +16,7 @@ | Checking a change before a pull request | [06-dev-loop.md](docs/agents/06-dev-loop.md) | - Where a new finding goes, once: a fact about one game (its passes, shader keys, measurements, why its profile needs a key or a cut, its status) in that game's note, in the section it belongs to and marked current or resolved; a general mechanism (a host or tool change that holds for other games) as an entry in its `docs/reference/<subsystem>.md` section (Symptom, Cause, Fix, Found on with the game's note linked), then `python3 dm/tools/docs_symptoms.py` to update the symptom index, and a line under the game note's "Found on this game". Link to a finding instead of repeating it. Adding a game takes its note and its row in the games table. Once Mac gameplay testing passes, it joins README's gallery ([CONTRIBUTING.md](CONTRIBUTING.md)); testing milestones and remaining validation stay in the game note. This file changes only when a rule does; it states no game count (the games table is the count). `dm/tools/tests/test_docs.py` checks the links and anchors, the notes and their table rows, the symptom index, and the length of this file (1,500 words) and of each guide in `docs/agents` (6,000). - Each game's constants and shader tables form a game profile in `dm/games/<id>/`, where `<id>` is the base game's title ID: `game.tsv` plus the tables (and `patches.py` when the rewriter has patches for its builds). Mario's profile is `010015100B514000`. Tools pick the profile with `DM_GAME`; `make -C dm/host` and `build_ipa.sh` pick it with `GAME`. There is no default game: set it every time (the tools stop and list the profiles otherwise). Put per-game values in the profile, not in code ([dm/games/README.md](dm/games/README.md)). -- Prefer general optimizations and fixes to game-specific rules. Performance (frame pacing, memory, power, load times) is a goal on every device, after correctness and no regressions; a gain on one class of Mac must not cost another ([charter](docs/charter.md#priorities)). First look for a change that holds for every game: Horizon / NVN / Vulkan semantics, or what the binary, its SDK version, its imports or its files show. Use a game-specific rule (a profile key, a rewriter cut, a build-ID gate, a per-game branch in the host) only when it is absolutely necessary, that is, when no general rule can do it. +- Prefer general optimizations and fixes to game-specific rules. Performance (frame pacing, memory, power, load times) is a goal on every device, after correctness and no regressions; a cost on another class of Mac is stated in the PR ([charter](docs/charter.md#priorities)). First look for a change that holds for every game: Horizon / NVN / Vulkan semantics, or what the binary, its SDK version, its imports or its files show. Use a game-specific rule (a profile key, a rewriter cut, a build-ID gate, a per-game branch in the host) only when it is absolutely necessary, that is, when no general rule can do it. - Find a bug's root cause and fix it there; do not just work around it. Before changing code, find why it happens: the faulting instruction and its decompilation, the value that went wrong and who wrote it, the Horizon / NVN / Vulkan / Metal semantics the host or the translator gets wrong. Then fix that place. A change that only hides the symptom (a stub, a skipped call, a clamp, a retry, a sleep or a longer timeout, a cache flush, a profile key that turns a feature off) is a workaround: use one only when the cause is known and lies where it cannot be fixed (the game's own code, which a rewriter cut changes deliberately, or a platform limit), or when the user asks for a stopgap. Then say so in the code comment and in the game note or reference entry: the cause, or what is still unknown, marked open. - Per-build knowledge (rewriter cuts, observation gates, frame-step stubs, host code at fixed module addresses) is keyed by the NSO build ID: never let fixed addresses run on a build they were not found in ([06-dev-loop.md](docs/agents/06-dev-loop.md#9-per-build-knowledge)). - To analyse or port **another** Switch title, first run `scripts/build_ipa_from_nsp.py` on its NSP folder. With no matching profile, it writes a survey to `<NSP folder>/<title ID>_survey/survey.md`, then a provisional profile guessed from the game files (`dm/games/profile_guess.py`; `<build folder>/profile/<title ID>/`; found by the tools through `DM_GAMES_DIR`), with a short heap check on the Mac when the game has virtual address memory, and a best-effort IPA that may not boot. Then follow [docs/agents](docs/agents/README.md) (extraction, binary survey, host bring-up, graphics specifics, debugging recipes; the [symptom index](docs/agents/symptoms.md) for each failure) and add a profile with its note. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d07912d25f..84f848406c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ Never commit or attach game files, keys, title keys or anything extracted from a ## Before you start -- **Read the [charter](docs/charter.md)**, at least its five-line summary: what the project is for, the base Macs a change is judged on, and what counts as a regression. +- **Read the [charter](docs/charter.md)**, at least its five-line summary: what the project is for, the Macs a measurement should name, and what counts as a regression. - **Look for existing work first, every time**: open and merged pull requests and issues by the game's label (`game: <title ID>`) and area label, by the game's name and title ID in titles, and the active branches ([how, with or without `gh`](docs/agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). Many people work on the same games, mostly through agents that don't see each other: build on what is there, or ask its author. - **Make your work findable**: open a draft pull request early, with the game's name and title ID in its title (`Star Fox (0400E88025B1A000): …`), and link the issue it belongs to. - Read [AGENTS.md](AGENTS.md): it lists where to start for each kind of task, and the rules for profiles, per-build knowledge and the shader translation chain. diff --git a/docs/charter.md b/docs/charter.md index 98677c9c8c..50d82ff9a9 100644 --- a/docs/charter.md +++ b/docs/charter.md @@ -1,21 +1,23 @@ # Charter +This page is for agent-driven work on nxnative. Most changes here are written by agents, started by many people who do not see each other's sessions, and an agent knows only what it reads. [AGENTS.md](../AGENTS.md) sends every session here first, so that each one knows what the project is for, what already exists, and what a change must not break before it starts. + > **If you read nothing else** > 1. **Start from the latest `main`, and look for existing work first**, every time: `git fetch` before a new branch or an issue (it may be fixed already), then pull requests and issues by game and area label and by title, active branches ([how](agents/06-dev-loop.md#0-before-you-start-existing-work-then-a-branch)). > 2. **Make your own work findable:** a draft pull request early, with the game's name and title ID in its title. -> 3. **Don't make the base Macs worse:** a change that costs an 8 GB M1 (Switch games) or a 16 GB M2 (Switch 2 games) is a regression, even when it helps the Mac it was made on. -> 4. **No regressions:** a gain on one Mac paid for by another is not a gain. +> 3. **Correctness first, and no regressions:** a regression is what worked and now breaks, or what got slower or bigger for nothing in return. A change that makes a game more correct is not a regression because it costs speed; it states the cost. +> 4. **Name the device:** a measurement says the device it was made on, and a cost known on the base Macs, the iPhone or the iPad is stated, not hidden. > 5. **The bar rises with reach:** a change to one game shows that game; a change to a shared path shows more ([tiers](#pull-requests)). -Many people work on nxnative, mostly through agents, usually on one game or subsystem at a time. This page says what the project is for, what a change must not break, and what to check first, so that work on one part does not cost another. [AGENTS.md](../AGENTS.md) links here; [06-dev-loop.md](agents/06-dev-loop.md) has the commands. +Sessions usually work on one game or subsystem at a time; this page is what keeps work on one part from costing another. [06-dev-loop.md](agents/06-dev-loop.md) has the commands. -**What this page does not ask.** You do not need a base Mac, and you do not need to work on low-spec performance. Bringing up games on whatever Mac you have, and features that use a fast Mac's headroom, are welcome. What is asked is narrower: shared code does not get worse on the base Macs, and a measurement names the Mac it was made on. +**What this page does not ask.** You do not need a base Mac, you do not owe a test on one, and you do not need to work on low-spec performance. Bringing up games on whatever Mac you have, and features that use a fast Mac's headroom, are welcome. What is asked is narrower: a measurement names the Mac it was made on, and a cost you know of on other Macs is written down so someone can weigh it or work on it. -Most of the work is agentic, which makes it cheap to start and easy to multiply. That is a strength when the sessions add up: each one knows what exists and what is under way, picks the piece that moves a goal, builds on what others have done, and leaves a record the next one can find. +Agent sessions are cheap to start and easy to multiply. That is a strength when they add up: each one knows what exists and what is under way, picks the piece that moves a goal, builds on what others have done, and leaves a record the next one can find. ## Aim -Play your own Switch and Switch 2 games on the iPhone, iPad and Mac by running the game's own code natively ([README](../README.md)), **as they play on the console**: same picture and sound, same feel in the hands, same pacing, same relation to real time. +Play your own Switch and Switch 2 games on the iPhone, iPad and Mac by running the game's own code natively ([README](../README.md)), **as they play on the console**: same picture and sound, same feel in the hands, same pacing, same relation to real time; and, where a device has the headroom, better than the console: higher resolution, better upscaling, higher frame rates where a game allows them. The project is the host, the rewriter, the shader chain and the tools that serve every game. Each game brought up finds and tests a part of them, and the general part of its fixes is what other games inherit: a fix is done when it holds for every game it reaches. @@ -29,46 +31,45 @@ A game is correct when it plays as on the console, not only when it looks right: - **Input:** the console's own controllers (Joy-Con, Pro Controller, the Switch 2's) work with their buttons, motion and rumble, as do other controllers. - **Gameplay** at the console's speed: no fast-forward, no slow motion. -## Targets for the shared code +## Reference devices -The bars the host, the translator, the tools and the defaults every game gets are measured against. They are not what each contributor must work on: they name the Macs most people play on, so that a shared change that helps a fast Mac and costs a slow one is seen as a cost. +Two Macs stand for the base machines most people play on ([appendix](#appendix-the-macs-people-play-on)): an **M1 with 8 GB** for Switch games and an **M2 with 16 GB and a 10-core GPU** for Switch 2 games. They are where low-spec optimization aims, where testers report, and what "the base Macs" means on this page. They are not a promise that every game fits them, and not a bar a change must clear: some games are heavy on any hardware (Star Fox leans on DLSS and runs a neural network for its camera), and a game that needs more Mac than these is a property of that game, not a failure of the shared code. -- **Every Switch game playable on an M1 Mac with 8 GB.** Benchmark: [Tears of the Kingdom](../dm/games/0100F2C0115B6000/README.md), recent and among the console's heaviest. -- **Every Switch 2 game playable on an M2 Mac with 16 GB and a 10-core GPU**, settings lowered where needed (render scale, console mode, upscaler). Benchmark, once it plays: Ocarina of Time (Switch 2, `0400486024DEC000`), the most demanding Switch 2 game brought up so far. +**The iPhone and iPad are not fast Macs.** The lowest the README supports, an iPhone 15 Pro, has 8 GB, and iOS ends an app that goes past its memory limit (higher with a sideloading tool's Increased Memory Limit, still well short of the device's memory). It runs on battery and slows down when it heats up over a long session. The host, the translator and the tools run on these devices as they do on the Mac, so a shared change's cost in memory or CPU time reaches them whatever Mac it was made on. That is a reason to measure memory on a phone, or ask for a test there, when a shared change grows it. -Where each game stands, and what holds it back on these Macs, is in its note ([games table](../dm/games/README.md#games)). +Useful benchmarks for optimization work: [Tears of the Kingdom](../dm/games/0100F2C0115B6000/README.md) on the 8 GB M1, recent and among the Switch's heaviest; Ocarina of Time (Switch 2, `0400486024DEC000`) on the 16 GB M2, once it plays. -**Playable** on a given Mac: correct as above from the start through normal play, no crash or hang, at the game's intended frame rate most of the time and evenly paced, no paging that stalls play, with settings the launcher offers. A game in the [games table](../dm/games/README.md#games) is playable on the Mac it was tested on; whether it is playable on the base Mac, and what stands in the way, goes in its note when known. A change that moves a game away from either is a regression. +**Playable** on a given device: correct as above from the start through normal play, no crash or hang, at the game's intended frame rate most of the time and evenly paced, no paging that stalls play, with settings the launcher offers. A game in the [games table](../dm/games/README.md#games) is playable on the device it was tested on. Whether it is playable on a reference Mac, an iPhone or an iPad, and what stands in the way, goes in its note when known. -**Why it pays everywhere:** less CPU and GPU time a frame is longer battery life on every MacBook, iPhone and iPad; on Pro and Max Macs it is headroom for higher frame rates (120 fps where a game allows) and better upscaling; and what fits an 8 GB Mac is close to what fits a phone. +**Why performance pays everywhere:** less CPU and GPU time a frame is longer battery life on every MacBook, iPhone and iPad; on Pro and Max Macs it is headroom for higher frame rates and better upscaling; and what fits an 8 GB Mac is close to what fits a phone. ## Devices -A change is judged by what it does on the lowest device of each platform it reaches, as well as on the device it was developed on: a gain there does not make up for a cost on the lowest. +A change is judged on the device it was developed on, which it names. What it does on the devices below, when someone has measured it, is stated beside that. -| Platform | Lowest supported | +| Platform | Lowest supported or reference | |---|---| | iPhone | iPhone 15 Pro (A17 Pro, 8 GB), the README's floor | | iPad | M1 iPad | -| Mac, Switch games | M1, 8 GB (a Switch has 4 GB) | -| Mac, Switch 2 games | M2, 16 GB, 10-core GPU (a Switch 2 has 12 GB). An M1 with 16 GB or more may also get there, with fewer GPU cores | +| Mac, Switch games | M1, 8 GB, reference (a Switch has 4 GB) | +| Mac, Switch 2 games | M2, 16 GB, 10-core GPU, reference (a Switch 2 has 12 GB). Some Switch 2 games may need more | Most Macs people play on are base chips with 8 or 16 GB: about two thirds of Apple silicon Macs on Steam, and a third or more likely still 8 GB ([appendix](#appendix-the-macs-people-play-on)). CPU and GPU share that memory, so memory is the limit these Macs meet first. -A change about speed, memory or power measured only above the floor says so, and is not called a gain for everyone. +A change about speed, memory or power measured on one Mac says so, and is not called a gain for everyone. ## Priorities When these conflict, the earlier wins. This is the order a conflict is decided in, not an order of whose work matters: -1. **Correctness**, in every sense above, in a game that worked. -2. **No regressions:** what worked keeps working, as smoothly and in as little memory, on every supported device. -3. **Performance on the lowest devices:** pacing, frame rate, memory, load time, power. +1. **Correctness**, in every sense above. A change that makes the host or the translator do what the console does wins even when it is slower or takes more memory. It states the cost it measured; a cheaper way to be equally correct is welcome afterwards, as a change of its own. +2. **No regressions:** what worked keeps working ([below](#what-counts-as-a-regression)). +3. **Performance, on every device:** pacing, frame rate, memory, load time, power on the base Macs, and better than the console where a device has the headroom. -Performance is a goal in itself, not only for the lowest devices. Settings let each device find its own balance: a base Mac lowers the render scale, plays in handheld mode or turns off an extra, while a Pro or Max Mac uses the headroom for higher resolution, better upscaling or 120 fps. So a feature for faster Macs is welcome **when it leaves the slower ones as they were**: behind a setting or a switch, or scaled to the device. What is not acceptable is a gain on one class of Mac paid for by another, for example: +Settings let each device find its own balance: a base Mac lowers the render scale, plays in handheld mode or turns off an extra, while a Pro or Max Mac uses the headroom for higher resolution, better upscaling or 120 fps. A feature for faster Macs fits best behind a setting or scaled to the device. When a performance change helps one class of Mac and costs another, the pull request says both, and the maintainers decide if the cost is large. Costs worth looking for before they land: -- a cache or buffer sized for a 24 GB Mac that pushes every 16 GB Mac into paging; -- a path tuned on a Pro or Max chip that drops every base chip from 60 to 30 fps; +- a cache or buffer sized for a 24 GB Mac that pushes 16 GB Macs into paging; +- a path tuned on a Pro or Max chip that drops base chips from 60 to 30 fps; - a default that helps one chip's GPU clock and costs the others' battery. Not goals unless the maintainers decide otherwise: features a console lacks (save states, rewind), 32-bit ARM games, online play. @@ -77,7 +78,7 @@ Not goals unless the maintainers decide otherwise: features a console lacks (sav Game support is welcome; everyone wants their favourite game working. The project also asks for work that serves every game: -- **Optimization:** CPU per frame on the submit path, memory, pacing, load times, power, measured on the lowest devices. +- **Optimization:** CPU per frame on the submit path, memory, pacing, load times, power, on the base Macs or on fast ones. - **Shared correctness:** a host service, translator instruction or replay rule fixed for every game that uses it. - **Measurement:** smoke routes and baselines for your games, and regression reports on games other than your own. - **Testing on a low-spec device:** no code needed (below). @@ -85,23 +86,17 @@ Game support is welcome; everyone wants their favourite game working. The projec When you bring up a game, the general part of each fix is what lasts; say which other games it reaches. -## Testing on the lowest devices - -Few contributors own the lowest device of each platform. A pull request whose result depends on one asks with a **Test request on a low-spec device** issue (the form in `.github/ISSUE_TEMPLATE`): what to run, where, and what to report. Anyone who owns such a device can answer in a few minutes. +## Testing on low-spec devices -A request does not hold a pull request forever: if no report has come after a week, the pull request goes ahead saying it was measured only above the floor, and the maintainers decide. The same holds for a review the tier asks for. +Few contributors own a base Mac or the lowest iPhone, and no one is asked to buy one. Anyone who wants a change tried on one, its author or anyone else, can open a **Test request on a low-spec device** issue (the form in `.github/ISSUE_TEMPLATE`): what to run, where, and what to report. Anyone who owns such a device can answer in a few minutes. A pull request does not wait for an answer; a report that arrives later is a finding like any other. ## What counts as a regression -Whatever `scripts/regress.py check` reports as `NEW-FAIL` or `REGRESSION` against the merge base (shaders, crashes, hangs, the route's frame, new `[RED]` lines, screenshots, frame time, memory, prepare time), and beyond what it sees: +**Something that worked and now breaks:** a shader, a crash or hang, the route's frame, a new `[RED]` line, the picture, a game's clock, a controller's buttons, motion or rumble, its speed changed from the console's, or a game that was playable on a Mac and no longer is. Whatever `scripts/regress.py check` reports as `NEW-FAIL` against the merge base is one, as are its new `[RED]` lines and a screenshot that is wrong rather than fixed. -- **Smoothness:** frame-time p95 or late frames worse in a played scene, even when the median holds. -- **Memory:** resident memory higher in a played scene on the lowest Mac or iPhone. -- **CPU per frame:** time added to the submit thread, the limit of several Switch 2 games on base Macs, even when a faster Mac hides it. -- **Time, input, gameplay:** a game's clock, a controller's buttons, motion or rumble, or its speed changed from the console's. -- **A default changed for every game** without the evidence below. +**Something that got slower or bigger for nothing in return:** frame time, frame-time p95 or late frames in a played scene, resident memory, CPU time on the submit thread, prepare time, power, on the device measured. `regress.py check` reports these beyond its tolerances as `REGRESSION`. When the change buys correctness or a feature, it is a cost, not a regression: the pull request states it with its reason. -A regression accepted on purpose is stated in the pull request with its cost and reason; the maintainers decide. +**A default changed for every game** without the evidence [below](#changes-that-apply-to-every-game). ## Before starting work @@ -115,13 +110,13 @@ A regression accepted on purpose is stated in the pull request with its cost and A new or removed default, or behaviour switched for every game (Game Mode, a timing source, barriers, a cache size, a thread priority), needs: -- evidence from more than the device it was developed on: a report from another device class, at best the lowest ([test request](#testing-on-the-lowest-devices)), or a statement that only one device was measured and a default that can be changed back per game; +- evidence from more than the device it was developed on: a report from another device class ([test request](#testing-on-low-spec-devices)), or a statement that only one device was measured and a default that can be changed back per game; - a switch that restores the old behaviour, listed in [env_switches.tsv](env_switches.tsv), unless the old behaviour was wrong; - an entry in [decisions.md](decisions.md): the choice, evidence, cost, and what would reverse it. A decision is reversed by a new entry with evidence, not by a commit that flips it back. ## Pull requests -[06-dev-loop.md](agents/06-dev-loop.md#7-before-you-open-a-pull-request) lists the checks by what a change touches. Every pull request also states: one change and its reach; the devices measured on, and whether the lowest was among them; before and after numbers from the same device and scene for a change about speed, memory or power (p95 with the median); what was not checked. +[06-dev-loop.md](agents/06-dev-loop.md#7-before-you-open-a-pull-request) lists the checks by what a change touches. Every pull request also states: one change and its reach; the devices measured on; before and after numbers from the same device and scene for a change about speed, memory or power (p95 with the median); what was not checked. The bar rises with reach and risk. The pull request's labels say most of it; [06-dev-loop.md](agents/06-dev-loop.md#which-tier) has the full guide to judging it: @@ -129,13 +124,13 @@ The bar rises with reach and risk. The pull request's labels say most of it; [06 |---|---|---| | **Narrow** | only `game: …`, `docs`, or a tool few games use | the game played; the tests that apply | | **Shared** | `host`, `nvn`, `vulkan`, `opengl`, `textures`, `rewriter`, `packing` | `regress.py impact`, and `regress.py check` on the games it names that the author has | -| **Wide or risky** | `shader chain`; or a change to replay ordering and barriers, threads and synchronization, memory layout, a default for every game; or several areas at once | the above on more games (each API and engine family it reaches, and the benchmarks), a test request on the lowest devices, a maintainer's review, and a switch to turn the new path off | +| **Wide or risky** | `shader chain`; or a change to replay ordering and barriers, threads and synchronization, memory layout, a default for every game; or several areas at once | the above on more games (each API and engine family it reaches, and the benchmarks), a maintainer's review, and a switch to turn the new path off | -When in doubt, take the higher tier. A wide pull request that can be split is split. One that cannot lands off by default behind a switch, and is turned on in a pull request of its own once played on the benchmarks and the lowest devices. +When in doubt, take the higher tier. A wide pull request that can be split is split. One that cannot lands off by default behind a switch, and is turned on in a pull request of its own once played on more than one class of device. ## Future work -**Regression runs on the base Macs, every day.** Most of the machinery exists: 21 games have a scripted smoke route (`dm/games/<id>/smoke.tsv`), Tears of the Kingdom among them, and `scripts/regress.py check` plays them, comparing frame time, memory, `[RED]` lines and screenshots with a baseline. What is missing is running it where it matters and keeping the result: an 8 GB M1 and a 16 GB M2 that run the benchmarks' routes nightly on `main` and on each wide pull request, a route for Ocarina of Time once it plays, and somewhere to publish the numbers so that "it feels slower" becomes a dated line to bisect. +**Regression runs on the base Macs, every day.** Most of the machinery exists: 21 games have a scripted smoke route (`dm/games/<id>/smoke.tsv`), Tears of the Kingdom among them, and `scripts/regress.py check` plays them, comparing frame time, memory, `[RED]` lines and screenshots with a baseline. What is missing is running it on the base Macs and keeping the result, so that no contributor has to own one: an 8 GB M1 and a 16 GB M2 that run the benchmarks' routes nightly on `main` and on each wide pull request, a route for Ocarina of Time once it plays, and somewhere to publish the numbers so that "it feels slower" becomes a dated line to bisect. ## Appendix: the Macs people play on