command_processor.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <cstddef>
  6. #include <memory>
  7. #include <utility>
  8. #include "common/assert.h"
  9. #include "common/logging/log.h"
  10. #include "common/microprofile.h"
  11. #include "common/vector_math.h"
  12. #include "core/memory.h"
  13. #include "core/tracer/recorder.h"
  14. #include "video_core/command_processor.h"
  15. #include "video_core/engines/fermi_2d.h"
  16. #include "video_core/engines/maxwell_3d.h"
  17. #include "video_core/engines/maxwell_compute.h"
  18. #include "video_core/gpu.h"
  19. #include "video_core/renderer_base.h"
  20. #include "video_core/video_core.h"
  21. namespace Tegra {
  22. enum class BufferMethods {
  23. BindObject = 0,
  24. SetGraphMacroCode = 0x45,
  25. SetGraphMacroCodeArg = 0x46,
  26. SetGraphMacroEntry = 0x47,
  27. CountBufferMethods = 0x100,
  28. };
  29. void GPU::WriteReg(u32 method, u32 subchannel, u32 value, u32 remaining_params) {
  30. LOG_WARNING(HW_GPU, "Processing method %08X on subchannel %u value %08X remaining params %u",
  31. method, subchannel, value, remaining_params);
  32. if (method == static_cast<u32>(BufferMethods::SetGraphMacroEntry)) {
  33. // Prepare to upload a new macro, reset the upload counter.
  34. LOG_DEBUG(HW_GPU, "Uploading GPU macro %08X", value);
  35. current_macro_entry = value;
  36. current_macro_code.clear();
  37. return;
  38. }
  39. if (method == static_cast<u32>(BufferMethods::SetGraphMacroCodeArg)) {
  40. // Append a new code word to the current macro.
  41. current_macro_code.push_back(value);
  42. // There are no more params remaining, submit the code to the 3D engine.
  43. if (remaining_params == 0) {
  44. maxwell_3d->SubmitMacroCode(current_macro_entry, std::move(current_macro_code));
  45. current_macro_entry = InvalidGraphMacroEntry;
  46. current_macro_code.clear();
  47. }
  48. return;
  49. }
  50. if (method == static_cast<u32>(BufferMethods::BindObject)) {
  51. // Bind the current subchannel to the desired engine id.
  52. LOG_DEBUG(HW_GPU, "Binding subchannel %u to engine %u", subchannel, value);
  53. ASSERT(bound_engines.find(subchannel) == bound_engines.end());
  54. bound_engines[subchannel] = static_cast<EngineID>(value);
  55. return;
  56. }
  57. if (method < static_cast<u32>(BufferMethods::CountBufferMethods)) {
  58. // TODO(Subv): Research and implement these methods.
  59. LOG_ERROR(HW_GPU, "Special buffer methods other than Bind are not implemented");
  60. return;
  61. }
  62. ASSERT(bound_engines.find(subchannel) != bound_engines.end());
  63. const EngineID engine = bound_engines[subchannel];
  64. switch (engine) {
  65. case EngineID::FERMI_TWOD_A:
  66. fermi_2d->WriteReg(method, value);
  67. break;
  68. case EngineID::MAXWELL_B:
  69. maxwell_3d->WriteReg(method, value, remaining_params);
  70. break;
  71. case EngineID::MAXWELL_COMPUTE_B:
  72. maxwell_compute->WriteReg(method, value);
  73. break;
  74. default:
  75. UNIMPLEMENTED();
  76. }
  77. }
  78. void GPU::ProcessCommandList(GPUVAddr address, u32 size) {
  79. // TODO(Subv): PhysicalToVirtualAddress is a misnomer, it converts a GPU VAddr into an
  80. // application VAddr.
  81. const VAddr head_address = memory_manager->PhysicalToVirtualAddress(address);
  82. VAddr current_addr = head_address;
  83. while (current_addr < head_address + size * sizeof(CommandHeader)) {
  84. const CommandHeader header = {Memory::Read32(current_addr)};
  85. current_addr += sizeof(u32);
  86. switch (header.mode.Value()) {
  87. case SubmissionMode::IncreasingOld:
  88. case SubmissionMode::Increasing: {
  89. // Increase the method value with each argument.
  90. for (unsigned i = 0; i < header.arg_count; ++i) {
  91. WriteReg(header.method + i, header.subchannel, Memory::Read32(current_addr),
  92. header.arg_count - i - 1);
  93. current_addr += sizeof(u32);
  94. }
  95. break;
  96. }
  97. case SubmissionMode::NonIncreasingOld:
  98. case SubmissionMode::NonIncreasing: {
  99. // Use the same method value for all arguments.
  100. for (unsigned i = 0; i < header.arg_count; ++i) {
  101. WriteReg(header.method, header.subchannel, Memory::Read32(current_addr),
  102. header.arg_count - i - 1);
  103. current_addr += sizeof(u32);
  104. }
  105. break;
  106. }
  107. case SubmissionMode::IncreaseOnce: {
  108. ASSERT(header.arg_count.Value() >= 1);
  109. // Use the original method for the first argument and then the next method for all other
  110. // arguments.
  111. WriteReg(header.method, header.subchannel, Memory::Read32(current_addr),
  112. header.arg_count - 1);
  113. current_addr += sizeof(u32);
  114. for (unsigned i = 1; i < header.arg_count; ++i) {
  115. WriteReg(header.method + 1, header.subchannel, Memory::Read32(current_addr),
  116. header.arg_count - i - 1);
  117. current_addr += sizeof(u32);
  118. }
  119. break;
  120. }
  121. case SubmissionMode::Inline: {
  122. // The register value is stored in the bits 16-28 as an immediate
  123. WriteReg(header.method, header.subchannel, header.inline_data, 0);
  124. break;
  125. }
  126. default:
  127. UNIMPLEMENTED();
  128. }
  129. }
  130. }
  131. } // namespace Tegra