dzn: Store the d3d12 module reference on the instance

Acked-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18306>
This commit is contained in:
Jesse Natalie
2022-08-29 12:45:14 -07:00
committed by Marge Bot
parent d2eebb670e
commit 4696aa484f
3 changed files with 31 additions and 35 deletions
+18 -6
View File
@@ -37,6 +37,7 @@
#include "util/disk_cache.h"
#include "util/macros.h"
#include "util/mesa-sha1.h"
#include "util/u_dl.h"
#include "glsl_types.h"
@@ -167,6 +168,8 @@ dzn_instance_destroy(struct dzn_instance *instance, const VkAllocationCallbacks
dzn_physical_device_destroy(pdev);
}
util_dl_close(instance->d3d12_mod);
vk_instance_finish(&instance->vk);
vk_free2(vk_default_allocator(), alloc, instance);
}
@@ -226,18 +229,27 @@ dzn_instance_create(const VkInstanceCreateInfo *pCreateInfo,
missing_validator = !instance->dxil_validator;
#endif
instance->d3d12.serialize_root_sig = d3d12_get_serialize_root_sig();
if (missing_validator) {
dzn_instance_destroy(instance, pAllocator);
return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED);
}
if (missing_validator ||
!instance->d3d12.serialize_root_sig) {
instance->d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!instance->d3d12_mod) {
dzn_instance_destroy(instance, pAllocator);
return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED);
}
instance->d3d12.serialize_root_sig = d3d12_get_serialize_root_sig(instance->d3d12_mod);
if (!instance->d3d12.serialize_root_sig) {
dzn_instance_destroy(instance, pAllocator);
return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED);
}
if (instance->debug_flags & DZN_DEBUG_D3D12)
d3d12_enable_debug_layer();
d3d12_enable_debug_layer(instance->d3d12_mod);
if (instance->debug_flags & DZN_DEBUG_GBV)
d3d12_enable_gpu_validation();
d3d12_enable_gpu_validation(instance->d3d12_mod);
instance->sync_binary_type = vk_sync_binary_get_type(&dzn_sync_type);
@@ -585,7 +597,7 @@ dzn_physical_device_get_d3d12_dev(struct dzn_physical_device *pdev)
mtx_lock(&pdev->dev_lock);
if (!pdev->dev) {
pdev->dev = d3d12_create_device(pdev->adapter, !instance->dxil_validator);
pdev->dev = d3d12_create_device(instance->d3d12_mod, pdev->adapter, !instance->dxil_validator);
dzn_physical_device_cache_caps(pdev);
dzn_physical_device_init_memory(pdev);
+6 -4
View File
@@ -75,6 +75,7 @@
#define dzn_stub() unreachable("Unsupported feature")
struct dxil_validator;
struct util_dl_library;
struct dzn_instance;
struct dzn_device;
@@ -227,16 +228,16 @@ dzn_get_shader_model(const struct dzn_physical_device *pdev);
mesa_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
d3d12_get_serialize_root_sig(void);
d3d12_get_serialize_root_sig(struct util_dl_library *d3d12_mod);
void
d3d12_enable_debug_layer(void);
d3d12_enable_debug_layer(struct util_dl_library *d3d12_mod);
void
d3d12_enable_gpu_validation(void);
d3d12_enable_gpu_validation(struct util_dl_library *d3d12_mod);
ID3D12Device2 *
d3d12_create_device(IUnknown *adapter, bool experimental_features);
d3d12_create_device(struct util_dl_library *d3d12_mod, IUnknown *adapter, bool experimental_features);
struct dzn_queue {
struct vk_queue vk;
@@ -1046,6 +1047,7 @@ struct dzn_instance {
struct vk_instance vk;
struct dxil_validator *dxil_validator;
struct util_dl_library *d3d12_mod;
struct {
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE serialize_root_sig;
} d3d12;
+7 -25
View File
@@ -297,17 +297,11 @@ dzn_translate_rect(D3D12_RECT *out,
}
static ID3D12Debug *
get_debug_interface()
get_debug_interface(struct util_dl_library *d3d12_mod)
{
typedef HRESULT(WINAPI *PFN_D3D12_GET_DEBUG_INTERFACE)(REFIID riid, void **ppFactory);
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterface;
struct util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!d3d12_mod) {
mesa_loge("failed to load D3D12\n");
return NULL;
}
D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)util_dl_get_proc_address(d3d12_mod, "D3D12GetDebugInterface");
if (!D3D12GetDebugInterface) {
mesa_loge("failed to load D3D12GetDebugInterface from D3D12.DLL\n");
@@ -324,9 +318,9 @@ get_debug_interface()
}
void
d3d12_enable_debug_layer(void)
d3d12_enable_debug_layer(struct util_dl_library *d3d12_mod)
{
ID3D12Debug *debug = get_debug_interface();
ID3D12Debug *debug = get_debug_interface(d3d12_mod);
if (debug) {
ID3D12Debug_EnableDebugLayer(debug);
ID3D12Debug_Release(debug);
@@ -334,9 +328,9 @@ d3d12_enable_debug_layer(void)
}
void
d3d12_enable_gpu_validation(void)
d3d12_enable_gpu_validation(struct util_dl_library *d3d12_mod)
{
ID3D12Debug *debug = get_debug_interface();
ID3D12Debug *debug = get_debug_interface(d3d12_mod);
if (debug) {
ID3D12Debug3 *debug3;
if (SUCCEEDED(ID3D12Debug_QueryInterface(debug,
@@ -350,17 +344,11 @@ d3d12_enable_gpu_validation(void)
}
ID3D12Device2 *
d3d12_create_device(IUnknown *adapter, bool experimental_features)
d3d12_create_device(struct util_dl_library *d3d12_mod, IUnknown *adapter, bool experimental_features)
{
typedef HRESULT(WINAPI *PFN_D3D12CREATEDEVICE)(IUnknown *, D3D_FEATURE_LEVEL, REFIID, void **);
PFN_D3D12CREATEDEVICE D3D12CreateDevice;
struct util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!d3d12_mod) {
mesa_loge("failed to load D3D12\n");
return NULL;
}
#ifdef _WIN32
if (experimental_features)
#endif
@@ -391,14 +379,8 @@ d3d12_create_device(IUnknown *adapter, bool experimental_features)
}
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
d3d12_get_serialize_root_sig(void)
d3d12_get_serialize_root_sig(struct util_dl_library *d3d12_mod)
{
struct util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!d3d12_mod) {
mesa_loge("failed to load D3D12\n");
return NULL;
}
return (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)
util_dl_get_proc_address(d3d12_mod, "D3D12SerializeVersionedRootSignature");
}