rasterizer_interface.h 4.8 KB

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