gpu.h 3.4 KB

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