PHANTOM
🇮🇳 IN
Skip to content

Add linear_indexing language feature#5554

Open
alan-baker wants to merge 6 commits intogpuweb:mainfrom
alan-baker:linear-indexes
Open

Add linear_indexing language feature#5554
alan-baker wants to merge 6 commits intogpuweb:mainfrom
alan-baker:linear-indexes

Conversation

@alan-baker
Copy link
Contributor

  • Two new builtins:
    • global_invocation_index - linearized global_invocation_id
    • workgroup_index - linearized workgroup_id

Fixes #5154

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

Previews, as seen when this build job started (f0b15af):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

Copy link
Member

@mehmetoguzderin mehmetoguzderin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a brief look and a minor question came to mind: was linear_indexing or linear_indices also considered as a name, given the technical nature of the specification? Apologies if this was already raised during the call and I missed the decision.

@alan-baker
Copy link
Contributor Author

I had a brief look and a minor question came to mind: was linear_indexing or linear_indices also considered as a name, given the technical nature of the specification? Apologies if this was already raised during the call and I missed the decision.

linear_indexing might be good. We didn't name on the call. I considered linear_indices, but wanted index specifically to match.

@mehmetoguzderin
Copy link
Member

Understood, linear_indexing might provide a reasonable balance. Thank you.

* Two new builtins:
  * `global_invocation_index` - linearized `global_invocation_id`
  * `workgroup_index` - linearized `workgroup_id`
@alan-baker alan-baker changed the title Add linear_indexes language feature Add linear_indexing language feature Feb 8, 2026
@jimblandy
Copy link
Contributor

I'll put this on the WGSL agenda once it comes out of draft.

@alan-baker
Copy link
Contributor Author

Draft CTS: gpuweb/cts#4595

@alan-baker alan-baker marked this pull request as ready for review February 17, 2026 04:18
Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with suggested wording tweaks, and optional notes.

[=built-in values/global_invocation_id=].x +<br>
([=built-in values/global_invocation_id=].y * [=attribute/workgroup_size=].x * [=built-in values/num_workgroups=].x) +<br>
([=built-in values/global_invocation_id=].z * [=attribute/workgroup_size=].x * [=built-in values/num_workgroups=].x * [=attribute/workgroup_size=].y * [=built-in values/num_workgroups=].y)
</table>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionally add a note here about overflow cases.

Note: If the number of workgroups in the dispatch would cause this index to exceed the range of the u32 type, then the dispatch will fail and invalidate the GPUComputePassEncoder.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the notes added and see what you think.

@alan-baker alan-baker requested a review from dneto0 February 26, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants