Skip to content

Commit 0df4e19

Browse files
ludovic-theobaldEvergreen
authored andcommitted
[VFX][Test] Make Ensure_Camera_Commands_Are_Culled test stable
1 parent c7e64bb commit 0df4e19

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

Tests/SRPTests/Packages/com.unity.testing.visualeffectgraph/Tests/Runtime/VFXCameraCullingTest.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ namespace UnityEngine.VFX.Test
1212
public class VFXCameraCullingTest
1313
{
1414
Recorder m_VFXSortRecorder;
15+
Recorder m_VFXProcessCameraRecorder;
1516
private const string kScenePath = "Packages/com.unity.testing.visualeffectgraph/Scenes/009_MultiCamera.unity";
1617
private const int kCameraVisibleCount = 4;
18+
private const int kCameraTotalCount = 6;
1719
//The camera command markers appear twice in the main thread
1820
//Once in the Render Pipeline preparation, once in the Render Context Submit.
1921
private const int kMarkerMultiplier = 2;
@@ -26,6 +28,9 @@ public void Init()
2628
m_VFXSortRecorder = Recorder.Get("VFX.SortBuffer");
2729
m_VFXSortRecorder.FilterToCurrentThread();
2830
m_VFXSortRecorder.enabled = false;
31+
m_VFXProcessCameraRecorder = Recorder.Get("VFX.ProcessCamera");
32+
m_VFXProcessCameraRecorder.FilterToCurrentThread();
33+
m_VFXProcessCameraRecorder.enabled = false;
2934
m_PreviousFrameRate = Application.targetFrameRate;
3035
Application.targetFrameRate = 30;
3136
}
@@ -37,7 +42,6 @@ public void Cleanup()
3742
}
3843

3944
[UnityTest]
40-
[Ignore("Unstable: https://jira.unity3d.com/browse/UUM-119807")]
4145
public IEnumerator Ensure_Camera_Commands_Are_Culled()
4246
{
4347
UnityEngine.SceneManagement.SceneManager.LoadScene(kScenePath);
@@ -46,6 +50,7 @@ public IEnumerator Ensure_Camera_Commands_Are_Culled()
4650
var vfxComponents = Resources.FindObjectsOfTypeAll<VisualEffect>();
4751

4852
m_VFXSortRecorder.enabled = true;
53+
m_VFXProcessCameraRecorder.enabled = true;
4954

5055
int maxFrame = 8;
5156
while (vfxComponents[^1].culled && maxFrame-- > 0)
@@ -54,17 +59,18 @@ public IEnumerator Ensure_Camera_Commands_Are_Culled()
5459
//Extra wait frame to ensure that the profiler recorder is ready
5560
yield return new WaitForEndOfFrame();
5661

57-
int totalSampleCount = 0;
62+
bool foundValidFrame = false;
5863
for (int i = 0; i < kWaitFrameCount; i++)
5964
{
60-
totalSampleCount += m_VFXSortRecorder.sampleBlockCount;
65+
if (m_VFXProcessCameraRecorder.sampleBlockCount == kCameraTotalCount * kMarkerMultiplier)
66+
{
67+
foundValidFrame = true;
68+
Assert.AreEqual(kCameraVisibleCount * kMarkerMultiplier, m_VFXSortRecorder.sampleBlockCount);
69+
break;
70+
}
6171
yield return new WaitForEndOfFrame();
6272
}
63-
64-
m_VFXSortRecorder.enabled = false;
65-
int averageSampleCount = Mathf.RoundToInt((float)totalSampleCount / kWaitFrameCount);
66-
67-
Assert.AreEqual(kCameraVisibleCount * kMarkerMultiplier, averageSampleCount);
73+
Assert.IsTrue(foundValidFrame, $"No valid frame with {kCameraTotalCount * kMarkerMultiplier} VFX.ProcessCamera markers could be found");
6874
}
6975
}
7076
}

0 commit comments

Comments
 (0)