hydra_GPUTest_AtomFeatureIntegrationBenchmark.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import azlmbr.legacy.general as general
  7. from editor_python_test_tools.editor_test_helper import EditorTestHelper
  8. from Atom.atom_utils.benchmark_utils import BenchmarkHelper
  9. SCREEN_WIDTH = 1280
  10. SCREEN_HEIGHT = 720
  11. DEGREE_RADIAN_FACTOR = 0.0174533
  12. helper = EditorTestHelper(log_prefix="Test_Atom_BasicLevelSetup")
  13. def run():
  14. """
  15. 1. View -> Layouts -> Restore Default Layout, sets the viewport to ratio 16:9 @ 1280 x 720
  16. 2. Runs console command r_DisplayInfo = 0
  17. 3. Opens AtomFeatureIntegrationBenchmark level
  18. 4. Initializes benchmark helper with benchmark name to capture benchmark metadata.
  19. 5. Idles for 100 frames, then collects pass timings for 100 frames.
  20. :return: None
  21. """
  22. def initial_viewport_setup(screen_width, screen_height):
  23. general.set_viewport_size(screen_width, screen_height)
  24. general.update_viewport()
  25. helper.wait_for_condition(
  26. function=lambda: helper.isclose(a=general.get_viewport_size().x, b=SCREEN_WIDTH, rel_tol=0.1)
  27. and helper.isclose(a=general.get_viewport_size().y, b=SCREEN_HEIGHT, rel_tol=0.1),
  28. timeout_in_seconds=4.0
  29. )
  30. result = helper.isclose(a=general.get_viewport_size().x, b=SCREEN_WIDTH, rel_tol=0.1) and helper.isclose(
  31. a=general.get_viewport_size().y, b=SCREEN_HEIGHT, rel_tol=0.1)
  32. general.log(general.get_viewport_size().x)
  33. general.log(general.get_viewport_size().y)
  34. general.log(general.get_viewport_size().z)
  35. general.log(f"Viewport is set to the expected size: {result}")
  36. general.run_console("r_DisplayInfo = 0")
  37. def after_level_load():
  38. """Function to call after creating/opening a level to ensure it loads."""
  39. # Give everything a second to initialize.
  40. general.idle_enable(True)
  41. general.idle_wait(1.0)
  42. general.update_viewport()
  43. general.idle_wait(0.5) # half a second is more than enough for updating the viewport.
  44. # Close out problematic windows, FPS meters, and anti-aliasing.
  45. if general.is_helpers_shown(): # Turn off the helper gizmos if visible
  46. general.toggle_helpers()
  47. general.idle_wait(1.0)
  48. if general.is_pane_visible("Error Report"): # Close Error Report windows that block focus.
  49. general.close_pane("Error Report")
  50. if general.is_pane_visible("Error Log"): # Close Error Log windows that block focus.
  51. general.close_pane("Error Log")
  52. general.idle_wait(1.0)
  53. general.run_console("r_displayInfo=0")
  54. general.idle_wait(1.0)
  55. return True
  56. # Wait for Editor idle loop before executing Python hydra scripts.
  57. general.idle_enable(True)
  58. general.open_level_no_prompt("AtomFeatureIntegrationBenchmark")
  59. # Basic setup after opening level.
  60. after_level_load()
  61. initial_viewport_setup(SCREEN_WIDTH, SCREEN_HEIGHT)
  62. general.enter_game_mode()
  63. general.idle_wait(1.0)
  64. helper.wait_for_condition(function=lambda: general.is_in_game_mode(), timeout_in_seconds=2.0)
  65. benchmarker = BenchmarkHelper("AtomFeatureIntegrationBenchmark")
  66. benchmarker.capture_benchmark_metadata()
  67. general.idle_wait_frames(100)
  68. for i in range(1, 101):
  69. benchmarker.capture_pass_timestamp(i)
  70. benchmarker.capture_cpu_frame_time(i)
  71. general.exit_game_mode()
  72. helper.wait_for_condition(function=lambda: not general.is_in_game_mode(), timeout_in_seconds=2.0)
  73. if __name__ == "__main__":
  74. run()