CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/GPUInterface.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <list>20#include <string>21#include <vector>2223#include "Common/Common.h"24#include "Common/Swap.h"25#include "GPU/GPU.h"26#include "Core/MemMap.h"27#include "GPU/ge_constants.h"28#include "GPU/Common/ShaderCommon.h"2930struct PspGeListArgs;31struct GPUgstate;32class PointerWrap;33struct VirtualFramebuffer;3435enum DisplayListStatus {36// The list has been completed37PSP_GE_LIST_COMPLETED = 0,38// The list is queued but not executed yet39PSP_GE_LIST_QUEUED = 1,40// The list is currently being executed41PSP_GE_LIST_DRAWING = 2,42// The list was stopped because it encountered stall address43PSP_GE_LIST_STALLING = 3,44// The list is paused because of a signal or sceGeBreak45PSP_GE_LIST_PAUSED = 4,46};4748enum DisplayListState {49// No state assigned, the list is empty50PSP_GE_DL_STATE_NONE = 0,51// The list has been queued52PSP_GE_DL_STATE_QUEUED = 1,53// The list is being executed54PSP_GE_DL_STATE_RUNNING = 2,55// The list was completed and will be removed56PSP_GE_DL_STATE_COMPLETED = 3,57// The list has been paused by a signal58PSP_GE_DL_STATE_PAUSED = 4,59};6061enum SignalBehavior {62PSP_GE_SIGNAL_NONE = 0x00,63PSP_GE_SIGNAL_HANDLER_SUSPEND = 0x01,64PSP_GE_SIGNAL_HANDLER_CONTINUE = 0x02,65PSP_GE_SIGNAL_HANDLER_PAUSE = 0x03,66PSP_GE_SIGNAL_SYNC = 0x08,67PSP_GE_SIGNAL_JUMP = 0x10,68PSP_GE_SIGNAL_CALL = 0x11,69PSP_GE_SIGNAL_RET = 0x12,70PSP_GE_SIGNAL_RJUMP = 0x13,71PSP_GE_SIGNAL_RCALL = 0x14,72PSP_GE_SIGNAL_OJUMP = 0x15,73PSP_GE_SIGNAL_OCALL = 0x16,7475PSP_GE_SIGNAL_RTBP0 = 0x20,76PSP_GE_SIGNAL_RTBP1 = 0x21,77PSP_GE_SIGNAL_RTBP2 = 0x22,78PSP_GE_SIGNAL_RTBP3 = 0x23,79PSP_GE_SIGNAL_RTBP4 = 0x24,80PSP_GE_SIGNAL_RTBP5 = 0x25,81PSP_GE_SIGNAL_RTBP6 = 0x26,82PSP_GE_SIGNAL_RTBP7 = 0x27,83PSP_GE_SIGNAL_OTBP0 = 0x28,84PSP_GE_SIGNAL_OTBP1 = 0x29,85PSP_GE_SIGNAL_OTBP2 = 0x2A,86PSP_GE_SIGNAL_OTBP3 = 0x2B,87PSP_GE_SIGNAL_OTBP4 = 0x2C,88PSP_GE_SIGNAL_OTBP5 = 0x2D,89PSP_GE_SIGNAL_OTBP6 = 0x2E,90PSP_GE_SIGNAL_OTBP7 = 0x2F,91PSP_GE_SIGNAL_RCBP = 0x30,92PSP_GE_SIGNAL_OCBP = 0x38,93PSP_GE_SIGNAL_BREAK1 = 0xF0,94PSP_GE_SIGNAL_BREAK2 = 0xFF,95};9697enum GPURunState {98GPUSTATE_RUNNING = 0,99GPUSTATE_DONE = 1,100GPUSTATE_STALL = 2,101GPUSTATE_INTERRUPT = 3,102GPUSTATE_ERROR = 4,103};104105enum GPUSyncType {106GPU_SYNC_DRAW,107GPU_SYNC_LIST,108};109110enum class WriteStencil {111NEEDS_CLEAR = 1,112STENCIL_IS_ZERO = 2,113IGNORE_ALPHA = 4,114};115ENUM_CLASS_BITOPS(WriteStencil);116117enum class GPUCopyFlag {118NONE = 0,119FORCE_SRC_MATCH_MEM = 1,120FORCE_DST_MATCH_MEM = 2,121// Note: implies src == dst and FORCE_SRC_MATCH_MEM.122MEMSET = 4,123DEPTH_REQUESTED = 8,124DEBUG_NOTIFIED = 16,125DISALLOW_CREATE_VFB = 32,126};127ENUM_CLASS_BITOPS(GPUCopyFlag);128129struct DisplayListStackEntry {130u32 pc;131u32 offsetAddr;132u32 baseAddr;133};134135struct DisplayList {136int id;137u32 startpc;138u32 pc;139u32 stall;140DisplayListState state;141SignalBehavior signal;142int subIntrBase;143u16 subIntrToken;144DisplayListStackEntry stack[32];145int stackptr;146bool interrupted;147u64 waitTicks;148bool interruptsEnabled;149bool pendingInterrupt;150bool started;151PSPPointer<u32_le> context;152u32 offsetAddr;153bool bboxResult;154u32 stackAddr;155156u32 padding; // Android x86-32 does not round the structure size up to the closest multiple of 8 like the other platforms.157};158159enum GPUInvalidationType {160// Affects all memory. Not considered highly.161GPU_INVALIDATE_ALL,162// Indicates some memory may have changed.163GPU_INVALIDATE_HINT,164// Reliable invalidation (where any hashing, etc. is unneeded, it'll always invalidate.)165GPU_INVALIDATE_SAFE,166// Forced invalidation for when the texture hash may not catch changes.167GPU_INVALIDATE_FORCE,168};169170namespace Draw {171class DrawContext;172}173174class GPUInterface {175public:176virtual ~GPUInterface() {}177178static const int DisplayListMaxCount = 64;179180virtual Draw::DrawContext *GetDrawContext() = 0;181182// Initialization183virtual bool IsStarted() = 0;184virtual void Reinitialize() = 0;185186// Frame managment187virtual void BeginHostFrame() = 0;188virtual void EndHostFrame() = 0;189190virtual void CheckDisplayResized() = 0;191virtual void CheckConfigChanged() = 0;192193// Draw queue management194virtual DisplayList* getList(int listid) = 0;195// TODO: Much of this should probably be shared between the different GPU implementations.196virtual u32 EnqueueList(u32 listpc, u32 stall, int subIntrBase, PSPPointer<PspGeListArgs> args, bool head) = 0;197virtual u32 DequeueList(int listid) = 0;198virtual u32 UpdateStall(int listid, u32 newstall) = 0;199virtual u32 DrawSync(int mode) = 0;200virtual int ListSync(int listid, int mode) = 0;201virtual u32 Continue() = 0;202virtual u32 Break(int mode) = 0;203virtual int GetStack(int index, u32 stackPtr) = 0;204virtual bool GetMatrix24(GEMatrixType type, u32_le *result, u32 cmdbits) = 0;205virtual void ResetMatrices() = 0;206virtual uint32_t SetAddrTranslation(uint32_t value) = 0;207208virtual void InterruptStart(int listid) = 0;209virtual void InterruptEnd(int listid) = 0;210virtual void SyncEnd(GPUSyncType waitType, int listid, bool wokeThreads) = 0;211212virtual void ExecuteOp(u32 op, u32 diff) = 0;213214// Framebuffer management215virtual void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) = 0;216virtual void PSPFrame() = 0;217virtual void CopyDisplayToOutput(bool reallyDirty) = 0;218219// Tells the GPU to update the gpuStats structure.220virtual void GetStats(char *buffer, size_t bufsize) = 0;221222// Invalidate any cached content sourced from the specified range.223// If size = -1, invalidate everything.224virtual void InvalidateCache(u32 addr, int size, GPUInvalidationType type) = 0;225// Clear caches, update hardware framebuffers, or similar based on written pixels of known format (typically video.)226virtual void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat format) = 0;227// Update either RAM from VRAM, or VRAM from RAM... or even VRAM from VRAM.228virtual bool PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags = GPUCopyFlag::NONE) = 0;229virtual bool PerformMemorySet(u32 dest, u8 v, int size) = 0;230// Update PSP memory with render results.231virtual bool PerformReadbackToMemory(u32 dest, int size) = 0;232// Update rendering data (i.e. hardware framebuffers) with data in PSP memory. Format unspecified.233virtual bool PerformWriteColorFromMemory(u32 dest, int size) = 0;234virtual bool PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil flags = WriteStencil::NEEDS_CLEAR) = 0;235236// Will cause the texture cache to be cleared at the start of the next frame.237virtual void ClearCacheNextFrame() = 0;238239// Internal hack to avoid interrupts from "PPGe" drawing (utility UI, etc)240virtual void EnableInterrupts(bool enable) = 0;241242virtual void DeviceLost() = 0;243virtual void DeviceRestore(Draw::DrawContext *draw) = 0;244virtual void ReapplyGfxState() = 0;245virtual void DoState(PointerWrap &p) = 0;246247// Called by the window system if the window size changed. This will be reflected in PSPCoreParam.pixel*.248virtual void NotifyDisplayResized() = 0;249virtual void NotifyRenderResized() = 0;250virtual void NotifyConfigChanged() = 0;251252virtual bool FramebufferDirty() = 0;253virtual bool FramebufferReallyDirty() = 0;254virtual bool BusyDrawing() = 0;255virtual bool PresentedThisFrame() const = 0;256257// If any jit is being used inside the GPU.258virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) = 0;259260// Debugging261virtual void DumpNextFrame() = 0;262virtual void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) = 0;263virtual const std::list<int>& GetDisplayLists() = 0;264// TODO: Currently Qt only, needs to be cleaned up.265virtual std::vector<const VirtualFramebuffer *> GetFramebufferList() const = 0;266virtual s64 GetListTicks(int listid) const = 0;267268// For debugging. The IDs returned are opaque, do not poke in them or display them in any way.269virtual std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) = 0;270virtual std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) = 0;271};272273274