gpu.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 Tegra {
  12. enum class RenderTargetFormat : u32 {
  13. NONE = 0x0,
  14. RGBA32_FLOAT = 0xC0,
  15. RGBA16_FLOAT = 0xCA,
  16. RGB10_A2_UNORM = 0xD1,
  17. RGBA8_UNORM = 0xD5,
  18. RGBA8_SRGB = 0xD6,
  19. R11G11B10_FLOAT = 0xE0,
  20. };
  21. /// Returns the number of bytes per pixel of each rendertarget format.
  22. u32 RenderTargetBytesPerPixel(RenderTargetFormat format);
  23. class DebugContext;
  24. /**
  25. * Struct describing framebuffer configuration
  26. */
  27. struct FramebufferConfig {
  28. enum class PixelFormat : u32 {
  29. ABGR8 = 1,
  30. };
  31. /**
  32. * Returns the number of bytes per pixel.
  33. */
  34. static u32 BytesPerPixel(PixelFormat format) {
  35. switch (format) {
  36. case PixelFormat::ABGR8:
  37. return 4;
  38. }
  39. UNREACHABLE();
  40. }
  41. VAddr address;
  42. u32 offset;
  43. u32 width;
  44. u32 height;
  45. u32 stride;
  46. PixelFormat pixel_format;
  47. using TransformFlags = Service::NVFlinger::BufferQueue::BufferTransformFlags;
  48. TransformFlags transform_flags;
  49. };
  50. namespace Engines {
  51. class Fermi2D;
  52. class Maxwell3D;
  53. class MaxwellCompute;
  54. class MaxwellDMA;
  55. } // namespace Engines
  56. enum class EngineID {
  57. FERMI_TWOD_A = 0x902D, // 2D Engine
  58. MAXWELL_B = 0xB197, // 3D Engine
  59. MAXWELL_COMPUTE_B = 0xB1C0,
  60. KEPLER_INLINE_TO_MEMORY_B = 0xA140,
  61. MAXWELL_DMA_COPY_A = 0xB0B5,
  62. };
  63. class GPU final {
  64. public:
  65. GPU();
  66. ~GPU();
  67. /// Processes a command list stored at the specified address in GPU memory.
  68. void ProcessCommandList(GPUVAddr address, u32 size);
  69. /// Returns a reference to the Maxwell3D GPU engine.
  70. const Engines::Maxwell3D& Get3DEngine() const;
  71. std::unique_ptr<MemoryManager> memory_manager;
  72. Engines::Maxwell3D& Maxwell3D() {
  73. return *maxwell_3d;
  74. }
  75. private:
  76. /// Writes a single register in the engine bound to the specified subchannel
  77. void WriteReg(u32 method, u32 subchannel, u32 value, u32 remaining_params);
  78. /// Mapping of command subchannels to their bound engine ids.
  79. std::unordered_map<u32, EngineID> bound_engines;
  80. /// 3D engine
  81. std::unique_ptr<Engines::Maxwell3D> maxwell_3d;
  82. /// 2D engine
  83. std::unique_ptr<Engines::Fermi2D> fermi_2d;
  84. /// Compute engine
  85. std::unique_ptr<Engines::MaxwellCompute> maxwell_compute;
  86. /// DMA engine
  87. std::unique_ptr<Engines::MaxwellDMA> maxwell_dma;
  88. };
  89. } // namespace Tegra