Commit: 2ebde4c82bd478d19a9b3116ac600e715ffc0165 Author: Clément Foucault Date: Mon Jun 5 22:05:21 2017 +0200 Branches: blender2.8 https://developer.blender.org/rB2ebde4c82bd478d19a9b3116ac600e715ffc0165
Eevee: Optimize scene with a large number of objects. Using a GHash to store the shgroup of every Material. This way we do not duplicates the DRWShadingGroups allocations on every object. =================================================================== M source/blender/draw/engines/eevee/eevee_engine.c M source/blender/draw/engines/eevee/eevee_materials.c M source/blender/draw/engines/eevee/eevee_private.h =================================================================== diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index 769edc3503c..2a75777c15e 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -109,10 +109,11 @@ static void EEVEE_cache_populate(void *vedata, Object *ob) } } -static void EEVEE_cache_finish(void *UNUSED(vedata)) +static void EEVEE_cache_finish(void *vedata) { EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get(); + EEVEE_materials_cache_finish(vedata); EEVEE_lights_cache_finish(sldata); EEVEE_probes_cache_finish(sldata); } diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index 3f01267fba0..a5f29872e58 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -28,6 +28,7 @@ #include "DNA_world_types.h" #include "BLI_dynstr.h" +#include "BLI_ghash.h" #include "GPU_material.h" @@ -276,6 +277,11 @@ void EEVEE_materials_cache_init(EEVEE_Data *vedata) EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl; EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get(); + /* Create Material Ghash */ + { + stl->g_data->material_hash = BLI_ghash_ptr_new("Eevee_material ghash"); + } + { psl->background_pass = DRW_pass_create("Background Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR); @@ -356,6 +362,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sl EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl; EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl; const DRWContextState *draw_ctx = DRW_context_state_get(); + GHash *material_hash = stl->g_data->material_hash; IDProperty *ces_mode_ob = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_OBJECT, ""); const bool do_cull = BKE_collection_engine_property_value_get_bool(ces_mode_ob, "show_backface_culling"); @@ -392,6 +399,12 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sl float *spec_p = &ma->spec; float *rough_p = &ma->gloss_mir; + shgrp = BLI_ghash_lookup(material_hash, (const void *)ma); + if (shgrp) { + ADD_SHGROUP_CALL(shgrp, ob, mat_geom[i]); + continue; + } + if (ma->use_nodes && ma->nodetree) { Scene *scene = draw_ctx->scene; struct GPUMaterial *gpumat = EEVEE_material_mesh_get(scene, ma); @@ -400,6 +413,8 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sl if (shgrp) { add_standard_uniforms(shgrp, sldata); + BLI_ghash_insert(material_hash, ma, shgrp); + ADD_SHGROUP_CALL(shgrp, ob, mat_geom[i]); } else { @@ -420,12 +435,21 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sl DRW_shgroup_uniform_float(shgrp, "specular", spec_p, 1); DRW_shgroup_uniform_float(shgrp, "roughness", rough_p, 1); + BLI_ghash_insert(material_hash, ma, shgrp); + ADD_SHGROUP_CALL(shgrp, ob, mat_geom[i]); } } } } +void EEVEE_materials_cache_finish(EEVEE_Data *vedata) +{ + EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl; + + BLI_ghash_free(stl->g_data->material_hash, NULL, NULL); +} + void EEVEE_materials_free(void) { MEM_SAFE_FREE(e_data.frag_shader_lib); diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 0d5ab592563..84c6de8593c 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -303,6 +303,7 @@ typedef struct EEVEE_PrivateData { struct DRWShadingGroup *shadow_shgrp; struct DRWShadingGroup *depth_shgrp; struct DRWShadingGroup *depth_shgrp_cull; + struct GHash *material_hash; } EEVEE_PrivateData; /* Transient data */ /* eevee_data.c */ @@ -315,6 +316,7 @@ EEVEE_LampEngineData *EEVEE_lamp_data_get(Object *ob); void EEVEE_materials_init(void); void EEVEE_materials_cache_init(EEVEE_Data *vedata); void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sldata, Object *ob, struct Batch *geom); +void EEVEE_materials_cache_finish(EEVEE_Data *vedata); struct GPUMaterial *EEVEE_material_world_probe_get(struct Scene *scene, struct World *wo); struct GPUMaterial *EEVEE_material_world_background_get(struct Scene *scene, struct World *wo); struct GPUMaterial *EEVEE_material_mesh_probe_get(struct Scene *scene, Material *ma); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs