|
- unit uvkuCommandPool;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils,
- Vulkan, uvkuBase, uvkuTypes;
-
- type
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuCommandPool = class(TvkuAllocHandle)
- private
- fHandle: VkCommandPool;
- fDeviceCommands: TVkDeviceCommands;
-
- procedure CreateHandle(const aCreateInfo: TVkCommandPoolCreateInfo);
- public
- property Handle: VkCommandPool read fHandle;
- property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
-
- function AllocateCommandBuffer(
- const aLevel: TVkCommandBufferLevel): VkCommandBuffer;
- function AllocateCommandBuffers(
- const aLevel: TVkCommandBufferLevel;
- const aCount: Integer): TVkCommandBufferArr;
- procedure FreeCommandBuffer(
- const aBuffer: VkCommandBuffer);
- procedure FreeCommandBuffers(
- const aBuffers: TVkCommandBufferArr);
-
- constructor Create(
- const aCreateInfo: TVkCommandPoolCreateInfo;
- const aDeviceCommands: TVkDeviceCommands;
- const aAllocCallbacks: PVkAllocationCallbacks = nil);
- constructor Create(
- const aHandle: VkCommandPool;
- const aOwnsHandle: Boolean;
- const aDeviceCommands: TVkDeviceCommands;
- const aAllocCallbacks: PVkAllocationCallbacks = nil);
- destructor Destroy; override;
- end;
-
- implementation
-
- uses
- uvkuUtils;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuCommandPool////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuCommandPool.CreateHandle(const aCreateInfo: TVkCommandPoolCreateInfo);
- var err: TVkResult;
- begin
- err := fDeviceCommands.vkCreateCommandPool(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
- if (err <> VK_SUCCESS) then
- raise TvkuErrorException.Create('unable to create command pool', err);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuCommandPool.AllocateCommandBuffer(const aLevel: TVkCommandBufferLevel): VkCommandBuffer;
- begin
- result := AllocateCommandBuffers(aLevel, 1)[0];
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuCommandPool.AllocateCommandBuffers(const aLevel: TVkCommandBufferLevel; const aCount: Integer): TVkCommandBufferArr;
- var
- AllocInfo: TVkCommandBufferAllocateInfo;
- err: TVkResult;
- begin
- FillByte(AllocInfo, SizeOf(AllocInfo), 0);
- AllocInfo.sType := VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
- AllocInfo.pNext := nil;
- AllocInfo.commandPool := fHandle;
- AllocInfo.level := aLevel;
- AllocInfo.commandBufferCount := aCount;
- SetLength(result, aCount);
- err := fDeviceCommands.vkAllocateCommandBuffers(fDeviceCommands.Device, @AllocInfo, @result[0]);
- if (err <> VK_SUCCESS) then
- raise TvkuErrorException.Create('unable to create command buffers', err);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuCommandPool.FreeCommandBuffer(const aBuffer: VkCommandBuffer);
- begin
- FreeCommandBuffers(TVkCommandBufferArr.Create(aBuffer));
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuCommandPool.FreeCommandBuffers(const aBuffers: TVkCommandBufferArr);
- begin
- fDeviceCommands.vkFreeCommandBuffers(fDeviceCommands.Device, fHandle, Length(aBuffers), @aBuffers[0]);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuCommandPool.Create(const aCreateInfo: TVkCommandPoolCreateInfo;
- const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
- begin
- inherited Create;
- fDeviceCommands := aDeviceCommands;
- SetAllocCallbacks(aAllocCallbacks);
- CreateHandle(aCreateInfo);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuCommandPool.Create(const aHandle: VkCommandPool; const aOwnsHandle: Boolean;
- const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
- begin
- inherited Create;
- fHandle := aHandle;
- fDeviceCommands := aDeviceCommands;
- OwnsHandle := aOwnsHandle;
- SetAllocCallbacks(aAllocCallbacks);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- destructor TvkuCommandPool.Destroy;
- begin
- if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
- fDeviceCommands.vkDestroyCommandPool(fDeviceCommands.Device, fHandle, AllocCallbacks);
- fHandle := VK_INVALID_NDP_HANDLE;
- inherited Destroy;
- end;
-
- end.
|