[Bf-blender-cvs] [c2dc65dfa4a] master: Fix Cycles HIP compiler error for some architectures even with light tree off

Brecht Van Lommel noreply at git.blender.org
Wed Dec 7 19:56:57 CET 2022


Commit: c2dc65dfa4ae60fa5d2c3b0cfe86f99dcb5bf16f
Author: Brecht Van Lommel
Date:   Wed Dec 7 17:45:33 2022 +0100
Branches: master
https://developer.blender.org/rBc2dc65dfa4ae60fa5d2c3b0cfe86f99dcb5bf16f

Fix Cycles HIP compiler error for some architectures even with light tree off

Revert some refactoring that is not strictly necessary and causes issues for
unknown reasons.

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

M	intern/cycles/kernel/light/distribution.h
M	intern/cycles/kernel/light/sample.h
M	intern/cycles/kernel/light/tree.h

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

diff --git a/intern/cycles/kernel/light/distribution.h b/intern/cycles/kernel/light/distribution.h
index 8afc15757db..45d6811d521 100644
--- a/intern/cycles/kernel/light/distribution.h
+++ b/intern/cycles/kernel/light/distribution.h
@@ -11,7 +11,7 @@ CCL_NAMESPACE_BEGIN
 /* Simple CDF based sampling over all lights in the scene, without taking into
  * account shading position or normal. */
 
-ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float &randu)
+ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *randu)
 {
   /* This is basically std::upper_bound as used by PBRT, to find a point light or
    * triangle to emit from, proportional to area. a good improvement would be to
@@ -19,7 +19,7 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float &ra
    * arbitrary shaders. */
   int first = 0;
   int len = kernel_data.integrator.num_distribution + 1;
-  float r = randu;
+  float r = *randu;
 
   do {
     int half_len = len >> 1;
@@ -42,32 +42,55 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float &ra
    * each area light be stratified as well. */
   float distr_min = kernel_data_fetch(light_distribution, index).totarea;
   float distr_max = kernel_data_fetch(light_distribution, index + 1).totarea;
-  randu = (r - distr_min) / (distr_max - distr_min);
+  *randu = (r - distr_min) / (distr_max - distr_min);
 
   return index;
 }
 
+template<bool in_volume_segment>
 ccl_device_noinline bool light_distribution_sample(KernelGlobals kg,
-                                                   ccl_private float &randu,
+                                                   float randu,
                                                    const float randv,
                                                    const float time,
                                                    const float3 P,
                                                    const int bounce,
                                                    const uint32_t path_flag,
-                                                   ccl_private int &emitter_object,
-                                                   ccl_private int &emitter_prim,
-                                                   ccl_private int &emitter_shader_flag,
-                                                   ccl_private float &emitter_pdf_selection)
+                                                   ccl_private LightSample *ls)
 {
   /* Sample light index from distribution. */
-  const int index = light_distribution_sample(kg, randu);
+  const int index = light_distribution_sample(kg, &randu);
   ccl_global const KernelLightDistribution *kdistribution = &kernel_data_fetch(light_distribution,
                                                                                index);
+  const int prim = kdistribution->prim;
 
-  emitter_object = kdistribution->mesh_light.object_id;
-  emitter_prim = kdistribution->prim;
-  emitter_shader_flag = kdistribution->mesh_light.shader_flag;
-  emitter_pdf_selection = kernel_data.integrator.distribution_pdf_lights;
+  if (prim >= 0) {
+    /* Mesh light. */
+    const int object = kdistribution->mesh_light.object_id;
+
+    /* Exclude synthetic meshes from shadow catcher pass. */
+    if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) &&
+        !(kernel_data_fetch(object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) {
+      return false;
+    }
+
+    const int shader_flag = kdistribution->mesh_light.shader_flag;
+    triangle_light_sample<in_volume_segment>(kg, prim, object, randu, randv, time, ls, P);
+    ls->shader |= shader_flag;
+    return (ls->pdf > 0.0f);
+  }
+
+  const int lamp = -prim - 1;
+
+  if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) {
+    return false;
+  }
+
+  if (!light_sample<in_volume_segment>(kg, lamp, randu, randv, P, path_flag, ls)) {
+    return false;
+  }
+
+  ls->pdf_selection = kernel_data.integrator.distribution_pdf_lights;
+  ls->pdf *= ls->pdf_selection;
 
   return true;
 }
diff --git a/intern/cycles/kernel/light/sample.h b/intern/cycles/kernel/light/sample.h
index 6a5219c3ae9..8dfaf329e43 100644
--- a/intern/cycles/kernel/light/sample.h
+++ b/intern/cycles/kernel/light/sample.h
@@ -325,7 +325,7 @@ ccl_device_inline float light_sample_mis_weight_nee(KernelGlobals kg,
 
 ccl_device_inline bool light_sample_from_volume_segment(KernelGlobals kg,
                                                         float randu,
-                                                        float randv,
+                                                        const float randv,
                                                         const float time,
                                                         const float3 P,
                                                         const float3 D,
@@ -334,89 +334,22 @@ ccl_device_inline bool light_sample_from_volume_segment(KernelGlobals kg,
                                                         const uint32_t path_flag,
                                                         ccl_private LightSample *ls)
 {
-  /* Select an emitter. */
-  int emitter_object = 0;
-  int emitter_prim = 0;
-  int emitter_shader_flag = 0;
-  float emitter_pdf_selection = 0.0f;
-
 #ifdef __LIGHT_TREE__
   if (kernel_data.integrator.use_light_tree) {
-    if (!light_tree_sample<true>(kg,
-                                 randu,
-                                 randv,
-                                 time,
-                                 P,
-                                 D,
-                                 t,
-                                 SD_BSDF_HAS_TRANSMISSION,
-                                 bounce,
-                                 path_flag,
-                                 emitter_object,
-                                 emitter_prim,
-                                 emitter_shader_flag,
-                                 emitter_pdf_selection)) {
-      return false;
-    }
+    return light_tree_sample<true>(
+        kg, randu, randv, time, P, D, t, SD_BSDF_HAS_TRANSMISSION, bounce, path_flag, ls);
   }
   else
 #endif
   {
-    if (!light_distribution_sample(kg,
-                                   randu,
-                                   randv,
-                                   time,
-                                   P,
-                                   bounce,
-                                   path_flag,
-                                   emitter_object,
-                                   emitter_prim,
-                                   emitter_shader_flag,
-                                   emitter_pdf_selection)) {
-      return false;
-    }
-  }
-
-  /* Set first, triangle light sampling from flat distribution will override. */
-  ls->pdf_selection = emitter_pdf_selection;
-
-  /* Sample a point on the chosen emitter. */
-  if (emitter_prim >= 0) {
-    /* Mesh light. */
-    /* Exclude synthetic meshes from shadow catcher pass. */
-    if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) &&
-        !(kernel_data_fetch(object_flag, emitter_object) & SD_OBJECT_SHADOW_CATCHER)) {
-      return false;
-    }
-
-    if (!triangle_light_sample<true>(
-            kg, emitter_prim, emitter_object, randu, randv, time, ls, P)) {
-      return false;
-    }
-  }
-  else {
-    /* Light object. */
-    const int lamp = ~emitter_prim;
-
-    if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) {
-      return false;
-    }
-
-    if (!light_sample<true>(kg, lamp, randu, randv, P, path_flag, ls)) {
-      return false;
-    }
+    return light_distribution_sample<true>(kg, randu, randv, time, P, bounce, path_flag, ls);
   }
-
-  ls->pdf *= ls->pdf_selection;
-  ls->shader |= emitter_shader_flag;
-
-  return (ls->pdf > 0);
 }
 
 ccl_device bool light_sample_from_position(KernelGlobals kg,
                                            ccl_private const RNGState *rng_state,
-                                           float randu,
-                                           float randv,
+                                           const float randu,
+                                           const float randv,
                                            const float time,
                                            const float3 P,
                                            const float3 N,
@@ -425,84 +358,16 @@ ccl_device bool light_sample_from_position(KernelGlobals kg,
                                            const uint32_t path_flag,
                                            ccl_private LightSample *ls)
 {
-  /* Select an emitter. */
-  int emitter_object = 0;
-  int emitter_prim = 0;
-  int emitter_shader_flag = 0;
-  float emitter_pdf_selection = 0.0f;
-
 #ifdef __LIGHT_TREE__
   if (kernel_data.integrator.use_light_tree) {
-    if (!light_tree_sample<false>(kg,
-                                  randu,
-                                  randv,
-                                  time,
-                                  P,
-                                  N,
-                                  0,
-                                  shader_flags,
-                                  bounce,
-                                  path_flag,
-                                  emitter_object,
-                                  emitter_prim,
-                                  emitter_shader_flag,
-                                  emitter_pdf_selection)) {
-      return false;
-    }
+    return light_tree_sample<false>(
+        kg, randu, randv, time, P, N, 0, shader_flags, bounce, path_flag, ls);
   }
   else
 #endif
   {
-    if (!light_distribution_sample(kg,
-                                   randu,
-                                   randv,
-                                   time,
-                                   P,
-                                   bounce,
-                                   path_flag,
-                                   emitter_object,
-                                   emitter_prim,
-                                   emitter_shader_flag,
-                                   emitter_pdf_selection)) {
-      return false;
-    }
-  }
-
-  /* Set first, triangle light sa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list