[Bf-blender-cvs] [619250f7f1d] principled-v2: Attempt to fix Metal compilation issues

Lukas Stockner noreply at git.blender.org
Mon Oct 31 20:17:02 CET 2022


Commit: 619250f7f1de9358461881a02327cd5e7b8f8754
Author: Lukas Stockner
Date:   Mon Oct 31 20:16:42 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB619250f7f1de9358461881a02327cd5e7b8f8754

Attempt to fix Metal compilation issues

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

M	intern/cycles/kernel/closure/bsdf_microfacet.h
M	intern/cycles/kernel/closure/bsdf_microfacet_glass.h
M	intern/cycles/kernel/closure/bsdf_microfacet_util.h
M	intern/cycles/kernel/closure/bsdf_principled_sheen.h
M	intern/cycles/kernel/closure/bsdf_util.h
M	intern/cycles/kernel/svm/closure_principled.h
M	intern/cycles/util/math_float2.h
M	intern/cycles/util/math_float3.h

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

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 13729df2985..8e4e4345a14 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -60,7 +60,7 @@ ccl_device_forceinline Spectrum reflection_color(ccl_private const MicrofacetBsd
     return make_spectrum(f);
   }
   else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID) {
-    MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
+    ccl_private MicrofacetExtrav2 *extra = (ccl_private MicrofacetExtrav2 *)bsdf->extra;
     Spectrum F = zero_spectrum();
     float cosHL = dot(H, L);
 
@@ -173,7 +173,7 @@ ccl_device int bsdf_microfacet_ggx_fresnel_v2_setup(KernelGlobals kg,
   bsdf->alpha_x = saturatef(bsdf->alpha_x);
   bsdf->alpha_y = saturatef(bsdf->alpha_y);
 
-  MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
+  ccl_private MicrofacetExtrav2 *extra = (ccl_private MicrofacetExtrav2 *)bsdf->extra;
 
   if (metallic > 0.0f) {
     Spectrum metal_Fss = fresnel_metallic_Fss(extra->metal_base, extra->metal_edge_factor);
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 160a9a8b76c..ad986eb15a6 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -68,7 +68,7 @@ ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(KernelGlobals kg,
 
 ccl_device_inline Spectrum glass_fresnel(ccl_private const MicrofacetBsdf *bsdf,
                                          float cosTheta,
-                                         float *reflect_pdf)
+                                         ccl_private float *reflect_pdf)
 {
   if (bsdf->T.x > 0.0f) {
     Spectrum F = fresnel_dielectric_thin_film(cosTheta, bsdf->ior, bsdf->T.y, bsdf->T.x);
@@ -155,7 +155,7 @@ ccl_device Spectrum bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Mi
   float reflect_pdf;
   Spectrum F = glass_fresnel(bsdf, cosMO, &reflect_pdf);
 
-  if (F == one_spectrum()) {
+  if (is_one(F)) {
     /* TIR */
     *pdf = 0.0f;
     return zero_spectrum();
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index 4a41155b3f7..661a8e87d33 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -162,7 +162,7 @@ ccl_device_inline float dielectric_fresnel_Fss(float eta)
  */
 
 ccl_device_inline void fresnel_dielectric_complex(
-    float cosTheta1, float eta1, float eta2, float2 *R, float2 *phi)
+    float cosTheta1, float eta1, float eta2, ccl_private float2 *R, ccl_private float2 *phi)
 {
 
   float sinTheta1Sqr = 1.0f - sqr(cosTheta1);
diff --git a/intern/cycles/kernel/closure/bsdf_principled_sheen.h b/intern/cycles/kernel/closure/bsdf_principled_sheen.h
index 949a6f8f567..6374c86d010 100644
--- a/intern/cycles/kernel/closure/bsdf_principled_sheen.h
+++ b/intern/cycles/kernel/closure/bsdf_principled_sheen.h
@@ -73,7 +73,7 @@ ccl_device_inline float sheen_v2_lambda(float mu, float w)
 }
 
 ccl_device_inline Spectrum
-sheen_v2_eval(float3 N, float3 V, float3 L, float3 H, float r, float *pdf)
+sheen_v2_eval(float3 N, float3 V, float3 L, float3 H, float r, ccl_private float *pdf)
 {
   float cosNH = dot(N, H), cosNV = dot(N, V), cosNL = dot(N, L);
 
diff --git a/intern/cycles/kernel/closure/bsdf_util.h b/intern/cycles/kernel/closure/bsdf_util.h
index 47a37a43c87..b1c5a9375dd 100644
--- a/intern/cycles/kernel/closure/bsdf_util.h
+++ b/intern/cycles/kernel/closure/bsdf_util.h
@@ -105,7 +105,7 @@ ccl_device float schlick_fresnel(float u)
  */
 ccl_device Spectrum metallic_edge_factor(Spectrum F0, Spectrum F82)
 {
-  if (F82 == one_spectrum()) {
+  if (is_one(F82)) {
     return zero_spectrum();
   }
 
diff --git a/intern/cycles/kernel/svm/closure_principled.h b/intern/cycles/kernel/svm/closure_principled.h
index 115d4aff12d..db1d850f5a2 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycles/kernel/svm/closure_principled.h
@@ -499,7 +499,7 @@ ccl_device_inline Spectrum principled_v2_clearcoat(KernelGlobals kg,
 
   float3 N = stack_valid(normal_offset) ? stack_load_float3(stack, normal_offset) : sd->N;
   Spectrum tint = saturate(rgb_to_spectrum(stack_load_float3(stack, tint_offset)));
-  if (tint != one_spectrum()) {
+  if (!is_one(tint)) {
     /* Tint is normalized to perpendicular incidence.
      * Therefore, if we define the coating thickness as length 1, the length along the ray is
      * t = sqrt(1+tan^2(angle(N, I))) = sqrt(1+tan^2(acos(dotNI))) = 1 / dotNI.
@@ -649,7 +649,7 @@ ccl_device_inline float principled_v2_specular(KernelGlobals kg,
   bsdf->N = N;
   bsdf->ior = ior;
   bsdf->T = T;
-  bsdf->extra = (MicrofacetExtra *)extra;
+  bsdf->extra = (ccl_private MicrofacetExtra *)extra;
 
   bsdf->alpha_x = sqr(roughness) / aspect;
   bsdf->alpha_y = sqr(roughness) * aspect;
@@ -704,7 +704,7 @@ ccl_device void svm_node_closure_principled_v2(KernelGlobals kg,
                                                uint4 node_2,
                                                float mix_weight,
                                                int path_flag,
-                                               int *offset)
+                                               ccl_private int *offset)
 {
   Spectrum weight = sd->svm_closure_weight * mix_weight;
 
@@ -756,7 +756,7 @@ ccl_device void svm_node_closure_principled(KernelGlobals kg,
                                             uint4 node_2,
                                             float mix_weight,
                                             int path_flag,
-                                            int *offset)
+                                            ccl_private int *offset)
 {
   /* Load distribution type. */
   uint packed_distribution, dummy;
diff --git a/intern/cycles/util/math_float2.h b/intern/cycles/util/math_float2.h
index ab0f3f9f16e..60686561f9b 100644
--- a/intern/cycles/util/math_float2.h
+++ b/intern/cycles/util/math_float2.h
@@ -36,7 +36,6 @@ ccl_device_inline bool operator==(const float2 &a, const float2 &b);
 ccl_device_inline bool operator!=(const float2 &a, const float2 &b);
 
 ccl_device_inline bool is_zero(const float2 &a);
-ccl_device_inline float average(const float2 &a);
 ccl_device_inline float distance(const float2 &a, const float2 &b);
 ccl_device_inline float dot(const float2 &a, const float2 &b);
 ccl_device_inline float cross(const float2 &a, const float2 &b);
@@ -52,11 +51,12 @@ ccl_device_inline float2 fabs(const float2 &a);
 ccl_device_inline float2 as_float2(const float4 &a);
 ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t);
 ccl_device_inline float2 floor(const float2 &a);
-ccl_device_inline float2 sqr(const float2 &a);
 ccl_device_inline float2 sqrt(const float2 &a);
 #endif /* !__KERNEL_METAL__ */
 
 ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b);
+ccl_device_inline float2 sqr(const float2 &a);
+ccl_device_inline float average(const float2 &a);
 
 /*******************************************************************************
  * Definition.
@@ -170,11 +170,6 @@ ccl_device_inline bool is_zero(const float2 &a)
   return (a.x == 0.0f && a.y == 0.0f);
 }
 
-ccl_device_inline float average(const float2 &a)
-{
-  return (a.x + a.y) * (1.0f / 2.0f);
-}
-
 ccl_device_inline float distance(const float2 &a, const float2 &b)
 {
   return len(a - b);
@@ -232,11 +227,6 @@ ccl_device_inline float2 as_float2(const float4 &a)
   return make_float2(a.x, a.y);
 }
 
-ccl_device_inline float2 sqr(const float2 &a)
-{
-  return a * a;
-}
-
 ccl_device_inline float2 sqrt(const float2 &a)
 {
   return make_float2(sqrtf(a.x), sqrtf(a.y));
@@ -274,6 +264,16 @@ ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b)
   return (b != 0.0f) ? a / b : zero_float2();
 }
 
+ccl_device_inline float average(const float2 &a)
+{
+  return (a.x + a.y) * (1.0f / 2.0f);
+}
+
+ccl_device_inline float2 sqr(const float2 &a)
+{
+  return a * a;
+}
+
 CCL_NAMESPACE_END
 
 #endif /* __UTIL_MATH_FLOAT2_H__ */
diff --git a/intern/cycles/util/math_float3.h b/intern/cycles/util/math_float3.h
index eec7122b9dc..e43c80761f3 100644
--- a/intern/cycles/util/math_float3.h
+++ b/intern/cycles/util/math_float3.h
@@ -69,6 +69,7 @@ ccl_device_inline float3 interp(float3 a, float3 b, float t);
 ccl_device_inline float3 sqr(float3 a);
 
 ccl_device_inline bool is_zero(const float3 a);
+ccl_device_inline bool is_one(const float3 a);
 ccl_device_inline float reduce_add(const float3 a);
 ccl_device_inline float average(const float3 a);
 ccl_device_inline bool isequal(const float3 a, const float3 b);
@@ -505,6 +506,15 @@ ccl_device_inline bool is_zero(const float3 a)
 #endif
 }
 
+ccl_device_inline bool is_one(const float3 a)
+{
+#ifdef __KERNEL_SSE__
+  return a == make_float3(1.0f);
+#else
+  return (a.x == 1.0f && a.y == 1.0f && a.z == 1.0f);
+#endif
+}
+
 ccl_device_inline float reduce_add(const float3 a)
 {
 #if defined(__KERNEL_SSE__) && defined(__KERNEL_NEON__)



More information about the Bf-blender-cvs mailing list