|
- unit uvkuSemaphore;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils,
- Vulkan, uvkuBase;
-
- type
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuSemaphore = class(TvkuAllocHandle)
- private
- fHandle: VkSemaphore;
- fDeviceCommands: TVkDeviceCommands;
-
- procedure CreateHandle(const aCreateInfo: TVkSemaphoreCreateInfo);
- public
- property Handle: VkSemaphore read fHandle;
- property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
-
- constructor Create(
- const aFlags: VkSemaphoreCreateFlags;
- const aDeviceCommands: TVkDeviceCommands;
- const aAllocCallbacks: PVkAllocationCallbacks = nil);
- constructor Create(
- const aCreateInfo: TVkSemaphoreCreateInfo;
- const aDeviceCommands: TVkDeviceCommands;
- const aAllocCallbacks: PVkAllocationCallbacks = nil);
- constructor Create(
- const aHandle: VkSemaphore;
- const aOwnsHandle: Boolean;
- const aDeviceCommands: TVkDeviceCommands;
- const aAllocCallbacks: PVkAllocationCallbacks = nil);
- destructor Destroy; override;
- end;
-
- implementation
-
- uses
- uvkuUtils;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuSemaphore//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuSemaphore.CreateHandle(const aCreateInfo: TVkSemaphoreCreateInfo);
- var err: TVkResult;
- begin
- if not Assigned(fDeviceCommands.vkCreateSemaphore) then
- raise TvkuInvalidFuncPtrException.Create('vkCreateSemaphore');
- err := fDeviceCommands.vkCreateSemaphore(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
- if (err <> VK_SUCCESS) then
- raise TvkuErrorException.Create('unable to create semaphore', err);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuSemaphore.Create(const aFlags: VkSemaphoreCreateFlags; const aDeviceCommands: TVkDeviceCommands;
- const aAllocCallbacks: PVkAllocationCallbacks);
- var CreateInfo: TVkSemaphoreCreateInfo;
- begin
- FillByte(CreateInfo, SizeOf(CreateInfo), 0);
- CreateInfo.sType := VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
- CreateInfo.pNext := nil;
- CreateInfo.flags := aFlags;
- Create(CreateInfo, aDeviceCommands, aAllocCallbacks);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuSemaphore.Create(const aCreateInfo: TVkSemaphoreCreateInfo; const aDeviceCommands: TVkDeviceCommands;
- const aAllocCallbacks: PVkAllocationCallbacks);
- begin
- inherited Create;
- fDeviceCommands := aDeviceCommands;
- SetAllocCallbacks(aAllocCallbacks);
- CreateHandle(aCreateInfo);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuSemaphore.Create(const aHandle: VkSemaphore; const aOwnsHandle: Boolean;
- const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
- begin
- inherited Create;
- fHandle := aHandle;
- fDeviceCommands := aDeviceCommands;
- OwnsHandle := aOwnsHandle;
- SetAllocCallbacks(aAllocCallbacks);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- destructor TvkuSemaphore.Destroy;
- begin
- if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
- fDeviceCommands.vkDestroySemaphore(fDeviceCommands.Device, fHandle, AllocCallbacks);
- fHandle := VK_INVALID_NDP_HANDLE;
- inherited Destroy;
- end;
-
- end.
|