Pārlūkot izejas kodu

* implemented shader modules

master
Bergmann89 pirms 10 gadiem
vecāks
revīzija
c081170ee2
12 mainītis faili ar 761 papildinājumiem un 297 dzēšanām
  1. +13
    -0
      data/shaders/triangle.frag
  2. Binārs
     
  3. +22
    -0
      data/shaders/triangle.vert
  4. Binārs
     
  5. +9
    -1
      projects/triangle/triangle.lpi
  6. +2
    -1
      projects/triangle/triangle.lpr
  7. +249
    -228
      projects/triangle/triangle.lps
  8. +235
    -55
      projects/triangle/uMainForm.pas
  9. +12
    -0
      projects/utils/VulkanUtils.pas
  10. +11
    -12
      projects/utils/uvkuFrameBufferFactory.pas
  11. +84
    -0
      projects/utils/uvkuShaderModule.pas
  12. +124
    -0
      projects/utils/uvkuShaderModuleFactory.pas

+ 13
- 0
data/shaders/triangle.frag Parādīt failu

@@ -0,0 +1,13 @@
#version 450

#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable

layout (location = 0) in vec3 inColor;

layout (location = 0) out vec4 outFragColor;

void main()
{
outFragColor = vec4(inColor, 1.0);
}

Binārs
Parādīt failu


+ 22
- 0
data/shaders/triangle.vert Parādīt failu

@@ -0,0 +1,22 @@
#version 450

#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable

layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inColor;

layout (binding = 0) uniform UBO
{
mat4 projectionMatrix;
mat4 modelMatrix;
mat4 viewMatrix;
} ubo;

layout (location = 0) out vec3 outColor;

void main()
{
outColor = inColor;
gl_Position = ubo.projectionMatrix * ubo.viewMatrix * ubo.modelMatrix * vec4(inPos.xyz, 1.0);
}

Binārs
Parādīt failu


+ 9
- 1
projects/triangle/triangle.lpi Parādīt failu

@@ -33,7 +33,7 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item1> </Item1>
</RequiredPackages> </RequiredPackages>
<Units Count="39">
<Units Count="41">
<Unit0> <Unit0>
<Filename Value="triangle.lpr"/> <Filename Value="triangle.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@@ -193,6 +193,14 @@
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/> <Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit38> </Unit38>
<Unit39>
<Filename Value="..\utils\uvkuShaderModule.pas"/>
<IsPartOfProject Value="True"/>
</Unit39>
<Unit40>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit40>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>


+ 2
- 1
projects/triangle/triangle.lpr Parādīt failu

@@ -7,7 +7,8 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads} {$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$ENDIF}{$ENDIF}
Interfaces, Dialogs, Forms, uMainForm, Vulkan, uvkuPipelineLayout, uvkuPipelineLayoutFactory;
Interfaces, Dialogs, Forms, uMainForm, Vulkan, uvkuPipelineLayout, uvkuPipelineLayoutFactory, uvkuShaderModule,
uvkuShaderModuleFactory;


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




+ 249
- 228
projects/triangle/triangle.lps Parādīt failu

@@ -4,13 +4,13 @@
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Version Value="9"/> <Version Value="9"/>
<BuildModes Active="Default"/> <BuildModes Active="Default"/>
<Units Count="57">
<Units Count="59">
<Unit0> <Unit0>
<Filename Value="triangle.lpr"/> <Filename Value="triangle.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="5"/>
<CursorPos X="22" Y="11"/>
<UsageCount Value="70"/>
<EditorIndex Value="8"/>
<CursorPos X="22" Y="12"/>
<UsageCount Value="72"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
@@ -19,24 +19,27 @@
<ComponentName Value="MainForm"/> <ComponentName Value="MainForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<EditorIndex Value="-1"/>
<TopLine Value="53"/>
<CursorPos X="150" Y="70"/>
<UsageCount Value="70"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="3"/>
<TopLine Value="335"/>
<CursorPos X="45" Y="361"/>
<UsageCount Value="72"/>
<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="11"/>
<TopLine Value="2629"/>
<CursorPos X="23" Y="2639"/>
<EditorIndex Value="14"/>
<TopLine Value="2350"/>
<CursorPos X="70" Y="2370"/>
<ExtraEditorCount Value="1"/> <ExtraEditorCount Value="1"/>
<ExtraEditor1> <ExtraEditor1>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="2785"/> <TopLine Value="2785"/>
<CursorPos X="3" Y="2800"/> <CursorPos X="3" Y="2800"/>
</ExtraEditor1> </ExtraEditor1>
<UsageCount Value="70"/>
<UsageCount Value="72"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
@@ -44,7 +47,7 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="30" Y="9"/> <CursorPos X="30" Y="9"/>
<UsageCount Value="68"/>
<UsageCount Value="70"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/> <Filename Value="..\utils\uvkuInstanceFactory.pas"/>
@@ -52,7 +55,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="19"/> <TopLine Value="19"/>
<CursorPos X="3" Y="161"/> <CursorPos X="3" Y="161"/>
<UsageCount Value="62"/>
<UsageCount Value="64"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/> <Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
@@ -60,7 +63,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="245"/> <TopLine Value="245"/>
<CursorPos X="38" Y="252"/> <CursorPos X="38" Y="252"/>
<UsageCount Value="62"/>
<UsageCount Value="64"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/> <Filename Value="..\utils\uvkuAllocationHandler.pas"/>
@@ -68,7 +71,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="91"/> <TopLine Value="91"/>
<CursorPos X="39" Y="99"/> <CursorPos X="39" Y="99"/>
<UsageCount Value="52"/>
<UsageCount Value="54"/>
</Unit6> </Unit6>
<Unit7> <Unit7>
<Filename Value="..\utils\uvkuDevice.pas"/> <Filename Value="..\utils\uvkuDevice.pas"/>
@@ -76,14 +79,14 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="51"/> <TopLine Value="51"/>
<CursorPos X="63" Y="66"/> <CursorPos X="63" Y="66"/>
<UsageCount Value="56"/>
<UsageCount Value="58"/>
</Unit7> </Unit7>
<Unit8> <Unit8>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/> <Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="13"/>
<EditorIndex Value="16"/>
<CursorPos X="11" Y="9"/> <CursorPos X="11" Y="9"/>
<UsageCount Value="54"/>
<UsageCount Value="56"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit8> </Unit8>
<Unit9> <Unit9>
@@ -92,22 +95,23 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="41"/> <TopLine Value="41"/>
<CursorPos X="94" Y="56"/> <CursorPos X="94" Y="56"/>
<UsageCount Value="49"/>
<UsageCount Value="51"/>
</Unit9> </Unit9>
<Unit10> <Unit10>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/> <Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="14"/>
<EditorIndex Value="17"/>
<CursorPos X="11" Y="10"/> <CursorPos X="11" Y="10"/>
<UsageCount Value="48"/>
<UsageCount Value="50"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit10> </Unit10>
<Unit11> <Unit11>
<Filename Value="..\utils\uvkuSwapChainFactory.pas"/> <Filename Value="..\utils\uvkuSwapChainFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="15"/>
<CursorPos X="60" Y="9"/>
<UsageCount Value="39"/>
<EditorIndex Value="18"/>
<TopLine Value="34"/>
<CursorPos X="14" Y="48"/>
<UsageCount Value="41"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit11> </Unit11>
<Unit12> <Unit12>
@@ -116,7 +120,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="62"/> <TopLine Value="62"/>
<CursorPos X="35" Y="78"/> <CursorPos X="35" Y="78"/>
<UsageCount Value="38"/>
<UsageCount Value="40"/>
</Unit12> </Unit12>
<Unit13> <Unit13>
<Filename Value="..\utils\uvkuImageView.pas"/> <Filename Value="..\utils\uvkuImageView.pas"/>
@@ -124,14 +128,15 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="29"/> <TopLine Value="29"/>
<CursorPos X="64" Y="47"/> <CursorPos X="64" Y="47"/>
<UsageCount Value="35"/>
<UsageCount Value="37"/>
</Unit13> </Unit13>
<Unit14> <Unit14>
<Filename Value="..\utils\uvkuImageViewFactory.pas"/> <Filename Value="..\utils\uvkuImageViewFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="17"/>
<CursorPos X="49" Y="9"/>
<UsageCount Value="35"/>
<EditorIndex Value="20"/>
<TopLine Value="21"/>
<CursorPos X="14" Y="36"/>
<UsageCount Value="37"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit14> </Unit14>
<Unit15> <Unit15>
@@ -140,7 +145,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="36"/> <TopLine Value="36"/>
<CursorPos X="102" Y="51"/> <CursorPos X="102" Y="51"/>
<UsageCount Value="34"/>
<UsageCount Value="36"/>
</Unit15> </Unit15>
<Unit16> <Unit16>
<Filename Value="..\utils\uvkuBase.pas"/> <Filename Value="..\utils\uvkuBase.pas"/>
@@ -148,7 +153,7 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="26"/> <TopLine Value="26"/>
<CursorPos X="5" Y="39"/> <CursorPos X="5" Y="39"/>
<UsageCount Value="33"/>
<UsageCount Value="35"/>
</Unit16> </Unit16>
<Unit17> <Unit17>
<Filename Value="..\utils\uvkuDeviceMemory.pas"/> <Filename Value="..\utils\uvkuDeviceMemory.pas"/>
@@ -156,7 +161,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="31"/>
<UsageCount Value="33"/>
</Unit17> </Unit17>
<Unit18> <Unit18>
<Filename Value="..\utils\uvkuBuffer.pas"/> <Filename Value="..\utils\uvkuBuffer.pas"/>
@@ -164,31 +169,31 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="10"/> <TopLine Value="10"/>
<CursorPos X="3" Y="13"/> <CursorPos X="3" Y="13"/>
<UsageCount Value="30"/>
<UsageCount Value="32"/>
</Unit18> </Unit18>
<Unit19> <Unit19>
<Filename Value="..\utils\uvkuImageFactory.pas"/> <Filename Value="..\utils\uvkuImageFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="16"/>
<EditorIndex Value="19"/>
<CursorPos X="22" Y="9"/> <CursorPos X="22" Y="9"/>
<UsageCount Value="30"/>
<UsageCount Value="32"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit19> </Unit19>
<Unit20> <Unit20>
<Filename Value="..\utils\uvkuTypes.pas"/> <Filename Value="..\utils\uvkuTypes.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="12"/>
<TopLine Value="10"/>
<CursorPos X="29" Y="30"/>
<UsageCount Value="30"/>
<EditorIndex Value="15"/>
<TopLine Value="3"/>
<CursorPos X="3" Y="18"/>
<UsageCount Value="32"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit20> </Unit20>
<Unit21> <Unit21>
<Filename Value="..\utils\uvkuBufferFactory.pas"/> <Filename Value="..\utils\uvkuBufferFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="18"/>
<EditorIndex Value="21"/>
<CursorPos X="23" Y="9"/> <CursorPos X="23" Y="9"/>
<UsageCount Value="29"/>
<UsageCount Value="31"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit21> </Unit21>
<Unit22> <Unit22>
@@ -197,31 +202,31 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="52"/> <TopLine Value="52"/>
<CursorPos X="56" Y="76"/> <CursorPos X="56" Y="76"/>
<UsageCount Value="29"/>
<UsageCount Value="31"/>
</Unit22> </Unit22>
<Unit23> <Unit23>
<Filename Value="..\utils\uvkuBufferViewFactory.pas"/> <Filename Value="..\utils\uvkuBufferViewFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="19"/>
<EditorIndex Value="22"/>
<CursorPos X="50" Y="9"/> <CursorPos X="50" Y="9"/>
<UsageCount Value="28"/>
<UsageCount Value="30"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit23> </Unit23>
<Unit24> <Unit24>
<Filename Value="..\utils\uvkuCommandPool.pas"/> <Filename Value="..\utils\uvkuCommandPool.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="20"/>
<EditorIndex Value="23"/>
<TopLine Value="58"/> <TopLine Value="58"/>
<CursorPos X="34" Y="78"/> <CursorPos X="34" Y="78"/>
<UsageCount Value="28"/>
<UsageCount Value="30"/>
<Loaded Value="True"/> <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="21"/>
<EditorIndex Value="24"/>
<CursorPos X="28" Y="9"/> <CursorPos X="28" Y="9"/>
<UsageCount Value="27"/>
<UsageCount Value="29"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit25> </Unit25>
<Unit26> <Unit26>
@@ -229,7 +234,7 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<CursorPos X="39" Y="13"/> <CursorPos X="39" Y="13"/>
<UsageCount Value="27"/>
<UsageCount Value="29"/>
</Unit26> </Unit26>
<Unit27> <Unit27>
<Filename Value="..\utils\uvkuQueue.pas"/> <Filename Value="..\utils\uvkuQueue.pas"/>
@@ -237,354 +242,370 @@
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="7"/> <TopLine Value="7"/>
<CursorPos X="22" Y="23"/> <CursorPos X="22" Y="23"/>
<UsageCount Value="27"/>
<UsageCount Value="29"/>
</Unit27> </Unit27>
<Unit28> <Unit28>
<Filename Value="..\utils\VulkanUtils.pas"/> <Filename Value="..\utils\VulkanUtils.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/> <EditorIndex Value="2"/>
<TopLine Value="77"/>
<CursorPos X="94" Y="101"/>
<UsageCount Value="26"/>
<TopLine Value="39"/>
<CursorPos X="45" Y="21"/>
<UsageCount Value="28"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit28> </Unit28>
<Unit29> <Unit29>
<Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="5"/>
<CursorPos X="19" Y="17"/>
<UsageCount Value="49"/>
</Unit29>
<Unit30>
<Filename Value="..\utils\uvkuUtils.pas"/> <Filename Value="..\utils\uvkuUtils.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="9"/>
<EditorIndex Value="12"/>
<TopLine Value="17"/> <TopLine Value="17"/>
<CursorPos X="28" Y="29"/> <CursorPos X="28" Y="29"/>
<UsageCount Value="43"/>
<UsageCount Value="45"/>
<Loaded Value="True"/>
</Unit29>
<Unit30>
<Filename Value="..\utils\uvkuRenderPass.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="8"/>
<CursorPos X="150" Y="12"/>
<UsageCount Value="26"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit30> </Unit30>
<Unit31> <Unit31>
<Filename Value="..\utils\uvkuRenderPassFactory.pas"/>
<IsPartOfProject Value="True"/>
<TopLine Value="35"/>
<CursorPos X="22" Y="56"/>
<UsageCount Value="26"/>
<Loaded Value="True"/>
</Unit31>
<Unit32>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="7"/>
<UsageCount Value="26"/>
</Unit32>
<Unit33>
<Filename Value="..\utils\uvkuFrameBuffer.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="11"/>
<TopLine Value="33"/>
<CursorPos X="150" Y="40"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit33>
<Unit34>
<Filename Value="..\utils\uvkuFrameBufferFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="13"/>
<TopLine Value="98"/>
<CursorPos X="39" Y="111"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit34>
<Unit35>
<Filename Value="..\utils\uvkuDescriptorSetLayout.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="6"/>
<CursorPos X="150" Y="12"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit35>
<Unit36>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="7"/>
<TopLine Value="64"/>
<CursorPos Y="77"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit36>
<Unit37>
<Filename Value="..\utils\uvkuPipelineLayout.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="9"/>
<TopLine Value="48"/>
<CursorPos X="150" Y="53"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit37>
<Unit38>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="10"/>
<TopLine Value="17"/>
<CursorPos X="14" Y="147"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit38>
<Unit39>
<Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="5"/>
<CursorPos X="19" Y="17"/>
<UsageCount Value="49"/>
</Unit39>
<Unit40>
<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="13"/> <UsageCount Value="13"/>
<DefaultSyntaxHighlighter Value="None"/> <DefaultSyntaxHighlighter Value="None"/>
</Unit31>
<Unit32>
</Unit40>
<Unit41>
<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="9"/> <UsageCount Value="9"/>
</Unit32>
<Unit33>
</Unit41>
<Unit42>
<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="181"/> <TopLine Value="181"/>
<CursorPos X="21" Y="223"/> <CursorPos X="21" Y="223"/>
<UsageCount Value="10"/> <UsageCount Value="10"/>
</Unit33>
<Unit34>
</Unit42>
<Unit43>
<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="8"/> <UsageCount Value="8"/>
</Unit34>
<Unit35>
</Unit43>
<Unit44>
<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="9"/> <UsageCount Value="9"/>
</Unit35>
<Unit36>
</Unit44>
<Unit45>
<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="9"/> <UsageCount Value="9"/>
</Unit36>
<Unit37>
</Unit45>
<Unit46>
<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="10"/> <UsageCount Value="10"/>
</Unit37>
<Unit38>
</Unit46>
<Unit47>
<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="9"/> <UsageCount Value="9"/>
</Unit38>
<Unit39>
</Unit47>
<Unit48>
<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="9"/> <UsageCount Value="9"/>
</Unit39>
<Unit40>
</Unit48>
<Unit49>
<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="9"/> <UsageCount Value="9"/>
</Unit40>
<Unit41>
</Unit49>
<Unit50>
<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="9"/> <UsageCount Value="9"/>
</Unit41>
<Unit42>
</Unit50>
<Unit51>
<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="11"/> <UsageCount Value="11"/>
</Unit42>
<Unit43>
</Unit51>
<Unit52>
<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="11"/> <UsageCount Value="11"/>
</Unit43>
<Unit44>
</Unit52>
<Unit53>
<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="11"/> <UsageCount Value="11"/>
</Unit44>
<Unit45>
</Unit53>
<Unit54>
<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="11"/> <UsageCount Value="11"/>
</Unit45>
<Unit46>
</Unit54>
<Unit55>
<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="11"/> <UsageCount Value="11"/>
</Unit46>
<Unit47>
</Unit55>
<Unit56>
<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="11"/> <UsageCount Value="11"/>
</Unit47>
<Unit48>
<Filename Value="..\utils\uvkuRenderPass.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="8"/>
<CursorPos X="150" Y="12"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit48>
<Unit49>
<Filename Value="..\utils\uvkuRenderPassFactory.pas"/>
<IsPartOfProject Value="True"/>
<TopLine Value="122"/>
<CursorPos Y="139"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit49>
<Unit50>
<Filename Value="..\utils\uvkuFactoryBase.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="7"/>
<UsageCount Value="23"/>
</Unit50>
<Unit51>
<Filename Value="..\utils\uvkuFrameBuffer.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="8"/>
<TopLine Value="33"/>
<CursorPos X="150" Y="40"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit51>
<Unit52>
<Filename Value="..\utils\uvkuFrameBufferFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="10"/>
<TopLine Value="67"/>
<CursorPos Y="85"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit52>
<Unit53>
<Filename Value="..\utils\uvkuDescriptorSetLayout.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="3"/>
<CursorPos X="29"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit53>
<Unit54>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
</Unit56>
<Unit57>
<Filename Value="..\utils\uvkuShaderModule.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="4"/> <EditorIndex Value="4"/>
<TopLine Value="64"/>
<CursorPos Y="77"/>
<CursorPos X="36" Y="79"/>
<UsageCount Value="21"/> <UsageCount Value="21"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit54>
<Unit55>
<Filename Value="..\utils\uvkuPipelineLayout.pas"/>
</Unit57>
<Unit58>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="6"/>
<TopLine Value="48"/>
<CursorPos X="150" Y="53"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit55>
<Unit56>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="7"/>
<TopLine Value="17"/>
<CursorPos X="14" Y="147"/>
<EditorIndex Value="5"/>
<TopLine Value="85"/>
<CursorPos X="46" Y="93"/>
<UsageCount Value="21"/> <UsageCount Value="21"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit56>
</Unit58>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29">
<JumpHistory Count="30" HistoryIndex="28">
<Position1> <Position1>
<Filename Value="..\utils\uvkuBufferViewFactory.pas"/>
<Caret Line="78" Column="56" TopLine="59"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="248" Column="23" TopLine="231"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="..\utils\uvkuCommandPool.pas"/>
<Caret Line="68" Column="62" TopLine="57"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="267" Column="13" TopLine="241"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="..\utils\uvkuCommandPoolFactory.pas"/>
<Caret Line="64" Column="57" TopLine="45"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="278" Column="12" TopLine="254"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="..\utils\uvkuCommandPool.pas"/>
<Caret Line="73" Column="21" TopLine="58"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="293" Column="5" TopLine="282"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="17" Column="34"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="292" Column="13" TopLine="282"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="28" Column="63" TopLine="4"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="96" Column="3" TopLine="81"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="32" TopLine="14"/>
<Filename Value="..\utils\uvkuFrameBufferFactory.pas"/>
<Caret Line="45" Column="19" TopLine="27"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="58" Column="3" TopLine="28"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="292" Column="13" TopLine="282"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="57" Column="3" TopLine="36"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="295" Column="29" TopLine="267"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="9" Column="85"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="331" Column="24" TopLine="301"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="35" Column="109" TopLine="13"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="36" Column="29"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="108" Column="69" TopLine="79"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="318" Column="42" TopLine="305"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="..\utils\uvkuDescriptorSetLayoutFactory.pas"/>
<Caret Line="46" Column="13" TopLine="26"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="332" Column="27" TopLine="319"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="triangle.lpr"/>
<Caret Line="10" Column="80"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="37" Column="41" TopLine="20"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="..\utils\uvkuPipelineLayout.pas"/>
<Caret Line="29" Column="10" TopLine="6"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="335" Column="36" TopLine="317"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="..\utils\uvkuPipelineLayout.pas"/>
<Caret Line="18" Column="76" TopLine="7"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="320" Column="78" TopLine="305"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="..\utils\uvkuPipelineLayout.pas"/>
<Caret Line="77" Column="36" TopLine="51"/>
<Filename Value="..\utils\uvkuShaderModule.pas"/>
<Caret Line="17" Column="74" TopLine="5"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="18" Column="9"/>
<Filename Value="..\utils\uvkuShaderModule.pas"/>
<Caret Line="78" Column="25" TopLine="48"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="24" Column="10" TopLine="5"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="17" Column="34"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="28" Column="58" TopLine="6"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="25" Column="29" TopLine="4"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="33" TopLine="14"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="32" Column="20" TopLine="19"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="57" Column="3" TopLine="27"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="75" Column="3" TopLine="45"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="61" Column="17" TopLine="38"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="77" Column="33" TopLine="53"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="62" Column="75" TopLine="38"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="31" Column="54" TopLine="19"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="9" Column="80" TopLine="3"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="28" Column="54" TopLine="11"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="35" Column="5" TopLine="5"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="41" Column="43" TopLine="22"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="38" Column="14"/>
<Filename Value="..\utils\uvkuShaderModuleFactory.pas"/>
<Caret Line="32" Column="71" TopLine="17"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="41" Column="107" TopLine="12"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="110" Column="9" TopLine="87"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="141" Column="52" TopLine="115"/>
<Filename Value="..\utils\VulkanUtils.pas"/>
<Caret Line="21" Column="45" TopLine="6"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="..\utils\uvkuPipelineLayoutFactory.pas"/>
<Caret Line="56" Column="13" TopLine="48"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="39" Column="14" TopLine="21"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectSession> </ProjectSession>


+ 235
- 55
projects/triangle/uMainForm.pas Parādīt failu

@@ -30,8 +30,13 @@ type
fQueue: TvkuQueue; fQueue: TvkuQueue;
fSurface: TvkuSurface; fSurface: TvkuSurface;
fSwapChain: TvkuSwapChain; fSwapChain: TvkuSwapChain;
public
{ public declarations }
fImageViews: array of TvkuImageView;
fRenderPass: TvkuRenderPass;
fFrameBuffers: array of TvkuFrameBuffer;
fDescSetLayout: TvkuDescriptorSetLayout;
fPipelineLayout: TvkuPipelineLayout;
fVertexShader: TvkuShaderModule;
fFragmentShader: TvkuShaderModule;
end; end;


var var
@@ -73,77 +78,93 @@ end;
procedure TMainForm.FormCreate(Sender: TObject); procedure TMainForm.FormCreate(Sender: TObject);
var var
PhyDevices: TvkuPhysicalDeviceArr; PhyDevices: TvkuPhysicalDeviceArr;
iFactory: TvkuInstanceFactory;
dFactory: TvkuDeviceFactory;
sFactory: TvkuSurfaceFactory;
scFactory: TvkuSwapChainFactory;

InstanceFactory: TvkuInstanceFactory;
DeviceFactory: TvkuDeviceFactory;
SurfaceFactory: TvkuSurfaceFactory;
SwapChainFactory: TvkuSwapChainFactory;
ImageViewFactory: TvkuImageViewFactory;
RenderPassFactory: TvkuRenderPassFactory;
FrameBufferFactory: TvkuFrameBufferFactory;
DescSetLayoutFactory: TvkuDescriptorSetLayoutFactory;
PipelineLayoutFactory: TvkuPipelineLayoutFactory;
ShaderModuleFactory: TvkuShaderModuleFactory;

Format: TVkSurfaceFormatKHR;
SubResourceRange: TVkImageSubresourceRange;
i: Integer;
qci: TvkuQueueCreateInfo; qci: TvkuQueueCreateInfo;
SrfFormats: TvkuSurfaceFormatArr; SrfFormats: TvkuSurfaceFormatArr;
SurfaceCapabilities: TVkSurfaceCapabilitiesKHR; SurfaceCapabilities: TVkSurfaceCapabilitiesKHR;
PresentModes: TvkuPresentModeArr; PresentModes: TvkuPresentModeArr;
pm: TVkPresentModeKHR; pm: TVkPresentModeKHR;
Images: TvkuImageArr;
ComponentMapping: TVkComponentMapping;
AttDesc: TVkAttachmentDescription;
AttRef: TVkAttachmentReference;
Subpass: TVkSubpassDescription;
DescSetLayoutBinding: TVkDescriptorSetLayoutBinding;
begin begin
fAllocHandler := TCustomAllocHandler.Create; fAllocHandler := TCustomAllocHandler.Create;



WriteLn('create vulkan instance');
iFactory := TvkuInstanceFactory.Create;
//////////////////////////////////////////////////////////////////////////////
WriteLn('create instance');
InstanceFactory := TvkuInstanceFactory.Create;
try try
iFactory.Extensions.Add(VK_KHR_SURFACE_EXTENSION_NAME);
iFactory.Extensions.Add(TvkuSurface.GetPlatformSurfaceExtensionName);
fInstance := iFactory.CreateInstance(fAllocHandler, false);
InstanceFactory.Extensions.Add(VK_KHR_SURFACE_EXTENSION_NAME);
InstanceFactory.Extensions.Add(TvkuSurface.GetPlatformSurfaceExtensionName);
fInstance := InstanceFactory.CreateInstance(fAllocHandler, false);
finally finally
FreeAndNil(iFactory);
FreeAndNil(InstanceFactory);
end; end;


WriteLn('check physical devices');
//////////////////////////////////////////////////////////////////////////////
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 Exception.Create('unable to get physical device');
fPhyDevice := TvkuPhysicalDevice.Create(PhyDevices[0], fInstance.InstanceCommands); fPhyDevice := TvkuPhysicalDevice.Create(PhyDevices[0], fInstance.InstanceCommands);


WriteLn('create vulkan surface');
sFactory := TvkuSurfaceFactory.Create(fInstance);
try
sFactory.WinControl := RenderPanel;
fSurface := sFactory.CreateSurface(fAllocHandler, false);
finally
FreeAndNil(sFactory);
end;


WriteLn('create vulkan device');
dFactory := TvkuDeviceFactory.Create(fInstance);
//////////////////////////////////////////////////////////////////////////////
WriteLn('create device');
DeviceFactory := TvkuDeviceFactory.Create(fInstance);
try try
SetLength(qci.Priorities, 1); SetLength(qci.Priorities, 1);
qci.Priorities[0] := 1.0; qci.Priorities[0] := 1.0;
qci.FamilyIndex := 0; qci.FamilyIndex := 0;
qci.Flags := 0; qci.Flags := 0;


dFactory.QueueCreateInfoCount := 1;
dFactory.QueueCreateInfo[0] := qci;
DeviceFactory.QueueCreateInfoCount := 1;
DeviceFactory.QueueCreateInfo[0] := qci;


fDevice := dFactory.CreateDevice(fPhyDevice.Handle, fAllocHandler, false);
fDevice := DeviceFactory.CreateDevice(fPhyDevice.Handle, fAllocHandler, false);
finally finally
FreeAndNil(dFactory);
FreeAndNil(DeviceFactory);
end; end;


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


//////////////////////////////////////////////////////////////////////////////
WriteLn('create surface');
SurfaceFactory := TvkuSurfaceFactory.Create(fInstance);
try
SurfaceFactory.WinControl := RenderPanel;
fSurface := SurfaceFactory.CreateSurface(fAllocHandler, false);
finally
FreeAndNil(SurfaceFactory);
end;


//////////////////////////////////////////////////////////////////////////////
WriteLn('create swap chain'); WriteLn('create swap chain');
scFactory := TvkuSwapChainFactory.Create(fDevice);
SwapChainFactory := TvkuSwapChainFactory.Create(fDevice);
try try
scFactory.Surface := fSurface.Handle;
scFactory.ImageUsage := [ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ];
scFactory.ImageArrayLayers := 1;
scFactory.ImageSharingMode := VK_SHARING_MODE_EXCLUSIVE;
scFactory.Clipped := true;
scFactory.ComposideAlpha := [ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR ];
SwapChainFactory.Surface := fSurface.Handle;
SwapChainFactory.ImageUsage := [ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ];
SwapChainFactory.ImageArrayLayers := 1;
SwapChainFactory.ImageSharingMode := VK_SHARING_MODE_EXCLUSIVE;
SwapChainFactory.Clipped := true;
SwapChainFactory.ComposideAlpha := [ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR ];


WriteLn(' get surface capabilities'); WriteLn(' get surface capabilities');
SurfaceCapabilities := fPhyDevice.GetSurfaceCapabilities(fSurface.Handle); SurfaceCapabilities := fPhyDevice.GetSurfaceCapabilities(fSurface.Handle);
@@ -154,13 +175,13 @@ begin
ClientWidth := SurfaceCapabilities.currentExtent.width; ClientWidth := SurfaceCapabilities.currentExtent.width;
ClientHeight := SurfaceCapabilities.currentExtent.height; ClientHeight := SurfaceCapabilities.currentExtent.height;
end; end;
scFactory.ImageExtent := SurfaceCapabilities.currentExtent;
SwapChainFactory.ImageExtent := SurfaceCapabilities.currentExtent;


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


WriteLn(' find suitable image format'); WriteLn(' find suitable image format');
SrfFormats := fPhyDevice.GetSurfaceFormats(fSurface.Handle); SrfFormats := fPhyDevice.GetSurfaceFormats(fSurface.Handle);
@@ -169,17 +190,20 @@ begin
halt; halt;
end; end;
if (Length(SrfFormats) = 1) and (SrfFormats[0].format = VK_FORMAT_UNDEFINED) then begin if (Length(SrfFormats) = 1) and (SrfFormats[0].format = VK_FORMAT_UNDEFINED) then begin
scFactory.ImageFormat := VK_FORMAT_R8G8B8A8_UNORM;
scFactory.ImageColorSpace := VK_COLORSPACE_SRGB_NONLINEAR_KHR;
Format.format := VK_FORMAT_R8G8B8A8_UNORM;
Format.colorSpace := VK_COLORSPACE_SRGB_NONLINEAR_KHR;
end else begin end else begin
scFactory.ImageFormat := SrfFormats[0].format;
scFactory.ImageColorSpace := SrfFormats[0].colorSpace;
Format.format := SrfFormats[0].format;
Format.colorSpace := SrfFormats[0].colorSpace;
end; end;
SwapChainFactory.ImageFormat := Format.format;
SwapChainFactory.ImageColorSpace := format.colorSpace;



WriteLn(' set pre transform'); WriteLn(' set pre transform');
scFactory.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
scFactory.PreTransform := scFactory.PreTransform + [ VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ];
SwapChainFactory.PreTransform := SwapChainFactory.PreTransform + [ VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ];


WriteLn(' find suitable present mode'); WriteLn(' find suitable present mode');
PresentModes := fPhyDevice.GetSurfacePresentModes(fSurface.Handle); PresentModes := fPhyDevice.GetSurfacePresentModes(fSurface.Handle);
@@ -189,24 +213,180 @@ begin
end; end;
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
scFactory.PresentMode := pm;
SwapChainFactory.PresentMode := pm;
break; break;
end; end;
end; end;


fSwapChain := scFactory.CreateSwapchain(fAllocHandler, false);
fSwapChain := SwapChainFactory.CreateSwapchain(fAllocHandler, false);
finally finally
FreeAndNil(scFactory);
FreeAndNil(SwapChainFactory);
end;

//////////////////////////////////////////////////////////////////////////////
WriteLn('create image views');
Images := fSwapChain.GetImages;
SetLength(fImageViews, Length(Images));
ImageViewFactory := TvkuImageViewFactory.Create(fDevice);
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;

SubResourceRange.aspectMask := [ VK_IMAGE_ASPECT_COLOR_BIT ];
SubResourceRange.baseMipLevel := 0;
SubResourceRange.levelCount := 1;
SubResourceRange.baseArrayLayer := 0;
SubResourceRange.layerCount := 1;

ImageViewFactory.Format := Format.format;
ImageViewFactory.Components := ComponentMapping;
ImageViewFactory.SubresourceRange := SubResourceRange;
ImageViewFactory.ViewType := VK_IMAGE_VIEW_TYPE_2D;
for i := Low(fImageViews) to High(fImageViews) do begin
ImageViewFactory.Image := Images[i];
fImageViews[i] := ImageViewFactory.CreateImageView(fAllocHandler, false);
end;
finally
FreeAndNil(ImageViewFactory);
end;

//////////////////////////////////////////////////////////////////////////////
WriteLn('create render pass');
RenderPassFactory := TvkuRenderPassFactory.Create(fDevice);
try
FillByte(AttDesc, SizeOf(AttDesc), 0);
AttDesc.format := Format.format;
AttDesc.samples := [ VK_SAMPLE_COUNT_1_BIT ];
AttDesc.loadOp := VK_ATTACHMENT_LOAD_OP_CLEAR;
AttDesc.storeOp := VK_ATTACHMENT_STORE_OP_STORE;
AttDesc.stencilLoadOp := VK_ATTACHMENT_LOAD_OP_DONT_CARE;
AttDesc.stencilStoreOp := VK_ATTACHMENT_STORE_OP_DONT_CARE;
AttDesc.initialLayout := VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
AttDesc.finalLayout := VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

FillByte(AttRef, SizeOf(AttRef), 0);
AttRef.attachment := 0;
AttRef.layout := VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

FillByte(Subpass, SizeOf(Subpass), 0);
Subpass.pipelineBindPoint := VK_PIPELINE_BIND_POINT_GRAPHICS;
Subpass.flags := 0;
Subpass.inputAttachmentCount := 0;
Subpass.pInputAttachments := nil;
Subpass.colorAttachmentCount := 1;
Subpass.pColorAttachments := @AttRef;
Subpass.pResolveAttachments := nil;
Subpass.pDepthStencilAttachment := nil;
Subpass.preserveAttachmentCount := 0;
Subpass.pPreserveAttachments := nil;

RenderPassFactory.AttachmentCount := 1;
RenderPassFactory.Attachment[0] := AttDesc;
RenderPassFactory.SubpassCount := 1;
RenderPassFactory.Subpass[0] := Subpass;

fRenderPass := RenderPassFactory.CreateRenderPass(fAllocHandler, false);
finally
FreeAndNil(RenderPassFactory);
end;

//////////////////////////////////////////////////////////////////////////////
WriteLn('create frame buffers');
FrameBufferFactory := TvkuFrameBufferFactory.Create(fDevice);
try
SetLength(fFrameBuffers, Length(fImageViews));

FrameBufferFactory.RenderPass := fRenderPass.Handle;
FrameBufferFactory.AttachmentCount := 1;
FrameBufferFactory.width := SurfaceCapabilities.currentExtent.width;
FrameBufferFactory.height := SurfaceCapabilities.currentExtent.height;
FrameBufferFactory.layers := 1;

for i := low(fFrameBuffers) to high(fFrameBuffers) do begin
FrameBufferFactory.Attachments[0] := fImageViews[i].Handle;
fFrameBuffers[i] := FrameBufferFactory.CreateFrameBuffer(fAllocHandler, false);
end;
finally
FreeAndNil(FrameBufferFactory);
end;

//////////////////////////////////////////////////////////////////////////////
WriteLn('create descriptor set layout');
DescSetLayoutFactory := TvkuDescriptorSetLayoutFactory.Create(fDevice);
try
FillByte(DescSetLayoutBinding, SizeOf(DescSetLayoutBinding), 0);
DescSetLayoutBinding.binding := 0; // binding 0 (Uniform Buffer/Vertex Shader)
DescSetLayoutBinding.descriptorType := VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
DescSetLayoutBinding.descriptorCount := 1;
DescSetLayoutBinding.stageFlags := [ VK_SHADER_STAGE_VERTEX_BIT ];
DescSetLayoutBinding.pImmutableSamplers := nil;

DescSetLayoutFactory.BindingCount := 1;
DescSetLayoutFactory.Binding[0] := DescSetLayoutBinding;

fDescSetLayout := DescSetLayoutFactory.CreateDescriptorSetLayout(fAllocHandler, false);
finally
FreeAndNil(DescSetLayoutFactory);
end;

//////////////////////////////////////////////////////////////////////////////
WriteLn('create pipeline layout');
PipelineLayoutFactory := TvkuPipelineLayoutFactory.Create(fDevice);
try
PipelineLayoutFactory.SetLayoutCount := 1;
PipelineLayoutFactory.SetLayout[0] := fDescSetLayout.Handle;
fPipelineLayout := PipelineLayoutFactory.CreatePipelineLayout(fAllocHandler, false);
finally
FreeAndNil(PipelineLayoutFactory);
end;

//////////////////////////////////////////////////////////////////////////////
WriteLn('create shader modules');
ShaderModuleFactory := TvkuShaderModuleFactory.Create(fDevice);
try
ShaderModuleFactory.SetShaderCode(ExtractFilePath(Application.ExeName) + '../../data/shaders/triangle.vert.spv');
fVertexShader := ShaderModuleFactory.CreateShaderModule(fAllocHandler, false);

ShaderModuleFactory.SetShaderCode(ExtractFilePath(Application.ExeName) + '../../data/shaders/triangle.frag.spv');
fFragmentShader := ShaderModuleFactory.CreateShaderModule(fAllocHandler, false);
finally
FreeAndNil(ShaderModuleFactory);
end; end;
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.FormDestroy(Sender: TObject); procedure TMainForm.FormDestroy(Sender: TObject);

procedure FreeAndNilFrameBuffers;
var i: Integer;
begin
for i := Low(fFrameBuffers) to High(fFrameBuffers) do
FreeAndNil(fFrameBuffers[i]);
SetLength(fFrameBuffers, 0);
end;

procedure FreeAndNilImageViews;
var i: Integer;
begin
for i := Low(fImageViews) to High(fImageViews) do
FreeAndNil(fImageViews[i]);
SetLength(fImageViews, 0);
end;

begin begin
FreeAndNil(fFragmentShader);
FreeAndNil(fVertexShader);
FreeAndNil(fPipelineLayout);
FreeAndNil(fDescSetLayout);
FreeAndNilFrameBuffers;
FreeAndNil(fRenderPass);
FreeAndNilImageViews;
FreeAndNil(fSwapChain); FreeAndNil(fSwapChain);
FreeAndNil(fSurface);
FreeAndNil(fQueue); FreeAndNil(fQueue);
FreeAndNil(fDevice); FreeAndNil(fDevice);
FreeAndNil(fSurface);
FreeAndNil(fPhyDevice); FreeAndNil(fPhyDevice);
FreeAndNil(fInstance); FreeAndNil(fInstance);
FreeAndNil(fAllocHandler); FreeAndNil(fAllocHandler);


+ 12
- 0
projects/utils/VulkanUtils.pas Parādīt failu

@@ -16,7 +16,9 @@ uses
uvkuCommandPool, uvkuCommandPoolFactory, uvkuCommandBuffer, uvkuCommandPool, uvkuCommandPoolFactory, uvkuCommandBuffer,
uvkuRenderPass, uvkuRenderPassFactory, uvkuRenderPass, uvkuRenderPassFactory,
uvkuFrameBuffer, uvkuFrameBufferFactory, uvkuFrameBuffer, uvkuFrameBufferFactory,
uvkuDescriptorSetLayout, uvkuDescriptorSetLayoutFactory,
uvkuPipelineLayout, uvkuPipelineLayoutFactory, uvkuPipelineLayout, uvkuPipelineLayoutFactory,
uvkuShaderModule, uvkuShaderModuleFactory,
uvkuUtils; uvkuUtils;


type type
@@ -95,11 +97,21 @@ type
TvkuFrameBufferEx = uvkuFrameBufferFactory.TvkuFrameBufferEx; TvkuFrameBufferEx = uvkuFrameBufferFactory.TvkuFrameBufferEx;
TvkuFrameBufferFactory = uvkuFrameBufferFactory.TvkuFrameBufferFactory; TvkuFrameBufferFactory = uvkuFrameBufferFactory.TvkuFrameBufferFactory;


{ DescriptorSetLayout }
TvkuDescriptorSetLayout = uvkuDescriptorSetLayout.TvkuDescriptorSetLayout;
TvkuDescriptorSetLayoutEx = uvkuDescriptorSetLayoutFactory.TvkuDescriptorSetLayoutEx;
TvkuDescriptorSetLayoutFactory = uvkuDescriptorSetLayoutFactory.TvkuDescriptorSetLayoutFactory;

{ Pipeline } { Pipeline }
TvkuPipelineLayout = uvkuPipelineLayout.TvkuPipelineLayout; TvkuPipelineLayout = uvkuPipelineLayout.TvkuPipelineLayout;
TvkuPipelineLayoutEx = uvkuPipelineLayoutFactory.TvkuPipelineLayoutEx; TvkuPipelineLayoutEx = uvkuPipelineLayoutFactory.TvkuPipelineLayoutEx;
TvkuPipelineLayoutFactory = uvkuPipelineLayoutFactory.TvkuPipelineLayoutFactory; TvkuPipelineLayoutFactory = uvkuPipelineLayoutFactory.TvkuPipelineLayoutFactory;


{ Shader Modules }
TvkuShaderModule = uvkuShaderModule.TvkuShaderModule;
TvkuShaderModuleEx = uvkuShaderModuleFactory.TvkuShaderModuleEx;
TvkuShaderModuleFactory = uvkuShaderModuleFactory.TvkuShaderModuleFactory;

{ Utils } { Utils }
TvkuException = uvkuUtils.TvkuException; TvkuException = uvkuUtils.TvkuException;
TvkuErrorException = uvkuUtils.TvkuErrorException; TvkuErrorException = uvkuUtils.TvkuErrorException;


+ 11
- 12
projects/utils/uvkuFrameBufferFactory.pas Parādīt failu

@@ -22,6 +22,7 @@ type
TvkuFrameBufferFactory = class(TvkuDeviceObjFactory) TvkuFrameBufferFactory = class(TvkuDeviceObjFactory)
private private
fFlags: VkFramebufferCreateFlags; fFlags: VkFramebufferCreateFlags;
fRenderPass: VkRenderPass;
fWidth: VkUint32; fWidth: VkUint32;
fHeight: VkUint32; fHeight: VkUint32;
fLayers: VkUint32; fLayers: VkUint32;
@@ -31,19 +32,18 @@ type
procedure SetAttachment(const aIndex: Integer; aValue: VkImageView); procedure SetAttachment(const aIndex: Integer; aValue: VkImageView);
procedure SetAttachmentCount(aValue: Integer); procedure SetAttachmentCount(aValue: Integer);
public public
property Flags: VkFramebufferCreateFlags read fFlags write fFlags;
property Width: VkUint32 read fWidth write fWidth;
property Height: VkUint32 read fHeight write fHeight;
property Layers: VkUint32 read fLayers write fLayers;
property Flags: VkFramebufferCreateFlags read fFlags write fFlags;
property RenderPass: VkRenderPass read fRenderPass write fRenderPass;
property Width: VkUint32 read fWidth write fWidth;
property Height: VkUint32 read fHeight write fHeight;
property Layers: VkUint32 read fLayers write fLayers;


property Attachments: TvkuImageViewArr read fAttachments write fAttachments; property Attachments: TvkuImageViewArr read fAttachments write fAttachments;
property AttachmentCount: Integer read GetAttachmentCount write SetAttachmentCount; property AttachmentCount: Integer read GetAttachmentCount write SetAttachmentCount;
property Attachment[const aIndex: Integer]: VkImageView read GetAttachment write SetAttachment; property Attachment[const aIndex: Integer]: VkImageView read GetAttachment write SetAttachment;


function CreateFrameBuffer: TvkuFrameBufferEx;
function CreateFrameBuffer( function CreateFrameBuffer(
const aRenderPass: VkRenderPass): TvkuFrameBufferEx;
function CreateFrameBuffer(
const aRenderPass: VkRenderPass;
const aAllocHandler: TvkuAllocationHandler; const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuFrameBufferEx; const aOwnsHandler: Boolean): TvkuFrameBufferEx;
end; end;
@@ -94,14 +94,13 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuFrameBufferFactory.CreateFrameBuffer(const aRenderPass: VkRenderPass): TvkuFrameBufferEx;
function TvkuFrameBufferFactory.CreateFrameBuffer: TvkuFrameBufferEx;
begin begin
result := CreateFrameBuffer(aRenderPass, nil, false);
result := CreateFrameBuffer(nil, false);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuFrameBufferFactory.CreateFrameBuffer(const aRenderPass: VkRenderPass;
const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuFrameBufferEx;
function TvkuFrameBufferFactory.CreateFrameBuffer(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuFrameBufferEx;
var var
CreateInfo: TVkFramebufferCreateInfo; CreateInfo: TVkFramebufferCreateInfo;
begin begin
@@ -109,7 +108,7 @@ begin
CreateInfo.sType := VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; CreateInfo.sType := VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
CreateInfo.pNext := nil; CreateInfo.pNext := nil;
CreateInfo.flags := fFlags; CreateInfo.flags := fFlags;
CreateInfo.renderPass := aRenderPass;
CreateInfo.renderPass := fRenderPass;
CreateInfo.attachmentCount := Length(fAttachments); CreateInfo.attachmentCount := Length(fAttachments);
CreateInfo.pAttachments := @fAttachments[0]; CreateInfo.pAttachments := @fAttachments[0];
CreateInfo.width := fWidth; CreateInfo.width := fWidth;


+ 84
- 0
projects/utils/uvkuShaderModule.pas Parādīt failu

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

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuBase;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuShaderModule = class(TvkuAllocHandle)
private
fHandle: VkShaderModule;
fDeviceCommands: TVkDeviceCommands;

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

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

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuShaderModule///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuShaderModule.CreateHandle(const aCreateInfo: TVkShaderModuleCreateInfo);
var err: TVkResult;
begin
if not Assigned(fDeviceCommands.vkCreateShaderModule) then
raise TvkuInvalidFuncPtrException.Create('vkCreateShaderModule');
err := fDeviceCommands.vkCreateShaderModule(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create shader module', err);
end;

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

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

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

end.


+ 124
- 0
projects/utils/uvkuShaderModuleFactory.pas Parādīt failu

@@ -0,0 +1,124 @@
unit uvkuShaderModuleFactory;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,
Vulkan, uvkuFactoryBase, uvkuAllocationHandler, uvkuShaderModule;

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuShaderModuleFactory = class(TvkuDeviceObjFactory)
private
fFlags: VkShaderModuleCreateFlags;
fShaderCode: PVkVoid;
fShaderCodeSize: VkSize;

procedure ReallocShaderCode(const aSize: VkSize);
public
property Flags: VkShaderModuleCreateFlags read fFlags write fFlags;

procedure SetShaderCode(const aStream: TStream; aSize: VkSize = 0);
procedure SetShaderCode(const aFilename: String);
procedure SetShaderCode(const aMem: PVkVoid; const aSize: VkSize);

function CreateShaderModule: TvkuShaderModuleEx;
function CreateShaderModule(
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuShaderModuleEx;

procedure BeforeDestruction; override;
end;

implementation

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuShaderModuleFactory////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuShaderModuleFactory.ReallocShaderCode(const aSize: VkSize);
begin
if Assigned(fShaderCode) then
Freememory(fShaderCode);
fShaderCodeSize := aSize;
if (fShaderCodeSize > 0) then
fShaderCode := GetMemory(fShaderCodeSize);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuShaderModuleFactory.SetShaderCode(const aStream: TStream; aSize: VkSize);
begin
if (aSize = 0) then
aSize := aStream.Size - aStream.Position;
ReallocShaderCode(aSize);
aStream.Read(fShaderCode^, fShaderCodeSize);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuShaderModuleFactory.SetShaderCode(const aFilename: String);
var fs: TFileStream;
begin
fs := TFileStream.Create(aFilename, fmOpenRead);
try
SetShaderCode(fs);
finally
FreeAndNil(fs);
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuShaderModuleFactory.SetShaderCode(const aMem: PVkVoid; const aSize: VkSize);
begin
ReallocShaderCode(aSize);
Move(aMem^, fShaderCode^, fShaderCodeSize);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuShaderModuleFactory.CreateShaderModule: TvkuShaderModuleEx;
begin
result := CreateShaderModule(nil, false);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuShaderModuleFactory.CreateShaderModule(const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuShaderModuleEx;
var
CreateInfo: TVkShaderModuleCreateInfo;
begin
FillByte(CreateInfo, SizeOf(CreateInfo), 0);
CreateInfo.sType := VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
CreateInfo.codeSize := fShaderCodeSize;
CreateInfo.pCode := fShaderCode;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuShaderModuleFactory.BeforeDestruction;
begin
inherited BeforeDestruction;
ReallocShaderCode(0);
end;

end.


Notiek ielāde…
Atcelt
Saglabāt