[shaders] Expose a binding index set per target language #362
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.
vello_shaders exposes a list of resource binding types for each
compute stage. This list contains only the bindings that are
actually reachable (obeying WebGPU WGSL validation rules). The
list also contains only the types and no index information is
provided; instead the elements are provided in their order of
declaration in the shader source and the client is expected to
infer the index from the declaration order.
This leads to some issues that are unique to each target language:
When targeting WGSL, this scheme is fragile if the shader source
doesn't keep the index declarations contiguous. Any gaps in the
indices will lead to incorrect results. This can happen due to a
programmer error. This can also happen due to bindings that are
unreachable by the entry point function, for example as a result
of some refactoring.
When targeting MSL, the client needs to know the vello_shader's
crate's internal binding re-assignment scheme and implement the
same logic on their end to compute the indices. This stems from
the fact that WGSL bindings *where indices are scoped to a
bind group) and MSL bindings (where indices are scoped separately
by resource type) get assigned from different ranges and
numerically not the same.
To resolve this, the crate now exposes a list of indices alongside each
backend source.
Additionally, as a cleanup, this PR removes all unused bindings and
rearranges the binding indices to leave no gaps.
Resolves #330