compute

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: GPL-3.0 Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

The compute packages and their Go subset

The VDP pixel pipelines are written once, in a restricted Go subset, and run twice: the software renderer calls them as ordinary Go functions, and the GPU renderer's compile stage parses the same source, lowers it to an intermediate representation, and emits the compute shaders of the backend in use. This file is the contract between the authors of the compute functions, the software renderer, and the compile stage. The compile stage and its backends are documented in internal/hostgpu/README.md.

Anything not explicitly allowed here is rejected by the compile stage with a source-position error, and a Go test runs the same validation, so a violation fails every test run and not only a session with the GPU renderer enabled.

Compilation unit

  • The compute functions live in two chip subpackages, draw for the VDP1 and screen for the VDP2. The buffer types, the operations interface (Operations in operations.go: the operations a compute function cannot write as plain Go, each with a form per renderer), and the software renderer's forms of those operations (software.go) live in this parent package. The whole tree is subject to these rules.
  • The subpackages may import only the parent, by name (no dot import), so every call of a parent helper is qualified. The parent's function bodies are never lowered: each is the software form of an operation in Operations, and the compile stage calls the GPU renderer's backend for the operation by the function's name. The parent imports nothing but embed for its source; embed.go and operations.go are outside the embedded set.
  • Source files are ordinary .go files: go build compiles them into the binary and the software renderer executes them directly. Each package embeds its own subset source, which is what the compile stage parses. The embed directives name those files one by one, since a pattern would take the package's tests into the binary and hand them to the compile stage, which parses everything the embedded set holds. A test in this package holds each directive against its directory, so a new subset file cannot be left out of the set.
  • The renderer names the entry points it dispatches when it hands the package to the compile stage; every other function, exported or not, is a helper emitted as a device function. Exported helpers exist because the software renderer calls the per-dot and per-row functions directly from core.
  • The call graph must be acyclic: no recursion, direct or indirect (shading languages do not support it). The compile stage verifies this.
  • Package-level const declarations are allowed. Package-level var is allowed only for lookup tables: arrays of scalars initialized by a literal of constants, that no function writes (Go cannot declare an array const). A table is used only by indexing it (and len): never copied, passed, or returned whole. The compile stage verifies the elements are constants and the table is never assigned, and lowers it to constant memory. All other package-level var is rejected; mutable state is locals, parameters, or buffer contents.
  • No init functions, no generics, no build tags inside the packages.

Types

Scalar types:

  • bool
  • int8, int16, int32, uint8, uint16, uint32
  • int64, uint64 (the RBG rotation and VDP1 edge-stepping fixed-point math needs the width). A backend checks for 64-bit integers, and for whatever else its emitted form needs, at device selection, and a host without them uses the software renderer.
  • float32. The hardware pipelines are all-integer, since their output must match the console bit for bit; float32 exists for enhancement functions that render beyond the hardware's output.

Not allowed: int, uint, uintptr (implementation-sized), float64, complex, string, rune. An untyped or int constant (a range bound, an index, a shift count) lowers to 32 bits, so its value must fit int32 (uint32 for uint).

Composite types:

  • Fixed-size arrays of scalars or of allowed structs, at least one element long.
  • Structs whose fields are scalars, fixed-size arrays, or other allowed structs. No embedding. Field order is layout: the Go struct and the emitted struct match field for field, and the compile stage computes and enforces identical offsets on both sides, since a stride that differs between the two would corrupt every record silently.
  • Named types over allowed scalars are permitted.
  • Buffer-visible structs, the params struct and any struct read from a buffer, may contain only bools, 32-bit and 64-bit scalars (int32, uint32, int64, uint64, float32), and arrays and structs of them. A bool is the byte Go stores at the offset Go gives it; a backend whose storage has no bool reads the word holding the byte and tests it against zero, so the host copies the Go struct's bytes as they are. 8/16-bit storage would require optional device capabilities, so byte-granular data rides in byte buffers. Narrow types remain fully usable as locals.

Buffers:

  • Render function inputs and outputs are flat buffers typed as this package's buffer types, byte-addressed or 32-bit-word-addressed. A fixed-size buffer is a named array type, taken by pointer; the renderer converts its slices to the array pointers at the call boundary. A variable-length buffer is a named []uint32 or []byte, taken by value; core owns its allocation and growth. Every buffer's size is a power of two: a fixed buffer's by its constant, a variable buffer's checked where core allocates it and where a backend binds it.
  • Word buffers are indexed: w[i] reads a word and w[i] = v writes one, compound assignments and increments included, with an int32 or uint32 index. uint32(len(v)) is a variable-length buffer's length, words for a word buffer and bytes for a byte buffer (the length converts to int32 or uint32 where it is used); len of a fixed buffer is a constant. A valid index is below the buffer's size. An index past it is an authoring or host error: Go stops on it, and a backend masks the index with the size, so the access stays inside the buffer on a device.
  • Byte buffers are read and written through the accessors in software.go, U8, U16BE, U32BE, PutU8, PutU16BE, and PutU32BE, never indexed. An access has a width and the Saturn's byte order, big-endian, and every byte of it is masked to the buffer's size individually, so an access straddling the end wraps as the hardware address does. The accessors are in Operations because their device forms differ from open-coded bytes: a target without byte loads and stores reads a word and extracts the byte and writes by masking its bytes into the word, and a 16-bit write done as two byte writes could interleave with another thread's write to the same pixel. A buffer type carries only the accessors a compute function uses. A variable-length byte buffer's accessors are value-receiver methods that mask with the slice's length minus one.
  • Each fixed-size Saturn memory (VDP2 VRAM 512 KB, CRAM 4 KB, VDP1 VRAM 512 KB) gets its own named buffer type. A VDP1 frame buffer half (VDP1FB) is a variable-length byte buffer in the hardware layout, VDP1FBSize (256 KB) at the native resolution. The renderer's intermediate buffers are variable-length: a layer buffer of packed pixels (Layer) and the output frame buffer (Framebuffer) word buffers, a rotation screen's line color buffer (LineColor) a byte buffer. Core sizes them per renderer, each a power of two: a layer or line color buffer holds the rows the renderer has between their setup and their render, each the row's width, and the output frame buffer the frame. A span's params name its row of the layer and line color buffers (Y), and the composite's its output frame row (FBRow).
  • Buffers appear only as parameters and group fields, passed on unchanged. They cannot be held in locals or ordinary structs, sliced, built, grown, or reassigned.
  • A buffer group is a struct, declared in any compute package, whose fields all hold buffers: a variable-length buffer by value, a fixed-size buffer or another group by pointer, or an array of either kind of buffer. A struct with a buffer field is a group, and every field must then be one of these. A compute function takes a group by pointer, and a path to one of its buffers (g.P.Out, in.LineColors[0]) is that buffer wherever a buffer may appear: indexed, the receiver of an accessor, the operand of len, or an argument; a path to a nested group is that group as an argument. An array of buffers is indexed by a constant, except that a word of it may be read by a variable index as the whole value of an assignment (px := in.Layers[p.LayerBuf[i]][pi]), which the compile stage lowers to a switch over the array's buffers. The compile stage binds every buffer a group holds as its own buffer, depth first in field order, so the IR and the backends see ordinary buffers and the host binds them in that order. The round state of the VDP1 draw, draw's Buffers, the page staging sets, and the composite's inputs are groups.
  • No workgroup-shared memory is exposed; ordering between dispatches is the host's job (encoder barriers), and ordering within a dispatch is by construction (a thread owns what it writes) or, in a group entry, by the one group primitive: NextPhase(), the point where the group's next phase begins, after which every buffer store the group's threads made before it is visible to every thread. It is called only as a statement directly in the body of a group entry, outside any if, switch, or loop (validated), so every thread of the group reaches it.
  • Three shared-word operations are exposed through Operations on variable-length word buffers, each masking its index with the region's length, each on the round state region whose role needs it. Raise, on the order stamps, raises a word to a value and returns nothing: the threads raising one word leave it at the greatest of their values in whatever order the backend runs them, so a compute function uses it to decide which of several dots on a pixel came last, by a key that carries the order. Add, on the fragment pool, adds to a word and returns the word's prior value: the threads adding to one word each take a distinct prior and leave the word at their sum, so a compute function uses it to reserve a range of a stream, never to order its threads. Swap, on the fragment list heads, stores a value into a word and returns the prior: the threads swapping into one word each take what the one before it stored, so a compute function links itself at the head of a list. A region type carries only the operation its role needs, so the wrong operation on a region is a compile error. A prior value is used for addressing or stored as a link and is not fed to another Add, since a device compiler may coalesce the adds of a group of lanes into one, and the conformance rules test the addressing and linking forms alone. A further primitive is added in the form a compute function needs when one does.
  • Operations (operations.go, outside the embedded set) is the list of operations a renderer implements for the compute functions: the byte buffer accessors, the word buffer index and store, the length of a variable-length buffer, min and max, the three shared-word operations, and NextPhase, the operations a compute function cannot write as plain Go. Their software forms are the functions of software.go, which the software renderer runs, one thread per dispatch, and which are the single-thread reference the conformance rules hold every backend to. The compile stage never compiles them: it calls the GPU renderer's backend, which implements Operations over its own operands, for each operation it meets, an atomic for the shared-word operations and a group barrier for NextPhase. A test of this package holds every function of the embedded source to an operation in Operations: its name, a buffer receiver exactly when the operation acts on a buffer, and its operand count. The compile stage holds each call of an operation to the operand count and result the interface gives it, and a backend missing an operation does not build.

Pointers:

  • Allowed only as method receivers and function parameters referring to a local struct or scalar (lowered to references in the thread's own storage). This covers the stepper pattern (a helper mutating its receiver per pixel).
  • Address-of appears only as a call argument, and its operand is a struct or scalar held in a local or a parameter, or a field or element path into one (&cands[i], &p.Window). The receiver of a pointer-receiver call, whose address the call takes, follows the same rule, so a table element is never a receiver. A pointer parameter's target is a value of the thread's own or the thread's params row, which is never written, so such a reference never reaches storage another thread writes.
  • No pointer arithmetic, no storing pointers in structs, arrays, or locals (a local aliasing part of the params struct is the excluded case: a target may have no pointers; select by index instead), no reassigning a pointer parameter, no nil, no address-of buffer contents, no returning pointers.
  • A call may pass two references into the same storage only to a callee that writes through neither. A reference may be a copy on a device: a target may implement a reference parameter by copying the value in at the call and back at the return, so two overlapping references are two private copies there and one object in Go, and the difference shows when the callee writes one and reads the other. The compile stage holds the rule: references overlap when one's path from the root variable is a prefix of the other's, with an index that is not a constant matching any element, and a callee writes through a parameter when it or a callee it passes the pointer, or a path into it, to assigns through it. Reading both is allowed (ranksAbove(&cands[i], &cands[j])), and so are distinct constant indices and distinct fields.
  • A statement may not read, outside a call, storage that the call writes: a path overlapping a reference argument the callee writes through (i + bump(&i), a[i] += bump(&i)), or a word of a buffer the call takes (w[i] + put(w, i)). Go leaves the order of a call and a plain read unspecified, and the software renderer, built by gc, runs the call first while a device may read first. A plain assignment target is not a read, and neither is an operand of the call itself. Overlap is by path, as for references.

Slices, maps, channels, interfaces, function values: not allowed.

Declarations and statements

Allowed:

  • const, var with explicit or inferred (fixed-width) type, short variable declarations, multiple assignment.
  • Assignment, compound assignment (+=, |=, ...), increment, decrement.
  • if / else.
  • switch on an integer or bool tag with constant cases and default. No tagless switch, no fallthrough, no type switches.
  • for in all three header forms (init; cond; post), condition-only, and infinite-with-break, and range over an integer (for i := range n, for range n), whose key takes n's type, so n is a fixed-width integer wherever the key is used. break and continue, unlabeled only, and break always leaves the innermost loop: a break directly inside a switch case is rejected, since in Go it would leave the switch. No range over arrays or anything but an integer, no labels, no goto.
  • return, including multiple return values and named results with bare return. Multiple results are lowered to out parameters per backend.
  • Calls to functions within the compute package tree and the software forms of the renderer operations. Method sets use value or pointer receivers; methods lower to functions with an explicit receiver argument.
  • Struct and array literals (keyed or positional), local composite variables, copying structs and arrays by value.

Not allowed: defer, go, select, closures and anonymous functions, variadic functions, panic/recover, type assertions, new, make, append, copy, builtins other than min and max on int32, int64, and uint32 operands (any number of them, lowered to each backend's native form), len/cap on fixed-size arrays (where they are compile-time constants), and len of a variable-length buffer converted to int32 or uint32.

Semantics (defined by the IR, honored by every emitter)

These are Go's semantics. Where a target language differs, the emitter compensates; the conformance functions verify each rule per backend per operation.

  • Integer arithmetic wraps modulo 2^width at the operand's declared width. Emitters computing in 32-bit registers mask or sign-extend at assignments, conversions, comparisons, and narrowing points so observable values always match the declared width.
  • Signed right shift is arithmetic, unsigned is logical.
  • Shift counts must be less than the operand width. This is an authoring rule, checked where the count is constant; for variable counts the software path is the arbiter (Go defines the result, GPU targets mask the count to the width, so a variable count that can reach the width is an authoring bug).
  • Integer division and remainder truncate toward zero, as Go's do, and every emitter produces that result. Division by zero is an authoring bug: the software path panics, GPU behavior is undefined. Divisors must be guarded or provably nonzero. A 32-bit or 64-bit signed minimum divided by minus one is the backend's native behavior, which the targets leave undefined, and is not guaranteed to match Go, which wraps the quotient to the minimum and the remainder to zero. Narrow widths are not affected: they divide in a 32-bit register and the Mask re-canonicalizes the result.
  • Conversions are explicit only. Narrowing truncates, widening zero-extends (unsigned) or sign-extends (signed), exactly as in Go. No implicit conversions anywhere, including untyped constants, which must fit the target type.
  • Evaluation order is Go's left-to-right. Emitters introduce temporaries where the target's order is unspecified.
  • bool is not an integer; no arithmetic on bool, no implicit tests.
  • float32 is IEEE 754 binary32 with no fast-math relaxations; emitters set the precise-math options on their pipelines.

Entry points and execution

  • An entry point's parameter list is, in order: buffers and buffer groups, then at most one params struct passed by pointer and never written through (the captured register state and per-dispatch constants), optionally one row-state struct passed by pointer that the function may update (explicit state carried across the software schedule's span calls on a row, such as a pattern name cache or a rasterizer's position; it starts fresh per row and per GPU thread), then scalar thread coordinates: two for a span (x0, x1), one for an index, or three for a group entry (the thread's index in its group, the group's size, and the group's index, whose params row is the group's). The params pointer exists for the software schedule: it calls a span for every few dots, and a by-value struct of a few hundred bytes copied per call is a frame-time cost. The GPU wrapper passes the thread's row of the params buffer. The order of the two structs is the whole of what tells them apart, so the compile stage holds it by the one difference the source shows: the params row is never written through, directly or by a function it or a path into it is passed to. Writing it would reach the caller's struct in software and the thread's params row on a device, and an entry written with the two the other way round would run in software and read a zeroed params row on a device.
  • Thread identity arrives through those trailing coordinate parameters. On the GPU the generated shader wrapper maps the global invocation id onto them; in software the renderer or a test calls the entry point in an ordinary loop. There are no thread-id intrinsics, which is what keeps the compute functions directly callable and testable.
  • On the software schedule, entry points are called per row or per span, never per pixel: the x loop lives inside the compute function, and its prologue loads params fields into locals once per row. A group entry's software execution is one thread per group, thread 0 of 1, which runs the group's phases in order. A group entry is written so its result is the same for any group size, and the number of threads a group gets is the backend's, sized from the group's work. The barrier (NextPhase) orders one workgroup, so an entry that uses it is dispatched one workgroup across.
  • A span entry's segment is the unit one thread takes whole, set by the renderer for the entry (a cell, a whole row, or one dot), and the dots a thread takes past the unit are the backend's. A span entry is written so its result is the same for any segment.
  • The grid's shape is the renderer's and the workgroup size the backend's; compute functions are written against coordinates, not group layout.
  • A compute function must bound every loop by values derived from its parameters and must clamp counts read from buffer contents before looping on them, since a count taken from garbage would otherwise loop for billions of iterations. The compile stage cannot prove boundedness; this is an authoring rule enforced in review, with min as the clamp.
  • A byte buffer accessor masks its address to the buffer's size in both implementations, matching the address masking of the hardware memory. A word buffer index past the buffer is an error: Go stops on it, and a backend masks it so the access stays inside the buffer.

Scale

The compute functions render at a scale N = 1 << ScaleShift on both axes, chosen by the renderer that calls them: ScaleShift 0 is the native resolution, and 1 to 4 are the enhanced renderers' 2x, 4x, 8x, and 16x. The same functions run at every scale; the scale is a parameter, and at its native value every function computes exactly what it computed before the parameter existed. The native output is held to the console bit for bit, so a change to a compute function must keep the native path's arithmetic unchanged at ScaleShift 0.

  • The parameters that carry the scale: draw.PixelParams.ScaleShift, with FBWidth and FBHeight the scaled frame buffer's; screen.ScreenParams.ScaleShift, which the NBG and RBG params hold; screen.NBGParams.SubRow, the sub-row of the native row (0 native); screen.GradationParams.Step, the blur's dot distance (1 native, N at scale); screen.CompositeParams.FieldBootstrap, the other field's row xor mask (0 off, 1 native, N at scale); and draw.PageCopyParams' ScaleShift, FBWidth, and Is8bpp, which place a CPU-written byte's N by N block in the scaled frame buffer.
  • A scaled position is the native fixed-point value carried at ScaleShift more fraction bits, never a divided step: the NBG source positions at 8 + ScaleShift bits, the rotation screen's row start, center, and coefficient address (Xsp, Ysp, Xp, Yp, LineKAst, and a coefficient's replacement of Xp) at 10 + ScaleShift, the rotated sprite read's column 0 coordinate (SpriteRow.BaseX and BaseY) at 10 + ScaleShift with its per-column step native, and the VDP1 texture coordinates and Gouraud steppers at 16 + ScaleShift. The per-dot steps stay native, since the thread coordinate is the scaled column. A value produced at one width and read at another moves a block corner, so the width a params field is carried at is part of its definition.
  • Geometry refines to the sub-dot and content keeps its native granularity: texel selection, the mesh and interlace parities, the double-interlace row, mosaic, and the per-line tables are taken on the native dot, the coordinate shifted right by ScaleShift.
  • The coordinates admitted at scale reach draw.nativeCoordLimit shifted left by ScaleShift, so a product of a coordinate delta and a step count is taken in int64, as the walk's position functions take it.
  • In the draw package a normal sprite is drawn as the scaled sprite over its blocks: each sub-column samples the native column whose block holds it, while its Gouraud is interpolated over the scaled width, so a block's dots share a texel and not a shade; a scaled sprite and a distorted sprite resample their character at the scaled destination; a connecting line, a line, and a polyline leg are the native walk on the scaled vertices, each dot claiming the N by N square on its + sides, a later dot of the line replacing an earlier one's claim, and the next line's dots replacing this line's when the two share a major axis (square.go). A line ends where the native walk's record ended it, never on a fresh end code count, since the finer sampling reads columns the native line skipped: a sprite row at ScaledRowEnd, a connecting line at the native step whose block holds the record. A distorted sprite's line at scale also reads the record of the line after it, so an entry is drawn once that record is final.
  • A compute function sees one row of the scaled width. The derivation of a native row's N sub-rows (the sub-row's source positions, rotation parameters, and output row) is the renderer's, in core.

Verification

  • The software execution of the compute packages is the reference semantics. The Go test suite tests the compute functions directly.
  • Conformance functions, one per operation class per rule above, are emitted and run on every backend and compared against the software results bit-exactly. They contain no VDP logic and lock down the emitters independently of renderer changes. They live in the conformance subpackage under the same subset rules. Each backend's tests run them on that platform's hardware device and skip where there is none.
  • The renderer's device tests in core drive the GPU renderer through its scenes on the platform's device and hold every frame bit-identical to the software renderer at native resolution, and the enhanced GPU renderer to the enhanced software renderer at every scale. The enhanced renderers at scale 1 equal the accurate ones byte for byte.

Documentation

Index

Constants

View Source
const (
	VDP2VRAMSize = 512 * 1024 // VDP2 VRAM, bytes
	CRAMSize     = 4 * 1024   // VDP2 color RAM, bytes
	VDP1VRAMSize = 512 * 1024 // VDP1 VRAM, bytes
	VDP1FBSize   = 256 * 1024 // one VDP1 frame buffer, bytes

	// PaletteWords holds one decoded entry per CRAM color (2048 in
	// CRAM mode 1, 1024 otherwise).
	PaletteWords = 2048

	// PageBytes is the unit VDP2 VRAM and CRAM are delivered to a
	// device in: a renderer stages whole pages of the live memory in
	// a page store with the destination page number of each in a
	// page table, and a copy entry writes them into the device
	// memory. PageWords is the words in a page, the copy entry's
	// threads per page.
	PageBytes = 1024
	PageWords = PageBytes / 4
	// PageStoreBytes holds the VDP2 VRAM pages staged for one
	// submission, CRAMPageStoreBytes the CRAM pages, and
	// PageTableWords the page numbers of either store.
	PageStoreBytes     = 4096 * PageBytes
	CRAMPageStoreBytes = 1024 * PageBytes
	PageTableWords     = 4096
	// VDP1PageStoreBytes holds the VDP1 VRAM pages staged for one
	// submission, eight times the VRAM, so a take that must still fit
	// the whole VRAM rarely forces a submission.
	VDP1PageStoreBytes = 8 * VDP1VRAMSize
)

Buffer sizes. The renderers size their intermediate buffers (the layer, line color, and output frame buffers) themselves, each a power of two so masked access applies to them as well.

View Source
const MaskStoreWords = VDP1PageStoreBytes / 32

MaskStoreWords is the words of a MaskStore: one bit per byte of every slot of a VDP1PageStore.

Variables

View Source
var Source embed.FS

Source is this package's Go source, which the GPU renderer's compile stage type-checks the compute packages against. The compile stage lowers none of it: every function in software.go is the software form of an operation in Operations, which a backend gives its own form by name.

The files are named one by one: the compile stage takes everything Source holds, so this file, operations.go, and the package's tests must stay out of it. TestEmbeddedSource holds the list against the directory.

Functions

func NextPhase

func NextPhase()

NextPhase marks the point where a group's next phase begins: every buffer store a thread of the group made before it is visible to every thread of the group after it. A group entry calls it between the phases whose stores the next phase reads, in uniform control flow, so every thread reaches it. The software renderer runs a group as one thread that executes the phases in order, so nothing happens here; a GPU backend substitutes the device's group barrier.

Types

type CRAM

type CRAM [CRAMSize]byte

CRAM is the VDP2 color RAM.

func (*CRAM) PutU32BE

func (b *CRAM) PutU32BE(a uint32, v uint32)

func (*CRAM) U16BE

func (b *CRAM) U16BE(a uint32) uint16

type CRAMPageStore

type CRAMPageStore [CRAMPageStoreBytes]byte

func (*CRAMPageStore) U32BE

func (b *CRAMPageStore) U32BE(a uint32) uint32

type FragmentHeads

type FragmentHeads []uint32

FragmentHeads holds, per 16-bit pixel, the slot of the pixel's last appended fragment in the round, zero when none has. Its length is the frame buffer's 16-bit pixels.

func (FragmentHeads) Swap

func (w FragmentHeads) Swap(i uint32, v uint32) uint32

Swap stores v into word i and returns the word's prior value. The threads of a dispatch swapping into one word each take the value the one before it stored, so a compute function links itself at the head of a list with it. The software renderer runs a dispatch as one thread, so this body is the whole operation there; a GPU backend substitutes the device's atomic exchange.

type FragmentPool

type FragmentPool []uint32

FragmentPool holds the round's fragments, the destination-reading dots deferred to the resolve: word 0 is the reservation counter and the fragments follow, laid out by the draw package, so slot 0 is never a fragment and a zero link ends a list.

func (FragmentPool) Add

func (w FragmentPool) Add(i uint32, v uint32) uint32

Add adds v to word i and returns the word's prior value. The threads of a dispatch adding to one word each take a distinct prior and leave the word at their sum, in whatever order the backend runs them, so a compute function reserves a range of a stream with it. The prior is used for addressing and never fed to another Add. The software renderer runs a dispatch as one thread, so this body is the whole operation there; a GPU backend substitutes the device's atomic add.

type Framebuffer

type Framebuffer []uint32

Framebuffer is the output frame buffer, one word per pixel of the frame: the decoded color (bits 23:16 blue, 15:8 green, 7:0 red) with bits 31:24 set, so a pixel's bytes in little-endian host memory are R, G, B, and an opaque alpha.

type Layer

type Layer []uint32

Layer is one layer buffer of packed pixels, the rows the host has in flight, each the row's width long.

type LineColor

type LineColor []byte

LineColor holds a rotation screen's per-dot coefficient line color data for the rows the host has in flight: one byte per dot, bit 7 set when the dot's coefficient supplied one, bits 6:0 the data.

func (LineColor) PutU8

func (b LineColor) PutU8(a uint32, v uint8)

func (LineColor) U8

func (b LineColor) U8(a uint32) uint8

type LineRecords

type LineRecords []uint32

LineRecords holds host-generated VDP1 line records. The host owns its capacity; compute functions receive a view and cannot resize it.

The length of every variable-length buffer is a power of two, checked where the host allocates it and where a backend binds it. An index past the length is a host error: Go stops on it, and a backend masks the index with the length, so the access stays inside the buffer.

type MaskStore

type MaskStore [MaskStoreWords]uint32

MaskStore holds, per staged page of CPU frame buffer writes, the bits of the bytes the CPU wrote.

type Operations

type Operations[B, V any] interface {
	U8(buf B, addr V) V
	U16BE(buf B, addr V) V
	U32BE(buf B, addr V) V
	PutU8(buf B, addr, v V)
	PutU16BE(buf B, addr, v V)
	PutU32BE(buf B, addr, v V)
	Load(buf B, i V) V
	Store(buf B, i, v V)
	Length(buf B) V
	Raise(buf B, i, v V)
	Add(buf B, i, v V) V
	Swap(buf B, i, v V) V
	MinI32(x, y V) V
	MaxI32(x, y V) V
	MinI64(x, y V) V
	MaxI64(x, y V) V
	MinU32(x, y V) V
	MaxU32(x, y V) V
	NextPhase()
}

Operations is the list of operations a renderer implements for the compute functions to run on it: the operations a compute function cannot write as plain Go, each with a form per renderer. The software renderer's forms are the Go bodies in software.go, which it runs directly. The GPU renderer's forms are the device forms its backend emits into the compute shaders: the compile stage calls the backend's method for each operation it meets, so a backend that lacks one does not build.

B is what the renderer refers to a buffer by and V what it refers to a value by, since a buffer is never a value in the compute subset: source text for a backend emitting source, an instruction id for one emitting instructions. An operation with no result (the writes, Raise, and NextPhase) is a statement, which a backend emits where it stands. The compile stage reads the operations from this interface: which take a buffer, how many operands each takes, and which have a result.

The byte accessors read and write a byte buffer at an address masked to the buffer's size, multi-byte accesses big-endian, every byte masked individually. Load and Store are a word buffer's index and indexed store, the index masked to the buffer's size. Length is the length of a variable-length buffer in its own units, bytes or words. The Min and Max operations are the Go builtins on two operands of the named type. Raise, Add, and Swap are the shared-word operations on a word buffer across the threads of a dispatch: the atomic maximum with no result, the atomic add returning the prior word, and the atomic exchange returning the prior word. NextPhase is a group's phase boundary, after which every buffer store the group's threads made before it is visible to every thread of the group.

This file is outside the embedded set: the interface is the renderers' contract, not compute source.

type OrderStamps

type OrderStamps []uint32

OrderStamps holds, per frame buffer byte, the draw order key of the last replace-class dot that landed on the pixel in the round, zero when none has. Its length is the frame buffer's bytes.

func (OrderStamps) Raise

func (w OrderStamps) Raise(i uint32, v uint32)

Raise raises word i to v when v is greater. The threads of a dispatch raising one word leave it at the greatest of their values in whatever order the backend runs them, and no thread learns the order, since nothing is returned. A compute function decides which of several dots on a pixel came last with it, by a key that carries the order. The software renderer runs a dispatch as one thread, so this body is the whole operation there; a GPU backend substitutes the device's atomic maximum.

type PageStore

type PageStore [PageStoreBytes]byte

PageStore holds staged VDP2 VRAM pages, CRAMPageStore staged CRAM pages, each a whole page per slot in memory order.

func (*PageStore) U32BE

func (b *PageStore) U32BE(a uint32) uint32

type PageTable

type PageTable [PageTableWords]uint32

PageTable holds the destination page number of each staged slot.

type Palette

type Palette [PaletteWords]uint32

Palette is the CRAM decoded per entry to a packed color: bit 31 the entry's color calculation bit, bits 23:0 the decoded color (bits 23:16 blue, 15:8 green, 7:0 red).

type RoundState

type RoundState struct {
	Stamps OrderStamps
	Heads  FragmentHeads
	Pool   FragmentPool
}

RoundState is the round's three buffers as one parameter, a buffer group: the compile stage binds each field as its own buffer, in field order, and a compute function addresses a region through the field.

type VDP1FB

type VDP1FB []byte

VDP1FB is one VDP1 frame buffer in the hardware layout, VDP1FBSize long at the native resolution: 16-bit big-endian pixels, or 8-bit pixels in the 8-bit modes.

func (VDP1FB) PutU8

func (b VDP1FB) PutU8(a uint32, v uint8)

func (VDP1FB) PutU16BE

func (b VDP1FB) PutU16BE(a uint32, v uint16)

func (VDP1FB) U8

func (b VDP1FB) U8(a uint32) uint8

func (VDP1FB) U16BE

func (b VDP1FB) U16BE(a uint32) uint16

type VDP1PageStore

type VDP1PageStore [VDP1PageStoreBytes]byte

VDP1PageStore holds staged VDP1 VRAM pages, or staged pages of the bytes the CPU wrote into a VDP1 frame buffer.

func (*VDP1PageStore) U8

func (b *VDP1PageStore) U8(a uint32) uint8

func (*VDP1PageStore) U32BE

func (b *VDP1PageStore) U32BE(a uint32) uint32

type VDP1VRAM

type VDP1VRAM [VDP1VRAMSize]byte

VDP1VRAM is the VDP1 VRAM.

func (*VDP1VRAM) PutU32BE

func (b *VDP1VRAM) PutU32BE(a uint32, v uint32)

func (*VDP1VRAM) U8

func (b *VDP1VRAM) U8(a uint32) uint8

func (*VDP1VRAM) U16BE

func (b *VDP1VRAM) U16BE(a uint32) uint16

type VDP2VRAM

type VDP2VRAM [VDP2VRAMSize]byte

VDP2VRAM is the VDP2 VRAM.

func (*VDP2VRAM) PutU8

func (b *VDP2VRAM) PutU8(a uint32, v uint8)

func (*VDP2VRAM) PutU16BE

func (b *VDP2VRAM) PutU16BE(a uint32, v uint16)

func (*VDP2VRAM) PutU32BE

func (b *VDP2VRAM) PutU32BE(a uint32, v uint32)

func (*VDP2VRAM) U8

func (b *VDP2VRAM) U8(a uint32) uint8

func (*VDP2VRAM) U16BE

func (b *VDP2VRAM) U16BE(a uint32) uint16

func (*VDP2VRAM) U32BE

func (b *VDP2VRAM) U32BE(a uint32) uint32

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL