Fix instance uniform data buffer update delay #79603
Merged
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.
This PR simply moves dirty resource updates after instance updates, as instance updates can cause some resources to become dirty. This can cause an extra frame of delay when updating instance uniforms, multimesh data or particle data. For example in the MRP project in the linked issue, the update order currently goes like this:
set_instance_shader_parameter()
, data is sent to server.RendererSceneCull::update_dirty_instances()
.RSG::utilities->update_dirty_resources()
updates dirty resources, more importantly in this scenario it callsMaterialStorage::get_singleton()->_update_global_shader_uniforms()
whichbuffer_update()
's dirty instance+global uniform data to GPU._update_dirty_instance()
for each of them and marks resources as dirty, including instance uniform buffer.This PR basically reverses the order of steps 3 and 4. Because step 4 can actually mark resources as dirty but as the dirty resources were already uploaded to GPU in step 3 this will cause one frame update delay.
I tested this PR with some more complex demos and didn't notice any regressions, but these issues can be pretty subtle to notice.
Also, if this PR is accepted, the same reordering should probably done to this PR #77594 as it adds
RendererCanvasCull::update_dirty_instances(
) which is functionally similar to RendererSceneCull implementation.