cdma_pusher.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // MIT License
  2. //
  3. // Copyright (c) Ryujinx Team and Contributors
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  6. // associated documentation files (the "Software"), to deal in the Software without restriction,
  7. // including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in all copies or
  12. // substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  15. // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  17. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. #include <bit>
  21. #include "command_classes/host1x.h"
  22. #include "command_classes/nvdec.h"
  23. #include "command_classes/vic.h"
  24. #include "video_core/cdma_pusher.h"
  25. #include "video_core/command_classes/nvdec_common.h"
  26. #include "video_core/engines/maxwell_3d.h"
  27. #include "video_core/gpu.h"
  28. #include "video_core/memory_manager.h"
  29. namespace Tegra {
  30. CDmaPusher::CDmaPusher(GPU& gpu_)
  31. : gpu{gpu_}, nvdec_processor(std::make_shared<Nvdec>(gpu)),
  32. vic_processor(std::make_unique<Vic>(gpu, nvdec_processor)),
  33. host1x_processor(std::make_unique<Host1x>(gpu)),
  34. sync_manager(std::make_unique<SyncptIncrManager>(gpu)) {}
  35. CDmaPusher::~CDmaPusher() = default;
  36. void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries) {
  37. std::vector<u32> values(entries.size());
  38. std::memcpy(values.data(), entries.data(), entries.size() * sizeof(u32));
  39. for (const u32 value : values) {
  40. if (mask != 0) {
  41. const auto lbs = static_cast<u32>(std::countr_zero(mask));
  42. mask &= ~(1U << lbs);
  43. ExecuteCommand(static_cast<u32>(offset + lbs), value);
  44. continue;
  45. } else if (count != 0) {
  46. --count;
  47. ExecuteCommand(static_cast<u32>(offset), value);
  48. if (incrementing) {
  49. ++offset;
  50. }
  51. continue;
  52. }
  53. const auto mode = static_cast<ChSubmissionMode>((value >> 28) & 0xf);
  54. switch (mode) {
  55. case ChSubmissionMode::SetClass: {
  56. mask = value & 0x3f;
  57. offset = (value >> 16) & 0xfff;
  58. current_class = static_cast<ChClassId>((value >> 6) & 0x3ff);
  59. break;
  60. }
  61. case ChSubmissionMode::Incrementing:
  62. case ChSubmissionMode::NonIncrementing:
  63. count = value & 0xffff;
  64. offset = (value >> 16) & 0xfff;
  65. incrementing = mode == ChSubmissionMode::Incrementing;
  66. break;
  67. case ChSubmissionMode::Mask:
  68. mask = value & 0xffff;
  69. offset = (value >> 16) & 0xfff;
  70. break;
  71. case ChSubmissionMode::Immediate: {
  72. const u32 data = value & 0xfff;
  73. offset = (value >> 16) & 0xfff;
  74. ExecuteCommand(static_cast<u32>(offset), data);
  75. break;
  76. }
  77. default:
  78. UNIMPLEMENTED_MSG("ChSubmission mode {} is not implemented!", static_cast<u32>(mode));
  79. break;
  80. }
  81. }
  82. }
  83. void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) {
  84. switch (current_class) {
  85. case ChClassId::NvDec:
  86. ThiStateWrite(nvdec_thi_state, state_offset, {data});
  87. switch (static_cast<ThiMethod>(state_offset)) {
  88. case ThiMethod::IncSyncpt: {
  89. LOG_DEBUG(Service_NVDRV, "NVDEC Class IncSyncpt Method");
  90. const auto syncpoint_id = static_cast<u32>(data & 0xFF);
  91. const auto cond = static_cast<u32>((data >> 8) & 0xFF);
  92. if (cond == 0) {
  93. sync_manager->Increment(syncpoint_id);
  94. } else {
  95. sync_manager->SignalDone(
  96. sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
  97. }
  98. break;
  99. }
  100. case ThiMethod::SetMethod1:
  101. LOG_DEBUG(Service_NVDRV, "NVDEC method 0x{:X}",
  102. static_cast<u32>(nvdec_thi_state.method_0));
  103. nvdec_processor->ProcessMethod(static_cast<Nvdec::Method>(nvdec_thi_state.method_0),
  104. {data});
  105. break;
  106. default:
  107. break;
  108. }
  109. break;
  110. case ChClassId::GraphicsVic:
  111. ThiStateWrite(vic_thi_state, static_cast<u32>(state_offset), {data});
  112. switch (static_cast<ThiMethod>(state_offset)) {
  113. case ThiMethod::IncSyncpt: {
  114. LOG_DEBUG(Service_NVDRV, "VIC Class IncSyncpt Method");
  115. const auto syncpoint_id = static_cast<u32>(data & 0xFF);
  116. const auto cond = static_cast<u32>((data >> 8) & 0xFF);
  117. if (cond == 0) {
  118. sync_manager->Increment(syncpoint_id);
  119. } else {
  120. sync_manager->SignalDone(
  121. sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
  122. }
  123. break;
  124. }
  125. case ThiMethod::SetMethod1:
  126. LOG_DEBUG(Service_NVDRV, "VIC method 0x{:X}, Args=({})",
  127. static_cast<u32>(vic_thi_state.method_0), data);
  128. vic_processor->ProcessMethod(static_cast<Vic::Method>(vic_thi_state.method_0), {data});
  129. break;
  130. default:
  131. break;
  132. }
  133. break;
  134. case ChClassId::Host1x:
  135. // This device is mainly for syncpoint synchronization
  136. LOG_DEBUG(Service_NVDRV, "Host1X Class Method");
  137. host1x_processor->ProcessMethod(static_cast<Host1x::Method>(state_offset), {data});
  138. break;
  139. default:
  140. UNIMPLEMENTED_MSG("Current class not implemented {:X}", static_cast<u32>(current_class));
  141. break;
  142. }
  143. }
  144. void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset,
  145. const std::vector<u32>& arguments) {
  146. u8* const state_offset_ptr = reinterpret_cast<u8*>(&state) + sizeof(u32) * state_offset;
  147. std::memcpy(state_offset_ptr, arguments.data(), sizeof(u32) * arguments.size());
  148. }
  149. } // namespace Tegra