perf: Improve UI batch performance #2887
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.
PR Details
DrawBatchPerTextureAndPassis called multiple times per frame and per instance,stride/sources/engine/Stride.Graphics/BatchBase.cs
Lines 461 to 467 in 4903592
GetTemporaryBuffer()here will retrieve the buffer it just used in a previous call when that buffer may be in use by the GPU causing a stall when callingMapSubresource()below:stride/sources/engine/Stride.Graphics/BatchBase.cs
Line 504 in 4903592
This PR cleans up the logic and ensures that temporary buffers are only released on the next
Beginof the batcher to make sure that they are not still being used.Performance difference goes from ~0.083ms to ~0.0013ms per call to MapSubresource. This method is called around 24 times per frame in the scene I ran, leading to a reduction of 1.96ms per frame. I expect more complex UIs would show an even larger difference.
As you may have noticed, someone commented on this performance issue. It is now fixed so I removed the comment they left.
Related Issue
N/A
Types of changes
Checklist