rasterizer_interface.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <atomic>
  6. #include <functional>
  7. #include <optional>
  8. #include "common/common_types.h"
  9. #include "video_core/engines/fermi_2d.h"
  10. #include "video_core/gpu.h"
  11. #include "video_core/guest_driver.h"
  12. namespace Tegra {
  13. class MemoryManager;
  14. }
  15. namespace VideoCore {
  16. enum class QueryType {
  17. SamplesPassed,
  18. };
  19. constexpr std::size_t NumQueryTypes = 1;
  20. enum class LoadCallbackStage {
  21. Prepare,
  22. Build,
  23. Complete,
  24. };
  25. using DiskResourceLoadCallback = std::function<void(LoadCallbackStage, std::size_t, std::size_t)>;
  26. class RasterizerInterface {
  27. public:
  28. virtual ~RasterizerInterface() {}
  29. /// Dispatches a draw invocation
  30. virtual void Draw(bool is_indexed, bool is_instanced) = 0;
  31. /// Clear the current framebuffer
  32. virtual void Clear() = 0;
  33. /// Dispatches a compute shader invocation
  34. virtual void DispatchCompute(GPUVAddr code_addr) = 0;
  35. /// Resets the counter of a query
  36. virtual void ResetCounter(QueryType type) = 0;
  37. /// Records a GPU query and caches it
  38. virtual void Query(GPUVAddr gpu_addr, QueryType type, std::optional<u64> timestamp) = 0;
  39. /// Notify rasterizer that all caches should be flushed to Switch memory
  40. virtual void FlushAll() = 0;
  41. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  42. virtual void FlushRegion(CacheAddr addr, u64 size) = 0;
  43. /// Notify rasterizer that any caches of the specified region should be invalidated
  44. virtual void InvalidateRegion(CacheAddr addr, u64 size) = 0;
  45. /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
  46. /// and invalidated
  47. virtual void FlushAndInvalidateRegion(CacheAddr addr, u64 size) = 0;
  48. /// Notify the rasterizer to send all written commands to the host GPU.
  49. virtual void FlushCommands() = 0;
  50. /// Notify rasterizer that a frame is about to finish
  51. virtual void TickFrame() = 0;
  52. /// Attempt to use a faster method to perform a surface copy
  53. virtual bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Regs::Surface& src,
  54. const Tegra::Engines::Fermi2D::Regs::Surface& dst,
  55. const Tegra::Engines::Fermi2D::Config& copy_config) {
  56. return false;
  57. }
  58. /// Attempt to use a faster method to display the framebuffer to screen
  59. virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
  60. u32 pixel_stride) {
  61. return false;
  62. }
  63. /// Increase/decrease the number of object in pages touching the specified region
  64. virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
  65. /// Initialize disk cached resources for the game being emulated
  66. virtual void LoadDiskResources(const std::atomic_bool& stop_loading = false,
  67. const DiskResourceLoadCallback& callback = {}) {}
  68. /// Initializes renderer dirty flags
  69. virtual void SetupDirtyFlags() {}
  70. /// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
  71. GuestDriverProfile& AccessGuestDriverProfile() {
  72. return guest_driver_profile;
  73. }
  74. /// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
  75. const GuestDriverProfile& AccessGuestDriverProfile() const {
  76. return guest_driver_profile;
  77. }
  78. private:
  79. GuestDriverProfile guest_driver_profile{};
  80. };
  81. } // namespace VideoCore