dma_pusher.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/core.h"
  5. #include "core/memory.h"
  6. #include "video_core/dma_pusher.h"
  7. #include "video_core/engines/maxwell_3d.h"
  8. #include "video_core/gpu.h"
  9. namespace Tegra {
  10. DmaPusher::DmaPusher(GPU& gpu) : gpu(gpu) {}
  11. DmaPusher::~DmaPusher() = default;
  12. void DmaPusher::DispatchCalls() {
  13. // On entering GPU code, assume all memory may be touched by the ARM core.
  14. gpu.Maxwell3D().dirty_flags.OnMemoryWrite();
  15. while (Core::System::GetInstance().IsPoweredOn()) {
  16. if (!Step()) {
  17. break;
  18. }
  19. }
  20. }
  21. bool DmaPusher::Step() {
  22. if (dma_get != dma_put) {
  23. // Push buffer non-empty, read a word
  24. const CommandHeader command_header{
  25. Memory::Read32(*gpu.MemoryManager().GpuToCpuAddress(dma_get))};
  26. dma_get += sizeof(u32);
  27. if (!non_main) {
  28. dma_mget = dma_get;
  29. }
  30. // now, see if we're in the middle of a command
  31. if (dma_state.length_pending) {
  32. // Second word of long non-inc methods command - method count
  33. dma_state.length_pending = 0;
  34. dma_state.method_count = command_header.method_count_;
  35. } else if (dma_state.method_count) {
  36. // Data word of methods command
  37. CallMethod(command_header.argument);
  38. if (!dma_state.non_incrementing) {
  39. dma_state.method++;
  40. }
  41. if (dma_increment_once) {
  42. dma_state.non_incrementing = true;
  43. }
  44. dma_state.method_count--;
  45. } else {
  46. // No command active - this is the first word of a new one
  47. switch (command_header.mode) {
  48. case SubmissionMode::Increasing:
  49. SetState(command_header);
  50. dma_state.non_incrementing = false;
  51. dma_increment_once = false;
  52. break;
  53. case SubmissionMode::NonIncreasing:
  54. SetState(command_header);
  55. dma_state.non_incrementing = true;
  56. dma_increment_once = false;
  57. break;
  58. case SubmissionMode::Inline:
  59. dma_state.method = command_header.method;
  60. dma_state.subchannel = command_header.subchannel;
  61. CallMethod(command_header.arg_count);
  62. dma_state.non_incrementing = true;
  63. dma_increment_once = false;
  64. break;
  65. case SubmissionMode::IncreaseOnce:
  66. SetState(command_header);
  67. dma_state.non_incrementing = false;
  68. dma_increment_once = true;
  69. break;
  70. }
  71. }
  72. } else if (ib_enable && !dma_pushbuffer.empty()) {
  73. // Current pushbuffer empty, but we have more IB entries to read
  74. const CommandListHeader& command_list_header{dma_pushbuffer.front()};
  75. dma_get = command_list_header.addr;
  76. dma_put = dma_get + command_list_header.size * sizeof(u32);
  77. non_main = command_list_header.is_non_main;
  78. dma_pushbuffer.pop();
  79. } else {
  80. // Otherwise, pushbuffer empty and IB empty or nonexistent - nothing to do
  81. return {};
  82. }
  83. return true;
  84. }
  85. void DmaPusher::SetState(const CommandHeader& command_header) {
  86. dma_state.method = command_header.method;
  87. dma_state.subchannel = command_header.subchannel;
  88. dma_state.method_count = command_header.method_count;
  89. }
  90. void DmaPusher::CallMethod(u32 argument) const {
  91. gpu.CallMethod({dma_state.method, argument, dma_state.subchannel, dma_state.method_count});
  92. }
  93. } // namespace Tegra