@@ -265,35 +265,62 @@ NVAPI_INTERFACE
265265NvAPI_EnumPhysicalGPUs (NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount) {
266266 if (!nvGPUHandle || !pGpuCount)
267267 return NVAPI_INVALID_ARGUMENT;
268- /*
269- * reasonable to report one fake gpu handle
270- */
271- *pGpuCount = 1 ;
272- nvGPUHandle[0 ] = (NvPhysicalGpuHandle)0xdeadbeef ;
268+
269+ auto devices = WMT::CopyAllDevices ();
270+ auto adapterCount = devices.count ();
271+ if (adapterCount > 1 ) {
272+ *pGpuCount = adapterCount;
273+ for (unsigned i = 0 ; i < adapterCount; i++) {
274+ nvGPUHandle[i] = (NvPhysicalGpuHandle)devices.object (i).registryID ();
275+ }
276+ } else {
277+ return NVAPI_NVIDIA_DEVICE_NOT_FOUND;
278+ }
279+
273280 return NVAPI_OK;
274281}
275282
276283NVAPI_INTERFACE
277284NvAPI_EnumLogicalGPUs (NvLogicalGpuHandle nvGPUHandle[NVAPI_MAX_LOGICAL_GPUS], NvU32 *pGpuCount) {
278285 if (!nvGPUHandle || !pGpuCount)
279286 return NVAPI_INVALID_ARGUMENT;
280- /*
281- * reasonable to report one fake gpu handle
282- */
283- *pGpuCount = 1 ;
284- nvGPUHandle[0 ] = (NvLogicalGpuHandle)0xdeadbeef ;
287+
288+ auto devices = WMT::CopyAllDevices ();
289+ auto adapterCount = devices.count ();
290+ if (adapterCount > 1 ) {
291+ *pGpuCount = adapterCount;
292+ for (unsigned i = 0 ; i < adapterCount; i++) {
293+ nvGPUHandle[i] = (NvLogicalGpuHandle)devices.object (i).registryID ();
294+ }
295+ } else {
296+ return NVAPI_NVIDIA_DEVICE_NOT_FOUND;
297+ }
298+
285299 return NVAPI_OK;
286300}
287301
288302NVAPI_INTERFACE
289303NvAPI_GetPhysicalGPUsFromDisplay (NvDisplayHandle hNvDisp, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount) {
290- if (!nvGPUHandle || !pGpuCount)
304+ if (!hNvDisp || ! nvGPUHandle || !pGpuCount)
291305 return NVAPI_INVALID_ARGUMENT;
292- /*
293- * reasonable to report one fake gpu handle
294- */
295- *pGpuCount = 1 ;
296- nvGPUHandle[0 ] = (NvPhysicalGpuHandle)0xdeadbeef ;
306+
307+ HMONITOR monitor = (HMONITOR)hNvDisp;
308+ if (!monitor)
309+ return NVAPI_NVIDIA_DEVICE_NOT_FOUND;
310+
311+ unsigned countDevices = 0 ;
312+ auto devices = WMT::CopyAllDevices ();
313+ auto adapterCount = devices.count ();
314+ if (adapterCount > 1 ) {
315+ for (unsigned i = 0 ; i < adapterCount; i++) {
316+ // TODO: Currently assuming all GPU instances are connected to specific monitor
317+ nvGPUHandle[countDevices++] = (NvPhysicalGpuHandle)devices.object (i).registryID ();
318+ }
319+ } else {
320+ return NVAPI_NVIDIA_DEVICE_NOT_FOUND;
321+ }
322+ *pGpuCount = countDevices;
323+
297324 return NVAPI_OK;
298325}
299326
@@ -427,7 +454,6 @@ NvAPI_Disp_HdrColorControl(NvU32 displayId, NV_HDR_COLOR_DATA *pHdrColorData) {
427454
428455NVAPI_INTERFACE
429456NvAPI_EnumNvidiaDisplayHandle (NvU32 thisEnum, NvDisplayHandle *pNvDispHandle) {
430-
431457 if (!pNvDispHandle)
432458 return NVAPI_INVALID_ARGUMENT;
433459
0 commit comments