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/FuncId.h
Views: 1401
1
// Copyright (c) 2021- 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 <algorithm>
21
#include <cstdint>
22
#include <functional>
23
24
#include "GPU/ge_constants.h"
25
26
// 0-10 match GEBlendSrcFactor/GEBlendDstFactor.
27
enum class PixelBlendFactor {
28
OTHERCOLOR,
29
INVOTHERCOLOR,
30
SRCALPHA,
31
INVSRCALPHA,
32
DSTALPHA,
33
INVDSTALPHA,
34
DOUBLESRCALPHA,
35
DOUBLEINVSRCALPHA,
36
DOUBLEDSTALPHA,
37
DOUBLEINVDSTALPHA,
38
FIX,
39
// These are invented, but common FIX values.
40
ZERO,
41
ONE,
42
};
43
44
#pragma pack(push, 1)
45
46
struct PixelFuncID {
47
PixelFuncID() {
48
}
49
50
struct {
51
// Warning: these are not hashed or compared for equal. Just cached values.
52
uint32_t colorWriteMask{};
53
int8_t ditherMatrix[16]{};
54
uint32_t fogColor;
55
int minz;
56
int maxz;
57
uint16_t framebufStride;
58
uint16_t depthbufStride;
59
GELogicOp logicOp;
60
uint8_t stencilRef;
61
uint8_t stencilTestMask;
62
uint8_t alphaTestMask;
63
GEComparison colorTestFunc;
64
uint32_t colorTestMask;
65
uint32_t colorTestRef;
66
uint32_t alphaBlendSrc;
67
uint32_t alphaBlendDst;
68
} cached;
69
70
union {
71
uint64_t fullKey{};
72
struct {
73
bool clearMode : 1;
74
// Reused as ColorClear.
75
bool colorTest : 1;
76
// Reused as StencilClear.
77
bool stencilTest : 1;
78
// Reused as DepthClear.
79
bool depthWrite : 1;
80
bool applyDepthRange : 1;
81
// If alpha testing is disabled, set to GE_COMP_ALWAYS.
82
uint8_t alphaTestFunc : 3;
83
// If depth testing is disabled, set to GE_COMP_ALWAYS.
84
uint8_t depthTestFunc : 3;
85
uint8_t stencilTestFunc : 3;
86
uint8_t fbFormat : 2;
87
// 16 bits before alphaTestRef.
88
uint8_t alphaTestRef : 8;
89
uint8_t stencilTestRef : 8;
90
// 32 bits before alphaBlend.
91
bool alphaBlend : 1;
92
uint8_t alphaBlendEq : 3;
93
uint8_t alphaBlendSrc : 4;
94
uint8_t alphaBlendDst : 4;
95
// Meaning: alphaTestMask != 0xFF
96
bool hasAlphaTestMask : 1;
97
// Meaning: stencilTestMask != 0xFF
98
bool hasStencilTestMask : 1;
99
bool dithering : 1;
100
bool applyLogicOp : 1;
101
// 48 bits before applyFog.
102
bool applyFog : 1;
103
// Meaning: fb_stride == 512 && z_stride == 512
104
bool useStandardStride : 1;
105
// Meaning: maskRGB != 0 || maskA != 0
106
bool applyColorWriteMask : 1;
107
uint8_t sFail : 3;
108
uint8_t zFail : 3;
109
uint8_t zPass : 3;
110
bool earlyZChecks : 1;
111
// 61 bits, 3 free.
112
};
113
};
114
115
bool ColorClear() const {
116
return colorTest;
117
}
118
bool StencilClear() const {
119
return stencilTest;
120
}
121
bool DepthClear() const {
122
return depthWrite;
123
}
124
125
GEComparison AlphaTestFunc() const {
126
return GEComparison(alphaTestFunc);
127
}
128
GEComparison DepthTestFunc() const {
129
return GEComparison(depthTestFunc);
130
}
131
GEComparison StencilTestFunc() const {
132
return GEComparison(stencilTestFunc);
133
}
134
135
GEBufferFormat FBFormat() const {
136
return GEBufferFormat(fbFormat);
137
}
138
139
GEBlendMode AlphaBlendEq() const {
140
return GEBlendMode(alphaBlendEq);
141
}
142
PixelBlendFactor AlphaBlendSrc() const {
143
return PixelBlendFactor(alphaBlendSrc);
144
}
145
PixelBlendFactor AlphaBlendDst() const {
146
return PixelBlendFactor(alphaBlendDst);
147
}
148
149
GEStencilOp SFail() const {
150
return GEStencilOp(sFail);
151
}
152
GEStencilOp ZFail() const {
153
return GEStencilOp(zFail);
154
}
155
GEStencilOp ZPass() const {
156
return GEStencilOp(zPass);
157
}
158
159
bool operator == (const PixelFuncID &other) const {
160
return fullKey == other.fullKey;
161
}
162
};
163
164
#pragma pack(pop)
165
166
struct SamplerID {
167
SamplerID() : fullKey(0) {
168
}
169
170
struct {
171
struct {
172
uint16_t w;
173
uint16_t h;
174
} sizes[8];
175
uint32_t texBlendColor;
176
uint32_t clutFormat;
177
union {
178
const uint8_t *clut;
179
const uint16_t *clut16;
180
const uint32_t *clut32;
181
};
182
} cached;
183
184
uint32_t pad;
185
186
union {
187
uint32_t fullKey;
188
struct {
189
uint8_t texfmt : 4;
190
uint8_t clutfmt : 2;
191
bool clampS : 1;
192
bool clampT : 1;
193
bool swizzle : 1;
194
bool useSharedClut : 1;
195
bool hasClutMask : 1;
196
bool hasClutShift : 1;
197
bool hasClutOffset : 1;
198
bool hasInvalidPtr : 1;
199
bool overReadSafe : 1;
200
bool useStandardBufw : 1;
201
uint8_t width0Shift : 4;
202
uint8_t height0Shift : 4;
203
uint8_t texFunc : 3;
204
bool useTextureAlpha : 1;
205
bool useColorDoubling : 1;
206
bool hasAnyMips : 1;
207
bool linear : 1;
208
bool fetch : 1;
209
};
210
};
211
212
GETextureFormat TexFmt() const {
213
return GETextureFormat(texfmt);
214
}
215
216
GEPaletteFormat ClutFmt() const {
217
return GEPaletteFormat(clutfmt);
218
}
219
220
GETexFunc TexFunc() const {
221
return GETexFunc(texFunc);
222
}
223
224
bool operator == (const SamplerID &other) const {
225
return fullKey == other.fullKey;
226
}
227
};
228
229
namespace std {
230
231
template <>
232
struct hash<PixelFuncID> {
233
std::size_t operator()(const PixelFuncID &k) const {
234
return hash<uint64_t>()(k.fullKey);
235
}
236
};
237
238
template <>
239
struct hash<SamplerID> {
240
std::size_t operator()(const SamplerID &k) const {
241
return hash<uint32_t>()(k.fullKey);
242
}
243
};
244
245
};
246
247
void ComputePixelFuncID(PixelFuncID *id);
248
std::string DescribePixelFuncID(const PixelFuncID &id);
249
250
void ComputeSamplerID(SamplerID *id);
251
std::string DescribeSamplerID(const SamplerID &id);
252
253