diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-04-04 14:36:58 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-04-04 16:43:12 +0300 |
commit | 92aeb84fde6402c0d2e337b030c06cfd171f5ba1 (patch) | |
tree | 8b61c241d23c3591f30de4a899dbb7dcbf613967 /intern/cycles/blender | |
parent | 7b149bfde649e178ab8710702f1f0157bff2ef7e (diff) |
Cycles: Tag shaders for update after the threading part is over
This avoids write access happening in non-atomic manner in
Shader::tag_update which modifies the global managers. Even
for 1 byte data types it's quite dangerous.
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 22 | ||||
-rw-r--r-- | intern/cycles/blender/blender_sync.h | 1 |
2 files changed, 12 insertions, 11 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index df21e2640bd..3f04f11aab4 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -27,7 +27,9 @@ #include "blender/blender_util.h" #include "util/util_debug.h" +#include "util/util_foreach.h" #include "util/util_string.h" +#include "util/util_set.h" #include "util/util_task.h" CCL_NAMESPACE_BEGIN @@ -1158,13 +1160,6 @@ static void add_nodes(Scene *scene, /* Sync Materials */ -void BlenderSync::sync_materials_simpligy(Shader *shader) -{ - ShaderGraph *graph = shader->graph; - graph->simplify(scene); - shader->tag_update(scene); -} - void BlenderSync::sync_materials(bool update_all) { shader_map.set_default(scene->default_surface); @@ -1173,6 +1168,7 @@ void BlenderSync::sync_materials(bool update_all) BL::BlendData::materials_iterator b_mat; TaskPool pool; + set<Shader*> updated_shaders; for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) { Shader *shader; @@ -1220,9 +1216,11 @@ void BlenderSync::sync_materials(bool update_all) * right before compiling. */ if(!preview) { - pool.push(function_bind(&BlenderSync::sync_materials_simpligy, - this, - shader)); + pool.push(function_bind(&ShaderGraph::simplify, graph, scene)); + /* NOTE: Update shaders out of the threads since those routines + * are accessing and writing to a global context. + */ + updated_shaders.insert(shader); } else { /* NOTE: Update tagging can access links which are being @@ -1234,6 +1232,10 @@ void BlenderSync::sync_materials(bool update_all) } pool.wait_work(); + + foreach(Shader *shader, updated_shaders) { + shader->tag_update(scene); + } } /* Sync World */ diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 62e2f8f563a..36bedc505af 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -96,7 +96,6 @@ public: private: /* sync */ void sync_lamps(bool update_all); - void sync_materials_simpligy(Shader *shader); void sync_materials(bool update_all); void sync_objects(BL::SpaceView3D& b_v3d, float motion_time = 0.0f); void sync_motion(BL::RenderSettings& b_render, |