dma_pusher.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/microprofile.h"
  5. #include "core/core.h"
  6. #include "core/memory.h"
  7. #include "video_core/dma_pusher.h"
  8. #include "video_core/engines/maxwell_3d.h"
  9. #include "video_core/gpu.h"
  10. #include "video_core/memory_manager.h"
  11. namespace Tegra {
  12. DmaPusher::DmaPusher(GPU& gpu) : gpu(gpu) {}
  13. DmaPusher::~DmaPusher() = default;
  14. MICROPROFILE_DEFINE(DispatchCalls, "GPU", "Execute command buffer", MP_RGB(128, 128, 192));
  15. void DmaPusher::DispatchCalls() {
  16. MICROPROFILE_SCOPE(DispatchCalls);
  17. dma_pushbuffer_subindex = 0;
  18. while (Core::System::GetInstance().IsPoweredOn()) {
  19. if (!Step()) {
  20. break;
  21. }
  22. }
  23. gpu.FlushCommands();
  24. }
  25. bool DmaPusher::Step() {
  26. if (!ib_enable || dma_pushbuffer.empty()) {
  27. // pushbuffer empty and IB empty or nonexistent - nothing to do
  28. return false;
  29. }
  30. const CommandList& command_list{dma_pushbuffer.front()};
  31. ASSERT_OR_EXECUTE(!command_list.empty(), {
  32. // Somehow the command_list is empty, in order to avoid a crash
  33. // We ignore it and assume its size is 0.
  34. dma_pushbuffer.pop();
  35. dma_pushbuffer_subindex = 0;
  36. return true;
  37. });
  38. const CommandListHeader command_list_header{command_list[dma_pushbuffer_subindex++]};
  39. GPUVAddr dma_get = command_list_header.addr;
  40. GPUVAddr dma_put = dma_get + command_list_header.size * sizeof(u32);
  41. bool non_main = command_list_header.is_non_main;
  42. if (dma_pushbuffer_subindex >= command_list.size()) {
  43. // We've gone through the current list, remove it from the queue
  44. dma_pushbuffer.pop();
  45. dma_pushbuffer_subindex = 0;
  46. }
  47. if (command_list_header.size == 0) {
  48. return true;
  49. }
  50. // Push buffer non-empty, read a word
  51. command_headers.resize(command_list_header.size);
  52. gpu.MemoryManager().ReadBlockUnsafe(dma_get, command_headers.data(),
  53. command_list_header.size * sizeof(u32));
  54. for (const CommandHeader& command_header : command_headers) {
  55. // now, see if we're in the middle of a command
  56. if (dma_state.length_pending) {
  57. // Second word of long non-inc methods command - method count
  58. dma_state.length_pending = 0;
  59. dma_state.method_count = command_header.method_count_;
  60. } else if (dma_state.method_count) {
  61. // Data word of methods command
  62. CallMethod(command_header.argument);
  63. if (!dma_state.non_incrementing) {
  64. dma_state.method++;
  65. }
  66. if (dma_increment_once) {
  67. dma_state.non_incrementing = true;
  68. }
  69. dma_state.method_count--;
  70. } else {
  71. // No command active - this is the first word of a new one
  72. switch (command_header.mode) {
  73. case SubmissionMode::Increasing:
  74. SetState(command_header);
  75. dma_state.non_incrementing = false;
  76. dma_increment_once = false;
  77. break;
  78. case SubmissionMode::NonIncreasing:
  79. SetState(command_header);
  80. dma_state.non_incrementing = true;
  81. dma_increment_once = false;
  82. break;
  83. case SubmissionMode::Inline:
  84. dma_state.method = command_header.method;
  85. dma_state.subchannel = command_header.subchannel;
  86. CallMethod(command_header.arg_count);
  87. dma_state.non_incrementing = true;
  88. dma_increment_once = false;
  89. break;
  90. case SubmissionMode::IncreaseOnce:
  91. SetState(command_header);
  92. dma_state.non_incrementing = false;
  93. dma_increment_once = true;
  94. break;
  95. default:
  96. break;
  97. }
  98. }
  99. }
  100. if (!non_main) {
  101. // TODO (degasus): This is dead code, as dma_mget is never read.
  102. dma_mget = dma_put;
  103. }
  104. return true;
  105. }
  106. void DmaPusher::SetState(const CommandHeader& command_header) {
  107. dma_state.method = command_header.method;
  108. dma_state.subchannel = command_header.subchannel;
  109. dma_state.method_count = command_header.method_count;
  110. }
  111. void DmaPusher::CallMethod(u32 argument) const {
  112. gpu.CallMethod({dma_state.method, argument, dma_state.subchannel, dma_state.method_count});
  113. }
  114. } // namespace Tegra