Module: Mesa Branch: main Commit: 05f0d27601287d44e145564e5b0f53959b0285b0 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=05f0d27601287d44e145564e5b0f53959b0285b0
Author: Sil Vilerino <[email protected]> Date: Wed Sep 7 13:40:44 2022 -0400 gallium/vl: Add vl_winsys_win32 support Acked-by: Emil Velikov <[email protected]> Reviewed-by: Jesse Natalie <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19063> --- src/gallium/auxiliary/meson.build | 8 ++- src/gallium/auxiliary/vl/vl_winsys.h | 7 +++ src/gallium/auxiliary/vl/vl_winsys_win32.c | 84 ++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/src/gallium/auxiliary/meson.build b/src/gallium/auxiliary/meson.build index 80052535183..820bf5ea7b1 100644 --- a/src/gallium/auxiliary/meson.build +++ b/src/gallium/auxiliary/meson.build @@ -438,8 +438,12 @@ files_libgalliumvl = files( ) vlwinsys_deps = [] -files_libgalliumvlwinsys = files('vl/vl_winsys.h', - 'vl/vl_winsys_drm.c') +files_libgalliumvlwinsys = files('vl/vl_winsys.h') +if host_machine.system() == 'windows' + files_libgalliumvlwinsys += files('vl/vl_winsys_win32.c') +else + files_libgalliumvlwinsys += files('vl/vl_winsys_drm.c') +endif if with_dri2 and with_platform_x11 files_libgalliumvlwinsys += files('vl/vl_winsys_dri.c') if with_dri3 diff --git a/src/gallium/auxiliary/vl/vl_winsys.h b/src/gallium/auxiliary/vl/vl_winsys.h index 7528eaae453..919f86c3416 100644 --- a/src/gallium/auxiliary/vl/vl_winsys.h +++ b/src/gallium/auxiliary/vl/vl_winsys.h @@ -35,6 +35,9 @@ #ifdef HAVE_X11_PLATFORM #include <X11/Xlib.h> #endif +#ifdef _WIN32 +#include <windows.h> +#endif #include "pipe/p_defines.h" #include "pipe/p_format.h" @@ -92,6 +95,9 @@ static inline struct vl_screen * vl_dri3_screen_create(void *display, int screen) { return NULL; }; #endif +#ifdef _WIN32 +struct vl_screen *vl_win32_screen_create(LUID *adapter); +#else /* Always enable the DRM vl winsys */ struct vl_screen * vl_drm_screen_create(int fd); @@ -107,5 +113,6 @@ vl_vgem_drm_screen_create(int fd); static inline struct vl_screen * vl_xlib_swrast_screen_create(void *display, int screen) { return NULL; } #endif +#endif #endif diff --git a/src/gallium/auxiliary/vl/vl_winsys_win32.c b/src/gallium/auxiliary/vl/vl_winsys_win32.c new file mode 100644 index 00000000000..1097bb2c56f --- /dev/null +++ b/src/gallium/auxiliary/vl/vl_winsys_win32.c @@ -0,0 +1,84 @@ +/* + * Copyright © Microsoft Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "pipe-loader/pipe_loader.h" +#include "pipe/p_screen.h" + +#include "util/u_memory.h" +#include "vl/vl_winsys.h" + +#include "gallium/winsys/sw/gdi/gdi_sw_winsys.h" +#include "gallium/drivers/d3d12/d3d12_public.h" + +struct vl_win32_screen +{ + struct vl_screen base; + LUID *adapter_luid; +}; + +static void +vl_win32_screen_destroy(struct vl_screen *vscreen) +{ + if (vscreen == NULL) + return; + + struct vl_win32_screen *win32_screen = (struct vl_win32_screen *) vscreen; + + if (vscreen->pscreen) + vscreen->pscreen->destroy(vscreen->pscreen); + + if (vscreen->dev) + pipe_loader_release(&vscreen->dev, 1); + + FREE(vscreen); +} + +struct vl_screen * +vl_win32_screen_create(LUID *adapter) +{ + struct vl_win32_screen *vscreen = CALLOC_STRUCT(vl_win32_screen); + if (!vscreen) + return NULL; + + struct sw_winsys* winsys = gdi_create_sw_winsys(); + if (!winsys) + goto release_pipe; + + /* If adapter is null, d3d12_create_dxcore_screen will choose one */ + vscreen->base.pscreen = d3d12_create_dxcore_screen(winsys, adapter); + + if (!vscreen->base.pscreen) + goto release_pipe; + + vscreen->adapter_luid = adapter; + + vscreen->base.destroy = vl_win32_screen_destroy; + vscreen->base.get_private = NULL; + vscreen->base.texture_from_drawable = NULL; + vscreen->base.get_dirty_area = NULL; + + return &vscreen->base; + +release_pipe: + vl_win32_screen_destroy(&vscreen->base); + return NULL; +}
