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