Clean up nvapi patches and add NvAPI_GetPhysicalGPUsFromLogicalGPU.

This commit is contained in:
Michael Müller 2015-01-08 01:09:51 +01:00
parent f80d76f069
commit 62d458238d
4 changed files with 197 additions and 21 deletions

View File

@ -1,4 +1,4 @@
From bf2433b8c878cfeb86a2822d799bb1975edb36e4 Mon Sep 17 00:00:00 2001
From 8ef1cf2176dfab90c442465c13b2ad25d144f441 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Mon, 5 Jan 2015 18:11:53 +0100
Subject: nvapi: First implementation.
@ -6,7 +6,7 @@ Subject: nvapi: First implementation.
---
configure.ac | 3 +
dlls/nvapi/Makefile.in | 4 +
dlls/nvapi/nvapi.c | 459 +++++++++++++++++++++++++++++++++++++++++++
dlls/nvapi/nvapi.c | 462 +++++++++++++++++++++++++++++++++++++++++++
dlls/nvapi/nvapi.spec | 5 +
dlls/nvapi/tests/Makefile.in | 5 +
dlls/nvapi/tests/nvapi.c | 276 ++++++++++++++++++++++++++
@ -14,7 +14,7 @@ Subject: nvapi: First implementation.
dlls/nvapi64/nvapi64.spec | 5 +
include/Makefile.in | 1 +
include/nvapi.h | 76 +++++++
10 files changed, 839 insertions(+)
10 files changed, 842 insertions(+)
create mode 100644 dlls/nvapi/Makefile.in
create mode 100644 dlls/nvapi/nvapi.c
create mode 100644 dlls/nvapi/nvapi.spec
@ -50,10 +50,10 @@ index 0000000..606177f
+ nvapi.c
diff --git a/dlls/nvapi/nvapi.c b/dlls/nvapi/nvapi.c
new file mode 100644
index 0000000..7b352d8
index 0000000..2c7eceb
--- /dev/null
+++ b/dlls/nvapi/nvapi.c
@@ -0,0 +1,459 @@
@@ -0,0 +1,462 @@
+/*
+ * Copyright (C) 2015 Michael Müller
+ * Copyright (C) 2015 Sebastian Lackner
@ -87,6 +87,9 @@ index 0000000..7b352d8
+
+WINE_DEFAULT_DEBUG_CHANNEL(nvapi);
+
+#define FAKE_PHYSICAL_GPU ((NvPhysicalGpuHandle)0xdead0001)
+#define FAKE_DISPLAY ((NvDisplayHandle)0xdead0002)
+
+#if defined(__i386__) || defined(__x86_64__)
+
+static NvAPI_Status CDECL unimplemented_stub(unsigned int offset)
@ -296,7 +299,7 @@ index 0000000..7b352d8
+ return NVAPI_INCOMPATIBLE_STRUCT_VERSION;
+
+ param->gpu_count = 1;
+ param->gpus[0].gpuHandle = (void *)0xdead0001;
+ param->gpus[0].gpuHandle = FAKE_PHYSICAL_GPU;
+ param->gpus[0].unknown2 = 11;
+
+ return NVAPI_OK;
@ -312,7 +315,7 @@ index 0000000..7b352d8
+ if (!retHandle)
+ return NVAPI_INVALID_ARGUMENT;
+
+ if (gpuHandle == (void *)0xdead0001)
+ if (gpuHandle == FAKE_PHYSICAL_GPU)
+ *retHandle = (void *)gpuHandle;
+ else
+ {
@ -330,7 +333,7 @@ index 0000000..7b352d8
+ if (!gpuHandle || !retHandle)
+ return NVAPI_INVALID_ARGUMENT;
+
+ if (gpuHandle == (void *)0xdead0001)
+ if (gpuHandle == FAKE_PHYSICAL_GPU)
+ *retHandle = (void *)gpuHandle;
+ else
+ {
@ -350,7 +353,7 @@ index 0000000..7b352d8
+
+ TRACE("(%p, %p)\n", hNvDisplay, pVersion);
+
+ if (hNvDisplay && hNvDisplay != (void *)0xdead0002)
+ if (hNvDisplay && hNvDisplay != FAKE_DISPLAY)
+ {
+ FIXME("invalid display handle: %p\n", hNvDisplay);
+ return NVAPI_INVALID_HANDLE;
@ -371,7 +374,7 @@ index 0000000..7b352d8
+{
+ TRACE("(%s, %p)\n", szDisplayName, pNvDispHandle);
+
+ *pNvDispHandle = (void *)0xdead0002;
+ *pNvDispHandle = FAKE_DISPLAY;
+ return NVAPI_OK;
+}
+
@ -379,7 +382,7 @@ index 0000000..7b352d8
+{
+ TRACE("(%p, %p, %p)\n", hNvDisp, nvGPUHandle, pGpuCount);
+
+ nvGPUHandle[0] = (void *)0xdead0003;
+ nvGPUHandle[0] = FAKE_PHYSICAL_GPU;
+ *pGpuCount = 1;
+
+ return NVAPI_OK;

View File

@ -1,20 +1,28 @@
From 5eb5136a83fa10e0cd344a49178875ff4c34d5ad Mon Sep 17 00:00:00 2001
From 86b33d987c6b1dc948018b58a2d1a131e701805f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Wed, 7 Jan 2015 23:26:27 +0100
Subject: nvapi: Add stubs for NvAPI_EnumLogicalGPUs and undocumented
equivalent.
---
dlls/nvapi/nvapi.c | 26 ++++++++++++++++++++-
dlls/nvapi/nvapi.c | 27 ++++++++++++++++++++-
dlls/nvapi/tests/nvapi.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
include/nvapi.h | 3 +++
3 files changed, 89 insertions(+), 1 deletion(-)
3 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/dlls/nvapi/nvapi.c b/dlls/nvapi/nvapi.c
index 7b352d8..b5e7694 100644
index 2c7eceb..efd6a66 100644
--- a/dlls/nvapi/nvapi.c
+++ b/dlls/nvapi/nvapi.c
@@ -401,6 +401,28 @@ static NvAPI_Status CDECL NvAPI_D3D9_StretchRectEx(IDirect3DDevice9 *pDevice, ID
@@ -33,6 +33,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(nvapi);
#define FAKE_PHYSICAL_GPU ((NvPhysicalGpuHandle)0xdead0001)
#define FAKE_DISPLAY ((NvDisplayHandle)0xdead0002)
+#define FAKE_LOGICAL_GPU ((NvLogicalGpuHandle)0xdead0003)
#if defined(__i386__) || defined(__x86_64__)
@@ -404,6 +405,28 @@ static NvAPI_Status CDECL NvAPI_D3D9_StretchRectEx(IDirect3DDevice9 *pDevice, ID
return NVAPI_UNREGISTERED_RESOURCE;
}
@ -28,7 +36,7 @@ index 7b352d8..b5e7694 100644
+ if (!count)
+ return NVAPI_INVALID_POINTER;
+
+ gpuHandle[0] = (NvLogicalGpuHandle)0xdead0004;
+ gpuHandle[0] = FAKE_LOGICAL_GPU;
+ *count = 1;
+
+ return NVAPI_OK;
@ -43,7 +51,7 @@ index 7b352d8..b5e7694 100644
void* CDECL nvapi_QueryInterface(unsigned int offset)
{
static const struct
@@ -427,7 +449,9 @@ void* CDECL nvapi_QueryInterface(unsigned int offset)
@@ -430,7 +453,9 @@ void* CDECL nvapi_QueryInterface(unsigned int offset)
{0x451f2134, NvAPI_Stereo_GetSeparation},
{0x5c069fa3, NvAPI_Stereo_SetSeparation},
{0x239c4545, NvAPI_Stereo_Enable},
@ -55,7 +63,7 @@ index 7b352d8..b5e7694 100644
unsigned int i;
TRACE("(%x)\n", offset);
diff --git a/dlls/nvapi/tests/nvapi.c b/dlls/nvapi/tests/nvapi.c
index d760a18..d563423 100644
index d760a18..ea630f3 100644
--- a/dlls/nvapi/tests/nvapi.c
+++ b/dlls/nvapi/tests/nvapi.c
@@ -33,6 +33,8 @@
@ -71,7 +79,7 @@ index d760a18..d563423 100644
static NvAPI_Status (CDECL *pNvAPI_unknown1)(void* param0);
static NvAPI_Status (CDECL *pNvAPI_unknown2)(NvPhysicalGpuHandle gpuHandle, void *param1);
static NvAPI_Status (CDECL *pNvAPI_unknown3)(void *param0, void *param1);
+static NvAPI_Status (CDECL *pNvAPI_EnumLogicalGPUs_unknown)(void *buffer, NvU32 *gpu_count);
+static NvAPI_Status (CDECL *pNvAPI_EnumLogicalGPUs_unknown)(NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount);
+static NvAPI_Status (CDECL *pNvAPI_EnumLogicalGPUs)(NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount);
static BOOL init(void)
@ -129,7 +137,7 @@ index d760a18..d563423 100644
+
+ memset(gpuHandle1, 0, sizeof(gpuHandle1));
+
+ status = pNvAPI_EnumLogicalGPUs_unknown(&gpuHandle1, &count1);
+ status = pNvAPI_EnumLogicalGPUs_unknown(gpuHandle1, &count1);
+ ok(status == NVAPI_OK, "Expected status NVAPI_OK, got %d\n", status);
+ ok(count1 > 0, "Expected count1 > 0, got %d\n", count1);
+ for (i = 0; i < count1; i++)

View File

@ -0,0 +1,163 @@
From 91fa06cbf5f9183063232bef9d208643304ad267 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Thu, 8 Jan 2015 00:54:18 +0100
Subject: nvapi: Add NvAPI_GetPhysicalGPUsFromLogicalGPU.
---
dlls/nvapi/nvapi.c | 28 ++++++++++++++++++++++++-
dlls/nvapi/tests/nvapi.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
include/nvapi.h | 1 +
3 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/dlls/nvapi/nvapi.c b/dlls/nvapi/nvapi.c
index efd6a66..3c3f2fd 100644
--- a/dlls/nvapi/nvapi.c
+++ b/dlls/nvapi/nvapi.c
@@ -427,6 +427,31 @@ static NvAPI_Status CDECL NvAPI_EnumLogicalGPUs_unknown(NvLogicalGpuHandle gpuHa
return NvAPI_EnumLogicalGPUs(gpuHandle, count);
}
+static NvAPI_Status CDECL NvAPI_GetPhysicalGPUsFromLogicalGPU(NvLogicalGpuHandle logicalGPU,
+ NvPhysicalGpuHandle physicalGPUs[NVAPI_MAX_PHYSICAL_GPUS],
+ NvU32 *count)
+{
+ if (!physicalGPUs)
+ return NVAPI_INVALID_ARGUMENT;
+
+ if (!count)
+ return NVAPI_INVALID_POINTER;
+
+ if (!logicalGPU)
+ return NVAPI_EXPECTED_LOGICAL_GPU_HANDLE;
+
+ if (logicalGPU != FAKE_LOGICAL_GPU)
+ {
+ FIXME("invalid handle: %p\n", logicalGPU);
+ return NVAPI_EXPECTED_LOGICAL_GPU_HANDLE;
+ }
+
+ physicalGPUs[0] = FAKE_PHYSICAL_GPU;
+ *count = 1;
+
+ return NVAPI_OK;
+}
+
void* CDECL nvapi_QueryInterface(unsigned int offset)
{
static const struct
@@ -455,7 +480,8 @@ void* CDECL nvapi_QueryInterface(unsigned int offset)
{0x239c4545, NvAPI_Stereo_Enable},
{0xaeaecd41, NvAPI_D3D9_StretchRectEx},
{0x48b3ea59, NvAPI_EnumLogicalGPUs},
- {0xfb9bc2ab, NvAPI_EnumLogicalGPUs_unknown}
+ {0xfb9bc2ab, NvAPI_EnumLogicalGPUs_unknown},
+ {0xaea3fa32, NvAPI_GetPhysicalGPUsFromLogicalGPU}
};
unsigned int i;
TRACE("(%x)\n", offset);
diff --git a/dlls/nvapi/tests/nvapi.c b/dlls/nvapi/tests/nvapi.c
index ea630f3..779dc32 100644
--- a/dlls/nvapi/tests/nvapi.c
+++ b/dlls/nvapi/tests/nvapi.c
@@ -35,6 +35,7 @@
#define NvAPI_unknown3_Offset 0x5380ad1a
#define NvAPI_EnumLogicalGPUs_unknown_Offset 0xfb9bc2ab
#define NvAPI_EnumLogicalGPUs_Offset 0x48b3ea59
+#define NvAPI_GetPhysicalGPUsFromLogicalGPU_Offset 0xaea3fa32
static void* (CDECL *pnvapi_QueryInterface)(unsigned int offset);
static NvAPI_Status (CDECL *pNvAPI_Initialize)(void);
@@ -44,6 +45,7 @@ static NvAPI_Status (CDECL *pNvAPI_unknown2)(NvPhysicalGpuHandle gpuHandle, void
static NvAPI_Status (CDECL *pNvAPI_unknown3)(void *param0, void *param1);
static NvAPI_Status (CDECL *pNvAPI_EnumLogicalGPUs_unknown)(NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount);
static NvAPI_Status (CDECL *pNvAPI_EnumLogicalGPUs)(NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount);
+static NvAPI_Status (CDECL *pNvAPI_GetPhysicalGPUsFromLogicalGPU)(NvLogicalGpuHandle hLogicalGPU, NvPhysicalGpuHandle hPhysicalGPU[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
static BOOL init(void)
{
@@ -73,6 +75,7 @@ static BOOL init(void)
pNvAPI_unknown3 = pnvapi_QueryInterface(NvAPI_unknown3_Offset);
pNvAPI_EnumLogicalGPUs_unknown = pnvapi_QueryInterface(NvAPI_EnumLogicalGPUs_unknown_Offset);
pNvAPI_EnumLogicalGPUs = pnvapi_QueryInterface(NvAPI_EnumLogicalGPUs_Offset);
+ pNvAPI_GetPhysicalGPUsFromLogicalGPU = pnvapi_QueryInterface(NvAPI_GetPhysicalGPUsFromLogicalGPU_Offset);
if (!pNvAPI_Initialize)
{
@@ -324,6 +327,56 @@ static void test_NvAPI_EnumLogicalGPUs(void)
ok(gpuHandle1[i] == gpuHandle2[i], "Expected gpuHandle1[i] == gpuHandle2[i], got %p != %p\n", gpuHandle1[i], gpuHandle2[i]);
}
+static void test_NvAPI_GetPhysicalGPUsFromLogicalGPU(void)
+{
+ NvLogicalGpuHandle gpus_logical[NVAPI_MAX_LOGICAL_GPUS];
+ NvPhysicalGpuHandle gpus_physical[NVAPI_MAX_PHYSICAL_GPUS];
+ NvAPI_Status status;
+ NvU32 count1, count2;
+ int i;
+
+ if (!pNvAPI_EnumLogicalGPUs)
+ {
+ win_skip("NvAPI_EnumLogicalGPUs export not found.\n");
+ return;
+ }
+
+ if (!pNvAPI_GetPhysicalGPUsFromLogicalGPU)
+ {
+ win_skip("NvAPI_GetPhysicalGPUsFromLogicalGPU export not found.\n");
+ return;
+ }
+
+ status = pNvAPI_EnumLogicalGPUs_unknown(gpus_logical, &count1);
+ ok(status == NVAPI_OK, "Expected status NVAPI_OK, got %d\n", status);
+ ok(count1 > 0, "Expected count1 > 0, got %d\n", count1);
+
+ status = pNvAPI_GetPhysicalGPUsFromLogicalGPU(NULL, NULL, NULL);
+ ok(status == NVAPI_INVALID_ARGUMENT, "Expected status NVAPI_INVALID_ARGUMENT, got %d\n", status);
+
+ status = pNvAPI_GetPhysicalGPUsFromLogicalGPU(gpus_logical[0], NULL, NULL);
+ ok(status == NVAPI_INVALID_ARGUMENT, "Expected status NVAPI_INVALID_ARGUMENT, got %d\n", status);
+
+ status = pNvAPI_GetPhysicalGPUsFromLogicalGPU(gpus_logical[0], gpus_physical, NULL);
+ ok(status == NVAPI_INVALID_POINTER, "Expected status NVAPI_INVALID_POINTER, got %d\n", status);
+
+ status = pNvAPI_GetPhysicalGPUsFromLogicalGPU(gpus_logical[0], NULL, &count2);
+ ok(status == NVAPI_INVALID_ARGUMENT, "Expected status NVAPI_INVALID_ARGUMENT, got %d\n", status);
+
+ status = pNvAPI_GetPhysicalGPUsFromLogicalGPU(NULL, gpus_physical, &count2);
+ ok(status == NVAPI_EXPECTED_LOGICAL_GPU_HANDLE, "Expected status NVAPI_EXPECTED_LOGICAL_GPU_HANDLE, got %d\n", status);
+
+ status = pNvAPI_GetPhysicalGPUsFromLogicalGPU((void*) 0xdeadbeef, gpus_physical, &count2);
+ ok(status == NVAPI_EXPECTED_LOGICAL_GPU_HANDLE, "Expected status NVAPI_EXPECTED_LOGICAL_GPU_HANDLE, got %d\n", status);
+
+ status = pNvAPI_GetPhysicalGPUsFromLogicalGPU(gpus_logical[0], gpus_physical, &count2);
+ ok(status == NVAPI_OK, "Expected status NVAPI_OK, got %d\n", status);
+ ok(count2 > 0, "Expected count1 > 0, got %d\n", count2);
+ for (i = 0; i < count2; i++)
+ ok(gpus_physical[i] != NULL, "Expected gpus_physical[%d] not be NULL, got %p\n", i, gpus_physical[i]);
+}
+
+
START_TEST( nvapi )
{
if (!init())
@@ -334,4 +387,5 @@ START_TEST( nvapi )
test_unknown2();
test_unknown3();
test_NvAPI_EnumLogicalGPUs();
+ test_NvAPI_GetPhysicalGPUsFromLogicalGPU();
}
diff --git a/include/nvapi.h b/include/nvapi.h
index 448b0ce..e3c94d8 100644
--- a/include/nvapi.h
+++ b/include/nvapi.h
@@ -32,6 +32,7 @@ typedef unsigned int NvU32;
#define NVAPI_INVALID_HANDLE -8
#define NVAPI_INCOMPATIBLE_STRUCT_VERSION -9
#define NVAPI_INVALID_POINTER -14
+#define NVAPI_EXPECTED_LOGICAL_GPU_HANDLE -100
#define NVAPI_EXPECTED_PHYSICAL_GPU_HANDLE -101
#define NVAPI_STEREO_NOT_INITIALIZED -140
#define NVAPI_UNREGISTERED_RESOURCE -170
--
1.9.1

View File

@ -2085,9 +2085,11 @@ fi
if [ "$enable_nvapi_Stub_DLL" -eq 1 ]; then
patch_apply nvapi-Stub_DLL/0001-nvapi-First-implementation.patch
patch_apply nvapi-Stub_DLL/0002-nvapi-Add-stubs-for-NvAPI_EnumLogicalGPUs-and-undocu.patch
patch_apply nvapi-Stub_DLL/0003-nvapi-Add-NvAPI_GetPhysicalGPUsFromLogicalGPU.patch
(
echo '+ { "Michael Müller", "nvapi: First implementation.", 1 },';
echo '+ { "Michael Müller", "nvapi: Add stubs for NvAPI_EnumLogicalGPUs and undocumented equivalent.", 1 },';
echo '+ { "Michael Müller", "nvapi: Add NvAPI_GetPhysicalGPUsFromLogicalGPU.", 1 },';
) >> "$patchlist"
fi