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/Common/ShaderCommon.h
Views: 1401
1
// Copyright (c) 2015- 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
#include <vector>
22
#include <string>
23
24
namespace Draw {
25
class DrawContext;
26
}
27
28
enum DebugShaderType {
29
SHADER_TYPE_VERTEX = 0,
30
SHADER_TYPE_FRAGMENT = 1,
31
SHADER_TYPE_GEOMETRY = 2,
32
SHADER_TYPE_VERTEXLOADER = 3, // Not really a shader, but might as well re-use this mechanism
33
SHADER_TYPE_PIPELINE = 4, // Vulkan and DX12 combines a bunch of state into pipeline objects. Might as well make them inspectable.
34
SHADER_TYPE_TEXTURE = 5,
35
SHADER_TYPE_SAMPLER = 6, // Not really a shader either. Need to rename this enum...
36
};
37
38
enum DebugShaderStringType {
39
SHADER_STRING_SHORT_DESC = 0,
40
SHADER_STRING_SOURCE_CODE = 1,
41
SHADER_STRING_STATS = 2,
42
};
43
44
// Shared between the backends. Not all are necessarily used by each backend, but this lets us share
45
// more code than before. TODO: Can probably cut the number of these down without too much slowdown.
46
enum : uint64_t {
47
DIRTY_PROJMATRIX = 1ULL << 0,
48
DIRTY_PROJTHROUGHMATRIX = 1ULL << 1,
49
DIRTY_FOGCOLOR = 1ULL << 2,
50
DIRTY_FOGCOEF = 1ULL << 3,
51
DIRTY_TEXENV = 1ULL << 4,
52
DIRTY_ALPHACOLORREF = 1ULL << 5,
53
54
DIRTY_STENCILREPLACEVALUE = 1ULL << 6,
55
56
DIRTY_ALPHACOLORMASK = 1ULL << 7,
57
DIRTY_LIGHT0 = 1ULL << 8,
58
DIRTY_LIGHT1 = 1ULL << 9,
59
DIRTY_LIGHT2 = 1ULL << 10,
60
DIRTY_LIGHT3 = 1ULL << 11,
61
62
DIRTY_MATDIFFUSE = 1ULL << 12,
63
DIRTY_MATSPECULAR = 1ULL << 13,
64
DIRTY_MATEMISSIVE = 1ULL << 14,
65
DIRTY_AMBIENT = 1ULL << 15,
66
DIRTY_MATAMBIENTALPHA = 1ULL << 16,
67
68
DIRTY_SHADERBLEND = 1ULL << 17, // Used only for in-shader blending.
69
70
DIRTY_UVSCALEOFFSET = 1ULL << 18,
71
DIRTY_DEPTHRANGE = 1ULL << 19,
72
73
DIRTY_WORLDMATRIX = 1ULL << 21,
74
DIRTY_VIEWMATRIX = 1ULL << 22,
75
DIRTY_TEXMATRIX = 1ULL << 23,
76
DIRTY_BONEMATRIX0 = 1ULL << 24, // NOTE: These must be under 32
77
DIRTY_BONEMATRIX1 = 1ULL << 25,
78
DIRTY_BONEMATRIX2 = 1ULL << 26,
79
DIRTY_BONEMATRIX3 = 1ULL << 27,
80
DIRTY_BONEMATRIX4 = 1ULL << 28,
81
DIRTY_BONEMATRIX5 = 1ULL << 29,
82
DIRTY_BONEMATRIX6 = 1ULL << 30,
83
DIRTY_BONEMATRIX7 = 1ULL << 31,
84
85
DIRTY_BEZIERSPLINE = 1ULL << 32,
86
DIRTY_TEXCLAMP = 1ULL << 33,
87
DIRTY_CULLRANGE = 1ULL << 34,
88
89
DIRTY_DEPAL = 1ULL << 35,
90
DIRTY_COLORWRITEMASK = 1ULL << 36,
91
92
DIRTY_MIPBIAS = 1ULL << 37,
93
DIRTY_LIGHT_CONTROL = 1ULL << 38,
94
DIRTY_TEX_ALPHA_MUL = 1ULL << 39,
95
96
// Bits 40-42 are free for new uniforms. Then we're really out and need to start merging.
97
// Don't forget to update DIRTY_ALL_UNIFORMS when you start using them.
98
99
DIRTY_BONE_UNIFORMS = 0xFF000000ULL,
100
101
DIRTY_ALL_UNIFORMS = 0x0FFFFFFFFFFULL,
102
103
// Other dirty elements that aren't uniforms
104
DIRTY_CULL_PLANES = 1ULL << 43,
105
DIRTY_FRAMEBUF = 1ULL << 44,
106
DIRTY_TEXTURE_IMAGE = 1ULL << 45, // Means that the definition of the texture image has changed (address, stride etc), and we need to look up again.
107
DIRTY_TEXTURE_PARAMS = 1ULL << 46,
108
109
// Render State
110
DIRTY_BLEND_STATE = 1ULL << 47,
111
DIRTY_DEPTHSTENCIL_STATE = 1ULL << 48,
112
DIRTY_RASTER_STATE = 1ULL << 49,
113
DIRTY_VIEWPORTSCISSOR_STATE = 1ULL << 50,
114
DIRTY_VERTEXSHADER_STATE = 1ULL << 51,
115
DIRTY_FRAGMENTSHADER_STATE = 1ULL << 52,
116
DIRTY_GEOMETRYSHADER_STATE = 1ULL << 53,
117
118
// Note that the top 8 bits (54-63) cannot be dirtied through the commonCommandTable due to packing of other flags.
119
120
// Everything that's not uniforms. Use this after using thin3d.
121
// TODO: Should we also add DIRTY_FRAMEBUF here? It kinda generally takes care of itself.
122
DIRTY_ALL_RENDER_STATE = DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE | DIRTY_GEOMETRYSHADER_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS,
123
124
DIRTY_ALL = 0xFFFFFFFFFFFFFFFF
125
};
126
127
class ShaderManagerCommon {
128
public:
129
ShaderManagerCommon(Draw::DrawContext *draw) : draw_(draw) {}
130
virtual ~ShaderManagerCommon() {}
131
132
virtual void ClearShaders() = 0;
133
virtual void DirtyLastShader() = 0;
134
135
virtual void DeviceLost() = 0;
136
virtual void DeviceRestore(Draw::DrawContext *draw) = 0; // must set draw_ to draw
137
138
virtual std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) = 0;
139
virtual std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) = 0;
140
141
protected:
142
Draw::DrawContext *draw_ = nullptr;
143
};
144
145
enum DoLightComputation {
146
LIGHT_OFF,
147
LIGHT_SHADE,
148
LIGHT_FULL,
149
};
150
151
// PSP vertex format.
152
enum class PspAttributeLocation {
153
POSITION = 0,
154
TEXCOORD = 1,
155
NORMAL = 2,
156
W1 = 3,
157
W2 = 4,
158
COLOR0 = 5,
159
COLOR1 = 6,
160
161
COUNT
162
};
163
164
// Pre-fetched attrs and uniforms (used by GL only).
165
enum {
166
ATTR_POSITION = 0,
167
ATTR_TEXCOORD = 1,
168
ATTR_NORMAL = 2,
169
ATTR_W1 = 3,
170
ATTR_W2 = 4,
171
ATTR_COLOR0 = 5,
172
ATTR_COLOR1 = 6,
173
174
ATTR_COUNT,
175
};
176
177