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

TrackedRenderPass internal tracking state reset #14948

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

PPakalns
Copy link
Contributor

@PPakalns PPakalns commented Aug 27, 2024

Objective

Fixes #13225

Solution

Invalidate TrackedRenderPass internal state upon accessing internal wgpu::RenderPass.

Testing

  • Tested by calling set_bind_group on RenderPass returned by TrackedRenderPass::wgpu_pass and checking if in later set_bind_group calls on TrackedRenderPass correct bind group is restored.

/// Resets tracking state
pub fn reset_tracking(&mut self) {
self.pipeline = None;
self.bind_groups.iter_mut().for_each(|val| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand why you set the values to None instead of just clearing the entire vec so it's emtpy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -95,6 +95,19 @@ impl DrawState {
) -> bool {
self.index_buffer == Some((buffer, offset, index_format))
}

/// Resets tracking state
pub fn reset_tracking(&mut self) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this just do self = Default::default()

Copy link
Contributor Author

@PPakalns PPakalns Aug 27, 2024

Choose a reason for hiding this comment

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

It is important to keep vector lengths to device limits. Additionally, we want to avoid reallocating Vec heap memory.

See TrackedRenderPass::new

 state: DrawState {
                bind_groups: vec![(None, Vec::new()); max_bind_groups],
                vertex_buffers: vec![None; max_vertex_buffers],
                ..default()
},

@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 S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 27, 2024
@alice-i-cecile
Copy link
Member

@fintelia could I get your review here?

@fintelia
Copy link
Contributor

This change looks plausible to me, but I'm not familiar enough with the surrounding code at this point to have much confidence.

The one suggestion I have is that it might make sense to have wgpu_pass always reset the tracking. It would be way less error-prone that way, and it would take a very particular set of circumstances for that not to be the desired behavior.

@PPakalns
Copy link
Contributor Author

PPakalns commented Aug 28, 2024

Applied @fintelia suggestion.

Fixed conflicts.

@PPakalns PPakalns force-pushed the tracked_render_pass_state_pr branch from 11a6650 to 6a9c663 Compare August 28, 2024 17:02
Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

Lgtm sans comment about the name.

@@ -24,6 +24,9 @@ struct DrawState {
/// List of vertex buffers by [`BufferId`], offset, and size. See [`DrawState::buffer_slice_key`]
vertex_buffers: Vec<Option<(BufferId, u64, u64)>>,
index_buffer: Option<(BufferId, u64, IndexFormat)>,

/// Stores whether this state is populated or empty for quick state invalidation
stores_state: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Bikeshed: this name confuses me, can we try one of

  • dirty
  • changed
  • modified

instead?

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 thought of multiple variants when I implemented this, but they do not improve the situation and didn't feel correct for me.

DrawState structure stores state.

  • changed: It doesn't store if state has changed between different points in time, it stores state information of RenderPass.
  • modified: The same as with changed.
  • dirty: Stored state doesn't make this structure dirty (It implies something incorrect, not cleaned up). In reality normally this structure should store state, be populated.

That is the reason why I decided to use explicit naming of store_state with documentation comment. Maybe populated could be used, but explicit name store_state made sense for me.

Can change variable name if other reviewers suggest to do so.

@PPakalns
Copy link
Contributor Author

Ping @IceSentry

@IceSentry IceSentry added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 12, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 12, 2024
Merged via the queue into bevyengine:main with commit e567669 Sep 12, 2024
27 checks passed
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 S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

TrackedRenderPass::wgpu_pass may compromize invariants
5 participants