[Fix] Reordered bindings when using a StorageBuffer #7886
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.
Description
I reached a weird bug where the Preprocessor generated code output and generated bind layout were misaligned.
(in
WebgpuShaderProcessorWGSL.processResources
) It seems that the constructor forBindGroupFormat
assigns 'slots' based on the order of theformats
arg, and then sorts the bindings into various groups (in my case, textures and buffers were sorted) - and then latergetTextureShaderDeclaration
(here) assigns ids to first textures, then storage buffers (which is not the same order asformats
was).This ended up with my storage buffer being the first binding in the bind layout (slot 0), but the last one in the actual shader source code (slot 5). I would share a PoC but I haven't got time to write a repro outside of my codebase right now, though if you need one I may be able to write one in the future.
Fixes #
I wrote a naive fix (which makes my code work), but my changes mean that
getTextureShaderDeclaration
no longer does anything withstartBindIndex
, which seems to be used in other places (and seemingly added by this PR #7342).I don't have very much context on Playcanvas or your shader system, so I would appreciate some feedback on the proper way to fix this bug!
Checklist