mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
The r5 merge kept DroidDeck's old D3D11 PopulateParameters line, which called the removed "DLSS unavailable on D3D11" helper; upstream fills D3D11 like Vulkan and D3D12 now. nvngx.dll failed to link. All six bridge DLLs build locally (mingw-w64 13.2) and match their exports. Headers of the modified bridge files name 71c140d9.
577 lines
27 KiB
C
577 lines
27 KiB
C
// DroidDeck: modified from michaelisomer-cyber/Winlator-NeuralScale 71c140d9 (see README.md).
|
|
// Full OptiScaler/fakenvapi-parity nvapi64.dll shim for Winlator Ludashi FSR 4 NPU.
|
|
// - Dynamically queries DXGI Adapter 0 LUID so NVIDIA Streamline (Cyberpunk 2077, etc.)
|
|
// matches the DXGI adapter to our spoofed NVIDIA GeForce RTX 2060 (Turing TU106).
|
|
// - Implements all core NVAPI interfaces required by RDR2 (Vulkan/DX12), Cyberpunk 2077
|
|
// (Streamline sl.common / sl.dlss), Unreal Engine, and DX11/DX12/Vulkan DLSS titles.
|
|
#include <windows.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "wl_ngx_hooks.h"
|
|
|
|
typedef int32_t NvAPI_Status;
|
|
#define NVAPI_OK 0
|
|
#define NVAPI_ERROR -1
|
|
#define NVAPI_INVALID_ARGUMENT -5
|
|
#define NVAPI_NO_IMPLEMENTATION -7
|
|
#define NVAPI_END_ENUMERATION -7
|
|
#define NVAPI_INVALID_POINTER -14
|
|
#define NVAPI_NOT_SUPPORTED -104
|
|
#define NVAPI_INCOMPATIBLE_STRUCT_VERSION -105
|
|
|
|
#define NVAPI_SHORT_STRING_MAX 64
|
|
#define NVAPI_MAX_PHYSICAL_GPUS 64
|
|
|
|
// NVIDIA Driver 570.00 (satisfies all DLSS 2/3/3.5/4 & Streamline 2.x checks)
|
|
#define WL_NV_DRIVER_VERSION 57000u
|
|
#define WL_NV_BUILD_BRANCH "r570_00"
|
|
#define WL_NV_GPU_NAME "NVIDIA GeForce RTX 2060"
|
|
|
|
static void *const k_fake_gpu = (void *)(uintptr_t)0x000010DE00001F08ULL;
|
|
static void *const k_fake_lgpu = (void *)(uintptr_t)0x000010DE00001F09ULL;
|
|
static void *const k_fake_disp = (void *)(uintptr_t)0x000010DE00000001ULL;
|
|
static void *const k_drs_sess = (void *)(uintptr_t)0x000010DE0000D001ULL;
|
|
static void *const k_drs_prof = (void *)(uintptr_t)0x000010DE0000D002ULL;
|
|
|
|
// Minimal COM vtable definitions for IDXGIFactory1 / IDXGIAdapter1 (no dxgi.lib link required)
|
|
typedef struct WlDxgiAdapterDesc1 {
|
|
WCHAR Description[128];
|
|
UINT VendorId;
|
|
UINT DeviceId;
|
|
UINT SubSysId;
|
|
UINT Revision;
|
|
SIZE_T DedicatedVideoMemory;
|
|
SIZE_T DedicatedSystemMemory;
|
|
SIZE_T SharedSystemMemory;
|
|
LUID AdapterLuid;
|
|
UINT Flags;
|
|
} WlDxgiAdapterDesc1;
|
|
|
|
typedef struct WlIDXGIAdapter1Vtbl {
|
|
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *, const GUID *, void **);
|
|
ULONG (STDMETHODCALLTYPE *AddRef)(void *);
|
|
ULONG (STDMETHODCALLTYPE *Release)(void *);
|
|
HRESULT (STDMETHODCALLTYPE *SetPrivateData)(void *, const GUID *, UINT, const void *);
|
|
HRESULT (STDMETHODCALLTYPE *SetPrivateDataInterface)(void *, const GUID *, const void *);
|
|
HRESULT (STDMETHODCALLTYPE *GetPrivateData)(void *, const GUID *, UINT *, void *);
|
|
HRESULT (STDMETHODCALLTYPE *GetParent)(void *, const GUID *, void **);
|
|
HRESULT (STDMETHODCALLTYPE *EnumOutputs)(void *, UINT, void **);
|
|
HRESULT (STDMETHODCALLTYPE *GetDesc)(void *, void *);
|
|
HRESULT (STDMETHODCALLTYPE *CheckInterfaceSupport)(void *, const GUID *, LARGE_INTEGER *);
|
|
HRESULT (STDMETHODCALLTYPE *GetDesc1)(void *, WlDxgiAdapterDesc1 *);
|
|
} WlIDXGIAdapter1Vtbl;
|
|
|
|
typedef struct { WlIDXGIAdapter1Vtbl *lpVtbl; } WlIDXGIAdapter1;
|
|
|
|
typedef struct WlIDXGIFactory1Vtbl {
|
|
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *, const GUID *, void **);
|
|
ULONG (STDMETHODCALLTYPE *AddRef)(void *);
|
|
ULONG (STDMETHODCALLTYPE *Release)(void *);
|
|
HRESULT (STDMETHODCALLTYPE *SetPrivateData)(void *, const GUID *, UINT, const void *);
|
|
HRESULT (STDMETHODCALLTYPE *SetPrivateDataInterface)(void *, const GUID *, const void *);
|
|
HRESULT (STDMETHODCALLTYPE *GetPrivateData)(void *, const GUID *, UINT *, void *);
|
|
HRESULT (STDMETHODCALLTYPE *GetParent)(void *, const GUID *, void **);
|
|
HRESULT (STDMETHODCALLTYPE *EnumAdapters)(void *, UINT, void **);
|
|
HRESULT (STDMETHODCALLTYPE *MakeWindowAssociation)(void *, HWND, UINT);
|
|
HRESULT (STDMETHODCALLTYPE *GetWindowAssociation)(void *, HWND *);
|
|
HRESULT (STDMETHODCALLTYPE *CreateSwapChain)(void *, void *, void *, void **);
|
|
HRESULT (STDMETHODCALLTYPE *CreateSoftwareAdapter)(void *, HMODULE, void **);
|
|
HRESULT (STDMETHODCALLTYPE *EnumAdapters1)(void *, UINT, WlIDXGIAdapter1 **);
|
|
} WlIDXGIFactory1Vtbl;
|
|
|
|
typedef struct { WlIDXGIFactory1Vtbl *lpVtbl; } WlIDXGIFactory1;
|
|
|
|
typedef HRESULT (WINAPI *PFN_CreateDXGIFactory1)(const GUID *riid, void **ppFactory);
|
|
static const GUID k_IID_IDXGIFactory1 = {
|
|
0x770aae78u, 0xf26fu, 0x4dbau, { 0xa8, 0x29, 0x25, 0x3c, 0x83, 0xd1, 0xb3, 0x87 }
|
|
};
|
|
|
|
static CRITICAL_SECTION g_cs;
|
|
static int g_cs_ready = 0;
|
|
static int g_dxgi_probed = 0;
|
|
static LUID g_luid = { 0x10DE1F08u, 0 };
|
|
static uint32_t g_vendor_id = 0x10DEu;
|
|
static uint32_t g_device_id = 0x1F08u;
|
|
static uint32_t g_subsys_id = 0x10DE1F08u;
|
|
static uint32_t g_rev_id = 0xA1u;
|
|
static uint64_t g_dxgi_vram_bytes = 0ULL;
|
|
|
|
static void ensure_cs(void) {
|
|
if (!g_cs_ready) { InitializeCriticalSection(&g_cs); g_cs_ready = 1; }
|
|
}
|
|
|
|
static void probe_dxgi_adapter_once(void) {
|
|
ensure_cs();
|
|
EnterCriticalSection(&g_cs);
|
|
if (!g_dxgi_probed) {
|
|
g_dxgi_probed = 1;
|
|
HMODULE hDxgi = GetModuleHandleA("dxgi.dll");
|
|
if (!hDxgi) hDxgi = LoadLibraryA("dxgi.dll");
|
|
if (hDxgi) {
|
|
PFN_CreateDXGIFactory1 fnCreate = (PFN_CreateDXGIFactory1)(void *)GetProcAddress(hDxgi, "CreateDXGIFactory1");
|
|
if (fnCreate) {
|
|
WlIDXGIFactory1 *factory = NULL;
|
|
if (SUCCEEDED(fnCreate(&k_IID_IDXGIFactory1, (void **)&factory)) && factory) {
|
|
WlIDXGIAdapter1 *adapter = NULL;
|
|
if (SUCCEEDED(factory->lpVtbl->EnumAdapters1(factory, 0, &adapter)) && adapter) {
|
|
WlDxgiAdapterDesc1 desc;
|
|
memset(&desc, 0, sizeof desc);
|
|
if (SUCCEEDED(adapter->lpVtbl->GetDesc1(adapter, &desc))) {
|
|
g_luid = desc.AdapterLuid;
|
|
if (desc.DedicatedVideoMemory > 0) {
|
|
g_dxgi_vram_bytes = (uint64_t)desc.DedicatedVideoMemory;
|
|
}
|
|
if (desc.VendorId == 0x10DEu && desc.DeviceId != 0) {
|
|
g_vendor_id = desc.VendorId;
|
|
g_device_id = desc.DeviceId;
|
|
if (desc.SubSysId) g_subsys_id = desc.SubSysId;
|
|
if (desc.Revision) g_rev_id = desc.Revision;
|
|
}
|
|
}
|
|
adapter->lpVtbl->Release(adapter);
|
|
}
|
|
factory->lpVtbl->Release(factory);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
LeaveCriticalSection(&g_cs);
|
|
}
|
|
|
|
static uint64_t wl_nv_vram_bytes(void) {
|
|
static const char *const names[] = { "DROIDDECK_UPSCALE_VRAM_MB", "WINLATOR_FSR4_VRAM_MB", "WRAPPER_VMEM_MAX_SIZE" };
|
|
char buf[64];
|
|
for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
|
|
DWORD n = GetEnvironmentVariableA(names[i], buf, sizeof(buf));
|
|
if (n > 0 && n < sizeof(buf)) {
|
|
unsigned long long mb = strtoull(buf, NULL, 10);
|
|
if (mb >= 512ULL && mb <= 65536ULL) return mb * 1024ULL * 1024ULL;
|
|
}
|
|
}
|
|
probe_dxgi_adapter_once();
|
|
if (g_dxgi_vram_bytes >= 512ULL * 1024ULL * 1024ULL) return g_dxgi_vram_bytes;
|
|
return 12ULL * 1024ULL * 1024ULL * 1024ULL;
|
|
}
|
|
|
|
static void copy_short_str(char *dst, const char *src) {
|
|
if (!dst) return;
|
|
strncpy(dst, src ? src : "", NVAPI_SHORT_STRING_MAX - 1);
|
|
dst[NVAPI_SHORT_STRING_MAX - 1] = '\0';
|
|
}
|
|
|
|
// ---- Exact NVAPI structs (verified against NVIDIA NVAPI SDK / fakenvapi) ----
|
|
typedef struct {
|
|
uint32_t version;
|
|
uint32_t drvVersion;
|
|
uint32_t bldChangeListNum;
|
|
char szBuildBranchString[NVAPI_SHORT_STRING_MAX];
|
|
char szAdapterString[NVAPI_SHORT_STRING_MAX];
|
|
} WlNvDisplayDriverVersion;
|
|
|
|
typedef struct {
|
|
uint32_t version;
|
|
uint32_t driverVersion;
|
|
char szBuildBranch[NVAPI_SHORT_STRING_MAX];
|
|
uint32_t flags; /* bit0=DCH, bit1=Studio, bit2=GameReady, bit3=RTXProd, bit4=RTXNFB */
|
|
char szBuildBaseBranch[NVAPI_SHORT_STRING_MAX];
|
|
uint32_t reservedEx;
|
|
} WlNvDisplayDriverInfoV2;
|
|
|
|
typedef struct {
|
|
uint32_t version;
|
|
void *pOSAdapterId;
|
|
uint32_t physicalGpuCount;
|
|
void *physicalGpuHandles[NVAPI_MAX_PHYSICAL_GPUS];
|
|
uint32_t reserved[8];
|
|
} WlNvLogicalGpuDataV1;
|
|
|
|
typedef struct {
|
|
uint32_t version;
|
|
uint32_t gpuCount;
|
|
struct {
|
|
void *hPhysicalGpu;
|
|
uint32_t flags;
|
|
} computeGpus[NVAPI_MAX_PHYSICAL_GPUS];
|
|
} WlNvComputeGpuTopologyV1;
|
|
|
|
typedef struct {
|
|
uint32_t bIsPresent;
|
|
uint32_t frequency;
|
|
} WlNvClockDomain;
|
|
|
|
typedef struct {
|
|
uint32_t version;
|
|
uint32_t clockType;
|
|
WlNvClockDomain domain[32];
|
|
} WlNvGpuClockFrequencies;
|
|
|
|
// ---- Core NVAPI implementations ----
|
|
static NvAPI_Status __cdecl impl_Initialize(void) {
|
|
wl_install_ngx_hooks_once();
|
|
probe_dxgi_adapter_once();
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_Unload(void) { return NVAPI_OK; }
|
|
static NvAPI_Status __cdecl impl_GetInterfaceVersionString(char *out) {
|
|
copy_short_str(out, "NVAPI Open Source Interface (Winlator FSR4 NPU)");
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GetErrorMessage(NvAPI_Status nr, char *out) {
|
|
copy_short_str(out, nr == NVAPI_OK ? "NVAPI_OK" : "NVAPI_ERROR");
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GetDisplayDriverVersion(void *disp, WlNvDisplayDriverVersion *ver) {
|
|
(void)disp;
|
|
if (!ver) return NVAPI_INVALID_ARGUMENT;
|
|
ver->drvVersion = WL_NV_DRIVER_VERSION;
|
|
ver->bldChangeListNum = 35000000u;
|
|
copy_short_str(ver->szBuildBranchString, WL_NV_BUILD_BRANCH);
|
|
copy_short_str(ver->szAdapterString, WL_NV_GPU_NAME);
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_SYS_GetDriverAndBranchVersion(uint32_t *ver, char *branch) {
|
|
if (ver) *ver = WL_NV_DRIVER_VERSION;
|
|
if (branch) copy_short_str(branch, WL_NV_BUILD_BRANCH);
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_SYS_GetDisplayDriverInfo(WlNvDisplayDriverInfoV2 *info) {
|
|
if (!info) return NVAPI_INVALID_ARGUMENT;
|
|
info->driverVersion = WL_NV_DRIVER_VERSION;
|
|
copy_short_str(info->szBuildBranch, WL_NV_BUILD_BRANCH);
|
|
info->flags = (1u << 0) | (1u << 1) | (1u << 2) | (1u << 3) | (1u << 4);
|
|
uint32_t struct_ver = (info->version >> 16) & 0xFFFFu;
|
|
if (struct_ver >= 2u || info->version == 2u) {
|
|
copy_short_str(info->szBuildBaseBranch, WL_NV_BUILD_BRANCH);
|
|
info->reservedEx = 0;
|
|
}
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_EnumPhysicalGPUs(void **handles, uint32_t *count) {
|
|
probe_dxgi_adapter_once();
|
|
if (handles) handles[0] = k_fake_gpu;
|
|
if (count) *count = 1u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_EnumLogicalGPUs(void **handles, uint32_t *count) {
|
|
probe_dxgi_adapter_once();
|
|
if (handles) handles[0] = k_fake_lgpu;
|
|
if (count) *count = 1u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_EnumNvidiaDisplayHandle(uint32_t idx, void **handle) {
|
|
if (idx > 0) return NVAPI_END_ENUMERATION;
|
|
if (handle) *handle = k_fake_disp;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_EnumUnattached(uint32_t idx, void **handle) {
|
|
(void)idx; (void)handle;
|
|
return NVAPI_END_ENUMERATION;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GetLogicalGPUFromPhysicalGPU(void *phys, void **logical) {
|
|
(void)phys;
|
|
if (logical) *logical = k_fake_lgpu;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GetPhysicalGPUsFromLogicalGPU(void *logical, void **phys, uint32_t *count) {
|
|
(void)logical;
|
|
if (phys) phys[0] = k_fake_gpu;
|
|
if (count) *count = 1u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GetPhysicalGPUsFromDisplay(void *disp, void **phys, uint32_t *count) {
|
|
(void)disp;
|
|
if (phys) phys[0] = k_fake_gpu;
|
|
if (count) *count = 1u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GetGPUIDfromPhysicalGPU(void *phys, uint32_t *gpuId) {
|
|
(void)phys;
|
|
if (gpuId) *gpuId = 0x100u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GetPhysicalGPUFromGPUID(uint32_t gpuId, void **phys) {
|
|
(void)gpuId;
|
|
if (phys) *phys = k_fake_gpu;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetAdapterIdFromPhysicalGpu(void *gpu, void *pOSAdapterId) {
|
|
(void)gpu;
|
|
if (!pOSAdapterId) return NVAPI_INVALID_ARGUMENT;
|
|
probe_dxgi_adapter_once();
|
|
memcpy(pOSAdapterId, &g_luid, sizeof(g_luid));
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetLogicalGpuInfo(void *logical, WlNvLogicalGpuDataV1 *data) {
|
|
(void)logical;
|
|
if (!data) return NVAPI_INVALID_ARGUMENT;
|
|
probe_dxgi_adapter_once();
|
|
if (data->pOSAdapterId) memcpy(data->pOSAdapterId, &g_luid, sizeof(g_luid));
|
|
data->physicalGpuCount = 1u;
|
|
data->physicalGpuHandles[0] = k_fake_gpu;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetFullName(void *gpu, char *name) {
|
|
(void)gpu;
|
|
copy_short_str(name, WL_NV_GPU_NAME);
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetPCIIdentifiers(void *gpu, uint32_t *devId, uint32_t *subSysId, uint32_t *revId, uint32_t *extDevId) {
|
|
(void)gpu;
|
|
probe_dxgi_adapter_once();
|
|
if (devId) *devId = (g_device_id << 16) | (g_vendor_id & 0xFFFFu);
|
|
if (subSysId) *subSysId = g_subsys_id;
|
|
if (revId) *revId = g_rev_id;
|
|
if (extDevId) *extDevId = g_device_id;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetArchInfo(void *gpu, void *info) {
|
|
(void)gpu;
|
|
if (!info) return NVAPI_INVALID_ARGUMENT;
|
|
uint32_t *u = (uint32_t *)info;
|
|
// NV_GPU_ARCH_INFO_V2: [0]=version, [1]=architecture (TU100=0x160), [2]=implementation (TU106=0x06), [3]=revision (0xA1)
|
|
u[1] = 0x00000160u;
|
|
u[2] = 0x00000006u;
|
|
u[3] = 0x000000A1u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetGPUType(void *gpu, uint32_t *type) {
|
|
(void)gpu;
|
|
if (type) *type = 2u; /* NV_SYSTEM_TYPE_DISCRETE */
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetMemoryInfo(void *gpu, uint32_t *info) {
|
|
(void)gpu;
|
|
if (info) {
|
|
uint64_t vram_kb64 = wl_nv_vram_bytes() / 1024ULL;
|
|
uint32_t vram_kb = (vram_kb64 > 0xFFFFFFFFULL) ? 0xFFFFFFFFu : (uint32_t)vram_kb64;
|
|
info[1] = vram_kb;
|
|
info[2] = vram_kb;
|
|
info[3] = 0u;
|
|
info[4] = vram_kb / 2u;
|
|
info[5] = (vram_kb / 8u) * 7u;
|
|
}
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetMemoryInfoEx(void *gpu, uint64_t *info) {
|
|
(void)gpu;
|
|
if (info) {
|
|
uint64_t vram_b = wl_nv_vram_bytes();
|
|
info[1] = vram_b;
|
|
info[2] = vram_b;
|
|
info[3] = 0ULL;
|
|
info[4] = vram_b / 2ULL;
|
|
info[5] = (vram_b / 8ULL) * 7ULL;
|
|
}
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetVbiosVersionString(void *gpu, char *out) {
|
|
(void)gpu;
|
|
copy_short_str(out, "90.06.2E.00.01");
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetPhysicalFrameBufferSize(void *gpu, uint32_t *kb) {
|
|
(void)gpu;
|
|
if (kb) {
|
|
uint64_t vram_kb64 = wl_nv_vram_bytes() / 1024ULL;
|
|
*kb = (vram_kb64 > 0xFFFFFFFFULL) ? 0xFFFFFFFFu : (uint32_t)vram_kb64;
|
|
}
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetGpuCoreCount(void *gpu, uint32_t *cnt) {
|
|
(void)gpu;
|
|
if (cnt) *cnt = 1920u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetConnectedDisplayIds(void *gpu, void *ids, uint32_t *cnt, uint32_t flags) {
|
|
(void)gpu; (void)ids; (void)flags;
|
|
if (cnt) *cnt = 0u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_CudaEnumComputeCapableGpus(WlNvComputeGpuTopologyV1 *topo) {
|
|
if (!topo) return NVAPI_INVALID_ARGUMENT;
|
|
topo->gpuCount = 1u;
|
|
topo->computeGpus[0].hPhysicalGpu = k_fake_gpu;
|
|
topo->computeGpus[0].flags = 0x7u; /* CAPABLE | ENABLE | RECOMMENDED */
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_GPU_GetAllClockFrequencies(void *gpu, WlNvGpuClockFrequencies *clk) {
|
|
(void)gpu;
|
|
if (!clk) return NVAPI_INVALID_ARGUMENT;
|
|
memset(clk->domain, 0, sizeof clk->domain);
|
|
clk->domain[0].bIsPresent = 1; clk->domain[0].frequency = 1680000u; /* Graphics */
|
|
clk->domain[4].bIsPresent = 1; clk->domain[4].frequency = 7000000u; /* Memory */
|
|
clk->domain[7].bIsPresent = 1; clk->domain[7].frequency = 1400000u; /* Video */
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_Disp_GetDisplayIdByDisplayName(const char *name, uint32_t *id) {
|
|
(void)name;
|
|
if (id) *id = 0u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_Disp_GetGDIPrimaryDisplayId(uint32_t *id) {
|
|
if (id) *id = 0u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_Disp_OutputMode(uint32_t dispId, uint32_t *mode) {
|
|
(void)dispId;
|
|
if (mode) *mode = 0u; /* SDR */
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_SYS_GetDisplayIdFromGpuAndOutputId(void *gpu, uint32_t outId, uint32_t *dispId) {
|
|
(void)gpu; (void)outId;
|
|
if (dispId) *dispId = 0u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_SYS_GetGpuAndOutputIdFromDisplayId(uint32_t dispId, void **gpu, uint32_t *outId) {
|
|
(void)dispId;
|
|
if (gpu) *gpu = k_fake_gpu;
|
|
if (outId) *outId = 0u;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_D3D_GetCurrentSLIState(void *dev, uint32_t *state) {
|
|
(void)dev;
|
|
if (state) {
|
|
state[1] = 1; state[2] = 1; state[3] = 0;
|
|
state[4] = 0; state[5] = 0; state[6] = 0;
|
|
}
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_D3D_GetObjectHandleForResource(void *dev, void *res, void **outH) {
|
|
(void)dev;
|
|
if (outH) *outH = res;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_D3D12_IsNvShaderExtnOpCodeSupported(void *dev, uint32_t op, uint8_t *supported) {
|
|
(void)dev; (void)op;
|
|
if (supported) *supported = 0;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_D3D12_GetRaytracingCaps(void *dev, uint32_t type, void *pData, size_t dataSize) {
|
|
(void)dev; (void)type;
|
|
if (!pData) return NVAPI_INVALID_POINTER;
|
|
memset(pData, 0, dataSize);
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_DRS_CreateSession(void **sess) {
|
|
if (sess) *sess = k_drs_sess;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_DRS_GetBaseProfile(void *sess, void **prof) {
|
|
(void)sess;
|
|
if (prof) *prof = k_drs_prof;
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_D3D_GetSleepStatus(void *dev, uint32_t *params) {
|
|
(void)dev;
|
|
if (params) {
|
|
params[1] = 0u; /* bLowLatencyMode */
|
|
params[2] = 0u; /* bFsVrr */
|
|
params[3] = 0u; /* bCplVsyncOn */
|
|
}
|
|
return NVAPI_OK;
|
|
}
|
|
static NvAPI_Status __cdecl impl_NoOpOk(void) { return NVAPI_OK; }
|
|
static NvAPI_Status __cdecl impl_NotSupported(void) { return NVAPI_NO_IMPLEMENTATION; }
|
|
|
|
__declspec(dllexport) void *__cdecl nvapi_QueryInterface(uint32_t id) {
|
|
wl_install_ngx_hooks_once();
|
|
switch (id) {
|
|
// Core & driver info
|
|
case 0x0150E828u: return (void *)impl_Initialize; // NvAPI_Initialize
|
|
case 0xD22BDD7Eu: return (void *)impl_Unload; // NvAPI_Unload
|
|
case 0x01053FA5u: return (void *)impl_GetInterfaceVersionString; // NvAPI_GetInterfaceVersionString
|
|
case 0x6C2D048Cu: return (void *)impl_GetErrorMessage; // NvAPI_GetErrorMessage
|
|
case 0xF951A4D1u: return (void *)impl_GetDisplayDriverVersion; // NvAPI_GetDisplayDriverVersion
|
|
case 0x2926AAADu: return (void *)impl_SYS_GetDriverAndBranchVersion; // NvAPI_SYS_GetDriverAndBranchVersion
|
|
case 0x721FACEBu: return (void *)impl_SYS_GetDisplayDriverInfo; // NvAPI_SYS_GetDisplayDriverInfo
|
|
case 0x08F2BAB4u: return (void *)impl_SYS_GetDisplayIdFromGpuAndOutputId;// NvAPI_SYS_GetDisplayIdFromGpuAndOutputId
|
|
case 0x112BA1A5u: return (void *)impl_SYS_GetGpuAndOutputIdFromDisplayId;// NvAPI_SYS_GetGpuAndOutputIdFromDisplayId
|
|
|
|
// Physical / logical GPU enumeration & LUID matching (CRITICAL for Streamline / Cyberpunk 2077)
|
|
case 0xE5AC921Fu: return (void *)impl_EnumPhysicalGPUs; // NvAPI_EnumPhysicalGPUs
|
|
case 0x48B3EA59u: return (void *)impl_EnumLogicalGPUs; // NvAPI_EnumLogicalGPUs
|
|
case 0x9ABDD40Du: return (void *)impl_EnumNvidiaDisplayHandle; // NvAPI_EnumNvidiaDisplayHandle
|
|
case 0x20DE9260u: return (void *)impl_EnumUnattached; // NvAPI_EnumNvidiaUnAttachedDisplayHandle
|
|
case 0xADD604D1u: return (void *)impl_GetLogicalGPUFromPhysicalGPU; // NvAPI_GetLogicalGPUFromPhysicalGPU
|
|
case 0xAEA3FA32u: return (void *)impl_GetPhysicalGPUsFromLogicalGPU; // NvAPI_GetPhysicalGPUsFromLogicalGPU
|
|
case 0x34EF9506u: return (void *)impl_GetPhysicalGPUsFromDisplay; // NvAPI_GetPhysicalGPUsFromDisplay
|
|
case 0x6533EA3Eu: return (void *)impl_GetGPUIDfromPhysicalGPU; // NvAPI_GetGPUIDfromPhysicalGPU
|
|
case 0x5380AD1Au: return (void *)impl_GetPhysicalGPUFromGPUID; // NvAPI_GetPhysicalGPUFromGPUID
|
|
case 0x0FF07FDEu: return (void *)impl_GPU_GetAdapterIdFromPhysicalGpu; // NvAPI_GPU_GetAdapterIdFromPhysicalGpu
|
|
case 0x842B066Eu: return (void *)impl_GPU_GetLogicalGpuInfo; // NvAPI_GPU_GetLogicalGpuInfo
|
|
|
|
// GPU capabilities & identity
|
|
case 0xCEEE8E9Fu: return (void *)impl_GPU_GetFullName; // NvAPI_GPU_GetFullName
|
|
case 0x2DDFB66Eu: return (void *)impl_GPU_GetPCIIdentifiers; // NvAPI_GPU_GetPCIIdentifiers
|
|
case 0xD8265D24u: return (void *)impl_GPU_GetArchInfo; // NvAPI_GPU_GetArchInfo
|
|
case 0xC33BAEB1u: return (void *)impl_GPU_GetGPUType; // NvAPI_GPU_GetGPUType
|
|
case 0x07F9B368u: return (void *)impl_GPU_GetMemoryInfo; // NvAPI_GPU_GetMemoryInfo
|
|
case 0xC0599498u: return (void *)impl_GPU_GetMemoryInfoEx; // NvAPI_GPU_GetMemoryInfoEx
|
|
case 0xA561FD7Du: return (void *)impl_GPU_GetVbiosVersionString; // NvAPI_GPU_GetVbiosVersionString
|
|
case 0x46FBEB03u: return (void *)impl_GPU_GetPhysicalFrameBufferSize; // NvAPI_GPU_GetPhysicalFrameBufferSize
|
|
case 0x5A04B644u: return (void *)impl_GPU_GetPhysicalFrameBufferSize; // NvAPI_GPU_GetVirtualFrameBufferSize
|
|
case 0xC7026A87u: return (void *)impl_GPU_GetGpuCoreCount; // NvAPI_GPU_GetGpuCoreCount
|
|
case 0x0078DBA2u: return (void *)impl_GPU_GetConnectedDisplayIds; // NvAPI_GPU_GetConnectedDisplayIds
|
|
case 0x5786CC6Eu: return (void *)impl_GPU_CudaEnumComputeCapableGpus; // NvAPI_GPU_CudaEnumComputeCapableGpus
|
|
case 0xDCB616C3u: return (void *)impl_GPU_GetAllClockFrequencies; // NvAPI_GPU_GetAllClockFrequencies
|
|
|
|
// Display
|
|
case 0xAE457190u: return (void *)impl_Disp_GetDisplayIdByDisplayName; // NvAPI_DISP_GetDisplayIdByDisplayName
|
|
case 0x1E9D8A31u: return (void *)impl_Disp_GetGDIPrimaryDisplayId; // NvAPI_DISP_GetGDIPrimaryDisplayId
|
|
case 0x98E7661Au: return (void *)impl_Disp_OutputMode; // NvAPI_Disp_SetOutputMode
|
|
case 0x81FED88Du: return (void *)impl_Disp_OutputMode; // NvAPI_Disp_GetOutputMode
|
|
case 0x84F2A8DFu: return (void *)impl_NoOpOk; // NvAPI_Disp_GetHdrCapabilities
|
|
case 0x351DA224u: return (void *)impl_NoOpOk; // NvAPI_Disp_HdrColorControl
|
|
|
|
// D3D / D3D12 / Reflex
|
|
case 0x4B708B54u: return (void *)impl_D3D_GetCurrentSLIState; // NvAPI_D3D_GetCurrentSLIState
|
|
case 0xFCEAC864u: return (void *)impl_D3D_GetObjectHandleForResource; // NvAPI_D3D_GetObjectHandleForResource
|
|
case 0x8C02C4D0u: return (void *)impl_NoOpOk; // NvAPI_D3D_RegisterDevice
|
|
case 0x3DFACEC8u: return (void *)impl_D3D12_IsNvShaderExtnOpCodeSupported;// NvAPI_D3D12_IsNvShaderExtnOpCodeSupported
|
|
case 0x43D867C0u: return (void *)impl_NoOpOk; // NvAPI_D3D12_SetNvShaderExtnSlotSpaceLocalThread
|
|
case 0x85A6C2A0u: return (void *)impl_D3D12_GetRaytracingCaps; // NvAPI_D3D12_GetRaytracingCaps
|
|
case 0x03D6E8CBu: return (void *)impl_NoOpOk; // NvAPI_D3D12_NotifyOutOfBandCommandQueue
|
|
case 0x13C98F73u: return (void *)impl_NoOpOk; // NvAPI_D3D12_SetAsyncFrameMarker
|
|
case 0xAEF96CA1u: return (void *)impl_D3D_GetSleepStatus; // NvAPI_D3D_GetSleepStatus
|
|
case 0xAC1CA9E0u: return (void *)impl_NoOpOk; // NvAPI_D3D_SetSleepMode
|
|
case 0x852CD1D2u: return (void *)impl_NoOpOk; // NvAPI_D3D_Sleep
|
|
case 0xB9F6FAFFu: return (void *)impl_NoOpOk; // NvAPI_D3D_SetReflexSync
|
|
case 0x1A587F9Cu: return (void *)impl_NoOpOk; // NvAPI_D3D_GetLatency
|
|
case 0xD9984C05u: return (void *)impl_NoOpOk; // NvAPI_D3D_SetLatencyMarker
|
|
|
|
// Vulkan Reflex (graceful unsupported so Vulkan games don't expect a timeline semaphore we didn't create)
|
|
case 0x5C1696B6u: return (void *)impl_NotSupported; // NvAPI_Vulkan_InitLowLatencyDevice
|
|
case 0x11A5932Bu: return (void *)impl_NoOpOk; // NvAPI_Vulkan_DestroyLowLatencyDevice
|
|
case 0xADF966AFu: return (void *)impl_NotSupported; // NvAPI_Vulkan_GetSleepStatus
|
|
case 0x2ACFD162u: return (void *)impl_NotSupported; // NvAPI_Vulkan_SetSleepMode
|
|
case 0x36732B1Eu: return (void *)impl_NotSupported; // NvAPI_Vulkan_Sleep
|
|
case 0x3233D44Au: return (void *)impl_NotSupported; // NvAPI_Vulkan_GetLatency
|
|
case 0xA17D13D6u: return (void *)impl_NotSupported; // NvAPI_Vulkan_SetLatencyMarker
|
|
case 0x5D6D3840u: return (void *)impl_NoOpOk; // NvAPI_Vulkan_NotifyOutOfBandVkQueue
|
|
|
|
// DRS (Driver Settings)
|
|
case 0x0694D52Eu: return (void *)impl_DRS_CreateSession; // NvAPI_DRS_CreateSession
|
|
case 0xDAD9CFF8u: return (void *)impl_NoOpOk; // NvAPI_DRS_DestroySession
|
|
case 0x375DBD6Bu: return (void *)impl_NoOpOk; // NvAPI_DRS_LoadSettings
|
|
case 0xFCBC7E14u: return (void *)impl_NoOpOk; // NvAPI_DRS_SaveSettings
|
|
case 0xDA8466A0u: return (void *)impl_DRS_GetBaseProfile; // NvAPI_DRS_GetBaseProfile
|
|
case 0x73BF8338u: return (void *)impl_NotSupported; // NvAPI_DRS_GetSetting
|
|
case 0x577DD202u: return (void *)impl_NoOpOk; // NvAPI_DRS_SetSetting
|
|
|
|
default: return NULL;
|
|
}
|
|
}
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
|
(void)reserved;
|
|
if (reason == DLL_PROCESS_ATTACH) {
|
|
g_wl_self_mod = hinst;
|
|
DisableThreadLibraryCalls(hinst);
|
|
ensure_cs();
|
|
}
|
|
return TRUE;
|
|
}
|