mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-19 05:52:11 +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");
|
||||
|
||||
Rc<DxvkDevice> result = new DxvkDevice(this,
|
||||
new vk::DeviceFn(m_vki->instance(), device),
|
||||
new vk::DeviceFn(true, m_vki->instance(), device),
|
||||
devExtensions, enabledFeatures);
|
||||
result->initResources();
|
||||
return result;
|
||||
|
@ -18,7 +18,7 @@ namespace dxvk {
|
||||
g_vrInstance.initInstanceExtensions();
|
||||
|
||||
m_vkl = new vk::LibraryFn();
|
||||
m_vki = new vk::InstanceFn(this->createInstance());
|
||||
m_vki = new vk::InstanceFn(true, this->createInstance());
|
||||
|
||||
m_adapters = this->queryAdapters();
|
||||
g_vrInstance.initDeviceExtensions(this);
|
||||
|
@ -19,8 +19,8 @@ namespace dxvk::vk {
|
||||
}
|
||||
|
||||
|
||||
InstanceLoader::InstanceLoader(VkInstance instance)
|
||||
: m_instance(instance) { }
|
||||
InstanceLoader::InstanceLoader(bool owned, VkInstance instance)
|
||||
: m_instance(instance), m_owned(owned) { }
|
||||
|
||||
|
||||
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>(
|
||||
dxvk::vk::GetInstanceProcAddr(instance, "vkGetDeviceProcAddr"))),
|
||||
m_device(device) { }
|
||||
m_device(device), m_owned(owned) { }
|
||||
|
||||
|
||||
PFN_vkVoidFunction DeviceLoader::sym(const char* name) const {
|
||||
@ -43,17 +43,19 @@ namespace dxvk::vk {
|
||||
LibraryFn::~LibraryFn() { }
|
||||
|
||||
|
||||
InstanceFn::InstanceFn(VkInstance instance)
|
||||
: InstanceLoader(instance) { }
|
||||
InstanceFn::InstanceFn(bool owned, VkInstance instance)
|
||||
: InstanceLoader(owned, instance) { }
|
||||
InstanceFn::~InstanceFn() {
|
||||
this->vkDestroyInstance(m_instance, nullptr);
|
||||
if (m_owned)
|
||||
this->vkDestroyInstance(m_instance, nullptr);
|
||||
}
|
||||
|
||||
|
||||
DeviceFn::DeviceFn(VkInstance instance, VkDevice device)
|
||||
: DeviceLoader(instance, device) { }
|
||||
DeviceFn::DeviceFn(bool owned, VkInstance instance, VkDevice device)
|
||||
: DeviceLoader(owned, instance, device) { }
|
||||
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.
|
||||
*/
|
||||
struct InstanceLoader : public RcObject {
|
||||
InstanceLoader(VkInstance instance);
|
||||
InstanceLoader(bool owned, VkInstance instance);
|
||||
PFN_vkVoidFunction sym(const char* name) const;
|
||||
VkInstance instance() const { return m_instance; }
|
||||
protected:
|
||||
const VkInstance m_instance;
|
||||
const bool m_owned;
|
||||
};
|
||||
|
||||
|
||||
@ -40,12 +41,13 @@ namespace dxvk::vk {
|
||||
* specific device.
|
||||
*/
|
||||
struct DeviceLoader : public RcObject {
|
||||
DeviceLoader(VkInstance instance, VkDevice device);
|
||||
DeviceLoader(bool owned, VkInstance instance, VkDevice device);
|
||||
PFN_vkVoidFunction sym(const char* name) const;
|
||||
VkDevice device() const { return m_device; }
|
||||
protected:
|
||||
const PFN_vkGetDeviceProcAddr m_getDeviceProcAddr;
|
||||
const VkDevice m_device;
|
||||
const bool m_owned;
|
||||
};
|
||||
|
||||
|
||||
@ -72,7 +74,7 @@ namespace dxvk::vk {
|
||||
* are independent of any Vulkan devices.
|
||||
*/
|
||||
struct InstanceFn : InstanceLoader {
|
||||
InstanceFn(VkInstance instance);
|
||||
InstanceFn(bool owned, VkInstance instance);
|
||||
~InstanceFn();
|
||||
|
||||
VULKAN_FN(vkCreateDevice);
|
||||
@ -141,7 +143,7 @@ namespace dxvk::vk {
|
||||
* This ensures that no slow dispatch code is executed.
|
||||
*/
|
||||
struct DeviceFn : DeviceLoader {
|
||||
DeviceFn(VkInstance instance, VkDevice device);
|
||||
DeviceFn(bool owned, VkInstance instance, VkDevice device);
|
||||
~DeviceFn();
|
||||
|
||||
VULKAN_FN(vkDestroyDevice);
|
||||
|
Loading…
x
Reference in New Issue
Block a user