-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Batch skinned meshes #10094
base: main
Are you sure you want to change the base?
Batch skinned meshes #10094
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,7 +20,7 @@ pub(crate) const JOINT_BUFFER_SIZE: usize = MAX_JOINTS * JOINT_SIZE; | |||||
|
||||||
/// Individual layout entries. | ||||||
mod layout_entry { | ||||||
use super::{JOINT_BUFFER_SIZE, MORPH_BUFFER_SIZE}; | ||||||
use super::{JOINT_BUFFER_SIZE, JOINT_SIZE, MORPH_BUFFER_SIZE}; | ||||||
use crate::MeshUniform; | ||||||
use bevy_render::{ | ||||||
render_resource::{ | ||||||
|
@@ -30,14 +30,23 @@ mod layout_entry { | |||||
renderer::RenderDevice, | ||||||
}; | ||||||
|
||||||
fn buffer(binding: u32, size: u64, visibility: ShaderStages) -> BindGroupLayoutEntry { | ||||||
fn buffer( | ||||||
binding: u32, | ||||||
size: u64, | ||||||
visibility: ShaderStages, | ||||||
is_storage: bool, | ||||||
) -> BindGroupLayoutEntry { | ||||||
BindGroupLayoutEntry { | ||||||
binding, | ||||||
visibility, | ||||||
count: None, | ||||||
ty: BindingType::Buffer { | ||||||
ty: BufferBindingType::Uniform, | ||||||
has_dynamic_offset: true, | ||||||
ty: if is_storage { | ||||||
BufferBindingType::Storage { read_only: true } | ||||||
} else { | ||||||
BufferBindingType::Uniform | ||||||
}, | ||||||
has_dynamic_offset: !is_storage, | ||||||
min_binding_size: BufferSize::new(size), | ||||||
}, | ||||||
} | ||||||
|
@@ -49,11 +58,27 @@ mod layout_entry { | |||||
render_device, | ||||||
) | ||||||
} | ||||||
pub(super) fn skinning(binding: u32) -> BindGroupLayoutEntry { | ||||||
buffer(binding, JOINT_BUFFER_SIZE as u64, ShaderStages::VERTEX) | ||||||
pub(super) fn skinning(render_device: &RenderDevice, binding: u32) -> BindGroupLayoutEntry { | ||||||
let is_storage = render_device.limits().max_storage_buffers_per_shader_stage > 0; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
At this point, I think we should add a method like "storage_buffers_supported()" to RenderDevice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does your suggestion change? The lines look identical to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't change anything sorry. This was meant to be a regular comment on that line. |
||||||
let min_binding_size = if is_storage { | ||||||
JOINT_SIZE | ||||||
} else { | ||||||
JOINT_BUFFER_SIZE | ||||||
}; | ||||||
buffer( | ||||||
binding, | ||||||
min_binding_size as u64, | ||||||
ShaderStages::VERTEX, | ||||||
is_storage, | ||||||
) | ||||||
} | ||||||
pub(super) fn weights(binding: u32) -> BindGroupLayoutEntry { | ||||||
buffer(binding, MORPH_BUFFER_SIZE as u64, ShaderStages::VERTEX) | ||||||
buffer( | ||||||
binding, | ||||||
MORPH_BUFFER_SIZE as u64, | ||||||
ShaderStages::VERTEX, | ||||||
false, | ||||||
) | ||||||
} | ||||||
pub(super) fn targets(binding: u32) -> BindGroupLayoutEntry { | ||||||
BindGroupLayoutEntry { | ||||||
|
@@ -72,8 +97,11 @@ mod layout_entry { | |||||
/// for bind groups. | ||||||
mod entry { | ||||||
use super::{JOINT_BUFFER_SIZE, MORPH_BUFFER_SIZE}; | ||||||
use bevy_render::render_resource::{ | ||||||
BindGroupEntry, BindingResource, Buffer, BufferBinding, BufferSize, TextureView, | ||||||
use bevy_render::{ | ||||||
render_resource::{ | ||||||
BindGroupEntry, BindingResource, Buffer, BufferBinding, BufferSize, TextureView, | ||||||
}, | ||||||
renderer::RenderDevice, | ||||||
}; | ||||||
|
||||||
fn entry(binding: u32, size: u64, buffer: &Buffer) -> BindGroupEntry { | ||||||
|
@@ -89,8 +117,19 @@ mod entry { | |||||
pub(super) fn model(binding: u32, resource: BindingResource) -> BindGroupEntry { | ||||||
BindGroupEntry { binding, resource } | ||||||
} | ||||||
pub(super) fn skinning(binding: u32, buffer: &Buffer) -> BindGroupEntry { | ||||||
entry(binding, JOINT_BUFFER_SIZE as u64, buffer) | ||||||
pub(super) fn skinning<'b>( | ||||||
render_device: &RenderDevice, | ||||||
binding: u32, | ||||||
buffer: &'b Buffer, | ||||||
) -> BindGroupEntry<'b> { | ||||||
if render_device.limits().max_storage_buffers_per_shader_stage > 0 { | ||||||
BindGroupEntry { | ||||||
binding, | ||||||
resource: buffer.as_entire_binding(), | ||||||
} | ||||||
} else { | ||||||
entry(binding, JOINT_BUFFER_SIZE as u64, buffer) | ||||||
} | ||||||
} | ||||||
pub(super) fn weights(binding: u32, buffer: &Buffer) -> BindGroupEntry { | ||||||
entry(binding, MORPH_BUFFER_SIZE as u64, buffer) | ||||||
|
@@ -149,7 +188,7 @@ impl MeshLayouts { | |||||
render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { | ||||||
entries: &[ | ||||||
layout_entry::model(render_device, 0), | ||||||
layout_entry::skinning(1), | ||||||
layout_entry::skinning(render_device, 1), | ||||||
], | ||||||
label: Some("skinned_mesh_layout"), | ||||||
}) | ||||||
|
@@ -168,7 +207,7 @@ impl MeshLayouts { | |||||
render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { | ||||||
entries: &[ | ||||||
layout_entry::model(render_device, 0), | ||||||
layout_entry::skinning(1), | ||||||
layout_entry::skinning(render_device, 1), | ||||||
layout_entry::weights(2), | ||||||
layout_entry::targets(3), | ||||||
], | ||||||
|
@@ -192,7 +231,10 @@ impl MeshLayouts { | |||||
skin: &Buffer, | ||||||
) -> BindGroup { | ||||||
render_device.create_bind_group(&BindGroupDescriptor { | ||||||
entries: &[entry::model(0, model.clone()), entry::skinning(1, skin)], | ||||||
entries: &[ | ||||||
entry::model(0, model.clone()), | ||||||
entry::skinning(render_device, 1, skin), | ||||||
], | ||||||
layout: &self.skinned, | ||||||
label: Some("skinned_mesh_bind_group"), | ||||||
}) | ||||||
|
@@ -225,7 +267,7 @@ impl MeshLayouts { | |||||
render_device.create_bind_group(&BindGroupDescriptor { | ||||||
entries: &[ | ||||||
entry::model(0, model.clone()), | ||||||
entry::skinning(1, skin), | ||||||
entry::skinning(render_device, 1, skin), | ||||||
entry::weights(2, weights), | ||||||
entry::targets(3, targets), | ||||||
], | ||||||
|
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.
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.
Agree with this change, as
from
has a special meaning in Rust wrt theFrom
-trait (I am aware that you're aware, but potential new contributors might not)