wgsl_reflect is a JavaScript and TypeScript library designed for parsing and reflecting WebGPU Shading Language (WGSL) shaders. It provides comprehensive static analysis of WGSL code, extracting critical metadata such as bind group layouts, resource bindings, uniform buffer structures, and the members, types, sizes, and offsets of these structures. This functionality is particularly valuable for WebGPU developers as the standard WebGPU API lacks built-in shader reflection capabilities, making dynamic buffer creation and data layout challenging. The library is actively maintained, with version 1.2.3 being the current stable release, and it generally follows semantic versioning. It serves as an essential tool for dynamically inspecting shader interfaces, streamlining the setup of GPU resources from JavaScript, and integrating with higher-level WebGPU frameworks.
npm install wgsl_reflectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a WGSL shader, extract its uniform buffer layouts, individual resource bindings, and entry point functions. It prints detailed information about the uniform variables, their struct members, and the shader's entry points, which is crucial for setting up WebGPU pipelines dynamically.
Regularly update `wgsl_reflect` to the latest version via `npm install wgsl_reflect@latest` to ensure compatibility with recent WGSL specification changes. Report any parsing issues with valid WGSL to the library's GitHub repository.
Always use `import { WgslReflect } from 'wgsl_reflect/wgsl_reflect.module.js';` for ESM imports. If using CommonJS, consider transpilation or a bundler that correctly handles ESM packages.Simplify complex WGSL constructs where possible if encountering parsing issues. Refer to the library's documentation and GitHub issues for known limitations or workarounds. Validate reflection output against expected shader behavior.
Change the import statement to `import { WgslReflect } from 'wgsl_reflect/wgsl_reflect.module.js';`Ensure `WgslReflect` is imported as a named export: `import { WgslReflect } from 'wgsl_reflect/wgsl_reflect.module.js';` (note the curly braces).Review the WGSL shader code for syntax errors. Ensure the `wgsl_reflect` library is up-to-date. If the WGSL is valid according to the latest spec but still fails, report an issue to the library's maintainers.
No dependency data recorded yet.