-
WebGPU-'s function createShaderModule takes a template literal and not a string. So, I-'ve had problems adding an "#include" directive like I-'ve done with OpenGL-s' shaders. It seems like the only way to achieve the same effect is with template literal interpolation. Example: Great tutorial by the way! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This might be one of those semantic things but WebGPU only takes strings. From the spec
A template literal generates a string
As for doing things like includes, preprocessing is explicitly out of scope. The topic is complex and the solution is to provide your own preprocessor with the features you personally want. In C/C++ land people want
At some point, maybe one of the preprocessors will become common. Here's one https://github.com/toji/wgsl-preprocessor As a example of an extremely simple build time preprocessor, the webgpu-samples rollup based builder defines a wgsl rule that takes a text file with raw WGSL inside and converts it to
at build time. It doesn't do any other preprocessing, but it's an example of making a build time rule where you could add more preprocessing if you want |
Beta Was this translation helpful? Give feedback.
This might be one of those semantic things but WebGPU only takes strings. From the spec
A template literal generates a string
a
,b
,c
,d
, ande
are exact the same. They are all a string with the contents'foo'
As for doing things like includes, preprocessing is explicitly out of scope. The topic is complex and the solution is to provide your own preprocessor w…