unit uvkuPipelineLayoutFactory; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Vulkan, uvkuFactoryBase, uvkuPipelineLayout, uvkuTypes; type ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuPushConstantRange = class(TvkuStructure) public StageFlags: VkShaderStageFlags; Offset: VkUint32; Size: VkUint32; function GetStructure: TVkPushConstantRange; procedure SetStructure(const aData: TVkPushConstantRange); end; TvkuPushConstantRangeList = specialize TvkuObjList; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuPipelineLayoutFactory = class(TvkuDeviceObjFactory) private fFlags: VkPipelineLayoutCreateFlags; fSetLayouts: TVkDescriptorSetLayoutList; fPushConstantRanges: TvkuPushConstantRangeList; fvkPushConstantRanges: TVkPushConstantRangeArr; public property Flags: VkPipelineLayoutCreateFlags read fFlags write fFlags; property SetLayouts: TVkDescriptorSetLayoutList read fSetLayouts; property PushConstantRanges: TvkuPushConstantRangeList read fPushConstantRanges; function GetStructure: TVkPipelineLayoutCreateInfo; procedure SetStructure(const aData: TVkPipelineLayoutCreateInfo); function CreatePipelineLayout: TvkuPipelineLayout; procedure AfterConstruction; override; procedure BeforeDestruction; override; end; implementation uses uvkuUtils; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuPushConstantRange////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuPushConstantRange.GetStructure: TVkPushConstantRange; begin FillByte(result, SizeOf(result), 0); result.stageFlags := StageFlags; result.offset := Offset; result.size := Size; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuPushConstantRange.SetStructure(const aData: TVkPushConstantRange); begin StageFlags := aData.stageFlags; Offset := aData.offset; Size := aData.size; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuPipelineLayoutFactory////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuPipelineLayoutFactory.GetStructure: TVkPipelineLayoutCreateInfo; var i: Integer; begin SetLength(fvkPushConstantRanges, fPushConstantRanges.Length); for i := low(fvkPushConstantRanges) to high(fvkPushConstantRanges) do fvkPushConstantRanges[i] := fPushConstantRanges[i].GetStructure; FillByte(result, SizeOf(result), 0); result.sType := VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; result.pNext := nil; result.flags := fFlags; result.setLayoutCount := fSetLayouts.Length; result.pSetLayouts := fSetLayouts.PData; result.pushConstantRangeCount := Length(fvkPushConstantRanges); result.pPushConstantRanges := @fvkPushConstantRanges[0]; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuPipelineLayoutFactory.SetStructure(const aData: TVkPipelineLayoutCreateInfo); var i: Integer; begin fFlags := aData.flags; fSetLayouts.SetData(aData.pSetLayouts, aData.setLayoutCount); fPushConstantRanges.Length := aData.pushConstantRangeCount; for i := 0 to fPushConstantRanges.Length-1 do fPushConstantRanges[i].SetStructure((aData.pPushConstantRanges + i)^); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuPipelineLayoutFactory.CreatePipelineLayout: TvkuPipelineLayout; begin result := TvkuPipelineLayout.Create(GetStructure, DeviceCommands, AllocCallbacks); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuPipelineLayoutFactory.AfterConstruction; begin inherited AfterConstruction; fSetLayouts := TVkDescriptorSetLayoutList.Create; fPushConstantRanges := TvkuPushConstantRangeList.Create; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuPipelineLayoutFactory.BeforeDestruction; begin FreeAndNil(fPushConstantRanges); FreeAndNil(fSetLayouts); inherited BeforeDestruction; end; end.