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/Common/GPU/Shader.h
Views: 1401
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_D3D9 = 8,
21
HLSL_D3D11 = 16,
22
};
23
24
inline bool ShaderLanguageIsOpenGL(ShaderLanguage lang) {
25
return lang == GLSL_1xx || lang == GLSL_3xx;
26
}
27
28
const char *ShaderLanguageAsString(ShaderLanguage lang);
29
30
enum class ShaderStage {
31
Vertex,
32
Fragment,
33
Geometry,
34
Compute,
35
};
36
37
const char *ShaderStageAsString(ShaderStage lang);
38
39
struct ShaderLanguageDesc {
40
ShaderLanguageDesc() {}
41
explicit ShaderLanguageDesc(ShaderLanguage lang);
42
43
void Init(ShaderLanguage lang);
44
45
int glslVersionNumber = 0;
46
ShaderLanguage shaderLanguage;
47
bool gles = false;
48
const char *varying_fs = nullptr;
49
const char *varying_vs = nullptr;
50
const char *attribute = nullptr;
51
const char *fragColor0 = nullptr;
52
const char *fragColor1 = nullptr;
53
const char *texture = nullptr;
54
const char *texture3D = nullptr;
55
const char *texelFetch = nullptr;
56
const char *lastFragData = nullptr;
57
const char *framebufferFetchExtension = nullptr;
58
const char *vsOutPrefix = "";
59
const char *viewportYSign = "";
60
61
bool vertexIndex = false;
62
bool glslES30 = false; // really glslES30Features. TODO: Clean this up.
63
bool bitwiseOps = false;
64
bool forceMatrix4x4 = false;
65
bool coefsFromBuffers = false;
66
char driverInfo[256]; // Really only GL uses this.
67
};
68
69
enum class UniformType : int8_t {
70
FLOAT1,
71
FLOAT2,
72
FLOAT3,
73
FLOAT4,
74
MATRIX4X4,
75
};
76
77
// Describe uniforms intricately enough that we can support them on all backends.
78
// This will generate a uniform struct on the newer backends and individual uniforms on the older ones.
79
struct UniformDesc {
80
const char *name; // For GL
81
int16_t vertexReg; // For D3D
82
int16_t fragmentReg; // For D3D
83
UniformType type;
84
int16_t offset; // in bytes
85
// TODO: Support array elements etc.
86
};
87
88
struct UniformBufferDesc {
89
size_t uniformBufferSize;
90
std::vector<UniformDesc> uniforms;
91
};
92
93
struct UniformDef {
94
const char *type;
95
const char *name;
96
int index;
97
};
98
99
enum class SamplerFlags {
100
ARRAY_ON_VULKAN = 1,
101
};
102
ENUM_CLASS_BITOPS(SamplerFlags);
103
104
struct SamplerDef {
105
int binding; // Might only be used by some backends.
106
const char *name;
107
SamplerFlags flags;
108
// TODO: Might need unsigned samplers, 3d samplers, or other types in the future.
109
};
110
111
// For passing error messages from shader compilation (and other critical issues) back to the host.
112
// This can run on any thread - be aware!
113
// TODO: See if we can find a less generic name for this.
114
typedef void (*ErrorCallbackFn)(const char *shortDesc, const char *details, void *userdata);
115
116