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
|
|
|
|
|
2017-08-04 17:59:41 +00:00
|
|
|
#include "GSFastList.h"
|
2018-11-16 18:41:37 +00:00
|
|
|
#include "Window/GSWnd.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSTexture.h"
|
|
|
|
#include "GSVertex.h"
|
2009-05-22 01:22:52 +00:00
|
|
|
#include "GSAlignedClass.h"
|
2016-09-18 20:40:51 +00:00
|
|
|
#include "GSOsdManager.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2018-10-23 09:52:27 +00:00
|
|
|
enum ShaderConvert
|
|
|
|
{
|
2015-09-08 14:36:23 +00:00
|
|
|
ShaderConvert_COPY = 0,
|
|
|
|
ShaderConvert_RGBA8_TO_16_BITS,
|
|
|
|
ShaderConvert_DATM_1,
|
|
|
|
ShaderConvert_DATM_0,
|
|
|
|
ShaderConvert_MOD_256,
|
|
|
|
ShaderConvert_SCANLINE = 5,
|
|
|
|
ShaderConvert_DIAGONAL_FILTER,
|
|
|
|
ShaderConvert_TRANSPARENCY_FILTER,
|
|
|
|
ShaderConvert_TRIANGULAR_FILTER,
|
|
|
|
ShaderConvert_COMPLEX_FILTER,
|
|
|
|
ShaderConvert_FLOAT32_TO_32_BITS = 10,
|
|
|
|
ShaderConvert_FLOAT32_TO_RGBA8,
|
|
|
|
ShaderConvert_FLOAT16_TO_RGB5A1,
|
|
|
|
ShaderConvert_RGBA8_TO_FLOAT32 = 13,
|
|
|
|
ShaderConvert_RGBA8_TO_FLOAT24,
|
|
|
|
ShaderConvert_RGBA8_TO_FLOAT16,
|
|
|
|
ShaderConvert_RGB5A1_TO_FLOAT16,
|
2016-10-09 12:17:54 +00:00
|
|
|
ShaderConvert_RGBA_TO_8I = 17,
|
2016-10-09 12:28:49 +00:00
|
|
|
ShaderConvert_YUV,
|
2018-12-10 17:31:59 +00:00
|
|
|
ShaderConvert_OSD,
|
2016-10-09 12:17:54 +00:00
|
|
|
ShaderConvert_Count
|
2015-09-08 14:36:23 +00:00
|
|
|
};
|
|
|
|
|
2018-10-23 09:52:27 +00:00
|
|
|
enum ChannelFetch
|
|
|
|
{
|
|
|
|
ChannelFetch_NONE = 0,
|
|
|
|
ChannelFetch_RED = 1,
|
|
|
|
ChannelFetch_GREEN = 2,
|
|
|
|
ChannelFetch_BLUE = 3,
|
|
|
|
ChannelFetch_ALPHA = 4,
|
2018-11-25 03:06:04 +00:00
|
|
|
ChannelFetch_RGB = 5,
|
2018-10-23 09:52:27 +00:00
|
|
|
ChannelFetch_GXBY = 6,
|
|
|
|
};
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
class MergeConstantBuffer
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-18 01:56:05 +00:00
|
|
|
public:
|
2009-02-09 21:15:56 +00:00
|
|
|
GSVector4 BGColor;
|
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
MergeConstantBuffer() {memset(this, 0, sizeof(*this));}
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
class InterlaceConstantBuffer
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-18 01:56:05 +00:00
|
|
|
public:
|
2009-02-09 21:15:56 +00:00
|
|
|
GSVector2 ZrH;
|
|
|
|
float hH;
|
|
|
|
float _pad[1];
|
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
InterlaceConstantBuffer() {memset(this, 0, sizeof(*this));}
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2014-01-17 10:17:24 +00:00
|
|
|
class ExternalFXConstantBuffer
|
|
|
|
{
|
|
|
|
public:
|
2014-11-03 07:15:34 +00:00
|
|
|
GSVector2 xyFrame;
|
2014-01-17 10:17:24 +00:00
|
|
|
GSVector4 rcpFrame;
|
|
|
|
GSVector4 rcpFrameOpt;
|
|
|
|
|
|
|
|
ExternalFXConstantBuffer() { memset(this, 0, sizeof(*this)); }
|
|
|
|
};
|
|
|
|
|
2011-07-25 11:16:01 +00:00
|
|
|
class FXAAConstantBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GSVector4 rcpFrame;
|
|
|
|
GSVector4 rcpFrameOpt;
|
|
|
|
|
|
|
|
FXAAConstantBuffer() {memset(this, 0, sizeof(*this));}
|
|
|
|
};
|
|
|
|
|
2012-02-29 00:29:29 +00:00
|
|
|
class ShadeBoostConstantBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GSVector4 rcpFrame;
|
|
|
|
GSVector4 rcpFrameOpt;
|
|
|
|
|
|
|
|
ShadeBoostConstantBuffer() {memset(this, 0, sizeof(*this));}
|
|
|
|
};
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2019-06-06 14:21:32 +00:00
|
|
|
enum HWBlendFlags
|
|
|
|
{
|
|
|
|
// A couple of flag to determine the blending behavior
|
|
|
|
BLEND_A_MAX = 0x100, // Impossible blending uses coeff bigger than 1
|
|
|
|
BLEND_C_CLR = 0x200, // Clear color blending (use directly the destination color as blending factor)
|
|
|
|
BLEND_NO_BAR = 0x400, // Doesn't require sampling of the RT as a texture
|
|
|
|
BLEND_ACCU = 0x800, // Allow to use a mix of SW and HW blending to keep the best of the 2 worlds
|
|
|
|
};
|
|
|
|
|
|
|
|
// Determines the HW blend function for DX11/OGL
|
|
|
|
struct HWBlend { uint16 flags, op, src, dst; };
|
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
class GSDevice : public GSAlignedClass<32>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2019-06-06 14:21:32 +00:00
|
|
|
private:
|
2017-08-04 17:59:41 +00:00
|
|
|
FastList<GSTexture*> m_pool;
|
2019-06-06 14:21:32 +00:00
|
|
|
static std::array<HWBlend, 3*3*3*3 + 1> m_blendMap;
|
2009-05-22 01:22:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
protected:
|
2019-06-06 14:21:32 +00:00
|
|
|
enum : uint16
|
|
|
|
{
|
|
|
|
// HW blend factors
|
|
|
|
SRC_COLOR, INV_SRC_COLOR, DST_COLOR, INV_DST_COLOR,
|
|
|
|
SRC1_COLOR, INV_SRC1_COLOR, SRC_ALPHA, INV_SRC_ALPHA,
|
|
|
|
DST_ALPHA, INV_DST_ALPHA, SRC1_ALPHA, INV_SRC1_ALPHA,
|
|
|
|
CONST_COLOR, INV_CONST_COLOR, CONST_ONE, CONST_ZERO,
|
|
|
|
|
|
|
|
// HW blend operations
|
|
|
|
OP_ADD, OP_SUBTRACT, OP_REV_SUBTRACT
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int m_NO_BLEND = 0;
|
|
|
|
static const int m_MERGE_BLEND = m_blendMap.size() - 1;
|
|
|
|
|
2017-02-22 21:02:34 +00:00
|
|
|
std::shared_ptr<GSWnd> m_wnd;
|
2017-05-21 20:14:34 +00:00
|
|
|
int m_vsync;
|
2009-07-06 16:35:06 +00:00
|
|
|
bool m_rbswapped;
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* m_backbuffer;
|
|
|
|
GSTexture* m_merge;
|
|
|
|
GSTexture* m_weavebob;
|
|
|
|
GSTexture* m_blend;
|
2019-02-12 11:12:41 +00:00
|
|
|
GSTexture* m_target_tmp;
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* m_current;
|
2012-01-05 02:40:24 +00:00
|
|
|
struct {size_t stride, start, count, limit;} m_vertex;
|
|
|
|
struct {size_t start, count, limit;} m_index;
|
2011-02-07 01:59:05 +00:00
|
|
|
unsigned int m_frame; // for ageing the pool
|
2016-08-27 17:23:12 +00:00
|
|
|
bool m_linear_present;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2019-01-14 21:28:23 +00:00
|
|
|
virtual GSTexture* CreateSurface(int type, int w, int h, int format) = 0;
|
|
|
|
virtual GSTexture* FetchSurface(int type, int w, int h, int format);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-10-09 11:20:31 +00:00
|
|
|
virtual void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) = 0;
|
2015-05-15 18:45:31 +00:00
|
|
|
virtual void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset) = 0;
|
|
|
|
virtual void DoFXAA(GSTexture* sTex, GSTexture* dTex) {}
|
|
|
|
virtual void DoShadeBoost(GSTexture* sTex, GSTexture* dTex) {}
|
|
|
|
virtual void DoExternalFX(GSTexture* sTex, GSTexture* dTex) {}
|
2019-06-06 14:21:32 +00:00
|
|
|
virtual uint16 ConvertBlendEnum(uint16 generic) = 0; // Convert blend factors/ops from the generic enum to DX11/OGl specific.
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
2016-09-18 20:40:51 +00:00
|
|
|
GSOsdManager m_osd;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSDevice();
|
|
|
|
virtual ~GSDevice();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void Recycle(GSTexture* t);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-04 15:14:04 +00:00
|
|
|
enum {Windowed, Fullscreen, DontCare};
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2017-02-22 21:02:34 +00:00
|
|
|
virtual bool Create(const std::shared_ptr<GSWnd> &wnd);
|
2009-09-18 18:45:37 +00:00
|
|
|
virtual bool Reset(int w, int h);
|
2009-07-04 15:14:04 +00:00
|
|
|
virtual bool IsLost(bool update = false) {return false;}
|
2009-10-31 01:06:23 +00:00
|
|
|
virtual void Present(const GSVector4i& r, int shader);
|
2015-05-15 18:49:25 +00:00
|
|
|
virtual void Present(GSTexture* sTex, GSTexture* dTex, const GSVector4& dRect, int shader = 0);
|
2009-10-31 01:06:23 +00:00
|
|
|
virtual void Flip() {}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2017-05-21 20:14:34 +00:00
|
|
|
virtual void SetVSync(int vsync) {m_vsync = vsync;}
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-06-03 22:45:28 +00:00
|
|
|
virtual void BeginScene() {}
|
2009-06-23 04:12:32 +00:00
|
|
|
virtual void DrawPrimitive() {};
|
2012-01-05 02:40:24 +00:00
|
|
|
virtual void DrawIndexedPrimitive() {}
|
2012-01-27 11:56:49 +00:00
|
|
|
virtual void DrawIndexedPrimitive(int offset, int count) {}
|
2009-07-31 23:59:06 +00:00
|
|
|
virtual void EndScene();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2019-02-07 11:08:44 +00:00
|
|
|
virtual bool HasDepthSparse() { return false; }
|
|
|
|
virtual bool HasColorSparse() { return false; }
|
|
|
|
|
2009-06-03 22:45:28 +00:00
|
|
|
virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {}
|
|
|
|
virtual void ClearRenderTarget(GSTexture* t, uint32 c) {}
|
2016-07-27 21:22:46 +00:00
|
|
|
virtual void ClearDepth(GSTexture* t) {}
|
2009-06-03 22:45:28 +00:00
|
|
|
virtual void ClearStencil(GSTexture* t, uint8 c) {}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2019-02-07 11:08:44 +00:00
|
|
|
GSTexture* CreateSparseRenderTarget(int w, int h, int format = 0);
|
|
|
|
GSTexture* CreateSparseDepthStencil(int w, int h, int format = 0);
|
2019-01-30 12:10:34 +00:00
|
|
|
GSTexture* CreateRenderTarget(int w, int h, int format = 0);
|
|
|
|
GSTexture* CreateDepthStencil(int w, int h, int format = 0);
|
|
|
|
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
|
|
|
|
2015-05-19 10:42:14 +00:00
|
|
|
virtual GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, int ps_shader = 0) {return NULL;}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2015-05-15 18:45:31 +00:00
|
|
|
virtual void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r) {}
|
2015-05-15 18:49:25 +00:00
|
|
|
virtual void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, int shader = 0, bool linear = true) {}
|
2019-05-14 20:18:31 +00:00
|
|
|
virtual void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, bool red, bool green, bool blue, bool alpha) {}
|
2011-02-22 20:58:21 +00:00
|
|
|
|
2015-05-15 18:49:25 +00:00
|
|
|
void StretchRect(GSTexture* sTex, GSTexture* dTex, const GSVector4& dRect, int shader = 0, bool linear = true);
|
2011-02-22 23:39:02 +00:00
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
virtual void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1) {}
|
2015-05-15 18:47:14 +00:00
|
|
|
virtual void PSSetShaderResource(int i, GSTexture* sRect) {}
|
2009-07-22 03:55:28 +00:00
|
|
|
virtual void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL) {}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* GetCurrent();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-10-09 11:20:31 +00:00
|
|
|
void Merge(GSTexture* sTex[3], GSVector4* sRect, GSVector4* dRect, const GSVector2i& fs, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c);
|
2009-06-03 12:09:04 +00:00
|
|
|
void Interlace(const GSVector2i& ds, int field, int mode, float yoffset);
|
2011-07-25 11:16:01 +00:00
|
|
|
void FXAA();
|
2012-02-29 00:29:29 +00:00
|
|
|
void ShadeBoost();
|
2014-01-17 10:17:24 +00:00
|
|
|
void ExternalFX();
|
2016-09-18 20:40:51 +00:00
|
|
|
virtual void RenderOsd(GSTexture* dt) {};
|
2009-06-19 20:24:18 +00:00
|
|
|
|
2019-02-12 11:06:02 +00:00
|
|
|
bool ResizeTexture(GSTexture** t, int type, int w, int h);
|
2009-07-04 15:14:04 +00:00
|
|
|
bool ResizeTexture(GSTexture** t, int w, int h);
|
2019-02-12 11:06:02 +00:00
|
|
|
bool ResizeTarget(GSTexture** t, int w, int h);
|
|
|
|
bool ResizeTarget(GSTexture** t);
|
2009-07-04 15:14:04 +00:00
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
bool IsRBSwapped() {return m_rbswapped;}
|
|
|
|
|
2010-05-23 15:33:50 +00:00
|
|
|
void AgePool();
|
2016-05-05 14:43:02 +00:00
|
|
|
void PurgePool();
|
2015-07-10 19:11:14 +00:00
|
|
|
|
|
|
|
virtual void PrintMemoryUsage();
|
2019-06-06 14:21:32 +00:00
|
|
|
|
|
|
|
// Convert the GS blend equations to HW specific blend factors/ops
|
|
|
|
// Index is computed as ((((A * 3 + B) * 3) + C) * 3) + D. A, B, C, D taken from ALPHA register.
|
|
|
|
HWBlend GetBlend(size_t index);
|
|
|
|
uint16 GetBlendFlags(size_t index);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
2011-02-22 23:39:02 +00:00
|
|
|
|
2012-08-06 05:26:44 +00:00
|
|
|
struct GSAdapter
|
|
|
|
{
|
|
|
|
uint32 vendor;
|
|
|
|
uint32 device;
|
|
|
|
uint32 subsys;
|
|
|
|
uint32 rev;
|
|
|
|
|
|
|
|
operator std::string() const;
|
|
|
|
bool operator==(const GSAdapter&) const;
|
|
|
|
bool operator==(const std::string &s) const
|
|
|
|
{
|
|
|
|
return (std::string)*this == s;
|
|
|
|
}
|
|
|
|
bool operator==(const char *s) const
|
|
|
|
{
|
|
|
|
return (std::string)*this == s;
|
|
|
|
}
|
|
|
|
|
2016-01-27 15:33:10 +00:00
|
|
|
#ifdef _WIN32
|
2012-08-06 05:26:44 +00:00
|
|
|
GSAdapter(const DXGI_ADAPTER_DESC1 &desc_dxgi);
|
|
|
|
#endif
|
2014-12-15 18:14:30 +00:00
|
|
|
#ifdef __linux__
|
2012-08-06 05:26:44 +00:00
|
|
|
// TODO
|
|
|
|
#endif
|
2013-10-24 20:54:27 +00:00
|
|
|
};
|