Skip to content

Commit 4da32b2

Browse files
committed
[ET-VK][ez] Streamline + fix enabling device extensions
## Changes Simplify the logic to construct a linked list of physical device feature structs When constructing the logical device, construct the linked list of device features to enable instead of using a stored pointer from the constructor of `PhysicalDevice`. The reason is that due to possible moves, the stored pointer may be invalid by the time the `Adapter` instance is constructed. It is safer to reconstruct the device features linked list at the time it is needed. Differential Revision: [D73438721](https://our.internmc.facebook.com/intern/diff/D73438721/) [ghstack-poisoned]
1 parent 95c663e commit 4da32b2

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

backends/vulkan/runtime/vk_api/Adapter.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,33 @@ VkDevice create_logical_device(
107107
nullptr, // pEnabledFeatures
108108
};
109109

110-
device_create_info.pNext = physical_device.extension_features;
110+
void* extension_list_top = nullptr;
111+
112+
#ifdef VK_KHR_16bit_storage
113+
VkPhysicalDevice16BitStorageFeatures shader_16bit_storage{
114+
physical_device.shader_16bit_storage};
115+
116+
shader_16bit_storage.pNext = extension_list_top;
117+
extension_list_top = &shader_16bit_storage;
118+
#endif /* VK_KHR_16bit_storage */
119+
120+
#ifdef VK_KHR_8bit_storage
121+
VkPhysicalDevice8BitStorageFeatures shader_8bit_storage{
122+
physical_device.shader_8bit_storage};
123+
124+
shader_8bit_storage.pNext = extension_list_top;
125+
extension_list_top = &shader_8bit_storage;
126+
#endif /* VK_KHR_8bit_storage */
127+
128+
#ifdef VK_KHR_shader_float16_int8
129+
VkPhysicalDeviceShaderFloat16Int8Features shader_float16_int8_types{
130+
physical_device.shader_float16_int8_types};
131+
132+
shader_float16_int8_types.pNext = extension_list_top;
133+
extension_list_top = &shader_float16_int8_types;
134+
#endif /* VK_KHR_shader_float16_int8 */
135+
136+
device_create_info.pNext = extension_list_top;
111137

112138
VkDevice handle = nullptr;
113139
VK_CHECK(vkCreateDevice(

backends/vulkan/runtime/vk_api/Device.cpp

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle)
3434
shader_float16_int8_types{
3535
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR},
3636
#endif /* VK_KHR_shader_float16_int8 */
37-
extension_features{nullptr},
3837
queue_families{},
3938
num_compute_queues(0),
4039
supports_int16_shader_types(false),
@@ -57,34 +56,24 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle)
5756

5857
// Create linked list to query availability of extensions
5958

59+
void* extension_list_top = nullptr;
60+
6061
#ifdef VK_KHR_16bit_storage
61-
extension_features = &shader_16bit_storage;
62-
features2.pNext = &shader_16bit_storage;
63-
#elif defined(VK_KHR_8bit_storage)
64-
extension_features = &shader_8bit_storage;
65-
features2.pNext = &shader_8bit_storage;
66-
#elif defined(VK_KHR_shader_float16_int8)
67-
extension_features = &shader_float16_int8_types;
68-
features2.pNext = &shader_float16_int8_types;
62+
shader_16bit_storage.pNext = extension_list_top;
63+
extension_list_top = &shader_16bit_storage;
6964
#endif /* VK_KHR_16bit_storage */
7065

71-
#if defined(VK_KHR_16bit_storage) && defined(VK_KHR_8bit_storage)
72-
shader_16bit_storage.pNext = &shader_8bit_storage;
73-
#elif defined(VK_KHR_16bit_storage) && defined(VK_KHR_shader_float16_int8)
74-
shader_16bit_storage.pNext = &shader_float16_int8_types;
75-
#elif defined(VK_KHR_16bit_storage)
76-
shader_16bit_storage.pNext = nullptr;
77-
#endif
78-
79-
#if defined(VK_KHR_8bit_storage) && defined(VK_KHR_shader_float16_int8)
80-
shader_8bit_storage.pNext = &shader_float16_int8_types;
81-
#elif defined(VK_KHR_8bit_storage)
82-
shader_8bit_storage.pNext = nullptr;
83-
#endif
66+
#ifdef VK_KHR_8bit_storage
67+
shader_8bit_storage.pNext = extension_list_top;
68+
extension_list_top = &shader_8bit_storage;
69+
#endif /* VK_KHR_8bit_storage */
8470

8571
#ifdef VK_KHR_shader_float16_int8
86-
shader_float16_int8_types.pNext = nullptr;
87-
#endif
72+
shader_float16_int8_types.pNext = extension_list_top;
73+
extension_list_top = &shader_float16_int8_types;
74+
#endif /* VK_KHR_shader_float16_int8 */
75+
76+
features2.pNext = extension_list_top;
8877

8978
vkGetPhysicalDeviceFeatures2(handle, &features2);
9079

backends/vulkan/runtime/vk_api/Device.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ struct PhysicalDevice final {
3737
VkPhysicalDeviceShaderFloat16Int8Features shader_float16_int8_types;
3838
#endif /* VK_KHR_shader_float16_int8 */
3939

40-
// Head of the linked list of extensions to be requested
41-
void* extension_features;
42-
4340
// Available GPU queues
4441
std::vector<VkQueueFamilyProperties> queue_families;
4542

0 commit comments

Comments
 (0)