You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

101 line
4.0 KiB

  1. unit uvkuSemaphore;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuBase;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuSemaphore = class(TvkuAllocHandle)
  10. private
  11. fHandle: VkSemaphore;
  12. fDeviceCommands: TVkDeviceCommands;
  13. procedure CreateHandle(const aCreateInfo: TVkSemaphoreCreateInfo);
  14. public
  15. property Handle: VkSemaphore read fHandle;
  16. property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
  17. constructor Create(
  18. const aFlags: VkSemaphoreCreateFlags;
  19. const aDeviceCommands: TVkDeviceCommands;
  20. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  21. constructor Create(
  22. const aCreateInfo: TVkSemaphoreCreateInfo;
  23. const aDeviceCommands: TVkDeviceCommands;
  24. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  25. constructor Create(
  26. const aHandle: VkSemaphore;
  27. const aOwnsHandle: Boolean;
  28. const aDeviceCommands: TVkDeviceCommands;
  29. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  30. destructor Destroy; override;
  31. end;
  32. implementation
  33. uses
  34. uvkuUtils;
  35. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. //TvkuSemaphore//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. procedure TvkuSemaphore.CreateHandle(const aCreateInfo: TVkSemaphoreCreateInfo);
  39. var err: TVkResult;
  40. begin
  41. if not Assigned(fDeviceCommands.vkCreateSemaphore) then
  42. raise TvkuInvalidFuncPtrException.Create('vkCreateSemaphore');
  43. err := fDeviceCommands.vkCreateSemaphore(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
  44. if (err <> VK_SUCCESS) then
  45. raise TvkuErrorException.Create('unable to create semaphore', err);
  46. end;
  47. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  48. constructor TvkuSemaphore.Create(const aFlags: VkSemaphoreCreateFlags; const aDeviceCommands: TVkDeviceCommands;
  49. const aAllocCallbacks: PVkAllocationCallbacks);
  50. var CreateInfo: TVkSemaphoreCreateInfo;
  51. begin
  52. FillByte(CreateInfo, SizeOf(CreateInfo), 0);
  53. CreateInfo.sType := VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
  54. CreateInfo.pNext := nil;
  55. CreateInfo.flags := aFlags;
  56. Create(CreateInfo, aDeviceCommands, aAllocCallbacks);
  57. end;
  58. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. constructor TvkuSemaphore.Create(const aCreateInfo: TVkSemaphoreCreateInfo; const aDeviceCommands: TVkDeviceCommands;
  60. const aAllocCallbacks: PVkAllocationCallbacks);
  61. begin
  62. inherited Create;
  63. fDeviceCommands := aDeviceCommands;
  64. SetAllocCallbacks(aAllocCallbacks);
  65. CreateHandle(aCreateInfo);
  66. end;
  67. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68. constructor TvkuSemaphore.Create(const aHandle: VkSemaphore; const aOwnsHandle: Boolean;
  69. const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
  70. begin
  71. inherited Create;
  72. fHandle := aHandle;
  73. fDeviceCommands := aDeviceCommands;
  74. OwnsHandle := aOwnsHandle;
  75. SetAllocCallbacks(aAllocCallbacks);
  76. end;
  77. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. destructor TvkuSemaphore.Destroy;
  79. begin
  80. if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
  81. fDeviceCommands.vkDestroySemaphore(fDeviceCommands.Device, fHandle, AllocCallbacks);
  82. fHandle := VK_INVALID_NDP_HANDLE;
  83. inherited Destroy;
  84. end;
  85. end.