wgsl-tooling-wg / wesl-spec

A portable and modular superset of WGSL
BSD 3-Clause "New" or "Revised" License
40 stars 3 forks source link

namespaces proposal #61

Open stefnotch opened 3 weeks ago

stefnotch commented 3 weeks ago

Maybe one of us should be brave enough to write up a WebGPU proposal for namespaces. One that lets us cleanly say "a WESL module creates a WGSL namespace".

We'd need

mighdoll commented 14 hours ago

Some ideas for namespaces summarized in this module system discussion doc. Notably:

Module Hierarchy Starts From File Hierarchy

Code in files and libraries are addressable in a 'module hierarchy'. File and directory names names in applications map automatically into the module hierarchy. Future features like namespace would also be placed into the module hierarchy.

namespaces

If zip.wgsl has a future namespace construct like namespace dig { fn bar() {} }, the namespace would map into the same addressable hierarchy.

hierarchy remapping (aka re-exporting)

Allow grafting subtrees into the module hierarchy from WESL.

For example, let's say the file system contains other/bar/zig.wesl and other/bar/zag.wesl. We've discussed namespace variations that place a namespace in the module hierarchy. We might put a statement like this in util/stuff.wesl:

Then you could write: