rasterizer_interface.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <atomic>
  6. #include <functional>
  7. #include <optional>
  8. #include "common/common_types.h"
  9. #include "video_core/engines/fermi_2d.h"
  10. #include "video_core/gpu.h"
  11. #include "video_core/guest_driver.h"
  12. namespace Tegra {
  13. class MemoryManager;
  14. }
  15. namespace VideoCore {
  16. enum class QueryType {
  17. SamplesPassed,
  18. };
  19. constexpr std::size_t NumQueryTypes = 1;
  20. enum class LoadCallbackStage {
  21. Prepare,
  22. Build,
  23. Complete,
  24. };
  25. using DiskResourceLoadCallback = std::function<void(LoadCallbackStage, std::size_t, std::size_t)>;
  26. class RasterizerInterface {
  27. public:
  28. virtual ~RasterizerInterface() = default;
  29. /// Dispatches a draw invocation
  30. virtual void Draw(bool is_indexed, bool is_instanced) = 0;
  31. /// Clear the current framebuffer
  32. virtual void Clear() = 0;
  33. /// Dispatches a compute shader invocation
  34. virtual void DispatchCompute(GPUVAddr code_addr) = 0;
  35. /// Resets the counter of a query
  36. virtual void ResetCounter(QueryType type) = 0;
  37. /// Records a GPU query and caches it
  38. virtual void Query(GPUVAddr gpu_addr, QueryType type, std::optional<u64> timestamp) = 0;
  39. /// Signal a GPU based semaphore as a fence
  40. virtual void SignalSemaphore(GPUVAddr addr, u32 value) = 0;
  41. /// Signal a GPU based syncpoint as a fence
  42. virtual void SignalSyncPoint(u32 value) = 0;
  43. /// Release all pending fences.
  44. virtual void ReleaseFences() = 0;
  45. /// Notify rasterizer that all caches should be flushed to Switch memory
  46. virtual void FlushAll() = 0;
  47. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  48. virtual void FlushRegion(VAddr addr, u64 size) = 0;
  49. /// Check if the the specified memory area requires flushing to CPU Memory.
  50. virtual bool MustFlushRegion(VAddr addr, u64 size) = 0;
  51. /// Notify rasterizer that any caches of the specified region should be invalidated
  52. virtual void InvalidateRegion(VAddr addr, u64 size) = 0;
  53. /// Notify rasterizer that any caches of the specified region are desync with guest
  54. virtual void OnCPUWrite(VAddr addr, u64 size) = 0;
  55. /// Sync memory between guest and host.
  56. virtual void SyncGuestHost() = 0;
  57. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  58. /// and invalidated
  59. virtual void FlushAndInvalidateRegion(VAddr addr, u64 size) = 0;
  60. /// Notify the host renderer to wait for previous primitive and compute operations.
  61. virtual void WaitForIdle() = 0;
  62. /// Notify the rasterizer to send all written commands to the host GPU.
  63. virtual void FlushCommands() = 0;
  64. /// Notify rasterizer that a frame is about to finish
  65. virtual void TickFrame() = 0;
  66. /// Attempt to use a faster method to perform a surface copy
  67. [[nodiscard]] virtual bool AccelerateSurfaceCopy(
  68. const Tegra::Engines::Fermi2D::Regs::Surface& src,
  69. const Tegra::Engines::Fermi2D::Regs::Surface& dst,
  70. const Tegra::Engines::Fermi2D::Config& copy_config) {
  71. return false;
  72. }
  73. /// Attempt to use a faster method to display the framebuffer to screen
  74. [[nodiscard]] virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config,
  75. VAddr framebuffer_addr, u32 pixel_stride) {
  76. return false;
  77. }
  78. /// Increase/decrease the number of object in pages touching the specified region
  79. virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
  80. /// Initialize disk cached resources for the game being emulated
  81. virtual void LoadDiskResources(u64 title_id, const std::atomic_bool& stop_loading,
  82. const DiskResourceLoadCallback& callback) {}
  83. /// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
  84. [[nodiscard]] GuestDriverProfile& AccessGuestDriverProfile() {
  85. return guest_driver_profile;
  86. }
  87. /// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
  88. [[nodiscard]] const GuestDriverProfile& AccessGuestDriverProfile() const {
  89. return guest_driver_profile;
  90. }
  91. private:
  92. GuestDriverProfile guest_driver_profile{};
  93. };
  94. } // namespace VideoCore