Eevee: Stop depsgraph update callback form allocating unneeded memory
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 29 Nov 2017 10:00:50 +0000 (11:00 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 29 Nov 2017 10:07:52 +0000 (11:07 +0100)
source/blender/draw/engines/eevee/eevee_data.c
source/blender/draw/engines/eevee/eevee_engine.c
source/blender/draw/engines/eevee/eevee_private.h
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_manager.c

index ef1ff02685521adcf774aaa7bf78cfe4f22caf59..d1cd1b1440cb15eead36125e5b6c72c60833a03f 100644 (file)
@@ -78,6 +78,12 @@ static void eevee_lightprobe_data_free(void *storage)
        BLI_freelistN(&ped->captured_object_list);
 }
 
+EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void)
+{
+       return (EEVEE_ViewLayerData *)DRW_view_layer_engine_data_get(
+               &draw_engine_eevee_type);
+}
+
 EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure(void)
 {
        EEVEE_ViewLayerData **sldata = (EEVEE_ViewLayerData **)DRW_view_layer_engine_data_ensure(
@@ -90,6 +96,12 @@ EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure(void)
        return *sldata;
 }
 
+EEVEE_ObjectEngineData *EEVEE_object_data_get(Object *ob)
+{
+       return (EEVEE_ObjectEngineData *)DRW_object_engine_data_get(
+               ob, &draw_engine_eevee_type);
+}
+
 EEVEE_ObjectEngineData *EEVEE_object_data_ensure(Object *ob)
 {
        EEVEE_ObjectEngineData **oedata = (EEVEE_ObjectEngineData **)DRW_object_engine_data_ensure(
@@ -102,6 +114,12 @@ EEVEE_ObjectEngineData *EEVEE_object_data_ensure(Object *ob)
        return *oedata;
 }
 
+EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_get(Object *ob)
+{
+       return (EEVEE_LightProbeEngineData *)DRW_object_engine_data_get(
+               ob, &draw_engine_eevee_type);
+}
+
 EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_ensure(Object *ob)
 {
        EEVEE_LightProbeEngineData **pedata = (EEVEE_LightProbeEngineData **)DRW_object_engine_data_ensure(
@@ -116,6 +134,12 @@ EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_ensure(Object *ob)
        return *pedata;
 }
 
+EEVEE_LampEngineData *EEVEE_lamp_data_get(Object *ob)
+{
+       return (EEVEE_LampEngineData *)DRW_object_engine_data_get(
+               ob, &draw_engine_eevee_type);
+}
+
 EEVEE_LampEngineData *EEVEE_lamp_data_ensure(Object *ob)
 {
        EEVEE_LampEngineData **ledata = (EEVEE_LampEngineData **)DRW_object_engine_data_ensure(
index e505b705f15bd08de7b35bbb305147e7fc191202..8989213baa03a9ebb90fd37ce3c9303e3bb4c57e 100644 (file)
@@ -290,15 +290,15 @@ static void EEVEE_id_update(void *UNUSED(vedata), ID *id)
        const ID_Type id_type = GS(id->name);
        if (id_type == ID_OB) {
                Object *object = (Object *)id;
-               EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(object);
+               EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(object);
                if (ped != NULL) {
                        ped->need_full_update = true;
                }
-               EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(object);
+               EEVEE_LampEngineData *led = EEVEE_lamp_data_get(object);
                if (led != NULL) {
                        led->need_update = true;
                }
-               EEVEE_ObjectEngineData *oedata = EEVEE_object_data_ensure(object);
+               EEVEE_ObjectEngineData *oedata = EEVEE_object_data_get(object);
                if (oedata != NULL) {
                        oedata->need_update = true;
                }
index 9d35d1658ea5ed99c89d8e9821b906329594cae1..dc99d941db805c877ba72d154b9dc033383b5165 100644 (file)
@@ -640,9 +640,13 @@ typedef struct EEVEE_PrivateData {
 } EEVEE_PrivateData; /* Transient data */
 
 /* eevee_data.c */
+EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void);
 EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure(void);
+EEVEE_ObjectEngineData *EEVEE_object_data_get(Object *ob);
 EEVEE_ObjectEngineData *EEVEE_object_data_ensure(Object *ob);
+EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_get(Object *ob);
 EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_ensure(Object *ob);
+EEVEE_LampEngineData *EEVEE_lamp_data_get(Object *ob);
 EEVEE_LampEngineData *EEVEE_lamp_data_ensure(Object *ob);
 
 /* eevee_materials.c */
index a34485e7e408654171ba288d2aa78fd6ab5746f7..0753dbc7a1a081bd2c4bfe5312a69b954189592c 100644 (file)
@@ -384,9 +384,11 @@ struct DefaultTextureList     *DRW_viewport_texture_list_get(void);
 void DRW_viewport_request_redraw(void);
 
 /* ViewLayers */
+void *DRW_view_layer_engine_data_get(DrawEngineType *engine_type);
 void **DRW_view_layer_engine_data_ensure(DrawEngineType *engine_type, void (*callback)(void *storage));
 
 /* Objects */
+void *DRW_object_engine_data_get(Object *ob, DrawEngineType *engine_type);
 void **DRW_object_engine_data_ensure(
         Object *ob, DrawEngineType *engine_type, void (*callback)(void *storage));
 struct LampEngineData *DRW_lamp_engine_data_ensure(Object *ob, struct RenderEngineType *engine_type);
index 9efbf067591e6d1f913f5caec94c72c063e4049b..806c8cce4d563fd280ac7f41cc1505d12cecf19e 100644 (file)
@@ -2702,6 +2702,16 @@ void DRW_viewport_request_redraw(void)
 /** \name ViewLayers (DRW_scenelayer)
  * \{ */
 
+void *DRW_view_layer_engine_data_get(DrawEngineType *engine_type)
+{
+       for (ViewLayerEngineData *sled = DST.draw_ctx.view_layer->drawdata.first; sled; sled = sled->next) {
+               if (sled->engine_type == engine_type) {
+                       return sled->storage;
+               }
+       }
+       return NULL;
+}
+
 void **DRW_view_layer_engine_data_ensure(DrawEngineType *engine_type, void (*callback)(void *storage))
 {
        ViewLayerEngineData *sled;
@@ -2728,6 +2738,16 @@ void **DRW_view_layer_engine_data_ensure(DrawEngineType *engine_type, void (*cal
 /** \name Objects (DRW_object)
  * \{ */
 
+void *DRW_object_engine_data_get(Object *ob, DrawEngineType *engine_type)
+{
+       for (ObjectEngineData *oed = ob->drawdata.first; oed; oed = oed->next) {
+               if (oed->engine_type == engine_type) {
+                       return oed->storage;
+               }
+       }
+       return NULL;
+}
+
 void **DRW_object_engine_data_ensure(
         Object *ob, DrawEngineType *engine_type, void (*callback)(void *storage))
 {