diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-11-09 12:59:15 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-11-09 12:59:15 +0300 |
commit | c99481b6320a77e4793c812403f7d37dfc2d5ced (patch) | |
tree | 448226ab76b4f2d92263cc115828c23f1f753540 | |
parent | ffe76ae9f4abe2a64d4c749623b99f70b3746d87 (diff) | |
parent | 8d7ec519dff93b04fdec548aeef4b90137d788c8 (diff) |
Merge branch 'master' into blender2.8
37 files changed, 346 insertions, 288 deletions
diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index 3e052bb926e..0364f809f8c 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -47,7 +47,6 @@ std::ostream& operator <<(std::ostream &os, { os << "Experimental features: " << (requested_features.experimental ? "On" : "Off") << std::endl; - os << "Max closure count: " << requested_features.max_closure << std::endl; os << "Max nodes group: " << requested_features.max_nodes_group << std::endl; /* TODO(sergey): Decode bitflag into list of names. */ os << "Nodes features: " << requested_features.nodes_features << std::endl; diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index a2cd3e23c79..70f56165f8a 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -91,9 +91,6 @@ public: /* Use experimental feature set. */ bool experimental; - /* Maximum number of closures in shader trees. */ - int max_closure; - /* Selective nodes compilation. */ /* Identifier of a node group up to which all the nodes needs to be @@ -146,7 +143,6 @@ public: { /* TODO(sergey): Find more meaningful defaults. */ experimental = false; - max_closure = 0; max_nodes_group = 0; nodes_features = 0; use_hair = false; @@ -167,7 +163,6 @@ public: bool modified(const DeviceRequestedFeatures& requested_features) { return !(experimental == requested_features.experimental && - max_closure == requested_features.max_closure && max_nodes_group == requested_features.max_nodes_group && nodes_features == requested_features.nodes_features && use_hair == requested_features.use_hair && @@ -198,7 +193,6 @@ public: string_printf("%d", max_nodes_group); build_options += " -D__NODES_FEATURES__=" + string_printf("%d", nodes_features); - build_options += string_printf(" -D__MAX_CLOSURE__=%d", max_closure); if(!use_hair) { build_options += " -D__NO_HAIR__"; } diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 1a54c3380ee..0f4001ab1a6 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -760,7 +760,6 @@ public: CPUSplitKernel *split_kernel = NULL; if(use_split_kernel) { split_kernel = new CPUSplitKernel(this); - requested_features.max_closure = MAX_CLOSURE; if(!split_kernel->load_kernels(requested_features)) { thread_kernel_globals_free((KernelGlobals*)kgbuffer.device_pointer); kgbuffer.free(); diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index 3334c2b9f91..2f52bd49b16 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -1882,10 +1882,6 @@ public: DeviceRequestedFeatures requested_features; if(use_split_kernel()) { - if(!use_adaptive_compilation()) { - requested_features.max_closure = 64; - } - if(split_kernel == NULL) { split_kernel = new CUDASplitKernel(this); split_kernel->load_kernels(requested_features); diff --git a/intern/cycles/device/device_split_kernel.cpp b/intern/cycles/device/device_split_kernel.cpp index 115273d9f0a..566d4020b33 100644 --- a/intern/cycles/device/device_split_kernel.cpp +++ b/intern/cycles/device/device_split_kernel.cpp @@ -34,7 +34,6 @@ DeviceSplitKernel::DeviceSplitKernel(Device *device) use_queues_flag(device, "use_queues_flag"), work_pool_wgs(device, "work_pool_wgs") { - current_max_closure = -1; first_tile = true; avg_time_per_sample = 0.0; @@ -116,8 +115,6 @@ bool DeviceSplitKernel::load_kernels(const DeviceRequestedFeatures& requested_fe #undef LOAD_KERNEL - current_max_closure = requested_features.max_closure; - return true; } diff --git a/intern/cycles/device/device_split_kernel.h b/intern/cycles/device/device_split_kernel.h index 0647c664447..2ec0261e847 100644 --- a/intern/cycles/device/device_split_kernel.h +++ b/intern/cycles/device/device_split_kernel.h @@ -92,9 +92,6 @@ private: /* Work pool with respect to each work group. */ device_only_memory<unsigned int> work_pool_wgs; - /* clos_max value for which the kernels have been loaded currently. */ - int current_max_closure; - /* Marked True in constructor and marked false at the end of path_trace(). */ bool first_tile; diff --git a/intern/cycles/kernel/kernel_bake.h b/intern/cycles/kernel/kernel_bake.h index 73cddeb27f7..8788e89c40e 100644 --- a/intern/cycles/kernel/kernel_bake.h +++ b/intern/cycles/kernel/kernel_bake.h @@ -51,7 +51,7 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg, path_state_init(kg, &emission_sd, &state, rng_hash, sample, NULL); /* evaluate surface shader */ - shader_eval_surface(kg, sd, &state, state.flag, MAX_CLOSURE); + shader_eval_surface(kg, sd, &state, state.flag, kernel_data.integrator.max_closures); /* TODO, disable more closures we don't need besides transparent */ shader_bsdf_disable_transparency(kg, sd); @@ -228,12 +228,12 @@ ccl_device float3 kernel_bake_evaluate_direct_indirect(KernelGlobals *kg, } else { /* surface color of the pass only */ - shader_eval_surface(kg, sd, state, 0, MAX_CLOSURE); + shader_eval_surface(kg, sd, state, 0, kernel_data.integrator.max_closures); return kernel_bake_shader_bsdf(kg, sd, type); } } else { - shader_eval_surface(kg, sd, state, 0, MAX_CLOSURE); + shader_eval_surface(kg, sd, state, 0, kernel_data.integrator.max_closures); color = kernel_bake_shader_bsdf(kg, sd, type); } @@ -333,7 +333,7 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input, { float3 N = sd.N; if((sd.flag & SD_HAS_BUMP)) { - shader_eval_surface(kg, &sd, &state, 0, MAX_CLOSURE); + shader_eval_surface(kg, &sd, &state, 0, kernel_data.integrator.max_closures); N = shader_bsdf_average_normal(kg, &sd); } diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h index 8519e0682e1..207ba741e6f 100644 --- a/intern/cycles/kernel/kernel_path.h +++ b/intern/cycles/kernel/kernel_path.h @@ -443,7 +443,7 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg, sd, &isect, ray); - shader_eval_surface(kg, sd, state, state->flag, MAX_CLOSURE); + shader_eval_surface(kg, sd, state, state->flag, kernel_data.integrator.max_closures); shader_prepare_closures(sd, state); /* Apply shadow catcher, holdout, emission. */ @@ -594,7 +594,7 @@ ccl_device_forceinline void kernel_path_integrate( /* Setup and evaluate shader. */ shader_setup_from_ray(kg, &sd, &isect, ray); - shader_eval_surface(kg, &sd, state, state->flag, MAX_CLOSURE); + shader_eval_surface(kg, &sd, state, state->flag, kernel_data.integrator.max_closures); shader_prepare_closures(&sd, state); /* Apply shadow catcher, holdout, emission. */ diff --git a/intern/cycles/kernel/kernel_path_branched.h b/intern/cycles/kernel/kernel_path_branched.h index b37bc65f4df..9996f52f9a4 100644 --- a/intern/cycles/kernel/kernel_path_branched.h +++ b/intern/cycles/kernel/kernel_path_branched.h @@ -474,7 +474,7 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg, /* Setup and evaluate shader. */ shader_setup_from_ray(kg, &sd, &isect, &ray); - shader_eval_surface(kg, &sd, &state, state.flag, MAX_CLOSURE); + shader_eval_surface(kg, &sd, &state, state.flag, kernel_data.integrator.max_closures); shader_merge_closures(&sd); /* Apply shadow catcher, holdout, emission. */ diff --git a/intern/cycles/kernel/kernel_subsurface.h b/intern/cycles/kernel/kernel_subsurface.h index 87e7d7ff398..616ad71af3c 100644 --- a/intern/cycles/kernel/kernel_subsurface.h +++ b/intern/cycles/kernel/kernel_subsurface.h @@ -76,11 +76,11 @@ ccl_device_inline float3 subsurface_scatter_eval(ShaderData *sd, } /* replace closures with a single diffuse bsdf closure after scatter step */ -ccl_device void subsurface_scatter_setup_diffuse_bsdf(ShaderData *sd, const ShaderClosure *sc, float3 weight, bool hit, float3 N) +ccl_device void subsurface_scatter_setup_diffuse_bsdf(KernelGlobals *kg, ShaderData *sd, const ShaderClosure *sc, float3 weight, bool hit, float3 N) { sd->flag &= ~SD_CLOSURE_FLAGS; sd->num_closure = 0; - sd->num_closure_left = MAX_CLOSURE; + sd->num_closure_left = kernel_data.integrator.max_closures; if(hit) { Bssrdf *bssrdf = (Bssrdf *)sc; @@ -154,7 +154,7 @@ ccl_device void subsurface_color_bump_blur(KernelGlobals *kg, if(bump || texture_blur > 0.0f) { /* average color and normal at incoming point */ - shader_eval_surface(kg, sd, state, state_flag, MAX_CLOSURE); + shader_eval_surface(kg, sd, state, state_flag, kernel_data.integrator.max_closures); float3 in_color = shader_bssrdf_sum(sd, (bump)? N: NULL, NULL); /* we simply divide out the average color and multiply with the average @@ -342,7 +342,7 @@ ccl_device_noinline void subsurface_scatter_multi_setup( subsurface_color_bump_blur(kg, sd, state, state_flag, &weight, &N); /* Setup diffuse BSDF. */ - subsurface_scatter_setup_diffuse_bsdf(sd, sc, weight, true, N); + subsurface_scatter_setup_diffuse_bsdf(kg, sd, sc, weight, true, N); } /* subsurface scattering step, from a point on the surface to another nearby point on the same object */ @@ -439,7 +439,7 @@ ccl_device void subsurface_scatter_step(KernelGlobals *kg, ShaderData *sd, ccl_a subsurface_color_bump_blur(kg, sd, state, state_flag, &eval, &N); /* setup diffuse bsdf */ - subsurface_scatter_setup_diffuse_bsdf(sd, sc, eval, (ss_isect.num_hits > 0), N); + subsurface_scatter_setup_diffuse_bsdf(kg, sd, sc, eval, (ss_isect.num_hits > 0), N); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index fc3e7b3da98..919dafbc780 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -782,10 +782,14 @@ typedef struct AttributeDescriptor { /* Closure data */ #ifdef __MULTI_CLOSURE__ -# ifndef __MAX_CLOSURE__ -# define MAX_CLOSURE 64 +# ifdef __SPLIT_KERNEL__ +# define MAX_CLOSURE 1 # else -# define MAX_CLOSURE __MAX_CLOSURE__ +# ifndef __MAX_CLOSURE__ +# define MAX_CLOSURE 64 +# else +# define MAX_CLOSURE __MAX_CLOSURE__ +# endif # endif #else # define MAX_CLOSURE 1 @@ -1313,7 +1317,8 @@ typedef struct KernelIntegrator { int volume_samples; int start_sample; - int pad; + + int max_closures; } KernelIntegrator; static_assert_align(KernelIntegrator, 16); diff --git a/intern/cycles/kernel/kernel_volume.h b/intern/cycles/kernel/kernel_volume.h index fb3c5437275..5604d8e5163 100644 --- a/intern/cycles/kernel/kernel_volume.h +++ b/intern/cycles/kernel/kernel_volume.h @@ -62,7 +62,7 @@ ccl_device_inline bool volume_shader_sample(KernelGlobals *kg, VolumeShaderCoefficients *coeff) { sd->P = P; - shader_eval_volume(kg, sd, state, state->volume_stack, state->flag, MAX_CLOSURE); + shader_eval_volume(kg, sd, state, state->volume_stack, state->flag, kernel_data.integrator.max_closures); if(!(sd->flag & (SD_EXTINCTION|SD_SCATTER|SD_EMISSION))) return false; diff --git a/intern/cycles/kernel/split/kernel_branched.h b/intern/cycles/kernel/split/kernel_branched.h index 2313feac089..6456636caaa 100644 --- a/intern/cycles/kernel/split/kernel_branched.h +++ b/intern/cycles/kernel/split/kernel_branched.h @@ -30,10 +30,14 @@ ccl_device_inline void kernel_split_branched_path_indirect_loop_init(KernelGloba BRANCHED_STORE(path_state); BRANCHED_STORE(throughput); BRANCHED_STORE(ray); - BRANCHED_STORE(sd); BRANCHED_STORE(isect); BRANCHED_STORE(ray_state); + branched_state->sd = *kernel_split_sd(sd, ray_index); + for(int i = 0; i < branched_state->sd.num_closure; i++) { + branched_state->sd.closure[i] = kernel_split_sd(sd, ray_index)->closure[i]; + } + #undef BRANCHED_STORE /* set loop counters to intial position */ @@ -53,10 +57,14 @@ ccl_device_inline void kernel_split_branched_path_indirect_loop_end(KernelGlobal BRANCHED_RESTORE(path_state); BRANCHED_RESTORE(throughput); BRANCHED_RESTORE(ray); - BRANCHED_RESTORE(sd); BRANCHED_RESTORE(isect); BRANCHED_RESTORE(ray_state); + *kernel_split_sd(sd, ray_index) = branched_state->sd; + for(int i = 0; i < branched_state->sd.num_closure; i++) { + kernel_split_sd(sd, ray_index)->closure[i] = branched_state->sd.closure[i]; + } + #undef BRANCHED_RESTORE /* leave indirect loop */ diff --git a/intern/cycles/kernel/split/kernel_direct_lighting.h b/intern/cycles/kernel/split/kernel_direct_lighting.h index 832b0e5b265..ca79602c565 100644 --- a/intern/cycles/kernel/split/kernel_direct_lighting.h +++ b/intern/cycles/kernel/split/kernel_direct_lighting.h @@ -58,7 +58,7 @@ ccl_device void kernel_direct_lighting(KernelGlobals *kg, if(IS_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE)) { ccl_global PathState *state = &kernel_split_state.path_state[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); /* direct lighting */ #ifdef __EMISSION__ diff --git a/intern/cycles/kernel/split/kernel_do_volume.h b/intern/cycles/kernel/split/kernel_do_volume.h index 02881da6c04..fb5bd3d48dd 100644 --- a/intern/cycles/kernel/split/kernel_do_volume.h +++ b/intern/cycles/kernel/split/kernel_do_volume.h @@ -29,7 +29,7 @@ ccl_device_noinline bool kernel_split_branched_path_volume_indirect_light_iter(K { SplitBranchedState *branched_state = &kernel_split_state.branched_state[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); PathRadiance *L = &kernel_split_state.path_radiance[ray_index]; ShaderData *emission_sd = AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]); @@ -140,7 +140,7 @@ ccl_device void kernel_do_volume(KernelGlobals *kg) ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index]; ccl_global Ray *ray = &kernel_split_state.ray[ray_index]; ccl_global Intersection *isect = &kernel_split_state.isect[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); ShaderData *emission_sd = AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]); bool hit = ! IS_STATE(ray_state, ray_index, RAY_HIT_BACKGROUND); diff --git a/intern/cycles/kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h b/intern/cycles/kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h index bc8ca3aa3ca..88919f47c7a 100644 --- a/intern/cycles/kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h +++ b/intern/cycles/kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h @@ -94,7 +94,7 @@ ccl_device void kernel_holdout_emission_blurring_pathtermination_ao( float3 throughput; ccl_global char *ray_state = kernel_split_state.ray_state; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); if(IS_STATE(ray_state, ray_index, RAY_ACTIVE)) { uint buffer_offset = kernel_split_state.buffer_offset[ray_index]; diff --git a/intern/cycles/kernel/split/kernel_indirect_background.h b/intern/cycles/kernel/split/kernel_indirect_background.h index 0c894bd3d71..4cf88a02590 100644 --- a/intern/cycles/kernel/split/kernel_indirect_background.h +++ b/intern/cycles/kernel/split/kernel_indirect_background.h @@ -55,7 +55,7 @@ ccl_device void kernel_indirect_background(KernelGlobals *kg) PathRadiance *L = &kernel_split_state.path_radiance[ray_index]; ccl_global Ray *ray = &kernel_split_state.ray[ray_index]; float3 throughput = kernel_split_state.throughput[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); kernel_path_background(kg, state, ray, throughput, sd, L); kernel_split_path_end(kg, ray_index); diff --git a/intern/cycles/kernel/split/kernel_lamp_emission.h b/intern/cycles/kernel/split/kernel_lamp_emission.h index d5099ac66e6..c14f66f664f 100644 --- a/intern/cycles/kernel/split/kernel_lamp_emission.h +++ b/intern/cycles/kernel/split/kernel_lamp_emission.h @@ -58,7 +58,7 @@ ccl_device void kernel_lamp_emission(KernelGlobals *kg) float3 throughput = kernel_split_state.throughput[ray_index]; Ray ray = kernel_split_state.ray[ray_index]; ccl_global Intersection *isect = &kernel_split_state.isect[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); kernel_path_lamp_emission(kg, state, &ray, throughput, isect, sd, L); } diff --git a/intern/cycles/kernel/split/kernel_next_iteration_setup.h b/intern/cycles/kernel/split/kernel_next_iteration_setup.h index c3373174582..bb6bf1cc7e6 100644 --- a/intern/cycles/kernel/split/kernel_next_iteration_setup.h +++ b/intern/cycles/kernel/split/kernel_next_iteration_setup.h @@ -58,7 +58,7 @@ ccl_device void kernel_split_branched_indirect_light_end(KernelGlobals *kg, int kernel_split_branched_path_indirect_loop_end(kg, ray_index); ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); ccl_global PathState *state = &kernel_split_state.path_state[ray_index]; ccl_global Ray *ray = &kernel_split_state.ray[ray_index]; @@ -126,7 +126,7 @@ ccl_device void kernel_next_iteration_setup(KernelGlobals *kg, if(active) { ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index]; ccl_global Ray *ray = &kernel_split_state.ray[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); ccl_global PathState *state = &kernel_split_state.path_state[ray_index]; PathRadiance *L = &kernel_split_state.path_radiance[ray_index]; diff --git a/intern/cycles/kernel/split/kernel_shader_eval.h b/intern/cycles/kernel/split/kernel_shader_eval.h index 22602537524..2409d1ba28b 100644 --- a/intern/cycles/kernel/split/kernel_shader_eval.h +++ b/intern/cycles/kernel/split/kernel_shader_eval.h @@ -50,15 +50,15 @@ ccl_device void kernel_shader_eval(KernelGlobals *kg) if(IS_STATE(ray_state, ray_index, RAY_ACTIVE)) { ccl_global PathState *state = &kernel_split_state.path_state[ray_index]; - shader_eval_surface(kg, &kernel_split_state.sd[ray_index], state, state->flag, MAX_CLOSURE); + shader_eval_surface(kg, kernel_split_sd(sd, ray_index), state, state->flag, kernel_data.integrator.max_closures); #ifdef __BRANCHED_PATH__ if(kernel_data.integrator.branched) { - shader_merge_closures(&kernel_split_state.sd[ray_index]); + shader_merge_closures(kernel_split_sd(sd, ray_index)); } else #endif { - shader_prepare_closures(&kernel_split_state.sd[ray_index], state); + shader_prepare_closures(kernel_split_sd(sd, ray_index), state); } } } diff --git a/intern/cycles/kernel/split/kernel_shader_setup.h b/intern/cycles/kernel/split/kernel_shader_setup.h index 0432689d9fa..9d428ee8139 100644 --- a/intern/cycles/kernel/split/kernel_shader_setup.h +++ b/intern/cycles/kernel/split/kernel_shader_setup.h @@ -61,7 +61,7 @@ ccl_device void kernel_shader_setup(KernelGlobals *kg, Ray ray = kernel_split_state.ray[ray_index]; shader_setup_from_ray(kg, - &kernel_split_state.sd[ray_index], + kernel_split_sd(sd, ray_index), &isect, &ray); } diff --git a/intern/cycles/kernel/split/kernel_shader_sort.h b/intern/cycles/kernel/split/kernel_shader_sort.h index 5a55b680695..2132c42220f 100644 --- a/intern/cycles/kernel/split/kernel_shader_sort.h +++ b/intern/cycles/kernel/split/kernel_shader_sort.h @@ -47,7 +47,7 @@ ccl_device void kernel_shader_sort(KernelGlobals *kg, int ray_index = kernel_split_state.queue_data[add]; bool valid = (ray_index != QUEUE_EMPTY_SLOT) && IS_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE); if(valid) { - value = kernel_split_state.sd[ray_index].shader & SHADER_MASK; + value = kernel_split_sd(sd, ray_index)->shader & SHADER_MASK; } } local_value[i + lid] = value; diff --git a/intern/cycles/kernel/split/kernel_shadow_blocked_ao.h b/intern/cycles/kernel/split/kernel_shadow_blocked_ao.h index b50de615fc8..a4cffd77eff 100644 --- a/intern/cycles/kernel/split/kernel_shadow_blocked_ao.h +++ b/intern/cycles/kernel/split/kernel_shadow_blocked_ao.h @@ -33,7 +33,7 @@ ccl_device void kernel_shadow_blocked_ao(KernelGlobals *kg) return; } - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); ShaderData *emission_sd = AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]); PathRadiance *L = &kernel_split_state.path_radiance[ray_index]; ccl_global PathState *state = &kernel_split_state.path_state[ray_index]; diff --git a/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h b/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h index 9a6bdfbdffe..da072fd5f1a 100644 --- a/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h +++ b/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h @@ -43,7 +43,7 @@ ccl_device void kernel_shadow_blocked_dl(KernelGlobals *kg) ccl_global PathState *state = &kernel_split_state.path_state[ray_index]; Ray ray = kernel_split_state.light_ray[ray_index]; PathRadiance *L = &kernel_split_state.path_radiance[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); float3 throughput = kernel_split_state.throughput[ray_index]; BsdfEval L_light = kernel_split_state.bsdf_eval[ray_index]; diff --git a/intern/cycles/kernel/split/kernel_split_data.h b/intern/cycles/kernel/split/kernel_split_data.h index eac22050a38..fa2f0b20a83 100644 --- a/intern/cycles/kernel/split/kernel_split_data.h +++ b/intern/cycles/kernel/split/kernel_split_data.h @@ -31,6 +31,14 @@ ccl_device_inline uint64_t split_data_buffer_size(KernelGlobals *kg, size_t num_ size = size SPLIT_DATA_ENTRIES; #undef SPLIT_DATA_ENTRY + uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures-1); + +#ifdef __BRANCHED_PATH__ + size += align_up(closure_size * num_elements, 16); +#endif + + size += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16); + return size; } @@ -49,6 +57,15 @@ ccl_device_inline void split_data_init(KernelGlobals *kg, SPLIT_DATA_ENTRIES; #undef SPLIT_DATA_ENTRY + uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures-1); + +#ifdef __BRANCHED_PATH__ + p += align_up(closure_size * num_elements, 16); +#endif + + split_data->_sd = (ShaderData*)p; + p += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16); + split_data->ray_state = ray_state; } diff --git a/intern/cycles/kernel/split/kernel_split_data_types.h b/intern/cycles/kernel/split/kernel_split_data_types.h index 5c2aadcf4ec..9ac3f904819 100644 --- a/intern/cycles/kernel/split/kernel_split_data_types.h +++ b/intern/cycles/kernel/split/kernel_split_data_types.h @@ -51,7 +51,6 @@ typedef ccl_global struct SplitBranchedState { float3 throughput; Ray ray; - struct ShaderData sd; Intersection isect; char ray_state; @@ -77,6 +76,9 @@ typedef ccl_global struct SplitBranchedState { int shared_sample_count; /* number of branched samples shared with other threads */ int original_ray; /* index of original ray when sharing branched samples */ bool waiting_on_shared_samples; + + /* Must be last in to allow for dynamic size of closures */ + struct ShaderData sd; } SplitBranchedState; #define SPLIT_DATA_BRANCHED_ENTRIES \ @@ -110,11 +112,11 @@ typedef ccl_global struct SplitBranchedState { SPLIT_DATA_ENTRY(ccl_global Ray, light_ray, 1) \ SPLIT_DATA_ENTRY(ccl_global int, queue_data, (NUM_QUEUES*2)) /* TODO(mai): this is too large? */ \ SPLIT_DATA_ENTRY(ccl_global uint, buffer_offset, 1) \ - SPLIT_DATA_ENTRY(ShaderData, sd, 1) \ SPLIT_DATA_ENTRY(ShaderDataTinyStorage, sd_DL_shadow, 1) \ SPLIT_DATA_SUBSURFACE_ENTRIES \ SPLIT_DATA_VOLUME_ENTRIES \ SPLIT_DATA_BRANCHED_ENTRIES \ + SPLIT_DATA_ENTRY(ShaderData, _sd, 0) /* entries to be copied to inactive rays when sharing branched samples (TODO: which are actually needed?) */ #define SPLIT_DATA_ENTRIES_BRANCHED_SHARED \ @@ -126,11 +128,11 @@ typedef ccl_global struct SplitBranchedState { SPLIT_DATA_ENTRY(ccl_global BsdfEval, bsdf_eval, 1) \ SPLIT_DATA_ENTRY(ccl_global int, is_lamp, 1) \ SPLIT_DATA_ENTRY(ccl_global Ray, light_ray, 1) \ - SPLIT_DATA_ENTRY(ShaderData, sd, 1) \ SPLIT_DATA_ENTRY(ShaderDataTinyStorage, sd_DL_shadow, 1) \ SPLIT_DATA_SUBSURFACE_ENTRIES \ SPLIT_DATA_VOLUME_ENTRIES \ SPLIT_DATA_BRANCHED_ENTRIES \ + SPLIT_DATA_ENTRY(ShaderData, _sd, 0) /* struct that holds pointers to data in the shared state buffer */ typedef struct SplitData { @@ -154,6 +156,12 @@ __device__ SplitParams __split_param_data; # define kernel_split_params (__split_param_data) #endif /* __KERNEL_CUDA__ */ +#define kernel_split_sd(sd, ray_index) ((ShaderData*) \ + ( \ + ((ccl_global char*)kernel_split_state._##sd) + \ + (sizeof(ShaderData) + sizeof(ShaderClosure)*(kernel_data.integrator.max_closures-1)) * (ray_index) \ + )) + /* Local storage for queue_enqueue kernel. */ typedef struct QueueEnqueueLocals { uint queue_atomics[2]; diff --git a/intern/cycles/kernel/split/kernel_subsurface_scatter.h b/intern/cycles/kernel/split/kernel_subsurface_scatter.h index c5504d0a89b..887c3e313d1 100644 --- a/intern/cycles/kernel/split/kernel_subsurface_scatter.h +++ b/intern/cycles/kernel/split/kernel_subsurface_scatter.h @@ -98,7 +98,7 @@ ccl_device_noinline bool kernel_split_branched_path_subsurface_indirect_light_it /* compute lighting with the BSDF closure */ for(int hit = branched_state->next_hit; hit < branched_state->num_hits; hit++) { - ShaderData *bssrdf_sd = &kernel_split_state.sd[ray_index]; + ShaderData *bssrdf_sd = kernel_split_sd(sd, ray_index); *bssrdf_sd = *sd; /* note: copy happens each iteration of inner loop, this is * important as the indirect path will write into bssrdf_sd */ @@ -228,7 +228,7 @@ ccl_device void kernel_subsurface_scatter(KernelGlobals *kg) ccl_global Ray *ray = &kernel_split_state.ray[ray_index]; ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index]; ccl_global SubsurfaceIndirectRays *ss_indirect = &kernel_split_state.ss_rays[ray_index]; - ShaderData *sd = &kernel_split_state.sd[ray_index]; + ShaderData *sd = kernel_split_sd(sd, ray_index); ShaderData *emission_sd = AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]); if(sd->flag & SD_BSSRDF) { diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 74cfd02e1a4..e8d9558c38d 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -642,13 +642,11 @@ DeviceRequestedFeatures Session::get_requested_device_features() DeviceRequestedFeatures requested_features; requested_features.experimental = params.experimental; - requested_features.max_closure = get_max_closure_count(); scene->shader_manager->get_requested_features( scene, &requested_features); if(!params.background) { /* Avoid too much re-compilations for viewport render. */ - requested_features.max_closure = 64; requested_features.max_nodes_group = NODE_GROUP_LEVEL_MAX; requested_features.nodes_features = NODE_FEATURE_ALL; } @@ -858,6 +856,16 @@ void Session::update_scene() if(scene->need_update()) { load_kernels(false); + /* Update max_closures. */ + KernelIntegrator *kintegrator = &scene->dscene.data.integrator; + if(params.background) { + kintegrator->max_closures = get_max_closure_count(); + } + else { + /* Currently viewport render is faster with higher max_closures, needs investigating. */ + kintegrator->max_closures = 64; + } + progress.set_status("Updating Scene"); MEM_GUARDED_CALL(&progress, scene->device_update, device, progress); } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index 0c1a3d21f84..58c9b6f10ca 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -118,7 +118,6 @@ namespace { struct BuilderWalkUserData { DepsgraphNodeBuilder *builder; - Scene *scene; }; static void modifier_walk(void *user_data, @@ -128,7 +127,7 @@ static void modifier_walk(void *user_data, { BuilderWalkUserData *data = (BuilderWalkUserData *)user_data; if (*obpoin) { - data->builder->build_object(data->scene, *obpoin, DEG_ID_LINKED_INDIRECTLY); + data->builder->build_object(*obpoin, DEG_ID_LINKED_INDIRECTLY); } } @@ -141,7 +140,7 @@ void constraint_walk(bConstraint * /*con*/, if (*idpoin) { ID *id = *idpoin; if (GS(id->name) == ID_OB) { - data->builder->build_object(data->scene, (Object *)id, DEG_ID_LINKED_INDIRECTLY); + data->builder->build_object((Object *)id, DEG_ID_LINKED_INDIRECTLY); } } } @@ -159,34 +158,35 @@ void free_copy_on_write_datablock(void *id_v) /* **** General purpose functions **** */ -DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph) : - m_bmain(bmain), - m_graph(graph), - m_cow_id_hash(NULL) +DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph) + : bmain_(bmain), + graph_(graph), + scene_(NULL), + cow_id_hash_(NULL) { } DepsgraphNodeBuilder::~DepsgraphNodeBuilder() { - if (m_cow_id_hash != NULL) { - BLI_ghash_free(m_cow_id_hash, NULL, free_copy_on_write_datablock); + if (cow_id_hash_ != NULL) { + BLI_ghash_free(cow_id_hash_, NULL, free_copy_on_write_datablock); } } IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id, bool do_tag) { if (!DEG_depsgraph_use_copy_on_write()) { - return m_graph->add_id_node(id); + return graph_->add_id_node(id); } IDDepsNode *id_node = NULL; - ID *id_cow = (ID *)BLI_ghash_lookup(m_cow_id_hash, id); + ID *id_cow = (ID *)BLI_ghash_lookup(cow_id_hash_, id); if (id_cow != NULL) { /* TODO(sergey): Is it possible to lookup and pop element from GHash * at the same time? */ - BLI_ghash_remove(m_cow_id_hash, id, NULL, NULL); + BLI_ghash_remove(cow_id_hash_, id, NULL, NULL); } - id_node = m_graph->add_id_node(id, do_tag, id_cow); + id_node = graph_->add_id_node(id, do_tag, id_cow); /* Currently all ID nodes are supposed to have copy-on-write logic. * * NOTE: Zero number of components indicates that ID node was just created. @@ -195,22 +195,22 @@ IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id, bool do_tag) ComponentDepsNode *comp_cow = id_node->add_component(DEG_NODE_TYPE_COPY_ON_WRITE); OperationDepsNode *op_cow = comp_cow->add_operation( - function_bind(deg_evaluate_copy_on_write, _1, m_graph, id_node), - DEG_OPCODE_COPY_ON_WRITE, - "", -1); - m_graph->operations.push_back(op_cow); + function_bind(deg_evaluate_copy_on_write, _1, graph_, id_node), + DEG_OPCODE_COPY_ON_WRITE, + "", -1); + graph_->operations.push_back(op_cow); } return id_node; } IDDepsNode *DepsgraphNodeBuilder::find_id_node(ID *id) { - return m_graph->find_id_node(id); + return graph_->find_id_node(id); } TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source() { - return m_graph->add_time_source(); + return graph_->add_time_source(); } ComponentDepsNode *DepsgraphNodeBuilder::add_component_node( @@ -236,7 +236,7 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node( name_tag); if (op_node == NULL) { op_node = comp_node->add_operation(op, opcode, name, name_tag); - m_graph->operations.push_back(op_node); + graph_->operations.push_back(op_node); } else { fprintf(stderr, @@ -318,7 +318,7 @@ OperationDepsNode *DepsgraphNodeBuilder::find_operation_node( ID *DepsgraphNodeBuilder::get_cow_id(const ID *id_orig) const { - return m_graph->get_cow_id(id_orig); + return graph_->get_cow_id(id_orig); } ID *DepsgraphNodeBuilder::ensure_cow_id(ID *id_orig) @@ -333,7 +333,7 @@ ID *DepsgraphNodeBuilder::ensure_cow_id(ID *id_orig) ID *DepsgraphNodeBuilder::expand_cow_id(IDDepsNode *id_node) { - return deg_expand_copy_on_write_datablock(m_graph, id_node, this, true); + return deg_expand_copy_on_write_datablock(graph_, id_node, this, true); } ID *DepsgraphNodeBuilder::expand_cow_id(ID *id_orig) @@ -344,17 +344,17 @@ ID *DepsgraphNodeBuilder::expand_cow_id(ID *id_orig) /* **** Build functions for entity nodes **** */ -void DepsgraphNodeBuilder::begin_build(Main *bmain) { +void DepsgraphNodeBuilder::begin_build() { /* LIB_TAG_DOIT is used to indicate whether node for given ID was already * created or not. This flag is being set in add_id_node(), so functions * shouldn't bother with setting it, they only might query this flag when * needed. */ - BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); + BKE_main_id_tag_all(bmain_, LIB_TAG_DOIT, false); /* XXX nested node trees are not included in tag-clearing above, * so we need to do this manually. */ - FOREACH_NODETREE(bmain, nodetree, id) + FOREACH_NODETREE(bmain_, nodetree, id) { if (id != (ID *)nodetree) { nodetree->id.tag &= ~LIB_TAG_DOIT; @@ -366,13 +366,13 @@ void DepsgraphNodeBuilder::begin_build(Main *bmain) { /* Store existing copy-on-write versions of datablock, so we can re-use * them for new ID nodes. */ - m_cow_id_hash = BLI_ghash_ptr_new("Depsgraph id hash"); - foreach (IDDepsNode *id_node, m_graph->id_nodes) { + cow_id_hash_ = BLI_ghash_ptr_new("Depsgraph id hash"); + foreach (IDDepsNode *id_node, graph_->id_nodes) { if (GS(id_node->id_orig->name) != ID_SCE) { continue; } if (deg_copy_on_write_is_expanded(id_node->id_cow)) { - BLI_ghash_insert(m_cow_id_hash, + BLI_ghash_insert(cow_id_hash_, id_node->id_orig, id_node->id_cow); id_node->id_cow = NULL; @@ -381,12 +381,12 @@ void DepsgraphNodeBuilder::begin_build(Main *bmain) { } /* Make sure graph has no nodes left from previous state. */ - m_graph->clear_all_nodes(); - m_graph->operations.clear(); - BLI_gset_clear(m_graph->entry_tags, NULL); + graph_->clear_all_nodes(); + graph_->operations.clear(); + BLI_gset_clear(graph_->entry_tags, NULL); } -void DepsgraphNodeBuilder::build_group(Scene *scene, Group *group) +void DepsgraphNodeBuilder::build_group(Group *group) { ID *group_id = &group->id; if (group_id->tag & LIB_TAG_DOIT) { @@ -395,12 +395,11 @@ void DepsgraphNodeBuilder::build_group(Scene *scene, Group *group) group_id->tag |= LIB_TAG_DOIT; LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { - build_object(scene, go->ob, DEG_ID_LINKED_INDIRECTLY); + build_object(go->ob, DEG_ID_LINKED_INDIRECTLY); } } -void DepsgraphNodeBuilder::build_object(Scene *scene, - Object *ob, +void DepsgraphNodeBuilder::build_object(Object *ob, eDepsNode_LinkedState_Type linked_state) { /* Skip rest of components if the ID node was already there. */ @@ -418,21 +417,19 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, ob->customdata_mask = 0; /* Standard components. */ - build_object_transform(scene, ob); + build_object_transform(ob); if (ob->parent != NULL) { - build_object(scene, ob->parent, linked_state); + build_object(ob->parent, linked_state); } if (ob->modifiers.first != NULL) { BuilderWalkUserData data; data.builder = this; - data.scene = scene; modifiers_foreachObjectLink(ob, modifier_walk, &data); } if (ob->constraints.first != NULL) { BuilderWalkUserData data; data.builder = this; - data.scene = scene; BKE_constraints_id_loop(&ob->constraints, constraint_walk, &data); } @@ -446,7 +443,7 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, case OB_SURF: case OB_MBALL: case OB_LATTICE: - build_obdata_geom(scene, ob); + build_obdata_geom(ob); /* TODO(sergey): Only for until we support granular * update of curves. */ @@ -463,7 +460,7 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, build_proxy_rig(ob); } else { - build_rig(scene, ob); + build_rig(ob); } break; @@ -500,7 +497,7 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, /* particle systems */ if (ob->particlesystem.first != NULL) { - build_particles(scene, ob); + build_particles(ob); } /* Grease pencil. */ @@ -511,19 +508,19 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, /* Object that this is a proxy for. */ if (ob->proxy) { ob->proxy->proxy_from = ob; - build_object(scene, ob->proxy, DEG_ID_LINKED_INDIRECTLY); + build_object(ob->proxy, DEG_ID_LINKED_INDIRECTLY); } /* Object dupligroup. */ if (ob->dup_group != NULL) { - build_group(scene, ob->dup_group); + build_group(ob->dup_group); } } -void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob) +void DepsgraphNodeBuilder::build_object_transform(Object *ob) { OperationDepsNode *op_node; - Scene *scene_cow = get_cow_datablock(scene); + Scene *scene_cow = get_cow_datablock(scene_); Object *ob_cow = get_cow_datablock(ob); /* local transforms (from transform channels - loc/rot/scale + deltas) */ @@ -545,7 +542,7 @@ void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob) /* object constraints */ if (ob->constraints.first != NULL) { - build_object_constraints(scene, ob); + build_object_constraints(ob); } /* Rest of transformation update. */ @@ -579,12 +576,12 @@ void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob) * * -- Aligorith, August 2013 */ -void DepsgraphNodeBuilder::build_object_constraints(Scene *scene, Object *ob) +void DepsgraphNodeBuilder::build_object_constraints(Object *ob) { /* create node for constraint stack */ add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM, function_bind(BKE_object_eval_constraints, _1, - get_cow_datablock(scene), + get_cow_datablock(scene_), get_cow_datablock(ob)), DEG_OPCODE_TRANSFORM_CONSTRAINTS); } @@ -758,7 +755,7 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene) } } -void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob) +void DepsgraphNodeBuilder::build_particles(Object *ob) { /** * Particle Systems Nodes @@ -780,7 +777,7 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob) add_component_node(&ob->id, DEG_NODE_TYPE_EVAL_PARTICLES); /* TODO(sergey): Need to get COW of PSYS. */ - Scene *scene_cow = get_cow_datablock(scene); + Scene *scene_cow = get_cow_datablock(scene_); Object *ob_cow = get_cow_datablock(ob); add_operation_node(psys_comp, @@ -839,9 +836,9 @@ void DepsgraphNodeBuilder::build_particle_settings(ParticleSettings *part) { DEG_OPCODE_PARTICLE_SETTINGS_RECALC_CLEAR); } -void DepsgraphNodeBuilder::build_cloth(Scene *scene, Object *object) +void DepsgraphNodeBuilder::build_cloth(Object *object) { - Scene *scene_cow = get_cow_datablock(scene); + Scene *scene_cow = get_cow_datablock(scene_); Object *object_cow = get_cow_datablock(object); add_operation_node(&object->id, DEG_NODE_TYPE_CACHE, @@ -864,10 +861,10 @@ void DepsgraphNodeBuilder::build_shapekeys(Key *key) /* ObData Geometry Evaluation */ // XXX: what happens if the datablock is shared! -void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) +void DepsgraphNodeBuilder::build_obdata_geom(Object *ob) { OperationDepsNode *op_node; - Scene *scene_cow = get_cow_datablock(scene); + Scene *scene_cow = get_cow_datablock(scene_); Object *object_cow = get_cow_datablock(ob); /* TODO(sergey): This way using this object's properties as driver target @@ -909,7 +906,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) /* Cloyth modifier. */ LINKLIST_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Cloth) { - build_cloth(scene, ob); + build_cloth(ob); } } @@ -975,8 +972,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) case OB_MBALL: { - Object *mom = BKE_mball_basis_find(scene, ob); - + Object *mom = BKE_mball_basis_find(scene_, ob); /* Motherball - mom depends on children! */ if (mom == ob) { /* metaball evaluation operations */ @@ -1012,13 +1008,13 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) */ Curve *cu = (Curve *)obdata; if (cu->bevobj != NULL) { - build_object(scene, cu->bevobj, DEG_ID_LINKED_INDIRECTLY); + build_object(cu->bevobj, DEG_ID_LINKED_INDIRECTLY); } if (cu->taperobj != NULL) { - build_object(scene, cu->taperobj, DEG_ID_LINKED_INDIRECTLY); + build_object(cu->taperobj, DEG_ID_LINKED_INDIRECTLY); } if (ob->type == OB_FONT && cu->textoncurve != NULL) { - build_object(scene, cu->textoncurve, DEG_ID_LINKED_INDIRECTLY); + build_object(cu->textoncurve, DEG_ID_LINKED_INDIRECTLY); } break; } @@ -1132,24 +1128,36 @@ void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree) /* nodetree's nodes... */ LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) { ID *id = bnode->id; - if (id != NULL) { - ID_Type id_type = GS(id->name); - if (id_type == ID_MA) { - build_material((Material *)id); - } - else if (id_type == ID_TE) { - build_texture((Tex *)id); - } - else if (id_type == ID_IM) { - build_image((Image *)id); - } - else if (bnode->type == NODE_GROUP) { - bNodeTree *group_ntree = (bNodeTree *)id; - if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) { - build_nodetree(group_ntree); - } + if (id == NULL) { + continue; + } + ID_Type id_type = GS(id->name); + if (id_type == ID_MA) { + build_material((Material *)id); + } + else if (id_type == ID_TE) { + build_texture((Tex *)id); + } + else if (id_type == ID_IM) { + build_image((Image *)id); + } + else if (id_type == ID_OB) { + build_object((Object *)id, DEG_ID_LINKED_INDIRECTLY); + } + else if (id_type == ID_SCE) { + /* Scenes are used by compositor trees, and handled by render + * pipeline. No need to build dependencies for them here. + */ + } + else if (bnode->type == NODE_GROUP) { + bNodeTree *group_ntree = (bNodeTree *)id; + if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) { + build_nodetree(group_ntree); } } + else { + BLI_assert(!"Unknown ID type used for node"); + } } // TODO: link from nodetree to owner_component? diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h index e7bf8c9998d..40d6a56e789 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h @@ -108,7 +108,7 @@ struct DepsgraphNodeBuilder { } } - void begin_build(Main *bmain); + void begin_build(); IDDepsNode *add_id_node(ID *id, bool do_tag = true); IDDepsNode *find_id_node(ID *id); @@ -157,34 +157,30 @@ struct DepsgraphNodeBuilder { const char *name = "", int name_tag = -1); - void build_scene(Main *bmain, - Scene *scene, + void build_scene(Scene *scene, eDepsNode_LinkedState_Type linked_state); - void build_group(Scene *scene, Group *group); - void build_object(Scene *scene, - Object *ob, + void build_group(Group *group); + void build_object(Object *ob, eDepsNode_LinkedState_Type linked_state); - void build_object_transform(Scene *scene, Object *ob); - void build_object_constraints(Scene *scene, Object *ob); - void build_pose_constraints(Scene *scene, Object *ob, bPoseChannel *pchan); + void build_object_transform(Object *ob); + void build_object_constraints(Object *ob); + void build_pose_constraints(Object *ob, bPoseChannel *pchan); void build_rigidbody(Scene *scene); - void build_particles(Scene *scene, Object *ob); + void build_particles(Object *ob); void build_particle_settings(ParticleSettings *part); - void build_cloth(Scene *scene, Object *object); + void build_cloth(Object *object); void build_animdata(ID *id); OperationDepsNode *build_driver(ID *id, FCurve *fcurve); - void build_ik_pose(Scene *scene, - Object *ob, + void build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con); - void build_splineik_pose(Scene *scene, - Object *ob, + void build_splineik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con); - void build_rig(Scene *scene, Object *ob); + void build_rig(Object *ob); void build_proxy_rig(Object *ob); void build_shapekeys(Key *key); - void build_obdata_geom(Scene *scene, Object *ob); + void build_obdata_geom(Object *ob); void build_camera(Object *ob); void build_lamp(Object *ob); void build_nodetree(bNodeTree *ntree); @@ -212,9 +208,14 @@ struct DepsgraphNodeBuilder { LayerCollectionState *state); void build_scene_layer_collections(Scene *scene); protected: - Main *m_bmain; - Depsgraph *m_graph; - GHash *m_cow_id_hash; + /* State which never changes, same for the whole builder time. */ + Main *bmain_; + Depsgraph *graph_; + + /* State which demotes currently built entities. */ + Scene *scene_; + + GHash *cow_id_hash_; }; } // namespace DEG diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc index dabebb9d4a9..7b78156b8f8 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc @@ -66,23 +66,20 @@ extern "C" { namespace DEG { -void DepsgraphNodeBuilder::build_pose_constraints(Scene *scene, - Object *ob, - bPoseChannel *pchan) +void DepsgraphNodeBuilder::build_pose_constraints(Object *ob, bPoseChannel *pchan) { /* create node for constraint stack */ add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, function_bind(BKE_pose_constraints_evaluate, _1, - get_cow_datablock(scene), + get_cow_datablock(scene_), get_cow_datablock(ob), pchan), DEG_OPCODE_BONE_CONSTRAINTS); } /* IK Solver Eval Steps */ -void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, - Object *ob, +void DepsgraphNodeBuilder::build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con) { @@ -102,16 +99,16 @@ void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, /* Operation node for evaluating/running IK Solver. */ add_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, - function_bind(BKE_pose_iktree_evaluate, _1, - get_cow_datablock(scene), + function_bind(BKE_pose_iktree_evaluate, + _1, + get_cow_datablock(scene_), get_cow_datablock(ob), rootchan), DEG_OPCODE_POSE_IK_SOLVER); } /* Spline IK Eval Steps */ -void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, - Object *ob, +void DepsgraphNodeBuilder::build_splineik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con) { @@ -127,14 +124,14 @@ void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, add_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, function_bind(BKE_pose_splineik_evaluate, _1, - get_cow_datablock(scene), + get_cow_datablock(scene_), get_cow_datablock(ob), rootchan), DEG_OPCODE_POSE_SPLINE_IK_SOLVER); } /* Pose/Armature Bones Graph */ -void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *object) +void DepsgraphNodeBuilder::build_rig(Object *object) { bArmature *armature = (bArmature *)object->data; const short armature_tag = armature->id.tag; @@ -145,12 +142,12 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *object) /* NOTE: We need to expand both object and armature, so this way we can * safely create object level pose. */ - scene_cow = get_cow_datablock(scene); + scene_cow = get_cow_datablock(scene_); object_cow = expand_cow_datablock(object); armature_cow = expand_cow_datablock(armature); } else { - scene_cow = scene; + scene_cow = scene_; object_cow = object; armature_cow = armature; } @@ -273,7 +270,7 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *object) op_node->set_as_exit(); /* Build constraints. */ if (pchan->constraints.first != NULL) { - build_pose_constraints(scene, object, pchan); + build_pose_constraints(object, pchan); } /** * IK Solvers. @@ -290,11 +287,11 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *object) LINKLIST_FOREACH (bConstraint *, con, &pchan->constraints) { switch (con->type) { case CONSTRAINT_TYPE_KINEMATIC: - build_ik_pose(scene, object, pchan, con); + build_ik_pose(object, pchan, con); break; case CONSTRAINT_TYPE_SPLINEIK: - build_splineik_pose(scene, object, pchan, con); + build_splineik_pose(object, pchan, con); break; default: @@ -304,7 +301,7 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *object) /* Custom shape. */ /* NOTE: Custom shape datablock is already remapped to CoW version. */ if (pchan->custom != NULL) { - build_object(scene, get_orig_datablock(pchan->custom), DEG_ID_LINKED_INDIRECTLY); + build_object(get_orig_datablock(pchan->custom), DEG_ID_LINKED_INDIRECTLY); } } } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc index 097720f514a..941a9bed5f1 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc @@ -65,7 +65,7 @@ extern "C" { namespace DEG { -void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene, eDepsNode_LinkedState_Type linked_state) +void DepsgraphNodeBuilder::build_scene(Scene *scene, eDepsNode_LinkedState_Type linked_state) { /* scene ID block */ add_id_node(&scene->id); @@ -77,20 +77,23 @@ void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene, eDepsNode_Link // XXX: depending on how this goes, that scene itself could probably store its // own little partial depsgraph? if (scene->set) { - build_scene(bmain, scene->set, DEG_ID_LINKED_VIA_SET); + build_scene(scene->set, DEG_ID_LINKED_VIA_SET); } + /* Setup currently building context. */ + scene_ = scene; + /* scene objects */ int select_color = 1; for (SceneLayer *sl = (SceneLayer *)scene->render_layers.first; sl; sl = sl->next) { for (Base *base = (Base *)sl->object_bases.first; base; base = base->next) { /* object itself */ - build_object(scene, base->object, linked_state); + build_object(base->object, linked_state); base->object->select_color = select_color++; } } if (scene->camera != NULL) { - build_object(scene, scene->camera, linked_state); + build_object(scene->camera, linked_state); } /* rigidbody */ @@ -122,17 +125,17 @@ void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene, eDepsNode_Link } /* Cache file. */ - LINKLIST_FOREACH (CacheFile *, cachefile, &bmain->cachefiles) { + LINKLIST_FOREACH (CacheFile *, cachefile, &bmain_->cachefiles) { build_cachefile(cachefile); } /* Masks. */ - LINKLIST_FOREACH (Mask *, mask, &bmain->mask) { + LINKLIST_FOREACH (Mask *, mask, &bmain_->mask) { build_mask(mask); } /* Movie clips. */ - LINKLIST_FOREACH (MovieClip *, clip, &bmain->movieclip) { + LINKLIST_FOREACH (MovieClip *, clip, &bmain_->movieclip) { build_movieclip(clip); } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 91902ed0ea6..34df44ae046 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -118,8 +118,6 @@ namespace { struct BuilderWalkUserData { DepsgraphRelationBuilder *builder; - Main *bmain; - Scene *scene; }; static void modifier_walk(void *user_data, @@ -129,7 +127,7 @@ static void modifier_walk(void *user_data, { BuilderWalkUserData *data = (BuilderWalkUserData *)user_data; if (*obpoin) { - data->builder->build_object(data->bmain, data->scene, *obpoin); + data->builder->build_object(*obpoin); } } @@ -142,7 +140,7 @@ void constraint_walk(bConstraint * /*con*/, if (*idpoin) { ID *id = *idpoin; if (GS(id->name) == ID_OB) { - data->builder->build_object(data->bmain, data->scene, (Object *)id); + data->builder->build_object((Object *)id); } } } @@ -194,8 +192,11 @@ RNAPathKey::RNAPathKey(ID *id, const char *path) : } } -DepsgraphRelationBuilder::DepsgraphRelationBuilder(Depsgraph *graph) : - m_graph(graph) +DepsgraphRelationBuilder::DepsgraphRelationBuilder(Main *bmain, + Depsgraph *graph) + : bmain_(bmain), + graph_(graph), + scene_(NULL) { } @@ -207,14 +208,14 @@ TimeSourceDepsNode *DepsgraphRelationBuilder::find_node( return NULL; } else { - return m_graph->time_source; + return graph_->time_source; } } ComponentDepsNode *DepsgraphRelationBuilder::find_node( const ComponentKey &key) const { - IDDepsNode *id_node = m_graph->find_id_node(key.id); + IDDepsNode *id_node = graph_->find_id_node(key.id); if (!id_node) { fprintf(stderr, "find_node component: Could not find ID %s\n", (key.id != NULL) ? key.id->name : "<null>"); @@ -228,7 +229,7 @@ ComponentDepsNode *DepsgraphRelationBuilder::find_node( OperationDepsNode *DepsgraphRelationBuilder::find_node( const OperationKey &key) const { - IDDepsNode *id_node = m_graph->find_id_node(key.id); + IDDepsNode *id_node = graph_->find_id_node(key.id); if (!id_node) { fprintf(stderr, "find_node operation: Could not find ID\n"); return NULL; @@ -253,13 +254,13 @@ OperationDepsNode *DepsgraphRelationBuilder::find_node( DepsNode *DepsgraphRelationBuilder::find_node(const RNAPathKey &key) const { - return m_graph->find_node_from_pointer(&key.ptr, key.prop); + return graph_->find_node_from_pointer(&key.ptr, key.prop); } OperationDepsNode *DepsgraphRelationBuilder::has_node( const OperationKey &key) const { - IDDepsNode *id_node = m_graph->find_id_node(key.id); + IDDepsNode *id_node = graph_->find_id_node(key.id); if (!id_node) { return NULL; } @@ -276,7 +277,7 @@ void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc, const char *description) { if (timesrc && node_to) { - m_graph->add_new_relation(timesrc, node_to, description); + graph_->add_new_relation(timesrc, node_to, description); } else { DEG_DEBUG_PRINTF("add_time_relation(%p = %s, %p = %s, %s) Failed\n", @@ -292,7 +293,7 @@ void DepsgraphRelationBuilder::add_operation_relation( const char *description) { if (node_from && node_to) { - m_graph->add_new_relation(node_from, node_to, description); + graph_->add_new_relation(node_from, node_to, description); } else { DEG_DEBUG_PRINTF("add_operation_relation(%p = %s, %p = %s, %s) Failed\n", @@ -367,31 +368,30 @@ void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key, Depsgraph *DepsgraphRelationBuilder::getGraph() { - return m_graph; + return graph_; } /* **** Functions to build relations between entities **** */ -void DepsgraphRelationBuilder::begin_build(Main *bmain) +void DepsgraphRelationBuilder::begin_build() { /* LIB_TAG_DOIT is used to indicate whether node for given ID was already * created or not. */ - BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); + BKE_main_id_tag_all(bmain_, LIB_TAG_DOIT, false); /* XXX nested node trees are notr included in tag-clearing above, * so we need to do this manually. */ - FOREACH_NODETREE(bmain, nodetree, id) { + FOREACH_NODETREE(bmain_, nodetree, id) + { if (id != (ID *)nodetree) { nodetree->id.tag &= ~LIB_TAG_DOIT; } - } FOREACH_NODETREE_END + } + FOREACH_NODETREE_END } -void DepsgraphRelationBuilder::build_group(Main *bmain, - Scene *scene, - Object *object, - Group *group) +void DepsgraphRelationBuilder::build_group(Object *object, Group *group) { ID *group_id = &group->id; bool group_done = (group_id->tag & LIB_TAG_DOIT) != 0; @@ -400,7 +400,7 @@ void DepsgraphRelationBuilder::build_group(Main *bmain, DEG_OPCODE_TRANSFORM_LOCAL); LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { if (!group_done) { - build_object(bmain, scene, go->ob); + build_object(go->ob); } ComponentKey dupli_transform_key(&go->ob->id, DEG_NODE_TYPE_TRANSFORM); add_relation(dupli_transform_key, object_local_transform_key, "Dupligroup"); @@ -408,7 +408,7 @@ void DepsgraphRelationBuilder::build_group(Main *bmain, group_id->tag |= LIB_TAG_DOIT; } -void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *ob) +void DepsgraphRelationBuilder::build_object(Object *ob) { if (ob->id.tag & LIB_TAG_DOIT) { return; @@ -437,15 +437,11 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o if (ob->modifiers.first != NULL) { BuilderWalkUserData data; data.builder = this; - data.bmain = bmain; - data.scene = scene; modifiers_foreachObjectLink(ob, modifier_walk, &data); } if (ob->constraints.first != NULL) { BuilderWalkUserData data; data.builder = this; - data.bmain = bmain; - data.scene = scene; BKE_constraints_id_loop(&ob->constraints, constraint_walk, &data); } @@ -456,10 +452,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o DEG_OPCODE_TRANSFORM_CONSTRAINTS); /* constraint relations */ - // TODO: provide base op - // XXX: this is broken - build_constraints(scene, - &ob->id, + build_constraints(&ob->id, DEG_NODE_TYPE_TRANSFORM, "", &ob->constraints, @@ -512,7 +505,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o case OB_MBALL: case OB_LATTICE: { - build_obdata_geom(bmain, scene, ob); + build_obdata_geom(ob); break; } @@ -521,7 +514,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o build_proxy_rig(ob); } else { - build_rig(bmain, scene, ob); + build_rig(ob); } break; @@ -548,7 +541,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o /* Particle systems. */ if (ob->particlesystem.first != NULL) { - build_particles(scene, ob); + build_particles(ob); } /* Grease pencil. */ @@ -559,7 +552,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o /* Object that this is a proxy for. */ if (ob->proxy != NULL) { ob->proxy->proxy_from = ob; - build_object(bmain, scene, ob->proxy); + build_object(ob->proxy); /* TODO(sergey): This is an inverted relation, matches old depsgraph * behavior and need to be investigated if it still need to be inverted. */ @@ -570,7 +563,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o /* Object dupligroup. */ if (ob->dup_group != NULL) { - build_group(bmain, scene, ob, ob->dup_group); + build_group(ob, ob->dup_group); } } @@ -666,7 +659,7 @@ void DepsgraphRelationBuilder::build_object_parent(Object *ob) } } -void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, +void DepsgraphRelationBuilder::build_constraints(ID *id, eDepsNode_Type component_type, const char *component_subdata, ListBase *constraints, @@ -717,8 +710,8 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) { depends_on_camera = true; } - if (depends_on_camera && scene->camera) { - ComponentKey camera_key(&scene->camera->id, DEG_NODE_TYPE_TRANSFORM); + if (depends_on_camera && scene_->camera != NULL) { + ComponentKey camera_key(&scene_->camera->id, DEG_NODE_TYPE_TRANSFORM); add_relation(camera_key, constraint_op_key, cti->name); } /* TODO(sergey): This is more a TimeSource -> MovieClip -> @@ -1018,7 +1011,7 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) /* Drivers on armature-level bone settings (i.e. bbone stuff), * which will affect the evaluation of corresponding pose bones. */ - IDDepsNode *arm_node = m_graph->find_id_node(id); + IDDepsNode *arm_node = graph_->find_id_node(id); char *bone_name = BLI_str_quoted_substrN(rna_path, "bones["); if (arm_node != NULL && bone_name != NULL) { /* Find objects which use this, and make their eval callbacks @@ -1342,7 +1335,7 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) } } -void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) +void DepsgraphRelationBuilder::build_particles(Object *ob) { TimeSourceKey time_src_key; OperationKey obdata_ubereval_key(&ob->id, @@ -1405,7 +1398,7 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) /* collisions */ if (part->type != PART_HAIR) { add_collision_relations(psys_key, - scene, + scene_, ob, part->collision_group, true, @@ -1416,7 +1409,7 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) psys->clmd->coll_parms != NULL) { add_collision_relations(psys_key, - scene, + scene_, ob, psys->clmd->coll_parms->group, true, @@ -1425,7 +1418,7 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) /* effectors */ add_forcefield_relations(psys_key, - scene, + scene_, ob, psys, part->effector_weights, @@ -1488,8 +1481,7 @@ void DepsgraphRelationBuilder::build_particle_settings(ParticleSettings *part) add_relation(eval_key, recalc_clear_key, "Particle Settings Clear Recalc"); } -void DepsgraphRelationBuilder::build_cloth(Scene * /*scene*/, - Object *object, +void DepsgraphRelationBuilder::build_cloth(Object *object, ModifierData * /*md*/) { OperationKey cache_key(&object->id, @@ -1546,7 +1538,7 @@ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) * re-evaluation of the individual instances of this geometry. */ // TODO: Materials and lighting should probably get their own component, instead of being lumped under geometry? -void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Object *ob) +void DepsgraphRelationBuilder::build_obdata_geom(Object *ob) { ID *obdata = (ID *)ob->data; @@ -1568,7 +1560,7 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje * things like data mask to be used. We add relation here to ensure object is * never evaluated prior to Scene's CoW is ready. */ - OperationKey scene_key(&scene->id, + OperationKey scene_key(&scene_->id, DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_PLACEHOLDER, "Scene Eval"); @@ -1583,8 +1575,8 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje DepsNodeHandle handle = create_node_handle(obdata_ubereval_key); mti->updateDepsgraph( md, - bmain, - scene, + bmain_, + scene_, ob, reinterpret_cast< ::DepsNodeHandle* >(&handle)); } @@ -1606,7 +1598,7 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje } if (md->type == eModifierType_Cloth) { - build_cloth(scene, ob, md); + build_cloth(ob, md); } } } @@ -1674,8 +1666,7 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje case OB_MBALL: { - Object *mom = BKE_mball_basis_find(scene, ob); - + Object *mom = BKE_mball_basis_find(scene_, ob); /* motherball - mom depends on children! */ if (mom != ob) { /* non-motherball -> cannot be directly evaluated! */ @@ -1696,18 +1687,18 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje // XXX: these needs geom data, but where is geom stored? if (cu->bevobj) { ComponentKey bevob_key(&cu->bevobj->id, DEG_NODE_TYPE_GEOMETRY); - build_object(bmain, scene, cu->bevobj); + build_object(cu->bevobj); add_relation(bevob_key, geom_key, "Curve Bevel"); } if (cu->taperobj) { ComponentKey taperob_key(&cu->taperobj->id, DEG_NODE_TYPE_GEOMETRY); - build_object(bmain, scene, cu->taperobj); + build_object(cu->taperobj); add_relation(taperob_key, geom_key, "Curve Taper"); } if (ob->type == OB_FONT) { if (cu->textoncurve) { ComponentKey textoncurve_key(&cu->textoncurve->id, DEG_NODE_TYPE_GEOMETRY); - build_object(bmain, scene, cu->textoncurve); + build_object(cu->textoncurve); add_relation(textoncurve_key, geom_key, "Text on Curve"); } } @@ -1826,23 +1817,40 @@ void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree) ComponentKey shading_key(ntree_id, DEG_NODE_TYPE_SHADING); /* nodetree's nodes... */ LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) { - if (bnode->id) { - if (GS(bnode->id->name) == ID_MA) { - build_material((Material *)bnode->id); - } - else if (bnode->type == ID_TE) { - build_texture((Tex *)bnode->id); - } - else if (bnode->type == NODE_GROUP) { - bNodeTree *group_ntree = (bNodeTree *)bnode->id; - if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) { - build_nodetree(group_ntree); - group_ntree->id.tag |= LIB_TAG_DOIT; - } - ComponentKey group_shading_key(&group_ntree->id, - DEG_NODE_TYPE_SHADING); - add_relation(group_shading_key, shading_key, "Group Node"); + ID *id = bnode->id; + if (id == NULL) { + continue; + } + ID_Type id_type = GS(id->name); + if (id_type == ID_MA) { + build_material((Material *)bnode->id); + } + else if (id_type == ID_TE) { + build_texture((Tex *)bnode->id); + } + else if (id_type == ID_IM) { + /* nothing for now. */ + } + else if (id_type == ID_OB) { + build_object((Object *)id); + } + else if (id_type == ID_SCE) { + /* Scenes are used by compositor trees, and handled by render + * pipeline. No need to build dependencies for them here. + */ + } + else if (bnode->type == NODE_GROUP) { + bNodeTree *group_ntree = (bNodeTree *)id; + if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) { + build_nodetree(group_ntree); + group_ntree->id.tag |= LIB_TAG_DOIT; } + ComponentKey group_shading_key(&group_ntree->id, + DEG_NODE_TYPE_SHADING); + add_relation(group_shading_key, shading_key, "Group Node"); + } + else { + BLI_assert(!"Unknown ID type used for node"); } } @@ -1990,7 +1998,7 @@ void DepsgraphRelationBuilder::build_lightprobe(Object *object) void DepsgraphRelationBuilder::build_copy_on_write_relations() { - foreach (IDDepsNode *id_node, m_graph->id_nodes) { + foreach (IDDepsNode *id_node, graph_->id_nodes) { build_copy_on_write_relations(id_node); } } @@ -2026,13 +2034,13 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDDepsNode *id_node */ OperationDepsNode *op_entry = comp_node->get_entry_operation(); if (op_entry != NULL) { - m_graph->add_new_relation(op_cow, op_entry, "CoW Dependency"); + graph_->add_new_relation(op_cow, op_entry, "CoW Dependency"); } /* All dangling operations should also be executed after copy-on-write. */ GHASH_FOREACH_BEGIN(OperationDepsNode *, op_node, comp_node->operations_map) { if (op_node->inlinks.size() == 0) { - m_graph->add_new_relation(op_cow, op_node, "CoW Dependency"); + graph_->add_new_relation(op_cow, op_node, "CoW Dependency"); } } GHASH_FOREACH_END(); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h index e8bdc662bd6..81636db0bcf 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.h @@ -167,9 +167,9 @@ struct RNAPathKey struct DepsgraphRelationBuilder { - DepsgraphRelationBuilder(Depsgraph *graph); + DepsgraphRelationBuilder(Main *bmain, Depsgraph *graph); - void begin_build(Main *bmain); + void begin_build(); template <typename KeyFrom, typename KeyTo> void add_relation(const KeyFrom& key_from, @@ -186,11 +186,11 @@ struct DepsgraphRelationBuilder const DepsNodeHandle *handle, const char *description); - void build_scene(Main *bmain, Scene *scene); - void build_group(Main *bmain, Scene *scene, Object *object, Group *group); - void build_object(Main *bmain, Scene *scene, Object *ob); + void build_scene(Scene *scene); + void build_group(Object *object, Group *group); + void build_object(Object *ob); void build_object_parent(Object *ob); - void build_constraints(Scene *scene, ID *id, + void build_constraints(ID *id, eDepsNode_Type component_type, const char *component_subdata, ListBase *constraints, @@ -199,9 +199,9 @@ struct DepsgraphRelationBuilder void build_driver(ID *id, FCurve *fcurve); void build_world(World *world); void build_rigidbody(Scene *scene); - void build_particles(Scene *scene, Object *ob); + void build_particles(Object *ob); void build_particle_settings(ParticleSettings *part); - void build_cloth(Scene *scene, Object *object, ModifierData *md); + void build_cloth(Object *object, ModifierData *md); void build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con, @@ -210,10 +210,10 @@ struct DepsgraphRelationBuilder bPoseChannel *pchan, bConstraint *con, RootPChanMap *root_map); - void build_rig(Main *bmain, Scene *scene, Object *ob); + void build_rig(Object *ob); void build_proxy_rig(Object *ob); void build_shapekeys(ID *obdata, Key *key); - void build_obdata_geom(Main *bmain, Scene *scene, Object *ob); + void build_obdata_geom(Object *ob); void build_camera(Object *ob); void build_lamp(Object *ob); void build_nodetree(bNodeTree *ntree); @@ -228,10 +228,15 @@ struct DepsgraphRelationBuilder void build_lightprobe(Object *object); void add_collision_relations(const OperationKey &key, - Scene *scene, Object *ob, Group *group, - bool dupli, const char *name); + Scene *scene, + Object *ob, + Group *group, + bool dupli, + const char *name); void add_forcefield_relations(const OperationKey &key, - Scene *scene, Object *ob, ParticleSystem *psys, + Scene *scene, + Object *ob, + ParticleSystem *psys, EffectorWeights *eff, bool add_absorption, const char *name); @@ -278,7 +283,12 @@ protected: bool needs_animdata_node(ID *id); private: - Depsgraph *m_graph; + /* State which never changes, same for the whole builder time. */ + Main *bmain_; + Depsgraph *graph_; + + /* State which demotes currently built entities. */ + Scene *scene_; }; struct DepsNodeHandle diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc index c23d6d3a2bd..476e793d3f7 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc @@ -302,7 +302,7 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object *ob, } /* Pose/Armature Bones Graph */ -void DepsgraphRelationBuilder::build_rig(Main *bmain, Scene *scene, Object *ob) +void DepsgraphRelationBuilder::build_rig(Object *ob) { /* Armature-Data */ bArmature *arm = (bArmature *)ob->data; @@ -415,7 +415,7 @@ void DepsgraphRelationBuilder::build_rig(Main *bmain, Scene *scene, Object *ob) /* Buil constraints. */ if (pchan->constraints.first != NULL) { /* constraints stack and constraint dependencies */ - build_constraints(scene, &ob->id, DEG_NODE_TYPE_BONE, pchan->name, &pchan->constraints, &root_map); + build_constraints(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, &pchan->constraints, &root_map); /* pose -> constraints */ OperationKey constraints_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_CONSTRAINTS); @@ -441,7 +441,7 @@ void DepsgraphRelationBuilder::build_rig(Main *bmain, Scene *scene, Object *ob) add_relation(bone_done_key, flush_key, "PoseEval Result-Bone Link"); /* Custom shape. */ if (pchan->custom != NULL) { - build_object(bmain, scene, pchan->custom); + build_object(pchan->custom); } } } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc index b8a2fe4851d..af37decdbc7 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc @@ -68,23 +68,26 @@ extern "C" { namespace DEG { -void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene) +void DepsgraphRelationBuilder::build_scene(Scene *scene) { if (scene->set) { - build_scene(bmain, scene->set); + build_scene(scene->set); } /* XXX store scene to access from DAG_get_scene */ - m_graph->scene = scene; + graph_->scene = scene; + + /* Setup currently building context. */ + scene_ = scene; /* scene objects */ for (SceneLayer *sl = (SceneLayer *)scene->render_layers.first; sl; sl = sl->next) { for (Base *base = (Base *)sl->object_bases.first; base; base = base->next) { - build_object(bmain, scene, base->object); + build_object(base->object); } } if (scene->camera != NULL) { - build_object(bmain, scene, scene->camera); + build_object(scene->camera); } /* rigidbody */ @@ -113,12 +116,12 @@ void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene) } /* Masks. */ - LINKLIST_FOREACH (Mask *, mask, &bmain->mask) { + LINKLIST_FOREACH (Mask *, mask, &bmain_->mask) { build_mask(mask); } /* Movie clips. */ - LINKLIST_FOREACH (MovieClip *, clip, &bmain->movieclip) { + LINKLIST_FOREACH (MovieClip *, clip, &bmain_->movieclip) { build_movieclip(clip); } @@ -126,8 +129,8 @@ void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene) build_scene_layer_collections(scene); /* TODO(sergey): Do this flush on CoW object? */ - for (Depsgraph::OperationNodes::const_iterator it_op = m_graph->operations.begin(); - it_op != m_graph->operations.end(); + for (Depsgraph::OperationNodes::const_iterator it_op = graph_->operations.begin(); + it_op != graph_->operations.end(); ++it_op) { OperationDepsNode *node = *it_op; diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc index ab7e28e1638..c8c36646ade 100644 --- a/source/blender/depsgraph/intern/depsgraph_build.cc +++ b/source/blender/depsgraph/intern/depsgraph_build.cc @@ -216,15 +216,15 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene) /* 1) Generate all the nodes in the graph first */ DEG::DepsgraphNodeBuilder node_builder(bmain, deg_graph); - node_builder.begin_build(bmain); - node_builder.build_scene(bmain, scene, DEG::DEG_ID_LINKED_DIRECTLY); + node_builder.begin_build(); + node_builder.build_scene(scene, DEG::DEG_ID_LINKED_DIRECTLY); /* 2) Hook up relationships between operations - to determine evaluation * order. */ - DEG::DepsgraphRelationBuilder relation_builder(deg_graph); - relation_builder.begin_build(bmain); - relation_builder.build_scene(bmain, scene); + DEG::DepsgraphRelationBuilder relation_builder(bmain, deg_graph); + relation_builder.begin_build(); + relation_builder.build_scene(scene); if (DEG_depsgraph_use_copy_on_write()) { relation_builder.build_copy_on_write_relations(); } |