Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Common/PresentationCommon.h
3186 views
1
// Copyright (c) 2012- 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 "Common/Common.h"
21
#include "Common/GPU/Shader.h"
22
23
struct CardboardSettings {
24
bool enabled;
25
float leftEyeXPosition;
26
float rightEyeXPosition;
27
float screenYPosition;
28
float screenWidth;
29
float screenHeight;
30
};
31
32
struct PostShaderUniforms {
33
float texelDelta[2]; float pixelDelta[2];
34
float time[4];
35
float timeDelta[4];
36
float setting[4];
37
float video; float pad[3];
38
float vr;
39
// Used on Direct3D9.
40
float gl_HalfPixel[4];
41
};
42
43
struct FRect {
44
float x;
45
float y;
46
float w;
47
float h;
48
};
49
50
struct Bounds; // from geom2d
51
52
FRect GetScreenFrame(float pixelWidth, float pixelHeight);
53
void SetOverrideScreenFrame(const Bounds *bounds);
54
void CalculateDisplayOutputRect(FRect *rc, float origW, float origH, const FRect &frame, int rotation);
55
56
namespace Draw {
57
class Buffer;
58
class DrawContext;
59
class Framebuffer;
60
class Pipeline;
61
class SamplerState;
62
class ShaderModule;
63
class Texture;
64
}
65
66
struct ShaderInfo;
67
class TextureCacheCommon;
68
69
enum class OutputFlags {
70
LINEAR = 0x0000,
71
NEAREST = 0x0001,
72
RB_SWIZZLE = 0x0002,
73
BACKBUFFER_FLIPPED = 0x0004, // Viewport/scissor coordinates are y-flipped.
74
POSITION_FLIPPED = 0x0008, // Vertex position in the shader is y-flipped relative to the screen.
75
PILLARBOX = 0x0010, // Squeeze the image horizontally. Used for the DarkStalkers hack.
76
};
77
ENUM_CLASS_BITOPS(OutputFlags);
78
79
class PresentationCommon {
80
public:
81
PresentationCommon(Draw::DrawContext *draw);
82
~PresentationCommon();
83
84
void UpdateDisplaySize(int w, int h) {
85
pixelWidth_ = w;
86
pixelHeight_ = h;
87
}
88
89
// NOTE: Should be un-rotated width/height.
90
void UpdateRenderSize(int rw, int rh) {
91
renderWidth_ = rw;
92
renderHeight_ = rh;
93
}
94
void SetLanguage(ShaderLanguage lang) {
95
lang_ = lang;
96
}
97
98
bool HasPostShader() {
99
return usePostShader_;
100
}
101
102
bool UpdatePostShader();
103
104
void BeginFrame() {
105
presentedThisFrame_ = false;
106
}
107
bool PresentedThisFrame() const {
108
return presentedThisFrame_;
109
}
110
void NotifyPresent() {
111
// Something else did the present, skipping PresentationCommon.
112
// If you haven't called BindFramebufferAsRenderTarget, you must not set this.
113
presentedThisFrame_ = true;
114
}
115
116
void DeviceLost();
117
void DeviceRestore(Draw::DrawContext *draw);
118
119
void UpdateUniforms(bool hasVideo);
120
void SourceTexture(Draw::Texture *texture, int bufferWidth, int bufferHeight);
121
void SourceFramebuffer(Draw::Framebuffer *fb, int bufferWidth, int bufferHeight);
122
void CopyToOutput(OutputFlags flags, int uvRotation, float u0, float v0, float u1, float v1);
123
124
void CalculateRenderResolution(int *width, int *height, int *scaleFactor, bool *upscaling, bool *ssaa) const;
125
126
protected:
127
void CreateDeviceObjects();
128
void DestroyDeviceObjects();
129
130
void DestroyPostShader();
131
void DestroyStereoShader();
132
133
static void ShowPostShaderError(const std::string &errorString);
134
135
Draw::ShaderModule *CompileShaderModule(ShaderStage stage, ShaderLanguage lang, const std::string &src, std::string *errorString) const;
136
Draw::Pipeline *CreatePipeline(std::vector<Draw::ShaderModule *> shaders, bool postShader, const UniformBufferDesc *uniformDesc) const;
137
bool CompilePostShader(const ShaderInfo *shaderInfo, Draw::Pipeline **outPipeline) const;
138
bool BuildPostShader(const ShaderInfo *shaderInfo, const ShaderInfo *next, Draw::Pipeline **outPipeline);
139
bool AllocateFramebuffer(int w, int h);
140
141
bool BindSource(int binding, bool bindStereo);
142
143
void GetCardboardSettings(CardboardSettings *cardboardSettings) const;
144
void CalculatePostShaderUniforms(int bufferWidth, int bufferHeight, int targetWidth, int targetHeight, const ShaderInfo *shaderInfo, PostShaderUniforms *uniforms) const;
145
146
Draw::DrawContext *draw_;
147
Draw::Pipeline *texColor_ = nullptr;
148
Draw::Pipeline *texColorRBSwizzle_ = nullptr;
149
Draw::SamplerState *samplerNearest_ = nullptr;
150
Draw::SamplerState *samplerLinear_ = nullptr;
151
Draw::Buffer *vdata_ = nullptr;
152
153
std::vector<Draw::Pipeline *> postShaderPipelines_;
154
std::vector<Draw::Framebuffer *> postShaderFramebuffers_;
155
std::vector<ShaderInfo> postShaderInfo_;
156
std::vector<Draw::Framebuffer *> previousFramebuffers_;
157
158
Draw::Pipeline *stereoPipeline_ = nullptr;
159
ShaderInfo *stereoShaderInfo_ = nullptr;
160
161
int previousIndex_ = 0;
162
PostShaderUniforms previousUniforms_{};
163
164
Draw::Texture *srcTexture_ = nullptr;
165
Draw::Framebuffer *srcFramebuffer_ = nullptr;
166
int srcWidth_ = 0;
167
int srcHeight_ = 0;
168
bool hasVideo_ = false;
169
170
int pixelWidth_ = 0;
171
int pixelHeight_ = 0;
172
int renderWidth_ = 0;
173
int renderHeight_ = 0;
174
175
bool usePostShader_ = false;
176
bool restorePostShader_ = false;
177
bool presentedThisFrame_ = false;
178
ShaderLanguage lang_;
179
180
struct PrevFBO {
181
Draw::Framebuffer *fbo;
182
int w;
183
int h;
184
};
185
std::vector<PrevFBO> postShaderFBOUsage_;
186
};
187
188