Specify immediate data API and WGSL <immediate> address space#5423
Specify immediate data API and WGSL <immediate> address space#5423shaoboyan091 wants to merge 20 commits intogpuweb:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for immediate data in WebGPU pipelines, allowing small amounts of data to be passed directly to shaders without requiring buffer bindings. This is useful for frequently changing small data like transformation matrices.
- Introduces
maxImmediateSizelimit (64 bytes) for immediate data ranges - Adds
immediateSizeparameter to pipeline layouts and validation for immediate data usage - Implements
setImmediateData()method for setting immediate data in encoders
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Previews, as seen when this build job started (fbde276): |
minutes from API committee meeting 2025-10-29
|
| <td>Invocations in the same [=shader stage=] | ||
| <td>[=access/read=] | ||
| <td>For [=immediate data=] variables.<br> | ||
| [=type/concrete|Concrete=] [=constructible=] [=host-shareable=] types, excluding arrays and structures containing array members.<br> |
There was a problem hiding this comment.
I agree with Alan here, the "Concrete ..." part is redundant, and should be removed.
alan-baker
left a comment
There was a problem hiding this comment.
Copying my other requests from #5424
There ought to be either a language feature or enable extension as part of this specification.
Additionally, there need to be some updates to the Resource Interface and Resource Layout Compatibility sections in the Entry Points chapter.
dneto0
left a comment
There was a problem hiding this comment.
I agree with other review comments. Once those are resolved I'm happy with this landing.
| <td>Invocations in the same [=shader stage=] | ||
| <td>[=access/read=] | ||
| <td>For [=immediate data=] variables.<br> | ||
| [=type/concrete|Concrete=] [=constructible=] [=host-shareable=] types, excluding arrays and structures containing array members.<br> |
There was a problem hiding this comment.
I agree with Alan here, the "Concrete ..." part is redundant, and should be removed.
Would prefer not using an enable extension since this is supported or can be easily emulated by all core devices (and compat too I think). I.e., WGSL language extension would be my preference. |
|
I can't make the meeting today but this is 👍 from Apple's side. Metal doesn't have the concept of immediates and there was some discussion about this taking up a buffer slot. If the UA is using argument buffers then it would not, since a slot is already needed for dynamic data and you can reuse / share the same slot for immediates. Basically any transient data (dynamic offsets, immediates, other constants) can be passed in a single call to set[Vertex/Fragment]Bytes. But we are also fine with this taking up a slot. This allows UAs to not have to migrate to ABs for everything for their Metal backends. I suppose its a tradeoff but either way is 👍 from Apple's side given our AB implementation is not really impacted either way. |
minutes from WGSL committee meeting 2025-11-4
|
@amaiorano is implementing this speculatively in Dawn, we are going with |
That works, but I'd also be ok with just |
Update index.bs to include the new <immediate> address space. Ref to proposal: immediate-data.md.
Co-authored-by: alan-baker <alanbaker@google.com>
Co-authored-by: alan-baker <alanbaker@google.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
They are their own thing in the shader interface, similar to override declarations
|
@jimblandy Done. Added "immediate data" to both sentences in the executeBundles() paragraph: "does not inherit the render pass's pipeline, bind groups, immediate data, or vertex and index buffers" |
kainino0x
left a comment
There was a problem hiding this comment.
I will reread the whole PR one more time when I have a moment but I think this looks good
Co-authored-by: Kai Ninomiya <kainino1@gmail.com>
|
I see |
|
@mooflu From implementation part, it is hard to expand to 128 bytes(as default limits) :(. We have some internal reserved push constants in implementation so we cannot expose all range as customer immediates. From spec view, we defined P.S. |
kainino0x
left a comment
There was a problem hiding this comment.
Final editorial review, finally!
Co-authored-by: Kai Ninomiya <kainino1@gmail.com>
|
@jimblandy Would you mind to do a final review for this? |
| Values are set by {{GPUBindingCommandsMixin/setImmediates()}}. | ||
|
|
||
| : <dfn>\[[immediate_data_set]]</dfn>, of type [=list=]<{{boolean}}> | ||
| : <dfn>\[[immediate_slots_set ]]</dfn>, of type [=list=]<{{boolean}}> |
There was a problem hiding this comment.
nit: Extra space in this dfn name
|
@jimblandy would you mind to take a look again on this spec PR? |
Landing the immediate data API specification into the WebGPU spec. Ref to proposal: immediate-data.md.