gpu.h 2.5 KB

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