rasterizer_interface.h 5.9 KB

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