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