Просмотр исходного кода

* refactored Vulkan initialization

* implemented DebugReporter
master
Bergmann89 10 лет назад
Родитель
Сommit
da6e22a74c
9 измененных файлов: 504 добавлений и 201 удалений
  1. +5
    -1
      projects/triangle/triangle.lpi
  2. +1
    -1
      projects/triangle/triangle.lpr
  3. +160
    -149
      projects/triangle/triangle.lps
  4. +151
    -43
      projects/triangle/uMainForm.pas
  5. +4
    -1
      projects/utils/VulkanUtils.pas
  6. +25
    -6
      projects/utils/uvkuAllocationHandler.pas
  7. +21
    -0
      projects/utils/uvkuCommandBuffer.pas
  8. +3
    -0
      projects/utils/uvkuCommandPoolFactory.pas
  9. +134
    -0
      projects/utils/uvkuDebugReporter.pas

+ 5
- 1
projects/triangle/triangle.lpi Просмотреть файл

@@ -33,7 +33,7 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item1> </Item1>
</RequiredPackages> </RequiredPackages>
<Units Count="43">
<Units Count="44">
<Unit0> <Unit0>
<Filename Value="triangle.lpr"/> <Filename Value="triangle.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@@ -209,6 +209,10 @@
<Filename Value="..\utils\uvkuPipelineFactory.pas"/> <Filename Value="..\utils\uvkuPipelineFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit42> </Unit42>
<Unit43>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<IsPartOfProject Value="True"/>
</Unit43>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>


+ 1
- 1
projects/triangle/triangle.lpr Просмотреть файл

@@ -8,7 +8,7 @@ uses
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$ENDIF}{$ENDIF}
SysUtils, Interfaces, Dialogs, Forms, SysUtils, Interfaces, Dialogs, Forms,
uMainForm, Vulkan;
uMainForm, Vulkan, uvkuDebugReporter;


{$R *.res} {$R *.res}




+ 160
- 149
projects/triangle/triangle.lps Просмотреть файл

@@ -4,14 +4,13 @@
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Version Value="9"/> <Version Value="9"/>
<BuildModes Active="Default"/> <BuildModes Active="Default"/>
<Units Count="63">
<Units Count="64">
<Unit0> <Unit0>
<Filename Value="triangle.lpr"/> <Filename Value="triangle.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="5"/>
<EditorIndex Value="-1"/>
<CursorPos X="3" Y="31"/> <CursorPos X="3" Y="31"/>
<UsageCount Value="93"/>
<Loaded Value="True"/>
<UsageCount Value="98"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="uMainForm.pas"/> <Filename Value="uMainForm.pas"/>
@@ -20,25 +19,25 @@
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<TopLine Value="104"/>
<CursorPos Y="118"/>
<UsageCount Value="93"/>
<EditorIndex Value="4"/>
<TopLine Value="327"/>
<CursorPos X="35" Y="349"/>
<UsageCount Value="98"/>
<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="4295"/>
<CursorPos X="41" Y="4316"/>
<EditorIndex Value="3"/>
<TopLine Value="712"/>
<CursorPos X="17" Y="727"/>
<ExtraEditorCount Value="1"/> <ExtraEditorCount Value="1"/>
<ExtraEditor1> <ExtraEditor1>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="1857"/>
<CursorPos X="75" Y="1873"/>
<TopLine Value="3271"/>
<CursorPos X="80" Y="3291"/>
</ExtraEditor1> </ExtraEditor1>
<UsageCount Value="93"/>
<UsageCount Value="98"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
@@ -46,49 +45,47 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="45" Y="16"/> <CursorPos X="45" Y="16"/>
<UsageCount Value="91"/>
<UsageCount Value="96"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/> <Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="2"/>
<EditorIndex Value="-1"/>
<TopLine Value="13"/> <TopLine Value="13"/>
<CursorPos X="3" Y="29"/> <CursorPos X="3" Y="29"/>
<UsageCount Value="85"/>
<Loaded Value="True"/>
<UsageCount Value="90"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/> <Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="6"/>
<TopLine Value="159"/>
<CursorPos X="16" Y="210"/>
<UsageCount Value="85"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="6"/>
<CursorPos X="67" Y="22"/>
<UsageCount Value="90"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/> <Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="4"/>
<CursorPos X="3" Y="93"/>
<UsageCount Value="75"/>
<TopLine Value="90"/>
<CursorPos X="15" Y="72"/>
<UsageCount Value="80"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit6> </Unit6>
<Unit7> <Unit7>
<Filename Value="..\utils\uvkuDevice.pas"/> <Filename Value="..\utils\uvkuDevice.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="54"/>
<CursorPos Y="81"/>
<UsageCount Value="79"/>
<TopLine Value="62"/>
<CursorPos X="35" Y="67"/>
<UsageCount Value="84"/>
</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="353"/>
<CursorPos Y="377"/>
<UsageCount Value="77"/>
<TopLine Value="11"/>
<CursorPos X="10" Y="18"/>
<UsageCount Value="82"/>
</Unit8> </Unit8>
<Unit9> <Unit9>
<Filename Value="..\utils\uvkuSurface.pas"/> <Filename Value="..\utils\uvkuSurface.pas"/>
@@ -96,7 +93,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="41"/> <TopLine Value="41"/>
<CursorPos X="94" Y="56"/> <CursorPos X="94" Y="56"/>
<UsageCount Value="72"/>
<UsageCount Value="77"/>
</Unit9> </Unit9>
<Unit10> <Unit10>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/> <Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
@@ -104,15 +101,15 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="44"/> <TopLine Value="44"/>
<CursorPos X="33" Y="60"/> <CursorPos X="33" Y="60"/>
<UsageCount Value="71"/>
<UsageCount Value="76"/>
</Unit10> </Unit10>
<Unit11> <Unit11>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/> <Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="64"/>
<CursorPos X="63" Y="51"/>
<UsageCount Value="62"/>
<EditorIndex Value="6"/>
<CursorPos X="3" Y="13"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
</Unit11> </Unit11>
<Unit12> <Unit12>
<Filename Value="..\utils\uvkuSwapChain.pas"/> <Filename Value="..\utils\uvkuSwapChain.pas"/>
@@ -120,7 +117,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="7"/> <TopLine Value="7"/>
<CursorPos X="36" Y="23"/> <CursorPos X="36" Y="23"/>
<UsageCount Value="61"/>
<UsageCount Value="66"/>
</Unit12> </Unit12>
<Unit13> <Unit13>
<Filename Value="..\utils\uvkuImageView.pas"/> <Filename Value="..\utils\uvkuImageView.pas"/>
@@ -128,7 +125,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="29"/> <TopLine Value="29"/>
<CursorPos X="64" Y="47"/> <CursorPos X="64" Y="47"/>
<UsageCount Value="58"/>
<UsageCount Value="63"/>
</Unit13> </Unit13>
<Unit14> <Unit14>
<Filename Value="..\utils\uvkuImageViewFactory.pas"/> <Filename Value="..\utils\uvkuImageViewFactory.pas"/>
@@ -136,7 +133,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="24"/> <TopLine Value="24"/>
<CursorPos X="60" Y="88"/> <CursorPos X="60" Y="88"/>
<UsageCount Value="58"/>
<UsageCount Value="63"/>
</Unit14> </Unit14>
<Unit15> <Unit15>
<Filename Value="..\utils\uvkuImage.pas"/> <Filename Value="..\utils\uvkuImage.pas"/>
@@ -144,15 +141,16 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="48"/> <TopLine Value="48"/>
<CursorPos X="17" Y="64"/> <CursorPos X="17" Y="64"/>
<UsageCount Value="57"/>
<UsageCount Value="62"/>
</Unit15> </Unit15>
<Unit16> <Unit16>
<Filename Value="..\utils\uvkuBase.pas"/> <Filename Value="..\utils\uvkuBase.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="21"/>
<CursorPos Y="82"/>
<UsageCount Value="56"/>
<EditorIndex Value="2"/>
<TopLine Value="16"/>
<CursorPos X="15" Y="32"/>
<UsageCount Value="61"/>
<Loaded Value="True"/>
</Unit16> </Unit16>
<Unit17> <Unit17>
<Filename Value="..\utils\uvkuDeviceMemory.pas"/> <Filename Value="..\utils\uvkuDeviceMemory.pas"/>
@@ -160,7 +158,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="33"/> <TopLine Value="33"/>
<CursorPos X="79" Y="44"/> <CursorPos X="79" Y="44"/>
<UsageCount Value="54"/>
<UsageCount Value="59"/>
</Unit17> </Unit17>
<Unit18> <Unit18>
<Filename Value="..\utils\uvkuBuffer.pas"/> <Filename Value="..\utils\uvkuBuffer.pas"/>
@@ -168,7 +166,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="10"/> <TopLine Value="10"/>
<CursorPos X="3" Y="13"/> <CursorPos X="3" Y="13"/>
<UsageCount Value="53"/>
<UsageCount Value="58"/>
</Unit18> </Unit18>
<Unit19> <Unit19>
<Filename Value="..\utils\uvkuImageFactory.pas"/> <Filename Value="..\utils\uvkuImageFactory.pas"/>
@@ -176,7 +174,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="20"/> <TopLine Value="20"/>
<CursorPos X="60" Y="74"/> <CursorPos X="60" Y="74"/>
<UsageCount Value="53"/>
<UsageCount Value="58"/>
</Unit19> </Unit19>
<Unit20> <Unit20>
<Filename Value="..\utils\uvkuTypes.pas"/> <Filename Value="..\utils\uvkuTypes.pas"/>
@@ -184,7 +182,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="79"/> <TopLine Value="79"/>
<CursorPos Y="95"/> <CursorPos Y="95"/>
<UsageCount Value="53"/>
<UsageCount Value="58"/>
</Unit20> </Unit20>
<Unit21> <Unit21>
<Filename Value="..\utils\uvkuBufferFactory.pas"/> <Filename Value="..\utils\uvkuBufferFactory.pas"/>
@@ -192,7 +190,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="20"/> <TopLine Value="20"/>
<CursorPos X="60" Y="58"/> <CursorPos X="60" Y="58"/>
<UsageCount Value="52"/>
<UsageCount Value="57"/>
</Unit21> </Unit21>
<Unit22> <Unit22>
<Filename Value="..\utils\uvkuBufferView.pas"/> <Filename Value="..\utils\uvkuBufferView.pas"/>
@@ -200,52 +198,57 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="52"/> <TopLine Value="52"/>
<CursorPos X="56" Y="76"/> <CursorPos X="56" Y="76"/>
<UsageCount Value="52"/>
<UsageCount Value="57"/>
</Unit22> </Unit22>
<Unit23> <Unit23>
<Filename Value="..\utils\uvkuBufferViewFactory.pas"/> <Filename Value="..\utils\uvkuBufferViewFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="31" Y="45"/> <CursorPos X="31" Y="45"/>
<UsageCount Value="51"/>
<UsageCount Value="56"/>
</Unit23> </Unit23>
<Unit24> <Unit24>
<Filename Value="..\utils\uvkuCommandPool.pas"/> <Filename Value="..\utils\uvkuCommandPool.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="57"/>
<CursorPos X="21" Y="73"/>
<UsageCount Value="51"/>
<EditorIndex Value="8"/>
<TopLine Value="61"/>
<CursorPos X="39" Y="77"/>
<UsageCount Value="56"/>
<Loaded Value="True"/>
</Unit24> </Unit24>
<Unit25> <Unit25>
<Filename Value="..\utils\uvkuCommandPoolFactory.pas"/> <Filename Value="..\utils\uvkuCommandPoolFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="46" Y="42"/>
<UsageCount Value="50"/>
<EditorIndex Value="9"/>
<TopLine Value="23"/>
<CursorPos X="3" Y="34"/>
<UsageCount Value="55"/>
<Loaded Value="True"/>
</Unit25> </Unit25>
<Unit26> <Unit26>
<Filename Value="..\utils\uvkuCommandBuffer.pas"/> <Filename Value="..\utils\uvkuCommandBuffer.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="39" Y="13"/>
<UsageCount Value="50"/>
<EditorIndex Value="7"/>
<TopLine Value="45"/>
<CursorPos X="91" Y="71"/>
<UsageCount Value="55"/>
<Loaded Value="True"/>
</Unit26> </Unit26>
<Unit27> <Unit27>
<Filename Value="..\utils\uvkuQueue.pas"/> <Filename Value="..\utils\uvkuQueue.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="7"/>
<CursorPos X="22" Y="23"/>
<UsageCount Value="50"/>
<TopLine Value="5"/>
<CursorPos Y="12"/>
<UsageCount Value="55"/>
</Unit27> </Unit27>
<Unit28> <Unit28>
<Filename Value="..\utils\VulkanUtils.pas"/> <Filename Value="..\utils\VulkanUtils.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="32"/>
<CursorPos X="3" Y="48"/>
<UsageCount Value="49"/>
<EditorIndex Value="5"/>
<TopLine Value="50"/>
<CursorPos X="3" Y="66"/>
<UsageCount Value="54"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit28> </Unit28>
<Unit29> <Unit29>
@@ -253,30 +256,29 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="14"/> <TopLine Value="14"/>
<UsageCount Value="66"/>
<UsageCount Value="71"/>
</Unit29> </Unit29>
<Unit30> <Unit30>
<Filename Value="..\utils\uvkuRenderPass.pas"/> <Filename Value="..\utils\uvkuRenderPass.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="3" Y="13"/> <CursorPos X="3" Y="13"/>
<UsageCount Value="47"/>
<UsageCount Value="52"/>
</Unit30> </Unit30>
<Unit31> <Unit31>
<Filename Value="..\utils\uvkuRenderPassFactory.pas"/> <Filename Value="..\utils\uvkuRenderPassFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="82" Y="11"/> <CursorPos X="82" Y="11"/>
<UsageCount Value="47"/>
<UsageCount Value="52"/>
</Unit31> </Unit31>
<Unit32> <Unit32>
<Filename Value="..\utils\uvkuFactoryBase.pas"/> <Filename Value="..\utils\uvkuFactoryBase.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="3"/>
<EditorIndex Value="-1"/>
<TopLine Value="69"/> <TopLine Value="69"/>
<CursorPos X="12" Y="82"/> <CursorPos X="12" Y="82"/>
<UsageCount Value="47"/>
<Loaded Value="True"/>
<UsageCount Value="52"/>
</Unit32> </Unit32>
<Unit33> <Unit33>
<Filename Value="..\utils\uvkuFrameBuffer.pas"/> <Filename Value="..\utils\uvkuFrameBuffer.pas"/>
@@ -284,7 +286,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="33"/> <TopLine Value="33"/>
<CursorPos X="150" Y="40"/> <CursorPos X="150" Y="40"/>
<UsageCount Value="45"/>
<UsageCount Value="50"/>
</Unit33> </Unit33>
<Unit34> <Unit34>
<Filename Value="..\utils\uvkuFrameBufferFactory.pas"/> <Filename Value="..\utils\uvkuFrameBufferFactory.pas"/>
@@ -292,14 +294,14 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="12"/> <TopLine Value="12"/>
<CursorPos X="25" Y="27"/> <CursorPos X="25" Y="27"/>
<UsageCount Value="45"/>
<UsageCount Value="50"/>
</Unit34> </Unit34>
<Unit35> <Unit35>
<Filename Value="..\utils\uvkuDescriptorSetLayout.pas"/> <Filename Value="..\utils\uvkuDescriptorSetLayout.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="150" Y="12"/> <CursorPos X="150" Y="12"/>
<UsageCount Value="45"/>
<UsageCount Value="50"/>
</Unit35> </Unit35>
<Unit36> <Unit36>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/> <Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
@@ -307,7 +309,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="89"/> <TopLine Value="89"/>
<CursorPos X="3" Y="106"/> <CursorPos X="3" Y="106"/>
<UsageCount Value="44"/>
<UsageCount Value="49"/>
</Unit36> </Unit36>
<Unit37> <Unit37>
<Filename Value="..\utils\uvkuPipelineLayout.pas"/> <Filename Value="..\utils\uvkuPipelineLayout.pas"/>
@@ -315,7 +317,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="48"/> <TopLine Value="48"/>
<CursorPos X="150" Y="53"/> <CursorPos X="150" Y="53"/>
<UsageCount Value="44"/>
<UsageCount Value="49"/>
</Unit37> </Unit37>
<Unit38> <Unit38>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/> <Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
@@ -323,7 +325,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="10"/> <TopLine Value="10"/>
<CursorPos X="37" Y="112"/> <CursorPos X="37" Y="112"/>
<UsageCount Value="44"/>
<UsageCount Value="49"/>
</Unit38> </Unit38>
<Unit39> <Unit39>
<Filename Value="..\utils\uvkuShaderModule.pas"/> <Filename Value="..\utils\uvkuShaderModule.pas"/>
@@ -331,7 +333,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="54"/> <TopLine Value="54"/>
<CursorPos X="3" Y="67"/> <CursorPos X="3" Y="67"/>
<UsageCount Value="42"/>
<UsageCount Value="47"/>
</Unit39> </Unit39>
<Unit40> <Unit40>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/> <Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
@@ -339,15 +341,15 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="117"/> <TopLine Value="117"/>
<CursorPos X="37" Y="127"/> <CursorPos X="37" Y="127"/>
<UsageCount Value="42"/>
<UsageCount Value="47"/>
</Unit40> </Unit40>
<Unit41> <Unit41>
<Filename Value="..\utils\uvkuPipeline.pas"/> <Filename Value="..\utils\uvkuPipeline.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="79"/>
<CursorPos X="17" Y="91"/>
<UsageCount Value="40"/>
<TopLine Value="7"/>
<CursorPos X="23" Y="92"/>
<UsageCount Value="45"/>
</Unit41> </Unit41>
<Unit42> <Unit42>
<Filename Value="..\utils\uvkuPipelineFactory.pas"/> <Filename Value="..\utils\uvkuPipelineFactory.pas"/>
@@ -355,7 +357,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="7"/> <TopLine Value="7"/>
<CursorPos X="3" Y="23"/> <CursorPos X="3" Y="23"/>
<UsageCount Value="39"/>
<UsageCount Value="44"/>
</Unit42> </Unit42>
<Unit43> <Unit43>
<Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/> <Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/>
@@ -412,8 +414,7 @@
<Unit50> <Unit50>
<Filename Value="..\Vulkan.inc"/> <Filename Value="..\Vulkan.inc"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="9" Y="5"/>
<UsageCount Value="7"/>
<UsageCount Value="10"/>
</Unit50> </Unit50>
<Unit51> <Unit51>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\forms.pp"/> <Filename Value="C:\Zusatzprogramme\Lazarus\lcl\forms.pp"/>
@@ -500,126 +501,136 @@
<CursorPos Y="2163"/> <CursorPos Y="2163"/>
<UsageCount Value="10"/> <UsageCount Value="10"/>
</Unit62> </Unit62>
<Unit63>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="102"/>
<CursorPos Y="119"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit63>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29">
<JumpHistory Count="30" HistoryIndex="25">
<Position1> <Position1>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="47" Column="97" TopLine="32"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="122" Column="83" TopLine="107"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="260" Column="23" TopLine="241"/>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<Caret Line="109" TopLine="90"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="257" Column="83" TopLine="241"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="512" Column="22" TopLine="486"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="245" Column="60" TopLine="229"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="33" Column="5" TopLine="16"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="257" Column="83" TopLine="241"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="47" Column="3" TopLine="31"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="4540" Column="93" TopLine="4525"/>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<Caret Line="117" TopLine="102"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="..\Vulkan.pas"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="512" TopLine="486"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="257" Column="83" TopLine="241"/>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<Caret Line="117" TopLine="102"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="uMainForm.pas"/>
<Caret Line="106" Column="10" TopLine="88"/>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<Caret Line="118" Column="83" TopLine="102"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="uMainForm.pas"/> <Filename Value="uMainForm.pas"/>
<Caret Line="13" Column="3"/>
<Caret Line="512" TopLine="486"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="44" Column="3" TopLine="28"/>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<Caret Line="117" TopLine="102"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="uMainForm.pas"/>
<Caret Line="117" Column="21" TopLine="104"/>
<Filename Value="..\utils\uvkuDebugReporter.pas"/>
<Caret Line="118" TopLine="102"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="48" Column="3" TopLine="32"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="253" Column="27" TopLine="242"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<Caret Line="163" Column="27" TopLine="144"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="94" Column="3" TopLine="77"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<Caret Line="29" Column="3" TopLine="13"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="82" Column="3" TopLine="66"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="74" TopLine="66"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="261" TopLine="248"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="82" TopLine="66"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="49" Column="5" TopLine="34"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="uMainForm.pas"/>
<Caret Line="111" TopLine="104"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="83" Column="3" TopLine="67"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="82" TopLine="66"/>
<Filename Value="..\utils\uvkuCommandBuffer.pas"/>
<Caret Line="23" Column="28" TopLine="4"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="66" TopLine="50"/>
<Filename Value="..\utils\uvkuCommandBuffer.pas"/>
<Caret Line="43" Column="22" TopLine="23"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="68" TopLine="50"/>
<Filename Value="..\utils\uvkuCommandBuffer.pas"/>
<Caret Line="45" Column="28" TopLine="23"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="69" TopLine="50"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="304" Column="42" TopLine="292"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="83" TopLine="67"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="259" Column="16" TopLine="244"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="77" Column="26" TopLine="69"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="261" Column="33" TopLine="245"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="83" TopLine="69"/>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="2887" Column="86" TopLine="2871"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="84" TopLine="69"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="315" Column="60" TopLine="300"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="85" TopLine="69"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="95" Column="3" TopLine="78"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="86" TopLine="69"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="66" Column="3" TopLine="50"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="87" TopLine="69"/>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Caret Line="13" Column="3"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<Caret Line="88" TopLine="69"/>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<Caret Line="23" Column="38"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectSession> </ProjectSession>


+ 151
- 43
projects/triangle/uMainForm.pas Просмотреть файл

@@ -23,7 +23,14 @@ type
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
private private
fGraphicsQueueFamilyIndex: VkUint32;
fGraphicsQueueNodeIndex: VkUint32;
fPresentQueueNodeIndex: VkUint32;
fSurfaceFormat: TVkFormat;
fSurfaceColorSpace: TVkColorSpaceKHR;

fAllocHandler: TCustomAllocHandler; fAllocHandler: TCustomAllocHandler;
fDebugReporter: TvkuConsoleDebugReporter;
fInstance: TvkuInstance; fInstance: TvkuInstance;
fPhyDevice: TvkuPhysicalDevice; fPhyDevice: TvkuPhysicalDevice;
fDevice: TvkuDevice; fDevice: TvkuDevice;
@@ -38,6 +45,8 @@ type
fVertexShader: TvkuShaderModule; fVertexShader: TvkuShaderModule;
fFragmentShader: TvkuShaderModule; fFragmentShader: TvkuShaderModule;
fPipeline: TvkuGraphicsPipeline; fPipeline: TvkuGraphicsPipeline;
fCommandPool: TvkuCommandPool;
fCommandBuffer: TvkuCommandBuffer;
end; end;


var var
@@ -54,7 +63,7 @@ implementation
function TCustomAllocHandler.AllocateMemory(const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid; function TCustomAllocHandler.AllocateMemory(const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid;
begin begin
result := inherited AllocateMemory(aSize, aAlignment, aScope); result := inherited AllocateMemory(aSize, aAlignment, aScope);
WriteLn(Format(' %d bytes of memory allocated at %p', [ aSize, result ]));
WriteLn(Format(' MEM - %d bytes of memory allocated at %p', [ aSize, result ]));
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -63,13 +72,13 @@ var p: PVkVoid;
begin begin
p := aOriginal; p := aOriginal;
result := inherited ReallocateMemory(aOriginal, aSize, aAlignment, aScope); result := inherited ReallocateMemory(aOriginal, aSize, aAlignment, aScope);
WriteLn(Format(' %d bytes of memory (from %p) reallocated at %p', [ aSize, p, result ]));
WriteLn(Format(' MEM - %d bytes of memory (from %p) reallocated at %p', [ aSize, p, result ]));
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TCustomAllocHandler.FreeMemory(const aMemory: PVkVoid); procedure TCustomAllocHandler.FreeMemory(const aMemory: PVkVoid);
begin begin
WriteLn(Format(' free memory at %p', [ aMemory ]));
WriteLn(Format(' MEM - free memory at %p', [ aMemory ]));
inherited FreeMemory(aMemory); inherited FreeMemory(aMemory);
end; end;


@@ -82,6 +91,7 @@ var
InstanceFactory: TvkuInstanceFactory; InstanceFactory: TvkuInstanceFactory;
DeviceFactory: TvkuDeviceFactory; DeviceFactory: TvkuDeviceFactory;
SurfaceFactory: TvkuSurfaceFactory; SurfaceFactory: TvkuSurfaceFactory;
CommandPoolFactory: TvkuCommandPoolFactory;
SwapChainFactory: TvkuSwapChainFactory; SwapChainFactory: TvkuSwapChainFactory;
ImageViewFactory: TvkuImageViewFactory; ImageViewFactory: TvkuImageViewFactory;
RenderPassFactory: TvkuRenderPassFactory; RenderPassFactory: TvkuRenderPassFactory;
@@ -91,9 +101,9 @@ var
ShaderModuleFactory: TvkuShaderModuleFactory; ShaderModuleFactory: TvkuShaderModuleFactory;
PipelineFactory: TvkuGraphicsPipelineFactory; PipelineFactory: TvkuGraphicsPipelineFactory;


QueueFamProps: TVkQueueFamilyPropertiesArr;
DepthFormat: TVkFormat; DepthFormat: TVkFormat;
f: TVkFormat; f: TVkFormat;
SurcafeFormat: TVkSurfaceFormatKHR;
i: Integer; i: Integer;
SrfFormats: TVkSurfaceFormatArr; SrfFormats: TVkSurfaceFormatArr;
SurfaceCapabilities: TVkSurfaceCapabilitiesKHR; SurfaceCapabilities: TVkSurfaceCapabilitiesKHR;
@@ -105,23 +115,44 @@ begin
fAllocHandler := TCustomAllocHandler.Create; fAllocHandler := TCustomAllocHandler.Create;


////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
WriteLn('create instance');
WriteLn('create instance: ');
InstanceFactory := TvkuInstanceFactory.Create; InstanceFactory := TvkuInstanceFactory.Create;
try try
InstanceFactory.AllocHandler := fAllocHandler; InstanceFactory.AllocHandler := fAllocHandler;
InstanceFactory.EnabledExtensionNames.Add(VK_KHR_SURFACE_EXTENSION_NAME); InstanceFactory.EnabledExtensionNames.Add(VK_KHR_SURFACE_EXTENSION_NAME);
InstanceFactory.EnabledExtensionNames.Add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
InstanceFactory.EnabledExtensionNames.Add(TvkuSurface.GetPlatformSurfaceExtensionName); InstanceFactory.EnabledExtensionNames.Add(TvkuSurface.GetPlatformSurfaceExtensionName);
fInstance := InstanceFactory.CreateInstance; fInstance := InstanceFactory.CreateInstance;
WriteLn(' handle: ', PtrUInt(fInstance.Handle));
WriteLn(' done');
finally finally
FreeAndNil(InstanceFactory); FreeAndNil(InstanceFactory);
end; end;


fDebugReporter := TvkuConsoleDebugReporter.Create(fInstance.InstanceCommands, fAllocHandler);

////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
WriteLn('find suitable physical device'); WriteLn('find suitable physical device');
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 TvkuException.Create('unable to get physical device');
fPhyDevice := TvkuPhysicalDevice.Create(PhyDevices[0], fInstance.InstanceCommands); fPhyDevice := TvkuPhysicalDevice.Create(PhyDevices[0], fInstance.InstanceCommands);
WriteLn(' handle: ', PtrUInt(fPhyDevice.Handle));

Write(' find suitable graphics queue index... ');
QueueFamProps := fPhyDevice.GetQueueFamilyProperties;
fGraphicsQueueFamilyIndex := high(fGraphicsQueueFamilyIndex);
for i := low(QueueFamProps) to high(QueueFamProps) do begin
if (VK_QUEUE_GRAPHICS_BIT in QueueFamProps[i].queueFlags) then begin
fGraphicsQueueFamilyIndex := i;
WriteLn(fGraphicsQueueFamilyIndex);
break;
end;
end;
if (fGraphicsQueueFamilyIndex = high(fGraphicsQueueFamilyIndex)) then
raise TvkuException.Create('unable to find graphics queue index');

Write(' find suitable depth format... ');
f := VK_FORMAT_UNDEFINED; f := VK_FORMAT_UNDEFINED;
for f in [ VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D16_UNORM ] do begin for f in [ VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D16_UNORM ] do begin
if (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT in fPhyDevice.GetFormatProperties(f).optimalTilingFeatures) then begin if (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT in fPhyDevice.GetFormatProperties(f).optimalTilingFeatures) then begin
@@ -129,39 +160,111 @@ begin
break; break;
end; end;
end; end;
WriteLn(DepthFormat);
WriteLn(' done');


////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
WriteLn('create device'); WriteLn('create device');
DeviceFactory := TvkuDeviceFactory.Create(fInstance); DeviceFactory := TvkuDeviceFactory.Create(fInstance);
try try
DeviceFactory.AllocHandler := fAllocHandler; DeviceFactory.AllocHandler := fAllocHandler;
DeviceFactory.EnabledExtensions.Add('VK_KHR_swapchain');
DeviceFactory.QueueCreateInfos.Length := 1; DeviceFactory.QueueCreateInfos.Length := 1;
with DeviceFactory.QueueCreateInfos[0] do begin with DeviceFactory.QueueCreateInfos[0] do begin
Flags := 0; Flags := 0;
QueueFamilyIndex := 0;
QueueFamilyIndex := fGraphicsQueueFamilyIndex;
QueuePriorities.Length := 1; QueuePriorities.Length := 1;
QueuePriorities[0] := 1.0; QueuePriorities[0] := 1.0;
end; end;
fDevice := DeviceFactory.CreateDevice(fPhyDevice.Handle); fDevice := DeviceFactory.CreateDevice(fPhyDevice.Handle);
WriteLn(' handle: ', PtrUInt(fDevice.Handle));
WriteLn(' done');
finally finally
FreeAndNil(DeviceFactory); FreeAndNil(DeviceFactory);
end; end;


////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
WriteLn('find suitable queue'); WriteLn('find suitable queue');
fQueue := TvkuQueue.Create(fDevice.GetQueue(0, 0), fDevice.DeviceCommands);
fQueue := TvkuQueue.Create(fDevice.GetQueue(fGraphicsQueueFamilyIndex, 0), fDevice.DeviceCommands);
WriteLn(' handle: ', PtrUInt(fQueue.Handle));
WriteLn(' done');


////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
WriteLn('create surface');
WriteLn('create surface: ');
SurfaceFactory := TvkuSurfaceFactory.Create(fInstance); SurfaceFactory := TvkuSurfaceFactory.Create(fInstance);
try try
SurfaceFactory.AllocHandler := fAllocHandler; SurfaceFactory.AllocHandler := fAllocHandler;
SurfaceFactory.WinControl := RenderPanel; SurfaceFactory.WinControl := RenderPanel;
fSurface := SurfaceFactory.CreateSurface; fSurface := SurfaceFactory.CreateSurface;
WriteLn(' handle: ', PtrUInt(fSurface.Handle));

WriteLn(' find suitable graphics and present queue node index');
fGraphicsQueueNodeIndex := high(fGraphicsQueueNodeIndex);
fPresentQueueNodeIndex := high(fPresentQueueNodeIndex);
QueueFamProps := fPhyDevice.GetQueueFamilyProperties;
for i := low(QueueFamProps) to high(QueueFamProps) do begin
if (VK_QUEUE_GRAPHICS_BIT in QueueFamProps[i].queueFlags) then
fGraphicsQueueNodeIndex := i;

if fPhyDevice.GetSurfaceSupport(i, fSurface.Handle) then begin
fGraphicsQueueNodeIndex := i;
fPresentQueueNodeIndex := i;
break;
end;
end;
if (fPresentQueueNodeIndex = high(fPresentQueueNodeIndex)) then begin
for i := low(QueueFamProps) to high(QueueFamProps) do begin
if fPhyDevice.GetSurfaceSupport(i, fSurface.Handle) then begin
fPresentQueueNodeIndex := i;
break;
end;
end;
end;
WriteLn(' graphics queue node index: ', fGraphicsQueueNodeIndex);
WriteLn(' present queue node index: ', fPresentQueueNodeIndex);
if (fGraphicsQueueNodeIndex = high(fGraphicsQueueNodeIndex)) or
(fPresentQueueNodeIndex = high(fPresentQueueNodeIndex)) or
(fPresentQueueNodeIndex <> fGraphicsQueueNodeIndex) then
raise TvkuException.Create('different graphic and present queue node index is not supported yet');

WriteLn(' find suitable image format');
SrfFormats := fPhyDevice.GetSurfaceFormats(fSurface.Handle);
if (Length(SrfFormats) = 0) then
raise TvkuException.Create('no suitable formats found');
if (Length(SrfFormats) = 1) and (SrfFormats[0].format = VK_FORMAT_UNDEFINED) then begin
fSurfaceFormat := VK_FORMAT_R8G8B8A8_UNORM;
fSurfaceColorSpace := VK_COLORSPACE_SRGB_NONLINEAR_KHR;
end else begin
fSurfaceFormat := SrfFormats[0].format;
fSurfaceColorSpace := SrfFormats[0].colorSpace;
end;
WriteLn(' format: ', fSurfaceFormat);
WriteLn(' color space: ', fSurfaceColorSpace);

WriteLn(' done');
finally finally
FreeAndNil(SurfaceFactory); FreeAndNil(SurfaceFactory);
end; end;


//////////////////////////////////////////////////////////////////////////////
WriteLn('create command pool');
CommandPoolFactory := TvkuCommandPoolFactory.Create(fDevice);
try
CommandPoolFactory.Flags := [ VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT ];
CommandPoolFactory.QueueFamilyIndex := fGraphicsQueueNodeIndex;
fCommandPool := CommandPoolFactory.CreateCommandPool;
WriteLn(' handle: ', PtrUInt(fCommandPool.Handle));

WriteLn(' alloc command buffer');
fCommandBuffer := TvkuCommandBuffer.Create(
fCommandPool.CreateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY),
true, fCommandPool.Handle, fDevice.DeviceCommands);
WriteLn(' handle: ', PtrUInt(fCommandBuffer.Handle));
WriteLn(' done');
finally
FreeAndNil(CommandPoolFactory);
end;

////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
WriteLn('create swap chain'); WriteLn('create swap chain');
SwapChainFactory := TvkuSwapChainFactory.Create(fDevice); SwapChainFactory := TvkuSwapChainFactory.Create(fDevice);
@@ -173,6 +276,8 @@ begin
SwapChainFactory.ImageSharingMode := VK_SHARING_MODE_EXCLUSIVE; SwapChainFactory.ImageSharingMode := VK_SHARING_MODE_EXCLUSIVE;
SwapChainFactory.Clipped := true; SwapChainFactory.Clipped := true;
SwapChainFactory.ComposideAlpha := [ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR ]; SwapChainFactory.ComposideAlpha := [ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR ];
SwapChainFactory.ImageFormat := fSurfaceFormat;
SwapChainFactory.ImageColorSpace := fSurfaceColorSpace;


WriteLn(' get surface capabilities'); WriteLn(' get surface capabilities');
SurfaceCapabilities := fPhyDevice.GetSurfaceCapabilities(fSurface.Handle); SurfaceCapabilities := fPhyDevice.GetSurfaceCapabilities(fSurface.Handle);
@@ -183,50 +288,37 @@ begin
ClientWidth := SurfaceCapabilities.currentExtent.width; ClientWidth := SurfaceCapabilities.currentExtent.width;
ClientHeight := SurfaceCapabilities.currentExtent.height; ClientHeight := SurfaceCapabilities.currentExtent.height;
end; end;
WriteLn(' width: ', SurfaceCapabilities.currentExtent.width);
WriteLn(' height: ', SurfaceCapabilities.currentExtent.height);
SwapChainFactory.ImageExtent := SurfaceCapabilities.currentExtent; SwapChainFactory.ImageExtent := SurfaceCapabilities.currentExtent;


WriteLn(' set min image count');
Write(' set min image count... ');
SwapChainFactory.MinImageCount := SurfaceCapabilities.minImageCount + 1; SwapChainFactory.MinImageCount := SurfaceCapabilities.minImageCount + 1;
if (SurfaceCapabilities.maxImageCount > 0) and if (SurfaceCapabilities.maxImageCount > 0) and
(SwapChainFactory.MinImageCount > SurfaceCapabilities.maxImageCount) then (SwapChainFactory.MinImageCount > SurfaceCapabilities.maxImageCount) then
SwapChainFactory.MinImageCount := SurfaceCapabilities.maxImageCount; SwapChainFactory.MinImageCount := SurfaceCapabilities.maxImageCount;
WriteLn(SwapChainFactory.MinImageCount);


WriteLn(' find suitable image format');
SrfFormats := fPhyDevice.GetSurfaceFormats(fSurface.Handle);
if (Length(SrfFormats) = 0) then begin
WriteLn('no suitable formats found');
halt;
end;
if (Length(SrfFormats) = 1) and (SrfFormats[0].format = VK_FORMAT_UNDEFINED) then begin
SurcafeFormat.format := VK_FORMAT_R8G8B8A8_UNORM;
SurcafeFormat.colorSpace := VK_COLORSPACE_SRGB_NONLINEAR_KHR;
end else begin
SurcafeFormat.format := SrfFormats[0].format;
SurcafeFormat.colorSpace := SrfFormats[0].colorSpace;
end;
SwapChainFactory.ImageFormat := SurcafeFormat.format;
SwapChainFactory.ImageColorSpace := SurcafeFormat.colorSpace;


WriteLn(' set pre transform');
WriteLn(' set pre transform...');
SwapChainFactory.PreTransform := SurfaceCapabilities.currentTransform; SwapChainFactory.PreTransform := SurfaceCapabilities.currentTransform;
if (VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR in SurfaceCapabilities.supportedTransforms) then if (VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR in SurfaceCapabilities.supportedTransforms) then
SwapChainFactory.PreTransform := SwapChainFactory.PreTransform + [ VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ];
SwapChainFactory.PreTransform := [ VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ];


WriteLn(' find suitable present mode');
Write(' find suitable present mode... ');
PresentModes := fPhyDevice.GetSurfacePresentModes(fSurface.Handle); PresentModes := fPhyDevice.GetSurfacePresentModes(fSurface.Handle);
if (Length(PresentModes) = 0) then begin
WriteLn('unable to get present modes');
halt;
end;
if (Length(PresentModes) = 0) then
raise TvkuException.Create('unable to get present modes');
for pm in PresentModes do begin for pm in PresentModes do begin
if (pm = VK_PRESENT_MODE_MAILBOX_KHR) then begin if (pm = VK_PRESENT_MODE_MAILBOX_KHR) then begin
SwapChainFactory.PresentMode := pm; SwapChainFactory.PresentMode := pm;
break; break;
end; end;
end; end;
WriteLn(SwapChainFactory.PresentMode);


fSwapChain := SwapChainFactory.CreateSwapchain; fSwapChain := SwapChainFactory.CreateSwapchain;
WriteLn(' handle: ', PtrUInt(fSwapChain.Handle));
WriteLn(' done');
finally finally
FreeAndNil(SwapChainFactory); FreeAndNil(SwapChainFactory);
end; end;
@@ -237,14 +329,8 @@ begin
SetLength(fImageViews, Length(Images)); SetLength(fImageViews, Length(Images));
ImageViewFactory := TvkuImageViewFactory.Create(fDevice); ImageViewFactory := TvkuImageViewFactory.Create(fDevice);
try try
ComponentMapping.r := VK_COMPONENT_SWIZZLE_R;
ComponentMapping.g := VK_COMPONENT_SWIZZLE_G;
ComponentMapping.b := VK_COMPONENT_SWIZZLE_B;
ComponentMapping.a := VK_COMPONENT_SWIZZLE_A;

ImageViewFactory.AllocHandler := fAllocHandler; ImageViewFactory.AllocHandler := fAllocHandler;
ImageViewFactory.Format := SurcafeFormat.format;
ImageViewFactory.Components := ComponentMapping;
ImageViewFactory.Format := fSurfaceFormat;
ImageViewFactory.ViewType := VK_IMAGE_VIEW_TYPE_2D; ImageViewFactory.ViewType := VK_IMAGE_VIEW_TYPE_2D;
with ImageViewFactory.SubresourceRange do begin with ImageViewFactory.SubresourceRange do begin
AspectMask := [ VK_IMAGE_ASPECT_COLOR_BIT ]; AspectMask := [ VK_IMAGE_ASPECT_COLOR_BIT ];
@@ -253,10 +339,19 @@ begin
BaseArrayLayer := 0; BaseArrayLayer := 0;
LayerCount := 1; LayerCount := 1;
end; end;
with ImageViewFactory.Components do begin
r := VK_COMPONENT_SWIZZLE_R;
g := VK_COMPONENT_SWIZZLE_G;
b := VK_COMPONENT_SWIZZLE_B;
a := VK_COMPONENT_SWIZZLE_A;
end;
for i := Low(fImageViews) to High(fImageViews) do begin for i := Low(fImageViews) to High(fImageViews) do begin
// TODO create image barrier
ImageViewFactory.Image := Images[i]; ImageViewFactory.Image := Images[i];
fImageViews[i] := ImageViewFactory.CreateImageView; fImageViews[i] := ImageViewFactory.CreateImageView;
WriteLn(' handle: ', PtrUInt(fImageViews[i].Handle));
end; end;
WriteLn(' done');
finally finally
FreeAndNil(ImageViewFactory); FreeAndNil(ImageViewFactory);
end; end;
@@ -267,7 +362,7 @@ begin
try try
RenderPassFactory.Attachments.Length := 2; RenderPassFactory.Attachments.Length := 2;
with RenderPassFactory.Attachments[0] do begin with RenderPassFactory.Attachments[0] do begin
Format := SurcafeFormat.format;
Format := fSurfaceFormat;
Samples := [ VK_SAMPLE_COUNT_1_BIT ]; Samples := [ VK_SAMPLE_COUNT_1_BIT ];
LoadOp := VK_ATTACHMENT_LOAD_OP_CLEAR; LoadOp := VK_ATTACHMENT_LOAD_OP_CLEAR;
StoreOp := VK_ATTACHMENT_STORE_OP_STORE; StoreOp := VK_ATTACHMENT_STORE_OP_STORE;
@@ -303,6 +398,9 @@ begin


RenderPassFactory.AllocHandler := fAllocHandler; RenderPassFactory.AllocHandler := fAllocHandler;
fRenderPass := RenderPassFactory.CreateRenderPass; fRenderPass := RenderPassFactory.CreateRenderPass;

WriteLn(' handle: ', PtrUInt(fRenderPass.Handle));
WriteLn(' done');
finally finally
FreeAndNil(RenderPassFactory); FreeAndNil(RenderPassFactory);
end; end;
@@ -323,7 +421,9 @@ begin
for i := low(fFrameBuffers) to high(fFrameBuffers) do begin for i := low(fFrameBuffers) to high(fFrameBuffers) do begin
FrameBufferFactory.Attachments[0] := fImageViews[i].Handle; FrameBufferFactory.Attachments[0] := fImageViews[i].Handle;
fFrameBuffers[i] := FrameBufferFactory.CreateFrameBuffer; fFrameBuffers[i] := FrameBufferFactory.CreateFrameBuffer;
WriteLn(' handle: ', PtrUInt(fFrameBuffers[i].Handle));
end; end;
WriteLn(' done');
finally finally
FreeAndNil(FrameBufferFactory); FreeAndNil(FrameBufferFactory);
end; end;
@@ -343,6 +443,8 @@ begin
DescSetLayoutFactory.AllocHandler := fAllocHandler; DescSetLayoutFactory.AllocHandler := fAllocHandler;


fDescSetLayout := DescSetLayoutFactory.CreateDescriptorSetLayout; fDescSetLayout := DescSetLayoutFactory.CreateDescriptorSetLayout;
WriteLn(' handle: ', PtrUInt(fDescSetLayout.Handle));
WriteLn(' done');
finally finally
FreeAndNil(DescSetLayoutFactory); FreeAndNil(DescSetLayoutFactory);
end; end;
@@ -355,6 +457,8 @@ begin
PipelineLayoutFactory.SetLayouts.Length := 1; PipelineLayoutFactory.SetLayouts.Length := 1;
PipelineLayoutFactory.SetLayouts[0] := fDescSetLayout.Handle; PipelineLayoutFactory.SetLayouts[0] := fDescSetLayout.Handle;
fPipelineLayout := PipelineLayoutFactory.CreatePipelineLayout; fPipelineLayout := PipelineLayoutFactory.CreatePipelineLayout;
WriteLn(' handle: ', PtrUInt(fPipelineLayout.Handle));
WriteLn(' done');
finally finally
FreeAndNil(PipelineLayoutFactory); FreeAndNil(PipelineLayoutFactory);
end; end;
@@ -367,9 +471,12 @@ begin


ShaderModuleFactory.LoadGlslCode(ExtractFilePath(Application.ExeName) + '../../data/shaders/triangle.vert', [ VK_SHADER_STAGE_VERTEX_BIT ]); ShaderModuleFactory.LoadGlslCode(ExtractFilePath(Application.ExeName) + '../../data/shaders/triangle.vert', [ VK_SHADER_STAGE_VERTEX_BIT ]);
fVertexShader := ShaderModuleFactory.CreateShaderModule; fVertexShader := ShaderModuleFactory.CreateShaderModule;
WriteLn(' vertex handle: ', PtrUInt(fVertexShader.Handle));


ShaderModuleFactory.LoadGlslCode(ExtractFilePath(Application.ExeName) + '../../data/shaders/triangle.frag', [ VK_SHADER_STAGE_FRAGMENT_BIT ]); ShaderModuleFactory.LoadGlslCode(ExtractFilePath(Application.ExeName) + '../../data/shaders/triangle.frag', [ VK_SHADER_STAGE_FRAGMENT_BIT ]);
fFragmentShader := ShaderModuleFactory.CreateShaderModule; fFragmentShader := ShaderModuleFactory.CreateShaderModule;
WriteLn(' fragment handle: ', PtrUInt(fFragmentShader.Handle));
WriteLn(' done');
finally finally
FreeAndNil(ShaderModuleFactory); FreeAndNil(ShaderModuleFactory);
end; end;
@@ -379,7 +486,7 @@ begin
PipelineFactory := TvkuGraphicsPipelineFactory.Create(fDevice); PipelineFactory := TvkuGraphicsPipelineFactory.Create(fDevice);
try try
PipelineFactory.AllocHandler := fAllocHandler; PipelineFactory.AllocHandler := fAllocHandler;
fPipeline := PipelineFactory.CreateGraphicsPipeline(VK_INVALID_NDP_HANDLE);
// TODO fPipeline := PipelineFactory.CreateGraphicsPipeline(VK_INVALID_NDP_HANDLE);
finally finally
FreeAndNil(PipelineFactory); FreeAndNil(PipelineFactory);
end; end;
@@ -418,6 +525,7 @@ begin
FreeAndNil(fQueue); FreeAndNil(fQueue);
FreeAndNil(fDevice); FreeAndNil(fDevice);
FreeAndNil(fPhyDevice); FreeAndNil(fPhyDevice);
FreeAndNil(fDebugReporter);
FreeAndNil(fInstance); FreeAndNil(fInstance);
FreeAndNil(fAllocHandler); FreeAndNil(fAllocHandler);
end; end;


+ 4
- 1
projects/utils/VulkanUtils.pas Просмотреть файл

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


uses uses
Classes, SysUtils, Classes, SysUtils,
uvkuTypes, uvkuAllocationHandler,
uvkuTypes, uvkuAllocationHandler, uvkuDebugReporter,
uvkuInstance, uvkuInstanceFactory, uvkuInstance, uvkuInstanceFactory,
uvkuPhysicalDevice, uvkuDevice, uvkuDeviceFactory, uvkuDeviceMemory, uvkuQueue, uvkuPhysicalDevice, uvkuDevice, uvkuDeviceFactory, uvkuDeviceMemory, uvkuQueue,
uvkuSurface, uvkuSurfaceFactory, uvkuSurface, uvkuSurfaceFactory,
@@ -43,6 +43,9 @@ type


TvkuAllocationHandler = uvkuAllocationHandler.TvkuAllocationHandler; TvkuAllocationHandler = uvkuAllocationHandler.TvkuAllocationHandler;


TvkuDebugReporter = uvkuDebugReporter.TvkuDebugReporter;
TvkuConsoleDebugReporter = uvkuDebugReporter.TvkuConsoleDebugReporter;

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


+ 25
- 6
projects/utils/uvkuAllocationHandler.pas Просмотреть файл

@@ -1,6 +1,7 @@
unit uvkuAllocationHandler; unit uvkuAllocationHandler;


{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{$I Vulkan.inc}


interface interface


@@ -25,32 +26,50 @@ type
implementation implementation


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AllocateMemoryCallback(aUserData: PVkVoid; aSize: VkSize; aAlignment: VkSize; aScope: TVkSystemAllocationScope): PVkVoid; stdcall;
function AllocateMemoryCallback(
aUserData: PVkVoid;
aSize: VkSize;
aAlignment: VkSize;
aScope: TVkSystemAllocationScope): PVkVoid; {$IFDEF VK_CDECL}cdecl{$ELSE}stdcall{$ENDIF};
begin begin
result := TvkuAllocationHandler(aUserData).AllocateMemory(aSize, aAlignment, aScope); result := TvkuAllocationHandler(aUserData).AllocateMemory(aSize, aAlignment, aScope);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ReallocateMemoryCallback(aUserData: PVkVoid; aOriginal: PVkVoid; aSize: VkSize;
aAlignment: VkSize; aScope: TVkSystemAllocationScope): PVkVoid; stdcall;
function ReallocateMemoryCallback(
aUserData: PVkVoid;
aOriginal: PVkVoid;
aSize: VkSize;
aAlignment: VkSize;
aScope: TVkSystemAllocationScope): PVkVoid; {$IFDEF VK_CDECL}cdecl{$ELSE}stdcall{$ENDIF};
begin begin
result := TvkuAllocationHandler(aUserData).ReallocateMemory(aOriginal, aSize, aAlignment, aScope); result := TvkuAllocationHandler(aUserData).ReallocateMemory(aOriginal, aSize, aAlignment, aScope);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure FreeMemoryCallback(aUserData: PVkVoid; aMemory: PVkVoid); stdcall;
procedure FreeMemoryCallback(
aUserData: PVkVoid;
aMemory: PVkVoid); {$IFDEF VK_CDECL}cdecl{$ELSE}stdcall{$ENDIF};
begin begin
TvkuAllocationHandler(aUserData).FreeMemory(aMemory); TvkuAllocationHandler(aUserData).FreeMemory(aMemory);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure InternalAllocationCallback(aUserData: PVkVoid; aSize: VkSize; aType: TVkInternalAllocationType; aScope: TVkSystemAllocationScope); stdcall;
procedure InternalAllocationCallback(
aUserData: PVkVoid;
aSize: VkSize;
aType: TVkInternalAllocationType;
aScope: TVkSystemAllocationScope); {$IFDEF VK_CDECL}cdecl{$ELSE}stdcall{$ENDIF};
begin begin
TvkuAllocationHandler(aUserData).InternalAllocationNotification(aSize, aType, aScope); TvkuAllocationHandler(aUserData).InternalAllocationNotification(aSize, aType, aScope);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure InternalFreeCallback(aUserData: PVkVoid; aSize: VkSize; aType: TVkInternalAllocationType; aScope: TVkSystemAllocationScope); stdcall;
procedure InternalFreeCallback(
aUserData: PVkVoid;
aSize: VkSize;
aType: TVkInternalAllocationType;
aScope: TVkSystemAllocationScope); {$IFDEF VK_CDECL}cdecl{$ELSE}stdcall{$ENDIF};
begin begin
TvkuAllocationHandler(aUserData).InternalFreeNotification(aSize, aType, aScope); TvkuAllocationHandler(aUserData).InternalFreeNotification(aSize, aType, aScope);
end; end;


+ 21
- 0
projects/utils/uvkuCommandBuffer.pas Просмотреть файл

@@ -20,6 +20,8 @@ type
property CommandPool: VkCommandPool read fCommandPool; property CommandPool: VkCommandPool read fCommandPool;
property DeviceCommands: TVkDeviceCommands read fDeviceCommands; property DeviceCommands: TVkDeviceCommands read fDeviceCommands;


procedure BeginCommand;

constructor Create( constructor Create(
const aHandle: VkCommandBuffer; const aHandle: VkCommandBuffer;
const aOwnsHandle: Boolean; const aOwnsHandle: Boolean;
@@ -30,8 +32,27 @@ type


implementation implementation


uses
uvkuUtils;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuCommandBuffer////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuCommandBuffer//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuCommandBuffer.BeginCommand;
var
Info: TVkCommandBufferBeginInfo;
err: TVkResult;
begin
FillByte(Info, SizeOf(Info), 0);
Info.sType := VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Info.pNext := nil;
Info.flags := []; // TODO
Info.pInheritanceInfo := nil; // TODO
err := DeviceCommands.vkBeginCommandBuffer(fHandle, @Info);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to begin command buffer', err);
end;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuCommandBuffer.Create(const aHandle: VkCommandBuffer; const aOwnsHandle: Boolean; constructor TvkuCommandBuffer.Create(const aHandle: VkCommandBuffer; const aOwnsHandle: Boolean;
const aCommandPool: VkCommandPool; const aDeviceCommands: TVkDeviceCommands); const aCommandPool: VkCommandPool; const aDeviceCommands: TVkDeviceCommands);


+ 3
- 0
projects/utils/uvkuCommandPoolFactory.pas Просмотреть файл

@@ -15,6 +15,9 @@ type
fFlags: VkCommandPoolCreateFlags; fFlags: VkCommandPoolCreateFlags;
fQueueFamilyIndex: VkUint32; fQueueFamilyIndex: VkUint32;
public public
property Flags: VkCommandPoolCreateFlags read fFlags write fFlags;
property QueueFamilyIndex: VkUint32 read fQueueFamilyIndex write fQueueFamilyIndex;

function GetStructure: TVkCommandPoolCreateInfo; function GetStructure: TVkCommandPoolCreateInfo;
procedure SetStructure(const aData: TVkCommandPoolCreateInfo); procedure SetStructure(const aData: TVkCommandPoolCreateInfo);




+ 134
- 0
projects/utils/uvkuDebugReporter.pas Просмотреть файл

@@ -0,0 +1,134 @@
unit uvkuDebugReporter;

{$mode objfpc}{$H+}
{$I Vulkan.inc}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase, uvkuAllocationHandler;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuDebugReporter = class(TvkuAllocHandle)
private
fHandle: VkDebugReportCallbackEXT;
fInstanceCommands: TVkInstanceCommands;
protected
function DebugMessage(
aFlags: VkDebugReportFlagsEXT;
aObjectType: TVkDebugReportObjectTypeEXT;
aObject: VkUint64;
aLocation: VkSize;
aMessageCode: VkInt32;
aLayerPrefix: String;
aMessage: String): Boolean; virtual;
public
property Handle: VkDebugReportCallbackEXT read fHandle;

constructor Create(
const aInstanceCommands: TVkInstanceCommands;
const aAllocHandler: TvkuAllocationHandler = nil);
destructor Destroy; override;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuConsoleDebugReporter = class(TvkuDebugReporter)
protected
function DebugMessage(aFlags: VkDebugReportFlagsEXT; aObjectType: TVkDebugReportObjectTypeEXT; aObject: VkUint64;
aLocation: VkSize; aMessageCode: VkInt32; aLayerPrefix: String; aMessage: String): Boolean; override;
end;

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function DebugReportCallback(
flags: VkDebugReportFlagsEXT;
objectType: TVkDebugReportObjectTypeEXT;
uObject: VkUint64;
location: VkSize;
messageCode: VkInt32;
pLayerPrefix: PVkChar;
pMessage: PVkChar;
pUserData: PVkVoid): VkBool32; {$IFDEF VK_CDECL}cdecl{$ELSE}stdcall{$ENDIF};
var ret: Boolean;
begin
ret := TvkuDebugReporter(pUserData).DebugMessage(
flags,
objectType,
uObject,
location,
messageCode,
String(pLayerPrefix),
String(pMessage));
if ret
then result := VK_TRUE
else result := VK_FALSE;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuDebugReporter//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuDebugReporter.DebugMessage(aFlags: VkDebugReportFlagsEXT; aObjectType: TVkDebugReportObjectTypeEXT;
aObject: VkUint64; aLocation: VkSize; aMessageCode: VkInt32; aLayerPrefix: String; aMessage: String): Boolean;
begin
result := true;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDebugReporter.Create(
const aInstanceCommands: TVkInstanceCommands;
const aAllocHandler: TvkuAllocationHandler);
var
CreateInfo: TVkDebugReportCallbackCreateInfoEXT;
err: TVkResult;
begin
inherited Create;
if Assigned(aAllocHandler) then
SetAllocCallbacks(aAllocHandler.MakeStructure);
fInstanceCommands := aInstanceCommands;

FillByte(CreateInfo, SizeOf(CreateInfo), 0);
CreateInfo.sType := VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
CreateInfo.pNext := nil;
CreateInfo.pfnCallback := @DebugReportCallback;
CreateInfo.pUserData := self;
CreateInfo.flags := [
VK_DEBUG_REPORT_INFORMATION_BIT_EXT,
VK_DEBUG_REPORT_WARNING_BIT_EXT,
VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
VK_DEBUG_REPORT_ERROR_BIT_EXT,
VK_DEBUG_REPORT_DEBUG_BIT_EXT
];
err := fInstanceCommands.vkCreateDebugReportCallbackEXT(fInstanceCommands.Instance, @CreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create debug report handle', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuDebugReporter.Destroy;
begin
if (fHandle <> VK_INVALID_NDP_HANDLE) then
fInstanceCommands.vkDestroyDebugReportCallbackEXT(fInstanceCommands.Instance, fHandle, AllocCallbacks);
fHandle := VK_INVALID_NDP_HANDLE;
inherited Destroy;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuConsoleDebugReporter///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuConsoleDebugReporter.DebugMessage(
aFlags: VkDebugReportFlagsEXT; aObjectType: TVkDebugReportObjectTypeEXT;
aObject: VkUint64; aLocation: VkSize; aMessageCode: VkInt32; aLayerPrefix: String; aMessage: String): Boolean;
begin
WriteLn(Format(' DBG - [%03d] %10s: %s', [ Integer(aFlags), aLayerPrefix, aMessage ]));
end;

end.


Загрузка…
Отмена
Сохранить