Proposal: rewrite the compatibility layer nearly from scratch #14

Open
opened 2026-12-01 20:42:16 +00:00 by github-bot · 0 comments
Owner

@⁠Zetsukae on GitHub · 2026-12-01 14:16 UTC · original

Summary

Proposal: rewrite Northstar's compatibility layer nearly from scratch, instead of carrying on patching the code inherited from VIctory.

The inherited base is great work, and it's the reason the title runs at all. But the glitches it leaves in game keep coming back. Our assessment after weeks of captures and bisection is that about 98% of them can't be fixed on this base without fighting its design. A rewrite planned around what we now know would cost less than carrying on patching it.

The glitches that keep coming back

Each one has a note in notes/ with what was tried and what was ruled out:

Glitch What the player sees Where it stands
Water scramble Characters and animated bodies tear, flicker or scramble whenever water is in view (at 1K/2K output, not at 4K) Triggered by the water's screen-space ray pre-pass; the fault lies in what its rays set going, still not found. notes/Water scramble.md
Black sand The ground near the camera by the water draws black The terrain's indirect draws run 0 mesh groups: a data delivery problem upstream of culling, not culling or shader translation. Parked. notes/Black sand.md
Car state In a crash the player's car shows damage that isn't there (a wheel flying off; the car is whole when looked at again) Not looked into yet. notes/Home.md
Disappearing objects Trees, shadows and props only appear near the player, fade in late or flicker GPU-driven draws end up with no work or draw invisible. Same family as Black sand. Parked. notes/Distant trees and shadows.md

See also #5 (texture corruption on beach scenes, flicker on distant objects), which traced the same kind of problem back to the upstream base.

Why patching isn't enough

These don't look like four separate bugs. They point at how the layer models the console's GPU, not at any single shader or draw:

  • The title's command lists are replayed onto host lists, its descriptor heap is mirrored into host heaps, and its textures get host copies uploaded behind its back. Every glitch above sits where those copies can disagree with what the title wrote: in timing, in contents, or in which slot it refers to.
  • GPU-driven work (indirect draws, cull passes, meshlet counts) reads data the title prepared in its own memory. When that data reaches the host late, stale or not at all, the draw quietly runs with nothing. That's what Black sand and Disappearing objects come down to.
  • Fixes so far have been switches layered on top (VICTORY_PORT_*, timing modes, audits of the heap). Each helps a case and adds a path, and the paths now interact in ways that are hard to reason about or test.

What a rewrite would aim for

To be agreed in this issue; a starting point:

  1. One model of the title's GPU memory. Heaps, descriptors and resources are kept as one consistent picture, not as copies to keep in sync.
  2. GPU-driven work as a first-class case. Indirect arguments, cull inputs and per-tile records reach the card exactly when the title's submission says they're ready.
  3. No assumptions on sizes. Odd render-target sizes, row pitches and dispatch counts are handled everywhere (the water scramble appears only at the odd sizes below 4K).
  4. Testable from the start. Each subsystem is checked against synthetic data our own code generates, following docs/asset-policy.md, and a frame capture can be replayed and compared pass by pass.
  5. Performance designed in. The current single submission thread (about 40 ms of a 45 ms frame) is planned around from the start, not tuned afterwards.

Proposed architecture

GAME              runs natively (its x86-64 code, unchanged)
  ↓  the console's graphics calls
GRAPHICS LAYER    our code, in Rust: a thin, direct translation
  ↓
DIRECT3D 12       no emulation
  ↓
GPU               draws

The game's code already runs natively today, and nothing in the path is emulated. The change is the middle layer. Instead of replaying the game's command lists and keeping copies of its memory, heaps and textures in sync, it would translate each call straight to Direct3D 12. Fewer copies and fewer buffers mean less work on the submission thread and on the card.

Memory: one pool for the game, two on PC

The console has one memory that the CPU and GPU share. A PC has RAM for the CPU and VRAM for the card. The game must keep believing it has one pool, while on PC it doesn't:

Console:  CPU ─┐
               ├─ one shared memory
          GPU ─┘

PC:       CPU ─── RAM          the game's own data
          GPU ─── VRAM         what the card reads (constants, descriptors,
                               indirect arguments, buffers), which the CPU
                               writes directly

The condition that decides whether it works: a plain split, with RAM on one side and copies in VRAM on the other, is what today's layer does, and it's where the glitches come from. The game writes GPU data straight into memory without telling us, and when the layer copies it late or misses it, draws read stale or empty data (Black sand, Disappearing objects). So the split has to keep one copy of what the card reads:

  • What the card reads lives in VRAM the CPU maps (Resizable BAR, through Direct3D 12's GPU upload heaps). The game's writes land where the card reads them, so there's nothing to copy and nothing to miss. The current code already does this for some buffers (VICTORY_WINDOWS_BAR_MB): a captured frame took 32 ms instead of 36.
  • Only what must differ on PC is translated, at the moment the game submits its work: descriptors (the console's hardware format), shaders, and tiled textures.
  • The limits to plan for: it needs Resizable BAR (recent AMD and NVIDIA cards with it enabled in the BIOS); the CPU reading back from VRAM crosses the bus slowly, so data the game reads back needs its own path; and VRAM is smaller than the console's pool, so there's a budget to manage.

Whether this removes the four glitches can only be proved by a prototype; that's the first milestone below.

How it could be done

  • Beside the current code, not in place. New crates are written next to the existing ones, and the current layer stays playable and stays the reference until the new one is better.
  • Keep what isn't broken. The PE loader, the texture formats (BCPack, detiling) and the shader translator may be kept or only cleaned up. Deciding that is the first step.
  • First, a prototype of the memory model above on one of the four glitches (Black sand is the clearest case of data that never reaches the card), to prove the approach before the rest.
  • Milestones a player can see: the title boots, then menus, then the world without the four glitches above, then performance on a par with today.
  • The launcher doesn't change: it starts whichever layer is built.

Rules

The project's rules apply as everywhere (see CONTRIBUTING.md):

  • Nothing from the game is ever committed.
  • The game is not named.
  • No code copied from other projects without a license that allows it, and credit.
  • The project's history and credits stay. Northstar remains GPL-3.0-or-later.

Open questions

  • How much really starts from zero: which crates stay, and which are rewritten?
  • Is there a smaller first step that fixes one of the four glitches by design and proves the approach?
  • Who wants to take part, and on which part?

Comments, objections and other ideas are welcome. If you think one of these glitches can be fixed on the current base, say so and point at the evidence.

**@⁠Zetsukae** on GitHub · 2026-12-01 14:16 UTC · [original](https://github.com/Zetsukae/Northstar-AMD/issues/14) ## Summary Proposal: **rewrite Northstar's compatibility layer nearly from scratch**, instead of carrying on patching the code inherited from VIctory. The inherited base is great work, and it's the reason the title runs at all. But the glitches it leaves in game keep coming back. Our assessment after weeks of captures and bisection is that about **98% of them can't be fixed** on this base without fighting its design. A rewrite planned around what we now know would cost less than carrying on patching it. ## The glitches that keep coming back Each one has a note in `notes/` with what was tried and what was ruled out: | Glitch | What the player sees | Where it stands | |---|---|---| | **Water scramble** | Characters and animated bodies tear, flicker or scramble whenever water is in view (at 1K/2K output, not at 4K) | Triggered by the water's screen-space ray pre-pass; the fault lies in what its rays set going, still not found. [`notes/Water scramble.md`](../blob/main/notes/Water%20scramble.md) | | **Black sand** | The ground near the camera by the water draws black | The terrain's indirect draws run 0 mesh groups: a **data delivery** problem upstream of culling, not culling or shader translation. Parked. [`notes/Black sand.md`](../blob/main/notes/Black%20sand.md) | | **Car state** | In a crash the player's car shows damage that isn't there (a wheel flying off; the car is whole when looked at again) | Not looked into yet. [`notes/Home.md`](../blob/main/notes/Home.md) | | **Disappearing objects** | Trees, shadows and props only appear near the player, fade in late or flicker | GPU-driven draws end up with no work or draw invisible. Same family as Black sand. Parked. [`notes/Distant trees and shadows.md`](../blob/main/notes/Distant%20trees%20and%20shadows.md) | See also #5 (texture corruption on beach scenes, flicker on distant objects), which traced the same kind of problem back to the upstream base. ## Why patching isn't enough These don't look like four separate bugs. They point at **how the layer models the console's GPU**, not at any single shader or draw: - The title's command lists are **replayed** onto host lists, its descriptor heap is **mirrored** into host heaps, and its textures get **host copies** uploaded behind its back. Every glitch above sits where those copies can disagree with what the title wrote: in timing, in contents, or in which slot it refers to. - GPU-driven work (indirect draws, cull passes, meshlet counts) reads data the title prepared in its own memory. When that data reaches the host late, stale or not at all, the draw quietly runs with nothing. That's what Black sand and Disappearing objects come down to. - Fixes so far have been switches layered on top (`VICTORY_PORT_*`, timing modes, audits of the heap). Each helps a case and adds a path, and the paths now interact in ways that are hard to reason about or test. ## What a rewrite would aim for To be agreed in this issue; a starting point: 1. **One model of the title's GPU memory.** Heaps, descriptors and resources are kept as one consistent picture, not as copies to keep in sync. 2. **GPU-driven work as a first-class case.** Indirect arguments, cull inputs and per-tile records reach the card exactly when the title's submission says they're ready. 3. **No assumptions on sizes.** Odd render-target sizes, row pitches and dispatch counts are handled everywhere (the water scramble appears only at the odd sizes below 4K). 4. **Testable from the start.** Each subsystem is checked against synthetic data our own code generates, following `docs/asset-policy.md`, and a frame capture can be replayed and compared pass by pass. 5. **Performance designed in.** The current single submission thread (about 40 ms of a 45 ms frame) is planned around from the start, not tuned afterwards. ## Proposed architecture ``` GAME runs natively (its x86-64 code, unchanged) ↓ the console's graphics calls GRAPHICS LAYER our code, in Rust: a thin, direct translation ↓ DIRECT3D 12 no emulation ↓ GPU draws ``` The game's code already runs natively today, and nothing in the path is emulated. The change is the middle layer. Instead of replaying the game's command lists and keeping copies of its memory, heaps and textures in sync, it would translate each call straight to Direct3D 12. Fewer copies and fewer buffers mean less work on the submission thread and on the card. ### Memory: one pool for the game, two on PC The console has one memory that the CPU and GPU share. A PC has RAM for the CPU and VRAM for the card. The game must keep believing it has one pool, while on PC it doesn't: ``` Console: CPU ─┐ ├─ one shared memory GPU ─┘ PC: CPU ─── RAM the game's own data GPU ─── VRAM what the card reads (constants, descriptors, indirect arguments, buffers), which the CPU writes directly ``` **The condition that decides whether it works:** a plain split, with RAM on one side and copies in VRAM on the other, is what today's layer does, and it's where the glitches come from. The game writes GPU data straight into memory without telling us, and when the layer copies it late or misses it, draws read stale or empty data (Black sand, Disappearing objects). So the split has to keep **one copy** of what the card reads: - **What the card reads lives in VRAM the CPU maps** (Resizable BAR, through Direct3D 12's GPU upload heaps). The game's writes land where the card reads them, so there's nothing to copy and nothing to miss. The current code already does this for some buffers (`VICTORY_WINDOWS_BAR_MB`): a captured frame took 32 ms instead of 36. - **Only what must differ on PC is translated**, at the moment the game submits its work: descriptors (the console's hardware format), shaders, and tiled textures. - **The limits to plan for:** it needs Resizable BAR (recent AMD and NVIDIA cards with it enabled in the BIOS); the CPU reading back from VRAM crosses the bus slowly, so data the game reads back needs its own path; and VRAM is smaller than the console's pool, so there's a budget to manage. Whether this removes the four glitches can only be proved by a prototype; that's the first milestone below. ## How it could be done - **Beside the current code, not in place.** New crates are written next to the existing ones, and the current layer stays playable and stays the reference until the new one is better. - **Keep what isn't broken.** The PE loader, the texture formats (BCPack, detiling) and the shader translator may be kept or only cleaned up. Deciding that is the first step. - **First, a prototype of the memory model above** on one of the four glitches (Black sand is the clearest case of data that never reaches the card), to prove the approach before the rest. - **Milestones a player can see:** the title boots, then menus, then the world without the four glitches above, then performance on a par with today. - The launcher doesn't change: it starts whichever layer is built. ## Rules The project's rules apply as everywhere (see [CONTRIBUTING.md](../blob/main/CONTRIBUTING.md)): - Nothing from the game is ever committed. - The game is not named. - No code copied from other projects without a license that allows it, and credit. - The project's history and credits stay. Northstar remains GPL-3.0-or-later. ## Open questions - How much really starts from zero: which crates stay, and which are rewritten? - Is there a smaller first step that fixes one of the four glitches by design and proves the approach? - Who wants to take part, and on which part? Comments, objections and other ideas are welcome. If you think one of these glitches can be fixed on the current base, say so and point at the evidence.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:42:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.