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

Allow using no vertex buffers for render pipeline layouts #10307

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 7 additions & 7 deletions crates/bevy_render/src/render_resource/pipeline_specializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ pub trait SpecializedMeshPipeline {
pub struct SpecializedMeshPipelines<S: SpecializedMeshPipeline> {
mesh_layout_cache:
PreHashMap<InnerMeshVertexBufferLayout, HashMap<S::Key, CachedRenderPipelineId>>,
vertex_layout_cache: HashMap<VertexBufferLayout, HashMap<S::Key, CachedRenderPipelineId>>,
vertex_layout_cache:
HashMap<Option<VertexBufferLayout>, HashMap<S::Key, CachedRenderPipelineId>>,
}

impl<S: SpecializedMeshPipeline> Default for SpecializedMeshPipelines<S> {
Expand Down Expand Up @@ -124,20 +125,19 @@ impl<S: SpecializedMeshPipeline> SpecializedMeshPipelines<S> {
}
err
})?;

// Different MeshVertexBufferLayouts can produce the same final VertexBufferLayout
// We want compatible vertex buffer layouts to use the same pipelines, so we must "deduplicate" them
let vertex_key = descriptor.vertex.buffers.get(0).cloned();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this clone have any negative performance consequences?

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 don't see a good way to avoid it, but it should be a fairly small clone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid the clone, I think we would have to wrap it in a Cow. Let me try that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't get it working, rip.

let layout_map = match self
.vertex_layout_cache
.raw_entry_mut()
.from_key(&descriptor.vertex.buffers[0])
.from_key(&vertex_key)
{
RawEntryMut::Occupied(entry) => entry.into_mut(),
RawEntryMut::Vacant(entry) => {
entry
.insert(descriptor.vertex.buffers[0].clone(), Default::default())
.1
}
RawEntryMut::Vacant(entry) => entry.insert(vertex_key, Default::default()).1,
};

Ok(*entry.insert(match layout_map.entry(key) {
Entry::Occupied(entry) => {
if cfg!(debug_assertions) {
Expand Down