The goal of this patch is to allow that the evaluated geometry of an object has different materials from the original geometry. We need that for geometry nodes. For some more context see T88196 and T86737. I extracted this patch out of D11155 so that it can be reviewed separately.
The main thing that changes for render engines is that the number of material slots on the object and on the geometry might not match anymore.
For original data, the slot counts are still equal, but not for evaluated data.
The "ground truth" for the number of materials is the number of materials on the geometry now. This is important in the current design, because Eevee needs to know the number of materials just based on the mesh in mesh_render_mat_len_get (and similarly in other places).
To lookup the actual materials, I added Material *BKE_object_material_get_eval(Object *ob, short act) which is only meant to be used on evaluated objects. For convenience there is also BKE_object_material_count_eval.
Both functions are exposed through rna, so that Cycles can access the materials the same way.
In a few places I had to add a special case for mesh edit mode to get it to work properly.