Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly check time since shadow was allocated in atlas to avoid unnecessary re-allocations #100064

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

clayjohn
Copy link
Member

@clayjohn clayjohn commented Dec 5, 2024

Fixes: #97472

The bug is simple, tick is the current time alloc_tick is the time when we allocated the slot in the atlas and shadow_atlas_realloc_tolerance_msec is the minimum time we want a shadow to live in the atlas before trying to move up to a higher resolution slot. When the difference between tick and alloc_tick is less than the tolerance, we shouldn't allow it to move. All of these variables are unsigned ints. tick is always bigger than alloc_tick so the left side of the comparison always overflows to some large number and the condition always passed.

The regression is more complicated. This condition is only checked when the current subdivision doesn't equal the best subdivision. In the MRP, that happens a lot because there are more shadows than can fit without the atlas. So there are always shadows asking to be moved onto the atlas (and thus evicting other shadows). In 4.2, we had a bug where some shadows would think they got a spot on the atlas, this led to us later attempting to read from non-existent memory which led to crashes. But when it didn't crash it had the side effect of causing that first check to fail, so this bug wasn't exposed. I explain the regression in more detail here: #97472 (comment)

For maintainers, this is a very safe change and should be merged for 4.4 and 4.3 ASAP.

…ecessary re-allocations

Co-authored-by: jitspoe <jitspoe@yahoo.com>
@clayjohn clayjohn added bug topic:rendering regression performance cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Dec 5, 2024
@clayjohn clayjohn added this to the 4.4 milestone Dec 5, 2024
@clayjohn clayjohn requested a review from a team as a code owner December 5, 2024 19:20
@Repiteo Repiteo merged commit 8e01601 into godotengine:master Dec 5, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 5, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release performance regression topic:rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Significant performance drop with OmniLight3D shadows between 4.2 and 4.3.
4 participants