gpu.h
1 // Copyright 2023 Citra Emulator Project 2 // Licensed under GPLv2 or any later version 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include <functional> 8 #include <memory> 9 #include <boost/serialization/access.hpp> 10 11 #include "core/hle/service/gsp/gsp_interrupt.h" 12 13 namespace Service::GSP { 14 struct Command; 15 struct FrameBufferInfo; 16 } // namespace Service::GSP 17 18 namespace Core { 19 class System; 20 } 21 22 namespace Pica { 23 class DebugContext; 24 class PicaCore; 25 struct RegsLcd; 26 union ColorFill; 27 } // namespace Pica 28 29 namespace Frontend { 30 class EmuWindow; 31 } 32 33 namespace VideoCore { 34 35 /// Measured on hardware to be 2240568 timer cycles or 4481136 ARM11 cycles 36 constexpr u64 FRAME_TICKS = 4481136ull; 37 38 class GraphicsDebugger; 39 class RendererBase; 40 41 /** 42 * The GPU class is the high level interface to the video_core for core services. 43 */ 44 class GPU { 45 public: 46 explicit GPU(Core::System& system, Frontend::EmuWindow& emu_window, 47 Frontend::EmuWindow* secondary_window); 48 ~GPU(); 49 50 /// Sets the function to call for signalling GSP interrupts. 51 void SetInterruptHandler(Service::GSP::InterruptHandler handler); 52 53 /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory 54 void FlushRegion(PAddr addr, u32 size); 55 56 /// Notify rasterizer that any caches of the specified region should be invalidated 57 void InvalidateRegion(PAddr addr, u32 size); 58 59 /// Flushes and invalidates all memory in the rasterizer cache and removes any leftover state. 60 void ClearAll(bool flush); 61 62 /// Executes the provided GSP command. 63 void Execute(const Service::GSP::Command& command); 64 65 /// Updates GPU display framebuffer configuration using the specified parameters. 66 void SetBufferSwap(u32 screen_id, const Service::GSP::FrameBufferInfo& info); 67 68 /// Sets the LCD color fill configuration for the top and bottom screens. 69 void SetColorFill(const Pica::ColorFill& fill); 70 71 /// Reads a word from the GPU virtual address. 72 u32 ReadReg(VAddr addr); 73 74 /// Writes the provided value to the GPU virtual address. 75 void WriteReg(VAddr addr, u32 data); 76 77 /// Synchronizes fixed function renderer state with PICA registers. 78 void Sync(); 79 80 /// Returns a mutable reference to the renderer. 81 [[nodiscard]] VideoCore::RendererBase& Renderer(); 82 83 /// Returns a mutable reference to the PICA GPU. 84 [[nodiscard]] Pica::PicaCore& PicaCore(); 85 86 /// Returns an immutable reference to the PICA GPU. 87 [[nodiscard]] const Pica::PicaCore& PicaCore() const; 88 89 /// Returns a mutable reference to the pica debugging context. 90 [[nodiscard]] Pica::DebugContext& DebugContext(); 91 92 /// Returns a mutable reference to the GSP command debugger. 93 [[nodiscard]] GraphicsDebugger& Debugger(); 94 95 private: 96 void SubmitCmdList(u32 index); 97 98 void MemoryFill(u32 index); 99 100 void MemoryTransfer(); 101 102 void VBlankCallback(uintptr_t user_data, s64 cycles_late); 103 104 friend class boost::serialization::access; 105 template <class Archive> 106 void serialize(Archive& ar, const u32 file_version); 107 108 private: 109 struct Impl; 110 std::unique_ptr<Impl> impl; 111 112 PAddr VirtualToPhysicalAddress(VAddr addr); 113 }; 114 115 } // namespace VideoCore