puller.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <cstddef>
  7. #include <vector>
  8. #include "common/bit_field.h"
  9. #include "common/common_funcs.h"
  10. #include "common/common_types.h"
  11. #include "video_core/engines/engine_interface.h"
  12. namespace Core {
  13. class System;
  14. }
  15. namespace Tegra {
  16. class MemoryManager;
  17. class DmaPusher;
  18. enum class EngineID {
  19. FERMI_TWOD_A = 0x902D, // 2D Engine
  20. MAXWELL_B = 0xB197, // 3D Engine
  21. KEPLER_COMPUTE_B = 0xB1C0,
  22. KEPLER_INLINE_TO_MEMORY_B = 0xA140,
  23. MAXWELL_DMA_COPY_A = 0xB0B5,
  24. };
  25. namespace Control {
  26. struct ChannelState;
  27. }
  28. } // namespace Tegra
  29. namespace VideoCore {
  30. class RasterizerInterface;
  31. }
  32. namespace Tegra::Engines {
  33. class Puller final {
  34. public:
  35. struct MethodCall {
  36. u32 method{};
  37. u32 argument{};
  38. u32 subchannel{};
  39. u32 method_count{};
  40. explicit MethodCall(u32 method_, u32 argument_, u32 subchannel_ = 0, u32 method_count_ = 0)
  41. : method(method_), argument(argument_), subchannel(subchannel_),
  42. method_count(method_count_) {}
  43. [[nodiscard]] bool IsLastCall() const {
  44. return method_count <= 1;
  45. }
  46. };
  47. enum class FenceOperation : u32 {
  48. Acquire = 0,
  49. Increment = 1,
  50. };
  51. union FenceAction {
  52. u32 raw;
  53. BitField<0, 1, FenceOperation> op;
  54. BitField<8, 24, u32> syncpoint_id;
  55. };
  56. explicit Puller(GPU& gpu_, MemoryManager& memory_manager_, DmaPusher& dma_pusher,
  57. Control::ChannelState& channel_state);
  58. ~Puller();
  59. void CallMethod(const MethodCall& method_call);
  60. void CallMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount,
  61. u32 methods_pending);
  62. void BindRasterizer(VideoCore::RasterizerInterface* rasterizer);
  63. void CallPullerMethod(const MethodCall& method_call);
  64. void CallEngineMethod(const MethodCall& method_call);
  65. void CallEngineMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount,
  66. u32 methods_pending);
  67. private:
  68. Tegra::GPU& gpu;
  69. MemoryManager& memory_manager;
  70. DmaPusher& dma_pusher;
  71. Control::ChannelState& channel_state;
  72. VideoCore::RasterizerInterface* rasterizer = nullptr;
  73. static constexpr std::size_t NUM_REGS = 0x800;
  74. struct Regs {
  75. static constexpr size_t NUM_REGS = 0x40;
  76. union {
  77. struct {
  78. INSERT_PADDING_WORDS_NOINIT(0x4);
  79. struct {
  80. u32 address_high;
  81. u32 address_low;
  82. [[nodiscard]] GPUVAddr SemaphoreAddress() const {
  83. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  84. address_low);
  85. }
  86. } semaphore_address;
  87. u32 semaphore_sequence;
  88. u32 semaphore_trigger;
  89. INSERT_PADDING_WORDS_NOINIT(0xC);
  90. // The pusher and the puller share the reference counter, the pusher only has read
  91. // access
  92. u32 reference_count;
  93. INSERT_PADDING_WORDS_NOINIT(0x5);
  94. u32 semaphore_acquire;
  95. u32 semaphore_release;
  96. u32 fence_value;
  97. FenceAction fence_action;
  98. INSERT_PADDING_WORDS_NOINIT(0xE2);
  99. // Puller state
  100. u32 acquire_mode;
  101. u32 acquire_source;
  102. u32 acquire_active;
  103. u32 acquire_timeout;
  104. u32 acquire_value;
  105. };
  106. std::array<u32, NUM_REGS> reg_array;
  107. };
  108. } regs{};
  109. void ProcessBindMethod(const MethodCall& method_call);
  110. void ProcessFenceActionMethod();
  111. void ProcessSemaphoreAcquire();
  112. void ProcessSemaphoreRelease();
  113. void ProcessSemaphoreTriggerMethod();
  114. [[nodiscard]] bool ExecuteMethodOnEngine(u32 method);
  115. /// Mapping of command subchannels to their bound engine ids
  116. std::array<EngineID, 8> bound_engines{};
  117. enum class GpuSemaphoreOperation {
  118. AcquireEqual = 0x1,
  119. WriteLong = 0x2,
  120. AcquireGequal = 0x4,
  121. AcquireMask = 0x8,
  122. };
  123. #define ASSERT_REG_POSITION(field_name, position) \
  124. static_assert(offsetof(Regs, field_name) == position * 4, \
  125. "Field " #field_name " has invalid position")
  126. ASSERT_REG_POSITION(semaphore_address, 0x4);
  127. ASSERT_REG_POSITION(semaphore_sequence, 0x6);
  128. ASSERT_REG_POSITION(semaphore_trigger, 0x7);
  129. ASSERT_REG_POSITION(reference_count, 0x14);
  130. ASSERT_REG_POSITION(semaphore_acquire, 0x1A);
  131. ASSERT_REG_POSITION(semaphore_release, 0x1B);
  132. ASSERT_REG_POSITION(fence_value, 0x1C);
  133. ASSERT_REG_POSITION(fence_action, 0x1D);
  134. ASSERT_REG_POSITION(acquire_mode, 0x100);
  135. ASSERT_REG_POSITION(acquire_source, 0x101);
  136. ASSERT_REG_POSITION(acquire_active, 0x102);
  137. ASSERT_REG_POSITION(acquire_timeout, 0x103);
  138. ASSERT_REG_POSITION(acquire_value, 0x104);
  139. #undef ASSERT_REG_POSITION
  140. };
  141. } // namespace Tegra::Engines