Repository navigation
Open
Labels
wgslWebGPU Shading Language Issues
Milestone
Description
We need a sensible design for supporting arrays-of-buffers
Arrays-of-bindings (for buffers) are an important newer feature of APIs, supporting a bindless style.
These can't be included in WebGPU 1.0, but the language design for that future feature may influence the 1.0 language.
So this is tagged for "1.0" for now.
This discussion builds on the two solutions so far for #1534:
- wgsl: replace stride attribute with array type parameter #2103: replace stride attribute with array type parameter, and declare fixed-size arrays and runtime-sized arrays with two different type keywords
- Remove block attribute #2104: replace 'block' attribute with a defined term 'buffer root' (debatable on exactly whether this is the right solution).
- In part, defining a 'buffer root' was motivated by the desire to design for array-of-bindings.
What Vulkan has
- Vulkan supports a single-dimensional array of buffers.
* Vulkan’s main feature bit: descriptorIndexing, and fine grain features in VkPhysicalDeviceDescriptorIndexingFeatures - Each element of the array corresponds to a descriptor binding point. The 0th element maps to the given descriptorSet and binding attribute, and binding numbers increase by 1 for each successive array element.
- Indexing into these is limited, by default, with opt-in extra features:
- Indexing by a SPIR-V constant expression
- Indexing by a dynamically computed but still uniform value
- Indexing by a dynamically computed value, not necessarily uniform.
- Indexing into these is limited, by default, with opt-in extra features:
- An extra feature is to allow a runtime-sized array of these descriptors. see the
runtimeDescriptorArraysubfeature in VkPhysicalDeviceDescriptorIndexingFeatures - Note: The design below does not contemplate these gradations of functionality.
Design sketch: arrays of buffers for WGSL
Key idea, while avoiding a block attribute: mark the container to say its elements are buffer-roots.
This covers both sized-arrays of buffers and dynamically-sized arrays of buffers.
Observations/questions about arrays of buffers
- Layout does not make sense, since it’s not contiguous storage.
- Perhaps stride does not apply: no [[stride(N)]] attribute, or stride parameterization of the array type?
- Are the array types constructible?
- What if the same type is used for array-of-buffer and internally?
- Perhaps allow them to be “constructible”, but limit what operations can be done on them, based on buffer-array variable concept, as below.
- Maybe it’s not really about the type, but about its use for a buffer-array variable.
- Principle: Allow reuse of a structure type for other things.
- This is allowed in options 0 and 4a.
Syntax and inference
Below are several options for how buffer-arrays are spelled out in WGSL source.
struct B {
a: i32;
data: array<f32>;
};
[[group(0),binding(0)]]
var<storage> single: B;
/*
Option 0: Don't have syntax. Implicit all the way down.
Idea:
- Infer the fact that these are buffer-array variables from the fact that
they are variables in the uniform or storage storage class, and are
arrays around a struct.
- Least fuss for users. Not much more work for tooling.
*/
[[group(1),binding(0)]] var<storage> sized: array<B,10>;
[[group(2),binding(0)]] var<storage> dynsized: dynamic_array<B>;
/*
Option 4b: Different syntax keyword for introducing the type.
4b: Different words.
But is it dynamic_buffer_array (more logical)
or buffer_dynamic_array (looks more composed, i.e. "just add dynamic_ before array"
*/
[[group(1),binding(0)]] var<storage> sized: buffer_array<B,10>;
[[group(2),binding(0)]] var<storage> dynsized: dynamic_buffer_array<B>;
/*
Option 5: Alternate syntax for struct to indicate it's only usable for a binding.
Some spec overhead, but also clearly delineates what can and cannot be done.
*/
block ssbo_interface {
x : dynamic_array<f32>;
};
[[group(0), binding(0)]] var<storage> sized : array<ssbo_interface, 8>;
[[group(0), binding(1)]] var<storage> dynsized : dynamic_array<ssbo_interface>;
Reacted by Théo Monnom
Metadata
Metadata
Assignees
Labels
wgslWebGPU Shading Language Issues
Type
Projects
- StatusShow more project fieldsTodo
Activity
kainino0x commentedon Sep 14, 2021
I think it's best to leave open the possibility of not requiring every binding to be a struct, but instead allowing arbitrary storable types to be used as buffer-roots. For example:
var<storage> data: i32;var<storage> data: MyStruct;var<storage> data: array<i32, 5>;var<storage> data: array<MyStruct, 5>;I think option 0 closes it, unless modified to add an annotation specifying it's an array, e.g.
[[group(0), binding_array_start(0)]] var<storage> data: array<MyStruct, 5>;or
[[group(0), binding(0), binding_array]] var<storage> data: array<MyStruct, 5>.FWIW I'm pretty sure bindings arrays need to extend to textures as well. This would work there too:
[[group(0), binding_array_start(0)]] var texs: array<texture_2d<f32>, 5>;[[group(0), binding_array_start(0)]] var texs: array<texture_2d_array<f32>, 5>;or with 4b:
[[group(0), binding(0)]] var texs: array_of_texture_2d<f32>;[[group(0), binding(0)]] var texs: array_of_texture_2d_array<f32>; // lolkvark commentedon Sep 14, 2021
Anybody explain to me why we have Options: 0, 4b, and 5?
One option that is missing here is:
[[block]].[[block]]are considered binding arrayskainino0x commentedon Sep 14, 2021
We had an internal doc that loosely brainstormed a bunch of different possible syntaxes with smallish differences. These three were the contenders to start discussion from, but kept the numbering.
Or could be
[[block]] array<...>dneto0 commentedon Dec 8, 2021
Other discussions have progressed:
That essentially eliminates options 0 and 5.
So this points to having something along the lines of 4: special syntax to indicate it's an binding array.
I hear there's discussion about arrays of textures and samplers also, so we can aim for something general, e.g
binding_array<T,N>declares an array of bindings, where each binding contains a T.dneto0 commentedon Dec 8, 2021
Should extend the example:
Base Vulkan/SPIR-V functionality restricts the indexing into such arrays (e.g. must be uniform value) so it's useful to consider them their own type, so we have a hook to hang the restriction on.
dneto0 commentedon Mar 8, 2022
I think we have good options for adding this feature after v1 ships.
It's a fundamental feature, so at very worst we can add an
enable, which allows us to use whatever syntax makes sense.Recommend pushing out of v1 milestone. I think I put it in v1 when i was concerned about implications for removing the
blockandstrideattributes. Those have been solved.kdashg commentedon Mar 9, 2022
WGSL meeting minutes 2022-03-08
dneto0 commentedon Sep 27, 2023
Related: #822 is about support for arrays of textures. That has some discussion of syntax.
I'm tempted to close this issue in favour of that one, as long as the solution there generalizes to other bound resource kinds.
kdashg commentedon Nov 28, 2023
WGSL 2023-11-28 Minutes
kdashg commentedon Dec 6, 2023
WGSL 2023-12-05 Minutes
devshgraphicsprogramming commentedon Jan 26, 2025
How about a BDA-like-API emulation? Since it seems the WebGPU API will always be playing catch-up to Vulkan, Metal and DX12 so may as well skip the immediate teething pain step of each of those APIs which are arrays of buffers and progress straight onto
uint64_tvirtual addresses.In DX12 one could emulate Vulkan's BDA via an array of
ByteAddressBuffers in special (hidden/reserved) global (instance/context wide) descriptor set where you'd use the lower 32 bits of theuint64_tto denote a byte and the upper to denote theByteAddressBufferyou'd use (or one can do theuvec2BDA shenanigans GLSL/SPIR-V allow for the exotic GPUs without uint64_t support).Then any buffer you'd make with the
DEVICE_ADDRESSusage would be allocated a slot in such reserved descriptor array.Obvioulsy this means
nonUniformEXTaround every bufffer load/store, but you'd get the range checks and robustness behaviour you'd usually have with SSBOs.P.S. Ofc if Metal and/or VK ever get robust BDA, you could implement the whole thing as "just BDA".
jimblandy commentedon Feb 9, 2026
I think this design work will be subsumed by the bindless effort. Do we really want to add this as a distinct feature before bindless lands?
dneto0 commentedon Feb 10, 2026
Moved to M3, per agreement in WGSL meeting 2026-02-10
jimblandy commentedon Feb 11, 2026
minutes from WGSL committee meeting 2026-2-10