From e821d617802ebbfff756844e4d9720342fc78a4e Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 13 Nov 2026 14:12:49 +0100 Subject: Swarm POC --- modules/swarm/c++/capability.hpp | 199 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 modules/swarm/c++/capability.hpp (limited to 'modules/swarm/c++/capability.hpp') diff --git a/modules/swarm/c++/capability.hpp b/modules/swarm/c++/capability.hpp new file mode 100644 index 0000000..8497969 --- /dev/null +++ b/modules/swarm/c++/capability.hpp @@ -0,0 +1,199 @@ +#pragma once + +#include + +/** + * What a worker tells the orchestrator about itself. + * + * The envelope is deliberately backend agnostic: common fields, then one + * section named by "kind". Browsers running WebGL2 and native processes are + * both first class worker kinds, and the swarm is meant to take WebGPU runners + * later; a string tag survives version skew where a positional format does not. + * + * A worker of another kind carries its own section instead. Nothing has to + * carry a section it has no business describing, because each kind gets its own + * full capability type -- see CapabilityOf below and the hello variants in + * message.hpp. + */ +namespace kel { +namespace lbm { +namespace sch { + +/** + * Queryable WebGL2 limits, straight from glGetIntegerv. + * + * Worth knowing which of these actually bind. max_draw_buffers and + * max_color_attachments are guaranteed to be only 4, and since a D2Q9 lattice + * needs ceil(9/4) = 3 render targets they are the limits that decide whether a + * descriptor fits in a single pass at all. The rest are either generous in + * practice or bound by memory long before they bind by count. + */ +using GlLimits = Struct< + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, "max_viewport_dims"> +>; + +/** + * Extension and context properties. + * + * color_buffer_float is a hard gate: without EXT_color_buffer_float a float + * texture is not color renderable and there is no f32 solver on this device at + * all. The others are reported so the orchestrator can decide, not so the + * worker can. + */ +using GlFeatures = Struct< + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member +>; + +/** + * What the worker measured, as opposed to what it was told. + * + * There is no queryable "available VRAM" in WebGL2 -- navigator.deviceMemory is + * system RAM and unrelated -- and max_texture_size overstates capacity by + * roughly a hundredfold on a typical desktop. So these come from an actual + * allocation trial. + * + * probed_bytes_max is the largest allocation that survived; probed_bytes_safe + * applies safety_factor to leave room for the canvas, the compositor and other + * tabs. Both are reported so the orchestrator can apply its own policy rather + * than inheriting the worker's. + * + * probe_hit_texture_size_bound distinguishes "ran out of memory" from "ran into + * max_texture_size", which are very different signals about a device. + */ +using GlBudget = Struct< + Member, + Member, + Member, + Member, + Member, + Member +>; + +/** + * One feasible way to lay a lattice out in textures on this device. + * + * This type has three jobs and keeping it as one type is what stops them + * drifting: it is an element of the capability report, it is the assignment + * message the orchestrator sends back, and it is the input to the shader + * preamble generator. + * + * The slot tables are the indirection that makes pixel stuffing expressible -- + * slot_tex_of_q[i] / slot_cmp_of_q[i] say which texture and which channel + * direction i lives in, and the aux tables do the same for the non + * distribution fields packed into otherwise idle slots. + */ +using PackingPlan = Struct< + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, + Member, "domain">, + Member, "tiles">, + Member, + Member, "texture_size">, + Member, + Member, + Member, "slot_tex_of_q">, + Member, "slot_cmp_of_q">, + Member, "slot_tex_of_aux">, + Member, "slot_cmp_of_aux">, + Member, "aux_names"> +>; + +using WebGl2Capability = Struct< + Member, + Member, + Member, + Member, "feasible"> +>; + +/** + * A worker that is a process rather than a browser tab. + * + * Native workers are not only a test fixture -- they are a worker kind in their + * own right, and the orchestrator should be able to hand them real work. What + * they report is correspondingly different: there is no texture budget to probe + * because there are no textures, so the interesting numbers are threads and + * addressable memory. + */ +using NativeCapability = Struct< + Member, + Member, + Member, + Member +>; + +/** + * The part every worker reports, whatever it is. + * + * This is deliberately the *whole* type rather than a prefix of a larger one. + * Decoding runs strict, so a struct naming every backend section would oblige a + * browser to describe a CPU and a native process to describe a texture budget. + * Instead the common part stands alone and is enough to route on: decode this, + * read "kind", then decode again as the matching full type below. The backend + * section is skipped on the first pass because unknown keys always are. + */ +using WorkerCapability = Struct< + Member, + Member, + Member, + Member, + Member +>; + +/** + * The common part plus exactly one backend section. One alias per kind, so + * adding a kind never widens what the existing ones have to fill in. + */ +template +using CapabilityOf = Struct< + Member, + Member, + Member, + Member, + Member, + Member +>; + +using WebGl2WorkerCapability = CapabilityOf; +using NativeWorkerCapability = CapabilityOf; + +/** + * The small, frequently resent part: enough to monitor a worker without + * re-sending its capability. Rides along on pong so a heartbeat doubles as a + * status update. + */ +using WorkerLive = Struct< + Member, + Member, + Member, + Member +>; + +} // namespace sch +} // namespace lbm +} // namespace kel -- cgit v1.3.1