rasterizer_interface.h 5.3 KB

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