rasterizer_interface.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <functional>
  5. #include <optional>
  6. #include <span>
  7. #include <utility>
  8. #include "common/common_types.h"
  9. #include "common/polyfill_thread.h"
  10. #include "video_core/cache_types.h"
  11. #include "video_core/engines/fermi_2d.h"
  12. #include "video_core/gpu.h"
  13. #include "video_core/rasterizer_download_area.h"
  14. namespace Tegra {
  15. class MemoryManager;
  16. namespace Engines {
  17. class AccelerateDMAInterface;
  18. }
  19. namespace Control {
  20. struct ChannelState;
  21. }
  22. } // namespace Tegra
  23. namespace VideoCore {
  24. enum class QueryType {
  25. SamplesPassed,
  26. };
  27. constexpr std::size_t NumQueryTypes = 1;
  28. enum class LoadCallbackStage {
  29. Prepare,
  30. Build,
  31. Complete,
  32. };
  33. using DiskResourceLoadCallback = std::function<void(LoadCallbackStage, std::size_t, std::size_t)>;
  34. class RasterizerInterface {
  35. public:
  36. virtual ~RasterizerInterface() = default;
  37. /// Dispatches a draw invocation
  38. virtual void Draw(bool is_indexed, u32 instance_count) = 0;
  39. /// Dispatches an indirect draw invocation
  40. virtual void DrawIndirect() {}
  41. /// Dispatches an draw texture invocation
  42. virtual void DrawTexture() = 0;
  43. /// Clear the current framebuffer
  44. virtual void Clear(u32 layer_count) = 0;
  45. /// Dispatches a compute shader invocation
  46. virtual void DispatchCompute() = 0;
  47. /// Resets the counter of a query
  48. virtual void ResetCounter(QueryType type) = 0;
  49. /// Records a GPU query and caches it
  50. virtual void Query(GPUVAddr gpu_addr, QueryType type, std::optional<u64> timestamp) = 0;
  51. /// Signal an uniform buffer binding
  52. virtual void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr,
  53. u32 size) = 0;
  54. /// Signal disabling of a uniform buffer
  55. virtual void DisableGraphicsUniformBuffer(size_t stage, u32 index) = 0;
  56. /// Signal a GPU based semaphore as a fence
  57. virtual void SignalFence(std::function<void()>&& func) = 0;
  58. /// Send an operation to be done after a certain amount of flushes.
  59. virtual void SyncOperation(std::function<void()>&& func) = 0;
  60. /// Signal a GPU based syncpoint as a fence
  61. virtual void SignalSyncPoint(u32 value) = 0;
  62. /// Signal a GPU based reference as point
  63. virtual void SignalReference() = 0;
  64. /// Release all pending fences.
  65. virtual void ReleaseFences() = 0;
  66. /// Notify rasterizer that all caches should be flushed to Switch memory
  67. virtual void FlushAll() = 0;
  68. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  69. virtual void FlushRegion(VAddr addr, u64 size,
  70. VideoCommon::CacheType which = VideoCommon::CacheType::All) = 0;
  71. /// Check if the the specified memory area requires flushing to CPU Memory.
  72. virtual bool MustFlushRegion(VAddr addr, u64 size,
  73. VideoCommon::CacheType which = VideoCommon::CacheType::All) = 0;
  74. virtual RasterizerDownloadArea GetFlushArea(VAddr addr, u64 size) = 0;
  75. /// Notify rasterizer that any caches of the specified region should be invalidated
  76. virtual void InvalidateRegion(VAddr addr, u64 size,
  77. VideoCommon::CacheType which = VideoCommon::CacheType::All) = 0;
  78. virtual void InnerInvalidation(std::span<const std::pair<VAddr, std::size_t>> sequences) {
  79. for (const auto& [cpu_addr, size] : sequences) {
  80. InvalidateRegion(cpu_addr, size);
  81. }
  82. }
  83. /// Notify rasterizer that any caches of the specified region are desync with guest
  84. virtual void OnCacheInvalidation(VAddr addr, u64 size) = 0;
  85. virtual bool OnCPUWrite(VAddr addr, u64 size) = 0;
  86. /// Sync memory between guest and host.
  87. virtual void InvalidateGPUCache() = 0;
  88. /// Unmap memory range
  89. virtual void UnmapMemory(VAddr addr, u64 size) = 0;
  90. /// Remap GPU memory range. This means underneath backing memory changed
  91. virtual void ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) = 0;
  92. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  93. /// and invalidated
  94. virtual void FlushAndInvalidateRegion(
  95. VAddr addr, u64 size, VideoCommon::CacheType which = VideoCommon::CacheType::All) = 0;
  96. /// Notify the host renderer to wait for previous primitive and compute operations.
  97. virtual void WaitForIdle() = 0;
  98. /// Notify the host renderer to wait for reads and writes to render targets and flush caches.
  99. virtual void FragmentBarrier() = 0;
  100. /// Notify the host renderer to make available previous render target writes.
  101. virtual void TiledCacheBarrier() = 0;
  102. /// Notify the rasterizer to send all written commands to the host GPU.
  103. virtual void FlushCommands() = 0;
  104. /// Notify rasterizer that a frame is about to finish
  105. virtual void TickFrame() = 0;
  106. virtual bool AccelerateConditionalRendering() {
  107. return false;
  108. }
  109. /// Attempt to use a faster method to perform a surface copy
  110. [[nodiscard]] virtual bool AccelerateSurfaceCopy(
  111. const Tegra::Engines::Fermi2D::Surface& src, const Tegra::Engines::Fermi2D::Surface& dst,
  112. const Tegra::Engines::Fermi2D::Config& copy_config) {
  113. return false;
  114. }
  115. [[nodiscard]] virtual Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() = 0;
  116. virtual void AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
  117. std::span<const u8> memory) = 0;
  118. /// Attempt to use a faster method to display the framebuffer to screen
  119. [[nodiscard]] virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config,
  120. VAddr framebuffer_addr, u32 pixel_stride) {
  121. return false;
  122. }
  123. /// Increase/decrease the number of object in pages touching the specified region
  124. virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
  125. /// Initialize disk cached resources for the game being emulated
  126. virtual void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
  127. const DiskResourceLoadCallback& callback) {}
  128. virtual void InitializeChannel(Tegra::Control::ChannelState& channel) {}
  129. virtual void BindChannel(Tegra::Control::ChannelState& channel) {}
  130. virtual void ReleaseChannel(s32 channel_id) {}
  131. };
  132. } // namespace VideoCore