kernel library
Compute kernels written in the kernel language, read once and translated for each placement: WGSL for WebGPU and the wgpu sidecar, a Dart kernel for the CPU — 1.0.
Pure Dart, with no dart:io, so a backend in a browser, a build
hook and a test read it alike. A device with compute loads a bundle's
kernel section through kernelsOf and translates what it finds; a
caller that wants a bundle of its own kernels makes one with
kernelBundle.
Classes
- ComputeKernel
- One compute kernel, read from kernel language source and checked.
- DartKernel
- A kernel as Dart: what the CPU placement runs.
- KernelBinding
- One binding a kernel declares, in the order it declares them: its index is its WGSL binding in group zero.
- KernelBindingKind
- What a KernelBinding is.
- KernelImage
-
A storage texture a kernel writes with
store, as the CPU placement hands it. - KernelInputs
- What a DartKernel dispatch reads and writes, by binding name: buffers as bytes (little-endian, as a GPU lays them), textures and images through the backend's own KernelTexture and KernelImage.
- KernelPixels
- RGBA8 texels in host memory, rows from the top, read and written as a kernel reads and writes a texture and an image: for a test, and for a backend whose textures are bytes already.
- KernelTexture
-
A texture a kernel reads with
load, as the CPU placement hands it. - WgslKernel
- A kernel's WGSL, and what binds it.
- WorkgroupSize
-
How many invocations a workgroup runs along each of its three axes: a
kernel's
workgroup x, y, z, and a material'sworkgroup x y.
Constants
- kernelEntryPoint → const String
- The entry point every translated kernel has.
- kernelLanguageFirstVersion → const int
-
The version a source without a
kernel <N>line is. - kernelLanguageVersion → const int
- The kernel language version this build reads, and every one below it.
Functions
-
kernelBundle(
String name, Iterable< ComputeKernel> kernels) → ShaderBundle -
A bundle named
namethat carrieskernelsin its kernel section, each claimed as a stage of its name: whatGraphicsDevice.loadShaderstakes on any device with compute. -
kernelsOf(
ShaderBundle bundle) → Map< String, ComputeKernel> -
The kernels
bundle's kernel section carries, read and checked, by stage name; empty when it has none. What a device'sloadShaderscalls. -
roundHalfEven(
double x) → double -
xto the nearest whole number, ties to even, as WGSL'sround. -
unormLevel(
double value) → int -
value, clamped to[0, 1], as the RGBA8 level a GPU stores for it:round(value × 255), the product in f32 and ties to even. -
unormValue(
int level) → double -
levelof 255 as the f32 a GPU reads an RGBA8 texel as.
Exceptions / Errors
- ComputeKernelException
- Kernel language source that is not a kernel: a word the language does not have, a type that does not fit, a write to a buffer declared read — with the line and column of the first thing that is wrong.