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/DrawEngineD3D11.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 <d3d11.h>
21
#include <d3d11_1.h>
22
23
#include "Common/Data/Collections/Hashmaps.h"
24
#include "GPU/GPUState.h"
25
#include "GPU/Common/GPUDebugInterface.h"
26
#include "GPU/Common/IndexGenerator.h"
27
#include "GPU/Common/VertexDecoderCommon.h"
28
#include "GPU/Common/DrawEngineCommon.h"
29
#include "GPU/Common/GPUStateUtils.h"
30
#include "GPU/D3D11/StateMappingD3D11.h"
31
#include "GPU/D3D11/D3D11Util.h"
32
33
struct DecVtxFormat;
34
struct UVScale;
35
36
class D3D11VertexShader;
37
class ShaderManagerD3D11;
38
class TextureCacheD3D11;
39
class FramebufferManagerD3D11;
40
41
class TessellationDataTransferD3D11 : public TessellationDataTransfer {
42
private:
43
ID3D11DeviceContext *context_;
44
ID3D11Device *device_;
45
ID3D11Buffer *buf[3]{};
46
ID3D11ShaderResourceView *view[3]{};
47
D3D11_BUFFER_DESC desc{};
48
int prevSize = 0;
49
int prevSizeWU = 0, prevSizeWV = 0;
50
public:
51
TessellationDataTransferD3D11(ID3D11DeviceContext *context, ID3D11Device *device);
52
~TessellationDataTransferD3D11();
53
// Send spline/bezier's control points and weights to vertex shader through structured shader buffer.
54
void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;
55
};
56
57
// Handles transform, lighting and drawing.
58
class DrawEngineD3D11 : public DrawEngineCommon {
59
public:
60
DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context);
61
~DrawEngineD3D11();
62
63
void DeviceLost() override { draw_ = nullptr; }
64
void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; }
65
66
void SetShaderManager(ShaderManagerD3D11 *shaderManager) {
67
shaderManager_ = shaderManager;
68
}
69
void SetTextureCache(TextureCacheD3D11 *textureCache) {
70
textureCache_ = textureCache;
71
}
72
void SetFramebufferManager(FramebufferManagerD3D11 *fbManager) {
73
framebufferManager_ = fbManager;
74
}
75
void InitDeviceObjects();
76
void DestroyDeviceObjects();
77
78
void BeginFrame();
79
80
// So that this can be inlined
81
void Flush() {
82
if (!numDrawVerts_)
83
return;
84
DoFlush();
85
}
86
87
void FinishDeferred() {
88
if (!numDrawVerts_)
89
return;
90
DecodeVerts(decoded_);
91
}
92
93
void DispatchFlush() override {
94
if (!numDrawVerts_)
95
return;
96
Flush();
97
}
98
99
void NotifyConfigChanged() override;
100
101
void ClearInputLayoutMap();
102
103
private:
104
void Invalidate(InvalidationCallbackFlags flags);
105
106
void DoFlush();
107
108
void ApplyDrawState(int prim);
109
void ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef);
110
111
ID3D11InputLayout *SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
112
113
Draw::DrawContext *draw_; // Used for framebuffer related things exclusively.
114
ID3D11Device *device_;
115
ID3D11Device1 *device1_;
116
ID3D11DeviceContext *context_;
117
ID3D11DeviceContext1 *context1_;
118
119
struct InputLayoutKey {
120
D3D11VertexShader *vshader;
121
u32 decFmtId;
122
bool operator <(const InputLayoutKey &other) const {
123
if (decFmtId < other.decFmtId)
124
return true;
125
if (decFmtId > other.decFmtId)
126
return false;
127
return vshader < other.vshader;
128
}
129
};
130
131
DenseHashMap<InputLayoutKey, ID3D11InputLayout *> inputLayoutMap_;
132
133
// Other
134
ShaderManagerD3D11 *shaderManager_ = nullptr;
135
TextureCacheD3D11 *textureCache_ = nullptr;
136
FramebufferManagerD3D11 *framebufferManager_ = nullptr;
137
138
// Pushbuffers
139
PushBufferD3D11 *pushVerts_;
140
PushBufferD3D11 *pushInds_;
141
142
// D3D11 state object caches.
143
DenseHashMap<uint64_t, ID3D11BlendState *> blendCache_;
144
DenseHashMap<uint64_t, ID3D11BlendState1 *> blendCache1_;
145
DenseHashMap<uint64_t, ID3D11DepthStencilState *> depthStencilCache_;
146
DenseHashMap<uint32_t, ID3D11RasterizerState *> rasterCache_;
147
148
// Keep the depth state between ApplyDrawState and ApplyDrawStateLate
149
ID3D11RasterizerState *rasterState_ = nullptr;
150
ID3D11BlendState *blendState_ = nullptr;
151
ID3D11BlendState1 *blendState1_ = nullptr;
152
ID3D11DepthStencilState *depthStencilState_ = nullptr;
153
154
// State keys
155
D3D11StateKeys keys_{};
156
D3D11DynamicState dynState_{};
157
158
// Hardware tessellation
159
TessellationDataTransferD3D11 *tessDataTransferD3D11;
160
161
int lastRenderStepId_ = -1;
162
};
163
164