You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Théo Monnom, David A Roberts, FishHawk, Dunfan Lu, Neil Sarkar, André Furchner, Aura Munoz, Guodong Chen, Stefan Devai, tigertang and 14 more
What are the expectations for the index into the array? Can it be anything, or must it be "dynamically uniform", i.e. dependent only on values that are derived from uniforms only?
In WGSL, how are we able to access a single texture in an array of textures? A binding such as this seems valid:
[[group(1), binding(0)]] var textures: array<texture_2d<f32>, 2>;
However, any attempt to access an index via textures[n] throws various compiler errors. Is there some special array access notation or am I just missing something?
The texture arrays example only has glsl shaders, and I couldn't find info about this in the spec other than the basic array notation syntax.
Edit:This non-uniform shader is the one I'm interested in writing in WGSL. That "flat" specifier also seems to cause errors everywhere I've tried to place it.
I remember that we had a resolution in the group to not allow arrays of textures (as distinct from texture arrays) in the first version of the language, because of uniformity rules. Texture arrays are allowed, though.
I did see that this was supported by wgpu on native with certain extensions. But you're saying there's currently no valid syntax for working with an array of textures in WGSL?
I think you're referring to bindless, and that hasn't been discussed for WebGPU at this point. Because the API doesn't support bindless (even as an extension), it doesn't make sense to add support for it in WGSL. Experimental syntax can be added to wgpu-rs / Naga though.
I'm not sure what "bindless" means tbh 👀, but to clarify, is it correct to say there's no way to achieve dynamic non-uniform texture indexing/sampling in WGSL at this point? Like those example shaders cannot be converted to WGSL yet?
You should be able to use conditionals to choose dynamically between branches that sample different textures (or perhaps even assign different textures into a pointer variable?). But we don't have a way to bind arrays of textures at the API surface, so you still have to have a separate binding point for each texture.
@kainino0x I had trouble taking that approach because, when compiling my shader, it apparently violated some non-uniformity restriction to selectively use a texture based on an in var from the vertex shader. So I ended up just rolling with a texture atlas.
Not sure if the support was added to WGSL after this issue, but textureSample and textureSampleLevel both allow you to specify the array layer index when using texture_2d<f32>.
2.12.1 Arrays of Textures, Texture Buffers, and Samplers
iOS: Arrays of textures supported since Metal 1.2; arrays of samplers since Metal 2; arrays of
texture buffers since Metal 2.1.
macOS: Arrays of textures supported since Metal 2; arrays of samplers since Metal 2; arrays of
texture buffers since Metal 2.1.
KR: haven't thought about this for a month, but Gregg pointed out that we need this for feature parity for WebGL. Can't expand out arrays of textures into single individual texture bindings.
JB: is this easier for textures?
KN: think it's a hardware feature.
GT: think you'll need arrays of samplers too for feature parity with WebGL, since in WebGL they're combined.
JB: next steps - figure out what this looks like in backends.
KN: not sure how you do this in Vk. Vk has dynamic indexing features for various things… Oh: Vk spec says, shaderSampledImageArrayDynamicIndexing provides both samplers and textures. So yes, we should bundle these together too.
JB: for WebGL parity, sounds important, so let's pick this up in the next meeting.
DN: Think it’s important gap in functionality now. Coupled to sketching design of array of buffer bindings. Have design issues with uniformity of indexing, but let’s keep that to design.
Any updates on the issue?
WebGPU is the only graphics API in existence that does not support array of resources.
While dynamically indexing resources may be involved (though all modern graphics APIs do support it), statically indexing resources should not be a problem and is supported supported in GLES1.0 and WebGL1.0.
Reacted by Mikhail Gorobets, Pietro Paolo Vismara, Schell Carl Scivally, martfunkel, Valentin Milea, Andrew Zhu Aday, Akio Gaule, rcelyte, Tarkan Sarıtaş, orange soeur and 4 more
Wanted to bump this as well. Bindless techniques are pretty common these days for writing GPU driven renderers and it's kind of a bust to not have arrays of textures support. I can be sort of faked by writing image data into storage buffers but then sampler filtering goes out the window and you have to roll out your own filtering solutions in a shader. Would love to know if there's any headway on this. I have no idea what the bureaucracy of open source standards is like 😅
This issue is not for bindless arrays of textures and buffers (that would be #380), only for fixed-size, bindfull arrays. We'd love to have bindless one day and it's something that's very likely to happen, but the amount of work to make it happen is massive so we aren't entertaining starting it until WebGPU is shipped everywhere.
Oh nice, didn't know there was a separate issue for it! Given that it possibly has a simpler roadmap, statically size bindfull arrays of textures or buffers can give us a sort of starting point for custom bindless implementations (i.e. single global bind group created ahead of time with large arrays of textures and buffers that can be modified on the fly, without recreating bind groups), which is I guess why I'm more interested in this issue for the time being. It seems more tractable and still sort of gives graphics programmer the power of "custom" bindless (albeit not the truest form of bindless).
CW: add an array size in the bind group; it’s inline with binding numbers (not a separate index like in Vulkan). On the WGSL side, there’s a new array type binding_array<type, number> (constant or override). And array indexing. The validation you would expect.
CW: What do we do with a GPU external texture. It’s a composite of bindings. WGSL could do a structure of arrays;
CW: Texel buffers could be supported.
CW: Question about uniformity of indexing. There’s some Vulkan HW which only allows constant indices. Worked around in ANGLE with a giant switch. I think we should support uniform indexing of every binding type. Question is should we support nonuniform indexing.
JSP: No preference on nonuniform. Can wait for bindless if we have to.
JSP: 1. Do we support the thing with dynamic offsets into these arrays.
CW: No.
JSP: Can you explain the binding number tithing. Can I put texture in binding0, then storage buffer starting at 10 to 20.
CW: Bindgropus can have holes. So that’s ok.
CW: Vulkan has a 3D binding model, but here I suggest we flatten it, collapse the array entries as individual binding numbers.
JSP: SGTM.
BJ: Unlike bindless proposal these don’t have to be last in the bind group.
CW: Right. And you can have multiple fixed size arrays in the bindgroup.
BJ: So basically this is syntactic sugar over having a bunch of individual bindings. Advantage is you get to index them in the shader.
CW: Yes.
AB: Looking at your GL hack again, GL couldn’t do storage buffers and things like that. How you’d want to do this in SPIR-V is you’d want to return a pointer, and then you need varaiblePointers. So maybe you have to specialize these functions (inlining etc.) to a great extent, which might get ugly. What’s allowed in base vulkan is arrays of textures.
CW: Let’s check gpuinfo for arrays of storage buffers; i think it doesn’t remove any devices. For nonuniform indexing it doesn’t remove many devices.
AB: Each nonuniform indexing is its own bit per resource type.
JSP: If I say I have 10 textures in the array I have to bind all of them.
CW: yes.
CW: We have to check availability in Vulkan: when they allow uniform indexing of these; try nonuniform indexing later.
KR: There were different rules for 1 and 2. 2 was restricted. Caused problems upgrading 1 to 2.
GT: Does the switch statement break derivatives?
KN: It works because you assume the index is uniform.
CW: Want to get agreement on direction.
JSP +1
JB: +1
TT: How prevalent is this feature. It’s not in Vulkan core.
CW: It’s in core in Vulkan.
KG: The only reason we punted on it before was because it was work.
JSP: you already have that WGSL language feature in wgpu.
CW: ok, sounds like we land the proposal doc, then check Vulkan coverage of uniform indexing, and go with that for now.
Activity
krogovin commentedon Aug 21, 2020
What are the expectations for the index into the array? Can it be anything, or must it be "dynamically uniform", i.e. dependent only on values that are derived from uniforms only?
kvark commentedon Aug 21, 2020
wgpuon native exposes the restrictions on the index as different extra features:cc @cwfitzgerald
jozanza commentedon Mar 7, 2021
In WGSL, how are we able to access a single texture in an array of textures? A binding such as this seems valid:
However, any attempt to access an index via
textures[n]throws various compiler errors. Is there some special array access notation or am I just missing something?The texture arrays example only has glsl shaders, and I couldn't find info about this in the spec other than the basic array notation syntax.
Edit: This non-uniform shader is the one I'm interested in writing in WGSL. That "flat" specifier also seems to cause errors everywhere I've tried to place it.
litherum commentedon Mar 7, 2021
I remember that we had a resolution in the group to not allow arrays of textures (as distinct from texture arrays) in the first version of the language, because of uniformity rules. Texture arrays are allowed, though.
jozanza commentedon Mar 7, 2021
I did see that this was supported by wgpu on native with certain extensions. But you're saying there's currently no valid syntax for working with an array of textures in WGSL?
Kangz commentedon Mar 8, 2021
I think you're referring to bindless, and that hasn't been discussed for WebGPU at this point. Because the API doesn't support bindless (even as an extension), it doesn't make sense to add support for it in WGSL. Experimental syntax can be added to wgpu-rs / Naga though.
kvark commentedon Mar 8, 2021
Correct, we'll need to work on WGSL syntax for this internally (prototyping in Naga), and then potentially returning to the group with a proposal.
jozanza commentedon Mar 8, 2021
Thanks for the comments!
I'm not sure what "bindless" means tbh 👀, but to clarify, is it correct to say there's no way to achieve dynamic non-uniform texture indexing/sampling in WGSL at this point? Like those example shaders cannot be converted to WGSL yet?
kvark commentedon Mar 8, 2021
That's correct, yes. At least, not in the "standard" WGSL.
kainino0x commentedon Mar 9, 2021
You should be able to use conditionals to choose dynamically between branches that sample different textures (or perhaps even assign different textures into a pointer variable?). But we don't have a way to bind arrays of textures at the API surface, so you still have to have a separate binding point for each texture.
jozanza commentedon Mar 10, 2021
@kainino0x I had trouble taking that approach because, when compiling my shader, it apparently violated some non-uniformity restriction to selectively use a texture based on an in var from the vertex shader. So I ended up just rolling with a texture atlas.
kainino0x commentedon Mar 11, 2021
Got it. I think it should* be valid if the conditional is uniform, but otherwise it will not be.
* I don't know if the uniformity rules are actually written out yet, but ultimately I think this will be the case.
aloucks commentedon Dec 31, 2021
Not sure if the support was added to WGSL after this issue, but
textureSampleandtextureSampleLevelboth allow you to specify the array layer index when usingtexture_2d<f32>.25 remaining items
kainino0x commentedon Nov 2, 2023
Similarly in Vulkan 1.2:
greggman commentedon Nov 2, 2023
From the metal docs
jimblandy commentedon Nov 2, 2023
Agenda / Minutes for GPU Web meeting 2023-11-01
kdashg commentedon Dec 6, 2023
WGSL 2023-12-05 Minutes
TheMostDiligent commentedon Jun 24, 2024
Any updates on the issue?
WebGPU is the only graphics API in existence that does not support array of resources.
While dynamically indexing resources may be involved (though all modern graphics APIs do support it), statically indexing resources should not be a problem and is supported supported in GLES1.0 and WebGL1.0.
gitbetter commentedon Jun 27, 2024
Wanted to bump this as well. Bindless techniques are pretty common these days for writing GPU driven renderers and it's kind of a bust to not have arrays of textures support. I can be sort of faked by writing image data into storage buffers but then sampler filtering goes out the window and you have to roll out your own filtering solutions in a shader. Would love to know if there's any headway on this. I have no idea what the bureaucracy of open source standards is like 😅
Kangz commentedon Jun 27, 2024
This issue is not for bindless arrays of textures and buffers (that would be #380), only for fixed-size, bindfull arrays. We'd love to have bindless one day and it's something that's very likely to happen, but the amount of work to make it happen is massive so we aren't entertaining starting it until WebGPU is shipped everywhere.
gitbetter commentedon Jun 27, 2024
Oh nice, didn't know there was a separate issue for it! Given that it possibly has a simpler roadmap, statically size bindfull arrays of textures or buffers can give us a sort of starting point for custom bindless implementations (i.e. single global bind group created ahead of time with large arrays of textures and buffers that can be modified on the fly, without recreating bind groups), which is I guess why I'm more interested in this issue for the time being. It seems more tractable and still sort of gives graphics programmer the power of "custom" bindless (albeit not the truest form of bindless).
Add a proposal for sized-binding-arrays
Kangz commentedon Nov 19, 2024
GPU Web WG 2024-10-29/30 Mountain View F2F
binding_array<type, number> (constant or override). And array indexing. The validation you would expect.Kbz-8 commentedon May 18, 2025
Any updates ? This issue has been opened for 5 years on a feature that even WebGL 1.0 supports
Kangz commentedon May 19, 2025
This is actively being worked on, see https://github.com/gpuweb/gpuweb/blob/main/proposals/sized-binding-arrays.md a number of related issues.