瀏覽代碼

* refactored utils to match new Vulkan.pas

master
Bergmann89 10 年之前
父節點
當前提交
5bf59cbc20
共有 18 個檔案被更改,包括 1186 行新增 和 548 行删除
  1. +27
    -23
      data/vulkan.tpl
  2. +230
    -226
      projects/Vulkan.pas
  3. +1
    -0
      projects/generator/generate.bat
  4. +2
    -2
      projects/generator/generator.lps
  5. +14
    -5
      projects/triangle/triangle.lpi
  6. +1
    -2
      projects/triangle/triangle.lpr
  7. +241
    -140
      projects/triangle/triangle.lps
  8. +11
    -0
      projects/triangle/uMainForm.lfm
  9. +22
    -4
      projects/triangle/uMainForm.pas
  10. +1
    -1
      projects/utils/uvkuAllocationHandler.pas
  11. +24
    -10
      projects/utils/uvkuDevice.pas
  12. +17
    -32
      projects/utils/uvkuDeviceFactory.pas
  13. +30
    -40
      projects/utils/uvkuInstance.pas
  14. +39
    -19
      projects/utils/uvkuInstanceFactory.pas
  15. +177
    -41
      projects/utils/uvkuPhysicalDevice.pas
  16. +15
    -3
      projects/utils/uvkuPhysicalDeviceFactory.pas
  17. +104
    -0
      projects/utils/uvkuSurface.pas
  18. +230
    -0
      projects/utils/uvkuSurfaceFactory.pas

+ 27
- 23
data/vulkan.tpl 查看文件

@@ -89,12 +89,12 @@ type
{%INTERFACE%}

type
TVkInstanceCommands = packed record
TVkInstanceCommands = class
Instance: VkInstance;
{%INSTANCE_COMMANDS.INTERFACE%}
end;

TVkDeviceCommands = packed record
TVkDeviceCommands = class
Device: VkDevice;
{%DEVICE_COMMANDS.INTERFACE%}
end;
@@ -111,12 +111,15 @@ function vkGetVersionMinor(const aVersion: VkVersion): Integer; inline;
function vkGetVersionPatch(const aVersion: VkVersion): Integer; inline;

function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
function LoadInstanceCommands(const aInstance: VkInstance; out aCommands: TVkInstanceCommands): Boolean;
function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice; out aCommands: TVkDeviceCommands): Boolean;
function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
procedure FinalizeVulkan;

implementation

uses
SysUtils;

type
{$IF DEFINED(VK_WIN)}
TvkLibHandle = TLibHandle;
@@ -210,46 +213,47 @@ begin
result := success;
end;

function LoadInstanceCommands(const aInstance: VkInstance; out aCommands: TVkInstanceCommands): Boolean;
var
success: Boolean;
function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;

function GetProcAddress(const aName: String): TvkVoidFunction;
begin
result := vkGetInstanceProcAddr(aInstance, PVkChar(aName));
if not Assigned(result) then
success := false;
end;

begin
FillByte(aCommands, SizeOf(aCommands), 0);
success := true;
with aCommands do begin
{%INSTANCE_COMMANDS.IMPLEMENTATION%}
result := TVkInstanceCommands.Create;
try
result.Instance := aInstance;
with result do begin
{%INSTANCE_COMMANDS.IMPLEMENTATION%}
end;
except
FreeAndNil(result);
raise;
end;
result := success;
end;

function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice; out aCommands: TVkDeviceCommands): Boolean;
function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
var
vkGetDeviceProcAddr: TvkGetDeviceProcAddr;
success: Boolean;

function GetProcAddress(const aName: String): TvkVoidFunction;
begin
result := vkGetDeviceProcAddr(aDevice, PVkChar(aName));
if not Assigned(result) then
success := false;
end;

begin
FillByte(aCommands, SizeOf(aCommands), 0);
vkGetDeviceProcAddr := TvkGetDeviceProcAddr(vkGetInstanceProcAddr(aInstance, 'vkGetDeviceProcAddr'));
success := true;
with aCommands do begin
{%DEVICE_COMMANDS.IMPLEMENTATION%}
result := TVkDeviceCommands.Create;
try
result.Device := aDevice;
with result do begin
{%DEVICE_COMMANDS.IMPLEMENTATION%}
end;
except
FreeAndNil(result);
raise;
end;
result := success;
end;

procedure FinalizeVulkan;


+ 230
- 226
projects/Vulkan.pas 查看文件

@@ -4227,7 +4227,7 @@ var
vkEnumerateInstanceLayerProperties: TvkEnumerateInstanceLayerProperties;

type
TVkInstanceCommands = packed record
TVkInstanceCommands = class
Instance: VkInstance;
{ ========================================== VK_VERSION_1_0 ========================================== }
@@ -4303,7 +4303,7 @@ type

end;

TVkDeviceCommands = packed record
TVkDeviceCommands = class
Device: VkDevice;
{ ========================================== VK_VERSION_1_0 ========================================== }
@@ -4452,12 +4452,15 @@ function vkGetVersionMinor(const aVersion: VkVersion): Integer; inline;
function vkGetVersionPatch(const aVersion: VkVersion): Integer; inline;

function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
function LoadInstanceCommands(const aInstance: VkInstance; out aCommands: TVkInstanceCommands): Boolean;
function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice; out aCommands: TVkDeviceCommands): Boolean;
function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
procedure FinalizeVulkan;

implementation

uses
SysUtils;

type
{$IF DEFINED(VK_WIN)}
TvkLibHandle = TLibHandle;
@@ -4554,249 +4557,250 @@ begin
result := success;
end;

function LoadInstanceCommands(const aInstance: VkInstance; out aCommands: TVkInstanceCommands): Boolean;
var
success: Boolean;
function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;

function GetProcAddress(const aName: String): TvkVoidFunction;
begin
result := vkGetInstanceProcAddr(aInstance, PVkChar(aName));
if not Assigned(result) then
success := false;
end;

begin
FillByte(aCommands, SizeOf(aCommands), 0);
success := true;
with aCommands do begin
{ ========================================== VK_VERSION_1_0 ========================================== }
vkDestroyInstance := TvkDestroyInstance (GetProcAddress('vkDestroyInstance'));
vkEnumeratePhysicalDevices := TvkEnumeratePhysicalDevices (GetProcAddress('vkEnumeratePhysicalDevices'));
vkGetPhysicalDeviceFeatures := TvkGetPhysicalDeviceFeatures (GetProcAddress('vkGetPhysicalDeviceFeatures'));
vkGetPhysicalDeviceFormatProperties := TvkGetPhysicalDeviceFormatProperties (GetProcAddress('vkGetPhysicalDeviceFormatProperties'));
vkGetPhysicalDeviceImageFormatProperties := TvkGetPhysicalDeviceImageFormatProperties (GetProcAddress('vkGetPhysicalDeviceImageFormatProperties'));
vkGetPhysicalDeviceProperties := TvkGetPhysicalDeviceProperties (GetProcAddress('vkGetPhysicalDeviceProperties'));
vkGetPhysicalDeviceQueueFamilyProperties := TvkGetPhysicalDeviceQueueFamilyProperties (GetProcAddress('vkGetPhysicalDeviceQueueFamilyProperties'));
vkGetPhysicalDeviceMemoryProperties := TvkGetPhysicalDeviceMemoryProperties (GetProcAddress('vkGetPhysicalDeviceMemoryProperties'));
vkGetDeviceProcAddr := TvkGetDeviceProcAddr (GetProcAddress('vkGetDeviceProcAddr'));
vkCreateDevice := TvkCreateDevice (GetProcAddress('vkCreateDevice'));
vkEnumerateDeviceExtensionProperties := TvkEnumerateDeviceExtensionProperties (GetProcAddress('vkEnumerateDeviceExtensionProperties'));
vkEnumerateDeviceLayerProperties := TvkEnumerateDeviceLayerProperties (GetProcAddress('vkEnumerateDeviceLayerProperties'));
vkGetPhysicalDeviceSparseImageFormatProperties := TvkGetPhysicalDeviceSparseImageFormatProperties (GetProcAddress('vkGetPhysicalDeviceSparseImageFormatProperties'));
{ ========================================== VK_KHR_surface ========================================== }
vkDestroySurfaceKHR := TvkDestroySurfaceKHR (GetProcAddress('vkDestroySurfaceKHR'));
vkGetPhysicalDeviceSurfaceSupportKHR := TvkGetPhysicalDeviceSurfaceSupportKHR (GetProcAddress('vkGetPhysicalDeviceSurfaceSupportKHR'));
vkGetPhysicalDeviceSurfaceCapabilitiesKHR := TvkGetPhysicalDeviceSurfaceCapabilitiesKHR (GetProcAddress('vkGetPhysicalDeviceSurfaceCapabilitiesKHR'));
vkGetPhysicalDeviceSurfaceFormatsKHR := TvkGetPhysicalDeviceSurfaceFormatsKHR (GetProcAddress('vkGetPhysicalDeviceSurfaceFormatsKHR'));
vkGetPhysicalDeviceSurfacePresentModesKHR := TvkGetPhysicalDeviceSurfacePresentModesKHR (GetProcAddress('vkGetPhysicalDeviceSurfacePresentModesKHR'));
{ ========================================== VK_KHR_display ========================================== }
vkGetPhysicalDeviceDisplayPropertiesKHR := TvkGetPhysicalDeviceDisplayPropertiesKHR (GetProcAddress('vkGetPhysicalDeviceDisplayPropertiesKHR'));
vkGetPhysicalDeviceDisplayPlanePropertiesKHR := TvkGetPhysicalDeviceDisplayPlanePropertiesKHR (GetProcAddress('vkGetPhysicalDeviceDisplayPlanePropertiesKHR'));
vkGetDisplayPlaneSupportedDisplaysKHR := TvkGetDisplayPlaneSupportedDisplaysKHR (GetProcAddress('vkGetDisplayPlaneSupportedDisplaysKHR'));
vkGetDisplayModePropertiesKHR := TvkGetDisplayModePropertiesKHR (GetProcAddress('vkGetDisplayModePropertiesKHR'));
vkCreateDisplayModeKHR := TvkCreateDisplayModeKHR (GetProcAddress('vkCreateDisplayModeKHR'));
vkGetDisplayPlaneCapabilitiesKHR := TvkGetDisplayPlaneCapabilitiesKHR (GetProcAddress('vkGetDisplayPlaneCapabilitiesKHR'));
vkCreateDisplayPlaneSurfaceKHR := TvkCreateDisplayPlaneSurfaceKHR (GetProcAddress('vkCreateDisplayPlaneSurfaceKHR'));
{ ======================================= VK_KHR_xlib_surface ======================================== }
{$IFDEF VK_USE_PLATFORM_XLIB_KHR}
vkCreateXlibSurfaceKHR := TvkCreateXlibSurfaceKHR (GetProcAddress('vkCreateXlibSurfaceKHR'));
vkGetPhysicalDeviceXlibPresentationSupportKHR := TvkGetPhysicalDeviceXlibPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceXlibPresentationSupportKHR'));
{$ENDIF}
{ ======================================== VK_KHR_xcb_surface ======================================== }
{$IFDEF VK_USE_PLATFORM_XCB_KHR}
vkCreateXcbSurfaceKHR := TvkCreateXcbSurfaceKHR (GetProcAddress('vkCreateXcbSurfaceKHR'));
vkGetPhysicalDeviceXcbPresentationSupportKHR := TvkGetPhysicalDeviceXcbPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceXcbPresentationSupportKHR'));
{$ENDIF}
{ ====================================== VK_KHR_wayland_surface ====================================== }
{$IFDEF VK_USE_PLATFORM_WAYLAND_KHR}
vkCreateWaylandSurfaceKHR := TvkCreateWaylandSurfaceKHR (GetProcAddress('vkCreateWaylandSurfaceKHR'));
vkGetPhysicalDeviceWaylandPresentationSupportKHR := TvkGetPhysicalDeviceWaylandPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceWaylandPresentationSupportKHR'));
{$ENDIF}
{ ======================================== VK_KHR_mir_surface ======================================== }
{$IFDEF VK_USE_PLATFORM_MIR_KHR}
vkCreateMirSurfaceKHR := TvkCreateMirSurfaceKHR (GetProcAddress('vkCreateMirSurfaceKHR'));
vkGetPhysicalDeviceMirPresentationSupportKHR := TvkGetPhysicalDeviceMirPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceMirPresentationSupportKHR'));
{$ENDIF}
{ ====================================== VK_KHR_android_surface ====================================== }
{$IFDEF VK_USE_PLATFORM_ANDROID_KHR}
vkCreateAndroidSurfaceKHR := TvkCreateAndroidSurfaceKHR (GetProcAddress('vkCreateAndroidSurfaceKHR'));
{$ENDIF}
{ ======================================= VK_KHR_win32_surface ======================================= }
{$IFDEF VK_USE_PLATFORM_WIN32_KHR}
vkCreateWin32SurfaceKHR := TvkCreateWin32SurfaceKHR (GetProcAddress('vkCreateWin32SurfaceKHR'));
vkGetPhysicalDeviceWin32PresentationSupportKHR := TvkGetPhysicalDeviceWin32PresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceWin32PresentationSupportKHR'));
{$ENDIF}
{ ======================================= VK_EXT_debug_report ======================================== }
vkCreateDebugReportCallbackEXT := TvkCreateDebugReportCallbackEXT (GetProcAddress('vkCreateDebugReportCallbackEXT'));
vkDestroyDebugReportCallbackEXT := TvkDestroyDebugReportCallbackEXT (GetProcAddress('vkDestroyDebugReportCallbackEXT'));
vkDebugReportMessageEXT := TvkDebugReportMessageEXT (GetProcAddress('vkDebugReportMessageEXT'));

result := TVkInstanceCommands.Create;
try
result.Instance := aInstance;
with result do begin
{ ========================================== VK_VERSION_1_0 ========================================== }
vkDestroyInstance := TvkDestroyInstance (GetProcAddress('vkDestroyInstance'));
vkEnumeratePhysicalDevices := TvkEnumeratePhysicalDevices (GetProcAddress('vkEnumeratePhysicalDevices'));
vkGetPhysicalDeviceFeatures := TvkGetPhysicalDeviceFeatures (GetProcAddress('vkGetPhysicalDeviceFeatures'));
vkGetPhysicalDeviceFormatProperties := TvkGetPhysicalDeviceFormatProperties (GetProcAddress('vkGetPhysicalDeviceFormatProperties'));
vkGetPhysicalDeviceImageFormatProperties := TvkGetPhysicalDeviceImageFormatProperties (GetProcAddress('vkGetPhysicalDeviceImageFormatProperties'));
vkGetPhysicalDeviceProperties := TvkGetPhysicalDeviceProperties (GetProcAddress('vkGetPhysicalDeviceProperties'));
vkGetPhysicalDeviceQueueFamilyProperties := TvkGetPhysicalDeviceQueueFamilyProperties (GetProcAddress('vkGetPhysicalDeviceQueueFamilyProperties'));
vkGetPhysicalDeviceMemoryProperties := TvkGetPhysicalDeviceMemoryProperties (GetProcAddress('vkGetPhysicalDeviceMemoryProperties'));
vkGetDeviceProcAddr := TvkGetDeviceProcAddr (GetProcAddress('vkGetDeviceProcAddr'));
vkCreateDevice := TvkCreateDevice (GetProcAddress('vkCreateDevice'));
vkEnumerateDeviceExtensionProperties := TvkEnumerateDeviceExtensionProperties (GetProcAddress('vkEnumerateDeviceExtensionProperties'));
vkEnumerateDeviceLayerProperties := TvkEnumerateDeviceLayerProperties (GetProcAddress('vkEnumerateDeviceLayerProperties'));
vkGetPhysicalDeviceSparseImageFormatProperties := TvkGetPhysicalDeviceSparseImageFormatProperties (GetProcAddress('vkGetPhysicalDeviceSparseImageFormatProperties'));
{ ========================================== VK_KHR_surface ========================================== }
vkDestroySurfaceKHR := TvkDestroySurfaceKHR (GetProcAddress('vkDestroySurfaceKHR'));
vkGetPhysicalDeviceSurfaceSupportKHR := TvkGetPhysicalDeviceSurfaceSupportKHR (GetProcAddress('vkGetPhysicalDeviceSurfaceSupportKHR'));
vkGetPhysicalDeviceSurfaceCapabilitiesKHR := TvkGetPhysicalDeviceSurfaceCapabilitiesKHR (GetProcAddress('vkGetPhysicalDeviceSurfaceCapabilitiesKHR'));
vkGetPhysicalDeviceSurfaceFormatsKHR := TvkGetPhysicalDeviceSurfaceFormatsKHR (GetProcAddress('vkGetPhysicalDeviceSurfaceFormatsKHR'));
vkGetPhysicalDeviceSurfacePresentModesKHR := TvkGetPhysicalDeviceSurfacePresentModesKHR (GetProcAddress('vkGetPhysicalDeviceSurfacePresentModesKHR'));
{ ========================================== VK_KHR_display ========================================== }
vkGetPhysicalDeviceDisplayPropertiesKHR := TvkGetPhysicalDeviceDisplayPropertiesKHR (GetProcAddress('vkGetPhysicalDeviceDisplayPropertiesKHR'));
vkGetPhysicalDeviceDisplayPlanePropertiesKHR := TvkGetPhysicalDeviceDisplayPlanePropertiesKHR (GetProcAddress('vkGetPhysicalDeviceDisplayPlanePropertiesKHR'));
vkGetDisplayPlaneSupportedDisplaysKHR := TvkGetDisplayPlaneSupportedDisplaysKHR (GetProcAddress('vkGetDisplayPlaneSupportedDisplaysKHR'));
vkGetDisplayModePropertiesKHR := TvkGetDisplayModePropertiesKHR (GetProcAddress('vkGetDisplayModePropertiesKHR'));
vkCreateDisplayModeKHR := TvkCreateDisplayModeKHR (GetProcAddress('vkCreateDisplayModeKHR'));
vkGetDisplayPlaneCapabilitiesKHR := TvkGetDisplayPlaneCapabilitiesKHR (GetProcAddress('vkGetDisplayPlaneCapabilitiesKHR'));
vkCreateDisplayPlaneSurfaceKHR := TvkCreateDisplayPlaneSurfaceKHR (GetProcAddress('vkCreateDisplayPlaneSurfaceKHR'));
{ ======================================= VK_KHR_xlib_surface ======================================== }
{$IFDEF VK_USE_PLATFORM_XLIB_KHR}
vkCreateXlibSurfaceKHR := TvkCreateXlibSurfaceKHR (GetProcAddress('vkCreateXlibSurfaceKHR'));
vkGetPhysicalDeviceXlibPresentationSupportKHR := TvkGetPhysicalDeviceXlibPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceXlibPresentationSupportKHR'));
{$ENDIF}
{ ======================================== VK_KHR_xcb_surface ======================================== }
{$IFDEF VK_USE_PLATFORM_XCB_KHR}
vkCreateXcbSurfaceKHR := TvkCreateXcbSurfaceKHR (GetProcAddress('vkCreateXcbSurfaceKHR'));
vkGetPhysicalDeviceXcbPresentationSupportKHR := TvkGetPhysicalDeviceXcbPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceXcbPresentationSupportKHR'));
{$ENDIF}
{ ====================================== VK_KHR_wayland_surface ====================================== }
{$IFDEF VK_USE_PLATFORM_WAYLAND_KHR}
vkCreateWaylandSurfaceKHR := TvkCreateWaylandSurfaceKHR (GetProcAddress('vkCreateWaylandSurfaceKHR'));
vkGetPhysicalDeviceWaylandPresentationSupportKHR := TvkGetPhysicalDeviceWaylandPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceWaylandPresentationSupportKHR'));
{$ENDIF}
{ ======================================== VK_KHR_mir_surface ======================================== }
{$IFDEF VK_USE_PLATFORM_MIR_KHR}
vkCreateMirSurfaceKHR := TvkCreateMirSurfaceKHR (GetProcAddress('vkCreateMirSurfaceKHR'));
vkGetPhysicalDeviceMirPresentationSupportKHR := TvkGetPhysicalDeviceMirPresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceMirPresentationSupportKHR'));
{$ENDIF}
{ ====================================== VK_KHR_android_surface ====================================== }
{$IFDEF VK_USE_PLATFORM_ANDROID_KHR}
vkCreateAndroidSurfaceKHR := TvkCreateAndroidSurfaceKHR (GetProcAddress('vkCreateAndroidSurfaceKHR'));
{$ENDIF}
{ ======================================= VK_KHR_win32_surface ======================================= }
{$IFDEF VK_USE_PLATFORM_WIN32_KHR}
vkCreateWin32SurfaceKHR := TvkCreateWin32SurfaceKHR (GetProcAddress('vkCreateWin32SurfaceKHR'));
vkGetPhysicalDeviceWin32PresentationSupportKHR := TvkGetPhysicalDeviceWin32PresentationSupportKHR (GetProcAddress('vkGetPhysicalDeviceWin32PresentationSupportKHR'));
{$ENDIF}
{ ======================================= VK_EXT_debug_report ======================================== }
vkCreateDebugReportCallbackEXT := TvkCreateDebugReportCallbackEXT (GetProcAddress('vkCreateDebugReportCallbackEXT'));
vkDestroyDebugReportCallbackEXT := TvkDestroyDebugReportCallbackEXT (GetProcAddress('vkDestroyDebugReportCallbackEXT'));
vkDebugReportMessageEXT := TvkDebugReportMessageEXT (GetProcAddress('vkDebugReportMessageEXT'));

end;
except
FreeAndNil(result);
raise;
end;
result := success;
end;

function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice; out aCommands: TVkDeviceCommands): Boolean;
function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
var
vkGetDeviceProcAddr: TvkGetDeviceProcAddr;
success: Boolean;

function GetProcAddress(const aName: String): TvkVoidFunction;
begin
result := vkGetDeviceProcAddr(aDevice, PVkChar(aName));
if not Assigned(result) then
success := false;
end;

begin
FillByte(aCommands, SizeOf(aCommands), 0);
vkGetDeviceProcAddr := TvkGetDeviceProcAddr(vkGetInstanceProcAddr(aInstance, 'vkGetDeviceProcAddr'));
success := true;
with aCommands do begin
{ ========================================== VK_VERSION_1_0 ========================================== }
vkDestroyDevice := TvkDestroyDevice (GetProcAddress('vkDestroyDevice'));
vkGetDeviceQueue := TvkGetDeviceQueue (GetProcAddress('vkGetDeviceQueue'));
vkQueueSubmit := TvkQueueSubmit (GetProcAddress('vkQueueSubmit'));
vkQueueWaitIdle := TvkQueueWaitIdle (GetProcAddress('vkQueueWaitIdle'));
vkDeviceWaitIdle := TvkDeviceWaitIdle (GetProcAddress('vkDeviceWaitIdle'));
vkAllocateMemory := TvkAllocateMemory (GetProcAddress('vkAllocateMemory'));
vkFreeMemory := TvkFreeMemory (GetProcAddress('vkFreeMemory'));
vkMapMemory := TvkMapMemory (GetProcAddress('vkMapMemory'));
vkUnmapMemory := TvkUnmapMemory (GetProcAddress('vkUnmapMemory'));
vkFlushMappedMemoryRanges := TvkFlushMappedMemoryRanges (GetProcAddress('vkFlushMappedMemoryRanges'));
vkInvalidateMappedMemoryRanges := TvkInvalidateMappedMemoryRanges (GetProcAddress('vkInvalidateMappedMemoryRanges'));
vkGetDeviceMemoryCommitment := TvkGetDeviceMemoryCommitment (GetProcAddress('vkGetDeviceMemoryCommitment'));
vkBindBufferMemory := TvkBindBufferMemory (GetProcAddress('vkBindBufferMemory'));
vkBindImageMemory := TvkBindImageMemory (GetProcAddress('vkBindImageMemory'));
vkGetBufferMemoryRequirements := TvkGetBufferMemoryRequirements (GetProcAddress('vkGetBufferMemoryRequirements'));
vkGetImageMemoryRequirements := TvkGetImageMemoryRequirements (GetProcAddress('vkGetImageMemoryRequirements'));
vkGetImageSparseMemoryRequirements := TvkGetImageSparseMemoryRequirements (GetProcAddress('vkGetImageSparseMemoryRequirements'));
vkQueueBindSparse := TvkQueueBindSparse (GetProcAddress('vkQueueBindSparse'));
vkCreateFence := TvkCreateFence (GetProcAddress('vkCreateFence'));
vkDestroyFence := TvkDestroyFence (GetProcAddress('vkDestroyFence'));
vkResetFences := TvkResetFences (GetProcAddress('vkResetFences'));
vkGetFenceStatus := TvkGetFenceStatus (GetProcAddress('vkGetFenceStatus'));
vkWaitForFences := TvkWaitForFences (GetProcAddress('vkWaitForFences'));
vkCreateSemaphore := TvkCreateSemaphore (GetProcAddress('vkCreateSemaphore'));
vkDestroySemaphore := TvkDestroySemaphore (GetProcAddress('vkDestroySemaphore'));
vkCreateEvent := TvkCreateEvent (GetProcAddress('vkCreateEvent'));
vkDestroyEvent := TvkDestroyEvent (GetProcAddress('vkDestroyEvent'));
vkGetEventStatus := TvkGetEventStatus (GetProcAddress('vkGetEventStatus'));
vkSetEvent := TvkSetEvent (GetProcAddress('vkSetEvent'));
vkResetEvent := TvkResetEvent (GetProcAddress('vkResetEvent'));
vkCreateQueryPool := TvkCreateQueryPool (GetProcAddress('vkCreateQueryPool'));
vkDestroyQueryPool := TvkDestroyQueryPool (GetProcAddress('vkDestroyQueryPool'));
vkGetQueryPoolResults := TvkGetQueryPoolResults (GetProcAddress('vkGetQueryPoolResults'));
vkCreateBuffer := TvkCreateBuffer (GetProcAddress('vkCreateBuffer'));
vkDestroyBuffer := TvkDestroyBuffer (GetProcAddress('vkDestroyBuffer'));
vkCreateBufferView := TvkCreateBufferView (GetProcAddress('vkCreateBufferView'));
vkDestroyBufferView := TvkDestroyBufferView (GetProcAddress('vkDestroyBufferView'));
vkCreateImage := TvkCreateImage (GetProcAddress('vkCreateImage'));
vkDestroyImage := TvkDestroyImage (GetProcAddress('vkDestroyImage'));
vkGetImageSubresourceLayout := TvkGetImageSubresourceLayout (GetProcAddress('vkGetImageSubresourceLayout'));
vkCreateImageView := TvkCreateImageView (GetProcAddress('vkCreateImageView'));
vkDestroyImageView := TvkDestroyImageView (GetProcAddress('vkDestroyImageView'));
vkCreateShaderModule := TvkCreateShaderModule (GetProcAddress('vkCreateShaderModule'));
vkDestroyShaderModule := TvkDestroyShaderModule (GetProcAddress('vkDestroyShaderModule'));
vkCreatePipelineCache := TvkCreatePipelineCache (GetProcAddress('vkCreatePipelineCache'));
vkDestroyPipelineCache := TvkDestroyPipelineCache (GetProcAddress('vkDestroyPipelineCache'));
vkGetPipelineCacheData := TvkGetPipelineCacheData (GetProcAddress('vkGetPipelineCacheData'));
vkMergePipelineCaches := TvkMergePipelineCaches (GetProcAddress('vkMergePipelineCaches'));
vkCreateGraphicsPipelines := TvkCreateGraphicsPipelines (GetProcAddress('vkCreateGraphicsPipelines'));
vkCreateComputePipelines := TvkCreateComputePipelines (GetProcAddress('vkCreateComputePipelines'));
vkDestroyPipeline := TvkDestroyPipeline (GetProcAddress('vkDestroyPipeline'));
vkCreatePipelineLayout := TvkCreatePipelineLayout (GetProcAddress('vkCreatePipelineLayout'));
vkDestroyPipelineLayout := TvkDestroyPipelineLayout (GetProcAddress('vkDestroyPipelineLayout'));
vkCreateSampler := TvkCreateSampler (GetProcAddress('vkCreateSampler'));
vkDestroySampler := TvkDestroySampler (GetProcAddress('vkDestroySampler'));
vkCreateDescriptorSetLayout := TvkCreateDescriptorSetLayout (GetProcAddress('vkCreateDescriptorSetLayout'));
vkDestroyDescriptorSetLayout := TvkDestroyDescriptorSetLayout (GetProcAddress('vkDestroyDescriptorSetLayout'));
vkCreateDescriptorPool := TvkCreateDescriptorPool (GetProcAddress('vkCreateDescriptorPool'));
vkDestroyDescriptorPool := TvkDestroyDescriptorPool (GetProcAddress('vkDestroyDescriptorPool'));
vkResetDescriptorPool := TvkResetDescriptorPool (GetProcAddress('vkResetDescriptorPool'));
vkAllocateDescriptorSets := TvkAllocateDescriptorSets (GetProcAddress('vkAllocateDescriptorSets'));
vkFreeDescriptorSets := TvkFreeDescriptorSets (GetProcAddress('vkFreeDescriptorSets'));
vkUpdateDescriptorSets := TvkUpdateDescriptorSets (GetProcAddress('vkUpdateDescriptorSets'));
vkCreateFramebuffer := TvkCreateFramebuffer (GetProcAddress('vkCreateFramebuffer'));
vkDestroyFramebuffer := TvkDestroyFramebuffer (GetProcAddress('vkDestroyFramebuffer'));
vkCreateRenderPass := TvkCreateRenderPass (GetProcAddress('vkCreateRenderPass'));
vkDestroyRenderPass := TvkDestroyRenderPass (GetProcAddress('vkDestroyRenderPass'));
vkGetRenderAreaGranularity := TvkGetRenderAreaGranularity (GetProcAddress('vkGetRenderAreaGranularity'));
vkCreateCommandPool := TvkCreateCommandPool (GetProcAddress('vkCreateCommandPool'));
vkDestroyCommandPool := TvkDestroyCommandPool (GetProcAddress('vkDestroyCommandPool'));
vkResetCommandPool := TvkResetCommandPool (GetProcAddress('vkResetCommandPool'));
vkAllocateCommandBuffers := TvkAllocateCommandBuffers (GetProcAddress('vkAllocateCommandBuffers'));
vkFreeCommandBuffers := TvkFreeCommandBuffers (GetProcAddress('vkFreeCommandBuffers'));
vkBeginCommandBuffer := TvkBeginCommandBuffer (GetProcAddress('vkBeginCommandBuffer'));
vkEndCommandBuffer := TvkEndCommandBuffer (GetProcAddress('vkEndCommandBuffer'));
vkResetCommandBuffer := TvkResetCommandBuffer (GetProcAddress('vkResetCommandBuffer'));
vkCmdBindPipeline := TvkCmdBindPipeline (GetProcAddress('vkCmdBindPipeline'));
vkCmdSetViewport := TvkCmdSetViewport (GetProcAddress('vkCmdSetViewport'));
vkCmdSetScissor := TvkCmdSetScissor (GetProcAddress('vkCmdSetScissor'));
vkCmdSetLineWidth := TvkCmdSetLineWidth (GetProcAddress('vkCmdSetLineWidth'));
vkCmdSetDepthBias := TvkCmdSetDepthBias (GetProcAddress('vkCmdSetDepthBias'));
vkCmdSetBlendConstants := TvkCmdSetBlendConstants (GetProcAddress('vkCmdSetBlendConstants'));
vkCmdSetDepthBounds := TvkCmdSetDepthBounds (GetProcAddress('vkCmdSetDepthBounds'));
vkCmdSetStencilCompareMask := TvkCmdSetStencilCompareMask (GetProcAddress('vkCmdSetStencilCompareMask'));
vkCmdSetStencilWriteMask := TvkCmdSetStencilWriteMask (GetProcAddress('vkCmdSetStencilWriteMask'));
vkCmdSetStencilReference := TvkCmdSetStencilReference (GetProcAddress('vkCmdSetStencilReference'));
vkCmdBindDescriptorSets := TvkCmdBindDescriptorSets (GetProcAddress('vkCmdBindDescriptorSets'));
vkCmdBindIndexBuffer := TvkCmdBindIndexBuffer (GetProcAddress('vkCmdBindIndexBuffer'));
vkCmdBindVertexBuffers := TvkCmdBindVertexBuffers (GetProcAddress('vkCmdBindVertexBuffers'));
vkCmdDraw := TvkCmdDraw (GetProcAddress('vkCmdDraw'));
vkCmdDrawIndexed := TvkCmdDrawIndexed (GetProcAddress('vkCmdDrawIndexed'));
vkCmdDrawIndirect := TvkCmdDrawIndirect (GetProcAddress('vkCmdDrawIndirect'));
vkCmdDrawIndexedIndirect := TvkCmdDrawIndexedIndirect (GetProcAddress('vkCmdDrawIndexedIndirect'));
vkCmdDispatch := TvkCmdDispatch (GetProcAddress('vkCmdDispatch'));
vkCmdDispatchIndirect := TvkCmdDispatchIndirect (GetProcAddress('vkCmdDispatchIndirect'));
vkCmdCopyBuffer := TvkCmdCopyBuffer (GetProcAddress('vkCmdCopyBuffer'));
vkCmdCopyImage := TvkCmdCopyImage (GetProcAddress('vkCmdCopyImage'));
vkCmdBlitImage := TvkCmdBlitImage (GetProcAddress('vkCmdBlitImage'));
vkCmdCopyBufferToImage := TvkCmdCopyBufferToImage (GetProcAddress('vkCmdCopyBufferToImage'));
vkCmdCopyImageToBuffer := TvkCmdCopyImageToBuffer (GetProcAddress('vkCmdCopyImageToBuffer'));
vkCmdUpdateBuffer := TvkCmdUpdateBuffer (GetProcAddress('vkCmdUpdateBuffer'));
vkCmdFillBuffer := TvkCmdFillBuffer (GetProcAddress('vkCmdFillBuffer'));
vkCmdClearColorImage := TvkCmdClearColorImage (GetProcAddress('vkCmdClearColorImage'));
vkCmdClearDepthStencilImage := TvkCmdClearDepthStencilImage (GetProcAddress('vkCmdClearDepthStencilImage'));
vkCmdClearAttachments := TvkCmdClearAttachments (GetProcAddress('vkCmdClearAttachments'));
vkCmdResolveImage := TvkCmdResolveImage (GetProcAddress('vkCmdResolveImage'));
vkCmdSetEvent := TvkCmdSetEvent (GetProcAddress('vkCmdSetEvent'));
vkCmdResetEvent := TvkCmdResetEvent (GetProcAddress('vkCmdResetEvent'));
vkCmdWaitEvents := TvkCmdWaitEvents (GetProcAddress('vkCmdWaitEvents'));
vkCmdPipelineBarrier := TvkCmdPipelineBarrier (GetProcAddress('vkCmdPipelineBarrier'));
vkCmdBeginQuery := TvkCmdBeginQuery (GetProcAddress('vkCmdBeginQuery'));
vkCmdEndQuery := TvkCmdEndQuery (GetProcAddress('vkCmdEndQuery'));
vkCmdResetQueryPool := TvkCmdResetQueryPool (GetProcAddress('vkCmdResetQueryPool'));
vkCmdWriteTimestamp := TvkCmdWriteTimestamp (GetProcAddress('vkCmdWriteTimestamp'));
vkCmdCopyQueryPoolResults := TvkCmdCopyQueryPoolResults (GetProcAddress('vkCmdCopyQueryPoolResults'));
vkCmdPushConstants := TvkCmdPushConstants (GetProcAddress('vkCmdPushConstants'));
vkCmdBeginRenderPass := TvkCmdBeginRenderPass (GetProcAddress('vkCmdBeginRenderPass'));
vkCmdNextSubpass := TvkCmdNextSubpass (GetProcAddress('vkCmdNextSubpass'));
vkCmdEndRenderPass := TvkCmdEndRenderPass (GetProcAddress('vkCmdEndRenderPass'));
vkCmdExecuteCommands := TvkCmdExecuteCommands (GetProcAddress('vkCmdExecuteCommands'));
{ ========================================= VK_KHR_swapchain ========================================= }
vkCreateSwapchainKHR := TvkCreateSwapchainKHR (GetProcAddress('vkCreateSwapchainKHR'));
vkDestroySwapchainKHR := TvkDestroySwapchainKHR (GetProcAddress('vkDestroySwapchainKHR'));
vkGetSwapchainImagesKHR := TvkGetSwapchainImagesKHR (GetProcAddress('vkGetSwapchainImagesKHR'));
vkAcquireNextImageKHR := TvkAcquireNextImageKHR (GetProcAddress('vkAcquireNextImageKHR'));
vkQueuePresentKHR := TvkQueuePresentKHR (GetProcAddress('vkQueuePresentKHR'));
{ ===================================== VK_KHR_display_swapchain ===================================== }
vkCreateSharedSwapchainsKHR := TvkCreateSharedSwapchainsKHR (GetProcAddress('vkCreateSharedSwapchainsKHR'));

result := TVkDeviceCommands.Create;
try
result.Device := aDevice;
with result do begin
{ ========================================== VK_VERSION_1_0 ========================================== }
vkDestroyDevice := TvkDestroyDevice (GetProcAddress('vkDestroyDevice'));
vkGetDeviceQueue := TvkGetDeviceQueue (GetProcAddress('vkGetDeviceQueue'));
vkQueueSubmit := TvkQueueSubmit (GetProcAddress('vkQueueSubmit'));
vkQueueWaitIdle := TvkQueueWaitIdle (GetProcAddress('vkQueueWaitIdle'));
vkDeviceWaitIdle := TvkDeviceWaitIdle (GetProcAddress('vkDeviceWaitIdle'));
vkAllocateMemory := TvkAllocateMemory (GetProcAddress('vkAllocateMemory'));
vkFreeMemory := TvkFreeMemory (GetProcAddress('vkFreeMemory'));
vkMapMemory := TvkMapMemory (GetProcAddress('vkMapMemory'));
vkUnmapMemory := TvkUnmapMemory (GetProcAddress('vkUnmapMemory'));
vkFlushMappedMemoryRanges := TvkFlushMappedMemoryRanges (GetProcAddress('vkFlushMappedMemoryRanges'));
vkInvalidateMappedMemoryRanges := TvkInvalidateMappedMemoryRanges (GetProcAddress('vkInvalidateMappedMemoryRanges'));
vkGetDeviceMemoryCommitment := TvkGetDeviceMemoryCommitment (GetProcAddress('vkGetDeviceMemoryCommitment'));
vkBindBufferMemory := TvkBindBufferMemory (GetProcAddress('vkBindBufferMemory'));
vkBindImageMemory := TvkBindImageMemory (GetProcAddress('vkBindImageMemory'));
vkGetBufferMemoryRequirements := TvkGetBufferMemoryRequirements (GetProcAddress('vkGetBufferMemoryRequirements'));
vkGetImageMemoryRequirements := TvkGetImageMemoryRequirements (GetProcAddress('vkGetImageMemoryRequirements'));
vkGetImageSparseMemoryRequirements := TvkGetImageSparseMemoryRequirements (GetProcAddress('vkGetImageSparseMemoryRequirements'));
vkQueueBindSparse := TvkQueueBindSparse (GetProcAddress('vkQueueBindSparse'));
vkCreateFence := TvkCreateFence (GetProcAddress('vkCreateFence'));
vkDestroyFence := TvkDestroyFence (GetProcAddress('vkDestroyFence'));
vkResetFences := TvkResetFences (GetProcAddress('vkResetFences'));
vkGetFenceStatus := TvkGetFenceStatus (GetProcAddress('vkGetFenceStatus'));
vkWaitForFences := TvkWaitForFences (GetProcAddress('vkWaitForFences'));
vkCreateSemaphore := TvkCreateSemaphore (GetProcAddress('vkCreateSemaphore'));
vkDestroySemaphore := TvkDestroySemaphore (GetProcAddress('vkDestroySemaphore'));
vkCreateEvent := TvkCreateEvent (GetProcAddress('vkCreateEvent'));
vkDestroyEvent := TvkDestroyEvent (GetProcAddress('vkDestroyEvent'));
vkGetEventStatus := TvkGetEventStatus (GetProcAddress('vkGetEventStatus'));
vkSetEvent := TvkSetEvent (GetProcAddress('vkSetEvent'));
vkResetEvent := TvkResetEvent (GetProcAddress('vkResetEvent'));
vkCreateQueryPool := TvkCreateQueryPool (GetProcAddress('vkCreateQueryPool'));
vkDestroyQueryPool := TvkDestroyQueryPool (GetProcAddress('vkDestroyQueryPool'));
vkGetQueryPoolResults := TvkGetQueryPoolResults (GetProcAddress('vkGetQueryPoolResults'));
vkCreateBuffer := TvkCreateBuffer (GetProcAddress('vkCreateBuffer'));
vkDestroyBuffer := TvkDestroyBuffer (GetProcAddress('vkDestroyBuffer'));
vkCreateBufferView := TvkCreateBufferView (GetProcAddress('vkCreateBufferView'));
vkDestroyBufferView := TvkDestroyBufferView (GetProcAddress('vkDestroyBufferView'));
vkCreateImage := TvkCreateImage (GetProcAddress('vkCreateImage'));
vkDestroyImage := TvkDestroyImage (GetProcAddress('vkDestroyImage'));
vkGetImageSubresourceLayout := TvkGetImageSubresourceLayout (GetProcAddress('vkGetImageSubresourceLayout'));
vkCreateImageView := TvkCreateImageView (GetProcAddress('vkCreateImageView'));
vkDestroyImageView := TvkDestroyImageView (GetProcAddress('vkDestroyImageView'));
vkCreateShaderModule := TvkCreateShaderModule (GetProcAddress('vkCreateShaderModule'));
vkDestroyShaderModule := TvkDestroyShaderModule (GetProcAddress('vkDestroyShaderModule'));
vkCreatePipelineCache := TvkCreatePipelineCache (GetProcAddress('vkCreatePipelineCache'));
vkDestroyPipelineCache := TvkDestroyPipelineCache (GetProcAddress('vkDestroyPipelineCache'));
vkGetPipelineCacheData := TvkGetPipelineCacheData (GetProcAddress('vkGetPipelineCacheData'));
vkMergePipelineCaches := TvkMergePipelineCaches (GetProcAddress('vkMergePipelineCaches'));
vkCreateGraphicsPipelines := TvkCreateGraphicsPipelines (GetProcAddress('vkCreateGraphicsPipelines'));
vkCreateComputePipelines := TvkCreateComputePipelines (GetProcAddress('vkCreateComputePipelines'));
vkDestroyPipeline := TvkDestroyPipeline (GetProcAddress('vkDestroyPipeline'));
vkCreatePipelineLayout := TvkCreatePipelineLayout (GetProcAddress('vkCreatePipelineLayout'));
vkDestroyPipelineLayout := TvkDestroyPipelineLayout (GetProcAddress('vkDestroyPipelineLayout'));
vkCreateSampler := TvkCreateSampler (GetProcAddress('vkCreateSampler'));
vkDestroySampler := TvkDestroySampler (GetProcAddress('vkDestroySampler'));
vkCreateDescriptorSetLayout := TvkCreateDescriptorSetLayout (GetProcAddress('vkCreateDescriptorSetLayout'));
vkDestroyDescriptorSetLayout := TvkDestroyDescriptorSetLayout (GetProcAddress('vkDestroyDescriptorSetLayout'));
vkCreateDescriptorPool := TvkCreateDescriptorPool (GetProcAddress('vkCreateDescriptorPool'));
vkDestroyDescriptorPool := TvkDestroyDescriptorPool (GetProcAddress('vkDestroyDescriptorPool'));
vkResetDescriptorPool := TvkResetDescriptorPool (GetProcAddress('vkResetDescriptorPool'));
vkAllocateDescriptorSets := TvkAllocateDescriptorSets (GetProcAddress('vkAllocateDescriptorSets'));
vkFreeDescriptorSets := TvkFreeDescriptorSets (GetProcAddress('vkFreeDescriptorSets'));
vkUpdateDescriptorSets := TvkUpdateDescriptorSets (GetProcAddress('vkUpdateDescriptorSets'));
vkCreateFramebuffer := TvkCreateFramebuffer (GetProcAddress('vkCreateFramebuffer'));
vkDestroyFramebuffer := TvkDestroyFramebuffer (GetProcAddress('vkDestroyFramebuffer'));
vkCreateRenderPass := TvkCreateRenderPass (GetProcAddress('vkCreateRenderPass'));
vkDestroyRenderPass := TvkDestroyRenderPass (GetProcAddress('vkDestroyRenderPass'));
vkGetRenderAreaGranularity := TvkGetRenderAreaGranularity (GetProcAddress('vkGetRenderAreaGranularity'));
vkCreateCommandPool := TvkCreateCommandPool (GetProcAddress('vkCreateCommandPool'));
vkDestroyCommandPool := TvkDestroyCommandPool (GetProcAddress('vkDestroyCommandPool'));
vkResetCommandPool := TvkResetCommandPool (GetProcAddress('vkResetCommandPool'));
vkAllocateCommandBuffers := TvkAllocateCommandBuffers (GetProcAddress('vkAllocateCommandBuffers'));
vkFreeCommandBuffers := TvkFreeCommandBuffers (GetProcAddress('vkFreeCommandBuffers'));
vkBeginCommandBuffer := TvkBeginCommandBuffer (GetProcAddress('vkBeginCommandBuffer'));
vkEndCommandBuffer := TvkEndCommandBuffer (GetProcAddress('vkEndCommandBuffer'));
vkResetCommandBuffer := TvkResetCommandBuffer (GetProcAddress('vkResetCommandBuffer'));
vkCmdBindPipeline := TvkCmdBindPipeline (GetProcAddress('vkCmdBindPipeline'));
vkCmdSetViewport := TvkCmdSetViewport (GetProcAddress('vkCmdSetViewport'));
vkCmdSetScissor := TvkCmdSetScissor (GetProcAddress('vkCmdSetScissor'));
vkCmdSetLineWidth := TvkCmdSetLineWidth (GetProcAddress('vkCmdSetLineWidth'));
vkCmdSetDepthBias := TvkCmdSetDepthBias (GetProcAddress('vkCmdSetDepthBias'));
vkCmdSetBlendConstants := TvkCmdSetBlendConstants (GetProcAddress('vkCmdSetBlendConstants'));
vkCmdSetDepthBounds := TvkCmdSetDepthBounds (GetProcAddress('vkCmdSetDepthBounds'));
vkCmdSetStencilCompareMask := TvkCmdSetStencilCompareMask (GetProcAddress('vkCmdSetStencilCompareMask'));
vkCmdSetStencilWriteMask := TvkCmdSetStencilWriteMask (GetProcAddress('vkCmdSetStencilWriteMask'));
vkCmdSetStencilReference := TvkCmdSetStencilReference (GetProcAddress('vkCmdSetStencilReference'));
vkCmdBindDescriptorSets := TvkCmdBindDescriptorSets (GetProcAddress('vkCmdBindDescriptorSets'));
vkCmdBindIndexBuffer := TvkCmdBindIndexBuffer (GetProcAddress('vkCmdBindIndexBuffer'));
vkCmdBindVertexBuffers := TvkCmdBindVertexBuffers (GetProcAddress('vkCmdBindVertexBuffers'));
vkCmdDraw := TvkCmdDraw (GetProcAddress('vkCmdDraw'));
vkCmdDrawIndexed := TvkCmdDrawIndexed (GetProcAddress('vkCmdDrawIndexed'));
vkCmdDrawIndirect := TvkCmdDrawIndirect (GetProcAddress('vkCmdDrawIndirect'));
vkCmdDrawIndexedIndirect := TvkCmdDrawIndexedIndirect (GetProcAddress('vkCmdDrawIndexedIndirect'));
vkCmdDispatch := TvkCmdDispatch (GetProcAddress('vkCmdDispatch'));
vkCmdDispatchIndirect := TvkCmdDispatchIndirect (GetProcAddress('vkCmdDispatchIndirect'));
vkCmdCopyBuffer := TvkCmdCopyBuffer (GetProcAddress('vkCmdCopyBuffer'));
vkCmdCopyImage := TvkCmdCopyImage (GetProcAddress('vkCmdCopyImage'));
vkCmdBlitImage := TvkCmdBlitImage (GetProcAddress('vkCmdBlitImage'));
vkCmdCopyBufferToImage := TvkCmdCopyBufferToImage (GetProcAddress('vkCmdCopyBufferToImage'));
vkCmdCopyImageToBuffer := TvkCmdCopyImageToBuffer (GetProcAddress('vkCmdCopyImageToBuffer'));
vkCmdUpdateBuffer := TvkCmdUpdateBuffer (GetProcAddress('vkCmdUpdateBuffer'));
vkCmdFillBuffer := TvkCmdFillBuffer (GetProcAddress('vkCmdFillBuffer'));
vkCmdClearColorImage := TvkCmdClearColorImage (GetProcAddress('vkCmdClearColorImage'));
vkCmdClearDepthStencilImage := TvkCmdClearDepthStencilImage (GetProcAddress('vkCmdClearDepthStencilImage'));
vkCmdClearAttachments := TvkCmdClearAttachments (GetProcAddress('vkCmdClearAttachments'));
vkCmdResolveImage := TvkCmdResolveImage (GetProcAddress('vkCmdResolveImage'));
vkCmdSetEvent := TvkCmdSetEvent (GetProcAddress('vkCmdSetEvent'));
vkCmdResetEvent := TvkCmdResetEvent (GetProcAddress('vkCmdResetEvent'));
vkCmdWaitEvents := TvkCmdWaitEvents (GetProcAddress('vkCmdWaitEvents'));
vkCmdPipelineBarrier := TvkCmdPipelineBarrier (GetProcAddress('vkCmdPipelineBarrier'));
vkCmdBeginQuery := TvkCmdBeginQuery (GetProcAddress('vkCmdBeginQuery'));
vkCmdEndQuery := TvkCmdEndQuery (GetProcAddress('vkCmdEndQuery'));
vkCmdResetQueryPool := TvkCmdResetQueryPool (GetProcAddress('vkCmdResetQueryPool'));
vkCmdWriteTimestamp := TvkCmdWriteTimestamp (GetProcAddress('vkCmdWriteTimestamp'));
vkCmdCopyQueryPoolResults := TvkCmdCopyQueryPoolResults (GetProcAddress('vkCmdCopyQueryPoolResults'));
vkCmdPushConstants := TvkCmdPushConstants (GetProcAddress('vkCmdPushConstants'));
vkCmdBeginRenderPass := TvkCmdBeginRenderPass (GetProcAddress('vkCmdBeginRenderPass'));
vkCmdNextSubpass := TvkCmdNextSubpass (GetProcAddress('vkCmdNextSubpass'));
vkCmdEndRenderPass := TvkCmdEndRenderPass (GetProcAddress('vkCmdEndRenderPass'));
vkCmdExecuteCommands := TvkCmdExecuteCommands (GetProcAddress('vkCmdExecuteCommands'));
{ ========================================= VK_KHR_swapchain ========================================= }
vkCreateSwapchainKHR := TvkCreateSwapchainKHR (GetProcAddress('vkCreateSwapchainKHR'));
vkDestroySwapchainKHR := TvkDestroySwapchainKHR (GetProcAddress('vkDestroySwapchainKHR'));
vkGetSwapchainImagesKHR := TvkGetSwapchainImagesKHR (GetProcAddress('vkGetSwapchainImagesKHR'));
vkAcquireNextImageKHR := TvkAcquireNextImageKHR (GetProcAddress('vkAcquireNextImageKHR'));
vkQueuePresentKHR := TvkQueuePresentKHR (GetProcAddress('vkQueuePresentKHR'));
{ ===================================== VK_KHR_display_swapchain ===================================== }
vkCreateSharedSwapchainsKHR := TvkCreateSharedSwapchainsKHR (GetProcAddress('vkCreateSharedSwapchainsKHR'));

end;
except
FreeAndNil(result);
raise;
end;
result := success;
end;

procedure FinalizeVulkan;


+ 1
- 0
projects/generator/generate.bat 查看文件

@@ -0,0 +1 @@
generator-i386-win32.exe -i ..\..\data\vk.xml -t ..\..\data\vulkan.tpl -o ..\Vulkan.pas

+ 2
- 2
projects/generator/generator.lps 查看文件

@@ -15,6 +15,7 @@
<Unit1>
<Filename Value="HeaderGenerator.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
@@ -29,9 +30,8 @@
</Unit2>
<Unit3>
<Filename Value="..\Vulkan.pas"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<TopLine Value="4423"/>
<TopLine Value="3935"/>
<CursorPos X="33" Y="4655"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>


+ 14
- 5
projects/triangle/triangle.lpi 查看文件

@@ -33,7 +33,7 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="11">
<Units Count="12">
<Unit0>
<Filename Value="triangle.lpr"/>
<IsPartOfProject Value="True"/>
@@ -54,15 +54,15 @@
<IsPartOfProject Value="True"/>
</Unit3>
<Unit4>
<Filename Value="..\utils\uvkuUtils.pas"/>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit4>
<Unit5>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<IsPartOfProject Value="True"/>
</Unit5>
<Unit6>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<IsPartOfProject Value="True"/>
</Unit6>
<Unit7>
@@ -78,9 +78,13 @@
<IsPartOfProject Value="True"/>
</Unit9>
<Unit10>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<IsPartOfProject Value="True"/>
</Unit10>
<Unit11>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<IsPartOfProject Value="True"/>
</Unit11>
</Units>
</ProjectOptions>
<CompilerOptions>
@@ -105,6 +109,11 @@
</Win32>
</Options>
</Linking>
<Other>
<CompilerMessages>
<IgnoredMessages idx5024="True"/>
</CompilerMessages>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">


+ 1
- 2
projects/triangle/triangle.lpr 查看文件

@@ -7,8 +7,7 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, Dialogs, Forms, uMainForm, Vulkan, uvkuDevice, uvkuDeviceFactory, uvkuPhysicalDeviceFactory,
uvkuAllocationHandler;
Interfaces, Dialogs, Forms, uMainForm, Vulkan, uvkuDevice, uvkuDeviceFactory;

{$R *.res}



+ 241
- 140
projects/triangle/triangle.lps 查看文件

@@ -4,13 +4,14 @@
<PathDelim Value="\"/>
<Version Value="9"/>
<BuildModes Active="Default"/>
<Units Count="17">
<Units Count="30">
<Unit0>
<Filename Value="triangle.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="44" Y="22"/>
<UsageCount Value="40"/>
<EditorIndex Value="7"/>
<CursorPos X="79" Y="10"/>
<UsageCount Value="51"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="uMainForm.pas"/>
@@ -18,253 +19,353 @@
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<EditorIndex Value="-1"/>
<TopLine Value="64"/>
<CursorPos Y="75"/>
<UsageCount Value="40"/>
<IsVisibleTab Value="True"/>
<TopLine Value="65"/>
<CursorPos X="28" Y="79"/>
<UsageCount Value="51"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
<Unit2>
<Filename Value="..\Vulkan.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="1480"/>
<CursorPos X="13" Y="1486"/>
<UsageCount Value="40"/>
<EditorIndex Value="5"/>
<TopLine Value="163"/>
<CursorPos X="63" Y="188"/>
<ExtraEditorCount Value="1"/>
<ExtraEditor1>
<EditorIndex Value="-1"/>
<TopLine Value="4282"/>
<CursorPos X="79" Y="4295"/>
</ExtraEditor1>
<UsageCount Value="51"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
<Filename Value="..\utils\uvkuInstance.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="83"/>
<CursorPos Y="96"/>
<UsageCount Value="38"/>
<EditorIndex Value="8"/>
<TopLine Value="12"/>
<CursorPos X="10" Y="24"/>
<UsageCount Value="49"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="..\utils\uvkuUtils.pas"/>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="28"/>
<CursorPos Y="40"/>
<UsageCount Value="35"/>
<EditorIndex Value="4"/>
<CursorPos X="58" Y="160"/>
<UsageCount Value="43"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="..\utils\uvkuInstanceFactory.pas"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="77"/>
<CursorPos Y="97"/>
<UsageCount Value="32"/>
<EditorIndex Value="10"/>
<TopLine Value="241"/>
<CursorPos Y="250"/>
<UsageCount Value="43"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="2"/>
<TopLine Value="40"/>
<CursorPos X="14" Y="18"/>
<UsageCount Value="32"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="73"/>
<CursorPos X="23" Y="93"/>
<UsageCount Value="33"/>
</Unit6>
<Unit7>
<Filename Value="..\utils\uvkuDevice.pas"/>
<IsPartOfProject Value="True"/>
<Filename Value="..\utils\uvkuUtils.pas"/>
<EditorIndex Value="-1"/>
<CursorPos X="29" Y="60"/>
<UsageCount Value="28"/>
<UsageCount Value="43"/>
</Unit7>
<Unit8>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="17"/>
<CursorPos X="38" Y="223"/>
<UsageCount Value="26"/>
<EditorIndex Value="1"/>
<TopLine Value="18"/>
<CursorPos X="17" Y="32"/>
<UsageCount Value="36"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos Y="16"/>
<UsageCount Value="26"/>
<EditorIndex Value="2"/>
<TopLine Value="44"/>
<CursorPos X="73" Y="58"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="..\utils\uvkuAllocationHandler.pas"/>
<Filename Value="..\utils\uvkuPhysicalDeviceFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="73"/>
<CursorPos Y="100"/>
<UsageCount Value="22"/>
<EditorIndex Value="9"/>
<CursorPos X="74" Y="30"/>
<UsageCount Value="35"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="..\utils\uvkuSurface.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="3"/>
<CursorPos Y="59"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit11>
<Unit12>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="6"/>
<TopLine Value="9"/>
<CursorPos X="20" Y="18"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
<Filename Value="..\..\data\Vulkan.tpl"/>
<EditorIndex Value="-1"/>
<TopLine Value="44"/>
<CursorPos X="27" Y="22"/>
<UsageCount Value="14"/>
<DefaultSyntaxHighlighter Value="None"/>
</Unit11>
<Unit12>
</Unit13>
<Unit14>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\packages\fcl-base\src\custapp.pp"/>
<UnitName Value="CustApp"/>
<EditorIndex Value="-1"/>
<TopLine Value="72"/>
<CursorPos X="14" Y="86"/>
<UsageCount Value="9"/>
</Unit12>
<Unit13>
<TopLine Value="13"/>
<CursorPos X="3" Y="30"/>
<UsageCount Value="10"/>
</Unit14>
<Unit15>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\inc\objpash.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="213"/>
<CursorPos X="21" Y="224"/>
<UsageCount Value="9"/>
</Unit13>
<Unit14>
</Unit15>
<Unit16>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\include\customform.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="138"/>
<CursorPos Y="154"/>
<UsageCount Value="9"/>
</Unit14>
<Unit15>
</Unit16>
<Unit17>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\sysstrh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="96"/>
<CursorPos X="10" Y="112"/>
<UsageCount Value="10"/>
</Unit15>
<Unit16>
</Unit17>
<Unit18>
<Filename Value="..\Vulkan_old.pas"/>
<IsVisibleTab Value="True"/>
<WindowIndex Value="1"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="2195"/>
<CursorPos X="3" Y="2211"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit16>
</Unit18>
<Unit19>
<Filename Value="..\Vulkan.inc"/>
<EditorIndex Value="-1"/>
<CursorPos X="9" Y="5"/>
<UsageCount Value="11"/>
</Unit19>
<Unit20>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\forms.pp"/>
<UnitName Value="Forms"/>
<EditorIndex Value="-1"/>
<TopLine Value="1249"/>
<CursorPos X="3" Y="1268"/>
<UsageCount Value="10"/>
</Unit20>
<Unit21>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\classes\classesh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="2100"/>
<CursorPos X="38" Y="2125"/>
<UsageCount Value="10"/>
</Unit21>
<Unit22>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\extctrls.pp"/>
<UnitName Value="ExtCtrls"/>
<EditorIndex Value="-1"/>
<TopLine Value="1023"/>
<CursorPos X="3" Y="1038"/>
<UsageCount Value="10"/>
</Unit22>
<Unit23>
<Filename Value="C:\Zusatzprogramme\Lazarus\lcl\controls.pp"/>
<UnitName Value="Controls"/>
<EditorIndex Value="-1"/>
<TopLine Value="2240"/>
<CursorPos X="3" Y="2255"/>
<UsageCount Value="10"/>
</Unit23>
<Unit24>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\sysutilh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="22"/>
<CursorPos X="4" Y="37"/>
<UsageCount Value="12"/>
</Unit24>
<Unit25>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\sysosh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="7"/>
<CursorPos X="3" Y="22"/>
<UsageCount Value="12"/>
</Unit25>
<Unit26>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\inc\systemh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="93"/>
<CursorPos X="19" Y="108"/>
<UsageCount Value="12"/>
</Unit26>
<Unit27>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\ascdef.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="57"/>
<CursorPos X="10" Y="72"/>
<UsageCount Value="12"/>
</Unit27>
<Unit28>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win32\windows.pp"/>
<EditorIndex Value="-1"/>
<UsageCount Value="12"/>
</Unit28>
<Unit29>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\base.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="84"/>
<CursorPos X="6" Y="99"/>
<UsageCount Value="12"/>
</Unit29>
</Units>
<JumpHistory Count="24" HistoryIndex="23">
<JumpHistory Count="30" HistoryIndex="28">
<Position1>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="118" TopLine="103"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="272" Column="3" TopLine="246"/>
</Position1>
<Position2>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="121" TopLine="103"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="258" Column="10" TopLine="239"/>
</Position2>
<Position3>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="103" TopLine="88"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="262" Column="79" TopLine="244"/>
</Position3>
<Position4>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="107" TopLine="88"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="62" Column="63" TopLine="48"/>
</Position4>
<Position5>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="105" TopLine="88"/>
<Filename Value="..\utils\uvkuPhysicalDevice.pas"/>
<Caret Line="262" Column="101" TopLine="244"/>
</Position5>
<Position6>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="106" TopLine="88"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Caret Line="14" Column="3"/>
</Position6>
<Position7>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="104" Column="3" TopLine="101"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Caret Line="57" Column="51" TopLine="42"/>
</Position7>
<Position8>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="120" TopLine="105"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Caret Line="69" Column="12" TopLine="63"/>
</Position8>
<Position9>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="91" TopLine="77"/>
<Filename Value="..\utils\uvkuSurface.pas"/>
<Caret Line="24" Column="67" TopLine="14"/>
</Position9>
<Position10>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="92" TopLine="77"/>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<Caret Line="198" Column="87" TopLine="176"/>
</Position10>
<Position11>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="93" TopLine="77"/>
<Filename Value="triangle.lpr"/>
<Caret Line="10" Column="48"/>
</Position11>
<Position12>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="95" TopLine="77"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="100" Column="60" TopLine="76"/>
</Position12>
<Position13>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="4430" Column="28" TopLine="4415"/>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="31" Column="27" TopLine="14"/>
</Position13>
<Position14>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="87" Column="56" TopLine="77"/>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<Caret Line="161" Column="87" TopLine="115"/>
</Position14>
<Position15>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="98" Column="5" TopLine="83"/>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<Caret Line="150" Column="14" TopLine="136"/>
</Position15>
<Position16>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="95" TopLine="83"/>
<Filename Value="..\utils\uvkuSurfaceFactory.pas"/>
<Caret Line="188" Column="24" TopLine="174"/>
</Position16>
<Position17>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="96" TopLine="83"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="11" Column="34" TopLine="90"/>
</Position17>
<Position18>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="2591" Column="3" TopLine="2576"/>
<Filename Value="uMainForm.pas"/>
<Caret Line="101" TopLine="91"/>
</Position18>
<Position19>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="2453" Column="40" TopLine="2437"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="96" Column="15" TopLine="56"/>
</Position19>
<Position20>
<Filename Value="..\utils\uvkuInstance.pas"/>
<Caret Line="96" TopLine="83"/>
<Filename Value="..\utils\uvkuDevice.pas"/>
<Caret Line="55" Column="11" TopLine="40"/>
</Position20>
<Position21>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="4178" Column="3" TopLine="4163"/>
<Caret Line="4454" Column="11" TopLine="4439"/>
</Position21>
<Position22>
<Filename Value="..\Vulkan_old.pas"/>
<Caret Line="11" Column="31" TopLine="61"/>
<Filename Value="..\Vulkan.pas"/>
</Position22>
<Position23>
<Filename Value="..\Vulkan_old.pas"/>
<Caret Line="2452" Column="20" TopLine="2427"/>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="86" Column="30" TopLine="61"/>
</Position23>
<Position24>
<Filename Value="..\Vulkan.pas"/>
<Caret Line="2999" Column="49" TopLine="2983"/>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<Caret Line="76" Column="22" TopLine="58"/>
</Position24>
<Position25>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<Caret Line="179" TopLine="215"/>
</Position25>
<Position26>
<Filename Value="uMainForm.pas"/>
<Caret Line="30" Column="5" TopLine="4"/>
</Position26>
<Position27>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<Caret Line="198" Column="96" TopLine="187"/>
</Position27>
<Position28>
<Filename Value="uMainForm.pas"/>
<Caret Line="12" Column="32"/>
</Position28>
<Position29>
<Filename Value="uMainForm.pas"/>
<Caret Line="111" Column="6" TopLine="89"/>
</Position29>
<Position30>
<Filename Value="..\utils\uvkuDeviceFactory.pas"/>
<Caret Line="58" Column="73" TopLine="44"/>
</Position30>
</JumpHistory>
</ProjectSession>
<Debugging>
<BreakPoints Count="3">
<Item1>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="uMainForm.pas"/>
<Line Value="100"/>
</Item1>
<Item2>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="uMainForm.pas"/>
<Line Value="75"/>
</Item2>
<Item3>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="..\utils\uvkuInstance.pas"/>
<Line Value="95"/>
</Item3>
</BreakPoints>
</Debugging>
</CONFIG>

+ 11
- 0
projects/triangle/uMainForm.lfm 查看文件

@@ -4,7 +4,18 @@ object MainForm: TMainForm
Top = 263
Width = 320
Caption = 'Triangle'
ClientHeight = 240
ClientWidth = 320
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '1.7'
object RenderPanel: TPanel
Left = 0
Height = 240
Top = 0
Width = 320
Align = alClient
BevelOuter = bvNone
TabOrder = 0
end
end

+ 22
- 4
projects/triangle/uMainForm.pas 查看文件

@@ -5,8 +5,11 @@ unit uMainForm;
interface

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

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -19,12 +22,14 @@ type

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TMainForm = class(TForm)
RenderPanel: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
fAllocHandler: TCustomAllocHandler;
fInstance: TvkuInstance;
fDevice: TvkuDevice;
fSurface: TvkuSurface;
public
{ public declarations }
end;
@@ -35,6 +40,7 @@ var
implementation

{$R *.lfm}
{$I Vulkan.inc}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TCustomAllocHandler////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -67,9 +73,9 @@ end;
procedure TMainForm.FormCreate(Sender: TObject);
var
PhyDevices: TvkuPhysicalDeviceArr;
QueueFamProps: TVkQueueFamilyPropertiesArr;
iFactory: TvkuInstanceFactory;
dFactory: TvkuDeviceFactory;
sFactory: TvkuSurfaceFactory;
qci: TvkuQueueCreateInfo;
begin
fAllocHandler := TCustomAllocHandler.Create;
@@ -77,6 +83,8 @@ begin
WriteLn('create vulkan instance');
iFactory := TvkuInstanceFactory.Create;
try
iFactory.Extensions.Add(VK_KHR_SURFACE_EXTENSION_NAME);
iFactory.Extensions.Add(TvkuInstanceFactory.GetPlatformSurfaceExtensionName);
fInstance := iFactory.CreateInstance(fAllocHandler, false);
finally
FreeAndNil(iFactory);
@@ -86,8 +94,17 @@ begin
if (Length(PhyDevices) <= 0) then
raise Exception.Create('unable to get physical device');

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;
dFactory := TvkuDeviceFactory.Create(fInstance);
try
SetLength(qci.Priorities, 1);
qci.Priorities[0] := 1.0;
@@ -107,6 +124,7 @@ end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(fDevice);
FreeAndNil(fSurface);
FreeAndNil(fInstance);
FreeAndNil(fAllocHandler);
end;


+ 1
- 1
projects/utils/uvkuAllocationHandler.pas 查看文件

@@ -90,7 +90,7 @@ end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuAllocationHandler.GetAllocationCallbacks: TVkAllocationCallbacks;
begin
FillByte(result, SizeOf(result), 0);
FillByte(result{%H-}, SizeOf(result), 0);
result.pUserData := self;
result.pfnAllocation := @AllocateMemoryCallback;
result.pfnReallocation := @ReallocateMemoryCallback;


+ 24
- 10
projects/utils/uvkuDevice.pas 查看文件

@@ -15,6 +15,8 @@ type
fHandle: VkDevice;
fPhysicalDevice: VkPhysicalDevice;
fAllocCallbacks: PVkAllocationCallbacks;
fInstanceCommands: TVkInstanceCommands;
fDeviceCommands: TVkDeviceCommands;

procedure CreateHandle(
const aCreateInfo: PVkDeviceCreateInfo;
@@ -25,10 +27,12 @@ type

constructor Create(
const aPhysicalDevice: VkPhysicalDevice;
const aCreateInfo: TVkDeviceCreateInfo);
const aCreateInfo: TVkDeviceCreateInfo;
const aInstanceCommands: TVkInstanceCommands);
constructor Create(
const aPhysicalDevice: VkPhysicalDevice;
const aCreateInfo: TVkDeviceCreateInfo;
const aInstanceCommands: TVkInstanceCommands;
const aAllocCallbacks: TVkAllocationCallbacks);
destructor Destroy; override;
end;
@@ -44,44 +48,54 @@ uses
procedure TvkuDevice.CreateHandle(const aCreateInfo: PVkDeviceCreateInfo; const aAllocCallbacks: PVkAllocationCallbacks);
var err: TVkResult;
begin
if not Assigned(fInstanceCommands.vkCreateDevice) then
raise TvkuException.Create('invalid function pointer: vkCreateDevice; did you load the vulkan core commands?');
if Assigned(aAllocCallbacks) then begin
new(fAllocCallbacks);
fAllocCallbacks^ := aAllocCallbacks^;
end;
err := vkCreateDevice(fPhysicalDevice, aCreateInfo, fAllocCallbacks, @fHandle);
err := fInstanceCommands.vkCreateDevice(fPhysicalDevice, aCreateInfo, fAllocCallbacks, @fHandle);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create device', err);
fDeviceCommands := LoadDeviceCommands(fInstanceCommands.Instance, fHandle);
if not Assigned(fDeviceCommands) then
raise TvkuException.Create('unable to load device commands');
end;

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

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

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



+ 17
- 32
projects/utils/uvkuDeviceFactory.pas 查看文件

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

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

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -24,20 +24,13 @@ type
fAllocHandler: TvkuAllocationHandler;
fOwnsHandler: Boolean;
public
constructor Create(
const aPhysicalDevice: VkPhysicalDevice;
const aCreateInfo: TVkDeviceCreateInfo);
constructor Create(
const aPhysicalDevice: VkPhysicalDevice;
const aCreateInfo: TVkDeviceCreateInfo;
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean);
destructor Destroy; override;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuDeviceFactory = class(TObject)
private
fInstance: TvkuInstance;
fFeatures: TVkPhysicalDeviceFeatures;
fFlags: VkDeviceCreateFlags;
fLayers: TStringList;
@@ -71,7 +64,7 @@ type
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean): TvkuDevice;

constructor Create;
constructor Create(const aInstance: TvkuInstance);
destructor Destroy; override;
end;

@@ -82,25 +75,6 @@ uses

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuDeviceEx///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDeviceEx.Create(const aPhysicalDevice: VkPhysicalDevice; const aCreateInfo: TVkDeviceCreateInfo);
begin
inherited Create(aPhysicalDevice, aCreateInfo);
fAllocHandler := nil;
fOwnsHandler := false;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDeviceEx.Create(const aPhysicalDevice: VkPhysicalDevice; const aCreateInfo: TVkDeviceCreateInfo;
const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean);
begin
fAllocHandler := aAllocHandler;
fOwnsHandler := aOwnsHandler;
if Assigned(fAllocHandler)
then inherited Create(aPhysicalDevice, aCreateInfo, fAllocHandler.GetAllocationCallbacks)
else inherited Create(aPhysicalDevice, aCreateInfo);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuDeviceEx.Destroy;
begin
@@ -172,7 +146,8 @@ begin
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuDeviceFactory.CreateDevice(const aPhysicalDevice: VkPhysicalDevice; const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuDevice;
function TvkuDeviceFactory.CreateDevice(const aPhysicalDevice: VkPhysicalDevice;
const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuDevice;
var
CreateInfo: TVkDeviceCreateInfo;
QueueInfos: array of TVkDeviceQueueCreateInfo;
@@ -218,14 +193,24 @@ begin
CreateInfo.ppEnabledExtensionNames := @ext[0];
CreateInfo.pEnabledFeatures := @fFeatures;

result := TvkuDeviceEx.Create(aPhysicalDevice, CreateInfo, aAllocHandler, aOwnsHandler);
if Assigned(aAllocHandler)
then result := TvkuDeviceEx.Create(aPhysicalDevice, CreateInfo, fInstance.InstanceCommands, aAllocHandler.GetAllocationCallbacks)
else result := TvkuDeviceEx.Create(aPhysicalDevice, CreateInfo, fInstance.InstanceCommands);
try
TvkuDeviceEx(result).fAllocHandler := aAllocHandler;
TvkuDeviceEx(result).fOwnsHandler := aOwnsHandler;
except
FreeAndNil(result);
raise;
end;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuDeviceFactory.Create;
constructor TvkuDeviceFactory.Create(const aInstance: TvkuInstance);
begin
inherited Create;
FillByte(fFeatures, SizeOf(fFeatures), 0);
fInstance := aInstance;
fLayers := TStringList.Create;
fExtensions := TStringList.Create;
end;


+ 30
- 40
projects/utils/uvkuInstance.pas 查看文件

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

uses
Classes, SysUtils,
Vulkan, uvkuPhysicalDevice;
Vulkan;

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

function GetPhysicalDeviceCount: Integer;
function GetPhysicalDevice(const aIndex: Integer): VkPhysicalDevice;
procedure UpdatePhysicalDevices;
protected
procedure CreateHandle(const aCreateInfo: PVkInstanceCreateInfo; const aAllocCallbacks: PVkAllocationCallbacks);
constructor Create;
{%H-}constructor Create;
public
property Handle: VkInstance read fHandle;
property PhysicalDeviceCount: Integer read GetPhysicalDeviceCount;
property PhysicalDevices[const aIndex: Integer]: VkPhysicalDevice read GetPhysicalDevice;
property Handle: VkInstance read fHandle;
property InstanceCommands: TVkInstanceCommands read fInstanceCommands;

function GetPhysicalDevices: TvkuPhysicalDeviceArr;

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

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

destructor Destroy; override;
end;

@@ -42,22 +45,6 @@ uses

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuInstance///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuInstance.GetPhysicalDeviceCount: Integer;
begin
UpdatePhysicalDevices;
result := Length(fPhysicalDevices);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuInstance.GetPhysicalDevice(const aIndex: Integer): VkPhysicalDevice;
begin
UpdatePhysicalDevices;
if (aIndex < Low(fPhysicalDevices)) or (aIndex > High(fPhysicalDevices)) then
raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fPhysicalDevices), High(fPhysicalDevices)]);
result := fPhysicalDevices[aIndex];
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuInstance.UpdatePhysicalDevices;
var
@@ -67,23 +54,16 @@ begin
if (Length(fPhysicalDevices) > 0) then
exit;

err := vkEnumeratePhysicalDevices(fHandle, @c, nil);
err := InstanceCommands.vkEnumeratePhysicalDevices(fHandle, @c, nil);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device number', err);
SetLength(fPhysicalDevices, c);

err := vkEnumeratePhysicalDevices(fHandle, @c, @fPhysicalDevices[0]);
err := InstanceCommands.vkEnumeratePhysicalDevices(fHandle, @c, @fPhysicalDevices[0]);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical devices', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuInstance.GetPhysicalDevices: TvkuPhysicalDeviceArr;
begin
UpdatePhysicalDevices;
result := fPhysicalDevices;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuInstance.CreateHandle(const aCreateInfo: PVkInstanceCreateInfo; const aAllocCallbacks: PVkAllocationCallbacks);
var e: TVkResult;
@@ -95,7 +75,9 @@ begin
e := vkCreateInstance(aCreateInfo, fAllocCallbacks, @fHandle);
if (e < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create vulkan instance', e);
LoadVulkanCommands(fHandle);
fInstanceCommands := LoadInstanceCommands(fHandle);
if not Assigned(InstanceCommands) then
raise TvkuException.Create('unable to load instance commands');
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -106,6 +88,13 @@ begin
fAllocCallbacks := nil;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuInstance.GetPhysicalDevices: TvkuPhysicalDeviceArr;
begin
UpdatePhysicalDevices;
result := fPhysicalDevices;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuInstance.Create(const aCreateInfo: TVkInstanceCreateInfo);
begin
@@ -123,14 +112,15 @@ end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuInstance.Destroy;
begin
if Assigned(fHandle) then begin
vkDestroyInstance(fHandle, fAllocCallbacks);
if (fHandle <> VK_INVALID_HANDLE) then begin
InstanceCommands.vkDestroyInstance(fHandle, fAllocCallbacks);
fHandle := nil;
end;
if Assigned(fAllocCallbacks) then begin
Dispose(fAllocCallbacks);
fAllocCallbacks := nil;
end;
FreeAndNil(fInstanceCommands);
inherited Destroy;
end;



+ 39
- 19
projects/utils/uvkuInstanceFactory.pas 查看文件

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

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

interface

@@ -24,10 +25,6 @@ type
fAllocHandler: TvkuAllocationHandler;
fOwnsHandler: Boolean;
public
constructor Create(
const aCreateInfo: TVkInstanceCreateInfo;
const aAllocHandler: TvkuAllocationHandler;
const aOwnsHandler: Boolean);
destructor Destroy; override;
end;

@@ -49,10 +46,14 @@ type
property Extensions: TStrings read GetExtensions;

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

constructor Create;
destructor Destroy; override;
public
class function GetPlatformSurfaceExtensionName: String;
end;

function vkuApplicationInfo: TvkuApplicationInfo;
@@ -78,7 +79,7 @@ end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function vkuApplicationInfo(aAppName: String; aAppVersion: VkVersion; aEngineName: String; aEngineVersion: VkVersion; aApiVersion: VkVersion): TvkuApplicationInfo;
begin
result := vkuApplicationInfo;
result := vkuApplicationInfo();
result.AppName := aAppName;
result.AppVersion := aAppVersion;
result.EngineName := aEngineName;
@@ -88,16 +89,6 @@ end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuInstanceEx/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuInstanceEx.Create(const aCreateInfo: TVkInstanceCreateInfo; const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean);
begin
fOwnsHandler := aOwnsHandler;
fAllocHandler := aAllocHandler;
if Assigned(fAllocHandler)
then inherited Create(aCreateInfo, fAllocHandler.GetAllocationCallbacks)
else inherited Create(aCreateInfo);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
destructor TvkuInstanceEx.Destroy;
begin
@@ -135,7 +126,7 @@ var
lay: array of PVkChar;
ext: array of PVkChar;
begin
FillByte(AppInfo, SizeOf(AppInfo), 0);
FillByte(AppInfo{%H-}, SizeOf(AppInfo), 0);
AppInfo.sType := VK_STRUCTURE_TYPE_APPLICATION_INFO;
AppInfo.pNext := nil;
AppInfo.pApplicationName := PVkChar(fApplicationInfo.AppName);
@@ -152,7 +143,7 @@ begin
for i := 0 to fExtensions.Count-1 do
ext[i] := PVkChar(fExtensions[i]);

FillByte(CreateInfo, SizeOf(CreateInfo), 0);
FillByte(CreateInfo{%H-}, SizeOf(CreateInfo), 0);
CreateInfo.sType := VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
@@ -162,7 +153,16 @@ begin
CreateInfo.enabledExtensionCount := Length(ext);
CreateInfo.ppEnabledExtensionNames := @ext[0];

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -183,5 +183,25 @@ begin
inherited Destroy;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class function TvkuInstanceFactory.GetPlatformSurfaceExtensionName: String;
begin
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
result := VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
{$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)}
result := VK_KHR_XCB_SURFACE_EXTENSION_NAME;
{$ELSEIF DEFINED(VK_USE_PLATFORM_WAYLAND_KHR)}
result := VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
{$ELSEIF DEFINED(VK_USE_PLATFORM_MIR_KHR)}
result := VK_KHR_MIR_SURFACE_EXTENSION_NAME;
{$ELSEIF DEFINED(VK_USE_PLATFORM_ANDROID_KHR)}
result := VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
{$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
result := VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
{$ELSE}
{$ERROR 'unknown or unsupportet platform'}
{$ENDIF}
end;

end.


+ 177
- 41
projects/utils/uvkuPhysicalDevice.pas 查看文件

@@ -6,18 +6,25 @@ interface

uses
Classes, SysUtils,
Vulkan;
Vulkan, uvkuInstance;

type
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TVkQueueFamilyPropertiesArr = array of TVkQueueFamilyProperties;
TVkSparseImageFormatPropertiesArr = array of TVkSparseImageFormatProperties;
TVkSurfaceFormatArr = array of TVkSurfaceFormatKHR;
TVkPresentModeArr = array of TVkPresentModeKHR;
TVkDisplayPropertiesArr = array of TVkDisplayPropertiesKHR;
TVkDisplayPlanePropertiesArr = array of TVkDisplayPlanePropertiesKHR;
TVkDisplayArr = array of VkDisplayKHR;
TVkDisplayModePropertiesArr = array of TVkDisplayModePropertiesKHR;

TvkuPhysicalDevice = class(TObject)
private
fHandle: VkPhysicalDevice;
function GetQueueFamilyProperties(const aIndex: Integer): TVkQueueFamilyProperties;
function GetQueueFamilyPropertyCount: Integer;
public
fInstanceCommands: TVkInstanceCommands;
public { VK_VERSION_1_0 }
function GetFeatures: TVkPhysicalDeviceFeatures;
function GetProperties: TVkPhysicalDeviceProperties;
function GetMemoryProperties: TVkPhysicalDeviceMemoryProperties;
@@ -35,18 +42,24 @@ type
const aSamples: TVkSampleCountFlagBits;
const aUsage: VkImageUsageFlags;
const aTiling: TVkImageTiling): TVkSparseImageFormatPropertiesArr;
public
property Handle: VkPhysicalDevice read fHandle;
property Features: TVkPhysicalDeviceFeatures read GetFeatures;
property Properties: TVkPhysicalDeviceProperties read GetProperties;
property MemoryProperties: TVkPhysicalDeviceMemoryProperties read GetMemoryProperties;

property QueueFamilyPropertyCount: Integer read GetQueueFamilyPropertyCount;
property QueueFamilyProperties[const aIndex: Integer]: TVkQueueFamilyProperties read GetQueueFamilyProperties;
public { VK_KHR_surface }
function GetSurfaceSupport(const aQueueFamilyIndex: VkUint32; const aSurface: VkSurfaceKHR): Boolean;
function GetSurfaceCapabilities(const aSurface: VkSurfaceKHR): TVkSurfaceCapabilitiesKHR;
function GetSurfaceFormats(const aSurface: VkSurfaceKHR): TVkSurfaceFormatArr;
function GetSurfacePresentModes(const aSurface: VkSurfaceKHR): TVkPresentModeArr;

property FormatProperties[const aFormat: TVkFormat]: TVkFormatProperties read GetFormatProperties;
public { VK_KHR_display }
function GetDisplayProperties: TVkDisplayPropertiesArr;
function GetDisplayPlaneProperties: TVkDisplayPlanePropertiesArr;
function GetDisplayPlaneSupportedDisplays(const aPlaneIndex: VkUint32): TVkDisplayArr;
function GetDisplayModeProperties(const aDisplay: VkDisplayKHR): TVkDisplayModePropertiesArr;

constructor Create(const aHandle: VkPhysicalDevice);
public
property Handle: VkPhysicalDevice read fHandle;
property InstanceCommands: TVkInstanceCommands read fInstanceCommands;

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

implementation
@@ -56,53 +69,47 @@ uses

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuPhysicalDevice/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetQueueFamilyProperties(const aIndex: Integer): TVkQueueFamilyProperties;
var arr: TVkQueueFamilyPropertiesArr;
begin
arr := GetQueueFamilyProperties();
if (aIndex < Low(arr)) or (aIndex > High(arr)) then
raise TvkuException.CreateFmt('index (%) out of range (%d : %d)', [aIndex, Low(arr), High(arr)]);
result := arr[aIndex];
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetQueueFamilyPropertyCount: Integer;
begin
result := Length(GetQueueFamilyProperties);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetFeatures: TVkPhysicalDeviceFeatures;
begin
vkGetPhysicalDeviceFeatures(fHandle, @result);
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFeatures) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceFeatures; did you load the vulkan core commands?');
fInstanceCommands.vkGetPhysicalDeviceFeatures(fHandle, @result);
end;

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

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetQueueFamilyProperties: TVkQueueFamilyPropertiesArr;
var c: VkUint32;
begin
vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, nil);
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceQueueFamilyProperties; did you load the vulkan core commands?');
fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, nil);
SetLength(result, c);
vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, @result[0]);
fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, @result[0]);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetFormatProperties(const aFormat: TVkFormat): TVkFormatProperties;
begin
vkGetPhysicalDeviceFormatProperties(fHandle, aFormat, @result);
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFormatProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceFormatProperties; did you load the vulkan core commands?');
fInstanceCommands.vkGetPhysicalDeviceFormatProperties(fHandle, aFormat, @result);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -110,7 +117,9 @@ function TvkuPhysicalDevice.GetImageFormatProperties(const aFormat: TVkFormat; c
const aTiling: TVkImageTiling; const aUsage: VkImageUsageFlags; const aFlags: VkImageCreateFlags): TVkImageFormatProperties;
var err: TVkResult;
begin
err := vkGetPhysicalDeviceImageFormatProperties(fHandle, aFormat, aImageType, aTiling, aUsage, aFlags, @result);
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceImageFormatProperties; did you load the vulkan core commands?');
err := fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties(fHandle, aFormat, aImageType, aTiling, aUsage, aFlags, @result);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device image format properties', err);
end;
@@ -120,18 +129,145 @@ function TvkuPhysicalDevice.GetSparseImageFormatProperties(const aFormat: TVkFor
const aSamples: TVkSampleCountFlagBits; const aUsage: VkImageUsageFlags; const aTiling: TVkImageTiling): TVkSparseImageFormatPropertiesArr;
var c: VkUint32;
begin
vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, nil);
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSparseImageFormatProperties; did you load the vulkan core commands?');
fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, nil);
SetLength(result, c);
fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, @result[0]);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetSurfaceSupport(const aQueueFamilyIndex: VkUint32; const aSurface: VkSurfaceKHR): Boolean;
var
b: VkBool32;
err: TVkResult;
begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceSupportKHR; did you enabled the VK_KHR_surface extension?');
err := fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR(fHandle, aQueueFamilyIndex, aSurface, @b);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device surface support', err);
result := (b <> 0);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetSurfaceCapabilities(const aSurface: VkSurfaceKHR): TVkSurfaceCapabilitiesKHR;
var
err: TVkResult;
begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceCapabilitiesKHR; did you enabled the VK_KHR_surface extension?');
err := fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(fHandle, aSurface, @result);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device surface capabilities', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetSurfaceFormats(const aSurface: VkSurfaceKHR): TVkSurfaceFormatArr;
var c: VkUint32;
begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceFormatsKHR; did you enabled the VK_KHR_surface extension?');
fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, nil);
SetLength(result, c);
fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, @result[0]);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetSurfacePresentModes(const aSurface: VkSurfaceKHR): TVkPresentModeArr;
var
c: VkUint32;
err: TVkResult;
begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfacePresentModesKHR; did you enabled the VK_KHR_surface extension?');
err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, nil);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device surface present mode count', err);
SetLength(result, c);
err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, @result[0]);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device surface present modes', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetDisplayProperties: TVkDisplayPropertiesArr;
var
err: TVkResult;
c: VkUint32;
begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPropertiesKHR; did you enabled the VK_KHR_display extension?');
err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, nil);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device display property count', err);
SetLength(result, c);
err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, @result[0]);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device display properties', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetDisplayPlaneProperties: TVkDisplayPlanePropertiesArr;
var
err: TVkResult;
c: VkUint32;
begin
if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPlanePropertiesKHR; did you enabled the VK_KHR_display extension?');
err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, nil);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device display plane property count', err);
SetLength(result, c);
err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, @result[0]);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get physical device display plane properties', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetDisplayPlaneSupportedDisplays(const aPlaneIndex: VkUint32): TVkDisplayArr;
var
err: TVkResult;
c: VkUint32;
begin
if not Assigned(fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR) then
raise TvkuException.Create('invalid function pointer: vkGetDisplayPlaneSupportedDisplaysKHR; did you enabled the VK_KHR_display extension?');
err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, nil);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get supported display plane count', err);
SetLength(result, c);
vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, @result[0]);
err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, @result[0]);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get supported display planes', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDevice.GetDisplayModeProperties(const aDisplay: VkDisplayKHR): TVkDisplayModePropertiesArr;
var
err: TVkResult;
c: VkUint32;
begin
if not Assigned(fInstanceCommands.vkGetDisplayModePropertiesKHR) then
raise TvkuException.Create('invalid function pointer: vkGetDisplayModePropertiesKHR; did you enabled the VK_KHR_display extension?');
err := fInstanceCommands.vkGetDisplayModePropertiesKHR(fHandle, aDisplay, @c, nil);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get display mode property count', err);
SetLength(result, c);
err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aDisplay, @c, @result[0]);
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to get display mode properties', err);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuPhysicalDevice.Create(const aHandle: VkPhysicalDevice);
constructor TvkuPhysicalDevice.Create(const aHandle: VkPhysicalDevice; const aInstanceCommands: TVkInstanceCommands);
begin
if not Assigned(aHandle) then
if (aHandle = VK_INVALID_HANDLE) then
raise TvkuException.Create('invalid physical device handle');
if not Assigned(aInstanceCommands) then
raise TvkuException.Create('invalid instance commands');
inherited Create;
fHandle := aHandle;
fHandle := aHandle;
fInstanceCommands := aInstanceCommands;
end;

end.


+ 15
- 3
projects/utils/uvkuPhysicalDeviceFactory.pas 查看文件

@@ -6,13 +6,18 @@ interface

uses
Classes, SysUtils,
Vulkan, uvkuPhysicalDevice;
Vulkan, uvkuInstance, uvkuPhysicalDevice;

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

constructor Create(const aInstance: TvkuInstance);
end;

implementation
@@ -22,7 +27,14 @@ implementation
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuPhysicalDeviceFactory.CreatePhysicalDevice(const aHandle: VkPhysicalDevice): TvkuPhysicalDevice;
begin
result := TvkuPhysicalDevice.Create(aHandle);
result := TvkuPhysicalDevice.Create(aHandle, fInstance.InstanceCommands);
end;

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

end.


+ 104
- 0
projects/utils/uvkuSurface.pas 查看文件

@@ -0,0 +1,104 @@
unit uvkuSurface;

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

interface

uses
Classes, SysUtils,
Vulkan;

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

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

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

implementation

uses
uvkuUtils;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuSurface////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurface.CreateHandle(const aCreateInfo: Pointer; const aAllocCallbacks: PVkAllocationCallbacks);
var err: TVkResult;
begin
if Assigned(aAllocCallbacks) then begin
new(fAllocCallbacks);
fAllocCallbacks^ := aAllocCallbacks^;
end;
{$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
if not Assigned(fInstanceCommands.vkCreateWin32SurfaceKHR) then
raise TvkuException.Create('invalid function pointer: vkCreateWin32SurfaceKHR; did you enabled the VK_KHR_win32_surface extension?');
err := fInstanceCommands.vkCreateWin32SurfaceKHR(fInstance, aCreateInfo, fAllocCallbacks, @fHandle);
{$ENDIF}
if (err < VK_SUCCESS) then
raise TvkuErrorException.Create('unable to create surface', err);
end;

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

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

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

end.


+ 230
- 0
projects/utils/uvkuSurfaceFactory.pas 查看文件

@@ -0,0 +1,230 @@
unit uvkuSurfaceFactory;

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

interface

uses
Classes, SysUtils, Controls,
Vulkan, uvkuInstance, uvkuSurface, uvkuAllocationHandler;

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TvkuSurfaceFactory = class(TObject)
{$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
private
fHInstance: Vulkan.HINSTANCE;
fHwnd: Vulkan.HWND;
procedure SetHwnd(const aValue: Vulkan.HWND);
public
property HInstance: Vulkan.HINSTANCE read fHInstance write fHInstance;
property Hwnd: Vulkan.HWND read fHwnd write SetHwnd;
{$ENDIF}

private
fFlags: VkFlags;
fWinControl: TWinControl;
fInstance: TvkuInstance;
procedure SetWinControl(aValue: TWinControl);
public
property WinControl: TWinControl read fWinControl write SetWinControl;
property Flags: VkFlags read fFlags write fFlags;

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

constructor Create(const aInstance: TvkuInstance);
end;

implementation

{$IF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
uses Windows;
{$ENDIF}

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TvkuSurfaceFactory/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
{$ERROR 'TODO: implement'}
procedure TvkuSurfaceFactory.SetDisplay(const aValue: TDisplay);
begin
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetWindow(const aValue: TWindow);
begin
end;

{$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)}
{$ERROR 'TODO: implement'}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetConnection(const aValue: xcb_connection_t);
begin
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetWindow(const aValue: xcb_window_t);
begin
end;

{$ELSEIF DEFINED(VK_USE_PLATFORM_WAYLAND_KHR)}
{$ERROR 'TODO: implement'}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetDisplay(const aValue: wl_display);
begin
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetSurface(const aValue: wl_surface);
begin
end;

{$ELSEIF DEFINED(VK_USE_PLATFORM_MIR_KHR)}
{$ERROR 'TODO: implement'}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetConnection(const aValue: MirConnection);
begin
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetSurface(const aValue: MirSurface);
begin
end;

{$ELSEIF DEFINED(VK_USE_PLATFORM_ANDROID_KHR)}
{$ERROR 'TODO: implement'}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetWindow(const aValue: ANativeWindow);
begin
end;

{$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetHwnd(const aValue: Vulkan.HWND);
begin
SetWinControl(nil);
fHwnd := aValue;
end;
{$ENDIF}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TvkuSurfaceFactory.SetWinControl(aValue: TWinControl);
begin
if fWinControl = aValue then
exit;
fWinControl := aValue;
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WAYLAND_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_MIR_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_ANDROID_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
fHwnd := Vulkan.HWND(fWinControl.Handle);
{$ENDIF}
end;

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TvkuSurfaceFactory.CreateSurface(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuSurface;
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WAYLAND_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_MIR_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_ANDROID_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
var CreateInfo: TVkWin32SurfaceCreateInfoKHR;
{$ENDIF}
var srf: TvkuSurfaceEx;
begin
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WAYLAND_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_MIR_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_ANDROID_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
FillByte(CreateInfo, SizeOf(CreateInfo), 0);
CreateInfo.sType := VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
CreateInfo.pNext := nil;
CreateInfo.flags := fFlags;
CreateInfo.hinstance := fHInstance;
CreateInfo.hwnd := fHwnd;
{$ENDIF}
if Assigned(aAllocHandler)
then srf := TvkuSurfaceEx.Create(fInstance.Handle, CreateInfo, fInstance.InstanceCommands, aAllocHandler.GetAllocationCallbacks)
else srf := TvkuSurfaceEx.Create(fInstance.Handle, CreateInfo, fInstance.InstanceCommands);
try
srf.fAllocHandler := aAllocHandler;
srf.fOwnsHandler := aOwnsHandler;
except
FreeAndNil(srf);
end;
result := srf;
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TvkuSurfaceFactory.Create(const aInstance: TvkuInstance);
begin
inherited Create;
{$IF DEFINED(VK_USE_PLATFORM_XLIB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_XCB_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WAYLAND_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_MIR_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_ANDROID_KHR)}
{$ERROR 'TODO: implement'}
{$ELSEIF DEFINED(VK_USE_PLATFORM_WIN32_KHR)}
fHInstance := Vulkan.HINSTANCE(GetModuleHandle(nil));
{$ENDIF}
fInstance := aInstance;
fFlags := 0;
end;

end.



Loading…
取消
儲存