Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2016-01-03 16:28:33 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-01-03 16:28:33 +0300
commita3df65dea819309496447a26ddf4d7dbe0c3203a (patch)
tree3050aeffd7cea5e577f7e6f4062c88ab7050ca5a /intern
parent80a76030aec3a8d62a92a643c4d85048a868e397 (diff)
Fix T47008: OSL Memory Corruption (Use after free)
The issue was caused by OSL using TLS which is required to be freed before the Cycles session is freed. This is quite tricky to do in Cycles because different render session are sharing the same task scheduler, so when one session is being freed TLS might need to be active still. In order to solve this, we are now doing JIT optimization ahead of the time which ensures either TLS of JIT is freed before the render on multi-core system or freed on OSLRenderSession destroy on single-core system. This might increase synchronization time due to JIT of unused function, but that we can solve later with some smart idea,
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/render/osl.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp
index 4933ed6c613..e5842c796db 100644
--- a/intern/cycles/render/osl.cpp
+++ b/intern/cycles/render/osl.cpp
@@ -125,11 +125,21 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
device_update_common(device, dscene, scene, progress);
- /* greedyjit test
{
+ /* Perform greedyjit optimization.
+ *
+ * This might waste time on optimizing gorups which are never actually
+ * used, but this prevents OSL from allocating data on TLS at render
+ * time.
+ *
+ * This is much better for us because this way we aren't required to
+ * stop task scheduler threads to make sure all TLS is clean and don't
+ * have issues with TLS data free accessing freed memory if task scheduler
+ * is being freed after the Session is freed.
+ */
thread_scoped_lock lock(ss_shared_mutex);
ss->optimize_all_groups();
- }*/
+ }
}
void OSLShaderManager::device_free(Device *device, DeviceScene *dscene, Scene *scene)
@@ -195,7 +205,7 @@ void OSLShaderManager::shading_system_init()
ss_shared->attribute("lockgeom", 1);
ss_shared->attribute("commonspace", "world");
ss_shared->attribute("searchpath:shader", path_get("shader"));
- //ss_shared->attribute("greedyjit", 1);
+ ss_shared->attribute("greedyjit", 1);
VLOG(1) << "Using shader search path: " << path_get("shader");