2121namespace vkcompute {
2222namespace vkapi {
2323
24- PhysicalDevice::PhysicalDevice (VkPhysicalDevice physical_device_handle)
25- : handle(physical_device_handle),
24+ PhysicalDevice::PhysicalDevice (
25+ VkInstance instance_handle,
26+ VkPhysicalDevice physical_device_handle)
27+ : instance(instance_handle),
28+ handle (physical_device_handle),
2629 properties{},
2730 memory_properties{},
2831#ifdef VK_KHR_16bit_storage
2932 shader_16bit_storage{
30- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES},
33+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES,
34+ nullptr },
3135#endif /* VK_KHR_16bit_storage */
3236#ifdef VK_KHR_8bit_storage
3337 shader_8bit_storage{
34- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES},
38+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES,
39+ nullptr },
3540#endif /* VK_KHR_8bit_storage */
3641#ifdef VK_KHR_shader_float16_int8
3742 shader_float16_int8_types{
38- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR},
43+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR,
44+ nullptr },
3945#endif /* VK_KHR_shader_float16_int8 */
4046#ifdef VK_KHR_shader_integer_dot_product
4147 shader_int_dot_product_features{
42- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES_KHR},
48+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES_KHR,
49+ nullptr },
4350 shader_int_dot_product_properties{
44- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_PROPERTIES_KHR},
51+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_PROPERTIES_KHR,
52+ nullptr },
4553#endif
4654 queue_families{},
4755 num_compute_queues (0 ),
56+ api_version_major (0 ),
57+ api_version_minor (0 ),
4858 supports_int16_shader_types (false ),
4959 supports_int64_shader_types (false ),
5060 supports_float64_shader_types (false ),
@@ -57,62 +67,28 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle)
5767 // Extract physical device properties
5868 vkGetPhysicalDeviceProperties (handle, &properties);
5969
70+ api_version_major = VK_VERSION_MAJOR (properties.apiVersion );
71+ api_version_minor = VK_VERSION_MINOR (properties.apiVersion );
72+
6073 // Extract fields of interest
6174 has_timestamps = properties.limits .timestampComputeAndGraphics ;
6275 timestamp_period = properties.limits .timestampPeriod ;
6376 min_ubo_alignment = properties.limits .minUniformBufferOffsetAlignment ;
6477
6578 vkGetPhysicalDeviceMemoryProperties (handle, &memory_properties);
6679
67- VkPhysicalDeviceFeatures2 features2{
68- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
69-
70- // Create linked list to query availability of extensions
71-
72- void * extension_list_top = nullptr ;
73-
74- #ifdef VK_KHR_16bit_storage
75- shader_16bit_storage.pNext = extension_list_top;
76- extension_list_top = &shader_16bit_storage;
77- #endif /* VK_KHR_16bit_storage */
78-
79- #ifdef VK_KHR_8bit_storage
80- shader_8bit_storage.pNext = extension_list_top;
81- extension_list_top = &shader_8bit_storage;
82- #endif /* VK_KHR_8bit_storage */
83-
84- #ifdef VK_KHR_shader_float16_int8
85- shader_float16_int8_types.pNext = extension_list_top;
86- extension_list_top = &shader_float16_int8_types;
87- #endif /* VK_KHR_shader_float16_int8 */
88-
89- #ifdef VK_KHR_shader_integer_dot_product
90- shader_int_dot_product_features.pNext = extension_list_top;
91- extension_list_top = &shader_int_dot_product_features;
92- shader_int_dot_product_properties.pNext = extension_list_top;
93- extension_list_top = &shader_int_dot_product_properties;
94- #endif /* VK_KHR_shader_integer_dot_product */
95-
96- features2.pNext = extension_list_top;
97-
98- vkGetPhysicalDeviceFeatures2 (handle, &features2);
99-
100- if (features2.features .shaderInt16 == VK_TRUE) {
101- supports_int16_shader_types = true ;
102- }
103- if (features2.features .shaderInt64 == VK_TRUE) {
104- supports_int64_shader_types = true ;
105- }
106- if (features2.features .shaderFloat64 == VK_TRUE) {
107- supports_float64_shader_types = true ;
80+ if (properties.apiVersion >= VK_API_VERSION_1_1) {
81+ query_extensions_vk_1_1 ();
82+ } else {
83+ query_extensions_vk_1_0 ();
10884 }
10985
11086 // Check if there are any memory types have both the HOST_VISIBLE and the
11187 // DEVICE_LOCAL property flags
11288 const VkMemoryPropertyFlags unified_memory_flags =
113- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
89+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
11490 for (size_t i = 0 ; i < memory_properties.memoryTypeCount ; ++i) {
115- if (memory_properties.memoryTypes [i].propertyFlags | unified_memory_flags) {
91+ if (memory_properties.memoryTypes [i].propertyFlags & unified_memory_flags) {
11692 has_unified_memory = true ;
11793 break ;
11894 }
@@ -153,6 +129,149 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle)
153129 }
154130}
155131
132+ void PhysicalDevice::query_extensions_vk_1_0 () {
133+ VkPhysicalDeviceFeatures features{};
134+ vkGetPhysicalDeviceFeatures (handle, &features);
135+
136+ if (features.shaderInt16 == VK_TRUE) {
137+ supports_int16_shader_types = true ;
138+ }
139+ if (features.shaderInt64 == VK_TRUE) {
140+ supports_int64_shader_types = true ;
141+ }
142+ if (features.shaderFloat64 == VK_TRUE) {
143+ supports_float64_shader_types = true ;
144+ }
145+
146+ // Try to query extension features using
147+ // VK_KHR_get_physical_device_properties2
148+ auto vkGetPhysicalDeviceFeatures2KHR =
149+ (PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr (
150+ instance, " vkGetPhysicalDeviceFeatures2KHR" );
151+
152+ if (vkGetPhysicalDeviceFeatures2KHR == nullptr ) {
153+ // Manually set extension features to false if the function is not available
154+ #ifdef VK_KHR_16bit_storage
155+ shader_16bit_storage.storageBuffer16BitAccess = VK_FALSE;
156+ shader_16bit_storage.uniformAndStorageBuffer16BitAccess = VK_FALSE;
157+ shader_16bit_storage.storagePushConstant16 = VK_FALSE;
158+ shader_16bit_storage.storageInputOutput16 = VK_FALSE;
159+ #endif /* VK_KHR_16bit_storage */
160+ #ifdef VK_KHR_8bit_storage
161+ shader_8bit_storage.storageBuffer8BitAccess = VK_FALSE;
162+ shader_8bit_storage.uniformAndStorageBuffer8BitAccess = VK_FALSE;
163+ shader_8bit_storage.storagePushConstant8 = VK_FALSE;
164+ #endif /* VK_KHR_8bit_storage */
165+ #ifdef VK_KHR_shader_float16_int8
166+ shader_float16_int8_types.shaderFloat16 = VK_FALSE;
167+ shader_float16_int8_types.shaderInt8 = VK_FALSE;
168+ #endif /* VK_KHR_shader_float16_int8 */
169+ #ifdef VK_KHR_shader_integer_dot_product
170+ shader_int_dot_product_features.shaderIntegerDotProduct = VK_FALSE;
171+ #endif /* VK_KHR_shader_integer_dot_product */
172+ return ;
173+ }
174+
175+ VkPhysicalDeviceFeatures2KHR features2{
176+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR};
177+
178+ void * extension_list_top = nullptr ;
179+
180+ #ifdef VK_KHR_16bit_storage
181+ shader_16bit_storage.pNext = extension_list_top;
182+ extension_list_top = &shader_16bit_storage;
183+ #endif /* VK_KHR_16bit_storage */
184+
185+ #ifdef VK_KHR_8bit_storage
186+ shader_8bit_storage.pNext = extension_list_top;
187+ extension_list_top = &shader_8bit_storage;
188+ #endif /* VK_KHR_8bit_storage */
189+
190+ #ifdef VK_KHR_shader_float16_int8
191+ shader_float16_int8_types.pNext = extension_list_top;
192+ extension_list_top = &shader_float16_int8_types;
193+ #endif /* VK_KHR_shader_float16_int8 */
194+
195+ #ifdef VK_KHR_shader_integer_dot_product
196+ shader_int_dot_product_features.pNext = extension_list_top;
197+ extension_list_top = &shader_int_dot_product_features;
198+ #endif /* VK_KHR_shader_integer_dot_product */
199+
200+ features2.pNext = extension_list_top;
201+
202+ vkGetPhysicalDeviceFeatures2KHR (handle, &features2);
203+
204+ // Query properties separately from features
205+ auto vkGetPhysicalDeviceProperties2KHR =
206+ (PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr (
207+ instance, " vkGetPhysicalDeviceProperties2KHR" );
208+
209+ if (vkGetPhysicalDeviceProperties2KHR != nullptr ) {
210+ VkPhysicalDeviceProperties2KHR properties2{
211+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR};
212+
213+ #ifdef VK_KHR_shader_integer_dot_product
214+ shader_int_dot_product_properties.pNext = nullptr ;
215+ properties2.pNext = &shader_int_dot_product_properties;
216+ #endif /* VK_KHR_shader_integer_dot_product */
217+
218+ vkGetPhysicalDeviceProperties2KHR (handle, &properties2);
219+ }
220+ }
221+
222+ void PhysicalDevice::query_extensions_vk_1_1 () {
223+ VkPhysicalDeviceFeatures2 features2{
224+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
225+
226+ // Create linked list to query availability of extensions
227+ void * extension_list_top = nullptr ;
228+
229+ #ifdef VK_KHR_16bit_storage
230+ shader_16bit_storage.pNext = extension_list_top;
231+ extension_list_top = &shader_16bit_storage;
232+ #endif /* VK_KHR_16bit_storage */
233+
234+ #ifdef VK_KHR_8bit_storage
235+ shader_8bit_storage.pNext = extension_list_top;
236+ extension_list_top = &shader_8bit_storage;
237+ #endif /* VK_KHR_8bit_storage */
238+
239+ #ifdef VK_KHR_shader_float16_int8
240+ shader_float16_int8_types.pNext = extension_list_top;
241+ extension_list_top = &shader_float16_int8_types;
242+ #endif /* VK_KHR_shader_float16_int8 */
243+
244+ #ifdef VK_KHR_shader_integer_dot_product
245+ shader_int_dot_product_features.pNext = extension_list_top;
246+ extension_list_top = &shader_int_dot_product_features;
247+ #endif /* VK_KHR_shader_integer_dot_product */
248+
249+ features2.pNext = extension_list_top;
250+
251+ vkGetPhysicalDeviceFeatures2 (handle, &features2);
252+
253+ if (features2.features .shaderInt16 == VK_TRUE) {
254+ supports_int16_shader_types = true ;
255+ }
256+ if (features2.features .shaderInt64 == VK_TRUE) {
257+ supports_int64_shader_types = true ;
258+ }
259+ if (features2.features .shaderFloat64 == VK_TRUE) {
260+ supports_float64_shader_types = true ;
261+ }
262+
263+ // Query properties separately from features
264+ VkPhysicalDeviceProperties2 properties2{
265+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
266+
267+ #ifdef VK_KHR_shader_integer_dot_product
268+ shader_int_dot_product_properties.pNext = nullptr ;
269+ properties2.pNext = &shader_int_dot_product_properties;
270+ #endif /* VK_KHR_shader_integer_dot_product */
271+
272+ vkGetPhysicalDeviceProperties2 (handle, &properties2);
273+ }
274+
156275//
157276// DeviceHandle
158277//
0 commit comments