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

Merge Draw function and RenderCommand #7172

Conversation

kurtkuehnert
Copy link
Contributor

@kurtkuehnert kurtkuehnert commented Jan 12, 2023

Objective

Currently, you can choose between a Draw function and a RenderCommand to render your PhaseItems.
Inspired by the recent merge of PhaseItem and EntityPhaseItem (#6885), this PR does the same for Draw and RenderCommand.
Are there use cases that are not covered by the RenderCommand abstraction?

This change aims to reduce the (irrelevant) decisions our users have to make and simplify our rendering terminology.

I believe that this is now much simpler: A RenderPhase renderers multiple RenderItems via the composable RenderCommands, by changing the state of the TrackedRenderPass.

We can still decide how we name this RenderCommand/DrawFunction, or maybe even DrawCommand.
Let me know which name you like best.

Solution

  • Draw functions can only be implemented using the RenderCommand trait.
  • Hides most of the implementation specifics.

Changelog

Todo

Migration Guide

Todo

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jan 12, 2023
@james7132 james7132 self-requested a review January 12, 2023 21:55
@kurtkuehnert kurtkuehnert force-pushed the merge_draw_function_and_render_command branch from 372d415 to 570d23c Compare January 13, 2023 09:53
@kurtkuehnert kurtkuehnert marked this pull request as ready for review January 13, 2023 09:55
@kurtkuehnert
Copy link
Contributor Author

I have updated the documentation and rebased it onto main. This PR should now be ready for review.

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.

Please fix the CI issues. Not sure if this fully compiles or not.

let draw_function = draw_functions.get_mut(item.draw_function()).unwrap();
draw_function.draw(world, render_pass, view, item);
}
let render_commands = world.resource::<RenderCommands<P>>();
Copy link
Member

Choose a reason for hiding this comment

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

Curious if we could use &mut World and World::resource_scope here. It would allow us to remove the internal RwLock on RenderCommands.

This is probably at odds with parallelizing the render phase (i.e. with wgpu's RenderBundles), so feel free to ignore this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not too familiar with the ECS internals, but could we move the RenderCommandState::prepare logic out of the render graph? Maybe into the actual RenderStage::Prepare?

It seems like the only thing inside the RenderCommandState::render method that requires a mutable reference to self is the line: let param = self.state.get(world);.
This seems linked to #7084. But there the line: let param = self.state.get_manual(world);, still requires a mutable reference to self. Would it be possible to change that or is SystemState fundamentally different from QueryState in this regard?

Given that we could make the render method immutable and run the prepare method before the render graph, then we could eliminate the need for the RwLock, right?

crates/bevy_render/src/render_phase/render_command.rs Outdated Show resolved Hide resolved
@james7132 james7132 self-requested a review January 15, 2023 06:25
@kurtkuehnert kurtkuehnert force-pushed the merge_draw_function_and_render_command branch 2 times, most recently from db49394 to 08edef5 Compare January 20, 2023 08:33
@kurtkuehnert kurtkuehnert force-pushed the merge_draw_function_and_render_command branch from 08edef5 to bc66cac Compare February 6, 2023 17:22
@kurtkuehnert kurtkuehnert force-pushed the merge_draw_function_and_render_command branch from bc66cac to 8101e7c Compare February 14, 2023 08:36
@kurtkuehnert kurtkuehnert force-pushed the merge_draw_function_and_render_command branch from 8101e7c to 5150e68 Compare March 9, 2023 13:21
Comment on lines -161 to -169
/// When fetching resources, note that, due to lifetime limitations of the `Deref` trait,
/// [`SRes::into_inner`] must be called on each [`SRes`] reference in the
/// [`RenderCommand::render`] method, instead of being automatically dereferenced as is the
/// case in normal `systems`.
///
/// All parameters have to be read only.
///
/// [`SRes`]: bevy_ecs::system::lifetimeless::SRes
/// [`SRes::into_inner`]: bevy_ecs::system::lifetimeless::SRes::into_inner
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should not be removed.

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-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants