Documentation
¶
Index ¶
- Constants
- Variables
- func Admits(p *PixelParams, x, y int32) bool
- func ApplyColorCalc(cc, dst, pixel, gouraud uint32) uint32
- func BeginQuadLine(op *DrawOp, st *QuadLine, i int32) int32
- func BeginSegment(st *Segment, x1, y1, x2, y2 int32, gStart, gEnd uint32)
- func BeginSpriteRow(op *DrawOp, st *SpriteRow, row int32) int32
- func ClearLists(rs *compute.RoundState, i uint32)
- func ClearStamps(rs *compute.RoundState, i uint32)
- func ClipSteps(x0, y0, x1, y1, clipX, clipY, lineLen int32) (j0, j1 int32, ok bool)
- func Combine(p *PixelParams, dst, pixel, gouraud uint32) uint32
- func CopyFBPages(fb compute.VDP1FB, writes *FBWrites, p *PageCopyParams, i uint32)
- func CopyVDP1Pages(vram *compute.VDP1VRAM, pages *VRAMPages, p *PageCopyParams, i uint32)
- func DotToPixel(vram *compute.VDP1VRAM, dot, cmdcolr, colorMode uint32) uint32
- func Draw(b *Buffers, op *DrawOp, st *DrawState)
- func EdgeAt(x1, y1, x2, y2, steps, i int32) (x, y int32)
- func EndsOnCount(p *PixelParams) bool
- func EraseRows(fb compute.VDP1FB, op *DrawOp, r0, r1 int32)
- func FragmentCap(poolWords uint32) uint32
- func Generate(b *Buffers, entry *DrawOp, t, n uint32)
- func GenerateTag(b *Buffers, entry *DrawOp, t, n, g uint32)
- func GenerateWrite(b *Buffers, entry *DrawOp, t, n, g uint32)
- func HoleFillDot(px, py, prevPx, prevPy int32) (gfx, gfy int32)
- func HoleFills(j, px, py, prevPx, prevPy int32) bool
- func IsEndCode(dot, colorMode uint32) bool
- func LerpGouraud(start, end uint32, i, n int32) uint32
- func LineKey(seq uint32, line int32) uint32
- func LineReadsTexels(op *DrawOp, checkECD bool, pixCycles int32) bool
- func LoadLineEnd(rec compute.LineRecords, base uint32, i int32) int32
- func NormalSrcX(op *DrawOp, x int32) int32
- func OpBox(op *DrawOp) (x0, y0, x1, y1 int32, ok bool)
- func OpCharData(op *DrawOp) (addr, size uint32)
- func OpChunks(op *DrawOp) uint32
- func OpColorTable(op *DrawOp) (addr, size uint32)
- func OpDots(op *DrawOp) int32
- func OpForm(op *DrawOp) uint32
- func OpLines(op *DrawOp) int32
- func OpRecordWords(op *DrawOp) uint32
- func PhysicalRow(p *PixelParams, y int32) int32
- func PolylineLeg(op *DrawOp, leg int32) (x1, y1, x2, y2 int32, gStart, gEnd uint32)
- func PreClipReject(minX, minY, maxX, maxY, clipX, clipY int32) bool
- func PutDot(fb compute.VDP1FB, rs *compute.RoundState, p *PixelParams, x, y int32, ...)
- func QuadBounds(op *DrawOp) (minX, minY, maxX, maxY int32)
- func QuadLineSpan(vram *compute.VDP1VRAM, fb compute.VDP1FB, rs *compute.RoundState, op *DrawOp, ...) int32
- func QuadLineTime(vram *compute.VDP1VRAM, op *DrawOp, st *QuadLine, j1, budget int32, ...) int32
- func QuadPos(st *QuadLine, j int32) (px, py int32)
- func QuadSrcU(op *DrawOp, st *QuadLine, u int32) int32
- func QuadSteps(op *DrawOp) int32
- func ReadRowDot(vram *compute.VDP1VRAM, rowBase uint32, x int32, colorMode uint32) uint32
- func ReadsDestination(p *PixelParams) bool
- func RecordStride(op *DrawOp) uint32
- func RecordedLineEnd(rec compute.LineRecords, op *DrawOp, line int32) int32
- func Resolve(fb compute.VDP1FB, rs *compute.RoundState, i uint32)
- func RightEdgeAt(x1, y1, x2, y2, steps, i int32) (x, y int32)
- func RowDotByte(vram *compute.VDP1VRAM, rowBase uint32, x int32) uint32
- func RowDotNibble(vram *compute.VDP1VRAM, rowBase uint32, x int32) uint32
- func RowDotWord(vram *compute.VDP1VRAM, rowBase uint32, x int32) uint32
- func RowStride(charW int32, colorMode uint32) int32
- func ScaledRowEnd(rec compute.LineRecords, op *DrawOp, row int32) int32
- func ScaledSrcX(op *DrawOp, x int32) int32
- func SegmentAt(st *Segment, i int32) (x, y, err int32)
- func SegmentSpan(fb compute.VDP1FB, rs *compute.RoundState, op *DrawOp, st *Segment, ...) int32
- func SegmentTime(st *Segment, i1, budget int32, pixCycles int32) int32
- func SimpleWrite(p *PixelParams) bool
- func SpriteGouraud(op *DrawOp, x, row int32) uint32
- func SpriteRowChecksECD(op *DrawOp) bool
- func SpriteRowSpan(vram *compute.VDP1VRAM, fb compute.VDP1FB, rs *compute.RoundState, op *DrawOp, ...) int32
- func SpriteRowTime(vram *compute.VDP1VRAM, op *DrawOp, st *SpriteRow, row, x1, budget int32, ...) int32
- func SpriteRowWidth(op *DrawOp) int32
- func SpriteRows(op *DrawOp) int32
- func StoreLineEnd(rec compute.LineRecords, base uint32, i, end int32)
- func TexelDraws(dot, colorMode, spd uint32, checkECD bool, ec *EndCodeCounter, column int32) bool
- type Buffers
- type DDAEdge
- type DistortedTexture
- type DrawOp
- type DrawState
- type EndCodeCounter
- type FBWrites
- type GouraudStepper
- type PageCopyParams
- type PixelParams
- type QuadLine
- type Segment
- type SpriteRow
- type VRAMPages
Constants ¶
const ( OpNormalSprite = 0 OpScaledSprite = 1 OpDistortedSprite = 2 OpPolygon = 3 OpPolyline = 4 OpLine = 5 OpErase = 6 // an erase of the frame buffer, not a command )
Draw op kinds, the VDP1 command types that draw.
const ( OpFlagECDOff = 1 << 0 // end code detection disabled (CMDPMOD ECD) OpFlagSPDOn = 1 << 1 // transparent dots drawn (CMDPMOD SPD) OpFlagFlipH = 1 << 2 // character read right to left OpFlagFlipV = 1 << 3 // character read bottom to top OpFlagHSS = 1 << 4 // high speed shrink (CMDPMOD HSS) OpFlagHSSOdd = 1 << 5 // high speed shrink samples odd source dots (FBCR EOS) )
Draw op flag bits.
const ( FragmentCounter = 0 FragmentWords = 4 )
The round state's regions are the RoundState's three buffers, each sized by the host: the order stamps, one per pixel at its finest addressing, each the key of the last replace-class dot on the pixel or zero; the fragment list heads, one per 16-bit pixel, the slot of the pixel's last appended fragment or zero; and the fragment pool, its word FragmentCounter the fragment counter in words and its fragments from slot FragmentWords, FragmentWords each: the dot's key, its pixel and Gouraud value packed, the slot of the next fragment of the list or zero, and the color calculation mode. Slot 0 holds the counter and is never a fragment, so a zero link ends a list. Destination-reading dots never land in an 8-bit frame buffer, whose modes replace, so the heads cover the 16-bit pixels.
const ( PassStore = 0 PassTag = 1 PassWrite = 2 )
The pixel write's passes. The walk stores every dot as it draws it (PassStore). A device draws a batch of ops in two passes over the same dots with no order between its threads: the tag pass (PassTag) raises each dot's pixel key word to the dot's draw order key, so the word ends at the key of the batch's last dot on the pixel, and the write pass (PassWrite) stores only the dot whose key the word holds. The two passes give the pixel the batch's last replace-class dot, which is the walk's result on a pixel whose dots replace.
const DDAFraction = 32
The DDA positions of the side edges and the connecting lines carry DDAFraction fraction bits, and a position's integer part is its dot: the nearest dot to the exact position, since the position starts half a dot past its start point. A step's error, the fraction the division drops, is below 2^-DDAFraction, so over the steps of a line in the drawing coordinate range, at any render scale, the accumulated error stays under the distance from any exact position to the nearest half dot, and only a position exactly half way between two dots takes its dot from the direction of the error: a step truncated toward zero leaves such a position at the dot toward the start point, and a step rounded away from zero at the dot away from it.
const EndCodeLimit = 2
EndCodeLimit is the end codes that end a line: the second one (VDP1 manual Sec 6.3).
const GenChunk = 32
GenChunk is the steps of a line one thread of Generate draws as one piece: a thread enters a chunk at its first step through the closed forms, so a long line is split across threads instead of being one thread's dependent chain.
const LineEndPending = -1
LineEndPending is the record of a line the walk has not ended.
const LineRecordWords = 1
Line records: one word per line of an op that reads texels, at the op's record base, holding where the line ended. A line's setup is a function of the op and the line index, so a renderer drawing the op recomputes it with the walk's own setup functions; what it cannot recompute is where the end code rule ended the line (VDP1 manual, End Code Disable: the row ends where its second end code is read), which the walk finds by reading the line's texels in order. The walk stores that word when the line ends. A sprite row's word is the column its span ended at: the row's width when no end code ended it, the second end code's column when one did, 0 for a scaled sprite row outside the drawing area. A connecting line's is its last step after the pre-clip: the pre-clipped last step when no end code ended it, the step before the second end code when one did, which is always below the pre-clipped last step. Polygons, polylines, lines, and erases read no texels and have no records. A record holds LineEndPending from the op's reservation until the walk ends the line, so a renderer drawing a line the walk has not ended can tell its record is not final; every final record is at least zero.
const NoStore = 1 << 16
NoStore is the combine's result when the dot stores nothing: a value above any 16-bit pixel.
const OffscreenRowCycles = 5
OffscreenRowCycles is the cycles a scaled sprite row outside the drawing area costs: the row is skipped without reading dots.
const PreClipLineCycles = 3
PreClipLineCycles is the per-line pre-clipping detection cost charged when a connecting line is wholly outside the drawing area. Off-screen dots of a partially visible line are charged per dot like visible dots, since the DDA iteration runs regardless and only the frame buffer write is discarded.
The VDP1 User's Manual Supplement Section 1.2 (Pre-Clipping Disable) states the detection overhead is "up to five CPU clock cycles for one line", a maximum with no formula for the actual value. 3 approximates an average over the detection cases (trivial reject through full clip-edge intersection).
const UnboundedCycles = 0x7FFFFFFF
UnboundedCycles is a budget no line reaches.
const YieldChunk = 8
YieldChunk is the dots a span function draws between checks of its cycle budget: it returns at the first chunk boundary at or past the budget. Smaller values give finer SH-2 / VDP1 interleaving at the cost of more in-loop branch overhead; larger values reduce overhead but allow more system cycles of overshoot per yield. Must be at least 1.
Variables ¶
var Entries = [...]string{"GenerateTag", "GenerateWrite", "ClearStamps", "ClearLists", "Resolve", "CopyVDP1Pages", "CopyFBPages"}
Entries names the package's entry points: the op draw's two passes, the order stamp clear, the fragment list clear, the fragment resolve, the VDP1 VRAM page copy, and the frame buffer write copy. A renderer indexes them by name.
var Source embed.FS
Source is this package's Go source for the GPU renderer's compile stage.
The files are named one by one: the compile stage takes everything Source holds, so this file and the package's tests must stay out of it. TestEmbeddedSource holds the list against the directory.
Functions ¶
func Admits ¶
func Admits(p *PixelParams, x, y int32) bool
Admits is the pixel write's gate: whether a dot at (x, y), in the command's coordinates (logical rows under DIE), lands. It lands inside the system clip, inside the user clip in user clip mode 2 and outside it in mode 3 (userClipAdmits), where x+y is even under mesh, and on the drawn field's parity under double interlace. The mesh and the parity are taken on the native dot, the position shifted right by ScaleShift, so a sub-dot takes its block's decision. The answer depends on the position and the params alone, so a pixel's dots all share it. The checks are written to inline into the per-dot store: the clip compares unsigned, so a negative coordinate fails as a large one (the clip bounds are never negative); mesh and the parity are masks, Mesh, DIE, and DILOdd being 0 or 1.
func ApplyColorCalc ¶
ApplyColorCalc applies a color calculation mode other than replace to a source pixel against the destination pixel dst, returning the value to store or NoStore. Shadow (modes 1 and 5) halves the destination where its MSB is set and stores nothing otherwise, the source and Gouraud unused. The other modes apply the Gouraud correction for modes 4 to 7, then half luminance or half transparency. It is one call for the non-replace modes, so that Combine inlines into the per-dot store.
func BeginQuadLine ¶
BeginQuadLine sets up connecting line i of op, from the A-D edge to the B-C edge at edge step i, and returns the cycles charged. The endpoints are the vertices at the first and last step and the edge DDA positions between. A single-dot line is step 0 alone. A longer line has its off-screen ends pre-clipped: the trailing dots are charged and dropped, and the leading dots too unless end codes are checked, since a skipped dot could hold the end code that ends the line.
func BeginSegment ¶
BeginSegment starts the segment from (x1, y1) to (x2, y2).
func BeginSpriteRow ¶
BeginSpriteRow starts row of op and returns the cycles charged. A scaled sprite row outside the drawing area is complete on return, its end at column 0 so no column of it draws.
func ClearLists ¶
func ClearLists(rs *compute.RoundState, i uint32)
ClearLists zeroes fragment list head i and, on the first thread, the fragment counter, once per round with destination-reading ops. Entry point: one thread per head.
func ClearStamps ¶
func ClearStamps(rs *compute.RoundState, i uint32)
ClearStamps zeroes order stamp i, once per frame after the op list restarts. Entry point: one thread per stamp.
func ClipSteps ¶
ClipSteps intersects the segment (x0,y0)-(x1,y1) with the drawing area [0,clipX] x [0,clipY] (Liang-Barsky) and returns the visible parameter range scaled to the segment's steps: j0 and j1 are the floors of t0 and t1 times lineLen, with t0 and t1 the entry and exit parameters in [0,1]. ok is false when the segment lies wholly outside. The rasterizers skip connecting-line dots outside [j0, j1] with a slack margin (VDP1 manual pre-clipping: for lines completely separated from the drawing area drawing does not start); output is unchanged because the pixel write discards those dots anyway.
The parameters are exact rationals: t0 is the largest entry fraction and t1 the smallest exit fraction, compared by cross multiplication, so the floors are exact.
func Combine ¶
func Combine(p *PixelParams, dst, pixel, gouraud uint32) uint32
Combine is the pixel write's value rule: from the destination pixel dst (meaningful only when ReadsDestination), the source pixel, and the Gouraud value, the value to store, or NoStore. Replace stores the source with bit 15 set under MSB-on (MSBOn is 0 or 1; the walk forces replace mode for MSB-on); the other modes go through ApplyColorCalc. An 8-bit frame buffer's store keeps the low byte: the walk forces replace mode there, so the width is the store's, not the rule's.
func CopyFBPages ¶
func CopyFBPages(fb compute.VDP1FB, writes *FBWrites, p *PageCopyParams, i uint32)
CopyFBPages writes byte i of a band's staged pages of CPU frame buffer writes into the frame buffer where the page's mask marks the byte as written. At scale the byte is one lane of a native pixel (the address over two in a 16-bit buffer, the address in an 8-bit one), and it is written to the same lane of every pixel of that pixel's N by N block at the scaled width. Entry point: one thread per byte.
func CopyVDP1Pages ¶
func CopyVDP1Pages(vram *compute.VDP1VRAM, pages *VRAMPages, p *PageCopyParams, i uint32)
CopyVDP1Pages writes word i of a band's staged pages into VDP1 VRAM. Entry point: one thread per word.
func DotToPixel ¶
DotToPixel converts a dot to a frame buffer pixel: mode 1 looks the dot up in the color lookup table at CMDCOLR, mode 5 is the dot itself, the other defined modes combine CMDCOLR's upper bits with the dot, and the undefined modes 6 and 7 give zero.
func Draw ¶
Draw is the walk's loop over a draw op: it draws the op's lines in order and every step of a line in order, through the walk's own setup and span functions, under its cycle budget, yielding with the state kept, and as it reads a textured line's dots in order it finds where the end code rule ended the line and records it. The device does not run Draw; its entry point is Generate, which takes each textured line's end from the walk's record.
Draw runs the pixel write's store pass, which reads no key word, so the walk's buffers hold no round state. Each line's state carries the line's draw order key, as the spans expect, though the store pass never reads it. A walk with Timing set runs the timing form of every span instead: the same cycles in the same pieces, the same line ends, texels read only where the cycles depend on them, and no dot drawn.
func EdgeAt ¶
EdgeAt is the dot of the A-D edge from (x1, y1) to (x2, y2) over steps steps at step i: the DDA start plus i deltas (NewDDAEdge).
func EndsOnCount ¶
func EndsOnCount(p *PixelParams) bool
EndsOnCount reports whether the end code counter cuts a line of an op drawn with the pixel params: only at native. A scaled line samples its character more finely than the native line, reading columns the native line skipped or a column more times, so a fresh count would end it early; at scale an end code dot is still skipped and counted, and the native line's recorded end alone cuts the line.
func EraseRows ¶
EraseRows erases rows [r0, r1) of the erase op's rectangle, r1 clamped to the rectangle's rows, with EWDR: the 16-bit modes store EWDR per dot, the 8-bit modes its high byte on even columns and its low byte on odd (VDP1 manual Sec 4.4). The column parity is the native column's, the column shifted right by ScaleShift, so every byte of a native pixel's block holds that pixel's byte.
func FragmentCap ¶
FragmentCap is the fragments a pool of poolWords words holds: its slots after the counter's. The host bounds a round to it.
func Generate ¶
Generate draws the entry's chunks in the store pass, the pass the walk draws in, reading no round state: thread t of n takes its chunks by stride. Run as thread 0 of 1 it draws the entry's lines and steps in order, the walk's own order, so a schedule that draws entries one at a time in the list's order needs no rounds.
func GenerateTag ¶
GenerateTag is the tag pass of Generate, the device's draw of one entry of a batch, a group entry point with the entry as the group's params row: the group's threads take the chunks of the entry's lines [LineFrom, LineTo) by stride, the first line from LineStart and the last to LineEnd, each entering its line at its chunk's first step through the walk's own setup functions and running the walk's span over the chunk, with no order between the threads. The pass is the entry point dispatched, GenerateTag or GenerateWrite, and says what the span's pixel write does with a dot, through the pixel params of the thread's copy of the entry: the tag pass raises the pixel's order stamp to the line's key and the write pass stores the dot whose key the stamp holds. A textured line ends where the walk's record says the end code rule ended it: a thread entering a line part way has not read the end codes before its chunk, and within the recorded range a fresh count never ends the line, since the record already cut it at the second end code. An entry's last line bounded by LineEnd is the same case: the walk had not ended that line when the entry closed. At scale a sprite row's end comes from its native row's record through ScaledRowEnd, and the entry's bounds, scaled, apply to every sub-row of the native rows they bound. A connecting line's or a segment's entry keeps its native bounds, and a sub-dot draws when the native line and step whose block holds it (quad.go) lie within them and, on a textured line, at or before the native line's record.
func GenerateWrite ¶
GenerateWrite is the write pass of Generate.
func HoleFillDot ¶
func HoleFills ¶
The anti-alias hole fill of a connecting line (VDP1 manual Sec 1, Anti-aliasing, Figure 1.6): when step j's dot at (px, py) shares neither coordinate with the previous step's at (prevPx, prevPy), the staircase drops a dot, and one corner of the step is filled before the step's own dot. The figure gives the corner for each of the eight drawing directions: (px, prevPy) when the step advances x and y in the same direction, (prevPx, py) when it advances them in opposite directions. HoleFills is the condition (step 0 has no previous dot), HoleFillDot the corner. Two functions so the condition stays a plain branch in the loops.
func IsEndCode ¶
IsEndCode reports whether a dot is the color mode's end code: the highest dot value of the 4-bit and 8-bit modes, 0x7FFF in the 16-bit mode (VDP1 manual Sec 6.3).
func LerpGouraud ¶
LerpGouraud linearly interpolates a packed Gouraud entry (RGB555) between start and end at position i out of n-1 steps, each channel truncating toward zero.
func LineKey ¶
LineKey is the draw order key of line line of the op at ordinal seq of its batch: the ordinal above the line, one added so no key is zero, which is the order stamp's value where no dot has landed. Two dots of one line never share a pixel, so the key needs no step. The frame's cycle budget bounds the ordinal under 2^16 (a command's table fetch costs 15 cycles), and the drawing coordinate range bounds the line under 2^16: VDP1 manual Sec 2.1, Frame Buffer Plane, gives -1024 to 1023 on both axes and states that operation is not guaranteed beyond it, so a part's edge has at most 2047 steps, 2047 << ScaleShift at scale, under 2^16 through a scale shift of 5. The walk accepts wider coordinates, and a list with an edge of 65536 steps or more, outside the guaranteed range by a factor of thirty at native and by 65536 >> ScaleShift native steps at scale, would let a line index carry into the ordinal; the manual defines no result for such a list. So the key orders the batch's lines as the walk drew them.
func LineReadsTexels ¶
LineReadsTexels reports whether a textured line's cycles depend on its texels: when the line checks end codes, since the second one ends it, or when a dot drawn costs more than a dot skipped, in a six-cycle mode with transparent dots not drawn. Every other line charges from its step count alone. With one cycle per dot a skipped dot and a drawn dot cost the same, and with transparent dots drawn every dot is drawn.
func LoadLineEnd ¶
func LoadLineEnd(rec compute.LineRecords, base uint32, i int32) int32
LoadLineEnd reads where line i of the op at base ended.
func NormalSrcX ¶
NormalSrcX is the source column destination column x of a normal sprite row reads: the column itself, from the right when the command flips horizontally.
func OpBox ¶
OpBox is the inclusive box of the dots op can store, in the op's own coordinates (logical rows under DIE): a draw's vertex or character box cut to the system clip, an erase's rectangle. ok is false when nothing can land.
func OpCharData ¶
OpCharData is the VRAM range op's texel reads cover: CharH rows of RowStride bytes from CharAddr, the character data a sprite of any kind reads. A kind that reads no texels has a zero size.
func OpChunks ¶
OpChunks is the chunks of op's work Generate's threads take apart, the most threads that do work for it: an erase's lines, and a drawn op's lines by its runs of GenChunk steps. A part of the op outside its line range or its bounds takes fewer, so the count holds every chunk a thread can be given.
func OpColorTable ¶
OpColorTable is the VRAM range of op's color lookup table, the 16 words at CMDCOLR times 8 that DotToPixel reads in color mode 1 for a sprite of any kind, and a zero size in every other mode or for a kind that reads no texels.
func OpDots ¶
OpDots is the most dots any line of op draws along its major axis: a sprite row's width; for a four-vertex part the longer of the A-B and D-C connecting lines plus two, since the lines between interpolate those two, whose larger axis distance is convex, and their endpoints are the rounded edge positions, the A-D edge taking a half-way position toward its start and the B-C edge away from it (NewDDAEdge, NewRightDDAEdge), which can place the ends one dot further apart than the exact positions; the longest polyline leg plus one; the line's dots; an erase rectangle's columns. At scale a connecting line or a segment is drawn per column of its major axis and reaches N - 1 columns past its last dot (square.go).
func OpForm ¶
OpForm is the loop a rasterizer runs for op: its kind, except that a polygon whose side edges are points is the A-B segment, the line form.
func OpLines ¶
OpLines is the lines a rasterizer draws for op: the rows of a sprite, the connecting lines of a four-vertex part (its edge steps plus one, and one for a polygon whose side edges are points, drawn as a segment), the four legs of a polyline, the one segment of a line, or the rows of an erase rectangle. An op whose vertices or character size lie outside what the walk can produce draws nothing: a renderer reading the op as buffer content must not run the loops it bounds on a corrupt record.
func OpRecordWords ¶
OpRecordWords is the words op's records take: one record per line.
func PhysicalRow ¶
func PhysicalRow(p *PixelParams, y int32) int32
PhysicalRow is the frame buffer row a dot at logical y lands on: the row itself, or its half under DIE, where the game's doubled Y halves to the physical row. At scale the halving is of the native row, y shifted right by ScaleShift, and the sub-row within the native row is kept.
func PolylineLeg ¶
PolylineLeg is the vertices of leg (0 to 3) of a polyline: A-B, B-C, C-D, D-A.
func PreClipReject ¶
PreClipReject reports whether a bounding box lies entirely outside the drawing area (0,0)-(clipX,clipY).
func PutDot ¶
func PutDot(fb compute.VDP1FB, rs *compute.RoundState, p *PixelParams, x, y int32, pixel, gouraud, key uint32)
PutDot writes the dot at (x, y): Admits decides whether it lands, the physical row is y halved under DIE, and then the op's pass decides what the dot does, one test per dot. The store pass reads the destination when the mode reads it, Combine gives the value, and the store is a byte in an 8-bit frame buffer and a word otherwise. The tag and write passes go through putDotKeyed with the dot's draw order key (LineKey); the store pass reads neither the key nor the round state.
Under DIE=1 the game submits y in 0..2*height-1 (VDP1 manual Table 1.2): the DIL parity filter discards the opposite parity and the surviving y halves to the physical row.
func QuadBounds ¶
QuadBounds is the bounding box of the four vertices.
func QuadLineSpan ¶
func QuadLineSpan(vram *compute.VDP1VRAM, fb compute.VDP1FB, rs *compute.RoundState, op *DrawOp, st *QuadLine, j1, budget int32, pixCycles int32) int32
QuadLineSpan draws steps [st.J, j1) of the connecting line, where j1 is at most st.JEnd+1, or to the first YieldChunk boundary at or past the cycle budget with the line unfinished, and returns the cycles charged: the source advance per dot (one, or the distance between texture samples, halved under high speed shrink) plus the balance to pixCycles for a dot drawn. Adjacent connecting lines overlap and double-write where they share dots, matching hardware (VDP1 manual Sec 1.6 "Anti-aliasing" / Sec 1.7), and each step fills its hole-fill dot (HoleFills, HoleFillDot) before its own. A plain replace under the system clip (SimpleWrite) stores its dots directly, the decision PutDot would reach.
func QuadLineTime ¶
func QuadLineTime(vram *compute.VDP1VRAM, op *DrawOp, st *QuadLine, j1, budget int32, pixCycles int32) int32
QuadLineTime charges steps [st.J, j1) of the line without drawing them, as QuadLineSpan would charge them, in the same YieldChunk pieces against the same budget, and ends the line where QuadLineSpan would: a distorted sprite line whose cycles depend on its texels reads them through the same rules and nothing else, any other distorted sprite line charges the source advance per step from the same closed forms, and a polygon line charges pixCycles per step.
func QuadPos ¶
QuadPos is the dot position at step j of the line: the DDA position from the left endpoint, pinned to the right endpoint at the last step.
func QuadSrcU ¶
QuadSrcU is the source column read for texture column u (a texture position's integer part): clamped to the character and snapped to one parity under high speed shrink.
func QuadSteps ¶
QuadSteps is the number of edge steps of a four-vertex part (a distorted sprite or a polygon): the larger Chebyshev length of the A-D and B-C side edges. Zero when both side edges are points.
func ReadRowDot ¶
ReadRowDot reads dot x of the character row at rowBase in the color mode. The undefined modes 6 and 7 read as zero.
func ReadsDestination ¶
func ReadsDestination(p *PixelParams) bool
ReadsDestination reports whether the combine reads the pixel already in the frame buffer: shadow and half transparency, the odd color calculation modes.
func RecordStride ¶
RecordStride is the words per line record of op's kind.
func RecordedLineEnd ¶
func RecordedLineEnd(rec compute.LineRecords, op *DrawOp, line int32) int32
RecordedLineEnd is the exclusive end step of line line of op as the walk's record ended it, the end a renderer drawing the line applies to it (generate): a sprite row's recorded end column, through ScaledRowEnd at scale, where line is the scaled row, and a distorted sprite's recorded last step plus one. A line the walk has not ended is at or below zero, so the line draws nothing. A kind with no records (RecordStride zero) has no recorded end, -1.
func Resolve ¶
func Resolve(fb compute.VDP1FB, rs *compute.RoundState, i uint32)
Resolve applies the fragment list of 16-bit pixel i, the round's destination-reading dots on the pixel, in draw order, over the pixel as the write pass left it: the dots keyed above the pixel's replace winner, which is the last replace-class dot of the round on the pixel or none, each smallest key next, through the mode's color calculation against a register read once and stored once. A dot keyed below the winner was drawn over by it and is dead, and of dots sharing a key one is applied. Entry point: one thread per pixel.
The list is in arrival order, not draw order, so each applied fragment is found by a walk of the whole list: about F squared over two loads for F fragments on the pixel. That is the cheaper form up to about sixteen fragments on a pixel, which covers the measured workloads, one destination-reading op per frame. Above that a bottom-up merge sort of the list in place through the link words, about three memory operations per node per pass over log2(F) passes, then one apply pass, costs less, more than ten times less at a thousand. The cycle budget bounds a round's fragments, so the worst case is a slow frame, never a wrong pixel.
func RightEdgeAt ¶
RightEdgeAt is the dot of the B-C edge from (x1, y1) to (x2, y2) over steps steps at step i (NewRightDDAEdge).
func RowDotNibble ¶
RowDotNibble, RowDotByte, and RowDotWord read dot x of the character row at rowBase in the 4-bit color modes (0 and 1, the even dot in the high nibble), the 8-bit modes (2 to 4), and the 16-bit mode (5).
func RowStride ¶
RowStride is the bytes per character row for the color mode: 4 bits per dot in modes 0 and 1, a byte in modes 2 to 4, a word in mode 5.
func ScaledRowEnd ¶
func ScaledRowEnd(rec compute.LineRecords, op *DrawOp, row int32) int32
ScaledRowEnd is the end column, exclusive, of scaled sprite row row of op: the row's width when the native row did not end on its end codes. The native row's ending sample c is its unflipped midpoint sample at the recorded column, and the scaled row's unflipped sample is at or past c from the first column x with (2x + 1) * CharW >= 2 * width * c. A normal sprite's sample is the column itself, which the same forms give at a width of CharW.
func ScaledSrcX ¶
ScaledSrcX is the source column destination column x of a scaled sprite row reads: the source position at the destination dot's center (midpoint sampling), from the right when the command flips horizontally, and snapped to one parity under high speed shrink (FBCR EOS selects the odd columns).
func SegmentAt ¶
SegmentAt is the dot position and error term at dot i of the segment: with the major axis advanced i dots, the minor axis has advanced floor((2*minor*i + major) / (2*major)) dots, which is exactly what i Bresenham steps from the error term -major reach.
func SegmentSpan ¶
func SegmentSpan(fb compute.VDP1FB, rs *compute.RoundState, op *DrawOp, st *Segment, i1, budget int32, pixCycles int32) int32
SegmentSpan draws dots [st.I, i1) of the segment, where i1 is at most st.IMax+1, or to the first YieldChunk boundary at or past the cycle budget with the segment unfinished, with op's color and pixel write parameters, and returns the cycles charged, pixCycles per dot.
func SegmentTime ¶
SegmentTime charges dots [st.I, i1) of the segment without drawing them, as SegmentSpan would charge them, pixCycles per dot in the same YieldChunk pieces against the same budget.
func SimpleWrite ¶
func SimpleWrite(p *PixelParams) bool
SimpleWrite reports whether the pixel write is a plain 16-bit replace gated by the system clip alone: no color calculation, MSB set, mesh, user clip, double interlace, or 8-bit frame buffer, in the walk's store pass. A rasterizer may then store the pixel directly.
func SpriteGouraud ¶
SpriteGouraud is the Gouraud value of destination column x of row row of a sprite: the table's four corners interpolated along the top and bottom edges over the row's width, then between them over the rows.
func SpriteRowChecksECD ¶
SpriteRowChecksECD reports whether a sprite's rows check end codes: not when the command disables them, and not on a scaled sprite under high speed shrink, which disables end codes on the row it samples by parity (VDP1 manual Sec 6.3); the walk sets the flag only when the row shrinks.
func SpriteRowSpan ¶
func SpriteRowSpan(vram *compute.VDP1VRAM, fb compute.VDP1FB, rs *compute.RoundState, op *DrawOp, st *SpriteRow, row, x1, budget int32, pixCycles int32) int32
SpriteRowSpan draws columns [st.X, x1) of row of op, x1 clamped to the row's end, or to the first YieldChunk boundary at or past the cycle budget, and returns the cycles charged. Normal sprites read the character dot for dot: one cycle per end code or transparent dot, pixCycles per dot drawn. Scaled sprites midpoint-sample the character (each destination dot reads the source position at its center), advance the source read by the distance between samples, halved under high speed shrink, and charge the larger of that advance and pixCycles.
func SpriteRowTime ¶
func SpriteRowTime(vram *compute.VDP1VRAM, op *DrawOp, st *SpriteRow, row, x1, budget int32, pixCycles int32) int32
SpriteRowTime charges columns [st.X, x1) of row of op without drawing them, as SpriteRowSpan would charge them, in the same YieldChunk pieces against the same budget, and cuts the row where SpriteRowSpan would: a row whose cycles depend on its texels reads them through the same rules and reads nothing else, and any other row charges from its columns alone.
func SpriteRowWidth ¶
SpriteRowWidth is the destination columns of a row.
func SpriteRows ¶
SpriteRows is the rows of a normal or scaled sprite: the character height, or the destination rectangle's height.
func StoreLineEnd ¶
func StoreLineEnd(rec compute.LineRecords, base uint32, i, end int32)
StoreLineEnd stores where line i of the op at base ended.
func TexelDraws ¶
func TexelDraws(dot, colorMode, spd uint32, checkECD bool, ec *EndCodeCounter, column int32) bool
TexelDraws applies the texel rules to a dot read from source column column and reports whether the dot is drawn. An end code, when the line checks them, is not drawn and counts through the counter, whose Ended then says whether the line ends; a zero dot is transparent and not drawn unless SPD draws it (CMDPMOD SPD), spd being the command's OpFlagSPDOn bit, nonzero when it does.
Types ¶
type Buffers ¶
type Buffers struct {
VRAM *compute.VDP1VRAM
FB compute.VDP1FB
Round *compute.RoundState
Records compute.LineRecords
}
Buffers are the buffers an op draw reads and writes: the VDP1 VRAM its texels come from, the frame buffer it draws into, the round state of the device's passes, and the line records. The walk's store pass reads no round state, and passes none.
type DDAEdge ¶
DDAEdge is a walk from one point to another over an exact number of steps: the start position and the delta per step, at DDAFraction fraction bits. The polygon and distorted sprite setup places its side edges with it (EdgeAt, RightEdgeAt).
func NewDDAEdge ¶
NewDDAEdge starts at (x1, y1) and reaches (x2, y2) after steps steps, a position half way between two dots taking the dot toward the start point: the walk of the A-D edge.
func NewRightDDAEdge ¶
NewRightDDAEdge starts at (x1, y1) and reaches (x2, y2) after steps steps, a position half way between two dots taking the dot away from the start point: the walk of the B-C edge.
type DistortedTexture ¶
DistortedTexture is a distorted sprite's texture walk: V steps with the edges in fixed point, 16 fraction bits plus the op's scale shift, across the part's edge steps, and every connecting line walks U from UStart to UEnd. The flips reverse the ranges.
func NewDistortedTexture ¶
func NewDistortedTexture(op *DrawOp, steps int32) DistortedTexture
NewDistortedTexture is the texture walk of op over steps edge steps. Over N times the native steps at the scale shift of N the V step is the native step, so edge step N*i reads the native row of edge step i.
type DrawOp ¶
type DrawOp struct {
Kind uint32
Seq uint32 // the entry's index in the frame's list
LineFrom uint32 // the lines a device draws of the entry, [LineFrom, LineTo); LineTo 0 draws to the last
LineTo uint32
LineStart uint32 // the first step drawn of line LineFrom
LineEnd uint32 // the exclusive end step of the entry's last line; 0 draws the whole line
Addr uint32 // command table address
Buffer uint32 // physical frame buffer drawn into, 0 or 1
RecordBase uint32 // the op's first line record (records.go), when recorded
Pixel PixelParams
CharAddr uint32
CharW int32
CharH int32
ColorMode uint32 // CMDPMOD bits 5:3
Color uint32 // CMDCOLR
Flags uint32
X [4]int32
Y [4]int32
Gouraud [4]uint32 // the Gouraud table, read when the color calculation uses it
}
DrawOp is one drawing command as the command list walk resolved it: the command's kind, the frame buffer it draws into, the pixel write parameters in effect (clip state and frame buffer mode included), the character and color fields, and the vertices with the local coordinates applied. It is self-contained: a rasterizer needs no walk state to draw it.
In a frame's list an op appears as one or more entries, each the range of the op's steps the walk drew between two points where its list took an event: the lines [LineFrom, LineTo), the first from step LineStart and the last to step LineEnd. A device draws an entry's range and nothing else, so the list orders the op's parts against the events between them as the walk did.
An erase (OpErase) is the frame change's or the manual erase's fill of a frame buffer rectangle with EWDR, recorded in the list where the walk performed it so a renderer drawing the list replays it in order against the draws: X[0], Y[0] and X[2], Y[2] hold the inclusive rectangle, Color holds EWDR, and Pixel holds the frame buffer format (Is8bpp and FBWidth); the other fields are zero.
Vertices by kind: a normal sprite carries its draw position in A; a scaled sprite the resolved destination rectangle, upper-left in A and lower-right in C, with the flip flags already combined with the coordinate order; a distorted sprite, polygon, and polyline the four vertices A to D; a line its two endpoints in A and B. The values a rasterizer derives per command (the edge step count, the texture steps, the row stride) are not stored.
type DrawState ¶
type DrawState struct {
Cycles int32
Budget int32
PixCycles int32
Lines int32
Form uint32
Line int32
Begun bool
Done bool
Timing bool
Sprite SpriteRow
Quad QuadLine
Seg Segment
}
DrawState is an op's progress through Draw. The walk calls Draw in budgeted pieces along its schedule and resumes from this state. Cycles is what the last call charged. Budget bounds a call's cycles, 0 for no bound. PixCycles is the cycles per dot drawn, the color calculation mode's cost, which the walk charges and a device does not count. Line is the next line: a sprite's row, a four-vertex part's connecting line, a polyline's leg, a line's or a point-sided polygon's one segment, or an erase's row; Begun marks the line's state below as set up; Done marks the op drawn. Lines and Form are the op's line count and the loop it runs, derived from the op on the first call and kept, since the walk re-enters every few cycles. Timing marks a walk that charges the op's cycles without drawing it: the spans are the timing forms, which read texels only where the cycles depend on them and store the same line ends.
type EndCodeCounter ¶
EndCodeCounter is the end code rule's state across a line's dots: the end codes counted and, plus one, the source column of the last one counted (zero before the first). An end code dot (IsEndCode) is never drawn; the counter decides how it counts and when the line ends. A shape whose dots read distinct columns passes its step as the column, so every end code counts.
func (*EndCodeCounter) Ended ¶
func (c *EndCodeCounter) Ended() bool
Ended reports whether the end codes counted have ended the line.
func (*EndCodeCounter) Ends ¶
func (c *EndCodeCounter) Ends(column int32) bool
Ends records an end code read from source column column and reports whether the line ends: an end code counts once per source column, since a shrunk row reads a column more than once, and the second one counted ends the line.
func (*EndCodeCounter) Reset ¶
func (c *EndCodeCounter) Reset()
Reset starts the line with no end codes seen.
type FBWrites ¶
type FBWrites struct {
Store *compute.VDP1PageStore
Masks *compute.MaskStore
Table *compute.PageTable
}
FBWrites is a submission's staged pages of the bytes the CPU wrote into a frame buffer: the page store, the mask store with a bit per byte of each slot that the CPU wrote, and the page table.
type GouraudStepper ¶
type GouraudStepper struct {
R, G, B int32 // current values, 16 plus the scale shift fraction bits
DR, DG, DB int32 // delta per step
}
GouraudStepper interpolates a packed Gouraud value in fixed point with one addition per step: 16 fraction bits, plus the scale shift the stepper was made with.
func NewGouraudStepper ¶
func NewGouraudStepper(start, end uint32, n int32, shift uint32) GouraudStepper
NewGouraudStepper starts at start and reaches end after n-1 steps, its values carried at shift more fraction bits than 16 (the scale shift, 0 native). The per-step delta truncates, so the last step may land one level below end when n-1 does not divide the channel difference. Over N times a native stepper's steps at the shift of N the delta is the native delta, so step N*i holds the native value of step i.
func (*GouraudStepper) Advance ¶
func (s *GouraudStepper) Advance(n int32)
Advance applies n steps at once; the stepper is linear and clamping happens only in Value, so this equals n calls of Step.
func (*GouraudStepper) Value ¶
func (s *GouraudStepper) Value(shift uint32) uint32
Value returns the current packed value with each channel clamped, for a stepper made with the scale shift.
type PageCopyParams ¶
PageCopyParams locates a band of staged VDP1 VRAM pages: the slot of its first page in the page store and the page table. Slot s of the band holds the bytes of page table entry Base+s, and the copy writes them to that page of the memory. A frame buffer band also carries the scale its frame buffer is held at (ScaleShift, 0 native) and the native frame buffer's width in pixels and pixel size, which place a staged byte's pixel in the scaled buffer.
type PixelParams ¶
type PixelParams struct {
CC uint32 // CMDPMOD bits 2:0: 0 replace, 1 shadow, 2 half luminance, 3 half transparent, 4-7 with Gouraud
MSBOn uint32 // CMDPMOD MON, 1 to set the pixel MSB: a bit the pixel write shifts into place
Mesh uint32 // CMDPMOD MESH, 1 to draw only where x+y is even: a bit Admits masks with
UserClip uint32 // CMDPMOD bits 10:9: 2 draws inside the user clip only, 3 outside only
UCX1 int32 // user clip rectangle, exclusive bounds: mode 2 draws strictly inside, mode 3 strictly outside (the walk widens its rectangle by one)
UCY1 int32
UCX2 int32
UCY2 int32
ClipX int32 // system clip, inclusive, clamped to the frame buffer
ClipY int32
DIE uint32 // 1 for double interlace, y spanning both fields with DIL selecting the parity drawn: a bit Admits masks with
DILOdd uint32 // 1 for the odd parity under DIE: a bit Admits compares
Is8bpp bool
FBWidth int32
FBHeight int32 // rows of the frame buffer the op draws into
ScaleShift uint32 // log2 of the render scale N (N = 1 << ScaleShift), 0 at native: positions are in scaled dots, and the parities and the DIE row are taken on the native dot
Pass uint32 // PassStore, PassTag, or PassWrite
}
PixelParams is the per-command state of the pixel write: the color calculation mode and draw mode bits, the clip rectangles, the frame buffer geometry, and the pass. The caller resolves the frame buffer to draw into (under DIE=1 with DIL=1 the odd-field buffer) and, for 8-bit frame buffers and MSB-on, sets CC to 0 since those modes replace.
type QuadLine ¶
type QuadLine struct {
LX, LY, RX, RY int32 // endpoints on the left (A-D) and right (B-C) edges
Len int32 // steps along the line, the larger axis distance
J int32 // next step
JEnd int32 // last step to draw, after the pre-clip
Key uint32 // the line's draw order key (LineKey)
DPX, DPY int64 // position step, DDAFraction fraction bits, truncated toward zero
UStart, DU int32 // texture column at step 0, and the texture position's step at 16 plus the op's scale shift fraction bits
RowBase uint32
EC EndCodeCounter // end codes seen on the line, counted per step
SrcReadU int32 // last source column read, -1 before the first
HSSShrink bool // the line shrinks the texture horizontally under high speed shrink
CheckECD bool // end codes end the line
Simple bool // the pixel write is a plain 16-bit replace under the system clip
Gouraud GouraudStepper // at step 0
}
QuadLine is one connecting line of a four-vertex part (a distorted sprite or a polygon): its endpoints and length, the steps still to draw, and the per-step deltas. A dot's position, texture column, and Gouraud value follow from its step by closed form, so a span call derives its state from J. EC and SrcReadU carry the end code count and the source advance across span calls.
type Segment ¶
type Segment struct {
X1, Y1 int32 // start
DX, DY int32 // absolute deltas
SX, SY int32 // step directions
I int32 // next dot
IMax int32 // last dot
Key uint32 // the segment's draw order key (LineKey)
XMajor bool // the major axis is X
GStart uint32 // Gouraud values at the endpoints
GEnd uint32
}
Segment is a Bresenham segment (a line command, one leg of a polyline, or the A-B segment of a polygon whose side edges are points): its start, its absolute deltas and step directions, and the next dot. A dot's position and error term follow from its index by closed form (SegmentAt), so a span call derives its state from I. Both endpoints are inclusive.
type SpriteRow ¶
type SpriteRow struct {
X int32 // next destination column
End int32 // columns [X, End) remain; cut to the column of the end code that ended the row
Key uint32 // the row's draw order key (LineKey)
EC EndCodeCounter // end codes seen on the row, counted per source column
SrcReadX int32 // scaled: last source column read, -1 before the first
}
SpriteRow is one row of a normal or scaled sprite: the next destination column, the column the row ends at, the row's draw order key, and the end code and source tracking. A dot's source column follows from its destination column, so a span call derives its state from X.