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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GSUtil.h"
|
|
|
|
|
2016-01-27 15:33:10 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-16 23:21:09 +00:00
|
|
|
#include "GSDeviceDX.h"
|
|
|
|
#include <VersionHelpers.h>
|
2011-02-19 23:41:52 +00:00
|
|
|
#include "svnrev.h"
|
|
|
|
#else
|
2011-02-19 09:05:15 +00:00
|
|
|
#define SVN_REV 0
|
|
|
|
#define SVN_MODS 0
|
2011-02-19 23:41:52 +00:00
|
|
|
#endif
|
2011-02-19 09:05:15 +00:00
|
|
|
|
2016-11-19 13:17:38 +00:00
|
|
|
Xbyak::util::Cpu g_cpu;
|
|
|
|
|
2011-02-19 23:41:52 +00:00
|
|
|
const char* GSUtil::GetLibName()
|
2011-02-19 03:36:30 +00:00
|
|
|
{
|
2016-07-23 22:19:30 +00:00
|
|
|
// The following ifdef mess is courtesy of "static string str;"
|
|
|
|
// being optimised by GCC to be unusable by older CPUs. Enjoy!
|
|
|
|
static char name[255];
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2016-11-22 20:34:27 +00:00
|
|
|
#if _M_SSE < 0x501
|
2016-11-19 22:02:35 +00:00
|
|
|
const char* sw_sse = g_cpu.has(Xbyak::util::Cpu::tAVX) ? "AVX" :
|
|
|
|
g_cpu.has(Xbyak::util::Cpu::tSSE41) ? "SSE41" :
|
|
|
|
g_cpu.has(Xbyak::util::Cpu::tSSSE3) ? "SSSE3" : "SSE2";
|
2016-11-22 20:34:27 +00:00
|
|
|
#endif
|
2016-11-19 22:02:35 +00:00
|
|
|
|
2016-07-23 22:19:30 +00:00
|
|
|
snprintf(name, sizeof(name), "GSdx "
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2016-07-23 22:19:30 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
"%lld "
|
|
|
|
#endif
|
|
|
|
#ifdef _M_AMD64
|
|
|
|
"64-bit "
|
|
|
|
#endif
|
|
|
|
#ifdef __INTEL_COMPILER
|
2016-11-19 22:02:35 +00:00
|
|
|
"(Intel C++ %d.%02d %s/%s)",
|
2016-07-23 22:19:30 +00:00
|
|
|
#elif _MSC_VER
|
2016-11-19 22:02:35 +00:00
|
|
|
"(MSVC %d.%02d %s/%s)",
|
2016-07-23 22:19:30 +00:00
|
|
|
#elif __clang__
|
2016-11-19 22:02:35 +00:00
|
|
|
"(clang %d.%d.%d %s/%s)",
|
2016-07-23 22:19:30 +00:00
|
|
|
#elif __GNUC__
|
2016-11-19 22:02:35 +00:00
|
|
|
"(GCC %d.%d.%d %s/%s)",
|
2016-07-23 22:19:30 +00:00
|
|
|
#else
|
2016-11-19 22:02:35 +00:00
|
|
|
"(%s/%s)",
|
2016-07-23 22:19:30 +00:00
|
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
|
|
SVN_REV,
|
|
|
|
#endif
|
|
|
|
#ifdef __INTEL_COMPILER
|
|
|
|
__INTEL_COMPILER / 100, __INTEL_COMPILER % 100,
|
|
|
|
#elif _MSC_VER
|
|
|
|
_MSC_VER / 100, _MSC_VER % 100,
|
|
|
|
#elif __clang__
|
|
|
|
__clang_major__, __clang_minor__, __clang_patchlevel__,
|
|
|
|
#elif __GNUC__
|
|
|
|
__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__,
|
|
|
|
#endif
|
2011-02-19 23:41:52 +00:00
|
|
|
|
2016-07-23 22:19:30 +00:00
|
|
|
#if _M_SSE >= 0x501
|
2016-11-19 22:02:35 +00:00
|
|
|
"AVX2", "AVX2"
|
2016-07-23 22:19:30 +00:00
|
|
|
#elif _M_SSE >= 0x500
|
2016-11-19 22:02:35 +00:00
|
|
|
"AVX", sw_sse
|
2016-07-23 22:19:30 +00:00
|
|
|
#elif _M_SSE >= 0x401
|
2016-11-19 22:02:35 +00:00
|
|
|
"SSE4.1", sw_sse
|
2016-07-23 22:19:30 +00:00
|
|
|
#elif _M_SSE >= 0x301
|
2016-11-19 22:02:35 +00:00
|
|
|
"SSSE3", sw_sse
|
2016-07-23 22:19:30 +00:00
|
|
|
#elif _M_SSE >= 0x200
|
2016-11-19 22:02:35 +00:00
|
|
|
"SSE2", sw_sse
|
2016-07-23 22:19:30 +00:00
|
|
|
#endif
|
|
|
|
);
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2016-07-23 22:19:30 +00:00
|
|
|
return name;
|
2011-02-19 03:36:30 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
static class GSUtilMaps
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-18 01:56:05 +00:00
|
|
|
public:
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8 PrimClassField[8];
|
2012-01-05 02:40:24 +00:00
|
|
|
uint8 VertexCountField[8];
|
2014-09-21 16:13:55 +00:00
|
|
|
uint8 ClassVertexCountField[4];
|
2009-07-04 15:14:04 +00:00
|
|
|
uint32 CompatibleBitsField[64][2];
|
|
|
|
uint32 SharedBitsField[64][2];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
GSUtilMaps()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
PrimClassField[GS_POINTLIST] = GS_POINT_CLASS;
|
|
|
|
PrimClassField[GS_LINELIST] = GS_LINE_CLASS;
|
|
|
|
PrimClassField[GS_LINESTRIP] = GS_LINE_CLASS;
|
|
|
|
PrimClassField[GS_TRIANGLELIST] = GS_TRIANGLE_CLASS;
|
|
|
|
PrimClassField[GS_TRIANGLESTRIP] = GS_TRIANGLE_CLASS;
|
|
|
|
PrimClassField[GS_TRIANGLEFAN] = GS_TRIANGLE_CLASS;
|
|
|
|
PrimClassField[GS_SPRITE] = GS_SPRITE_CLASS;
|
|
|
|
PrimClassField[GS_INVALID] = GS_INVALID_CLASS;
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
VertexCountField[GS_POINTLIST] = 1;
|
|
|
|
VertexCountField[GS_LINELIST] = 2;
|
|
|
|
VertexCountField[GS_LINESTRIP] = 2;
|
|
|
|
VertexCountField[GS_TRIANGLELIST] = 3;
|
|
|
|
VertexCountField[GS_TRIANGLESTRIP] = 3;
|
|
|
|
VertexCountField[GS_TRIANGLEFAN] = 3;
|
|
|
|
VertexCountField[GS_SPRITE] = 2;
|
|
|
|
VertexCountField[GS_INVALID] = 1;
|
|
|
|
|
2014-09-21 16:13:55 +00:00
|
|
|
ClassVertexCountField[GS_POINT_CLASS] = 1;
|
|
|
|
ClassVertexCountField[GS_LINE_CLASS] = 2;
|
|
|
|
ClassVertexCountField[GS_TRIANGLE_CLASS] = 3;
|
|
|
|
ClassVertexCountField[GS_SPRITE_CLASS] = 2;
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
memset(CompatibleBitsField, 0, sizeof(CompatibleBitsField));
|
|
|
|
|
2009-07-04 15:14:04 +00:00
|
|
|
for(int i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
CompatibleBitsField[i][i >> 5] |= 1 << (i & 0x1f);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-04 15:14:04 +00:00
|
|
|
CompatibleBitsField[PSM_PSMCT32][PSM_PSMCT24 >> 5] |= 1 << (PSM_PSMCT24 & 0x1f);
|
|
|
|
CompatibleBitsField[PSM_PSMCT24][PSM_PSMCT32 >> 5] |= 1 << (PSM_PSMCT32 & 0x1f);
|
|
|
|
CompatibleBitsField[PSM_PSMCT16][PSM_PSMCT16S >> 5] |= 1 << (PSM_PSMCT16S & 0x1f);
|
|
|
|
CompatibleBitsField[PSM_PSMCT16S][PSM_PSMCT16 >> 5] |= 1 << (PSM_PSMCT16 & 0x1f);
|
|
|
|
CompatibleBitsField[PSM_PSMZ32][PSM_PSMZ24 >> 5] |= 1 << (PSM_PSMZ24 & 0x1f);
|
|
|
|
CompatibleBitsField[PSM_PSMZ24][PSM_PSMZ32 >> 5] |= 1 << (PSM_PSMZ32 & 0x1f);
|
|
|
|
CompatibleBitsField[PSM_PSMZ16][PSM_PSMZ16S >> 5] |= 1 << (PSM_PSMZ16S & 0x1f);
|
|
|
|
CompatibleBitsField[PSM_PSMZ16S][PSM_PSMZ16 >> 5] |= 1 << (PSM_PSMZ16 & 0x1f);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-04 15:14:04 +00:00
|
|
|
memset(SharedBitsField, 0, sizeof(SharedBitsField));
|
|
|
|
|
|
|
|
SharedBitsField[PSM_PSMCT24][PSM_PSMT8H >> 5] |= 1 << (PSM_PSMT8H & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMCT24][PSM_PSMT4HL >> 5] |= 1 << (PSM_PSMT4HL & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMCT24][PSM_PSMT4HH >> 5] |= 1 << (PSM_PSMT4HH & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMZ24][PSM_PSMT8H >> 5] |= 1 << (PSM_PSMT8H & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMZ24][PSM_PSMT4HL >> 5] |= 1 << (PSM_PSMT4HL & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMZ24][PSM_PSMT4HH >> 5] |= 1 << (PSM_PSMT4HH & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT8H][PSM_PSMCT24 >> 5] |= 1 << (PSM_PSMCT24 & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT8H][PSM_PSMZ24 >> 5] |= 1 << (PSM_PSMZ24 & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT4HL][PSM_PSMCT24 >> 5] |= 1 << (PSM_PSMCT24 & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT4HL][PSM_PSMZ24 >> 5] |= 1 << (PSM_PSMZ24 & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT4HL][PSM_PSMT4HH >> 5] |= 1 << (PSM_PSMT4HH & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT4HH][PSM_PSMCT24 >> 5] |= 1 << (PSM_PSMCT24 & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT4HH][PSM_PSMZ24 >> 5] |= 1 << (PSM_PSMZ24 & 0x1f);
|
|
|
|
SharedBitsField[PSM_PSMT4HH][PSM_PSMT4HL >> 5] |= 1 << (PSM_PSMT4HL & 0x1f);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} s_maps;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
GS_PRIM_CLASS GSUtil::GetPrimClass(uint32 prim)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return (GS_PRIM_CLASS)s_maps.PrimClassField[prim];
|
|
|
|
}
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
int GSUtil::GetVertexCount(uint32 prim)
|
|
|
|
{
|
|
|
|
return s_maps.VertexCountField[prim];
|
|
|
|
}
|
|
|
|
|
2014-09-21 16:13:55 +00:00
|
|
|
int GSUtil::GetClassVertexCount(uint32 primclass)
|
|
|
|
{
|
|
|
|
return s_maps.ClassVertexCountField[primclass];
|
|
|
|
}
|
|
|
|
|
2012-01-13 18:10:05 +00:00
|
|
|
const uint32* GSUtil::HasSharedBitsPtr(uint32 dpsm)
|
|
|
|
{
|
|
|
|
return s_maps.SharedBitsField[dpsm];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSUtil::HasSharedBits(uint32 spsm, const uint32* RESTRICT ptr)
|
|
|
|
{
|
|
|
|
return (ptr[spsm >> 5] & (1 << (spsm & 0x1f))) == 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
bool GSUtil::HasSharedBits(uint32 spsm, uint32 dpsm)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-04 15:14:04 +00:00
|
|
|
return (s_maps.SharedBitsField[dpsm][spsm >> 5] & (1 << (spsm & 0x1f))) == 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
bool GSUtil::HasSharedBits(uint32 sbp, uint32 spsm, uint32 dbp, uint32 dpsm)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-04 15:14:04 +00:00
|
|
|
return ((sbp ^ dbp) | (s_maps.SharedBitsField[dpsm][spsm >> 5] & (1 << (spsm & 0x1f)))) == 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
bool GSUtil::HasCompatibleBits(uint32 spsm, uint32 dpsm)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-04 15:14:04 +00:00
|
|
|
return (s_maps.CompatibleBitsField[spsm][dpsm >> 5] & (1 << (dpsm & 0x1f))) != 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
bool GSUtil::CheckSSE()
|
|
|
|
{
|
2016-11-18 16:59:58 +00:00
|
|
|
bool status = true;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2016-11-18 16:59:58 +00:00
|
|
|
struct ISA {
|
|
|
|
Xbyak::util::Cpu::Type type;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
|
|
|
|
ISA checks[] = {
|
|
|
|
{Xbyak::util::Cpu::tSSE2, "SSE2"},
|
2016-11-19 14:01:14 +00:00
|
|
|
#if _M_SSE >= 0x301
|
2016-11-18 16:59:58 +00:00
|
|
|
{Xbyak::util::Cpu::tSSSE3, "SSSE3"},
|
|
|
|
#endif
|
2016-11-19 14:01:14 +00:00
|
|
|
#if _M_SSE >= 0x401
|
2016-11-18 16:59:58 +00:00
|
|
|
{Xbyak::util::Cpu::tSSE41, "SSE41"},
|
|
|
|
#endif
|
2016-11-19 14:01:14 +00:00
|
|
|
#if _M_SSE >= 0x500
|
2016-11-18 16:59:58 +00:00
|
|
|
{Xbyak::util::Cpu::tAVX, "AVX1"},
|
|
|
|
#endif
|
|
|
|
#if _M_SSE >= 0x501
|
|
|
|
{Xbyak::util::Cpu::tAVX2, "AVX2"},
|
2017-01-30 17:23:52 +00:00
|
|
|
{Xbyak::util::Cpu::tBMI1, "BMI1"},
|
|
|
|
{Xbyak::util::Cpu::tBMI2, "BMI2"},
|
2016-11-18 16:59:58 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < countof(checks); i++) {
|
2016-11-19 13:17:38 +00:00
|
|
|
if(!g_cpu.has(checks[i].type)) {
|
2016-11-18 16:59:58 +00:00
|
|
|
fprintf(stderr, "This CPU does not support %s\n", checks[i].name);
|
|
|
|
|
|
|
|
status = false;
|
|
|
|
}
|
2011-02-19 03:36:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 16:59:58 +00:00
|
|
|
return status;
|
2011-02-19 03:36:30 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 21:55:53 +00:00
|
|
|
CRCHackLevel GSUtil::GetRecommendedCRCHackLevel(GSRendererType type)
|
|
|
|
{
|
|
|
|
return type == GSRendererType::OGL_HW ? CRCHackLevel::Partial : CRCHackLevel::Full;
|
|
|
|
}
|
|
|
|
|
2015-08-02 18:21:49 +00:00
|
|
|
#define OCL_PROGRAM_VERSION 3
|
2014-09-22 07:15:25 +00:00
|
|
|
|
2014-12-01 22:06:24 +00:00
|
|
|
#ifdef ENABLE_OPENCL
|
2014-09-22 07:15:25 +00:00
|
|
|
void GSUtil::GetDeviceDescs(list<OCLDeviceDesc>& dl)
|
2014-09-22 00:50:51 +00:00
|
|
|
{
|
2014-09-22 07:15:25 +00:00
|
|
|
dl.clear();
|
2014-09-22 00:50:51 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::vector<cl::Platform> platforms;
|
|
|
|
|
|
|
|
cl::Platform::get(&platforms);
|
|
|
|
|
|
|
|
for(auto& p : platforms)
|
|
|
|
{
|
|
|
|
std::string platform_vendor = p.getInfo<CL_PLATFORM_VENDOR>();
|
|
|
|
|
|
|
|
std::vector<cl::Device> ds;
|
|
|
|
|
|
|
|
p.getDevices(CL_DEVICE_TYPE_ALL, &ds);
|
|
|
|
|
|
|
|
for(auto& device : ds)
|
|
|
|
{
|
|
|
|
string type;
|
|
|
|
|
|
|
|
switch(device.getInfo<CL_DEVICE_TYPE>())
|
|
|
|
{
|
|
|
|
case CL_DEVICE_TYPE_GPU: type = "GPU"; break;
|
|
|
|
case CL_DEVICE_TYPE_CPU: type = "CPU"; break;
|
|
|
|
}
|
|
|
|
|
2014-09-22 07:15:25 +00:00
|
|
|
if(type.empty()) continue;
|
|
|
|
|
|
|
|
std::string version = device.getInfo<CL_DEVICE_OPENCL_C_VERSION>();
|
|
|
|
|
2014-09-22 03:29:40 +00:00
|
|
|
int major = 0;
|
|
|
|
int minor = 0;
|
2014-09-22 00:50:51 +00:00
|
|
|
|
|
|
|
if(!type.empty() && sscanf(version.c_str(), "OpenCL C %d.%d", &major, &minor) == 2 && major == 1 && minor >= 1 || major > 1)
|
|
|
|
{
|
2014-09-22 07:15:25 +00:00
|
|
|
OCLDeviceDesc desc;
|
|
|
|
|
|
|
|
desc.device = device;
|
|
|
|
desc.name = GetDeviceUniqueName(device);
|
|
|
|
desc.version = major * 100 + minor * 10;
|
|
|
|
|
2017-01-23 18:14:43 +00:00
|
|
|
#ifdef _WIN32
|
2014-09-22 07:15:25 +00:00
|
|
|
char* buff = new char[MAX_PATH + 1];
|
|
|
|
GetTempPath(MAX_PATH, buff);
|
|
|
|
desc.tmppath = string(buff) + "/" + desc.name;
|
|
|
|
|
|
|
|
WIN32_FIND_DATA FindFileData;
|
|
|
|
HANDLE hFind = FindFirstFile(desc.tmppath.c_str(), &FindFileData);
|
|
|
|
if(hFind != INVALID_HANDLE_VALUE) FindClose(hFind);
|
|
|
|
else CreateDirectory(desc.tmppath.c_str(), NULL);
|
2014-09-22 00:50:51 +00:00
|
|
|
|
2014-09-22 07:15:25 +00:00
|
|
|
sprintf(buff, "/%d", OCL_PROGRAM_VERSION);
|
|
|
|
desc.tmppath += buff;
|
|
|
|
delete[] buff;
|
2014-09-22 00:50:51 +00:00
|
|
|
|
2014-09-22 07:15:25 +00:00
|
|
|
hFind = FindFirstFile(desc.tmppath.c_str(), &FindFileData);
|
|
|
|
if(hFind != INVALID_HANDLE_VALUE) FindClose(hFind);
|
|
|
|
else CreateDirectory(desc.tmppath.c_str(), NULL);
|
2017-01-23 18:14:43 +00:00
|
|
|
#else
|
|
|
|
// TODO: linux
|
|
|
|
ASSERT(0);
|
|
|
|
#endif
|
2014-09-22 00:50:51 +00:00
|
|
|
|
2014-09-22 07:15:25 +00:00
|
|
|
dl.push_back(desc);
|
2014-09-22 00:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(cl::Error err)
|
|
|
|
{
|
|
|
|
printf("%s (%d)\n", err.what(), err.err());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 07:15:25 +00:00
|
|
|
string GSUtil::GetDeviceUniqueName(cl::Device& device)
|
|
|
|
{
|
|
|
|
std::string vendor = device.getInfo<CL_DEVICE_VENDOR>();
|
|
|
|
std::string name = device.getInfo<CL_DEVICE_NAME>();
|
|
|
|
std::string version = device.getInfo<CL_DEVICE_OPENCL_C_VERSION>();
|
|
|
|
|
|
|
|
string type;
|
|
|
|
|
|
|
|
switch(device.getInfo<CL_DEVICE_TYPE>())
|
|
|
|
{
|
|
|
|
case CL_DEVICE_TYPE_GPU: type = "GPU"; break;
|
|
|
|
case CL_DEVICE_TYPE_CPU: type = "CPU"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
version.erase(version.find_last_not_of(' ') + 1);
|
|
|
|
|
|
|
|
return vendor + " " + name + " " + version + " " + type;
|
|
|
|
}
|
2014-12-01 22:06:24 +00:00
|
|
|
#endif
|
2014-09-22 07:15:25 +00:00
|
|
|
|
2016-01-27 15:33:10 +00:00
|
|
|
#ifdef _WIN32
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
bool GSUtil::CheckDirectX()
|
|
|
|
{
|
2015-12-16 23:21:09 +00:00
|
|
|
if (GSDeviceDX::LoadD3DCompiler())
|
2009-08-07 21:11:27 +00:00
|
|
|
{
|
2015-12-16 23:21:09 +00:00
|
|
|
GSDeviceDX::FreeD3DCompiler();
|
|
|
|
return true;
|
2009-08-07 21:11:27 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 23:21:09 +00:00
|
|
|
// User's system is likely broken if it fails and is Windows 8.1 or greater.
|
|
|
|
if (!IsWindows8Point1OrGreater())
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2015-12-16 23:21:09 +00:00
|
|
|
printf("Cannot find d3dcompiler_43.dll\n");
|
|
|
|
if (MessageBox(nullptr, TEXT("You need to update some DirectX libraries, would you like to do it now?"), TEXT("GSdx"), MB_YESNO) == IDYES)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2015-12-16 23:21:09 +00:00
|
|
|
ShellExecute(nullptr, TEXT("open"), TEXT("https://www.microsoft.com/en-us/download/details.aspx?id=8109"), nullptr, nullptr, SW_SHOWNORMAL);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-16 23:21:09 +00:00
|
|
|
return false;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-20 16:09:46 +00:00
|
|
|
// ---------------------------------------------------------------------------------
|
|
|
|
// DX11 Detection (includes DXGI detection and dynamic library method bindings)
|
|
|
|
// ---------------------------------------------------------------------------------
|
|
|
|
// Code 'Borrowed' from Microsoft's DXGI sources -- Modified to suit our needs. --air
|
2012-08-06 01:56:25 +00:00
|
|
|
// Stripped down because of unnecessary complexity and false positives
|
|
|
|
// e.g. (d3d11_beta.dll would fail at device creation time) --pseudonym
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
static int s_DXGI;
|
|
|
|
static int s_D3D11;
|
|
|
|
|
|
|
|
bool GSUtil::CheckDXGI()
|
2011-02-20 16:09:46 +00:00
|
|
|
{
|
2012-08-06 01:56:25 +00:00
|
|
|
if (0 == s_DXGI)
|
2011-02-20 16:09:46 +00:00
|
|
|
{
|
2012-08-06 01:56:25 +00:00
|
|
|
HMODULE hmod = LoadLibrary("dxgi.dll");
|
|
|
|
s_DXGI = hmod ? 1 : -1;
|
|
|
|
if (hmod)
|
|
|
|
FreeLibrary(hmod);
|
2011-02-20 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
return s_DXGI > 0;
|
2011-02-20 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
bool GSUtil::CheckD3D11()
|
2011-02-20 16:09:46 +00:00
|
|
|
{
|
2012-08-06 01:56:25 +00:00
|
|
|
if (!CheckDXGI())
|
|
|
|
return false;
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
if (0 == s_D3D11)
|
2011-02-20 16:09:46 +00:00
|
|
|
{
|
2012-08-06 01:56:25 +00:00
|
|
|
HMODULE hmod = LoadLibrary("d3d11.dll");
|
|
|
|
s_D3D11 = hmod ? 1 : -1;
|
|
|
|
if (hmod)
|
|
|
|
FreeLibrary(hmod);
|
2011-02-20 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
return s_D3D11 > 0;
|
2011-02-20 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
D3D_FEATURE_LEVEL GSUtil::CheckDirect3D11Level(IDXGIAdapter *adapter, D3D_DRIVER_TYPE type)
|
2011-02-20 16:09:46 +00:00
|
|
|
{
|
2012-08-06 01:56:25 +00:00
|
|
|
HRESULT hr;
|
|
|
|
D3D_FEATURE_LEVEL level;
|
|
|
|
|
|
|
|
if(!CheckD3D11())
|
|
|
|
return (D3D_FEATURE_LEVEL)0;
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
hr = D3D11CreateDevice(adapter, type, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, &level, NULL);
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
return SUCCEEDED(hr) ? level : (D3D_FEATURE_LEVEL)0;
|
2011-02-20 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 07:39:50 +00:00
|
|
|
GSRendererType GSUtil::GetBestRenderer()
|
|
|
|
{
|
|
|
|
CComPtr<IDXGIFactory1> dxgi_factory;
|
|
|
|
if (SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory))))
|
|
|
|
{
|
|
|
|
CComPtr<IDXGIAdapter1> adapter;
|
|
|
|
if (SUCCEEDED(dxgi_factory->EnumAdapters1(0, &adapter)))
|
|
|
|
{
|
|
|
|
DXGI_ADAPTER_DESC1 desc;
|
|
|
|
if (SUCCEEDED(adapter->GetDesc1(&desc)))
|
|
|
|
{
|
|
|
|
D3D_FEATURE_LEVEL level = GSUtil::CheckDirect3D11Level();
|
|
|
|
// Check for Nvidia VendorID. Latest OpenGL features need at least DX11 level GPU
|
|
|
|
if (desc.VendorId == 0x10DE && level >= D3D_FEATURE_LEVEL_11_0)
|
|
|
|
return GSRendererType::OGL_HW;
|
|
|
|
if (level >= D3D_FEATURE_LEVEL_10_0)
|
|
|
|
return GSRendererType::DX1011_HW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GSRendererType::DX9_HW;
|
|
|
|
}
|
|
|
|
|
2015-09-26 11:41:44 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
void GSmkdir(const char* dir)
|
|
|
|
{
|
2016-06-10 20:01:48 +00:00
|
|
|
int err = mkdir(dir, 0777);
|
|
|
|
if (!err && errno != EEXIST)
|
2015-09-26 11:41:44 +00:00
|
|
|
fprintf(stderr, "Failed to create directory: %s\n", dir);
|
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#endif
|
2016-08-03 16:07:54 +00:00
|
|
|
|
|
|
|
const char* psm_str(int psm)
|
|
|
|
{
|
|
|
|
switch(psm) {
|
|
|
|
// Normal color
|
|
|
|
case PSM_PSMCT32: return "C_32";
|
|
|
|
case PSM_PSMCT24: return "C_24";
|
|
|
|
case PSM_PSMCT16: return "C_16";
|
|
|
|
case PSM_PSMCT16S: return "C_16S";
|
|
|
|
|
|
|
|
// Palette color
|
|
|
|
case PSM_PSMT8: return "P_8";
|
|
|
|
case PSM_PSMT4: return "P_4";
|
|
|
|
case PSM_PSMT8H: return "P_8H";
|
|
|
|
case PSM_PSMT4HL: return "P_4HL";
|
|
|
|
case PSM_PSMT4HH: return "P_4HH";
|
|
|
|
|
|
|
|
// Depth
|
|
|
|
case PSM_PSMZ32: return "Z_32";
|
|
|
|
case PSM_PSMZ24: return "Z_24";
|
|
|
|
case PSM_PSMZ16: return "Z_16";
|
|
|
|
case PSM_PSMZ16S: return "Z_16S";
|
|
|
|
|
2016-10-05 19:06:38 +00:00
|
|
|
case PSM_PSGPU24: return "PS24";
|
|
|
|
|
2016-08-03 16:07:54 +00:00
|
|
|
default:break;
|
|
|
|
}
|
|
|
|
return "BAD_PSM";
|
|
|
|
}
|