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/Software/SoftGpu.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 <cstdint>
21
#include "GPU/GPUCommon.h"
22
#include "GPU/Common/GPUDebugInterface.h"
23
#include "Common/GPU/thin3d.h"
24
25
struct FormatBuffer {
26
FormatBuffer() { data = nullptr; }
27
union {
28
u8 *data;
29
u16 *as16;
30
u32 *as32;
31
};
32
33
inline void Set16(int x, int y, int stride, u16 v) const {
34
as16[x + y * stride] = v;
35
}
36
37
inline void Set32(int x, int y, int stride, u32 v) const {
38
as32[x + y * stride] = v;
39
}
40
41
inline u16 Get16(int x, int y, int stride) const {
42
return as16[x + y * stride];
43
}
44
45
inline u32 Get32(int x, int y, int stride) const {
46
return as32[x + y * stride];
47
}
48
49
inline u16 *Get16Ptr(int x, int y, int stride) const {
50
return &as16[x + y * stride];
51
}
52
53
inline u32 *Get32Ptr(int x, int y, int stride) const {
54
return &as32[x + y * stride];
55
}
56
};
57
58
enum class SoftDirty : uint64_t {
59
NONE = 0,
60
61
PIXEL_BASIC = 1ULL << 0,
62
PIXEL_STENCIL = 1ULL << 1,
63
PIXEL_ALPHA = 1ULL << 2,
64
PIXEL_DITHER = 1ULL << 3,
65
PIXEL_WRITEMASK = 1ULL << 4,
66
PIXEL_CACHED = 1ULL << 5,
67
PIXEL_ALL = 0b111111ULL << 0,
68
69
SAMPLER_BASIC = 1ULL << 6,
70
SAMPLER_TEXLIST = 1ULL << 7,
71
SAMPLER_CLUT = 1ULL << 8,
72
SAMPLER_ALL = 0b111ULL << 6,
73
74
RAST_BASIC = 1ULL << 9,
75
RAST_TEX = 1ULL << 10,
76
RAST_OFFSET = 1ULL << 11,
77
RAST_ALL = 0b111ULL << 9,
78
79
LIGHT_BASIC = 1ULL << 12,
80
LIGHT_MATERIAL = 1ULL << 13,
81
LIGHT_0 = 1ULL << 14,
82
LIGHT_1 = 1ULL << 15,
83
LIGHT_2 = 1ULL << 16,
84
LIGHT_3 = 1ULL << 17,
85
LIGHT_ALL = 0b111111ULL << 12,
86
87
TRANSFORM_BASIC = 1ULL << 18,
88
TRANSFORM_MATRIX = 1ULL << 19,
89
TRANSFORM_VIEWPORT = 1ULL << 20,
90
TRANSFORM_FOG = 1ULL << 21,
91
TRANSFORM_ALL = 0b1111ULL << 18,
92
93
BINNER_RANGE = 1ULL << 22,
94
BINNER_OVERLAP = 1ULL << 23,
95
};
96
static inline SoftDirty operator |(const SoftDirty &lhs, const SoftDirty &rhs) {
97
return SoftDirty((uint64_t)lhs | (uint64_t)rhs);
98
}
99
static inline SoftDirty &operator |=(SoftDirty &lhs, const SoftDirty &rhs) {
100
lhs = lhs | rhs;
101
return lhs;
102
}
103
static inline bool operator &(const SoftDirty &lhs, const SoftDirty &rhs) {
104
return ((uint64_t)lhs & (uint64_t)rhs) != 0;
105
}
106
static inline SoftDirty &operator &=(SoftDirty &lhs, const SoftDirty &rhs) {
107
lhs = SoftDirty((uint64_t)lhs & (uint64_t)rhs);
108
return lhs;
109
}
110
static inline SoftDirty operator ~(const SoftDirty &v) {
111
return SoftDirty(~(uint64_t)v);
112
}
113
114
class PresentationCommon;
115
class SoftwareDrawEngine;
116
117
enum class SoftGPUVRAMDirty : uint8_t {
118
CLEAR = 0,
119
DIRTY = 1,
120
REALLY_DIRTY = 2,
121
};
122
123
ENUM_CLASS_BITOPS(SoftGPUVRAMDirty);
124
125
class SoftGPU : public GPUCommon {
126
public:
127
SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw);
128
~SoftGPU();
129
130
u32 CheckGPUFeatures() const override { return 0; }
131
bool IsStarted() override;
132
void ExecuteOp(u32 op, u32 diff) override;
133
void FinishDeferred() override;
134
int ListSync(int listid, int mode) override;
135
u32 DrawSync(int mode) override;
136
void UpdateCmdInfo() override {}
137
138
void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override;
139
void CopyDisplayToOutput(bool reallyDirty) override;
140
void GetStats(char *buffer, size_t bufsize) override;
141
std::vector<const VirtualFramebuffer *> GetFramebufferList() const override { return std::vector<const VirtualFramebuffer *>(); }
142
void InvalidateCache(u32 addr, int size, GPUInvalidationType type) override;
143
void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat format) override;
144
bool PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags = GPUCopyFlag::NONE) override;
145
bool PerformMemorySet(u32 dest, u8 v, int size) override;
146
bool PerformReadbackToMemory(u32 dest, int size) override;
147
bool PerformWriteColorFromMemory(u32 dest, int size) override;
148
bool PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil flags) override;
149
150
void DeviceLost() override;
151
void DeviceRestore(Draw::DrawContext *draw) override;
152
153
void NotifyRenderResized() override;
154
void NotifyDisplayResized() override;
155
156
void CheckDisplayResized() override;
157
void CheckConfigChanged() override;
158
159
void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) override {
160
primaryInfo = "Software";
161
fullInfo = "Software";
162
}
163
164
bool FramebufferDirty() override;
165
bool FramebufferReallyDirty() override;
166
167
bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes = -1) override;
168
bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;
169
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) override;
170
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override;
171
bool GetCurrentTexture(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override;
172
bool GetCurrentClut(GPUDebugBuffer &buffer) override;
173
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) override;
174
175
bool DescribeCodePtr(const u8 *ptr, std::string &name) override;
176
177
void Execute_BlockTransferStart(u32 op, u32 diff);
178
void Execute_Prim(u32 op, u32 diff);
179
void Execute_Bezier(u32 op, u32 diff);
180
void Execute_Spline(u32 op, u32 diff);
181
void Execute_LoadClut(u32 op, u32 diff);
182
void Execute_FramebufPtr(u32 op, u32 diff);
183
void Execute_FramebufFormat(u32 op, u32 diff);
184
void Execute_ZbufPtr(u32 op, u32 diff);
185
void Execute_VertexType(u32 op, u32 diff);
186
187
// Overridden to change flushing behavior.
188
void Execute_Call(u32 op, u32 diff);
189
190
// Overridden for a dirty flag change.
191
void Execute_BoundingBox(u32 op, u32 diff);
192
193
void Execute_WorldMtxNum(u32 op, u32 diff);
194
void Execute_ViewMtxNum(u32 op, u32 diff);
195
void Execute_ProjMtxNum(u32 op, u32 diff);
196
void Execute_TgenMtxNum(u32 op, u32 diff);
197
void Execute_BoneMtxNum(u32 op, u32 diff);
198
199
void Execute_WorldMtxData(u32 op, u32 diff);
200
void Execute_ViewMtxData(u32 op, u32 diff);
201
void Execute_ProjMtxData(u32 op, u32 diff);
202
void Execute_TgenMtxData(u32 op, u32 diff);
203
void Execute_BoneMtxData(u32 op, u32 diff);
204
205
bool GetMatrix24(GEMatrixType type, u32_le *result, u32 cmdbits) override;
206
void ResetMatrices() override;
207
208
void Execute_ImmVertexAlphaPrim(u32 op, u32 diff);
209
210
typedef void (SoftGPU::*CmdFunc)(u32 op, u32 diff);
211
212
protected:
213
void FastRunLoop(DisplayList &list) override;
214
void CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight);
215
void ConvertTextureDescFrom16(Draw::TextureDesc &desc, int srcwidth, int srcheight, const uint16_t *overrideData = nullptr);
216
217
void BuildReportingInfo() override {}
218
219
private:
220
void MarkDirty(uint32_t addr, uint32_t stride, uint32_t height, GEBufferFormat fmt, SoftGPUVRAMDirty value);
221
void MarkDirty(uint32_t addr, uint32_t bytes, SoftGPUVRAMDirty value);
222
bool ClearDirty(uint32_t addr, uint32_t stride, uint32_t height, GEBufferFormat fmt, SoftGPUVRAMDirty value);
223
bool ClearDirty(uint32_t addr, uint32_t bytes, SoftGPUVRAMDirty value);
224
225
uint8_t vramDirty_[2048];
226
uint32_t lastDirtyAddr_ = 0;
227
uint32_t lastDirtySize_ = 0;
228
SoftGPUVRAMDirty lastDirtyValue_ = SoftGPUVRAMDirty::CLEAR;
229
230
u32 displayFramebuf_;
231
u32 displayStride_;
232
GEBufferFormat displayFormat_;
233
SoftDirty dirtyFlags_ = SoftDirty(-1);
234
235
PresentationCommon *presentation_ = nullptr;
236
SoftwareDrawEngine *drawEngine_ = nullptr;
237
238
Draw::Texture *fbTex = nullptr;
239
std::vector<u32> fbTexBuffer_;
240
};
241
242
// TODO: These shouldn't be global.
243
extern uint8_t clut[1024];
244
extern FormatBuffer fb;
245
extern FormatBuffer depthbuf;
246
247
// Type for the DarkStalkers stretch replacement.
248
enum class DSStretch {
249
Off = 0,
250
Normal,
251
Wide,
252
};
253
254