The open source OpenXR runtime

a/vk + c/main + c/util: Detect/enable KHR_present_wait

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2515>

+85
+63
src/xrt/auxiliary/vk/vk_bundle_init.c
··· 846 846 } 847 847 #endif // defined(VK_KHR_maintenance4) 848 848 849 + #if defined(VK_KHR_present_wait) && defined(VK_KHR_present_id) 850 + if (strcmp(ext, VK_KHR_PRESENT_WAIT_EXTENSION_NAME) == 0) { 851 + vk->has_KHR_present_wait = true; 852 + continue; 853 + } 854 + #endif // defined(VK_KHR_present_wait) && defined(VK_KHR_present_id) 855 + 849 856 #if defined(VK_KHR_synchronization2) 850 857 if (strcmp(ext, VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME) == 0) { 851 858 vk->has_KHR_synchronization2 = true; ··· 1063 1070 }; 1064 1071 #endif 1065 1072 1073 + #if defined(VK_KHR_present_id) && defined(VK_KHR_present_wait) 1074 + VkPhysicalDevicePresentIdFeaturesKHR present_id_info = { 1075 + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, 1076 + .pNext = NULL, 1077 + }; 1078 + 1079 + VkPhysicalDevicePresentWaitFeaturesKHR present_wait_info = { 1080 + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR, 1081 + .pNext = NULL, 1082 + }; 1083 + #endif 1084 + 1066 1085 #ifdef VK_KHR_synchronization2 1067 1086 VkPhysicalDeviceSynchronization2FeaturesKHR synchronization_2_info = { 1068 1087 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR, ··· 1103 1122 } 1104 1123 #endif 1105 1124 1125 + #if defined(VK_KHR_present_id) && defined(VK_KHR_present_wait) 1126 + if (vk->has_KHR_present_wait) { 1127 + vk_append_to_pnext_chain((VkBaseInStructure *)&physical_device_features, 1128 + (VkBaseInStructure *)&present_id_info); 1129 + 1130 + vk_append_to_pnext_chain((VkBaseInStructure *)&physical_device_features, 1131 + (VkBaseInStructure *)&present_wait_info); 1132 + } 1133 + #endif 1134 + 1106 1135 #ifdef VK_KHR_synchronization2 1107 1136 if (vk->has_KHR_synchronization2) { 1108 1137 vk_append_to_pnext_chain((VkBaseInStructure *)&physical_device_features, ··· 1140 1169 CHECK(timeline_semaphore, timeline_semaphore_info.timelineSemaphore); 1141 1170 #endif 1142 1171 1172 + #if defined(VK_KHR_present_id) && defined(VK_KHR_present_wait) 1173 + // we need both extensions enabled/functional 1174 + CHECK(present_wait, present_id_info.presentId && present_wait_info.presentWait); 1175 + #endif 1176 + 1143 1177 #ifdef VK_KHR_synchronization2 1144 1178 CHECK(synchronization_2, synchronization_2_info.synchronization2); 1145 1179 #endif ··· 1218 1252 filter_device_features(vk, vk->physical_device, optional_device_features, &device_features); 1219 1253 vk->features.timeline_semaphore = device_features.timeline_semaphore; 1220 1254 vk->features.synchronization_2 = device_features.synchronization_2; 1255 + vk->features.present_wait = device_features.present_wait; 1221 1256 1222 1257 1223 1258 /* ··· 1308 1343 }; 1309 1344 #endif 1310 1345 1346 + #if VK_KHR_present_wait 1347 + VkPhysicalDevicePresentWaitFeaturesKHR present_wait = { 1348 + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR, 1349 + .pNext = NULL, 1350 + .presentWait = device_features.present_wait, 1351 + }; 1352 + #endif 1353 + 1354 + #if VK_KHR_present_id 1355 + VkPhysicalDevicePresentIdFeaturesKHR present_id = { 1356 + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, 1357 + .pNext = NULL, 1358 + .presentId = device_features.present_wait, 1359 + }; 1360 + #endif 1361 + 1311 1362 #ifdef VK_KHR_timeline_semaphore 1312 1363 VkPhysicalDeviceTimelineSemaphoreFeaturesKHR timeline_semaphore_info = { 1313 1364 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR, ··· 1355 1406 #ifdef VK_KHR_8bit_storage 1356 1407 if (vk->has_KHR_8bit_storage) { 1357 1408 vk_append_to_pnext_chain((VkBaseInStructure *)&device_create_info, (VkBaseInStructure *)&storage_8bit); 1409 + } 1410 + #endif 1411 + 1412 + #ifdef VK_KHR_present_id 1413 + if (vk->has_KHR_present_wait) { 1414 + vk_append_to_pnext_chain((VkBaseInStructure *)&device_create_info, (VkBaseInStructure *)&present_id); 1415 + } 1416 + #endif 1417 + 1418 + #ifdef VK_KHR_present_wait 1419 + if (vk->has_KHR_present_wait) { 1420 + vk_append_to_pnext_chain((VkBaseInStructure *)&device_create_info, (VkBaseInStructure *)&present_wait); 1358 1421 } 1359 1422 #endif 1360 1423
+5
src/xrt/auxiliary/vk/vk_function_loaders.c
··· 85 85 vk->vkEnumerateDeviceExtensionProperties = GET_INS_PROC(vk, vkEnumerateDeviceExtensionProperties); 86 86 vk->vkEnumerateDeviceLayerProperties = GET_INS_PROC(vk, vkEnumerateDeviceLayerProperties); 87 87 88 + #if defined(VK_KHR_present_wait) 89 + vk->vkWaitForPresentKHR = GET_INS_PROC(vk, vkWaitForPresentKHR); 90 + 91 + #endif // defined(VK_KHR_present_wait) 92 + 88 93 #if defined(VK_EXT_calibrated_timestamps) 89 94 vk->vkGetPhysicalDeviceCalibrateableTimeDomainsEXT = GET_INS_PROC(vk, vkGetPhysicalDeviceCalibrateableTimeDomainsEXT); 90 95
+10
src/xrt/auxiliary/vk/vk_helpers.h
··· 148 148 bool has_EXT_global_priority; 149 149 bool has_EXT_image_drm_format_modifier; 150 150 bool has_EXT_robustness2; 151 + bool has_KHR_present_wait; 151 152 bool has_ANDROID_external_format_resolve; 152 153 bool has_GOOGLE_display_timing; 153 154 // end of GENERATED device extension code - do not modify - used by scripts ··· 174 175 175 176 //! Was synchronization2 requested, available, and enabled? 176 177 bool synchronization_2; 178 + 179 + //! Was KHR_present_wait requested, available, and enabled? 180 + bool present_wait; 177 181 } features; 178 182 179 183 //! Is the GPU a tegra device. ··· 216 220 PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR vkGetPhysicalDeviceExternalSemaphorePropertiesKHR; 217 221 PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties; 218 222 PFN_vkEnumerateDeviceLayerProperties vkEnumerateDeviceLayerProperties; 223 + 224 + #if defined(VK_KHR_present_wait) 225 + PFN_vkWaitForPresentKHR vkWaitForPresentKHR; 226 + 227 + #endif // defined(VK_KHR_present_wait) 219 228 220 229 #if defined(VK_EXT_calibrated_timestamps) 221 230 PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT vkGetPhysicalDeviceCalibrateableTimeDomainsEXT; ··· 1019 1028 bool synchronization_2; 1020 1029 bool ext_fmt_resolve; 1021 1030 bool storage_buffer_8bit_access; 1031 + bool present_wait; 1022 1032 }; 1023 1033 1024 1034 /*!
+6
src/xrt/compositor/main/comp_compositor.c
··· 573 573 #error "Need port!" 574 574 #endif 575 575 576 + #ifdef VK_KHR_present_id 577 + VK_KHR_PRESENT_ID_EXTENSION_NAME, 578 + #endif 579 + #ifdef VK_KHR_present_wait 580 + VK_KHR_PRESENT_WAIT_EXTENSION_NAME, 581 + #endif 576 582 #ifdef VK_KHR_format_feature_flags2 577 583 VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME, 578 584 #endif
+1
src/xrt/compositor/util/comp_vulkan.c
··· 281 281 .null_descriptor = only_compute_queue, 282 282 .timeline_semaphore = vk_args->timeline_semaphore, 283 283 .synchronization_2 = true, 284 + .present_wait = true, 284 285 }; 285 286 286 287 ret = vk_init_mutex(vk);