5454wrapper_tramp_$name(
5555 $decl_params)
5656{
57- int cmd_id = commands ++;
57+ int cmd_id = __wrapper_commands ++;
5858 struct temporary_objects temp;
5959 list_inithead(&temp.objects);
6060$handle_unwrap_logic
6464 return $return_block;
6565}""" )
6666
67+
6768COMMAND_BLACKLIST = [
6869 'FreeCommandBuffers' , # implemented
6970 'CreateDevice' , # implemented
@@ -169,7 +170,7 @@ def _generate_trampoline(command, dispatch_table="device->dispatch_table"):
169170 physical_device = "base->physical"
170171
171172 # handle_unwrap_logic.append(f"#ifdef NEEDS_PRINTING_{command.name}")
172- handle_unwrap_logic .append (f" VK_CMD_LOG(\" { command .name } (id=%d)\" , cmd_id);" )
173+ handle_unwrap_logic .append (f" VK_CMD_LOG(\" dispatch-> { command .name } (id=%d)\" , cmd_id);" )
173174 # handle_unwrap_logic.append(f"#endif")
174175
175176 handle_unwrap_logic .append (f"" )
@@ -359,7 +360,7 @@ def _generate_trampoline(command, dispatch_table="device->dispatch_table"):
359360 if command .return_type == 'VkResult' and command .name not in SPAMMY_COMMANDS :
360361 logger = "WLOGE" if command .name not in ("AllocateDescriptorSets" , "GetPhysicalDeviceImageFormatProperties" ) else "WLOG"
361362 handle_wrap_logic .append (f" if (result != VK_SUCCESS) {{" )
362- handle_wrap_logic .append (f" { logger } (\" Call to { command .name } with ({ "," .join (types )} ) failed with result: %d\" , { "," .join (call )} , result);" )
363+ handle_wrap_logic .append (f" { logger } (\" dispatch-> { command .name } ({ "," .join (types )} ) failed with result: %d (id=%d) \" , { "," .join (call )} , result, cmd_id );" )
363364 handle_wrap_logic .append (f" }}" )
364365
365366 if command .return_type == 'VkResult' :
@@ -371,7 +372,9 @@ def _generate_trampoline(command, dispatch_table="device->dispatch_table"):
371372 return_block = "" if command .return_type == 'void' else "result"
372373 assign_block = "" if command .return_type == 'void' else f"{ command .return_type } result = "
373374
374- handle_unwrap_logic [idx ] = f"WLOGA(\" { command .name } ({ ', ' .join (types )} )\" , { ', ' .join ([p .name for p in params ])} );"
375+ if command .name not in SPAMMY_COMMANDS :
376+ handle_unwrap_logic [idx ] = f" WLOGA(\" dispatch->{ command .name } ({ ', ' .join (types )} ) (id=%d)\" , { ', ' .join ([p .name for p in params ])} , cmd_id);"
377+ handle_wrap_logic .append (f" WLOGA(\" dispatch->{ command .name } { 'returned %d' if command .return_type != 'void' else 'finished' } (id=%d)\" { ', result' if command .return_type != 'void' else '' } , cmd_id);" )
375378
376379 return TRAMPOLINE_TEMPLATE .substitute (
377380 return_type = command .return_type ,
@@ -402,6 +405,18 @@ def __init__(self, name):
402405 def prefixed_name (self , prefix ):
403406 return prefix + '_' + self .name
404407
408+ WRAP_TEMPLATE = string .Template ("""
409+ VKAPI_ATTR $return_type VKAPI_CALL wrapper_$name($decl_params) {
410+ int cmd_id = __wrapper_commands++;
411+ WLOGT("wrapper->$name($type_params) (id=%d)", $call_params, cmd_id);
412+ bool should_print = VK_CMD_CAN_TRACE;
413+ $PRINT_PRE
414+ $assign __wrapper_$name($call_params);
415+ WLOGT("wrapper->$name $return_str (id=%d)", $return_fmt cmd_id);
416+ $PRINT_POST
417+ return $result;
418+ }""" )
419+
405420class Entrypoint (EntrypointBase ):
406421 def __init__ (self , name , return_type , params ):
407422 super (Entrypoint , self ).__init__ (name )
@@ -443,6 +458,84 @@ def trampoline(self):
443458 return _generate_trampoline (self , dispatch_table = "base->dispatch_table" )
444459 else :
445460 return _generate_trampoline (self , dispatch_table = "base->device->dispatch_table" )
461+
462+ def wrap (self ):
463+ if self .alias :
464+ return ""
465+
466+ call = [param .name for param in self .params ]
467+ types = []
468+
469+ for param in self .params :
470+ is_input = param .num_pointers == 0 or param .is_const
471+
472+ if not is_input :
473+ types .append (f"{ param .name } : %p" )
474+ continue
475+ is_wrapped = param .type in WrappedStructs
476+ is_struct = param .type in TYPES
477+ is_special = param .type in SPECIAL_TYPES
478+
479+ # Wrapped handles
480+ if is_wrapped :
481+ types .append (f"{ param .name } : %p" )
482+ elif is_struct :
483+ types .append (f"{ param .name } : %p" )
484+ elif is_special :
485+ types .append (f"{ param .name } : %x" )
486+ else :
487+ types .append (f"{ param .name } : %x" )
488+ # handle_wrap_logic.append(f" WLOGA(\"dispatch->{command.name} {'returned %d' if command.return_type != 'void' else 'finished'} (id=%d)\"{', result' if command.return_type != 'void' else ''}, cmd_id);")
489+ pre_print = []
490+ pre_print .append (f" if (should_log) {{" )
491+ pre_print .append (f" VK_CMD_LOG(\" wrapper_{ self .name } (id=%d)\" , cmd_id);" )
492+ # pre_print += print_param(self, self.params[0], mode='input')
493+ for param in self .params :
494+ if self .name in COMMAND_BLACKLIST :
495+ continue
496+ is_input = param .num_pointers == 0 or param .is_const
497+ if not is_input :
498+ continue
499+ pre_print += print_param (self , param , mode = 'input' )
500+ pre_print .append (f" VK_CMD_FLUSH();" )
501+ pre_print .append (f" }}" )
502+
503+ post_print = []
504+ post_print .append (f" if (should_log) {{" )
505+ if self .return_type == 'VkResult' :
506+ post_print += print_param (self , 'result' , mode = 'output' )
507+ for param in self .params [1 :]:
508+ if self .name in COMMAND_BLACKLIST :
509+ continue
510+ is_input = param .num_pointers == 0 or param .is_const
511+ if is_input :
512+ continue
513+ if self .return_type == 'VkResult' :
514+ post_print .append (f" if ({ param .name } && result == VK_SUCCESS) {{" )
515+ else :
516+ post_print .append (f" if ({ param .name } ) {{" )
517+ post_print += print_param (self , param , mode = 'output' )
518+ post_print .append (f" }} else {{" )
519+ post_print += [
520+ f" VK_CMD_LOG_UNCONDITIONAL(\" out: *{ param .name } : { param .type } * = %p\" , { param .name } );" ,
521+ f" }}"
522+ ]
523+ post_print .append (f" }}" )
524+
525+
526+ return WRAP_TEMPLATE .substitute (
527+ return_type = self .return_type ,
528+ name = self .name ,
529+ assign = f"{ self .return_type } result =" if self .return_type != "void" else "" ,
530+ result = f"result" if self .return_type != "void" else "" ,
531+ decl_params = self .decl_params (),
532+ call_params = ", " .join (call ),
533+ type_params = types ,
534+ return_str = 'returned %d' if self .return_type != 'void' else 'finished' ,
535+ return_fmt = 'result,' if self .return_type != 'void' else '' ,
536+ PRINT_PRE = "\n " .join (pre_print ),
537+ PRINT_POST = "\n " .join (post_print ),
538+ )
446539
447540class EntrypointAlias (EntrypointBase ):
448541 def __init__ (self , name , entrypoint ):
0 commit comments