Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/D3D11/ShaderManagerD3D11.h
3187 views
1
// Copyright (c) 2017- 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
22
#include <d3d11.h>
23
#include <wrl/client.h>
24
25
#include "Common/CommonTypes.h"
26
#include "GPU/Common/ShaderCommon.h"
27
#include "GPU/Common/ShaderId.h"
28
#include "GPU/Common/ShaderUniforms.h"
29
#include "GPU/Common/FragmentShaderGenerator.h"
30
31
class D3D11Context;
32
class D3D11PushBuffer;
33
34
class D3D11FragmentShader {
35
public:
36
D3D11FragmentShader(ID3D11Device *device, D3D_FEATURE_LEVEL featureLevel, FShaderID id, const char *code, bool useHWTransform);
37
~D3D11FragmentShader();
38
39
const std::string &source() const { return source_; }
40
41
bool Failed() const { return failed_; }
42
bool UseHWTransform() const { return useHWTransform_; }
43
44
std::string GetShaderString(DebugShaderStringType type) const;
45
ID3D11PixelShader *GetShader() const { return module_.Get(); }
46
47
protected:
48
Microsoft::WRL::ComPtr<ID3D11PixelShader> module_;
49
50
ID3D11Device *device_;
51
std::string source_;
52
bool failed_ = false;
53
bool useHWTransform_;
54
FShaderID id_;
55
};
56
57
class D3D11VertexShader {
58
public:
59
D3D11VertexShader(ID3D11Device *device, D3D_FEATURE_LEVEL featureLevel, VShaderID id, const char *code, bool useHWTransform);
60
~D3D11VertexShader();
61
62
const std::string &source() const { return source_; }
63
const std::vector<uint8_t> &bytecode() const { return bytecode_; }
64
bool Failed() const { return failed_; }
65
bool UseHWTransform() const { return useHWTransform_; }
66
67
std::string GetShaderString(DebugShaderStringType type) const;
68
ID3D11VertexShader *GetShader() const { return module_.Get(); }
69
70
protected:
71
Microsoft::WRL::ComPtr<ID3D11VertexShader> module_;
72
73
ID3D11Device *device_;
74
std::string source_;
75
std::vector<uint8_t> bytecode_;
76
77
bool failed_ = false;
78
bool useHWTransform_;
79
VShaderID id_;
80
};
81
82
class D3D11PushBuffer;
83
84
class ShaderManagerD3D11 : public ShaderManagerCommon {
85
public:
86
ShaderManagerD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context, D3D_FEATURE_LEVEL featureLevel);
87
~ShaderManagerD3D11();
88
89
void GetShaders(int prim, u32 vertexType, D3D11VertexShader **vshader, D3D11FragmentShader **fshader, const ComputedPipelineState &pipelineState, bool useHWTransform, bool useHWTessellation, bool weightsAsFloat, bool useSkinInDecode);
90
void ClearShaders() override;
91
void DirtyLastShader() override;
92
93
void InitDeviceObjects();
94
void DestroyDeviceObjects();
95
96
void DeviceLost() override;
97
void DeviceRestore(Draw::DrawContext *draw) override;
98
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
99
int GetNumFragmentShaders() const { return (int)fsCache_.size(); }
100
101
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) override;
102
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) override;
103
104
uint64_t UpdateUniforms(bool useBufferedRendering);
105
void BindUniforms();
106
107
// TODO: Avoid copying these buffers if same as last draw, can still point to it assuming we're still in the same pushbuffer.
108
// Applies dirty changes and copies the buffer.
109
bool IsBaseDirty() { return true; }
110
bool IsLightDirty() { return true; }
111
bool IsBoneDirty() { return true; }
112
113
private:
114
void Clear();
115
116
ID3D11Device *device_;
117
ID3D11DeviceContext *context_;
118
D3D_FEATURE_LEVEL featureLevel_;
119
120
typedef std::map<FShaderID, D3D11FragmentShader *> FSCache;
121
FSCache fsCache_;
122
123
typedef std::map<VShaderID, D3D11VertexShader *> VSCache;
124
VSCache vsCache_;
125
126
char *codeBuffer_;
127
128
// Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time.
129
UB_VS_FS_Base ub_base;
130
UB_VS_Lights ub_lights;
131
UB_VS_Bones ub_bones;
132
133
// Not actual pushbuffers, requires D3D11.1, let's try to live without that first.
134
Microsoft::WRL::ComPtr<ID3D11Buffer> push_base;
135
Microsoft::WRL::ComPtr<ID3D11Buffer> push_lights;
136
Microsoft::WRL::ComPtr<ID3D11Buffer> push_bones;
137
138
D3D11FragmentShader *lastFShader_ = nullptr;
139
D3D11VertexShader *lastVShader_ = nullptr;
140
141
FShaderID lastFSID_;
142
VShaderID lastVSID_;
143
};
144
145