winemac.drv: Give Apple GPUs device IDs.

This commit is contained in:
Evan Tang 2023-06-28 11:50:31 -05:00 committed by Alexandre Julliard
parent aec014fe8f
commit 731f06d97f

View file

@ -256,6 +256,37 @@ static int macdrv_get_gpu_info_from_registry_id(struct macdrv_gpu* gpu, uint64_t
return ret; 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 * 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 * 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. */ * using the integrated GPU. This is the behavior of Windows on a Mac. */
primary_device = [MTLCreateSystemDefaultDevice() autorelease]; 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; goto done;
/* Hide the integrated GPU if the system default device is a dedicated GPU */ /* 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++) 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; goto done;
if (hide_integrated && devices[i].isLowPower) if (hide_integrated && devices[i].isLowPower)