bevy/crates
Robert Swain 4fdea02087
Use instancing for sprites (#9597)
# Objective

- Supercedes #8872 
- Improve sprite rendering performance after the regression in #9236 

## Solution

- Use an instance-rate vertex buffer to store per-instance data.
- Store color, UV offset and scale, and a transform per instance.
- Convert Sprite rect, custom_size, anchor, and flip_x/_y to an affine
3x4 matrix and store the transpose of that in the per-instance data.
This is similar to how MeshUniform uses transpose affine matrices.
- Use a special index buffer that has batches of 6 indices referencing 4
vertices. The lower 2 bits indicate the x and y of a quad such that the
corners are:
  ```
  10    11

  00    01
  ```
UVs are implicit but get modified by UV offset and scale The remaining
upper bits contain the instance index.

## Benchmarks

I will compare versus `main` before #9236 because the results should be
as good as or faster than that. Running `bevymark -- 10000 16` on an M1
Max with `main` at `e8b38925` in yellow, this PR in red:

![Screenshot 2023-08-27 at 18 44
10](https://github.com/bevyengine/bevy/assets/302146/bdc5c929-d547-44bb-b519-20dce676a316)

Looking at the median frame times, that's a 37% reduction from before.

---

## Changelog

- Changed: Improved sprite rendering performance by leveraging an
instance-rate vertex buffer.

---------

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2023-09-02 18:03:19 +00:00
..
bevy_a11y Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_animation Fixing some doc comments (#9646) 2023-08-31 19:05:49 +00:00
bevy_app Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
bevy_asset Fixing some doc comments (#9646) 2023-08-31 19:05:49 +00:00
bevy_audio Fixing some doc comments (#9646) 2023-08-31 19:05:49 +00:00
bevy_core Remove Resource and add Debug to TaskPoolOptions (#9485) 2023-08-20 22:32:41 +00:00
bevy_core_pipeline Reorder render sets, refactor bevy_sprite to take advantage (#9236) 2023-08-27 14:33:49 +00:00
bevy_derive bevy_derive: Fix #[deref] breaking other attributes (#9551) 2023-08-28 17:36:18 +00:00
bevy_diagnostic Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_dylib Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_dynamic_plugin Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_ecs Fix anonymous set name stack overflow (#9650) 2023-08-31 22:52:59 +00:00
bevy_ecs_compile_fail_tests Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
bevy_encase_derive Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_gilrs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
bevy_gizmos Reorder render sets, refactor bevy_sprite to take advantage (#9236) 2023-08-27 14:33:49 +00:00
bevy_gltf only take up to the max number of joints (#9351) 2023-08-28 16:58:45 +00:00
bevy_hierarchy Split ComputedVisibility into two components to allow for accurate change detection and speed up visibility propagation (#9497) 2023-09-01 13:00:18 +00:00
bevy_input Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
bevy_internal fix clippy::default_constructed_unit_structs and trybuild errors (#9144) 2023-07-13 22:23:04 +00:00
bevy_log Update tracy-client requirement from 0.15 to 0.16 (#9436) 2023-08-15 07:45:21 +00:00
bevy_macro_utils Add some more helpful errors to BevyManifest when it doesn't find Cargo.toml (#9207) 2023-07-19 12:05:04 +00:00
bevy_macros_compile_fail_tests bevy_derive: Fix #[deref] breaking other attributes (#9551) 2023-08-28 17:36:18 +00:00
bevy_math Fix erronenous glam version (#9653) 2023-08-31 12:55:17 +00:00
bevy_mikktspace Fix erronenous glam version (#9653) 2023-08-31 12:55:17 +00:00
bevy_pbr Use instancing for sprites (#9597) 2023-09-02 18:03:19 +00:00
bevy_ptr Put #[repr(transparent)] attr to bevy_ptr types (#9068) 2023-07-14 18:55:15 +00:00
bevy_reflect Fix erronenous glam version (#9653) 2023-08-31 12:55:17 +00:00
bevy_reflect_compile_fail_tests Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
bevy_render Use instancing for sprites (#9597) 2023-09-02 18:03:19 +00:00
bevy_scene Split ComputedVisibility into two components to allow for accurate change detection and speed up visibility propagation (#9497) 2023-09-01 13:00:18 +00:00
bevy_sprite Use instancing for sprites (#9597) 2023-09-02 18:03:19 +00:00
bevy_tasks elaborate on TaskPool and bevy tasks (#8750) 2023-08-11 21:07:28 +00:00
bevy_text Split ComputedVisibility into two components to allow for accurate change detection and speed up visibility propagation (#9497) 2023-09-01 13:00:18 +00:00
bevy_time Move schedule name into Schedule (#9600) 2023-08-28 20:44:48 +00:00
bevy_transform Fixing some doc comments (#9646) 2023-08-31 19:05:49 +00:00
bevy_ui Split ComputedVisibility into two components to allow for accurate change detection and speed up visibility propagation (#9497) 2023-09-01 13:00:18 +00:00
bevy_utils Add system.map(...) for transforming the output of a system (#8526) 2023-08-28 16:36:46 +00:00
bevy_window Change Window::physical_cursor_position to use the physical size of the window (#9657) 2023-08-31 19:02:33 +00:00
bevy_winit Fixing some doc comments (#9646) 2023-08-31 19:05:49 +00:00