Mesa (master): d3d12: Add D3D12 WGL winsys

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Nov 18 10:43:32 UTC 2020


Module: Mesa
Branch: master
Commit: bb9cc7ede4daf1d74b2e8140008e2f1fe03b96bd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bb9cc7ede4daf1d74b2e8140008e2f1fe03b96bd

Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Fri Apr 24 16:09:07 2020 -0400

d3d12: Add D3D12 WGL winsys

Add a winsys for code paths common to the libgl-gdi and
libgl-d3d12 targets when using the D3D12 gallium driver.

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Reviewed-by: Charmaine Lee <charmainel at vmware.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7535>

---

 src/gallium/meson.build                         |  5 ++-
 src/gallium/targets/libgl-d3d12/libgl_d3d12.c   | 24 ++----------
 src/gallium/targets/libgl-d3d12/meson.build     |  4 +-
 src/gallium/targets/libgl-gdi/libgl_gdi.c       | 11 ++----
 src/gallium/targets/libgl-gdi/meson.build       |  4 +-
 src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h | 50 +++++++++++++++++++++++++
 src/gallium/winsys/d3d12/wgl/d3d12_wgl_winsys.c | 50 +++++++++++++++++++++++++
 src/gallium/winsys/d3d12/wgl/meson.build        | 32 ++++++++++++++++
 8 files changed, 146 insertions(+), 34 deletions(-)

diff --git a/src/gallium/meson.build b/src/gallium/meson.build
index 4c887fbcb62..fed719e2e38 100644
--- a/src/gallium/meson.build
+++ b/src/gallium/meson.build
@@ -217,10 +217,13 @@ if with_gallium_st_nine
 endif
 if with_platform_windows
   subdir('frontends/wgl')
-  subdir('targets/libgl-gdi')
   if with_gallium_d3d12
+    subdir('winsys/d3d12/wgl')
     subdir('targets/libgl-d3d12')
+  else
+    winsys_d3d12_wgl = declare_dependency()
   endif
+  subdir('targets/libgl-gdi')
 endif
 if with_tests
   subdir('targets/graw-null')
diff --git a/src/gallium/targets/libgl-d3d12/libgl_d3d12.c b/src/gallium/targets/libgl-d3d12/libgl_d3d12.c
index 6a284e4a77c..8789d719b58 100644
--- a/src/gallium/targets/libgl-d3d12/libgl_d3d12.c
+++ b/src/gallium/targets/libgl-d3d12/libgl_d3d12.c
@@ -36,24 +36,19 @@
 #ifndef GALLIUM_D3D12
 #error "This file must be compiled only with the D3D12 driver"
 #endif
-#include "d3d12/d3d12_public.h"
+#include "d3d12/wgl/d3d12_wgl_public.h"
 
 static struct pipe_screen *
 gdi_screen_create(HDC hDC)
 {
    struct pipe_screen *screen = NULL;
    struct sw_winsys *winsys;
-   LUID *adapter_luid = NULL, local_luid;
 
    winsys = gdi_create_sw_winsys();
    if(!winsys)
       goto no_winsys;
 
-   if (stw_dev && stw_dev->callbacks.pfnGetAdapterLuid) {
-      stw_dev->callbacks.pfnGetAdapterLuid(hDC, &local_luid);
-      adapter_luid = &local_luid;
-   }
-   screen = d3d12_create_screen( winsys, adapter_luid );
+   screen = d3d12_wgl_create_screen( winsys, hDC );
 
    if(!screen)
       goto no_screen;
@@ -72,20 +67,7 @@ gdi_present(struct pipe_screen *screen,
             struct pipe_resource *res,
             HDC hDC)
 {
-   /* This will fail if any interposing layer (trace, debug, etc) has
-    * been introduced between the state-trackers and the pipe driver.
-    *
-    * Ideally this would get replaced with a call to
-    * pipe_screen::flush_frontbuffer().
-    *
-    * Failing that, it may be necessary for intervening layers to wrap
-    * other structs such as this stw_winsys as well...
-    */
-
-   struct sw_winsys *winsys = NULL;
-   struct sw_displaytarget *dt = NULL;
-
-   screen->flush_frontbuffer(screen, res, 0, 0, hDC, NULL);
+   d3d12_wgl_present(screen, res, hDC);
 }
 
 
diff --git a/src/gallium/targets/libgl-d3d12/meson.build b/src/gallium/targets/libgl-d3d12/meson.build
index 2f60a29d7c9..0f09d96478d 100644
--- a/src/gallium/targets/libgl-d3d12/meson.build
+++ b/src/gallium/targets/libgl-d3d12/meson.build
@@ -24,11 +24,11 @@ libopenglon12 = shared_library(
   vs_module_defs : 'openglon12.def',
   include_directories : [
     inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux,
-    inc_wgl, inc_gallium_winsys_sw, inc_gallium_drivers,
+    inc_wgl, inc_gallium_winsys, inc_gallium_winsys_sw, inc_gallium_drivers,
   ],
   link_whole : [libwgl],
   link_with : [
-    libgallium, libglsl, libmesa_gallium, libwsgdi, libglapi_static, libglapi
+    libgallium, libglsl, libmesa_gallium, libwsgdi, libd3d12winsys, libglapi_static, libglapi
   ],
   dependencies : [
     dep_ws2_32, idep_nir, idep_mesautil, driver_d3d12
diff --git a/src/gallium/targets/libgl-gdi/libgl_gdi.c b/src/gallium/targets/libgl-gdi/libgl_gdi.c
index b34181dce2f..a806e64aef4 100644
--- a/src/gallium/targets/libgl-gdi/libgl_gdi.c
+++ b/src/gallium/targets/libgl-gdi/libgl_gdi.c
@@ -57,7 +57,7 @@
 #include "swr/swr_public.h"
 #endif
 #ifdef GALLIUM_D3D12
-#include "d3d12/d3d12_public.h"
+#include "d3d12/wgl/d3d12_wgl_public.h"
 #endif
 
 #ifdef GALLIUM_ZINK
@@ -117,12 +117,7 @@ gdi_screen_create(HDC hDC)
 #endif
 #ifdef GALLIUM_D3D12
    if (strcmp(driver, "d3d12") == 0) {
-      LUID* adapter_luid = NULL, local_luid;
-      if (stw_dev && stw_dev->callbacks.pfnGetAdapterLuid) {
-         stw_dev->callbacks.pfnGetAdapterLuid(hDC, &local_luid);
-         adapter_luid = &local_luid;
-      }
-      screen = d3d12_create_screen( winsys, adapter_luid );
+      screen = d3d12_wgl_create_screen( winsys, hDC );
       if (screen)
          use_d3d12 = TRUE;
    }
@@ -188,7 +183,7 @@ gdi_present(struct pipe_screen *screen,
 
 #ifdef GALLIUM_D3D12
    if (use_d3d12) {
-      screen->flush_frontbuffer(screen, res, 0, 0, hDC, NULL);
+      d3d12_wgl_present(screen, res, hDC);
       return;
    }
 #endif
diff --git a/src/gallium/targets/libgl-gdi/meson.build b/src/gallium/targets/libgl-gdi/meson.build
index 87ee9f17c69..7ed09f543da 100644
--- a/src/gallium/targets/libgl-gdi/meson.build
+++ b/src/gallium/targets/libgl-gdi/meson.build
@@ -31,7 +31,7 @@ libopengl32 = shared_library(
   ['libgl_gdi.c'],
   vs_module_defs : ogldef,
   include_directories : [
-    inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_wgl, inc_gallium_winsys_sw, inc_gallium_drivers,
+    inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_wgl, inc_gallium_winsys, inc_gallium_winsys_sw, inc_gallium_drivers,
   ],
   link_whole : [libwgl],
   link_with : [
@@ -39,7 +39,7 @@ libopengl32 = shared_library(
   ],
   dependencies : [
     dep_ws2_32, idep_nir, idep_mesautil, driver_swrast, driver_swr,
-    driver_d3d12, driver_zink
+    driver_d3d12, driver_zink, winsys_d3d12_wgl
   ],
   name_prefix : '',  # otherwise mingw will create libopengl32.dll
   install : true,
diff --git a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h
new file mode 100644
index 00000000000..8a9d1f666cd
--- /dev/null
+++ b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+#ifndef D3D12_WGL_PUBLIC_H
+#define D3D12_WGL_PUBLIC_H
+
+#include <windows.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct pipe_resource;
+struct pipe_screen;
+struct stw_winsys;
+
+struct pipe_screen *
+d3d12_wgl_create_screen(struct sw_winsys *winsys,
+                        HDC hDC);
+
+void
+d3d12_wgl_present(struct pipe_screen *screen,
+                  struct pipe_resource *res,
+                  HDC hDC);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_winsys.c b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_winsys.c
new file mode 100644
index 00000000000..6981381175e
--- /dev/null
+++ b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_winsys.c
@@ -0,0 +1,50 @@
+/*
+ * 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 "d3d12_wgl_public.h"
+#include "d3d12/d3d12_public.h"
+
+#include "stw_device.h"
+#include "stw_winsys.h"
+
+#include "pipe/p_screen.h"
+#include "util/u_memory.h"
+
+struct pipe_screen *
+d3d12_wgl_create_screen(struct sw_winsys *winsys, HDC hDC)
+{
+   LUID *adapter_luid = NULL, local_luid;
+   if (stw_dev && stw_dev->callbacks.pfnGetAdapterLuid) {
+      stw_dev->callbacks.pfnGetAdapterLuid(hDC, &local_luid);
+      adapter_luid = &local_luid;
+   }
+   return d3d12_create_screen(winsys, adapter_luid);
+}
+
+void
+d3d12_wgl_present(struct pipe_screen *screen,
+                  struct pipe_resource *res,
+                  HDC hDC)
+{
+   screen->flush_frontbuffer(screen, res, 0, 0, hDC, NULL);
+}
diff --git a/src/gallium/winsys/d3d12/wgl/meson.build b/src/gallium/winsys/d3d12/wgl/meson.build
new file mode 100644
index 00000000000..9f41560b811
--- /dev/null
+++ b/src/gallium/winsys/d3d12/wgl/meson.build
@@ -0,0 +1,32 @@
+# 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.
+
+
+libd3d12winsys = static_library(
+  'd3d12winsys',
+  files('d3d12_wgl_winsys.c'),
+  include_directories : [inc_src, inc_wgl, inc_include, inc_gallium, inc_gallium_aux, inc_gallium_drivers],
+  gnu_symbol_visibility : 'hidden',
+)
+
+winsys_d3d12_wgl = declare_dependency(
+  link_with : [libd3d12winsys],
+)



More information about the mesa-commit mailing list