gpu.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <memory>
  7. #include <vector>
  8. #include "common/common_types.h"
  9. #include "core/hle/service/nvflinger/buffer_queue.h"
  10. #include "video_core/memory_manager.h"
  11. namespace VideoCore {
  12. class RasterizerInterface;
  13. }
  14. namespace Tegra {
  15. enum class RenderTargetFormat : u32 {
  16. NONE = 0x0,
  17. RGBA32_FLOAT = 0xC0,
  18. RGBA32_UINT = 0xC2,
  19. RGBA16_UNORM = 0xC6,
  20. RGBA16_UINT = 0xC9,
  21. RGBA16_FLOAT = 0xCA,
  22. RG32_FLOAT = 0xCB,
  23. RG32_UINT = 0xCD,
  24. BGRA8_UNORM = 0xCF,
  25. BGRA8_SRGB = 0xD0,
  26. RGB10_A2_UNORM = 0xD1,
  27. RGBA8_UNORM = 0xD5,
  28. RGBA8_SRGB = 0xD6,
  29. RGBA8_SNORM = 0xD7,
  30. RGBA8_UINT = 0xD9,
  31. RG16_UNORM = 0xDA,
  32. RG16_SNORM = 0xDB,
  33. RG16_SINT = 0xDC,
  34. RG16_UINT = 0xDD,
  35. RG16_FLOAT = 0xDE,
  36. R11G11B10_FLOAT = 0xE0,
  37. R32_UINT = 0xE4,
  38. R32_FLOAT = 0xE5,
  39. B5G6R5_UNORM = 0xE8,
  40. RG8_UNORM = 0xEA,
  41. RG8_SNORM = 0xEB,
  42. R16_UNORM = 0xEE,
  43. R16_SNORM = 0xEF,
  44. R16_SINT = 0xF0,
  45. R16_UINT = 0xF1,
  46. R16_FLOAT = 0xF2,
  47. R8_UNORM = 0xF3,
  48. R8_UINT = 0xF6,
  49. };
  50. enum class DepthFormat : u32 {
  51. Z32_FLOAT = 0xA,
  52. Z16_UNORM = 0x13,
  53. S8_Z24_UNORM = 0x14,
  54. Z24_X8_UNORM = 0x15,
  55. Z24_S8_UNORM = 0x16,
  56. Z24_C8_UNORM = 0x18,
  57. Z32_S8_X24_FLOAT = 0x19,
  58. };
  59. /// Returns the number of bytes per pixel of each rendertarget format.
  60. u32 RenderTargetBytesPerPixel(RenderTargetFormat format);
  61. /// Returns the number of bytes per pixel of each depth format.
  62. u32 DepthFormatBytesPerPixel(DepthFormat format);
  63. struct CommandListHeader;
  64. class DebugContext;
  65. /**
  66. * Struct describing framebuffer configuration
  67. */
  68. struct FramebufferConfig {
  69. enum class PixelFormat : u32 {
  70. ABGR8 = 1,
  71. };
  72. /**
  73. * Returns the number of bytes per pixel.
  74. */
  75. static u32 BytesPerPixel(PixelFormat format);
  76. VAddr address;
  77. u32 offset;
  78. u32 width;
  79. u32 height;
  80. u32 stride;
  81. PixelFormat pixel_format;
  82. using TransformFlags = Service::NVFlinger::BufferQueue::BufferTransformFlags;
  83. TransformFlags transform_flags;
  84. MathUtil::Rectangle<int> crop_rect;
  85. };
  86. namespace Engines {
  87. class Fermi2D;
  88. class Maxwell3D;
  89. class MaxwellCompute;
  90. class MaxwellDMA;
  91. class KeplerMemory;
  92. } // namespace Engines
  93. enum class EngineID {
  94. FERMI_TWOD_A = 0x902D, // 2D Engine
  95. MAXWELL_B = 0xB197, // 3D Engine
  96. MAXWELL_COMPUTE_B = 0xB1C0,
  97. KEPLER_INLINE_TO_MEMORY_B = 0xA140,
  98. MAXWELL_DMA_COPY_A = 0xB0B5,
  99. };
  100. class GPU final {
  101. public:
  102. explicit GPU(VideoCore::RasterizerInterface& rasterizer);
  103. ~GPU();
  104. /// Processes a command list stored at the specified address in GPU memory.
  105. void ProcessCommandLists(const std::vector<CommandListHeader>& commands);
  106. /// Returns a reference to the Maxwell3D GPU engine.
  107. Engines::Maxwell3D& Maxwell3D();
  108. /// Returns a const reference to the Maxwell3D GPU engine.
  109. const Engines::Maxwell3D& Maxwell3D() const;
  110. /// Returns a reference to the GPU memory manager.
  111. Tegra::MemoryManager& MemoryManager();
  112. /// Returns a const reference to the GPU memory manager.
  113. const Tegra::MemoryManager& MemoryManager() const;
  114. private:
  115. std::unique_ptr<Tegra::MemoryManager> memory_manager;
  116. /// Mapping of command subchannels to their bound engine ids.
  117. std::array<EngineID, 8> bound_engines = {};
  118. /// 3D engine
  119. std::unique_ptr<Engines::Maxwell3D> maxwell_3d;
  120. /// 2D engine
  121. std::unique_ptr<Engines::Fermi2D> fermi_2d;
  122. /// Compute engine
  123. std::unique_ptr<Engines::MaxwellCompute> maxwell_compute;
  124. /// DMA engine
  125. std::unique_ptr<Engines::MaxwellDMA> maxwell_dma;
  126. /// Inline memory engine
  127. std::unique_ptr<Engines::KeplerMemory> kepler_memory;
  128. };
  129. } // namespace Tegra