-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Mesh overhaul with custom vertex attributes #592 #599
Conversation
crates/bevy_render/src/mesh/mesh.rs
Outdated
for index in 1..4 { //TODO: use actual vertex buffer count | ||
if let Some(RenderResourceId::Buffer(vertex_buffer)) = | ||
render_resource_context.get_asset_resource(*handle, index) | ||
{ | ||
println!("setup vertex buffer {}", index); | ||
render_pipelines.bindings.set_vertex_buffer(index as u8, vertex_buffer); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on my above comments, this would end up as something like
for pipeline in render_pipelines.pipelines {
let pipeline_descriptor = pipeline_descriptors.get(pipeline.descriptor).unwrap();
if let Some(layout) = pipelin_descriptor.layout {
for (slot, vertex_buffer_descriptor) in layout.vertex_buffer_descriptors.iter().enumerate() {
let handle = render_resource_context
.get_asset_resource(*handle, vertex_buffer_descriptor.name)
.expect("mesh does not provide required vertex attribute {} for pipeline {:?}", vertex_buffer_descriptor.name, pipeline_descriptor);
println!("setup vertex buffer {}", slot);
render_pipelines.bindings.set_vertex_buffer(slot as u8, handle);
}
}
}
Gonna fix the rough edges now and propose this PR. ⌨️ |
removed uncessary tests as they don't apply anymore for seperate buffers removed vertex.rs and as_vertex_buffer_descriptor.rs simplified ``VertexBufferDescriptor`` to use only one ``VertexAttributeDescriptor`` ran clippy and fmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looking good to me. Has this been tested with sprite/2d pipelines?
crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs
Outdated
Show resolved
Hide resolved
Works all for me🙂 |
…vetions; moved torwards naming based resources
… vertex_buffers in RenderResourceBinding
Quick summary
Uncool things
|
Okay, from my POV there’s nothing to add to this anymore. 🙂 Some post PR things: While this approach will work for now, over long term, we will hit some issues:
My idea would be to decouple all these things from
This would probably sit somewhere at
|
Summary (Dev version)
Future stuff
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this looks good to me. Most of my feedback is superficial. Allocating a "fallback buffer" for each Mesh feels like overkill, but its not a big deal and we could always allocate "shared fallback buffers" of varying sizes if/when it becomes a problem. We might need to revisit it when we re-add support for multiple vertex buffers (ex: for instancing).
Another followup I'd like is a "custom mesh with custom attributes" example that proves that we support arbitrary layouts with custom shaders. |
…Mesh::new(). Typo fixes. feedback cart
Agree. I'm thinking of a generic buffer that expands size by the largest allocated mesh. Will add this to the followup. |
Looks like sorting attributes breaks the |
Gave the new fixes a try with various permutations of attributes in custom shaders and they all worked. I think this is good to go! |
After update to latest bevy code, there is a big performance degradation caused by this PR. |
My frame rate dropped from 28 to 7, I check out |
@J-F-Liu sounds interesting, can you tell some context? (or even provide some source code?) |
@julhe There are 5431 mesh objects rendered as PrimitiveTopology::LineList, plus mouse movement screen ray interaction checking. |
I'm guessing the extra allocations for the VertexBufferDescriptor in each entity's PipelineSpecialization are to blame for the slight drop in performance (and maybe also the act of re-computing it). If so that would be resolved by the followups called out here: #768 (comment) |
I think the approach we're using now is the right path forward. We just need to remove some of the hot-spots introduced by some slightly naive choices made for simplicity (and to meet the 0.3 deadline that I have arbitrarily set 😄 ). |
Pull request draft for #592