gpuweb / gpuweb

Where the GPU for the Web work happens!
https://webgpu.io
Other
4.85k stars 319 forks source link

Validation requires vertex buffers to be set, even if they are unused #4999

Open kainino0x opened 5 days ago

kainino0x commented 5 days ago

When creating a GPURenderPipeline, it is possible to specify vertex buffers that have no attributes, and therefore is not actually used by the pipeline. However, in draw-time validation, we still require a vertex buffer to be bound to that slot.

We could normalize the descriptor such that { arrayStride, attributes: [] } does the same thing as null.

Additionally, we could ~optionally~ skip validation of arrayStride if attributes.length==0, ~but this doesn't matter~.

The motivation for revisiting this is for language bindings such as C: https://github.com/webgpu-native/webgpu-headers/issues/432 We previously discussed this in gpuweb #2864, in which we conservatively chose not to change the JS spec, and decided that webgpu.h should indicate a hole with something other than attributes=[] (we used a WGPUVertexStepMode_VertexBufferNotUsed sentinel value).

Revisiting this with the benefit of time, though, it is very strange that the JS API will validate this thing that is totally unused. I don't really think there's any reasonable bug that this could usefully catch; for example if you forgot to specify any attributes and forgot to bind a vertex buffer, you would still get an error in createRenderPipeline(), as long as the shader attempted to use those attributes.

kainino0x commented 5 days ago

Additionally, we could optionally skip validation of arrayStride if attributes.length==0, but this doesn't matter.

Actually it would be preferable to skip the validation of arrayStride when there are no attributes, to make null and { attributes: [] } behave the same. Otherwise the C API still needs some distinction in order to implement the JS API correctly.