diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-05 03:48:07 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-05 03:48:07 +0400 |
commit | c77f46d2dd28b2d450f29a51df133dfa7aff35d9 (patch) | |
tree | dc7f033e1509a25c9de6b39e6e79e1696d0013f6 /intern | |
parent | 0874237358aa6a80b7b56df1ca482a2db17a5d0d (diff) |
Fix #34601: cycles OSL crash when using preview render and viewport render at
the same time, due to shared texture cache system.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/render/osl.cpp | 40 | ||||
-rw-r--r-- | intern/cycles/render/osl.h | 5 |
2 files changed, 37 insertions, 8 deletions
diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index cefb6315725..3294f1ebe4c 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -41,6 +41,12 @@ CCL_NAMESPACE_BEGIN #ifdef WITH_OSL +/* Shared Texture System */ + +OSL::TextureSystem *OSLShaderManager::ts_shared = NULL; +int OSLShaderManager::ts_shared_users = 0; +thread_mutex OSLShaderManager::ts_shared_mutex; + /* Shader Manager */ OSLShaderManager::OSLShaderManager() @@ -54,7 +60,17 @@ OSLShaderManager::OSLShaderManager() OSLShaderManager::~OSLShaderManager() { OSL::ShadingSystem::destroy(ss); - OSL::TextureSystem::destroy(ts); + + /* shared texture system decrease users and destroy if no longer used */ + { + thread_scoped_lock lock(ts_shared_mutex); + ts_shared_users--; + + if(ts_shared_users == 0) { + OSL::TextureSystem::destroy(ts_shared); + ts_shared = NULL; + } + } delete services; } @@ -133,14 +149,22 @@ void OSLShaderManager::device_free(Device *device, DeviceScene *dscene, Scene *s void OSLShaderManager::texture_system_init() { - /* if we let OSL create it, it leaks */ - ts = TextureSystem::create(true); - ts->attribute("automip", 1); - ts->attribute("autotile", 64); - ts->attribute("gray_to_rgb", 1); + /* create texture system, shared between different renders to reduce memory usage */ + thread_scoped_lock lock(ts_shared_mutex); + + if(ts_shared_users == 0) { + ts_shared = TextureSystem::create(true); + + ts_shared->attribute("automip", 1); + ts_shared->attribute("autotile", 64); + ts_shared->attribute("gray_to_rgb", 1); + + /* effectively unlimited for now, until we support proper mipmap lookups */ + ts_shared->attribute("max_memory_MB", 16384); + } - /* effectively unlimited for now, until we support proper mipmap lookups */ - ts->attribute("max_memory_MB", 16384); + ts = ts_shared; + ts_shared_users++; } void OSLShaderManager::shading_system_init() diff --git a/intern/cycles/render/osl.h b/intern/cycles/render/osl.h index 2d3996df0eb..c459f6bfa08 100644 --- a/intern/cycles/render/osl.h +++ b/intern/cycles/render/osl.h @@ -21,6 +21,7 @@ #include "util_set.h" #include "util_string.h" +#include "util_thread.h" #include "shader.h" @@ -92,6 +93,10 @@ protected: OSLRenderServices *services; OSL::ErrorHandler errhandler; map<string, OSLShaderInfo> loaded_shaders; + + static OSL::TextureSystem *ts_shared; + static thread_mutex ts_shared_mutex; + static int ts_shared_users; }; #endif |