Skip to content

Conversation

samw-improbable
Copy link

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 for BindGroupFormat assigns 'slots' based on the order of the formats arg, and then sorts the bindings into various groups (in my case, textures and buffers were sorted) - and then later getTextureShaderDeclaration (here) assigns ids to first textures, then storage buffers (which is not the same order as formats 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 with startBindIndex, 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

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

@samw-improbable samw-improbable changed the title Reordered bindings when using a StorageBuffer [Fix] Reordered bindings when using a StorageBuffer Aug 5, 2025
@mvaligursky
Copy link
Contributor

Hi @samw-improbable - thanks for the report, I'm definitely keen to sort this out, and it'd be amazing to have some repro, at least the shader that you used to create this issue, so that I can see its source and processed output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants