@@ -1300,8 +1300,11 @@ pub struct MaterialProperties {
1300
1300
pub reads_view_transmission_texture : bool ,
1301
1301
pub render_phase_type : RenderPhaseType ,
1302
1302
pub material_layout : Option < BindGroupLayout > ,
1303
- pub draw_functions : HashMap < InternedDrawFunctionLabel , DrawFunctionId > ,
1304
- pub shaders : HashMap < InternedShaderLabel , Handle < Shader > > ,
1303
+ /// Backing array is a size of 4 because the `StandardMaterial` needs 4 draw functions by default
1304
+ pub draw_functions : SmallVec < [ ( InternedDrawFunctionLabel , DrawFunctionId ) ; 4 ] > ,
1305
+ /// Backing array is a size of 3 because the `StandardMaterial` has 3 custom shaders (`frag`, `prepass_frag`, `deferred_frag`) which is the
1306
+ /// most common use case
1307
+ pub shaders : SmallVec < [ ( InternedShaderLabel , Handle < Shader > ) ; 3 ] > ,
1305
1308
/// Whether this material *actually* uses bindless resources, taking the
1306
1309
/// platform support (or lack thereof) of bindless resources into account.
1307
1310
pub bindless : bool ,
@@ -1320,27 +1323,31 @@ pub struct MaterialProperties {
1320
1323
1321
1324
impl MaterialProperties {
1322
1325
pub fn get_shader ( & self , label : impl ShaderLabel ) -> Option < Handle < Shader > > {
1323
- self . shaders . get ( & label. intern ( ) ) . cloned ( )
1326
+ self . shaders
1327
+ . iter ( )
1328
+ . find ( |( inner_label, _) | inner_label == & label. intern ( ) )
1329
+ . map ( |( _, shader) | shader)
1330
+ . cloned ( )
1324
1331
}
1325
1332
1326
- pub fn add_shader (
1327
- & mut self ,
1328
- label : impl ShaderLabel ,
1329
- shader : Handle < Shader > ,
1330
- ) -> Option < Handle < Shader > > {
1331
- self . shaders . insert ( label. intern ( ) , shader)
1333
+ pub fn add_shader ( & mut self , label : impl ShaderLabel , shader : Handle < Shader > ) {
1334
+ self . shaders . push ( ( label. intern ( ) , shader) ) ;
1332
1335
}
1333
1336
1334
1337
pub fn get_draw_function ( & self , label : impl DrawFunctionLabel ) -> Option < DrawFunctionId > {
1335
- self . draw_functions . get ( & label. intern ( ) ) . copied ( )
1338
+ self . draw_functions
1339
+ . iter ( )
1340
+ . find ( |( inner_label, _) | inner_label == & label. intern ( ) )
1341
+ . map ( |( _, shader) | shader)
1342
+ . cloned ( )
1336
1343
}
1337
1344
1338
1345
pub fn add_draw_function (
1339
1346
& mut self ,
1340
1347
label : impl DrawFunctionLabel ,
1341
1348
draw_function : DrawFunctionId ,
1342
- ) -> Option < DrawFunctionId > {
1343
- self . draw_functions . insert ( label. intern ( ) , draw_function)
1349
+ ) {
1350
+ self . draw_functions . push ( ( label. intern ( ) , draw_function) ) ;
1344
1351
}
1345
1352
}
1346
1353
@@ -1472,27 +1479,27 @@ where
1472
1479
_ => None ,
1473
1480
} ;
1474
1481
1475
- let mut draw_functions = HashMap :: new ( ) ;
1476
- draw_functions. insert ( MaterialDrawFunction . intern ( ) , draw_function_id) ;
1482
+ let mut draw_functions = SmallVec :: new ( ) ;
1483
+ draw_functions. push ( ( MaterialDrawFunction . intern ( ) , draw_function_id) ) ;
1477
1484
if let Some ( prepass_draw_function_id) = prepass_draw_function_id {
1478
- draw_functions. insert ( PrepassDrawFunction . intern ( ) , prepass_draw_function_id) ;
1485
+ draw_functions. push ( ( PrepassDrawFunction . intern ( ) , prepass_draw_function_id) ) ;
1479
1486
}
1480
1487
if let Some ( deferred_draw_function_id) = deferred_draw_function_id {
1481
- draw_functions. insert ( DeferredDrawFunction . intern ( ) , deferred_draw_function_id) ;
1488
+ draw_functions. push ( ( DeferredDrawFunction . intern ( ) , deferred_draw_function_id) ) ;
1482
1489
}
1483
1490
if let Some ( shadow_draw_function_id) = shadow_draw_function_id {
1484
- draw_functions. insert ( ShadowsDrawFunction . intern ( ) , shadow_draw_function_id) ;
1491
+ draw_functions. push ( ( ShadowsDrawFunction . intern ( ) , shadow_draw_function_id) ) ;
1485
1492
}
1486
1493
1487
- let mut shaders = HashMap :: new ( ) ;
1494
+ let mut shaders = SmallVec :: new ( ) ;
1488
1495
let mut add_shader = |label : InternedShaderLabel , shader_ref : ShaderRef | {
1489
1496
let mayber_shader = match shader_ref {
1490
1497
ShaderRef :: Default => None ,
1491
1498
ShaderRef :: Handle ( handle) => Some ( handle) ,
1492
1499
ShaderRef :: Path ( path) => Some ( asset_server. load ( path) ) ,
1493
1500
} ;
1494
1501
if let Some ( shader) = mayber_shader {
1495
- shaders. insert ( label, shader) ;
1502
+ shaders. push ( ( label, shader) ) ;
1496
1503
}
1497
1504
} ;
1498
1505
add_shader ( MaterialVertexShader . intern ( ) , M :: vertex_shader ( ) ) ;
0 commit comments