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

Commit

Permalink
NGX relies on the chip implementation identifier as well as architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukem9 committed Feb 16, 2024
1 parent bc4ae88 commit 89ddc8c
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions source/wrapper_generic/nvapi.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
typedef LONG NTSTATUS;
#include <d3dkmthk.h>

enum class NV_STATUS : uint32_t
{
Success = 0,
Expand All @@ -14,7 +17,8 @@ struct NV_ARCH_INFO
{
uint32_t Version;
uint32_t Architecture;
uint32_t Unknown[2];
uint32_t Implementation;
uint32_t Unknown[1];
};

struct NV_SCG_PRIORITY_INFO
Expand All @@ -29,21 +33,35 @@ struct NV_SCG_PRIORITY_INFO
uint32_t Unknown8; // 14
};

struct NV_D3DKMT_PRIVATE_DRIVER_DATA // nvwg2umx.dll (546.33)
{
uint32_t Header; // 0 NVDA
char Padding[0xE4]; // 4
uint32_t Architecture; // E8
};

using PfnNvAPI_QueryInterface = void *(__stdcall *)(NV_INTERFACE InterfaceId);
using PfnNvAPI_GPU_GetArchInfo = NV_STATUS(__stdcall *)(void *GPUHandle, NV_ARCH_INFO *ArchInfo);

PfnNvAPI_QueryInterface OriginalNvAPI_QueryInterface = nullptr;
PfnNvAPI_GPU_GetArchInfo OriginalNvAPI_GPU_GetArchInfo = nullptr;
decltype(&D3DKMTQueryAdapterInfo) OriginalD3DKMTQueryAdapterInfo = nullptr;

NV_STATUS __stdcall HookedNvAPI_GPU_GetArchInfo(void *GPUHandle, NV_ARCH_INFO *ArchInfo)
{
if (OriginalNvAPI_GPU_GetArchInfo)
{
const auto status = OriginalNvAPI_GPU_GetArchInfo(GPUHandle, ArchInfo);

// Spoof Ada GPU arch
if (status == NV_STATUS::Success && ArchInfo && ArchInfo->Architecture < 0x190)
ArchInfo->Architecture = 0x190;
if (status == NV_STATUS::Success && ArchInfo)
{
// if (arch < ada or arch >= special)
if (ArchInfo->Architecture < 0x190 || ArchInfo->Architecture >= 0xE0000000)
{
ArchInfo->Architecture = 0x190; // Force Ada
ArchInfo->Implementation = 4; // Force GA104
}
}

return status;
}
Expand All @@ -67,17 +85,40 @@ void *__stdcall HookedNvAPI_QueryInterface(NV_INTERFACE InterfaceId)
{
const auto result = OriginalNvAPI_QueryInterface(InterfaceId);

if (InterfaceId == NV_INTERFACE::GPU_GetArchInfo)
if (result)
{
OriginalNvAPI_GPU_GetArchInfo = static_cast<PfnNvAPI_GPU_GetArchInfo>(result);
return &HookedNvAPI_GPU_GetArchInfo;
if (InterfaceId == NV_INTERFACE::GPU_GetArchInfo)
{
OriginalNvAPI_GPU_GetArchInfo = static_cast<PfnNvAPI_GPU_GetArchInfo>(result);
return &HookedNvAPI_GPU_GetArchInfo;
}

if (InterfaceId == NV_INTERFACE::D3D12_SetRawScgPriority)
return &HookedNvAPI_D3D12_SetRawScgPriority;
}

if (InterfaceId == NV_INTERFACE::D3D12_SetRawScgPriority)
return &HookedNvAPI_D3D12_SetRawScgPriority;
return result;
}

#if 0
NTSTATUS WINAPI HookedD3DKMTQueryAdapterInfo(const D3DKMT_QUERYADAPTERINFO *Info)
{
const auto result = OriginalD3DKMTQueryAdapterInfo(Info);

if (result == 0 && Info && Info->Type == KMTQAITYPE_UMDRIVERPRIVATE)
{
if (Info->pPrivateDriverData && Info->PrivateDriverDataSize >= sizeof(NV_D3DKMT_PRIVATE_DRIVER_DATA))
{
auto driverData = static_cast<NV_D3DKMT_PRIVATE_DRIVER_DATA *>(Info->pPrivateDriverData);

if (driverData->Header == 0x4E564441)
driverData->Architecture = 0x150;
}
}

return result;
}
#endif

bool TryInterceptNvAPIFunction(void *ModuleHandle, const void *FunctionName, void **FunctionPointer)
{
Expand Down

0 comments on commit 89ddc8c

Please sign in to comment.