# VIF0, VIF1 and the GIF Sources: EEUM ch. 6 (VPU, VIF) and ch. 7 (GIF) (Sony, DOC, facts only); ps2tek "Vector Interface (VIF)", "Graphics Interface (GIF)" (tier 3); judges: ps2autotests `dma/vif/*` (6 programs: `basic`, `intstall`, `mskpath3`, `stcycl`, `stmod`, `unpack`) and `gs/*` (ISC, TEST ROM). ## The VIFs (chip rule: they stay in the board) A VIF is the front end of a VPU: it takes a DMA stream of 32-bit VIFcodes and their data, **unpacks** vector data into VU data memory (UNPACK with formats S-32/16/8, V2/V3/V4 of 32/16/8 bits, V4-5; masking by STMASK/MASK, skipping and filling by STCYCL, addition decompression by STMOD and the ROW/COL registers), uploads microcode (MPG), starts and synchronises the VU (MSCAL, MSCALF, MSCNT, FLUSHE, FLUSH, FLUSHA), and on VIF1 handles **double buffering** in VU1 memory (BASE, OFFSET, TOPS/TOP, ITOP), **PATH2** to the GIF (DIRECT, DIRECTHL) and the VIF-side **PATH3 mask** (MSKPATH3) (EEUM §6.3-6.4; ps2tek "Command List"). VIF0 has the smaller set (no double buffering, no GIF path). Why this belongs to the board, not to vu-python: a VIF is a DMA-fed peripheral with its own FIFO, registers at 10003800h/10003C00h (EEUM §2.2.1) and interrupts (INTC bits 4-5); it is used only by the PS2. **VIF1 and VU1 are tightly coupled at run time**: VIF1 writes VU1 data memory while VU1 runs a microprogram from the other half of the double buffer, MSCAL waits for VU1 to end, and FLUSH waits for PATH1. They belong to one scheduling domain (domains.md, domain B). **Timing is observable**: whether an UNPACK has landed before VU1 reads that address, when MSCAL's stall ends, when PATH2 gets the GIF. EEUM §6.3 gives the data flow and the stalls, not cycle costs; the cost per qword of each UNPACK format is **U9**. ## The GIF (EEUM ch. 7) - **Three paths** into one 64-bit output to the GS at BUSCLK (EEUM §7.1, figure): PATH1 from VU1 memory by XGKICK; PATH2 from VIF1's FIFO (DIRECT/DIRECTHL, and image readback); PATH3 from DMA channel 2 (main memory or scratchpad). - **Priority PATH1 > PATH2 > PATH3**, checked whenever a GS **packet** ends (the last primitive with EOP = 1). Each arbitration costs one idle cycle at 147.456 MHz, and a tag whose PRIM field is not output costs another (EEUM §7.1.2). - **PATH3 in IMAGE mode** may be intermittent (GIF_STAT.IMT = 1): it checks the other paths every 8-qword slice, giving way to PATH1 and to PATH2's DIRECT, not DIRECTHL (EEUM §7.1.3). - **PATH3 masking**: VIF1's MSKPATH3 and GIF_MODE.M3R, independent; PATH3 runs only when both are clear (EEUM §7.1.4). Games use MSKPATH3 to synchronise texture uploads with VU1's drawing; its exact take-effect point is what `dma/vif/mskpath3` prints. - **XGKICK** (VU side): stalls if PATH1 is still busy; one kick queues while PATH2/PATH3 transfer, a second stalls (EEUM §7.1.1). - **GS packets**: GIFtag (128 bits: NLOOP, EOP, PRE/PRIM, FLG = PACKED / REGLIST / IMAGE, NREG, REGS) then data; PACKED converts each qword into a GS register write per the register descriptor; REGLIST sends 64-bit register values; IMAGE sends raw data to HWREG (EEUM §7.2-7.5). - GIF_CTRL, GIF_MODE, GIF_STAT, GIF_TAG0-3, GIF_CNT, GIF_P3CNT, GIF_P3TAG at 10003000h (EEUM §2.2.1). **Why arbitration makes timing visible.** The order in which PATH1 and PATH3 packets reach the GS decides the picture whenever both carry drawing state (a texture upload by PATH3 that VU1's primitives depend on). That order depends on when VU1 executes XGKICK and when DMA channel 2 delivers, so **the GS's input stream is a function of the timing of three domains**. This is the PS2's equivalent of the N64's RDP joins, and it is the main reason the board's domains must be synchronised at the GIF (domains.md). ## Unknowns U9 VIF cycle costs per UNPACK format and per VIFcode; U10 the cycle at which MSKPATH3 takes effect relative to an in-flight PATH3 packet (the test prints the observable result); U11 GIF FIFO depth as seen by the DMAC's slices (EEUM Figure 1-1 gives FIFO sizes in qwords, but its text layer does not say which number belongs to which FIFO: to read from the rendered page); U12 PATH2's behaviour when DIRECT data runs out mid-packet.