[Bf-blender-cvs] [e28f07b5c89] master: Metal: GLSL shader compatibility 4th pass

Jason Fielder noreply at git.blender.org
Thu Apr 14 12:00:40 CEST 2022


Commit: e28f07b5c899a3036060e9e3f50a3e878663f02a
Author: Jason Fielder
Date:   Thu Apr 14 11:54:53 2022 +0200
Branches: master
https://developer.blender.org/rBe28f07b5c899a3036060e9e3f50a3e878663f02a

Metal: GLSL shader compatibility 4th pass

MSL follows C++ standard convention, and such variable declarations within switch statements must have their scope localised within each case. Adding braces in all cases ensures correct behaviour and avoids 'case ... bypass initialization of local variable' compilation error.

struct initialisation to follow C++ rules for Metal. Implicit constructors replaced with either explicit constructors or list-initialization where appropriate.

Ref T96261

Authored by Apple: Michael Parkin-White

Reviewed By: fclem

Maniphest Tasks: T96261

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

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

M	source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl
M	source/blender/draw/engines/eevee/shaders/closure_eval_diffuse_lib.glsl
M	source/blender/draw/engines/eevee/shaders/closure_eval_glossy_lib.glsl
M	source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl
M	source/blender/draw/engines/eevee/shaders/closure_eval_refraction_lib.glsl
M	source/blender/draw/engines/eevee/shaders/closure_eval_translucent_lib.glsl
M	source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl
M	source/blender/draw/engines/eevee/shaders/effect_dof_lib.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
M	source/blender/draw/engines/overlay/shaders/background_frag.glsl

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

diff --git a/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl b/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl
index 1c7ef775ac2..4da30dd74ee 100644
--- a/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl
@@ -40,6 +40,15 @@ struct OcclusionData {
   vec4 horizons;
   /* Custom large scale occlusion. */
   float custom_occlusion;
+
+#ifdef GPU_METAL
+  /* Constructors required for OcclusionData(..) syntax. */
+  inline OcclusionData() = default;
+  inline OcclusionData(vec4 in_horizons, float in_custom_occlusion)
+      : horizons(in_horizons), custom_occlusion(in_custom_occlusion)
+  {
+  }
+#endif
 };
 
 vec4 pack_occlusion_data(OcclusionData data)
diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_diffuse_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_diffuse_lib.glsl
index 5bf20fe6979..5cd82d298d5 100644
--- a/source/blender/draw/engines/eevee/shaders/closure_eval_diffuse_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/closure_eval_diffuse_lib.glsl
@@ -7,7 +7,15 @@ struct ClosureInputDiffuse {
   vec3 albedo; /** Used for multibounce GTAO approximation. Not applied to final radiance. */
 };
 
-#define CLOSURE_INPUT_Diffuse_DEFAULT ClosureInputDiffuse(vec3(0.0), vec3(0.0))
+#ifdef GPU_METAL
+/* C++ struct initialization. */
+#  define CLOSURE_INPUT_Diffuse_DEFAULT \
+    { \
+      vec3(0.0), vec3(0.0) \
+    }
+#else
+#  define CLOSURE_INPUT_Diffuse_DEFAULT ClosureInputDiffuse(vec3(0.0), vec3(0.0))
+#endif
 
 struct ClosureEvalDiffuse {
   vec3 probe_sampling_dir; /** Direction to sample probes from. */
diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_glossy_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_glossy_lib.glsl
index ddc6a0b9661..4271ac9105b 100644
--- a/source/blender/draw/engines/eevee/shaders/closure_eval_glossy_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/closure_eval_glossy_lib.glsl
@@ -10,7 +10,14 @@ struct ClosureInputGlossy {
   float roughness; /** Input roughness, not squared. */
 };
 
-#define CLOSURE_INPUT_Glossy_DEFAULT ClosureInputGlossy(vec3(0.0), 0.0)
+#ifdef GPU_METAL
+#  define CLOSURE_INPUT_Glossy_DEFAULT \
+    { \
+      vec3(0.0), 0.0 \
+    }
+#else
+#  define CLOSURE_INPUT_Glossy_DEFAULT ClosureInputGlossy(vec3(0.0), 0.0)
+#endif
 
 struct ClosureEvalGlossy {
   vec4 ltc_mat;            /** LTC matrix values. */
diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl
index 311887cf2f5..a96d8ad3dac 100644
--- a/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl
@@ -157,7 +157,15 @@
 #define ClosureInputDummy ClosureOutput
 #define ClosureOutputDummy ClosureOutput
 #define ClosureEvalDummy ClosureOutput
-#define CLOSURE_EVAL_DUMMY ClosureOutput(vec3(0))
+#ifdef GPU_METAL
+/* C++ struct initialization. */
+#  define CLOSURE_EVAL_DUMMY \
+    { \
+      vec3(0) \
+    }
+#else
+#  define CLOSURE_EVAL_DUMMY ClosureOutput(vec3(0))
+#endif
 #define CLOSURE_INPUT_Dummy_DEFAULT CLOSURE_EVAL_DUMMY
 #define closure_Dummy_eval_init(cl_in, cl_common, cl_out) CLOSURE_EVAL_DUMMY
 #define closure_Dummy_planar_eval(cl_in, cl_eval, cl_common, data, cl_out)
@@ -180,8 +188,15 @@ struct ClosureInputCommon {
   /** Custom occlusion value set by the user. */
   float occlusion;
 };
-
-#define CLOSURE_INPUT_COMMON_DEFAULT ClosureInputCommon(1.0)
+#ifdef GPU_METAL
+/* C++ struct initialization. */
+#  define CLOSURE_INPUT_COMMON_DEFAULT \
+    { \
+      1.0 \
+    }
+#else
+#  define CLOSURE_INPUT_COMMON_DEFAULT ClosureInputCommon(1.0)
+#endif
 
 struct ClosureEvalCommon {
   /** Result of SSAO. */
diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_refraction_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_refraction_lib.glsl
index 9011eea07c4..8129988920c 100644
--- a/source/blender/draw/engines/eevee/shaders/closure_eval_refraction_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/closure_eval_refraction_lib.glsl
@@ -10,8 +10,15 @@ struct ClosureInputRefraction {
   float roughness; /** Input roughness, not squared. */
   float ior;       /** Index of refraction ratio. */
 };
-
-#define CLOSURE_INPUT_Refraction_DEFAULT ClosureInputRefraction(vec3(0.0), 0.0, 0.0)
+#ifdef GPU_METAL
+/* C++ struct initialization. */
+#  define CLOSURE_INPUT_Refraction_DEFAULT \
+    { \
+      vec3(0.0), 0.0, 0.0 \
+    }
+#else
+#  define CLOSURE_INPUT_Refraction_DEFAULT ClosureInputRefraction(vec3(0.0), 0.0, 0.0)
+#endif
 
 struct ClosureEvalRefraction {
   vec3 P;                  /** LTC matrix values. */
diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_translucent_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_translucent_lib.glsl
index 183219c9088..706b75cb7f9 100644
--- a/source/blender/draw/engines/eevee/shaders/closure_eval_translucent_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/closure_eval_translucent_lib.glsl
@@ -7,9 +7,15 @@
 struct ClosureInputTranslucent {
   vec3 N; /** Shading normal. */
 };
-
-#define CLOSURE_INPUT_Translucent_DEFAULT ClosureInputTranslucent(vec3(0.0))
-
+#ifdef GPU_METAL
+/* C++ struct initialization. */
+#  define CLOSURE_INPUT_Translucent_DEFAULT \
+    { \
+      vec3(0.0) \
+    }
+#else
+#  define CLOSURE_INPUT_Translucent_DEFAULT ClosureInputTranslucent(vec3(0.0))
+#endif
 /* Stubs. */
 #define ClosureEvalTranslucent ClosureEvalDummy
 #define ClosureOutputTranslucent ClosureOutput
diff --git a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl
index fefc8743691..9022a9d3130 100644
--- a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl
@@ -30,6 +30,50 @@ struct Closure {
 #  endif
 
 #endif
+
+/* Metal Default Constructor - Requred for C++ constructor syntax. */
+#ifdef GPU_METAL
+  inline Closure() = default;
+#  ifdef VOLUMETRICS
+  /* Explicit Closure constructors -- To support GLSL syntax */
+  inline Closure(vec3 in_absorption, vec3 in_scatter, vec3 in_emission, float in_anisotropy)
+      : absorption(in_absorption),
+        scatter(in_scatter),
+        emission(in_emission),
+        anisotropy(in_anisotropy)
+  {
+  }
+#  else
+  /* Explicit Closure constructors -- To support GLSL syntax */
+  inline Closure(vec3 in_radiance,
+                 vec3 in_transmittance,
+                 float in_holdout,
+                 vec4 in_ssr_data,
+                 vec2 in_ssr_normal,
+                 int in_flag
+#    ifdef USE_SSS
+                 ,
+                 vec3 in_sss_irradiance,
+                 vec3 in_sss_albedo,
+                 float in_sss_radius
+#    endif /* USE_SSS */
+                 )
+      : radiance(in_radiance),
+        transmittance(in_transmittance),
+        holdout(in_holdout),
+        ssr_data(in_ssr_data),
+        ssr_normal(in_ssr_normal),
+        flag(in_flag)
+#    ifdef USE_SSS
+        ,
+        sss_irradiance(in_sss_irradiance),
+        sss_albedo(in_sss_albedo),
+        sss_radius(in_sss_radius)
+#    endif /* USE_SSS */
+  {
+  }
+#  endif   /* VOLUMETRICS */
+#endif     /* GPU_METAL */
 };
 
 #ifndef GPU_METAL
diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_lib.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_lib.glsl
index e288e1a55ea..9ed6ffa90c7 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_dof_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_dof_lib.glsl
@@ -334,7 +334,15 @@ struct DofGatherData {
   float layer_opacity;
 };
 
-#define GATHER_DATA_INIT DofGatherData(vec4(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
+#ifdef GPU_METAL
+/* C++ struct initialization. */
+#  define GATHER_DATA_INIT \
+    { \
+      vec4(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 \
+    }
+#else
+#  define GATHER_DATA_INIT DofGatherData(vec4(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
+#endif
 
 void dof_gather_ammend_weight(inout DofGatherData sample_data, float weight)
 {
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
index cf38c1fc12c..75bd3d30d68 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -116,7 +116,7 @@ void blend_mode_output(
       color.a *= opacity;
       frag_revealage = frag_color = clamp(1.0 / max(vec4(1e-6), 1.0 - color * color.a), 0.0, 1e18);
       break;
-    case MODE_HARDLIGHT:
+    case MODE_HARDLIGHT: {
       /* Reminder: Blending func is multiply blend (dst.rgba * src.rgba). */
       /**
        * We need to separate the overlay equation into 2 term (one mul and one add).
@@ -134,6 +134,7 @@ void blend_mode_output(
       frag_revealage = frag_color = 2.0 * s + 2.0 * color * (1.0 - s * 2.0);
       frag_revealage = max(vec4(0.0), frag_revealage);
       break;
+    }
     case MODE_HARDLIGHT_SECOND_PASS:
       /* Reminder: Blending func is additive blend (dst.rgba + src.rgba). */
       color = mix(vec4(0.5), color, color.a * opacity);
diff --git a/source/blender/draw/engines/overlay/shaders/background_frag.glsl b/source/blender/draw/engines/overlay/shaders/background_frag.glsl
index 19313c0415b..6b45b341ca4 100644
--- a/source/blender/draw/engines/overlay/shaders/background_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/background_frag.glsl
@@ -57,13 +57,13 @@ void main()
       /* XXX do interpolation in a non-linear space to have a better visual result. */
       col_high = pow(colorBackground.rgb, vec3(1.0 / 2.2));
       col_low = pow(colorBackgroundGradient.rgb, vec3(1.0 / 2.2));
-      bg_col = mix(col_low, col_high, uvcoordsvar.t);
+      bg_col = mix(col_low, col_high, uvcoordsvar.y);
       /* Convert back to linear. */
       bg_col = pow(bg_col, vec3(2.2));
       /*  Dither to hide low precision buffer. (Could be improved) */
  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list