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.
Overview
This PR attempts to close #3334
Progress
When used in concert with this naga PR, significantly simplifies wgpu's Metal backend by, in large part, replacing the existing resource binding model with argument buffers.
In many ways, a large part of the work done by the existing Metal backend is attempting to resolve the impedance mismatch between WebGPU (and, by extension, Vulkan's) descriptor set based binding model and Metal's pre-argument buffer binding model. This required very careful tracking and populating of a function argument table and passing knowledge of those bindings down to naga at shader generation time.
This PR instead tries to simplify that work by instead generating a Metal shader that uses argument buffers and employs a "reflection" style architecture that allows the generated shader to provide a simple 1:1 mapping between the members of a given bind group and the resources used in the shader.
Further work
While I believe the bulk of the work has been done, I have sadly run out of available time to fully test and resolve all the edge cases required to finish this issue.
In particular, there are, unfortunately, at least two wrinkles that prevent the wholesale adoption of argument buffers:
These two use cases would require passing the resource by argument into the entry point, as per the existing binding model. It should be reasonably straightforward to check for the presence of these two cases, and any others that arise, and handle them accordingly.
I have also not yet integrated the new binding model with compute shaders as I had hoped to resolve the issues with fragment/vertex shaders first.