Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/blender_shader.cpp
| Show All 22 Lines | |||||
| #include "shader.h" | #include "shader.h" | ||||
| #include "blender_texture.h" | #include "blender_texture.h" | ||||
| #include "blender_sync.h" | #include "blender_sync.h" | ||||
| #include "blender_util.h" | #include "blender_util.h" | ||||
| #include "util_debug.h" | #include "util_debug.h" | ||||
| #include "util_string.h" | #include "util_string.h" | ||||
| #include "util_task.h" | |||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| typedef map<void*, ShaderInput*> PtrInputMap; | typedef map<void*, ShaderInput*> PtrInputMap; | ||||
| typedef map<void*, ShaderOutput*> PtrOutputMap; | typedef map<void*, ShaderOutput*> PtrOutputMap; | ||||
| typedef map<string, ConvertNode*> ProxyMap; | typedef map<string, ConvertNode*> ProxyMap; | ||||
| /* Find */ | /* Find */ | ||||
| ▲ Show 20 Lines • Show All 1,115 Lines • ▼ Show 20 Lines | |||||
| void BlenderSync::sync_materials(bool update_all) | void BlenderSync::sync_materials(bool update_all) | ||||
| { | { | ||||
| shader_map.set_default(scene->default_surface); | shader_map.set_default(scene->default_surface); | ||||
| /* material loop */ | /* material loop */ | ||||
| BL::BlendData::materials_iterator b_mat; | BL::BlendData::materials_iterator b_mat; | ||||
| TaskPool pool; | |||||
| for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) { | for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) { | ||||
| Shader *shader; | Shader *shader; | ||||
| /* test if we need to sync */ | /* test if we need to sync */ | ||||
| if(shader_map.sync(&shader, *b_mat) || update_all) { | if(shader_map.sync(&shader, *b_mat) || update_all) { | ||||
| ShaderGraph *graph = new ShaderGraph(); | ShaderGraph *graph = new ShaderGraph(); | ||||
| shader->name = b_mat->name().c_str(); | shader->name = b_mat->name().c_str(); | ||||
| Show All 19 Lines | if(shader_map.sync(&shader, *b_mat) || update_all) { | ||||
| shader->use_mis = get_boolean(cmat, "sample_as_light"); | shader->use_mis = get_boolean(cmat, "sample_as_light"); | ||||
| shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow"); | shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow"); | ||||
| shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume"); | shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume"); | ||||
| shader->volume_sampling_method = get_volume_sampling(cmat); | shader->volume_sampling_method = get_volume_sampling(cmat); | ||||
| shader->volume_interpolation_method = get_volume_interpolation(cmat); | shader->volume_interpolation_method = get_volume_interpolation(cmat); | ||||
| shader->displacement_method = (experimental) ? get_displacement_method(cmat) : DISPLACE_BUMP; | shader->displacement_method = (experimental) ? get_displacement_method(cmat) : DISPLACE_BUMP; | ||||
| shader->set_graph(graph); | shader->set_graph(graph); | ||||
| /* By simplifying the shader graph as soon as possible, some shader nodes might be | |||||
| * removed which can help to skip unneccessary attribures later. | |||||
| * | |||||
| * However, since graph simplification also accounts for e.g. mix weight, this would | |||||
| * cause frequent expensive resyncs in interactive sessions. */ | |||||
| if(!preview) { | |||||
| pool.push(function_bind(&ShaderGraph::simplify, shader->graph, scene)); | |||||
sergey: Please bother to do benchmarks on real scenes rather than just wacking threading code into… | |||||
sergeyUnsubmitted Not Done Inline ActionsOk, re-read code more carefully. This is pushing the outer loop data. While in theory we can do the whole material sync from thread current code should be good enough already. sergey: Ok, re-read code more carefully. This is pushing the outer loop data. While in theory we can do… | |||||
| } | |||||
| shader->tag_update(scene); | shader->tag_update(scene); | ||||
| } | } | ||||
| } | } | ||||
| if(!preview) { | |||||
| pool.wait_work(); | |||||
sergeyUnsubmitted Not Done Inline ActionsIMO safer to always for pool.wait_work(). If there is no work to be done it'll be almost NOOP. ut if we'll be using pool for something else than non-preview tasks it'll save us from possible issues related on missing wait_work. sergey: IMO safer to always for pool.wait_work(). If there is no work to be done it'll be almost NOOP. | |||||
| } | |||||
| } | } | ||||
| /* Sync World */ | /* Sync World */ | ||||
| void BlenderSync::sync_world(bool update_all) | void BlenderSync::sync_world(bool update_all) | ||||
| { | { | ||||
| Background *background = scene->background; | Background *background = scene->background; | ||||
| Background prevbackground = *background; | Background prevbackground = *background; | ||||
| ▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines | |||||
Please bother to do benchmarks on real scenes rather than just wacking threading code into somewhere inside of an inner loop.
Ideally threading should start as early as possible (in this case, export the whole material), otherwise synchronization overhead in the current task scheduler implementation might make things slower than they were before making things threaded.