-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ShaderCommon.h
179 lines (144 loc) · 4.57 KB
/
ShaderCommon.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
// Copyright (c) 2015- PPSSPP Project.
// This program 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, version 2.0 or later versions.
// This program 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include <cstdint>
#include <vector>
namespace Draw {
class DrawContext;
}
enum ShaderLanguage {
GLSL_140,
GLSL_300,
GLSL_VULKAN,
HLSL_DX9,
HLSL_D3D11,
HLSL_D3D11_TEST, // temporary
};
enum DebugShaderType {
SHADER_TYPE_VERTEX = 0,
SHADER_TYPE_FRAGMENT = 1,
SHADER_TYPE_GEOMETRY = 2,
SHADER_TYPE_VERTEXLOADER = 3, // Not really a shader, but might as well re-use this mechanism
SHADER_TYPE_PIPELINE = 4, // Vulkan and DX12 combines a bunch of state into pipeline objects. Might as well make them inspectable.
SHADER_TYPE_DEPAL = 5,
SHADER_TYPE_SAMPLER = 6, // Not really a shader either. Need to rename this enum...
};
enum DebugShaderStringType {
SHADER_STRING_SHORT_DESC = 0,
SHADER_STRING_SOURCE_CODE = 1,
SHADER_STRING_STATS = 2,
};
// Shared between the backends. Not all are necessarily used by each backend, but this lets us share
// more code than before.
enum : uint64_t {
DIRTY_PROJMATRIX = 1ULL << 0,
DIRTY_PROJTHROUGHMATRIX = 1ULL << 1,
DIRTY_FOGCOLOR = 1ULL << 2,
DIRTY_FOGCOEF = 1ULL << 3,
DIRTY_TEXENV = 1ULL << 4,
DIRTY_ALPHACOLORREF = 1ULL << 5,
DIRTY_STENCILREPLACEVALUE = 1ULL << 6,
DIRTY_ALPHACOLORMASK = 1ULL << 7,
DIRTY_LIGHT0 = 1ULL << 8,
DIRTY_LIGHT1 = 1ULL << 9,
DIRTY_LIGHT2 = 1ULL << 10,
DIRTY_LIGHT3 = 1ULL << 11,
DIRTY_MATDIFFUSE = 1ULL << 12,
DIRTY_MATSPECULAR = 1ULL << 13,
DIRTY_MATEMISSIVE = 1ULL << 14,
DIRTY_AMBIENT = 1ULL << 15,
DIRTY_MATAMBIENTALPHA = 1ULL << 16,
DIRTY_SHADERBLEND = 1ULL << 17, // Used only for in-shader blending.
DIRTY_UVSCALEOFFSET = 1ULL << 18,
DIRTY_DEPTHRANGE = 1ULL << 19,
DIRTY_WORLDMATRIX = 1ULL << 21,
DIRTY_VIEWMATRIX = 1ULL << 22,
DIRTY_TEXMATRIX = 1ULL << 23,
DIRTY_BONEMATRIX0 = 1ULL << 24, // NOTE: These must be under 32
DIRTY_BONEMATRIX1 = 1ULL << 25,
DIRTY_BONEMATRIX2 = 1ULL << 26,
DIRTY_BONEMATRIX3 = 1ULL << 27,
DIRTY_BONEMATRIX4 = 1ULL << 28,
DIRTY_BONEMATRIX5 = 1ULL << 29,
DIRTY_BONEMATRIX6 = 1ULL << 30,
DIRTY_BONEMATRIX7 = 1ULL << 31,
DIRTY_BEZIERSPLINE = 1ULL << 32,
DIRTY_TEXCLAMP = 1ULL << 33,
DIRTY_CULLRANGE = 1ULL << 34,
DIRTY_DEPAL = 1ULL << 35,
// space for 5 more uniform dirty flags. Remember to update DIRTY_ALL_UNIFORMS.
DIRTY_BONE_UNIFORMS = 0xFF000000ULL,
DIRTY_ALL_UNIFORMS = 0xFFFFFFFFFULL,
DIRTY_ALL_LIGHTS = DIRTY_LIGHT0 | DIRTY_LIGHT1 | DIRTY_LIGHT2 | DIRTY_LIGHT3,
// Other dirty elements that aren't uniforms!
DIRTY_FRAMEBUF = 1ULL << 40,
DIRTY_TEXTURE_IMAGE = 1ULL << 41, // Means that the definition of the texture image has changed (address, stride etc), and we need to look up again.
DIRTY_TEXTURE_PARAMS = 1ULL << 42,
// Render State
DIRTY_BLEND_STATE = 1ULL << 43,
DIRTY_DEPTHSTENCIL_STATE = 1ULL << 44,
DIRTY_RASTER_STATE = 1ULL << 45,
DIRTY_VIEWPORTSCISSOR_STATE = 1ULL << 46,
DIRTY_VERTEXSHADER_STATE = 1ULL << 47,
DIRTY_FRAGMENTSHADER_STATE = 1ULL << 48,
DIRTY_ALL = 0xFFFFFFFFFFFFFFFF
};
class ShaderManagerCommon {
public:
ShaderManagerCommon(Draw::DrawContext *draw) : draw_(draw) {}
virtual ~ShaderManagerCommon() {}
virtual void DirtyLastShader() = 0;
protected:
Draw::DrawContext *draw_ = nullptr;
};
struct TBuiltInResource;
void init_resources(TBuiltInResource &Resources);
enum DoLightComputation {
LIGHT_OFF,
LIGHT_SHADE,
LIGHT_FULL,
};
struct GLSLShaderCompat {
int glslVersionNumber;
bool gles;
bool vulkan;
bool d3d11;
bool d3d9;
const char *varying_fs;
const char *varying_vs;
const char *attribute;
const char *fragColor0;
const char *fragColor1;
const char *texture;
const char *texelFetch;
const char *lastFragData;
const char *framebufferFetchExtension;
const char *inPrefix;
bool glslES30;
bool bitwiseOps;
bool forceMatrix4x4;
bool coefsFromBuffers;
void SetupForVulkan();
void SetupForD3D11();
};
// PSP vertex format.
enum class PspAttributeLocation {
POSITION = 0,
TEXCOORD = 1,
NORMAL = 2,
W1 = 3,
W2 = 4,
COLOR0 = 5,
COLOR1 = 6,
COUNT
};