shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
2.51k stars 198 forks source link

WGSL: Functions cannot be called at module scope #5607

Open aleino-nv opened 2 days ago

aleino-nv commented 2 days ago

Failing tests:

Example output:

WGPU error: Error while parsing WGSL: :8:24 error: functions cannot be called at module-scope
const result_0 : i32 = EnsureCompileTimeEval_getValue_0();
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 - While validating [ShaderModuleDescriptor]
 - While calling [Device].CreateShaderModule([ShaderModuleDescriptor]).
aleino-nv commented 15 hours ago

@csyonghe I haven't looked into this yet, but from the name it sounds like Slang is emitting code where EnsureCompileTimeEval_getValue_0() is supposed to be evaluated by WGSL at compile time.

Is this something Slang does? WGSL has some support for something similar to "constexpr", but I think they have to be explicitly marked as such.

csyonghe commented 15 hours ago

I think this is supposed to be inlined and evaluated by slang so it never actually appears in the generated wgsl code.