2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-09-18 00:16:52 +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-09-18 00:16:52 +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-09-18 00:16:52 +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-09-18 00:16:52 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GSVector.h"
|
|
|
|
#include "GSDevice.h"
|
|
|
|
#include "GSAlignedClass.h"
|
|
|
|
|
|
|
|
class GSDeviceDX : public GSDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
2016-05-11 23:24:37 +00:00
|
|
|
struct alignas(32) VSConstantBuffer
|
2009-09-18 00:16:52 +00:00
|
|
|
{
|
|
|
|
GSVector4 VertexScale;
|
|
|
|
GSVector4 VertexOffset;
|
2017-02-17 09:59:21 +00:00
|
|
|
GSVector4 Texture_Scale_Offset;
|
2009-09-18 00:16:52 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
struct VSConstantBuffer()
|
2009-09-18 00:16:52 +00:00
|
|
|
{
|
|
|
|
VertexScale = GSVector4::zero();
|
|
|
|
VertexOffset = GSVector4::zero();
|
2017-02-17 09:59:21 +00:00
|
|
|
Texture_Scale_Offset = GSVector4::zero();
|
2009-09-18 00:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline bool Update(const VSConstantBuffer* cb)
|
|
|
|
{
|
|
|
|
GSVector4i* a = (GSVector4i*)this;
|
|
|
|
GSVector4i* b = (GSVector4i*)cb;
|
|
|
|
|
2017-02-17 09:59:21 +00:00
|
|
|
if(!((a[0] == b[0]) & (a[1] == b[1]) & (a[2] == b[2]) & (a[3] == b[3])).alltrue())
|
2009-09-18 00:16:52 +00:00
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
a[0] = b[0];
|
|
|
|
a[1] = b[1];
|
|
|
|
a[2] = b[2];
|
|
|
|
a[3] = b[3];
|
2009-09-18 00:16:52 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VSSelector
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 bppz:2;
|
|
|
|
uint32 tme:1;
|
|
|
|
uint32 fst:1;
|
|
|
|
uint32 logz:1;
|
2010-05-14 14:05:39 +00:00
|
|
|
uint32 rtcopy:1;
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32 key;
|
|
|
|
};
|
|
|
|
|
2012-06-19 00:35:42 +00:00
|
|
|
operator uint32() {return key & 0xff;}
|
2009-09-18 00:16:52 +00:00
|
|
|
|
|
|
|
VSSelector() : key(0) {}
|
|
|
|
};
|
|
|
|
|
2016-05-11 23:24:37 +00:00
|
|
|
struct alignas(32) PSConstantBuffer
|
2009-09-18 00:16:52 +00:00
|
|
|
{
|
|
|
|
GSVector4 FogColor_AREF;
|
|
|
|
GSVector4 HalfTexel;
|
|
|
|
GSVector4 WH;
|
|
|
|
GSVector4 MinMax;
|
|
|
|
GSVector4 MinF_TA;
|
|
|
|
GSVector4i MskFix;
|
|
|
|
|
2013-02-12 10:57:48 +00:00
|
|
|
GSVector4 TC_OffsetHack;
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
struct PSConstantBuffer()
|
2009-09-18 00:16:52 +00:00
|
|
|
{
|
|
|
|
FogColor_AREF = GSVector4::zero();
|
|
|
|
HalfTexel = GSVector4::zero();
|
|
|
|
WH = GSVector4::zero();
|
|
|
|
MinMax = GSVector4::zero();
|
|
|
|
MinF_TA = GSVector4::zero();
|
|
|
|
MskFix = GSVector4i::zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline bool Update(const PSConstantBuffer* cb)
|
|
|
|
{
|
|
|
|
GSVector4i* a = (GSVector4i*)this;
|
|
|
|
GSVector4i* b = (GSVector4i*)cb;
|
|
|
|
|
2017-02-17 09:59:21 +00:00
|
|
|
if(!((a[0] == b[0]) /*& (a[1] == b1)*/ & (a[2] == b[2]) & (a[3] == b[3]) & (a[4] == b[4]) & (a[5] == b[5])).alltrue()) // if WH matches HalfTexel does too
|
2009-09-18 00:16:52 +00:00
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
a[0] = b[0];
|
|
|
|
a[1] = b[1];
|
|
|
|
a[2] = b[2];
|
|
|
|
a[3] = b[3];
|
|
|
|
a[4] = b[4];
|
|
|
|
a[5] = b[5];
|
2009-09-18 00:16:52 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-03 21:18:49 +00:00
|
|
|
struct alignas(32) GSConstantBuffer
|
|
|
|
{
|
|
|
|
GSVector2 PointSize;
|
|
|
|
|
|
|
|
struct GSConstantBuffer()
|
|
|
|
{
|
|
|
|
PointSize = GSVector2(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline bool Update(const GSConstantBuffer* cb)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
struct GSSelector
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 iip:1;
|
|
|
|
uint32 prim:2;
|
2017-03-03 21:18:49 +00:00
|
|
|
uint32 point:1;
|
|
|
|
uint32 line:1;
|
|
|
|
|
|
|
|
uint32 _free:27;
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32 key;
|
|
|
|
};
|
|
|
|
|
2017-03-03 21:18:49 +00:00
|
|
|
operator uint32() {return key;}
|
2009-09-18 00:16:52 +00:00
|
|
|
|
|
|
|
GSSelector() : key(0) {}
|
2017-03-03 21:18:49 +00:00
|
|
|
GSSelector(uint32 k) : key(k) {}
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PSSelector
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 fst:1;
|
|
|
|
uint32 wms:2;
|
|
|
|
uint32 wmt:2;
|
2017-02-17 09:59:21 +00:00
|
|
|
uint32 fmt:4;
|
2009-09-18 00:16:52 +00:00
|
|
|
uint32 aem:1;
|
|
|
|
uint32 tfx:3;
|
|
|
|
uint32 tcc:1;
|
|
|
|
uint32 atst:3;
|
|
|
|
uint32 fog:1;
|
|
|
|
uint32 clr1:1;
|
|
|
|
uint32 fba:1;
|
|
|
|
uint32 aout:1;
|
|
|
|
uint32 rt:1;
|
|
|
|
uint32 ltf:1;
|
2010-03-12 19:01:05 +00:00
|
|
|
uint32 colclip:2;
|
2010-05-14 14:05:39 +00:00
|
|
|
uint32 date:2;
|
2012-06-19 01:12:01 +00:00
|
|
|
uint32 spritehack:1;
|
2013-02-12 10:57:48 +00:00
|
|
|
uint32 tcoffsethack:1;
|
2012-07-19 20:40:42 +00:00
|
|
|
uint32 point_sampler:1;
|
2015-06-09 23:17:26 +00:00
|
|
|
uint32 shuffle:1;
|
|
|
|
uint32 read_ba:1;
|
2017-02-17 09:59:21 +00:00
|
|
|
|
|
|
|
uint32 _free:32;
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
|
|
|
|
2017-02-17 09:59:21 +00:00
|
|
|
uint64 key;
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
|
|
|
|
2017-02-17 09:59:21 +00:00
|
|
|
operator uint64() {return key;}
|
2009-09-18 00:16:52 +00:00
|
|
|
|
|
|
|
PSSelector() : key(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PSSamplerSelector
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 tau:1;
|
|
|
|
uint32 tav:1;
|
|
|
|
uint32 ltf:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32 key;
|
|
|
|
};
|
|
|
|
|
|
|
|
operator uint32() {return key & 0x7;}
|
|
|
|
|
|
|
|
PSSamplerSelector() : key(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OMDepthStencilSelector
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 ztst:2;
|
|
|
|
uint32 zwe:1;
|
|
|
|
uint32 date:1;
|
|
|
|
uint32 fba:1;
|
2012-07-24 02:20:07 +00:00
|
|
|
uint32 alpha_stencil:1;
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32 key;
|
|
|
|
};
|
|
|
|
|
2012-07-24 02:20:07 +00:00
|
|
|
operator uint32() {return key & 0x3f;}
|
2009-09-18 00:16:52 +00:00
|
|
|
|
|
|
|
OMDepthStencilSelector() : key(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OMBlendSelector
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 abe:1;
|
|
|
|
uint32 a:2;
|
|
|
|
uint32 b:2;
|
|
|
|
uint32 c:2;
|
|
|
|
uint32 d:2;
|
|
|
|
uint32 wr:1;
|
|
|
|
uint32 wg:1;
|
|
|
|
uint32 wb:1;
|
|
|
|
uint32 wa:1;
|
2010-03-12 19:01:05 +00:00
|
|
|
uint32 negative:1;
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 _pad:1;
|
|
|
|
uint32 abcd:8;
|
|
|
|
uint32 wrgba:4;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32 key;
|
|
|
|
};
|
|
|
|
|
2010-03-12 19:01:05 +00:00
|
|
|
operator uint32() {return key & 0x3fff;}
|
2009-09-18 00:16:52 +00:00
|
|
|
|
|
|
|
OMBlendSelector() : key(0) {}
|
|
|
|
|
|
|
|
bool IsCLR1() const
|
|
|
|
{
|
|
|
|
return (key & 0x19f) == 0x93; // abe == 1 && a == 1 && b == 2 && d == 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
struct D3D9Blend {int bogus, op, src, dst;};
|
|
|
|
static const D3D9Blend m_blendMapD3D9[3*3*3*3];
|
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2011-02-18 03:50:12 +00:00
|
|
|
protected:
|
2012-01-13 18:10:05 +00:00
|
|
|
struct {D3D_FEATURE_LEVEL level; string model, vs, gs, ps, cs;} m_shader;
|
2011-02-18 03:50:12 +00:00
|
|
|
uint32 m_msaa;
|
|
|
|
DXGI_SAMPLE_DESC m_msaa_desc;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-03-19 19:07:02 +00:00
|
|
|
static HMODULE s_d3d_compiler_dll;
|
|
|
|
static decltype(&D3DCompile) s_pD3DCompile;
|
|
|
|
// Older version doesn't support D3D_COMPILE_STANDARD_FILE_INCLUDE, which
|
|
|
|
// could be useful for external shaders.
|
|
|
|
static bool s_old_d3d_compiler_dll;
|
|
|
|
|
2011-02-22 23:39:02 +00:00
|
|
|
GSTexture* FetchSurface(int type, int w, int h, bool msaa, int format);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-18 03:50:12 +00:00
|
|
|
public:
|
|
|
|
GSDeviceDX();
|
|
|
|
virtual ~GSDeviceDX();
|
|
|
|
|
|
|
|
bool SetFeatureLevel(D3D_FEATURE_LEVEL level, bool compat_mode);
|
2012-01-13 18:10:05 +00:00
|
|
|
void GetFeatureLevel(D3D_FEATURE_LEVEL& level) const {level = m_shader.level;}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
virtual void SetupVS(VSSelector sel, const VSConstantBuffer* cb) = 0;
|
2017-03-03 21:18:49 +00:00
|
|
|
virtual void SetupGS(GSSelector sel, const GSConstantBuffer* cb) = 0;
|
2009-09-18 00:16:52 +00:00
|
|
|
virtual void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel) = 0;
|
|
|
|
virtual void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix) = 0;
|
2009-11-07 17:50:48 +00:00
|
|
|
|
2011-02-18 03:50:12 +00:00
|
|
|
virtual void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm) = 0;
|
2010-05-14 14:05:39 +00:00
|
|
|
|
|
|
|
virtual bool HasStencil() = 0;
|
|
|
|
virtual bool HasDepth32() = 0;
|
2011-02-18 03:50:12 +00:00
|
|
|
|
2016-03-19 19:07:02 +00:00
|
|
|
static bool LoadD3DCompiler();
|
|
|
|
static void FreeD3DCompiler();
|
|
|
|
|
2011-02-18 03:50:12 +00:00
|
|
|
template<class T> void PrepareShaderMacro(vector<T>& dst, const T* src)
|
|
|
|
{
|
|
|
|
dst.clear();
|
|
|
|
|
|
|
|
while(src && src->Definition && src->Name)
|
|
|
|
{
|
|
|
|
dst.push_back(*src++);
|
|
|
|
}
|
|
|
|
|
|
|
|
T m;
|
|
|
|
|
|
|
|
m.Name = "SHADER_MODEL";
|
|
|
|
m.Definition = m_shader.model.c_str();
|
|
|
|
|
|
|
|
dst.push_back(m);
|
|
|
|
|
|
|
|
m.Name = NULL;
|
|
|
|
m.Definition = NULL;
|
|
|
|
|
|
|
|
dst.push_back(m);
|
|
|
|
}
|
2009-09-18 00:16:52 +00:00
|
|
|
};
|
2011-02-22 23:39:02 +00:00
|
|
|
|