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

Stop extracting mesh entities to the render world. #11803

Merged
merged 3 commits into from
Feb 10, 2024

Conversation

pcwalton
Copy link
Contributor

@pcwalton pcwalton commented Feb 10, 2024

This fixes a FIXME in extract_meshes and results in a performance improvement.

As a result of this change, meshes in the render world might not be attached to entities anymore. Therefore, the entity parameter to RenderCommand::render() is now wrapped in an Option. Most applications that use the render app's ECS can simply unwrap the Option.

Note that for now sprites, gizmos, and UI elements still use the render world as usual.

Migration guide

  • For efficiency reasons, some meshes in the render world may not have corresponding Entity IDs anymore. As a result, the entity parameter to RenderCommand::render() is now wrapped in an Option. Custom rendering code may need to be updated to handle the case in which no Entity exists for an object that is to be rendered.

This fixes a `FIXME` in `extract_meshes` and results in a performance
improvement.

As a result of this change, meshes in the render world might not be
attached to entities anymore. Therefore, the `entity` parameter to
`RenderCommand::render()` is now wrapped in an `Option`. Most
applications that use the render app's ECS can simply unwrap the
`Option`.

Note that for now sprites, gizmos, and UI elements still use the render
world as usual.

Migration guide
---------------

* For efficiency reasons, some meshes in the render world may not have
  corresponding `Entity` IDs anymore. As a result, the `entity`
  parameter to `RenderCommand::render()` is now wrapped in an `Option`.
  Custom rendering code may need to be updated to handle the case in
  which no `Entity` exists for an object that is to be rendered.
@JMS55 JMS55 added this to the 0.13 milestone Feb 10, 2024
@superdump
Copy link
Contributor

CI failed formatting.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide labels Feb 10, 2024
Copy link
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

Copy link
Contributor

@NthTensor NthTensor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.

Profiling reveals a small but reliable improvement in extract_meshs, but I could not detect a change in the frame-rate or render schedule timings on the scenes I have available. Tested on many_cubes, many_foxes and several of the gltf test scenes using scene_viewer.

This is from many_cubes.

sc_1707534181

This PR paves the way for some other improvements that could take extract_meshes down into the nanoseconds most of the time.

The breaking change is pretty minor so I think we could still merge this for 0.13.

@pcwalton pcwalton 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 10, 2024
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The render command encoding seems to be ~4% slower on average (tested on many_foxes):
image

This is probably a result of the panicking added into RenderCommand implementations, and this is likely still preferable than spending the time in the extract schedule as it blocks both the render and main schedules.

I can confirm similar performance improvements to what @NthTensor is noting with everything else though.

crates/bevy_gizmos/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_pbr/src/render/mesh.rs Outdated Show resolved Hide resolved
@james7132 james7132 added this pull request to the merge queue Feb 10, 2024
Merged via the queue into bevyengine:main with commit 3af8526 Feb 10, 2024
23 checks passed
@rparrett
Copy link
Contributor

The migration guide here is a bit mysterious. Rust's suggestions for fixing up the function params seem good enough, but maybe it could be amended to specifically mention returning RenderCommandResult::Failure, or add a before/after code block.

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-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide 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.

7 participants