Metal: Fix dynamic uniform buffer offset corruption when rebinding sets#114778
Merged
Conversation
When the same uniform set is bound multiple times within a render pass (e.g., OPAQUE pass then ALPHA pass with different instance buffers), the dynamic offset bits were being OR'd together, corrupting the packed frame indices. For example, if OPAQUE binds set 1 with frame_idx=1 (0x10) and ALPHA binds set 1 with frame_idx=2 (0x20), the OR produces 0x30 instead of the correct 0x20, causing the shader to read from the wrong buffer offset. This fix clears the relevant bits for each set being bound before OR'ing the new values, ensuring only the latest frame indices are used. Fixes rendering artifacts in the mobile renderer which uses two dynamic uniforms (uniform buffer + storage buffer) in set 1, unlike the clustered renderer which only has one.
8c4f848 to
541f626
Compare
clayjohn
approved these changes
Jan 9, 2026
Member
|
Thanks! |
rivie13
pushed a commit
to rivie13/Phoenix-Agentic-Engine
that referenced
this pull request
Feb 16, 2026
…_offsets Metal: Fix dynamic uniform buffer offset corruption when rebinding sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #114069
When the same uniform set is bound multiple times within a render pass (e.g., OPAQUE pass then ALPHA pass with different instance buffers), the dynamic offset bits were being OR'd together, corrupting the packed frame indices.
For example, if OPAQUE binds set 1 with frame_idx=1 (0x10) and ALPHA binds set 1 with frame_idx=2 (0x20), the OR produces 0x30 instead of the correct 0x20, causing the shader to read from the wrong buffer offset.
This fix clears the relevant bits for each set being bound before OR'ing the new values, ensuring only the latest frame indices are used.
Fixes rendering artefacts in the mobile renderer which uses two dynamic uniforms (uniform buffer + storage buffer) in set 1, unlike the clustered renderer which only has one.
🤖 AI disclosure
I used AI to identify the bug. I have validated the code and verified the fix.
I used the following prompt: