2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
#include "GSDeviceDX.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSTexture9.h"
|
|
|
|
|
|
|
|
struct Direct3DSamplerState9
|
|
|
|
{
|
|
|
|
D3DTEXTUREFILTERTYPE FilterMin[2];
|
|
|
|
D3DTEXTUREFILTERTYPE FilterMag[2];
|
2014-02-03 16:58:11 +00:00
|
|
|
D3DTEXTUREFILTERTYPE FilterMip[2];
|
|
|
|
D3DTEXTUREFILTERTYPE Anisotropic[2];
|
2009-02-09 21:15:56 +00:00
|
|
|
D3DTEXTUREADDRESS AddressU;
|
|
|
|
D3DTEXTUREADDRESS AddressV;
|
2014-02-03 16:58:11 +00:00
|
|
|
D3DTEXTUREADDRESS AddressW;
|
|
|
|
DWORD MaxAnisotropy;
|
|
|
|
DWORD MaxLOD;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Direct3DDepthStencilState9
|
|
|
|
{
|
|
|
|
BOOL DepthEnable;
|
|
|
|
BOOL DepthWriteMask;
|
|
|
|
D3DCMPFUNC DepthFunc;
|
|
|
|
BOOL StencilEnable;
|
|
|
|
UINT8 StencilReadMask;
|
|
|
|
UINT8 StencilWriteMask;
|
|
|
|
D3DSTENCILOP StencilFailOp;
|
|
|
|
D3DSTENCILOP StencilDepthFailOp;
|
|
|
|
D3DSTENCILOP StencilPassOp;
|
|
|
|
D3DCMPFUNC StencilFunc;
|
2009-06-17 11:24:42 +00:00
|
|
|
uint32 StencilRef;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Direct3DBlendState9
|
|
|
|
{
|
|
|
|
BOOL BlendEnable;
|
|
|
|
D3DBLEND SrcBlend;
|
|
|
|
D3DBLEND DestBlend;
|
|
|
|
D3DBLENDOP BlendOp;
|
|
|
|
D3DBLEND SrcBlendAlpha;
|
|
|
|
D3DBLEND DestBlendAlpha;
|
|
|
|
D3DBLENDOP BlendOpAlpha;
|
|
|
|
UINT8 RenderTargetWriteMask;
|
|
|
|
};
|
|
|
|
|
2010-03-19 18:02:56 +00:00
|
|
|
struct GSVertexShader9
|
|
|
|
{
|
|
|
|
CComPtr<IDirect3DVertexShader9> vs;
|
|
|
|
CComPtr<IDirect3DVertexDeclaration9> il;
|
|
|
|
};
|
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
class GSDevice9 : public GSDeviceDX
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-22 23:39:02 +00:00
|
|
|
GSTexture* CreateSurface(int type, int w, int h, bool msaa, int format);
|
2009-05-22 01:22:52 +00:00
|
|
|
|
2016-10-09 11:20:31 +00:00
|
|
|
void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c);
|
2015-05-15 18:45:31 +00:00
|
|
|
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);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2014-02-02 17:50:32 +00:00
|
|
|
void InitExternalFX();
|
|
|
|
void InitFXAA();
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
D3DCAPS9 m_d3dcaps;
|
2009-07-04 22:54:57 +00:00
|
|
|
D3DPRESENT_PARAMETERS m_pp;
|
2009-02-09 21:15:56 +00:00
|
|
|
CComPtr<IDirect3D9> m_d3d;
|
|
|
|
CComPtr<IDirect3DDevice9> m_dev;
|
|
|
|
CComPtr<IDirect3DSwapChain9> m_swapchain;
|
2009-07-31 23:59:06 +00:00
|
|
|
CComPtr<IDirect3DVertexBuffer9> m_vb;
|
|
|
|
CComPtr<IDirect3DVertexBuffer9> m_vb_old;
|
2012-01-05 02:40:24 +00:00
|
|
|
CComPtr<IDirect3DIndexBuffer9> m_ib;
|
|
|
|
CComPtr<IDirect3DIndexBuffer9> m_ib_old;
|
2009-07-04 15:14:04 +00:00
|
|
|
bool m_lost;
|
2010-05-14 14:05:39 +00:00
|
|
|
D3DFORMAT m_depth_format;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-26 03:40:31 +00:00
|
|
|
struct
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
IDirect3DVertexBuffer9* vb;
|
|
|
|
size_t vb_stride;
|
2012-01-05 02:40:24 +00:00
|
|
|
IDirect3DIndexBuffer9* ib;
|
2009-07-31 23:59:06 +00:00
|
|
|
IDirect3DVertexDeclaration9* layout;
|
|
|
|
D3DPRIMITIVETYPE topology;
|
|
|
|
IDirect3DVertexShader9* vs;
|
|
|
|
float* vs_cb;
|
|
|
|
int vs_cb_len;
|
2010-05-14 14:05:39 +00:00
|
|
|
IDirect3DTexture9* ps_srvs[3];
|
2009-07-31 23:59:06 +00:00
|
|
|
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;
|
2009-05-26 03:40:31 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public: // TODO
|
|
|
|
|
2014-02-02 17:50:32 +00:00
|
|
|
bool FXAA_Compiled;
|
2014-01-17 10:17:24 +00:00
|
|
|
bool ExShader_Compiled;
|
2014-01-06 22:51:45 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<IDirect3DVertexDeclaration9> il;
|
2009-05-23 23:52:53 +00:00
|
|
|
CComPtr<IDirect3DVertexShader9> vs;
|
2014-01-12 19:47:49 +00:00
|
|
|
CComPtr<IDirect3DPixelShader9> ps[10];
|
2009-02-09 21:15:56 +00:00
|
|
|
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;
|
|
|
|
|
2014-01-17 10:17:24 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<IDirect3DPixelShader9> ps;
|
|
|
|
} m_shaderfx;
|
|
|
|
|
2011-07-25 11:16:01 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<IDirect3DPixelShader9> ps;
|
|
|
|
} m_fxaa;
|
|
|
|
|
2012-02-29 00:29:29 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<IDirect3DPixelShader9> ps;
|
|
|
|
} m_shadeboost;
|
|
|
|
|
2009-11-07 17:50:48 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
Direct3DDepthStencilState9 dss;
|
|
|
|
Direct3DBlendState9 bs;
|
|
|
|
} m_date;
|
|
|
|
|
2011-02-18 03:50:12 +00:00
|
|
|
void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm);
|
2009-11-07 17:50:48 +00:00
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
// Shaders...
|
|
|
|
|
2010-03-19 18:02:56 +00:00
|
|
|
hash_map<uint32, GSVertexShader9 > m_vs;
|
2017-02-17 09:59:21 +00:00
|
|
|
hash_map<uint64, CComPtr<IDirect3DPixelShader9> > m_ps;
|
2009-09-18 00:16:52 +00:00
|
|
|
hash_map<uint32, Direct3DSamplerState9* > m_ps_ss;
|
2010-04-25 00:31:27 +00:00
|
|
|
hash_map<uint32, Direct3DDepthStencilState9* > m_om_dss;
|
|
|
|
hash_map<uint32, Direct3DBlendState9* > m_om_bs;
|
2009-09-18 00:16:52 +00:00
|
|
|
hash_map<uint32, GSTexture*> m_mskfix;
|
|
|
|
|
|
|
|
GSTexture* CreateMskFix(uint32 size, uint32 msk, uint32 fix);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public:
|
|
|
|
GSDevice9();
|
|
|
|
virtual ~GSDevice9();
|
|
|
|
|
2017-02-22 21:02:34 +00:00
|
|
|
bool Create(const std::shared_ptr<GSWnd> &wnd);
|
2009-09-18 18:45:37 +00:00
|
|
|
bool Reset(int w, int h);
|
2009-07-04 15:14:04 +00:00
|
|
|
bool IsLost(bool update);
|
2009-10-31 01:06:23 +00:00
|
|
|
void Flip();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
void SetVSync(bool enable);
|
2009-05-22 01:22:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
void BeginScene();
|
2009-05-26 03:40:31 +00:00
|
|
|
void DrawPrimitive();
|
2012-01-05 02:40:24 +00:00
|
|
|
void DrawIndexedPrimitive();
|
2009-02-09 21:15:56 +00:00
|
|
|
void EndScene();
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void ClearRenderTarget(GSTexture* t, const GSVector4& c);
|
|
|
|
void ClearRenderTarget(GSTexture* t, uint32 c);
|
2016-07-27 21:22:46 +00:00
|
|
|
void ClearDepth(GSTexture* t);
|
2009-05-22 01:22:52 +00:00
|
|
|
void ClearStencil(GSTexture* t, uint8 c);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
GSTexture* CreateRenderTarget(int w, int h, bool msaa, int format = 0);
|
|
|
|
GSTexture* CreateDepthStencil(int w, int h, bool msaa, int format = 0);
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* CreateTexture(int w, int h, int format = 0);
|
|
|
|
GSTexture* CreateOffscreen(int w, int h, int format = 0);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
GSTexture* Resolve(GSTexture* t);
|
|
|
|
|
2015-05-19 10:42:14 +00:00
|
|
|
GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, int ps_shader = 0);
|
2009-05-22 01:22:52 +00:00
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r);
|
2009-05-22 01:22:52 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
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);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
void IASetVertexBuffer(const void* vertex, size_t stride, size_t count);
|
2012-01-19 04:53:36 +00:00
|
|
|
bool IAMapVertexBuffer(void** vertex, size_t stride, size_t count);
|
|
|
|
void IAUnmapVertexBuffer();
|
2009-05-23 23:52:53 +00:00
|
|
|
void IASetVertexBuffer(IDirect3DVertexBuffer9* vb, size_t stride);
|
2012-01-05 02:40:24 +00:00
|
|
|
void IASetIndexBuffer(const void* index, size_t count);
|
|
|
|
void IASetIndexBuffer(IDirect3DIndexBuffer9* ib);
|
2009-02-09 21:15:56 +00:00
|
|
|
void IASetInputLayout(IDirect3DVertexDeclaration9* layout);
|
|
|
|
void IASetPrimitiveTopology(D3DPRIMITIVETYPE topology);
|
|
|
|
void VSSetShader(IDirect3DVertexShader9* vs, const float* vs_cb, int vs_cb_len);
|
2009-05-22 01:22:52 +00:00
|
|
|
void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1);
|
2015-05-21 07:48:15 +00:00
|
|
|
void PSSetShaderResource(int i, GSTexture* sr);
|
2009-02-09 21:15:56 +00:00
|
|
|
void PSSetShader(IDirect3DPixelShader9* ps, const float* ps_cb, int ps_cb_len);
|
|
|
|
void PSSetSamplerState(Direct3DSamplerState9* ss);
|
2009-06-17 11:24:42 +00:00
|
|
|
void OMSetDepthStencilState(Direct3DDepthStencilState9* dss);
|
2009-05-14 16:41:52 +00:00
|
|
|
void OMSetBlendState(Direct3DBlendState9* bs, uint32 bf);
|
2009-07-22 03:55:28 +00:00
|
|
|
void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
IDirect3DDevice9* operator->() {return m_dev;}
|
|
|
|
operator IDirect3DDevice9*() {return m_dev;}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2015-12-16 23:21:09 +00:00
|
|
|
void CompileShader(const char *source, size_t size, const char *filename, const string& entry, const D3D_SHADER_MACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il);
|
|
|
|
void CompileShader(const char *source, size_t size, const char *filename, const string& entry, const D3D_SHADER_MACRO* macro, IDirect3DPixelShader9** ps);
|
2012-08-20 19:46:51 +00:00
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
void SetupVS(VSSelector sel, const VSConstantBuffer* cb);
|
2017-03-03 21:18:49 +00:00
|
|
|
void SetupGS(GSSelector sel, const GSConstantBuffer* cb) {}
|
2009-09-18 00:16:52 +00:00
|
|
|
void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel);
|
|
|
|
void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix);
|
2010-05-14 14:05:39 +00:00
|
|
|
|
|
|
|
bool HasStencil() { return m_depth_format == D3DFMT_D24S8; }
|
|
|
|
bool HasDepth32() { return m_depth_format != D3DFMT_D24S8; }
|
2011-01-02 10:24:36 +00:00
|
|
|
|
2012-08-06 05:26:44 +00:00
|
|
|
static uint32 GetMaxDepth(uint32 msaaCount = 0, std::string adapter_id = "");
|
2011-01-02 10:24:36 +00:00
|
|
|
static void ForceValidMsaaConfig();
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
2011-02-22 23:39:02 +00:00
|
|
|
|