d3d12: Use u_dl instead of Windows DLL APIs
authorJesse Natalie <jenatali@microsoft.com>
Tue, 8 Dec 2020 18:56:03 +0000 (10:56 -0800)
committerMarge Bot <eric+marge@anholt.net>
Wed, 16 Dec 2020 16:25:54 +0000 (16:25 +0000)
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7937>

src/gallium/drivers/d3d12/d3d12_compiler.cpp
src/gallium/drivers/d3d12/d3d12_context.cpp
src/gallium/drivers/d3d12/d3d12_dxcore_screen.cpp
src/gallium/drivers/d3d12/d3d12_dxgi_screen.cpp
src/gallium/drivers/d3d12/d3d12_screen.cpp

index fcadf43..996ea2b 100644 (file)
@@ -40,6 +40,7 @@
 #include "util/u_memory.h"
 #include "util/u_prim.h"
 #include "util/u_simple_shaders.h"
+#include "util/u_dl.h"
 
 #include <directx/d3d12.h>
 #include <dxguids/dxguids.h>
@@ -69,9 +70,9 @@ struct d3d12_validation_tools
       ~HModule();
 
       bool load(LPCSTR file_name);
-      operator HMODULE () const;
+      operator util_dl_library *() const;
    private:
-      HMODULE module;
+      util_dl_library *module;
    };
 
    HModule dxil_module;
@@ -1141,7 +1142,7 @@ extern "C" extern IMAGE_DOS_HEADER __ImageBase;
 
 void d3d12_validation_tools::load_dxil_dll()
 {
-   if (!dxil_module.load("dxil.dll")) {
+   if (!dxil_module.load(UTIL_DL_PREFIX "dxil" UTIL_DL_EXT)) {
       char selfPath[MAX_PATH] = "";
       uint32_t pathSize = GetModuleFileNameA((HINSTANCE)&__ImageBase, selfPath, sizeof(selfPath));
       if (pathSize == 0 || pathSize == sizeof(selfPath)) {
@@ -1168,7 +1169,7 @@ void d3d12_validation_tools::load_dxil_dll()
 d3d12_validation_tools::d3d12_validation_tools()
 {
    load_dxil_dll();
-   DxcCreateInstanceProc dxil_create_func = (DxcCreateInstanceProc)GetProcAddress(dxil_module, "DxcCreateInstance");
+   DxcCreateInstanceProc dxil_create_func = (DxcCreateInstanceProc)util_dl_get_proc_address(dxil_module, "DxcCreateInstance");
    assert(dxil_create_func);
 
    HRESULT hr = dxil_create_func(CLSID_DxcValidator,  IID_PPV_ARGS(&validator));
@@ -1178,7 +1179,7 @@ d3d12_validation_tools::d3d12_validation_tools()
 
    DxcCreateInstanceProc compiler_create_func  = nullptr;
    if(dxc_compiler_module.load("dxcompiler.dll"))
-      compiler_create_func = (DxcCreateInstanceProc)GetProcAddress(dxc_compiler_module, "DxcCreateInstance");
+      compiler_create_func = (DxcCreateInstanceProc)util_dl_get_proc_address(dxc_compiler_module, "DxcCreateInstance");
 
    if (compiler_create_func) {
       hr = compiler_create_func(CLSID_DxcLibrary, IID_PPV_ARGS(&library));
@@ -1205,11 +1206,11 @@ d3d12_validation_tools::HModule::HModule():
 d3d12_validation_tools::HModule::~HModule()
 {
    if (module)
-      ::FreeLibrary(module);
+      util_dl_close(module);
 }
 
 inline
-d3d12_validation_tools::HModule::operator HMODULE () const
+d3d12_validation_tools::HModule::operator util_dl_library * () const
 {
    return module;
 }
@@ -1217,7 +1218,7 @@ d3d12_validation_tools::HModule::operator HMODULE () const
 bool
 d3d12_validation_tools::HModule::load(LPCSTR file_name)
 {
-   module = ::LoadLibrary(file_name);
+   module = util_dl_open(file_name);
    return module != nullptr;
 }
 
index 022df36..1fa1217 100644 (file)
@@ -41,6 +41,7 @@
 #include "util/u_memory.h"
 #include "util/u_upload_mgr.h"
 #include "util/u_pstipple.h"
+#include "util/u_dl.h"
 #include "nir_to_dxil.h"
 
 #include "D3D12ResourceState.h"
@@ -1936,13 +1937,13 @@ d3d12_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
    d3d12_root_signature_cache_init(ctx);
    d3d12_gs_variant_cache_init(ctx);
 
-   HMODULE hD3D12Mod = LoadLibrary("D3D12.DLL");
-   if (!hD3D12Mod) {
+   util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
+   if (!d3d12_mod) {
       debug_printf("D3D12: failed to load D3D12.DLL\n");
       return NULL;
    }
    ctx->D3D12SerializeVersionedRootSignature =
-      (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)GetProcAddress(hD3D12Mod, "D3D12SerializeVersionedRootSignature");
+      (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)util_dl_get_proc_address(d3d12_mod, "D3D12SerializeVersionedRootSignature");
 
    if (FAILED(screen->dev->CreateFence(0, D3D12_FENCE_FLAG_NONE,
                                        IID_PPV_ARGS(&ctx->cmdqueue_fence)))) {
index 58369b5..20b72ee 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "util/debug.h"
 #include "util/u_memory.h"
+#include "util/u_dl.h"
 
 #include <directx/dxcore.h>
 #include <dxguids/dxguids.h>
@@ -36,13 +37,13 @@ get_dxcore_factory()
    typedef HRESULT(WINAPI *PFN_CREATE_DXCORE_ADAPTER_FACTORY)(REFIID riid, void **ppFactory);
    PFN_CREATE_DXCORE_ADAPTER_FACTORY DXCoreCreateAdapterFactory;
 
-   HMODULE hDXCoreMod = LoadLibrary("DXCore.DLL");
-   if (!hDXCoreMod) {
+   util_dl_library *dxcore_mod = util_dl_open(UTIL_DL_PREFIX "dxcore" UTIL_DL_EXT);
+   if (!dxcore_mod) {
       debug_printf("D3D12: failed to load DXCore.DLL\n");
       return NULL;
    }
 
-   DXCoreCreateAdapterFactory = (PFN_CREATE_DXCORE_ADAPTER_FACTORY)GetProcAddress(hDXCoreMod, "DXCoreCreateAdapterFactory");
+   DXCoreCreateAdapterFactory = (PFN_CREATE_DXCORE_ADAPTER_FACTORY)util_dl_get_proc_address(dxcore_mod, "DXCoreCreateAdapterFactory");
    if (!DXCoreCreateAdapterFactory) {
       debug_printf("D3D12: failed to load DXCoreCreateAdapterFactory from DXCore.DLL\n");
       return NULL;
index 9967fa1..8cdf1e3 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "util/debug.h"
 #include "util/u_memory.h"
+#include "util/u_dl.h"
 
 #include <dxgi1_4.h>
 
@@ -40,13 +41,13 @@ get_dxgi_factory()
    typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
    PFN_CREATE_DXGI_FACTORY CreateDXGIFactory;
 
-   HMODULE hDXGIMod = LoadLibrary("DXGI.DLL");
-   if (!hDXGIMod) {
+   util_dl_library *dxgi_mod = util_dl_open(UTIL_DL_PREFIX "dxgi" UTIL_DL_EXT);
+   if (!dxgi_mod) {
       debug_printf("D3D12: failed to load DXGI.DLL\n");
       return NULL;
    }
 
-   CreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY)GetProcAddress(hDXGIMod, "CreateDXGIFactory");
+   CreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY)util_dl_get_proc_address(dxgi_mod, "CreateDXGIFactory");
    if (!CreateDXGIFactory) {
       debug_printf("D3D12: failed to load CreateDXGIFactory from DXGI.DLL\n");
       return NULL;
index f23cff1..666875e 100644 (file)
@@ -37,6 +37,7 @@
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_screen.h"
+#include "util/u_dl.h"
 
 #include "nir.h"
 #include "frontend/sw_winsys.h"
@@ -645,13 +646,13 @@ get_debug_interface()
    typedef HRESULT(WINAPI *PFN_D3D12_GET_DEBUG_INTERFACE)(REFIID riid, void **ppFactory);
    PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterface;
 
-   HMODULE hD3D12Mod = LoadLibrary("D3D12.DLL");
-   if (!hD3D12Mod) {
+   util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
+   if (!d3d12_mod) {
       debug_printf("D3D12: failed to load D3D12.DLL\n");
       return NULL;
    }
 
-   D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(hD3D12Mod, "D3D12GetDebugInterface");
+   D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)util_dl_get_proc_address(d3d12_mod, "D3D12GetDebugInterface");
    if (!D3D12GetDebugInterface) {
       debug_printf("D3D12: failed to load D3D12GetDebugInterface from D3D12.DLL\n");
       return NULL;
@@ -692,18 +693,18 @@ create_device(IUnknown *adapter)
    PFN_D3D12CREATEDEVICE D3D12CreateDevice;
    PFN_D3D12ENABLEEXPERIMENTALFEATURES D3D12EnableExperimentalFeatures;
 
-   HMODULE hD3D12Mod = LoadLibrary("D3D12.DLL");
-   if (!hD3D12Mod) {
+   util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
+   if (!d3d12_mod) {
       debug_printf("D3D12: failed to load D3D12.DLL\n");
       return NULL;
    }
 
    if (d3d12_debug & D3D12_DEBUG_EXPERIMENTAL) {
-      D3D12EnableExperimentalFeatures = (PFN_D3D12ENABLEEXPERIMENTALFEATURES)GetProcAddress(hD3D12Mod, "D3D12EnableExperimentalFeatures");
+      D3D12EnableExperimentalFeatures = (PFN_D3D12ENABLEEXPERIMENTALFEATURES)util_dl_get_proc_address(d3d12_mod, "D3D12EnableExperimentalFeatures");
       D3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModels, NULL, NULL);
    }
 
-   D3D12CreateDevice = (PFN_D3D12CREATEDEVICE)GetProcAddress(hD3D12Mod, "D3D12CreateDevice");
+   D3D12CreateDevice = (PFN_D3D12CREATEDEVICE)util_dl_get_proc_address(d3d12_mod, "D3D12CreateDevice");
    if (!D3D12CreateDevice) {
       debug_printf("D3D12: failed to load D3D12CreateDevice from D3D12.DLL\n");
       return NULL;