cdma_pusher.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-FileCopyrightText: Ryujinx Team and Contributors
  2. // SPDX-License-Identifier: MIT
  3. #include <bit>
  4. #include "command_classes/host1x.h"
  5. #include "command_classes/nvdec.h"
  6. #include "command_classes/vic.h"
  7. #include "video_core/cdma_pusher.h"
  8. #include "video_core/command_classes/sync_manager.h"
  9. #include "video_core/engines/maxwell_3d.h"
  10. #include "video_core/gpu.h"
  11. namespace Tegra {
  12. CDmaPusher::CDmaPusher(GPU& gpu_)
  13. : gpu{gpu_}, nvdec_processor(std::make_shared<Nvdec>(gpu)),
  14. vic_processor(std::make_unique<Vic>(gpu, nvdec_processor)),
  15. host1x_processor(std::make_unique<Host1x>(gpu)),
  16. sync_manager(std::make_unique<SyncptIncrManager>(gpu)) {}
  17. CDmaPusher::~CDmaPusher() = default;
  18. void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries) {
  19. for (const auto& value : entries) {
  20. if (mask != 0) {
  21. const auto lbs = static_cast<u32>(std::countr_zero(mask));
  22. mask &= ~(1U << lbs);
  23. ExecuteCommand(offset + lbs, value.raw);
  24. continue;
  25. } else if (count != 0) {
  26. --count;
  27. ExecuteCommand(offset, value.raw);
  28. if (incrementing) {
  29. ++offset;
  30. }
  31. continue;
  32. }
  33. const auto mode = value.submission_mode.Value();
  34. switch (mode) {
  35. case ChSubmissionMode::SetClass: {
  36. mask = value.value & 0x3f;
  37. offset = value.method_offset;
  38. current_class = static_cast<ChClassId>((value.value >> 6) & 0x3ff);
  39. break;
  40. }
  41. case ChSubmissionMode::Incrementing:
  42. case ChSubmissionMode::NonIncrementing:
  43. count = value.value;
  44. offset = value.method_offset;
  45. incrementing = mode == ChSubmissionMode::Incrementing;
  46. break;
  47. case ChSubmissionMode::Mask:
  48. mask = value.value;
  49. offset = value.method_offset;
  50. break;
  51. case ChSubmissionMode::Immediate: {
  52. const u32 data = value.value & 0xfff;
  53. offset = value.method_offset;
  54. ExecuteCommand(offset, data);
  55. break;
  56. }
  57. default:
  58. UNIMPLEMENTED_MSG("ChSubmission mode {} is not implemented!", static_cast<u32>(mode));
  59. break;
  60. }
  61. }
  62. }
  63. void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) {
  64. switch (current_class) {
  65. case ChClassId::NvDec:
  66. ThiStateWrite(nvdec_thi_state, offset, data);
  67. switch (static_cast<ThiMethod>(offset)) {
  68. case ThiMethod::IncSyncpt: {
  69. LOG_DEBUG(Service_NVDRV, "NVDEC Class IncSyncpt Method");
  70. const auto syncpoint_id = static_cast<u32>(data & 0xFF);
  71. const auto cond = static_cast<u32>((data >> 8) & 0xFF);
  72. if (cond == 0) {
  73. sync_manager->Increment(syncpoint_id);
  74. } else {
  75. sync_manager->SignalDone(
  76. sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
  77. }
  78. break;
  79. }
  80. case ThiMethod::SetMethod1:
  81. LOG_DEBUG(Service_NVDRV, "NVDEC method 0x{:X}",
  82. static_cast<u32>(nvdec_thi_state.method_0));
  83. nvdec_processor->ProcessMethod(nvdec_thi_state.method_0, data);
  84. break;
  85. default:
  86. break;
  87. }
  88. break;
  89. case ChClassId::GraphicsVic:
  90. ThiStateWrite(vic_thi_state, static_cast<u32>(state_offset), {data});
  91. switch (static_cast<ThiMethod>(state_offset)) {
  92. case ThiMethod::IncSyncpt: {
  93. LOG_DEBUG(Service_NVDRV, "VIC Class IncSyncpt Method");
  94. const auto syncpoint_id = static_cast<u32>(data & 0xFF);
  95. const auto cond = static_cast<u32>((data >> 8) & 0xFF);
  96. if (cond == 0) {
  97. sync_manager->Increment(syncpoint_id);
  98. } else {
  99. sync_manager->SignalDone(
  100. sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
  101. }
  102. break;
  103. }
  104. case ThiMethod::SetMethod1:
  105. LOG_DEBUG(Service_NVDRV, "VIC method 0x{:X}, Args=({})",
  106. static_cast<u32>(vic_thi_state.method_0), data);
  107. vic_processor->ProcessMethod(static_cast<Vic::Method>(vic_thi_state.method_0), data);
  108. break;
  109. default:
  110. break;
  111. }
  112. break;
  113. case ChClassId::Host1x:
  114. // This device is mainly for syncpoint synchronization
  115. LOG_DEBUG(Service_NVDRV, "Host1X Class Method");
  116. host1x_processor->ProcessMethod(static_cast<Host1x::Method>(offset), data);
  117. break;
  118. default:
  119. UNIMPLEMENTED_MSG("Current class not implemented {:X}", static_cast<u32>(current_class));
  120. break;
  121. }
  122. }
  123. void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset, u32 argument) {
  124. u8* const offset_ptr = reinterpret_cast<u8*>(&state) + sizeof(u32) * state_offset;
  125. std::memcpy(offset_ptr, &argument, sizeof(u32));
  126. }
  127. } // namespace Tegra