diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-14 20:11:47 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-14 20:11:47 +0400 |
commit | adbd84c320d8b0781e97d09055f6cde4920b79f8 (patch) | |
tree | 4df5496bd2d96a0115aa45526555097f73caad3c | |
parent | a47af30561ea9b0b2933a4af202a560b3576ee11 (diff) |
Fix #34121: OSL + persistent images option was not freeing shader memory properly,
causing memory to increase continuously during animation render.
-rw-r--r-- | intern/cycles/blender/blender_sync.cpp | 5 | ||||
-rw-r--r-- | intern/cycles/render/mesh.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/render/osl.cpp | 13 | ||||
-rw-r--r-- | intern/cycles/render/osl.h | 2 | ||||
-rw-r--r-- | intern/cycles/render/scene.cpp | 14 | ||||
-rw-r--r-- | intern/cycles/render/shader.h | 2 | ||||
-rw-r--r-- | intern/cycles/render/svm.cpp | 4 | ||||
-rw-r--r-- | intern/cycles/render/svm.h | 2 | ||||
-rw-r--r-- | source/blender/editors/render/render_preview.c | 2 |
9 files changed, 42 insertions, 10 deletions
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index 7ad663b7e26..87c4efffe6c 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -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; } diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index 57776e4cfa6..3a6fba32b34 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -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) diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index 28de56f3a72..56158278e29 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -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; diff --git a/intern/cycles/render/osl.h b/intern/cycles/render/osl.h index d17f4c81362..4b4ed6cba00 100644 --- a/intern/cycles/render/osl.h +++ b/intern/cycles/render/osl.h @@ -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); diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp index 093bfecf88e..a1fcffa94a4 100644 --- a/intern/cycles/render/scene.cpp +++ b/intern/cycles/render/scene.cpp @@ -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 */ diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h index d4421002ceb..b38e098e3cb 100644 --- a/intern/cycles/render/shader.h +++ b/intern/cycles/render/shader.h @@ -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 */ diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp index f7cb8f62247..5cb11a4ec1a 100644 --- a/intern/cycles/render/svm.cpp +++ b/intern/cycles/render/svm.cpp @@ -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) diff --git a/intern/cycles/render/svm.h b/intern/cycles/render/svm.h index 0b15c5aaa1e..c1ce619e12a 100644 --- a/intern/cycles/render/svm.h +++ b/intern/cycles/render/svm.h @@ -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); }; diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 33b00cbf2ea..dfc80e4cf51 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -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; } |