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
resource arrays - Support for arrays of textures #822. In Vulkan, these occupy a single binding, using another dimension in the binding space - the array dimension. In D3D and Metal (argument buffers), the arrays are placed continuously into the binding space. Bindings are currently unlimited.
shader input/output being arrays or matrices (internally between stages)
For each of these, we can make a decision to either allocate consecutive indices (starting with the one that user specified), or shadow-allocate the locations/bindings internally. The former would be consistent with native APIs. The latter is possible if the implementations have to re-map all the bindings (and/or locations) anyway.
It would be good if our story on the subject was consistent.
We talked about this a bit on the editors call. One of the concerns raised was - if we have to remap binding indices, then it becomes problematic to generate SPIR-V at shader module creation time. We'd either have to drop it, and only generate SPIR-V at pipeline creation time, or do some raw number patching after SPIR-V is generated. We could also take advantage of the hint in #1064, but it's still more complicated than it is today (so less preferred).
Matrices and arrays of scalars / resources being represented as multiple locations makes sense so that there is a way to uniquely identify the various parts of the interface variable. (so you can bind multiple vec4 attributes to the various columns / rows of a matrix). However external textures are a completely opaque object and the application can't access or set the various parts of an external_texture binding individually. So I don't think they should count for multiple locations.
Binding indices are not bounded at the moment and can be any u32 and I don't think we should make them bounded (because it's useful to devs to pick arbitrary numbers). All implementations on Vulkan will need to do some kind of remapping because values like UINT32_MAX will cause issues in drivers with integer overflows and other fun stuff (we've found such an issue in Swiftshader). Also Vulkan allows drivers to make VkDescriptorSet use O(max binding index) memory and not only O(number of binding points).
In Chromium we are not looking at generating the SPIR-V at shader module creation time, same as other backends. Instead of "raw number patching" Firefox could delay the emission of only the bindings part of SPIRV emission if it care about the cost of emitting SPIR-V.
Since we don't support matrices as attributes right now, it's up to us to determine if it's even possible to see a matrix attribute as individual vectors on the shader side. Arguably, the user can always just access columns of the matrix, instead, in which case it's all one single binding, just like the external texture.
I don't like the idea of forcing the implementations to remap binding indices. This is too restricting, and the only benefit we gain - arbitrary indices - is one that isn't even present in any of the native APIs. So this part is confusing - why are we sacrificing implementation complexity for functionality that isn't expected today in native APIs? We'd be fine just telling the same story as Vulkan - you can use arbitrary indices but expect that higher indices will have proportionally longer processing times.
The problem with SPIR-V generation can't really be worked around. The fact that we can't generate SPIR-V right away is one thing. Naga can do it pretty quickly on the spot. But there is also the fact we can't call vkCreateShaderModule early, and that is rather limiting.
Since we don't support matrices as attributes right now, it's up to us to determine if it's even possible to see a matrix attribute as individual vectors on the shader side. Arguably, the user can always just access columns of the matrix, instead, in which case it's all one single binding, just like the external texture.
We could choose to do that, but then to map to underlying APIs we would need to make matrix attribute types take multiple vertex attribute slots. Not a big deal but it would be a leaky abstraction.
I don't like the idea of forcing the implementations to remap binding indices. This is too restricting, and the only benefit we gain - arbitrary indices - is one that isn't even present in any of the native APIs. So this part is confusing - why are we sacrificing implementation complexity for functionality that isn't expected today in native APIs?
Register numbers in D3D12 are arbitrary as far as I can tell, and technically Vulkan has arbitrary binding numbers although the spec doesn't guarantee anything about the memory use. I think it is convenient for developers to have arbitrary numbers. Of course they should never use UINT32_MAX in practice but splitting various types of bindings with large number gaps is useful.
I don't understand the pushback here: isn't wgpu required to renumber bindings for D3D12 and non-argument-buffer Metal anyway? I'm sure some wgpu contributors could hammer the remapping in days.
The problem with SPIR-V generation can't really be worked around. The fact that we can't generate SPIR-V right away is one thing. Naga can do it pretty quickly on the spot. But there is also the fact we can't call vkCreateShaderModule early, and that is rather limiting.
That's not a concern for Chromium, as described extensively in #1064 I don't think it's practical to take as a design constraint that we must produce the underlying shader module object at shader module creation time.
We could choose to do that, but then to map to underlying APIs we would need to make matrix attribute types take multiple vertex attribute slots. Not a big deal but it would be a leaky abstraction.
If it's all opaque to the user (i.e. with us remapping attribute locations anyway), then it's no more leaky than the external texture stuff.
Register numbers in D3D12 are arbitrary as far as I can tell,
They are arbitrary in the shader, because the user has to remap them in the root signature, anyway. So the remapping is explicit and controlled by the user, which isn't the case for us.
I.e. one could argue that the users are free to do their own remapping if that's convenient for them (just like they are forced to do in D3D12).
I don't understand the pushback here: isn't wgpu required to renumber bindings for D3D12 and non-argument-buffer Metal anyway? I'm sure some wgpu contributors could hammer the remapping in days.
wgpu does the re-mapping from Vulkan style bindings to D3D12 and Metal, and this is done in the backends, internally. It does no remapping on Vulkan. What you are talking about is remapping at WebGPU implementation level, backend-independent. For us it means:
extra work that will unlikely interest any external contributors
duplication of responsibilities between wgpu and gfx
inability to produce VkShaderModule early
These all don't sound particularly exciting to me, for something that people aren't expecting to get in native, anyway.
That's not a concern for Chromium, as described extensively in #1064 I don't think it's practical to take as a design constraint that we must produce the underlying shader module object at shader module creation time.
I don't understand why we'd be dropping the idea of generating VkShaderModule on the floor without even seeing how it performs. I'd rather have a design that allows an implementation goes either way, and then we can narrow it down when we have more data on how it performs (e.g. with MVP feedback). Also kinda fun to point to #1064 without specifying a concrete comment in there :)
If it's all opaque to the user (i.e. with us remapping attribute locations anyway), then it's no more leaky than the external texture stuff.
The key difference is that in the external texture case there is no way to make what's inside useful to the developer because its shape can change, but on the other side for matrices, there is technically some flexibility they could gain for example by sourcing it from different buffers (even if it is probably a bad idea).
wgpu does the re-mapping from Vulkan style bindings to D3D12 and Metal, and this is done in the backends, internally. It does no remapping on Vulkan. What you are talking about is remapping at WebGPU implementation level, backend-independent.
Sorry, but this seems like an implementation detail.
Except the part about early VkShaderModule compilation and #1064 gives a hint you can use, plus in that issue all of my comments are about why it's not practical to ask compilation to backend languages to happen at createShaderModule since 1) caching and async pipeline creation at load time gets us a long way 2) more than just the layout will be needed as implementations mature.
The key difference is that in the external texture case there is no way to make what's inside useful to the developer because its shape can change, but on the other side for matrices, there is technically some flexibility they could gain for example by sourcing it from different buffers (even if it is probably a bad idea).
Since it's a bad idea, we shouldn't allow it. And if we don't allow it, then the whole point of "no way to make what's inside useful to the developer" doesn't stand any more.
I don't understand the pushback here: isn't wgpu required to renumber bindings for D3D12 and non-argument-buffer Metal anyway? I'm sure some wgpu contributors could hammer the remapping in days.
wgpu does the re-mapping from Vulkan style bindings to D3D12 and Metal, and this is done in the backends, internally. It does no remapping on Vulkan. What you are talking about is remapping at WebGPU implementation level, backend-independent.
Sorry, but this seems like an implementation detail.
You inquired about the pushback, and I explained the pushback. We have to weight API decisions based on the implementations costs, and re-mapping bindings affects them non-trivially for us (among other things).
A better compromise would be to just apply a similar scheme to #1720 for bindings: saying that binding is basically u16. That, in addition to allocating bindings linearly for things like external texture, would allow implementations to not do any remapping if they want to. Consequently, it would allow VkShaderModule creation early.
I think I agree with the logic at #1652. Can we defer these questions until after MVP, until the point the group decides these features should be pursued?
external texture taking multiple bindings
I see no reason why the bindings for this should have to be consecutive.
Can we defer these questions until after MVP, until the point the group decides these features should be pursued?
This issue isn't pushing to add the arrays of resources (for example) to MVP. It just tries to take a cohesive look at features we want to see, so that the API is developed consistently. If today we have external texture taking 1 explicit binding plus a few hiddnen, and tomorrow we have a resource array taking N consecutive bindings, explicitly, wouldn't this be inconsistent?
I don't think it would be particularly inconsistent for external textures to use a different binding mechanism than arrays of resources. Those seem like different beasts to me.
Activity
kvark commentedon May 17, 2021
We talked about this a bit on the editors call. One of the concerns raised was - if we have to remap binding indices, then it becomes problematic to generate SPIR-V at shader module creation time. We'd either have to drop it, and only generate SPIR-V at pipeline creation time, or do some raw number patching after SPIR-V is generated. We could also take advantage of the hint in #1064, but it's still more complicated than it is today (so less preferred).
Kangz commentedon May 18, 2021
Matrices and arrays of scalars / resources being represented as multiple locations makes sense so that there is a way to uniquely identify the various parts of the interface variable. (so you can bind multiple vec4 attributes to the various columns / rows of a matrix). However external textures are a completely opaque object and the application can't access or set the various parts of an
external_texturebinding individually. So I don't think they should count for multiple locations.Binding indices are not bounded at the moment and can be any
u32and I don't think we should make them bounded (because it's useful to devs to pick arbitrary numbers). All implementations on Vulkan will need to do some kind of remapping because values likeUINT32_MAXwill cause issues in drivers with integer overflows and other fun stuff (we've found such an issue in Swiftshader). Also Vulkan allows drivers to makeVkDescriptorSetuse O(max binding index) memory and not only O(number of binding points).In Chromium we are not looking at generating the SPIR-V at shader module creation time, same as other backends. Instead of "raw number patching" Firefox could delay the emission of only the bindings part of SPIRV emission if it care about the cost of emitting SPIR-V.
kvark commentedon May 18, 2021
Since we don't support matrices as attributes right now, it's up to us to determine if it's even possible to see a matrix attribute as individual vectors on the shader side. Arguably, the user can always just access columns of the matrix, instead, in which case it's all one single binding, just like the external texture.
I don't like the idea of forcing the implementations to remap binding indices. This is too restricting, and the only benefit we gain - arbitrary indices - is one that isn't even present in any of the native APIs. So this part is confusing - why are we sacrificing implementation complexity for functionality that isn't expected today in native APIs? We'd be fine just telling the same story as Vulkan - you can use arbitrary indices but expect that higher indices will have proportionally longer processing times.
The problem with SPIR-V generation can't really be worked around. The fact that we can't generate SPIR-V right away is one thing. Naga can do it pretty quickly on the spot. But there is also the fact we can't call
vkCreateShaderModuleearly, and that is rather limiting.Kangz commentedon May 18, 2021
We could choose to do that, but then to map to underlying APIs we would need to make matrix attribute types take multiple vertex attribute slots. Not a big deal but it would be a leaky abstraction.
Register numbers in D3D12 are arbitrary as far as I can tell, and technically Vulkan has arbitrary binding numbers although the spec doesn't guarantee anything about the memory use. I think it is convenient for developers to have arbitrary numbers. Of course they should never use
UINT32_MAXin practice but splitting various types of bindings with large number gaps is useful.I don't understand the pushback here: isn't wgpu required to renumber bindings for D3D12 and non-argument-buffer Metal anyway? I'm sure some wgpu contributors could hammer the remapping in days.
That's not a concern for Chromium, as described extensively in #1064 I don't think it's practical to take as a design constraint that we must produce the underlying shader module object at shader module creation time.
kvark commentedon May 18, 2021
If it's all opaque to the user (i.e. with us remapping attribute locations anyway), then it's no more leaky than the external texture stuff.
They are arbitrary in the shader, because the user has to remap them in the root signature, anyway. So the remapping is explicit and controlled by the user, which isn't the case for us.
I.e. one could argue that the users are free to do their own remapping if that's convenient for them (just like they are forced to do in D3D12).
wgpudoes the re-mapping from Vulkan style bindings to D3D12 and Metal, and this is done in the backends, internally. It does no remapping on Vulkan. What you are talking about is remapping at WebGPU implementation level, backend-independent. For us it means:VkShaderModuleearlyThese all don't sound particularly exciting to me, for something that people aren't expecting to get in native, anyway.
I don't understand why we'd be dropping the idea of generating
VkShaderModuleon the floor without even seeing how it performs. I'd rather have a design that allows an implementation goes either way, and then we can narrow it down when we have more data on how it performs (e.g. with MVP feedback). Also kinda fun to point to #1064 without specifying a concrete comment in there :)Kangz commentedon May 19, 2021
The key difference is that in the external texture case there is no way to make what's inside useful to the developer because its shape can change, but on the other side for matrices, there is technically some flexibility they could gain for example by sourcing it from different buffers (even if it is probably a bad idea).
Sorry, but this seems like an implementation detail.
Except the part about early
VkShaderModulecompilation and #1064 gives a hint you can use, plus in that issue all of my comments are about why it's not practical to ask compilation to backend languages to happen atcreateShaderModulesince 1) caching and async pipeline creation at load time gets us a long way 2) more than just the layout will be needed as implementations mature.kvark commentedon May 19, 2021
Since it's a bad idea, we shouldn't allow it. And if we don't allow it, then the whole point of "no way to make what's inside useful to the developer" doesn't stand any more.
You inquired about the pushback, and I explained the pushback. We have to weight API decisions based on the implementations costs, and re-mapping bindings affects them non-trivially for us (among other things).
A better compromise would be to just apply a similar scheme to #1720 for bindings: saying that
bindingis basicallyu16. That, in addition to allocating bindings linearly for things like external texture, would allow implementations to not do any remapping if they want to. Consequently, it would allowVkShaderModulecreation early.Kangz commentedon May 20, 2021
This would likely be fine for us as it doesn't lose developer flexibility.
litherum commentedon May 28, 2021
I think I agree with the logic at #1652. Can we defer these questions until after MVP, until the point the group decides these features should be pursued?
I see no reason why the bindings for this should have to be consecutive.
kvark commentedon May 28, 2021
This issue isn't pushing to add the arrays of resources (for example) to MVP. It just tries to take a cohesive look at features we want to see, so that the API is developed consistently. If today we have external texture taking 1 explicit binding plus a few hiddnen, and tomorrow we have a resource array taking N consecutive bindings, explicitly, wouldn't this be inconsistent?
litherum commentedon May 28, 2021
I don't think it would be particularly inconsistent for external textures to use a different binding mechanism than arrays of resources. Those seem like different beasts to me.
Add 'VideoFrame' in 'SourceType' for external_texture cts (gpuweb#1733)