rasterizer_interface.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <functional>
  6. #include <optional>
  7. #include <span>
  8. #include <stop_token>
  9. #include "common/common_types.h"
  10. #include "video_core/engines/fermi_2d.h"
  11. #include "video_core/gpu.h"
  12. #include "video_core/guest_driver.h"
  13. namespace Tegra {
  14. class MemoryManager;
  15. namespace Engines {
  16. class AccelerateDMAInterface;
  17. }
  18. } // namespace Tegra
  19. namespace VideoCore {
  20. enum class QueryType {
  21. SamplesPassed,
  22. };
  23. constexpr std::size_t NumQueryTypes = 1;
  24. enum class LoadCallbackStage {
  25. Prepare,
  26. Build,
  27. Complete,
  28. };
  29. using DiskResourceLoadCallback = std::function<void(LoadCallbackStage, std::size_t, std::size_t)>;
  30. class RasterizerInterface {
  31. public:
  32. virtual ~RasterizerInterface() = default;
  33. /// Dispatches a draw invocation
  34. virtual void Draw(bool is_indexed, bool is_instanced) = 0;
  35. /// Clear the current framebuffer
  36. virtual void Clear() = 0;
  37. /// Dispatches a compute shader invocation
  38. virtual void DispatchCompute(GPUVAddr code_addr) = 0;
  39. /// Resets the counter of a query
  40. virtual void ResetCounter(QueryType type) = 0;
  41. /// Records a GPU query and caches it
  42. virtual void Query(GPUVAddr gpu_addr, QueryType type, std::optional<u64> timestamp) = 0;
  43. /// Signal an uniform buffer binding
  44. virtual void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr,
  45. u32 size) = 0;
  46. /// Signal disabling of a uniform buffer
  47. virtual void DisableGraphicsUniformBuffer(size_t stage, u32 index) = 0;
  48. /// Signal a GPU based semaphore as a fence
  49. virtual void SignalSemaphore(GPUVAddr addr, u32 value) = 0;
  50. /// Signal a GPU based syncpoint as a fence
  51. virtual void SignalSyncPoint(u32 value) = 0;
  52. /// Signal a GPU based reference as point
  53. virtual void SignalReference() = 0;
  54. /// Release all pending fences.
  55. virtual void ReleaseFences() = 0;
  56. /// Notify rasterizer that all caches should be flushed to Switch memory
  57. virtual void FlushAll() = 0;
  58. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  59. virtual void FlushRegion(VAddr addr, u64 size) = 0;
  60. /// Check if the the specified memory area requires flushing to CPU Memory.
  61. virtual bool MustFlushRegion(VAddr addr, u64 size) = 0;
  62. /// Notify rasterizer that any caches of the specified region should be invalidated
  63. virtual void InvalidateRegion(VAddr addr, u64 size) = 0;
  64. /// Notify rasterizer that any caches of the specified region are desync with guest
  65. virtual void OnCPUWrite(VAddr addr, u64 size) = 0;
  66. /// Sync memory between guest and host.
  67. virtual void SyncGuestHost() = 0;
  68. /// Unmap memory range
  69. virtual void UnmapMemory(VAddr addr, u64 size) = 0;
  70. /// Remap GPU memory range. This means underneath backing memory changed
  71. virtual void ModifyGPUMemory(GPUVAddr addr, u64 size) = 0;
  72. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  73. /// and invalidated
  74. virtual void FlushAndInvalidateRegion(VAddr addr, u64 size) = 0;
  75. /// Notify the host renderer to wait for previous primitive and compute operations.
  76. virtual void WaitForIdle() = 0;
  77. /// Notify the host renderer to wait for reads and writes to render targets and flush caches.
  78. virtual void FragmentBarrier() = 0;
  79. /// Notify the host renderer to make available previous render target writes.
  80. virtual void TiledCacheBarrier() = 0;
  81. /// Notify the rasterizer to send all written commands to the host GPU.
  82. virtual void FlushCommands() = 0;
  83. /// Notify rasterizer that a frame is about to finish
  84. virtual void TickFrame() = 0;
  85. /// Attempt to use a faster method to perform a surface copy
  86. [[nodiscard]] virtual bool AccelerateSurfaceCopy(
  87. const Tegra::Engines::Fermi2D::Surface& src, const Tegra::Engines::Fermi2D::Surface& dst,
  88. const Tegra::Engines::Fermi2D::Config& copy_config) {
  89. return false;
  90. }
  91. [[nodiscard]] virtual Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() = 0;
  92. /// Attempt to use a faster method to display the framebuffer to screen
  93. [[nodiscard]] virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config,
  94. VAddr framebuffer_addr, u32 pixel_stride) {
  95. return false;
  96. }
  97. /// Increase/decrease the number of object in pages touching the specified region
  98. virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
  99. /// Initialize disk cached resources for the game being emulated
  100. virtual void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
  101. const DiskResourceLoadCallback& callback) {}
  102. /// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
  103. [[nodiscard]] GuestDriverProfile& AccessGuestDriverProfile() {
  104. return guest_driver_profile;
  105. }
  106. /// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
  107. [[nodiscard]] const GuestDriverProfile& AccessGuestDriverProfile() const {
  108. return guest_driver_profile;
  109. }
  110. private:
  111. GuestDriverProfile guest_driver_profile{};
  112. };
  113. } // namespace VideoCore