gpu.h 2.5 KB

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