forked from melonDS-emu/melonDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPU3D_Compute.h
242 lines (178 loc) · 5.93 KB
/
GPU3D_Compute.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
Copyright 2016-2022 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#ifndef GPU3D_COMPUTE
#define GPU3D_COMPUTE
#include <memory>
#include "types.h"
#include "GPU3D.h"
#include "OpenGLSupport.h"
#include "GPU_OpenGL.h"
#include "GPU3D_TexcacheOpenGL.h"
#include "NonStupidBitfield.h"
namespace melonDS
{
class ComputeRenderer : public Renderer3D
{
public:
static std::unique_ptr<ComputeRenderer> New();
~ComputeRenderer() override;
void Reset(GPU& gpu) override;
void SetRenderSettings(int scale, bool highResolutionCoordinates);
void VCount144(GPU& gpu) override;
void RenderFrame(GPU& gpu) override;
void RestartFrame(GPU& gpu) override;
u32* GetLine(int line) override;
void SetupAccelFrame() override;
void PrepareCaptureFrame() override;
void BindOutputTexture(int buffer) override;
void Blit(const GPU& gpu) override;
void Stop(const GPU& gpu) override;
bool NeedsShaderCompile() { return ShaderStepIdx != 33; }
void ShaderCompileStep(int& current, int& count) override;
private:
ComputeRenderer(GLCompositor&& compositor);
GLuint ShaderInterpXSpans[2];
GLuint ShaderBinCombined;
GLuint ShaderDepthBlend[2];
GLuint ShaderRasteriseNoTexture[2];
GLuint ShaderRasteriseNoTextureToon[2];
GLuint ShaderRasteriseNoTextureHighlight[2];
GLuint ShaderRasteriseUseTextureDecal[2];
GLuint ShaderRasteriseUseTextureModulate[2];
GLuint ShaderRasteriseUseTextureToon[2];
GLuint ShaderRasteriseUseTextureHighlight[2];
GLuint ShaderRasteriseShadowMask[2];
GLuint ShaderClearCoarseBinMask;
GLuint ShaderClearIndirectWorkCount;
GLuint ShaderCalculateWorkListOffset;
GLuint ShaderSortWork;
GLuint ShaderFinalPass[8];
GLuint YSpanIndicesTextureMemory;
GLuint YSpanIndicesTexture;
GLuint YSpanSetupMemory;
GLuint XSpanSetupMemory;
GLuint BinResultMemory;
GLuint RenderPolygonMemory;
GLuint WorkDescMemory;
enum
{
tilememoryLayer_Color,
tilememoryLayer_Depth,
tilememoryLayer_Attr,
tilememoryLayer_Num,
};
GLuint TileMemory[tilememoryLayer_Num];
GLuint FinalTileMemory;
u32 DummyLine[256] = {};
struct SpanSetupY
{
// Attributes
s32 Z0, Z1, W0, W1;
s32 ColorR0, ColorG0, ColorB0;
s32 ColorR1, ColorG1, ColorB1;
s32 TexcoordU0, TexcoordV0;
s32 TexcoordU1, TexcoordV1;
// Interpolator
s32 I0, I1;
s32 Linear;
s32 IRecip;
s32 W0n, W0d, W1d;
// Slope
s32 Increment;
s32 X0, X1, Y0, Y1;
s32 XMin, XMax;
s32 DxInitial;
s32 XCovIncr;
u32 IsDummy;
};
struct SpanSetupX
{
s32 X0, X1;
s32 EdgeLenL, EdgeLenR, EdgeCovL, EdgeCovR;
s32 XRecip;
u32 Flags;
s32 Z0, Z1, W0, W1;
s32 ColorR0, ColorG0, ColorB0;
s32 ColorR1, ColorG1, ColorB1;
s32 TexcoordU0, TexcoordV0;
s32 TexcoordU1, TexcoordV1;
s32 CovLInitial, CovRInitial;
};
struct SetupIndices
{
u16 PolyIdx, SpanIdxL, SpanIdxR, Y;
};
struct RenderPolygon
{
u32 FirstXSpan;
s32 YTop, YBot;
s32 XMin, XMax;
s32 XMinY, XMaxY;
u32 Variant;
u32 Attr;
float TextureLayer;
};
static constexpr int TileSize = 8;
static constexpr int CoarseTileCountX = 8;
static constexpr int CoarseTileCountY = 4;
static constexpr int CoarseTileW = CoarseTileCountX * TileSize;
static constexpr int CoarseTileH = CoarseTileCountY * TileSize;
static constexpr int BinStride = 2048/32;
static constexpr int CoarseBinStride = BinStride/32;
static constexpr int MaxVariants = 256;
static constexpr int UniformIdxCurVariant = 0;
static constexpr int UniformIdxTextureSize = 1;
static constexpr int MaxFullscreenLayers = 16;
struct BinResultHeader
{
u32 VariantWorkCount[MaxVariants*4];
u32 SortedWorkOffset[MaxVariants];
u32 SortWorkWorkCount[4];
};
static const int MaxYSpanSetups = 6144*2;
std::vector<SetupIndices> YSpanIndices;
SpanSetupY YSpanSetups[MaxYSpanSetups];
RenderPolygon RenderPolygons[2048];
TexcacheOpenGL Texcache;
struct MetaUniform
{
u32 NumPolygons;
u32 NumVariants;
u32 AlphaRef;
u32 DispCnt;
u32 ToonTable[4*34];
u32 ClearColor, ClearDepth, ClearAttr;
u32 FogOffset, FogShift, FogColor;
};
GLuint MetaUniformMemory;
GLuint Samplers[9];
GLuint Framebuffer = 0;
GLuint LowResFramebuffer;
GLuint PixelBuffer;
u32 FramebufferCPU[256*192];
int ScreenWidth, ScreenHeight;
int TilesPerLine, TileLines;
int ScaleFactor = -1;
int MaxWorkTiles;
bool HiresCoordinates;
GLCompositor CurGLCompositor;
int ShaderStepIdx = 0;
void DeleteShaders();
void SetupAttrs(SpanSetupY* span, Polygon* poly, int from, int to);
void SetupYSpan(RenderPolygon* rp, SpanSetupY* span, Polygon* poly, int from, int to, int side, s32 positions[10][2]);
void SetupYSpanDummy(RenderPolygon* rp, SpanSetupY* span, Polygon* poly, int vertex, int side, s32 positions[10][2]);
bool CompileShader(GLuint& shader, const std::string& source, const std::initializer_list<const char*>& defines);
};
}
#endif