gpu.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. maxwell_3d = std::make_unique<Engines::Maxwell3D>(rasterizer, *memory_manager);
  25. fermi_2d = std::make_unique<Engines::Fermi2D>(rasterizer, *memory_manager);
  26. maxwell_compute = std::make_unique<Engines::MaxwellCompute>();
  27. maxwell_dma = std::make_unique<Engines::MaxwellDMA>(rasterizer, *memory_manager);
  28. kepler_memory = std::make_unique<Engines::KeplerMemory>(rasterizer, *memory_manager);
  29. }
  30. GPU::~GPU() = default;
  31. Engines::Maxwell3D& GPU::Maxwell3D() {
  32. return *maxwell_3d;
  33. }
  34. const Engines::Maxwell3D& GPU::Maxwell3D() const {
  35. return *maxwell_3d;
  36. }
  37. MemoryManager& GPU::MemoryManager() {
  38. return *memory_manager;
  39. }
  40. const MemoryManager& GPU::MemoryManager() const {
  41. return *memory_manager;
  42. }
  43. u32 RenderTargetBytesPerPixel(RenderTargetFormat format) {
  44. ASSERT(format != RenderTargetFormat::NONE);
  45. switch (format) {
  46. case RenderTargetFormat::RGBA32_FLOAT:
  47. case RenderTargetFormat::RGBA32_UINT:
  48. return 16;
  49. case RenderTargetFormat::RGBA16_UINT:
  50. case RenderTargetFormat::RGBA16_UNORM:
  51. case RenderTargetFormat::RGBA16_FLOAT:
  52. case RenderTargetFormat::RG32_FLOAT:
  53. case RenderTargetFormat::RG32_UINT:
  54. return 8;
  55. case RenderTargetFormat::RGBA8_UNORM:
  56. case RenderTargetFormat::RGBA8_SNORM:
  57. case RenderTargetFormat::RGBA8_SRGB:
  58. case RenderTargetFormat::RGBA8_UINT:
  59. case RenderTargetFormat::RGB10_A2_UNORM:
  60. case RenderTargetFormat::BGRA8_UNORM:
  61. case RenderTargetFormat::BGRA8_SRGB:
  62. case RenderTargetFormat::RG16_UNORM:
  63. case RenderTargetFormat::RG16_SNORM:
  64. case RenderTargetFormat::RG16_UINT:
  65. case RenderTargetFormat::RG16_SINT:
  66. case RenderTargetFormat::RG16_FLOAT:
  67. case RenderTargetFormat::R32_FLOAT:
  68. case RenderTargetFormat::R11G11B10_FLOAT:
  69. case RenderTargetFormat::R32_UINT:
  70. return 4;
  71. case RenderTargetFormat::R16_UNORM:
  72. case RenderTargetFormat::R16_SNORM:
  73. case RenderTargetFormat::R16_UINT:
  74. case RenderTargetFormat::R16_SINT:
  75. case RenderTargetFormat::R16_FLOAT:
  76. case RenderTargetFormat::RG8_UNORM:
  77. case RenderTargetFormat::RG8_SNORM:
  78. return 2;
  79. case RenderTargetFormat::R8_UNORM:
  80. case RenderTargetFormat::R8_UINT:
  81. return 1;
  82. default:
  83. UNIMPLEMENTED_MSG("Unimplemented render target format {}", static_cast<u32>(format));
  84. }
  85. }
  86. u32 DepthFormatBytesPerPixel(DepthFormat format) {
  87. switch (format) {
  88. case DepthFormat::Z32_S8_X24_FLOAT:
  89. return 8;
  90. case DepthFormat::Z32_FLOAT:
  91. case DepthFormat::S8_Z24_UNORM:
  92. case DepthFormat::Z24_X8_UNORM:
  93. case DepthFormat::Z24_S8_UNORM:
  94. case DepthFormat::Z24_C8_UNORM:
  95. return 4;
  96. case DepthFormat::Z16_UNORM:
  97. return 2;
  98. default:
  99. UNIMPLEMENTED_MSG("Unimplemented Depth format {}", static_cast<u32>(format));
  100. }
  101. }
  102. } // namespace Tegra