Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite plugin for WESL #40

Closed
mighdoll opened this issue Nov 21, 2024 · 2 comments
Closed

vite plugin for WESL #40

mighdoll opened this issue Nov 21, 2024 · 2 comments
Assignees
Milestone

Comments

@mighdoll
Copy link
Contributor

We've floated various ideas for what a vite plugin might do. Let's prototype some of them to explore what's possible. Here are a few ideas:

Produce WGSL Reflection info

Use the linker to parse the source code and produce some TypeScript descriptors of the WGSL code. Things like the names of entry points, and the shape of certain struct elements would be useful for to have in TypeScript. Consider whether to imitate wgsl_reflect format in reporting.

Inject Structs into WESL

Convert some TypeScript structs into their equivalent WGSL structs and generate a WGSL file that WESL users can import.

Produce Auto-Layout

Parse WGSL and generate a GPUPipelineLayout as requested by the WebGPU team. See notes and #4957

Collect WGSL Files

Currently the linker expects that the user collect a set of named shader strings into a Record and pass that Record to the linker. But the list of shader files can be found elsewhere, probably wesl.toml will have the same glob search pattern (so language servers can find the files).

For example, the user might do something like this to collect the shader strings in the common case that they're using vite as a bundler:

const wgsl = import.meta.glob("./shaders/*.wgsl", {
  query: "?raw",
  eager: true,
  import: "default",
});

Can a vite plugin read wesl.toml and inject the shader source Record into the .js. That would make this code unnecessary and the programmer wouldn't have to maintain duplicate glob search strings in two locations.

@mighdoll
Copy link
Contributor Author

mighdoll commented Feb 2, 2025

Marking as M1 for the collect wesl files variant. Packaging the user files w/o a plugin will be possible, but it's error prone. A plugin will smooth the first experience for users.

The recent work with unplugin and binding structs plugins shows most of the work needed.

@mighdoll mighdoll added this to the M1 milestone Feb 2, 2025
@mighdoll mighdoll self-assigned this Feb 2, 2025
@mighdoll mighdoll moved this from Todo to In Progress in wesl-js Feb 6, 2025
@mighdoll
Copy link
Contributor Author

?link is now available in the vite plugin for collecting files. I think this will be the recommended approach for most people to build with wesl-js.

These experimental build extensions are also available:
?simple_reflection - generates both javascript and typescript (.d.ts) descriptions of wgsl structs
?bindingLayout - generates javascript BindingGroupLayoutEntry objects for #4957 style binding structs.

Injection of structs into wgsl is now also available via the virtualLibs option to link().

@github-project-automation github-project-automation bot moved this from In Progress to Done in wesl-js Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant