Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RuntimeProfilerTests.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.TestTools;
  7. using UnityEngine.Rendering;
  8. using UnityEngine.SceneManagement;
  9. using NUnit.Framework;
  10. namespace UnityEngine.Rendering.Tests
  11. {
  12. class RuntimeProfilerTestBase
  13. {
  14. protected const int k_NumWarmupFrames = 10;
  15. protected const int k_NumFramesToRender = 30;
  16. protected DebugFrameTiming m_DebugFrameTiming;
  17. protected GameObject m_ToCleanup;
  18. [SetUp]
  19. public void Setup()
  20. {
  21. if (!FrameTimingManager.IsFeatureEnabled())
  22. Assert.Ignore("Frame timing stats are disabled in Player Settings, skipping test.");
  23. if (Application.isBatchMode)
  24. Assert.Ignore("Frame timing tests are not supported in batch mode, skipping test.");
  25. // HACK #1 - really shouldn't have to do this here, but previous tests are leaking gameobjects
  26. var objects = GameObject.FindObjectsByType<GameObject>(FindObjectsSortMode.InstanceID);
  27. foreach (var o in objects)
  28. {
  29. // HACK #2 - must not destroy DebugUpdater, which happens to have an EventSystem.
  30. if (o.GetComponent<EventSystem>() == null)
  31. CoreUtils.Destroy(o);
  32. }
  33. m_DebugFrameTiming = new DebugFrameTiming();
  34. }
  35. [TearDown]
  36. public void TearDown()
  37. {
  38. if (m_ToCleanup != null)
  39. CoreUtils.Destroy(m_ToCleanup);
  40. }
  41. protected IEnumerator Warmup()
  42. {
  43. for (int i = 0; i < k_NumWarmupFrames; i++)
  44. yield return null;
  45. m_DebugFrameTiming.Reset();
  46. }
  47. }
  48. // Fails on WebGL and Oculus Quest.
  49. // Unfortunately, there is no good way to exclude Oculus Quest from the test without excluding all Android devices.
  50. // https://jira.unity3d.com/browse/GFXFOUND-559
  51. [UnityPlatform(exclude = new RuntimePlatform[] { RuntimePlatform.WebGLPlayer, RuntimePlatform.Android })]
  52. class RuntimeProfilerTests : RuntimeProfilerTestBase
  53. {
  54. [UnityTest]
  55. public IEnumerator RuntimeProfilerGivesNonZeroOutput()
  56. {
  57. if ((Application.platform == RuntimePlatform.LinuxPlayer ||
  58. Application.platform == RuntimePlatform.LinuxEditor)
  59. && SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore)
  60. {
  61. Assert.Ignore("Test is failing on Linux OpenGLCore. https://jira.unity3d.com/browse/GFXFOUND-559");
  62. }
  63. yield return Warmup();
  64. m_ToCleanup = new GameObject();
  65. var camera = m_ToCleanup.AddComponent<Camera>();
  66. for (int i = 0; i < k_NumFramesToRender; i++)
  67. {
  68. m_DebugFrameTiming.UpdateFrameTiming();
  69. var rr = new UnityEngine.Rendering.RenderPipeline.StandardRequest();
  70. rr.destination = RenderTexture.GetTemporary(128, 128, 24, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_SRGB);
  71. rr.mipLevel = 0;
  72. rr.slice = 0;
  73. rr.face = CubemapFace.Unknown;
  74. UnityEngine.Rendering.RenderPipeline.SubmitRenderRequest(camera, rr);
  75. RenderTexture.ReleaseTemporary(rr.destination);
  76. yield return null;
  77. }
  78. Assert.True(
  79. m_DebugFrameTiming.m_BottleneckHistory.Histogram.Balanced > 0 ||
  80. m_DebugFrameTiming.m_BottleneckHistory.Histogram.CPU > 0 ||
  81. m_DebugFrameTiming.m_BottleneckHistory.Histogram.GPU > 0 ||
  82. m_DebugFrameTiming.m_BottleneckHistory.Histogram.PresentLimited > 0);
  83. }
  84. }
  85. }