feat: Use explicit pipeline layouts from shaderLayout #2355
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.
Background
Solves an issue raised in: visgl/deck.gl#9531
Unused uniforms are stripped from WebGPU shaders by the compiler as they are not part of the shader's resource interface (as per spec)
When shader source injection is performed as a result of using
modules
ingetShaders
, if the bindings injected by that call (such as lighting) go unused, the automatic layout generated by WebGPU will not contain these unused bindings.Attempting to create the
BindGroupLayout
in this case will result inluma
attempting to pass a binding for each uniform it's aware of from our WGSL introspection library. Ideally, we want to avoid this mismatch as it makes for a poor developer experience as commenting out lines of code to debug shaders will result in these sorts of errors being thrown.Possible solutions
shaderLayout
in order to match the automatic layout.shaderLayout
, which will allow us to bind values to the unused bindings without throwing an error.Here I've experimented with implementing option 2 for the following reasons:
BindGroup
/BindLayout
s so that they can be shared across layouts/layers. This could be quite useful for luma-injected bindings likeproject
andlighting
.dynamicOffset
s or unfiltered textures, which users creating custom layers may well want to do in the future.Change List
shaderLayout
and produces a layout for the render pipeline to use.