Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Support v1 monitors on MacOS with Metal #382

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint4> _Histogram;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint4> _Waveform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint> _Vectorscope;
Expand Down
10 changes: 8 additions & 2 deletions PostProcessing/Editor Resources/Monitors/WaveformCompute.compute
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint4> _Waveform;
Expand Down
9 changes: 7 additions & 2 deletions PostProcessing/Editor/Monitors/ParadeMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ public class ParadeMonitor : PostProcessingMonitor

ComputeShader m_ComputeShader;
ComputeBuffer m_Buffer;
int m_ThreadGroupSize;
Material m_Material;
RenderTexture m_WaveformTexture;
Rect m_MonitorAreaRect;

public ParadeMonitor()
{
m_ComputeShader = EditorResources.Load<ComputeShader>("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()
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 7 additions & 2 deletions PostProcessing/Editor/Monitors/VectorscopeMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ public class VectorscopeMonitor : PostProcessingMonitor

ComputeShader m_ComputeShader;
ComputeBuffer m_Buffer;
int m_ThreadGroupSize;
Material m_Material;
RenderTexture m_VectorscopeTexture;
Rect m_MonitorAreaRect;

public VectorscopeMonitor()
{
m_ComputeShader = EditorResources.Load<ComputeShader>("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()
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 7 additions & 2 deletions PostProcessing/Editor/Monitors/WaveformMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ public class WaveformMonitor : PostProcessingMonitor

ComputeShader m_ComputeShader;
ComputeBuffer m_Buffer;
int m_ThreadGroupSize;
Material m_Material;
RenderTexture m_WaveformTexture;
Rect m_MonitorAreaRect;

public WaveformMonitor()
{
m_ComputeShader = EditorResources.Load<ComputeShader>("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()
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion PostProcessing/Runtime/Utils/GraphicsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down