gpu.h 3.2 KB

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