Skip to content

builtins with a 3D variant should all have 1D variants (global_invocation_index, workgroup_index) (WGSL proposed language change) #5154

@jowens

Description

@jowens

Some builtins have both 3D and 1D variants, e.g., local_invocation_id and local_invocation_index. The latter is a linearized function of the former. Both are useful. They relieve the programmer from manually computing one from the other (usually 3D -> 1D), a computation that is unfortunately (in my experience) error-prone.

Two builtins have 3D but not 1D variants. I would like to see two 1D variants added as builtins:

  • global_invocation_index (from global_invocation_id). I should add here that from a teaching perspective, this is a very useful builtin as it allows a simpler WGSL 101 kernel (“one million threads each fetch one u32, add 1 to it, and write it back”). (But of course we shouldn’t add builtins for strictly pedagogical reasons.)
  • workgroup_index (from workgroup_id)

I expect these could be easily polyfilled, correctly, once, by the compiler team, and not many times, sometimes incorrectly, by WGSL programmers. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issues
    No fields configured for Feature.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions