forked from s90110019/Gsdx-cutie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GSDevice9.h
266 lines (221 loc) · 8.21 KB
/
GSDevice9.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* Copyright (C) 2007-2009 Gabest
* http://www.gabest.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "GSDeviceDX.h"
#include "GSTexture9.h"
struct Direct3DSamplerState9
{
D3DTEXTUREFILTERTYPE FilterMin[2];
D3DTEXTUREFILTERTYPE FilterMag[2];
D3DTEXTUREFILTERTYPE FilterMip[2];
D3DTEXTUREFILTERTYPE Anisotropic[2];
D3DTEXTUREADDRESS AddressU;
D3DTEXTUREADDRESS AddressV;
D3DTEXTUREADDRESS AddressW;
DWORD MaxAnisotropy;
DWORD MaxLOD;
};
struct Direct3DDepthStencilState9
{
BOOL DepthEnable;
BOOL DepthWriteMask;
D3DCMPFUNC DepthFunc;
BOOL StencilEnable;
UINT8 StencilReadMask;
UINT8 StencilWriteMask;
D3DSTENCILOP StencilFailOp;
D3DSTENCILOP StencilDepthFailOp;
D3DSTENCILOP StencilPassOp;
D3DCMPFUNC StencilFunc;
uint32 StencilRef;
};
struct Direct3DBlendState9
{
BOOL BlendEnable;
D3DBLEND SrcBlend;
D3DBLEND DestBlend;
D3DBLENDOP BlendOp;
D3DBLEND SrcBlendAlpha;
D3DBLEND DestBlendAlpha;
D3DBLENDOP BlendOpAlpha;
UINT8 RenderTargetWriteMask;
};
struct GSVertexShader9
{
CComPtr<IDirect3DVertexShader9> vs;
CComPtr<IDirect3DVertexDeclaration9> il;
};
class GSDevice9 : public GSDeviceDX
{
GSTexture* CreateSurface(int type, int w, int h, bool msaa, int format);
void DoMerge(GSTexture* sTex[2], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, bool slbg, bool mmod, const GSVector4& c);
void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0);
void DoFXAA(GSTexture* sTex, GSTexture* dTex);
void DoShadeBoost(GSTexture* sTex, GSTexture* dTex);
void DoExternalFX(GSTexture* sTex, GSTexture* dTex);
void DoCustomShader(GSTexture* sTex, GSTexture* dTex);
void InitExternalFX();
void InitCustomShader();
void InitFXAA();
//
D3DCAPS9 m_d3dcaps;
D3DPRESENT_PARAMETERS m_pp;
CComPtr<IDirect3D9> m_d3d;
CComPtr<IDirect3DDevice9> m_dev;
CComPtr<IDirect3DSwapChain9> m_swapchain;
CComPtr<IDirect3DVertexBuffer9> m_vb;
CComPtr<IDirect3DVertexBuffer9> m_vb_old;
CComPtr<IDirect3DIndexBuffer9> m_ib;
CComPtr<IDirect3DIndexBuffer9> m_ib_old;
bool m_lost;
D3DFORMAT m_depth_format;
struct
{
IDirect3DVertexBuffer9* vb;
size_t vb_stride;
IDirect3DIndexBuffer9* ib;
IDirect3DVertexDeclaration9* layout;
D3DPRIMITIVETYPE topology;
IDirect3DVertexShader9* vs;
float* vs_cb;
int vs_cb_len;
IDirect3DTexture9* ps_srvs[3];
IDirect3DPixelShader9* ps;
float* ps_cb;
int ps_cb_len;
Direct3DSamplerState9* ps_ss;
GSVector4i scissor;
Direct3DDepthStencilState9* dss;
Direct3DBlendState9* bs;
uint32 bf;
IDirect3DSurface9* rtv;
IDirect3DSurface9* dsv;
} m_state;
public: // TODO
bool FXAA_Compiled;
bool ExShader_Compiled;
bool CustomShader_Compiled;
struct
{
CComPtr<IDirect3DVertexDeclaration9> il;
CComPtr<IDirect3DVertexShader9> vs;
CComPtr<IDirect3DPixelShader9> ps[10];
Direct3DSamplerState9 ln;
Direct3DSamplerState9 pt;
Direct3DDepthStencilState9 dss;
Direct3DBlendState9 bs;
} m_convert;
struct
{
CComPtr<IDirect3DPixelShader9> ps[2];
Direct3DBlendState9 bs;
} m_merge;
struct
{
CComPtr<IDirect3DPixelShader9> ps[4];
} m_interlace;
struct
{
CComPtr<IDirect3DPixelShader9> ps;
} m_shaderfx;
struct
{
CComPtr<IDirect3DPixelShader9> ps;
} m_customshader;
struct
{
CComPtr<IDirect3DPixelShader9> ps;
} m_fxaa;
struct
{
CComPtr<IDirect3DPixelShader9> ps;
} m_shadeboost;
struct
{
Direct3DDepthStencilState9 dss;
Direct3DBlendState9 bs;
} m_date;
void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm);
// Shaders...
hash_map<uint32, GSVertexShader9 > m_vs;
hash_map<uint32, CComPtr<IDirect3DPixelShader9> > m_ps;
hash_map<uint32, Direct3DSamplerState9* > m_ps_ss;
hash_map<uint32, Direct3DDepthStencilState9* > m_om_dss;
hash_map<uint32, Direct3DBlendState9* > m_om_bs;
hash_map<uint32, GSTexture*> m_mskfix;
GSTexture* CreateMskFix(uint32 size, uint32 msk, uint32 fix);
public:
GSDevice9();
virtual ~GSDevice9();
bool Create(GSWnd* wnd);
bool Reset(int w, int h);
bool IsLost(bool update);
void Flip();
void SetVSync(bool enable);
void BeginScene();
void DrawPrimitive();
void DrawIndexedPrimitive();
void EndScene();
void ClearRenderTarget(GSTexture* t, const GSVector4& c);
void ClearRenderTarget(GSTexture* t, uint32 c);
void ClearDepth(GSTexture* t, float c);
void ClearStencil(GSTexture* t, uint8 c);
GSTexture* CreateRenderTarget(int w, int h, bool msaa, int format = 0);
GSTexture* CreateDepthStencil(int w, int h, bool msaa, int format = 0);
GSTexture* CreateTexture(int w, int h, int format = 0);
GSTexture* CreateOffscreen(int w, int h, int format = 0);
GSTexture* Resolve(GSTexture* t);
GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, int ps_shader = 0);
void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r);
void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, int shader = 0, bool linear = true);
void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, IDirect3DPixelShader9* ps, const float* ps_cb, int ps_cb_len, bool linear = true);
void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, IDirect3DPixelShader9* ps, const float* ps_cb, int ps_cb_len, Direct3DBlendState9* bs, bool linear = true);
void IASetVertexBuffer(const void* vertex, size_t stride, size_t count);
bool IAMapVertexBuffer(void** vertex, size_t stride, size_t count);
void IAUnmapVertexBuffer();
void IASetVertexBuffer(IDirect3DVertexBuffer9* vb, size_t stride);
void IASetIndexBuffer(const void* index, size_t count);
void IASetIndexBuffer(IDirect3DIndexBuffer9* ib);
void IASetInputLayout(IDirect3DVertexDeclaration9* layout);
void IASetPrimitiveTopology(D3DPRIMITIVETYPE topology);
void VSSetShader(IDirect3DVertexShader9* vs, const float* vs_cb, int vs_cb_len);
void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1);
void PSSetShaderResource(int i, GSTexture* sRect);
void PSSetShader(IDirect3DPixelShader9* ps, const float* ps_cb, int ps_cb_len);
void PSSetSamplerState(Direct3DSamplerState9* ss);
void OMSetDepthStencilState(Direct3DDepthStencilState9* dss);
void OMSetBlendState(Direct3DBlendState9* bs, uint32 bf);
void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL);
IDirect3DDevice9* operator->() {return m_dev;}
operator IDirect3DDevice9*() {return m_dev;}
void CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il);
void CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps);
void CompileShader(const char* fn, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il);
void CompileShader(const char* fn, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps);
void SetupVS(VSSelector sel, const VSConstantBuffer* cb);
void SetupGS(GSSelector sel) {}
void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel);
void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix);
bool HasStencil() { return m_depth_format == D3DFMT_D24S8; }
bool HasDepth32() { return m_depth_format != D3DFMT_D24S8; }
static uint32 GetMaxDepth(uint32 msaaCount = 0, std::string adapter_id = "");
static void ForceValidMsaaConfig();
};