gpu.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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/assert.h"
  5. #include "video_core/engines/fermi_2d.h"
  6. #include "video_core/engines/kepler_memory.h"
  7. #include "video_core/engines/maxwell_3d.h"
  8. #include "video_core/engines/maxwell_compute.h"
  9. #include "video_core/engines/maxwell_dma.h"
  10. #include "video_core/gpu.h"
  11. #include "video_core/rasterizer_interface.h"
  12. namespace Tegra {
  13. u32 FramebufferConfig::BytesPerPixel(PixelFormat format) {
  14. switch (format) {
  15. case PixelFormat::ABGR8:
  16. return 4;
  17. default:
  18. return 4;
  19. }
  20. UNREACHABLE();
  21. }
  22. GPU::GPU(VideoCore::RasterizerInterface& rasterizer) {
  23. memory_manager = std::make_unique<Tegra::MemoryManager>();
  24. dma_pusher = std::make_unique<Tegra::DmaPusher>(*this);
  25. maxwell_3d = std::make_unique<Engines::Maxwell3D>(rasterizer, *memory_manager);
  26. fermi_2d = std::make_unique<Engines::Fermi2D>(rasterizer, *memory_manager);
  27. maxwell_compute = std::make_unique<Engines::MaxwellCompute>();
  28. maxwell_dma = std::make_unique<Engines::MaxwellDMA>(rasterizer, *memory_manager);
  29. kepler_memory = std::make_unique<Engines::KeplerMemory>(rasterizer, *memory_manager);
  30. }
  31. GPU::~GPU() = default;
  32. Engines::Maxwell3D& GPU::Maxwell3D() {
  33. return *maxwell_3d;
  34. }
  35. const Engines::Maxwell3D& GPU::Maxwell3D() const {
  36. return *maxwell_3d;
  37. }
  38. MemoryManager& GPU::MemoryManager() {
  39. return *memory_manager;
  40. }
  41. const MemoryManager& GPU::MemoryManager() const {
  42. return *memory_manager;
  43. }
  44. DmaPusher& GPU::DmaPusher() {
  45. return *dma_pusher;
  46. }
  47. const DmaPusher& GPU::DmaPusher() const {
  48. return *dma_pusher;
  49. }
  50. u32 RenderTargetBytesPerPixel(RenderTargetFormat format) {
  51. ASSERT(format != RenderTargetFormat::NONE);
  52. switch (format) {
  53. case RenderTargetFormat::RGBA32_FLOAT:
  54. case RenderTargetFormat::RGBA32_UINT:
  55. return 16;
  56. case RenderTargetFormat::RGBA16_UINT:
  57. case RenderTargetFormat::RGBA16_UNORM:
  58. case RenderTargetFormat::RGBA16_FLOAT:
  59. case RenderTargetFormat::RG32_FLOAT:
  60. case RenderTargetFormat::RG32_UINT:
  61. return 8;
  62. case RenderTargetFormat::RGBA8_UNORM:
  63. case RenderTargetFormat::RGBA8_SNORM:
  64. case RenderTargetFormat::RGBA8_SRGB:
  65. case RenderTargetFormat::RGBA8_UINT:
  66. case RenderTargetFormat::RGB10_A2_UNORM:
  67. case RenderTargetFormat::BGRA8_UNORM:
  68. case RenderTargetFormat::BGRA8_SRGB:
  69. case RenderTargetFormat::RG16_UNORM:
  70. case RenderTargetFormat::RG16_SNORM:
  71. case RenderTargetFormat::RG16_UINT:
  72. case RenderTargetFormat::RG16_SINT:
  73. case RenderTargetFormat::RG16_FLOAT:
  74. case RenderTargetFormat::R32_FLOAT:
  75. case RenderTargetFormat::R11G11B10_FLOAT:
  76. case RenderTargetFormat::R32_UINT:
  77. return 4;
  78. case RenderTargetFormat::R16_UNORM:
  79. case RenderTargetFormat::R16_SNORM:
  80. case RenderTargetFormat::R16_UINT:
  81. case RenderTargetFormat::R16_SINT:
  82. case RenderTargetFormat::R16_FLOAT:
  83. case RenderTargetFormat::RG8_UNORM:
  84. case RenderTargetFormat::RG8_SNORM:
  85. return 2;
  86. case RenderTargetFormat::R8_UNORM:
  87. case RenderTargetFormat::R8_UINT:
  88. return 1;
  89. default:
  90. UNIMPLEMENTED_MSG("Unimplemented render target format {}", static_cast<u32>(format));
  91. return 1;
  92. }
  93. }
  94. u32 DepthFormatBytesPerPixel(DepthFormat format) {
  95. switch (format) {
  96. case DepthFormat::Z32_S8_X24_FLOAT:
  97. return 8;
  98. case DepthFormat::Z32_FLOAT:
  99. case DepthFormat::S8_Z24_UNORM:
  100. case DepthFormat::Z24_X8_UNORM:
  101. case DepthFormat::Z24_S8_UNORM:
  102. case DepthFormat::Z24_C8_UNORM:
  103. return 4;
  104. case DepthFormat::Z16_UNORM:
  105. return 2;
  106. default:
  107. UNIMPLEMENTED_MSG("Unimplemented Depth format {}", static_cast<u32>(format));
  108. return 1;
  109. }
  110. }
  111. enum class BufferMethods {
  112. BindObject = 0,
  113. CountBufferMethods = 0x40,
  114. };
  115. void GPU::CallMethod(const MethodCall& method_call) {
  116. LOG_TRACE(HW_GPU, "Processing method {:08X} on subchannel {}", method_call.method,
  117. method_call.subchannel);
  118. ASSERT(method_call.subchannel < bound_engines.size());
  119. if (method_call.method == static_cast<u32>(BufferMethods::BindObject)) {
  120. // Bind the current subchannel to the desired engine id.
  121. LOG_DEBUG(HW_GPU, "Binding subchannel {} to engine {}", method_call.subchannel,
  122. method_call.argument);
  123. bound_engines[method_call.subchannel] = static_cast<EngineID>(method_call.argument);
  124. return;
  125. }
  126. if (method_call.method < static_cast<u32>(BufferMethods::CountBufferMethods)) {
  127. // TODO(Subv): Research and implement these methods.
  128. LOG_ERROR(HW_GPU, "Special buffer methods other than Bind are not implemented");
  129. return;
  130. }
  131. const EngineID engine = bound_engines[method_call.subchannel];
  132. switch (engine) {
  133. case EngineID::FERMI_TWOD_A:
  134. fermi_2d->CallMethod(method_call);
  135. break;
  136. case EngineID::MAXWELL_B:
  137. maxwell_3d->CallMethod(method_call);
  138. break;
  139. case EngineID::MAXWELL_COMPUTE_B:
  140. maxwell_compute->CallMethod(method_call);
  141. break;
  142. case EngineID::MAXWELL_DMA_COPY_A:
  143. maxwell_dma->CallMethod(method_call);
  144. break;
  145. case EngineID::KEPLER_INLINE_TO_MEMORY_B:
  146. kepler_memory->CallMethod(method_call);
  147. break;
  148. default:
  149. UNIMPLEMENTED_MSG("Unimplemented engine");
  150. }
  151. }
  152. } // namespace Tegra