GPU: Metal: Rebind storage buffers when their locations change. #14653
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.
When you change the pipeline to one that uses a different number of vertex/fragment uniform buffers, that moves the actual locations storage buffers should be bound to on the Metal side.
This PR makes the GPU Metal driver take that into account when changing the pipeline. Beforehand, buffers would not be rebound at their new locations, causing issues.
Description
The new code compares the previous and new pipeline when they change, and checks whether the base index of where storage buffers are located on the Metal side has changed (this is caused by uniform buffers pushing them higher/lower). If the base index has changed, it forces a rebind.
This logic is repeated for vertex and fragment storage buffers.
It's possible there are similar bugs to this one if other resource types also share indices on the Metal side in this way, eg. storage textures. It would probably be good if someone more familiar with the Metal backend checked whether that is the case, possibly adding more forced rebinds on pipeline change if needed.
Existing Issue(s)
Fixes #14652.