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

Commit 01bd4d8

Browse files
committed
Cleanup
1 parent d31420b commit 01bd4d8

7 files changed

Lines changed: 67 additions & 60 deletions

File tree

PostProcessing/Runtime/Effects/ColorGrading.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,8 @@ void RenderHDRPipeline(PostProcessRenderContext context)
224224
break;
225225
}
226226

227-
bool isAndroidOpenGL = Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan;
228227
int groupSizeXY = Mathf.CeilToInt(k_Lut3DSize / 8f);
229-
int groupSizeZ = Mathf.CeilToInt(k_Lut3DSize / (isAndroidOpenGL ? 2f : 8f));
228+
int groupSizeZ = Mathf.CeilToInt(k_Lut3DSize / (RuntimeUtilities.isAndroidOpenGL ? 2f : 8f));
230229
var cmd = context.command;
231230
cmd.SetComputeTextureParam(compute, kernel, "_Output", m_InternalLogLut);
232231
cmd.SetComputeVectorParam(compute, "_Size", new Vector4(k_Lut3DSize, 1f / (k_Lut3DSize - 1f), 0f, 0f));

PostProcessing/Runtime/Monitors/HistogramMonitor.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ public enum Channel
1818
public Channel channel = Channel.Master;
1919

2020
ComputeBuffer m_Data;
21-
private int numBins;
22-
private int threadGroupSizeX;
23-
private int threadGroupSizeY;
21+
int m_NumBins;
22+
int m_ThreadGroupSizeX;
23+
int m_ThreadGroupSizeY;
2424

2525
internal override void OnEnable()
2626
{
27-
base.OnEnable();
28-
29-
bool isAndroidOpenGL = Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan;
30-
31-
numBins = isAndroidOpenGL ? 128 : 256;
32-
threadGroupSizeX = isAndroidOpenGL ? 16 : 16;
33-
threadGroupSizeY = isAndroidOpenGL ? 8 : 16;
27+
m_ThreadGroupSizeX = 16;
28+
29+
if (RuntimeUtilities.isAndroidOpenGL)
30+
{
31+
m_NumBins = 128;
32+
m_ThreadGroupSizeY = 8;
33+
}
34+
else
35+
{
36+
m_NumBins = 256;
37+
m_ThreadGroupSizeY = 16;
38+
}
3439
}
3540

3641
internal override void OnDisable()
@@ -53,7 +58,7 @@ internal override void Render(PostProcessRenderContext context)
5358
CheckOutput(width, height);
5459

5560
if (m_Data == null)
56-
m_Data = new ComputeBuffer(numBins, sizeof(uint));
61+
m_Data = new ComputeBuffer(m_NumBins, sizeof(uint));
5762

5863
var compute = context.resources.computeShaders.gammaHistogram;
5964
var cmd = context.command;
@@ -62,7 +67,7 @@ internal override void Render(PostProcessRenderContext context)
6267
// Clear the buffer on every frame as we use it to accumulate values on every frame
6368
int kernel = compute.FindKernel("KHistogramClear");
6469
cmd.SetComputeBufferParam(compute, kernel, "_HistogramBuffer", m_Data);
65-
cmd.DispatchCompute(compute, kernel, Mathf.CeilToInt(numBins / (float)threadGroupSizeX), 1, 1);
70+
cmd.DispatchCompute(compute, kernel, Mathf.CeilToInt(m_NumBins / (float)m_ThreadGroupSizeX), 1, 1);
6671

6772
// Gather all pixels and fill in our histogram
6873
kernel = compute.FindKernel("KHistogramGather");
@@ -77,8 +82,8 @@ internal override void Render(PostProcessRenderContext context)
7782
cmd.SetComputeTextureParam(compute, kernel, "_Source", ShaderIDs.HalfResFinalCopy);
7883
cmd.SetComputeBufferParam(compute, kernel, "_HistogramBuffer", m_Data);
7984
cmd.DispatchCompute(compute, kernel,
80-
Mathf.CeilToInt(parameters.x / threadGroupSizeX),
81-
Mathf.CeilToInt(parameters.y / threadGroupSizeY),
85+
Mathf.CeilToInt(parameters.x / m_ThreadGroupSizeX),
86+
Mathf.CeilToInt(parameters.y / m_ThreadGroupSizeY),
8287
1
8388
);
8489

PostProcessing/Runtime/Monitors/VectorscopeMonitor.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace UnityEngine.Rendering.PostProcessing
44
{
@@ -9,8 +9,14 @@ public sealed class VectorscopeMonitor : Monitor
99
public float exposure = 0.12f;
1010

1111
ComputeBuffer m_Data;
12-
private int threadGroupSizeX;
13-
private int threadGroupSizeY;
12+
int m_ThreadGroupSizeX;
13+
int m_ThreadGroupSizeY;
14+
15+
internal override void OnEnable()
16+
{
17+
m_ThreadGroupSizeX = 16;
18+
m_ThreadGroupSizeY = RuntimeUtilities.isAndroidOpenGL ? 8 : 16;
19+
}
1420

1521
internal override void OnDisable()
1622
{
@@ -21,16 +27,6 @@ internal override void OnDisable()
2127

2228
m_Data = null;
2329
}
24-
25-
internal override void OnEnable()
26-
{
27-
base.OnEnable();
28-
29-
bool isAndroidOpenGL = Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan;
30-
31-
threadGroupSizeX = isAndroidOpenGL ? 16 : 16;
32-
threadGroupSizeY = isAndroidOpenGL ? 8 : 16;
33-
}
3430

3531
internal override bool NeedsHalfRes()
3632
{
@@ -67,8 +63,8 @@ internal override void Render(PostProcessRenderContext context)
6763
cmd.SetComputeBufferParam(compute, kernel, "_VectorscopeBuffer", m_Data);
6864
cmd.SetComputeVectorParam(compute, "_Params", parameters);
6965
cmd.DispatchCompute(compute, kernel,
70-
Mathf.CeilToInt(size / (float)threadGroupSizeX),
71-
Mathf.CeilToInt(size / (float)threadGroupSizeY),
66+
Mathf.CeilToInt(size / (float)m_ThreadGroupSizeX),
67+
Mathf.CeilToInt(size / (float)m_ThreadGroupSizeY),
7268
1
7369
);
7470

@@ -77,8 +73,8 @@ internal override void Render(PostProcessRenderContext context)
7773
cmd.SetComputeBufferParam(compute, kernel, "_VectorscopeBuffer", m_Data);
7874
cmd.SetComputeTextureParam(compute, kernel, "_Source", ShaderIDs.HalfResFinalCopy);
7975
cmd.DispatchCompute(compute, kernel,
80-
Mathf.CeilToInt(parameters.x / threadGroupSizeX),
81-
Mathf.CeilToInt(parameters.y / threadGroupSizeY),
76+
Mathf.CeilToInt(parameters.x / m_ThreadGroupSizeX),
77+
Mathf.CeilToInt(parameters.y / m_ThreadGroupSizeY),
8278
1
8379
);
8480

PostProcessing/Runtime/Monitors/WaveformMonitor.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,25 @@ public sealed class WaveformMonitor : Monitor
1010

1111
ComputeBuffer m_Data;
1212

13-
private int threadGroupSize;
14-
private int threadGroupSizeX;
15-
private int threadGroupSizeY;
13+
int m_ThreadGroupSize;
14+
int m_ThreadGroupSizeX;
15+
int m_ThreadGroupSizeY;
16+
17+
internal override void OnEnable()
18+
{
19+
m_ThreadGroupSizeX = 16;
20+
21+
if (RuntimeUtilities.isAndroidOpenGL)
22+
{
23+
m_ThreadGroupSize = 128;
24+
m_ThreadGroupSizeY = 8;
25+
}
26+
else
27+
{
28+
m_ThreadGroupSize = 256;
29+
m_ThreadGroupSizeY = 16;
30+
}
31+
}
1632

1733
internal override void OnDisable()
1834
{
@@ -24,17 +40,6 @@ internal override void OnDisable()
2440
m_Data = null;
2541
}
2642

27-
internal override void OnEnable()
28-
{
29-
base.OnEnable();
30-
31-
bool isAndroidOpenGL = Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan;
32-
33-
threadGroupSize = isAndroidOpenGL ? 128 : 256;
34-
threadGroupSizeX = isAndroidOpenGL ? 16 : 16;
35-
threadGroupSizeY = isAndroidOpenGL ? 8 : 16;
36-
}
37-
3843
internal override bool NeedsHalfRes()
3944
{
4045
return true;
@@ -75,7 +80,7 @@ internal override void Render(PostProcessRenderContext context)
7580
int kernel = compute.FindKernel("KWaveformClear");
7681
cmd.SetComputeBufferParam(compute, kernel, "_WaveformBuffer", m_Data);
7782
cmd.SetComputeVectorParam(compute, "_Params", parameters);
78-
cmd.DispatchCompute(compute, kernel, Mathf.CeilToInt(width / (float)threadGroupSizeX), Mathf.CeilToInt(height / (float)threadGroupSizeY), 1);
83+
cmd.DispatchCompute(compute, kernel, Mathf.CeilToInt(width / (float)m_ThreadGroupSizeX), Mathf.CeilToInt(height / (float)m_ThreadGroupSizeY), 1);
7984

8085
// For performance reasons, especially on consoles, we'll just downscale the source
8186
// again to reduce VMEM stalls. Eventually the whole algorithm needs to be rewritten as
@@ -88,7 +93,7 @@ internal override void Render(PostProcessRenderContext context)
8893
cmd.SetComputeBufferParam(compute, kernel, "_WaveformBuffer", m_Data);
8994
cmd.SetComputeTextureParam(compute, kernel, "_Source", ShaderIDs.WaveformSource);
9095
cmd.SetComputeVectorParam(compute, "_Params", parameters);
91-
cmd.DispatchCompute(compute, kernel, width, Mathf.CeilToInt(height / (float)threadGroupSize), 1);
96+
cmd.DispatchCompute(compute, kernel, width, Mathf.CeilToInt(height / (float)m_ThreadGroupSize), 1);
9297
cmd.ReleaseTemporaryRT(ShaderIDs.WaveformSource);
9398

9499
// Generate the waveform texture

PostProcessing/Runtime/Utils/LogHistogram.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ public sealed class LogHistogram
77

88
// Don't forget to update 'ExposureHistogram.hlsl' if you change these values !
99
const int k_Bins = 128;
10-
int threadX;
11-
int threadY;
10+
int m_ThreadX;
11+
int m_ThreadY;
1212

1313
public ComputeBuffer data { get; private set; }
1414

1515
public void Generate(PostProcessRenderContext context)
1616
{
1717
if (data == null)
1818
{
19-
bool isAndroidOpenGL = Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan;
20-
threadX = isAndroidOpenGL ? 16 : 16;
21-
threadY = isAndroidOpenGL ? 8 : 16;
19+
m_ThreadX = 16;
20+
m_ThreadY = RuntimeUtilities.isAndroidOpenGL ? 8 : 16;
2221
data = new ComputeBuffer (k_Bins, sizeof(uint));
2322
}
2423

@@ -30,16 +29,16 @@ public void Generate(PostProcessRenderContext context)
3029
// Clear the buffer on every frame as we use it to accumulate luminance values on each frame
3130
int kernel = compute.FindKernel("KEyeHistogramClear");
3231
cmd.SetComputeBufferParam(compute, kernel, "_HistogramBuffer", data);
33-
cmd.DispatchCompute(compute, kernel, Mathf.CeilToInt(k_Bins / (float)threadX), 1, 1);
32+
cmd.DispatchCompute(compute, kernel, Mathf.CeilToInt(k_Bins / (float)m_ThreadX), 1, 1);
3433

3534
// Get a log histogram
3635
kernel = compute.FindKernel("KEyeHistogram");
3736
cmd.SetComputeBufferParam(compute, kernel, "_HistogramBuffer", data);
3837
cmd.SetComputeTextureParam(compute, kernel, "_Source", context.source);
3938
cmd.SetComputeVectorParam(compute, "_ScaleOffsetRes", scaleOffsetRes);
4039
cmd.DispatchCompute(compute, kernel,
41-
Mathf.CeilToInt(scaleOffsetRes.z / (float)threadX),
42-
Mathf.CeilToInt(scaleOffsetRes.w / (float)threadY),
40+
Mathf.CeilToInt(scaleOffsetRes.z / (float)m_ThreadX),
41+
Mathf.CeilToInt(scaleOffsetRes.w / (float)m_ThreadY),
4342
1
4443
);
4544

PostProcessing/Runtime/Utils/RuntimeUtilities.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ public static bool isVREnabled
251251
}
252252
}
253253

254+
public static bool isAndroidOpenGL
255+
{
256+
get { return Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan; }
257+
}
258+
254259
public static void Destroy(UnityObject obj)
255260
{
256261
if (obj != null)

PostProcessing/Runtime/Utils/TextureLerper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ internal Texture Lerp(Texture from, Texture to, float t)
107107

108108
RenderTexture rt = null;
109109

110-
bool isAndroidOpenGL = Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan;
111-
112110
if (is3d)
113111
{
114112
int size = to.width;
@@ -122,7 +120,7 @@ internal Texture Lerp(Texture from, Texture to, float t)
122120
m_Command.SetComputeTextureParam(compute, kernel, "_To", to);
123121

124122
int groupSizeXY = Mathf.CeilToInt(size / 8f);
125-
int groupSizeZ = Mathf.CeilToInt(size / (isAndroidOpenGL ? 2f : 8f));
123+
int groupSizeZ = Mathf.CeilToInt(size / (RuntimeUtilities.isAndroidOpenGL ? 2f : 8f));
126124
m_Command.DispatchCompute(compute, kernel, groupSizeXY, groupSizeXY, groupSizeZ);
127125
}
128126
else

0 commit comments

Comments
 (0)