Open-source project
software-mansion/TypeGPU avatar
software-mansion/TypeGPU

TypeGPU: one shader function, three consumers, and a repo README partly written by a generator

A modular and open-ended toolkit for WebGPU, with advanced type inference and the ability to write shaders in TypeScript

3,323 stars146 forksTypeScriptMIT

At a glance

What is it?
TypeGPU is a TypeScript layer over WebGPU that turns a function marked with a string literal into WGSL, a JS value, or a GPU dispatch. Its release tags bundle packages at different version numbers, its test script builds every package before testing it again, and part of its README is generated from a file at the repository root.
Who is it for?
TypeGPU fits a team already writing WebGPU that wants compile-time checking on buffer shapes and shader code without leaving TypeScript, and that can accept a toolkit sitting between its application and the raw API. Before adopting it, check which package you actually need: the release tags ship `typegpu`, `@typegpu/gl` and `@typegpu/cli` at three different version numbers, so a tag is not a single version to pin.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • software-mansion/TypeGPU3,323 ★ · +92
Star history
Repository2026-09-242026-11-15
software-mansion/TypeGPU3.2k3.3k

92 Stars in the last 52 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

One function, three consumers, and a string literal as the marker

The opening example is the whole mechanism in 27 lines:

ts
const neighborhood = (a: number, r: number) => {
  'use gpu';
  return d.vec2f(a - r, a + r);
};

//
// #1) Can be called in JS
//
const range = neighborhood(1.1, 0.5);
//    ^? d.v2f

//
// #2) Used to generate WGSL
//
const main = () => {
  'use gpu';
  return neighborhood(1.1, 0.5);
};

const wgsl = tgpu.resolve([main]);
//    ^? string

//
// #3) Executed on the GPU (generates WGSL underneath)
//
root.createGuardedComputePipeline(main).dispatchThreads();

Nothing converts the function. The string literal `'use gpu'` inside the body is the marker, and the same arrow is then called as an ordinary function, wrapped in a second function that gets resolved into a WGSL string, and handed to a guarded compute pipeline for dispatch on the GPU. The `^?` comments are TypeScript's inline type queries, so the editor reports the result type at each call site.

The third example stops before the function it declares returns

The example that builds a typed API is cut off mid-function. It declares `export async function generateHeightMap(root: TgpuRoot, opts: { width: number; height: number }): Promise<TgpuBuffer<HeightMap> & StorageFlag>`, creates a buffer with `root.createBuffer(HeightMap(opts.width, opts.height)).$usage('storage');`, and then the snippet ends, with no return statement and no closing brace. So the one place the documentation shows how a storage buffer is handed back to a caller never shows the hand-back. The example above it is deliberately broken instead: `plot.array1d(root, terrainBuffer)` carries a comment reading ERROR, because a two-dimensional buffer is not assignable to a one-dimensional parameter, and the line after it, `plot.array2d(root, terrainBuffer)`, is marked SUCCESS. Both the failure and the fix are presented as type errors the compiler catches before any GPU work starts.

Every release tag bundles packages at three different versions

The repository is a pnpm workspace with `packages/`, a `pnpm-workspace.yaml`, a `pnpm-lock.yaml` and a root manifest named `typegpu-monorepo` that is private and pinned at version 0.0.0, so no published version number lives in the file most people read first. The tags carry several packages at once, each on its own version line: v0.12.6 ships `typegpu` 0.12.6 with `@typegpu/radiance-cascades` 0.12.1, v0.12.5 ships `typegpu` 0.12.5 with `@typegpu/gl` 0.12.4 and `@typegpu/cli` 0.12.3, and v0.12.4 ships `typegpu` 0.12.4 with `@typegpu/gl` 0.12.3. A tag is therefore a release train, not a single version you can pin. The root also carries a `patches/` directory, the conventional home for patched dependencies, and nothing in the README says what is patched or why. The Node version the repo builds against is pinned separately in `.nvmrc`.

The test script runs everything twice, once against built output

`pnpm test` is five suites chained with `&&`, and the order matters. `test:types` runs a `transform-overloads` step in the docs app before recursing into every package in parallel. `test:style` runs oxlint with `--max-warnings=0` and `--type-aware`, then prettier over the docs app's astro files, then `oxfmt --check`. `test:unit-and-attest` runs `ENABLE_ATTEST=1 vitest run --project=!browser`, where the environment variable switches on the attestation tests and the negated project leaves browser tests out. `test:built-unit-and-attest` builds every package first and repeats the run against the build output, which is how the published entry points get covered. Last comes `test:circular-deps`, a dpdm invocation with `--exit-code circular:1` over both `index.ts` and `index.js` under `packages/`, so the source entry points and the built ones must both stay free of cycles.

The lint gate excludes one template, then lints it separately

The style gate is not one command. The first oxlint pass runs type-aware over the workspace with an ignore pattern of `packages/typegpu-cli/templates/template-expo-bare/**`, and a second oxlint pass then covers exactly that excluded path without the type-aware flag. Both ask for `--report-unused-disable-directives`, so a suppression comment that no longer suppresses anything fails the run. The formatter story is split three ways as well: `pnpm fix` runs `oxlint --fix`, then prettier scoped to `apps/typegpu-docs/**/*.astro`, then `oxfmt`. So prettier's only territory in this repository is astro markup in the docs app, and JavaScript and TypeScript formatting belongs to oxfmt, configured through `.oxfmtrc.json` while lint rules sit in `oxlint.config.ts` and editor settings in `.prettierrc`. The Expo bare template inside the CLI package is a vendored starting point, and the config treats it that way.

Interoperability is the feature and also the footprint

The README frames the toolkit as a layer you can eject from at any point, and lists the three problems a typed WebGPU library runs into: serializing data, dynamically generating parts of a WGSL shader, and complex type inference. Those three are also the three places TypeGPU inserts itself. The second example makes the coupling concrete, since every library function takes the same `root: TgpuRoot` object, created once through `await tgpu.init()` and described as the common root for allocating resources, so a library built this way cannot be called without an initialized TypeGPU root in hand. The schema side avoids copying data back to CPU-accessible memory by defining shapes as ordinary functions, `HeightMap(width, height)` returning a nested array schema, and recovering the type with `ReturnType<typeof HeightMap>`.

Part of the README is generated from a file at the repository root

The badge block is wrapped in an `automd:badges` marker carrying `license`, `name="typegpu"`, `bundlephobia` and `no-npmDownloads`, and the projects section is pulled in by an `automd:file` marker pointing at `projects-using-typegpu.md`, which is a top-level file in the repository. The lists of libraries and apps you see in the README are therefore whatever that file says, rewritten by the generator rather than by hand, and the applications section runs to Screen Studio, a macOS screen recorder, and Shaders v3, whose entry stops partway through its URL. The site addresses are split three ways too: the repository homepage field is `http://typegpu.com`, the logo in the README is served from `https://typegpu.com`, and both the Website link and the package homepage point at `https://docs.swmansion.com/TypeGPU`.

The stated audience is split three ways, each with its own entry point

The README is organised around three roles rather than around features. As a foundation, TypeGPU mirrors WGSL syntax in TypeScript so that the toolkit and the underlying shading language are learned together. As a piece of an existing application, the APIs are meant to be used together or in isolation, so partial adoption is meant to cost a few lines. As an interoperability layer for library authors, the pitch is that a type-safe WebGPU library otherwise has to copy data back to JavaScript or drop into untyped WebGPU, and TypeGPU can sit between two libraries that have different focuses, with the procedural generation and plotting libraries in the example standing in for that. Each of the three is a link to a documentation site rather than a section you can read here.

Editorial conclusion

TypeGPU fits a team already writing WebGPU that wants compile-time checking on buffer shapes and shader code without leaving TypeScript, and that can accept a toolkit sitting between its application and the raw API. Before adopting it, check which package you actually need: the release tags ship `typegpu`, `@typegpu/gl` and `@typegpu/cli` at three different version numbers, so a tag is not a single version to pin. Read the examples as carefully as the prose, because the third one ends before the function it declares returns anything. Budget for the repo's own gates, since `pnpm test` chains five suites and rebuilds every package on the way, and remember that the dependency patches live in this repository rather than in the published package. Anyone who needs a comparison against three.js or Vulkan will not find one here.

Frequently asked questions

what is typegpu

A MIT-licensed TypeScript toolkit for WebGPU from Software Mansion, published to npm as `typegpu` with sibling packages such as `@typegpu/gl` and `@typegpu/cli`. It lets you write shader code as TypeScript functions marked with a `'use gpu'` literal and generates WGSL from them at build or resolve time, and the repository is a pnpm workspace with the packages under `packages/`.

Does TypeGPU replace writing WGSL by hand?

It generates WGSL, and its syntax is designed to mirror the shading language so the two are learned together. The opening example resolves a function into a WGSL string, and a compute pipeline call runs it on the GPU with that string produced underneath.

How do I install TypeGPU for a project?

The packages ship to npm, with `typegpu` as the main one and `@typegpu/gl` and `@typegpu/cli` released alongside it. Install them from npm rather than from the repository, since the root of the repository is a private workspace manifest pinned at 0.0.0 and its `patches/` directory applies to this repository's own install only.

What does TypeGPU's test suite check?

`pnpm test` chains five suites: type tests, style checks, unit and attestation tests, the same unit tests again against freshly built packages, and a circular dependency check over both source and built entry points. Attestation tests run behind `ENABLE_ATTEST=1`, and browser tests are excluded from the unit runs by `--project=!browser`.

Is TypeGPU better than three.js or raw WebGPU?

The repository makes no such comparison, and it names no benchmark. What it states is that TypeGPU is a layer over WebGPU that keeps types on buffer shapes and shader generation, and that you can eject into vanilla WebGPU where you need to. Any answer comparing it with three.js has to come from outside this project.

Official sources

  1. License: MIT
  2. Project website
  3. README
  4. Releases
  5. software-mansion/TypeGPU on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/software-mansion-typegpu.svg)](https://hysenlabs.com/projects/software-mansion-typegpu)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/software-mansion-typegpu.svg)](https://hysenlabs.com/projects/software-mansion-typegpu)

Was this useful?