[Bf-blender-cvs] [74df307] master: Cycles: Free unused image buffers when rendering with locked interface

Sergey Sharybin noreply at git.blender.org
Mon Apr 6 15:07:54 CEST 2015


Commit: 74df307ca43df14b759fd9eb6a049a6c5d90dcda
Author: Sergey Sharybin
Date:   Thu Apr 2 19:24:14 2015 +0500
Branches: master
https://developer.blender.org/rB74df307ca43df14b759fd9eb6a049a6c5d90dcda

Cycles: Free unused image buffers when rendering with locked interface

It is still possible to free a bit more memory by detecting buildin images
which are not used by shaders, but that's not going to improve memory usage
that much to bother about this now.

Such change brings peak memory usage from 4.1GB to 3.4GB when rendering
01_01_01_D layout scene from the Gooseberry project. Mainly because of
freeing memory used by rather huge environment map in the viewport.

Reviewers: campbellbarton, juicyfruit

Subscribers: eyecandy

Differential Revision: https://developer.blender.org/D1215

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

M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/blender/blender_sync.h
M	source/blender/makesrna/intern/rna_image_api.c

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

diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index 2ed6186..aaf7d7d 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -150,6 +150,7 @@ void BlenderSync::sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, void *
 	sync_integrator();
 	sync_film();
 	sync_shaders();
+	sync_images();
 	sync_curve_settings();
 
 	mesh_synced.clear(); /* use for objects and motion sync */
@@ -360,6 +361,38 @@ void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer)
 	}
 }
 
+/* Images */
+void BlenderSync::sync_images()
+{
+	/* Sync is a convention for this API, but currently it frees unused buffers. */
+
+	const bool is_interface_locked = b_engine.render() &&
+	                                 b_engine.render().use_lock_interface();
+	if(is_interface_locked == false && BlenderSession::headless == false) {
+		/* If interface is not locked, it's possible image is needed for
+		 * the display.
+		 */
+		return;
+	}
+	/* Free buffers used by images which are not needed for render. */
+	BL::BlendData::images_iterator b_image;
+	for(b_data.images.begin(b_image);
+	    b_image != b_data.images.end();
+	    ++b_image)
+	{
+		/* TODO(sergey): Consider making it an utility function to check
+		 * whether image is considered builtin.
+		 */
+		const bool is_builtin = b_image->packed_file() ||
+		                        b_image->source() == BL::Image::source_GENERATED ||
+		                        b_image->source() == BL::Image::source_MOVIE;
+		if(is_builtin == false) {
+			b_image->buffers_free();
+		}
+		/* TODO(sergey): Free builtin images not used by any shader. */
+	}
+}
+
 /* Scene Parameters */
 
 SceneParams BlenderSync::get_scene_params(BL::Scene b_scene, bool background, bool is_cpu)
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 2c2e41f..5fbf2c3 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -95,6 +95,9 @@ private:
 	/* particles */
 	bool sync_dupli_particle(BL::Object b_ob, BL::DupliObject b_dup, Object *object);
 
+	/* Images. */
+	void sync_images();
+
 	/* util */
 	void find_shader(BL::ID id, vector<uint>& used_shaders, int default_shader);
 	bool BKE_object_is_modified(BL::Object b_ob);
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index b9a1237..7fb5885 100644
--- a/source/blender/makesrna/intern/rna_image_api.c
+++ b/source/blender/makesrna/intern/rna_image_api.c
@@ -288,6 +288,11 @@ static void rna_Image_filepath_from_user(Image *image, ImageUser *image_user, ch
 	BKE_image_user_file_path(image_user, image, filepath);
 }
 
+static void rna_Image_buffers_free(Image *image)
+{
+	BKE_image_free_buffers(image);
+}
+
 #else
 
 void RNA_api_image(StructRNA *srna)
@@ -374,6 +379,9 @@ void RNA_api_image(StructRNA *srna)
 	RNA_def_property_flag(parm, PROP_THICK_WRAP);  /* needed for string return value */
 	RNA_def_function_output(func, parm);
 
+	func = RNA_def_function(srna, "buffers_free", "rna_Image_buffers_free");
+	RNA_def_function_ui_description(func, "Free the image buffers from memory");
+
 	/* TODO, pack/unpack, maybe should be generic functions? */
 }




More information about the Bf-blender-cvs mailing list