@@ -39,7 +39,7 @@ use std::marker::PhantomData;
3939/// way to render [`Mesh`] entities with custom shader logic. For materials that can specialize their [`RenderPipelineDescriptor`]
4040/// based on specific material values, see [`SpecializedMaterial`]. [`Material`] automatically implements [`SpecializedMaterial`]
4141/// and can be used anywhere that type is used (such as [`MaterialPlugin`]).
42- pub trait Material : Asset + RenderAsset {
42+ pub trait Material : Asset + RenderAsset + Sized {
4343 /// Returns this material's [`BindGroup`]. This should match the layout returned by [`Material::bind_group_layout`].
4444 fn bind_group ( material : & <Self as RenderAsset >:: PreparedAsset ) -> & BindGroup ;
4545
@@ -78,6 +78,7 @@ pub trait Material: Asset + RenderAsset {
7878 #[ allow( unused_variables) ]
7979 #[ inline]
8080 fn specialize (
81+ pipeline : & MaterialPipeline < Self > ,
8182 descriptor : & mut RenderPipelineDescriptor ,
8283 layout : & MeshVertexBufferLayout ,
8384 ) -> Result < ( ) , SpecializedMeshPipelineError > {
@@ -89,19 +90,16 @@ impl<M: Material> SpecializedMaterial for M {
8990 type Key = ( ) ;
9091
9192 #[ inline]
92- fn key (
93- _render_device : & RenderDevice ,
94- _material : & <Self as RenderAsset >:: PreparedAsset ,
95- ) -> Self :: Key {
96- }
93+ fn key ( _material : & <Self as RenderAsset >:: PreparedAsset ) -> Self :: Key { }
9794
9895 #[ inline]
9996 fn specialize (
97+ pipeline : & MaterialPipeline < Self > ,
10098 descriptor : & mut RenderPipelineDescriptor ,
10199 _key : Self :: Key ,
102100 layout : & MeshVertexBufferLayout ,
103101 ) -> Result < ( ) , SpecializedMeshPipelineError > {
104- <M as Material >:: specialize ( descriptor, layout)
102+ <M as Material >:: specialize ( pipeline , descriptor, layout)
105103 }
106104
107105 #[ inline]
@@ -141,20 +139,18 @@ impl<M: Material> SpecializedMaterial for M {
141139/// way to render [`Mesh`] entities with custom shader logic. [`SpecializedMaterials`](SpecializedMaterial) use their [`SpecializedMaterial::Key`]
142140/// to customize their [`RenderPipelineDescriptor`] based on specific material values. The slightly simpler [`Material`] trait
143141/// should be used for materials that do not need specialization. [`Material`] types automatically implement [`SpecializedMaterial`].
144- pub trait SpecializedMaterial : Asset + RenderAsset {
142+ pub trait SpecializedMaterial : Asset + RenderAsset + Sized {
145143 /// The key used to specialize this material's [`RenderPipelineDescriptor`].
146144 type Key : PartialEq + Eq + Hash + Clone + Send + Sync ;
147145
148146 /// Extract the [`SpecializedMaterial::Key`] for the "prepared" version of this material. This key will be
149147 /// passed in to the [`SpecializedMaterial::specialize`] function when compiling the [`RenderPipeline`](bevy_render::render_resource::RenderPipeline)
150148 /// for a given entity's material.
151- fn key (
152- render_device : & RenderDevice ,
153- material : & <Self as RenderAsset >:: PreparedAsset ,
154- ) -> Self :: Key ;
149+ fn key ( material : & <Self as RenderAsset >:: PreparedAsset ) -> Self :: Key ;
155150
156151 /// Specializes the given `descriptor` according to the given `key`.
157152 fn specialize (
153+ pipeline : & MaterialPipeline < Self > ,
158154 descriptor : & mut RenderPipelineDescriptor ,
159155 key : Self :: Key ,
160156 layout : & MeshVertexBufferLayout ,
@@ -258,7 +254,7 @@ impl<M: SpecializedMaterial> SpecializedMeshPipeline for MaterialPipeline<M> {
258254 self . mesh_pipeline. mesh_layout. clone( ) ,
259255 ] ) ;
260256
261- M :: specialize ( & mut descriptor, key. material_key , layout) ?;
257+ M :: specialize ( self , & mut descriptor, key. material_key , layout) ?;
262258 Ok ( descriptor)
263259 }
264260}
@@ -315,7 +311,6 @@ pub fn queue_material_meshes<M: SpecializedMaterial>(
315311 material_pipeline : Res < MaterialPipeline < M > > ,
316312 mut pipelines : ResMut < SpecializedMeshPipelines < MaterialPipeline < M > > > ,
317313 mut pipeline_cache : ResMut < PipelineCache > ,
318- render_device : Res < RenderDevice > ,
319314 msaa : Res < Msaa > ,
320315 render_meshes : Res < RenderAssets < Mesh > > ,
321316 render_materials : Res < RenderAssets < M > > ,
@@ -328,7 +323,6 @@ pub fn queue_material_meshes<M: SpecializedMaterial>(
328323 & mut RenderPhase < Transparent3d > ,
329324 ) > ,
330325) {
331- let render_device = render_device. into_inner ( ) ;
332326 for ( view, visible_entities, mut opaque_phase, mut alpha_mask_phase, mut transparent_phase) in
333327 views. iter_mut ( )
334328 {
@@ -363,7 +357,7 @@ pub fn queue_material_meshes<M: SpecializedMaterial>(
363357 mesh_key |= MeshPipelineKey :: TRANSPARENT_MAIN_PASS ;
364358 }
365359
366- let material_key = M :: key ( render_device , material) ;
360+ let material_key = M :: key ( material) ;
367361
368362 let pipeline_id = pipelines. specialize (
369363 & mut pipeline_cache,
0 commit comments