Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 89ddc8c

Browse files
committed
NGX relies on the chip implementation identifier as well as architecture
1 parent bc4ae88 commit 89ddc8c

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

source/wrapper_generic/nvapi.cpp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
typedef LONG NTSTATUS;
2+
#include <d3dkmthk.h>
3+
14
enum class NV_STATUS : uint32_t
25
{
36
Success = 0,
@@ -14,7 +17,8 @@ struct NV_ARCH_INFO
1417
{
1518
uint32_t Version;
1619
uint32_t Architecture;
17-
uint32_t Unknown[2];
20+
uint32_t Implementation;
21+
uint32_t Unknown[1];
1822
};
1923

2024
struct NV_SCG_PRIORITY_INFO
@@ -29,21 +33,35 @@ struct NV_SCG_PRIORITY_INFO
2933
uint32_t Unknown8; // 14
3034
};
3135

36+
struct NV_D3DKMT_PRIVATE_DRIVER_DATA // nvwg2umx.dll (546.33)
37+
{
38+
uint32_t Header; // 0 NVDA
39+
char Padding[0xE4]; // 4
40+
uint32_t Architecture; // E8
41+
};
42+
3243
using PfnNvAPI_QueryInterface = void *(__stdcall *)(NV_INTERFACE InterfaceId);
3344
using PfnNvAPI_GPU_GetArchInfo = NV_STATUS(__stdcall *)(void *GPUHandle, NV_ARCH_INFO *ArchInfo);
3445

3546
PfnNvAPI_QueryInterface OriginalNvAPI_QueryInterface = nullptr;
3647
PfnNvAPI_GPU_GetArchInfo OriginalNvAPI_GPU_GetArchInfo = nullptr;
48+
decltype(&D3DKMTQueryAdapterInfo) OriginalD3DKMTQueryAdapterInfo = nullptr;
3749

3850
NV_STATUS __stdcall HookedNvAPI_GPU_GetArchInfo(void *GPUHandle, NV_ARCH_INFO *ArchInfo)
3951
{
4052
if (OriginalNvAPI_GPU_GetArchInfo)
4153
{
4254
const auto status = OriginalNvAPI_GPU_GetArchInfo(GPUHandle, ArchInfo);
4355

44-
// Spoof Ada GPU arch
45-
if (status == NV_STATUS::Success && ArchInfo && ArchInfo->Architecture < 0x190)
46-
ArchInfo->Architecture = 0x190;
56+
if (status == NV_STATUS::Success && ArchInfo)
57+
{
58+
// if (arch < ada or arch >= special)
59+
if (ArchInfo->Architecture < 0x190 || ArchInfo->Architecture >= 0xE0000000)
60+
{
61+
ArchInfo->Architecture = 0x190; // Force Ada
62+
ArchInfo->Implementation = 4; // Force GA104
63+
}
64+
}
4765

4866
return status;
4967
}
@@ -67,17 +85,40 @@ void *__stdcall HookedNvAPI_QueryInterface(NV_INTERFACE InterfaceId)
6785
{
6886
const auto result = OriginalNvAPI_QueryInterface(InterfaceId);
6987

70-
if (InterfaceId == NV_INTERFACE::GPU_GetArchInfo)
88+
if (result)
7189
{
72-
OriginalNvAPI_GPU_GetArchInfo = static_cast<PfnNvAPI_GPU_GetArchInfo>(result);
73-
return &HookedNvAPI_GPU_GetArchInfo;
90+
if (InterfaceId == NV_INTERFACE::GPU_GetArchInfo)
91+
{
92+
OriginalNvAPI_GPU_GetArchInfo = static_cast<PfnNvAPI_GPU_GetArchInfo>(result);
93+
return &HookedNvAPI_GPU_GetArchInfo;
94+
}
95+
96+
if (InterfaceId == NV_INTERFACE::D3D12_SetRawScgPriority)
97+
return &HookedNvAPI_D3D12_SetRawScgPriority;
7498
}
7599

76-
if (InterfaceId == NV_INTERFACE::D3D12_SetRawScgPriority)
77-
return &HookedNvAPI_D3D12_SetRawScgPriority;
100+
return result;
101+
}
102+
103+
#if 0
104+
NTSTATUS WINAPI HookedD3DKMTQueryAdapterInfo(const D3DKMT_QUERYADAPTERINFO *Info)
105+
{
106+
const auto result = OriginalD3DKMTQueryAdapterInfo(Info);
107+
108+
if (result == 0 && Info && Info->Type == KMTQAITYPE_UMDRIVERPRIVATE)
109+
{
110+
if (Info->pPrivateDriverData && Info->PrivateDriverDataSize >= sizeof(NV_D3DKMT_PRIVATE_DRIVER_DATA))
111+
{
112+
auto driverData = static_cast<NV_D3DKMT_PRIVATE_DRIVER_DATA *>(Info->pPrivateDriverData);
113+
114+
if (driverData->Header == 0x4E564441)
115+
driverData->Architecture = 0x150;
116+
}
117+
}
78118

79119
return result;
80120
}
121+
#endif
81122

82123
bool TryInterceptNvAPIFunction(void *ModuleHandle, const void *FunctionName, void **FunctionPointer)
83124
{

0 commit comments

Comments
 (0)