npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

minimal-gpu

v1.0.4

Published

Minimal is thin layer of abstraction on top of WebGPU with the purpose of making Shader Programming, GPU Simulations and Parallel Programming much easier.

Readme

( ⚠ WIP ) Minimal :: A Shader Driven WebGPU Framework 💎

🔗 https://youtu.be/Sx39Y--kZvY

2 (2)

⚠ Disclamer: Minimal is WIP and still under heavy development!

Minimal is a thin layer of abstraction on top of WebGPU with the purpose of making Shader Programming easier!

At the core of minimal, is an idea called Shader Driven Programming, which allows you to create and control your GPU resources dynamically from shader code.

Minimal introduces MSL (Minimal Shading Language) which is a superset of WGSL (the shading language of WebGPU).

Learn more about minimal, and how to use it by watching this video:

🔗 https://youtu.be/Sx39Y--kZvY

Installation

npm i minimal-gpu

Usage

Learn here.

See example here.

Decorators

Decorators (also known as Attributes in WGSL), are words that start with the @ symbol.

NOTE: required parameters are marked with a *

@texture() => creates a GPU texture ( GPUTexture )

  • @size(*) => defines the texture size
  • @format(*) => defines the texture format

example:

@texture(@size(1920, 1080), @format(rgba16float)) var output_texture: texture_2d<f32>;

@buffer() => creates a storage buffer ( GPUBuffer )

  • @size(*) => defines the buffer size
  • @stride() => defines the buffer stride

example:

@buffer(@size(1920 * 1080)) var<storage, read> output_buffer: array<f32>;

@uniform() => creates a uniform buffer ( GPUBuffer )

  • @uniform_name(*) => initializes a property in the uniform struct

NOTE: the struct type is required.

example:

struct Uniforms {
  color: vec3<f32>,
};

@uniform(@color(0.05, 0.7, 0.4)) var<uniform> uniforms: Uniforms;

@ref => references a GPU resource by binding it to the shader

  • input format should be (shader_name.resource_name)

example:

@ref(resource.output_buffer) var<storage, read_write> input_buffer: array<f32>;

@sampler() => creates a GPU sampler resource ( GPUSampler ).

  • @addressModeU()
  • @addressModeV()
  • @addressModeW()
  • @magFilter()
  • @minFilter()
  • @mipmapFilter()
  • @lodMinClamp()
  • @lodMaxClamp()
  • @compare()
  • @maxAnisotropy()

example:

@sampler(@addressModeU(repeat), @addressModeV(repeat)) var tex_sampler_1: sampler;
@sampler var tex_sampler_2: sampler;

@group => default wgsl decorator which we'll handle implicitly and explicitly @binding => default wgsl decorator which we'll handle implicitly and explicitly

@compute(*) => required decorator for compute shaders => it takes in the number of threads as input.

example:

// 1D
@compute(100)

// 2D
@compute(100, 100)

// 3D
@compute(100, 100, 100)

@fragment(*) => required decorator for fragment shaders => it takes in a texture name as input

example:

@fragment(output_texture)

@canvas => creates a canvas element, and can only be used as the input to a @fragment decorator. takes in the width and the height as inputs.

example:

@fragment(@canvas(1920, 1080))

Wildcards

Wildcards are special variables that can be used as inputs in MSL decorators. Wildcards can be (f32, vec2, vec3, vec4).

Example of Resource Shader, using a wildcard:

const rShader = /* wgsl */ `
  @buffer(@size(wc.resolution.x * wc.resolution.y)) var<storage, read> output_buffer: array<f32>;
`;

const resolution = new Wildcard("resolution", [window.innerWidth, window.innerHeight]);

window.addEventListener("resize", () => {
  resolution.set(window.innerWidth, window.innerHeight); // update wildcard
});

const resourceNode = new Shader(device, "resource", rShader, [resolution]);

Resources

All resources are normal WebGPU resources (GPUBuffer, GPUTexture, GPUSampler).

To get a gpu resource use the getResource function in the shader class. (remember that when you can call getResource(resource_name), you will only recieve a resource if "resource_name" is created within that shader, using a decorator )

Shaders

Shaders are the core building block in Minimal.

General Example of Shaders and Referencing:


import { Color, Composer, GUI, Shader, Wildcard } from "minimal-gpu";

// create webgpu device

const navigator = window.navigator as any;
if (!navigator.gpu) throw new Error("WebGPU not supported, this application will not run.");

const adapter = await navigator.gpu.requestAdapter();
if (!adapter) throw new Error("No adapter found");

const device = (await adapter.requestDevice({
  requiredFeatures: ["timestamp-query"],
})) as GPUDevice;

// write shaders

const rShader = /* wgsl */ `

@buffer(@size(wc.resolution.x * wc.resolution.y * 3)) var<storage, read> output_buffer: array<f32>;

`;

const cShader = /* wgsl */ `

@ref(resource.output_buffer) var<storage, read_write> input_buffer: array<f32>;

struct Uniforms {
  color: vec3<f32>,
};

// ! Struct Types are important because the initializer needs a name to work with
// ! so "uniforms: vec3<f32>;" is not allowed...
@uniform(@color(0.05, 0.7, 0.4)) var<uniform> uniforms: Uniforms;

@compute(wc.resolution.x, wc.resolution.y)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
  let index = (global_id.x + global_id.y * u32(window.resolution.x)) * 3;
  input_buffer[index + 0] = uniforms.color.x;
  input_buffer[index + 1] = uniforms.color.y;
  input_buffer[index + 2] = uniforms.color.z;
}

`;

const fShader = /* wgsl */ `

@ref(resource.output_buffer) var<storage, read> input_buffer: array<f32>;

@fragment(@canvas(wc.resolution))
fn main(@builtin(position) coord: vec4f) -> @location(0) vec4<f32> {
  let index = u32(coord.x + coord.y * window.resolution.x) * 3;
  let color = vec3(input_buffer[index], input_buffer[index + 1], input_buffer[index + 2]);

  return vec4(color, 1);
}

`;

// create shaders

const resolution = new Wildcard("resolution", [window.innerWidth, window.innerHeight]);

window.addEventListener("resize", () => {
  resolution.set(window.innerWidth, window.innerHeight); // update wildcard
});

const resourceNode = new Shader(device, "resource", rShader, [resolution]);
const colorizeNode = new Shader(device, "colorize", cShader, [resolution]);
const redNode = new Shader(device, "fullscreen", fShader, [resolution]);

document.body.appendChild(redNode.getCanvas());

const composer = new Composer(device, true);

// add all the shaders
composer.addShader(resourceNode);
composer.addShader(colorizeNode);
composer.addShader(redNode);

// set all the inputs. prepare for running.
composer.setInputs();

function tick() {
  composer.update();

  requestAnimationFrame(tick);
}

requestAnimationFrame(tick);

// gui

const gui = new GUI();

// pass in the uniform buffer name + the individual uniform name
const colorUniform = colorizeNode.getUniform("uniforms", "color");

// load in default values of the uniform
const colorStruct = new Color().fromArray(colorUniform.array as number[]);
const controlParams = {
  colorStruct,
};
gui.addColor(controlParams, "colorStruct").onChange((newColor: Color) => {
  // update the uniform
  colorUniform.set(newColor);
});

Roadmap / TODO

  • vertex shader support
  • capable 3d renderer
  • camera control system
  • geometry generation compute shaders
  • more decorators for dynamic resource creation like @length, @count etc...