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

Address common community WGSL string interpolation cases in WESL #50

Open
mighdoll opened this issue Oct 3, 2024 · 22 comments
Open

Address common community WGSL string interpolation cases in WESL #50

mighdoll opened this issue Oct 3, 2024 · 22 comments
Milestone

Comments

@mighdoll
Copy link
Contributor

mighdoll commented Oct 3, 2024

Community projects in WGSL (and other shader communities) typically rely on string interpolation to inject some host specific variation into shaders.

Let's enumerate the common string interpolation use cases in this issue (and make separate issues for the uncommon cases) and then document them on the spec site.

We originally planned to address these common cases by standardizing a string interpolation mechanism (see SimpleTemplating). I think the current discussions lean towards more precise language features than string insertion, but either way a clear understanding of the use cases will help validate our solutions. When we agree on spec features to address these community use cases, we can document them alongside.

@k2d222
Copy link
Contributor

k2d222 commented Oct 3, 2024

Some of what I have seen (mostly glsl)

  • substitute a function name (similar to @link)
  • concatenate identifiers, e.g. alias array${N}f = array<f32, ${N}>;
  • inject a bunch of code, for example a prelude, polyfills, or imports.
  • repeat N times, unroll loops or implement recursion (usually implemented with other special markers in code)
  • feature flags, e.g. const my_feat: bool = ${MY_FEAT_ENABLED};
  • inject cpu-precomputed math: e.g. let my_const = ${3+2}
  • conditional compilation (with string injections that may be empty) e.g. ${DEBUG_BEGIN} ... some stuff ... ${DEBUG_END}
  • writing metadata in the file: build date, time, file name, line number, deploy url, file hash...
  • markers for parsing
  • stateful injections, e.g. @bind(${i++})

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 4, 2024

pixijs: host code controlled linking via string insertion here
pixijs: aligning vert and frag @location indices here
pixijs: custom code generation for blur filter: here

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 5, 2024

nanite-webgpu

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 5, 2024

lygia

  • mostly static functions
  • assumes existence of an #include facility
  • glsl versions use #define and possibly function overloading, wished for features in WGSL

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 5, 2024

webgpu-torch

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 5, 2024

pbmpm

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 5, 2024

frostbitten-hair-webgpu

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 5, 2024

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 6, 2024

alpenglow

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 6, 2024

Egrogia

  • custom #include and #ifdef preprocessor
  • (no runtime injection of strings or numbers AFAICT)

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 6, 2024

strahl

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 6, 2024

luma.gl

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 6, 2024

vello

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 6, 2024

webgpu-particles

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 6, 2024

webgpu-marching-cubes

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 7, 2024

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 7, 2024

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 7, 2024

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 7, 2024

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 7, 2024

pixijs-filters

  • image plugins with standard plugin uniforms and separate per plugin uniforms

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 7, 2024

@mighdoll
Copy link
Contributor Author

mighdoll commented Oct 7, 2024

GraphWaGu

  • file per shader, copy paste for struct sharing

@mighdoll mighdoll added this to the M1 milestone Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants