这是indexloc提供的服务,不要输入任何密码
Skip to content

The order of top-level declarations should be irrelevant #875

@litherum

Description

@litherum

#741 describes how authors usually don't put all of their shader sources in a single file; they often split them up in many source files. That issue seems to be moving in the direction of "authors should just concatenate all their sources together in JS before delivering to the browser."

If order of declarations at the top level is important, this approach breaks down. Traditionally, #include order is defined inside source files, so if order is important in WGSL and authors are using their existing workflows, they would either need an authoring-time build step, or a WGSL parser in Javascript, to resolve the include order. Avoiding these things are some of the reasons WGSL exists in the first place.

A better solution is to treat top-level declarations as an unordered set, rather than an ordered array. From an authoring perspective, this means that authors can just concatenate their sources in JS in any order and it will just work (no parser required). From an implementation perspective, resolving names would be pulled out into a separate pass after the parser is completed. This doesn't really increase complexity because it's the same name resolution code - it's just at a different place in the shader pipeline.

If we resolve the order of top-level declarations will be important, such a resolution would indicate that we should take another pass at solving #741 a different way.

Metadata

Metadata

Assignees

Labels

wgslWebGPU Shading Language Issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions