From aabafece03fee807d6b9e5e6d40273f70cc4b9d8 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 8 Feb 2018 12:45:12 +0100 Subject: Code refactor: tweaks in SSS code to prepare for coming changes. This also fixes a subtle bug in the split kernel branched path SSS, the volume stack update can't be shared between multiple hit points. --- .../cycles/kernel/split/kernel_split_data_types.h | 4 -- .../kernel/split/kernel_subsurface_scatter.h | 43 +++++++++------------- 2 files changed, 17 insertions(+), 30 deletions(-) (limited to 'intern/cycles/kernel/split') diff --git a/intern/cycles/kernel/split/kernel_split_data_types.h b/intern/cycles/kernel/split/kernel_split_data_types.h index 5f40fdc9240..56194d9f857 100644 --- a/intern/cycles/kernel/split/kernel_split_data_types.h +++ b/intern/cycles/kernel/split/kernel_split_data_types.h @@ -67,10 +67,6 @@ typedef ccl_global struct SplitBranchedState { uint lcg_state; LocalIntersection ss_isect; - -# ifdef __VOLUME__ - VolumeStack volume_stack[VOLUME_STACK_SIZE]; -# endif /* __VOLUME__ */ #endif /*__SUBSURFACE__ */ int shared_sample_count; /* number of branched samples shared with other threads */ diff --git a/intern/cycles/kernel/split/kernel_subsurface_scatter.h b/intern/cycles/kernel/split/kernel_subsurface_scatter.h index 993e8d4d477..f902d000918 100644 --- a/intern/cycles/kernel/split/kernel_subsurface_scatter.h +++ b/intern/cycles/kernel/split/kernel_subsurface_scatter.h @@ -61,11 +61,16 @@ ccl_device_noinline bool kernel_split_branched_path_subsurface_indirect_light_it /* do subsurface scatter step with copy of shader data, this will * replace the BSSRDF with a diffuse BSDF closure */ for(int j = branched_state->ss_next_sample; j < num_samples; j++) { + ccl_global PathState *hit_state = &kernel_split_state.path_state[ray_index]; + *hit_state = branched_state->path_state; + hit_state->rng_hash = bssrdf_rng_hash; + path_state_branch(hit_state, j, num_samples); + ccl_global LocalIntersection *ss_isect = &branched_state->ss_isect; float bssrdf_u, bssrdf_v; path_branched_rng_2D(kg, bssrdf_rng_hash, - &branched_state->path_state, + hit_state, j, num_samples, PRNG_BSDF_U, @@ -89,6 +94,8 @@ ccl_device_noinline bool kernel_split_branched_path_subsurface_indirect_light_it *ss_isect = ss_isect_private; } + hit_state->rng_offset += PRNG_BOUNCE_NUM; + #ifdef __VOLUME__ Ray volume_ray = branched_state->ray; bool need_update_volume_stack = @@ -107,39 +114,24 @@ ccl_device_noinline bool kernel_split_branched_path_subsurface_indirect_light_it &ss_isect_private, hit, bssrdf_sd, - &branched_state->path_state, - branched_state->path_state.flag, - sc, - true); + hit_state, + sc); *ss_isect = ss_isect_private; - ccl_global PathState *hit_state = &kernel_split_state.path_state[ray_index]; - *hit_state = branched_state->path_state; - - path_state_branch(hit_state, j, num_samples); - hit_state->rng_offset += PRNG_BOUNCE_NUM; - #ifdef __VOLUME__ if(need_update_volume_stack) { /* Setup ray from previous surface point to the new one. */ float3 P = ray_offset(bssrdf_sd->P, -bssrdf_sd->Ng); volume_ray.D = normalize_len(P - volume_ray.P, &volume_ray.t); - /* this next part is expensive as it does scene intersection so only do once */ - if(branched_state->next_closure == 0 && branched_state->next_sample == 0) { - for(int k = 0; k < VOLUME_STACK_SIZE; k++) { - branched_state->volume_stack[k] = hit_state->volume_stack[k]; - } - - kernel_volume_stack_update_for_subsurface(kg, - emission_sd, - &volume_ray, - branched_state->volume_stack); - } - for(int k = 0; k < VOLUME_STACK_SIZE; k++) { - hit_state->volume_stack[k] = branched_state->volume_stack[k]; + hit_state->volume_stack[k] = branched_state->path_state.volume_stack[k]; } + + kernel_volume_stack_update_for_subsurface(kg, + emission_sd, + &volume_ray, + hit_state->volume_stack); } #endif /* __VOLUME__ */ @@ -148,7 +140,7 @@ ccl_device_noinline bool kernel_split_branched_path_subsurface_indirect_light_it /* direct light */ if(kernel_data.integrator.use_direct_light) { int all = (kernel_data.integrator.sample_all_lights_direct) || - (branched_state->path_state.flag & PATH_RAY_SHADOW_CATCHER); + (hit_state->flag & PATH_RAY_SHADOW_CATCHER); kernel_branched_path_surface_connect_light(kg, bssrdf_sd, emission_sd, @@ -265,7 +257,6 @@ ccl_device void kernel_subsurface_scatter(KernelGlobals *kg) subsurface_scatter_step(kg, sd, state, - state->flag, sc, &lcg_state, bssrdf_u, bssrdf_v, -- cgit v1.2.3