fix: Ensure VertexBufferLayout matches parsed WGSL shader @location layout #2363
+105
−29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For deck.gl tracker, and to fix issue raised in visgl/deck.gl#9531
Background
When I originally ported the pointcloud layer, the attribute struct had been set up like the following:
which results, perhaps confusingly, in the following error, as

instanceColors
are provided as aunorm8x4
and should have stride 4, not 24.If, instead, that struct is ordered in the following way (note:
instancePositions
have been moved down), it works as expected:After some digging, it turns out that error is being thrown because the
VertexBufferLayout
we pass to theWebGPURenderPipeline
contained a different order of attributes than those being bound to the shader bysetVertexBuffer
. In some cases that generates this error. In other cases, where the buffer sizes all match it subtly binds the buffers with data meant for other buffers. In my case, I got 'lucky' that I re-ordered the buffers into the same order as they were specified by deck's AttributeManager.Instead, ensure that we produce a
VertexBufferLayout
that matches the order of the attributes from the WGSL source code by sorting thebufferLayout
. This means that both WGSL samples work as expected.