cdma_pusher.cpp 5.1 KB

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