unit uvkuDebugReporter; {$mode objfpc}{$H+} {$I Vulkan.inc} interface uses Classes, SysUtils, Vulkan, uvkuBase, uvkuAllocationHandler; type ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuDebugReporter = class(TvkuAllocHandle) private fHandle: VkDebugReportCallbackEXT; fInstanceCommands: TVkInstanceCommands; protected function DebugMessage( aFlags: VkDebugReportFlagsEXT; aObjectType: TVkDebugReportObjectTypeEXT; aObject: VkUint64; aLocation: VkSize; aMessageCode: VkInt32; aLayerPrefix: String; aMessage: String): Boolean; virtual; public property Handle: VkDebugReportCallbackEXT read fHandle; constructor Create( const aInstanceCommands: TVkInstanceCommands; const aAllocHandler: TvkuAllocationHandler = nil); destructor Destroy; override; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuConsoleDebugReporter = class(TvkuDebugReporter) protected function DebugMessage(aFlags: VkDebugReportFlagsEXT; aObjectType: TVkDebugReportObjectTypeEXT; aObject: VkUint64; aLocation: VkSize; aMessageCode: VkInt32; aLayerPrefix: String; aMessage: String): Boolean; override; end; implementation uses uvkuUtils; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function DebugReportCallback( flags: VkDebugReportFlagsEXT; objectType: TVkDebugReportObjectTypeEXT; uObject: VkUint64; location: VkSize; messageCode: VkInt32; pLayerPrefix: PVkChar; pMessage: PVkChar; pUserData: PVkVoid): VkBool32; {$IFDEF VK_CDECL}cdecl{$ELSE}stdcall{$ENDIF}; var ret: Boolean; begin ret := TvkuDebugReporter(pUserData).DebugMessage( flags, objectType, uObject, location, messageCode, String(pLayerPrefix), String(pMessage)); if ret then result := VK_TRUE else result := VK_FALSE; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuDebugReporter////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuDebugReporter.DebugMessage(aFlags: VkDebugReportFlagsEXT; aObjectType: TVkDebugReportObjectTypeEXT; aObject: VkUint64; aLocation: VkSize; aMessageCode: VkInt32; aLayerPrefix: String; aMessage: String): Boolean; begin result := true; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// constructor TvkuDebugReporter.Create( const aInstanceCommands: TVkInstanceCommands; const aAllocHandler: TvkuAllocationHandler); var CreateInfo: TVkDebugReportCallbackCreateInfoEXT; err: TVkResult; begin inherited Create; if Assigned(aAllocHandler) then SetAllocCallbacks(aAllocHandler.GetStructure); fInstanceCommands := aInstanceCommands; FillByte(CreateInfo, SizeOf(CreateInfo), 0); CreateInfo.sType := VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; CreateInfo.pNext := nil; CreateInfo.pfnCallback := @DebugReportCallback; CreateInfo.pUserData := self; CreateInfo.flags := [ VK_DEBUG_REPORT_INFORMATION_BIT_EXT, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_DEBUG_BIT_EXT ]; err := fInstanceCommands.vkCreateDebugReportCallbackEXT(fInstanceCommands.Instance, @CreateInfo, AllocCallbacks, @fHandle); if (err <> VK_SUCCESS) then raise TvkuErrorException.Create('unable to create debug report handle', err); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// destructor TvkuDebugReporter.Destroy; begin if (fHandle <> VK_INVALID_NDP_HANDLE) then fInstanceCommands.vkDestroyDebugReportCallbackEXT(fInstanceCommands.Instance, fHandle, AllocCallbacks); fHandle := VK_INVALID_NDP_HANDLE; inherited Destroy; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuConsoleDebugReporter/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuConsoleDebugReporter.DebugMessage( aFlags: VkDebugReportFlagsEXT; aObjectType: TVkDebugReportObjectTypeEXT; aObject: VkUint64; aLocation: VkSize; aMessageCode: VkInt32; aLayerPrefix: String; aMessage: String): Boolean; begin WriteLn(Format(' DBG - [%03d] %10s: %s', [ Integer(aFlags), aLayerPrefix, aMessage ])); end; end.