gs

41 definitions in 8 files, 37 with an encoding diagram. src/isa/gs

Files

FileDefinitionsOtherWhat
package.lisp00the ISA.GS package: the PS2's Graphics Synthesizer, its registers as an ISA, GIF packets, local memory.
state.lisp019the GS as a machine: local memory, its registers, the vertex queue, transfers, the CLUT.
lmem.lisp08the GS's local memory: pages, blocks, columns, the swizzled pixel layouts.
regs.lisp414the GS's general registers as an ISA: addresses, fields, semantics.
draw.lisp034the GS's drawing: vertex kicks, primitives, and a reference rasterizer into local memory.
xfer.lisp05the GS's transfers: host to local (HWREG), local to host, local to local.
gif.lisp07GIF packets: GIFtags and their PACKED, REGLIST and IMAGE data, as the GS's command stream.
priv.lisp012the GS's privileged registers: the display circuits, CSR, IMR, SIGLBLID; the picture shown.

README

src/isa/gs: the PS2's Graphics Synthesizer, described as an ISA

The GS is driven by 64-bit writes to its general registers (through the GIF's packets) and by the EE's accesses to its privileged registers. Its instructions are those register writes, as the RSX's are method writes (src/isa/rsx). Package ISA.GS (uses CL and CORE).

FileRole
package.lispthe package and its exports
state.lispthe machine (gsm): 4 MiB local memory, registers, the vertex queue, transfers, the CLUT, counters; gs-reset; the PSM codes
lmem.lisplocal memory through the core's layouts (texfmt-gs-addr32/16/8/4): gs-read-pixel, gs-write-pixel, gs-color32
regs.lispdefgsreg: every general register's address(es), fields and semantics; gs-write, generated from the table
draw.lispthe vertex kick, primitives as the abstract state (gs-state), the reference rasterizer and pixel pipeline, the CLUT load
xfer.lisptransfers: host to local (HWREG), local to host, local to local
gif.lispGIF packets: GIFtags, PACKED, REGLIST, IMAGE (gif-qword)
priv.lispprivileged registers (PMODE ... BGCOLOR, CSR, IMR, SIGLBLID), VSYNC, the interrupt, the picture the display circuits read

The register form

(defgsreg TEST (#x47 #x48) ((ate 0 1) (atst 1 3) (alpha-ref 4 8) (afail 12 2) ...)
  "Pixel tests: alpha, destination alpha, depth")
(defgsreg TRXDIR #x53 ((xdir 0 2))
  "Transfer activation: ..."
  (gs-xfer-start g xdir))

A register has one address, or two for the drawing contexts' pairs (_1, _2: ctx is bound to 0 or 1); its fields are (name lsb size) and are bound in the body, with g the GS and value the 64 bits. The value is stored in (gsm-reg g address) before the body runs, so (greg NAME [ctx]) reads any register's last value (drawing decodes the context's registers once per primitive, gs-setup). gs-reg-name, gs-reg-fields and gs-reg-addresses give the table at compile time.

Each primitive drawn is said in the abstract graphics state (docs/gfx.md) from its context's registers (gs-state, draw.lisp), before the reference draws it: the queued vertices as immediate (12.4 positions less XYOFFSET: coordinates fraction 4, ST/Q when FST is 0), one primitive's topology (a sprite a rectangle-list), FRAME and ZBUF as color-target 0/attachment 0 and depth-target/depth-attachment (format codes of texfmt.lisp, layouts gs-swizzle..., FBMSK as blend 0 write-bits), SCISSOR, SCANMSK (raster line-skip), DTHE/DIMX, TEST (alpha test with AFAIL, DATE/DATM as mask-bit test/pass, the depth test), ALPHA/PABE/COLCLAMP as combine, FBA as mask-bit force, FOGCOL, TEX0/TEX1/TEXA/CLAMP as texture 0 and sampler 0 (CLUT format and offset; region clamp and repeat).

Local memory (lmem.lisp)

512 pages of 8 KiB, 32 blocks of 256 bytes a page. A buffer starts at a block and is a number of 64-pixel units wide; the pixel's block depends on the format's page and block shape, its place in the block on the column layout ([GSUM]). The layouts are the core's (src/core/texfmt.lisp, texfmt-gs-addr32 ... : the layout gs-swizzle of the abstract state), written as bit interleavings (bit i of the result from bit j of x or y) and checked against PCSX2's tables ([PCSX2] pcsx2/GS/GSTables.cpp) for every position; the Z formats' block numbers are those xor #x18. PSMT8H / PSMT4HL / PSMT4HH live in the top bits of a PSMCT32 word. Memory is kept exact: transfers, reads back and drawing share it byte for byte.

Drawing (draw.lisp)

The reference rasterizer: coverage at pixels' top-left corners in the 12.4 coordinates less XYOFFSET, top-left fill rule; sprites cover [x0, x1) rounded up. The pixel pipeline: scissor, SCANMSK, texture (all PSMs, CLAMP's four wrap modes, CLUT CSM1/CSM2, TEXA), the four texture functions, nearest or (TEX1.MMAG) bilinear texels, fog, alpha test with AFAIL, destination alpha test, depth test (Z32/24/16/16S), blending with PABE, DIMX dithering on 16-bit buffers, COLCLAMP, FBA, FBMSK. Not yet: minification by the LOD and mipmaps (MMAG's filter serves every size), AA1, the hardware's exact texel and line rules.

Tests

gs_gs (tests/isa/gs/gs.lisp): known addresses of each layout, every format's page a permutation of its bytes, round trips of all 13 formats; GIF PACKED, REGLIST and IMAGE packets; transfers each way; a sprite, two triangles sharing an edge (each pixel drawn once, counted by additive blending), a CLUT texture, alpha and depth tests; the display size and pixel, VSYNC and IMR.


Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.