# GX: the graphics pipeline (CP, XF, SU/RAS, TX, TEV, PE), the EFB, its copies and the VI Sources: YAGCD 5.1-5.3, 5.11, 7, 8, 15 (TPL), 17 (graphic formats) (community, facts only, tier 3); Copetti's "Graphics" section (CC BY 4.0, secondary); the Nintendo/ArtX patents YAGCD 19 lists (public, tier 2, **not fetched yet**: open decision 7). No hardware-captured GX result is in hand. Everything about precision is unknown and listed. ## The pipeline, front to back 1. **Command FIFO (CP).** The CPU writes commands to the GX FIFO address (0x0C008000) through the write-gather pipe; Flipper appends each 32-byte burst to a ring buffer in main memory (base, end, write pointer; PI's CPU-side registers at 0x0C00300C-14 and CP's own at 0x0C000000), and the CP reads from it, with high/low watermarks that raise the CP interrupt (YAGCD 5.1, 5.4.1.1). The FIFO can be detached from the pipe so that the same commands build a **display list** in memory, called later with CALL DL (YAGCD 5.4.1.1, 5.11.5). The FIFO in RAM is the channel between the CPU domain and the GPU domain (domains-and-speed.md). 2. **Command stream** (YAGCD 5.11.5): an 8-bit command (opcode in bits 3-7, VAT index in 0-2): 0x00 NOP, 0x08 load CP register, 0x10 load XF registers, 0x20/0x28/0x30/0x38 load indexed XF data (INDX A-D), 0x40 CALL DL, 0x48 invalidate vertex cache, 0x61 load BP register, 0x80 quads, 0x90 triangles, 0x98 strips, 0xA0 fans, 0xA8 lines, 0xB0 line strips, 0xB8 points (draws OR-ed with the VAT index). 3. **Vertex loading** (CP registers): the vertex descriptor (which attributes are present, direct or indexed 8/16-bit) and eight vertex attribute tables (component counts, types u8/s8/u16/s16/f32, fixed-point shift), with array base and stride registers for indexed attributes (YAGCD 5.11.2). The vertex cache that serves indexed fetches from main memory is a timing structure (US 6,717,577 "Vertex cache"; HYPOTHESIS that it has no visible effect beyond timing and the explicit invalidate command). 4. **Transform (XF).** Matrix memory (position, normal, texture and post-transform matrices), up to 8 lights, two colour channels, up to 8 texture coordinate generators, viewport and projection; loaded by register writes (YAGCD 5.11.3-5.11.4). It is a fixed-function unit with its own floating-point format: **its precision and rounding are unknown** (U10). 5. **Setup and rasteriser (SU/RAS).** Culling, clipping (including the near-Z treatment of US 6,618,048), scissor, line and point widths, and rasterisation in 2x2 pixel quads (HYPOTHESIS from the four pixel pipes Copetti describes); edge and attribute interpolation precision unknown (U11). 6. **Textures (TX) and TMEM.** 1 MB of TMEM, split by software between cache and preloaded regions (Copetti; YAGCD 5.11.1). Formats (YAGCD 15, the TPL table): 0 I4 (8x8 tiles), 1 I8 (8x4), 2 IA4 (8x4), 3 IA8 (4x4), 4 RGB565 (4x4), 5 RGB5A3 (4x4), 6 RGBA8 (4x4, AR and GB in two cache lines), 8 CI4 (8x8), 9 CI8 (8x4), 10 CI14X2 (4x4), 14 CMPR (S3TC, 2x2 blocks of 4x4); palettes (TLUT) in TMEM; mipmaps, LOD bias, wrap modes, bilinear and trilinear filtering, anisotropy settings. **Indirect texturing** (16 indirect stages: YAGCD's BP list, IND_CMD0-F; bump mapping) feeds texture coordinates from other textures. 7. **TEV** (texture environment): up to 16 stages, each a colour and an alpha combiner of the form (d + lerp(a, b, c) + bias) * scale, with clamping, compare modes, constant ("konst") colours, four colour registers and swap tables (YAGCD's BP list: TEV_COLOR_ENV, TEV_ALPHA_ENV, TEV_REGISTER, TEV_KSEL; RAS1_TREF for the stage order; Copetti "TEV"). **The arithmetic's bit widths, rounding of the lerp, and clamping points are not in the sources in hand** (U12): the single largest precision question of the board, and the one where a hardware capture would matter most. 8. **Pixel engine (PE).** Z compare (before or after texturing: "early Z"; US 6,636,214), alpha compare, fog (US 6,580,430), blending, logic ops, dithering; writes to the EFB. Tokens and the "draw done" (FINISH) raise PE interrupts; a token is how the CPU learns how far the GPU has got (YAGCD 5.2, 5.11.1). PE also keeps a **bounding box** of drawn pixels readable by the CPU (YAGCD 5.2, BP 0x55/0x56). ## The EFB and its copies - **EFB**: 2 MB on Flipper, at most 640 x 528 pixels (Copetti); pixel formats RGB8 with 24-bit Z, RGBA6 with 24-bit Z, and RGB565 with 16-bit Z for 3-sample anti-aliasing (the formats from YAGCD 5.11's PE control register; HYPOTHESIS until transcribed with its bit numbers at M5). - **The CPU can read and write the EFB directly** at physical 0x08000000 ("peek/poke"), through PE, with its Z and alpha read modes (YAGCD 4.1, 5.2). Games use it (for example for lens-flare occlusion: HYPOTHESIS, a commonly cited case). - **EFB copy** (BP registers: source rectangle, destination address and stride, format, scale, clear): the GPU writes a rectangle of the EFB to **main memory**, either - to the **XFB** (external frame buffer) in YCbYCr 4:2:2 (YAGCD 17.1 gives the colour conversion as used by software; the copy's own coefficients and its vertical anti-aliasing/deflicker filter come from BP registers: HYPOTHESIS until transcribed), with optional vertical scaling and gamma; or - to a **texture** in one of the texture formats (and Z formats), for render-to-texture, shadows, reflections, motion blur. The copy may clear the EFB as it goes. - **What a copy means for the emulator:** a copy is where the GPU's private memory becomes visible to every other domain (the CPU reads it, the VI scans it out, the next draw samples it as a texture). It is the GX equivalent of the N64 RDP's "join". ## The VI (video interface; YAGCD 5.3, 7) VI scans the XFB out of main memory, top and bottom fields for interlaced modes, with its own timing registers (horizontal and vertical counts, display position, four display interrupts DI0-DI3 at programmed positions), NTSC, PAL, MPAL and progressive (480p) modes, and a horizontal scaler (YAGCD 5.3, 5.3.1). Its line counter and interrupts are how games pace themselves. The VI reads RAM at scan-out times: a frame read while the CPU or a copy is writing it shows the mixture (the observable contract's "video output"). ## What the specification models, at which level | Block | Level | Why | | --- | --- | --- | | CP, FIFO pointers, watermarks, display lists, register loads | transaction | its reads of RAM and its interrupts are channel events | | XF | functional, with its arithmetic stated as a FITTED model | no hardware evidence of its floating-point format in hand | | SU/RAS/TX/TEV/PE | functional per pixel: every pixel's value defined, order of writes defined; timing per primitive estimated | per-pixel values are what copies, peeks and the VI show; no cycle-level evidence exists | | EFB copies, peek/poke | transaction (each copy a timed write burst to RAM) | the join between domains | | VI | cycle of its own counters (line and pixel), reads of RAM per line | interrupts and scan-out timing are in the observable contract | The Python specification of the pixel pipeline is a **readable software rasteriser**: slow (execution-architecture.md gives the numbers) and exercised by short slices and test programs, never by whole games.