2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2010-04-24 21:37:39 +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
|
|
|
*
|
2010-04-24 21:37:39 +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
|
|
|
*
|
2010-04-24 21:37:39 +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.
|
2010-04-24 21:37:39 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GSDeviceDX.h"
|
|
|
|
#include "GSTexture11.h"
|
|
|
|
|
|
|
|
struct GSVertexShader11
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11VertexShader> vs;
|
|
|
|
CComPtr<ID3D11InputLayout> il;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GSDevice11 : public GSDeviceDX
|
|
|
|
{
|
2011-02-22 23:39:02 +00:00
|
|
|
GSTexture* CreateSurface(int type, int w, int h, bool msaa, int format);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
void DoMerge(GSTexture* sTex[2], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, bool slbg, bool mmod, 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);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-01-17 10:17:24 +00:00
|
|
|
void InitExternalFX();
|
2014-01-09 21:51:42 +00:00
|
|
|
void InitFXAA(); // Bug workaround! Stack corruption? Heap corruption? No idea
|
2014-01-17 10:17:24 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
CComPtr<ID3D11Device> m_dev;
|
|
|
|
CComPtr<ID3D11DeviceContext> m_ctx;
|
|
|
|
CComPtr<IDXGISwapChain> m_swapchain;
|
|
|
|
CComPtr<ID3D11Buffer> m_vb;
|
|
|
|
CComPtr<ID3D11Buffer> m_vb_old;
|
2012-01-05 02:40:24 +00:00
|
|
|
CComPtr<ID3D11Buffer> m_ib;
|
|
|
|
CComPtr<ID3D11Buffer> m_ib_old;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-05-14 14:05:39 +00:00
|
|
|
bool m_srv_changed, m_ss_changed;
|
2015-11-10 22:58:43 +00:00
|
|
|
int spritehack;
|
2016-06-06 19:45:30 +00:00
|
|
|
bool isNative;
|
2010-05-14 14:05:39 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
ID3D11Buffer* vb;
|
|
|
|
size_t vb_stride;
|
2012-01-05 02:40:24 +00:00
|
|
|
ID3D11Buffer* ib;
|
2010-04-24 21:37:39 +00:00
|
|
|
ID3D11InputLayout* layout;
|
|
|
|
D3D11_PRIMITIVE_TOPOLOGY topology;
|
|
|
|
ID3D11VertexShader* vs;
|
|
|
|
ID3D11Buffer* vs_cb;
|
|
|
|
ID3D11GeometryShader* gs;
|
2012-01-18 11:47:31 +00:00
|
|
|
ID3D11ShaderResourceView* ps_srv[16];
|
2010-04-24 21:37:39 +00:00
|
|
|
ID3D11PixelShader* ps;
|
|
|
|
ID3D11Buffer* ps_cb;
|
2010-05-14 14:05:39 +00:00
|
|
|
ID3D11SamplerState* ps_ss[3];
|
2012-01-27 11:56:49 +00:00
|
|
|
ID3D11ShaderResourceView* cs_srv[16];
|
2012-01-13 18:10:05 +00:00
|
|
|
ID3D11ComputeShader* cs;
|
2012-01-27 11:56:49 +00:00
|
|
|
ID3D11Buffer* cs_cb;
|
2010-04-24 21:37:39 +00:00
|
|
|
GSVector2i viewport;
|
|
|
|
GSVector4i scissor;
|
|
|
|
ID3D11DepthStencilState* dss;
|
|
|
|
uint8 sref;
|
|
|
|
ID3D11BlendState* bs;
|
|
|
|
float bf;
|
|
|
|
ID3D11RenderTargetView* rtv;
|
|
|
|
ID3D11DepthStencilView* dsv;
|
|
|
|
} m_state;
|
|
|
|
|
|
|
|
public: // TODO
|
|
|
|
CComPtr<ID3D11RasterizerState> m_rs;
|
|
|
|
|
2014-02-02 17:50:32 +00:00
|
|
|
bool FXAA_Compiled;
|
2014-01-17 10:17:24 +00:00
|
|
|
bool ExShader_Compiled;
|
2014-01-05 23:31:26 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11InputLayout> il;
|
|
|
|
CComPtr<ID3D11VertexShader> vs;
|
2014-01-12 19:47:49 +00:00
|
|
|
CComPtr<ID3D11PixelShader> ps[10];
|
2010-04-24 21:37:39 +00:00
|
|
|
CComPtr<ID3D11SamplerState> ln;
|
|
|
|
CComPtr<ID3D11SamplerState> pt;
|
|
|
|
CComPtr<ID3D11DepthStencilState> dss;
|
|
|
|
CComPtr<ID3D11BlendState> bs;
|
|
|
|
} m_convert;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11PixelShader> ps[2];
|
|
|
|
CComPtr<ID3D11Buffer> cb;
|
|
|
|
CComPtr<ID3D11BlendState> bs;
|
|
|
|
} m_merge;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11PixelShader> ps[4];
|
|
|
|
CComPtr<ID3D11Buffer> cb;
|
|
|
|
} m_interlace;
|
|
|
|
|
2014-01-17 10:17:24 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11PixelShader> ps;
|
|
|
|
CComPtr<ID3D11Buffer> cb;
|
|
|
|
} m_shaderfx;
|
|
|
|
|
2011-07-25 11:16:01 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11PixelShader> ps;
|
|
|
|
CComPtr<ID3D11Buffer> cb;
|
|
|
|
} m_fxaa;
|
|
|
|
|
2012-02-29 00:29:29 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11PixelShader> ps;
|
|
|
|
CComPtr<ID3D11Buffer> cb;
|
|
|
|
} m_shadeboost;
|
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CComPtr<ID3D11DepthStencilState> dss;
|
|
|
|
CComPtr<ID3D11BlendState> bs;
|
|
|
|
} m_date;
|
|
|
|
|
2011-02-18 03:50:12 +00:00
|
|
|
void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
// Shaders...
|
|
|
|
|
|
|
|
hash_map<uint32, GSVertexShader11 > m_vs;
|
|
|
|
CComPtr<ID3D11Buffer> m_vs_cb;
|
|
|
|
hash_map<uint32, CComPtr<ID3D11GeometryShader> > m_gs;
|
|
|
|
hash_map<uint32, CComPtr<ID3D11PixelShader> > m_ps;
|
|
|
|
CComPtr<ID3D11Buffer> m_ps_cb;
|
|
|
|
hash_map<uint32, CComPtr<ID3D11SamplerState> > m_ps_ss;
|
|
|
|
CComPtr<ID3D11SamplerState> m_palette_ss;
|
2010-05-14 14:05:39 +00:00
|
|
|
CComPtr<ID3D11SamplerState> m_rt_ss;
|
2010-04-25 00:31:27 +00:00
|
|
|
hash_map<uint32, CComPtr<ID3D11DepthStencilState> > m_om_dss;
|
|
|
|
hash_map<uint32, CComPtr<ID3D11BlendState> > m_om_bs;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
VSConstantBuffer m_vs_cb_cache;
|
|
|
|
PSConstantBuffer m_ps_cb_cache;
|
|
|
|
|
2011-02-20 18:59:02 +00:00
|
|
|
bool CreateTextureFX();
|
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
public:
|
|
|
|
GSDevice11();
|
|
|
|
virtual ~GSDevice11();
|
|
|
|
|
|
|
|
bool Create(GSWnd* wnd);
|
|
|
|
bool Reset(int w, int h);
|
|
|
|
void Flip();
|
|
|
|
|
|
|
|
void SetExclusive(bool isExcl);
|
|
|
|
|
|
|
|
void DrawPrimitive();
|
2012-01-05 02:40:24 +00:00
|
|
|
void DrawIndexedPrimitive();
|
2012-01-27 11:56:49 +00:00
|
|
|
void DrawIndexedPrimitive(int offset, int count);
|
2012-01-13 18:10:05 +00:00
|
|
|
void Dispatch(uint32 x, uint32 y, uint32 z);
|
2010-04-24 21:37:39 +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);
|
2010-04-24 21:37:39 +00:00
|
|
|
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);
|
|
|
|
|
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);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r);
|
2010-04-24 21:37:39 +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, ID3D11PixelShader* ps, ID3D11Buffer* ps_cb, bool linear = true);
|
|
|
|
void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, ID3D11PixelShader* ps, ID3D11Buffer* ps_cb, ID3D11BlendState* bs, bool linear = true);
|
2010-04-24 21:37:39 +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();
|
2010-04-24 21:37:39 +00:00
|
|
|
void IASetVertexBuffer(ID3D11Buffer* vb, size_t stride);
|
2012-01-05 02:40:24 +00:00
|
|
|
void IASetIndexBuffer(const void* index, size_t count);
|
|
|
|
void IASetIndexBuffer(ID3D11Buffer* ib);
|
2010-04-24 21:37:39 +00:00
|
|
|
void IASetInputLayout(ID3D11InputLayout* layout);
|
|
|
|
void IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY topology);
|
|
|
|
void VSSetShader(ID3D11VertexShader* vs, ID3D11Buffer* vs_cb);
|
|
|
|
void GSSetShader(ID3D11GeometryShader* gs);
|
|
|
|
void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1);
|
2015-05-21 07:48:15 +00:00
|
|
|
void PSSetShaderResource(int i, GSTexture* sr);
|
2012-01-18 11:47:31 +00:00
|
|
|
void PSSetShaderResourceView(int i, ID3D11ShaderResourceView* srv);
|
2010-04-24 21:37:39 +00:00
|
|
|
void PSSetShader(ID3D11PixelShader* ps, ID3D11Buffer* ps_cb);
|
2010-05-14 14:05:39 +00:00
|
|
|
void PSSetSamplerState(ID3D11SamplerState* ss0, ID3D11SamplerState* ss1, ID3D11SamplerState* ss2 = NULL);
|
2012-01-13 18:10:05 +00:00
|
|
|
void CSSetShaderSRV(int i, ID3D11ShaderResourceView* srv);
|
|
|
|
void CSSetShaderUAV(int i, ID3D11UnorderedAccessView* uav);
|
2012-01-27 11:56:49 +00:00
|
|
|
void CSSetShader(ID3D11ComputeShader* cs, ID3D11Buffer* cs_cb);
|
2010-04-24 21:37:39 +00:00
|
|
|
void OMSetDepthStencilState(ID3D11DepthStencilState* dss, uint8 sref);
|
|
|
|
void OMSetBlendState(ID3D11BlendState* bs, float bf);
|
|
|
|
void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL);
|
2012-01-27 11:56:49 +00:00
|
|
|
void OMSetRenderTargets(const GSVector2i& rtsize, int count, ID3D11UnorderedAccessView** uav, uint32* counters, const GSVector4i* scissor = NULL);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-05-14 14:05:39 +00:00
|
|
|
bool HasStencil() { return true; }
|
|
|
|
bool HasDepth32() { return true; }
|
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
ID3D11Device* operator->() {return m_dev;}
|
|
|
|
operator ID3D11Device*() {return m_dev;}
|
|
|
|
operator ID3D11DeviceContext*() {return m_ctx;}
|
|
|
|
|
2015-12-16 23:05:58 +00:00
|
|
|
void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il);
|
|
|
|
void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs);
|
|
|
|
void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count);
|
|
|
|
void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps);
|
|
|
|
void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11ComputeShader** cs);
|
2010-04-24 21:37:39 +00:00
|
|
|
};
|
2011-02-22 23:39:02 +00:00
|
|
|
|