Skip to content

Commit d53d1dd

Browse files
authored
Add DirectX Agility SDK Upgrade (#282)
1 parent 66bbb93 commit d53d1dd

File tree

6 files changed

+219
-0
lines changed

6 files changed

+219
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ FodyWeavers.xsd
418418
*.dylib
419419
*.dll
420420

421+
!external/directx_agility_sdk/lib/D3D12Core.dll
422+
421423
# Fortran module files
422424
*.mod
423425
*.smod

OptiScaler/OptiScaler.vcxproj

+3
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ copy $(SolutionDir)external\FidelityFX-SDK\docs\license.md $(SolutionDir)x64\Rel
255255
copy $(SolutionDir)external\FidelityFX-SDK\PrebuiltSignedDLL\*.dll $(SolutionDir)x64\Release\a\ /Y
256256
copy $(SolutionDir)OptiScaler.ini $(SolutionDir)x64\Release\a\ /Y
257257
copy "$(SolutionDir)OptiScaler Setup.bat" $(SolutionDir)x64\Release\a\ /Y
258+
md $(SolutionDir)x64\Release\a\D3D12_Optiscaler\
259+
copy "$(SolutionDir)external\directx_agility_sdk\lib\*.dll" $(SolutionDir)x64\Release\a\D3D12_Optiscaler\ /Y
260+
copy "$(SolutionDir)external\directx_agility_sdk\LICENSE.txt" $(SolutionDir)x64\Release\a\D3D12_Optiscaler\LICENSE.txt /Y
258261
copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y</Command>
259262
</PostBuildEvent>
260263
<PreBuildEvent>

OptiScaler/dllmain.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static PFN_LoadLibraryW o_LoadLibraryW = nullptr;
6363
static PFN_LoadLibraryExA o_LoadLibraryExA = nullptr;
6464
static PFN_LoadLibraryExW o_LoadLibraryExW = nullptr;
6565
static PFN_GetProcAddress o_GetProcAddress = nullptr;
66+
static PFN_GetProcAddress o_GetProcAddressKernelBase = nullptr;
6667
static PFN_GetModuleHandleA o_GetModuleHandleA = nullptr;
6768
static PFN_GetModuleHandleW o_GetModuleHandleW = nullptr;
6869
static PFN_GetModuleHandleExA o_GetModuleHandleExA = nullptr;
@@ -843,6 +844,10 @@ HRESULT STDMETHODCALLTYPE hkAmdExtD3DCreateInterface(IUnknown* pOuter, REFIID ri
843844
return E_NOINTERFACE;
844845
}
845846

847+
static UINT customD3D12SDKVersion = 615;
848+
849+
static const char8_t* customD3D12SDKPath = u8".\\D3D12_Optiscaler\\"; //Hardcoded for now
850+
846851
static FARPROC hkGetProcAddress(HMODULE hModule, LPCSTR lpProcName)
847852
{
848853
if (hModule == dllModule && lpProcName != nullptr)
@@ -858,6 +863,24 @@ static FARPROC hkGetProcAddress(HMODULE hModule, LPCSTR lpProcName)
858863
return (FARPROC)hkAmdExtD3DCreateInterface;
859864
}
860865

866+
// For Agility SDK Upgrade
867+
HMODULE mod_mainExe;
868+
GetModuleHandleEx(2u, 0i64, &mod_mainExe);
869+
if (hModule == mod_mainExe && lpProcName != nullptr)
870+
{
871+
if (strcmp(lpProcName, "D3D12SDKVersion") == 0)
872+
{
873+
LOG_INFO("D3D12SDKVersion call, returning this version!");
874+
return (FARPROC)&customD3D12SDKVersion;
875+
}
876+
877+
if (strcmp(lpProcName, "D3D12SDKPath") == 0)
878+
{
879+
LOG_INFO("D3D12SDKPath call, returning this path!");
880+
return (FARPROC)&customD3D12SDKPath;
881+
}
882+
}
883+
861884
if (State::Instance().isRunningOnLinux && lpProcName != nullptr && hModule == GetModuleHandle(L"gdi32.dll") && lstrcmpA(lpProcName, "D3DKMTEnumAdapters2") == 0)
862885
return (FARPROC)&customD3DKMTEnumAdapters2;
863886

@@ -1764,6 +1787,12 @@ static void DetachHooks()
17641787
o_GetProcAddress = nullptr;
17651788
}
17661789

1790+
if (o_GetProcAddressKernelBase)
1791+
{
1792+
DetourDetach(&(PVOID&)o_GetProcAddressKernelBase, hkGetProcAddress);
1793+
o_GetProcAddressKernelBase = nullptr;
1794+
}
1795+
17671796
if (o_vkGetPhysicalDeviceProperties)
17681797
{
17691798
DetourDetach(&(PVOID&)o_vkGetPhysicalDeviceProperties, hkvkGetPhysicalDeviceProperties);
@@ -1854,6 +1883,7 @@ static void AttachHooks()
18541883
o_GetModuleHandleExW = reinterpret_cast<PFN_GetModuleHandleExW>(DetourFindFunction("kernel32.dll", "GetModuleHandleExW"));
18551884
#endif
18561885
o_GetProcAddress = reinterpret_cast<PFN_GetProcAddress>(DetourFindFunction("kernel32.dll", "GetProcAddress"));
1886+
o_GetProcAddressKernelBase = reinterpret_cast<PFN_GetProcAddress>(DetourFindFunction("kernelbase.dll", "GetProcAddress"));
18571887

18581888
if (o_LoadLibraryA != nullptr || o_LoadLibraryW != nullptr || o_LoadLibraryExA != nullptr || o_LoadLibraryExW != nullptr)
18591889
{
@@ -1896,6 +1926,9 @@ static void AttachHooks()
18961926
if (o_GetProcAddress)
18971927
DetourAttach(&(PVOID&)o_GetProcAddress, hkGetProcAddress);
18981928

1929+
if (o_GetProcAddressKernelBase)
1930+
DetourAttach(&(PVOID&)o_GetProcAddressKernelBase, hkGetProcAddress);
1931+
18991932
DetourTransactionCommit();
19001933
}
19011934
}

OptiScaler/hooks/HooksDx.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -3864,6 +3864,29 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
38643864
{
38653865
LOG_FUNC();
38663866

3867+
if (pAdapter == nullptr) {
3868+
3869+
IDXGIFactory* pFactory;
3870+
if (CreateDXGIFactory(IID_PPV_ARGS(&pFactory)) != S_OK)
3871+
return E_FAIL;
3872+
3873+
UINT i = 0;
3874+
IDXGIAdapter* adapter;
3875+
std::vector <IDXGIAdapter*> vAdapters;
3876+
while (pFactory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND)
3877+
{
3878+
vAdapters.push_back(adapter);
3879+
++i;
3880+
}
3881+
3882+
pFactory->Release();
3883+
3884+
if (vAdapters.size() > 0)
3885+
pAdapter = vAdapters[0];
3886+
else
3887+
return E_FAIL;
3888+
}
3889+
38673890
#ifdef ENABLE_DEBUG_LAYER_DX12
38683891
LOG_WARN("Debug layers active!");
38693892
if (debugController == nullptr && D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)) == S_OK)
+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
MICROSOFT SOFTWARE LICENSE TERMS
2+
3+
MICROSOFT DIRECTX
4+
5+
These license terms are an agreement between you and Microsoft
6+
Corporation (or one of its affiliates). They apply to the software named
7+
above and any Microsoft services or software updates (except to the
8+
extent such services or updates are accompanied by new or additional
9+
terms, in which case those different terms apply prospectively and do
10+
not alter your or Microsoft’s rights relating to pre-updated software or
11+
services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU HAVE THE RIGHTS
12+
BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS.
13+
14+
INSTALLATION AND USE RIGHTS.
15+
16+
General. Subject to the terms of this agreement, you may install and use any number of copies of the software, and solely for use on Windows.
17+
18+
Included Microsoft Applications. The software may include other Microsoft applications. These license terms apply to those included applications, if any, unless other license terms are provided with the other Microsoft applications.
19+
20+
Microsoft Platforms. The software may include components from Microsoft Windows. These components are governed by separate agreements and their own product support policies, as described in the license terms found in the installation directory for that component or in the “Licenses” folder accompanying the software.
21+
22+
Third Party Components. The software may include third party components with separate legal notices or governed by other agreements, as may be described in the ThirdPartyNotices file(s) accompanying the software.
23+
24+
DATA.
25+
26+
Data Collection. The software may collect information about you and your use of the software, and send that to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may opt-out of many of these scenarios, but not all, as described in the product documentation.  There are also some features in the software that may enable you to collect data from users of your applications. If you use these features to enable data collection in your applications, you must comply with applicable law, including providing appropriate notices to users of your applications. You can learn more about data collection and use in the help documentation and the privacy statement at https://aka.ms/privacy. Your use of the software operates as your consent to these practices.
27+
28+
Processing of Personal Data. To the extent Microsoft is a processor or subprocessor of personal data in connection with the software, Microsoft makes the commitments in the European Union General Data Protection Regulation Terms of the Online Services Terms to all customers effective May 25, 2018, at https://docs.microsoft.com/en-us/legal/gdpr.
29+
30+
DISTRIBUTABLE CODE. The software may contain code you are permitted to distribute (i.e. make available for third parties) in applications you develop, as described in this Section.
31+
32+
Distribution Rights. The code and test files described below are distributable if included with the software.
33+
34+
Distributables. You may copy and distribute the object code form of the software listed in the distributables file list in the software; and
35+
36+
Third Party Distribution. You may permit distributors of your applications to copy and distribute any of this distributable code you elect to distribute with your applications.
37+
38+
Distribution Requirements. For any code you distribute, you must:
39+
40+
add significant primary functionality to it in your applications;
41+
42+
i. require distributors and external end users to agree to terms that protect it and Microsoft at least as much as this agreement; and
43+
44+
ii. indemnify, defend, and hold harmless Microsoft from any claims, including attorneys’ fees, related to the distribution or use of your applications, except to the extent that any claim is based solely on the unmodified distributable code.
45+
46+
Distribution Restrictions. You may not:
47+
48+
use Microsoft’s trademarks or trade dress in your application in any way that suggests your application comes from or is endorsed by Microsoft; or modify or distribute the source code of any distributable code so that any part of it becomes subject to any license that requires that the distributable code, any other part of the software, or any of Microsoft’s other intellectual property be disclosed or distributed in source code form, or that others have the right to modify it.
49+
50+
SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you will not (and have no right to):
51+
52+
work around any technical limitations in the software that only allow you to use it in certain ways;
53+
54+
reverse engineer, decompile or disassemble the software, or otherwise attempt to derive the source code for the software, except and to the extent required by third party licensing terms governing use of certain open source components that may be included in the software;
55+
56+
remove, minimize, block, or modify any notices of Microsoft or its suppliers in the software;
57+
58+
use the software in any way that is against the law or to create or propagate malware; or
59+
60+
share, publish, distribute, or lease the software (except for any distributable code, subject to the terms above), provide the software as a stand-alone offering for others to use, or transfer the software or this agreement to any third party.
61+
62+
EXPORT RESTRICTIONS. You must comply with all domestic and international export laws and regulations that apply to the software, which include restrictions on destinations, end users, and end use. For further information on export restrictions, visit https://aka.ms/exporting.
63+
64+
SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any support services for the software. Any support provided is “as is”, “with all faults”, and without warranty of any kind.
65+
66+
UPDATES. The software may periodically check for updates, and download and install them for you. You may obtain updates only from Microsoft or authorized sources. Microsoft may need to update your system to provide you with updates. You agree to receive these automatic updates without any additional notice. Updates may not include or support all existing software features, services, or peripheral devices.
67+
68+
ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for supplements, updates, or third-party applications, is the entire agreement for the software.
69+
70+
APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in the United States or Canada, the laws of the state or province where you live (or, if a business, where your principal place of business is located) govern the interpretation of this agreement, claims for its breach, and all other claims (including consumer protection, unfair competition, and tort claims), regardless of conflict of laws principles. If you acquired the software in any other country, its laws apply. If U.S. federal jurisdiction exists, you and Microsoft consent to exclusive jurisdiction and venue in the federal court in King County, Washington for all disputes heard in court. If not, you and Microsoft consent to exclusive jurisdiction and venue in the Superior Court of King County, Washington for all disputes heard in court.
71+
72+
CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal rights. You may have other rights, including consumer rights, under the laws of your state or country. Separate and apart from your relationship with Microsoft, you may also have rights with respect to the party from which you acquired the software. This agreement does not change those other rights if the laws of your state or country do not permit it to do so. For example, if you acquired the software in one of the below regions, or mandatory country law applies, then the following provisions apply to you:
73+
74+
a. Australia. You have statutory guarantees under the Australian
75+
Consumer Law and nothing in this agreement is intended to affect
76+
those rights.
77+
78+
b. Canada. If you acquired this software in Canada, you may stop
79+
receiving updates by turning off the automatic update feature,
80+
disconnecting your device from the Internet (if and when you
81+
re-connect to the Internet, however, the software will resume
82+
checking for and installing updates), or uninstalling the software.
83+
The product documentation, if any, may also specify how to turn off
84+
updates for your specific device or software.
85+
86+
c. Germany and Austria.
87+
88+
i. Warranty. The properly licensed software will perform substantially
89+
as described in any Microsoft materials that accompany the software.
90+
However, Microsoft gives no contractual guarantee in relation to the
91+
licensed software.
92+
93+
ii. Limitation of Liability. In case of intentional conduct, gross
94+
negligence, claims based on the Product Liability Act, as well as, in
95+
case of death or personal or physical injury, Microsoft is liable
96+
according to the statutory law.
97+
98+
Subject to the foregoing clause ii., Microsoft will only be liable for slight negligence if Microsoft is in breach of such material contractual obligations, the fulfillment of which facilitate the due performance of this agreement, the breach of which would endanger the purpose of this agreement and the compliance with which a party may constantly trust in (so-called "cardinal obligations"). In other cases of slight negligence, Microsoft will not be liable for slight negligence.
99+
100+
DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
101+
102+
LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT, OR INCIDENTAL DAMAGES.
103+
104+
This limitation applies to (a) anything related to the software,
105+
services, content (including code) on third party Internet sites, or
106+
third party applications; and (b) claims for breach of contract,
107+
warranty, guarantee, or condition; strict liability, negligence, or
108+
other tort; or any other claim; in each case to the extent permitted by
109+
applicable law.
110+
111+
It also applies even if Microsoft knew or should have known about the
112+
possibility of the damages. The above limitation or exclusion may not
113+
apply to you because your state, province, or country may not allow the
114+
exclusion or limitation of incidental, consequential, or other damages.
115+
116+
Please note: As this software is distributed in Canada, some of the
117+
clauses in this agreement are provided below in French.
118+
119+
Remarque: Ce logiciel étant distribué au Canada, certaines des clauses
120+
dans ce contrat sont fournies ci-dessous en français.
121+
122+
EXONÉRATION DE GARANTIE. Le logiciel visé par une licence est offert «
123+
tel quel ». Toute utilisation de ce logiciel est à votre seule risque et
124+
péril. Microsoft n’accorde aucune autre garantie expresse. Vous pouvez
125+
bénéficier de droits additionnels en vertu du droit local sur la
126+
protection des consommateurs, que ce contrat ne peut modifier. La ou
127+
elles sont permises par le droit locale, les garanties implicites de
128+
qualité marchande, d’adéquation à un usage particulier et d’absence de
129+
contrefaçon sont exclues.
130+
131+
LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES
132+
DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une
133+
indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $
134+
US. Vous ne pouvez prétendre à aucune indemnisation pour les autres
135+
dommages, y compris les dommages spéciaux, indirects ou accessoires et
136+
pertes de bénéfices.
137+
138+
Cette limitation concerne:
139+
140+
• tout ce qui est relié au logiciel, aux services ou au contenu (y
141+
compris le code) figurant sur des sites Internet tiers ou dans des
142+
programmes tiers; et
143+
144+
• les réclamations au titre de violation de contrat ou de garantie, ou
145+
au titre de responsabilité stricte, de négligence ou d’une autre faute
146+
dans la limite autorisée par la loi en vigueur.
147+
148+
Elle s’applique également, même si Microsoft connaissait ou devrait
149+
connaître l’éventualité d’un tel dommage. Si votre pays n’autorise pas
150+
l’exclusion ou la limitation de responsabilité pour les dommages
151+
indirects, accessoires ou de quelque nature que ce soit, il se peut que
152+
la limitation ou l’exclusion ci-dessus ne s’appliquera pas à votre
153+
égard.
154+
155+
EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques.
156+
Vous pourriez avoir d’autres droits prévus par les lois de votre pays.
157+
Le présent contrat ne modifie pas les droits que vous confèrent les lois
158+
de votre pays si celles-ci ne le permettent pas.
3.2 MB
Binary file not shown.

0 commit comments

Comments
 (0)