d3d12: Use u_dl instead of Windows DLL APIs

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7937>
This commit is contained in:
Jesse Natalie
2020-12-08 10:56:03 -08:00
committed by Marge Bot
parent 29ccbd9b1e
commit dfeb5ecd4a
5 changed files with 29 additions and 24 deletions

View File

@@ -40,6 +40,7 @@
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_prim.h" #include "util/u_prim.h"
#include "util/u_simple_shaders.h" #include "util/u_simple_shaders.h"
#include "util/u_dl.h"
#include <directx/d3d12.h> #include <directx/d3d12.h>
#include <dxguids/dxguids.h> #include <dxguids/dxguids.h>
@@ -69,9 +70,9 @@ struct d3d12_validation_tools
~HModule(); ~HModule();
bool load(LPCSTR file_name); bool load(LPCSTR file_name);
operator HMODULE () const; operator util_dl_library *() const;
private: private:
HMODULE module; util_dl_library *module;
}; };
HModule dxil_module; HModule dxil_module;
@@ -1141,7 +1142,7 @@ extern "C" extern IMAGE_DOS_HEADER __ImageBase;
void d3d12_validation_tools::load_dxil_dll() 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] = ""; char selfPath[MAX_PATH] = "";
uint32_t pathSize = GetModuleFileNameA((HINSTANCE)&__ImageBase, selfPath, sizeof(selfPath)); uint32_t pathSize = GetModuleFileNameA((HINSTANCE)&__ImageBase, selfPath, sizeof(selfPath));
if (pathSize == 0 || pathSize == 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() d3d12_validation_tools::d3d12_validation_tools()
{ {
load_dxil_dll(); 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); assert(dxil_create_func);
HRESULT hr = dxil_create_func(CLSID_DxcValidator, IID_PPV_ARGS(&validator)); 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; DxcCreateInstanceProc compiler_create_func = nullptr;
if(dxc_compiler_module.load("dxcompiler.dll")) 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) { if (compiler_create_func) {
hr = compiler_create_func(CLSID_DxcLibrary, IID_PPV_ARGS(&library)); hr = compiler_create_func(CLSID_DxcLibrary, IID_PPV_ARGS(&library));
@@ -1205,11 +1206,11 @@ d3d12_validation_tools::HModule::HModule():
d3d12_validation_tools::HModule::~HModule() d3d12_validation_tools::HModule::~HModule()
{ {
if (module) if (module)
::FreeLibrary(module); util_dl_close(module);
} }
inline inline
d3d12_validation_tools::HModule::operator HMODULE () const d3d12_validation_tools::HModule::operator util_dl_library * () const
{ {
return module; return module;
} }
@@ -1217,7 +1218,7 @@ d3d12_validation_tools::HModule::operator HMODULE () const
bool bool
d3d12_validation_tools::HModule::load(LPCSTR file_name) d3d12_validation_tools::HModule::load(LPCSTR file_name)
{ {
module = ::LoadLibrary(file_name); module = util_dl_open(file_name);
return module != nullptr; return module != nullptr;
} }

View File

@@ -41,6 +41,7 @@
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_upload_mgr.h" #include "util/u_upload_mgr.h"
#include "util/u_pstipple.h" #include "util/u_pstipple.h"
#include "util/u_dl.h"
#include "nir_to_dxil.h" #include "nir_to_dxil.h"
#include "D3D12ResourceState.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_root_signature_cache_init(ctx);
d3d12_gs_variant_cache_init(ctx); d3d12_gs_variant_cache_init(ctx);
HMODULE hD3D12Mod = LoadLibrary("D3D12.DLL"); util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!hD3D12Mod) { if (!d3d12_mod) {
debug_printf("D3D12: failed to load D3D12.DLL\n"); debug_printf("D3D12: failed to load D3D12.DLL\n");
return NULL; return NULL;
} }
ctx->D3D12SerializeVersionedRootSignature = 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, if (FAILED(screen->dev->CreateFence(0, D3D12_FENCE_FLAG_NONE,
IID_PPV_ARGS(&ctx->cmdqueue_fence)))) { IID_PPV_ARGS(&ctx->cmdqueue_fence)))) {

View File

@@ -26,6 +26,7 @@
#include "util/debug.h" #include "util/debug.h"
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_dl.h"
#include <directx/dxcore.h> #include <directx/dxcore.h>
#include <dxguids/dxguids.h> #include <dxguids/dxguids.h>
@@ -36,13 +37,13 @@ get_dxcore_factory()
typedef HRESULT(WINAPI *PFN_CREATE_DXCORE_ADAPTER_FACTORY)(REFIID riid, void **ppFactory); typedef HRESULT(WINAPI *PFN_CREATE_DXCORE_ADAPTER_FACTORY)(REFIID riid, void **ppFactory);
PFN_CREATE_DXCORE_ADAPTER_FACTORY DXCoreCreateAdapterFactory; PFN_CREATE_DXCORE_ADAPTER_FACTORY DXCoreCreateAdapterFactory;
HMODULE hDXCoreMod = LoadLibrary("DXCore.DLL"); util_dl_library *dxcore_mod = util_dl_open(UTIL_DL_PREFIX "dxcore" UTIL_DL_EXT);
if (!hDXCoreMod) { if (!dxcore_mod) {
debug_printf("D3D12: failed to load DXCore.DLL\n"); debug_printf("D3D12: failed to load DXCore.DLL\n");
return NULL; 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) { if (!DXCoreCreateAdapterFactory) {
debug_printf("D3D12: failed to load DXCoreCreateAdapterFactory from DXCore.DLL\n"); debug_printf("D3D12: failed to load DXCoreCreateAdapterFactory from DXCore.DLL\n");
return NULL; return NULL;

View File

@@ -26,6 +26,7 @@
#include "util/debug.h" #include "util/debug.h"
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_dl.h"
#include <dxgi1_4.h> #include <dxgi1_4.h>
@@ -40,13 +41,13 @@ get_dxgi_factory()
typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory); typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
PFN_CREATE_DXGI_FACTORY CreateDXGIFactory; PFN_CREATE_DXGI_FACTORY CreateDXGIFactory;
HMODULE hDXGIMod = LoadLibrary("DXGI.DLL"); util_dl_library *dxgi_mod = util_dl_open(UTIL_DL_PREFIX "dxgi" UTIL_DL_EXT);
if (!hDXGIMod) { if (!dxgi_mod) {
debug_printf("D3D12: failed to load DXGI.DLL\n"); debug_printf("D3D12: failed to load DXGI.DLL\n");
return NULL; 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) { if (!CreateDXGIFactory) {
debug_printf("D3D12: failed to load CreateDXGIFactory from DXGI.DLL\n"); debug_printf("D3D12: failed to load CreateDXGIFactory from DXGI.DLL\n");
return NULL; return NULL;

View File

@@ -37,6 +37,7 @@
#include "util/u_math.h" #include "util/u_math.h"
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_screen.h" #include "util/u_screen.h"
#include "util/u_dl.h"
#include "nir.h" #include "nir.h"
#include "frontend/sw_winsys.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); typedef HRESULT(WINAPI *PFN_D3D12_GET_DEBUG_INTERFACE)(REFIID riid, void **ppFactory);
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterface; PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterface;
HMODULE hD3D12Mod = LoadLibrary("D3D12.DLL"); util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!hD3D12Mod) { if (!d3d12_mod) {
debug_printf("D3D12: failed to load D3D12.DLL\n"); debug_printf("D3D12: failed to load D3D12.DLL\n");
return NULL; 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) { if (!D3D12GetDebugInterface) {
debug_printf("D3D12: failed to load D3D12GetDebugInterface from D3D12.DLL\n"); debug_printf("D3D12: failed to load D3D12GetDebugInterface from D3D12.DLL\n");
return NULL; return NULL;
@@ -692,18 +693,18 @@ create_device(IUnknown *adapter)
PFN_D3D12CREATEDEVICE D3D12CreateDevice; PFN_D3D12CREATEDEVICE D3D12CreateDevice;
PFN_D3D12ENABLEEXPERIMENTALFEATURES D3D12EnableExperimentalFeatures; PFN_D3D12ENABLEEXPERIMENTALFEATURES D3D12EnableExperimentalFeatures;
HMODULE hD3D12Mod = LoadLibrary("D3D12.DLL"); util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!hD3D12Mod) { if (!d3d12_mod) {
debug_printf("D3D12: failed to load D3D12.DLL\n"); debug_printf("D3D12: failed to load D3D12.DLL\n");
return NULL; return NULL;
} }
if (d3d12_debug & D3D12_DEBUG_EXPERIMENTAL) { 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); D3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModels, NULL, NULL);
} }
D3D12CreateDevice = (PFN_D3D12CREATEDEVICE)GetProcAddress(hD3D12Mod, "D3D12CreateDevice"); D3D12CreateDevice = (PFN_D3D12CREATEDEVICE)util_dl_get_proc_address(d3d12_mod, "D3D12CreateDevice");
if (!D3D12CreateDevice) { if (!D3D12CreateDevice) {
debug_printf("D3D12: failed to load D3D12CreateDevice from D3D12.DLL\n"); debug_printf("D3D12: failed to load D3D12CreateDevice from D3D12.DLL\n");
return NULL; return NULL;