Module: wine
Branch: master
Commit: 731f06d97f810063b7b7c613b26db32a091af8a5
URL: https://gitlab.winehq.org/wine/wine/-/commit/731f06d97f810063b7b7c613b26db3…
Author: Evan Tang <etang(a)codeweavers.com>
Date: Wed Jun 28 11:50:31 2023 -0500
winemac.drv: Give Apple GPUs device IDs.
---
dlls/winemac.drv/cocoa_display.m | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_display.m b/dlls/winemac.drv/cocoa_display.m
index b5096a39ca4..b2608bafcd0 100644
--- a/dlls/winemac.drv/cocoa_display.m
+++ b/dlls/winemac.drv/cocoa_display.m
@@ -256,6 +256,37 @@ static int macdrv_get_gpu_info_from_registry_id(struct macdrv_gpu* gpu, uint64_t
return ret;
}
+/***********************************************************************
+ * macdrv_get_gpu_info_from_mtldevice
+ *
+ * Get GPU information from a Metal device that responds to the registryID selector.
+ *
+ * Returns non-zero value on failure.
+ */
+static int macdrv_get_gpu_info_from_mtldevice(struct macdrv_gpu* gpu, id<MTLDevice> device)
+{
+ int ret;
+ if ((ret = macdrv_get_gpu_info_from_registry_id(gpu, [device registryID])))
+ return ret;
+ /* Apple GPUs aren't PCI devices and therefore have no device ID
+ * Use the Metal GPUFamily as the device ID */
+ if (!gpu->device_id && [device respondsToSelector:@selector(supportsFamily:)] && [device supportsFamily:MTLGPUFamilyApple1])
+ {
+ MTLGPUFamily highest = MTLGPUFamilyApple1;
+ while (1)
+ {
+ /* Apple2, etc are all in order */
+ MTLGPUFamily next = highest + 1;
+ if ([device supportsFamily:next])
+ highest = next;
+ else
+ break;
+ }
+ gpu->device_id = highest;
+ }
+ return 0;
+}
+
/***********************************************************************
* macdrv_get_gpus_from_metal
*
@@ -289,7 +320,7 @@ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count)
* the primary GPU because we need to hide the integrated GPU for an automatic graphic switching pair to avoid apps
* using the integrated GPU. This is the behavior of Windows on a Mac. */
primary_device = [MTLCreateSystemDefaultDevice() autorelease];
- if (macdrv_get_gpu_info_from_registry_id(&primary_gpu, primary_device.registryID))
+ if (macdrv_get_gpu_info_from_mtldevice(&primary_gpu, primary_device))
goto done;
/* Hide the integrated GPU if the system default device is a dedicated GPU */
@@ -301,7 +332,7 @@ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count)
for (i = 0; i < devices.count; i++)
{
- if (macdrv_get_gpu_info_from_registry_id(&gpus[gpu_count], devices[i].registryID))
+ if (macdrv_get_gpu_info_from_mtldevice(&gpus[gpu_count], devices[i]))
goto done;
if (hide_integrated && devices[i].isLowPower)