Chip Davis : winemac.drv: Pass the CAMetalLayer to MoltenVK.

Alexandre Julliard julliard at winehq.org
Mon Apr 20 15:01:56 CDT 2020


Module: wine
Branch: oldstable
Commit: a6dde4d38b08ca11d5979a26747b556ca6ea5445
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=a6dde4d38b08ca11d5979a26747b556ca6ea5445

Author: Chip Davis <cdavis at codeweavers.com>
Date:   Mon Dec 16 23:58:17 2019 -0600

winemac.drv: Pass the CAMetalLayer to MoltenVK.

It isn't safe to access the view object from any thread other than the
main thread. In fact, if you try to call vkCreateMacOSSurfaceMVK() from
any other thread, MoltenVK prints out a big, scary warning telling you
not to do this! Instead, get the layer from the view ourselves and pass
that to MoltenVK. Recent versions of MoltenVK can accept either the view
or the layer.

Signed-off-by: Chip Davis <cdavis at codeweavers.com>
Signed-off-by: Ken Thomases <ken at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 606424bbbc614f720ac6190151f9fe5cc3e57005)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/winemac.drv/cocoa_window.m | 12 ++++++++++++
 dlls/winemac.drv/macdrv_cocoa.h |  2 ++
 dlls/winemac.drv/vulkan.c       |  2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m
index f43b26b8e3..0b9fd64ebb 100644
--- a/dlls/winemac.drv/cocoa_window.m
+++ b/dlls/winemac.drv/cocoa_window.m
@@ -3789,6 +3789,18 @@ macdrv_metal_view macdrv_view_create_metal_view(macdrv_view v, macdrv_metal_devi
     return (macdrv_metal_view)metalView;
 }
 
+macdrv_metal_layer macdrv_view_get_metal_layer(macdrv_metal_view v)
+{
+    WineMetalView* view = (WineMetalView*)v;
+    __block CAMetalLayer* layer;
+
+    OnMainThread(^{
+        layer = (CAMetalLayer*)view.layer;
+    });
+
+    return (macdrv_metal_layer)layer;
+}
+
 void macdrv_view_release_metal_view(macdrv_metal_view v)
 {
     WineMetalView* view = (WineMetalView*)v;
diff --git a/dlls/winemac.drv/macdrv_cocoa.h b/dlls/winemac.drv/macdrv_cocoa.h
index 011b1ffd37..da82f9dbfa 100644
--- a/dlls/winemac.drv/macdrv_cocoa.h
+++ b/dlls/winemac.drv/macdrv_cocoa.h
@@ -141,6 +141,7 @@ typedef struct macdrv_opaque_opengl_context* macdrv_opengl_context;
 #ifdef HAVE_METAL_METAL_H
 typedef struct macdrv_opaque_metal_device* macdrv_metal_device;
 typedef struct macdrv_opaque_metal_view* macdrv_metal_view;
+typedef struct macdrv_opaque_metal_layer* macdrv_metal_layer;
 #endif
 typedef struct macdrv_opaque_status_item* macdrv_status_item;
 struct macdrv_event;
@@ -538,6 +539,7 @@ extern void macdrv_remove_view_opengl_context(macdrv_view v, macdrv_opengl_conte
 extern macdrv_metal_device macdrv_create_metal_device(void) DECLSPEC_HIDDEN;
 extern void macdrv_release_metal_device(macdrv_metal_device d) DECLSPEC_HIDDEN;
 extern macdrv_metal_view macdrv_view_create_metal_view(macdrv_view v, macdrv_metal_device d) DECLSPEC_HIDDEN;
+extern macdrv_metal_layer macdrv_view_get_metal_layer(macdrv_metal_view v) DECLSPEC_HIDDEN;
 extern void macdrv_view_release_metal_view(macdrv_metal_view v) DECLSPEC_HIDDEN;
 #endif
 extern int macdrv_get_view_backing_size(macdrv_view v, int backing_size[2]) DECLSPEC_HIDDEN;
diff --git a/dlls/winemac.drv/vulkan.c b/dlls/winemac.drv/vulkan.c
index d49c9a1ab2..580002cf21 100644
--- a/dlls/winemac.drv/vulkan.c
+++ b/dlls/winemac.drv/vulkan.c
@@ -280,7 +280,7 @@ static VkResult macdrv_vkCreateWin32SurfaceKHR(VkInstance instance,
     create_info_host.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
     create_info_host.pNext = NULL;
     create_info_host.flags = 0; /* reserved */
-    create_info_host.pView = mac_surface->view;
+    create_info_host.pView = macdrv_view_get_metal_layer(mac_surface->view);
 
     res = pvkCreateMacOSSurfaceMVK(instance, &create_info_host, NULL /* allocator */, &mac_surface->surface);
     if (res != VK_SUCCESS)




More information about the wine-cvs mailing list