wgl: Refactor drivers to a libgallium_wgl.dll

I'd like to support EGL on Windows, using the same architecture as Linux.
On Linux, libgallium_dri.so is a "megadriver," containing the Mesa Gallium
state tracker, plus the actual driver implementations.

Now, on Windows, libgallium_wgl.dll is a proper OpenGL ICD, and OpenGL32.dll
is just a stub DLL which implements the wgl* APIs in terms of that ICD.

This is the more "architecturally clean" way to share the state tracker
between EGL and WGL.

Reviewed By: Bill Kristiansen <billkris@microsoft.com>

Reviewed-by: Charmaine Lee >charmainel@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12677>
This commit is contained in:
Jesse Natalie 2021-09-01 07:07:57 -07:00
parent e2bb111e02
commit f36921effe
6 changed files with 95 additions and 20 deletions

View File

@ -1,6 +1,7 @@
$env:PIGLIT_NO_FAST_SKIP = 1
Copy-Item -Path _install\bin\opengl32.dll -Destination C:\Piglit\lib\piglit\bin\opengl32.dll
Copy-Item -Path _install\bin\libgallium_wgl.dll -Destination C:\Piglit\lib\piglit\bin\libgallium_wgl.dll
# Run this using VsDevCmd.bat to ensure DXIL.dll is in %PATH%
cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=amd64 && py -3 C:\Piglit\bin\piglit.py run `"$env:PIGLIT_PROFILE`" $env:PIGLIT_OPTIONS $env:PIGLIT_TESTS .\results"

View File

@ -240,6 +240,7 @@ if with_platform_windows
else
winsys_d3d12_wgl = declare_dependency()
endif
subdir('targets/wgl')
subdir('targets/libgl-gdi')
endif
if with_tests

View File

@ -28,18 +28,16 @@ ogldef = files('opengl32.def')[0]
libopengl32 = shared_library(
'opengl32',
['libgl_gdi.c', 'stw_wgl.c'],
['stw_wgl.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, inc_gallium_winsys_sw, inc_gallium_drivers,
inc_include, inc_wgl, inc_src,
],
link_whole : [libwgl],
link_with : [
libgallium, libglsl, libmesa_gallium, libwsgdi, libglapi_static, libglapi
libgallium_wgl, libglapi_static, libglapi
],
dependencies : [
dep_ws2_32, idep_nir, idep_mesautil, driver_swrast, driver_swr,
driver_d3d12, driver_zink, winsys_d3d12_wgl
idep_mesautil
],
c_args : ['-D_GDI32_'],
link_args : opengl32_link_args,
@ -69,6 +67,7 @@ if with_tests
# The CI pipeline for MinGW doesn't support creating a window, so don't run these tests there
if with_tests and cc.get_id() != 'gcc'
wgl_test_env = environment()
wgl_test_env.append('PATH', libgallium_wgl_build_dir)
if with_shared_glapi
wgl_test_env.append('PATH', libglapi_build_dir)
endif

View File

@ -0,0 +1,26 @@
EXPORTS
DrvCopyContext
DrvCreateContext
DrvCreateLayerContext
DrvDeleteContext
DrvDescribeLayerPlane
DrvDescribePixelFormat
DrvGetLayerPaletteEntries
DrvGetProcAddress
DrvPresentBuffers
DrvRealizeLayerPalette
DrvReleaseContext
DrvSetCallbackProcs
DrvSetContext
DrvSetLayerPaletteEntries
DrvSetPixelFormat
DrvShareLists
DrvSwapBuffers
DrvSwapLayerBuffers
DrvValidateVersion
stw_get_current_context
stw_get_current_dc
stw_pixelformat_choose
stw_pixelformat_get
stw_override_opengl32_entry_points

View File

@ -0,0 +1,48 @@
# 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 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.
gallium_wgl_link_args = []
if cc.get_id() == 'gcc' and host_machine.cpu_family() != 'x86_64'
gallium_wgl_link_args += ['-Wl,--enable-stdcall-fixup']
endif
wgldef = files('gallium_wgl.def')[0]
libgallium_wgl = shared_library(
'gallium_wgl',
['wgl.c'],
vs_module_defs : wgldef,
include_directories : [
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 : [
libgallium, libglsl, libmesa_gallium, libwsgdi, libglapi_static, libglapi
],
dependencies : [
dep_ws2_32, idep_nir, idep_mesautil, driver_swrast, driver_swr,
driver_d3d12, driver_zink, winsys_d3d12_wgl
],
link_args : gallium_wgl_link_args,
name_prefix : 'lib',
install : true,
)
libgallium_wgl_build_dir = meson.current_build_dir()

View File

@ -83,7 +83,7 @@ static boolean use_zink = FALSE;
static const char *created_driver_name = NULL;
static struct pipe_screen *
gdi_screen_create_by_name(HDC hDC, const char* driver, struct sw_winsys *winsys)
wgl_screen_create_by_name(HDC hDC, const char* driver, struct sw_winsys *winsys)
{
struct pipe_screen* screen = NULL;
@ -125,7 +125,7 @@ gdi_screen_create_by_name(HDC hDC, const char* driver, struct sw_winsys *winsys)
}
static struct pipe_screen *
gdi_screen_create(HDC hDC)
wgl_screen_create(HDC hDC)
{
struct sw_winsys *winsys;
UNUSED bool sw_only = env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
@ -154,7 +154,7 @@ gdi_screen_create(HDC hDC)
* sorted list. Don't do this if GALLIUM_DRIVER is specified.
*/
for (unsigned i = 0; i < ARRAY_SIZE(drivers); ++i) {
struct pipe_screen* screen = gdi_screen_create_by_name(hDC, drivers[i], winsys);
struct pipe_screen* screen = wgl_screen_create_by_name(hDC, drivers[i], winsys);
if (screen) {
created_driver_name = drivers[i];
return screen;
@ -169,7 +169,7 @@ gdi_screen_create(HDC hDC)
static void
gdi_present(struct pipe_screen *screen,
wgl_present(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_resource *res,
HDC hDC)
@ -227,7 +227,7 @@ gdi_present(struct pipe_screen *screen,
#if WINVER >= 0xA00
static boolean
gdi_get_adapter_luid(struct pipe_screen* screen,
wgl_get_adapter_luid(struct pipe_screen* screen,
HDC hDC,
LUID* adapter_luid)
{
@ -241,7 +241,7 @@ gdi_get_adapter_luid(struct pipe_screen* screen,
static unsigned
gdi_get_pfd_flags(struct pipe_screen *screen)
wgl_get_pfd_flags(struct pipe_screen *screen)
{
#ifdef GALLIUM_D3D12
if (use_d3d12)
@ -252,7 +252,7 @@ gdi_get_pfd_flags(struct pipe_screen *screen)
static struct stw_winsys_framebuffer *
gdi_create_framebuffer(struct pipe_screen *screen,
wgl_create_framebuffer(struct pipe_screen *screen,
HDC hDC,
int iPixelFormat)
{
@ -264,26 +264,26 @@ gdi_create_framebuffer(struct pipe_screen *screen,
}
static const char *
gdi_get_name(void)
wgl_get_name(void)
{
return created_driver_name;
}
static const struct stw_winsys stw_winsys = {
&gdi_screen_create,
&gdi_present,
&wgl_screen_create,
&wgl_present,
#if WINVER >= 0xA00
&gdi_get_adapter_luid,
&wgl_get_adapter_luid,
#else
NULL, /* get_adapter_luid */
#endif
NULL, /* shared_surface_open */
NULL, /* shared_surface_close */
NULL, /* compose */
&gdi_get_pfd_flags,
&gdi_create_framebuffer,
&gdi_get_name,
&wgl_get_pfd_flags,
&wgl_create_framebuffer,
&wgl_get_name,
};