Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/Shader.cpp
3187 views
1
#include "Common/GPU/Shader.h"
2
3
#ifdef USE_CRT_DBG
4
#undef new
5
#endif
6
7
#include "ext/glslang/SPIRV/GlslangToSpv.h"
8
9
const char *ShaderLanguageAsString(ShaderLanguage lang) {
10
switch (lang) {
11
case GLSL_1xx: return "GLSL 1.x";
12
case GLSL_3xx: return "GLSL 3.x";
13
case GLSL_VULKAN: return "GLSL-VK";
14
case HLSL_D3D11: return "HLSL-D3D11";
15
default: return "(combination)";
16
}
17
}
18
19
const char *ShaderStageAsString(ShaderStage stage) {
20
switch (stage) {
21
case ShaderStage::Fragment: return "Fragment";
22
case ShaderStage::Vertex: return "Vertex";
23
case ShaderStage::Geometry: return "Geometry";
24
case ShaderStage::Compute: return "Compute";
25
default: return "(unknown)";
26
}
27
}
28
29
ShaderLanguageDesc::ShaderLanguageDesc(ShaderLanguage lang) {
30
Init(lang);
31
}
32
33
void ShaderLanguageDesc::Init(ShaderLanguage lang) {
34
shaderLanguage = lang;
35
strcpy(driverInfo, "");
36
switch (lang) {
37
case GLSL_1xx:
38
// Just used in the shader test, and as a basis for the others in DetectShaderLanguage.
39
// The real OpenGL initialization happens in thin3d_gl.cpp.
40
glslVersionNumber = 110;
41
attribute = "attribute";
42
varying_vs = "varying";
43
varying_fs = "varying";
44
fragColor0 = "gl_FragColor";
45
fragColor1 = "fragColor1";
46
texture = "texture2D";
47
texture3D = "texture3D";
48
texelFetch = nullptr;
49
bitwiseOps = false;
50
lastFragData = nullptr;
51
gles = false;
52
forceMatrix4x4 = true;
53
break;
54
case GLSL_3xx:
55
// Just used in the shader test.
56
glslVersionNumber = 300; // GLSL ES 3.0
57
varying_vs = "out";
58
varying_fs = "in";
59
attribute = "in";
60
fragColor0 = "fragColor0";
61
fragColor1 = "fragColor1";
62
texture = "texture";
63
texture3D = "texture";
64
texelFetch = "texelFetch";
65
bitwiseOps = true;
66
lastFragData = nullptr;
67
gles = true;
68
forceMatrix4x4 = true;
69
glslES30 = true;
70
break;
71
case GLSL_VULKAN:
72
fragColor0 = "fragColor0";
73
fragColor1 = "fragColor1";
74
varying_fs = "in";
75
varying_vs = "out";
76
attribute = "in";
77
bitwiseOps = true;
78
framebufferFetchExtension = nullptr;
79
gles = false;
80
glslES30 = true;
81
glslVersionNumber = 450;
82
lastFragData = nullptr;
83
texture = "texture";
84
texture3D = "texture";
85
texelFetch = "texelFetch";
86
forceMatrix4x4 = false;
87
coefsFromBuffers = true;
88
vertexIndex = true;
89
break;
90
case HLSL_D3D11:
91
fragColor0 = "outfragment.target";
92
fragColor1 = "outfragment.target1";
93
vertexIndex = true; // if declared as a semantic input
94
varying_fs = "in";
95
varying_vs = "out";
96
attribute = "in";
97
bitwiseOps = lang == HLSL_D3D11;
98
framebufferFetchExtension = nullptr;
99
gles = false;
100
glslES30 = true;
101
glslVersionNumber = 0;
102
lastFragData = nullptr;
103
texture = "texture";
104
texture3D = "texture";
105
texelFetch = "texelFetch";
106
forceMatrix4x4 = false;
107
coefsFromBuffers = true;
108
vsOutPrefix = "Out.";
109
viewportYSign = "-";
110
break;
111
}
112
}
113
114
void InitShaderResources(TBuiltInResource &Resources) {
115
Resources.maxLights = 32;
116
Resources.maxClipPlanes = 6;
117
Resources.maxTextureUnits = 32;
118
Resources.maxTextureCoords = 32;
119
Resources.maxVertexAttribs = 64;
120
Resources.maxVertexUniformComponents = 4096;
121
Resources.maxVaryingFloats = 64;
122
Resources.maxVertexTextureImageUnits = 32;
123
Resources.maxCombinedTextureImageUnits = 80;
124
Resources.maxTextureImageUnits = 32;
125
Resources.maxFragmentUniformComponents = 4096;
126
Resources.maxDrawBuffers = 32;
127
Resources.maxVertexUniformVectors = 128;
128
Resources.maxVaryingVectors = 8;
129
Resources.maxFragmentUniformVectors = 16;
130
Resources.maxVertexOutputVectors = 16;
131
Resources.maxFragmentInputVectors = 15;
132
Resources.minProgramTexelOffset = -8;
133
Resources.maxProgramTexelOffset = 7;
134
Resources.maxClipDistances = 8;
135
Resources.maxComputeWorkGroupCountX = 65535;
136
Resources.maxComputeWorkGroupCountY = 65535;
137
Resources.maxComputeWorkGroupCountZ = 65535;
138
Resources.maxComputeWorkGroupSizeX = 1024;
139
Resources.maxComputeWorkGroupSizeY = 1024;
140
Resources.maxComputeWorkGroupSizeZ = 64;
141
Resources.maxComputeUniformComponents = 1024;
142
Resources.maxComputeTextureImageUnits = 16;
143
Resources.maxComputeImageUniforms = 8;
144
Resources.maxComputeAtomicCounters = 8;
145
Resources.maxComputeAtomicCounterBuffers = 1;
146
Resources.maxVaryingComponents = 60;
147
Resources.maxVertexOutputComponents = 64;
148
Resources.maxGeometryInputComponents = 64;
149
Resources.maxGeometryOutputComponents = 128;
150
Resources.maxFragmentInputComponents = 128;
151
Resources.maxImageUnits = 8;
152
Resources.maxCombinedImageUnitsAndFragmentOutputs = 8;
153
Resources.maxCombinedShaderOutputResources = 8;
154
Resources.maxImageSamples = 0;
155
Resources.maxVertexImageUniforms = 0;
156
Resources.maxTessControlImageUniforms = 0;
157
Resources.maxTessEvaluationImageUniforms = 0;
158
Resources.maxGeometryImageUniforms = 0;
159
Resources.maxFragmentImageUniforms = 8;
160
Resources.maxCombinedImageUniforms = 8;
161
Resources.maxGeometryTextureImageUnits = 16;
162
Resources.maxGeometryOutputVertices = 256;
163
Resources.maxGeometryTotalOutputComponents = 1024;
164
Resources.maxGeometryUniformComponents = 1024;
165
Resources.maxGeometryVaryingComponents = 64;
166
Resources.maxTessControlInputComponents = 128;
167
Resources.maxTessControlOutputComponents = 128;
168
Resources.maxTessControlTextureImageUnits = 16;
169
Resources.maxTessControlUniformComponents = 1024;
170
Resources.maxTessControlTotalOutputComponents = 4096;
171
Resources.maxTessEvaluationInputComponents = 128;
172
Resources.maxTessEvaluationOutputComponents = 128;
173
Resources.maxTessEvaluationTextureImageUnits = 16;
174
Resources.maxTessEvaluationUniformComponents = 1024;
175
Resources.maxTessPatchComponents = 120;
176
Resources.maxPatchVertices = 32;
177
Resources.maxTessGenLevel = 64;
178
Resources.maxViewports = 16;
179
Resources.maxVertexAtomicCounters = 0;
180
Resources.maxTessControlAtomicCounters = 0;
181
Resources.maxTessEvaluationAtomicCounters = 0;
182
Resources.maxGeometryAtomicCounters = 0;
183
Resources.maxFragmentAtomicCounters = 8;
184
Resources.maxCombinedAtomicCounters = 8;
185
Resources.maxAtomicCounterBindings = 1;
186
Resources.maxVertexAtomicCounterBuffers = 0;
187
Resources.maxTessControlAtomicCounterBuffers = 0;
188
Resources.maxTessEvaluationAtomicCounterBuffers = 0;
189
Resources.maxGeometryAtomicCounterBuffers = 0;
190
Resources.maxFragmentAtomicCounterBuffers = 1;
191
Resources.maxCombinedAtomicCounterBuffers = 1;
192
Resources.maxAtomicCounterBufferSize = 16384;
193
Resources.maxTransformFeedbackBuffers = 4;
194
Resources.maxTransformFeedbackInterleavedComponents = 64;
195
Resources.maxCullDistances = 8;
196
Resources.maxCombinedClipAndCullDistances = 8;
197
Resources.maxSamples = 4;
198
Resources.maxDualSourceDrawBuffersEXT = 1;
199
Resources.limits.nonInductiveForLoops = 1;
200
Resources.limits.whileLoops = 1;
201
Resources.limits.doWhileLoops = 1;
202
Resources.limits.generalUniformIndexing = 1;
203
Resources.limits.generalAttributeMatrixVectorIndexing = 1;
204
Resources.limits.generalVaryingIndexing = 1;
205
Resources.limits.generalSamplerIndexing = 1;
206
Resources.limits.generalVariableIndexing = 1;
207
Resources.limits.generalConstantMatrixVectorIndexing = 1;
208
}
209
210