unit uvkuPipeline; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Vulkan, uvkuBase; type ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuPipeline = class(TvkuAllocHandle) private fHandle: VkPipeline; fDeviceCommands: TVkDeviceCommands; public property Handle: VkPipeline read fHandle; property DeviceCommands: TVkDeviceCommands read fDeviceCommands; constructor Create( const aHandle: VkPipeline; const aOwnsHandle: Boolean; const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks = nil); destructor Destroy; override; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuGraphicsPipeline = class(TvkuPipeline) private procedure CreateHandle(const aCreateInfo: TVkGraphicsPipelineCreateInfo; const aPipelineCache: VkPipelineCache); public constructor Create( const aCreateInfo: TVkGraphicsPipelineCreateInfo; const aPipelineCache: VkPipelineCache; const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks = nil); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuComputePipeline = class(TvkuPipeline) private procedure CreateHandle(const aCreateInfo: TVkComputePipelineCreateInfo; const aPipelineCache: VkPipelineCache); public constructor Create( const aCreateInfo: TVkComputePipelineCreateInfo; const aPipelineCache: VkPipelineCache; const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks = nil); end; implementation uses uvkuUtils; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuPipeline/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// constructor TvkuPipeline.Create(const aHandle: VkPipeline; const aOwnsHandle: Boolean; const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks); begin inherited Create; fHandle := aHandle; fDeviceCommands := aDeviceCommands; OwnsHandle := aOwnsHandle; SetAllocCallbacks(aAllocCallbacks); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// destructor TvkuPipeline.Destroy; begin if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then fDeviceCommands.vkDestroyPipeline(fDeviceCommands.Device, fHandle, AllocCallbacks); fHandle := VK_INVALID_NDP_HANDLE; inherited Destroy; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuGraphicsPipeline/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuGraphicsPipeline.CreateHandle(const aCreateInfo: TVkGraphicsPipelineCreateInfo; const aPipelineCache: VkPipelineCache); var err: TVkResult; begin if not Assigned(fDeviceCommands.vkCreateGraphicsPipelines) then raise TvkuInvalidFuncPtrException.Create('vkCreateGraphicsPipelines'); err := fDeviceCommands.vkCreateGraphicsPipelines(fDeviceCommands.Device, aPipelineCache, 1, @aCreateInfo, AllocCallbacks, @fHandle); if (err <> VK_SUCCESS) then raise TvkuErrorException.Create('unable to create graphics pipeline', err); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// constructor TvkuGraphicsPipeline.Create(const aCreateInfo: TVkGraphicsPipelineCreateInfo; const aPipelineCache: VkPipelineCache; const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks); begin inherited Create(VK_INVALID_NDP_HANDLE, true, aDeviceCommands, aAllocCallbacks); CreateHandle(aCreateInfo, aPipelineCache); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuComputePipeline//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuComputePipeline.CreateHandle(const aCreateInfo: TVkComputePipelineCreateInfo; const aPipelineCache: VkPipelineCache); var err: TVkResult; begin if not Assigned(fDeviceCommands.vkCreateComputePipelines) then raise TvkuInvalidFuncPtrException.Create('vkCreateComputePipelines'); err := fDeviceCommands.vkCreateComputePipelines(fDeviceCommands.Device, aPipelineCache, 1, @aCreateInfo, AllocCallbacks, @fHandle); if (err <> VK_SUCCESS) then raise TvkuErrorException.Create('unable to create compute pipeline', err); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// constructor TvkuComputePipeline.Create(const aCreateInfo: TVkComputePipelineCreateInfo; const aPipelineCache: VkPipelineCache; const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks); begin inherited Create(VK_INVALID_NDP_HANDLE, true, aDeviceCommands, aAllocCallbacks); CreateHandle(aCreateInfo, aPipelineCache); end; end.