Fix #36545: crash with branched path tracing, correlated multi-jittered
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 23 Aug 2013 23:04:50 +0000 (23:04 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 23 Aug 2013 23:04:50 +0000 (23:04 +0000)
sampling and subsurface scattering.

intern/cycles/kernel/kernel_jitter.h
intern/cycles/kernel/kernel_path.h

index d8b4db498c8aba4d40deea4a5ebabe9a44c5a41d..18666b51c0cb856407a13128c90bd4e65f721e6e 100644 (file)
@@ -137,6 +137,8 @@ __device_inline float cmj_randfloat(uint i, uint p)
 #ifdef __CMJ__
 __device float cmj_sample_1D(int s, int N, int p)
 {
+       kernel_assert(s < N);
+
        uint x = cmj_permute(s, N, p * 0x68bc21eb);
        float jx = cmj_randfloat(s, p * 0x967a889b);
 
@@ -146,6 +148,8 @@ __device float cmj_sample_1D(int s, int N, int p)
 
 __device void cmj_sample_2D(int s, int N, int p, float *fx, float *fy)
 {
+       kernel_assert(s < N);
+
        int m = float_to_int(sqrtf(N));
        int n = (N + m - 1)/m;
        float invN = 1.0f/N;
index ffbbbe71cfc348dae1580d9f7edc1ca3f23fcdd4..cdf80aed4d1ae8e3579da62d5a918400eea3d45f 100644 (file)
@@ -231,7 +231,7 @@ __device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *ra
        return result;
 }
 
-__device float4 kernel_path_integrator(KernelGlobals *kg, RNG *rng, int sample, Ray ray, __global float *buffer)
+__device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, Ray ray, __global float *buffer)
 {
        /* initialize */
        PathRadiance L;
@@ -778,17 +778,12 @@ __device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, int sample, Ray
        }
 }
 
-__device_noinline void kernel_branched_path_integrate_lighting(KernelGlobals *kg, RNG *rng, int sample,
+__device_noinline void kernel_branched_path_integrate_lighting(KernelGlobals *kg, RNG *rng,
+       int sample, int aa_samples,
        ShaderData *sd, float3 throughput, float num_samples_adjust,
        float min_ray_pdf, float ray_pdf, PathState state,
        int rng_offset, PathRadiance *L, __global float *buffer)
 {
-#ifdef __CMJ__
-       int aa_samples = kernel_data.integrator.aa_samples;
-#else
-       int aa_samples = 0;
-#endif
-
 #ifdef __AO__
        /* ambient occlusion */
        if(kernel_data.integrator.use_ambient_occlusion || (sd->flag & SD_AO)) {
@@ -1115,6 +1110,7 @@ __device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, int
 
                                                /* compute lighting with the BSDF closure */
                                                kernel_branched_path_integrate_lighting(kg, rng, sample*num_samples + j,
+                                                       aa_samples*num_samples,
                                                        &bssrdf_sd, throughput, num_samples_inv,
                                                        ray_pdf, ray_pdf, state, rng_offset, &L, buffer);
                                        }
@@ -1127,6 +1123,7 @@ __device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, int
                                                /* compute lighting with the BSDF closure */
                                                for(int hit = 0; hit < num_hits; hit++)
                                                        kernel_branched_path_integrate_lighting(kg, rng, sample*num_samples + j,
+                                                               aa_samples*num_samples,
                                                                &bssrdf_sd[hit], throughput, num_samples_inv,
                                                                ray_pdf, ray_pdf, state, rng_offset, &L, buffer);
                                        }
@@ -1136,8 +1133,8 @@ __device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, int
 #endif
 
                /* lighting */
-               kernel_branched_path_integrate_lighting(kg, rng, sample, &sd, throughput,
-                       1.0f, ray_pdf, ray_pdf, state, rng_offset, &L, buffer);
+               kernel_branched_path_integrate_lighting(kg, rng, sample, aa_samples,
+                       &sd, throughput, 1.0f, ray_pdf, ray_pdf, state, rng_offset, &L, buffer);
 
                /* continue in case of transparency */
                throughput *= shader_bsdf_transparency(kg, &sd);
@@ -1213,7 +1210,7 @@ __device void kernel_path_trace(KernelGlobals *kg,
        float4 L;
 
        if (ray.t != 0.0f)
-               L = kernel_path_integrator(kg, &rng, sample, ray, buffer);
+               L = kernel_path_integrate(kg, &rng, sample, ray, buffer);
        else
                L = make_float4(0.0f, 0.0f, 0.0f, 0.0f);