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

[Merged by Bors] - Only compute sprite color once per quad #7498

Closed

Conversation

abnormalbrain
Copy link
Contributor

@abnormalbrain abnormalbrain commented Feb 4, 2023

Objective

This change substantially increased performance when drawing thousands of colored sprites.

Solution

The same color is used for each vertex in the quad sprites are drawn too, but the color is converted to a linear color each time. This computation only needs to be done once.

The as_linear_rgba_f32() call was showing up in profiling the basic example in my particle system library as a hot path. This change added about 50 fps to the example, from about 150fps to about 200 fps, when rendering around 10k colored sprites.

Tracy Results:
"This trace" is with the change.

Change in frame time:
image

Change in queue_sprites:
image

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@james7132 james7132 added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times labels Feb 4, 2023
@james7132
Copy link
Member

This seems to have the same effect as #7311 but for 2D sprites. Could you test the results with Tracy on one of the stress tests (i.e. many_sprites)?

@alice-i-cecile alice-i-cecile added this to the 0.10 milestone Feb 4, 2023
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 4, 2023
@abnormalbrain
Copy link
Contributor Author

@james7132 Added tracy comparisons for many_sprites to the description. I swapped to a windows machine to run Tracy, instead of the macbook I originally tested on. It's a lot more powerful so the performance difference seems a bit less noticeable, but it's still present. Personally, still seems like a win.

@superdump
Copy link
Contributor

bors r+

bors bot pushed a commit that referenced this pull request Feb 4, 2023
# Objective

This change substantially increased performance when drawing thousands of colored sprites.

## Solution

The same color is used for each vertex in the quad sprites are drawn too, but the color is converted to a linear color each time. This computation only needs to be done once.

The `as_linear_rgba_f32()` call was showing up in profiling the `basic` example in my [particle system library](https://github.com/abnormalbrain/bevy_particle_systems) as a hot path. This change added about 50 fps to the example, from about 150fps to about 200 fps, when rendering around 10k colored sprites. 

Tracy Results:
"This trace" is with the change.

Change in frame time:
![image](https://user-images.githubusercontent.com/102993888/216752612-5e0ad0ce-1c59-4b56-873e-8018287408bb.png)

Change in `queue_sprites`:
![image](https://user-images.githubusercontent.com/102993888/216752767-6f1a6a5c-6181-45d3-bf86-5823bd81dfc4.png)
@bors bors bot changed the title Only compute sprite color once per quad [Merged by Bors] - Only compute sprite color once per quad Feb 4, 2023
@bors bors bot closed this Feb 4, 2023
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-Performance A change motivated by improving speed, memory usage or compile times S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants