diff --git a/Source/Core/DolphinWX/Dolphin.vcxproj b/Source/Core/DolphinWX/Dolphin.vcxproj
index 829a7d9f4e..f42b84ed1d 100644
--- a/Source/Core/DolphinWX/Dolphin.vcxproj
+++ b/Source/Core/DolphinWX/Dolphin.vcxproj
@@ -374,9 +374,6 @@ xcopy "$(SolutionDir)..\Externals\msvcrt\$(PlatformName)\*.dll" "$(TargetDir)" /
{9a4c733c-bade-4ac6-b58a-6e274395e90e}
-
- {dc7d7af4-ce47-49e8-8b63-265cb6233a49}
-
{1909cd2d-1707-456f-86ca-0df42a727c99}
@@ -408,4 +405,4 @@ xcopy "$(SolutionDir)..\Externals\msvcrt\$(PlatformName)\*.dll" "$(TargetDir)" /
-
\ No newline at end of file
+
diff --git a/Source/Core/VideoCommon/Src/VideoBackendBase.cpp b/Source/Core/VideoCommon/Src/VideoBackendBase.cpp
index 4769ede3a0..ddec3446cd 100644
--- a/Source/Core/VideoCommon/Src/VideoBackendBase.cpp
+++ b/Source/Core/VideoCommon/Src/VideoBackendBase.cpp
@@ -6,7 +6,6 @@
// TODO: ugly
#ifdef _WIN32
-#include "../../../Plugins/Plugin_VideoDX9/Src/VideoBackend.h"
#include "../../../Plugins/Plugin_VideoDX11/Src/VideoBackend.h"
#endif
#if !defined(USE_GLES) || USE_GLES3
@@ -43,7 +42,6 @@ void VideoBackend::PopulateList()
// D3D11 > OGL > D3D9 > SW
#ifdef _WIN32
- g_available_video_backends.push_back(backends[2] = new DX9::VideoBackend);
if (IsGteVista())
g_available_video_backends.push_back(backends[0] = new DX11::VideoBackend);
#endif
diff --git a/Source/Dolphin_2010.sln b/Source/Dolphin_2010.sln
index 207795dd26..ffa7dee930 100644
--- a/Source/Dolphin_2010.sln
+++ b/Source/Dolphin_2010.sln
@@ -64,12 +64,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DiscIO", "Core\DiscIO\DiscI
{3E1339F5-9311-4122-9442-369702E8FCAD} = {3E1339F5-9311-4122-9442-369702E8FCAD}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VideoDX9", "Plugins\Plugin_VideoDX9\Plugin_VideoDX9.vcxproj", "{DC7D7AF4-CE47-49E8-8B63-265CB6233A49}"
- ProjectSection(ProjectDependencies) = postProject
- {3E5C4E02-1BA9-4776-BDBE-E3F91FFA34CF} = {3E5C4E02-1BA9-4776-BDBE-E3F91FFA34CF}
- {1C8436C9-DBAF-42BE-83BC-CF3EC9175ABE} = {1C8436C9-DBAF-42BE-83BC-CF3EC9175ABE}
- EndProjectSection
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VideoDX11", "Plugins\Plugin_VideoDX11\Plugin_VideoDX11.vcxproj", "{9A4C733C-BADE-4AC6-B58A-6E274395E90E}"
ProjectSection(ProjectDependencies) = postProject
{3E5C4E02-1BA9-4776-BDBE-E3F91FFA34CF} = {3E5C4E02-1BA9-4776-BDBE-E3F91FFA34CF}
@@ -278,18 +272,6 @@ Global
{B6398059-EBB6-4C34-B547-95F365B71FF4}.Release|Win32.Build.0 = Release|Win32
{B6398059-EBB6-4C34-B547-95F365B71FF4}.Release|x64.ActiveCfg = Release|x64
{B6398059-EBB6-4C34-B547-95F365B71FF4}.Release|x64.Build.0 = Release|x64
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Debug|Win32.ActiveCfg = Debug|Win32
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Debug|Win32.Build.0 = Debug|Win32
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Debug|x64.ActiveCfg = Debug|x64
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Debug|x64.Build.0 = Debug|x64
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.DebugFast|Win32.ActiveCfg = DebugFast|Win32
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.DebugFast|Win32.Build.0 = DebugFast|Win32
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.DebugFast|x64.ActiveCfg = DebugFast|x64
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.DebugFast|x64.Build.0 = DebugFast|x64
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Release|Win32.ActiveCfg = Release|Win32
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Release|Win32.Build.0 = Release|Win32
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Release|x64.ActiveCfg = Release|x64
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}.Release|x64.Build.0 = Release|x64
{9A4C733C-BADE-4AC6-B58A-6E274395E90E}.Debug|Win32.ActiveCfg = Debug|Win32
{9A4C733C-BADE-4AC6-B58A-6E274395E90E}.Debug|Win32.Build.0 = Debug|Win32
{9A4C733C-BADE-4AC6-B58A-6E274395E90E}.Debug|x64.ActiveCfg = Debug|x64
diff --git a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcxproj b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcxproj
deleted file mode 100644
index 02d39e314f..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcxproj
+++ /dev/null
@@ -1,239 +0,0 @@
-
-
-
-
- DebugFast
- Win32
-
-
- DebugFast
- x64
-
-
- Debug
- Win32
-
-
- Debug
- x64
-
-
- Release
- Win32
-
-
- Release
- x64
-
-
-
- {DC7D7AF4-CE47-49E8-8B63-265CB6233A49}
- Plugin_VideoDX9
- VideoDX9
-
-
-
- StaticLibrary
- true
- Unicode
-
-
- StaticLibrary
- true
- Unicode
-
-
- StaticLibrary
- false
- Unicode
- false
-
-
- StaticLibrary
- false
- Unicode
-
-
- StaticLibrary
- false
- Unicode
-
-
- StaticLibrary
- false
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $(PlatformName)\$(Configuration)\
-
-
-
- $(ProjectName)D
-
-
-
-
-
-
-
-
-
-
-
-
- Disabled
- ..\..\Core\Common\Src;..\..\Core\Core\Src;..\..\Core\VideoCommon\Src;..\..\Core\DolphinWX\Src;..\..\..\Externals\wxWidgets3;..\..\..\Externals\wxWidgets3\include;%(AdditionalIncludeDirectories)
- _SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
- MultiThreadedDebug
- stdafx.h
- Use
-
-
- true
- ..\..\..\Binary\$(PlatformName)\Plugins\$(TargetName)$(TargetExt)
-
-
-
-
- ..\..\Core\Common\Src;..\..\Core\Core\Src;..\..\Core\VideoCommon\Src;..\..\Core\DolphinWX\Src;..\..\..\Externals\wxWidgets3;..\..\..\Externals\wxWidgets3\include;%(AdditionalIncludeDirectories)
-
-
- true
- ..\..\..\Binary\$(PlatformName)\Plugins\$(TargetName)$(TargetExt)
-
-
-
-
- ..\..\Core\Common\Src;..\..\Core\Core\Src;..\..\Core\VideoCommon\Src;..\..\Core\DolphinWX\Src;..\..\..\Externals\wxWidgets3;..\..\..\Externals\wxWidgets3\include;%(AdditionalIncludeDirectories)
-
-
- true
- true
- true
- ..\..\..\Binary\$(PlatformName)\Plugins\$(TargetName)$(TargetExt)
-
-
-
-
- ..\..\Core\Common\Src;..\..\Core\Core\Src;..\..\Core\VideoCommon\Src;..\..\Core\DolphinWX\Src;..\..\..\Externals\wxWidgets3;..\..\..\Externals\wxWidgets3\include;%(AdditionalIncludeDirectories)
-
-
- true
- true
- true
- ..\..\..\Binary\$(PlatformName)\Plugins\$(TargetName)$(TargetExt)
-
-
-
-
- ..\..\Core\Common\Src;..\..\Core\Core\Src;..\..\Core\VideoCommon\Src;..\..\Core\DolphinWX\Src;..\..\..\Externals\wxWidgets3;..\..\..\Externals\wxWidgets3\include;%(AdditionalIncludeDirectories)
-
-
- true
- true
- true
- ..\..\..\Binary\$(PlatformName)\Plugins\$(TargetName)$(TargetExt)
-
-
-
-
- ..\..\Core\Common\Src;..\..\Core\Core\Src;..\..\Core\VideoCommon\Src;..\..\Core\DolphinWX\Src;..\..\..\Externals\wxWidgets3;..\..\..\Externals\wxWidgets3\include;%(AdditionalIncludeDirectories)
-
-
- true
- true
- true
- ..\..\..\Binary\$(PlatformName)\Plugins\$(TargetName)$(TargetExt)
-
-
-
-
- {3e5c4e02-1ba9-4776-bdbe-e3f91ffa34cf}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Create
- Create
- Create
- Create
- Create
- Create
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcxproj.filters b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcxproj.filters
deleted file mode 100644
index c1d091c239..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcxproj.filters
+++ /dev/null
@@ -1,96 +0,0 @@
-
-
-
-
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- D3D
-
-
- D3D
-
-
- D3D
-
-
- D3D
-
-
- D3D
-
-
- Render
-
-
-
-
-
-
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- Render
-
-
- D3D
-
-
- D3D
-
-
- D3D
-
-
- D3D
-
-
- D3D
-
-
- Render
-
-
-
-
- {7acd5e48-186b-4788-ab0a-3551205635f8}
-
-
- {46f1aa47-0eaf-4c32-bdbb-f61c587cd233}
-
-
-
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp
deleted file mode 100644
index 44e5abd317..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp
+++ /dev/null
@@ -1,955 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include "D3DBase.h"
-#include "VideoConfig.h"
-#include "Render.h"
-#include "XFStructs.h"
-#include "StringUtil.h"
-#include "VideoCommon.h"
-
-D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA = NULL;
-D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA = NULL;
-D3DXCOMPILESHADERTYPE PD3DXCompileShader = NULL;
-
-namespace DX9
-{
-static char vsVersions[5][7] = {"ERROR", "vs_1_4", "vs_2_a", "vs_3_0", "vs_4_0"};
-static char psVersions[5][7] = {"ERROR", "ps_1_4", "ps_2_a", "ps_3_0", "ps_4_0"};
-// D3DX
-HINSTANCE hD3DXDll = NULL;
-int d3dx_dll_ref = 0;
-
-typedef IDirect3D9* (WINAPI* DIRECT3DCREATE9)(UINT);
-DIRECT3DCREATE9 PDirect3DCreate9 = NULL;
-HINSTANCE hD3DDll = NULL;
-int d3d_dll_ref = 0;
-
-namespace D3D
-{
-
-LPDIRECT3D9 D3D = NULL; // Used to create the D3DDevice
-LPDIRECT3DDEVICE9 dev = NULL; // Our rendering device
-LPDIRECT3DSURFACE9 back_buffer;
-LPDIRECT3DSURFACE9 back_buffer_z;
-D3DCAPS9 caps;
-HWND hWnd;
-
-static int multisample;
-static int resolution;
-static int xres, yres;
-static bool auto_depth_stencil = false;
-
-#define VENDOR_NVIDIA 4318
-#define VENDOR_ATI 4098
-#define VENDOR_INTEL 32902
-
-bool bFrameInProgress = false;
-
-#define MAX_ADAPTERS 4
-static Adapter adapters[MAX_ADAPTERS];
-static int numAdapters;
-static int cur_adapter;
-
-// Value caches for state filtering
-const int MaxStreamSources = 16;
-const int MaxTextureStages = 9;
-const int MaxRenderStates = 210 + 46;
-const int MaxTextureTypes = 33;
-const int MaxSamplerSize = 13;
-const int MaxSamplerTypes = 15;
-static bool m_RenderStatesSet[MaxRenderStates];
-static DWORD m_RenderStates[MaxRenderStates];
-static bool m_RenderStatesChanged[MaxRenderStates];
-
-static DWORD m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
-static bool m_TextureStageStatesSet[MaxTextureStages][MaxTextureTypes];
-static bool m_TextureStageStatesChanged[MaxTextureStages][MaxTextureTypes];
-
-static DWORD m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
-static bool m_SamplerStatesSet[MaxSamplerSize][MaxSamplerTypes];
-static bool m_SamplerStatesChanged[MaxSamplerSize][MaxSamplerTypes];
-
-static LPDIRECT3DBASETEXTURE9 m_Textures[16];
-static LPDIRECT3DVERTEXDECLARATION9 m_VtxDecl;
-static bool m_VtxDeclChanged;
-static LPDIRECT3DPIXELSHADER9 m_PixelShader;
-static bool m_PixelShaderChanged;
-static LPDIRECT3DVERTEXSHADER9 m_VertexShader;
-static bool m_VertexShaderChanged;
-struct StreamSourceDescriptor
-{
- LPDIRECT3DVERTEXBUFFER9 pStreamData;
- UINT OffsetInBytes;
- UINT Stride;
-};
-static StreamSourceDescriptor m_stream_sources[MaxStreamSources];
-static bool m_stream_sources_Changed[MaxStreamSources];
-static LPDIRECT3DINDEXBUFFER9 m_index_buffer;
-static bool m_index_buffer_Changed;
-
-// Z buffer formats to be used for EFB depth surface
-D3DFORMAT DepthFormats[] = {
- FOURCC_INTZ,
- FOURCC_DF24,
- FOURCC_RAWZ,
- FOURCC_DF16,
- D3DFMT_D24X8,
- D3DFMT_D24X4S4,
- D3DFMT_D24S8,
- D3DFMT_D24FS8,
- D3DFMT_D32, // too much precision, but who cares
- D3DFMT_D16, // much lower precision, but better than nothing
- D3DFMT_D15S1,
-};
-
-
-void Enumerate();
-
-int GetNumAdapters() { return numAdapters; }
-const Adapter &GetAdapter(int i) { return adapters[i]; }
-const Adapter &GetCurAdapter() { return adapters[cur_adapter]; }
-
-bool IsATIDevice()
-{
- return GetCurAdapter().ident.VendorId == VENDOR_ATI;
-}
-bool IsIntelDevice()
-{
- return GetCurAdapter().ident.VendorId == VENDOR_INTEL;
-}
-
-
-HRESULT Init()
-{
- if (d3d_dll_ref++ > 0) return S_OK;
-
- hD3DDll = LoadLibraryA("d3d9.dll");
- if (!hD3DDll)
- {
- MessageBoxA(NULL, "Failed to load d3d9.dll", "Critical error", MB_OK | MB_ICONERROR);
- return E_FAIL;
- }
- PDirect3DCreate9 = (DIRECT3DCREATE9)GetProcAddress(hD3DDll, "Direct3DCreate9");
- if (PDirect3DCreate9 == NULL) MessageBoxA(NULL, "GetProcAddress failed for Direct3DCreate9!", "Critical error", MB_OK | MB_ICONERROR);
-
- // Create the D3D object, which is needed to create the D3DDevice.
- D3D = PDirect3DCreate9(D3D_SDK_VERSION);
- if (!D3D)
- {
- --d3d_dll_ref;
- return E_FAIL;
- }
-
- // Init the caps structure using data from the currently selected device
- int adapter = g_Config.iAdapter;
- D3D->GetDeviceCaps((adapter >= 0 && adapter < std::min(MAX_ADAPTERS, numAdapters)) ? adapter : D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
- Enumerate();
- if(IsIntelDevice()){
- // Murder the a because Intel doesn't support 2.0a because the 'a' part was a ATI and Nvidia war going on
- psVersions[2][5] = '0';
- vsVersions[2][5] = '0';
- }
-
- return S_OK;
-}
-
-void Shutdown()
-{
- if (!d3d_dll_ref) return;
- if (--d3d_dll_ref != 0) return;
-
- if (D3D) D3D->Release();
- D3D = NULL;
-
- if (hD3DDll) FreeLibrary(hD3DDll);
- PDirect3DCreate9 = NULL;
-}
-
-void EnableAlphaToCoverage()
-{
- // Each vendor has their own specific little hack.
- if (GetCurAdapter().ident.VendorId == VENDOR_ATI)
- SetRenderState(D3DRS_POINTSIZE, (D3DFORMAT)MAKEFOURCC('A', '2', 'M', '1'));
- else
- SetRenderState(D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C'));
-}
-
-void InitPP(int adapter, int f, int aa_mode, D3DPRESENT_PARAMETERS *pp)
-{
- ZeroMemory(pp, sizeof(D3DPRESENT_PARAMETERS));
- pp->hDeviceWindow = hWnd;
- if (auto_depth_stencil)
- {
- pp->EnableAutoDepthStencil = TRUE;
- pp->AutoDepthStencilFormat = D3DFMT_D24S8;
- } else {
- pp->EnableAutoDepthStencil = FALSE;
- pp->AutoDepthStencilFormat = D3DFMT_UNKNOWN;
- }
- pp->BackBufferFormat = D3DFMT_X8R8G8B8;
- if (aa_mode >= (int)adapters[adapter].aa_levels.size())
- aa_mode = 0;
-
- pp->MultiSampleType = adapters[adapter].aa_levels[aa_mode].ms_setting;
- pp->MultiSampleQuality = adapters[adapter].aa_levels[aa_mode].qual_setting;
-
- pp->Flags = auto_depth_stencil ? D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL : 0;
-
- if(g_Config.b3DVision)
- {
- xres = pp->BackBufferWidth = adapters[adapter].resolutions[f].xres;
- yres = pp->BackBufferHeight = adapters[adapter].resolutions[f].yres;
- }
- else
- {
- RECT client;
- GetClientRect(hWnd, &client);
- xres = pp->BackBufferWidth = client.right - client.left;
- yres = pp->BackBufferHeight = client.bottom - client.top;
- }
- pp->SwapEffect = D3DSWAPEFFECT_DISCARD;
- pp->PresentationInterval = g_Config.IsVSync() ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;
- pp->Windowed = !g_Config.b3DVision;
-}
-
-void Enumerate()
-{
- numAdapters = D3D->GetAdapterCount();
-
- for (int i = 0; i < std::min(MAX_ADAPTERS, numAdapters); i++)
- {
- Adapter &a = adapters[i];
- a.aa_levels.clear();
- a.resolutions.clear();
- D3D->GetAdapterIdentifier(i, 0, &a.ident);
- bool isNvidia = a.ident.VendorId == VENDOR_NVIDIA;
-
- // Add SuperSamples modes
- a.aa_levels.push_back(AALevel("None", D3DMULTISAMPLE_NONE, 0));
- a.aa_levels.push_back(AALevel("4x SSAA", D3DMULTISAMPLE_NONE, 0));
- a.aa_levels.push_back(AALevel("9x SSAA", D3DMULTISAMPLE_NONE, 0));
- //Add multisample modes
- //disable them will they are not implemnted
- /*
- DWORD qlevels = 0;
- if (D3DERR_NOTAVAILABLE != D3D->CheckDeviceMultiSampleType(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, &qlevels))
- if (qlevels > 0)
- a.aa_levels.push_back(AALevel("2x MSAA", D3DMULTISAMPLE_2_SAMPLES, 0));
-
- if (D3DERR_NOTAVAILABLE != D3D->CheckDeviceMultiSampleType(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, &qlevels))
- if (qlevels > 0)
- a.aa_levels.push_back(AALevel("4x MSAA", D3DMULTISAMPLE_4_SAMPLES, 0));
-
- if (D3DERR_NOTAVAILABLE != D3D->CheckDeviceMultiSampleType(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_8_SAMPLES, &qlevels))
- if (qlevels > 0)
- a.aa_levels.push_back(AALevel("8x MSAA", D3DMULTISAMPLE_8_SAMPLES, 0));
-
- if (isNvidia)
- {
- // CSAA support
- if (D3DERR_NOTAVAILABLE != D3D->CheckDeviceMultiSampleType(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_4_SAMPLES, &qlevels))
- {
- if (qlevels > 2)
- {
- // 8x, 8xQ are available
- // See http://developer.nvidia.com/object/coverage-sampled-aa.html
- a.aa_levels.push_back(AALevel("8x CSAA", D3DMULTISAMPLE_4_SAMPLES, 2));
- a.aa_levels.push_back(AALevel("8xQ CSAA", D3DMULTISAMPLE_8_SAMPLES, 0));
- }
- }
- if (D3DERR_NOTAVAILABLE != D3D->CheckDeviceMultiSampleType(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_8_SAMPLES, &qlevels))
- {
- if (qlevels > 2)
- {
- // 16x, 16xQ are available
- // See http://developer.nvidia.com/object/coverage-sampled-aa.html
- a.aa_levels.push_back(AALevel("16x CSAA", D3DMULTISAMPLE_4_SAMPLES, 4));
- a.aa_levels.push_back(AALevel("16xQ CSAA", D3DMULTISAMPLE_8_SAMPLES, 2));
- }
- }
- }
- */
- // Determine if INTZ is supported. Code from ATI's doc.
- // http://developer.amd.com/gpu_assets/Advanced%20DX9%20Capabilities%20for%20ATI%20Radeon%20Cards.pdf
- a.supports_intz = D3D_OK == D3D->CheckDeviceFormat(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
- D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_INTZ);
- // Also check for RAWZ (nvidia only, but the only option to get Z24 textures on sub GF8800
- a.supports_rawz = D3D_OK == D3D->CheckDeviceFormat(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
- D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_RAWZ);
- // Might as well check for RESZ and NULL too.
- a.supports_resz = D3D_OK == D3D->CheckDeviceFormat(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
- D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_RESZ);
- a.supports_null = D3D_OK == D3D->CheckDeviceFormat(
- i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
- D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_NULL);
-
- if (a.aa_levels.size() == 1)
- {
- strcpy(a.aa_levels[0].name, "(Not supported on this device)");
- }
- int numModes = D3D->GetAdapterModeCount(i, D3DFMT_X8R8G8B8);
- for (int m = 0; m < numModes; m++)
- {
- D3DDISPLAYMODE mode;
- D3D->EnumAdapterModes(i, D3DFMT_X8R8G8B8, m, &mode);
-
- int found = -1;
- for (int x = 0; x < (int)a.resolutions.size(); x++)
- {
- if (a.resolutions[x].xres == mode.Width && a.resolutions[x].yres == mode.Height)
- {
- found = x;
- break;
- }
- }
-
- Resolution temp;
- Resolution &r = found==-1 ? temp : a.resolutions[found];
-
- sprintf(r.name, "%ix%i", mode.Width, mode.Height);
- r.bitdepths.insert(mode.Format);
- r.refreshes.insert(mode.RefreshRate);
- if (found == -1 && mode.Width >= 640 && mode.Height >= 480)
- {
- r.xres = mode.Width;
- r.yres = mode.Height;
- a.resolutions.push_back(r);
- }
- }
- }
-}
-
-// dynamically picks one of the available d3dx9 dlls and loads it.
-// we're first trying to load the dll Dolphin was compiled with, otherwise the most up-to-date one
-HRESULT LoadD3DX9()
-{
- if (d3dx_dll_ref++ > 0) return S_OK;
-
- HRESULT hr = E_FAIL;
- hD3DXDll = LoadLibraryA(StringFromFormat("d3dx9_%d.dll", D3DX_SDK_VERSION).c_str());
- if (hD3DXDll != NULL)
- {
- hr = S_OK;
- }
- else
- {
- // if that fails, try loading older dlls (no need to look for newer ones)
- for (unsigned int num = D3DX_SDK_VERSION-1; num >= 24; --num)
- {
- hD3DXDll = LoadLibraryA(StringFromFormat("d3dx9_%d.dll", num).c_str());
- if (hD3DXDll != NULL)
- {
- NOTICE_LOG(VIDEO, "Successfully loaded %s. If you're having trouble, try updating your DX runtime first.", StringFromFormat("d3dx9_%d.dll", num).c_str());
- hr = S_OK;
- break;
- }
- }
- if (FAILED(hr))
- {
- MessageBoxA(NULL, "Failed to load any D3DX9 dll, update your DX9 runtime, please", "Critical error", MB_OK | MB_ICONERROR);
- return hr;
- }
- }
- PD3DXCompileShader = (D3DXCOMPILESHADERTYPE)GetProcAddress(hD3DXDll, "D3DXCompileShader");
- if (PD3DXCompileShader == NULL)
- {
- MessageBoxA(NULL, "GetProcAddress failed for D3DXCompileShader!", "Critical error", MB_OK | MB_ICONERROR);
- goto fail;
- }
-
- PD3DXSaveSurfaceToFileA = (D3DXSAVESURFACETOFILEATYPE)GetProcAddress(hD3DXDll, "D3DXSaveSurfaceToFileA");
- if (PD3DXSaveSurfaceToFileA == NULL)
- {
- MessageBoxA(NULL, "GetProcAddress failed for D3DXSaveSurfaceToFileA!", "Critical error", MB_OK | MB_ICONERROR);
- goto fail;
- }
-
- PD3DXSaveTextureToFileA = (D3DXSAVETEXTURETOFILEATYPE)GetProcAddress(hD3DXDll, "D3DXSaveTextureToFileA");
- if (PD3DXSaveTextureToFileA == NULL)
- {
- MessageBoxA(NULL, "GetProcAddress failed for D3DXSaveTextureToFileA!", "Critical error", MB_OK | MB_ICONERROR);
- goto fail;
- }
- return S_OK;
-
-fail:
- --d3dx_dll_ref;
- FreeLibrary(hD3DXDll);
- PD3DXCompileShader = NULL;
- PD3DXSaveSurfaceToFileA = NULL;
- PD3DXSaveTextureToFileA = NULL;
- return E_FAIL;
-}
-
-void UnloadD3DX9()
-{
- if (!d3dx_dll_ref) return;
- if (--d3dx_dll_ref != 0) return;
-
- FreeLibrary(hD3DXDll);
- PD3DXCompileShader = NULL;
- PD3DXSaveSurfaceToFileA = NULL;
- PD3DXSaveTextureToFileA = NULL;
-}
-
-HRESULT Create(int adapter, HWND wnd, int _resolution, int aa_mode, bool auto_depth)
-{
- hWnd = wnd;
- multisample = aa_mode;
- resolution = _resolution;
- auto_depth_stencil = auto_depth;
- cur_adapter = adapter;
- D3DPRESENT_PARAMETERS d3dpp;
-
- HRESULT hr = LoadD3DX9();
- if (FAILED(hr)) return hr;
-
- InitPP(adapter, resolution, aa_mode, &d3dpp);
-
- if (FAILED(D3D->CreateDevice(
- adapter,
- D3DDEVTYPE_HAL,
- wnd,
- D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, //doesn't seem to make a difference
- &d3dpp, &dev)))
- {
- if (FAILED(D3D->CreateDevice(
- adapter,
- D3DDEVTYPE_HAL,
- wnd,
- D3DCREATE_SOFTWARE_VERTEXPROCESSING,
- &d3dpp, &dev)))
- {
- MessageBox(wnd,
- _T("Failed to initialize Direct3D."),
- _T("Dolphin Direct3D Backend"), MB_OK | MB_ICONERROR);
- return E_FAIL;
- }
- }
-
- dev->GetDeviceCaps(&caps);
- dev->GetRenderTarget(0, &back_buffer);
- if (dev->GetDepthStencilSurface(&back_buffer_z) == D3DERR_NOTFOUND)
- back_buffer_z = NULL;
- SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE );
- SetRenderState(D3DRS_FILLMODE, g_Config.bWireFrame ? D3DFILL_WIREFRAME : D3DFILL_SOLID);
- memset(m_Textures, 0, sizeof(m_Textures));
- memset(m_TextureStageStatesSet, 0, sizeof(m_TextureStageStatesSet));
- memset(m_RenderStatesSet, 0, sizeof(m_RenderStatesSet));
- memset(m_SamplerStatesSet, 0, sizeof(m_SamplerStatesSet));
- memset(m_TextureStageStatesChanged, 0, sizeof(m_TextureStageStatesChanged));
- memset(m_RenderStatesChanged, 0, sizeof(m_RenderStatesChanged));
- memset(m_SamplerStatesChanged, 0, sizeof(m_SamplerStatesChanged));
- m_VtxDecl = NULL;
- m_PixelShader = NULL;
- m_VertexShader = NULL;
- m_index_buffer = NULL;
- memset(m_stream_sources, 0, sizeof(m_stream_sources));
- m_index_buffer = NULL;
-
- m_VtxDeclChanged = false;
- m_PixelShaderChanged = false;
- m_VertexShaderChanged = false;
- memset(m_stream_sources_Changed, 0 , sizeof(m_stream_sources_Changed));
- m_index_buffer_Changed = false;
- // Device state would normally be set here
- return S_OK;
-}
-
-void Close()
-{
- UnloadD3DX9();
-
- if (back_buffer_z)
- back_buffer_z->Release();
- back_buffer_z = NULL;
- if( back_buffer )
- back_buffer->Release();
- back_buffer = NULL;
-
- ULONG references = dev->Release();
- if (references)
- ERROR_LOG(VIDEO, "Unreleased references: %i.", references);
-
- dev = NULL;
-}
-
-const D3DCAPS9 &GetCaps()
-{
- return caps;
-}
-
-// returns true if size was changed
-bool FixTextureSize(int& width, int& height)
-{
- int oldw = width, oldh = height;
-
- // conditional nonpow2 support should work fine for us
- if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
- {
- // all texture dimensions need to be powers of two
- width = (int)MakePow2((u32)width);
- height = (int)MakePow2((u32)height);
- }
- if (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
- {
- width = height = max(width, height);
- }
-
- width = min(width, (int)caps.MaxTextureWidth);
- height = min(height, (int)caps.MaxTextureHeight);
-
- return (width != oldw) || (height != oldh);
-}
-
-// returns true if format is supported
-bool CheckTextureSupport(DWORD usage, D3DFORMAT tex_format)
-{
- return D3D_OK == D3D->CheckDeviceFormat(cur_adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, usage, D3DRTYPE_TEXTURE, tex_format);
-}
-
-bool CheckDepthStencilSupport(D3DFORMAT target_format, D3DFORMAT depth_format)
-{
- return D3D_OK == D3D->CheckDepthStencilMatch(cur_adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, target_format, depth_format);
-}
-
-D3DFORMAT GetSupportedDepthTextureFormat()
-{
- for (int i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
- if (CheckTextureSupport(D3DUSAGE_DEPTHSTENCIL, DepthFormats[i]))
- return DepthFormats[i];
-
- return D3DFMT_UNKNOWN;
-}
-
-D3DFORMAT GetSupportedDepthSurfaceFormat(D3DFORMAT target_format)
-{
- for (int i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
- if (CheckDepthStencilSupport(target_format, DepthFormats[i]))
- return DepthFormats[i];
-
- return D3DFMT_UNKNOWN;
-}
-
-const char *VertexShaderVersionString()
-{
- int version = ((caps.VertexShaderVersion >> 8) & 0xFF);
- return vsVersions[std::min(4, version)];
-}
-
-const char *PixelShaderVersionString()
-{
- int version = ((caps.PixelShaderVersion >> 8) & 0xFF);
- return psVersions[std::min(4, version)];
-}
-
-LPDIRECT3DSURFACE9 GetBackBufferSurface()
-{
- return back_buffer;
-}
-
-LPDIRECT3DSURFACE9 GetBackBufferDepthSurface()
-{
- return back_buffer_z;
-}
-
-void ShowD3DError(HRESULT err)
-{
- switch (err)
- {
- case D3DERR_DEVICELOST:
- PanicAlert("Device Lost");
- break;
- case D3DERR_INVALIDCALL:
- PanicAlert("Invalid Call");
- break;
- case D3DERR_DRIVERINTERNALERROR:
- PanicAlert("Driver Internal Error");
- break;
- case D3DERR_OUTOFVIDEOMEMORY:
- PanicAlert("Out of vid mem");
- break;
- default:
- // MessageBox(0,_T("Other error or success"),_T("ERROR"),0);
- break;
- }
-}
-
-void Reset()
-{
- if (dev)
- {
- // ForgetCachedState();
-
- // Can't keep a pointer around to the backbuffer surface when resetting.
- if (back_buffer_z)
- back_buffer_z->Release();
- back_buffer_z = NULL;
- back_buffer->Release();
- back_buffer = NULL;
-
- D3DPRESENT_PARAMETERS d3dpp;
- InitPP(cur_adapter, resolution, multisample, &d3dpp);
- HRESULT hr = dev->Reset(&d3dpp);
- ShowD3DError(hr);
-
- dev->GetRenderTarget(0, &back_buffer);
- if (dev->GetDepthStencilSurface(&back_buffer_z) == D3DERR_NOTFOUND)
- back_buffer_z = NULL;
- ApplyCachedState();
- }
-}
-
-int GetBackBufferWidth()
-{
- return xres;
-}
-
-int GetBackBufferHeight()
-{
- return yres;
-}
-
-bool BeginFrame()
-{
- if (bFrameInProgress)
- {
- PanicAlert("BeginFrame WTF");
- return false;
- }
- bFrameInProgress = true;
- if (dev)
- {
- dev->BeginScene();
- return true;
- }
- else
- return false;
-}
-
-void EndFrame()
-{
- if (!bFrameInProgress)
- {
- PanicAlert("EndFrame WTF");
- return;
- }
- bFrameInProgress = false;
- dev->EndScene();
-}
-
-void Present()
-{
- if (dev)
- {
- dev->Present(NULL, NULL, NULL, NULL);
- }
-}
-
-void ApplyCachedState()
-{
- for (int sampler = 0; sampler < 8; sampler++)
- {
- for (int type = 0; type < MaxSamplerTypes; type++)
- {
- if(m_SamplerStatesSet[sampler][type])
- dev->SetSamplerState(sampler, (D3DSAMPLERSTATETYPE)type, m_SamplerStates[sampler][type]);
- }
- }
-
- for (int rs = 0; rs < MaxRenderStates; rs++)
- {
- if (m_RenderStatesSet[rs])
- dev->SetRenderState((D3DRENDERSTATETYPE)rs, m_RenderStates[rs]);
- }
-
- // We don't bother restoring these so let's just wipe the state copy
- // so no stale state is around.
- memset(m_Textures, 0, sizeof(m_Textures));
- memset(m_TextureStageStatesSet, 0, sizeof(m_TextureStageStatesSet));
- memset(m_TextureStageStatesChanged, 0, sizeof(m_TextureStageStatesChanged));
- m_VtxDecl = NULL;
- m_PixelShader = NULL;
- m_VertexShader = NULL;
- memset(m_stream_sources, 0, sizeof(m_stream_sources));
- m_index_buffer = NULL;
- m_VtxDeclChanged = false;
- m_PixelShaderChanged = false;
- m_VertexShaderChanged = false;
- memset(m_stream_sources_Changed, 0 , sizeof(m_stream_sources_Changed));
- m_index_buffer_Changed = false;
-}
-
-void SetTexture(DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture)
-{
- if (m_Textures[Stage] != pTexture)
- {
- m_Textures[Stage] = pTexture;
- dev->SetTexture(Stage, pTexture);
- }
-}
-
-void RefreshRenderState(D3DRENDERSTATETYPE State)
-{
- if(m_RenderStatesSet[State] && m_RenderStatesChanged[State])
- {
- dev->SetRenderState(State, m_RenderStates[State]);
- m_RenderStatesChanged[State] = false;
- }
-}
-
-void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value)
-{
- if (m_RenderStates[State] != Value || !m_RenderStatesSet[State])
- {
- m_RenderStates[State] = Value;
- m_RenderStatesSet[State] = true;
- m_RenderStatesChanged[State] = false;
- dev->SetRenderState(State, Value);
- }
-}
-
-void ChangeRenderState(D3DRENDERSTATETYPE State, DWORD Value)
-{
- if (m_RenderStates[State] != Value || !m_RenderStatesSet[State])
- {
- m_RenderStatesChanged[State] = m_RenderStatesSet[State];
- dev->SetRenderState(State, Value);
- }
- else
- {
- m_RenderStatesChanged[State] = false;
- }
-}
-
-void SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
-{
- if (m_TextureStageStates[Stage][Type] != Value || !m_TextureStageStatesSet[Stage][Type])
- {
- m_TextureStageStates[Stage][Type] = Value;
- m_TextureStageStatesSet[Stage][Type]=true;
- m_TextureStageStatesChanged[Stage][Type]=false;
- dev->SetTextureStageState(Stage, Type, Value);
- }
-}
-
-void RefreshTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type)
-{
- if(m_TextureStageStatesSet[Stage][Type] && m_TextureStageStatesChanged[Stage][Type])
- {
- dev->SetTextureStageState(Stage, Type, m_TextureStageStates[Stage][Type]);
- m_TextureStageStatesChanged[Stage][Type] = false;
- }
-}
-
-void ChangeTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
-{
- if (m_TextureStageStates[Stage][Type] != Value || !m_TextureStageStatesSet[Stage][Type])
- {
- m_TextureStageStatesChanged[Stage][Type] = m_TextureStageStatesSet[Stage][Type];
- dev->SetTextureStageState(Stage, Type, Value);
- }
- else
- {
- m_TextureStageStatesChanged[Stage][Type] = false;
- }
-}
-
-void SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
-{
- if (m_SamplerStates[Sampler][Type] != Value || !m_SamplerStatesSet[Sampler][Type])
- {
- m_SamplerStates[Sampler][Type] = Value;
- m_SamplerStatesSet[Sampler][Type] = true;
- m_SamplerStatesChanged[Sampler][Type] = false;
- dev->SetSamplerState(Sampler, Type, Value);
- }
-}
-
-void RefreshSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type)
-{
- if(m_SamplerStatesSet[Sampler][Type] && m_SamplerStatesChanged[Sampler][Type])
- {
- dev->SetSamplerState(Sampler, Type, m_SamplerStates[Sampler][Type]);
- m_SamplerStatesChanged[Sampler][Type] = false;
- }
-}
-
-void ChangeSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
-{
- if (m_SamplerStates[Sampler][Type] != Value || !m_SamplerStatesSet[Sampler][Type])
- {
- m_SamplerStatesChanged[Sampler][Type] = m_SamplerStatesSet[Sampler][Type];
- dev->SetSamplerState(Sampler, Type, Value);
- }
- else
- {
- m_SamplerStatesChanged[Sampler][Type] = false;
- }
-}
-
-void RefreshVertexDeclaration()
-{
- if (m_VtxDeclChanged)
- {
- dev->SetVertexDeclaration(m_VtxDecl);
- m_VtxDeclChanged = false;
- }
-}
-
-void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl)
-{
- if (decl != m_VtxDecl)
- {
- dev->SetVertexDeclaration(decl);
- m_VtxDecl = decl;
- m_VtxDeclChanged = false;
- }
-}
-
-void ChangeVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl)
-{
- if (decl != m_VtxDecl) {
- dev->SetVertexDeclaration(decl);
- m_VtxDeclChanged = true;
- }
-}
-
-void ChangeVertexShader(LPDIRECT3DVERTEXSHADER9 shader)
-{
- if (shader != m_VertexShader)
- {
- dev->SetVertexShader(shader);
- m_VertexShaderChanged = true;
- }
-}
-
-void RefreshVertexShader()
-{
- if (m_VertexShaderChanged)
- {
- dev->SetVertexShader(m_VertexShader);
- m_VertexShaderChanged = false;
- }
-}
-
-void SetVertexShader(LPDIRECT3DVERTEXSHADER9 shader)
-{
- if (shader != m_VertexShader)
- {
- dev->SetVertexShader(shader);
- m_VertexShader = shader;
- m_VertexShaderChanged = false;
- }
-}
-
-void RefreshPixelShader()
-{
- if (m_PixelShaderChanged)
- {
- dev->SetPixelShader(m_PixelShader);
- m_PixelShaderChanged = false;
- }
-}
-
-void SetPixelShader(LPDIRECT3DPIXELSHADER9 shader)
-{
- if (shader != m_PixelShader)
- {
- dev->SetPixelShader(shader);
- m_PixelShader = shader;
- m_PixelShaderChanged = false;
- }
-}
-
-void ChangePixelShader(LPDIRECT3DPIXELSHADER9 shader)
-{
- if (shader != m_PixelShader)
- {
- dev->SetPixelShader(shader);
- m_PixelShaderChanged = true;
- }
-}
-
-void SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride)
-{
- if (m_stream_sources[StreamNumber].OffsetInBytes != OffsetInBytes
- || m_stream_sources[StreamNumber].pStreamData != pStreamData
- || m_stream_sources[StreamNumber].Stride != Stride)
- {
- m_stream_sources[StreamNumber].OffsetInBytes = OffsetInBytes;
- m_stream_sources[StreamNumber].pStreamData = pStreamData;
- m_stream_sources[StreamNumber].Stride = Stride;
- dev->SetStreamSource(StreamNumber, pStreamData, OffsetInBytes, Stride);
- m_stream_sources_Changed[StreamNumber] = false;
- }
-}
-
-void ChangeStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride)
-{
- if (m_stream_sources[StreamNumber].OffsetInBytes != OffsetInBytes
- || m_stream_sources[StreamNumber].pStreamData != pStreamData
- || m_stream_sources[StreamNumber].Stride != Stride)
- {
- dev->SetStreamSource(StreamNumber, pStreamData, OffsetInBytes, Stride);
- m_stream_sources_Changed[StreamNumber] = true;
- }
-
-}
-
-void RefreshStreamSource(UINT StreamNumber)
-{
- if (m_PixelShaderChanged)
- {
- dev->SetStreamSource(
- StreamNumber,
- m_stream_sources[StreamNumber].pStreamData,
- m_stream_sources[StreamNumber].OffsetInBytes,
- m_stream_sources[StreamNumber].Stride);
- m_stream_sources_Changed[StreamNumber] = false;
- }
-}
-
-void SetIndices(LPDIRECT3DINDEXBUFFER9 pIndexData)
-{
- if(pIndexData != m_index_buffer)
- {
- m_index_buffer = pIndexData;
- dev->SetIndices(pIndexData);
- m_index_buffer_Changed = false;
- }
-}
-
-void ChangeIndices(LPDIRECT3DINDEXBUFFER9 pIndexData)
-{
- if(pIndexData != m_index_buffer)
- {
- dev->SetIndices(pIndexData);
- m_index_buffer_Changed = true;
- }
-}
-
-void RefreshIndices()
-{
- if (m_index_buffer_Changed)
- {
- dev->SetIndices(m_index_buffer);
- m_index_buffer_Changed = false;
- }
-}
-
-
-
-} // namespace
-
-} // namespace DX9
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.h b/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.h
deleted file mode 100644
index b5a6649989..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.h
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include
-#include
-
-#include
-
-#include "Common.h"
-
-namespace DX9
-{
-
-namespace D3D
-{
-
-// From http://developer.amd.com/gpu_assets/Advanced%20DX9%20Capabilities%20for%20ATI%20Radeon%20Cards.pdf
-// Magic FourCC's to unlock undocumented D3D9 features:
-
-// Z texture formats
-#define FOURCC_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')))
-#define FOURCC_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z')))
-#define FOURCC_DF24 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4')))
-#define FOURCC_DF16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6')))
-
-// Depth buffer resolve:
-#define FOURCC_RESZ ((D3DFORMAT)(MAKEFOURCC('R','E','S','Z')))
-#define RESZ_CODE 0x7fa05000
-
-// Null render target to do Z-only shadow maps: (probably not useful for Dolphin)
-#define FOURCC_NULL ((D3DFORMAT)(MAKEFOURCC('N','U','L','L')))
-
-bool IsATIDevice();
-bool IsIntelDevice();
-HRESULT Init();
-HRESULT Create(int adapter, HWND wnd, int resolution, int aa_mode, bool auto_depth);
-void Close();
-void Shutdown();
-
-// Direct access to the device.
-extern LPDIRECT3DDEVICE9 dev;
-extern bool bFrameInProgress;
-
-void Reset();
-bool BeginFrame();
-void EndFrame();
-void Present();
-bool CanUseINTZ();
-
-int GetBackBufferWidth();
-int GetBackBufferHeight();
-LPDIRECT3DSURFACE9 GetBackBufferSurface();
-LPDIRECT3DSURFACE9 GetBackBufferDepthSurface();
-LPDIRECT3DVERTEXBUFFER9 GetquadVB();
-LPDIRECT3DVERTEXDECLARATION9 GetBasicvertexDecl();
-const D3DCAPS9 &GetCaps();
-const char *PixelShaderVersionString();
-const char *VertexShaderVersionString();
-void ShowD3DError(HRESULT err);
-
-// returns true if size was changed
-bool FixTextureSize(int& width, int& height);
-
-// returns true if format is supported
-bool CheckTextureSupport(DWORD usage, D3DFORMAT tex_format);
-bool CheckDepthStencilSupport(D3DFORMAT target_format, D3DFORMAT depth_format);
-
-D3DFORMAT GetSupportedDepthTextureFormat();
-D3DFORMAT GetSupportedDepthSurfaceFormat(D3DFORMAT target_format);
-
-// The following are "filtered" versions of the corresponding D3Ddev-> functions.
-void SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture);
-void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
-void RefreshRenderState(D3DRENDERSTATETYPE State);
-void ChangeRenderState(D3DRENDERSTATETYPE State, DWORD Value);
-
-void SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
-void RefreshTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type);
-void ChangeTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
-
-void SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
-void RefreshSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type);
-void ChangeSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
-
-void RefreshVertexDeclaration();
-void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl);
-void ChangeVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl);
-
-void RefreshVertexShader();
-void SetVertexShader(LPDIRECT3DVERTEXSHADER9 shader);
-void ChangeVertexShader(LPDIRECT3DVERTEXSHADER9 shader);
-
-void RefreshPixelShader();
-void SetPixelShader(LPDIRECT3DPIXELSHADER9 shader);
-void ChangePixelShader(LPDIRECT3DPIXELSHADER9 shader);
-
-void SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
-void ChangeStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
-void RefreshStreamSource(UINT StreamNumber);
-
-void SetIndices(LPDIRECT3DINDEXBUFFER9 pIndexData);
-void ChangeIndices(LPDIRECT3DINDEXBUFFER9 pIndexData);
-void RefreshIndices();
-
-void ApplyCachedState();
-
-// Utility functions for vendor specific hacks. So far, just the one.
-void EnableAlphaToCoverage();
-
-struct Resolution
-{
- char name[32];
- int xres;
- int yres;
- std::set bitdepths;
- std::set refreshes;
-};
-
-struct AALevel
-{
- AALevel(const char *n, D3DMULTISAMPLE_TYPE m, int q) {
- strncpy(name, n, 32);
- name[31] = '\0';
- ms_setting = m;
- qual_setting = q;
- }
- char name[32];
- D3DMULTISAMPLE_TYPE ms_setting;
- int qual_setting;
-};
-
-struct Adapter
-{
- D3DADAPTER_IDENTIFIER9 ident;
- std::vector resolutions;
- std::vector aa_levels;
- bool supports_alpha_to_coverage;
-
- // Magic render targets, see the top of this file.
- bool supports_intz;
- bool supports_rawz;
- bool supports_resz;
- bool supports_null;
-};
-
-const Adapter &GetAdapter(int i);
-const Adapter &GetCurAdapter();
-int GetNumAdapters();
-
-} // namespace
-
-} // namespace DX9
-
-
-// Used to not require the SDK and runtime versions to match:
-// Linking with d3dx9.lib makes the most recent d3dx9_xx.dll of the
-// compiler's SDK an actually unnecessary requirement.
-// Add any d3dx9 functions which you want to use here and load them in LoadD3DX9()
-typedef HRESULT (WINAPI* D3DXSAVESURFACETOFILEATYPE)(LPCSTR, D3DXIMAGE_FILEFORMAT, LPDIRECT3DSURFACE9, CONST PALETTEENTRY*, CONST RECT*);
-typedef HRESULT (WINAPI* D3DXSAVETEXTURETOFILEATYPE)(LPCSTR, D3DXIMAGE_FILEFORMAT, LPDIRECT3DBASETEXTURE9, CONST PALETTEENTRY*);
-typedef HRESULT (WINAPI* D3DXCOMPILESHADERTYPE)(LPCSTR, UINT, CONST D3DXMACRO*, LPD3DXINCLUDE, LPCSTR, LPCSTR, DWORD, LPD3DXBUFFER*, LPD3DXBUFFER*, LPD3DXCONSTANTTABLE*);
-
-extern D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA;
-extern D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA;
-extern D3DXCOMPILESHADERTYPE PD3DXCompileShader;
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp
deleted file mode 100644
index 8649ebfac2..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include
-#include
-
-#include "VideoConfig.h"
-#include "D3DShader.h"
-
-namespace DX9
-{
-
-namespace D3D
-{
-
-// bytecode->shader.
-LPDIRECT3DVERTEXSHADER9 CreateVertexShaderFromByteCode(const u8 *bytecode, int len)
-{
- LPDIRECT3DVERTEXSHADER9 v_shader;
- HRESULT hr = D3D::dev->CreateVertexShader((DWORD *)bytecode, &v_shader);
- if (FAILED(hr))
- return NULL;
-
- return v_shader;
-}
-
-// code->bytecode.
-bool CompileVertexShader(const char *code, int len, u8 **bytecode, int *bytecodelen)
-{
- LPD3DXBUFFER shaderBuffer = NULL;
- LPD3DXBUFFER errorBuffer = NULL;
- HRESULT hr = PD3DXCompileShader(code, len, 0, 0, "main", D3D::VertexShaderVersionString(),
- 0, &shaderBuffer, &errorBuffer, 0);
- if (FAILED(hr))
- {
- static int num_failures = 0;
- char szTemp[MAX_PATH];
- sprintf(szTemp, "%sbad_vs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
- std::ofstream file;
- OpenFStream(file, szTemp, std::ios_base::out);
- file << code;
- file.close();
-
- PanicAlert("Failed to compile vertex shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%s):\n%s",
- szTemp,
- D3D::VertexShaderVersionString(),
- (char*)errorBuffer->GetBufferPointer());
-
- *bytecode = NULL;
- *bytecodelen = 0;
- }
- else
- {
- *bytecodelen = shaderBuffer->GetBufferSize();
- *bytecode = new u8[*bytecodelen];
- memcpy(*bytecode, shaderBuffer->GetBufferPointer(), *bytecodelen);
- }
-
- //cleanup
- if (shaderBuffer)
- shaderBuffer->Release();
- if (errorBuffer)
- errorBuffer->Release();
- return SUCCEEDED(hr) ? true : false;
-}
-
-// bytecode->shader
-LPDIRECT3DPIXELSHADER9 CreatePixelShaderFromByteCode(const u8 *bytecode, int len)
-{
- LPDIRECT3DPIXELSHADER9 p_shader;
- HRESULT hr = D3D::dev->CreatePixelShader((DWORD *)bytecode, &p_shader);
- if (FAILED(hr))
- return NULL;
-
- return p_shader;
-}
-
-// code->bytecode
-bool CompilePixelShader(const char *code, int len, u8 **bytecode, int *bytecodelen)
-{
- LPD3DXBUFFER shaderBuffer = 0;
- LPD3DXBUFFER errorBuffer = 0;
-
- // Someone:
- // For some reason, I had this kind of errors : "Shader uses texture addressing operations
- // in a dependency chain that is too complex for the target shader model (ps_2_0) to handle."
- HRESULT hr = PD3DXCompileShader(code, len, 0, 0, "main", D3D::PixelShaderVersionString(),
- 0, &shaderBuffer, &errorBuffer, 0);
-
- if (FAILED(hr))
- {
- static int num_failures = 0;
- char szTemp[MAX_PATH];
- sprintf(szTemp, "%sbad_ps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
- std::ofstream file;
- OpenFStream(file, szTemp, std::ios_base::out);
- file << code;
- file.close();
-
- PanicAlert("Failed to compile pixel shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%s):\n%s",
- szTemp,
- D3D::PixelShaderVersionString(),
- (char*)errorBuffer->GetBufferPointer());
-
- *bytecode = NULL;
- *bytecodelen = 0;
- }
- else
- {
- *bytecodelen = shaderBuffer->GetBufferSize();
- *bytecode = new u8[*bytecodelen];
- memcpy(*bytecode, shaderBuffer->GetBufferPointer(), *bytecodelen);
- }
-
- //cleanup
- if (shaderBuffer)
- shaderBuffer->Release();
- if (errorBuffer)
- errorBuffer->Release();
- return SUCCEEDED(hr) ? true : false;
-}
-
-LPDIRECT3DVERTEXSHADER9 CompileAndCreateVertexShader(const char *code, int len)
-{
- u8 *bytecode;
- int bytecodelen;
- if (CompileVertexShader(code, len, &bytecode, &bytecodelen))
- {
- LPDIRECT3DVERTEXSHADER9 v_shader = CreateVertexShaderFromByteCode(bytecode, len);
- delete [] bytecode;
- return v_shader;
- }
- return NULL;
-}
-
-LPDIRECT3DPIXELSHADER9 CompileAndCreatePixelShader(const char* code, unsigned int len)
-{
- u8 *bytecode;
- int bytecodelen;
- if (CompilePixelShader(code, len, &bytecode, &bytecodelen))
- {
- LPDIRECT3DPIXELSHADER9 p_shader = CreatePixelShaderFromByteCode(bytecode, len);
- delete [] bytecode;
- return p_shader;
- }
- return NULL;
-}
-
-} // namespace
-
-} // namespace DX9
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.h b/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.h
deleted file mode 100644
index 449f2dacea..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "D3DBase.h"
-
-namespace DX9
-{
-
-namespace D3D
-{
- LPDIRECT3DVERTEXSHADER9 CreateVertexShaderFromByteCode(const u8 *bytecode, int len);
- LPDIRECT3DPIXELSHADER9 CreatePixelShaderFromByteCode(const u8 *bytecode, int len);
-
- // The returned bytecode buffers should be delete[]-d.
- bool CompileVertexShader(const char *code, int len, u8 **bytecode, int *bytecodelen);
- bool CompilePixelShader(const char *code, int len, u8 **bytecode, int *bytecodelen);
-
- // Utility functions
- LPDIRECT3DVERTEXSHADER9 CompileAndCreateVertexShader(const char *code, int len);
- LPDIRECT3DPIXELSHADER9 CompileAndCreatePixelShader(const char *code, unsigned int len);
-}
-
-} // namespace DX9
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp
deleted file mode 100644
index f16e308eef..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp
+++ /dev/null
@@ -1,406 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include "D3DBase.h"
-#include "D3DTexture.h"
-
-#include "CPUDetect.h"
-
-#if _M_SSE >= 0x401
-#include
-#include
-#elif _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
-#include
-#endif
-
-namespace DX9
-{
-
-namespace D3D
-{
-
-void ConvertRGBA_BGRA_SSE2(u32 *dst, const int dstPitch, u32 *pIn, const int width, const int height, const int pitch)
-{
- // Converts RGBA to BGRA:
- // TODO: this would be totally unnecessary if we just change the TextureDecoder_RGBA to decode
- // to BGRA instead.
- for (int y = 0; y < height; y++, pIn += pitch)
- {
- u8 *pIn8 = (u8 *)pIn;
- u8 *pBits = (u8 *)((u8*)dst + (y * dstPitch));
-
- // Batch up loads/stores into 16 byte chunks to use SSE2 efficiently:
- int sse2blocks = (width * 4) / 16;
- int sse2remainder = (width * 4) & 15;
-
- // Do conversions in batches of 16 bytes:
- if (sse2blocks > 0)
- {
- // Generate a constant of all FF bytes:
- const __m128i allFFs128 = _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128());
- __m128i *src128 = (__m128i *)pIn8;
- __m128i *dst128 = (__m128i *)pBits;
-
- // Increment by 16 bytes at a time:
- for (int i = 0; i < sse2blocks; ++i, ++dst128, ++src128)
- {
- // Load up 4 colors simultaneously:
- __m128i rgba = _mm_loadu_si128(src128);
- // Swap the R and B components:
- // Isolate the B component and shift it left 16 bits:
- // ABGR
- const __m128i bMask = _mm_srli_epi32(allFFs128, 24);
- const __m128i bNew = _mm_slli_epi32(_mm_and_si128(rgba, bMask), 16);
- // Isolate the R component and shift it right 16 bits:
- const __m128i rMask = _mm_slli_epi32(bMask, 16);
- const __m128i rNew = _mm_srli_epi32(_mm_and_si128(rgba, rMask), 16);
- // Now mask off the old R and B components from the rgba data to get 0g0a:
- const __m128i _g_a = _mm_or_si128(
- _mm_and_si128(
- rgba,
- _mm_or_si128(
- _mm_slli_epi32(bMask, 8),
- _mm_slli_epi32(rMask, 8)
- )
- ),
- _mm_or_si128(rNew, bNew)
- );
- // Finally, OR up all the individual components to get BGRA:
- const __m128i bgra = _mm_or_si128(_g_a, _mm_or_si128(rNew, bNew));
- _mm_storeu_si128(dst128, bgra);
- }
- }
-
- // Take the remainder colors at the end of the row that weren't able to
- // be included into the last 16 byte chunk:
- if (sse2remainder > 0)
- {
- for (int x = (sse2blocks * 16); x < (width * 4); x += 4)
- {
- pBits[x + 0] = pIn8[x + 2];
- pBits[x + 1] = pIn8[x + 1];
- pBits[x + 2] = pIn8[x + 0];
- pBits[x + 3] = pIn8[x + 3];
- }
- }
- }
-
- // Memory fence to make sure the stores are good:
- _mm_mfence();
-}
-
-void ConvertRGBA_BGRA_SSSE3(u32 *dst, const int dstPitch, u32 *pIn, const int width, const int height, const int pitch)
-{
- __m128i mask = _mm_set_epi8(15, 12, 13, 14, 11, 8, 9, 10, 7, 4, 5, 6, 3, 0, 1, 2);
- for (int y = 0; y < height; y++, pIn += pitch)
- {
- u8 *pIn8 = (u8 *)pIn;
- u8 *pBits = (u8 *)((u8*)dst + (y * dstPitch));
-
- // Batch up loads/stores into 16 byte chunks to use SSE2 efficiently:
- int ssse3blocks = (width * 4) / 16;
- int ssse3remainder = (width * 4) & 15;
-
- // Do conversions in batches of 16 bytes:
- if (ssse3blocks > 0)
- {
- __m128i *src128 = (__m128i *)pIn8;
- __m128i *dst128 = (__m128i *)pBits;
-
- // Increment by 16 bytes at a time:
- for (int i = 0; i < ssse3blocks; ++i, ++dst128, ++src128)
- {
- _mm_storeu_si128(dst128, _mm_shuffle_epi8(_mm_loadu_si128(src128), mask));
- }
- }
-
- // Take the remainder colors at the end of the row that weren't able to
- // be included into the last 16 byte chunk:
- if (ssse3remainder > 0)
- {
- for (int x = (ssse3blocks * 16); x < (width * 4); x += 4)
- {
- pBits[x + 0] = pIn8[x + 2];
- pBits[x + 1] = pIn8[x + 1];
- pBits[x + 2] = pIn8[x + 0];
- pBits[x + 3] = pIn8[x + 3];
- }
- }
- }
-
- // Memory fence to make sure the stores are good:
- _mm_mfence();
-}
-
-LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int height, const int pitch, D3DFORMAT fmt, bool swap_r_b, int levels)
-{
- u32* pBuffer = (u32*)buffer;
- LPDIRECT3DTEXTURE9 pTexture;
-
- // crazy bitmagic, sorry :)
- bool isPow2 = !((width&(width-1)) || (height&(height-1)));
- bool bExpand = false;
-
- if (fmt == D3DFMT_A8P8) {
- fmt = D3DFMT_A8L8;
- bExpand = true;
- }
-
- HRESULT hr;
- if (levels > 0)
- hr = dev->CreateTexture(width, height, levels, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
- else
- hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
-
- if (FAILED(hr))
- return 0;
- int level = 0;
- D3DLOCKED_RECT Lock;
- pTexture->LockRect(level, &Lock, NULL, 0);
- switch (fmt)
- {
- case D3DFMT_L8:
- case D3DFMT_A8:
- case D3DFMT_A4L4:
- {
- const u8 *pIn = buffer;
- for (int y = 0; y < height; y++)
- {
- u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width);
- pIn += pitch;
- }
- }
- break;
- case D3DFMT_R5G6B5:
- {
- const u16 *pIn = (u16*)buffer;
- for (int y = 0; y < height; y++)
- {
- u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width * 2);
- pIn += pitch;
- }
- }
- break;
- case D3DFMT_A8L8:
- {
- if (bExpand) { // I8
- const u8 *pIn = buffer;
- // TODO(XK): Find a better way that does not involve either unpacking
- // or downsampling (i.e. A4L4)
- for (int y = 0; y < height; y++)
- {
- u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
- for(int i = 0; i < width * 2; i += 2) {
- pBits[i] = pIn[i / 2];
- pBits[i + 1] = pIn[i / 2];
- }
- pIn += pitch;
- }
- } else { // IA8
- const u16 *pIn = (u16*)buffer;
-
- for (int y = 0; y < height; y++)
- {
- u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width * 2);
- pIn += pitch;
- }
- }
- }
- break;
- case D3DFMT_A8R8G8B8:
- {
- if(pitch * 4 == Lock.Pitch && !swap_r_b)
- {
- memcpy(Lock.pBits,buffer,Lock.Pitch*height);
- }
- else
- {
- u32* pIn = pBuffer;
- if (!swap_r_b) {
- for (int y = 0; y < height; y++)
- {
- u32 *pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width * 4);
- pIn += pitch;
- }
- } else {
-#if _M_SSE >= 0x301
- // Uses SSSE3 intrinsics to optimize RGBA -> BGRA swizzle:
- if (cpu_info.bSSSE3) {
- ConvertRGBA_BGRA_SSSE3((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
- } else
-#endif
- // Uses SSE2 intrinsics to optimize RGBA -> BGRA swizzle:
- {
- ConvertRGBA_BGRA_SSE2((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
- }
-#if 0
- for (int y = 0; y < height; y++)
- {
- u8 *pIn8 = (u8 *)pIn;
- u8 *pBits = (u8 *)((u8*)Lock.pBits + (y * Lock.Pitch));
- for (int x = 0; x < width * 4; x += 4) {
- pBits[x + 0] = pIn8[x + 2];
- pBits[x + 1] = pIn8[x + 1];
- pBits[x + 2] = pIn8[x + 0];
- pBits[x + 3] = pIn8[x + 3];
- }
- pIn += pitch;
- }
-#endif
- }
- }
- }
- break;
- case D3DFMT_DXT1:
- memcpy(Lock.pBits,buffer,((width+3)/4)*((height+3)/4)*8);
- break;
- default:
- PanicAlert("D3D: Invalid texture format %i", fmt);
- }
- pTexture->UnlockRect(level);
- return pTexture;
-}
-
-LPDIRECT3DTEXTURE9 CreateOnlyTexture2D(const int width, const int height, D3DFORMAT fmt)
-{
- LPDIRECT3DTEXTURE9 pTexture;
- // crazy bitmagic, sorry :)
- bool isPow2 = !((width&(width-1)) || (height&(height-1)));
- bool bExpand = false;
- HRESULT hr;
- // TODO(ector): Allow mipmaps for non-pow textures on newer cards?
- // TODO(ector): Use the game-specified mipmaps?
- if (!isPow2)
- hr = dev->CreateTexture(width, height, 1, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
- else
- hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
-
- if (FAILED(hr))
- return 0;
- return pTexture;
-}
-
-void ReplaceTexture2D(LPDIRECT3DTEXTURE9 pTexture, const u8* buffer, const int width, const int height, const int pitch, D3DFORMAT fmt, bool swap_r_b, int level)
-{
- u32* pBuffer = (u32*)buffer;
- D3DLOCKED_RECT Lock;
- pTexture->LockRect(level, &Lock, NULL, 0);
- u32* pIn = pBuffer;
-
- bool bExpand = false;
-
- if (fmt == D3DFMT_A8P8) {
- fmt = D3DFMT_A8L8;
- bExpand = true;
- }
- switch (fmt)
- {
- case D3DFMT_A8R8G8B8:
- if(pitch * 4 == Lock.Pitch && !swap_r_b)
- {
- memcpy(Lock.pBits, pBuffer, Lock.Pitch*height);
- }
- else if (!swap_r_b)
- {
- for (int y = 0; y < height; y++)
- {
- u32 *pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width * 4);
- pIn += pitch;
- }
- }
- else
- {
-#if _M_SSE >= 0x301
- // Uses SSSE3 intrinsics to optimize RGBA -> BGRA swizzle:
- if (cpu_info.bSSSE3) {
- ConvertRGBA_BGRA_SSSE3((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
- } else
-#endif
- // Uses SSE2 intrinsics to optimize RGBA -> BGRA swizzle:
- {
- ConvertRGBA_BGRA_SSE2((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
- }
-#if 0
- for (int y = 0; y < height; y++)
- {
- u8 *pIn8 = (u8 *)pIn;
- u8 *pBits = (u8 *)((u8*)Lock.pBits + (y * Lock.Pitch));
- for (int x = 0; x < width * 4; x += 4)
- {
- pBits[x + 0] = pIn8[x + 2];
- pBits[x + 1] = pIn8[x + 1];
- pBits[x + 2] = pIn8[x + 0];
- pBits[x + 3] = pIn8[x + 3];
- }
- pIn += pitch;
- }
-#endif
- }
- break;
- case D3DFMT_L8:
- case D3DFMT_A8:
- case D3DFMT_A4L4:
- {
- const u8 *pIn = buffer;
- for (int y = 0; y < height; y++)
- {
- u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width);
- pIn += pitch;
- }
- }
- break;
- case D3DFMT_R5G6B5:
- {
- const u16 *pIn = (u16*)buffer;
- for (int y = 0; y < height; y++)
- {
- u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width * 2);
- pIn += pitch;
- }
- }
- break;
- case D3DFMT_A8L8:
- {
- if (bExpand) { // I8
- const u8 *pIn = buffer;
- // TODO(XK): Find a better way that does not involve either unpacking
- // or downsampling (i.e. A4L4)
- for (int y = 0; y < height; y++)
- {
- u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
- for(int i = 0; i < width * 2; i += 2) {
- pBits[i] = pIn[i / 2];
- pBits[i + 1] = pIn[i / 2];
- }
- pIn += pitch;
- }
- } else { // IA8
- const u16 *pIn = (u16*)buffer;
-
- for (int y = 0; y < height; y++)
- {
- u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
- memcpy(pBits, pIn, width * 2);
- pIn += pitch;
- }
- }
- }
- break;
- case D3DFMT_DXT1:
- memcpy(Lock.pBits,buffer,((width+3)/4)*((height+3)/4)*8);
- break;
- }
- pTexture->UnlockRect(level);
-}
-
-} // namespace
-
-} // namespace DX9
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.h b/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.h
deleted file mode 100644
index 54ed57000a..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "D3DBase.h"
-
-namespace DX9
-{
-
-namespace D3D
-{
- LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int height, const int pitch, D3DFORMAT fmt = D3DFMT_A8R8G8B8, bool swap_r_b = false, int levels = 1);
- void ReplaceTexture2D(LPDIRECT3DTEXTURE9 pTexture, const u8* buffer, const int width, const int height, const int pitch, D3DFORMAT fmt, bool swap_r_b, int level = 0);
- LPDIRECT3DTEXTURE9 CreateRenderTarget(const int width, const int height);
- LPDIRECT3DSURFACE9 CreateDepthStencilSurface(const int width, const int height);
- LPDIRECT3DTEXTURE9 CreateOnlyTexture2D(const int width, const int height, D3DFORMAT fmt);
-}
-
-} // namespace DX9
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp
deleted file mode 100644
index 066f99ad3f..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp
+++ /dev/null
@@ -1,463 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include "Common.h"
-#include "StringUtil.h"
-
-#include "D3DBase.h"
-#include "D3DUtil.h"
-#include "Render.h"
-#include "PixelShaderCache.h"
-#include "VertexShaderCache.h"
-
-namespace DX9
-{
-
-namespace D3D
-{
-CD3DFont font;
-
-#define MAX_NUM_VERTICES 50*6
-struct FONT2DVERTEX {
- float x,y,z;
- float rhw;
- u32 color;
- float tu, tv;
-};
-
-#define D3DFVF_FONT2DVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
-#define D3DFVF_FONT3DVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_NORMAL|D3DFVF_TEX1)
-
-inline FONT2DVERTEX InitFont2DVertex(float x, float y, u32 color, float tu, float tv)
-{
- FONT2DVERTEX v; v.x=x; v.y=y; v.z=0; v.rhw=1.0f; v.color = color; v.tu = tu; v.tv = tv;
- return v;
-}
-
-CD3DFont::CD3DFont()
-{
- m_pTexture = NULL;
- m_pVB = NULL;
-}
-
-enum {m_dwTexWidth = 512, m_dwTexHeight = 512};
-
-int CD3DFont::Init()
-{
- // Create vertex buffer for the letters
- HRESULT hr;
- if (FAILED(hr = dev->CreateVertexBuffer(MAX_NUM_VERTICES*sizeof(FONT2DVERTEX),
- D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &m_pVB, NULL)))
- {
- return hr;
- }
- m_fTextScale = 1.0f; // Draw fonts into texture without scaling
-
- // Prepare to create a bitmap
- unsigned int* pBitmapBits;
- BITMAPINFO bmi;
- ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = (int)m_dwTexWidth;
- bmi.bmiHeader.biHeight = -(int)m_dwTexHeight;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biBitCount = 32;
-
- // Create a DC and a bitmap for the font
- HDC hDC = CreateCompatibleDC(NULL);
- HBITMAP hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);
- SetMapMode(hDC, MM_TEXT);
-
- // Create a font. By specifying ANTIALIASED_QUALITY, we might get an
- // antialiased font, but this is not guaranteed.
- // We definitely don't want to get it cleartype'd, anyway.
- int m_dwFontHeight = 24;
- int nHeight = -MulDiv(m_dwFontHeight, int(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72);
- int dwBold = FW_NORMAL; ///FW_BOLD
- HFONT hFont = CreateFont(nHeight, 0, 0, 0, dwBold, 0,
- FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
- CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
- VARIABLE_PITCH, _T("Tahoma"));
- if (NULL == hFont)
- return E_FAIL;
-
- HGDIOBJ hOldbmBitmap = SelectObject(hDC, hbmBitmap);
- HGDIOBJ hOldFont = SelectObject(hDC, hFont);
-
- // Set text properties
- SetTextColor(hDC, 0xFFFFFF);
- SetBkColor (hDC, 0);
- SetTextAlign(hDC, TA_TOP);
-
- // Loop through all printable characters and output them to the bitmap
- // Meanwhile, keep track of the corresponding tex coords for each character.
- int x = 0, y = 0;
- char str[2] = "\0";
- for (int c = 0; c < 127 - 32; c++)
- {
- str[0] = c + 32;
- SIZE size;
- GetTextExtentPoint32A(hDC, str, 1, &size);
- if ((int)(x+size.cx+1) > m_dwTexWidth)
- {
- x = 0;
- y += size.cy + 1;
- }
-
- ExtTextOutA(hDC, x+1, y+0, ETO_OPAQUE | ETO_CLIPPED, NULL, str, 1, NULL);
- m_fTexCoords[c][0] = ((float)(x+0))/m_dwTexWidth;
- m_fTexCoords[c][1] = ((float)(y+0))/m_dwTexHeight;
- m_fTexCoords[c][2] = ((float)(x+0+size.cx))/m_dwTexWidth;
- m_fTexCoords[c][3] = ((float)(y+0+size.cy))/m_dwTexHeight;
-
- x += size.cx + 3; // 3 to work around annoying ij conflict (part of the j ends up with the i)
- }
-
- // Create a new texture for the font
- // possible optimization: store the converted data in a buffer and fill the texture on creation.
- // That way, we can use a static texture
- hr = dev->CreateTexture(m_dwTexWidth, m_dwTexHeight, 1, D3DUSAGE_DYNAMIC,
- D3DFMT_A4R4G4B4, D3DPOOL_DEFAULT, &m_pTexture, NULL);
- if (FAILED(hr))
- {
- PanicAlert("Failed to create font texture");
- return hr;
- }
-
- // Lock the surface and write the alpha values for the set pixels
- D3DLOCKED_RECT d3dlr;
- m_pTexture->LockRect(0, &d3dlr, 0, D3DLOCK_DISCARD);
- int bAlpha; // 4-bit measure of pixel intensity
-
- for (y = 0; y < m_dwTexHeight; y++)
- {
- u16 *pDst16 = (u16*)((u8 *)d3dlr.pBits + y * d3dlr.Pitch);
- for (x = 0; x < m_dwTexWidth; x++)
- {
- bAlpha = ((pBitmapBits[m_dwTexWidth * y + x] & 0xff) >> 4);
- pDst16[x] = (bAlpha << 12) | 0x0fff;
- }
- }
-
- // Done updating texture, so clean up used objects
- m_pTexture->UnlockRect(0);
-
- SelectObject(hDC, hOldbmBitmap);
- DeleteObject(hbmBitmap);
-
- SelectObject(hDC, hOldFont);
- DeleteObject(hFont);
-
- return S_OK;
-}
-
-int CD3DFont::Shutdown()
-{
- m_pVB->Release();
- m_pVB = NULL;
- m_pTexture->Release();
- m_pTexture = NULL;
- return S_OK;
-}
-
-
-const int RS[6][2] =
-{
- {D3DRS_ALPHABLENDENABLE, TRUE},
- {D3DRS_SRCBLEND, D3DBLEND_SRCALPHA},
- {D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA},
- {D3DRS_CULLMODE, D3DCULL_NONE},
- {D3DRS_ZENABLE, FALSE},
- {D3DRS_FOGENABLE, FALSE},
-};
-const int TS[6][2] =
-{
- {D3DTSS_COLOROP, D3DTOP_MODULATE},
- {D3DTSS_COLORARG1, D3DTA_TEXTURE},
- {D3DTSS_COLORARG2, D3DTA_DIFFUSE },
- {D3DTSS_ALPHAOP, D3DTOP_MODULATE },
- {D3DTSS_ALPHAARG1, D3DTA_TEXTURE },
- {D3DTSS_ALPHAARG2, D3DTA_DIFFUSE },
-};
-
-void RestoreShaders()
-{
- D3D::SetTexture(0, 0);
- D3D::RefreshStreamSource(0);
- D3D::RefreshIndices();
- D3D::RefreshVertexDeclaration();
- D3D::RefreshPixelShader();
- D3D::RefreshVertexShader();
-}
-
-void RestoreRenderStates()
-{
- RestoreShaders();
- for (int i = 0; i < 6; i++)
- {
- D3D::RefreshRenderState((_D3DRENDERSTATETYPE)RS[i][0]);
- D3D::RefreshTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]));
- }
-}
-
-void CD3DFont::SetRenderStates()
-{
- D3D::SetTexture(0, m_pTexture);
-
- D3D::ChangePixelShader(0);
- D3D::ChangeVertexShader(0);
- D3D::ChangeVertexDeclaration(0);
- dev->SetFVF(D3DFVF_FONT2DVERTEX);
-
- for (int i = 0; i < 6; i++)
- {
- D3D::ChangeRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS[i][1]);
- D3D::ChangeTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1]);
- }
-}
-
-
-int CD3DFont::DrawTextScaled(float x, float y, float fXScale, float fYScale, float spacing, u32 dwColor, const char* strText)
-{
- if (!m_pVB)
- return 0;
-
- SetRenderStates();
- D3D::ChangeStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX));
-
- float vpWidth = 1;
- float vpHeight = 1;
-
- float sx = x*vpWidth-0.5f;
- float sy = y*vpHeight-0.5f;
-
- float fStartX = sx;
-
- float invLineHeight = 1.0f / ((m_fTexCoords[0][3] - m_fTexCoords[0][1]) * m_dwTexHeight);
- // Fill vertex buffer
- FONT2DVERTEX* pVertices;
- int dwNumTriangles = 0L;
- m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
-
- const char *oldstrText=strText;
- //First, let's measure the text
- float tw=0;
- float mx=0;
- float maxx=0;
-
- while (*strText)
- {
- char c = *strText++;
-
- if (c == ('\n'))
- mx = 0;
- if (c < (' '))
- continue;
-
- float tx1 = m_fTexCoords[c-32][0];
- float tx2 = m_fTexCoords[c-32][2];
-
- float w = (tx2-tx1)*m_dwTexWidth;
- w *= (fXScale*vpHeight)*invLineHeight;
- mx += w + spacing*fXScale*vpWidth;
- if (mx > maxx) maxx = mx;
- }
-
- float offset = -maxx/2;
- strText = oldstrText;
-
- float wScale = (fXScale*vpHeight)*invLineHeight;
- float hScale = (fYScale*vpHeight)*invLineHeight;
-
- // Let's draw it
- while (*strText)
- {
- char c = *strText++;
-
- if (c == ('\n'))
- {
- sx = fStartX;
- sy += fYScale*vpHeight;
- }
- if (c < (' '))
- continue;
-
- c -= 32;
- float tx1 = m_fTexCoords[c][0];
- float ty1 = m_fTexCoords[c][1];
- float tx2 = m_fTexCoords[c][2];
- float ty2 = m_fTexCoords[c][3];
-
- float w = (tx2-tx1)*m_dwTexWidth;
- float h = (ty2-ty1)*m_dwTexHeight;
-
- w *= wScale;
- h *= hScale;
-
- FONT2DVERTEX v[6];
- v[0] = InitFont2DVertex(sx, sy+h, dwColor, tx1, ty2);
- v[1] = InitFont2DVertex(sx, sy, dwColor, tx1, ty1);
- v[2] = InitFont2DVertex(sx+w, sy+h, dwColor, tx2, ty2);
- v[3] = InitFont2DVertex(sx+w, sy, dwColor, tx2, ty1);
- v[4] = v[2];
- v[5] = v[1];
-
- memcpy(pVertices, v, 6*sizeof(FONT2DVERTEX));
-
- pVertices+=6;
- dwNumTriangles += 2;
-
- if (dwNumTriangles * 3 > (MAX_NUM_VERTICES - 6))
- {
- // Unlock, render, and relock the vertex buffer
- m_pVB->Unlock();
- dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
- m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
- dwNumTriangles = 0;
- }
- sx += w + spacing*fXScale*vpWidth;
- }
-
- // Unlock and render the vertex buffer
- m_pVB->Unlock();
- if (dwNumTriangles > 0)
- dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
- RestoreRenderStates();
- return S_OK;
-}
-
-/* Explanation of texture copying via drawShadedTexQuad and drawShadedTexSubQuad:
- From MSDN: "When rendering 2D output using pre-transformed vertices,
- care must be taken to ensure that each texel area correctly corresponds
- to a single pixel area, otherwise texture distortion can occur."
- => We need to subtract 0.5 from the vertex positions to properly map texels to pixels.
- HOWEVER, the MSDN article talks about D3DFVF_XYZRHW vertices, which bypass the programmable pipeline.
- Since we're using D3DFVF_XYZW and the programmable pipeline though, the vertex positions
- are normalized to [-1;+1], i.e. we need to scale the -0.5 offset by the texture dimensions.
- For example see a texture with a width of 640 pixels:
- "Expected" coordinate range when using D3DFVF_XYZRHW: [0;640]
- Normalizing this coordinate range for D3DFVF_XYZW: [0;640]->[-320;320]->[-1;1]
- i.e. we're subtracting width/2 and dividing by width/2
- BUT: The actual range when using D3DFVF_XYZRHW needs to be [-0.5;639.5] because of the need for exact texel->pixel mapping.
- We can still apply the same normalizing procedure though:
- [-0.5;639.5]->[-320-0.5;320-0.5]->[-1-0.5/320;1-0.5/320]
-
- So generally speaking the correct coordinate range is [-1-0.5/(w/2);1-0.5/(w/2)]
- which can be simplified to [-1-1/w;1-1/w].
-
- Note that while for D3DFVF_XYZRHW the y coordinate of the bottom of the screen is positive,
- it's negative for D3DFVF_XYZW. This is why we need to _add_ 1/h for the second position component instead of subtracting it.
-
- For a detailed explanation of this read the MSDN article "Directly Mapping Texels to Pixels (Direct3D 9)".
-*/
-void drawShadedTexQuad(IDirect3DTexture9 *texture,
- const RECT *rSource,
- int SourceWidth,
- int SourceHeight,
- int DestWidth,
- int DestHeight,
- IDirect3DPixelShader9 *PShader,
- IDirect3DVertexShader9 *Vshader,
- float Gamma)
-{
- float sw = 1.0f /(float) SourceWidth;
- float sh = 1.0f /(float) SourceHeight;
- float dw = 1.0f /(float) DestWidth;
- float dh = 1.0f /(float) DestHeight;
- float u1=((float)rSource->left) * sw;
- float u2=((float)rSource->right) * sw;
- float v1=((float)rSource->top) * sh;
- float v2=((float)rSource->bottom) * sh;
- float g = 1.0f/Gamma;
-
- const struct Q2DVertex { float x,y,z,rhw,u,v,w,h,G; } coords[4] = {
- {-1.0f - dw,-1.0f + dh, 0.0f,1.0f, u1, v2, sw, sh, g},
- {-1.0f - dw, 1.0f + dh, 0.0f,1.0f, u1, v1, sw, sh, g},
- { 1.0f - dw,-1.0f + dh, 0.0f,1.0f, u2, v2, sw, sh, g},
- { 1.0f - dw, 1.0f + dh, 0.0f,1.0f, u2, v1, sw, sh, g}
- };
- D3D::ChangeVertexShader(Vshader);
- D3D::ChangePixelShader(PShader);
- D3D::SetTexture(0, texture);
- D3D::ChangeVertexDeclaration(0);
- dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE1(2));
- dev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, coords, sizeof(Q2DVertex));
- RestoreShaders();
-}
-
-void drawShadedTexSubQuad(IDirect3DTexture9 *texture,
- const MathUtil::Rectangle *rSource,
- int SourceWidth,
- int SourceHeight,
- const MathUtil::Rectangle *rDest,
- int DestWidth,
- int DestHeight,
- IDirect3DPixelShader9 *PShader,
- IDirect3DVertexShader9 *Vshader,
- float Gamma)
-{
- float sw = 1.0f /(float) SourceWidth;
- float sh = 1.0f /(float) SourceHeight;
- float dw = 1.0f /(float) DestWidth;
- float dh = 1.0f /(float) DestHeight;
- float u1= rSource->left * sw;
- float u2= rSource->right * sw;
- float v1= rSource->top * sh;
- float v2= rSource->bottom * sh;
- float g = 1.0f/Gamma;
-
- struct Q2DVertex { float x,y,z,rhw,u,v,w,h,G; } coords[4] = {
- { rDest->left - dw , rDest->top + dh, 1.0f,1.0f, u1, v2, sw, sh, g},
- { rDest->left - dw , rDest->bottom + dh, 1.0f,1.0f, u1, v1, sw, sh, g},
- { rDest->right - dw , rDest->top + dh, 1.0f,1.0f, u2, v2, sw, sh, g},
- { rDest->right - dw , rDest->bottom + dh, 1.0f,1.0f, u2, v1, sw, sh, g}
- };
- D3D::ChangeVertexShader(Vshader);
- D3D::ChangePixelShader(PShader);
- D3D::SetTexture(0, texture);
- D3D::ChangeVertexDeclaration(0);
- dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE1(2));
- dev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, coords, sizeof(Q2DVertex));
- RestoreShaders();
-}
-
-// Fills a certain area of the current render target with the specified color
-// Z buffer disabled; destination coordinates normalized to (-1;1)
-void drawColorQuad(u32 Color, float x1, float y1, float x2, float y2)
-{
- struct CQVertex { float x, y, z, rhw; u32 col; } coords[4] = {
- { x1, y2, 0.f, 1.f, Color },
- { x2, y2, 0.f, 1.f, Color },
- { x1, y1, 0.f, 1.f, Color },
- { x2, y1, 0.f, 1.f, Color },
- };
- D3D::ChangeVertexShader(VertexShaderCache::GetClearVertexShader());
- D3D::ChangePixelShader(PixelShaderCache::GetClearProgram());
- D3D::ChangeVertexDeclaration(0);
- dev->SetFVF(D3DFVF_XYZW | D3DFVF_DIFFUSE);
- dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(CQVertex));
- RestoreShaders();
-}
-
-void drawClearQuad(u32 Color,float z,IDirect3DPixelShader9 *PShader,IDirect3DVertexShader9 *Vshader)
-{
- struct Q2DVertex { float x,y,z,rhw;u32 color;} coords[4] = {
- {-1.0f, 1.0f, z, 1.0f, Color},
- { 1.0f, 1.0f, z, 1.0f, Color},
- { 1.0f, -1.0f, z, 1.0f, Color},
- {-1.0f, -1.0f, z, 1.0f, Color}
- };
- D3D::ChangeVertexShader(Vshader);
- D3D::ChangePixelShader(PShader);
- D3D::ChangeVertexDeclaration(0);
- dev->SetFVF(D3DFVF_XYZW | D3DFVF_DIFFUSE);
- dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex));
- RestoreShaders();
-}
-
-
-} // namespace
-
-} // namespace DX9
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.h b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.h
deleted file mode 100644
index 35cc63a5f0..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "D3DBase.h"
-#include
-#include
-
-namespace DX9
-{
-
-namespace D3D
-{
- // Font creation flags
- #define D3DFONT_BOLD 0x0001
- #define D3DFONT_ITALIC 0x0002
-
- // Font rendering flags
- #define D3DFONT_CENTERED 0x0001
-
- //a cut-down variant of the DXSDK CD3DFont class
- class CD3DFont
- {
- LPDIRECT3DTEXTURE9 m_pTexture; // The d3d texture for this font
- LPDIRECT3DVERTEXBUFFER9 m_pVB; // VertexBuffer for rendering text
- //int m_dwTexWidth; // Texture dimensions
- //int m_dwTexHeight;
- float m_fTextScale;
- float m_fTexCoords[128-32][4];
-
- public:
- CD3DFont();
- // 2D (no longer 3D) text drawing function
- // Initializing and destroying device-dependent objects
- void SetRenderStates();
- int Init();
- int Shutdown();
- int DrawTextScaled( float x, float y,
- float fXScale, float fYScale,
- float spacing, u32 dwColor,
- const char* strText);
-
-
- // Constructor / destructor
- //~CD3DFont();
- };
-
- extern CD3DFont font;
-
- void quad2d(float x1, float y1, float x2, float y2, u32 color, float u1=0, float v1=0, float u2=1, float v2=1);
- void drawShadedTexQuad(IDirect3DTexture9 *texture,
- const RECT *rSource,
- int SourceWidth,
- int SourceHeight,
- int DestWidth,
- int DestHeight,
- IDirect3DPixelShader9 *PShader,
- IDirect3DVertexShader9 *Vshader,
- float Gamma = 1.0f);
- void drawShadedTexSubQuad(IDirect3DTexture9 *texture,
- const MathUtil::Rectangle *rSource,
- int SourceWidth,
- int SourceHeight,
- const MathUtil::Rectangle *rDest,
- int DestWidth,
- int DestHeight,
- IDirect3DPixelShader9 *PShader,
- IDirect3DVertexShader9 *Vshader,
- float Gamma = 1.0f);
- void drawClearQuad(u32 Color, float z, IDirect3DPixelShader9 *PShader, IDirect3DVertexShader9 *Vshader);
- void drawColorQuad(u32 Color, float x1, float y1, float x2, float y2);
-
- void SaveRenderStates();
- void RestoreRenderStates();
-}
-
-} // namespace DX9
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp
deleted file mode 100644
index 6b83b0e0d6..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include "D3DBase.h"
-#include "Render.h"
-#include "FramebufferManager.h"
-#include "VideoConfig.h"
-#include "PixelShaderCache.h"
-#include "VertexShaderCache.h"
-#include "TextureConverter.h"
-#include "HW/Memmap.h"
-
-namespace DX9
-{
-
-// TODO: this is probably somewhere else
-#define SAFE_RELEASE(p) if (p) { (p)->Release(); (p) = NULL; }
-
-#undef CHECK
-#define CHECK(hr, Message, ...) if (FAILED(hr)) { PanicAlert(__FUNCTION__ "Failed in %s at line %d: " Message, __FILE__, __LINE__, __VA_ARGS__); }
-
-inline void GetSurface(IDirect3DTexture9* texture, IDirect3DSurface9** surface)
-{
- if (!texture) return;
- texture->GetSurfaceLevel(0, surface);
-}
-
-FramebufferManager::Efb FramebufferManager::s_efb;
-
-FramebufferManager::FramebufferManager()
-{
- bool depth_textures_supported = true;
- int target_width = Renderer::GetTargetWidth();
- int target_height = Renderer::GetTargetHeight();
- s_efb.color_surface_Format = D3DFMT_A8R8G8B8;
-
- // EFB color texture - primary render target
- HRESULT hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb.color_surface_Format,
- D3DPOOL_DEFAULT, &s_efb.color_texture, NULL);
- GetSurface(s_efb.color_texture, &s_efb.color_surface);
- CHECK(hr, "Create color texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
-
- // Render buffer for AccessEFB (color data)
- hr = D3D::dev->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, s_efb.color_surface_Format,
- D3DPOOL_DEFAULT, &s_efb.colorRead_texture, NULL);
- GetSurface(s_efb.colorRead_texture, &s_efb.color_ReadBuffer);
- CHECK(hr, "Create Color Read Texture (hr=%#x)", hr);
-
- // AccessEFB - Sysmem buffer used to retrieve the pixel data from color_ReadBuffer
- hr = D3D::dev->CreateOffscreenPlainSurface(1, 1, s_efb.color_surface_Format, D3DPOOL_SYSTEMMEM, &s_efb.color_OffScreenReadBuffer, NULL);
- CHECK(hr, "Create offscreen color surface (hr=%#x)", hr);
-
- // Select a Z-buffer texture format with hardware support
- s_efb.depth_surface_Format = D3D::GetSupportedDepthTextureFormat();
- if (s_efb.depth_surface_Format == D3DFMT_UNKNOWN)
- {
- // workaround for Intel GPUs etc: only create a depth _surface_
- depth_textures_supported = false;
- s_efb.depth_surface_Format = D3D::GetSupportedDepthSurfaceFormat(s_efb.color_surface_Format);
- ERROR_LOG(VIDEO, "No supported depth texture format found, disabling Z peeks for EFB access.");
- }
-
- if (depth_textures_supported)
- {
- // EFB depth buffer - primary depth buffer
- hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_DEPTHSTENCIL, s_efb.depth_surface_Format,
- D3DPOOL_DEFAULT, &s_efb.depth_texture, NULL);
- GetSurface(s_efb.depth_texture, &s_efb.depth_surface);
- CHECK(hr, "Framebuffer depth texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
-
- // Render buffer for AccessEFB (depth data)
- D3DFORMAT DepthTexFormats[2];
- DepthTexFormats[0] = D3DFMT_D24X8;
- // This is expected to work on all hardware
- DepthTexFormats[1] = D3DFMT_A8R8G8B8;
-
- for (int i = 0; i < 2; ++i)
- {
- if (D3D::CheckTextureSupport(D3DUSAGE_RENDERTARGET, DepthTexFormats[i]))
- {
- s_efb.depth_ReadBuffer_Format = DepthTexFormats[i];
- break;
- }
- }
- hr = D3D::dev->CreateTexture(4, 4, 1, D3DUSAGE_RENDERTARGET, s_efb.depth_ReadBuffer_Format,
- D3DPOOL_DEFAULT, &s_efb.depthRead_texture, NULL);
- GetSurface(s_efb.depthRead_texture, &s_efb.depth_ReadBuffer);
- CHECK(hr, "Create depth read texture (hr=%#x)", hr);
-
- // AccessEFB - Sysmem buffer used to retrieve the pixel data from depth_ReadBuffer
- hr = D3D::dev->CreateOffscreenPlainSurface(4, 4, s_efb.depth_ReadBuffer_Format, D3DPOOL_SYSTEMMEM, &s_efb.depth_OffScreenReadBuffer, NULL);
- CHECK(hr, "Create depth offscreen surface (hr=%#x)", hr);
- }
- else if (s_efb.depth_surface_Format)
- {
- // just create a depth surface
- hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, s_efb.depth_surface_Format, D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb.depth_surface, NULL);
- CHECK(hr, "Framebuffer depth surface (size: %dx%d; hr=%#x)", target_width, target_height, hr);
- }
-
- // ReinterpretPixelData - EFB color data will be copy-converted to this texture and the buffers are swapped then
- hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb.color_surface_Format,
- D3DPOOL_DEFAULT, &s_efb.color_reinterpret_texture, NULL);
- GetSurface(s_efb.color_reinterpret_texture, &s_efb.color_reinterpret_surface);
- CHECK(hr, "Create color reinterpret texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
-}
-
-FramebufferManager::~FramebufferManager()
-{
- SAFE_RELEASE(s_efb.depth_surface);
- SAFE_RELEASE(s_efb.color_surface);
- SAFE_RELEASE(s_efb.color_ReadBuffer);
- SAFE_RELEASE(s_efb.depth_ReadBuffer);
- SAFE_RELEASE(s_efb.color_OffScreenReadBuffer);
- SAFE_RELEASE(s_efb.depth_OffScreenReadBuffer);
- SAFE_RELEASE(s_efb.color_texture);
- SAFE_RELEASE(s_efb.colorRead_texture);
- SAFE_RELEASE(s_efb.depth_texture);
- SAFE_RELEASE(s_efb.depthRead_texture);
- SAFE_RELEASE(s_efb.color_reinterpret_texture);
- SAFE_RELEASE(s_efb.color_reinterpret_surface);
- s_efb.color_surface_Format = D3DFMT_UNKNOWN;
- s_efb.depth_surface_Format = D3DFMT_UNKNOWN;
- s_efb.depth_ReadBuffer_Format = D3DFMT_UNKNOWN;
-}
-
-XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height)
-{
- LPDIRECT3DTEXTURE9 tex;
- D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET,
- s_efb.color_surface_Format, D3DPOOL_DEFAULT, &tex, NULL);
-
- return new XFBSource(tex);
-}
-
-void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc)
-{
- TargetRectangle targetSource;
-
- targetSource.top = ScaleToVirtualXfbHeight(sourceRc.top, Renderer::GetBackbufferHeight());
- targetSource.bottom = ScaleToVirtualXfbHeight(sourceRc.bottom, Renderer::GetBackbufferHeight());
- targetSource.left = ScaleToVirtualXfbWidth(sourceRc.left, Renderer::GetBackbufferWidth());
- targetSource.right = ScaleToVirtualXfbWidth(sourceRc.right, Renderer::GetBackbufferWidth());
-
- *width = targetSource.right - targetSource.left;
- *height = targetSource.bottom - targetSource.top;
-}
-
-void XFBSource::Draw(const MathUtil::Rectangle &sourcerc,
- const MathUtil::Rectangle &drawrc, int width, int height) const
-{
- D3D::drawShadedTexSubQuad(texture, &sourcerc, texWidth, texHeight, &drawrc, width , height,
- PixelShaderCache::GetColorCopyProgram(0), VertexShaderCache::GetSimpleVertexShader(0));
-}
-
-void XFBSource::DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
-{
- TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, texture);
-}
-
-void FramebufferManager::CopyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma)
-{
- u8* xfb_in_ram = Memory::GetPointer(xfbAddr);
- if (!xfb_in_ram)
- {
- WARN_LOG(VIDEO, "Tried to copy to invalid XFB address");
- return;
- }
-
- TargetRectangle targetRc = g_renderer->ConvertEFBRectangle(sourceRc);
- TextureConverter::EncodeToRamYUYV(GetEFBColorTexture(), targetRc, xfb_in_ram, fbWidth, fbHeight,Gamma);
-}
-
-void XFBSource::CopyEFB(float Gamma)
-{
- g_renderer->ResetAPIState(); // reset any game specific settings
-
- // Copy EFB data to XFB and restore render target again
- LPDIRECT3DSURFACE9 Rendersurf = NULL;
- texture->GetSurfaceLevel(0, &Rendersurf);
- D3D::dev->SetDepthStencilSurface(NULL);
- D3D::dev->SetRenderTarget(0, Rendersurf);
-
- D3DVIEWPORT9 vp;
- vp.X = 0;
- vp.Y = 0;
- vp.Width = texWidth;
- vp.Height = texHeight;
- vp.MinZ = 0.0f;
- vp.MaxZ = 1.0f;
- D3D::dev->SetViewport(&vp);
-
- RECT sourcerect;
- sourcerect.bottom = sourceRc.bottom;
- sourcerect.left = sourceRc.left;
- sourcerect.right = sourceRc.right;
- sourcerect.top = sourceRc.top;
-
- D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
- D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
-
- D3D::drawShadedTexQuad(
- FramebufferManager::GetEFBColorTexture(),
- &sourcerect,
- Renderer::GetTargetWidth(),
- Renderer::GetTargetHeight(),
- texWidth,
- texHeight,
- PixelShaderCache::GetColorCopyProgram( g_ActiveConfig.iMultisampleMode),
- VertexShaderCache::GetSimpleVertexShader( g_ActiveConfig.iMultisampleMode),
- Gamma);
-
- D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
- D3D::RefreshSamplerState(0, D3DSAMP_MAGFILTER);
- D3D::SetTexture(0, NULL);
- D3D::dev->SetRenderTarget(0, FramebufferManager::GetEFBColorRTSurface());
- D3D::dev->SetDepthStencilSurface(FramebufferManager::GetEFBDepthRTSurface());
-
- Rendersurf->Release();
-
- g_renderer->RestoreAPIState();
-}
-
-} // namespace DX9
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.h b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.h
deleted file mode 100644
index 66cdc2ec99..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.h
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "D3DBase.h"
-#include "FramebufferManagerBase.h"
-
-// On the GameCube, the game sends a request for the graphics processor to
-// transfer its internal EFB (Embedded Framebuffer) to an area in GameCube RAM
-// called the XFB (External Framebuffer). The size and location of the XFB is
-// decided at the time of the copy, and the format is always YUYV. The video
-// interface is given a pointer to the XFB, which will be decoded and
-// displayed on the TV.
-//
-// There are two ways for Dolphin to emulate this:
-//
-// Real XFB mode:
-//
-// Dolphin will behave like the GameCube and encode the EFB to
-// a portion of GameCube RAM. The emulated video interface will decode the data
-// for output to the screen.
-//
-// Advantages: Behaves exactly like the GameCube.
-// Disadvantages: Resolution will be limited.
-//
-// Virtual XFB mode:
-//
-// When a request is made to copy the EFB to an XFB, Dolphin
-// will remember the RAM location and size of the XFB in a Virtual XFB list.
-// The video interface will look up the XFB in the list and use the enhanced
-// data stored there, if available.
-//
-// Advantages: Enables high resolution graphics, better than real hardware.
-// Disadvantages: If the GameCube CPU writes directly to the XFB (which is
-// possible but uncommon), the Virtual XFB will not capture this information.
-
-namespace DX9
-{
-
-struct XFBSource : public XFBSourceBase
-{
- XFBSource(LPDIRECT3DTEXTURE9 tex) : texture(tex) {}
- ~XFBSource() { texture->Release(); }
-
- void Draw(const MathUtil::Rectangle &sourcerc,
- const MathUtil::Rectangle &drawrc, int width, int height) const;
- void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight);
- void CopyEFB(float Gamma);
-
- LPDIRECT3DTEXTURE9 const texture;
-};
-
-class FramebufferManager : public FramebufferManagerBase
-{
-public:
- FramebufferManager();
- ~FramebufferManager();
-
- static LPDIRECT3DTEXTURE9 GetEFBColorTexture() { return s_efb.color_texture; }
- static LPDIRECT3DTEXTURE9 GetEFBDepthTexture() { return s_efb.depth_texture; }
-
- static LPDIRECT3DSURFACE9 GetEFBColorRTSurface() { return s_efb.color_surface; }
- static LPDIRECT3DSURFACE9 GetEFBDepthRTSurface() { return s_efb.depth_surface; }
-
- static LPDIRECT3DSURFACE9 GetEFBColorOffScreenRTSurface() { return s_efb.color_OffScreenReadBuffer; }
- static LPDIRECT3DSURFACE9 GetEFBDepthOffScreenRTSurface() { return s_efb.depth_OffScreenReadBuffer; }
-
- static D3DFORMAT GetEFBDepthRTSurfaceFormat() { return s_efb.depth_surface_Format; }
- static D3DFORMAT GetEFBColorRTSurfaceFormat() { return s_efb.color_surface_Format; }
- static D3DFORMAT GetEFBDepthReadSurfaceFormat() { return s_efb.depth_ReadBuffer_Format; }
-
- static LPDIRECT3DSURFACE9 GetEFBColorReadSurface() { return s_efb.color_ReadBuffer; }
- static LPDIRECT3DSURFACE9 GetEFBDepthReadSurface() { return s_efb.depth_ReadBuffer; }
-
- static LPDIRECT3DTEXTURE9 GetEFBColorReinterpretTexture() { return s_efb.color_reinterpret_texture; }
- static LPDIRECT3DSURFACE9 GetEFBColorReinterpretSurface() { return s_efb.color_reinterpret_surface; }
- static void SwapReinterpretTexture()
- {
- LPDIRECT3DSURFACE9 swapsurf = GetEFBColorReinterpretSurface();
- LPDIRECT3DTEXTURE9 swaptex = GetEFBColorReinterpretTexture();
- s_efb.color_reinterpret_surface = GetEFBColorRTSurface();
- s_efb.color_reinterpret_texture = GetEFBColorTexture();
- s_efb.color_surface = swapsurf;
- s_efb.color_texture = swaptex;
- }
-
-private:
- XFBSourceBase* CreateXFBSource(unsigned int target_width, unsigned int target_height);
- void GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc);
-
- void CopyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma);
-
- static struct Efb
- {
- Efb() : color_texture(NULL), colorRead_texture(NULL), depth_texture(NULL), depthRead_texture(NULL),
- color_reinterpret_texture(NULL), color_reinterpret_surface(NULL),
- depth_surface(NULL), color_surface(NULL), color_ReadBuffer(NULL), depth_ReadBuffer(NULL),
- color_OffScreenReadBuffer(NULL), depth_OffScreenReadBuffer(NULL),
- color_surface_Format(D3DFMT_UNKNOWN), depth_surface_Format(D3DFMT_UNKNOWN),
- depth_ReadBuffer_Format(D3DFMT_UNKNOWN) {}
-
- LPDIRECT3DTEXTURE9 color_texture;//Texture that contains the color data of the render target
- LPDIRECT3DTEXTURE9 colorRead_texture;//1 pixel texture for temporal data store
- LPDIRECT3DTEXTURE9 depth_texture;//Texture that contains the depth data of the render target
- LPDIRECT3DTEXTURE9 depthRead_texture;//4 pixel texture for temporal data store
-
- LPDIRECT3DTEXTURE9 color_reinterpret_texture;//buffer used for ReinterpretPixelData
- LPDIRECT3DSURFACE9 color_reinterpret_surface;//corresponding surface
-
- LPDIRECT3DSURFACE9 depth_surface;//Depth Surface
- LPDIRECT3DSURFACE9 color_surface;//Color Surface
- LPDIRECT3DSURFACE9 color_ReadBuffer;//Surface 0 of colorRead_texture
- LPDIRECT3DSURFACE9 depth_ReadBuffer;//Surface 0 of depthRead_texture
- LPDIRECT3DSURFACE9 color_OffScreenReadBuffer;//System memory Surface that can be locked to retrieve the data
- LPDIRECT3DSURFACE9 depth_OffScreenReadBuffer;//System memory Surface that can be locked to retrieve the data
-
- D3DFORMAT color_surface_Format;//Format of the color Surface
- D3DFORMAT depth_surface_Format;//Format of the Depth Surface
- D3DFORMAT depth_ReadBuffer_Format;//Format of the Depth color Read Surface
- } s_efb;
-};
-
-} // namespace DX9
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Globals.h b/Source/Plugins/Plugin_VideoDX9/Src/Globals.h
deleted file mode 100644
index 89800694e8..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/Globals.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#ifndef _GLOBALS_H_
-#define _GLOBALS_H_
-
-#include "Common.h"
-#include "VideoConfig.h"
-#include "main.h"
-
-#include "VideoCommon.h"
-
-#endif // _GLOBALS_H_
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp
deleted file mode 100644
index 69de7e0a58..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include "D3DBase.h"
-
-#include "x64Emitter.h"
-#include "x64ABI.h"
-#include "MemoryUtil.h"
-#include "VertexShaderGen.h"
-
-#include "CPMemory.h"
-#include "NativeVertexFormat.h"
-#include "VertexManager.h"
-
-namespace DX9
-{
-
-class D3DVertexFormat : public NativeVertexFormat
-{
- LPDIRECT3DVERTEXDECLARATION9 d3d_decl;
-
-public:
- D3DVertexFormat() : d3d_decl(NULL) {}
- ~D3DVertexFormat();
- virtual void Initialize(const PortableVertexDeclaration &_vtx_decl);
- virtual void SetupVertexPointers();
-
-#if defined(_DEBUG) || defined(DEBUGFAST)
- D3DVERTEXELEMENT9 elements[32];
- int num_elements;
-#endif
-};
-
-NativeVertexFormat* VertexManager::CreateNativeVertexFormat()
-{
- return new D3DVertexFormat();
-}
-
-void DX9::VertexManager::GetElements(NativeVertexFormat* format, D3DVERTEXELEMENT9** elems, int* num)
-{
-#if defined(_DEBUG) || defined(DEBUGFAST)
- *elems = ((D3DVertexFormat*)format)->elements;
- *num = ((D3DVertexFormat*)format)->num_elements;
-#else
- *elems = NULL;
- *num = 0;
-#endif
-}
-
-D3DVertexFormat::~D3DVertexFormat()
-{
- if (d3d_decl)
- {
- d3d_decl->Release();
- d3d_decl = NULL;
- }
-}
-
-D3DDECLTYPE VarToD3D(VarType t, int size)
-{
- if (t < 0 || t > 4) {
- PanicAlert("VarToD3D: Invalid VarType %i", t);
- }
- static const D3DDECLTYPE lookup1[5] = {
- D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_FLOAT1,
- };
- static const D3DDECLTYPE lookup2[5] = {
- D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_SHORT2N, D3DDECLTYPE_USHORT2N, D3DDECLTYPE_FLOAT2,
- };
- static const D3DDECLTYPE lookup3[5] = {
- D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_UNUSED, D3DDECLTYPE_FLOAT3,
- };
- // Sadly, D3D9 has no SBYTE4N. D3D10 does, though.
- static const D3DDECLTYPE lookup4[5] = {
- D3DDECLTYPE_UNUSED, D3DDECLTYPE_UBYTE4N, D3DDECLTYPE_SHORT4N, D3DDECLTYPE_USHORT4N, D3DDECLTYPE_FLOAT4,
- };
- D3DDECLTYPE retval = D3DDECLTYPE_UNUSED;
- switch (size)
- {
- case 1: retval = lookup1[t]; break;
- case 2: retval = lookup2[t]; break;
- case 3: retval = lookup3[t]; break;
- case 4: retval = lookup4[t]; break;
- default: break;
- }
- if (retval == D3DDECLTYPE_UNUSED) {
- PanicAlert("VarToD3D: Invalid type/size combo %i , %i", (int)t, size);
- }
- return retval;
-}
-
-void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
-{
- vertex_stride = _vtx_decl.stride;
-
- D3DVERTEXELEMENT9 elems[32];
- memset(elems, 0, sizeof(elems));
-
- // There's only one stream and it's 0, so the above memset takes care of that - no need to set Stream.
- // Same for method.
-
- // So, here we go. First position:
- int elem_idx = 0;
- elems[elem_idx].Offset = 0; // Positions are always first, at position 0. Always float3.
- elems[elem_idx].Type = D3DDECLTYPE_FLOAT3;
- elems[elem_idx].Usage = D3DDECLUSAGE_POSITION;
- ++elem_idx;
-
- for (int i = 0; i < 3; i++)
- {
- if (_vtx_decl.normal_offset[i] > 0)
- {
- elems[elem_idx].Offset = _vtx_decl.normal_offset[i];
- elems[elem_idx].Type = VarToD3D(_vtx_decl.normal_gl_type, _vtx_decl.normal_gl_size);
- elems[elem_idx].Usage = D3DDECLUSAGE_NORMAL;
- elems[elem_idx].UsageIndex = i;
- ++elem_idx;
- }
- }
-
- for (int i = 0; i < 2; i++)
- {
- if (_vtx_decl.color_offset[i] > 0)
- {
- elems[elem_idx].Offset = _vtx_decl.color_offset[i];
- elems[elem_idx].Type = VarToD3D(_vtx_decl.color_gl_type, 4);
- elems[elem_idx].Usage = D3DDECLUSAGE_COLOR;
- elems[elem_idx].UsageIndex = i;
- ++elem_idx;
- }
- }
-
- for (int i = 0; i < 8; i++)
- {
- if (_vtx_decl.texcoord_offset[i] > 0)
- {
- elems[elem_idx].Offset = _vtx_decl.texcoord_offset[i];
- elems[elem_idx].Type = VarToD3D(_vtx_decl.texcoord_gl_type[i], _vtx_decl.texcoord_size[i]);
- elems[elem_idx].Usage = D3DDECLUSAGE_TEXCOORD;
- elems[elem_idx].UsageIndex = i;
- ++elem_idx;
- }
- }
-
- if (_vtx_decl.posmtx_offset != -1)
- {
- elems[elem_idx].Offset = _vtx_decl.posmtx_offset;
- elems[elem_idx].Usage = D3DDECLUSAGE_BLENDINDICES;
- elems[elem_idx].Type = D3DDECLTYPE_D3DCOLOR;
- elems[elem_idx].UsageIndex = 0;
- ++elem_idx;
- }
-
- // End marker
- elems[elem_idx].Stream = 0xff;
- elems[elem_idx].Type = D3DDECLTYPE_UNUSED;
- ++elem_idx;
-
- if (FAILED(DX9::D3D::dev->CreateVertexDeclaration(elems, &d3d_decl)))
- {
- PanicAlert("Failed to create D3D vertex declaration!");
- return;
- }
-#if defined(_DEBUG) || defined(DEBUGFAST)
- memcpy(&elements, elems, sizeof(elems));
- num_elements = elem_idx;
-#endif
-}
-
-void D3DVertexFormat::SetupVertexPointers()
-{
- if (d3d_decl)
- DX9::D3D::SetVertexDeclaration(d3d_decl);
- else
- ERROR_LOG(VIDEO, "Invalid D3D decl");
-}
-
-} // namespace DX9
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp
deleted file mode 100644
index 3e6f058fdd..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-#include "RenderBase.h"
-
-#include "D3DBase.h"
-#include "PerfQuery.h"
-
-namespace DX9 {
-
-PerfQuery::PerfQuery()
- : m_query_read_pos()
- , m_query_count()
-{
-
-}
-
-PerfQuery::~PerfQuery()
-{
-
-}
-
-void PerfQuery::CreateDeviceObjects()
-{
- for (int i = 0; i != ArraySize(m_query_buffer); ++i)
- {
- D3D::dev->CreateQuery(D3DQUERYTYPE_OCCLUSION, &m_query_buffer[i].query);
- }
- ResetQuery();
-}
-void PerfQuery::DestroyDeviceObjects()
-{
- for (int i = 0; i != ArraySize(m_query_buffer); ++i)
- {
- m_query_buffer[i].query->Release();
- }
-}
-
-void PerfQuery::EnableQuery(PerfQueryGroup type)
-{
- if (!ShouldEmulate())
- return;
- // Is this sane?
- if (m_query_count > ArraySize(m_query_buffer) / 2)
- WeakFlush();
-
- if (ArraySize(m_query_buffer) == m_query_count)
- {
- // TODO
- FlushOne();
- ERROR_LOG(VIDEO, "Flushed query buffer early!");
- }
-
- // start query
- if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
- {
- auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % ArraySize(m_query_buffer)];
- entry.query->Issue(D3DISSUE_BEGIN);
- entry.query_type = type;
- ++m_query_count;
- }
-}
-
-void PerfQuery::DisableQuery(PerfQueryGroup type)
-{
- if (!ShouldEmulate())
- return;
- // stop query
- if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
- {
- auto& entry = m_query_buffer[(m_query_read_pos + m_query_count + ArraySize(m_query_buffer)-1) % ArraySize(m_query_buffer)];
- entry.query->Issue(D3DISSUE_END);
- }
-}
-
-void PerfQuery::ResetQuery()
-{
- m_query_count = 0;
- std::fill_n(m_results, ArraySize(m_results), 0);
-}
-
-u32 PerfQuery::GetQueryResult(PerfQueryType type)
-{
- if (!ShouldEmulate())
- return 0;
- u32 result = 0;
-
- if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC)
- {
- result = m_results[PQG_ZCOMP_ZCOMPLOC];
- }
- else if (type == PQ_ZCOMP_INPUT || type == PQ_ZCOMP_OUTPUT)
- {
- result = m_results[PQG_ZCOMP];
- }
- else if (type == PQ_BLEND_INPUT)
- {
- result = m_results[PQG_ZCOMP] + m_results[PQG_ZCOMP_ZCOMPLOC];
- }
- else if (type == PQ_EFB_COPY_CLOCKS)
- {
- result = m_results[PQG_EFB_COPY_CLOCKS];
- }
-
- return result / 4;
-}
-
-void PerfQuery::FlushOne()
-{
- if (!ShouldEmulate())
- return;
- auto& entry = m_query_buffer[m_query_read_pos];
-
- DWORD result = 0;
- HRESULT hr = S_FALSE;
- while (hr != S_OK && hr != D3DERR_DEVICELOST)
- {
- // TODO: Might cause us to be stuck in an infinite loop!
- hr = entry.query->GetData(&result, sizeof(result), D3DGETDATA_FLUSH);
- }
-
- // NOTE: Reported pixel metrics should be referenced to native resolution
- m_results[entry.query_type] += (u32)((u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight());
-
- m_query_read_pos = (m_query_read_pos + 1) % ArraySize(m_query_buffer);
- --m_query_count;
-}
-
-// TODO: could selectively flush things, but I don't think that will do much
-void PerfQuery::FlushResults()
-{
- if (!ShouldEmulate())
- return;
- while (!IsFlushed())
- FlushOne();
-}
-
-void PerfQuery::WeakFlush()
-{
- if (!ShouldEmulate())
- return;
- while (!IsFlushed())
- {
- auto& entry = m_query_buffer[m_query_read_pos];
-
- DWORD result = 0;
- HRESULT hr = entry.query->GetData(&result, sizeof(result), 0);
-
- if (hr == S_OK)
- {
- // NOTE: Reported pixel metrics should be referenced to native resolution
- m_results[entry.query_type] += (u32)((u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight());
-
- m_query_read_pos = (m_query_read_pos + 1) % ArraySize(m_query_buffer);
- --m_query_count;
- }
- else
- {
- break;
- }
- }
-}
-
-bool PerfQuery::IsFlushed() const
-{
- if (!ShouldEmulate())
- return true;
- return 0 == m_query_count;
-}
-
-
-} // namespace
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.h b/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.h
deleted file mode 100644
index 9b8f637655..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef _PERFQUERY_H_
-#define _PERFQUERY_H_
-
-#include "PerfQueryBase.h"
-
-namespace DX9 {
-
-class PerfQuery : public PerfQueryBase
-{
-public:
- PerfQuery();
- ~PerfQuery();
-
- void EnableQuery(PerfQueryGroup type);
- void DisableQuery(PerfQueryGroup type);
- void ResetQuery();
- u32 GetQueryResult(PerfQueryType type);
- void FlushResults();
- bool IsFlushed() const;
- void CreateDeviceObjects();
- void DestroyDeviceObjects();
-
-private:
- struct ActiveQuery
- {
- IDirect3DQuery9* query;
- PerfQueryGroup query_type;
- };
-
- void WeakFlush();
- // Only use when non-empty
- void FlushOne();
-
- // when testing in SMS: 64 was too small, 128 was ok
- static const int PERF_QUERY_BUFFER_SIZE = 512;
-
- ActiveQuery m_query_buffer[PERF_QUERY_BUFFER_SIZE];
- int m_query_read_pos;
-
- // TODO: sloppy
- volatile int m_query_count;
- volatile u32 m_results[PQG_NUM_MEMBERS];
-};
-
-} // namespace
-
-#endif // _PERFQUERY_H_
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp
deleted file mode 100644
index ea6503e9e0..0000000000
--- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp
+++ /dev/null
@@ -1,449 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include