Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/targets/libgl-d3d12/libgl_d3d12.c
4565 views
1
/*
2
* Copyright © Microsoft Corporation
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
* IN THE SOFTWARE.
22
*/
23
24
25
#include <windows.h>
26
27
#include "util/u_debug.h"
28
#include "stw_winsys.h"
29
#include "stw_device.h"
30
#include "gdi/gdi_sw_winsys.h"
31
32
#include "softpipe/sp_texture.h"
33
#include "softpipe/sp_screen.h"
34
#include "softpipe/sp_public.h"
35
36
#ifndef GALLIUM_D3D12
37
#error "This file must be compiled only with the D3D12 driver"
38
#endif
39
#include "d3d12/wgl/d3d12_wgl_public.h"
40
41
static struct pipe_screen *
42
gdi_screen_create(HDC hDC)
43
{
44
struct pipe_screen *screen = NULL;
45
struct sw_winsys *winsys;
46
47
winsys = gdi_create_sw_winsys();
48
if(!winsys)
49
goto no_winsys;
50
51
screen = d3d12_wgl_create_screen( winsys, hDC );
52
53
if(!screen)
54
goto no_screen;
55
56
return screen;
57
58
no_screen:
59
winsys->destroy(winsys);
60
no_winsys:
61
return NULL;
62
}
63
64
65
static void
66
gdi_present(struct pipe_screen *screen,
67
struct pipe_context *context,
68
struct pipe_resource *res,
69
HDC hDC)
70
{
71
d3d12_wgl_present(screen, context, res, hDC);
72
}
73
74
75
static boolean
76
gdi_get_adapter_luid(struct pipe_screen *screen,
77
HDC hDC,
78
LUID *adapter_luid)
79
{
80
if (!stw_dev || !stw_dev->callbacks.pfnGetAdapterLuid)
81
return false;
82
83
stw_dev->callbacks.pfnGetAdapterLuid(hDC, adapter_luid);
84
return true;
85
}
86
87
88
static unsigned
89
gdi_get_pfd_flags(struct pipe_screen *screen)
90
{
91
return d3d12_wgl_get_pfd_flags(screen);
92
}
93
94
95
static struct stw_winsys_framebuffer *
96
gdi_create_framebuffer(struct pipe_screen *screen,
97
HDC hDC,
98
int iPixelFormat)
99
{
100
return d3d12_wgl_create_framebuffer(screen, hDC, iPixelFormat);
101
}
102
103
104
static const struct stw_winsys stw_winsys = {
105
&gdi_screen_create,
106
&gdi_present,
107
&gdi_get_adapter_luid,
108
NULL, /* shared_surface_open */
109
NULL, /* shared_surface_close */
110
NULL, /* compose */
111
&gdi_get_pfd_flags,
112
&gdi_create_framebuffer
113
};
114
115
116
EXTERN_C BOOL WINAPI
117
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
118
119
120
BOOL WINAPI
121
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
122
{
123
switch (fdwReason) {
124
case DLL_PROCESS_ATTACH:
125
stw_init(&stw_winsys);
126
stw_init_thread();
127
break;
128
129
case DLL_THREAD_ATTACH:
130
stw_init_thread();
131
break;
132
133
case DLL_THREAD_DETACH:
134
stw_cleanup_thread();
135
break;
136
137
case DLL_PROCESS_DETACH:
138
if (lpvReserved == NULL) {
139
// We're being unloaded from the process.
140
stw_cleanup_thread();
141
stw_cleanup();
142
} else {
143
// Process itself is terminating, and all threads and modules are
144
// being detached.
145
//
146
// The order threads (including llvmpipe rasterizer threads) are
147
// destroyed can not be relied up, so it's not safe to cleanup.
148
//
149
// However global destructors (e.g., LLVM's) will still be called, and
150
// if Microsoft OPENGL32.DLL's DllMain is called after us, it will
151
// still try to invoke DrvDeleteContext to destroys all outstanding,
152
// so set stw_dev to NULL to return immediately if that happens.
153
stw_dev = NULL;
154
}
155
break;
156
}
157
return TRUE;
158
}
159
160