library gpu
Modules
commandsCommands recorded for the device to run when submitted: every backend runs the same list, the CPU device directly, Vulkan from a command buffer it records, WebGPU through the browser's encoder.
cpu::deviceThe CPU device: buffers and textures in memory, shaders run by the SPIR-V interpreter, triangles rasterized by raster.alloy. It follows WebGPU's rules (pixel centers at halves, the top-left fill rule, depth from 0 to 1, y up in clip space), so its images are the reference the GPU backends are compared with.
cpu::interpreterRuns the SPIR-V the shader compiler writes, one invocation at a time, for the CPU device. The module is decoded once: every instruction into an Op, every result id given fixed cells (32-bit words) in a register file, every variable fixed cells in memory, composites flattened, since shaders do not recurse. A pointer is three cells: its space (memory, a buffer, a texture or sampler handle), the buffer or handle's index, and the offset, in cells in memory and in bytes in buffers, where values are laid out by their decorations. The ops are then compiled into steps naming registers, types' sizes and branches' targets found, which a run goes through reading nothing else.
cpu::rasterTriangles into pixels for the CPU device, by WebGPU's rules: clipped against the near plane, mapped to the target with y down, covered where a pixel's center is inside by the top-left rule (edges in fixed point, 8 bits under the pixel), outputs interpolated with perspective (integers flat, from the first vertex), the fragment stage run per pixel and its color blended into the target.
cpu::resourcesWhat the CPU device holds: buffers as bytes, textures as RGBA8 pixels (red in the low byte), samplers as their settings. Shaders reach them through the bindings a draw or dispatch sets.
gpuThe GPU, the same way on every platform (PLAN.md, stage F2): an API in WebGPU's shape over Vulkan, Metal on macOS (F7b), WebGPU in the browser, and a CPU rasterizer that runs the same shaders, for tests and where no GPU is.
metal::metalThe Metal device (PLAN.md, F7b), on macOS: Metal's objects through Objective-C messages (pkg::alloy::objc). Shaders are the MSL
#shaderwrote (shader/msl.alloy), compiled when made; each stage binds its resources at the Metal indicesmetal_indexgives, and its vertex buffers after them. Buffers and textures live in the GPU's private memory: writes wait until the next submission copies them in from a shared staging buffer with a blit, and reads copy out into a shared buffer the device waits on. Metal tracks what each command buffer uses, so objects are released at once. A window's surface is a CAMetalLayer as its view's layer, each frame one of its drawables. Clip space keeps y up, as WebGPU's.shader::blobA compiled shader as the program carries it: bytes
#shadermakes while compiling, read back when the program creates the shader. Words of 4 bytes, little-endian:shader::compilerThe shader compiler: checks a WGSL module's syntax tree and writes it as a SPIR-V 1.3 module for Vulkan 1.1, which the CPU rasterizer runs too. Every entry point (
@vertex,@fragment,@compute) becomes a SPIR-V entry function that reads the stage's inputs from Input variables, calls the WGSL function, and writes its result to Output variables. Locals declared withvarare Function variables,letvalues are SSA ids. The first error stops it.shader::mslMetal's shading language from the shader compiler's SPIR-V (PLAN.md, F7b): the module the compiler wrote from the checked WGSL, its types, layouts and control flow already settled, read back and written as MSL source, which the Metal device compiles while the program runs. Only what the compiler emits is read: structured selections and loops, no phi.
shader::spirvSPIR-V's numbers, the ones the shader compiler emits and the CPU device's interpreter and the MSL writer read, and the instruction words: an instruction is its word count in the top half of its first word, its opcode in the bottom half, then its operands.
shader::syntaxWGSL's syntax, as far as the package's shaders use it: tokens, and a tree of nodes kept in arrays and named by index, which the checker walks. Parsing stops at the first error, reported with its line and column.
shader::typesThe shader compiler's types: interned, each with its SPIR-V id once declared, and laid out in memory by WGSL's rules for the buffers that hold them.
slotsThe indices a device's objects take in its tables: a released one first, so a table stays as long as the most objects alive at once.
vulkan::vkThe part of Vulkan the GPU package uses, written by hand from the Khronos headers (vulkan_core.h, Apache-2.0 or MIT): the structures it fills, in C's layout, the numbers it passes, and the functions, loaded through vkGetInstanceProcAddr and vkGetDeviceProcAddr. Dispatchable handles (instance, physical device, device, queue, command buffer) are pointers; the others are 64-bit numbers.
vulkan::vulkanThe Vulkan device: Vulkan 1.1 with dynamic rendering and synchronization2, core in 1.3. Buffers and textures live in the GPU's memory; writes wait in a staging buffer until the next submission copies them in, and reads copy out through a buffer the host reads after waiting. Textures rest between commands in the layout their usage asks for, and every pass, copy and dispatch ends with a full barrier: simple rules, enough until measurements ask for more. Clip space keeps y up, as WebGPU's, through a viewport of negative height.
webgpu::webgpuThe WebGPU device, in a browser: the JavaScript beside this file (webgpu.web.js) opens the browser's device before the program starts and keeps the objects, the program holding their indices. Shaders are the WGSL
#shaderchecked, which the browser compiles. Reads back (read_texture,read_buffer) are not there: WebGPU only completes them later, in the browser's event loop.
Dependencies
pkg::alloy::comCOM on Windows, the package
pkg::alloy::com(PLAN.md, F6b; a package of its own since F10, whichwindowandtextshare): interface ids, calls through another object's table of functions, and the strings, arrays and variants UI Automation, the file dialogs, drops and DirectWrite pass, with UTF-16 text both ways. The tables' slots each user reads are checked against MinGW's headers bytests/windows/com_layout.sh.pkg::alloy::dbusA D-Bus client (PLAN.md, F6c): a connection to a bus over a Unix socket, authenticated as the process's user (SASL EXTERNAL), which sends method calls, replies, errors and signals and receives them, for the accessibility bus and the desktop portal and any program using the session or system bus. Calls can wait for their reply; everything else arrives through
receive, which never blocks, the connection's socket polled beside a program's own (fd).pkg::alloy::dbus::wireD-Bus's wire format, little-endian: values written and read by their signatures, each aligned to its size from the message's start, and the messages around them (a header of fixed fields and a field array, then the body).
pkg::alloy::objcObjective-C from Alloy (PLAN.md, F7), the package
pkg::alloy::objc: the runtime's C functions, loaded while running, for AppKit and Metal on Apple systems. Every message isobjc_msgSendread as the method's exact C prototype (F0 question 4), so arguments pass as the method declares them:pkg::alloy::windowWindows, their events and input on every platform (PLAN.md, stage F1): Wayland on Linux, Win32 on Windows, AppKit on macOS (F7), a canvas in the browser, and a headless window for tests. A program gives
runits state and a handler, which the platform's event loop calls with each event until the program closes the window.pkg::alloy::window::appkitThe window on macOS, through AppKit (PLAN.md, F7): the frameworks open while running and every call is an Objective-C message (objc.alloy). AppKit's own loop runs (
[NSApp run], F7 question 2A) and calls the program back through classes made here: AlloyView, the window's content, takes the mouse, the keyboard, input methods (as an NSTextInputClient), the Edit menu's commands, drops and the cursor, and answers VoiceOver (nsaccessibility.alloy); AlloyWindowDelegate the window's closing, resizing, scale and focus; AlloyApplicationDelegate the application's quitting. Each method is a block reaching this module's state through a cell in C's heap, so the classes, made once a process, serve every window run after. Redraws are paced by a CVDisplayLink, whose thread signals a run loop source on the main thread, as a Waker does; frames from the CPU go into the view's layer as a CGImage. The clipboard is the general NSPasteboard and file dialogs are NSOpenPanel and NSSavePanel, run modal. macOS 11 or later.pkg::alloy::window::atspiAT-SPI for the Wayland window (PLAN.md, F6c): when the session's accessibility is on (org.a11y.Status), the window joins the accessibility bus, embeds its application object in the registry's desktop and answers screen readers such as Orca from the tree the program sends: org.a11y.atspi.Accessible, Component, Action, Value, Text and EditableText, Table and TableCell, and the properties, on an object a node under /org/a11y/atspi/accessible/. Changes to the tree go out as the Event.Object signals Orca follows; what a screen reader asks comes back to the program as Event::Action.
pkg::alloy::window::browserThe window in a browser: a canvas, and the page's events, through the JavaScript beside this file (browser.web.js), which calls the program back for each one.
runreturns at once, leaving the program running in the browser's event loop. A canvas with the idalloyis used when the page has one, sized by its style; otherwise one is added to the page at the configured size. Closing the window stops its events. Input methods compose in a hidden textarea kept at the caret, which has the keyboard while the program asks for text input. Programs using tasks run in a worker, which has no page: their windows do not open yet.pkg::alloy::window::cocoaFoundation's values as AppKit passes them, for the macOS window (appkit.alloy) and its accessibility (nsaccessibility.alloy): points, sizes, rectangles and ranges by value, arrays, and the conversions between the view's pixels and the screen's points and between UTF-8 and the UTF-16 NSString counts in.
pkg::alloy::window::headlessA window with no platform behind it, for tests: a list of events replayed through the program's handler, and the frames it presents kept for the test to look at.
pkg::alloy::window::layerThe page's accessibility layer, which browser.alloy's
start_layerstarts once a program installs screen readers: hidden elements over the canvas, one a node, behind a "Turn on accessibility" button, made by the JavaScript beside this file (layer.web.js). Only the installed layer calls these externs, so only a program installing it bundles that JavaScript, which reaches the canvas, keys and focus through what browser.web.js puts in the glue'salloy.page.pkg::alloy::window::loadingFunctions of the system libraries the platforms load while running.
pkg::alloy::window::nsaccessibilityVoiceOver for the macOS window (PLAN.md, F7c), through NSAccessibility: the view stands for the tree's root and every other node gets an element, an AlloyAccessibilityElement (a subclass of NSAccessibilityElement made here) holding the node's id, made as VoiceOver reaches it and released once the node is gone. The view's and the elements' methods answer from the tree the program sent; a node of no role is left out, its children standing in for it. The first question about the view asks the program for its tree, and what VoiceOver asks of a node is queued for the window to give the program once the call returns, as on Windows; changes to the tree post NSAccessibility's notifications. A grid's cells go into rows made from their own, elements standing for no node. A node sent with a map of its text answers lines, ranges, their frames and attributed strings from it (text_ranges.alloy), in UTF-16 units.
pkg::alloy::window::portalFile dialogs on Linux through the desktop portal (PLAN.md, F6c): org.freedesktop.portal.FileChooser over the session bus, which every desktop answers with its own dialog, inside a Flatpak too. A call gives a request object at once; its Response signal, later, gives the chosen files as URIs. With no session bus or no portal, a dialog is answered at once with no files. The desktop's wish for less motion is read from org.freedesktop.portal.Settings (F11e), its SettingChanged signal telling a change. Reached once a program installs files or screen readers (window.alloy's
install_files,install_access).pkg::alloy::window::posixThe C library's functions the Linux window uses, apart from the window's own names.
pkg::alloy::window::shellThe Win32 window's file dialogs and drops (PLAN.md, F6b): the shell's IFileOpenDialog and IFileSaveDialog, shown modal to the window, and an IDropTarget registered with OLE, whose calls queue events the window gives the program after them.
pkg::alloy::window::text_rangesWhat screen readers ask of a node's text, answered from its TextMap for every platform (decisions/F14.md, F14b): the unit holding an offset, moves by units, the boxes a range covers and the offset at a point. Offsets are bytes of the node's text on grapheme boundaries; each platform counts them its own way (unicode.alloy). Ranges are in the text's order, their boxes in the order they are drawn.
pkg::alloy::window::uiaUI Automation for the Win32 window (PLAN.md, F6b): the window answers WM_GETOBJECT with a provider for the root of the tree the program sends, and every node gets a provider as UI Automation asks for it. A provider is one COM object with a table of functions for each interface it answers, at fixed offsets within it: the simple provider, the fragment, the fragment root (the root's only) and the patterns (Invoke for buttons, Toggle for checkboxes, RangeValue for sliders, Value for fields, combo boxes and buttons with a value, ScrollItem for anything, ExpandCollapse for what opens, Selection for list boxes, radio groups, tab lists and calendars, SelectionItem for their options, radios, tabs and days, Grid and Table for calendars, GridItem for their days, Text and Text2 for what has a text map: fields and texts of several lines, whose ranges are COM objects of their own, a node and two byte offsets, answered from the map by text_ranges.alloy). Calls come on the window's thread (ProviderOptions_UseComThreading); what a screen reader asks goes to the program as Event::Action, and changes to the tree raise UI Automation's events while a client listens.
pkg::alloy::window::unicodeUTF-8, the text the program sees, and UTF-16, Windows' and Cocoa's, both ways; positions in one counted in the other.
pkg::alloy::window::waylandThe window on Linux, through Wayland: libwayland-client, loaded while running, speaks the protocols wayland_protocol.alloy reads from their XML, one dispatcher receiving every event. The window is an xdg-shell toplevel, decorated by the compositor where it offers to (xdg-decoration; GNOME does not), at the compositor's fractional scale where it gives one (fractional-scale and viewporter), else its integer one. Frames
presentgives go through shared memory, a GPU surface drawing into the wl_surface itself. Input methods speak through text-input-unstable-v3, which GNOME and KDE implement.pkg::alloy::window::wayland_protocolThe Wayland protocols the window speaks, read from their XML while compiling. libwayland marshals each message by the signature and the argument types a
wl_interfacegives it. The tables here describe those as plain rows, every name and signature inNAMES, since a compile-time result holds no address;Protocol::buildlays them out as the C structures when a window opens.pkg::alloy::window::win32The window on Windows, through Win32, whose system libraries every Windows program can call: a window procedure receives every message. The process is aware of each monitor's DPI (the scale is the DPI over 96), frames
presentgives go through GDI and a GPU surface's through its swapchain, and DWM paces redraws one after another to the display. Input methods speak through IMM32, the program drawing their compositions. Screen readers read the program's tree through UI Automation (uia.alloy), and the shell's file dialogs and OLE's drops come through COM (shell.alloy), the window's thread a single-threaded apartment. Needs Windows 10 1703 or later.pkg::alloy::window::xkbThe keyboard on Wayland: the compositor sends its keymap in xkbcommon's text format, which libxkbcommon turns into keys, text and modifiers for each key code (loaded while running, like libwayland-client).
std::disposeValues that must be released by a call, not only freed.
std::equalEquality: the Equal interface.
std::ffiValues C holds for Alloy (LANGUAGE_SPEC.md section 6.3): a C library that calls back through an
extern (...) -> Rfunction often passes along avoid *its caller gave it.c_pointeris that pointer: made from a reference, read back as one by the callback, which names the type it was made from.std::float_digitsThe shortest decimal digits of a float that read back to the same value, by Ryu (Ulf Adams, "Ryu: fast float-to-string conversion", PLDI 2018), which std::format writes floats with (LANGUAGE_SPEC.md section 6.5). Integer arithmetic only, so compile-time code formats floats too.
std::formatFormatting values as text: the Format interface.
std::fsThe file system: directories, paths and what is at them.
std::hashHashing: the Key interface of hash map keys.
std::ioConsole and file input/output.
std::iterableThe iteration interfaces driving
forloops.std::jsonJSON values (RFC 8259): parsing, writing, reading and building.
std::macrosThe built-in compile-time macros (LANGUAGE_SPEC.md section 7.4).
std::mapThe hash map.
std::mathMathematics over floats (LANGUAGE_SPEC.md section 6.1a).
std::numberThe numeric constraint interface.
std::optionThe optional value: a payload (
Some) or its absence (None).std::processThe running process's environment.
std::resultThe outcome of something that may fail: a value (
Ok) or the error that took its place (Err).std::sortSorting in place.
std::stringThe owned, growable byte string.
std::textSearching and parsing byte text.
std::timeTime: a monotonic clock for measuring, the wall clock, sleeping, and the calendar: days of the proleptic Gregorian calendar, times of day and the system's offset from UTC; time zones by name from the platform's database, dates and times on a zone's clocks, and ISO 8601, RFC 3339 and HTTP dates (F12e, notes at the end).
std::vectorThe growable array.
std::webThe browser's side of a
web-wasm32program, whose event loop is the browser's: the program sets up what the browser calls back, such as animation frames and input events, then letsmainreturn while it keeps running. Externs a module declares come from the JavaScript beside it,<module>.web.js(section 6.3), as this module's do.