brendan-duncan /wgsl_reflect

A WebGPU Shading Language parser and reflection library for Javascript.

★ 300⑂ 32👁 8⑃ 37● 62▤ 0
TypeScriptMITCreated 2021-11-14
+0
日增长
+0
周增长
300
stars
32
forks
8
watchers
37
prs
62
issues
0
releases

README

WebGPU Shading Language Reflection Library

A WebGPU Shading Language (WGSL) parser, reflection, execution, and debugging library for Typescript and Javascript.

 Example

---

wgsl_reflect is a self-contained toolkit for working with WGSL shaders without a GPU:

- Reflection — parse a WGSL shader and analyze its contents: bind group layout, resource bindings, uniform and storage buffers, struct members with their names, types, sizes, and byte offsets, entry points, and inter-stage inputs/outputs.
- Execution — run a WGSL shader on the CPU. WgslExec emulates compute dispatches and produces the same buffer results a GPU would, which is useful for testing shaders without a device.
- Debugging — step through a compute, vertex, or fragment shader one statement at a time with WgslDebug: breakpoints, step into/over/out, and variable inspection — the building blocks of a shader debugger. Fragment shaders can be debugged over their 2×2 quad so dpdx/dpdy/fwidth and textureSample mip selection resolve correctly.
- Race condition detection — detectRaces runs every invocation of a workgroup in lockstep to catch missing workgroupBarrier()/storageBarrier() calls that cause data races.
- Static performance analysis — analyzePerformance flags potential bottlenecks in vertex, fragment, and compute shaders, such as expensive math, division, atomics, and barriers inside loops.

 Contents

- Installation
- Quick Start
- Documentation
- Reflection API Reference
- Reflection Examples

 Installation

From NPM:


npm install wgsl_reflect


The _wgsl_reflect.module.js_ file is a self-contained roll-up of the library that can be included in your project and imported with:

javascript
import { WgslReflect } from "wgsl_reflect/wgsl_reflect.module.js";
// Parsees the WGSL in shaderCode, extracs information about it.
const reflect = new WgslReflect(shaderCode);


 Quick Start

javascript
import { WgslReflect } from "wgsl_reflect/wgsl_reflect.module.js";

// Parsees the WGSL in shader_code, extracs information about it.
const reflect = new WgslReflect(shaderCode);

// What resources does the shader bind?
const groups = reflect.getBindGroups();

// What are the compute/vertex/fragment entry points?
console.log(reflect.entry.compute.map(fn = fn.name));


 Documentation

The reflection API is documented below. The execution, debugging, race
detection, and performance analysis features each have a dedicated guide in the
docs folder:

- Shader Execution — run WGSL shaders on the CPU and emulate compute dispatches with WgslExec.
- Shader Debugging — step through a shader, set breakpoints, and inspect state with WgslDebug.
- Race Condition Detection — find missing barriers in compute shaders with detectRaces.
- Static Performance Analysis — flag potential performance bottlenecks in shaders with analyzePerformance.

 Reflection API Reference

javascript

// A collection of gathered reflection information about the s

Discussions

Snapshot: 2026-11-27T22:26:53Z · Data license Apache-2.0 · JSON