Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/Shader.h
3186 views
1
#pragma once
2
3
#include <vector>
4
#include <cstdint>
5
#include <cstddef> // for size_t
6
7
#include "Common/Common.h"
8
9
struct TBuiltInResource;
10
void InitShaderResources(TBuiltInResource &Resources);
11
12
// GLSL_1xx and GLSL_3xx each cover a lot of sub variants. All the little quirks
13
// that differ are covered in ShaderLanguageDesc.
14
// Defined as a bitmask so stuff like GetSupportedShaderLanguages can return combinations.
15
// TODO: We can probably move away from this distinction soon, now that we mostly generate/translate shaders.
16
enum ShaderLanguage {
17
GLSL_1xx = 1,
18
GLSL_3xx = 2,
19
GLSL_VULKAN = 4,
20
HLSL_D3D11 = 16,
21
};
22
23
inline bool ShaderLanguageIsOpenGL(ShaderLanguage lang) {
24
return lang == GLSL_1xx || lang == GLSL_3xx;
25
}
26
27
const char *ShaderLanguageAsString(ShaderLanguage lang);
28
29
enum class ShaderStage {
30
Vertex,
31
Fragment,
32
Geometry,
33
Compute,
34
};
35
36
const char *ShaderStageAsString(ShaderStage lang);
37
38
struct ShaderLanguageDesc {
39
ShaderLanguageDesc() {}
40
explicit ShaderLanguageDesc(ShaderLanguage lang);
41
42
void Init(ShaderLanguage lang);
43
44
int glslVersionNumber = 0;
45
ShaderLanguage shaderLanguage;
46
bool gles = false;
47
const char *varying_fs = nullptr;
48
const char *varying_vs = nullptr;
49
const char *attribute = nullptr;
50
const char *fragColor0 = nullptr;
51
const char *fragColor1 = nullptr;
52
const char *texture = nullptr;
53
const char *texture3D = nullptr;
54
const char *texelFetch = nullptr;
55
const char *lastFragData = nullptr;
56
const char *framebufferFetchExtension = nullptr;
57
const char *vsOutPrefix = "";
58
const char *viewportYSign = "";
59
60
bool vertexIndex = false;
61
bool glslES30 = false; // really glslES30Features. TODO: Clean this up.
62
bool bitwiseOps = false;
63
bool forceMatrix4x4 = false;
64
bool coefsFromBuffers = false;
65
char driverInfo[256]; // Really only GL uses this.
66
};
67
68
enum class UniformType : int8_t {
69
FLOAT1,
70
FLOAT2,
71
FLOAT3,
72
FLOAT4,
73
MATRIX4X4,
74
};
75
76
// Describe uniforms intricately enough that we can support them on all backends.
77
// This will generate a uniform struct on the newer backends and individual uniforms on the older ones.
78
struct UniformDesc {
79
const char *name; // For GL
80
int16_t vertexReg; // For D3D
81
int16_t fragmentReg; // For D3D
82
UniformType type;
83
int16_t offset; // in bytes
84
// TODO: Support array elements etc.
85
};
86
87
struct UniformBufferDesc {
88
size_t uniformBufferSize;
89
std::vector<UniformDesc> uniforms;
90
};
91
92
struct UniformDef {
93
const char *type;
94
const char *name;
95
int index;
96
};
97
98
enum class SamplerFlags {
99
ARRAY_ON_VULKAN = 1,
100
};
101
ENUM_CLASS_BITOPS(SamplerFlags);
102
103
struct SamplerDef {
104
int binding; // Might only be used by some backends.
105
const char *name;
106
SamplerFlags flags;
107
// TODO: Might need unsigned samplers, 3d samplers, or other types in the future.
108
};
109
110
// For passing error messages from shader compilation (and other critical issues) back to the host.
111
// This can run on any thread - be aware!
112
// TODO: See if we can find a less generic name for this.
113
typedef void (*ErrorCallbackFn)(const char *shortDesc, const char *details, void *userdata);
114
115