[Bf-blender-cvs] [cc927b359c5] soc-2022-many-lights-sampling: Fix an illegal address and assert issue with Many Lights Sampling

Brecht Van Lommel noreply at git.blender.org
Tue Sep 20 01:07:42 CEST 2022


Commit: cc927b359c5925a9d0cc566cd5689b8063ba849a
Author: Brecht Van Lommel
Date:   Tue Sep 20 00:08:54 2022 +0200
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rBcc927b359c5925a9d0cc566cd5689b8063ba849a

Fix an illegal address and assert issue with Many Lights Sampling

If the emitter_index in light_tree_emitter_reservoir_weight() is less than 0,
then this lead to an error when using the kernel_data_fetch function.

This patch fixes this by returning a weight of 0 and ending the function before
we reach kernel_data_fetch in this situation.  Returning a weight of 0 is safe
here as an emitter_index less than 0 indicates that no lights were picked. So
they will have a weight of 0.

Contributed by Alaska

Differential Revision: https://developer.blender.org/D15991

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

M	intern/cycles/kernel/light/light_tree.h

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

diff --git a/intern/cycles/kernel/light/light_tree.h b/intern/cycles/kernel/light/light_tree.h
index f5eb4347492..1d1ea67a467 100644
--- a/intern/cycles/kernel/light/light_tree.h
+++ b/intern/cycles/kernel/light/light_tree.h
@@ -83,6 +83,10 @@ ccl_device float light_tree_emitter_reservoir_weight(KernelGlobals kg,
                                                      const float3 N,
                                                      int emitter_index)
 {
+  if (emitter_index < 0) {
+    return 0.0f;
+  }
+
   ccl_global const KernelLightTreeEmitter *kemitter = &kernel_data_fetch(light_tree_emitters,
                                                                          emitter_index);
   const int prim = kemitter->prim_id;
@@ -235,7 +239,6 @@ ccl_device int light_tree_cluster_select_emitter(KernelGlobals kg,
     total_emitter_importance += light_tree_emitter_importance(kg, P, N, prim_index);
   }
 
-  /* to-do: need to handle a case when total importance is 0. */
   if (total_emitter_importance == 0.0f) {
     return -1;
   }



More information about the Bf-blender-cvs mailing list