unit vulkan;

{$MODE FPC}
{$MODESWITCH DEFAULTPARAMETERS}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}

interface

const
{$IF Defined(WINDOWS)}
  VulkanLibraryName = 'vulkan-1.dll';
{$ELSE}
  VulkanLibraryName = 'libvulkan.so.1';
{$ENDIF}

const
  VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO      = 1;

type
  VkInstance = Pointer;
  PVkInstance = ^VkInstance;
  PFN_vkVoidFunction = Pointer; // procedure; stdcall;
  VkResult = PtrUInt;
  VkStructureType = PtrUInt;
  VkFlags = UInt32;
  VkInstanceCreateFlags = VkFlags;

  PVkApplicationInfo = ^VkApplicationInfo;
  VkApplicationInfo = packed record
    // TODO
  end;

  PVkAllocationCallbacks = ^VkAllocationCallbacks;
  VkAllocationCallbacks = packed record
  end;

  VkInstanceCreateInfo = packed record
    sType: VkStructureType;
    pNext: Pointer;
    flags: VkInstanceCreateFlags;
    pApplicationInfo: PVkApplicationInfo;
    enabledLayerCount: UInt32;
    ppEnabledLayerNames: PPAnsiChar;
    enabledExtensionCount: UInt32;
    ppEnabledExtensionNames: PPAnsiChar;
  end;
  PVkInstanceCreateInfo = ^VkInstanceCreateInfo;

  TvkEnumerateInstanceVersion = function (pApiVersion: PUInt32): VkResult; stdcall;
  TvkCreateInstance = function (pCreateInfo: PVkInstanceCreateInfo;
                                pAllocator: PVkAllocationCallbacks;
                                pInstance: PVkInstance): VkResult; stdcall;

var
  vkEnumerateInstanceVersion: TvkEnumerateInstanceVersion;
  vkCreateInstance: TvkCreateInstance;

function vkGetInstanceProcAddr(instance: VkInstance;
                               pName: PAnsiChar): PFN_vkVoidFunction;
                               stdcall; external VulkanLibraryName;

procedure LoadVulkan;

implementation

procedure LoadVulkan;
begin
  vkEnumerateInstanceVersion := TvkEnumerateInstanceVersion(vkGetInstanceProcAddr(nil, 'vkEnumerateInstanceVersion'));
  vkCreateInstance := TvkCreateInstance(vkGetInstanceProcAddr(nil, 'vkCreateInstance'));
end;

end.
