diff --git a/PostProcessing/Editor Resources/Monitors/HistogramRender.shader b/PostProcessing/Editor Resources/Monitors/HistogramRender.shader index c69cf759..2bfdd7e7 100644 --- a/PostProcessing/Editor Resources/Monitors/HistogramRender.shader +++ b/PostProcessing/Editor Resources/Monitors/HistogramRender.shader @@ -8,7 +8,7 @@ Shader "Hidden/Post FX/Monitors/Histogram Render" CGINCLUDE #pragma fragmentoption ARB_precision_hint_fastest - #pragma target 5.0 + #pragma target 4.5 #include "UnityCG.cginc" StructuredBuffer _Histogram; diff --git a/PostProcessing/Editor Resources/Monitors/ParadeRender.shader b/PostProcessing/Editor Resources/Monitors/ParadeRender.shader index 3ff1ca65..d73a6a14 100644 --- a/PostProcessing/Editor Resources/Monitors/ParadeRender.shader +++ b/PostProcessing/Editor Resources/Monitors/ParadeRender.shader @@ -8,7 +8,7 @@ Shader "Hidden/Post FX/Monitors/Parade Render" CGINCLUDE #pragma fragmentoption ARB_precision_hint_fastest - #pragma target 5.0 + #pragma target 4.5 #include "UnityCG.cginc" StructuredBuffer _Waveform; diff --git a/PostProcessing/Editor Resources/Monitors/VectorscopeCompute.compute b/PostProcessing/Editor Resources/Monitors/VectorscopeCompute.compute index c5c61d0d..953edbea 100644 --- a/PostProcessing/Editor Resources/Monitors/VectorscopeCompute.compute +++ b/PostProcessing/Editor Resources/Monitors/VectorscopeCompute.compute @@ -8,7 +8,12 @@ CBUFFER_START (Params) float4 _Res; CBUFFER_END -#define GROUP_SIZE 32 +// Limited thread group size on MacOS with Metal (monitors are Editor-only so don't affect ios/Android limits) +#if defined SHADER_API_METAL + #define GROUP_SIZE 16 +#else + #define GROUP_SIZE 32 +#endif float3 RgbToYUV(float3 c) { diff --git a/PostProcessing/Editor Resources/Monitors/VectorscopeRender.shader b/PostProcessing/Editor Resources/Monitors/VectorscopeRender.shader index 62a7a037..e0a3648b 100644 --- a/PostProcessing/Editor Resources/Monitors/VectorscopeRender.shader +++ b/PostProcessing/Editor Resources/Monitors/VectorscopeRender.shader @@ -8,7 +8,7 @@ Shader "Hidden/Post FX/Monitors/Vectorscope Render" CGINCLUDE #pragma fragmentoption ARB_precision_hint_fastest - #pragma target 5.0 + #pragma target 4.5 #include "UnityCG.cginc" StructuredBuffer _Vectorscope; diff --git a/PostProcessing/Editor Resources/Monitors/WaveformCompute.compute b/PostProcessing/Editor Resources/Monitors/WaveformCompute.compute index cc79b153..fc37c99c 100644 --- a/PostProcessing/Editor Resources/Monitors/WaveformCompute.compute +++ b/PostProcessing/Editor Resources/Monitors/WaveformCompute.compute @@ -9,9 +9,15 @@ CBUFFER_START (Params) CBUFFER_END #define COLUMNS 384 +// Limited thread group size on MacOS with Metal (monitors are Editor-only so don't affect ios/Android limits) +#if defined SHADER_API_METAL + #define GROUP_SIZE COLUMNS / 2 +#else + #define GROUP_SIZE COLUMNS +#endif #pragma kernel KWaveform -[numthreads(1,COLUMNS,1)] +[numthreads(1,GROUP_SIZE,1)] void KWaveform(uint2 dispatchThreadId : SV_DispatchThreadID) { // We want a gamma corrected colors @@ -35,7 +41,7 @@ void KWaveform(uint2 dispatchThreadId : SV_DispatchThreadID) } #pragma kernel KWaveformClear -[numthreads(1, COLUMNS, 1)] +[numthreads(1, GROUP_SIZE, 1)] void KWaveformClear(uint2 dispatchThreadId : SV_DispatchThreadID) { _Waveform[dispatchThreadId.x * COLUMNS + dispatchThreadId.y] = uint4(0u, 0u, 0u, 0u); diff --git a/PostProcessing/Editor Resources/Monitors/WaveformRender.shader b/PostProcessing/Editor Resources/Monitors/WaveformRender.shader index 39cffd76..0961ae45 100644 --- a/PostProcessing/Editor Resources/Monitors/WaveformRender.shader +++ b/PostProcessing/Editor Resources/Monitors/WaveformRender.shader @@ -8,7 +8,7 @@ Shader "Hidden/Post FX/Monitors/Waveform Render" CGINCLUDE #pragma fragmentoption ARB_precision_hint_fastest - #pragma target 5.0 + #pragma target 4.5 #include "UnityCG.cginc" StructuredBuffer _Waveform; diff --git a/PostProcessing/Editor/Monitors/ParadeMonitor.cs b/PostProcessing/Editor/Monitors/ParadeMonitor.cs index 03494b10..bb2cd9f3 100644 --- a/PostProcessing/Editor/Monitors/ParadeMonitor.cs +++ b/PostProcessing/Editor/Monitors/ParadeMonitor.cs @@ -10,6 +10,7 @@ public class ParadeMonitor : PostProcessingMonitor ComputeShader m_ComputeShader; ComputeBuffer m_Buffer; + int m_ThreadGroupSize; Material m_Material; RenderTexture m_WaveformTexture; Rect m_MonitorAreaRect; @@ -17,6 +18,10 @@ public class ParadeMonitor : PostProcessingMonitor public ParadeMonitor() { m_ComputeShader = EditorResources.Load("Monitors/WaveformCompute.compute"); + + // Limited thread group size on MacOS with Metal (monitors are Editor-only so don't affect ios/Android limits) + bool isMacOSMetal = Application.platform == RuntimePlatform.OSXEditor && SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal; + m_ThreadGroupSize = isMacOSMetal ? 192 : 384; } public override void Dispose() @@ -226,14 +231,14 @@ void ComputeWaveform(RenderTexture source) int kernel = cs.FindKernel("KWaveformClear"); cs.SetBuffer(kernel, "_Waveform", m_Buffer); - cs.Dispatch(kernel, source.width, 1, 1); + cs.Dispatch(kernel, source.width, Mathf.CeilToInt(source.height / (float)m_ThreadGroupSize), 1); kernel = cs.FindKernel("KWaveform"); cs.SetBuffer(kernel, "_Waveform", m_Buffer); cs.SetTexture(kernel, "_Source", source); cs.SetInt("_IsLinear", GraphicsUtils.isLinearColorSpace ? 1 : 0); cs.SetVector("_Channels", channels); - cs.Dispatch(kernel, source.width, 1, 1); + cs.Dispatch(kernel, source.width, Mathf.CeilToInt(source.height / (float)m_ThreadGroupSize), 1); if (m_WaveformTexture == null || m_WaveformTexture.width != (source.width * 3) || m_WaveformTexture.height != source.height) { diff --git a/PostProcessing/Editor/Monitors/VectorscopeMonitor.cs b/PostProcessing/Editor/Monitors/VectorscopeMonitor.cs index 85145493..79f6aad3 100644 --- a/PostProcessing/Editor/Monitors/VectorscopeMonitor.cs +++ b/PostProcessing/Editor/Monitors/VectorscopeMonitor.cs @@ -10,6 +10,7 @@ public class VectorscopeMonitor : PostProcessingMonitor ComputeShader m_ComputeShader; ComputeBuffer m_Buffer; + int m_ThreadGroupSize; Material m_Material; RenderTexture m_VectorscopeTexture; Rect m_MonitorAreaRect; @@ -17,6 +18,10 @@ public class VectorscopeMonitor : PostProcessingMonitor public VectorscopeMonitor() { m_ComputeShader = EditorResources.Load("Monitors/VectorscopeCompute.compute"); + + // Limited thread group size on MacOS with Metal (monitors are Editor-only so don't affect ios/Android limits) + bool isMacOSMetal = Application.platform == RuntimePlatform.OSXEditor && SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal; + m_ThreadGroupSize = isMacOSMetal ? 16 : 32; } public override void Dispose() @@ -211,14 +216,14 @@ void ComputeVectorscope(RenderTexture source) int kernel = cs.FindKernel("KVectorscopeClear"); cs.SetBuffer(kernel, "_Vectorscope", m_Buffer); cs.SetVector("_Res", new Vector4(source.width, source.height, 0f, 0f)); - cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 32f), Mathf.CeilToInt(source.height / 32f), 1); + cs.Dispatch(kernel, Mathf.CeilToInt(source.width / (float)m_ThreadGroupSize), Mathf.CeilToInt(source.height / (float)m_ThreadGroupSize), 1); kernel = cs.FindKernel("KVectorscope"); cs.SetBuffer(kernel, "_Vectorscope", m_Buffer); cs.SetTexture(kernel, "_Source", source); cs.SetInt("_IsLinear", GraphicsUtils.isLinearColorSpace ? 1 : 0); cs.SetVector("_Res", new Vector4(source.width, source.height, 0f, 0f)); - cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 32f), Mathf.CeilToInt(source.height / 32f), 1); + cs.Dispatch(kernel, Mathf.CeilToInt(source.width / (float)m_ThreadGroupSize), Mathf.CeilToInt(source.height / (float)m_ThreadGroupSize), 1); if (m_VectorscopeTexture == null || m_VectorscopeTexture.width != source.width || m_VectorscopeTexture.height != source.height) { diff --git a/PostProcessing/Editor/Monitors/WaveformMonitor.cs b/PostProcessing/Editor/Monitors/WaveformMonitor.cs index 98d3f8eb..998fe7a7 100644 --- a/PostProcessing/Editor/Monitors/WaveformMonitor.cs +++ b/PostProcessing/Editor/Monitors/WaveformMonitor.cs @@ -10,6 +10,7 @@ public class WaveformMonitor : PostProcessingMonitor ComputeShader m_ComputeShader; ComputeBuffer m_Buffer; + int m_ThreadGroupSize; Material m_Material; RenderTexture m_WaveformTexture; Rect m_MonitorAreaRect; @@ -17,6 +18,10 @@ public class WaveformMonitor : PostProcessingMonitor public WaveformMonitor() { m_ComputeShader = EditorResources.Load("Monitors/WaveformCompute.compute"); + + // Limited thread group size on MacOS with Metal (monitors are Editor-only so don't affect ios/Android limits) + bool isMacOSMetal = Application.platform == RuntimePlatform.OSXEditor && SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal; + m_ThreadGroupSize = isMacOSMetal ? 192 : 384; } public override void Dispose() @@ -249,14 +254,14 @@ void ComputeWaveform(RenderTexture source) int kernel = cs.FindKernel("KWaveformClear"); cs.SetBuffer(kernel, "_Waveform", m_Buffer); - cs.Dispatch(kernel, source.width, 1, 1); + cs.Dispatch(kernel, source.width, Mathf.CeilToInt(source.height / (float)m_ThreadGroupSize), 1); kernel = cs.FindKernel("KWaveform"); cs.SetBuffer(kernel, "_Waveform", m_Buffer); cs.SetTexture(kernel, "_Source", source); cs.SetInt("_IsLinear", GraphicsUtils.isLinearColorSpace ? 1 : 0); cs.SetVector("_Channels", channels); - cs.Dispatch(kernel, source.width, 1, 1); + cs.Dispatch(kernel, source.width, Mathf.CeilToInt(source.height / (float)m_ThreadGroupSize), 1); if (m_WaveformTexture == null || m_WaveformTexture.width != source.width || m_WaveformTexture.height != source.height) { diff --git a/PostProcessing/Runtime/Utils/GraphicsUtils.cs b/PostProcessing/Runtime/Utils/GraphicsUtils.cs index 5e428c0c..64c46575 100644 --- a/PostProcessing/Runtime/Utils/GraphicsUtils.cs +++ b/PostProcessing/Runtime/Utils/GraphicsUtils.cs @@ -14,7 +14,7 @@ public static bool supportsDX11 #if UNITY_WEBGL get { return false; } #else - get { return SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders; } + get { return SystemInfo.graphicsShaderLevel >= 45 && SystemInfo.supportsComputeShaders; } #endif }