mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[dxvk] Track device / instance ownership
This allows us to use the Vulkan function loader for a vkd3d device.
This commit is contained in:
parent
175385481e
commit
45a234607a
@ -278,7 +278,7 @@ namespace dxvk {
|
|||||||
throw DxvkError("DxvkAdapter: Failed to create device");
|
throw DxvkError("DxvkAdapter: Failed to create device");
|
||||||
|
|
||||||
Rc<DxvkDevice> result = new DxvkDevice(this,
|
Rc<DxvkDevice> result = new DxvkDevice(this,
|
||||||
new vk::DeviceFn(m_vki->instance(), device),
|
new vk::DeviceFn(true, m_vki->instance(), device),
|
||||||
devExtensions, enabledFeatures);
|
devExtensions, enabledFeatures);
|
||||||
result->initResources();
|
result->initResources();
|
||||||
return result;
|
return result;
|
||||||
|
@ -18,7 +18,7 @@ namespace dxvk {
|
|||||||
g_vrInstance.initInstanceExtensions();
|
g_vrInstance.initInstanceExtensions();
|
||||||
|
|
||||||
m_vkl = new vk::LibraryFn();
|
m_vkl = new vk::LibraryFn();
|
||||||
m_vki = new vk::InstanceFn(this->createInstance());
|
m_vki = new vk::InstanceFn(true, this->createInstance());
|
||||||
|
|
||||||
m_adapters = this->queryAdapters();
|
m_adapters = this->queryAdapters();
|
||||||
g_vrInstance.initDeviceExtensions(this);
|
g_vrInstance.initDeviceExtensions(this);
|
||||||
|
@ -19,8 +19,8 @@ namespace dxvk::vk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InstanceLoader::InstanceLoader(VkInstance instance)
|
InstanceLoader::InstanceLoader(bool owned, VkInstance instance)
|
||||||
: m_instance(instance) { }
|
: m_instance(instance), m_owned(owned) { }
|
||||||
|
|
||||||
|
|
||||||
PFN_vkVoidFunction InstanceLoader::sym(const char* name) const {
|
PFN_vkVoidFunction InstanceLoader::sym(const char* name) const {
|
||||||
@ -28,10 +28,10 @@ namespace dxvk::vk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceLoader::DeviceLoader(VkInstance instance, VkDevice device)
|
DeviceLoader::DeviceLoader(bool owned, VkInstance instance, VkDevice device)
|
||||||
: m_getDeviceProcAddr(reinterpret_cast<PFN_vkGetDeviceProcAddr>(
|
: m_getDeviceProcAddr(reinterpret_cast<PFN_vkGetDeviceProcAddr>(
|
||||||
dxvk::vk::GetInstanceProcAddr(instance, "vkGetDeviceProcAddr"))),
|
dxvk::vk::GetInstanceProcAddr(instance, "vkGetDeviceProcAddr"))),
|
||||||
m_device(device) { }
|
m_device(device), m_owned(owned) { }
|
||||||
|
|
||||||
|
|
||||||
PFN_vkVoidFunction DeviceLoader::sym(const char* name) const {
|
PFN_vkVoidFunction DeviceLoader::sym(const char* name) const {
|
||||||
@ -43,17 +43,19 @@ namespace dxvk::vk {
|
|||||||
LibraryFn::~LibraryFn() { }
|
LibraryFn::~LibraryFn() { }
|
||||||
|
|
||||||
|
|
||||||
InstanceFn::InstanceFn(VkInstance instance)
|
InstanceFn::InstanceFn(bool owned, VkInstance instance)
|
||||||
: InstanceLoader(instance) { }
|
: InstanceLoader(owned, instance) { }
|
||||||
InstanceFn::~InstanceFn() {
|
InstanceFn::~InstanceFn() {
|
||||||
this->vkDestroyInstance(m_instance, nullptr);
|
if (m_owned)
|
||||||
|
this->vkDestroyInstance(m_instance, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceFn::DeviceFn(VkInstance instance, VkDevice device)
|
DeviceFn::DeviceFn(bool owned, VkInstance instance, VkDevice device)
|
||||||
: DeviceLoader(instance, device) { }
|
: DeviceLoader(owned, instance, device) { }
|
||||||
DeviceFn::~DeviceFn() {
|
DeviceFn::~DeviceFn() {
|
||||||
this->vkDestroyDevice(m_device, nullptr);
|
if (m_owned)
|
||||||
|
this->vkDestroyDevice(m_device, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -25,11 +25,12 @@ namespace dxvk::vk {
|
|||||||
* called for a specific instance.
|
* called for a specific instance.
|
||||||
*/
|
*/
|
||||||
struct InstanceLoader : public RcObject {
|
struct InstanceLoader : public RcObject {
|
||||||
InstanceLoader(VkInstance instance);
|
InstanceLoader(bool owned, VkInstance instance);
|
||||||
PFN_vkVoidFunction sym(const char* name) const;
|
PFN_vkVoidFunction sym(const char* name) const;
|
||||||
VkInstance instance() const { return m_instance; }
|
VkInstance instance() const { return m_instance; }
|
||||||
protected:
|
protected:
|
||||||
const VkInstance m_instance;
|
const VkInstance m_instance;
|
||||||
|
const bool m_owned;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -40,12 +41,13 @@ namespace dxvk::vk {
|
|||||||
* specific device.
|
* specific device.
|
||||||
*/
|
*/
|
||||||
struct DeviceLoader : public RcObject {
|
struct DeviceLoader : public RcObject {
|
||||||
DeviceLoader(VkInstance instance, VkDevice device);
|
DeviceLoader(bool owned, VkInstance instance, VkDevice device);
|
||||||
PFN_vkVoidFunction sym(const char* name) const;
|
PFN_vkVoidFunction sym(const char* name) const;
|
||||||
VkDevice device() const { return m_device; }
|
VkDevice device() const { return m_device; }
|
||||||
protected:
|
protected:
|
||||||
const PFN_vkGetDeviceProcAddr m_getDeviceProcAddr;
|
const PFN_vkGetDeviceProcAddr m_getDeviceProcAddr;
|
||||||
const VkDevice m_device;
|
const VkDevice m_device;
|
||||||
|
const bool m_owned;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +74,7 @@ namespace dxvk::vk {
|
|||||||
* are independent of any Vulkan devices.
|
* are independent of any Vulkan devices.
|
||||||
*/
|
*/
|
||||||
struct InstanceFn : InstanceLoader {
|
struct InstanceFn : InstanceLoader {
|
||||||
InstanceFn(VkInstance instance);
|
InstanceFn(bool owned, VkInstance instance);
|
||||||
~InstanceFn();
|
~InstanceFn();
|
||||||
|
|
||||||
VULKAN_FN(vkCreateDevice);
|
VULKAN_FN(vkCreateDevice);
|
||||||
@ -141,7 +143,7 @@ namespace dxvk::vk {
|
|||||||
* This ensures that no slow dispatch code is executed.
|
* This ensures that no slow dispatch code is executed.
|
||||||
*/
|
*/
|
||||||
struct DeviceFn : DeviceLoader {
|
struct DeviceFn : DeviceLoader {
|
||||||
DeviceFn(VkInstance instance, VkDevice device);
|
DeviceFn(bool owned, VkInstance instance, VkDevice device);
|
||||||
~DeviceFn();
|
~DeviceFn();
|
||||||
|
|
||||||
VULKAN_FN(vkDestroyDevice);
|
VULKAN_FN(vkDestroyDevice);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user