puller.h 5.2 KB

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