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
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GS.h"
|
|
|
|
#include "GSUtil.h"
|
|
|
|
#include "svnrev.h"
|
2009-05-14 16:41:52 +00:00
|
|
|
#include "xbyak/xbyak_util.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
static struct GSUtilMaps
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8 PrimClassField[8];
|
2009-07-04 15:14:04 +00:00
|
|
|
uint32 CompatibleBitsField[64][2];
|
|
|
|
uint32 SharedBitsField[64][2];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
struct GSUtilMaps()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool GSUtil::CheckDirectX()
|
|
|
|
{
|
2009-08-07 21:11:27 +00:00
|
|
|
OSVERSIONINFOEX version;
|
|
|
|
memset(&version, 0, sizeof(version));
|
|
|
|
version.dwOSVersionInfoSize = sizeof(version);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-08-07 21:11:27 +00:00
|
|
|
if(GetVersionEx((OSVERSIONINFO*)&version))
|
|
|
|
{
|
|
|
|
printf("Windows %d.%d.%d",
|
2010-04-25 00:31:27 +00:00
|
|
|
version.dwMajorVersion,
|
|
|
|
version.dwMinorVersion,
|
2009-08-07 21:11:27 +00:00
|
|
|
version.dwBuildNumber);
|
|
|
|
|
|
|
|
if(version.wServicePackMajor > 0)
|
|
|
|
{
|
|
|
|
printf(" (%s %d.%d)",
|
2010-04-25 00:31:27 +00:00
|
|
|
version.szCSDVersion,
|
2009-08-07 21:11:27 +00:00
|
|
|
version.wServicePackMajor,
|
|
|
|
version.wServicePackMinor);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION))
|
|
|
|
{
|
|
|
|
D3DADAPTER_IDENTIFIER9 id;
|
|
|
|
|
|
|
|
if(S_OK == d3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &id))
|
|
|
|
{
|
|
|
|
printf("%s (%d.%d.%d.%d)\n",
|
2010-04-25 00:31:27 +00:00
|
|
|
id.Description,
|
|
|
|
id.DriverVersion.HighPart >> 16,
|
|
|
|
id.DriverVersion.HighPart & 0xffff,
|
|
|
|
id.DriverVersion.LowPart >> 16,
|
2009-08-07 21:11:27 +00:00
|
|
|
id.DriverVersion.LowPart & 0xffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
d3d->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
string d3dx9_dll = format("d3dx9_%d.dll", D3DX_SDK_VERSION);
|
|
|
|
|
|
|
|
if(HINSTANCE hDll = LoadLibrary(d3dx9_dll.c_str()))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
FreeLibrary(hDll);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-07 21:11:27 +00:00
|
|
|
printf("Cannot find %s\n", d3dx9_dll.c_str());
|
|
|
|
|
2010-01-15 15:21:43 +00:00
|
|
|
if(MessageBox(NULL, "You need to update some directx libraries, would you like to do it now?", "GSdx", MB_YESNO) == IDYES)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
const char* url = "http://www.microsoft.com/downloads/details.aspx?FamilyId=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3";
|
|
|
|
|
|
|
|
ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSUtil::CheckSSE()
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
Xbyak::util::Cpu cpu;
|
|
|
|
Xbyak::util::Cpu::Type type;
|
|
|
|
|
|
|
|
#if _M_SSE >= 0x402
|
|
|
|
type = Xbyak::util::Cpu::tSSE42;
|
|
|
|
#elif _M_SSE >= 0x401
|
|
|
|
type = Xbyak::util::Cpu::tSSE41;
|
|
|
|
#elif _M_SSE >= 0x301
|
|
|
|
type = Xbyak::util::Cpu::tSSSE3;
|
|
|
|
#elif _M_SSE >= 0x200
|
|
|
|
type = Xbyak::util::Cpu::tSSE2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!cpu.has(type))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
string s = format("This CPU does not support SSE %d.%02d", _M_SSE >> 8, _M_SSE & 0xff);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-12-19 18:30:56 +00:00
|
|
|
MessageBox(GetActiveWindow(), s.c_str(), "GSdx", MB_OK);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-07 03:32:13 +00:00
|
|
|
typedef IDirect3D9* (WINAPI * LPDIRECT3DCREATE9) (UINT);
|
|
|
|
|
|
|
|
static HMODULE s_hModD3D9 = NULL;
|
|
|
|
static LPDIRECT3DCREATE9 s_DynamicDirect3DCreate9 = NULL;
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
char* GSUtil::GetLibName()
|
|
|
|
{
|
2009-05-28 02:57:01 +00:00
|
|
|
static string str;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-28 02:57:01 +00:00
|
|
|
str = format("GSdx %d", SVN_REV);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
if(SVN_MODS) str += "m";
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
#if _M_AMD64
|
2009-05-11 08:18:00 +00:00
|
|
|
str += " 64-bit";
|
2009-05-14 16:41:52 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
list<string> sl;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
// TODO: gcc
|
|
|
|
|
|
|
|
#ifdef __INTEL_COMPILER
|
2009-05-11 08:18:00 +00:00
|
|
|
sl.push_back(format("Intel C++ %d.%02d", __INTEL_COMPILER / 100, __INTEL_COMPILER % 100));
|
2009-05-14 16:41:52 +00:00
|
|
|
#elif _MSC_VER
|
2009-05-11 08:18:00 +00:00
|
|
|
sl.push_back(format("MSVC %d.%02d", _MSC_VER / 100, _MSC_VER % 100));
|
2009-05-14 16:41:52 +00:00
|
|
|
#endif
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
#if _M_SSE >= 0x402
|
2009-05-11 08:18:00 +00:00
|
|
|
sl.push_back("SSE42");
|
2009-05-14 16:41:52 +00:00
|
|
|
#elif _M_SSE >= 0x401
|
2009-05-11 08:18:00 +00:00
|
|
|
sl.push_back("SSE41");
|
2009-05-14 16:41:52 +00:00
|
|
|
#elif _M_SSE >= 0x301
|
2009-05-11 08:18:00 +00:00
|
|
|
sl.push_back("SSSE3");
|
2009-05-14 16:41:52 +00:00
|
|
|
#elif _M_SSE >= 0x200
|
2009-05-11 08:18:00 +00:00
|
|
|
sl.push_back("SSE2");
|
2009-05-14 16:41:52 +00:00
|
|
|
#elif _M_SSE >= 0x100
|
2009-05-11 08:18:00 +00:00
|
|
|
sl.push_back("SSE");
|
2009-05-14 16:41:52 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
for(list<string>::iterator i = sl.begin(); i != sl.end(); )
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
if(i == sl.begin()) str += " (";
|
|
|
|
str += *i;
|
|
|
|
str += ++i != sl.end() ? ", " : ")";
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
return (char*)str.c_str();
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|