Fix material slot overflow in bindless slab#23554
Open
kristoff3r wants to merge 1 commit intobevyengine:mainfrom
Open
Fix material slot overflow in bindless slab#23554kristoff3r wants to merge 1 commit intobevyengine:mainfrom
kristoff3r wants to merge 1 commit intobevyengine:mainfrom
Conversation
When allocating in MaterialBindlessSlab it can hold up to 32 bits of allocations. However, when used on the GPU the slot is packed into 16 bits and combined with the lightmap slot. To fix we set add some debug asserts to validate that the bit packing succeeds, and limit the slab to 16 bits of allocations.
f962eeb to
fff3b9a
Compare
JMS55
approved these changes
Mar 28, 2026
Contributor
|
Isn't this just going to make the bug louder with the asserts and error? I'm not sure how that fixes the bug. |
Contributor
Author
When running the example with this PR I don't hit the asserts. My understanding is that the slab saying it's full will cause a new slab to be created instead, but I could be wrong. |
Contributor
|
Ah, right, that makes sense, I didn't realize the Err branch was in try_allocate. And yeah, I tested the example and it does appear to work. |
IceSentry
approved these changes
Mar 28, 2026
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.
Objective
Fixes #23128
When allocating in MaterialBindlessSlab it can hold up to 32 bits of allocations. However, when used on the GPU the slot is packed into 16 bits and combined with the lightmap slot, and when it overflows both slots end up being wrong.
Solution
Add some debug asserts to validate that the bit packing succeeds, and limit the slab to 16 bits of allocations.
I'm not super well versed in this part of the codebase, so I don't know if this is the best spot to put the check, since the limitation isn't really on the slab itself. And I don't know if this has other ramifications that need to be handled.
Testing
Test using the reproducer from the issue.