diff options
author | Jason Fielder <jason_apple> | 2022-04-14 12:47:52 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-04-14 12:49:18 +0300 |
commit | b0dc3aff2c73f2a1b65406dcb7fe73c95b9485ed (patch) | |
tree | 29642f7e85e2f5189549c1710854c421463a2e0d /source/blender/draw/intern | |
parent | d62f443f2d0b464131f77f770f9aa19d81164f0c (diff) |
Metal: GLSL shader compatibility 3rd pass
Undefined behaviour for divergent control-flow fixes, replacement for partial vector references, and resolution of a number of calculation precision issues occuring on macOS.
Authored by Apple: Michael Parkin-White
Ref: T96261
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D14437
Diffstat (limited to 'source/blender/draw/intern')
3 files changed, 33 insertions, 7 deletions
diff --git a/source/blender/draw/intern/shaders/common_hair_lib.glsl b/source/blender/draw/intern/shaders/common_hair_lib.glsl index 6a8f1132e1b..ff52b483d77 100644 --- a/source/blender/draw/intern/shaders/common_hair_lib.glsl +++ b/source/blender/draw/intern/shaders/common_hair_lib.glsl @@ -211,6 +211,11 @@ void hair_get_pos_tan_binor_time(bool is_persp, wpos += wbinor * thick_time * scale; } + else { + /* Note: Ensures 'hairThickTime' is initialised - + * avoids undefined behaviour on certain macOS configurations. */ + thick_time = 0.0; + } } float hair_get_customdata_float(const samplerBuffer cd_buf) diff --git a/source/blender/draw/intern/shaders/common_hair_refine_vert.glsl b/source/blender/draw/intern/shaders/common_hair_refine_vert.glsl index 371d43827b9..2eccae5bceb 100644 --- a/source/blender/draw/intern/shaders/common_hair_refine_vert.glsl +++ b/source/blender/draw/intern/shaders/common_hair_refine_vert.glsl @@ -18,7 +18,7 @@ void main(void) vec4 weights = hair_get_weights_cardinal(interp_time); finalColor = hair_interp_data(data0, data1, data2, data3, weights); -#ifdef TF_WORKAROUND +#if defined(TF_WORKAROUND) int id = gl_VertexID - idOffset; gl_Position.x = ((float(id % targetWidth) + 0.5) / float(targetWidth)) * 2.0 - 1.0; gl_Position.y = ((float(id / targetWidth) + 0.5) / float(targetHeight)) * 2.0 - 1.0; @@ -26,5 +26,10 @@ void main(void) gl_Position.w = 1.0; gl_PointSize = 1.0; +#else +# ifdef GPU_METAL + /* Metal still expects an output position for TF shaders. */ + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); +# endif #endif } diff --git a/source/blender/draw/intern/shaders/common_smaa_lib.glsl b/source/blender/draw/intern/shaders/common_smaa_lib.glsl index 73f65fb0799..dbc4c998b34 100644 --- a/source/blender/draw/intern/shaders/common_smaa_lib.glsl +++ b/source/blender/draw/intern/shaders/common_smaa_lib.glsl @@ -569,7 +569,7 @@ SamplerState PointSampler # define SMAAGather(tex, coord) tex.Gather(LinearSampler, coord, 0) # endif #endif -#if defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4) +#if defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4) || defined(GPU_METAL) # define SMAATexture2D(tex) sampler2D tex # define SMAATexturePass2D(tex) tex # define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) @@ -641,14 +641,14 @@ float2 SMAACalculatePredicatedThreshold(float2 texcoord, */ void SMAAMovc(bool2 cond, inout float2 variable, float2 value) { - SMAA_FLATTEN if (cond.x) variable.x = value.x; - SMAA_FLATTEN if (cond.y) variable.y = value.y; + /* Use select function (select(genType A, genType B, genBType cond)). */ + variable = select(variable, value, cond); } void SMAAMovc(bool4 cond, inout float4 variable, float4 value) { - SMAAMovc(cond.xy, variable.xy, value.xy); - SMAAMovc(cond.zw, variable.zw, value.zw); + /* Use select function (select(genType A, genType B, genBType cond)). */ + variable = select(variable, value, cond); } #if SMAA_INCLUDE_VS @@ -1281,7 +1281,15 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord, // Fix corners: coords.y = texcoord.y; - SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, d); + +# ifdef GPU_METAL + /* Partial vector references are unsupported in MSL. */ + vec2 _weights = weights.rg; + SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), _weights, coords.xyzy, d); + weights.rg = _weights; +# else + SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, d); +# endif # if !defined(SMAA_DISABLE_DIAG_DETECTION) } @@ -1324,7 +1332,15 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord, // Fix corners: coords.x = texcoord.x; + +# ifdef GPU_METAL + /* Partial vector references are unsupported in MSL. */ + vec2 _weights = weights.ba; + SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), _weights, coords.xyxz, d); + weights.ba = _weights; +# else SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, d); +# endif } return weights; |