[Bf-blender-cvs] [32449e1b213] master: Code cleanup: store branch factor in PathState.

Brecht Van Lommel noreply at git.blender.org
Wed Sep 13 15:30:50 CEST 2017


Commit: 32449e1b21359c867c14d8b880e14960002a72aa
Author: Brecht Van Lommel
Date:   Sun Sep 10 14:09:12 2017 +0200
Branches: master
https://developer.blender.org/rB32449e1b21359c867c14d8b880e14960002a72aa

Code cleanup: store branch factor in PathState.

===================================================================

M	intern/cycles/kernel/kernel_bake.h
M	intern/cycles/kernel/kernel_path.h
M	intern/cycles/kernel/kernel_path_branched.h
M	intern/cycles/kernel/kernel_path_state.h
M	intern/cycles/kernel/kernel_random.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/split/kernel_branched.h
M	intern/cycles/kernel/split/kernel_do_volume.h
M	intern/cycles/kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h
M	intern/cycles/kernel/split/kernel_split_data_types.h

===================================================================

diff --git a/intern/cycles/kernel/kernel_bake.h b/intern/cycles/kernel/kernel_bake.h
index ef6f1969941..b05f6e9ed5e 100644
--- a/intern/cycles/kernel/kernel_bake.h
+++ b/intern/cycles/kernel/kernel_bake.h
@@ -102,7 +102,6 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
 					                     &emission_sd,
 					                     &ray,
 					                     throughput,
-					                     state.num_samples,
 					                     &state,
 					                     &L_sample);
 					kernel_path_subsurface_accum_indirect(&ss_indirect, &L_sample);
@@ -121,7 +120,7 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
 				state.ray_t = 0.0f;
 #endif
 				/* compute indirect light */
-				kernel_path_indirect(kg, &indirect_sd, &emission_sd, &ray, throughput, 1, &state, &L_sample);
+				kernel_path_indirect(kg, &indirect_sd, &emission_sd, &ray, throughput, &state, &L_sample);
 
 				/* sum and reset indirect light pass variables for the next samples */
 				path_radiance_sum_indirect(&L_sample);
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
index 6ad2a00272b..fc157feb28c 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -388,7 +388,6 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg,
                                      ShaderData *emission_sd,
                                      Ray *ray,
                                      float3 throughput,
-                                     int num_samples,
                                      PathState *state,
                                      PathRadiance *L)
 {
@@ -455,10 +454,7 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg,
 		/* path termination. this is a strange place to put the termination, it's
 		 * mainly due to the mixed in MIS that we use. gives too many unneeded
 		 * shader evaluations, only need emission if we are going to terminate */
-		float probability =
-		        path_state_continuation_probability(kg,
-		                                         state,
-		                                         throughput*num_samples);
+		float probability = path_state_continuation_probability(kg, state, throughput);
 
 		if(probability == 0.0f) {
 			break;
diff --git a/intern/cycles/kernel/kernel_path_branched.h b/intern/cycles/kernel/kernel_path_branched.h
index b908cbbe970..3994d8d4954 100644
--- a/intern/cycles/kernel/kernel_path_branched.h
+++ b/intern/cycles/kernel/kernel_path_branched.h
@@ -142,7 +142,6 @@ ccl_device_noinline void kernel_branched_path_surface_indirect_light(KernelGloba
 			                     emission_sd,
 			                     &bsdf_ray,
 			                     tp*num_samples_inv,
-			                     num_samples,
 			                     &ps,
 			                     L);
 
@@ -359,7 +358,6 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
 						                     &emission_sd,
 						                     &pray,
 						                     tp*num_samples_inv,
-						                     num_samples,
 						                     &ps,
 						                     L);
 
@@ -415,7 +413,6 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
 						                     &emission_sd,
 						                     &pray,
 						                     tp,
-						                     num_samples,
 						                     &ps,
 						                     L);
 
diff --git a/intern/cycles/kernel/kernel_path_state.h b/intern/cycles/kernel/kernel_path_state.h
index bedcd655bc6..bb09b4ac080 100644
--- a/intern/cycles/kernel/kernel_path_state.h
+++ b/intern/cycles/kernel/kernel_path_state.h
@@ -29,6 +29,7 @@ ccl_device_inline void path_state_init(KernelGlobals *kg,
 	state->rng_offset = PRNG_BASE_NUM;
 	state->sample = sample;
 	state->num_samples = kernel_data.integrator.aa_samples;
+	state->branch_factor = 1.0f;
 
 	state->bounce = 0;
 	state->diffuse_bounce = 0;
@@ -157,7 +158,9 @@ ccl_device_inline uint path_state_ray_visibility(KernelGlobals *kg, ccl_addr_spa
 	return flag;
 }
 
-ccl_device_inline float path_state_continuation_probability(KernelGlobals *kg, ccl_addr_space PathState *state, const float3 throughput)
+ccl_device_inline float path_state_continuation_probability(KernelGlobals *kg,
+                                                            ccl_addr_space PathState *state,
+                                                            const float3 throughput)
 {
 	if(state->flag & PATH_RAY_TRANSPARENT) {
 		/* Transparent rays are treated separately with own max bounces. */
@@ -201,7 +204,7 @@ ccl_device_inline float path_state_continuation_probability(KernelGlobals *kg, c
 
 	/* Probalistic termination: use sqrt() to roughly match typical view
 	 * transform and do path termination a bit later on average. */
-	return min(sqrtf(max3(fabs(throughput))), 1.0f);
+	return min(sqrtf(max3(fabs(throughput)) * state->branch_factor), 1.0f);
 }
 
 /* TODO(DingTo): Find more meaningful name for this */
@@ -224,5 +227,20 @@ ccl_device_inline bool path_state_ao_bounce(KernelGlobals *kg, ccl_addr_space Pa
     return (bounce > kernel_data.integrator.ao_bounces);
 }
 
+ccl_device_inline void path_state_branch(ccl_addr_space PathState *state,
+                                         int branch,
+                                         int num_branches)
+{
+	state->rng_offset += PRNG_BOUNCE_NUM;
+
+	if(num_branches > 1) {
+		/* Path is splitting into a branch, adjust so that each branch
+		 * still gets a unique sample from the same sequence. */
+		state->sample = state->sample*num_branches + branch;
+		state->num_samples = state->num_samples*num_branches;
+		state->branch_factor *= num_branches;
+	}
+}
+
 CCL_NAMESPACE_END
 
diff --git a/intern/cycles/kernel/kernel_random.h b/intern/cycles/kernel/kernel_random.h
index 221d92f5de1..b35ed3bd279 100644
--- a/intern/cycles/kernel/kernel_random.h
+++ b/intern/cycles/kernel/kernel_random.h
@@ -296,17 +296,6 @@ ccl_device_inline float path_branched_rng_light_termination(
 	return 0.0f;
 }
 
-ccl_device_inline void path_state_branch(ccl_addr_space PathState *state,
-                                         int branch,
-                                         int num_branches)
-{
-	/* path is splitting into a branch, adjust so that each branch
-	 * still gets a unique sample from the same sequence */
-	state->rng_offset += PRNG_BOUNCE_NUM;
-	state->sample = state->sample*num_branches + branch;
-	state->num_samples = state->num_samples*num_branches;
-}
-
 ccl_device_inline uint lcg_state_init(PathState *state,
                                       uint scramble)
 {
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index e3d2ae15f5c..1b4e926ca28 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -1008,9 +1008,10 @@ typedef struct PathState {
 
 	/* random number generator state */
 	uint rng_hash;          /* per pixel hash */
-	int rng_offset;    		/* dimension offset */
-	int sample;        		/* path sample number */
-	int num_samples;		/* total number of times this path will be sampled */
+	int rng_offset;         /* dimension offset */
+	int sample;             /* path sample number */
+	int num_samples;        /* total number of times this path will be sampled */
+	float branch_factor;    /* number of branches in indirect paths */
 
 	/* bounce counting */
 	int bounce;
diff --git a/intern/cycles/kernel/split/kernel_branched.h b/intern/cycles/kernel/split/kernel_branched.h
index 9fe4ec18e9e..2c390593ba1 100644
--- a/intern/cycles/kernel/split/kernel_branched.h
+++ b/intern/cycles/kernel/split/kernel_branched.h
@@ -188,7 +188,6 @@ ccl_device_noinline bool kernel_split_branched_path_surface_indirect_light_iter(
 			/* update state for next iteration */
 			branched_state->next_closure = i;
 			branched_state->next_sample = j+1;
-			branched_state->num_samples = num_samples;
 
 			/* start the indirect path */
 			*tp *= num_samples_inv;
diff --git a/intern/cycles/kernel/split/kernel_do_volume.h b/intern/cycles/kernel/split/kernel_do_volume.h
index 478d83d633e..2975aa20004 100644
--- a/intern/cycles/kernel/split/kernel_do_volume.h
+++ b/intern/cycles/kernel/split/kernel_do_volume.h
@@ -72,7 +72,6 @@ ccl_device_noinline bool kernel_split_branched_path_volume_indirect_light_iter(K
 			/* start the indirect path */
 			branched_state->next_closure = 0;
 			branched_state->next_sample = j+1;
-			branched_state->num_samples = num_samples;
 
 			/* Attempting to share too many samples is slow for volumes as it causes us to
 			 * loop here more and have many calls to kernel_volume_integrate which evaluates
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 733c25f5aa4..9036b1e473d 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
@@ -134,38 +134,22 @@ ccl_device void kernel_holdout_emission_blurring_pathtermination_ao(
 		 * mainly due to the mixed in MIS that we use. gives too many unneeded
 		 * shader evaluations, only need emission if we are going to terminate.
 		 */
-#ifndef __BRANCHED_PATH__
 		float probability = path_state_continuation_probability(kg, state, throughput);
-#else
-		float probability = 1.0f;
-
-		if(!kernel_data.integrator.branched) {
-			probability = path_state_continuation_probability(kg, state, throughput);
-		}
-		else if(IS_FLAG(ray_state, ray_index, RAY_BRANCHED_INDIRECT)) {
-			int num_samples = kernel_split_state.branched_state[ray_index].num_samples;
-			probability = path_state_continuation_probability(kg, state, throughput*num_samples);
-		}
-		else if(state->flag & PATH_RAY_TRANSPARENT) {
-			probability = path_state_continuation_probability(kg, state, throughput);
-		}
-#endif
 
 		if(probability == 0.0f) {
 			kernel_split_path_end(kg, ray_index);
 		}
-
-		if(IS_STATE(ray_state, ray_index, RAY_ACTIVE)) {
-			if(probability != 1.0f) {
-				float terminate = path_state_rng_1D_for_deci

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list