mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
- AGENTS.md: agents never merge their own pull request, as CONTRIBUTING.md says; the cargo test command no longer skips depth_bounds_pipeline_loads_and_filters_draws, which d3d12.yml runs and passes. - The switches page said no CI job keeps it current; tests/test_d3d12_switches.py runs --check on it in the required check job. Fixed in the generator and the page. - docs/design.md carried "PAL stage descriptors" twice, byte for byte; the second copy is gone. - port_status.md and port_plan.md describe the Vulkan base and victory/, which no longer exists: a banner says so and points to d3d12/, and the index lists them under a historical heading instead of "Start here". Claim: DOCS-STALE-AGENT-RULES (#3312) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
171 lines
11 KiB
Markdown
171 lines
11 KiB
Markdown
# Guide for coding agents
|
|
|
|
Read this alongside [CONTRIBUTING.md](CONTRIBUTING.md) (shared contributor, clean-room, claiming and AI-disclosure
|
|
rules) and [docs/design.md](docs/design.md) (measured formats and translator contract). This file covers repository
|
|
layout, the engineering bar, agent-specific traps, and the canonical no-game-files test commands.
|
|
|
|
## Repository layout
|
|
|
|
A port of the Xbox Series build of GTA VI running on the player's PC from their own copy, with **two runtimes** and
|
|
nothing of the game in the repository:
|
|
|
|
- **`d3d12/` (`leonida.exe`, Rust)** — the playable Direct3D 12 runtime on Windows (and Linux via Wine/Proton +
|
|
VKD3D-Proton), launched via `Launcher.bat`, `scripts/play-d3d12.ps1` or `scripts/play-linux.sh`. Measured notes:
|
|
[d3d12/docs/findings.md](d3d12/docs/findings.md); variables: [d3d12/docs/switches.md](d3d12/docs/switches.md).
|
|
- **`make_game.py` + `runtime/` (`gta6rt.exe`, C++20)** — the offline RDNA2 → SPIR-V shader translator, asset exporter
|
|
and recompiled PE loader with import shims and a D3D12 → Vulkan layer (`runtime/test/` has CTest and GPU harnesses).
|
|
- **`launcher/` & `mods/`** — web launcher (`index.html`, `serve.py`), optional Rust native launcher
|
|
(`launcher/native/`), `Launcher.bat` (`tools/leonida_launcher.py`), and Lua, camera and archetype-swap mods.
|
|
- **`docs/`** — measured format and runtime notes, indexed by [docs/README.md](docs/README.md); `docs/design.md` is
|
|
quoted most.
|
|
- **`scripts/`** — launchers (`play-d3d12.ps1`, `play-linux.sh`), GPU/Wine test runners (`run_gpu_tests.py`,
|
|
`run_wine_tests.py`), translator/standalone runners (`run_semantic_tests.py`, `run_standalone_tests.py`), red/green
|
|
verifier (`red_green.py`), `check_no_game_data.py` and PowerShell build helpers.
|
|
- **`viewer/`** — local-only map and asset viewer (`index.html`, `studio.html`, `serve.py`).
|
|
- **`third_party/`** — `rpf9-explorer` submodule (`tools/rpf9dump` needs `git submodule update --init`), vendored
|
|
`xtaskqueue` (`xgameruntime` shim), vendored `bcpack-rs` (BCPack calibration), and the Cargo `xma` license notice
|
|
(`third_party/xma/`, linked by `runtime/xma_decoder`).
|
|
- **`game/xbox-1.0.2.1.json`** — package size and SHA-256 manifest (hashes only, no game content).
|
|
- **`tests/semantic/`** — translator regression suite; a new translator rule comes with a small hand-written `.asm`
|
|
fixture there.
|
|
|
|
## Hard rules
|
|
|
|
Follow the clean-room rules in [CONTRIBUTING.md](CONTRIBUTING.md) (no game data, no keys/decryption/protection
|
|
workarounds, nothing online), plus these agent-specific rules:
|
|
|
|
- **Never push directly to `main`.** Always create a separate branch and open a pull request so every change goes
|
|
through CI and review (agents may open, change, merge, and close pull requests on separate branches, but never merge their own
|
|
pull request (see CONTRIBUTING.md) and never push directly to `main`).
|
|
- **Verify clean-room before every commit:** run `python -I scripts/check_no_game_data.py` (or pass explicit paths) —
|
|
it inspects file header bytes and catches renamed files that CI's extension check misses. A test needing a shader
|
|
builds its input by hand or reads from the user's work folder.
|
|
- **Encrypted formats stop at documentation:** if a format turns out to be encrypted, record that in `docs/design.md`
|
|
and stop there.
|
|
- **Fix, don't disable:** a shader the translator rejects gets a rule, not a skip list. Add every new rule to the
|
|
contract table in `docs/design.md` with how it was confirmed (a GPU test, a Mesa/LLVM reference, or a corpus count).
|
|
|
|
## Engineering bar
|
|
|
|
- **Fix the root cause, never stack workarounds.** Trace bugs, mismatches and regressions to their real cause rather
|
|
than layering patches, special cases or silent fallbacks on top of earlier patches.
|
|
- **Keep code simple, clean, modular, maintainable and performant.** Structure changes into small, cohesive modules and
|
|
functions with clear ownership — no spaghetti control flow, dead code or duplicated logic. On hot paths (frame
|
|
submission, command replay, descriptor management, shader translation), avoid unnecessary allocations, copies and
|
|
repeated linear scans.
|
|
- **Run a separate, read-only reviewer agent before every pull request.** Always invoke an independent read-only
|
|
reviewer agent (using one of the code-review models in [CONTRIBUTING.md](CONTRIBUTING.md#ai-assisted-contributions))
|
|
to audit the full diff, edge cases, red/green tests and clean-room rules before opening or updating a pull request.
|
|
Address its findings and re-run it after non-trivial edits.
|
|
|
|
## Claim before you start
|
|
|
|
Follow the claiming workflow and `ItsNotRexed/Leonida` archive pointers in
|
|
[CONTRIBUTING.md](CONTRIBUTING.md#before-you-start). Agent-specific rules:
|
|
|
|
- Look up the active coordination issue before starting (never hardcode an old number):
|
|
|
|
```sh
|
|
gh issue list -R ProjectLeonida/mandy --state open --search "Coordinating who works on what in:title"
|
|
```
|
|
|
|
If you lack `gh` auth, tell the user instead of guessing an item is unclaimed. Check its tables and open pull
|
|
requests first; if claimed or already open, stop and tell the user rather than duplicating it.
|
|
- Include the item ID and `Depends on: #N` for every pull request yours builds on. Report unworked follow-ups as
|
|
`finding: <one line>` with file, line, impact, and whether game files or specific hardware are needed.
|
|
- For the D3D12 → Vulkan layer (`runtime/shims/d3d12_*`, `runtime/src/vulkan_*`), read
|
|
[docs/d3d12_vulkan.md](docs/d3d12_vulkan.md) and the open pull requests first.
|
|
- Never run `gh` against the private `ItsNotRexed/Leonida` repo or cite a pre-23-November-2026 `#N` as readable.
|
|
|
|
## Before you guess, look
|
|
|
|
- The format or behaviour may already be measured in `docs/design.md`. Quote the file and offset a claim comes from,
|
|
or call it a hypothesis.
|
|
- Count over the whole corpus, not a sample: a rule that holds for 400 shaders can fail on the other 26 000.
|
|
- Frame rates of the D3D12 runtime (`d3d12/`): search [d3d12/docs/findings.md](d3d12/docs/findings.md) for the switch
|
|
or function before measuring it, and measure as [docs/measuring_fps.md](docs/measuring_fps.md) says (a switch by
|
|
turns inside one run). The variables are listed in [d3d12/docs/switches.md](d3d12/docs/switches.md).
|
|
- Show the test **fails without the fix**, not just that it passes with it. Run the new case on `main`, or revert
|
|
only the source the change touches and run again (for D3D12 Rust crates and Python `tests/`,
|
|
`python -I scripts/red_green.py <PR | ref>` automates this). Say which you did.
|
|
- Check the instrument before trusting the number: rebuild before `ctest` after switching branches, compare the
|
|
**change** between two branches rather than the file, and read the test's own header before describing what it proves.
|
|
|
|
## Test without the game first
|
|
|
|
None of these need game files. Most run in seconds — the translator suite (over 550 files) takes a few minutes on a
|
|
multi-core machine, and native builds take longer — so run the targeted test file or crate while iterating and the
|
|
relevant full suite once before the pull request:
|
|
|
|
```powershell
|
|
python -I scripts/check_no_game_data.py # every tracked file (or pass explicit paths)
|
|
python -m compileall -q make_game.py tools tests
|
|
python -I make_game.py --help
|
|
python -I scripts/run_semantic_tests.py tests/semantic # translator suite, one file per core; no LLVM, SPIR-V tools or GPU needed
|
|
python -m unittest discover -s tests/semantic -p test_<name>.py # one translator test file
|
|
python -I tests/test_<name>.py # standalone standard-library unit test
|
|
python -m unittest discover -s tests -p "test_docs_*.py" -v # documentation and repo-hygiene checks
|
|
node --test tests/test_*.cjs # viewer streaming & studio tests; needs Node 22+ (CI runs 24 LTS)
|
|
dotnet build tools/rpf9dump/rpf9dump.csproj -c Release
|
|
cmake -S runtime -B runtime/build; cmake --build runtime/build --config RelWithDebInfo
|
|
ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure
|
|
```
|
|
|
|
For the Rust D3D12 runtime (`d3d12/`, currently Windows-only; toolchain pinned in `d3d12/rust-toolchain.toml`), run
|
|
from `d3d12/`:
|
|
|
|
```powershell
|
|
cargo build --workspace --all-targets --locked
|
|
cargo test --workspace --exclude xtask --locked
|
|
cargo test -p leonida-gpu --features diagnostics --test replay --locked
|
|
```
|
|
|
|
(The `--skip` avoids a software-adapter mismatch on Windows CI runners; run `cargo test -p <crate> --locked` while
|
|
iterating on one crate.) For the optional Rust native launcher (`launcher/native/`, Windows and Linux), run
|
|
`cargo clippy --locked --all-targets -- -D warnings` and `cargo test --locked` from `launcher/native/`.
|
|
|
|
`gta6rt` and the shims are Windows-only, so Linux and macOS configure the portable subset of `runtime/` tests (macOS
|
|
CI in `.github/workflows/runtime.yml` is currently disabled). Runtime tests needing the retail package read
|
|
`LEONIDA_GAME_DIR` (and `LEONIDA_MOVIE`) in place and print `SKIP` when unset. `loader_test` writes small PE images to
|
|
`%TEMP%\leonida_loader_test`, which antivirus can block (exclude it or set `LEONIDA_TEST_DIR` to a folder it skips).
|
|
|
|
For pytest-based tests (files with `import pytest` or no `__main__` block, which fail or run nothing under `python -I`),
|
|
install [`tests/requirements.txt`](tests/requirements.txt) in a virtual environment and run from the repository root:
|
|
|
|
```powershell
|
|
python -m pip install -r tests/requirements.txt
|
|
python -m pytest tests/test_user_sgpr_census.py
|
|
```
|
|
|
|
With a work folder already built, check a translator change on a slice before the full run and compare with the run
|
|
before it (merge `index.part*.json` into `index.json` with `--merge`; lowering translated or `spirv-val`-valid counts
|
|
is a regression):
|
|
|
|
```powershell
|
|
python -I tools/rdna2spirv.py <work>/shaders/dxbc/disasm --out <scratch> --limit 200
|
|
python -I tools/rdna2spirv.py <work>/shaders/dxbc/disasm --out <scratch> --shard 0/8 # one of 8 parallel slices
|
|
```
|
|
|
|
## Runtime traps
|
|
|
|
- **No `thread_local` with a destructor in `gta6rt.exe`.** It makes the loader register a thread-exit callback with
|
|
the shared C runtime, which accepts one per process; the title's own registration then fails and the title aborts
|
|
with `0xC0000409` before its first frame. Keep per-thread scratch in the thread's own frame (a worker's loop) or
|
|
in a plain-data `thread_local`.
|
|
- **A console method that returns a struct by value** takes a hidden return pointer as its first argument (RCX)
|
|
and `this` in RDX, as MSVC does for COM methods returning structs (`GetCustomHeapProperties`, `GetDesc`-style
|
|
slots); a proxy that reads RCX as `this` faults on a null vtable.
|
|
|
|
## Conventions
|
|
|
|
- Python tools run with `python -I` and use only the standard library unless a file says otherwise; the exceptions
|
|
are the texture and model tools that import numpy or Pillow: `bc_feature.py`, `amd_swizzle.py`,
|
|
`tile_probe.py`, `swizzle_search.py`, `tex_export.py`, `tex_mode_probe.py`, `calibrated_texture.py`,
|
|
`world_grid_atlas.py`, `tex_headers.py` and `skinned_glb.py` (the last two fall back to the
|
|
standard library when numpy is absent).
|
|
- Keep `make_game.py` working on Windows first: paths through `os.path`, no bash in the build.
|
|
- Follow the shared coding, line-ending and report-path rules in [CONTRIBUTING.md](CONTRIBUTING.md#working-on-the-code),
|
|
and the AI-assistance/model disclosure rules in [CONTRIBUTING.md](CONTRIBUTING.md#ai-assisted-contributions).
|
|
- For multi-agent coordination (machine profiles, evidence tags and handoff blocks), see
|
|
[docs/agent_collaboration.md](docs/agent_collaboration.md).
|