Skip to content

Commit ab3734a

Browse files
jrs-unityEvergreen
authored andcommitted
Updated TemporalAA and STP to work with CoreCLR
1 parent 5409018 commit ab3734a

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/StpPostProcessPass.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal sealed class StpPostProcessPass : PostProcessPass
1212
public const string k_UpscaledColorTargetName = "CameraColorUpscaledSTP";
1313
Texture2D[] m_BlueNoise16LTex;
1414
bool m_IsValid;
15+
uint m_WarnCounter;
1516

1617
public StpPostProcessPass(Texture2D[] blueNoise16LTex)
1718
{
@@ -20,6 +21,8 @@ public StpPostProcessPass(Texture2D[] blueNoise16LTex)
2021
m_BlueNoise16LTex = blueNoise16LTex;
2122

2223
m_IsValid = m_BlueNoise16LTex != null && m_BlueNoise16LTex.Length > 0;
24+
25+
m_WarnCounter = 0;
2326
}
2427

2528
public override void Dispose()
@@ -52,7 +55,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
5255
{
5356
// Warn users if TAA and STP are disabled despite being requested
5457
if (cameraData.IsTemporalAARequested())
55-
TemporalAA.ValidateAndWarn(cameraData, isSTPRequested);
58+
TemporalAA.ValidateAndWarn(cameraData, ref m_WarnCounter, isSTPRequested);
5659
return;
5760
}
5861

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/TemporalAntiAliasingPostProcessPass.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal sealed class TemporalAntiAliasingPostProcessPass : PostProcessPass
1010

1111
Material m_Material;
1212
bool m_IsValid;
13+
uint m_WarnCounter;
1314

1415
public TemporalAntiAliasingPostProcessPass(Shader shader)
1516
{
@@ -18,6 +19,8 @@ public TemporalAntiAliasingPostProcessPass(Shader shader)
1819

1920
m_Material = PostProcessUtils.LoadShader(shader, passName);
2021
m_IsValid = m_Material != null;
22+
23+
m_WarnCounter = 0;
2124
}
2225

2326
public override void Dispose()
@@ -49,7 +52,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
4952
{
5053
// Warn users if TAA is disabled despite being requested
5154
if (cameraData.IsTemporalAARequested())
52-
TemporalAA.ValidateAndWarn(cameraData, false);
55+
TemporalAA.ValidateAndWarn(cameraData, ref m_WarnCounter, false);
5356
return;
5457
}
5558

Packages/com.unity.render-pipelines.universal/Runtime/StpUtils.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void PopulateStpConfig(UniversalCameraData cameraData, in TextureHandle i
113113
config.perViewConfigs = STP.perViewConfigs;
114114
}
115115

116-
static internal void Execute(RenderGraph renderGraph, UniversalResourceData resourceData, UniversalCameraData cameraData, in TextureHandle inputColor, in TextureHandle inputDepth, in TextureHandle inputMotion, in TextureHandle destination, Texture2D noiseTexture)
116+
internal static void Execute(RenderGraph renderGraph, UniversalResourceData resourceData, UniversalCameraData cameraData, in TextureHandle inputColor, in TextureHandle inputDepth, in TextureHandle inputMotion, in TextureHandle destination, Texture2D noiseTexture)
117117
{
118118
var debugView = TextureHandle.nullHandle;
119119
int debugViewIndex = 0;
@@ -141,5 +141,13 @@ static internal void Execute(RenderGraph renderGraph, UniversalResourceData reso
141141
PopulateStpConfig(cameraData, inputColor, inputDepth, inputMotion, debugViewIndex, debugView, destination, noiseTexture, out var config);
142142
STP.Execute(renderGraph, ref config);
143143
}
144+
145+
#if UNITY_EDITOR
146+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
147+
static void ResetStaticsOnLoad()
148+
{
149+
s_JitterFunc = CalculateJitter;
150+
}
151+
#endif
144152
}
145153
}

Packages/com.unity.render-pipelines.universal/Runtime/TemporalAA.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ internal static float[] CalculateFilterWeights(ref Settings settings)
291291
return taaFilterWeights;
292292
}
293293

294-
internal static GraphicsFormat[] AccumulationFormatList = new GraphicsFormat[]
294+
internal static readonly GraphicsFormat[] AccumulationFormatList = new GraphicsFormat[]
295295
{
296296
GraphicsFormat.R16G16B16A16_SFloat,
297297
GraphicsFormat.B10G11R11_UFloatPack32,
@@ -335,9 +335,7 @@ internal static RenderTextureDescriptor TemporalAADescFromCameraDesc(ref RenderT
335335
return taaDesc;
336336
}
337337

338-
static uint s_warnCounter = 0;
339-
340-
internal static string ValidateAndWarn(UniversalCameraData cameraData, bool isSTPRequested = false)
338+
internal static string ValidateAndWarn(UniversalCameraData cameraData, ref uint warnCounter, bool isSTPRequested = false)
341339
{
342340
string reasonWarning = null;
343341

@@ -375,9 +373,13 @@ internal static string ValidateAndWarn(UniversalCameraData cameraData, bool isST
375373
if (reasonWarning != null)
376374
{
377375
const int warningThrottleFrames = 60 * 1; // 60 FPS * 1 sec
378-
if (s_warnCounter % warningThrottleFrames == 0)
376+
if (warnCounter % warningThrottleFrames == 0)
379377
Debug.LogWarning("Disabling TAA " + (isSTPRequested ? "and STP " : "") + reasonWarning);
380-
s_warnCounter++;
378+
379+
unchecked
380+
{
381+
warnCounter++;
382+
}
381383
}
382384

383385
return reasonWarning;
@@ -529,5 +531,13 @@ internal static void Render(RenderGraph renderGraph, Material taaMaterial, Unive
529531
cameraData.taaHistory.SetAccumulationVersion(multipassId, Time.frameCount);
530532
}
531533
}
534+
535+
#if UNITY_EDITOR
536+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
537+
static void ResetStaticsOnLoad()
538+
{
539+
s_JitterFunc = CalculateJitter;
540+
}
541+
#endif
532542
}
533543
}

0 commit comments

Comments
 (0)