Skip to content

Add primitive-index feature and associated builtin#5273

Merged
toji merged 5 commits intogpuweb:mainfrom
toji:primitive_id
Aug 20, 2025
Merged

Add primitive-index feature and associated builtin#5273
toji merged 5 commits intogpuweb:mainfrom
toji:primitive_id

Conversation

@toji
Copy link
Copy Markdown
Member

@toji toji commented Jul 30, 2025

Adds the "primitive-id" feature, which enables the primitive_id WGSL builtin, to both the WebGPU and WGSL specs.

Fixes #1786

Copy link
Copy Markdown
Member

@dj2 dj2 left a comment

Choose a reason for hiding this comment

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

LGTM. Will leave it to Alan for approval.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 5, 2025

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

@toji
Copy link
Copy Markdown
Member Author

toji commented Aug 7, 2025

Thanks all! Just need WG approval at this point (I don't think we finalized that previously.)

@Kangz
Copy link
Copy Markdown
Contributor

Kangz commented Aug 8, 2025

Let's try to get approval offline: @teoxoy @jimblandy this is basically the same as WGPU's SHADER_PRIMITIVE_INDEX feature, would you be ok merging this in?

@teoxoy
Copy link
Copy Markdown
Member

teoxoy commented Aug 13, 2025

LGTM but should it be primitive_index instead of primitive_id? same as vertex/instance/sample ending in _index. We do use ID for some of the builtins and it seemed to me that it was for those that don't have a scalar type (with the only exception being the recent-ish subgroup_invocation_id).

@mwyrzykowski
Copy link
Copy Markdown

LGTM but should it be primitive_index instead of primitive_id? same as vertex/instance/sample ending in _index. We do use ID for some of the builtins and it seemed to me that it was for those that don't have a scalar type (with the only exception being the recent-ish subgroup_invocation_id).

Oh good observation, reading the relevant WGSL specification I am confused regarding when _id vs _index is used as it doesn't seem consistent. If we renamed subgroup_invocation_id to subgroup_invocation_index and also named this primitive_index then it would seem consistent as pointed out.

@toji
Copy link
Copy Markdown
Member Author

toji commented Aug 13, 2025

That's a really good point. I went with primitive_id because that's how it had initially been discussed and GLSL/HLSL/MSL all refer to it as "Primitive ID". They also use Vertex ID/Instance ID however, and we decided on the "Index" verbiage anyway, so I don't see any reason to break that pattern here.

I'm in favor of renaming to primitive_index, even if it means some minor refactoring Dawn/Chrome. :)

toji and others added 5 commits August 13, 2025 10:06
Adds the "primitive-id" feature, which enables the `primitive_id`
builtin, to the WebGPU and WGSL specs.

Fixes gpuweb#1786
Co-authored-by: dan sinclair <dj2@everburning.com>
@toji toji changed the title Add primitive-id feature and associated builtin Add primitive-index feature and associated builtin Aug 13, 2025
@kainino0x kainino0x added the wgsl WebGPU Shading Language Issues label Aug 15, 2025
@kainino0x
Copy link
Copy Markdown
Contributor

kainino0x commented Aug 15, 2025

I'm not a WGSL designer but in my mind, that canonical thing is called id, and then IF we need a linearized version of the id, then that is called index. So primitive_id and subgroup_invocation_id are consistent.

@toji
Copy link
Copy Markdown
Member Author

toji commented Aug 15, 2025

I'm not sure I understand the difference, in that case, between vertex_index, instance_index, and primitive_id. All of them are "linearized" ids, and canonically the vertex and instance versions are referred to as ID by the native APIs. (SPIR-V appears to be the outlier?) If we still choose to call them vertex_index and instance_index in WGSL then I'm not sure why primitive would be different?

Ultimately I'll ensure the spec change follows whatever the WGSL group decides, but it does seem like "index" would be the more consistent verbiage.

@mwyrzykowski
Copy link
Copy Markdown

I agree with @toji 's analysis. vertex_index, instance_index, and sample_index have no corresponding *_id equivalent.

The outlier then becomes subgroup_invocation_id - I'm not sure how much adoption of subgroups exists so far which would allow us to make a breaking change there for consistency

@kainino0x
Copy link
Copy Markdown
Contributor

Ah fair point, I missed that about vertex/instance.

I'm still a little unsure if this should be called an "index" since it's not an index into any actual array, but I don't feel strongly about that.

@mwyrzykowski
Copy link
Copy Markdown

Assuming index suffix means 'index into an array', then yes I think we should leave this as-is (primitive_id). Either naming is fine with me :)

@toji toji merged commit d191ad2 into gpuweb:main Aug 20, 2025
4 checks passed
@toji toji deleted the primitive_id branch August 20, 2025 17:56
@Kangz
Copy link
Copy Markdown
Contributor

Kangz commented Sep 2, 2025

GPU Web WG 2025-08-20 Atlantic-time
  • BJ: Primary rationale is that we have vertex_index and instance_index. Most things we call index even though native calls them IDs.
  • JB: Mozilla likes _index, and likes the proposal overall
  • MW: 👍
  • Consensus: Index.
  • KN: Are we good to land it after that?
  • (all): Yes. (PR already approved by google and apple)

juj added a commit to juj/wasm_webgpu that referenced this pull request Sep 12, 2025
kainino0x pushed a commit to gpuweb/types that referenced this pull request Sep 15, 2025
Following up on gpuweb/gpuweb#5273, this PR adds
the `"primitive-index"` GPUFeatureName.
kainino0x pushed a commit to webgpu-native/webgpu-headers that referenced this pull request Sep 16, 2025
Following up on gpuweb/gpuweb#5273, this PR adds
the `"primitive-index"` GPUFeatureName.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wgsl WebGPU Shading Language Issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for gl_PrimitiveID / SV_PrimitiveID -like construct?

7 participants