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

Batch skinned meshes on platforms where storage buffers are available. #16599

Merged
merged 15 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/meshlet/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl InstanceManager {
previous_world_from_local: (&previous_transform).into(),
flags: flags.bits(),
};
let mesh_uniform = MeshUniform::new(&transforms, 0, None);
let mesh_uniform = MeshUniform::new(&transforms, 0, None, None, None);

// Append instance data
self.instances.push((
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_pbr/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ pub struct PrepassPipeline<M: Material> {
pub deferred_material_vertex_shader: Option<Handle<Shader>>,
pub deferred_material_fragment_shader: Option<Handle<Shader>>,
pub material_pipeline: MaterialPipeline<M>,

/// Whether skins will use uniform buffers on account of storage buffers
/// being unavailable on this platform.
pub skins_use_uniform_buffers: bool,

_marker: PhantomData<M>,
}

Expand Down Expand Up @@ -315,6 +320,7 @@ impl<M: Material> FromWorld for PrepassPipeline<M> {
},
material_layout: M::bind_group_layout(render_device),
material_pipeline: world.resource::<MaterialPipeline<M>>().clone(),
skins_use_uniform_buffers: skin::skins_use_uniform_buffers(render_device),
_marker: PhantomData,
}
}
Expand Down Expand Up @@ -468,6 +474,7 @@ where
&key.mesh_key,
&mut shader_defs,
&mut vertex_attributes,
self.skins_use_uniform_buffers,
);
bind_group_layouts.insert(1, bind_group);

Expand Down
7 changes: 6 additions & 1 deletion crates/bevy_pbr/src/prepass/prepass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
#endif

#ifdef SKINNED
var world_from_local = skinning::skin_model(vertex.joint_indices, vertex.joint_weights);
var world_from_local = skinning::skin_model(
vertex.joint_indices,
vertex.joint_weights,
vertex_no_morph.instance_index
);
#else // SKINNED
// Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
// See https://github.com/gfx-rs/naga/issues/2416
Expand Down Expand Up @@ -140,6 +144,7 @@ fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
let prev_model = skinning::skin_prev_model(
prev_vertex.joint_indices,
prev_vertex.joint_weights,
vertex_no_morph.instance_index
);
#else // HAS_PREVIOUS_SKIN
let prev_model = mesh_functions::get_previous_world_from_local(prev_vertex.instance_index);
Expand Down
Loading