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/Directx9/ShaderManagerDX9.h
Views: 1401
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 <map>
21
#include <cstdint>
22
#include <d3d9.h>
23
#include <wrl/client.h>
24
25
#include "Common/CommonTypes.h"
26
#include "GPU/Common/VertexShaderGenerator.h"
27
#include "GPU/Common/FragmentShaderGenerator.h"
28
#include "GPU/Common/ShaderCommon.h"
29
#include "GPU/Common/ShaderId.h"
30
#include "Common/Math/lin/matrix4x4.h"
31
32
class PSShader;
33
class VSShader;
34
35
// Real public interface
36
37
class PSShader {
38
public:
39
PSShader(LPDIRECT3DDEVICE9 device, FShaderID id, const char *code);
40
~PSShader();
41
42
const std::string &source() const { return source_; }
43
44
bool Failed() const { return failed_; }
45
46
std::string GetShaderString(DebugShaderStringType type) const;
47
48
Microsoft::WRL::ComPtr<IDirect3DPixelShader9> shader;
49
50
protected:
51
std::string source_;
52
bool failed_ = false;
53
FShaderID id_;
54
};
55
56
class VSShader {
57
public:
58
VSShader(LPDIRECT3DDEVICE9 device, VShaderID id, const char *code, bool useHWTransform);
59
~VSShader();
60
61
const std::string &source() const { return source_; }
62
63
bool Failed() const { return failed_; }
64
bool UseHWTransform() const { return useHWTransform_; }
65
66
std::string GetShaderString(DebugShaderStringType type) const;
67
68
Microsoft::WRL::ComPtr<IDirect3DVertexShader9> shader;
69
70
protected:
71
std::string source_;
72
bool failed_ = false;
73
bool useHWTransform_;
74
VShaderID id_;
75
};
76
77
class ShaderManagerDX9 : public ShaderManagerCommon {
78
public:
79
ShaderManagerDX9(Draw::DrawContext *draw, LPDIRECT3DDEVICE9 device);
80
~ShaderManagerDX9();
81
82
void ClearShaders() override;
83
VSShader *ApplyShader(bool useHWTransform, bool useHWTessellation, VertexDecoder *decoder, bool weightsAsFloat, bool useSkinInDecode, const ComputedPipelineState &pipelineState);
84
void DirtyLastShader() override;
85
86
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
87
int GetNumFragmentShaders() const { return (int)fsCache_.size(); }
88
89
void DeviceLost() override { draw_ = nullptr; }
90
void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; }
91
92
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) override;
93
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) override;
94
95
private:
96
void PSUpdateUniforms(u64 dirtyUniforms);
97
void VSUpdateUniforms(u64 dirtyUniforms);
98
inline void PSSetColorUniform3Alpha255(int creg, u32 color, u8 alpha);
99
inline void PSSetColorUniform3(int creg, u32 color);
100
inline void PSSetFloat(int creg, float value);
101
inline void PSSetFloatArray(int creg, const float *value, int count);
102
103
void VSSetMatrix4x3_3(int creg, const float *m4x3);
104
inline void VSSetColorUniform3(int creg, u32 color);
105
inline void VSSetColorUniform3ExtraFloat(int creg, u32 color, float extra);
106
inline void VSSetColorUniform3Alpha(int creg, u32 color, u8 alpha);
107
void VSSetMatrix(int creg, const float* pMatrix);
108
void VSSetFloat(int creg, float value);
109
void VSSetFloatArray(int creg, const float *value, int count);
110
void VSSetFloat24Uniform3(int creg, const u32 data[3]);
111
void VSSetFloat24Uniform3Normalized(int creg, const u32 data[3]);
112
void VSSetFloatUniform4(int creg, const float data[4]);
113
114
void Clear();
115
116
LPDIRECT3DDEVICE9 device_;
117
118
FShaderID lastFSID_;
119
VShaderID lastVSID_;
120
121
char *codeBuffer_;
122
123
VSShader *lastVShader_ = nullptr;
124
PSShader *lastPShader_ = nullptr;
125
126
typedef std::map<FShaderID, PSShader *> FSCache;
127
FSCache fsCache_;
128
129
typedef std::map<VShaderID, VSShader *> VSCache;
130
VSCache vsCache_;
131
};
132
133