command_processor.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/renderer_base.h"
  19. #include "video_core/video_core.h"
  20. namespace Tegra {
  21. namespace CommandProcessor {
  22. enum class BufferMethods {
  23. BindObject = 0,
  24. CountBufferMethods = 0x100,
  25. };
  26. enum class EngineID {
  27. FERMI_TWOD_A = 0x902D, // 2D Engine
  28. MAXWELL_B = 0xB197, // 3D Engine
  29. MAXWELL_COMPUTE_B = 0xB1C0,
  30. KEPLER_INLINE_TO_MEMORY_B = 0xA140,
  31. MAXWELL_DMA_COPY_A = 0xB0B5,
  32. };
  33. // Mapping of subchannels to their bound engine ids.
  34. static std::unordered_map<u32, EngineID> bound_engines;
  35. static void WriteReg(u32 method, u32 subchannel, u32 value) {
  36. LOG_WARNING(HW_GPU, "Processing method %08X on subchannel %u value %08X", method, subchannel,
  37. value);
  38. if (method == static_cast<u32>(BufferMethods::BindObject)) {
  39. // Bind the current subchannel to the desired engine id.
  40. LOG_DEBUG(HW_GPU, "Binding subchannel %u to engine %u", subchannel, value);
  41. ASSERT(bound_engines.find(subchannel) == bound_engines.end());
  42. bound_engines[subchannel] = static_cast<EngineID>(value);
  43. return;
  44. }
  45. if (method < static_cast<u32>(BufferMethods::CountBufferMethods)) {
  46. // TODO(Subv): Research and implement these methods.
  47. LOG_ERROR(HW_GPU, "Special buffer methods other than Bind are not implemented");
  48. return;
  49. }
  50. ASSERT(bound_engines.find(subchannel) != bound_engines.end());
  51. const EngineID engine = bound_engines[subchannel];
  52. switch (engine) {
  53. case EngineID::FERMI_TWOD_A:
  54. Engines::Fermi2D::WriteReg(method, value);
  55. break;
  56. case EngineID::MAXWELL_B:
  57. Engines::Maxwell3D::WriteReg(method, value);
  58. break;
  59. case EngineID::MAXWELL_COMPUTE_B:
  60. Engines::MaxwellCompute::WriteReg(method, value);
  61. break;
  62. default:
  63. UNIMPLEMENTED();
  64. }
  65. }
  66. void ProcessCommandList(VAddr address, u32 size) {
  67. VAddr current_addr = address;
  68. while (current_addr < address + size * sizeof(CommandHeader)) {
  69. const CommandHeader header = {Memory::Read32(current_addr)};
  70. current_addr += sizeof(u32);
  71. switch (header.mode.Value()) {
  72. case SubmissionMode::IncreasingOld:
  73. case SubmissionMode::Increasing: {
  74. // Increase the method value with each argument.
  75. for (unsigned i = 0; i < header.arg_count; ++i) {
  76. WriteReg(header.method + i, header.subchannel, Memory::Read32(current_addr));
  77. current_addr += sizeof(u32);
  78. }
  79. break;
  80. }
  81. case SubmissionMode::NonIncreasingOld:
  82. case SubmissionMode::NonIncreasing: {
  83. // Use the same method value for all arguments.
  84. for (unsigned i = 0; i < header.arg_count; ++i) {
  85. WriteReg(header.method, header.subchannel, Memory::Read32(current_addr));
  86. current_addr += sizeof(u32);
  87. }
  88. break;
  89. }
  90. case SubmissionMode::IncreaseOnce: {
  91. ASSERT(header.arg_count.Value() >= 1);
  92. // Use the original method for the first argument and then the next method for all other
  93. // arguments.
  94. WriteReg(header.method, header.subchannel, Memory::Read32(current_addr));
  95. current_addr += sizeof(u32);
  96. // Use the same method value for all arguments.
  97. for (unsigned i = 1; i < header.arg_count; ++i) {
  98. WriteReg(header.method + 1, header.subchannel, Memory::Read32(current_addr));
  99. current_addr += sizeof(u32);
  100. }
  101. break;
  102. }
  103. case SubmissionMode::Inline: {
  104. // The register value is stored in the bits 16-28 as an immediate
  105. WriteReg(header.method, header.subchannel, header.inline_data);
  106. break;
  107. }
  108. default:
  109. UNIMPLEMENTED();
  110. }
  111. }
  112. }
  113. } // namespace CommandProcessor
  114. } // namespace Tegra