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

[wgsl] Reasoning behind inheriting rust-like syntax #593

@Yen

Description

@Yen

Looking at the limited samples and construct definitions in the spec, I think there is a lot of influence in the languages syntax from the syntax used in rust. Is there was a specific reason for this decision over inheriting syntax where possible from GLSL or in general, traditional C like constructs?

I might be incorrect on this but for the most part, I find that most of the constructs currently present in the spec were expressable in GLSL with less text. Using the EXAMPLE 1 from the WGSL spec:

[[location 0]] var<out> gl_FragColor : vec4<f32>;
fn main() -> void {
    gl_FragColor = vec4<f32>(0.4, 0.4, 0.8, 1.0);
    return;
}
entry_point fragment = main;

Could be expressed with more condensed syntax using a form of (slightly modified) GLSL:

layout (location = 0) out vec4<f32> gl_FragColor;
void main() {
    gl_FragColor = vec4<f32>(0.4, 0.4, 0.8, 1.0);
    return;
}
entry_point fragment = main;

The differences are small but I think overall there is a lot of syntax present in the spec that does not have reasoning as far as I can see. It is instead inherited from a more complex language where the verbostity in syntax avoids ambiguity, but as WGSL does not inherit the realted complexities, the syntax does not serve a clear purpose to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions