[Bf-blender-cvs] [d3c645f72d3] temp-eeveelightcache: Eevee: Move LightCache from ViewLayer to Scene

Clément Foucault noreply at git.blender.org
Fri Jun 15 18:03:22 CEST 2018


Commit: d3c645f72d34547a5dface893285203d7555dd52
Author: Clément Foucault
Date:   Fri Jun 15 18:01:48 2018 +0200
Branches: temp-eeveelightcache
https://developer.blender.org/rBd3c645f72d34547a5dface893285203d7555dd52

Eevee: Move LightCache from ViewLayer to Scene

Also integrate it into the undo system and the depsgraph.

Green light means no cache, red means a baked light cache is used.

===================================================================

M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
M	source/blender/draw/engines/eevee/eevee_data.c
M	source/blender/draw/engines/eevee/eevee_lightcache.c
M	source/blender/draw/engines/eevee/eevee_lightcache.h
M	source/blender/draw/engines/eevee/eevee_lightprobes.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/editors/render/render_shading.c
M	source/blender/makesdna/DNA_scene_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 7e161a8dd2d..47439284c60 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -102,6 +102,9 @@
 #include "DEG_depsgraph_query.h"
 
 #include "RE_engine.h"
+#include "RE_engine.h"
+
+#include "engines/eevee/eevee_lightcache.h"
 
 #include "PIL_time.h"
 
@@ -316,6 +319,9 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
 	else {
 		sce_dst->preview = NULL;
 	}
+
+	sce_dst->eevee.light_cache = NULL;
+	/* TODO Copy the cache. */
 }
 
 Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
@@ -512,6 +518,11 @@ void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
 		sce->master_collection = NULL;
 	}
 
+	if (sce->eevee.light_cache) {
+		EEVEE_lightcache_free(sce->eevee.light_cache);
+		sce->eevee.light_cache = NULL;
+	}
+
 	/* These are freed on doversion. */
 	BLI_assert(sce->layer_properties == NULL);
 }
@@ -854,6 +865,8 @@ void BKE_scene_init(Scene *sce)
 	sce->eevee.shadow_cube_size = 512;
 	sce->eevee.shadow_cascade_size = 1024;
 
+	sce->eevee.light_cache = NULL;
+
 	sce->eevee.flag =
 	        SCE_EEVEE_VOLUMETRIC_LIGHTS |
 	        SCE_EEVEE_VOLUMETRIC_COLORED |
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 8d90a11f5d9..db51e5ba486 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -389,10 +389,13 @@ BlendFileData *BLO_read_from_memfile(
 		blo_split_main(&old_mainlist, oldmain);
 		/* add the library pointers in oldmap lookup */
 		blo_add_library_pointer_map(&old_mainlist, fd);
-		
+
 		/* makes lookup of existing images in old main */
 		blo_make_image_pointer_map(fd, oldmain);
-		
+
+		/* makes lookup of existing light caches in old main */
+		blo_make_scene_pointer_map(fd, oldmain);
+
 		/* makes lookup of existing video clips in old main */
 		blo_make_movieclip_pointer_map(fd, oldmain);
 
@@ -402,7 +405,10 @@ BlendFileData *BLO_read_from_memfile(
 		/* removed packed data from this trick - it's internal data that needs saves */
 		
 		bfd = blo_read_file_internal(fd, filename);
-		
+
+		/* ensures relinked light caches are not freed */
+		blo_end_scene_pointer_map(fd, oldmain);
+
 		/* ensures relinked images are not freed */
 		blo_end_image_pointer_map(fd, oldmain);
 		
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9267e956642..2a95ead6a5f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1338,6 +1338,8 @@ void blo_freefiledata(FileData *fd)
 			oldnewmap_free(fd->imamap);
 		if (fd->movieclipmap)
 			oldnewmap_free(fd->movieclipmap);
+		if (fd->scenemap)
+			oldnewmap_free(fd->scenemap);
 		if (fd->soundmap)
 			oldnewmap_free(fd->soundmap);
 		if (fd->packedmap)
@@ -1525,6 +1527,13 @@ static void *newimaadr(FileData *fd, const void *adr)		    /* used to restore im
 	return NULL;
 }
 
+static void *newsceadr(FileData *fd, const void *adr)		    /* used to restore scene data after undo */
+{
+	if (fd->scenemap && adr)
+		return oldnewmap_lookup_and_inc(fd->scenemap, adr, true);
+	return NULL;
+}
+
 static void *newmclipadr(FileData *fd, const void *adr)      /* used to restore movie clip data after undo */
 {
 	if (fd->movieclipmap && adr)
@@ -1630,6 +1639,37 @@ void blo_clear_proxy_pointers_from_lib(Main *oldmain)
 	}
 }
 
+void blo_make_scene_pointer_map(FileData *fd, Main *oldmain)
+{
+	Scene *sce = oldmain->scene.first;
+
+	fd->scenemap = oldnewmap_new();
+
+	for (; sce; sce = sce->id.next) {
+		if (sce->eevee.light_cache) {
+			struct EEVEE_LightCache *light_cache = sce->eevee.light_cache;
+			oldnewmap_insert(fd->scenemap, light_cache, light_cache, 0);
+		}
+	}
+}
+
+void blo_end_scene_pointer_map(FileData *fd, Main *oldmain)
+{
+	OldNew *entry = fd->scenemap->entries;
+	Scene *sce = oldmain->scene.first;
+	int i;
+
+	/* used entries were restored, so we put them to zero */
+	for (i = 0; i < fd->scenemap->nentries; i++, entry++) {
+		if (entry->nr > 0)
+			entry->newp = NULL;
+	}
+
+	for (; sce; sce = sce->id.next) {
+		sce->eevee.light_cache = newsceadr(fd, sce->eevee.light_cache);
+	}
+}
+
 void blo_make_image_pointer_map(FileData *fd, Main *oldmain)
 {
 	Image *ima = oldmain->image.first;
@@ -6324,6 +6364,9 @@ static void direct_link_scene(FileData *fd, Scene *sce)
 		direct_link_view_layer(fd, view_layer);
 	}
 
+	if (fd->scenemap) sce->eevee.light_cache = newsceadr(fd, sce->eevee.light_cache);
+	else sce->eevee.light_cache = NULL;
+
 	sce->layer_properties = newdataadr(fd, sce->layer_properties);
 	IDP_DirectLinkGroup_OrFree(&sce->layer_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 }
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 7618c023882..bb1f0ef4d7b 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -90,6 +90,7 @@ typedef struct FileData {
 	struct OldNewMap *libmap;
 	struct OldNewMap *imamap;
 	struct OldNewMap *movieclipmap;
+	struct OldNewMap *scenemap;
 	struct OldNewMap *soundmap;
 	struct OldNewMap *packedmap;
 	
@@ -140,6 +141,8 @@ FileData *blo_openblendermemfile(struct MemFile *memfile, struct ReportList *rep
 void blo_clear_proxy_pointers_from_lib(Main *oldmain);
 void blo_make_image_pointer_map(FileData *fd, Main *oldmain);
 void blo_end_image_pointer_map(FileData *fd, Main *oldmain);
+void blo_make_scene_pointer_map(FileData *fd, Main *oldmain);
+void blo_end_scene_pointer_map(FileData *fd, Main *oldmain);
 void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain);
 void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain);
 void blo_make_sound_pointer_map(FileData *fd, Main *oldmain);
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
index 0f49d57a826..86071967d71 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -553,6 +553,13 @@ void update_special_pointers(const Depsgraph *depsgraph,
 			update_particle_system_orig_pointers(object_orig, object_cow);
 			break;
 		}
+		case ID_SCE:
+		{
+			Scene *scene_cow = (Scene *)id_cow;
+			const Scene *scene_orig = (const Scene *)id_orig;
+			scene_cow->eevee.light_cache = scene_orig->eevee.light_cache;
+			break;
+		}
 		default:
 			break;
 	}
@@ -911,6 +918,12 @@ void discard_mesh_edit_mode_pointers(ID *id_cow)
 	mesh_cow->edit_btmesh = NULL;
 }
 
+void discard_scene_pointers(ID *id_cow)
+{
+	Scene *scene_cow = (Scene *)id_cow;
+	scene_cow->eevee.light_cache = NULL;
+}
+
 /* NULL-ify all edit mode pointers which points to data from
  * original object.
  */
@@ -933,6 +946,11 @@ void discard_edit_mode_pointers(ID *id_cow)
 		case ID_LT:
 			discard_lattice_edit_mode_pointers(id_cow);
 			break;
+		case ID_SCE:
+			/* Not really edit mode but still needs to run before
+			 * BKE_libblock_free_datablock() */
+			discard_scene_pointers(id_cow);
+			break;
 		default:
 			break;
 	}
diff --git a/source/blender/draw/engines/eevee/eevee_data.c b/source/blender/draw/engines/eevee/eevee_data.c
index 85b2109e618..96372c0dc30 100644
--- a/source/blender/draw/engines/eevee/eevee_data.c
+++ b/source/blender/draw/engines/eevee/eevee_data.c
@@ -53,11 +53,6 @@ static void eevee_view_layer_data_free(void *storage)
 	MEM_SAFE_FREE(sldata->shcasters_buffers[1].shadow_casters);
 	MEM_SAFE_FREE(sldata->shcasters_buffers[1].flags);
 
-	if (sldata->light_cache != NULL) {
-		EEVEE_lightcache_free(sldata->light_cache);
-		sldata->light_cache = NULL;
-	}
-
 	/* Probes */
 	MEM_SAFE_FREE(sldata->probes);
 	DRW_UBO_FREE_SAFE(sldata->probe_ubo);
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c
index d4a21fd6d6b..da477602839 100644
--- a/source/blender/draw/engines/eevee/eevee_lightcache.c
+++ b/source/blender/draw/engines/eevee/eevee_lightcache.c
@@ -56,6 +56,13 @@
 #define IRRADIANCE_SAMPLE_SIZE_Y 2
 #endif
 
+#ifdef IRRADIANCE_SH_L2
+/* we need a signed format for Spherical Harmonics */
+#  define IRRADIANCE_FORMAT GPU_RGBA16F
+#else
+#  define IRRADIANCE_FORMAT GPU_RGBA8
+#endif
+
 #define IRRADIANCE_MAX_POOL_LAYER 256 /* OpenGL 3.3 core requirement, can be extended but it's already very big */
 #define IRRADIANCE_MAX_POOL_SIZE 1024
 #define MAX_IRRADIANCE_SAMPLES \
@@ -114,7 +121,63 @@ typedef struct EEVEE_LightBake {
 	void *gl_context, *gwn_context;  /* If running in parallel (in a separate thread), use this context. */
 } EEVEE_LightBake;
 
-void *EEVEE_lightcache_job_data_alloc(struct Main *bmain, struct ViewLayer *view_layer, struct Scene *scene, bool run_as_job)
+/* -------------------------------------------------------------------- */
+
+/** \name Light Cache
+ * \{ */
+
+static bool EEVEE_lightcache_validate(
+        const EEVEE_LightCache *light_cache,
+        const SceneEEVEE *UNUSED(eevee),
+        const int UNUSED(cube_count),
+        const int UNUSED(irr_samples))
+{
+	if (light_cache) {
+		/* TODO if settings and probe count matches... */
+		return true;
+	}
+	return false;
+}
+
+EEVEE_LightCache *EEVEE_lightcache_create(
+        const SceneEEVEE *UNUSED(eevee),
+        const int UNUSED(cube_count),
+        const int UNUSED(irr_samples))
+{
+	EEVEE_LightCache *light_cache = MEM_callocN(sizeof(EEVEE_LightCache), "EEVEE_LightCache");
+
+	float rgba[4] = {1.0f, 0.0f, 0.0f, 1.0f};
+	light_cache->grid_tx = DRW_texture_create_2D_array(1, 1, 1, IRRADIANCE_FORMAT, DRW_TEX_FILTER, rgba);
+	light_cache->cube_tx = DRW_texture_create_2D_array(1, 1, 1, GPU_RGBA8, DRW_TEX_FILTER, rgba);
+
+	// int irr_size[3];
+	// irradiance_pool_size_get(lbake->vis_res, lbake->total_irr_samples, irr_size);
+
+	// light_cache->grid_tx = DRW_texture_create_2D_array(irr_size[0], irr_size[1], irr_size[2], IRRADIANCE_FORMAT, DRW_TEX_FILTER, NULL);
+	// light_cache->cube_tx = DRW_texture_create_2D_array(lbake->ref_cube_res, lbake->ref_cube_res, lcac

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list