Fix T54962: Cycles crash using subsurface scattering texture blur.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 3 Jan 2019 16:08:46 +0000 (17:08 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 3 Jan 2019 16:10:37 +0000 (17:10 +0100)
intern/cycles/kernel/kernel_path_branched.h
intern/cycles/kernel/kernel_path_subsurface.h
intern/cycles/kernel/kernel_subsurface.h
intern/cycles/kernel/split/kernel_subsurface_scatter.h

index 80fcf5b056557153e55a7b03891167cc1a5f4488..21da4d9308b8e1d737e3068abf4d8529497a16d7 100644 (file)
@@ -368,12 +368,16 @@ ccl_device void kernel_branched_path_subsurface_scatter(KernelGlobals *kg,
                        /* compute lighting with the BSDF closure */
                        for(int hit = 0; hit < num_hits; hit++) {
                                ShaderData bssrdf_sd = *sd;
+                               Bssrdf *bssrdf = (Bssrdf *)sc;
+                               ClosureType bssrdf_type = sc->type;
+                               float bssrdf_roughness = bssrdf->roughness;
                                subsurface_scatter_multi_setup(kg,
                                                               &ss_isect,
                                                               hit,
                                                               &bssrdf_sd,
                                                               &hit_state,
-                                                              sc);
+                                                              bssrdf_type,
+                                                              bssrdf_roughness);
 
 #ifdef __VOLUME__
                                if(need_update_volume_stack) {
index 962776f21c17a60b98472211907ad4960b3fc44d..b5a92c74ed55c1c470e85237d16fc44ddd88c0fd 100644 (file)
@@ -64,6 +64,11 @@ bool kernel_path_subsurface_scatter(
                        sd->object_flag & SD_OBJECT_INTERSECTS_VOLUME;
 #  endif  /* __VOLUME__ */
 
+               /* Closure memory will be overwritten, so read required variables now. */
+               Bssrdf *bssrdf = (Bssrdf *)sc;
+               ClosureType bssrdf_type = sc->type;
+               float bssrdf_roughness = bssrdf->roughness;
+
                /* compute lighting with the BSDF closure */
                for(int hit = 0; hit < num_hits; hit++) {
                        /* NOTE: We reuse the existing ShaderData, we assume the path
@@ -74,7 +79,8 @@ bool kernel_path_subsurface_scatter(
                                                       hit,
                                                       sd,
                                                       state,
-                                                      sc);
+                                                      bssrdf_type,
+                                                      bssrdf_roughness);
 
                        kernel_path_surface_connect_light(kg, sd, emission_sd, *throughput, state, L);
 
index a06fbe72ffaf6a985981f6d9d22774c01bb53300..96b717530ce850960de56bd83d78fdabd4b5e067 100644 (file)
@@ -69,22 +69,21 @@ 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(KernelGlobals *kg, ShaderData *sd, const ShaderClosure *sc, float3 weight, float3 N)
+ccl_device void subsurface_scatter_setup_diffuse_bsdf(KernelGlobals *kg, ShaderData *sd, ClosureType type, float roughness, float3 weight, float3 N)
 {
        sd->flag &= ~SD_CLOSURE_FLAGS;
        sd->num_closure = 0;
        sd->num_closure_left = kernel_data.integrator.max_closures;
 
-       Bssrdf *bssrdf = (Bssrdf *)sc;
 #ifdef __PRINCIPLED__
-       if(bssrdf->type == CLOSURE_BSSRDF_PRINCIPLED_ID ||
-          bssrdf->type == CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID)
+       if(type == CLOSURE_BSSRDF_PRINCIPLED_ID ||
+          type == CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID)
        {
                PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf*)bsdf_alloc(sd, sizeof(PrincipledDiffuseBsdf), weight);
 
                if(bsdf) {
                        bsdf->N = N;
-                       bsdf->roughness = bssrdf->roughness;
+                       bsdf->roughness = roughness;
                        sd->flag |= bsdf_principled_diffuse_setup(bsdf);
 
                        /* replace CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID with this special ID so render passes
@@ -92,8 +91,8 @@ ccl_device void subsurface_scatter_setup_diffuse_bsdf(KernelGlobals *kg, ShaderD
                        bsdf->type = CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID;
                }
        }
-       else if(CLOSURE_IS_BSDF_BSSRDF(bssrdf->type) ||
-                       CLOSURE_IS_BSSRDF(bssrdf->type))
+       else if(CLOSURE_IS_BSDF_BSSRDF(type) ||
+                       CLOSURE_IS_BSSRDF(type))
 #endif  /* __PRINCIPLED__ */
        {
                DiffuseBsdf *bsdf = (DiffuseBsdf*)bsdf_alloc(sd, sizeof(DiffuseBsdf), weight);
@@ -309,7 +308,8 @@ ccl_device_noinline void subsurface_scatter_multi_setup(
         int hit,
         ShaderData *sd,
         ccl_addr_space PathState *state,
-        const ShaderClosure *sc)
+        ClosureType type,
+        float roughness)
 {
 #ifdef __SPLIT_KERNEL__
        Ray ray_object = ss_isect->ray;
@@ -332,7 +332,7 @@ ccl_device_noinline void subsurface_scatter_multi_setup(
        subsurface_color_bump_blur(kg, sd, state, &weight, &N);
 
        /* Setup diffuse BSDF. */
-       subsurface_scatter_setup_diffuse_bsdf(kg, sd, sc, weight, N);
+       subsurface_scatter_setup_diffuse_bsdf(kg, sd, type, roughness, weight, N);
 }
 
 /* Random walk subsurface scattering.
index af0303d860890d71557cfb95b5fba5c075f8a726..c51246fbc90634834ed9366e48cd6d3d99292072 100644 (file)
@@ -110,13 +110,18 @@ ccl_device_noinline bool kernel_split_branched_path_subsurface_indirect_light_it
                                *bssrdf_sd = *sd; /* note: copy happens each iteration of inner loop, this is
                                                   * important as the indirect path will write into bssrdf_sd */
 
+                               Bssrdf *bssrdf = (Bssrdf *)sc;
+                               ClosureType bssrdf_type = sc->type;
+                               float bssrdf_roughness = bssrdf->roughness;
+
                                LocalIntersection ss_isect_private = *ss_isect;
                                subsurface_scatter_multi_setup(kg,
                                                               &ss_isect_private,
                                                               hit,
                                                               bssrdf_sd,
                                                               hit_state,
-                                                              sc);
+                                                              bssrdf_type,
+                                                              bssrdf_roughness);
                                *ss_isect = ss_isect_private;
 
 #ifdef __VOLUME__