Skip to content

Reallocate materials when they change.#17979

Merged
superdump merged 1 commit intobevyengine:mainfrom
pcwalton:update-materials-on-change
Feb 22, 2025
Merged

Reallocate materials when they change.#17979
superdump merged 1 commit intobevyengine:mainfrom
pcwalton:update-materials-on-change

Conversation

@pcwalton
Copy link
Copy Markdown
Contributor

PR #17898 regressed this, causing much of #17970. This commit fixes the issue by freeing and reallocating materials in the MaterialBindGroupAllocator on change. Note that more efficiency is possible, but I opted for the simple approach because (1) we should fix this bug ASAP; (2) I'd like #17965 to land first, because that unlocks the biggest potential optimization, which is not recreating the bind group if it isn't necessary to do so.

PR bevyengine#17898 regressed this, causing much of bevyengine#17970. This commit fixes the
issue by freeing and reallocating materials in the
`MaterialBindGroupAllocator` on change. Note that more efficiency is
possible, but I opted for the simple approach because (1) we should fix
this bug ASAP; (2) I'd like bevyengine#17965 to land first, because that unlocks
the biggest potential optimization, which is not recreating the bind
group if it isn't necessary to do so.
@pcwalton pcwalton added A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 21, 2025
@rparrett
Copy link
Copy Markdown
Contributor

With this PR I am now seeing the same panic I was seeing in alien_cake_addict in animated_material and specular_tint as well.

This may be metal-specific.

@pcwalton pcwalton added the P-Regression Functionality that used to work but no longer does. Add a test for this! label Feb 21, 2025
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Feb 21, 2025
pcwalton added a commit to pcwalton/bevy that referenced this pull request Feb 21, 2025
This patch fixes two bugs in the new non-bindless material allocator
that landed in PR bevyengine#17898:

1. A debug assertion to prevent double frees had been flipped: we
   checked to see whether the slot was empty before freeing, while we
   should have checked to see whether the slot was full.

2. The non-bindless allocator returned `None` when querying a slab that
   hadn't been prepared yet instead of returning a handle to that slab.
   This resulted in a 1-frame delay when modifying materials. In the
   `animated_material` example, this resulted in the meshes never
   showing up at all, because that example changes every material every
   frame.

Together with bevyengine#17979, this patch locally fixes the problems with
`animated_material` on macOS that were reported in bevyengine#17970.
github-merge-queue bot pushed a commit that referenced this pull request Feb 22, 2025
This patch fixes two bugs in the new non-bindless material allocator
that landed in PR #17898:

1. A debug assertion to prevent double frees had been flipped: we
checked to see whether the slot was empty before freeing, while we
should have checked to see whether the slot was full.

2. The non-bindless allocator returned `None` when querying a slab that
hadn't been prepared yet instead of returning a handle to that slab.
This resulted in a 1-frame delay when modifying materials. In the
`animated_material` example, this resulted in the meshes never showing
up at all, because that example changes every material every frame.

Together with #17979, this patch locally fixes the problems with
`animated_material` on macOS that were reported in #17970.
@superdump superdump added this pull request to the merge queue Feb 22, 2025
Merged via the queue into bevyengine:main with commit ad3817c Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this! S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants