Path: blob/21.2-virgl/src/gallium/targets/libgl-d3d12/libgl_d3d12.c
4565 views
/*1* Copyright © Microsoft Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/222324#include <windows.h>2526#include "util/u_debug.h"27#include "stw_winsys.h"28#include "stw_device.h"29#include "gdi/gdi_sw_winsys.h"3031#include "softpipe/sp_texture.h"32#include "softpipe/sp_screen.h"33#include "softpipe/sp_public.h"3435#ifndef GALLIUM_D3D1236#error "This file must be compiled only with the D3D12 driver"37#endif38#include "d3d12/wgl/d3d12_wgl_public.h"3940static struct pipe_screen *41gdi_screen_create(HDC hDC)42{43struct pipe_screen *screen = NULL;44struct sw_winsys *winsys;4546winsys = gdi_create_sw_winsys();47if(!winsys)48goto no_winsys;4950screen = d3d12_wgl_create_screen( winsys, hDC );5152if(!screen)53goto no_screen;5455return screen;5657no_screen:58winsys->destroy(winsys);59no_winsys:60return NULL;61}626364static void65gdi_present(struct pipe_screen *screen,66struct pipe_context *context,67struct pipe_resource *res,68HDC hDC)69{70d3d12_wgl_present(screen, context, res, hDC);71}727374static boolean75gdi_get_adapter_luid(struct pipe_screen *screen,76HDC hDC,77LUID *adapter_luid)78{79if (!stw_dev || !stw_dev->callbacks.pfnGetAdapterLuid)80return false;8182stw_dev->callbacks.pfnGetAdapterLuid(hDC, adapter_luid);83return true;84}858687static unsigned88gdi_get_pfd_flags(struct pipe_screen *screen)89{90return d3d12_wgl_get_pfd_flags(screen);91}929394static struct stw_winsys_framebuffer *95gdi_create_framebuffer(struct pipe_screen *screen,96HDC hDC,97int iPixelFormat)98{99return d3d12_wgl_create_framebuffer(screen, hDC, iPixelFormat);100}101102103static const struct stw_winsys stw_winsys = {104&gdi_screen_create,105&gdi_present,106&gdi_get_adapter_luid,107NULL, /* shared_surface_open */108NULL, /* shared_surface_close */109NULL, /* compose */110&gdi_get_pfd_flags,111&gdi_create_framebuffer112};113114115EXTERN_C BOOL WINAPI116DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);117118119BOOL WINAPI120DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)121{122switch (fdwReason) {123case DLL_PROCESS_ATTACH:124stw_init(&stw_winsys);125stw_init_thread();126break;127128case DLL_THREAD_ATTACH:129stw_init_thread();130break;131132case DLL_THREAD_DETACH:133stw_cleanup_thread();134break;135136case DLL_PROCESS_DETACH:137if (lpvReserved == NULL) {138// We're being unloaded from the process.139stw_cleanup_thread();140stw_cleanup();141} else {142// Process itself is terminating, and all threads and modules are143// being detached.144//145// The order threads (including llvmpipe rasterizer threads) are146// destroyed can not be relied up, so it's not safe to cleanup.147//148// However global destructors (e.g., LLVM's) will still be called, and149// if Microsoft OPENGL32.DLL's DllMain is called after us, it will150// still try to invoke DrvDeleteContext to destroys all outstanding,151// so set stw_dev to NULL to return immediately if that happens.152stw_dev = NULL;153}154break;155}156return TRUE;157}158159160