Skip to content

Commit 0112ff7

Browse files
committed
Defer proxy deletion until after driver vk*Destroy
1 parent cf5fd87 commit 0112ff7

File tree

21 files changed

+184
-76
lines changed

21 files changed

+184
-76
lines changed

generator/vk_layer/source/device.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,15 @@ Device* Device::retrieve(
7979
}
8080

8181
/* See header for documentation. */
82-
void Device::destroy(
83-
Device* device
82+
std::unique_ptr<Device> Device::destroy(
83+
VkDevice handle
8484
) {
85-
g_devices.erase(getDispatchKey(device));
85+
void* key = getDispatchKey(handle);
86+
assert(isInMap(key, g_devices));
87+
88+
auto device = std::move(g_devices.at(key));
89+
g_devices.erase(key);
90+
return device;
8691
}
8792

8893
/* See header for documentation. */

generator/vk_layer/source/device.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ class Device
115115
VkCommandBuffer handle);
116116

117117
/**
118-
* @brief Drop a device from the global store of dispatchable devices.
118+
* \brief Drop a device from the global store of dispatchable devices.
119119
*
120-
* @param device The device to drop.
120+
* This must be called before the driver VkDevice has been destroyed, as
121+
* we deference the native device handle to get the dispatch key.
122+
*
123+
* \param handle The dispatchable device handle to use as an indirect lookup.
124+
*
125+
* \return Returns the ownership of the Device object to the caller.
121126
*/
122-
static void destroy(
123-
Device* device);
127+
static std::unique_ptr<Device> destroy(
128+
VkDevice handle);
124129

125130
/**
126131
* @brief Create a new layer device object.

generator/vk_layer/source/instance.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@ Instance* Instance::retrieve(
7070
}
7171

7272
/* See header for documentation. */
73-
void Instance::destroy(
74-
Instance* instance
73+
std::unique_ptr<Instance> Instance::destroy(
74+
VkInstance handle
7575
) {
76-
g_instances.erase(getDispatchKey(instance->instance));
76+
void* key = getDispatchKey(handle);
77+
assert(isInMap(key, g_instances));
78+
79+
auto instance = std::move(g_instances.at(key));
80+
g_instances.erase(key);
81+
return instance;
7782
}
7883

7984
/* See header for documentation. */

generator/vk_layer/source/instance.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,17 @@ class Instance
9999
VkPhysicalDevice handle);
100100

101101
/**
102-
* @brief Drop an instance from the global store of dispatchable instances.
102+
* \brief Drop an instance from the global store of dispatchable instances.
103103
*
104-
* @param instance The instance to drop.
104+
* This must be called before the driver VkInstance has been destroyed, as
105+
* we deference the native instance handle to get the dispatch key.
106+
*
107+
* \param handle The dispatchable instance handle to use as an indirect lookup.
108+
*
109+
* \return Returns the ownership of the Instance object to the caller.
105110
*/
106-
static void destroy(
107-
Instance* instance);
111+
static std::unique_ptr<Instance> destroy(
112+
VkInstance handle);
108113

109114
/**
110115
* @brief Create a new layer instance object.

layer_example/source/device.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@ Device* Device::retrieve(VkCommandBuffer handle)
7575
}
7676

7777
/* See header for documentation. */
78-
void Device::destroy(Device* device)
79-
{
80-
g_devices.erase(getDispatchKey(device));
78+
std::unique_ptr<Device> Device::destroy(
79+
VkDevice handle
80+
) {
81+
void* key = getDispatchKey(handle);
82+
assert(isInMap(key, g_devices));
83+
84+
auto device = std::move(g_devices.at(key));
85+
g_devices.erase(key);
86+
return device;
8187
}
8288

8389
/* See header for documentation. */

layer_example/source/device.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ class Device
110110
static Device* retrieve(VkCommandBuffer handle);
111111

112112
/**
113-
* @brief Drop a device from the global store of dispatchable devices.
113+
* \brief Drop a device from the global store of dispatchable devices.
114114
*
115-
* @param device The device to drop.
115+
* This must be called before the driver VkDevice has been destroyed, as
116+
* we deference the native device handle to get the dispatch key.
117+
*
118+
* \param handle The dispatchable device handle to use as an indirect lookup.
119+
*
120+
* \return Returns the ownership of the Device object to the caller.
116121
*/
117-
static void destroy(Device* device);
122+
static std::unique_ptr<Device> destroy(
123+
VkDevice handle);
118124

119125
/**
120126
* @brief Create a new layer device object.

layer_example/source/instance.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ Instance* Instance::retrieve(VkPhysicalDevice handle)
6464
}
6565

6666
/* See header for documentation. */
67-
void Instance::destroy(Instance* instance)
68-
{
69-
g_instances.erase(getDispatchKey(instance->instance));
67+
std::unique_ptr<Instance> Instance::destroy(
68+
VkInstance handle
69+
) {
70+
void* key = getDispatchKey(handle);
71+
assert(isInMap(key, g_instances));
72+
73+
auto instance = std::move(g_instances.at(key));
74+
g_instances.erase(key);
75+
return instance;
7076
}
7177

7278
/* See header for documentation. */

layer_example/source/instance.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ class Instance
9595
static Instance* retrieve(VkPhysicalDevice handle);
9696

9797
/**
98-
* @brief Drop an instance from the global store of dispatchable instances.
98+
* \brief Drop an instance from the global store of dispatchable instances.
9999
*
100-
* @param instance The instance to drop.
100+
* This must be called before the driver VkInstance has been destroyed, as
101+
* we deference the native instance handle to get the dispatch key.
102+
*
103+
* \param handle The dispatchable instance handle to use as an indirect lookup.
104+
*
105+
* \return Returns the ownership of the Instance object to the caller.
101106
*/
102-
static void destroy(Instance* instance);
107+
static std::unique_ptr<Instance> destroy(
108+
VkInstance handle);
103109

104110
/**
105111
* @brief Create a new layer instance object.

layer_gpu_profile/source/device.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,15 @@ Device* Device::retrieve(VkCommandBuffer handle)
8282
}
8383

8484
/* See header for documentation. */
85-
void Device::destroy(Device* device)
86-
{
87-
g_devices.erase(getDispatchKey(device));
85+
std::unique_ptr<Device> Device::destroy(
86+
VkDevice handle
87+
) {
88+
void* key = getDispatchKey(handle);
89+
assert(isInMap(key, g_devices));
90+
91+
auto device = std::move(g_devices.at(key));
92+
g_devices.erase(key);
93+
return device;
8894
}
8995

9096
/* See header for documentation. */

layer_gpu_profile/source/device.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,17 @@ class Device
118118
static Device* retrieve(VkCommandBuffer handle);
119119

120120
/**
121-
* @brief Drop a device from the global store of dispatchable devices.
121+
* \brief Drop a device from the global store of dispatchable devices.
122122
*
123-
* @param device The device to drop.
123+
* This must be called before the driver VkDevice has been destroyed, as
124+
* we deference the native device handle to get the dispatch key.
125+
*
126+
* \param handle The dispatchable device handle to use as an indirect lookup.
127+
*
128+
* \return Returns the ownership of the Device object to the caller.
124129
*/
125-
static void destroy(Device* device);
130+
static std::unique_ptr<Device> destroy(
131+
VkDevice handle);
126132

127133
/**
128134
* @brief Create a new layer device object.

0 commit comments

Comments
 (0)