From 744fa18d950abdc7940323083d1298af70885738 Mon Sep 17 00:00:00 2001 From: lightningterror Date: Fri, 25 Jan 2019 18:06:08 +0100 Subject: [PATCH] gsdx-d3d11: Merge/move GSDeviceDX code to GSDevice11. Update VS and cmake project files, remove GSDeviceDX files. --- plugins/GSdx/CMakeLists.txt | 2 - plugins/GSdx/GS.cpp | 4 +- plugins/GSdx/GSUtil.cpp | 6 +- plugins/GSdx/GSdx.vcxproj | 2 - plugins/GSdx/GSdx.vcxproj.filters | 6 - plugins/GSdx/PSX/GPU.cpp | 4 +- plugins/GSdx/Renderers/DX11/GSDevice11.cpp | 193 ++++++++- plugins/GSdx/Renderers/DX11/GSDevice11.h | 342 +++++++++++++++- plugins/GSdx/Renderers/DX11/GSRendererDX11.h | 18 +- .../GSdx/Renderers/DXCommon/GSDeviceDX.cpp | 225 ----------- plugins/GSdx/Renderers/DXCommon/GSDeviceDX.h | 365 ------------------ 11 files changed, 538 insertions(+), 629 deletions(-) delete mode 100644 plugins/GSdx/Renderers/DXCommon/GSDeviceDX.cpp delete mode 100644 plugins/GSdx/Renderers/DXCommon/GSDeviceDX.h diff --git a/plugins/GSdx/CMakeLists.txt b/plugins/GSdx/CMakeLists.txt index ccbbd3bd26..510119581d 100644 --- a/plugins/GSdx/CMakeLists.txt +++ b/plugins/GSdx/CMakeLists.txt @@ -213,7 +213,6 @@ set(GSdxHeaders if(Windows) LIST(APPEND GSdxSources Renderers/DX11/GSDevice11.cpp - Renderers/DXCommon/GSDeviceDX.cpp Window/GSDialog.cpp Renderers/DX11/GSRendererDX11.cpp Renderers/DX11/GSTexture11.cpp @@ -230,7 +229,6 @@ if(Windows) LIST(APPEND GSdxHeaders Renderers/DX11/GSDevice11.h - Renderers/DXCommon/GSDeviceDX.h Renderers/DX11/GSRendererDX11.h Renderers/DX11/GSTexture11.h Renderers/DX11/GSTextureCache11.h diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index 53ee251e73..193e632439 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -151,7 +151,7 @@ EXPORT_C_(int) GSinit() s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); - if (!GSDeviceDX::LoadD3DCompiler()) + if (!GSDevice11::LoadD3DCompiler()) { return -1; } @@ -178,7 +178,7 @@ EXPORT_C GSshutdown() s_hr = E_FAIL; } - GSDeviceDX::FreeD3DCompiler(); + GSDevice11::FreeD3DCompiler(); #endif } diff --git a/plugins/GSdx/GSUtil.cpp b/plugins/GSdx/GSUtil.cpp index da7e716281..ef339bc4b6 100644 --- a/plugins/GSdx/GSUtil.cpp +++ b/plugins/GSdx/GSUtil.cpp @@ -23,7 +23,7 @@ #include "GSUtil.h" #ifdef _WIN32 -#include "Renderers/DXCommon/GSDeviceDX.h" +#include "Renderers/DX11/GSDevice11.h" #include #include "svnrev.h" #else @@ -341,9 +341,9 @@ std::string GSUtil::GetDeviceUniqueName(cl::Device& device) bool GSUtil::CheckDirectX() { - if (GSDeviceDX::LoadD3DCompiler()) + if (GSDevice11::LoadD3DCompiler()) { - GSDeviceDX::FreeD3DCompiler(); + GSDevice11::FreeD3DCompiler(); return true; } diff --git a/plugins/GSdx/GSdx.vcxproj b/plugins/GSdx/GSdx.vcxproj index 9045ae714a..ee6143f6f3 100644 --- a/plugins/GSdx/GSdx.vcxproj +++ b/plugins/GSdx/GSdx.vcxproj @@ -102,7 +102,6 @@ - @@ -190,7 +189,6 @@ - diff --git a/plugins/GSdx/GSdx.vcxproj.filters b/plugins/GSdx/GSdx.vcxproj.filters index 2a032999f6..a23f4a842e 100644 --- a/plugins/GSdx/GSdx.vcxproj.filters +++ b/plugins/GSdx/GSdx.vcxproj.filters @@ -186,9 +186,6 @@ Source Files - - Source Files - Source Files @@ -308,9 +305,6 @@ Header Files - - Header Files - Header Files diff --git a/plugins/GSdx/PSX/GPU.cpp b/plugins/GSdx/PSX/GPU.cpp index 6c94688421..33760b6479 100644 --- a/plugins/GSdx/PSX/GPU.cpp +++ b/plugins/GSdx/PSX/GPU.cpp @@ -98,7 +98,7 @@ EXPORT_C_(int32) GPUclose() s_gpu = NULL; #ifdef _WIN32 - GSDeviceDX::FreeD3DCompiler(); + GSDevice11::FreeD3DCompiler(); if(SUCCEEDED(s_hr)) { @@ -130,7 +130,7 @@ EXPORT_C_(int32) GPUopen(void* hWnd) return -1; } - if (!GSDeviceDX::LoadD3DCompiler()) + if (!GSDevice11::LoadD3DCompiler()) return -1; #endif diff --git a/plugins/GSdx/Renderers/DX11/GSDevice11.cpp b/plugins/GSdx/Renderers/DX11/GSDevice11.cpp index ab293e4dab..1b09bddc1e 100644 --- a/plugins/GSdx/Renderers/DX11/GSDevice11.cpp +++ b/plugins/GSdx/Renderers/DX11/GSDevice11.cpp @@ -25,6 +25,11 @@ #include "GSUtil.h" #include "resource.h" #include +#include + +HMODULE GSDevice11::s_d3d_compiler_dll = nullptr; +decltype(&D3DCompile) GSDevice11::s_pD3DCompile = nullptr; +bool GSDevice11::s_old_d3d_compiler_dll; GSDevice11::GSDevice11() { @@ -40,10 +45,86 @@ GSDevice11::GSDevice11() m_state.bf = -1; m_mipmap = theApp.GetConfigI("mipmap"); + m_upscale_multiplier = theApp.GetConfigI("upscale_multiplier"); } -GSDevice11::~GSDevice11() +bool GSDevice11::LoadD3DCompiler() { + // Windows 8.1 and later come with the latest d3dcompiler_47.dll, but + // Windows 7 devs might also have the dll available for use (which will + // have to be placed in the application directory) + s_d3d_compiler_dll = LoadLibraryEx(D3DCOMPILER_DLL, nullptr, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); + + // Windows Vista and 7 can use the older version. If the previous LoadLibrary + // call fails on Windows 8.1 and later, then the user's system is likely + // broken. + if (s_d3d_compiler_dll) + { + s_old_d3d_compiler_dll = false; + } + else + { + if (!IsWindows8Point1OrGreater()) + // Use LoadLibrary instead of LoadLibraryEx, some Windows 7 systems + // have issues with it. + s_d3d_compiler_dll = LoadLibrary("D3DCompiler_43.dll"); + + if (s_d3d_compiler_dll == nullptr) + return false; + + s_old_d3d_compiler_dll = true; + } + + s_pD3DCompile = reinterpret_cast(GetProcAddress(s_d3d_compiler_dll, "D3DCompile")); + if (s_pD3DCompile) + return true; + + FreeLibrary(s_d3d_compiler_dll); + s_d3d_compiler_dll = nullptr; + return false; +} + +void GSDevice11::FreeD3DCompiler() +{ + s_pD3DCompile = nullptr; + if (s_d3d_compiler_dll) + FreeLibrary(s_d3d_compiler_dll); + s_d3d_compiler_dll = nullptr; +} + +bool GSDevice11::SetFeatureLevel(D3D_FEATURE_LEVEL level, bool compat_mode) +{ + m_shader.level = level; + + switch (level) + { + case D3D_FEATURE_LEVEL_10_0: + m_shader.model = "0x400"; + m_shader.vs = "vs_4_0"; + m_shader.gs = "gs_4_0"; + m_shader.ps = "ps_4_0"; + m_shader.cs = "cs_4_0"; + break; + case D3D_FEATURE_LEVEL_10_1: + m_shader.model = "0x401"; + m_shader.vs = "vs_4_1"; + m_shader.gs = "gs_4_1"; + m_shader.ps = "ps_4_1"; + m_shader.cs = "cs_4_1"; + break; + case D3D_FEATURE_LEVEL_11_0: + m_shader.model = "0x500"; + m_shader.vs = "vs_5_0"; + m_shader.gs = "gs_5_0"; + m_shader.ps = "ps_5_0"; + m_shader.cs = "cs_5_0"; + break; + default: + ASSERT(0); + return false; + } + + return true; } bool GSDevice11::Create(const std::shared_ptr &wnd) @@ -596,6 +677,11 @@ GSTexture* GSDevice11::CreateSurface(int type, int w, int h, int format) return t; } +GSTexture* GSDevice11::FetchSurface(int type, int w, int h, int format) +{ + return __super::FetchSurface(type, w, h, format); +} + GSTexture* GSDevice11::CreateRenderTarget(int w, int h, int format) { return __super::CreateRenderTarget(w, h, format ? format : DXGI_FORMAT_R8G8B8A8_UNORM); @@ -1480,4 +1566,107 @@ void GSDevice11::CompileShader(std::vector source, const char* fn, ID3DInc { throw GSDXRecoverableError(); } -} \ No newline at end of file +} + +// (A - B) * C + D +// A: Cs/Cd/0 +// B: Cs/Cd/0 +// C: As/Ad/FIX +// D: Cs/Cd/0 + +// bogus: 0100, 0110, 0120, 0200, 0210, 0220, 1001, 1011, 1021 +// tricky: 1201, 1211, 1221 + +// Source.rgb = float3(1, 1, 1); +// 1201 Cd*(1 + As) => Source * Dest color + Dest * Source alpha +// 1211 Cd*(1 + Ad) => Source * Dest color + Dest * Dest alpha +// 1221 Cd*(1 + F) => Source * Dest color + Dest * Factor + +// Special blending method table: +// # (tricky) => 1 * Cd + Cd * F => Use (Cd, F) as factor of color (1, Cd) +// * (bogus) => C * (1 + F ) + ... => factor is always bigger than 1 (except above case) + +const GSDevice11::D3D11Blend GSDevice11::m_blendMapD3D11[3*3*3*3] = +{ + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 0000: (Cs - Cs)*As + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 0001: (Cs - Cs)*As + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 0002: (Cs - Cs)*As + 0 ==> 0 + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 0010: (Cs - Cs)*Ad + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 0011: (Cs - Cs)*Ad + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 0012: (Cs - Cs)*Ad + 0 ==> 0 + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 0020: (Cs - Cs)*F + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 0021: (Cs - Cs)*F + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 0022: (Cs - Cs)*F + 0 ==> 0 + { 1, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_SRC1_ALPHA } , //*0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_INV_SRC1_ALPHA } , // 0101: (Cs - Cd)*As + Cd ==> Cs*As + Cd*(1 - As) + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_SRC1_ALPHA } , // 0102: (Cs - Cd)*As + 0 ==> Cs*As - Cd*As + { 1, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA } , //*0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_INV_DEST_ALPHA } , // 0111: (Cs - Cd)*Ad + Cd ==> Cs*Ad + Cd*(1 - Ad) + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_DEST_ALPHA } , // 0112: (Cs - Cd)*Ad + 0 ==> Cs*Ad - Cd*Ad + { 1, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR } , //*0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_INV_BLEND_FACTOR } , // 0121: (Cs - Cd)*F + Cd ==> Cs*F + Cd*(1 - F) + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_BLEND_FACTOR } , // 0122: (Cs - Cd)*F + 0 ==> Cs*F - Cd*F + { 1, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , //*0200: (Cs - 0)*As + Cs ==> Cs*(As + 1) + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ONE } , // 0201: (Cs - 0)*As + Cd ==> Cs*As + Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ZERO } , // 0202: (Cs - 0)*As + 0 ==> Cs*As + { 1, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1) + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ONE } , // 0211: (Cs - 0)*Ad + Cd ==> Cs*Ad + Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ZERO } , // 0212: (Cs - 0)*Ad + 0 ==> Cs*Ad + { 1, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1) + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ONE } , // 0221: (Cs - 0)*F + Cd ==> Cs*F + Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ZERO } , // 0222: (Cs - 0)*F + 0 ==> Cs*F + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_SRC1_ALPHA , D3D11_BLEND_SRC1_ALPHA } , // 1000: (Cd - Cs)*As + Cs ==> Cd*As + Cs*(1 - As) + { 1, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ONE } , //*1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_SRC1_ALPHA } , // 1002: (Cd - Cs)*As + 0 ==> Cd*As - Cs*As + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_DEST_ALPHA , D3D11_BLEND_DEST_ALPHA } , // 1010: (Cd - Cs)*Ad + Cs ==> Cd*Ad + Cs*(1 - Ad) + { 1, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ONE } , //*1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_DEST_ALPHA } , // 1012: (Cd - Cs)*Ad + 0 ==> Cd*Ad - Cs*Ad + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_BLEND_FACTOR , D3D11_BLEND_BLEND_FACTOR } , // 1020: (Cd - Cs)*F + Cs ==> Cd*F + Cs*(1 - F) + { 1, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ONE } , //*1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_BLEND_FACTOR } , // 1022: (Cd - Cs)*F + 0 ==> Cd*F - Cs*F + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 1100: (Cd - Cd)*As + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 1101: (Cd - Cd)*As + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 1102: (Cd - Cd)*As + 0 ==> 0 + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 1110: (Cd - Cd)*Ad + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 1111: (Cd - Cd)*Ad + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 1112: (Cd - Cd)*Ad + 0 ==> 0 + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 1120: (Cd - Cd)*F + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 1121: (Cd - Cd)*F + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 1122: (Cd - Cd)*F + 0 ==> 0 + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_SRC1_ALPHA } , // 1200: (Cd - 0)*As + Cs ==> Cs + Cd*As + { 2, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_COLOR , D3D11_BLEND_SRC1_ALPHA } , //#1201: (Cd - 0)*As + Cd ==> Cd*(1 + As) // ffxii main menu background glow effect + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_SRC1_ALPHA } , // 1202: (Cd - 0)*As + 0 ==> Cd*As + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA } , // 1210: (Cd - 0)*Ad + Cs ==> Cs + Cd*Ad + { 2, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_COLOR , D3D11_BLEND_DEST_ALPHA } , //#1211: (Cd - 0)*Ad + Cd ==> Cd*(1 + Ad) + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_DEST_ALPHA } , // 1212: (Cd - 0)*Ad + 0 ==> Cd*Ad + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR } , // 1220: (Cd - 0)*F + Cs ==> Cs + Cd*F + { 2, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_COLOR , D3D11_BLEND_BLEND_FACTOR } , //#1221: (Cd - 0)*F + Cd ==> Cd*(1 + F) + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_BLEND_FACTOR } , // 1222: (Cd - 0)*F + 0 ==> Cd*F + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_SRC1_ALPHA , D3D11_BLEND_ZERO } , // 2000: (0 - Cs)*As + Cs ==> Cs*(1 - As) + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ONE } , // 2001: (0 - Cs)*As + Cd ==> Cd - Cs*As + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ZERO } , // 2002: (0 - Cs)*As + 0 ==> 0 - Cs*As + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_DEST_ALPHA , D3D11_BLEND_ZERO } , // 2010: (0 - Cs)*Ad + Cs ==> Cs*(1 - Ad) + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ONE } , // 2011: (0 - Cs)*Ad + Cd ==> Cd - Cs*Ad + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ZERO } , // 2012: (0 - Cs)*Ad + 0 ==> 0 - Cs*Ad + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_BLEND_FACTOR , D3D11_BLEND_ZERO } , // 2020: (0 - Cs)*F + Cs ==> Cs*(1 - F) + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ONE } , // 2021: (0 - Cs)*F + Cd ==> Cd - Cs*F + { 0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ZERO } , // 2022: (0 - Cs)*F + 0 ==> 0 - Cs*F + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_SRC1_ALPHA } , // 2100: (0 - Cd)*As + Cs ==> Cs - Cd*As + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_INV_SRC1_ALPHA } , // 2101: (0 - Cd)*As + Cd ==> Cd*(1 - As) + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ZERO , D3D11_BLEND_SRC1_ALPHA } , // 2102: (0 - Cd)*As + 0 ==> 0 - Cd*As + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA } , // 2110: (0 - Cd)*Ad + Cs ==> Cs - Cd*Ad + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_INV_DEST_ALPHA } , // 2111: (0 - Cd)*Ad + Cd ==> Cd*(1 - Ad) + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA } , // 2112: (0 - Cd)*Ad + 0 ==> 0 - Cd*Ad + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR } , // 2120: (0 - Cd)*F + Cs ==> Cs - Cd*F + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_INV_BLEND_FACTOR } , // 2121: (0 - Cd)*F + Cd ==> Cd*(1 - F) + { 0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR } , // 2122: (0 - Cd)*F + 0 ==> 0 - Cd*F + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 2200: (0 - 0)*As + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 2201: (0 - 0)*As + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 2202: (0 - 0)*As + 0 ==> 0 + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 2210: (0 - 0)*Ad + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 2211: (0 - 0)*Ad + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 2212: (0 - 0)*Ad + 0 ==> 0 + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO } , // 2220: (0 - 0)*F + Cs ==> Cs + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE } , // 2221: (0 - 0)*F + Cd ==> Cd + { 0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO } , // 2222: (0 - 0)*F + 0 ==> 0 +}; \ No newline at end of file diff --git a/plugins/GSdx/Renderers/DX11/GSDevice11.h b/plugins/GSdx/Renderers/DX11/GSDevice11.h index 8d8625f904..7f4ee21c74 100644 --- a/plugins/GSdx/Renderers/DX11/GSDevice11.h +++ b/plugins/GSdx/Renderers/DX11/GSDevice11.h @@ -21,8 +21,9 @@ #pragma once -#include "Renderers\DXCommon\GSDeviceDX.h" #include "GSTexture11.h" +#include "GSVector.h" +#include "Renderers/Common/GSDevice.h" struct GSVertexShader11 { @@ -30,9 +31,297 @@ struct GSVertexShader11 CComPtr il; }; -class GSDevice11 : public GSDeviceDX +class GSDevice11 final : public GSDevice { +public: + #pragma pack(push, 1) + + struct alignas(32) VSConstantBuffer + { + GSVector4 VertexScale; + GSVector4 VertexOffset; + GSVector4 Texture_Scale_Offset; + + VSConstantBuffer() + { + VertexScale = GSVector4::zero(); + VertexOffset = GSVector4::zero(); + Texture_Scale_Offset = GSVector4::zero(); + } + + __forceinline bool Update(const VSConstantBuffer* cb) + { + GSVector4i* a = (GSVector4i*)this; + GSVector4i* b = (GSVector4i*)cb; + + if(!((a[0] == b[0]) & (a[1] == b[1]) & (a[2] == b[2]) & (a[3] == b[3])).alltrue()) + { + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; + + return true; + } + + return false; + } + }; + + struct VSSelector + { + union + { + struct + { + uint32 bppz:2; + uint32 tme:1; + uint32 fst:1; + + uint32 _free:28; + }; + + uint32 key; + }; + + operator uint32() const {return key;} + + VSSelector() : key(0) {} + VSSelector(uint32 k) : key(k) {} + }; + + struct alignas(32) PSConstantBuffer + { + GSVector4 FogColor_AREF; + GSVector4 HalfTexel; + GSVector4 WH; + GSVector4 MinMax; + GSVector4 MinF_TA; + GSVector4i MskFix; + GSVector4i ChannelShuffle; + + GSVector4 TC_OffsetHack; + + PSConstantBuffer() + { + FogColor_AREF = GSVector4::zero(); + HalfTexel = GSVector4::zero(); + WH = GSVector4::zero(); + MinMax = GSVector4::zero(); + MinF_TA = GSVector4::zero(); + MskFix = GSVector4i::zero(); + ChannelShuffle = GSVector4i::zero(); + } + + __forceinline bool Update(const PSConstantBuffer* cb) + { + GSVector4i* a = (GSVector4i*)this; + GSVector4i* b = (GSVector4i*)cb; + + if(!((a[0] == b[0]) /*& (a[1] == b1)*/ & (a[2] == b[2]) & (a[3] == b[3]) & (a[4] == b[4]) & (a[5] == b[5]) & (a[6] == b[6])).alltrue()) // if WH matches HalfTexel does too + { + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; + a[4] = b[4]; + a[5] = b[5]; + a[6] = b[6]; + + return true; + } + + return false; + } + }; + + struct alignas(32) GSConstantBuffer + { + GSVector2 PointSize; + + GSConstantBuffer() + { + PointSize = GSVector2(0); + } + + __forceinline bool Update(const GSConstantBuffer* cb) + { + return true; + } + }; + + struct GSSelector + { + union + { + struct + { + uint32 iip:1; + uint32 prim:2; + uint32 point:1; + uint32 line:1; + + uint32 _free:27; + }; + + uint32 key; + }; + + operator uint32() {return key;} + + GSSelector() : key(0) {} + GSSelector(uint32 k) : key(k) {} + }; + + struct PSSelector + { + union + { + struct + { + // *** Word 1 + // Format + uint32 fmt:4; + uint32 dfmt:2; + uint32 depth_fmt:2; + // Alpha extension/Correction + uint32 aem:1; + uint32 fba:1; + // Fog + uint32 fog:1; + // Pixel test + uint32 atst:3; + // Color sampling + uint32 fst:1; + uint32 tfx:3; + uint32 tcc:1; + uint32 wms:2; + uint32 wmt:2; + uint32 ltf:1; + // Shuffle and fbmask effect + uint32 shuffle:1; + uint32 read_ba:1; + + // *** Word 2 + // Blend and Colclip + uint32 clr1:1; + + // Others ways to fetch the texture + uint32 channel:3; + + // Hack + uint32 aout:1; + uint32 spritehack:1; + uint32 tcoffsethack:1; + uint32 urban_chaos_hle:1; + uint32 tales_of_abyss_hle:1; + uint32 point_sampler:1; + + uint32 _free:28; + }; + + uint64 key; + }; + + operator uint64() {return key;} + + PSSelector() : key(0) {} + }; + + struct PSSamplerSelector + { + union + { + struct + { + uint32 tau:1; + uint32 tav:1; + uint32 ltf:1; + }; + + uint32 key; + }; + + operator uint32() {return key & 0x7;} + + PSSamplerSelector() : key(0) {} + }; + + struct OMDepthStencilSelector + { + union + { + struct + { + uint32 ztst:2; + uint32 zwe:1; + uint32 date:1; + uint32 fba:1; + uint32 date_one:1; + }; + + uint32 key; + }; + + operator uint32() {return key & 0x3f;} + + OMDepthStencilSelector() : key(0) {} + }; + + struct OMBlendSelector + { + union + { + struct + { + uint32 abe:1; + uint32 a:2; + uint32 b:2; + uint32 c:2; + uint32 d:2; + uint32 wr:1; + uint32 wg:1; + uint32 wb:1; + uint32 wa:1; + }; + + struct + { + uint32 _pad:1; + uint32 abcd:8; + uint32 wrgba:4; + }; + + uint32 key; + }; + + operator uint32() {return key & 0x1fff;} + + OMBlendSelector() : key(0) {} + + bool IsCLR1() const + { + return (key & 0x19f) == 0x93; // abe == 1 && a == 1 && b == 2 && d == 1 + } + }; + + struct D3D11Blend + { + int bogus; + D3D11_BLEND_OP op; + D3D11_BLEND src, dst; + }; + static const D3D11Blend m_blendMapD3D11[3*3*3*3]; + + #pragma pack(pop) + +private: + float m_hack_topleft_offset; + int m_upscale_multiplier; + int m_mipmap; + GSTexture* CreateSurface(int type, int w, int h, int format); + GSTexture* FetchSurface(int type, int w, int h, int format); void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c); void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0); @@ -53,10 +342,6 @@ class GSDevice11 : public GSDeviceDX CComPtr m_ib; CComPtr m_ib_old; - float m_hack_topleft_offset; - - int m_mipmap; - struct { ID3D11Buffer* vb; @@ -85,7 +370,6 @@ class GSDevice11 : public GSDeviceDX ID3D11DepthStencilView* dsv; } m_state; -public: // TODO CComPtr m_rs; bool FXAA_Compiled; @@ -140,8 +424,6 @@ public: // TODO CComPtr bs; } m_date; - void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm); - // Shaders... std::unordered_map m_vs; @@ -162,11 +444,24 @@ public: // TODO std::unique_ptr m_font; - bool CreateTextureFX(); +protected: + struct {D3D_FEATURE_LEVEL level; std::string model, vs, gs, ps, cs;} m_shader; + + static HMODULE s_d3d_compiler_dll; + static decltype(&D3DCompile) s_pD3DCompile; + // Older version doesn't support D3D_COMPILE_STANDARD_FILE_INCLUDE, which + // could be useful for external shaders. + static bool s_old_d3d_compiler_dll; public: GSDevice11(); - virtual ~GSDevice11(); + virtual ~GSDevice11() {} + + bool SetFeatureLevel(D3D_FEATURE_LEVEL level, bool compat_mode); + void GetFeatureLevel(D3D_FEATURE_LEVEL& level) const { level = m_shader.level; } + + static bool LoadD3DCompiler(); + static void FreeD3DCompiler(); bool Create(const std::shared_ptr &wnd); bool Reset(int w, int h); @@ -200,6 +495,8 @@ public: void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, ID3D11PixelShader* ps, ID3D11Buffer* ps_cb, bool linear = true); void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, ID3D11PixelShader* ps, ID3D11Buffer* ps_cb, ID3D11BlendState* bs, bool linear = true); + void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm); + void IASetVertexBuffer(const void* vertex, size_t stride, size_t count); bool IAMapVertexBuffer(void** vertex, size_t stride, size_t count); void IAUnmapVertexBuffer(); @@ -221,6 +518,7 @@ public: void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL); void OMSetRenderTargets(const GSVector2i& rtsize, int count, ID3D11UnorderedAccessView** uav, uint32* counters, const GSVector4i* scissor = NULL); + bool CreateTextureFX(); void SetupVS(VSSelector sel, const VSConstantBuffer* cb); void SetupGS(GSSelector sel, const GSConstantBuffer* cb); void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel); @@ -235,5 +533,27 @@ public: void CreateShader(std::vector source, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps); void CompileShader(std::vector source, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3DBlob** shader, std::string shader_model); + + template void PrepareShaderMacro(std::vector& dst, const T* src) + { + dst.clear(); + + while (src && src->Definition && src->Name) + { + dst.push_back(*src++); + } + + T m; + + m.Name = "SHADER_MODEL"; + m.Definition = m_shader.model.c_str(); + + dst.push_back(m); + + m.Name = NULL; + m.Definition = NULL; + + dst.push_back(m); + } }; diff --git a/plugins/GSdx/Renderers/DX11/GSRendererDX11.h b/plugins/GSdx/Renderers/DX11/GSRendererDX11.h index 5ec2613f69..f83aad52cf 100644 --- a/plugins/GSdx/Renderers/DX11/GSRendererDX11.h +++ b/plugins/GSdx/Renderers/DX11/GSRendererDX11.h @@ -40,17 +40,17 @@ private: inline void EmulateChannelShuffle(GSTexture** rt, const GSTextureCache::Source* tex); inline void EmulateTextureSampler(const GSTextureCache::Source* tex); - GSDeviceDX::VSSelector m_vs_sel; - GSDeviceDX::GSSelector m_gs_sel; - GSDeviceDX::PSSelector m_ps_sel; + GSDevice11::VSSelector m_vs_sel; + GSDevice11::GSSelector m_gs_sel; + GSDevice11::PSSelector m_ps_sel; - GSDeviceDX::PSSamplerSelector m_ps_ssel; - GSDeviceDX::OMBlendSelector m_om_bsel; - GSDeviceDX::OMDepthStencilSelector m_om_dssel; + GSDevice11::PSSamplerSelector m_ps_ssel; + GSDevice11::OMBlendSelector m_om_bsel; + GSDevice11::OMDepthStencilSelector m_om_dssel; - GSDeviceDX::PSConstantBuffer ps_cb; - GSDeviceDX::VSConstantBuffer vs_cb; - GSDeviceDX::GSConstantBuffer gs_cb; + GSDevice11::PSConstantBuffer ps_cb; + GSDevice11::VSConstantBuffer vs_cb; + GSDevice11::GSConstantBuffer gs_cb; public: GSRendererDX11(); diff --git a/plugins/GSdx/Renderers/DXCommon/GSDeviceDX.cpp b/plugins/GSdx/Renderers/DXCommon/GSDeviceDX.cpp deleted file mode 100644 index c38d17705a..0000000000 --- a/plugins/GSdx/Renderers/DXCommon/GSDeviceDX.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (C) 2007-2009 Gabest - * http://www.gabest.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#include "stdafx.h" -#include "GSdx.h" -#include "GSDeviceDX.h" -#include - -HMODULE GSDeviceDX::s_d3d_compiler_dll = nullptr; -decltype(&D3DCompile) GSDeviceDX::s_pD3DCompile = nullptr; -bool GSDeviceDX::s_old_d3d_compiler_dll; - -GSDeviceDX::GSDeviceDX() -{ - m_upscale_multiplier = theApp.GetConfigI("upscale_multiplier"); -} - -GSDeviceDX::~GSDeviceDX() -{ -} - -bool GSDeviceDX::LoadD3DCompiler() -{ - // Windows 8.1 and later come with the latest d3dcompiler_47.dll, but - // Windows 7 devs might also have the dll available for use (which will - // have to be placed in the application directory) - s_d3d_compiler_dll = LoadLibraryEx(D3DCOMPILER_DLL, nullptr, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); - - // Windows Vista and 7 can use the older version. If the previous LoadLibrary - // call fails on Windows 8.1 and later, then the user's system is likely - // broken. - if (s_d3d_compiler_dll) - { - s_old_d3d_compiler_dll = false; - } - else - { - if (!IsWindows8Point1OrGreater()) - // Use LoadLibrary instead of LoadLibraryEx, some Windows 7 systems - // have issues with it. - s_d3d_compiler_dll = LoadLibrary("D3DCompiler_43.dll"); - - if (s_d3d_compiler_dll == nullptr) - return false; - - s_old_d3d_compiler_dll = true; - } - - s_pD3DCompile = reinterpret_cast(GetProcAddress(s_d3d_compiler_dll, "D3DCompile")); - if (s_pD3DCompile) - return true; - - FreeLibrary(s_d3d_compiler_dll); - s_d3d_compiler_dll = nullptr; - return false; -} - -void GSDeviceDX::FreeD3DCompiler() -{ - s_pD3DCompile = nullptr; - if (s_d3d_compiler_dll) - FreeLibrary(s_d3d_compiler_dll); - s_d3d_compiler_dll = nullptr; -} - -GSTexture* GSDeviceDX::FetchSurface(int type, int w, int h, int format) -{ - return __super::FetchSurface(type, w, h, format); -} - -bool GSDeviceDX::SetFeatureLevel(D3D_FEATURE_LEVEL level, bool compat_mode) -{ - m_shader.level = level; - - switch(level) - { - case D3D_FEATURE_LEVEL_10_0: - m_shader.model = "0x400"; - m_shader.vs = "vs_4_0"; - m_shader.gs = "gs_4_0"; - m_shader.ps = "ps_4_0"; - m_shader.cs = "cs_4_0"; - break; - case D3D_FEATURE_LEVEL_10_1: - m_shader.model = "0x401"; - m_shader.vs = "vs_4_1"; - m_shader.gs = "gs_4_1"; - m_shader.ps = "ps_4_1"; - m_shader.cs = "cs_4_1"; - break; - case D3D_FEATURE_LEVEL_11_0: - m_shader.model = "0x500"; - m_shader.vs = "vs_5_0"; - m_shader.gs = "gs_5_0"; - m_shader.ps = "ps_5_0"; - m_shader.cs = "cs_5_0"; - break; - default: - ASSERT(0); - return false; - } - - return true; -} - -// (A - B) * C + D -// A: Cs/Cd/0 -// B: Cs/Cd/0 -// C: As/Ad/FIX -// D: Cs/Cd/0 - -// bogus: 0100, 0110, 0120, 0200, 0210, 0220, 1001, 1011, 1021 -// tricky: 1201, 1211, 1221 - -// Source.rgb = float3(1, 1, 1); -// 1201 Cd*(1 + As) => Source * Dest color + Dest * Source alpha -// 1211 Cd*(1 + Ad) => Source * Dest color + Dest * Dest alpha -// 1221 Cd*(1 + F) => Source * Dest color + Dest * Factor - -// Special blending method table: -// # (tricky) => 1 * Cd + Cd * F => Use (Cd, F) as factor of color (1, Cd) -// * (bogus) => C * (1 + F ) + ... => factor is always bigger than 1 (except above case) - -const GSDeviceDX::D3D11Blend GSDeviceDX::m_blendMapD3D11[3*3*3*3] = -{ - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 0000: (Cs - Cs)*As + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 0001: (Cs - Cs)*As + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 0002: (Cs - Cs)*As + 0 ==> 0 - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 0010: (Cs - Cs)*Ad + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 0011: (Cs - Cs)*Ad + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 0012: (Cs - Cs)*Ad + 0 ==> 0 - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 0020: (Cs - Cs)*F + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 0021: (Cs - Cs)*F + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 0022: (Cs - Cs)*F + 0 ==> 0 - {1, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_SRC1_ALPHA} , //*0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_INV_SRC1_ALPHA} , // 0101: (Cs - Cd)*As + Cd ==> Cs*As + Cd*(1 - As) - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_SRC1_ALPHA} , // 0102: (Cs - Cd)*As + 0 ==> Cs*As - Cd*As - {1, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA} , //*0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_INV_DEST_ALPHA} , // 0111: (Cs - Cd)*Ad + Cd ==> Cs*Ad + Cd*(1 - Ad) - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_DEST_ALPHA} , // 0112: (Cs - Cd)*Ad + 0 ==> Cs*Ad - Cd*Ad - {1, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR} , //*0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_INV_BLEND_FACTOR} , // 0121: (Cs - Cd)*F + Cd ==> Cs*F + Cd*(1 - F) - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_BLEND_FACTOR} , // 0122: (Cs - Cd)*F + 0 ==> Cs*F - Cd*F - {1, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , //*0200: (Cs - 0)*As + Cs ==> Cs*(As + 1) - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ONE} , // 0201: (Cs - 0)*As + Cd ==> Cs*As + Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ZERO} , // 0202: (Cs - 0)*As + 0 ==> Cs*As - {1, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1) - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ONE} , // 0211: (Cs - 0)*Ad + Cd ==> Cs*Ad + Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ZERO} , // 0212: (Cs - 0)*Ad + 0 ==> Cs*Ad - {1, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1) - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ONE} , // 0221: (Cs - 0)*F + Cd ==> Cs*F + Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ZERO} , // 0222: (Cs - 0)*F + 0 ==> Cs*F - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_SRC1_ALPHA , D3D11_BLEND_SRC1_ALPHA} , // 1000: (Cd - Cs)*As + Cs ==> Cd*As + Cs*(1 - As) - {1, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ONE} , //*1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_SRC1_ALPHA} , // 1002: (Cd - Cs)*As + 0 ==> Cd*As - Cs*As - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_DEST_ALPHA , D3D11_BLEND_DEST_ALPHA} , // 1010: (Cd - Cs)*Ad + Cs ==> Cd*Ad + Cs*(1 - Ad) - {1, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ONE} , //*1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_DEST_ALPHA} , // 1012: (Cd - Cs)*Ad + 0 ==> Cd*Ad - Cs*Ad - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_BLEND_FACTOR , D3D11_BLEND_BLEND_FACTOR} , // 1020: (Cd - Cs)*F + Cs ==> Cd*F + Cs*(1 - F) - {1, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ONE} , //*1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_BLEND_FACTOR} , // 1022: (Cd - Cs)*F + 0 ==> Cd*F - Cs*F - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 1100: (Cd - Cd)*As + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 1101: (Cd - Cd)*As + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 1102: (Cd - Cd)*As + 0 ==> 0 - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 1110: (Cd - Cd)*Ad + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 1111: (Cd - Cd)*Ad + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 1112: (Cd - Cd)*Ad + 0 ==> 0 - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 1120: (Cd - Cd)*F + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 1121: (Cd - Cd)*F + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 1122: (Cd - Cd)*F + 0 ==> 0 - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_SRC1_ALPHA} , // 1200: (Cd - 0)*As + Cs ==> Cs + Cd*As - {2, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_COLOR , D3D11_BLEND_SRC1_ALPHA} , //#1201: (Cd - 0)*As + Cd ==> Cd*(1 + As) // ffxii main menu background glow effect - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_SRC1_ALPHA} , // 1202: (Cd - 0)*As + 0 ==> Cd*As - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA} , // 1210: (Cd - 0)*Ad + Cs ==> Cs + Cd*Ad - {2, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_COLOR , D3D11_BLEND_DEST_ALPHA} , //#1211: (Cd - 0)*Ad + Cd ==> Cd*(1 + Ad) - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_DEST_ALPHA} , // 1212: (Cd - 0)*Ad + 0 ==> Cd*Ad - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR} , // 1220: (Cd - 0)*F + Cs ==> Cs + Cd*F - {2, D3D11_BLEND_OP_ADD , D3D11_BLEND_DEST_COLOR , D3D11_BLEND_BLEND_FACTOR} , //#1221: (Cd - 0)*F + Cd ==> Cd*(1 + F) - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_BLEND_FACTOR} , // 1222: (Cd - 0)*F + 0 ==> Cd*F - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_SRC1_ALPHA , D3D11_BLEND_ZERO} , // 2000: (0 - Cs)*As + Cs ==> Cs*(1 - As) - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ONE} , // 2001: (0 - Cs)*As + Cd ==> Cd - Cs*As - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_SRC1_ALPHA , D3D11_BLEND_ZERO} , // 2002: (0 - Cs)*As + 0 ==> 0 - Cs*As - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_DEST_ALPHA , D3D11_BLEND_ZERO} , // 2010: (0 - Cs)*Ad + Cs ==> Cs*(1 - Ad) - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ONE} , // 2011: (0 - Cs)*Ad + Cd ==> Cd - Cs*Ad - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_DEST_ALPHA , D3D11_BLEND_ZERO} , // 2012: (0 - Cs)*Ad + 0 ==> 0 - Cs*Ad - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_INV_BLEND_FACTOR , D3D11_BLEND_ZERO} , // 2020: (0 - Cs)*F + Cs ==> Cs*(1 - F) - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ONE} , // 2021: (0 - Cs)*F + Cd ==> Cd - Cs*F - {0, D3D11_BLEND_OP_REV_SUBTRACT , D3D11_BLEND_BLEND_FACTOR , D3D11_BLEND_ZERO} , // 2022: (0 - Cs)*F + 0 ==> 0 - Cs*F - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_SRC1_ALPHA} , // 2100: (0 - Cd)*As + Cs ==> Cs - Cd*As - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_INV_SRC1_ALPHA} , // 2101: (0 - Cd)*As + Cd ==> Cd*(1 - As) - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ZERO , D3D11_BLEND_SRC1_ALPHA} , // 2102: (0 - Cd)*As + 0 ==> 0 - Cd*As - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA} , // 2110: (0 - Cd)*Ad + Cs ==> Cs - Cd*Ad - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_INV_DEST_ALPHA} , // 2111: (0 - Cd)*Ad + Cd ==> Cd*(1 - Ad) - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_DEST_ALPHA} , // 2112: (0 - Cd)*Ad + 0 ==> 0 - Cd*Ad - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR} , // 2120: (0 - Cd)*F + Cs ==> Cs - Cd*F - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_INV_BLEND_FACTOR} , // 2121: (0 - Cd)*F + Cd ==> Cd*(1 - F) - {0, D3D11_BLEND_OP_SUBTRACT , D3D11_BLEND_ONE , D3D11_BLEND_BLEND_FACTOR} , // 2122: (0 - Cd)*F + 0 ==> 0 - Cd*F - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 2200: (0 - 0)*As + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 2201: (0 - 0)*As + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 2202: (0 - 0)*As + 0 ==> 0 - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 2210: (0 - 0)*Ad + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 2211: (0 - 0)*Ad + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 2212: (0 - 0)*Ad + 0 ==> 0 - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ONE , D3D11_BLEND_ZERO} , // 2220: (0 - 0)*F + Cs ==> Cs - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ONE} , // 2221: (0 - 0)*F + Cd ==> Cd - {0, D3D11_BLEND_OP_ADD , D3D11_BLEND_ZERO , D3D11_BLEND_ZERO} , // 2222: (0 - 0)*F + 0 ==> 0 -}; diff --git a/plugins/GSdx/Renderers/DXCommon/GSDeviceDX.h b/plugins/GSdx/Renderers/DXCommon/GSDeviceDX.h deleted file mode 100644 index 2b0dd45fde..0000000000 --- a/plugins/GSdx/Renderers/DXCommon/GSDeviceDX.h +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (C) 2007-2009 Gabest - * http://www.gabest.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#pragma once - -#include "GSVector.h" -#include "Renderers/Common/GSDevice.h" -#include "GSAlignedClass.h" - -class GSDeviceDX : public GSDevice -{ -protected: - int m_upscale_multiplier; - -public: - #pragma pack(push, 1) - - struct alignas(32) VSConstantBuffer - { - GSVector4 VertexScale; - GSVector4 VertexOffset; - GSVector4 Texture_Scale_Offset; - - struct VSConstantBuffer() - { - VertexScale = GSVector4::zero(); - VertexOffset = GSVector4::zero(); - Texture_Scale_Offset = GSVector4::zero(); - } - - __forceinline bool Update(const VSConstantBuffer* cb) - { - GSVector4i* a = (GSVector4i*)this; - GSVector4i* b = (GSVector4i*)cb; - - if(!((a[0] == b[0]) & (a[1] == b[1]) & (a[2] == b[2]) & (a[3] == b[3])).alltrue()) - { - a[0] = b[0]; - a[1] = b[1]; - a[2] = b[2]; - a[3] = b[3]; - - return true; - } - - return false; - } - }; - - struct VSSelector - { - union - { - struct - { - uint32 bppz:2; - uint32 tme:1; - uint32 fst:1; - - uint32 _free:28; - }; - - uint32 key; - }; - - operator uint32() const {return key;} - - VSSelector() : key(0) {} - VSSelector(uint32 k) : key(k) {} - }; - - struct alignas(32) PSConstantBuffer - { - GSVector4 FogColor_AREF; - GSVector4 HalfTexel; - GSVector4 WH; - GSVector4 MinMax; - GSVector4 MinF_TA; - GSVector4i MskFix; - GSVector4i ChannelShuffle; - - GSVector4 TC_OffsetHack; - - struct PSConstantBuffer() - { - FogColor_AREF = GSVector4::zero(); - HalfTexel = GSVector4::zero(); - WH = GSVector4::zero(); - MinMax = GSVector4::zero(); - MinF_TA = GSVector4::zero(); - MskFix = GSVector4i::zero(); - ChannelShuffle = GSVector4i::zero(); - } - - __forceinline bool Update(const PSConstantBuffer* cb) - { - GSVector4i* a = (GSVector4i*)this; - GSVector4i* b = (GSVector4i*)cb; - - if(!((a[0] == b[0]) /*& (a[1] == b1)*/ & (a[2] == b[2]) & (a[3] == b[3]) & (a[4] == b[4]) & (a[5] == b[5]) & (a[6] == b[6])).alltrue()) // if WH matches HalfTexel does too - { - a[0] = b[0]; - a[1] = b[1]; - a[2] = b[2]; - a[3] = b[3]; - a[4] = b[4]; - a[5] = b[5]; - a[6] = b[6]; - - return true; - } - - return false; - } - }; - - struct alignas(32) GSConstantBuffer - { - GSVector2 PointSize; - - struct GSConstantBuffer() - { - PointSize = GSVector2(0); - } - - __forceinline bool Update(const GSConstantBuffer* cb) - { - return true; - } - }; - - struct GSSelector - { - union - { - struct - { - uint32 iip:1; - uint32 prim:2; - uint32 point:1; - uint32 line:1; - - uint32 _free:27; - }; - - uint32 key; - }; - - operator uint32() {return key;} - - GSSelector() : key(0) {} - GSSelector(uint32 k) : key(k) {} - }; - - struct PSSelector - { - union - { - struct - { - // *** Word 1 - // Format - uint32 fmt:4; - uint32 dfmt:2; - uint32 depth_fmt:2; - // Alpha extension/Correction - uint32 aem:1; - uint32 fba:1; - // Fog - uint32 fog:1; - // Pixel test - uint32 atst:3; - // Color sampling - uint32 fst:1; - uint32 tfx:3; - uint32 tcc:1; - uint32 wms:2; - uint32 wmt:2; - uint32 ltf:1; - // Shuffle and fbmask effect - uint32 shuffle:1; - uint32 read_ba:1; - - // *** Word 2 - // Blend and Colclip - uint32 clr1:1; - - // Others ways to fetch the texture - uint32 channel:3; - - // Hack - uint32 aout:1; - uint32 spritehack:1; - uint32 tcoffsethack:1; - uint32 urban_chaos_hle:1; - uint32 tales_of_abyss_hle:1; - uint32 point_sampler:1; - - uint32 _free:28; - }; - - uint64 key; - }; - - operator uint64() {return key;} - - PSSelector() : key(0) {} - }; - - struct PSSamplerSelector - { - union - { - struct - { - uint32 tau:1; - uint32 tav:1; - uint32 ltf:1; - }; - - uint32 key; - }; - - operator uint32() {return key & 0x7;} - - PSSamplerSelector() : key(0) {} - }; - - struct OMDepthStencilSelector - { - union - { - struct - { - uint32 ztst:2; - uint32 zwe:1; - uint32 date:1; - uint32 fba:1; - uint32 date_one:1; - }; - - uint32 key; - }; - - operator uint32() {return key & 0x3f;} - - OMDepthStencilSelector() : key(0) {} - }; - - struct OMBlendSelector - { - union - { - struct - { - uint32 abe:1; - uint32 a:2; - uint32 b:2; - uint32 c:2; - uint32 d:2; - uint32 wr:1; - uint32 wg:1; - uint32 wb:1; - uint32 wa:1; - }; - - struct - { - uint32 _pad:1; - uint32 abcd:8; - uint32 wrgba:4; - }; - - uint32 key; - }; - - operator uint32() {return key & 0x1fff;} - - OMBlendSelector() : key(0) {} - - bool IsCLR1() const - { - return (key & 0x19f) == 0x93; // abe == 1 && a == 1 && b == 2 && d == 1 - } - }; - - struct D3D11Blend - { - int bogus; - D3D11_BLEND_OP op; - D3D11_BLEND src, dst; - }; - static const D3D11Blend m_blendMapD3D11[3*3*3*3]; - - #pragma pack(pop) - -protected: - struct {D3D_FEATURE_LEVEL level; std::string model, vs, gs, ps, cs;} m_shader; - - static HMODULE s_d3d_compiler_dll; - static decltype(&D3DCompile) s_pD3DCompile; - // Older version doesn't support D3D_COMPILE_STANDARD_FILE_INCLUDE, which - // could be useful for external shaders. - static bool s_old_d3d_compiler_dll; - - GSTexture* FetchSurface(int type, int w, int h, int format); - -public: - GSDeviceDX(); - virtual ~GSDeviceDX(); - - bool SetFeatureLevel(D3D_FEATURE_LEVEL level, bool compat_mode); - void GetFeatureLevel(D3D_FEATURE_LEVEL& level) const {level = m_shader.level;} - - virtual void SetupVS(VSSelector sel, const VSConstantBuffer* cb) = 0; - virtual void SetupGS(GSSelector sel, const GSConstantBuffer* cb) = 0; - virtual void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel) = 0; - virtual void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix) = 0; - - virtual void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm) = 0; - - static bool LoadD3DCompiler(); - static void FreeD3DCompiler(); - - template void PrepareShaderMacro(std::vector& dst, const T* src) - { - dst.clear(); - - while(src && src->Definition && src->Name) - { - dst.push_back(*src++); - } - - T m; - - m.Name = "SHADER_MODEL"; - m.Definition = m_shader.model.c_str(); - - dst.push_back(m); - - m.Name = NULL; - m.Definition = NULL; - - dst.push_back(m); - } -}; -