I want to make multimateral system (rust) so I need to use a unique pipeline for each material. I store a hashmap in a renderer struct with material types and pipelines (HashMap<TypeId, Pipeline>) and actual materials as vector of different materials (rust dynamic objects). As I want to have the same descriptor sets (camera, lights and textures) for multiple pipelines, I create descriptor sets and layouts first and push them into every my pipeline layout
device.begin_command_buffer(...);
device.cmd_begin_render_pass(...);
// Iterate over TypeIds of binded materials
for material_type in self.pipelines.keys() {
// Get pipeline from HashMap
let pipeline = self.pipelines.get(&material_type).unwrap();
// Bind pipeline
device.cmd_bind_pipeline(... pipeline ...);
// Bind DescSets (they are the same and are stored in separate struct)
device.cmd_bind_descriptor_sets(
...
[
descriptor_pool.descriptor_sets_camera[index],
descriptor_pool.descriptor_sets_texture[index],
descriptor_pool.descriptor_sets_light[index],
]
...
);
// ECS-iterate of models with materials and draw each
for (_, (mesh, handle, transform)) in &mut world.query::<(
&Mesh, &MaterialHandle, &Transform,
)>(){
// Get material from vector
let material = self.materials[handle];
// Compare found material type and binded material type
if material.type_id() == material_type {
device.cmd_bind_index_buffer(...);
device.cmd_bind_vertex_buffers(...);
device.cmd_draw_indexed(...);
}
}
}
device.cmd_end_render_pass(...);
device.end_command_buffer(...)?;