# The renderer and the 2D layers Sources: MAME 0.285 `model2_v.cpp` and `model2rd.ipp` (BSD-3-Clause, pinned; cited M2V, **OBSERVED**), `segas24_v.cpp` (Olivier Galibert, BSD-3-Clause) for the tilemaps. M2V names its own sources: "the Geometry Engine code disassembly from a 2B game", "the Model 2B-CRX Manual" and "ElSemi's Direct3D implementation of the geometrizer engine". No manufacturer document for the renderer is in hand; the "Lockheed-Martin" in M2's header refers to the Real3D lineage of the rasterisation hardware (OBSERVED wording only). ## The pipeline as MAME models it 1. **Geometrizer** output: polygons in screen space with texture, colour and Z ([geometry.md](geometry.md)). 2. **Z-sort and clip.** "Not much information about this hardware"; a master Z-clip enable and a Z-sort mode. The manual is quoted as saying Z-sort works internally in a 1.4.8 format, with the mode value added to the float Z and converted to 16 bits (most likely 4.12); polygons can inherit the previous polygon's Z ordinal, or take their minimum or maximum. **Polygons from later windows always draw on top of earlier windows.** MAME sorts into 65,536 buckets by 4.12 Z. Four frustum planes clip before projection. 3. **Renderer.** Double-buffered (page flip or single buffer), 60 Hz or 30 Hz output. Textures with U and V in 13.3 fixed point, log tables and distance coefficients choosing the level of detail, mip maps averaged between two levels, 128 x 128 "microtextures" for close-up detail. **Polygons are drawn front to back with a fill buffer that stops pixels being overwritten**, "to ensure that the polygons closest to the camera are rendered first, in case the renderer runs out of time and has to skip ahead to the next frame." (All M2V header.) 4. **Output** mixes the 3D frame buffer with the System 24 tilemap layers and the palette and colour-translation tables (M2 memory map, `model2_base_mem`). ## What the specification must decide (unknowns, in board order) - **The renderer's time budget** is observable: a frame that runs out of time drops its farthest polygons. A specification that ignores renderer time gets busy scenes "too right". The budget, the cost per polygon and per pixel, and the drop rule are unknown (U6). Tag: FITTED, from detector frames where MAME is known to drop or not. - **The Z-sort's arithmetic** (1.4.8 internal, 4.12 key, the override modes) and the window ordering: from the 2B manual if it can be found, otherwise detector-fitted (U7). - **Texture filtering and LOD arithmetic**: bit widths of the blend, the log table's contents (it is in the 2A video board ROMs, `video_unk`, read as data, never shipped), rounding (U8). - **The fill buffer**: per pixel, per frame; whether it can be read by the CPU (U9). ## The 2D layers Sega's System 24 tilemap generator (MAME's `S24TILE`, `segas24_v.cpp`), the same chip family as Model 1's. No System 24 board exists in the family, so it stays inside model2-python (and model1-python, if that board is built: see decision M7). ## Speed and the GPU question Visible pixels: 496 x 384 at 57.5 Hz = **10.95 M pixels/s**. Because the renderer draws front to back with a fill buffer, each visible pixel is shaded once at most; rejected fragments cost a fill-buffer test (HYPOTHESIS from M2V's description). Software cost at 200-400 desktop-equivalent host cycles per shaded pixel (texture fetch, mip blend between two levels, colour translation; HYPOTHESIS, in line with the N64 document's 160-400 per RDP pixel): | Target | Budget per pixel (cycles/s / 10.95 M) | Cores needed at 200-400 | | --- | ---: | --- | | Desktop (5.0e9) | 457 | 0.44-0.88 | | Phone app (4.0e9) | 365 | 0.55-1.10 | | Phone browser (2.4e9) | 219 | 0.91-1.83 | So the renderer fits a software back end on every target with one or two worker threads, **if** frames are split by the late-era rule: a front end on the CPU thread decides the timing observables (busy bits, the drop point, the polygon count register at 0x10400000), and the pixel back end runs behind it, joining only when the i960 reads a frame buffer (0x11600000-0x116FFFFF) or the scan-out needs a line. A GPU back end is then **turbo, not required**; it would be judged per pixel against the software back end (late-era method, section 4). Upscaling or texture filtering beyond the hardware's is a named concession, off by default. The exactness of that split depends on X3's question from the N64 Phase 0: is the drop point a function of geometry and modes alone, or of pixel results? If the renderer's time depends on how many pixels the fill buffer rejected, the front end must count pixels too, which costs a coverage pass but no shading (HYPOTHESIS; decision M6).