CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/GPUInterface.h
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <list>
21
#include <string>
22
#include <vector>
23
24
#include "Common/Common.h"
25
#include "Common/Swap.h"
26
#include "GPU/GPU.h"
27
#include "Core/MemMap.h"
28
#include "GPU/ge_constants.h"
29
#include "GPU/Common/ShaderCommon.h"
30
31
struct PspGeListArgs;
32
struct GPUgstate;
33
class PointerWrap;
34
struct VirtualFramebuffer;
35
36
enum DisplayListStatus {
37
// The list has been completed
38
PSP_GE_LIST_COMPLETED = 0,
39
// The list is queued but not executed yet
40
PSP_GE_LIST_QUEUED = 1,
41
// The list is currently being executed
42
PSP_GE_LIST_DRAWING = 2,
43
// The list was stopped because it encountered stall address
44
PSP_GE_LIST_STALLING = 3,
45
// The list is paused because of a signal or sceGeBreak
46
PSP_GE_LIST_PAUSED = 4,
47
};
48
49
enum DisplayListState {
50
// No state assigned, the list is empty
51
PSP_GE_DL_STATE_NONE = 0,
52
// The list has been queued
53
PSP_GE_DL_STATE_QUEUED = 1,
54
// The list is being executed
55
PSP_GE_DL_STATE_RUNNING = 2,
56
// The list was completed and will be removed
57
PSP_GE_DL_STATE_COMPLETED = 3,
58
// The list has been paused by a signal
59
PSP_GE_DL_STATE_PAUSED = 4,
60
};
61
62
enum SignalBehavior {
63
PSP_GE_SIGNAL_NONE = 0x00,
64
PSP_GE_SIGNAL_HANDLER_SUSPEND = 0x01,
65
PSP_GE_SIGNAL_HANDLER_CONTINUE = 0x02,
66
PSP_GE_SIGNAL_HANDLER_PAUSE = 0x03,
67
PSP_GE_SIGNAL_SYNC = 0x08,
68
PSP_GE_SIGNAL_JUMP = 0x10,
69
PSP_GE_SIGNAL_CALL = 0x11,
70
PSP_GE_SIGNAL_RET = 0x12,
71
PSP_GE_SIGNAL_RJUMP = 0x13,
72
PSP_GE_SIGNAL_RCALL = 0x14,
73
PSP_GE_SIGNAL_OJUMP = 0x15,
74
PSP_GE_SIGNAL_OCALL = 0x16,
75
76
PSP_GE_SIGNAL_RTBP0 = 0x20,
77
PSP_GE_SIGNAL_RTBP1 = 0x21,
78
PSP_GE_SIGNAL_RTBP2 = 0x22,
79
PSP_GE_SIGNAL_RTBP3 = 0x23,
80
PSP_GE_SIGNAL_RTBP4 = 0x24,
81
PSP_GE_SIGNAL_RTBP5 = 0x25,
82
PSP_GE_SIGNAL_RTBP6 = 0x26,
83
PSP_GE_SIGNAL_RTBP7 = 0x27,
84
PSP_GE_SIGNAL_OTBP0 = 0x28,
85
PSP_GE_SIGNAL_OTBP1 = 0x29,
86
PSP_GE_SIGNAL_OTBP2 = 0x2A,
87
PSP_GE_SIGNAL_OTBP3 = 0x2B,
88
PSP_GE_SIGNAL_OTBP4 = 0x2C,
89
PSP_GE_SIGNAL_OTBP5 = 0x2D,
90
PSP_GE_SIGNAL_OTBP6 = 0x2E,
91
PSP_GE_SIGNAL_OTBP7 = 0x2F,
92
PSP_GE_SIGNAL_RCBP = 0x30,
93
PSP_GE_SIGNAL_OCBP = 0x38,
94
PSP_GE_SIGNAL_BREAK1 = 0xF0,
95
PSP_GE_SIGNAL_BREAK2 = 0xFF,
96
};
97
98
enum GPURunState {
99
GPUSTATE_RUNNING = 0,
100
GPUSTATE_DONE = 1,
101
GPUSTATE_STALL = 2,
102
GPUSTATE_INTERRUPT = 3,
103
GPUSTATE_ERROR = 4,
104
};
105
106
enum GPUSyncType {
107
GPU_SYNC_DRAW,
108
GPU_SYNC_LIST,
109
};
110
111
enum class WriteStencil {
112
NEEDS_CLEAR = 1,
113
STENCIL_IS_ZERO = 2,
114
IGNORE_ALPHA = 4,
115
};
116
ENUM_CLASS_BITOPS(WriteStencil);
117
118
enum class GPUCopyFlag {
119
NONE = 0,
120
FORCE_SRC_MATCH_MEM = 1,
121
FORCE_DST_MATCH_MEM = 2,
122
// Note: implies src == dst and FORCE_SRC_MATCH_MEM.
123
MEMSET = 4,
124
DEPTH_REQUESTED = 8,
125
DEBUG_NOTIFIED = 16,
126
DISALLOW_CREATE_VFB = 32,
127
};
128
ENUM_CLASS_BITOPS(GPUCopyFlag);
129
130
struct DisplayListStackEntry {
131
u32 pc;
132
u32 offsetAddr;
133
u32 baseAddr;
134
};
135
136
struct DisplayList {
137
int id;
138
u32 startpc;
139
u32 pc;
140
u32 stall;
141
DisplayListState state;
142
SignalBehavior signal;
143
int subIntrBase;
144
u16 subIntrToken;
145
DisplayListStackEntry stack[32];
146
int stackptr;
147
bool interrupted;
148
u64 waitTicks;
149
bool interruptsEnabled;
150
bool pendingInterrupt;
151
bool started;
152
PSPPointer<u32_le> context;
153
u32 offsetAddr;
154
bool bboxResult;
155
u32 stackAddr;
156
157
u32 padding; // Android x86-32 does not round the structure size up to the closest multiple of 8 like the other platforms.
158
};
159
160
enum GPUInvalidationType {
161
// Affects all memory. Not considered highly.
162
GPU_INVALIDATE_ALL,
163
// Indicates some memory may have changed.
164
GPU_INVALIDATE_HINT,
165
// Reliable invalidation (where any hashing, etc. is unneeded, it'll always invalidate.)
166
GPU_INVALIDATE_SAFE,
167
// Forced invalidation for when the texture hash may not catch changes.
168
GPU_INVALIDATE_FORCE,
169
};
170
171
namespace Draw {
172
class DrawContext;
173
}
174
175
class GPUInterface {
176
public:
177
virtual ~GPUInterface() {}
178
179
static const int DisplayListMaxCount = 64;
180
181
virtual Draw::DrawContext *GetDrawContext() = 0;
182
183
// Initialization
184
virtual bool IsStarted() = 0;
185
virtual void Reinitialize() = 0;
186
187
// Frame managment
188
virtual void BeginHostFrame() = 0;
189
virtual void EndHostFrame() = 0;
190
191
virtual void CheckDisplayResized() = 0;
192
virtual void CheckConfigChanged() = 0;
193
194
// Draw queue management
195
virtual DisplayList* getList(int listid) = 0;
196
// TODO: Much of this should probably be shared between the different GPU implementations.
197
virtual u32 EnqueueList(u32 listpc, u32 stall, int subIntrBase, PSPPointer<PspGeListArgs> args, bool head) = 0;
198
virtual u32 DequeueList(int listid) = 0;
199
virtual u32 UpdateStall(int listid, u32 newstall) = 0;
200
virtual u32 DrawSync(int mode) = 0;
201
virtual int ListSync(int listid, int mode) = 0;
202
virtual u32 Continue() = 0;
203
virtual u32 Break(int mode) = 0;
204
virtual int GetStack(int index, u32 stackPtr) = 0;
205
virtual bool GetMatrix24(GEMatrixType type, u32_le *result, u32 cmdbits) = 0;
206
virtual void ResetMatrices() = 0;
207
virtual uint32_t SetAddrTranslation(uint32_t value) = 0;
208
209
virtual void InterruptStart(int listid) = 0;
210
virtual void InterruptEnd(int listid) = 0;
211
virtual void SyncEnd(GPUSyncType waitType, int listid, bool wokeThreads) = 0;
212
213
virtual void ExecuteOp(u32 op, u32 diff) = 0;
214
215
// Framebuffer management
216
virtual void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) = 0;
217
virtual void PSPFrame() = 0;
218
virtual void CopyDisplayToOutput(bool reallyDirty) = 0;
219
220
// Tells the GPU to update the gpuStats structure.
221
virtual void GetStats(char *buffer, size_t bufsize) = 0;
222
223
// Invalidate any cached content sourced from the specified range.
224
// If size = -1, invalidate everything.
225
virtual void InvalidateCache(u32 addr, int size, GPUInvalidationType type) = 0;
226
// Clear caches, update hardware framebuffers, or similar based on written pixels of known format (typically video.)
227
virtual void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat format) = 0;
228
// Update either RAM from VRAM, or VRAM from RAM... or even VRAM from VRAM.
229
virtual bool PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags = GPUCopyFlag::NONE) = 0;
230
virtual bool PerformMemorySet(u32 dest, u8 v, int size) = 0;
231
// Update PSP memory with render results.
232
virtual bool PerformReadbackToMemory(u32 dest, int size) = 0;
233
// Update rendering data (i.e. hardware framebuffers) with data in PSP memory. Format unspecified.
234
virtual bool PerformWriteColorFromMemory(u32 dest, int size) = 0;
235
virtual bool PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil flags = WriteStencil::NEEDS_CLEAR) = 0;
236
237
// Will cause the texture cache to be cleared at the start of the next frame.
238
virtual void ClearCacheNextFrame() = 0;
239
240
// Internal hack to avoid interrupts from "PPGe" drawing (utility UI, etc)
241
virtual void EnableInterrupts(bool enable) = 0;
242
243
virtual void DeviceLost() = 0;
244
virtual void DeviceRestore(Draw::DrawContext *draw) = 0;
245
virtual void ReapplyGfxState() = 0;
246
virtual void DoState(PointerWrap &p) = 0;
247
248
// Called by the window system if the window size changed. This will be reflected in PSPCoreParam.pixel*.
249
virtual void NotifyDisplayResized() = 0;
250
virtual void NotifyRenderResized() = 0;
251
virtual void NotifyConfigChanged() = 0;
252
253
virtual bool FramebufferDirty() = 0;
254
virtual bool FramebufferReallyDirty() = 0;
255
virtual bool BusyDrawing() = 0;
256
virtual bool PresentedThisFrame() const = 0;
257
258
// If any jit is being used inside the GPU.
259
virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) = 0;
260
261
// Debugging
262
virtual void DumpNextFrame() = 0;
263
virtual void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) = 0;
264
virtual const std::list<int>& GetDisplayLists() = 0;
265
// TODO: Currently Qt only, needs to be cleaned up.
266
virtual std::vector<const VirtualFramebuffer *> GetFramebufferList() const = 0;
267
virtual s64 GetListTicks(int listid) const = 0;
268
269
// For debugging. The IDs returned are opaque, do not poke in them or display them in any way.
270
virtual std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) = 0;
271
virtual std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) = 0;
272
};
273
274