Correctly check time since shadow was allocated in atlas to avoid unnecessary re-allocations #100064
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.
Fixes: #97472
The bug is simple,
tick
is the current timealloc_tick
is the time when we allocated the slot in the atlas andshadow_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 betweentick
andalloc_tick
is less than the tolerance, we shouldn't allow it to move. All of these variables are unsigned ints.tick
is always bigger thanalloc_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.