[osx, metal] Set metal layer's device to layer.preferredDevice instead of calling MTLCreateDefaultSystemDevice(). This fixes issue 15 so we can use Discord's screen sharing while using Orca. This will need to be revisited when we want to actually use a different metal device.

This commit is contained in:
Martin Fouilleul 2023-07-07 10:41:17 +02:00
parent 806f00417e
commit 9bfae2c4e8
2 changed files with 11 additions and 5 deletions

View File

@ -153,7 +153,7 @@ mg_surface mg_surface_create_for_window(mp_window window, mg_surface_api api)
mg_surface mg_surface_create_remote(u32 width, u32 height, mg_surface_api api)
{
if(__mgData.init)
if(!__mgData.init)
{
mg_init();
}
@ -180,7 +180,7 @@ mg_surface mg_surface_create_remote(u32 width, u32 height, mg_surface_api api)
mg_surface mg_surface_create_host(mp_window window)
{
if(__mgData.init)
if(!__mgData.init)
{
mg_init();
}

View File

@ -170,12 +170,18 @@ mg_surface_data* mg_mtl_surface_create_for_window(mp_window window)
//NOTE(martin): create a mtl device and a mtl layer and
//-----------------------------------------------------------
surface->device = MTLCreateSystemDefaultDevice();
[surface->device retain];
/*WARN(martin):
Calling MTLCreateDefaultSystemDevice(), as advised by the doc, hangs Discord's screen sharing...
The workaround I found, which doesn't make sense, is to set the mtlLayer.device to mtlLayer.preferredDevice,
even if mtlLayer.preferredDevice is the same value as returned by MTLCreateDefaultSystemDevice().
This works for now and allows screen sharing while using orca, but we'll have to revisit this when we want
more control over what GPU gets used.
*/
surface->mtlLayer = [CAMetalLayer layer];
[surface->mtlLayer retain];
surface->mtlLayer.device = surface->mtlLayer.preferredDevice;
surface->device = surface->mtlLayer.device;
surface->mtlLayer.device = surface->device;
[surface->mtlLayer setOpaque:NO];
[surface->interface.layer.caLayer addSublayer: (CALayer*)surface->mtlLayer];