gpu.h 3.5 KB

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