VideoEvents.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2023 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <string_view>
  5. #include <vector>
  6. #include "Common/CommonTypes.h"
  7. #include "Common/HookableEvent.h"
  8. namespace Core
  9. {
  10. class System;
  11. }
  12. // Called when certain video config setting are changed
  13. using ConfigChangedEvent = Common::HookableEvent<"ConfigChanged", u32>;
  14. // An event called just before the first draw call of a frame
  15. using BeforeFrameEvent = Common::HookableEvent<"BeforeFrame">;
  16. // An event called after the frame XFB copy begins processing on the host GPU.
  17. // Useful for "once per frame" usecases.
  18. // Note: In a few rare cases, games do multiple XFB copies per frame and join them while presenting.
  19. // If this matters to your usecase, you should use BeforePresent instead.
  20. using AfterFrameEvent = Common::HookableEvent<"AfterFrame", Core::System&>;
  21. struct PresentInfo
  22. {
  23. enum class PresentReason
  24. {
  25. Immediate, // FIFO is Presenting the XFB immediately, straight after the XFB copy
  26. VideoInterface, // VideoInterface has triggered a present with a new frame
  27. VideoInterfaceDuplicate, // VideoInterface has triggered a present with a duplicate frame
  28. };
  29. // The number of (unique) frames since the emulated console booted
  30. u64 frame_count = 0;
  31. // The number of presents since the video backend was initialized.
  32. // never goes backwards.
  33. u64 present_count = 0;
  34. // The frame is identical to the previous frame
  35. PresentReason reason = PresentReason::Immediate;
  36. // The exact emulated time of the when real hardware would have presented this frame
  37. // FIXME: Immediate should predict the timestamp of this present
  38. u64 emulated_timestamp = 0;
  39. // TODO:
  40. // u64 intended_present_time = 0;
  41. // AfterPresent only: The actual time the frame was presented
  42. u64 actual_present_time = 0;
  43. enum class PresentTimeAccuracy
  44. {
  45. // The Driver/OS has given us an exact timestamp of when the first line of the frame started
  46. // scanning out to the monitor
  47. PresentOnScreenExact,
  48. // An approximate timestamp of scanout.
  49. PresentOnScreen,
  50. // Dolphin doesn't have visibility of the present time. But the present operation has
  51. // been queued with the GPU driver and will happen in the near future.
  52. PresentInProgress,
  53. // Not implemented
  54. Unimplemented,
  55. };
  56. // Accuracy of actual_present_time
  57. PresentTimeAccuracy present_time_accuracy = PresentTimeAccuracy::Unimplemented;
  58. std::vector<std::string_view> xfb_copy_hashes;
  59. };
  60. // An event called just as a frame is queued for presentation.
  61. // The exact timing of this event depends on the "Immediately Present XFB" option.
  62. //
  63. // If enabled, this event will trigger immediately after AfterFrame
  64. // If disabled, this event won't trigger until the emulated interface starts drawing out a new
  65. // frame.
  66. //
  67. // frame_count: The number of frames
  68. using BeforePresentEvent = Common::HookableEvent<"BeforePresent", PresentInfo&>;
  69. // An event that is triggered after a frame is presented.
  70. // The exact timing of this event depends on backend/driver support.
  71. using AfterPresentEvent = Common::HookableEvent<"AfterPresent", PresentInfo&>;
  72. // An end of frame event that runs on the CPU thread
  73. using VIEndFieldEvent = Common::HookableEvent<"VIEndField">;