Explorar el Código

* implemented Buffer, BufferView, CommandBuffer, CommandPool, DeviceMemory, Image, ImageView and Queue

master
Bergmann89 hace 10 años
padre
commit
0bcfe56b08
Se han modificado 31 ficheros con 2178 adiciones y 472 borrados
  1. +66
    -6
      projects/triangle/triangle.lpi
  2. +294
    -175
      projects/triangle/triangle.lps
  3. +9
    -14
      projects/triangle/uMainForm.pas
  4. +87
    -0
      projects/utils/VulkanUtils.pas
  5. +40
    -7
      projects/utils/uvkuAllocationHandler.pas
  6. +92
    -0
      projects/utils/uvkuBase.pas
  7. +82
    -0
      projects/utils/uvkuBuffer.pas
  8. +140
    -0
      projects/utils/uvkuBufferFactory.pas
  9. +82
    -0
      projects/utils/uvkuBufferView.pas
  10. +107
    -0
      projects/utils/uvkuBufferViewFactory.pas
  11. +56
    -0
      projects/utils/uvkuCommandBuffer.pas
  12. +128
    -0
      projects/utils/uvkuCommandPool.pas
  13. +92
    -0
      projects/utils/uvkuCommandPoolFactory.pas
  14. +35
    -34
      projects/utils/uvkuDevice.pas
  15. +6
    -15
      projects/utils/uvkuDeviceFactory.pas
  16. +100
    -0
      projects/utils/uvkuDeviceMemory.pas
  17. +177
    -0
      projects/utils/uvkuImage.pas
  18. +161
    -0
      projects/utils/uvkuImageFactory.pas
  19. +84
    -0
      projects/utils/uvkuImageView.pas
  20. +110
    -0
      projects/utils/uvkuImageViewFactory.pas
  21. +23
    -39
      projects/utils/uvkuInstance.pas
  22. +6
    -15
      projects/utils/uvkuInstanceFactory.pas
  23. +20
    -27
      projects/utils/uvkuPhysicalDevice.pas
  24. +0
    -41
      projects/utils/uvkuPhysicalDeviceFactory.pas
  25. +39
    -0
      projects/utils/uvkuQueue.pas
  26. +26
    -36
      projects/utils/uvkuSurface.pas
  27. +9
    -11
      projects/utils/uvkuSurfaceFactory.pas
  28. +28
    -42
      projects/utils/uvkuSwapChain.pas
  29. +7
    -10
      projects/utils/uvkuSwapChainFactory.pas
  30. +45
    -0
      projects/utils/uvkuTypes.pas
  31. +27
    -0
      projects/utils/uvkuUtils.pas

+ 66
- 6
projects/triangle/triangle.lpi Ver fichero

@@ -33,7 +33,7 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item1> </Item1>
</RequiredPackages> </RequiredPackages>
<Units Count="14">
<Units Count="29">
<Unit0> <Unit0>
<Filename Value="triangle.lpr"/> <Filename Value="triangle.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@@ -74,25 +74,85 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit8> </Unit8>
<Unit9> <Unit9>
<Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit9> </Unit9>
<Unit10> <Unit10>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit10> </Unit10>
<Unit11> <Unit11>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit11> </Unit11>
<Unit12> <Unit12>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit12> </Unit12>
<Unit13> <Unit13>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Filename Value="..\utils\uvkuImageView.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit13> </Unit13>
<Unit14>
<Filename Value="..\utils\uvkuImageViewFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit14>
<Unit15>
<Filename Value="..\utils\uvkuImage.pas"/>
<IsPartOfProject Value="True"/>
</Unit15>
<Unit16>
<Filename Value="..\utils\uvkuBase.pas"/>
<IsPartOfProject Value="True"/>
</Unit16>
<Unit17>
<Filename Value="..\utils\uvkuDeviceMemory.pas"/>
<IsPartOfProject Value="True"/>
</Unit17>
<Unit18>
<Filename Value="..\utils\uvkuBuffer.pas"/>
<IsPartOfProject Value="True"/>
</Unit18>
<Unit19>
<Filename Value="..\utils\uvkuImageFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit19>
<Unit20>
<Filename Value="..\utils\uvkuTypes.pas"/>
<IsPartOfProject Value="True"/>
</Unit20>
<Unit21>
<Filename Value="..\utils\uvkuBufferFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit21>
<Unit22>
<Filename Value="..\utils\uvkuBufferView.pas"/>
<IsPartOfProject Value="True"/>
</Unit22>
<Unit23>
<Filename Value="..\utils\uvkuBufferViewFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit23>
<Unit24>
<Filename Value="..\utils\uvkuCommandPool.pas"/>
<IsPartOfProject Value="True"/>
</Unit24>
<Unit25>
<Filename Value="..\utils\uvkuCommandPoolFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit25>
<Unit26>
<Filename Value="..\utils\uvkuCommandBuffer.pas"/>
<IsPartOfProject Value="True"/>
</Unit26>
<Unit27>
<Filename Value="..\utils\uvkuQueue.pas"/>
<IsPartOfProject Value="True"/>
</Unit27>
<Unit28>
<Filename Value="..\utils\VulkanUtils.pas"/>
<IsPartOfProject Value="True"/>
</Unit28>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>


+ 294
- 175
projects/triangle/triangle.lps Ver fichero

@@ -4,13 +4,13 @@
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Version Value="9"/> <Version Value="9"/>
<BuildModes Active="Default"/> <BuildModes Active="Default"/>
<Units Count="32">
<Units Count="48">
<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"/> <CursorPos X="48" Y="10"/>
<UsageCount Value="55"/>
<UsageCount Value="66"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="uMainForm.pas"/> <Filename Value="uMainForm.pas"/>
@@ -18,383 +18,502 @@
<ComponentName Value="MainForm"/> <ComponentName Value="MainForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<TopLine Value="20"/>
<CursorPos X="5" Y="36"/>
<UsageCount Value="55"/>
<TopLine Value="121"/>
<CursorPos X="33" Y="177"/>
<UsageCount Value="66"/>
<Loaded Value="True"/> <Loaded 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="7"/>
<TopLine Value="4263"/>
<CursorPos X="61" Y="4268"/>
<EditorIndex Value="9"/>
<TopLine Value="1301"/>
<CursorPos X="3" Y="1316"/>
<ExtraEditorCount Value="1"/> <ExtraEditorCount Value="1"/>
<ExtraEditor1> <ExtraEditor1>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="42"/>
<CursorPos X="12" Y="50"/>
<TopLine Value="2048"/>
<CursorPos X="17" Y="2064"/>
</ExtraEditor1> </ExtraEditor1>
<UsageCount Value="55"/>
<UsageCount Value="66"/>
<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="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="98"/>
<CursorPos X="33" Y="117"/>
<UsageCount Value="53"/>
<CursorPos X="30" Y="9"/>
<UsageCount Value="64"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/> <Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="42"/>
<CursorPos Y="55"/>
<UsageCount Value="47"/>
<TopLine Value="29"/>
<CursorPos X="3" Y="23"/>
<UsageCount Value="58"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/> <Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="4"/>
<TopLine Value="154"/>
<CursorPos X="3" Y="163"/>
<UsageCount Value="47"/>
<EditorIndex Value="8"/>
<TopLine Value="245"/>
<CursorPos X="38" Y="252"/>
<UsageCount Value="58"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/> <Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="5"/>
<TopLine Value="73"/>
<CursorPos Y="100"/>
<UsageCount Value="37"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="91"/>
<CursorPos X="39" Y="99"/>
<UsageCount Value="48"/>
</Unit6> </Unit6>
<Unit7> <Unit7>
<Filename Value="..\utils\uvkuDevice.pas"/> <Filename Value="..\utils\uvkuDevice.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="3"/>
<TopLine Value="21"/>
<CursorPos Y="50"/>
<UsageCount Value="41"/>
<EditorIndex Value="2"/>
<TopLine Value="51"/>
<CursorPos X="63" Y="66"/>
<UsageCount Value="52"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit7> </Unit7>
<Unit8> <Unit8>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/> <Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="165"/>
<CursorPos Y="158"/>
<UsageCount Value="39"/>
<TopLine Value="37"/>
<CursorPos X="49" Y="56"/>
<UsageCount Value="50"/>
</Unit8> </Unit8>
<Unit9> <Unit9>
<Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/> <Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="74" Y="30"/>
<UsageCount Value="40"/>
<TopLine Value="5"/>
<CursorPos X="19" Y="17"/>
<UsageCount Value="49"/>
</Unit9> </Unit9>
<Unit10> <Unit10>
<Filename Value="..\utils\uvkuSurface.pas"/> <Filename Value="..\utils\uvkuSurface.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="2"/>
<TopLine Value="11"/>
<CursorPos X="71" Y="66"/>
<UsageCount Value="34"/>
<EditorIndex Value="3"/>
<TopLine Value="41"/>
<CursorPos X="94" Y="56"/>
<UsageCount Value="45"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit10> </Unit10>
<Unit11> <Unit11>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/> <Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="187"/>
<CursorPos Y="200"/>
<UsageCount Value="33"/>
<TopLine Value="30"/>
<CursorPos X="42" Y="43"/>
<UsageCount Value="44"/>
</Unit11> </Unit11>
<Unit12> <Unit12>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/> <Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="128"/>
<CursorPos Y="152"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="141"/>
<CursorPos X="11" Y="156"/>
<UsageCount Value="35"/>
</Unit12> </Unit12>
<Unit13> <Unit13>
<Filename Value="..\utils\uvkuSwapChain.pas"/> <Filename Value="..\utils\uvkuSwapChain.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="6"/>
<CursorPos X="65" Y="93"/>
<UsageCount Value="23"/>
<EditorIndex Value="4"/>
<TopLine Value="62"/>
<CursorPos X="35" Y="78"/>
<UsageCount Value="34"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit13> </Unit13>
<Unit14> <Unit14>
<Filename Value="..\utils\uvkuUtils.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="423"/>
<CursorPos X="61" Y="447"/>
<UsageCount Value="43"/>
<Filename Value="..\utils\uvkuImageView.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="5"/>
<TopLine Value="29"/>
<CursorPos X="64" Y="47"/>
<UsageCount Value="31"/>
<Loaded Value="True"/>
</Unit14> </Unit14>
<Unit15> <Unit15>
<Filename Value="..\utils\uvkuImageViewFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="34"/>
<CursorPos X="52" Y="45"/>
<UsageCount Value="31"/>
</Unit15>
<Unit16>
<Filename Value="..\utils\uvkuImage.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="36"/>
<CursorPos X="102" Y="51"/>
<UsageCount Value="30"/>
</Unit16>
<Unit17>
<Filename Value="..\utils\uvkuUtils.pas"/>
<EditorIndex Value="7"/>
<TopLine Value="41"/>
<CursorPos X="45" Y="61"/>
<UsageCount Value="42"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="..\..\data\Vulkan.tpl"/> <Filename Value="..\..\data\Vulkan.tpl"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="44"/> <TopLine Value="44"/>
<CursorPos X="27" Y="22"/> <CursorPos X="27" Y="22"/>
<UsageCount Value="14"/>
<UsageCount Value="13"/>
<DefaultSyntaxHighlighter Value="None"/> <DefaultSyntaxHighlighter Value="None"/>
</Unit15>
<Unit16>
</Unit18>
<Unit19>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\packages\fcl-base\src\custapp.pp"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\packages\fcl-base\src\custapp.pp"/>
<UnitName Value="CustApp"/> <UnitName Value="CustApp"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="13"/> <TopLine Value="13"/>
<CursorPos X="3" Y="30"/> <CursorPos X="3" Y="30"/>
<UsageCount Value="10"/>
</Unit16>
<Unit17>
<UsageCount Value="9"/>
</Unit19>
<Unit20>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\inc\objpash.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\inc\objpash.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="213"/> <TopLine Value="213"/>
<CursorPos X="21" Y="224"/> <CursorPos X="21" Y="224"/>
<UsageCount Value="9"/>
</Unit17>
<Unit18>
<UsageCount Value="8"/>
</Unit20>
<Unit21>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\include\customform.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\lcl\include\customform.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="138"/> <TopLine Value="138"/>
<CursorPos Y="154"/> <CursorPos Y="154"/>
<UsageCount Value="9"/>
</Unit18>
<Unit19>
<UsageCount Value="8"/>
</Unit21>
<Unit22>
<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="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="96"/> <TopLine Value="96"/>
<CursorPos X="10" Y="112"/> <CursorPos X="10" Y="112"/>
<UsageCount Value="10"/>
</Unit19>
<Unit20>
<UsageCount Value="9"/>
</Unit22>
<Unit23>
<Filename Value="..\Vulkan_old.pas"/> <Filename Value="..\Vulkan_old.pas"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<WindowIndex Value="-1"/> <WindowIndex Value="-1"/>
<TopLine Value="2195"/> <TopLine Value="2195"/>
<CursorPos X="3" Y="2211"/> <CursorPos X="3" Y="2211"/>
<UsageCount Value="10"/>
</Unit20>
<Unit21>
<UsageCount Value="9"/>
</Unit23>
<Unit24>
<Filename Value="..\Vulkan.inc"/> <Filename Value="..\Vulkan.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="9" Y="5"/> <CursorPos X="9" Y="5"/>
<UsageCount Value="11"/>
</Unit21>
<Unit22>
<UsageCount Value="10"/>
</Unit24>
<Unit25>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\forms.pp"/> <Filename Value="C:\Zusatzprogramme\Lazarus\lcl\forms.pp"/>
<UnitName Value="Forms"/> <UnitName Value="Forms"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="1249"/> <TopLine Value="1249"/>
<CursorPos X="3" Y="1268"/> <CursorPos X="3" Y="1268"/>
<UsageCount Value="10"/>
</Unit22>
<Unit23>
<UsageCount Value="9"/>
</Unit25>
<Unit26>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\classes\classesh.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\classes\classesh.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="2100"/> <TopLine Value="2100"/>
<CursorPos X="38" Y="2125"/> <CursorPos X="38" Y="2125"/>
<UsageCount Value="10"/>
</Unit23>
<Unit24>
<UsageCount Value="9"/>
</Unit26>
<Unit27>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\extctrls.pp"/> <Filename Value="C:\Zusatzprogramme\Lazarus\lcl\extctrls.pp"/>
<UnitName Value="ExtCtrls"/> <UnitName Value="ExtCtrls"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="1023"/> <TopLine Value="1023"/>
<CursorPos X="3" Y="1038"/> <CursorPos X="3" Y="1038"/>
<UsageCount Value="10"/>
</Unit24>
<Unit25>
<UsageCount Value="9"/>
</Unit27>
<Unit28>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\controls.pp"/> <Filename Value="C:\Zusatzprogramme\Lazarus\lcl\controls.pp"/>
<UnitName Value="Controls"/> <UnitName Value="Controls"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="2240"/> <TopLine Value="2240"/>
<CursorPos X="3" Y="2255"/> <CursorPos X="3" Y="2255"/>
<UsageCount Value="10"/>
</Unit25>
<Unit26>
<UsageCount Value="9"/>
</Unit28>
<Unit29>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\sysutilh.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\sysutilh.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="22"/> <TopLine Value="22"/>
<CursorPos X="4" Y="37"/> <CursorPos X="4" Y="37"/>
<UsageCount Value="12"/>
</Unit26>
<Unit27>
<UsageCount Value="11"/>
</Unit29>
<Unit30>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\sysosh.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\sysosh.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="7"/> <TopLine Value="7"/>
<CursorPos X="3" Y="22"/> <CursorPos X="3" Y="22"/>
<UsageCount Value="12"/>
</Unit27>
<Unit28>
<UsageCount Value="11"/>
</Unit30>
<Unit31>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\inc\systemh.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\inc\systemh.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="93"/> <TopLine Value="93"/>
<CursorPos X="19" Y="108"/> <CursorPos X="19" Y="108"/>
<UsageCount Value="12"/>
</Unit28>
<Unit29>
<UsageCount Value="11"/>
</Unit31>
<Unit32>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\ascdef.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\ascdef.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="57"/> <TopLine Value="57"/>
<CursorPos X="10" Y="72"/> <CursorPos X="10" Y="72"/>
<UsageCount Value="12"/>
</Unit29>
<Unit30>
<UsageCount Value="11"/>
</Unit32>
<Unit33>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win32\windows.pp"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win32\windows.pp"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<UsageCount Value="12"/>
</Unit30>
<Unit31>
<UsageCount Value="11"/>
</Unit33>
<Unit34>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\base.inc"/> <Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\base.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="84"/> <TopLine Value="84"/>
<CursorPos X="6" Y="99"/> <CursorPos X="6" Y="99"/>
<UsageCount Value="12"/>
</Unit31>
<UsageCount Value="11"/>
</Unit34>
<Unit35>
<Filename Value="..\utils\uvkuBase.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="60"/>
<CursorPos X="41" Y="65"/>
<UsageCount Value="29"/>
</Unit35>
<Unit36>
<Filename Value="..\utils\uvkuDeviceMemory.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="6"/>
<TopLine Value="33"/>
<CursorPos X="79" Y="44"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
</Unit36>
<Unit37>
<Filename Value="..\utils\uvkuBuffer.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="10"/>
<CursorPos X="3" Y="13"/>
<UsageCount Value="26"/>
</Unit37>
<Unit38>
<Filename Value="..\utils\uvkuImageFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="36"/>
<CursorPos X="3" Y="22"/>
<UsageCount Value="26"/>
</Unit38>
<Unit39>
<Filename Value="..\utils\uvkuTypes.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="13"/>
<CursorPos X="57" Y="39"/>
<UsageCount Value="26"/>
</Unit39>
<Unit40>
<Filename Value="..\utils\uvkuBufferFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="27"/>
<CursorPos X="49" Y="48"/>
<UsageCount Value="25"/>
</Unit40>
<Unit41>
<Filename Value="..\utils\uvkuBufferView.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="52"/>
<CursorPos X="56" Y="76"/>
<UsageCount Value="25"/>
</Unit41>
<Unit42>
<Filename Value="..\utils\uvkuBufferViewFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="59"/>
<CursorPos X="120" Y="68"/>
<UsageCount Value="24"/>
</Unit42>
<Unit43>
<Filename Value="..\utils\uvkuCommandPool.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="57"/>
<CursorPos X="62" Y="68"/>
<UsageCount Value="24"/>
</Unit43>
<Unit44>
<Filename Value="..\utils\uvkuCommandPoolFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="49"/>
<CursorPos X="95" Y="58"/>
<UsageCount Value="23"/>
</Unit44>
<Unit45>
<Filename Value="..\utils\uvkuCommandBuffer.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="39" Y="13"/>
<UsageCount Value="23"/>
</Unit45>
<Unit46>
<Filename Value="..\utils\uvkuQueue.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="10"/>
<TopLine Value="7"/>
<CursorPos X="22" Y="23"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit46>
<Unit47>
<Filename Value="..\utils\VulkanUtils.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="31"/>
<CursorPos X="3" Y="46"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit47>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Caret Line="134" TopLine="127"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="29" Column="5" TopLine="13"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Caret Line="135" TopLine="127"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="46" Column="3" TopLine="31"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Caret Line="136" TopLine="127"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="26" Column="32" TopLine="13"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Caret Line="151" TopLine="127"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="65" Column="85" TopLine="62"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Caret Line="152" TopLine="128"/>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="4593" Column="72" TopLine="4578"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="93" TopLine="73"/>
<Filename Value="..\Vulkan.pas"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="94" TopLine="73"/>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="3400" Column="20" TopLine="3375"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="95" TopLine="73"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="66" Column="37" TopLine="62"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="96" TopLine="73"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="63" Column="79" TopLine="48"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="97" TopLine="73"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="135" Column="51" TopLine="116"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="98" TopLine="73"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="66" Column="75" TopLine="44"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="99" TopLine="73"/>
<Filename Value="..\utils\uvkuUtils.pas"/>
<Caret Line="32" Column="88" TopLine="7"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Caret Line="100" TopLine="73"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="77" Column="59" TopLine="63"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="74" TopLine="61"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="53" Column="113" TopLine="44"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="79" TopLine="61"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Caret Line="54" TopLine="48"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="..\utils\uvkuSwapChain.pas"/> <Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="76" TopLine="61"/>
<Caret Line="9" Column="30"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="77" TopLine="61"/>
<Filename Value="..\utils\uvkuImageView.pas"/>
<Caret Line="78" Column="73" TopLine="54"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="78" TopLine="61"/>
<Filename Value="..\utils\uvkuDeviceMemory.pas"/>
<Caret TopLine="10"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="51" TopLine="36"/>
<Filename Value="..\utils\uvkuDeviceMemory.pas"/>
<Caret Line="48" Column="78" TopLine="35"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="52" TopLine="36"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Caret Line="56" Column="52" TopLine="48"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="..\utils\uvkuSwapChain.pas"/> <Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="53" TopLine="36"/>
<Caret Line="79" Column="52" TopLine="86"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="55" TopLine="36"/>
<Filename Value="..\utils\uvkuImageView.pas"/>
<Caret Line="47" Column="52" TopLine="32"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="57" TopLine="36"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="266" Column="24" TopLine="245"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="78" TopLine="63"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="66" Column="38" TopLine="75"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="uMainForm.pas"/>
<Caret Line="203" TopLine="190"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="53" Column="62" TopLine="38"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="uMainForm.pas"/>
<Caret Line="36" Column="5" TopLine="20"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="66" Column="11" TopLine="72"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="15" Column="28" TopLine="11"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Caret Line="56" Column="54" TopLine="41"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="1635" Column="61" TopLine="1626"/>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="79" Column="45" TopLine="76"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="3089" Column="61" TopLine="3081"/>
<Filename Value="..\utils\uvkuImageView.pas"/>
<Caret Line="47" Column="38" TopLine="29"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="..\utils\uvkuSwapChain.pas"/>
<Caret Line="29" Column="20" TopLine="20"/>
<Filename Value="..\utils\uvkuDeviceMemory.pas"/>
<Caret Line="48" Column="38" TopLine="49"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectSession> </ProjectSession>
<Debugging> <Debugging>
<BreakPoints Count="1">
<Item1>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="uMainForm.pas"/>
<Line Value="203"/>
</Item1>
</BreakPoints>
<Watches Count="1"> <Watches Count="1">
<Item1> <Item1>
<Expression Value="self"/> <Expression Value="self"/>


+ 9
- 14
projects/triangle/uMainForm.pas Ver fichero

@@ -6,12 +6,7 @@ interface


uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Vulkan, uvkuAllocationHandler,
uvkuInstance, uvkuInstanceFactory,
uvkuPhysicalDevice, uvkuPhysicalDeviceFactory,
uvkuSurface, uvkuSurfaceFactory,
uvkuDevice, uvkuDeviceFactory,
uvkuSwapChain, uvkuSwapChainFactory;
Vulkan, VulkanUtils;


type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -32,6 +27,7 @@ type
fInstance: TvkuInstance; fInstance: TvkuInstance;
fPhyDevice: TvkuPhysicalDevice; fPhyDevice: TvkuPhysicalDevice;
fDevice: TvkuDevice; fDevice: TvkuDevice;
fQueue: TvkuQueue;
fSurface: TvkuSurface; fSurface: TvkuSurface;
fSwapChain: TvkuSwapChain; fSwapChain: TvkuSwapChain;
public public
@@ -78,7 +74,6 @@ procedure TMainForm.FormCreate(Sender: TObject);
var var
PhyDevices: TvkuPhysicalDeviceArr; PhyDevices: TvkuPhysicalDeviceArr;
iFactory: TvkuInstanceFactory; iFactory: TvkuInstanceFactory;
pdFactory: TvkuPhysicalDeviceFactory;
dFactory: TvkuDeviceFactory; dFactory: TvkuDeviceFactory;
sFactory: TvkuSurfaceFactory; sFactory: TvkuSurfaceFactory;
scFactory: TvkuSwapChainFactory; scFactory: TvkuSwapChainFactory;
@@ -107,13 +102,7 @@ begin
PhyDevices := fInstance.GetPhysicalDevices; PhyDevices := fInstance.GetPhysicalDevices;
if (Length(PhyDevices) <= 0) then if (Length(PhyDevices) <= 0) then
raise Exception.Create('unable to get physical device'); raise Exception.Create('unable to get physical device');
pdFactory := TvkuPhysicalDeviceFactory.Create(fInstance);
try
fPhyDevice := pdFactory.CreatePhysicalDevice(PhyDevices[0]);
finally
FreeAndNil(pdFactory);
end;

fPhyDevice := TvkuPhysicalDevice.Create(PhyDevices[0], fInstance.InstanceCommands);


WriteLn('create vulkan surface'); WriteLn('create vulkan surface');
sFactory := TvkuSurfaceFactory.Create(fInstance); sFactory := TvkuSurfaceFactory.Create(fInstance);
@@ -141,6 +130,11 @@ begin
FreeAndNil(dFactory); FreeAndNil(dFactory);
end; end;



WriteLn('get queue from device');
fQueue := TvkuQueue.Create(fDevice.GetQueue(0, 0), fDevice.DeviceCommands);


WriteLn('create swap chain'); WriteLn('create swap chain');
scFactory := TvkuSwapChainFactory.Create(fDevice); scFactory := TvkuSwapChainFactory.Create(fDevice);
try try
@@ -210,6 +204,7 @@ end;
procedure TMainForm.FormDestroy(Sender: TObject); procedure TMainForm.FormDestroy(Sender: TObject);
begin begin
FreeAndNil(fSwapChain); FreeAndNil(fSwapChain);
FreeAndNil(fQueue);
FreeAndNil(fDevice); FreeAndNil(fDevice);
FreeAndNil(fSurface); FreeAndNil(fSurface);
FreeAndNil(fPhyDevice); FreeAndNil(fPhyDevice);


+ 87
- 0
projects/utils/VulkanUtils.pas Ver fichero

@@ -0,0 +1,87 @@
unit VulkanUtils;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
uvkuTypes, uvkuAllocationHandler,
uvkuInstance, uvkuInstanceFactory,
uvkuPhysicalDevice, uvkuDevice, uvkuDeviceFactory, uvkuDeviceMemory, uvkuQueue,
uvkuSurface, uvkuSurfaceFactory,
uvkuSwapChain, uvkuSwapChainFactory,
uvkuImage, uvkuImageFactory, uvkuImageView, uvkuImageViewFactory,
uvkuBuffer, uvkuBufferFactory, uvkuBufferView, uvkuBufferViewFactory,
uvkuCommandPool, uvkuCommandPoolFactory, uvkuCommandBuffer;

type
{ Types }
TvkuFloatArr = uvkuTypes.TvkuFloatArr;
TvkuUint32Arr = uvkuTypes.TvkuUint32Arr;
TvkuImageArr = uvkuTypes.TvkuImageArr;
TvkuPhysicalDeviceArr = uvkuTypes.TvkuPhysicalDeviceArr;
TvkuQueueFamilyPropertiesArr = uvkuTypes.TvkuQueueFamilyPropertiesArr;
TvkuSparseImageFormatPropertiesArr = uvkuTypes.TvkuSparseImageFormatPropertiesArr;
TvkuSurfaceFormatArr = uvkuTypes.TvkuSurfaceFormatArr;
TvkuPresentModeArr = uvkuTypes.TvkuPresentModeArr;
TvkuDisplayPropertiesArr = uvkuTypes.TvkuDisplayPropertiesArr;
TvkuDisplayPlanePropertiesArr = uvkuTypes.TvkuDisplayPlanePropertiesArr;
TvkuDisplayArr = uvkuTypes.TvkuDisplayArr;
TvkuDisplayModePropertiesArr = uvkuTypes.TvkuDisplayModePropertiesArr;
TvkuCommandBufferArr = uvkuTypes.TvkuCommandBufferArr;
TvkuApplicationInfo = uvkuTypes.TvkuApplicationInfo;
TvkuQueueCreateInfo = uvkuTypes.TvkuQueueCreateInfo;
TvkuQueueCreateInfoArr = uvkuTypes.TvkuQueueCreateInfoArr;

TvkuAllocationHandler = uvkuAllocationHandler.TvkuAllocationHandler;

{ Instance }
TvkuInstance = uvkuInstance.TvkuInstance;
TvkuInstanceEx = uvkuInstanceFactory.TvkuInstanceEx;
TvkuInstanceFactory = uvkuInstanceFactory.TvkuInstanceFactory;

{ Device }
TvkuPhysicalDevice = uvkuPhysicalDevice.TvkuPhysicalDevice;
TvkuDevice = uvkuDevice.TvkuDevice;
TvkuDeviceEx = uvkuDeviceFactory.TvkuDeviceEx;
TvkuDeviceFactory = uvkuDeviceFactory.TvkuDeviceFactory;
TvkuDeviceMemory = uvkuDeviceMemory.TvkuDeviceMemory;
TvkuQueue = uvkuQueue.TvkuQueue;

{ Surface }
TvkuSurface = uvkuSurface.TvkuSurface;
TvkuSurfaceEx = uvkuSurfaceFactory.TvkuSurfaceEx;
TvkuSurfaceFactory = uvkuSurfaceFactory.TvkuSurfaceFactory;

{ SwapChain }
TvkuSwapChain = uvkuSwapChain.TvkuSwapChain;
TvkuSwapChainEx = uvkuSwapChainFactory.TvkuSwapChainEx;
TvkuSwapChainFactory = uvkuSwapChainFactory.TvkuSwapChainFactory;

{ Image }
TvkuImage = uvkuImage.TvkuImage;
TvkuImageEx = uvkuImageFactory.TvkuImageEx;
TvkuImageFactory = uvkuImageFactory.TvkuImageFactory;
TvkuImageView = uvkuImageView.TvkuImageView;
TvkuImageViewEx = uvkuImageViewFactory.TvkuImageViewEx;
TvkuImageViewFactory = uvkuImageViewFactory.TvkuImageViewFactory;

{ Buffer }
TvkuBuffer = uvkuBuffer.TvkuBuffer;
TvkuBufferEx = uvkuBufferFactory.TvkuBufferEx;
TvkuBufferFactory = uvkuBufferFactory.TvkuBufferFactory;
TvkuBufferView = uvkuBufferView.TvkuBufferView;
TvkuBufferViewEx = uvkuBufferViewFactory.TvkuBufferViewEx;
TvkuBufferViewFactory = uvkuBufferViewFactory.TvkuBufferViewFactory;

{ Commands }
TvkuCommandPool = uvkuCommandPool.TvkuCommandPool;
TvkuCommandPoolEx = uvkuCommandPoolFactory.TvkuCommandPoolEx;
TvkuCommandPoolFactory = uvkuCommandPoolFactory.TvkuCommandPoolFactory;
TvkuCommandBuffer = uvkuCommandBuffer.TvkuCommandBuffer;

implementation

end.


+ 40
- 7
projects/utils/uvkuAllocationHandler.pas Ver fichero

@@ -11,6 +11,8 @@ uses
type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuAllocationHandler = class(TObject) TvkuAllocationHandler = class(TObject)
private
fAllocCallbacks: PVkAllocationCallbacks;
protected protected
function AllocateMemory(const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid; virtual; function AllocateMemory(const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid; virtual;
function ReallocateMemory(const aOriginal: PVkVoid; const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid; virtual; function ReallocateMemory(const aOriginal: PVkVoid; const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid; virtual;
@@ -20,6 +22,10 @@ type
procedure InternalFreeNotification(const aSize: VkSize; const aType: TVkInternalAllocationType; const aScope: TVkSystemAllocationScope); procedure InternalFreeNotification(const aSize: VkSize; const aType: TVkInternalAllocationType; const aScope: TVkSystemAllocationScope);
public public
function GetAllocationCallbacks: TVkAllocationCallbacks; function GetAllocationCallbacks: TVkAllocationCallbacks;
function GetAllocationCallbacksPtr: PVkAllocationCallbacks;

constructor Create;
destructor Destroy; override;
end; end;


implementation implementation
@@ -90,13 +96,40 @@ end;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuAllocationHandler.GetAllocationCallbacks: TVkAllocationCallbacks; function TvkuAllocationHandler.GetAllocationCallbacks: TVkAllocationCallbacks;
begin begin
FillByte(result{%H-}, SizeOf(result), 0);
result.pUserData := self;
result.pfnAllocation := @AllocateMemoryCallback;
result.pfnReallocation := @ReallocateMemoryCallback;
result.pfnFree := @FreeMemoryCallback;
result.pfnInternalAllocation := @InternalAllocationCallback;
result.pfnInternalFree := @InternalFreeCallback;
result := GetAllocationCallbacksPtr^;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuAllocationHandler.GetAllocationCallbacksPtr: PVkAllocationCallbacks;
begin
if not Assigned(fAllocCallbacks) then begin
new(fAllocCallbacks);
FillByte(fAllocCallbacks^, SizeOf(result), 0);
fAllocCallbacks^.pUserData := self;
fAllocCallbacks^.pfnAllocation := @AllocateMemoryCallback;
fAllocCallbacks^.pfnReallocation := @ReallocateMemoryCallback;
fAllocCallbacks^.pfnFree := @FreeMemoryCallback;
fAllocCallbacks^.pfnInternalAllocation := @InternalAllocationCallback;
fAllocCallbacks^.pfnInternalFree := @InternalFreeCallback;
end;
result := fAllocCallbacks;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuAllocationHandler.Create;
begin
inherited Create;
fAllocCallbacks := nil;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuAllocationHandler.Destroy;
begin
if Assigned(fAllocCallbacks) then begin
Dispose(fAllocCallbacks);
fAllocCallbacks := nil;
end;
inherited Destroy;
end; end;


end. end.


+ 92
- 0
projects/utils/uvkuBase.pas Ver fichero

@@ -0,0 +1,92 @@
unit uvkuBase;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuObject = class(TObject)
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuHandle = class(TvkuObject)
private
fOwnsHandle: Boolean;
public
property OwnsHandle: Boolean read fOwnsHandle write fOwnsHandle;
constructor Create;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuAllocHandle = class(TvkuHandle)
private
fAllocCallbacks: PVkAllocationCallbacks;
protected
property AllocCallbacks: PVkAllocationCallbacks read fAllocCallbacks;

procedure SetAllocCallbacks(const aAllocCallbacks: TVkAllocationCallbacks);
procedure SetAllocCallbacks(const aAllocCallbacks: PVkAllocationCallbacks);
procedure DisposeAllocCallbacks;
public
constructor Create;
destructor Destroy; override;
end;

implementation

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuHandle/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuHandle.Create;
begin
inherited Create;
fOwnsHandle := true;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuAllocHandle////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuAllocHandle.SetAllocCallbacks(const aAllocCallbacks: TVkAllocationCallbacks);
begin
if not Assigned(fAllocCallbacks) then
new(fAllocCallbacks);
fAllocCallbacks^ := aAllocCallbacks;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuAllocHandle.SetAllocCallbacks(const aAllocCallbacks: PVkAllocationCallbacks);
begin
if Assigned(aAllocCallbacks) then
SetAllocCallbacks(aAllocCallbacks^);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuAllocHandle.DisposeAllocCallbacks;
begin
if not Assigned(fAllocCallbacks) then
exit;
Dispose(fAllocCallbacks);
fAllocCallbacks := nil;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuAllocHandle.Create;
begin
inherited Create;
fAllocCallbacks := nil;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuAllocHandle.Destroy;
begin
inherited Destroy;
DisposeAllocCallbacks;
end;

end.


+ 82
- 0
projects/utils/uvkuBuffer.pas Ver fichero

@@ -0,0 +1,82 @@
unit uvkuBuffer;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuBuffer = class(TvkuAllocHandle)
private
fHandle: VkBuffer;
fDeviceCommands: TVkDeviceCommands;

procedure CreateHandle(const aCreateInfo: TVkBufferCreateInfo);
public
property Handle: VkBuffer read fHandle;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

constructor Create(
const aCreateInfo: TVkBufferCreateInfo;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
constructor Create(
const aHandle: VkBuffer;
const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override;
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuBuffer/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuBuffer.CreateHandle(const aCreateInfo: TVkBufferCreateInfo);
var err: TVkResult;
begin
err := fDeviceCommands.vkCreateBuffer(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create buffer', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBuffer.Create(const aCreateInfo: TVkBufferCreateInfo; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(aCreateInfo);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBuffer.Create(const aHandle: VkBuffer; const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fHandle := aHandle;
fDeviceCommands := aDeviceCommands;
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuBuffer.Destroy;
begin
if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
fDeviceCommands.vkDestroyBuffer(fDeviceCommands.Device, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy;
end;

end.


+ 140
- 0
projects/utils/uvkuBufferFactory.pas Ver fichero

@@ -0,0 +1,140 @@
unit uvkuBufferFactory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBuffer, uvkuDevice, uvkuAllocationHandler, uvkuTypes;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuBufferEx = class(TvkuBuffer)
private
fAllocHandler: TvkuAllocationHandler;
fOwnsHandle: Boolean;
public
destructor Destroy; override;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuBufferFactory = class(TObject)
private
fDeviceCommands: TVkDeviceCommands;
fFlags: VkBufferCreateFlags;
fSize: VkDeviceSize;
fUsage: VkBufferUsageFlags;
fSharingMode: TVkSharingMode;
fQueueFamilyIndices: TvkuUint32Arr;

function GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
function GetQueueFamilyIndexCount: Integer;
procedure SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
public
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
property Flags: VkBufferCreateFlags read fFlags write fFlags;
property Size: VkDeviceSize read fSize write fSize;
property Usage: VkBufferUsageFlags read fUsage write fUsage;
property SharingMode: TVkSharingMode read fSharingMode write fSharingMode;

property QueueFamilyIndices: TvkuUint32Arr read fQueueFamilyIndices;
property QueueFamilyIndexCount: Integer read GetQueueFamilyIndexCount;
property QueueFamilyIndex[const aIndex: Integer]: VkUint32 read GetQueueFamilyIndex write SetQueueFamilyIndex;

function CreateBuffer: TvkuBufferEx;
function CreateBuffer(
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuBufferEx;

constructor Create(const aDevice: TvkuDevice);
constructor Create(const aDeviceCommands: TVkDeviceCommands);
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuBufferEx///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuBufferEx.Destroy;
begin
if fOwnsHandle then
FreeAndNil(fAllocHandler);
inherited Destroy;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuBufferFactory//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuBufferFactory.GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
begin
if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
result := fQueueFamilyIndices[aIndex];
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuBufferFactory.GetQueueFamilyIndexCount: Integer;
begin
result := Length(fQueueFamilyIndices);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuBufferFactory.SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
begin
if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
fQueueFamilyIndices[aIndex] := aValue;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuBufferFactory.CreateBuffer: TvkuBufferEx;
begin
result := CreateBuffer(nil, false);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuBufferFactory.CreateBuffer(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuBufferEx;
var
CreateInfo: TVkBufferCreateInfo;
begin
FillByte(CreateInfo, 0, SizeOf(CreateInfo));
CreateInfo.sType := VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
CreateInfo.size := fSize;
CreateInfo.usage := fUsage;
CreateInfo.sharingMode := fSharingMode;
CreateInfo.queueFamilyIndexCount := Length(fQueueFamilyIndices);
CreateInfo.pQueueFamilyIndices := @fQueueFamilyIndices[0];

if Assigned(aAllocHandler)
then result := TvkuBufferEx.Create(CreateInfo, fDeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuBufferEx.Create(CreateInfo, fDeviceCommands);
try
TvkuBufferEx(result).fAllocHandler := aAllocHandler;
TvkuBufferEx(result).fOwnsHandle := aOwnsHandler;
except
FreeAndNil(result);
raise;
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBufferFactory.Create(const aDevice: TvkuDevice);
begin
Create(aDevice.DeviceCommands);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBufferFactory.Create(const aDeviceCommands: TVkDeviceCommands);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
end;

end.


+ 82
- 0
projects/utils/uvkuBufferView.pas Ver fichero

@@ -0,0 +1,82 @@
unit uvkuBufferView;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuBufferView = class(TvkuAllocHandle)
private
fHandle: VkBufferView;
fDeviceCommands: TVkDeviceCommands;

procedure CreateHandle(const aCreateInfo: TVkBufferViewCreateInfo);
public
property Handle: VkBufferView read fHandle;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

constructor Create(
const aCreateInfo: TVkBufferViewCreateInfo;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
constructor Create(
const aHandle: VkBufferView;
const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override;
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuBufferView/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuBufferView.CreateHandle(const aCreateInfo: TVkBufferViewCreateInfo);
var err: TVkResult;
begin
err := fDeviceCommands.vkCreateBufferView(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create buffer view', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBufferView.Create(const aCreateInfo: TVkBufferViewCreateInfo; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(aCreateInfo);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBufferView.Create(const aHandle: VkBufferView; const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fHandle := aHandle;
fDeviceCommands := aDeviceCommands;
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuBufferView.Destroy;
begin
if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
fDeviceCommands.vkDestroyBufferView(fDeviceCommands.Device, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy;
end;

end.


+ 107
- 0
projects/utils/uvkuBufferViewFactory.pas Ver fichero

@@ -0,0 +1,107 @@
unit uvkuBufferViewFactory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBufferView, uvkuAllocationHandler, uvkuDevice;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuBufferViewEx = class(TvkuBufferView)
private
fAllocHandler: TvkuAllocationHandler;
fOwnsHandler: Boolean;
public
destructor Destroy; override;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuBufferViewFactory = class(TObject)
private
fDeviceCommands: TVkDeviceCommands;

fFlags: VkBufferViewCreateFlags;
fBuffer: VkBuffer;
fFormat: TVkFormat;
fOffset: VkDeviceSize;
fRange: VkDeviceSize;
public
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

property Flags: VkBufferViewCreateFlags read fFlags write fFlags;
property Buffer: VkBuffer read fBuffer write fBuffer;
property Format: TVkFormat read fFormat write fFormat;
property Offset: VkDeviceSize read fOffset write fOffset;
property Range: VkDeviceSize read fRange write fRange;

function CreateBufferView: TvkuBufferViewEx;
function CreateBufferView(
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuBufferViewEx;

constructor Create(const aDevice: TvkuDevice);
constructor Create(const aDeviceCommands: TVkDeviceCommands);
end;

implementation

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuBufferViewEx///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuBufferViewEx.Destroy;
begin
inherited Destroy;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuBufferViewFactory//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuBufferViewFactory.CreateBufferView: TvkuBufferViewEx;
begin
result := CreateBufferView(nil, false);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuBufferViewFactory.CreateBufferView(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuBufferViewEx;
var
CreateInfo: TVkBufferViewCreateInfo;
begin
FillByte(CreateInfo, SizeOf(CreateInfo), 0);
CreateInfo.sType := VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
CreateInfo.buffer := fBuffer;
CreateInfo.format := fFormat;
CreateInfo.offset := fOffset;
CreateInfo.range := fRange;

if Assigned(aAllocHandler)
then result := TvkuBufferViewEx.Create(CreateInfo, fDeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuBufferViewEx.Create(CreateInfo, fDeviceCommands);
try
TvkuBufferViewEx(result).fAllocHandler := aAllocHandler;
TvkuBufferViewEx(result).fOwnsHandler := aOwnsHandler;
except
FreeAndNil(result);
raise;
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBufferViewFactory.Create(const aDevice: TvkuDevice);
begin
Create(aDevice.DeviceCommands);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuBufferViewFactory.Create(const aDeviceCommands: TVkDeviceCommands);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
end;

end.


+ 56
- 0
projects/utils/uvkuCommandBuffer.pas Ver fichero

@@ -0,0 +1,56 @@
unit uvkuCommandBuffer;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuCommandBuffer = class(TvkuHandle)
private
fHandle: VkCommandBuffer;
fCommandPool: VkCommandPool;
fDeviceCommands: TVkDeviceCommands;
public
property Handle: VkCommandBuffer read fHandle;
property CommandPool: VkCommandPool read fCommandPool;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

constructor Create(
const aHandle: VkCommandBuffer;
const aOwnsHandle: Boolean;
const aCommandPool: VkCommandPool;
const aDeviceCommands: TVkDeviceCommands);
destructor Destroy; override;
end;

implementation

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuCommandBuffer//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuCommandBuffer.Create(const aHandle: VkCommandBuffer; const aOwnsHandle: Boolean;
const aCommandPool: VkCommandPool; const aDeviceCommands: TVkDeviceCommands);
begin
inherited Create;
fHandle := aHandle;
fCommandPool := aCommandPool;
fDeviceCommands := aDeviceCommands;
OwnsHandle := aOwnsHandle;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuCommandBuffer.Destroy;
begin
if OwnsHandle and (fHandle <> VK_INVALID_HANDLE) then
fDeviceCommands.vkFreeCommandBuffers(fDeviceCommands.Device, fCommandPool, 1, @fHandle);
fHandle := VK_INVALID_HANDLE;
inherited Destroy;
end;

end.


+ 128
- 0
projects/utils/uvkuCommandPool.pas Ver fichero

@@ -0,0 +1,128 @@
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 CreateCommandBuffer(
const aLevel: TVkCommandBufferLevel): VkCommandBuffer;
function CreateCommandBuffers(
const aLevel: TVkCommandBufferLevel;
const aCount: Integer): TvkuCommandBufferArr;
procedure FreeCommandBuffer(
const aBuffer: VkCommandBuffer);
procedure FreeCommandBuffers(
const aBuffers: TvkuCommandBufferArr);

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.CreateCommandBuffer(const aLevel: TVkCommandBufferLevel): VkCommandBuffer;
begin
result := CreateCommandBuffers(aLevel, 1)[0];
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuCommandPool.CreateCommandBuffers(const aLevel: TVkCommandBufferLevel; const aCount: Integer): TvkuCommandBufferArr;
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(TvkuCommandBufferArr.Create(aBuffer));
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuCommandPool.FreeCommandBuffers(const aBuffers: TvkuCommandBufferArr);
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.


+ 92
- 0
projects/utils/uvkuCommandPoolFactory.pas Ver fichero

@@ -0,0 +1,92 @@
unit uvkuCommandPoolFactory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuCommandPool, uvkuDevice, uvkuAllocationHandler;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuCommandPoolEx = class(TvkuCommandPool)
private
fAllocHandler: TvkuAllocationHandler;
fOwnsHandler: Boolean;
public
destructor Destroy; override;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuCommandPoolFactory = class(TObject)
private
fDeviceCommands: TVkDeviceCommands;
fFlags: VkCommandPoolCreateFlags;
fQueueFamilyIndex: VkUint32;
public
function CreateCommandPool: TvkuCommandPoolEx;
function CreateCommandPool(
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuCommandPoolEx;

constructor Create(const aDevice: TvkuDevice);
constructor Create(const aDeviceCommands: TVkDeviceCommands);
end;

implementation

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuCommandPoolEx//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuCommandPoolEx.Destroy;
begin
if fOwnsHandler then
FreeAndNil(fAllocHandler);
inherited Destroy;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuCommandPoolFactory/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuCommandPoolFactory.CreateCommandPool: TvkuCommandPoolEx;
begin
result := CreateCommandPool(nil, false);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuCommandPoolFactory.CreateCommandPool(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuCommandPoolEx;
var CreateInfo: TVkCommandPoolCreateInfo;
begin
FillByte(CreateInfo, SizeOf(CreateInfo), 0);
CreateInfo.sType := VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
CreateInfo.queueFamilyIndex := fQueueFamilyIndex;
if Assigned(aAllocHandler)
then result := TvkuCommandPoolEx.Create(CreateInfo, fDeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuCommandPoolEx.Create(CreateInfo, fDeviceCommands);
try
TvkuCommandPoolEx(result).fAllocHandler := aAllocHandler;
TvkuCommandPoolEx(result).fOwnsHandler := aOwnsHandler;
except
FreeAndNil(result);
raise;
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuCommandPoolFactory.Create(const aDevice: TvkuDevice);
begin
Create(aDevice.DeviceCommands);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuCommandPoolFactory.Create(const aDeviceCommands: TVkDeviceCommands);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
end;

end.


+ 35
- 34
projects/utils/uvkuDevice.pas Ver fichero

@@ -6,35 +6,35 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan;
Vulkan, uvkuBase;


type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuDevice = class(TObject)
TvkuDevice = class(TvkuAllocHandle)
private private
fHandle: VkDevice; fHandle: VkDevice;
fPhysicalDevice: VkPhysicalDevice;
fAllocCallbacks: PVkAllocationCallbacks;
fInstanceCommands: TVkInstanceCommands; fInstanceCommands: TVkInstanceCommands;
fDeviceCommands: TVkDeviceCommands; fDeviceCommands: TVkDeviceCommands;


procedure CreateHandle( procedure CreateHandle(
const aCreateInfo: PVkDeviceCreateInfo;
const aAllocCallbacks: PVkAllocationCallbacks);
const aPhyDevice: VkPhysicalDevice;
const aCreateInfo: PVkDeviceCreateInfo);
public public
property Handle: VkDevice read fHandle; property Handle: VkDevice read fHandle;
property PhysicalDevice: VkPhysicalDevice read fPhysicalDevice;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands; property DeviceCommands: TVkDeviceCommands read fDeviceCommands;


function GetQueue(const aQueueFamilyIndex, aQueueIndex: VkUint32): VkQueue;

constructor Create( constructor Create(
const aPhysicalDevice: VkPhysicalDevice; const aPhysicalDevice: VkPhysicalDevice;
const aCreateInfo: TVkDeviceCreateInfo; const aCreateInfo: TVkDeviceCreateInfo;
const aInstanceCommands: TVkInstanceCommands);
const aInstanceCommands: TVkInstanceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
constructor Create( constructor Create(
const aPhysicalDevice: VkPhysicalDevice;
const aCreateInfo: TVkDeviceCreateInfo;
const aHandle: VkDevice;
const aOwnsHandle: Boolean;
const aInstanceCommands: TVkInstanceCommands; const aInstanceCommands: TVkInstanceCommands;
const aAllocCallbacks: TVkAllocationCallbacks);
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override; destructor Destroy; override;
end; end;


@@ -46,16 +46,12 @@ uses
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuDevice///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuDevice/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuDevice.CreateHandle(const aCreateInfo: PVkDeviceCreateInfo; const aAllocCallbacks: PVkAllocationCallbacks);
procedure TvkuDevice.CreateHandle(const aPhyDevice: VkPhysicalDevice; const aCreateInfo: PVkDeviceCreateInfo);
var err: TVkResult; var err: TVkResult;
begin begin
if not Assigned(fInstanceCommands.vkCreateDevice) then if not Assigned(fInstanceCommands.vkCreateDevice) then
raise TvkuException.Create('invalid function pointer: vkCreateDevice; did you load the vulkan core commands?');
if Assigned(aAllocCallbacks) then begin
new(fAllocCallbacks);
fAllocCallbacks^ := aAllocCallbacks^;
end;
err := fInstanceCommands.vkCreateDevice(fPhysicalDevice, aCreateInfo, fAllocCallbacks, @fHandle);
raise TvkuInvalidFuncPtrException.Create('vkCreateDevice');
err := fInstanceCommands.vkCreateDevice(aPhyDevice, aCreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create device', err); raise TvkuErrorException.Create('unable to create device', err);
fDeviceCommands := LoadDeviceCommands(fInstanceCommands.Instance, fHandle); fDeviceCommands := LoadDeviceCommands(fInstanceCommands.Instance, fHandle);
@@ -63,39 +59,44 @@ begin
raise TvkuException.Create('unable to load device commands'); raise TvkuException.Create('unable to load device commands');
end; end;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuDevice.GetQueue(const aQueueFamilyIndex, aQueueIndex: VkUint32): VkQueue;
begin
if not Assigned(fDeviceCommands.vkGetDeviceQueue) then
raise TvkuInvalidFuncPtrException.Create('vkGetDeviceQueue');
fDeviceCommands.vkGetDeviceQueue(fHandle, aQueueFamilyIndex, aQueueIndex, @result);
if (result = VK_INVALID_HANDLE) then
raise TvkuException.Create('unable to get device queue');
end;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDevice.Create(const aPhysicalDevice: VkPhysicalDevice; const aCreateInfo: TVkDeviceCreateInfo; constructor TvkuDevice.Create(const aPhysicalDevice: VkPhysicalDevice; const aCreateInfo: TVkDeviceCreateInfo;
const aInstanceCommands: TVkInstanceCommands);
const aInstanceCommands: TVkInstanceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
inherited Create; inherited Create;
fHandle := nil; fHandle := nil;
fPhysicalDevice := aPhysicalDevice;
fInstanceCommands := aInstanceCommands; fInstanceCommands := aInstanceCommands;
CreateHandle(@aCreateInfo, nil);
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(aPhysicalDevice, @aCreateInfo);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDevice.Create(const aPhysicalDevice: VkPhysicalDevice; const aCreateInfo: TVkDeviceCreateInfo;
const aInstanceCommands: TVkInstanceCommands; const aAllocCallbacks: TVkAllocationCallbacks);
constructor TvkuDevice.Create(const aHandle: VkDevice; const aOwnsHandle: Boolean;
const aInstanceCommands: TVkInstanceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
inherited Create; inherited Create;
fHandle := nil;
fPhysicalDevice := aPhysicalDevice;
fHandle := aHandle;
fInstanceCommands := aInstanceCommands; fInstanceCommands := aInstanceCommands;
CreateHandle(@aCreateInfo, @aAllocCallbacks);
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuDevice.Destroy; destructor TvkuDevice.Destroy;
begin begin
if (fHandle <> VK_INVALID_HANDLE) then begin
fDeviceCommands.vkDestroyDevice(fHandle, fAllocCallbacks);
fHandle := VK_INVALID_HANDLE;
end;
if Assigned(fAllocCallbacks) then begin
Dispose(fAllocCallbacks);
fAllocCallbacks := nil;
end;
if OwnsHandle and (fHandle <> VK_INVALID_HANDLE) then
fDeviceCommands.vkDestroyDevice(fHandle, AllocCallbacks);
fHandle := VK_INVALID_HANDLE;
FreeAndNil(fDeviceCommands); FreeAndNil(fDeviceCommands);
inherited Destroy; inherited Destroy;
end; end;


+ 6
- 15
projects/utils/uvkuDeviceFactory.pas Ver fichero

@@ -6,18 +6,9 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan, uvkuInstance, uvkuDevice, uvkuAllocationHandler;
Vulkan, uvkuInstance, uvkuDevice, uvkuAllocationHandler, uvkuTypes;


type type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuQueuePriorityArr = array of VkFloat;
TvkuQueueCreateInfo = packed record
Flags: VkDeviceQueueCreateFlags;
FamilyIndex: VkUint32;
Priorities: TvkuQueuePriorityArr;
end;
TvkuQueueCreateInfoArr = array of TvkuQueueCreateInfo;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuDeviceEx = class(TvkuDevice) TvkuDeviceEx = class(TvkuDevice)
private private
@@ -58,11 +49,11 @@ type
property QueueCreateInfo[const aIndex: Integer]: TvkuQueueCreateInfo read GetQueueCreateInfo write SetQueueCreateInfo; property QueueCreateInfo[const aIndex: Integer]: TvkuQueueCreateInfo read GetQueueCreateInfo write SetQueueCreateInfo;


function CreateDevice( function CreateDevice(
const aPhysicalDevice: VkPhysicalDevice): TvkuDevice;
const aPhysicalDevice: VkPhysicalDevice): TvkuDeviceEx;
function CreateDevice( function CreateDevice(
const aPhysicalDevice: VkPhysicalDevice; const aPhysicalDevice: VkPhysicalDevice;
const aAllocHandler: TvkuAllocationHandler; const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuDevice;
const aOwnsHandler: Boolean): TvkuDeviceEx;


constructor Create(const aInstance: TvkuInstance); constructor Create(const aInstance: TvkuInstance);
constructor Create(const aInstanceCommands: TVkInstanceCommands); constructor Create(const aInstanceCommands: TVkInstanceCommands);
@@ -141,14 +132,14 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuDeviceFactory.CreateDevice(const aPhysicalDevice: VkPhysicalDevice): TvkuDevice;
function TvkuDeviceFactory.CreateDevice(const aPhysicalDevice: VkPhysicalDevice): TvkuDeviceEx;
begin begin
result := CreateDevice(aPhysicalDevice, nil, false); result := CreateDevice(aPhysicalDevice, nil, false);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuDeviceFactory.CreateDevice(const aPhysicalDevice: VkPhysicalDevice; function TvkuDeviceFactory.CreateDevice(const aPhysicalDevice: VkPhysicalDevice;
const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuDevice;
const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuDeviceEx;
var var
CreateInfo: TVkDeviceCreateInfo; CreateInfo: TVkDeviceCreateInfo;
QueueInfos: array of TVkDeviceQueueCreateInfo; QueueInfos: array of TVkDeviceQueueCreateInfo;
@@ -193,7 +184,7 @@ begin
CreateInfo.pEnabledFeatures := @fFeatures; CreateInfo.pEnabledFeatures := @fFeatures;


if Assigned(aAllocHandler) if Assigned(aAllocHandler)
then result := TvkuDeviceEx.Create(aPhysicalDevice, CreateInfo, fInstanceCommands, aAllocHandler.GetAllocationCallbacks)
then result := TvkuDeviceEx.Create(aPhysicalDevice, CreateInfo, fInstanceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuDeviceEx.Create(aPhysicalDevice, CreateInfo, fInstanceCommands); else result := TvkuDeviceEx.Create(aPhysicalDevice, CreateInfo, fInstanceCommands);
try try
TvkuDeviceEx(result).fAllocHandler := aAllocHandler; TvkuDeviceEx(result).fAllocHandler := aAllocHandler;


+ 100
- 0
projects/utils/uvkuDeviceMemory.pas Ver fichero

@@ -0,0 +1,100 @@
unit uvkuDeviceMemory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuDeviceMemory = class(TvkuAllocHandle)
private
fHandle: VkDeviceMemory;
fDeviceCommands: TVkDeviceCommands;

procedure CreateHandle(const aAllocInfo: TVkMemoryAllocateInfo);
public
property Handle: VkDeviceMemory read fHandle;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

function Map(const aOffset: VkDeviceSize; aSize: VkDeviceSize; aFlags: VkMemoryMapFlags): PVkVoid;
procedure Unmap;

constructor Create(const aAllocInfo: TVkMemoryAllocateInfo; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks);
constructor Create(
const aHandle: VkDeviceMemory;
const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override;
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuDeviceMemory///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuDeviceMemory.CreateHandle(const aAllocInfo: TVkMemoryAllocateInfo);
var err: TVkResult;
begin
if not Assigned(fDeviceCommands.vkAllocateMemory) then
raise TvkuInvalidFuncPtrException.Create('vkAllocateMemory');
err := fDeviceCommands.vkAllocateMemory(fDeviceCommands.Device, @aAllocInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to allocate device memory', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuDeviceMemory.Map(const aOffset: VkDeviceSize; aSize: VkDeviceSize; aFlags: VkMemoryMapFlags): PVkVoid;
var err: TVkResult;
begin
err := fDeviceCommands.vkMapMemory(fDeviceCommands.Device, fHandle, aOffset, aSize, aFlags, @result);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to map device memory', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuDeviceMemory.Unmap;
begin
fDeviceCommands.vkUnmapMemory(fDeviceCommands.Device, fHandle);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDeviceMemory.Create(const aAllocInfo: TVkMemoryAllocateInfo; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(aAllocInfo);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDeviceMemory.Create(const aHandle: VkDeviceMemory; const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fHandle := aHandle;
fDeviceCommands := aDeviceCommands;
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuDeviceMemory.Destroy;
begin
if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
fDeviceCommands.vkFreeMemory(fDeviceCommands.Device, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy;
end;

end.


+ 177
- 0
projects/utils/uvkuImage.pas Ver fichero

@@ -0,0 +1,177 @@
unit uvkuImage;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuImage = class(TvkuAllocHandle)
private
fHandle: VkImage;
fDeviceCommands: TVkDeviceCommands;

procedure CreateHandle(const aCreateInfo: TVkImageCreateInfo);
public
property Handle: VkImage read fHandle;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

function GetMemoryBarrier(
const aAspectMask: VkImageAspectFlags;
const aOldLayout: TVkImageLayout;
const aNewLayout: TVkImageLayout): TVkImageMemoryBarrier;

constructor Create(
const aCreateInfo: TVkImageCreateInfo;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
constructor Create(
const aHandle: VkImage;
const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override;
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuImage//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuImage.CreateHandle(const aCreateInfo: TVkImageCreateInfo);
var err: TVkResult;
begin
err := fDeviceCommands.vkCreateImage(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
TvkuErrorException.Create('unable to create image', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuImage.GetMemoryBarrier(
const aAspectMask: VkImageAspectFlags;
const aOldLayout: TVkImageLayout;
const aNewLayout: TVkImageLayout): TVkImageMemoryBarrier;
var
range: TVkImageSubresourceRange;
begin
FillByte(range, SizeOf(range), 0);
range.aspectMask := aAspectMask;
range.baseMipLevel := 0;
range.levelCount := 1;
range.baseArrayLayer := 0;
range.layerCount := 1;

FillByte(result, SizeOf(result), 0);
result.sType := VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
result.pNext := nil;
result.srcAccessMask := [];
result.dstAccessMask := [];
result.oldLayout := aOldLayout;
result.newLayout := aNewLayout;
result.srcQueueFamilyIndex := 0;
result.dstQueueFamilyIndex := 0;
result.image := fHandle;
result.subresourceRange := range;

case aOldLayout of
// Undefined layout:
// Note: Only allowed as initial layout!
// Note: Make sure any writes to the image have been finished
VK_IMAGE_LAYOUT_UNDEFINED: begin
result.srcAccessMask := [ VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT ];
end;

// Old layout is color attachment:
// Note: Make sure any writes to the color buffer have been finished
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: begin
result.srcAccessMask := [ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ];
end;

// Old layout is transfer source:
// Note: Make sure any reads from the image have been finished
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: begin
result.srcAccessMask := [ VK_ACCESS_TRANSFER_READ_BIT ];
end;

// Old layout is shader read (sampler, input attachment):
// Note: Make sure any shader reads from the image have been finished
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: begin
result.srcAccessMask := [ VK_ACCESS_SHADER_READ_BIT ];
end;
end;

case aNewLayout of
// New layout is transfer destination (copy, blit):
// Note: Make sure any copyies to the image have been finished
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: begin
result.dstAccessMask := [ VK_ACCESS_TRANSFER_WRITE_BIT ];
end;

// New layout is transfer source (copy, blit):
// Note: Make sure any reads from and writes to the image have been finished
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: begin
result.srcAccessMask := result.srcAccessMask + [ VK_ACCESS_TRANSFER_READ_BIT ];
result.dstAccessMask := [ VK_ACCESS_TRANSFER_READ_BIT ];
end;

// New layout is color attachment:
// Note: Make sure any writes to the color buffer hav been finished
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: begin
result.dstAccessMask := [ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ];
result.srcAccessMask := [ VK_ACCESS_TRANSFER_READ_BIT ];
end;

// New layout is depth attachment:
// Note: Make sure any writes to depth/stencil buffer have been finished
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: begin
result.dstAccessMask := result.dstAccessMask + [ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT ];
end;

// New layout is shader read (sampler, input attachment):
// Note: Make sure any writes to the image have been finished
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: begin
result.srcAccessMask := [ VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT ];
result.dstAccessMask := [ VK_ACCESS_SHADER_READ_BIT ];
end;
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImage.Create(const aCreateInfo: TVkImageCreateInfo; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(aCreateInfo);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImage.Create(const aHandle: VkImage; const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fHandle := aHandle;
fDeviceCommands := aDeviceCommands;
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuImage.Destroy;
begin
if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
fDeviceCommands.vkDestroyImage(fDeviceCommands.Device, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy;
end;

end.


+ 161
- 0
projects/utils/uvkuImageFactory.pas Ver fichero

@@ -0,0 +1,161 @@
unit uvkuImageFactory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuImage, uvkuDevice, uvkuAllocationHandler, uvkuTypes;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuImageEx = class(TvkuImage)
private
fAllocHandler: TvkuAllocationHandler;
fOwnsHandle: Boolean;
public
destructor Destroy; override;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuImageFactory = class(TObject)
private
fDeviceCommands: TVkDeviceCommands;
fFlags: VkImageCreateFlags;
fImageType: TVkImageType;
fFormat: TVkFormat;
fExtent: TVkExtent3D;
fMipLevels: VkUint32;
fArrayLayers: VkUint32;
fSamples: TVkSampleCountFlagBits;
fTiling: TVkImageTiling;
fUsage: VkImageUsageFlags;
fSharingMode: TVkSharingMode;
fQueueFamilyIndices: TvkuUint32Arr;
fInitialLayout: TVkImageLayout;

function GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
function GetQueueFamilyIndexCount: Integer;
procedure SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
public
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
property Flags: VkImageCreateFlags read fFlags write fFlags;
property ImageType: TVkImageType read fImageType write fImageType;
property Format: TVkFormat read fFormat write fFormat;
property Extent: TVkExtent3D read fExtent write fExtent;
property MipLevels: VkUint32 read fMipLevels write fMipLevels;
property ArrayLayers: VkUint32 read fArrayLayers write fArrayLayers;
property Samples: TVkSampleCountFlagBits read fSamples write fSamples;
property Tiling: TVkImageTiling read fTiling write fTiling;
property Usage: VkImageUsageFlags read fUsage write fUsage;
property SharingMode: TVkSharingMode read fSharingMode write fSharingMode;
property InitialLayout: TVkImageLayout read fInitialLayout write fInitialLayout;

property QueueFamilyIndices: TvkuUint32Arr read fQueueFamilyIndices;
property QueueFamilyIndexCount: Integer read GetQueueFamilyIndexCount;
property QueueFamilyIndex[const aIndex: Integer]: VkUint32 read GetQueueFamilyIndex write SetQueueFamilyIndex;

function CreateImage: TvkuImageEx;
function CreateImage(
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuImageEx;

constructor Create(const aDevice: TvkuDevice);
constructor Create(const aDeviceCommands: TVkDeviceCommands);
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuImageEx////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuImageEx.Destroy;
begin
if fOwnsHandle then
FreeAndNil(fAllocHandler);
inherited Destroy;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuImageFactory///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuImageFactory.GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
begin
if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
result := fQueueFamilyIndices[aIndex];
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuImageFactory.GetQueueFamilyIndexCount: Integer;
begin
result := Length(fQueueFamilyIndices);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuImageFactory.SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
begin
if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
fQueueFamilyIndices[aIndex] := aValue;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuImageFactory.CreateImage: TvkuImageEx;
begin
result := CreateImage(nil, false);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuImageFactory.CreateImage(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuImageEx;
var
CreateInfo: TVkImageCreateInfo;
begin
FillByte(CreateInfo, 0, SizeOf(CreateInfo));
CreateInfo.sType := VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
CreateInfo.imageType := fImageType;
CreateInfo.format := fFormat;
CreateInfo.extent := fExtent;
CreateInfo.mipLevels := fMipLevels;
CreateInfo.arrayLayers := fArrayLayers;
CreateInfo.samples := fSamples;
CreateInfo.tiling := fTiling;
CreateInfo.usage := fUsage;
CreateInfo.sharingMode := fSharingMode;
CreateInfo.queueFamilyIndexCount := Length(fQueueFamilyIndices);
CreateInfo.pQueueFamilyIndices := @fQueueFamilyIndices[0];
CreateInfo.initialLayout := fInitialLayout;

if Assigned(aAllocHandler)
then result := TvkuImageEx.Create(CreateInfo, fDeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuImageEx.Create(CreateInfo, fDeviceCommands);
try
TvkuImageEx(result).fAllocHandler := aAllocHandler;
TvkuImageEx(result).fOwnsHandle := aOwnsHandler;
except
FreeAndNil(result);
raise;
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImageFactory.Create(const aDevice: TvkuDevice);
begin
Create(aDevice.DeviceCommands);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImageFactory.Create(const aDeviceCommands: TVkDeviceCommands);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
end;

end.


+ 84
- 0
projects/utils/uvkuImageView.pas Ver fichero

@@ -0,0 +1,84 @@
unit uvkuImageView;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuImageView = class(TvkuAllocHandle)
private
fHandle: VkImageView;
fDeviceCommands: TVkDeviceCommands;

procedure CreateHandle(const aCreateInfo: TVkImageViewCreateInfo);
public
property Handle: VkImageView read fHandle;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

constructor Create(
const aCreateInfo: TVkImageViewCreateInfo;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
constructor Create(
const aHandle: VkImageView;
const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override;
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuImageView//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuImageView.CreateHandle(const aCreateInfo: TVkImageViewCreateInfo);
var err: TVkResult;
begin
if not Assigned(fDeviceCommands.vkCreateImageView) then
raise TvkuInvalidFuncPtrException.Create('vkCreateImageView');
err := fDeviceCommands.vkCreateImageView(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create image view', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImageView.Create(const aCreateInfo: TVkImageViewCreateInfo; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(aCreateInfo);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImageView.Create(const aHandle: VkImageView; const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin
inherited Create;
fHandle := aHandle;
fDeviceCommands := aDeviceCommands;
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuImageView.Destroy;
begin
if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
fDeviceCommands.vkDestroyImageView(fDeviceCommands.Device, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy;
end;

end.


+ 110
- 0
projects/utils/uvkuImageViewFactory.pas Ver fichero

@@ -0,0 +1,110 @@
unit uvkuImageViewFactory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuAllocationHandler, uvkuImageView, uvkuDevice;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuImageViewEx = class(TvkuImageView)
private
fAllocHandler: TvkuAllocationHandler;
fOwnsHandler: Boolean;
public
destructor Destroy; override;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuImageViewFactory = class(TObject)
private
fDeviceCommands: TVkDeviceCommands;

fFlags: VkImageViewCreateFlags;
fImage: VkImage;
fViewType: TVkImageViewType;
fFormat: TVkFormat;
fComponents: TVkComponentMapping;
fSubresourceRange: TVkImageSubresourceRange;
public
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

property Flags: VkImageViewCreateFlags read fFlags write fFlags;
property Image: VkImage read fImage write fImage;
property ViewType: TVkImageViewType read fViewType write fViewType;
property Format: TVkFormat read fFormat write fFormat;
property Components: TVkComponentMapping read fComponents write fComponents;
property SubresourceRange: TVkImageSubresourceRange read fSubresourceRange write fSubresourceRange;

function CreateImageView: TvkuImageViewEx;
function CreateImageView(
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuImageViewEx;

constructor Create(const aDevice: TvkuDevice);
constructor Create(const aDeviceCommands: TVkDeviceCommands);
end;

implementation

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuImageViewEx////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuImageViewEx.Destroy;
begin
inherited Destroy;
if fOwnsHandler then
FreeAndNil(fAllocHandler);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuImageViewFactory///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuImageViewFactory.CreateImageView: TvkuImageViewEx;
begin
result := CreateImageView(nil, false);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuImageViewFactory.CreateImageView(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuImageViewEx;
var CreateInfo: TVkImageViewCreateInfo;
begin
FillByte(CreateInfo, SizeOf(CreateInfo), 0);
CreateInfo.sType := VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
CreateInfo.image := fImage;
CreateInfo.viewType := fViewType;
CreateInfo.format := fFormat;
CreateInfo.components := fComponents;
CreateInfo.subresourceRange := fSubresourceRange;
if Assigned(aAllocHandler)
then result := TvkuImageViewEx.Create(CreateInfo, fDeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuImageViewEx.Create(CreateInfo, fDeviceCommands);
try
TvkuImageViewEx(result).fAllocHandler := aAllocHandler;
TvkuImageViewEx(result).fOwnsHandler := aOwnsHandler;
except
FreeAndNil(result);
raise;
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImageViewFactory.Create(const aDevice: TvkuDevice);
begin
Create(aDevice.DeviceCommands);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuImageViewFactory.Create(const aDeviceCommands: TVkDeviceCommands);
begin
inherited Create;
fDeviceCommands := aDeviceCommands;
end;

end.


+ 23
- 39
projects/utils/uvkuInstance.pas Ver fichero

@@ -6,35 +6,32 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan;
Vulkan, uvkuBase, uvkuTypes;


type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuPhysicalDeviceArr = array of VkPhysicalDevice;
TvkuInstance = class(TObject)
TvkuInstance = class(TvkuAllocHandle)
private private
fHandle: VkInstance; fHandle: VkInstance;
fAllocCallbacks: PVkAllocationCallbacks;
fPhysicalDevices: TvkuPhysicalDeviceArr; fPhysicalDevices: TvkuPhysicalDeviceArr;
fInstanceCommands: TVkInstanceCommands; fInstanceCommands: TVkInstanceCommands;


procedure UpdatePhysicalDevices; procedure UpdatePhysicalDevices;
protected protected
procedure CreateHandle(const aCreateInfo: PVkInstanceCreateInfo; const aAllocCallbacks: PVkAllocationCallbacks);
{%H-}constructor Create;
procedure CreateHandle(const aCreateInfo: PVkInstanceCreateInfo);
public public
property Handle: VkInstance read fHandle; property Handle: VkInstance read fHandle;
property InstanceCommands: TVkInstanceCommands read fInstanceCommands; property InstanceCommands: TVkInstanceCommands read fInstanceCommands;


function GetPhysicalDevices: TvkuPhysicalDeviceArr; function GetPhysicalDevices: TvkuPhysicalDeviceArr;


constructor Create(
const aCreateInfo: TVkInstanceCreateInfo);

constructor Create( constructor Create(
const aCreateInfo: TVkInstanceCreateInfo; const aCreateInfo: TVkInstanceCreateInfo;
const aAllocCallbacks: TVkAllocationCallbacks);

const aAllocCallbacks: PVkAllocationCallbacks = nil);
constructor Create(
const aHandle: VkInstance;
const aOwnsHandle: Boolean;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override; destructor Destroy; override;
end; end;


@@ -65,14 +62,10 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuInstance.CreateHandle(const aCreateInfo: PVkInstanceCreateInfo; const aAllocCallbacks: PVkAllocationCallbacks);
procedure TvkuInstance.CreateHandle(const aCreateInfo: PVkInstanceCreateInfo);
var e: TVkResult; var e: TVkResult;
begin begin
if Assigned(aAllocCallbacks) then begin
new(fAllocCallbacks);
fAllocCallbacks^ := aAllocCallbacks^;
end;
e := vkCreateInstance(aCreateInfo, fAllocCallbacks, @fHandle);
e := vkCreateInstance(aCreateInfo, AllocCallbacks, @fHandle);
if (e < VK_SUCCESS) then if (e < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create vulkan instance', e); raise TvkuErrorException.Create('unable to create vulkan instance', e);
fInstanceCommands := LoadInstanceCommands(fHandle); fInstanceCommands := LoadInstanceCommands(fHandle);
@@ -80,14 +73,6 @@ begin
raise TvkuException.Create('unable to load instance commands'); raise TvkuException.Create('unable to load instance commands');
end; end;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuInstance.Create;
begin
inherited Create;
fHandle := nil;
fAllocCallbacks := nil;
end;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuInstance.GetPhysicalDevices: TvkuPhysicalDeviceArr; function TvkuInstance.GetPhysicalDevices: TvkuPhysicalDeviceArr;
begin begin
@@ -96,30 +81,29 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuInstance.Create(const aCreateInfo: TVkInstanceCreateInfo);
constructor TvkuInstance.Create(const aCreateInfo: TVkInstanceCreateInfo; const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
Create;
CreateHandle(@aCreateInfo, nil);
inherited Create;
fHandle := VK_INVALID_HANDLE;
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(@aCreateInfo);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuInstance.Create(const aCreateInfo: TVkInstanceCreateInfo; const aAllocCallbacks: TVkAllocationCallbacks);
constructor TvkuInstance.Create(const aHandle: VkInstance; const aOwnsHandle: Boolean; const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
Create;
CreateHandle(@aCreateInfo, @aAllocCallbacks);
inherited Create;
fHandle := aHandle;
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuInstance.Destroy; destructor TvkuInstance.Destroy;
begin begin
if (fHandle <> VK_INVALID_HANDLE) then begin
InstanceCommands.vkDestroyInstance(fHandle, fAllocCallbacks);
fHandle := VK_INVALID_HANDLE;
end;
if Assigned(fAllocCallbacks) then begin
Dispose(fAllocCallbacks);
fAllocCallbacks := nil;
end;
if OwnsHandle and (fHandle <> VK_INVALID_HANDLE) then
InstanceCommands.vkDestroyInstance(fHandle, AllocCallbacks);
fHandle := VK_INVALID_HANDLE;
FreeAndNil(fInstanceCommands); FreeAndNil(fInstanceCommands);
inherited Destroy; inherited Destroy;
end; end;


+ 6
- 15
projects/utils/uvkuInstanceFactory.pas Ver fichero

@@ -7,18 +7,9 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan, uvkuInstance, uvkuAllocationHandler;
Vulkan, uvkuInstance, uvkuAllocationHandler, uvkuTypes;


type type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuApplicationInfo = packed record
AppName: String;
AppVersion: VkVersion;
EngineName: String;
EngineVersion: VkVersion;
ApiVersion: VkVersion;
end;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuInstanceEx = class(TvkuInstance) TvkuInstanceEx = class(TvkuInstance)
private private
@@ -45,10 +36,10 @@ type
property Layers: TStrings read GetLayers; property Layers: TStrings read GetLayers;
property Extensions: TStrings read GetExtensions; property Extensions: TStrings read GetExtensions;


function CreateInstance: TvkuInstance;
function CreateInstance: TvkuInstanceEx;
function CreateInstance( function CreateInstance(
const aAllocHandler: TvkuAllocationHandler; const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuInstance;
const aOwnsHandler: Boolean): TvkuInstanceEx;


constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
@@ -110,13 +101,13 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuInstanceFactory.CreateInstance: TvkuInstance;
function TvkuInstanceFactory.CreateInstance: TvkuInstanceEx;
begin begin
result := CreateInstance(nil, false); result := CreateInstance(nil, false);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuInstanceFactory.CreateInstance(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuInstance;
function TvkuInstanceFactory.CreateInstance(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuInstanceEx;
var var
CreateInfo: TVkInstanceCreateInfo; CreateInfo: TVkInstanceCreateInfo;
AppInfo: TVkApplicationInfo; AppInfo: TVkApplicationInfo;
@@ -152,7 +143,7 @@ begin
CreateInfo.ppEnabledExtensionNames := @ext[0]; CreateInfo.ppEnabledExtensionNames := @ext[0];


if Assigned(aAllocHandler) if Assigned(aAllocHandler)
then result := TvkuInstanceEx.Create(CreateInfo, aAllocHandler.GetAllocationCallbacks)
then result := TvkuInstanceEx.Create(CreateInfo, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuInstanceEx.Create(CreateInfo); else result := TvkuInstanceEx.Create(CreateInfo);
try try
TvkuInstanceEx(result).fAllocHandler := aAllocHandler; TvkuInstanceEx(result).fAllocHandler := aAllocHandler;


+ 20
- 27
projects/utils/uvkuPhysicalDevice.pas Ver fichero

@@ -6,20 +6,11 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan, uvkuInstance;
Vulkan, uvkuBase, uvkuTypes;


type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuQueueFamilyPropertiesArr = array of TVkQueueFamilyProperties;
TvkuSparseImageFormatPropertiesArr = array of TVkSparseImageFormatProperties;
TvkuSurfaceFormatArr = array of TVkSurfaceFormatKHR;
TvkuPresentModeArr = array of TVkPresentModeKHR;
TvkuDisplayPropertiesArr = array of TVkDisplayPropertiesKHR;
TvkuDisplayPlanePropertiesArr = array of TVkDisplayPlanePropertiesKHR;
TvkuDisplayArr = array of VkDisplayKHR;
TvkuDisplayModePropertiesArr = array of TVkDisplayModePropertiesKHR;

TvkuPhysicalDevice = class(TObject)
TvkuPhysicalDevice = class(TvkuObject)
private private
fHandle: VkPhysicalDevice; fHandle: VkPhysicalDevice;
fInstanceCommands: TVkInstanceCommands; fInstanceCommands: TVkInstanceCommands;
@@ -59,7 +50,9 @@ type
property Handle: VkPhysicalDevice read fHandle; property Handle: VkPhysicalDevice read fHandle;
property InstanceCommands: TVkInstanceCommands read fInstanceCommands; property InstanceCommands: TVkInstanceCommands read fInstanceCommands;


constructor Create(const aHandle: VkPhysicalDevice; const aInstanceCommands: TVkInstanceCommands);
constructor Create(
const aHandle: VkPhysicalDevice;
const aInstanceCommands: TVkInstanceCommands);
end; end;


implementation implementation
@@ -73,7 +66,7 @@ uses
function TvkuPhysicalDevice.GetFeatures: TVkPhysicalDeviceFeatures; function TvkuPhysicalDevice.GetFeatures: TVkPhysicalDeviceFeatures;
begin begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFeatures) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFeatures) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceFeatures; did you load the vulkan core commands?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceFeatures');
fInstanceCommands.vkGetPhysicalDeviceFeatures(fHandle, @result); fInstanceCommands.vkGetPhysicalDeviceFeatures(fHandle, @result);
end; end;


@@ -81,7 +74,7 @@ end;
function TvkuPhysicalDevice.GetProperties: TVkPhysicalDeviceProperties; function TvkuPhysicalDevice.GetProperties: TVkPhysicalDeviceProperties;
begin begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceProperties) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceProperties; did you load the vulkan core commands?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceProperties');
fInstanceCommands.vkGetPhysicalDeviceProperties(fHandle, @result); fInstanceCommands.vkGetPhysicalDeviceProperties(fHandle, @result);
end; end;


@@ -89,7 +82,7 @@ end;
function TvkuPhysicalDevice.GetMemoryProperties: TVkPhysicalDeviceMemoryProperties; function TvkuPhysicalDevice.GetMemoryProperties: TVkPhysicalDeviceMemoryProperties;
begin begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceMemoryProperties) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceMemoryProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceMemoryProperties; did you load the vulkan core commands?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceMemoryProperties');
fInstanceCommands.vkGetPhysicalDeviceMemoryProperties(fHandle, @result); fInstanceCommands.vkGetPhysicalDeviceMemoryProperties(fHandle, @result);
end; end;


@@ -99,7 +92,7 @@ var c: VkUint32;
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceQueueFamilyProperties; did you load the vulkan core commands?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceQueueFamilyProperties');
fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, nil); fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, nil);
SetLength(result, c); SetLength(result, c);
fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, @result[0]); fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, @result[0]);
@@ -109,7 +102,7 @@ end;
function TvkuPhysicalDevice.GetFormatProperties(const aFormat: TVkFormat): TVkFormatProperties; function TvkuPhysicalDevice.GetFormatProperties(const aFormat: TVkFormat): TVkFormatProperties;
begin begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFormatProperties) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFormatProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceFormatProperties; did you load the vulkan core commands?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceFormatProperties');
fInstanceCommands.vkGetPhysicalDeviceFormatProperties(fHandle, aFormat, @result); fInstanceCommands.vkGetPhysicalDeviceFormatProperties(fHandle, aFormat, @result);
end; end;


@@ -119,7 +112,7 @@ function TvkuPhysicalDevice.GetImageFormatProperties(const aFormat: TVkFormat; c
var err: TVkResult; var err: TVkResult;
begin begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceImageFormatProperties; did you load the vulkan core commands?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceImageFormatProperties');
err := fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties(fHandle, aFormat, aImageType, aTiling, aUsage, aFlags, @result); err := fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties(fHandle, aFormat, aImageType, aTiling, aUsage, aFlags, @result);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device image format properties', err); raise TvkuErrorException.Create('unable to get physical device image format properties', err);
@@ -132,7 +125,7 @@ var c: VkUint32;
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSparseImageFormatProperties; did you load the vulkan core commands?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceSparseImageFormatProperties');
fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, nil); fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, nil);
SetLength(result, c); SetLength(result, c);
fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, @result[0]); fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, @result[0]);
@@ -145,7 +138,7 @@ var
err: TVkResult; err: TVkResult;
begin begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceSupportKHR; did you enabled the VK_KHR_surface extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceSurfaceSupportKHR', 'VK_KHR_surface');
err := fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR(fHandle, aQueueFamilyIndex, aSurface, @b); err := fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR(fHandle, aQueueFamilyIndex, aSurface, @b);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device surface support', err); raise TvkuErrorException.Create('unable to get physical device surface support', err);
@@ -158,7 +151,7 @@ var
err: TVkResult; err: TVkResult;
begin begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceCapabilitiesKHR; did you enabled the VK_KHR_surface extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceSurfaceCapabilitiesKHR', 'VK_KHR_surface');
err := fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(fHandle, aSurface, @result); err := fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(fHandle, aSurface, @result);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device surface capabilities', err); raise TvkuErrorException.Create('unable to get physical device surface capabilities', err);
@@ -170,7 +163,7 @@ var c: VkUint32;
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceFormatsKHR; did you enabled the VK_KHR_surface extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceSurfaceFormatsKHR', 'VK_KHR_surface');
fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, nil); fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, nil);
SetLength(result, c); SetLength(result, c);
fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, @result[0]); fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, @result[0]);
@@ -184,7 +177,7 @@ var
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfacePresentModesKHR; did you enabled the VK_KHR_surface extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceSurfacePresentModesKHR', 'VK_KHR_surface');
err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, nil); err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, nil);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device surface present mode count', err); raise TvkuErrorException.Create('unable to get physical device surface present mode count', err);
@@ -202,7 +195,7 @@ var
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPropertiesKHR; did you enabled the VK_KHR_display extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceDisplayPropertiesKHR', 'VK_KHR_display');
err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, nil); err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, nil);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device display property count', err); raise TvkuErrorException.Create('unable to get physical device display property count', err);
@@ -220,7 +213,7 @@ var
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR) then if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPlanePropertiesKHR; did you enabled the VK_KHR_display extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetPhysicalDeviceDisplayPlanePropertiesKHR', 'VK_KHR_display');
err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, nil); err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, nil);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device display plane property count', err); raise TvkuErrorException.Create('unable to get physical device display plane property count', err);
@@ -238,7 +231,7 @@ var
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR) then if not Assigned(fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR) then
raise TvkuException.Create('invalid function pointer: vkGetDisplayPlaneSupportedDisplaysKHR; did you enabled the VK_KHR_display extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetDisplayPlaneSupportedDisplaysKHR', 'VK_KHR_display');
err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, nil); err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, nil);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get supported display plane count', err); raise TvkuErrorException.Create('unable to get supported display plane count', err);
@@ -256,7 +249,7 @@ var
begin begin
result := nil; result := nil;
if not Assigned(fInstanceCommands.vkGetDisplayModePropertiesKHR) then if not Assigned(fInstanceCommands.vkGetDisplayModePropertiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetDisplayModePropertiesKHR; did you enabled the VK_KHR_display extension?');
raise TvkuInvalidFuncPtrException.Create('vkGetDisplayModePropertiesKHR', 'VK_KHR_display');
err := fInstanceCommands.vkGetDisplayModePropertiesKHR(fHandle, aDisplay, @c, nil); err := fInstanceCommands.vkGetDisplayModePropertiesKHR(fHandle, aDisplay, @c, nil);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get display mode property count', err); raise TvkuErrorException.Create('unable to get display mode property count', err);


+ 0
- 41
projects/utils/uvkuPhysicalDeviceFactory.pas Ver fichero

@@ -1,41 +0,0 @@
unit uvkuPhysicalDeviceFactory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuInstance, uvkuPhysicalDevice;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuPhysicalDeviceFactory = class(TObject)
private
fInstance: TvkuInstance;
public
function CreatePhysicalDevice(
const aHandle: VkPhysicalDevice): TvkuPhysicalDevice;

constructor Create(const aInstance: TvkuInstance);
end;

implementation

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuPhysicalDeviceFactory//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDeviceFactory.CreatePhysicalDevice(const aHandle: VkPhysicalDevice): TvkuPhysicalDevice;
begin
result := TvkuPhysicalDevice.Create(aHandle, fInstance.InstanceCommands);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuPhysicalDeviceFactory.Create(const aInstance: TvkuInstance);
begin
inherited Create;
fInstance := aInstance;
end;

end.


+ 39
- 0
projects/utils/uvkuQueue.pas Ver fichero

@@ -0,0 +1,39 @@
unit uvkuQueue;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuQueue = class(TvkuObject)
private
fHandle: VkQueue;
fDeviceCommands: TVkDeviceCommands;
public
property Handle: VkQueue read fHandle;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands;

constructor Create(
const aHandle: VkQueue;
const aDeviceCommands: TVkDeviceCommands);
end;

implementation

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuQueue//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuQueue.Create(const aHandle: VkQueue; const aDeviceCommands: TVkDeviceCommands);
begin
inherited Create;
fHandle := aHandle;
fDeviceCommands := aDeviceCommands;
end;

end.


+ 26
- 36
projects/utils/uvkuSurface.pas Ver fichero

@@ -7,36 +7,34 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan;
Vulkan, uvkuBase;


type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuSurface = class(TObject)
TvkuSurface = class(TvkuAllocHandle)
private private
fHandle: VkSurfaceKHR; fHandle: VkSurfaceKHR;
fInstance: VkInstance;
fAllocCallbacks: PVkAllocationCallbacks;
fInstanceCommands: TVkInstanceCommands; fInstanceCommands: TVkInstanceCommands;


procedure CreateHandle(const aCreateInfo: Pointer; const aAllocCallbacks: PVkAllocationCallbacks);
procedure CreateHandle(const aCreateInfo: Pointer);
public public
property Handle: VkSurfaceKHR read fHandle; property Handle: VkSurfaceKHR read fHandle;
property Instance: VkInstance read fInstance;
property InstanceCommands: TVkInstanceCommands read fInstanceCommands; property InstanceCommands: TVkInstanceCommands read fInstanceCommands;


{$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)} {$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
constructor Create( constructor Create(
const aInstance: VkInstance;
const aCreateInfo: TVkWin32SurfaceCreateInfoKHR;
const aInstanceCommands: TVkInstanceCommands);
constructor Create(
const aInstance: VkInstance;
const aCreateInfo: TVkWin32SurfaceCreateInfoKHR; const aCreateInfo: TVkWin32SurfaceCreateInfoKHR;
const aInstanceCommands: TVkInstanceCommands; const aInstanceCommands: TVkInstanceCommands;
const aAllocCallbacks: TVkAllocationCallbacks);
const aAllocCallbacks: PVkAllocationCallbacks = nil);
{$ELSE} {$ELSE}
{$ERROR 'unknown or unsupportet platform'} {$ERROR 'unknown or unsupportet platform'}
{$ENDIF} {$ENDIF}

constructor Create(
const aHandle: VkSurfaceKHR;
const aOwnsHandle: Boolean;
const aInstanceCommands: TVkInstanceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil);
destructor Destroy; override; destructor Destroy; override;
public public
class function GetPlatformSurfaceExtensionName: String; class function GetPlatformSurfaceExtensionName: String;
@@ -50,17 +48,13 @@ uses
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuSurface//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuSurface////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurface.CreateHandle(const aCreateInfo: Pointer; const aAllocCallbacks: PVkAllocationCallbacks);
procedure TvkuSurface.CreateHandle(const aCreateInfo: Pointer);
var err: TVkResult; var err: TVkResult;
begin begin
if Assigned(aAllocCallbacks) then begin
new(fAllocCallbacks);
fAllocCallbacks^ := aAllocCallbacks^;
end;
{$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)} {$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
if not Assigned(fInstanceCommands.vkCreateWin32SurfaceKHR) then if not Assigned(fInstanceCommands.vkCreateWin32SurfaceKHR) then
raise TvkuException.Create('invalid function pointer: vkCreateWin32SurfaceKHR; did you enabled the VK_KHR_win32_surface extension?');
err := fInstanceCommands.vkCreateWin32SurfaceKHR(fInstance, aCreateInfo, fAllocCallbacks, @fHandle);
raise TvkuInvalidFuncPtrException.Create('vkCreateWin32SurfaceKHR', 'VK_KHR_win32_surface');
err := fInstanceCommands.vkCreateWin32SurfaceKHR(fInstanceCommands.Instance, aCreateInfo, AllocCallbacks, @fHandle);
{$ENDIF} {$ENDIF}
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create surface', err); raise TvkuErrorException.Create('unable to create surface', err);
@@ -68,37 +62,33 @@ end;


{$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)} {$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSurface.Create(const aInstance: VkInstance; const aCreateInfo: TVkWin32SurfaceCreateInfoKHR;
const aInstanceCommands: TVkInstanceCommands);
constructor TvkuSurface.Create(const aCreateInfo: TVkWin32SurfaceCreateInfoKHR;
const aInstanceCommands: TVkInstanceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
inherited Create; inherited Create;
fInstance := aInstance;
fInstanceCommands := aInstanceCommands; fInstanceCommands := aInstanceCommands;
CreateHandle(@aCreateInfo, nil);
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(@aCreateInfo);
end; end;
{$ENDIF}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSurface.Create(const aInstance: VkInstance; const aCreateInfo: TVkWin32SurfaceCreateInfoKHR;
const aInstanceCommands: TVkInstanceCommands; const aAllocCallbacks: TVkAllocationCallbacks);
constructor TvkuSurface.Create(const aHandle: VkSurfaceKHR; const aOwnsHandle: Boolean;
const aInstanceCommands: TVkInstanceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
inherited Create; inherited Create;
fInstance := aInstance;
fHandle := aHandle;
fInstanceCommands := aInstanceCommands; fInstanceCommands := aInstanceCommands;
CreateHandle(@aCreateInfo, @aAllocCallbacks);
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end; end;
{$ENDIF}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuSurface.Destroy; destructor TvkuSurface.Destroy;
begin begin
if (fHandle <> VK_INVALID_NDP_HANDLE) then begin
fInstanceCommands.vkDestroySurfaceKHR(fInstance, fHandle, fAllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
end;
if Assigned(fAllocCallbacks) then begin
Dispose(fAllocCallbacks);
fAllocCallbacks := nil;
end;
if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
fInstanceCommands.vkDestroySurfaceKHR(fInstanceCommands.Instance, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy; inherited Destroy;
end; end;




+ 9
- 11
projects/utils/uvkuSurfaceFactory.pas Ver fichero

@@ -34,20 +34,19 @@ type
private private
fFlags: VkFlags; fFlags: VkFlags;
fWinControl: TWinControl; fWinControl: TWinControl;
fInstance: VkInstance;
fInstanceCommands: TVkInstanceCommands; fInstanceCommands: TVkInstanceCommands;
procedure SetWinControl(aValue: TWinControl); procedure SetWinControl(aValue: TWinControl);
public public
property WinControl: TWinControl read fWinControl write SetWinControl; property WinControl: TWinControl read fWinControl write SetWinControl;
property Flags: VkFlags read fFlags write fFlags; property Flags: VkFlags read fFlags write fFlags;


function CreateSurface: TvkuSurface;
function CreateSurface: TvkuSurfaceEx;
function CreateSurface( function CreateSurface(
const aAllocHandler: TvkuAllocationHandler; const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuSurface;
const aOwnsHandler: Boolean): TvkuSurfaceEx;


constructor Create(const aInstance: TvkuInstance); constructor Create(const aInstance: TvkuInstance);
constructor Create(const aInstance: VkInstance; const aInstanceCommands: TVkInstanceCommands);
constructor Create(const aInstanceCommands: TVkInstanceCommands);
end; end;


implementation implementation
@@ -154,13 +153,13 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuSurfaceFactory.CreateSurface: TvkuSurface;
function TvkuSurfaceFactory.CreateSurface: TvkuSurfaceEx;
begin begin
result := CreateSurface(nil, false); result := CreateSurface(nil, false);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuSurfaceFactory.CreateSurface(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuSurface;
function TvkuSurfaceFactory.CreateSurface(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuSurfaceEx;
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)} {$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
{$ERROR 'TODO: implement'} {$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)} {$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)}
@@ -195,8 +194,8 @@ begin
CreateInfo.hwnd := fHwnd; CreateInfo.hwnd := fHwnd;
{$ENDIF} {$ENDIF}
if Assigned(aAllocHandler) if Assigned(aAllocHandler)
then srf := TvkuSurfaceEx.Create(fInstance, CreateInfo, fInstanceCommands, aAllocHandler.GetAllocationCallbacks)
else srf := TvkuSurfaceEx.Create(fInstance, CreateInfo, fInstanceCommands);
then srf := TvkuSurfaceEx.Create(CreateInfo, fInstanceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else srf := TvkuSurfaceEx.Create(CreateInfo, fInstanceCommands);
try try
srf.fAllocHandler := aAllocHandler; srf.fAllocHandler := aAllocHandler;
srf.fOwnsHandler := aOwnsHandler; srf.fOwnsHandler := aOwnsHandler;
@@ -209,11 +208,11 @@ end;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSurfaceFactory.Create(const aInstance: TvkuInstance); constructor TvkuSurfaceFactory.Create(const aInstance: TvkuInstance);
begin begin
Create(aInstance.Handle, aInstance.InstanceCommands);
Create(aInstance.InstanceCommands);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSurfaceFactory.Create(const aInstance: VkInstance; const aInstanceCommands: TVkInstanceCommands);
constructor TvkuSurfaceFactory.Create(const aInstanceCommands: TVkInstanceCommands);
begin begin
inherited Create; inherited Create;
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)} {$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
@@ -229,7 +228,6 @@ begin
{$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)} {$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
fHInstance := Vulkan.HINSTANCE(GetModuleHandle(nil)); fHInstance := Vulkan.HINSTANCE(GetModuleHandle(nil));
{$ENDIF} {$ENDIF}
fInstance := aInstance;
fInstanceCommands := aInstanceCommands; fInstanceCommands := aInstanceCommands;
fFlags := 0; fFlags := 0;
end; end;


+ 28
- 42
projects/utils/uvkuSwapChain.pas Ver fichero

@@ -6,38 +6,32 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan;
Vulkan, uvkuBase, uvkuTypes;


type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuImageArr = array of VkImage;
TvkuSwapChain = class(TObject)
TvkuSwapChain = class(TvkuAllocHandle)
private private
fHandle: VkSwapchainKHR; fHandle: VkSwapchainKHR;
fDevice: VkDevice;
fAllocCallbacks: PVkAllocationCallbacks;
fDeviceCommands: TVkDeviceCommands; fDeviceCommands: TVkDeviceCommands;


procedure CreateHandle(
const aCreateInfo: PVkSwapchainCreateInfoKHR;
const aAllocCallbacks: PVkAllocationCallbacks);
procedure CreateHandle(const aCreateInfo: PVkSwapchainCreateInfoKHR);
public public
property Handle: VkSwapchainKHR read fHandle; property Handle: VkSwapchainKHR read fHandle;
property Device: VkDevice read fDevice;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands; property DeviceCommands: TVkDeviceCommands read fDeviceCommands;


function GetImages: TvkuImageArr; function GetImages: TvkuImageArr;
function AcquireNextImage(const aTimeout: VkUint64; const aSemaphore: VkSemaphore; const aFence: VkFence): VkUint32; function AcquireNextImage(const aTimeout: VkUint64; const aSemaphore: VkSemaphore; const aFence: VkFence): VkUint32;


constructor Create( constructor Create(
const aDevice: VkDevice;
const aCreateInfo: TVkSwapchainCreateInfoKHR; const aCreateInfo: TVkSwapchainCreateInfoKHR;
const aDeviceCommands: TVkDeviceCommands);
const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks = nil); overload;
constructor Create( constructor Create(
const aDevice: VkDevice;
const aCreateInfo: TVkSwapchainCreateInfoKHR;
const aHandle: VkSwapchainKHR;
const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: TVkAllocationCallbacks);
const aAllocCallbacks: PVkAllocationCallbacks = nil); overload;
destructor Destroy; override; destructor Destroy; override;
end; end;


@@ -49,18 +43,14 @@ uses
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuSwapChain////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuSwapChain//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSwapChain.CreateHandle(const aCreateInfo: PVkSwapchainCreateInfoKHR; const aAllocCallbacks: PVkAllocationCallbacks);
procedure TvkuSwapChain.CreateHandle(const aCreateInfo: PVkSwapchainCreateInfoKHR);
var err: TVkResult; var err: TVkResult;
begin begin
if Assigned(aAllocCallbacks) then begin
new(fAllocCallbacks);
fAllocCallbacks^ := aAllocCallbacks^;
end;
if not Assigned(fDeviceCommands.vkCreateSwapchainKHR) then if not Assigned(fDeviceCommands.vkCreateSwapchainKHR) then
raise TvkuException.Create('invalid function pointer: vkCreateSwapchainKHR; did you enabled the VK_KHR_swapchain extension?'); raise TvkuException.Create('invalid function pointer: vkCreateSwapchainKHR; did you enabled the VK_KHR_swapchain extension?');
err := fDeviceCommands.vkCreateSwapchainKHR(fDevice, aCreateInfo, fAllocCallbacks, @fHandle);
err := fDeviceCommands.vkCreateSwapchainKHR(fDeviceCommands.Device, aCreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create surface', err);
raise TvkuErrorException.Create('unable to create swap chain', err);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -70,12 +60,12 @@ var
err: TVkResult; err: TVkResult;
begin begin
if not Assigned(fDeviceCommands.vkGetSwapchainImagesKHR) then if not Assigned(fDeviceCommands.vkGetSwapchainImagesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetSwapchainImagesKHR; did you enabled the VK_KHR_swapchain extension?');
err := fDeviceCommands.vkGetSwapchainImagesKHR(fDevice, fHandle, @c, nil);
raise TvkuInvalidFuncPtrException.Create('vkGetSwapchainImagesKHR', 'VK_KHR_swapchain');
err := fDeviceCommands.vkGetSwapchainImagesKHR(fDeviceCommands.Device, fHandle, @c, nil);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get swap chain image count', err); raise TvkuErrorException.Create('unable to get swap chain image count', err);
SetLength(result, c); SetLength(result, c);
err := fDeviceCommands.vkGetSwapchainImagesKHR(fDevice, fHandle, @c, @result[0]);
err := fDeviceCommands.vkGetSwapchainImagesKHR(fDeviceCommands.Device, fHandle, @c, @result[0]);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get swap chain images', err); raise TvkuErrorException.Create('unable to get swap chain images', err);
end; end;
@@ -83,46 +73,42 @@ end;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuSwapChain.AcquireNextImage(const aTimeout: VkUint64; const aSemaphore: VkSemaphore; const aFence: VkFence): VkUint32; function TvkuSwapChain.AcquireNextImage(const aTimeout: VkUint64; const aSemaphore: VkSemaphore; const aFence: VkFence): VkUint32;
var var
c: VkUint32;
err: TVkResult; err: TVkResult;
begin begin
if not Assigned(fDeviceCommands.vkAcquireNextImageKHR) then if not Assigned(fDeviceCommands.vkAcquireNextImageKHR) then
raise TvkuException.Create('invalid function pointer: vkAcquireNextImageKHR; did you enabled the VK_KHR_swapchain extension?');
err := fDeviceCommands.vkAcquireNextImageKHR(fDevice, fHandle, aTimeout, aSemaphore, aFence, @result);
raise TvkuInvalidFuncPtrException.Create('vkAcquireNextImageKHR', 'VK_KHR_swapchain');
err := fDeviceCommands.vkAcquireNextImageKHR(fDeviceCommands.Device, fHandle, aTimeout, aSemaphore, aFence, @result);
if (err < VK_SUCCESS) then if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to aquire next image', err); raise TvkuErrorException.Create('unable to aquire next image', err);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSwapChain.Create(const aDevice: VkDevice; const aCreateInfo: TVkSwapchainCreateInfoKHR; const aDeviceCommands: TVkDeviceCommands);
constructor TvkuSwapChain.Create(const aCreateInfo: TVkSwapchainCreateInfoKHR; const aDeviceCommands: TVkDeviceCommands;
const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
inherited Create; inherited Create;
fDevice := aDevice;
fDeviceCommands := aDeviceCommands; fDeviceCommands := aDeviceCommands;
CreateHandle(@aCreateInfo, nil);
SetAllocCallbacks(aAllocCallbacks);
CreateHandle(@aCreateInfo);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSwapChain.Create(const aDevice: VkDevice; const aCreateInfo: TVkSwapchainCreateInfoKHR;
const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: TVkAllocationCallbacks);
constructor TvkuSwapChain.Create(const aHandle: VkSwapchainKHR; const aOwnsHandle: Boolean;
const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
begin begin
inherited Create; inherited Create;
fDevice := aDevice;
fHandle := aHandle;
fDeviceCommands := aDeviceCommands; fDeviceCommands := aDeviceCommands;
CreateHandle(@aCreateInfo, @aAllocCallbacks);
OwnsHandle := aOwnsHandle;
SetAllocCallbacks(aAllocCallbacks);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuSwapChain.Destroy; destructor TvkuSwapChain.Destroy;
begin begin
if (fHandle <> VK_INVALID_NDP_HANDLE) then begin
fDeviceCommands.vkDestroySwapchainKHR(fDevice, fHandle, fAllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
end;
if Assigned(fAllocCallbacks) then begin
Dispose(fAllocCallbacks);
fAllocCallbacks := nil;
end;
if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
fDeviceCommands.vkDestroySwapchainKHR(fDeviceCommands.Device, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy; inherited Destroy;
end; end;




+ 7
- 10
projects/utils/uvkuSwapChainFactory.pas Ver fichero

@@ -6,7 +6,7 @@ interface


uses uses
Classes, SysUtils, Classes, SysUtils,
Vulkan, uvkuSwapChain, uvkuAllocationHandler, uvkuDevice;
Vulkan, uvkuSwapChain, uvkuTypes, uvkuAllocationHandler, uvkuDevice;


type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -19,10 +19,8 @@ type
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuUint32Arr = array of VkUint32;
TvkuSwapChainFactory = class(TObject) TvkuSwapChainFactory = class(TObject)
private private
fDevice: VkDevice;
fDeviceCommands: TVkDeviceCommands; fDeviceCommands: TVkDeviceCommands;


fFlags: VkSwapchainCreateFlagsKHR; fFlags: VkSwapchainCreateFlagsKHR;
@@ -45,7 +43,6 @@ type
function GetQueueFamilyIndex(const aIndex: Integer): VkUint32; function GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
procedure SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32); procedure SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
public public
property Device: VkDevice read fDevice;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands; property DeviceCommands: TVkDeviceCommands read fDeviceCommands;


property Flags: VkSwapchainCreateFlagsKHR read fFlags write fFlags; property Flags: VkSwapchainCreateFlagsKHR read fFlags write fFlags;
@@ -73,7 +70,7 @@ type
const aOwnsHandler: Boolean): TvkuSwapChain; const aOwnsHandler: Boolean): TvkuSwapChain;


constructor Create(const aDevice: TvkuDevice); constructor Create(const aDevice: TvkuDevice);
constructor Create(const aDevice: VkDevice; const aDeviceCommands: TVkDeviceCommands);
constructor Create(const aDeviceCommands: TVkDeviceCommands);
end; end;


implementation implementation
@@ -149,27 +146,27 @@ begin
else CreateInfo.clipped := VK_FALSE; else CreateInfo.clipped := VK_FALSE;


if Assigned(aAllocHandler) if Assigned(aAllocHandler)
then result := TvkuSwapChainEx.Create(fDevice, CreateInfo, fDeviceCommands, aAllocHandler.GetAllocationCallbacks)
else result := TvkuSwapChainEx.Create(fDevice, CreateInfo, fDeviceCommands);
then result := TvkuSwapChainEx.Create(CreateInfo, fDeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
else result := TvkuSwapChainEx.Create(CreateInfo, fDeviceCommands);
try try
TvkuSwapChainEx(result).fAllocHandler := aAllocHandler; TvkuSwapChainEx(result).fAllocHandler := aAllocHandler;
TvkuSwapChainEx(result).fOwnsHandler := aOwnsHandler; TvkuSwapChainEx(result).fOwnsHandler := aOwnsHandler;
except except
FreeAndNil(result); FreeAndNil(result);
raise;
end; end;
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSwapChainFactory.Create(const aDevice: TvkuDevice); constructor TvkuSwapChainFactory.Create(const aDevice: TvkuDevice);
begin begin
Create(aDevice.Handle, aDevice.DeviceCommands);
Create(aDevice.DeviceCommands);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSwapChainFactory.Create(const aDevice: VkDevice; const aDeviceCommands: TVkDeviceCommands);
constructor TvkuSwapChainFactory.Create(const aDeviceCommands: TVkDeviceCommands);
begin begin
inherited Create; inherited Create;
fDevice := aDevice;
fDeviceCommands := aDeviceCommands; fDeviceCommands := aDeviceCommands;
fPresentMode := VK_PRESENT_MODE_FIFO_KHR; fPresentMode := VK_PRESENT_MODE_FIFO_KHR;
end; end;


+ 45
- 0
projects/utils/uvkuTypes.pas Ver fichero

@@ -0,0 +1,45 @@
unit uvkuTypes;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan;

type
TvkuFloatArr = array of VkFloat;
TvkuUint32Arr = array of VkUint32;
TvkuImageArr = array of VkImage;
TvkuPhysicalDeviceArr = array of VkPhysicalDevice;
TvkuQueueFamilyPropertiesArr = array of TVkQueueFamilyProperties;
TvkuSparseImageFormatPropertiesArr = array of TVkSparseImageFormatProperties;
TvkuSurfaceFormatArr = array of TVkSurfaceFormatKHR;
TvkuPresentModeArr = array of TVkPresentModeKHR;
TvkuDisplayPropertiesArr = array of TVkDisplayPropertiesKHR;
TvkuDisplayPlanePropertiesArr = array of TVkDisplayPlanePropertiesKHR;
TvkuDisplayArr = array of VkDisplayKHR;
TvkuDisplayModePropertiesArr = array of TVkDisplayModePropertiesKHR;
TvkuCommandBufferArr = array of VkCommandBuffer;

TvkuApplicationInfo = packed record
AppName: String;
AppVersion: VkVersion;
EngineName: String;
EngineVersion: VkVersion;
ApiVersion: VkVersion;
end;

TvkuQueueCreateInfo = packed record
Flags: VkDeviceQueueCreateFlags;
FamilyIndex: VkUint32;
Priorities: TvkuFloatArr;
end;
TvkuQueueCreateInfoArr = array of TvkuQueueCreateInfo;


implementation

end.


+ 27
- 0
projects/utils/uvkuUtils.pas Ver fichero

@@ -11,6 +11,7 @@ uses
type type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuException = class(Exception); TvkuException = class(Exception);

TvkuErrorException = class(TvkuException) TvkuErrorException = class(TvkuException)
private private
fError: TVkResult; fError: TVkResult;
@@ -19,6 +20,18 @@ type
constructor Create(const msg: string; const aError: TVkResult); constructor Create(const msg: string; const aError: TVkResult);
end; end;


TvkuInvalidFuncPtrException = class(TvkuException)
private
fExtensionName: String;
fFunctionName: String;
fExtentionName: String;
public
property FunctionName: String read fFunctionName;
property ExtensionName: String read fExtensionName;

constructor Create(const aFunctionName: String; const aExtensionName: String = '');
end;

function vkuMakeString(const aFeatures: TVkPhysicalDeviceFeatures; const aSeperator: String = sLineBreak): String; function vkuMakeString(const aFeatures: TVkPhysicalDeviceFeatures; const aSeperator: String = sLineBreak): String;
function vkuMakeString(const aProperties: TVkPhysicalDeviceProperties; const aPrintLimits, aPrintSparseProps: Boolean): String; function vkuMakeString(const aProperties: TVkPhysicalDeviceProperties; const aPrintLimits, aPrintSparseProps: Boolean): String;
function vkuMakeString(const aMemoryProperties: TVkPhysicalDeviceMemoryProperties): String; function vkuMakeString(const aMemoryProperties: TVkPhysicalDeviceMemoryProperties): String;
@@ -34,6 +47,20 @@ begin
fError := aError; fError := aError;
end; end;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuInvalidFuncPtrException////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuInvalidFuncPtrException.Create(const aFunctionName: String; const aExtensionName: String);
var s: String;
begin
fFunctionName := aFunctionName;
fExtensionName := aExtensionName;
s := 'did you load the vulkan core commands?';
if (aExtensionName <> '') then
s := 'did you enabled/load the ' + fExtensionName + ' extension?';
inherited Create('invalid function pointer: ' + fFunctionName + '; ' + s);
end;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Cargando…
Cancelar
Guardar