Skip to content

Handle unallocated GPU memory for mesh extraction #20112

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,11 @@ impl RenderMeshInstanceGpuBuilder {
mesh_vertex_slice.range.start,
mesh_vertex_slice.range.end - mesh_vertex_slice.range.start,
),
None => (0, 0),
None => {
// GPU memory for this mesh hasn't been allocated yet. Retry next frame.
Copy link
Contributor

Choose a reason for hiding this comment

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

What cases will this occur?

We don't want to end up in an infinite retry loop for failed meshes.

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 there's a way to detect this here? With that said it's also possible this reextract thing should happen somewhere else and not here.

Copy link
Member

Choose a reason for hiding this comment

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

I really don't like that this is an Option: a Result would have a lot clearer semantics to me.

meshes_to_reextract_next_frame.insert(entity);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the fix, we might need to do the same for the mesh_index_slice a few lines below this.

I'm unsure why it previously didn't return None in this case. I feel like this might not be the full fix. I'll need to investigate further.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, thinking about this more, no, we shouldn't do this for the index_slice because not having indices is a valid case

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a case where vertex_slice is ready, but not index_slice?

Copy link
Contributor

Choose a reason for hiding this comment

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

For non indexed meshes index_slice will never be ready. I'm not sure it's possible for an indexed mesh to not have the index_slice ready. AFAIK they are allocated together but I could be wrong.

return None;
}
};
let (mesh_is_indexed, first_index_index, index_count) =
match mesh_allocator.mesh_index_slice(&self.shared.mesh_asset_id) {
Expand Down
Loading