The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/vk: Also generate the extension list/checking

+113 -23
+95 -20
scripts/generate_vk_helpers.py
··· 4 4 """Simple script to update vk_helpers.{c,h}.""" 5 5 6 6 from pathlib import Path 7 - from typing import List, Tuple 7 + from typing import List, Optional, Tuple 8 8 9 - # Each tuple is a function name, followed optionally by one or more conditions to test in the preprocessor, which will be wrapped in "defined()" 9 + # Each tuple is a function name, followed optionally by one or more conditions 10 + # to test in the preprocessor, which will be wrapped in "defined()" 10 11 # if they aren't already. Empty tuples insert a blank line. 11 12 12 13 DEVICE_FUNCTIONS = [ ··· 180 181 ] 181 182 182 183 EXTENSIONS_TO_CHECK = [ 183 - "GOOGLE_display_timing", 184 - "EXT_global_priority", 185 - "EXT_robustness2", 184 + "VK_GOOGLE_display_timing", 185 + "VK_EXT_global_priority", 186 + "VK_EXT_robustness2", 186 187 ] 187 188 188 189 ROOT = Path(__file__).resolve().parent.parent ··· 206 207 return " && ".join(wrap_condition(x) for x in pp_conditions) 207 208 208 209 210 + class ConditionalGenerator: 211 + """Keep track of conditions to avoid unneeded repetition of ifdefs.""" 212 + 213 + def __init__(self): 214 + self.current_condition = None 215 + 216 + def process_condition(self, new_condition: Optional[str]) -> Optional[str]: 217 + """Return a line (or lines) to yield if required based on the new condition state.""" 218 + lines = [] 219 + if self.current_condition and new_condition != self.current_condition: 220 + # Close current condition if required. 221 + lines.append("#endif // {}".format(self.current_condition)) 222 + # empty line 223 + lines.append("") 224 + self.current_condition = None 225 + 226 + if new_condition != self.current_condition: 227 + # Open new condition if required 228 + lines.append("#if {}".format(new_condition)) 229 + self.current_condition = new_condition 230 + 231 + if lines: 232 + return "\n".join(lines) 233 + 234 + def finish(self) -> Optional[str]: 235 + """Return a line (or lines) to yield if required at the end of the loop.""" 236 + return self.process_condition(None) 237 + 238 + 209 239 def generate_per_function(functions: List[Tuple[str, ...]], per_function_handler): 210 - current_condition = None 240 + conditional = ConditionalGenerator() 211 241 for data in functions: 212 242 if not data: 213 243 # empty line 214 244 yield "" 215 245 continue 216 - new_condition = compute_condition(data[1:]) 217 - if current_condition and new_condition != current_condition: 218 - # Close current condition if required. 219 - yield "#endif // {}".format(current_condition) 220 - # empty line 221 - yield "" 222 - current_condition = None 223 - 224 - if new_condition != current_condition: 225 - # Open new condition if required 226 - yield "#if {}".format(new_condition) 227 - current_condition = new_condition 246 + condition_line = conditional.process_condition(compute_condition(data[1:])) 247 + if condition_line: 248 + yield condition_line 228 249 229 250 yield per_function_handler(data[0]) 230 251 231 252 # close any trailing conditions 232 - if current_condition: 233 - yield "#endif // {}".format(current_condition) 253 + condition_line = conditional.finish() 254 + if condition_line: 255 + yield condition_line 234 256 235 257 236 258 def generate_structure_members(functions: List[Tuple[str, ...]]): ··· 254 276 return generate_per_function(functions, per_function) 255 277 256 278 279 + def make_ext_member_name(ext: str): 280 + return "has_{}".format(ext[3:]) 281 + 282 + 283 + def make_ext_name_define(ext: str): 284 + return "{}_EXTENSION_NAME".format(ext.upper()).replace("2", "_2") 285 + 286 + 287 + def generate_ext_members(): 288 + for ext in EXTENSIONS_TO_CHECK: 289 + yield "\tbool {};".format(make_ext_member_name(ext)) 290 + 291 + 292 + def generate_ext_check(): 293 + yield "\t// Reset before filling out." 294 + 295 + for ext in EXTENSIONS_TO_CHECK: 296 + yield "\tvk->{} = false;".format(make_ext_member_name(ext)) 297 + 298 + yield "" 299 + yield "\tfor (uint32_t i = 0; i < device_extension_count; i++) {" 300 + yield "\t\tconst char *ext = device_extensions[i];" 301 + yield "" 302 + 303 + conditional = ConditionalGenerator() 304 + for ext in EXTENSIONS_TO_CHECK: 305 + condition_line = conditional.process_condition(compute_condition((ext,))) 306 + if condition_line: 307 + yield condition_line 308 + yield "\t\tif (strcmp(ext, {}) == 0) {{".format(make_ext_name_define(ext)) 309 + yield "\t\t\tvk->{} = true;".format(make_ext_member_name(ext)) 310 + yield "\t\t\tcontinue;" 311 + yield "\t\t}" 312 + # close any trailing conditions 313 + condition_line = conditional.finish() 314 + if condition_line: 315 + yield condition_line 316 + yield "\t}" 317 + 318 + 257 319 def replace_middle( 258 320 lines: List[str], start_sentinel: str, end_sentinel: str, new_middle: List[str] 259 321 ) -> List[str]: ··· 293 355 DEVICE_TEMPLATES["END"], 294 356 list(generate_structure_members(DEVICE_FUNCTIONS)), 295 357 ) 358 + lines = replace_middle( 359 + lines, 360 + EXT_TEMPLATES["BEGIN"], 361 + EXT_TEMPLATES["END"], 362 + list(generate_ext_members()), 363 + ) 296 364 297 365 with open(str(HEADER_FN), "w", encoding="utf-8") as fp: 298 366 fp.write("\n".join(lines)) ··· 315 383 DEVICE_TEMPLATES["BEGIN"], 316 384 DEVICE_TEMPLATES["END"], 317 385 list(generate_dev_proc(DEVICE_FUNCTIONS)), 386 + ) 387 + 388 + lines = replace_middle( 389 + lines, 390 + EXT_TEMPLATES["BEGIN"], 391 + EXT_TEMPLATES["END"], 392 + list(generate_ext_check()), 318 393 ) 319 394 320 395 with open(str(IMPL_FN), "w", encoding="utf-8") as fp:
+15 -3
src/xrt/auxiliary/vk/vk_helpers.c
··· 884 884 #if defined(VK_USE_PLATFORM_WIN32_KHR) 885 885 vk->vkCreateWin32SurfaceKHR = GET_INS_PROC(vk, vkCreateWin32SurfaceKHR); 886 886 #endif // defined(VK_USE_PLATFORM_WIN32_KHR) 887 - // end of GENERATED instance loader code - do not modify - used by scripts 887 + 888 + // end of GENERATED instance loader code - do not modify - used by scripts 888 889 889 890 return VK_SUCCESS; 890 891 } ··· 1220 1221 static void 1221 1222 fill_in_has_extensions(struct vk_bundle *vk, const char **device_extensions, uint32_t num_device_extensions) 1222 1223 { 1224 + // beginning of GENERATED extension code - do not modify - used by scripts 1223 1225 // Reset before filling out. 1224 1226 vk->has_GOOGLE_display_timing = false; 1225 1227 vk->has_EXT_global_priority = false; ··· 1228 1230 for (uint32_t i = 0; i < num_device_extensions; i++) { 1229 1231 const char *ext = device_extensions[i]; 1230 1232 1233 + #if defined(VK_GOOGLE_display_timing) 1231 1234 if (strcmp(ext, VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME) == 0) { 1232 1235 vk->has_GOOGLE_display_timing = true; 1236 + continue; 1233 1237 } 1238 + #endif // defined(VK_GOOGLE_display_timing) 1239 + 1240 + #if defined(VK_EXT_global_priority) 1234 1241 if (strcmp(ext, VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME) == 0) { 1235 1242 vk->has_EXT_global_priority = true; 1243 + continue; 1236 1244 } 1237 - #ifdef VK_EXT_robustness2 1245 + #endif // defined(VK_EXT_global_priority) 1246 + 1247 + #if defined(VK_EXT_robustness2) 1238 1248 if (strcmp(ext, VK_EXT_ROBUSTNESS_2_EXTENSION_NAME) == 0) { 1239 1249 vk->has_EXT_robustness2 = true; 1250 + continue; 1240 1251 } 1241 - #endif 1252 + #endif // defined(VK_EXT_robustness2) 1242 1253 } 1254 + // end of GENERATED extension code - do not modify - used by scripts 1243 1255 } 1244 1256 1245 1257 static VkResult
+3
src/xrt/auxiliary/vk/vk_helpers.h
··· 48 48 49 49 struct os_mutex queue_mutex; 50 50 51 + // beginning of GENERATED extension code - do not modify - used by scripts 51 52 bool has_GOOGLE_display_timing; 52 53 bool has_EXT_global_priority; 53 54 bool has_EXT_robustness2; 55 + // end of GENERATED extension code - do not modify - used by scripts 54 56 55 57 bool is_tegra; 56 58 ··· 129 131 #if defined(VK_USE_PLATFORM_WIN32_KHR) 130 132 PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR; 131 133 #endif // defined(VK_USE_PLATFORM_WIN32_KHR) 134 + 132 135 // end of GENERATED instance loader code - do not modify - used by scripts 133 136 134 137 // beginning of GENERATED device loader code - do not modify - used by scripts