TypeGPU Kit is a set of GPU on TypeGPU. Each borrows your root and records into your passes. You create the device, run the loop and submit the commands. This page sets up a web project, draws a and hands it to a .
In a terminal the initializer asks which scene to start from: the shader this page builds, or another of the starter scenes. Pass --scene lit to choose the lit scene without a prompt. With npm, put it after --. Without a terminal, the initializer defaults to the shader scene.
my-scene gets the packages and configuration from Install and an AGENTS.md for coding agents. Its canvas page is the one from Host a scene, running the scene you chose. The initializer prints the commands that install the packages and start Vite. To add the kit to a project you already have, follow the rest of this page.
In a Vite project, install the kit, TypeGPU and its noise and colour packages. As dev dependencies, install Vite, the TypeGPU bundler plugin, tsover in place of TypeScript, and WebGPU’s types:
The code on this site imports files by their .ts names. For this setup, use allowImportingTsExtensions with noEmit. Vite’s TypeScript templates set both.
The script asks TypeGPU for a root, its handle on the GPU. A surface configures the canvas for the root and sizes its drawing buffer from the canvas layout and pixel ratio. A fragment function colours every pixel of a triangle that covers the canvas. A frame loop gives each frame an encoder and submits it when your function returns:
The frame this section draws. Turn on Glow to add a bloom.
TgpuRoot.createUniform<d.F32>(typeSchema: d.F32, initial?: number |((buffer:TgpuBuffer<NoInfer<d.F32>>)=>void)|undefined): TgpuUniform<d.F32>(+1 overload)
Allocates memory on the GPU, allows passing data between host and shader.
Read-only on the GPU, optimized for small data. For a general-purpose buffer,
use
TgpuRoot.createBuffer
.
@param ― typeSchema The type of data that this buffer will hold.
@param ― initial Either initial value of the buffer, or an initializer to execute on the mapped buffer. (optional)
createUniform(
import d
d.
constf32:d.F32
export f32
A schema that represents a 32-bit float value. (equivalent to f32 in WGSL)
Records commands for submission after the recorder returns. submit() replaces this encoder.
Read it at each call instead of keeping it, and let the frame submit it.
Runs the loop on each scheduled frame. Time advances by at most maxDt per frame, never steps
back, and stops while the surface is paused. Destroying the animation keeps the loop alive.
Another animation on the same loop continues from its recorded time. A frame error, or a run
that returns false because the loop was destroyed, stops the animation.
@param ― loop the loop to run on each unpaused frame. Continues from its seconds if it ran before
@returns ― an animation you destroy to stop the frames
animate(
constloop:frames.Frames
loop);
Start Vite, then open the page in a WebGPU browser:
Move what you draw into a that exports createScene(root, surface). Have the return an object with a frame function. Include a destroy function when the scene has resources to free. A scene holds no loop or page code, so it runs unchanged on the web, on React Native and in a test.
src/scene.ts
importtype{
(alias)interfaceFrame
importFrame
Represents one frame being recorded. Each run creates a separate object, so modules can
compare frames by identity.
Frame,
(alias)interfaceSurface
importSurface
Provides a destination for frames, such as a canvas from web.surface or native.surface, or a
texture from offscreenSurface in a test. Pass the frame to view for code that works with
every destination.
Provides a destination for frames, such as a canvas from web.surface or native.surface, or a
texture from offscreenSurface in a test. Pass the frame to view for code that works with
every destination.
Surface){
// The uniform, fragment function and pipeline from index.ts
return{
functionframe(frame:Frame):void
frame(
frame: Frame
frame:
(alias)interfaceFrame
importFrame
Represents one frame being recorded. Each run creates a separate object, so modules can
compare frames by identity.
Frame){
// The body of the frame loop from index.ts
},
};
}
web.host creates the root, surface and loop, runs the scene and reports its first error. Its handle’s destroy() tears them down in order:
Runs a scene on a canvas with a root, surface, frame loop and animation. destroy tears them
down in order. Use send to control the scene or onFrame to read it. If scene options are
optional, call host(createScene, { canvas }). Throws if both device and root are supplied.
@param ― createScene the scene file's createScene
@param ― options the scene's third argument
@param ― hosting the canvas, the device or root, and what the page runs beside the scene
@returns ― a hosted scene you send closures to and destroy
Starter scenes gives four whole src/scene.ts files to start from: this shader, a lit mesh with a shadow, a frame finished with bloom, and particles stepped on the GPU.
The tutorials build examples in this project, starting from no graphics or TypeGPU knowledge.
The packages ship built JavaScript and type declarations, with their 'use gpu' functions already transformed. The plugin transforms your own 'use gpu' functions. Vector operators in them, such as a * b, type-check only under tsover, TypeGPU’s fork of TypeScript. It replaces typescript, so a project on another TypeScript version moves to tsover’s.
A few entries need optional peers:
Import
Needs
text’s font baker, @typegpu/kit/fontBaker and typegpu-kit-bake-font
@pmndrs/glyph and Node 24.2 or later, at build time. On React Native, add rgba to Metro’s assetExts for the .
@typegpu/kit/native/host, /native/react and /native/runtimes
React 19, React Native 0.88.1, react-native-webgpu 0.21.1 and react-native-worklets 0.13.1 or later. Only /native/react imports React.
The packages ship built JavaScript, so leave them to Vite’s dependency prebundling, and add no resolve.dedupe. If you exclude them from optimizeDeps while TypeGPU stays prebundled, the page loads two copies of TypeGPU. It warns “Found duplicate TypeGPU version”, then fails on its first schema.
Vite leaves out the of a kit namespace that your code never reads. esbuild keeps every member of a namespace you import from @typegpu/kit. In an esbuild build, import members from the module’s subpath instead:
Accumulates elapsed time for fixed simulation steps. Accumulates nothing while paused. Throws
unless step is finite and above 0 and maxSteps is an integer above 0.
@returns ― a clock whose update says how many steps to run each frame
Accumulates elapsed time for fixed simulation steps. Accumulates nothing while paused. Throws
unless step is finite and above 0 and maxSteps is an integer above 0.
@returns ― a clock whose update says how many steps to run each frame
fixedStep({
FixedStepOptions.step: number
Sets the step duration in seconds, such as 1 / 120.
step:1/120});
By default a hosted scene runs on a , which needs react-native-worklets’ Bundle Mode. In Bundle Mode, a worklet’s named imports load again on the runtime it runs on. The kit’s React Native entries require at least the versions the table above lists. The configs below are for Expo 58, whose Metro is 0.87.1.
babel.config.js
constworklets={
bundleMode:true,
strictGlobal:true,
importForwarding:{
// Packages a worklet imports from, with their subpaths, loaded again on the runtime it runs on.
Bundle Mode needs two Metro patches. The kit ships them in node_modules/@typegpu/kit/patches/. With pnpm, copy them into the project and list them in pnpm-workspace.yaml, then install again:
With npm or Yarn, use the patch-package or Yarn versions of the same patches from react-native-worklets’ Bundle Mode patches, which also cover other Metro versions.
moduleNames lists every package your worklets import from; each entry covers the package’s subpaths too. relativePaths lists the kit and the file of your scene worklets, the one-line wrappers a hosted scene takes off the JS thread. Entries match folder names inside packages too. A bare src would also forward Reanimated’s own imports, which crashes its animations on the UI runtime.
relativePaths entries match the path after the last node_modules. '@typegpu/kit' matches the kit installed from npm.
Import 'react-native-webgpu' first in index.ts. Bundle Mode turns on inline requires, so an import further down installs navigator.gpu only when first used.
Import kit subpaths on React Native, such as @typegpu/kit/frames, because Metro keeps every file it reaches. The helpers that @typegpu/kit exports flat have subpaths too: @typegpu/kit/inject for byStage, unfilled, Checked and Inject, @typegpu/kit/owner and @typegpu/kit/memo.
The patches are for Expo 58’s versions, and the patched metro is the one inside @expo/metro. Both are worklets’ own workarounds for Bundle Mode. Without the metro patch, the bundle fails with “Failed to get the SHA-1” for a file in react-native-worklets/.worklets. The metro-runtime patch carries Fast Refresh to the worklet runtimes in development.
The surface page draws the same first frame on a React Native canvas, and Platforms lists each platform’s requirements.
Each kit minor runs on one TypeGPU minor, the one its peer range names. A patch release changes nothing you call. A minor release can change the kit in three ways, and its notes list every change:
The contract changes only by addition. Your own modules and scenes are written against it:
frames, Frame and the optional helper owner, and the fill helpers Inject, Injectable, byStage, unfilled and Checked
the drawing contract of passes: Drawing, Compound, Into, Built, Drawn, Output with passes.output, and what reads from its
cameras.current and the Camera schema, FloatTexture, and the post source types
how every module behaves: the root comes first and is borrowed, destroy() frees only what the factory made, initAsync() is optional, and inject() can be called any number of times
A module keeps its import path, namespace, factory names and recording methods. Its options, defaults, other members and looks can change. So can the shader-side of shading and lighting. A lit module of your own therefore one kit minor.
A module whose card says unstable can change in any way, as can @typegpu/kit/geometry and @typegpu/kit/debug.
Generated WGSL, the exact commands a frame records and how a picture looks can change in any release.
The kit ships a guide for coding agents, the skill skills/typegpu-kit/SKILL.md. It lists the kit’s rules, such as recording a frame into the frame’s encoder, splitting uniforms by when they change, and @typegpu/noise. It links to these pages as Markdown in the package’s docs/, along with every module’s contract and the examples’ source. The site serves each page as Markdown too, at its address with .md for the trailing slash, and lists them in llms.txt at the site’s root. The Markdown pages and llms.txt name the kit version they describe. Both send an agent working in a project with the kit installed to the package’s docs/.
TypeGPU ships its own skill for TypeGPU itself, skills/typegpu/SKILL.md in the typegpu package. Each skill matches the installed version of its package.
The skill, docs/index.md and docs/modules.md keep their paths in the package, and the package’s exports list them. In a project with the kit installed, import.meta.resolve('@typegpu/kit/docs/index.md') finds the index.
TanStack Intent points the project’s agent config at the skills its packages ship, so it finds both. Run it once:
Or point to both skills from the project’s AGENTS.md:
AGENTS.md
Read node_modules/@typegpu/kit/skills/typegpu-kit/SKILL.md and node_modules/typegpu/skills/typegpu/SKILL.md before writing GPU code.
moduleA module is one piece of GPU work, made by a factory that borrows your root and returns resources, shader functions and methods that record into your frame.A module borrows →
frameA frame is one turn of the loop, and the object your function gets for it, which holds the encoder, the time and the time since the last frame.You own the frame →
hostA host runs a scene for you, which means it makes the device, the surface and the frame loop and frees them in order.Hosting scenes →
sceneA scene is the function a scene file exports, which creates its modules and returns the function that records each frame.Hosting scenes →
factoryA factory is the function that creates a module, which allocates what the module needs and returns its resources, functions and recording methods.A module borrows →
atlasAn atlas is one texture that holds many small pictures side by side, such as every glyph of a font or every view of a model.Words →
memberA member is a function or accessor on what a factory returns that reads that instance's own resources, so a pipeline that uses it needs no fill.Members and placeholders →
workletA worklet is a function that react-native-worklets can run on a thread other than the main JavaScript thread.Words →
runtimeA runtime is one JavaScript thread with its own memory, such as the page, a worker or a React Native worklet thread.Words →
drawingA drawing is what a renderer hands to a pass description: what each vertex carries to its pixels, what a pixel looks like and the draw call.Every renderer is a drawing →
pass descriptionA pass description says once which textures a pass draws into and what each holds, and builds the pipeline for every drawing added to it.Scenes and passes →
recorderThe recorder is the function you give the frame loop, which records one frame into the encoder it is handed.Words →
hookA hook is a placeholder that each pipeline fills with its own choice, such as the camera it draws through.Members and placeholders →
fixed stepA fixed step advances a simulation by one set length of time, and each frame runs a whole number of them, so the result is the same at any frame rate.A fixed step →