| @@ -33,7 +33,7 @@ | |||||
| <PackageName Value="LCL"/> | <PackageName Value="LCL"/> | ||||
| </Item1> | </Item1> | ||||
| </RequiredPackages> | </RequiredPackages> | ||||
| <Units Count="7"> | |||||
| <Units Count="8"> | |||||
| <Unit0> | <Unit0> | ||||
| <Filename Value="triangle.lpr"/> | <Filename Value="triangle.lpr"/> | ||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| @@ -58,13 +58,17 @@ | |||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| </Unit4> | </Unit4> | ||||
| <Unit5> | <Unit5> | ||||
| <Filename Value="..\utils\uvkuInstanceEx.pas"/> | |||||
| <Filename Value="..\utils\uvkuInstanceFactory.pas"/> | |||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| </Unit5> | </Unit5> | ||||
| <Unit6> | <Unit6> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | ||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| </Unit6> | </Unit6> | ||||
| <Unit7> | |||||
| <Filename Value="..\utils\uvkuDevice.pas"/> | |||||
| <IsPartOfProject Value="True"/> | |||||
| </Unit7> | |||||
| </Units> | </Units> | ||||
| </ProjectOptions> | </ProjectOptions> | ||||
| <CompilerOptions> | <CompilerOptions> | ||||
| @@ -7,7 +7,7 @@ uses | |||||
| {$IFDEF UNIX}{$IFDEF UseCThreads} | {$IFDEF UNIX}{$IFDEF UseCThreads} | ||||
| cthreads, | cthreads, | ||||
| {$ENDIF}{$ENDIF} | {$ENDIF}{$ENDIF} | ||||
| Interfaces, Dialogs, Forms, uMainForm, Vulkan; | |||||
| Interfaces, Dialogs, Forms, uMainForm, Vulkan, uvkuDevice; | |||||
| {$R *.res} | {$R *.res} | ||||
| @@ -4,13 +4,13 @@ | |||||
| <PathDelim Value="\"/> | <PathDelim Value="\"/> | ||||
| <Version Value="9"/> | <Version Value="9"/> | ||||
| <BuildModes Active="Default"/> | <BuildModes Active="Default"/> | ||||
| <Units Count="12"> | |||||
| <Units Count="13"> | |||||
| <Unit0> | <Unit0> | ||||
| <Filename Value="triangle.lpr"/> | <Filename Value="triangle.lpr"/> | ||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| <EditorIndex Value="1"/> | <EditorIndex Value="1"/> | ||||
| <CursorPos X="48" Y="10"/> | |||||
| <UsageCount Value="32"/> | |||||
| <CursorPos X="60" Y="10"/> | |||||
| <UsageCount Value="34"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| </Unit0> | </Unit0> | ||||
| <Unit1> | <Unit1> | ||||
| @@ -19,54 +19,54 @@ | |||||
| <ComponentName Value="MainForm"/> | <ComponentName Value="MainForm"/> | ||||
| <HasResources Value="True"/> | <HasResources Value="True"/> | ||||
| <ResourceBaseClass Value="Form"/> | <ResourceBaseClass Value="Form"/> | ||||
| <CursorPos X="56" Y="9"/> | |||||
| <UsageCount Value="32"/> | |||||
| <TopLine Value="6"/> | |||||
| <CursorPos X="44" Y="9"/> | |||||
| <UsageCount Value="34"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| <LoadedDesigner Value="True"/> | <LoadedDesigner Value="True"/> | ||||
| </Unit1> | </Unit1> | ||||
| <Unit2> | <Unit2> | ||||
| <Filename Value="..\Vulkan.pas"/> | <Filename Value="..\Vulkan.pas"/> | ||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| <EditorIndex Value="6"/> | |||||
| <TopLine Value="1417"/> | |||||
| <CursorPos X="3" Y="1433"/> | |||||
| <UsageCount Value="32"/> | |||||
| <EditorIndex Value="7"/> | |||||
| <CursorPos X="33" Y="1694"/> | |||||
| <UsageCount Value="34"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| </Unit2> | </Unit2> | ||||
| <Unit3> | <Unit3> | ||||
| <Filename Value="..\utils\uvkuInstance.pas"/> | <Filename Value="..\utils\uvkuInstance.pas"/> | ||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| <EditorIndex Value="4"/> | <EditorIndex Value="4"/> | ||||
| <TopLine Value="43"/> | |||||
| <CursorPos Y="50"/> | |||||
| <UsageCount Value="30"/> | |||||
| <TopLine Value="3"/> | |||||
| <CursorPos X="44" Y="18"/> | |||||
| <UsageCount Value="32"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| </Unit3> | </Unit3> | ||||
| <Unit4> | <Unit4> | ||||
| <Filename Value="..\utils\uvkuUtils.pas"/> | <Filename Value="..\utils\uvkuUtils.pas"/> | ||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| <EditorIndex Value="8"/> | |||||
| <EditorIndex Value="9"/> | |||||
| <TopLine Value="28"/> | <TopLine Value="28"/> | ||||
| <CursorPos Y="40"/> | <CursorPos Y="40"/> | ||||
| <UsageCount Value="27"/> | |||||
| <UsageCount Value="29"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| </Unit4> | </Unit4> | ||||
| <Unit5> | <Unit5> | ||||
| <Filename Value="..\utils\uvkuInstanceEx.pas"/> | |||||
| <Filename Value="..\utils\uvkuInstanceFactory.pas"/> | |||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| <IsVisibleTab Value="True"/> | |||||
| <EditorIndex Value="2"/> | <EditorIndex Value="2"/> | ||||
| <CursorPos X="56" Y="212"/> | |||||
| <UsageCount Value="24"/> | |||||
| <TopLine Value="170"/> | |||||
| <CursorPos Y="186"/> | |||||
| <UsageCount Value="26"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| </Unit5> | </Unit5> | ||||
| <Unit6> | <Unit6> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | ||||
| <IsPartOfProject Value="True"/> | <IsPartOfProject Value="True"/> | ||||
| <IsVisibleTab Value="True"/> | |||||
| <EditorIndex Value="5"/> | <EditorIndex Value="5"/> | ||||
| <TopLine Value="17"/> | |||||
| <CursorPos X="14" Y="32"/> | |||||
| <UsageCount Value="24"/> | |||||
| <CursorPos X="32" Y="38"/> | |||||
| <UsageCount Value="26"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| </Unit6> | </Unit6> | ||||
| <Unit7> | <Unit7> | ||||
| @@ -74,7 +74,7 @@ | |||||
| <EditorIndex Value="3"/> | <EditorIndex Value="3"/> | ||||
| <TopLine Value="44"/> | <TopLine Value="44"/> | ||||
| <CursorPos X="27" Y="22"/> | <CursorPos X="27" Y="22"/> | ||||
| <UsageCount Value="14"/> | |||||
| <UsageCount Value="15"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| <DefaultSyntaxHighlighter Value="None"/> | <DefaultSyntaxHighlighter Value="None"/> | ||||
| </Unit7> | </Unit7> | ||||
| @@ -102,134 +102,90 @@ | |||||
| </Unit10> | </Unit10> | ||||
| <Unit11> | <Unit11> | ||||
| <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\sysstrh.inc"/> | <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\sysstrh.inc"/> | ||||
| <EditorIndex Value="7"/> | |||||
| <EditorIndex Value="8"/> | |||||
| <TopLine Value="96"/> | <TopLine Value="96"/> | ||||
| <CursorPos X="10" Y="112"/> | <CursorPos X="10" Y="112"/> | ||||
| <UsageCount Value="10"/> | |||||
| <UsageCount Value="11"/> | |||||
| <Loaded Value="True"/> | <Loaded Value="True"/> | ||||
| </Unit11> | </Unit11> | ||||
| <Unit12> | |||||
| <Filename Value="..\utils\uvkuDevice.pas"/> | |||||
| <IsPartOfProject Value="True"/> | |||||
| <EditorIndex Value="6"/> | |||||
| <TopLine Value="8"/> | |||||
| <CursorPos X="29" Y="31"/> | |||||
| <UsageCount Value="22"/> | |||||
| <Loaded Value="True"/> | |||||
| </Unit12> | |||||
| </Units> | </Units> | ||||
| <JumpHistory Count="30" HistoryIndex="27"> | |||||
| <JumpHistory Count="14" HistoryIndex="13"> | |||||
| <Position1> | <Position1> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="273" Column="36" TopLine="258"/> | |||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="83" Column="19" TopLine="64"/> | |||||
| </Position1> | </Position1> | ||||
| <Position2> | <Position2> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="268" Column="19" TopLine="249"/> | |||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="84" Column="16" TopLine="64"/> | |||||
| </Position2> | </Position2> | ||||
| <Position3> | <Position3> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="274" Column="29" TopLine="253"/> | |||||
| <Filename Value="triangle.lpr"/> | |||||
| <Caret Line="10" Column="40"/> | |||||
| </Position3> | </Position3> | ||||
| <Position4> | <Position4> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | ||||
| <Caret Line="511" Column="8" TopLine="490"/> | |||||
| <Caret Line="136" TopLine="14"/> | |||||
| </Position4> | </Position4> | ||||
| <Position5> | <Position5> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="517" Column="77" TopLine="503"/> | |||||
| <Filename Value="..\utils\uvkuDevice.pas"/> | |||||
| <Caret Line="18" Column="23"/> | |||||
| </Position5> | </Position5> | ||||
| <Position6> | <Position6> | ||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="59" Column="46" TopLine="36"/> | |||||
| <Filename Value="..\utils\uvkuDevice.pas"/> | |||||
| <Caret Line="31" Column="29" TopLine="8"/> | |||||
| </Position6> | </Position6> | ||||
| <Position7> | <Position7> | ||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="524" Column="35" TopLine="507"/> | |||||
| <Filename Value="..\Vulkan.pas"/> | |||||
| <Caret Line="1836" Column="25" TopLine="1817"/> | |||||
| </Position7> | </Position7> | ||||
| <Position8> | <Position8> | ||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="16" Column="60"/> | |||||
| <Filename Value="..\utils\uvkuInstance.pas"/> | |||||
| <Caret Line="13" Column="27" TopLine="6"/> | |||||
| </Position8> | </Position8> | ||||
| <Position9> | <Position9> | ||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="52" Column="10" TopLine="36"/> | |||||
| <Filename Value="..\utils\uvkuInstance.pas"/> | |||||
| <Caret Line="29" Column="87" TopLine="17"/> | |||||
| </Position9> | </Position9> | ||||
| <Position10> | <Position10> | ||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="18"/> | |||||
| <Filename Value="..\utils\uvkuInstance.pas"/> | |||||
| <Caret Line="84" Column="29" TopLine="65"/> | |||||
| </Position10> | </Position10> | ||||
| <Position11> | <Position11> | ||||
| <Filename Value="uMainForm.pas"/> | <Filename Value="uMainForm.pas"/> | ||||
| <Caret Line="85" Column="7" TopLine="57"/> | |||||
| <Caret Line="9" Column="56"/> | |||||
| </Position11> | </Position11> | ||||
| <Position12> | <Position12> | ||||
| <Filename Value="uMainForm.pas"/> | <Filename Value="uMainForm.pas"/> | ||||
| <Caret Line="83" Column="70" TopLine="64"/> | |||||
| <Caret Line="73" Column="26" TopLine="56"/> | |||||
| </Position12> | </Position12> | ||||
| <Position13> | <Position13> | ||||
| <Filename Value="uMainForm.pas"/> | <Filename Value="uMainForm.pas"/> | ||||
| <Caret Line="84" Column="64" TopLine="64"/> | |||||
| <Caret Line="25" Column="28" TopLine="10"/> | |||||
| </Position13> | </Position13> | ||||
| <Position14> | <Position14> | ||||
| <Filename Value="uMainForm.pas"/> | <Filename Value="uMainForm.pas"/> | ||||
| <Caret Line="83" Column="19" TopLine="64"/> | |||||
| <Caret Line="9" Column="44" TopLine="6"/> | |||||
| </Position14> | </Position14> | ||||
| <Position15> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="223" Column="17" TopLine="204"/> | |||||
| </Position15> | |||||
| <Position16> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="515" Column="7" TopLine="386"/> | |||||
| </Position16> | |||||
| <Position17> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="213" Column="52" TopLine="197"/> | |||||
| </Position17> | |||||
| <Position18> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="515" Column="7" TopLine="493"/> | |||||
| </Position18> | |||||
| <Position19> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="213" Column="52" TopLine="197"/> | |||||
| </Position19> | |||||
| <Position20> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="516" Column="10" TopLine="489"/> | |||||
| </Position20> | |||||
| <Position21> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="213" Column="52" TopLine="197"/> | |||||
| </Position21> | |||||
| <Position22> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="526" Column="46" TopLine="500"/> | |||||
| </Position22> | |||||
| <Position23> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="137" TopLine="127"/> | |||||
| </Position23> | |||||
| <Position24> | |||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="83" Column="19" TopLine="64"/> | |||||
| </Position24> | |||||
| <Position25> | |||||
| <Filename Value="uMainForm.pas"/> | |||||
| <Caret Line="84" Column="16" TopLine="64"/> | |||||
| </Position25> | |||||
| <Position26> | |||||
| <Filename Value="triangle.lpr"/> | |||||
| <Caret Line="10" Column="40"/> | |||||
| </Position26> | |||||
| <Position27> | |||||
| <Filename Value="..\utils\uvkuInstanceEx.pas"/> | |||||
| <Caret Line="9" Column="23" TopLine="37"/> | |||||
| </Position27> | |||||
| <Position28> | |||||
| <Filename Value="..\utils\uvkuPhysicalDevice.pas"/> | |||||
| <Caret Line="136" TopLine="14"/> | |||||
| </Position28> | |||||
| <Position29> | |||||
| <Filename Value="..\Vulkan.pas"/> | |||||
| <Caret Line="1433" Column="3" TopLine="1417"/> | |||||
| </Position29> | |||||
| <Position30> | |||||
| <Filename Value="..\Vulkan.pas"/> | |||||
| <Caret Line="1443" Column="22" TopLine="1426"/> | |||||
| </Position30> | |||||
| </JumpHistory> | </JumpHistory> | ||||
| </ProjectSession> | </ProjectSession> | ||||
| <Debugging> | |||||
| <BreakPoints Count="1"> | |||||
| <Item1> | |||||
| <Kind Value="bpkSource"/> | |||||
| <WatchScope Value="wpsLocal"/> | |||||
| <WatchKind Value="wpkWrite"/> | |||||
| <Source Value="..\utils\uvkuInstanceFactory.pas"/> | |||||
| <Line Value="186"/> | |||||
| </Item1> | |||||
| </BreakPoints> | |||||
| </Debugging> | |||||
| </CONFIG> | </CONFIG> | ||||
| @@ -6,7 +6,7 @@ interface | |||||
| uses | uses | ||||
| Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, | ||||
| Vulkan, uvkuInstanceEx, uvkuPhysicalDevice, uvkuUtils; | |||||
| Vulkan, uvkuInstance, uvkuInstanceFactory, uvkuPhysicalDevice, uvkuUtils; | |||||
| type | type | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -22,7 +22,7 @@ type | |||||
| procedure FormCreate(Sender: TObject); | procedure FormCreate(Sender: TObject); | ||||
| procedure FormDestroy(Sender: TObject); | procedure FormDestroy(Sender: TObject); | ||||
| private | private | ||||
| fIntance: TvkuInstanceEx; | |||||
| fInstance: TvkuInstance; | |||||
| public | public | ||||
| { public declarations } | { public declarations } | ||||
| end; | end; | ||||
| @@ -65,30 +65,21 @@ end; | |||||
| procedure TMainForm.FormCreate(Sender: TObject); | procedure TMainForm.FormCreate(Sender: TObject); | ||||
| var | var | ||||
| i: Integer; | i: Integer; | ||||
| d: TvkuPhysicalDevice; | |||||
| iFactory: TvkuInstanceFactory; | |||||
| begin | begin | ||||
| WriteLn('create vulkan instance'); | WriteLn('create vulkan instance'); | ||||
| fIntance := TvkuInstanceEx.Create( | |||||
| 0, | |||||
| [], | |||||
| [], | |||||
| TvkuInstanceEx.DefaultApplicationInfo, | |||||
| TvkuAllocationHandler.Create, | |||||
| true); | |||||
| WriteLn('read vulkan devices:'); | |||||
| for i := 0 to fIntance.PhysicalDeviceCount-1 do begin | |||||
| d := fIntance.PhysicalDevices[i]; | |||||
| WriteLn(vkuMakeString(d.GetFeatures, ', ')); | |||||
| WriteLn(vkuMakeString(d.GetProperties, true, true)); | |||||
| WriteLn(vkuMakeString(d.GetMemoryProperties)); | |||||
| iFactory := TvkuInstanceFactory.Create; | |||||
| try | |||||
| fInstance := iFactory.CreateInstance(TCustomAllocHandler.Create, true); | |||||
| finally | |||||
| FreeAndNil(iFactory); | |||||
| end; | end; | ||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TMainForm.FormDestroy(Sender: TObject); | procedure TMainForm.FormDestroy(Sender: TObject); | ||||
| begin | begin | ||||
| FreeAndNil(fIntance); | |||||
| FreeAndNil(fInstance); | |||||
| end; | end; | ||||
| end. | end. | ||||
| @@ -0,0 +1,42 @@ | |||||
| unit uvkuDevice; | |||||
| {$mode objfpc}{$H+} | |||||
| interface | |||||
| uses | |||||
| Classes, SysUtils, | |||||
| Vulkan; | |||||
| type | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| TvkuDevice = class(TObject) | |||||
| private | |||||
| fHandle: VkDevice; | |||||
| public | |||||
| property Handle: VkDevice read fHandle; | |||||
| constructor Create(const aPhysicalDevice: VkDevice); | |||||
| destructor Destroy; override; | |||||
| end; | |||||
| implementation | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| //TvkuDevice///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| constructor TvkuDevice.Create(const aPhysicalDevice: VkDevice); | |||||
| var | |||||
| info: TVkDeviceCreateInfo; | |||||
| begin | |||||
| inherited Create; | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| destructor TvkuDevice.Destroy; | |||||
| begin | |||||
| inherited Destroy; | |||||
| end; | |||||
| end. | |||||
| @@ -10,23 +10,25 @@ uses | |||||
| type | type | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TvkuPhysicalDeviceArr = array of VkPhysicalDevice; | |||||
| TvkuInstance = class(TObject) | TvkuInstance = class(TObject) | ||||
| private | private | ||||
| fHandle: VkInstance; | fHandle: VkInstance; | ||||
| fAllocCallbacks: PVkAllocationCallbacks; | fAllocCallbacks: PVkAllocationCallbacks; | ||||
| fPhysicalDevices: array of TvkuPhysicalDevice; | |||||
| fPhysicalDevices: TvkuPhysicalDeviceArr; | |||||
| function GetPhysicalDeviceCount: Integer; | function GetPhysicalDeviceCount: Integer; | ||||
| function GetPhysicalDevices(const aIndex: Integer): TvkuPhysicalDevice; | |||||
| function GetPhysicalDevice(const aIndex: Integer): VkPhysicalDevice; | |||||
| procedure UpdatePhysicalDevices; | procedure UpdatePhysicalDevices; | ||||
| procedure ClearPhysicalDevices; | |||||
| protected | protected | ||||
| procedure CreateHandle(aCreateInfo: PVkInstanceCreateInfo; aAllocCallbacks: PVkAllocationCallbacks); | procedure CreateHandle(aCreateInfo: PVkInstanceCreateInfo; aAllocCallbacks: PVkAllocationCallbacks); | ||||
| constructor Create; | constructor Create; | ||||
| public | public | ||||
| property Handle: VkInstance read fHandle; | |||||
| property PhysicalDeviceCount: Integer read GetPhysicalDeviceCount; | |||||
| property PhysicalDevices[const aIndex: Integer]: TvkuPhysicalDevice read GetPhysicalDevices; | |||||
| property Handle: VkInstance read fHandle; | |||||
| property PhysicalDeviceCount: Integer read GetPhysicalDeviceCount; | |||||
| property PhysicalDevices[const aIndex: Integer]: VkPhysicalDevice read GetPhysicalDevice; | |||||
| function GetPhysicalDevices: TvkuPhysicalDeviceArr; | |||||
| constructor Create(const aCreateInfo: TVkInstanceCreateInfo); | constructor Create(const aCreateInfo: TVkInstanceCreateInfo); | ||||
| constructor Create(const aCreateInfo: TVkInstanceCreateInfo; const aAllocCallbacks: TVkAllocationCallbacks); | constructor Create(const aCreateInfo: TVkInstanceCreateInfo; const aAllocCallbacks: TVkAllocationCallbacks); | ||||
| @@ -48,7 +50,7 @@ begin | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TvkuInstance.GetPhysicalDevices(const aIndex: Integer): TvkuPhysicalDevice; | |||||
| function TvkuInstance.GetPhysicalDevice(const aIndex: Integer): VkPhysicalDevice; | |||||
| begin | begin | ||||
| UpdatePhysicalDevices; | UpdatePhysicalDevices; | ||||
| if (aIndex < Low(fPhysicalDevices)) or (aIndex > High(fPhysicalDevices)) then | if (aIndex < Low(fPhysicalDevices)) or (aIndex > High(fPhysicalDevices)) then | ||||
| @@ -59,9 +61,7 @@ end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TvkuInstance.UpdatePhysicalDevices; | procedure TvkuInstance.UpdatePhysicalDevices; | ||||
| var | var | ||||
| i: Integer; | |||||
| c: VkUint32; | c: VkUint32; | ||||
| arr: array of VkPhysicalDevice; | |||||
| err: TVkResult; | err: TVkResult; | ||||
| begin | begin | ||||
| if (Length(fPhysicalDevices) > 0) then | if (Length(fPhysicalDevices) > 0) then | ||||
| @@ -70,24 +70,18 @@ begin | |||||
| err := vkEnumeratePhysicalDevices(fHandle, @c, nil); | err := vkEnumeratePhysicalDevices(fHandle, @c, nil); | ||||
| if (err < VK_SUCCESS) then | if (err < VK_SUCCESS) then | ||||
| raise TvkuErrorException.Create('unable to get physical device number', err); | raise TvkuErrorException.Create('unable to get physical device number', err); | ||||
| SetLength(arr, c); | |||||
| SetLength(fPhysicalDevices, c); | |||||
| err := vkEnumeratePhysicalDevices(fHandle, @c, @arr[0]); | |||||
| err := vkEnumeratePhysicalDevices(fHandle, @c, @fPhysicalDevices[0]); | |||||
| if (err < VK_SUCCESS) then | if (err < VK_SUCCESS) then | ||||
| raise TvkuErrorException.Create('unable to get physical devices', err); | raise TvkuErrorException.Create('unable to get physical devices', err); | ||||
| SetLength(fPhysicalDevices, c); | |||||
| for i := 0 to c-1 do | |||||
| fPhysicalDevices[i] := TvkuPhysicalDevice.Create(arr[i]); | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TvkuInstance.ClearPhysicalDevices; | |||||
| var i: Integer; | |||||
| function TvkuInstance.GetPhysicalDevices: TvkuPhysicalDeviceArr; | |||||
| begin | begin | ||||
| for i := low(fPhysicalDevices) to high(fPhysicalDevices) do | |||||
| FreeAndNil(fPhysicalDevices[i]); | |||||
| SetLength(fPhysicalDevices, 0); | |||||
| UpdatePhysicalDevices; | |||||
| result := fPhysicalDevices; | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -128,7 +122,6 @@ end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| destructor TvkuInstance.Destroy; | destructor TvkuInstance.Destroy; | ||||
| begin | begin | ||||
| ClearPhysicalDevices; | |||||
| if Assigned(fHandle) then begin | if Assigned(fHandle) then begin | ||||
| vkDestroyInstance(fHandle, fAllocCallbacks); | vkDestroyInstance(fHandle, fAllocCallbacks); | ||||
| fHandle := nil; | fHandle := nil; | ||||
| @@ -1,4 +1,4 @@ | |||||
| unit uvkuInstanceEx; | |||||
| unit uvkuInstanceFactory; | |||||
| {$mode objfpc}{$H+} | {$mode objfpc}{$H+} | ||||
| @@ -30,64 +30,69 @@ type | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TvkuInstanceEx = class(TvkuInstance) | |||||
| TvkuInstanceFactory = class(TObject) | |||||
| private type | |||||
| TvkuInstanceEx = class(TvkuInstance) | |||||
| private | |||||
| fAllocHandler: TvkuAllocationHandler; | |||||
| fOwnsHandler: Boolean; | |||||
| public | |||||
| constructor Create(const aCreateInfo: TVkInstanceCreateInfo; const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean); | |||||
| destructor Destroy; override; | |||||
| end; | |||||
| private | private | ||||
| fFlags: VkInstanceCreateFlags; | |||||
| fOwnsAllocHandler: Boolean; | |||||
| fAllocationHandler: TvkuAllocationHandler; | |||||
| fApplicationInfo: TvkuApplicationInfo; | |||||
| fFlags: VkInstanceCreateFlags; | |||||
| fApplicationInfo: TvkuApplicationInfo; | |||||
| fLayers: TStringList; | fLayers: TStringList; | ||||
| fExtensions: TStringList; | fExtensions: TStringList; | ||||
| function GetLayers: TStrings; | function GetLayers: TStrings; | ||||
| function GetExtensions: TStrings; | function GetExtensions: TStrings; | ||||
| procedure Initialize; | |||||
| procedure MakeStringsFromArray(const aArray: array of String; const aStrings: TStrings); | |||||
| procedure CreateHandle; | |||||
| public | public | ||||
| property Flags: VkInstanceCreateFlags read fFlags; | |||||
| property OwnsAllocHandler: Boolean read fOwnsAllocHandler; | |||||
| property AllocationHandler: TvkuAllocationHandler read fAllocationHandler; | |||||
| property ApplicationInfo: TvkuApplicationInfo read fApplicationInfo; | |||||
| property Layers: TStrings read GetLayers; | |||||
| property Extensions: TStrings read GetExtensions; | |||||
| constructor Create; | |||||
| property Flags: VkInstanceCreateFlags read fFlags; | |||||
| property ApplicationInfo: TvkuApplicationInfo read fApplicationInfo; | |||||
| property Layers: TStrings read GetLayers; | |||||
| property Extensions: TStrings read GetExtensions; | |||||
| constructor Create( | |||||
| const aFlags: VkInstanceCreateFlags; | |||||
| const aLayers: array of String; | |||||
| const aExtensions: array of String); | |||||
| constructor Create( | |||||
| const aFlags: VkInstanceCreateFlags; | |||||
| const aLayers: array of String; | |||||
| const aExtensions: array of String; | |||||
| const aAppInfo: TvkuApplicationInfo); | |||||
| constructor Create( | |||||
| const aFlags: VkInstanceCreateFlags; | |||||
| const aLayers: array of String; | |||||
| const aExtensions: array of String; | |||||
| const aAppInfo: TvkuApplicationInfo; | |||||
| const aAllocHandler: TvkuAllocationHandler; | |||||
| const aOwnsAllocHandler: Boolean); | |||||
| function CreateInstance: TvkuInstance; | |||||
| function CreateInstance(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuInstance; | |||||
| constructor Create; | |||||
| destructor Destroy; override; | destructor Destroy; override; | ||||
| public | |||||
| class function DefaultApplicationInfo: TvkuApplicationInfo; | |||||
| class function MakeApplicationInfo( | |||||
| aAppName: String; | |||||
| aAppVersion: VkVersion; | |||||
| aEngineName: String; | |||||
| aEngineVersion: VkVersion; | |||||
| aApiVersion: VkVersion = VK_API_VERSION): TvkuApplicationInfo; | |||||
| end; | end; | ||||
| function vkuApplicationInfo: TvkuApplicationInfo; | |||||
| function vkuApplicationInfo( | |||||
| aAppName: String; | |||||
| aAppVersion: VkVersion; | |||||
| aEngineName: String; | |||||
| aEngineVersion: VkVersion; | |||||
| aApiVersion: VkVersion = VK_API_VERSION): TvkuApplicationInfo; | |||||
| implementation | implementation | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function vkuApplicationInfo: TvkuApplicationInfo; | |||||
| begin | |||||
| result.AppName := ExtractFileName(ParamStr(0)); | |||||
| result.AppVersion := 0; | |||||
| result.EngineName := ExtractFileName(ParamStr(0)); | |||||
| result.EngineVersion := 0; | |||||
| result.ApiVersion := VK_API_VERSION; | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function vkuApplicationInfo(aAppName: String; aAppVersion: VkVersion; aEngineName: String; aEngineVersion: VkVersion; aApiVersion: VkVersion): TvkuApplicationInfo; | |||||
| begin | |||||
| result := vkuApplicationInfo; | |||||
| result.AppName := aAppName; | |||||
| result.AppVersion := aAppVersion; | |||||
| result.EngineName := aEngineName; | |||||
| result.EngineVersion := aEngineVersion; | |||||
| result.ApiVersion := aApiVersion; | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TvkuAllocationHandler////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //TvkuAllocationHandler////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -153,43 +158,60 @@ begin | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TvkuInstanceEx/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| //TvkuInstanceFactory.TvkuInstanceEx///////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TvkuInstanceEx.GetLayers: TStrings; | |||||
| constructor TvkuInstanceFactory.TvkuInstanceEx.Create(const aCreateInfo: TVkInstanceCreateInfo; const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean); | |||||
| var | |||||
| AllocCallbacks: TVkAllocationCallbacks; | |||||
| begin | begin | ||||
| result := fLayers; | |||||
| fOwnsHandler := aOwnsHandler; | |||||
| fAllocHandler := aAllocHandler; | |||||
| if Assigned(fAllocHandler) then begin | |||||
| FillByte(AllocCallbacks, SizeOf(AllocCallbacks), 0); | |||||
| AllocCallbacks.pUserData := fAllocHandler; | |||||
| AllocCallbacks.pfnAllocation := @AllocateMemoryCallback; | |||||
| AllocCallbacks.pfnReallocation := @ReallocateMemoryCallback; | |||||
| AllocCallbacks.pfnFree := @FreeMemoryCallback; | |||||
| AllocCallbacks.pfnInternalAllocation := @InternalAllocationCallback; | |||||
| AllocCallbacks.pfnInternalFree := @InternalFreeCallback; | |||||
| inherited Create(aCreateInfo, AllocCallbacks); | |||||
| end else | |||||
| inherited Create(aCreateInfo); | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TvkuInstanceEx.GetExtensions: TStrings; | |||||
| destructor TvkuInstanceFactory.TvkuInstanceEx.Destroy; | |||||
| begin | begin | ||||
| result := fExtensions; | |||||
| inherited Destroy; | |||||
| if fOwnsHandler then | |||||
| FreeAndNil(fAllocHandler); | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| //TvkuInstanceFactory/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function TvkuInstanceFactory.GetLayers: TStrings; | |||||
| begin | |||||
| result := fLayers; | |||||
| end; | end; | ||||
| procedure TvkuInstanceEx.Initialize; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function TvkuInstanceFactory.GetExtensions: TStrings; | |||||
| begin | begin | ||||
| fLayers := TStringList.Create; | |||||
| fExtensions := TStringList.Create; | |||||
| fApplicationInfo := DefaultApplicationInfo; | |||||
| fFlags := 0; | |||||
| fAllocationHandler := nil; | |||||
| fOwnsAllocHandler := false; | |||||
| result := fExtensions; | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TvkuInstanceEx.MakeStringsFromArray(const aArray: array of String; const aStrings: TStrings); | |||||
| var i: Integer; | |||||
| function TvkuInstanceFactory.CreateInstance: TvkuInstance; | |||||
| begin | begin | ||||
| for i := Low(aArray) to High(aArray) do | |||||
| aStrings.Add(aArray[i]); | |||||
| result := CreateInstance(nil, false); | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TvkuInstanceEx.CreateHandle; | |||||
| function TvkuInstanceFactory.CreateInstance(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuInstance; | |||||
| var | var | ||||
| CreateInfo: TVkInstanceCreateInfo; | |||||
| AppInfo: TVkApplicationInfo; | |||||
| AllocCallbacks: TVkAllocationCallbacks; | |||||
| CreateInfo: TVkInstanceCreateInfo; | |||||
| AppInfo: TVkApplicationInfo; | |||||
| i: Integer; | i: Integer; | ||||
| lay: array of PVkChar; | lay: array of PVkChar; | ||||
| ext: array of PVkChar; | ext: array of PVkChar; | ||||
| @@ -221,95 +243,25 @@ begin | |||||
| CreateInfo.enabledExtensionCount := Length(ext); | CreateInfo.enabledExtensionCount := Length(ext); | ||||
| CreateInfo.ppEnabledExtensionNames := @ext[0]; | CreateInfo.ppEnabledExtensionNames := @ext[0]; | ||||
| if Assigned(fAllocationHandler) then begin | |||||
| FillByte(AllocCallbacks, SizeOf(AllocCallbacks), 0); | |||||
| AllocCallbacks.pUserData := fAllocationHandler; | |||||
| AllocCallbacks.pfnAllocation := @AllocateMemoryCallback; | |||||
| AllocCallbacks.pfnReallocation := @ReallocateMemoryCallback; | |||||
| AllocCallbacks.pfnFree := @FreeMemoryCallback; | |||||
| AllocCallbacks.pfnInternalAllocation := @InternalAllocationCallback; | |||||
| AllocCallbacks.pfnInternalFree := @InternalFreeCallback; | |||||
| inherited CreateHandle(@CreateInfo, @AllocCallbacks); | |||||
| end else | |||||
| inherited CreateHandle(@CreateInfo, nil); | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| constructor TvkuInstanceEx.Create; | |||||
| begin | |||||
| Initialize; | |||||
| CreateHandle; | |||||
| result := TvkuInstanceEx.Create(CreateInfo, aAllocHandler, aOwnsHandler); | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TvkuInstanceEx.Create(const aFlags: VkInstanceCreateFlags; | |||||
| const aLayers: array of String; const aExtensions: array of String); | |||||
| constructor TvkuInstanceFactory.Create; | |||||
| begin | begin | ||||
| inherited Create; | inherited Create; | ||||
| Initialize; | |||||
| fFlags := aFlags; | |||||
| MakeStringsFromArray(aLayers, fLayers); | |||||
| MakeStringsFromArray(aExtensions, fExtensions); | |||||
| CreateHandle; | |||||
| fLayers := TStringList.Create; | |||||
| fExtensions := TStringList.Create; | |||||
| fApplicationInfo := vkuApplicationInfo; | |||||
| fFlags := 0; | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TvkuInstanceEx.Create(const aFlags: VkInstanceCreateFlags;const aLayers: array of String; | |||||
| const aExtensions: array of String; const aAppInfo: TvkuApplicationInfo); | |||||
| destructor TvkuInstanceFactory.Destroy; | |||||
| begin | begin | ||||
| inherited Create; | |||||
| Initialize; | |||||
| fFlags := aFlags; | |||||
| fApplicationInfo := aAppInfo; | |||||
| MakeStringsFromArray(aLayers, fLayers); | |||||
| MakeStringsFromArray(aExtensions, fExtensions); | |||||
| CreateHandle; | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| constructor TvkuInstanceEx.Create(const aFlags: VkInstanceCreateFlags; const aLayers: array of String;const aExtensions: array of String; | |||||
| const aAppInfo: TvkuApplicationInfo; const aAllocHandler: TvkuAllocationHandler; const aOwnsAllocHandler: Boolean); | |||||
| begin | |||||
| inherited Create; | |||||
| Initialize; | |||||
| fFlags := aFlags; | |||||
| fApplicationInfo := aAppInfo; | |||||
| fAllocationHandler := aAllocHandler; | |||||
| fOwnsAllocHandler := aOwnsAllocHandler; | |||||
| MakeStringsFromArray(aLayers, fLayers); | |||||
| MakeStringsFromArray(aExtensions, fExtensions); | |||||
| CreateHandle; | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| destructor TvkuInstanceEx.Destroy; | |||||
| begin | |||||
| inherited Destroy; | |||||
| if fOwnsAllocHandler then | |||||
| FreeAndNil(fAllocationHandler); | |||||
| FreeAndNil(fLayers); | FreeAndNil(fLayers); | ||||
| FreeAndNil(fExtensions); | FreeAndNil(fExtensions); | ||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| class function TvkuInstanceEx.DefaultApplicationInfo: TvkuApplicationInfo; | |||||
| begin | |||||
| result.AppName := ExtractFileName(ParamStr(0)); | |||||
| result.AppVersion := 0; | |||||
| result.EngineName := ExtractFileName(ParamStr(0)); | |||||
| result.EngineVersion := 0; | |||||
| result.ApiVersion := VK_API_VERSION; | |||||
| end; | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| class function TvkuInstanceEx.MakeApplicationInfo(aAppName: String; aAppVersion: VkVersion; aEngineName: String; aEngineVersion: VkVersion; aApiVersion: VkVersion): TvkuApplicationInfo; | |||||
| begin | |||||
| result := DefaultApplicationInfo; | |||||
| result.AppName := aAppName; | |||||
| result.AppVersion := aAppVersion; | |||||
| result.EngineName := aEngineName; | |||||
| result.EngineVersion := aEngineVersion; | |||||
| result.ApiVersion := aApiVersion; | |||||
| inherited Destroy; | |||||
| end; | end; | ||||
| end. | end. | ||||