[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 23/26] hw/display/apple-gfx: Host GPU picking improvements
From: |
Phil Dennis-Jordan |
Subject: |
[PATCH 23/26] hw/display/apple-gfx: Host GPU picking improvements |
Date: |
Mon, 15 Jul 2024 23:07:02 +0200 |
During startup of the PV graphics device, we need to specify the
host GPU to use for PV acceleration of the guest's graphics
operations.
On a host system, this is trivial: pick the only one. The
MTLCreateSystemDefaultDevice() function will do the right thing
in this case.
It gets a little more complicated on systems with more than one
GPU; first and foremost, this applies to x86-64 MacBook Pros
with 15/16" displays. However, with eGPUs, in theory any x86-64
Mac can gain one or more additional GPUs. In these cases, the
default is often not ideal - usually, discrete GPUs are selected.
In my tests, performance tends to be best with iGPUs, however,
and they are usually also best in terms of energy consumption.
Ideally, we will want to allow the user to manually select a GPU
if they so choose. In this patch, I am interested in picking a
sensible default. Instead of the built-in default logic, it is
now:
1. Select a GPU with unified memory (iGPU)
2. If (1) fails, select a GPU that is built-in, not an eGPU.
3. If (2) fails, fall back to system default.
Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
hw/display/apple-gfx.m | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m
index cbcbaf0006..6c92f2579b 100644
--- a/hw/display/apple-gfx.m
+++ b/hw/display/apple-gfx.m
@@ -502,6 +502,32 @@ static void
apple_gfx_register_task_mapping_handlers(AppleGFXState *s,
return mode_array;
}
+static id<MTLDevice> copy_suitable_metal_device(void)
+{
+ id<MTLDevice> dev = nil;
+ NSArray<id<MTLDevice>> *devs = MTLCopyAllDevices();
+
+ /* Prefer a unified memory GPU. Failing that, pick a non-removable GPU. */
+ for (size_t i = 0; i < devs.count; ++i) {
+ if (devs[i].hasUnifiedMemory) {
+ dev = devs[i];
+ break;
+ }
+ if (!devs[i].removable) {
+ dev = devs[i];
+ }
+ }
+
+ if (dev != nil) {
+ [dev retain];
+ } else {
+ dev = MTLCreateSystemDefaultDevice();
+ }
+ [devs release];
+
+ return dev;
+}
+
void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc)
{
PGDisplayDescriptor *disp_desc = nil;
@@ -509,7 +535,7 @@ void apple_gfx_common_realize(AppleGFXState *s,
PGDeviceDescriptor *desc)
QTAILQ_INIT(&s->tasks);
s->render_queue = dispatch_queue_create("apple-gfx.render",
DISPATCH_QUEUE_SERIAL);
- s->mtl = MTLCreateSystemDefaultDevice();
+ s->mtl = copy_suitable_metal_device();
s->mtl_queue = [s->mtl newCommandQueue];
desc.device = s->mtl;
--
2.39.3 (Apple Git-146)
- Re: hw/display/apple-gfx, (continued)
Re:, Phil Dennis-Jordan, 2024/07/17
[PATCH 09/26] hw/display/apple-gfx: Wraps ObjC autorelease code in pool, Phil Dennis-Jordan, 2024/07/17
[PATCH 10/26] hw/display/apple-gfx: Fixes ObjC new/init misuse, plugs leaks, Phil Dennis-Jordan, 2024/07/17
[PATCH 08/26] hw/display/apple-gfx: Adds migration blocker, Phil Dennis-Jordan, 2024/07/17
[PATCH 24/26] hw/display/apple-gfx: Adds configurable mode list, Phil Dennis-Jordan, 2024/07/17
[PATCH 25/26] MAINTAINERS: Add myself as maintainer for apple-gfx, reviewer for HVF, Phil Dennis-Jordan, 2024/07/17
[PATCH 21/26] hw/display/apple-gfx: Implements texture syncing for non-UMA GPUs, Phil Dennis-Jordan, 2024/07/17
[PATCH 04/26] hw/display/apple-gfx: uses DEFINE_TYPES macro, Phil Dennis-Jordan, 2024/07/17
[PATCH 23/26] hw/display/apple-gfx: Host GPU picking improvements,
Phil Dennis-Jordan <=
[PATCH 01/26] hw/vmapple/apple-gfx: Introduce ParavirtualizedGraphics.Framework support, Phil Dennis-Jordan, 2024/07/17
[PATCH 02/26] hw/vmapple/apple-gfx: BQL renaming update, Phil Dennis-Jordan, 2024/07/17
[PATCH 05/26] hw/display/apple-gfx: native -> little endian memory ops, Phil Dennis-Jordan, 2024/07/17
[PATCH 07/26] hw/display/apple-gfx: Makes set_mode thread & memory safe, Phil Dennis-Jordan, 2024/07/17
[PATCH 20/26] hw/display/apple-gfx: Fixes cursor hotspot handling, Phil Dennis-Jordan, 2024/07/17
[PATCH 06/26] hw/display/apple-gfx: Removes dead/superfluous code, Phil Dennis-Jordan, 2024/07/17
[PATCH 17/26] hw/display/apple-gfx: Asynchronous rendering and graphics update, Phil Dennis-Jordan, 2024/07/17
[PATCH 13/26] hw/display/apple-gfx: Defines PGTask_s struct instead of casting, Phil Dennis-Jordan, 2024/07/17
[PATCH 16/26] hw/display/apple-gfx: Asynchronous MMIO writes on x86-64, Phil Dennis-Jordan, 2024/07/17