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/ShaderUniforms.h
Views: 1401
1
#pragma once
2
3
#include <cstdint>
4
5
#include "ShaderCommon.h"
6
7
// Used by the "modern" backends that use uniform buffers. They can share this without issue.
8
9
enum : uint64_t {
10
DIRTY_BASE_UNIFORMS =
11
DIRTY_WORLDMATRIX | DIRTY_PROJTHROUGHMATRIX | DIRTY_VIEWMATRIX | DIRTY_TEXMATRIX | DIRTY_ALPHACOLORREF |
12
DIRTY_PROJMATRIX | DIRTY_FOGCOLOR | DIRTY_FOGCOEF | DIRTY_TEXENV | DIRTY_TEX_ALPHA_MUL | DIRTY_STENCILREPLACEVALUE |
13
DIRTY_ALPHACOLORMASK | DIRTY_SHADERBLEND | DIRTY_COLORWRITEMASK | DIRTY_UVSCALEOFFSET | DIRTY_TEXCLAMP | DIRTY_DEPTHRANGE | DIRTY_MATAMBIENTALPHA |
14
DIRTY_BEZIERSPLINE | DIRTY_DEPAL,
15
DIRTY_LIGHT_UNIFORMS =
16
DIRTY_LIGHT_CONTROL | DIRTY_LIGHT0 | DIRTY_LIGHT1 | DIRTY_LIGHT2 | DIRTY_LIGHT3 |
17
DIRTY_MATDIFFUSE | DIRTY_MATSPECULAR | DIRTY_MATEMISSIVE | DIRTY_AMBIENT,
18
};
19
20
// Currently 496 bytes.
21
// Every line here is a 4-float.
22
struct alignas(16) UB_VS_FS_Base {
23
float proj[16];
24
float proj_through[16];
25
float view[12];
26
float world[12];
27
float tex[12];
28
float uvScaleOffset[4];
29
float depthRange[4];
30
float matAmbient[4];
31
float cullRangeMin[4];
32
float cullRangeMax[4];
33
uint32_t spline_counts; uint32_t depal_mask_shift_off_fmt; // 4 params packed into one.
34
uint32_t colorWriteMask; float mipBias;
35
// Fragment data
36
float texNoAlpha; float texMul; float padding[2]; // this vec4 will hold ubershader stuff. We won't use integer flags in the fragment shader.
37
float fogColor[3]; uint32_t alphaColorRef;
38
float texEnvColor[3]; uint32_t colorTestMask;
39
float texClamp[4];
40
float texClampOffset[2]; float fogCoef[2];
41
float blendFixA[3]; float stencilReplaceValue;
42
float blendFixB[3]; float rotation;
43
// VR stuff is to go here, later. For normal drawing, we can then get away
44
// with just uploading the first 448 bytes of the struct (up to and including fogCoef).
45
};
46
47
static const char * const ub_baseStr =
48
R"( mat4 u_proj;
49
mat4 u_proj_through;
50
mat3x4 u_view;
51
mat3x4 u_world;
52
mat3x4 u_texmtx;
53
vec4 u_uvscaleoffset;
54
vec4 u_depthRange;
55
vec4 u_matambientalpha;
56
vec4 u_cullRangeMin;
57
vec4 u_cullRangeMax;
58
uint u_spline_counts;
59
uint u_depal_mask_shift_off_fmt;
60
uint u_colorWriteMask;
61
float u_mipBias;
62
vec2 u_texNoAlphaMul; float pad1; float pad2;
63
vec3 u_fogcolor; uint u_alphacolorref;
64
vec3 u_texenv; uint u_alphacolormask;
65
vec4 u_texclamp;
66
vec2 u_texclampoff; vec2 u_fogcoef;
67
vec3 u_blendFixA; float u_stencilReplaceValue;
68
vec3 u_blendFixB; float u_rotation;
69
)";
70
71
// 512 bytes. Would like to shrink more. Some colors only have 8-bit precision and we expand
72
// them to float unnecessarily, could just as well expand in the shader.
73
struct alignas(16) UB_VS_Lights {
74
float ambientColor[4];
75
float materialDiffuse[4];
76
float materialSpecular[4];
77
float materialEmissive[3];
78
uint32_t lightControl;
79
float lpos[4][4];
80
float ldir[4][4];
81
float latt[4][4];
82
float lightAngle_SpotCoef[4][4]; // TODO: Merge with lightSpotCoef, use .xy
83
float lightAmbient[4][4];
84
float lightDiffuse[4][4];
85
float lightSpecular[4][4];
86
};
87
88
static const char * const ub_vs_lightsStr =
89
R"( vec4 u_ambient;
90
vec3 u_matdiffuse;
91
vec4 u_matspecular;
92
vec3 u_matemissive;
93
uint u_lightControl; // light ubershader control bits
94
vec3 u_lightpos[4];
95
vec3 u_lightdir[4];
96
vec3 u_lightatt[4];
97
vec4 u_lightangle_spotCoef[4];
98
vec3 u_lightambient[4];
99
vec3 u_lightdiffuse[4];
100
vec3 u_lightspecular[4];
101
)";
102
103
// With some cleverness, we could get away with uploading just half this when only the four or five first
104
// bones are being used. This is 384b.
105
struct alignas(16) UB_VS_Bones {
106
float bones[8][12];
107
};
108
109
static const char * const ub_vs_bonesStr =
110
R"( mat3x4 u_bone0; mat3x4 u_bone1; mat3x4 u_bone2; mat3x4 u_bone3; mat3x4 u_bone4; mat3x4 u_bone5; mat3x4 u_bone6; mat3x4 u_bone7; mat3x4 u_bone8;
111
)";
112
113
void CalcCullRange(float minValues[4], float maxValues[4], bool flipViewport, bool hasNegZ);
114
115
void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipViewport, bool useBufferedRendering);
116
void LightUpdateUniforms(UB_VS_Lights *ub, uint64_t dirtyUniforms);
117
void BoneUpdateUniforms(UB_VS_Bones *ub, uint64_t dirtyUniforms);
118
119
uint32_t PackLightControlBits();
120
121