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