Priority 1: Core Graphics Layer
shachi-gfx (Multi-Pass + Texture Management)
What: The 2 CRITICAL KOS gaps, filled.
Why: Multi-pass rendering enables lightmaps, shadow
passes, bump mapping, screen-space effects. Texture GC prevents VRAM
fragmentation in streaming scenarios. Reference: Kamui
KMFLOWCONTROL.C, KMYSTARTRENDER.C,
KMLOADTEXTURE.C
Multi-pass (~400 lines C):
shachi_pass_begin(SHACHI_PASS_0); // Configure OPB, list enables for this pass
// Submit opaque base geometry
shachi_pass_end();
shachi_pass_begin(SHACHI_PASS_1); // Second pass config
// Submit lightmap/bump/shadow overlays with depth-GEQUAL + Z-write disabled
shachi_pass_end();
shachi_render(); // Trigger ISP/TSP
- Up to 4 passes (Kamui does 8 — start conservative)
- Per-pass OPB configuration
- Automatic EOL injection between passes
- Depth comparison mode override per pass
Texture lifecycle (~300 lines C):
shachi_tex_t *tex = shachi_tex_load("texture.pvr"); // Upload to VRAM
shachi_tex_bind(tex); // Make active
shachi_tex_unload(tex); // Free VRAM
shachi_tex_gc(); // Defragment
- Track all texture allocations with metadata (size, format, last-used frame)
- LRU eviction for streaming scenarios
- Defragmentation via copy + remap (expensive — call between scenes, not frames)
- SmallVQ-aware loading (reduced codebook for small textures)
- Mipmap-twiddled offset (skip 1 DWORD — KOS misses this)
shachi-clip (Near-Z Clipping)
What: Software near-plane clipping for all submitted geometry. Why: DIV-001 (CRITICAL). Every shipped DC game needed this. PVR2 TA has no near-plane clip. Reference: Kamui/Ninja internal clipping (not in available source — implement from spec). Scope: ~200 lines C. Sutherland-Hodgman against Z=NEAR in camera space. Per-triangle: 3 visible→submit, 0 visible→cull, 2/1 visible→clip to quad/triangle with interpolated vertices.