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

V2 - Fix threadgroup size warning on MacOS Metal #591

Open
wants to merge 1 commit into
base: v2
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
5 changes: 4 additions & 1 deletion PostProcessing/Runtime/Effects/ColorGrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void RenderHDRPipeline3D(PostProcessRenderContext context)
}

int groupSizeXY = Mathf.CeilToInt(k_Lut3DSize / 8f);
int groupSizeZ = Mathf.CeilToInt(k_Lut3DSize / (RuntimeUtilities.isAndroidOpenGL ? 2f : 8f));
int groupSizeZ = Mathf.CeilToInt(k_Lut3DSize / (RuntimeUtilities.isAndroidOpenGL || RuntimeUtilities.isOSXMetal ? 2f : 8f));
var cmd = context.command;
cmd.SetComputeTextureParam(compute, kernel, "_Output", m_InternalLogLut);
cmd.SetComputeVectorParam(compute, "_Size", new Vector4(k_Lut3DSize, 1f / (k_Lut3DSize - 1f), 0f, 0f));
Expand Down Expand Up @@ -289,6 +289,9 @@ void RenderHDRPipeline3D(PostProcessRenderContext context)
}

// Generate the lut
uint tx, ty, tz = 0;
compute.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz);
//Debug.LogFormat("Size: {0} {1} {2}", tx, ty, tz);
context.command.BeginSample("HdrColorGradingLut3D");
cmd.DispatchCompute(compute, kernel, groupSizeXY, groupSizeXY, groupSizeZ);
context.command.EndSample("HdrColorGradingLut3D");
Expand Down
6 changes: 6 additions & 0 deletions PostProcessing/Runtime/Utils/RuntimeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ public static bool isAndroidOpenGL
get { return Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan; }
}

public static bool isOSXMetal
{
get { return Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer
&& SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal; }
}

public static RenderTextureFormat defaultHDRRenderTextureFormat
{
get
Expand Down
2 changes: 1 addition & 1 deletion PostProcessing/Runtime/Utils/TextureLerper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ internal Texture Lerp(Texture from, Texture to, float t)
m_Command.SetComputeTextureParam(compute, kernel, "_To", to);

int groupSizeXY = Mathf.CeilToInt(size / 8f);
int groupSizeZ = Mathf.CeilToInt(size / 8f);
int groupSizeZ = Mathf.CeilToInt(size / (RuntimeUtilities.isOSXMetal ? 2f : 8f));
m_Command.DispatchCompute(compute, kernel, groupSizeXY, groupSizeXY, groupSizeZ);
return rt;
}
Expand Down
2 changes: 1 addition & 1 deletion PostProcessing/Shaders/Builtins/Lut3DBaker.compute
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Eval(uint3 id)
}
}

#ifdef SHADER_API_GLES3
#if defined(SHADER_API_GLES3) || defined(SHADER_API_METAL)
#define GROUP_SIZE_XY 8
#define GROUP_SIZE_Z 2
#else
Expand Down
12 changes: 9 additions & 3 deletions PostProcessing/Shaders/Builtins/Texture3DLerp.compute
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ CBUFFER_END
Texture3D _From;
Texture3D _To;

#define GROUP_SIZE 8
#ifdef SHADER_API_METAL
#define GROUP_SIZE_XY 8
#define GROUP_SIZE_Z 2
#else
#define GROUP_SIZE_XY 8
#define GROUP_SIZE_Z 8
#endif

#ifdef DISABLE_COMPUTE_SHADERS

Expand All @@ -25,7 +31,7 @@ TRIVIAL_COMPUTE_KERNEL(KTexture3DLerpToColor)

#else

[numthreads(GROUP_SIZE, GROUP_SIZE, GROUP_SIZE)]
[numthreads(GROUP_SIZE_XY, GROUP_SIZE_XY, GROUP_SIZE_Z)]
void KTexture3DLerp(uint3 id : SV_DispatchThreadID)
{
if(all(float3(id) < _DimensionsAndLerp.xyz))
Expand All @@ -36,7 +42,7 @@ void KTexture3DLerp(uint3 id : SV_DispatchThreadID)
}
}

[numthreads(GROUP_SIZE, GROUP_SIZE, GROUP_SIZE)]
[numthreads(GROUP_SIZE_XY, GROUP_SIZE_XY, GROUP_SIZE_Z)]
void KTexture3DLerpToColor(uint3 id : SV_DispatchThreadID)
{
if(all(float3(id) < _DimensionsAndLerp.xyz))
Expand Down