Fix #34121: OSL + persistent images option was not freeing shader memory properly,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 14 Feb 2013 16:11:47 +0000 (16:11 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 14 Feb 2013 16:11:47 +0000 (16:11 +0000)
causing memory to increase continuously during animation render.

intern/cycles/blender/blender_sync.cpp
intern/cycles/render/mesh.cpp
intern/cycles/render/osl.cpp
intern/cycles/render/osl.h
intern/cycles/render/scene.cpp
intern/cycles/render/shader.h
intern/cycles/render/svm.cpp
intern/cycles/render/svm.h
source/blender/editors/render/render_preview.c

index 7ad663b7e26d2881e23a6496dc7ed471cc2e9385..87c4efffe6c07027fe71f26f4824145264b0511f 100644 (file)
@@ -307,7 +307,10 @@ SceneParams BlenderSync::get_scene_params(BL::Scene b_scene, bool background)
        params.use_bvh_spatial_split = RNA_boolean_get(&cscene, "debug_use_spatial_splits");
        params.use_bvh_cache = (background)? RNA_boolean_get(&cscene, "use_cache"): false;
 
-       params.persistent_images = (background)? r.use_persistent_data(): false;
+       if(background && params.shadingsystem != SceneParams::OSL)
+               params.persistent_images = r.use_persistent_data();
+       else
+               params.persistent_images = false;
 
        return params;
 }
index 57776e4cfa635f7f0eaf34f4cfea13e1f189dba4..3a6fba32b344555e2c8eb75a8c0dc4fbc69a29e6 100644 (file)
@@ -966,6 +966,14 @@ void MeshManager::device_free(Device *device, DeviceScene *dscene)
        dscene->attributes_map.clear();
        dscene->attributes_float.clear();
        dscene->attributes_float3.clear();
+
+       OSLGlobals *og = (OSLGlobals*)device->osl_memory();
+
+       if(og) {
+               og->object_name_map.clear();
+               og->attribute_map.clear();
+               og->object_names.clear();
+       }
 }
 
 void MeshManager::tag_update(Scene *scene)
index 28de56f3a727a96c7d4a96b412c5a761bd5c901d..56158278e29e8593ac2606a9da27e1cb0f2bf603 100644 (file)
@@ -47,15 +47,25 @@ OSLShaderManager::OSLShaderManager()
 {
        services = new OSLRenderServices();
 
-       shading_system_init();
        texture_system_init();
+       shading_system_init();
 }
 
 OSLShaderManager::~OSLShaderManager()
 {
        OSL::ShadingSystem::destroy(ss);
        OSL::TextureSystem::destroy(ts);
+
+       delete services;
+}
+
+void OSLShaderManager::reset(Scene *scene)
+{
+       OSL::ShadingSystem::destroy(ss);
        delete services;
+
+       services = new OSLRenderServices();
+       shading_system_init();
 }
 
 void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
@@ -88,6 +98,7 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
        og->ss = ss;
        og->ts = ts;
        og->services = services;
+
        int background_id = scene->shader_manager->get_shader_id(scene->default_background);
        og->background_state = og->surface_state[background_id & SHADER_MASK];
        og->use = true;
index d17f4c813621cf57332032fc27427a48f458ac34..4b4ed6cba0038a9a14b39967012ff7ff50db69df 100644 (file)
@@ -64,6 +64,8 @@ public:
        OSLShaderManager();
        ~OSLShaderManager();
 
+       void reset(Scene *scene);
+
        bool use_osl() { return true; }
 
        void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
index 093bfecf88e0ef9c5156671baf2cb12f15194049..a1fcffa94a42d494ea9fe1298d8da6685130f845 100644 (file)
@@ -85,6 +85,12 @@ void Scene::free_memory(bool final)
        foreach(ParticleSystem *p, particle_systems)
                delete p;
 
+       shaders.clear();
+       meshes.clear();
+       objects.clear();
+       lights.clear();
+       particle_systems.clear();
+
        if(device) {
                camera->device_free(device, &dscene);
                filter->device_free(device, &dscene);
@@ -118,13 +124,6 @@ void Scene::free_memory(bool final)
                delete curve_system_manager;
                delete image_manager;
        }
-       else {
-               shaders.clear();
-               meshes.clear();
-               objects.clear();
-               lights.clear();
-               particle_systems.clear();
-       }
 }
 
 void Scene::device_update(Device *device_, Progress& progress)
@@ -257,6 +256,7 @@ bool Scene::need_reset()
 
 void Scene::reset()
 {
+       shader_manager->reset(this);
        shader_manager->add_default(this);
 
        /* ensure all objects are updated */
index d4421002cebc0e6e246ecf7f4a54d0f691ecf465..b38e098e3cbef4e93d78392f34d631eaff840244 100644 (file)
@@ -110,6 +110,8 @@ public:
        static ShaderManager *create(Scene *scene, int shadingsystem);
        virtual ~ShaderManager();
 
+       virtual void reset(Scene *scene) = 0;
+
        virtual bool use_osl() { return false; }
 
        /* device update */
index f7cb8f62247b42c2916ddd076384383a6e6a591b..5cb11a4ec1aa3c0a83d26dbef127b5db19d323f2 100644 (file)
@@ -40,6 +40,10 @@ SVMShaderManager::~SVMShaderManager()
 {
 }
 
+void SVMShaderManager::reset(Scene *scene)
+{
+}
+
 void SVMShaderManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
 {
        if(!need_update)
index 0b15c5aaa1ef9c5437e722711e0f126e35185e60..c1ce619e12a8824dee0d14d476d575cac13711ed 100644 (file)
@@ -45,6 +45,8 @@ public:
        SVMShaderManager();
        ~SVMShaderManager();
 
+       void reset(Scene *scene);
+
        void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
        void device_free(Device *device, DeviceScene *dscene);
 };
index 33b00cbf2ea21dea430ed76bd8556d675ac384de..dfc80e4cf515f82b490024d1dab13603925430bd 100644 (file)
@@ -362,7 +362,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                }
                                else {
                                        /* use current scene world to light sphere */
-                                       if (ma->pr_type == MA_SPHERE_A)
+                                       if (mat->pr_type == MA_SPHERE_A)
                                                sce->world = scene->world;
                                }