gpu.cpp 3.5 KB

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