-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Immediately apply deferred system params in System::run #11823
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
Immediately apply deferred system params in System::run #11823
Conversation
Much simpler. Feel free to merge once you get CI passing. |
Co-authored-by: Alice Cecile <[email protected]>
Is this going to mess up pipelined rendering extract schedule if you run all the schedules single threaded? i.e. that schedule needs to skip applying it's buffers until it's moved to the render thread. |
That would likely be a performance regression. That said I'm not sure why one would be running pipelined rendering with a single threaded executor. It seems counter intuitive. |
For lower core systems like quest or switch that only have 3 cores available. The perf you get from pipelining will be worth it. But the overhead from running your schedule multi threaded won't be |
@JoJoJet I think that's good enough justification to not deprecate the SimpleExecutor and retain the behavior in the single threaded executor. Thoughts? |
…1823) # Objective Fixes bevyengine#11821. ## Solution * Run `System::apply_deferred` in `System::run` after executing the system. * Switch to using `System::run_unsafe` in `SingleThreadedExecutor` to preserve the current behavior. * Remove the `System::apply_deferred` in `SimpleExecutor` as it's now redundant. * Remove the `System::apply_deferred` when running one-shot systems, as it's now redundant. --- ## Changelog Changed: `System::run` will now immediately apply deferred system params after running the system. ## Migration Guide `System::run` will now always run `System::apply_deferred` immediately after running the system now. If you were running systems and then applying their deferred buffers at a later point in time, you can eliminate the latter. ```rust // in 0.13 system.run(world); // .. sometime later ... system.apply_deferred(world); // in 0.14 system.run(world); ``` --------- Co-authored-by: Alice Cecile <[email protected]>
…1823) # Objective Fixes bevyengine#11821. ## Solution * Run `System::apply_deferred` in `System::run` after executing the system. * Switch to using `System::run_unsafe` in `SingleThreadedExecutor` to preserve the current behavior. * Remove the `System::apply_deferred` in `SimpleExecutor` as it's now redundant. * Remove the `System::apply_deferred` when running one-shot systems, as it's now redundant. --- ## Changelog Changed: `System::run` will now immediately apply deferred system params after running the system. ## Migration Guide `System::run` will now always run `System::apply_deferred` immediately after running the system now. If you were running systems and then applying their deferred buffers at a later point in time, you can eliminate the latter. ```rust // in 0.13 system.run(world); // .. sometime later ... system.apply_deferred(world); // in 0.14 system.run(world); ``` --------- Co-authored-by: Alice Cecile <[email protected]>
# Objective Fix panic in `run_system` when running an exclusive system wrapped in a `PipeSystem` or `AdapterSystem`. #18076 introduced a `System::run_without_applying_deferred` method. It normally calls `System::run_unsafe`, but `ExclusiveFunctionSystem::run_unsafe` panics, so it was overridden for that type. Unfortunately, `PipeSystem::run_without_applying_deferred` still calls `PipeSystem::run_unsafe`, which can then call `ExclusiveFunctionSystem::run_unsafe` and panic. ## Solution Make `ExclusiveFunctionSystem::run_unsafe` work instead of panicking. Clarify the safety requirements that make this sound. The alternative is to override `run_without_applying_deferred` in `PipeSystem`, `CombinatorSystem`, `AdapterSystem`, `InfallibleSystemWrapper`, and `InfallibleObserverWrapper`. That seems like a lot of extra code just to preserve a confusing special case! Remove some implementations of `System::run` that are no longer necessary with this change. This slightly changes the behavior of `PipeSystem` and `CombinatorSystem`: Currently `run` will call `apply_deferred` on the first system before running the second, but after this change it will only call it after *both* systems have run. The new behavior is consistent with `run_unsafe` and `run_without_applying_deferred`, and restores the behavior prior to #11823. The panic was originally necessary because [`run_unsafe` took `&World`](https://github.com/bevyengine/bevy/pull/6083/files#diff-708dfc60ec5eef432b20a6f471357a7ea9bfb254dc2f918d5ed4a66deb0e85baR90). Now that it takes `UnsafeWorldCell`, it is possible to make it work. See also Cart's concerns at #4166 (comment), although those also predate `UnsafeWorldCell`. And see #6698 for a previous bug caused by this panic.
# Objective Fix panic in `run_system` when running an exclusive system wrapped in a `PipeSystem` or `AdapterSystem`. #18076 introduced a `System::run_without_applying_deferred` method. It normally calls `System::run_unsafe`, but `ExclusiveFunctionSystem::run_unsafe` panics, so it was overridden for that type. Unfortunately, `PipeSystem::run_without_applying_deferred` still calls `PipeSystem::run_unsafe`, which can then call `ExclusiveFunctionSystem::run_unsafe` and panic. ## Solution Make `ExclusiveFunctionSystem::run_unsafe` work instead of panicking. Clarify the safety requirements that make this sound. The alternative is to override `run_without_applying_deferred` in `PipeSystem`, `CombinatorSystem`, `AdapterSystem`, `InfallibleSystemWrapper`, and `InfallibleObserverWrapper`. That seems like a lot of extra code just to preserve a confusing special case! Remove some implementations of `System::run` that are no longer necessary with this change. This slightly changes the behavior of `PipeSystem` and `CombinatorSystem`: Currently `run` will call `apply_deferred` on the first system before running the second, but after this change it will only call it after *both* systems have run. The new behavior is consistent with `run_unsafe` and `run_without_applying_deferred`, and restores the behavior prior to #11823. The panic was originally necessary because [`run_unsafe` took `&World`](https://github.com/bevyengine/bevy/pull/6083/files#diff-708dfc60ec5eef432b20a6f471357a7ea9bfb254dc2f918d5ed4a66deb0e85baR90). Now that it takes `UnsafeWorldCell`, it is possible to make it work. See also Cart's concerns at #4166 (comment), although those also predate `UnsafeWorldCell`. And see #6698 for a previous bug caused by this panic.
Objective
Fixes #11821.
Solution
System::apply_deferred
inSystem::run
after executing the system.System::run_unsafe
inSingleThreadedExecutor
to preserve the current behavior.System::apply_deferred
inSimpleExecutor
as it's now redundant.System::apply_deferred
when running one-shot systems, as it's now redundant.Changelog
Changed:
System::run
will now immediately apply deferred system params after running the system.Migration Guide
System::run
will now always runSystem::apply_deferred
immediately after running the system now. If you were running systems and then applying their deferred buffers at a later point in time, you can eliminate the latter.