Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

271 linhas
6.8 KiB

  1. { ============================================================================
  2. This file is autogenerated from vk.xml
  3. You may retrieve the latest version of this file at the Delphi OpenGL
  4. Community home page, located at http://www.delphigl.com/
  5. The contents of this file are used with permission, subject to
  6. the Mozilla Public License Version 1.1 (the "License"); you may
  7. not use this file except in compliance with the License. You may
  8. obtain a copy of the License at
  9. http://www.mozilla.org/MPL/MPL-1.1.html
  10. Software distributed under the License is distributed on an
  11. "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  12. implied. See the License for the specific language governing
  13. rights and limitations under the License.
  14. Original vk.xml comment:
  15. ==============================================================================
  16. {%COMMENT%}
  17. ============================================================================ }
  18. unit Vulkan;
  19. {$IFDEF FPC}
  20. {$MODE Delphi}
  21. {$IFNDEF WINDOWS}
  22. {$LINKLIB c}
  23. {$ENDIF}
  24. {$MINENUMSIZE 4}
  25. {$PACKSET 4}
  26. {$ENDIF}
  27. {$I Vulkan.inc}
  28. interface
  29. type
  30. VkUint8 = Byte;
  31. VkUint16 = Word;
  32. VkUint32 = Cardinal;
  33. VkUint64 = QWord;
  34. VkInt16 = SmallInt;
  35. VkInt32 = Integer;
  36. VkInt64 = Int64;
  37. VkFloat = Single;
  38. VkDouble = Double;
  39. VkChar = AnsiChar;
  40. VkSize = SizeUInt;
  41. VkHandle = Pointer;
  42. VkNonDispatchableHandle = {$IFDEF VK_CPU64}Pointer{$ELSE}VkUint64{$ENDIF};
  43. const
  44. VK_INVALID_HANDLE: VkHandle = nil;
  45. VK_INVALID_NDP_HANDLE: VkNonDispatchableHandle = {$IFDEF VK_CPU64}nil{$ELSE}0{$ENDIF};
  46. type
  47. {$IFDEF VK_USE_PLATFORM_WIN32_KHR}
  48. HINSTANCE = VkHandle;
  49. HWND = VkHandle;
  50. {$ENDIF}
  51. PVkVoid = Pointer;
  52. PVkHandle = ^VkHandle;
  53. PVkUint8 = ^VkUint8;
  54. PVkUint16 = ^VkUint16;
  55. PVkUint32 = ^VkUint32;
  56. PVkUint64 = ^VkUint64;
  57. PVkInt16 = ^VkInt16;
  58. PVkInt32 = ^VkInt32;
  59. PVkInt64 = ^VkInt64;
  60. PVkFloat = ^VkFloat;
  61. PVkDouble = ^VkDouble;
  62. PVkChar = ^VkChar;
  63. PVkSize = ^VkSize;
  64. PPVkVoid = ^PVkVoid;
  65. PPVkHandle = ^PVkHandle;
  66. PPVkUint8 = ^PVkUint8;
  67. PPVkUint16 = ^PVkUint16;
  68. PPVkUint32 = ^PVkUint32;
  69. PPVkUint64 = ^PVkUint64;
  70. PPVkInt16 = ^PVkInt16;
  71. PPVkInt32 = ^PVkInt32;
  72. PPVkInt64 = ^PVkInt64;
  73. PPVkFloat = ^PVkFloat;
  74. PPVkDouble = ^PVkDouble;
  75. PPVkChar = ^PVkChar;
  76. PPVkSize = ^PVkSize;
  77. {%INTERFACE%}
  78. type
  79. TVkInstanceCommands = class
  80. Instance: VkInstance;
  81. {%INSTANCE_COMMANDS.INTERFACE%}
  82. end;
  83. TVkDeviceCommands = class
  84. Device: VkDevice;
  85. {%DEVICE_COMMANDS.INTERFACE%}
  86. end;
  87. const
  88. VULKAN_LIBNAME = 'vulkan-1.dll';
  89. type
  90. VkVersion = VkInt32;
  91. function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion; inline;
  92. function vkGetVersionMajor(const aVersion: VkVersion): Integer; inline;
  93. function vkGetVersionMinor(const aVersion: VkVersion): Integer; inline;
  94. function vkGetVersionPatch(const aVersion: VkVersion): Integer; inline;
  95. function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
  96. function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
  97. function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
  98. procedure FinalizeVulkan;
  99. implementation
  100. uses
  101. SysUtils;
  102. type
  103. {$IF DEFINED(VK_WIN)}
  104. TvkLibHandle = TLibHandle;
  105. {$ELSE}
  106. TvkLibHandle = Pointer;
  107. {$ENDIF}
  108. const
  109. {$IF DEFINED(VK_WIN)}
  110. InvalidLibHandle = 0;
  111. {$ELSE}
  112. InvalidLibHandle = nil;
  113. {$ENDIF}
  114. var
  115. vkLibHandle: TvkLibHandle = InvalidLibHandle;
  116. { ===================================== Library Handling ============================================= }
  117. function vkLoadLibrary(const aLibName: String): TvkLibHandle;
  118. begin
  119. {$IF DEFINED(VK_WIN)}
  120. result := LoadLibrary(aLibName);
  121. {$ELSE}
  122. result := InvalidLibHandle;
  123. {$ENDIF}
  124. end;
  125. function vkGetProcAddress(const aProcName: String; aLibHandle: TvkLibHandle = InvalidLibHandle): TvkVoidFunction;
  126. begin
  127. result := nil;
  128. if (aLibHandle = InvalidLibHandle) then
  129. aLibHandle := vkLibHandle;
  130. {$IF DEFINED(VK_WIN)}
  131. result := TvkVoidFunction(GetProcAddress(aLibHandle, AnsiString(aProcName)));
  132. {$ELSE}
  133. result := nil;
  134. {$ENDIF}
  135. end;
  136. procedure vkFreeLibrary(var aLibHandle: TvkLibHandle);
  137. begin
  138. if (aLibHandle <> InvalidLibHandle) then begin
  139. {$IF DEFINED(VK_WIN)}
  140. FreeLibrary(aLibHandle);
  141. {$ENDIF}
  142. aLibHandle := InvalidLibHandle;
  143. end;
  144. end;
  145. { ===================================== Vulkan Version Helpers ======================================= }
  146. function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion;
  147. begin
  148. result := (aMajor shl 22) or (aMinor shl 12) or aPatch;
  149. end;
  150. function vkGetVersionMajor(const aVersion: VkVersion): Integer;
  151. begin
  152. result := (aVersion shr 22);
  153. end;
  154. function vkGetVersionMinor(const aVersion: VkVersion): Integer;
  155. begin
  156. result := (aVersion shr 12) and $3FF;
  157. end;
  158. function vkGetVersionPatch(const aVersion: VkVersion): Integer;
  159. begin
  160. result := (aVersion and $FFF);
  161. end;
  162. { ===================================== Initialize Routines ========================================== }
  163. function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
  164. var success: Boolean;
  165. function GetProcAddress(const aName: String): TvkVoidFunction;
  166. begin
  167. result := vkGetProcAddress(aName);
  168. if not Assigned(result) then
  169. success := false;
  170. end;
  171. begin
  172. FinalizeVulkan;
  173. vkLibHandle := vkLoadLibrary(aLibName);
  174. success := (vkLibHandle <> InvalidLibHandle);
  175. if not success then
  176. exit;
  177. {%IMPLEMENTATION%}
  178. result := success;
  179. end;
  180. function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
  181. function GetProcAddress(const aName: String): TvkVoidFunction;
  182. begin
  183. result := vkGetInstanceProcAddr(aInstance, PVkChar(aName));
  184. end;
  185. begin
  186. result := TVkInstanceCommands.Create;
  187. try
  188. result.Instance := aInstance;
  189. with result do begin
  190. {%INSTANCE_COMMANDS.IMPLEMENTATION%}
  191. end;
  192. except
  193. FreeAndNil(result);
  194. raise;
  195. end;
  196. end;
  197. function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
  198. var
  199. vkGetDeviceProcAddr: TvkGetDeviceProcAddr;
  200. function GetProcAddress(const aName: String): TvkVoidFunction;
  201. begin
  202. result := vkGetDeviceProcAddr(aDevice, PVkChar(aName));
  203. end;
  204. begin
  205. vkGetDeviceProcAddr := TvkGetDeviceProcAddr(vkGetInstanceProcAddr(aInstance, 'vkGetDeviceProcAddr'));
  206. result := TVkDeviceCommands.Create;
  207. try
  208. result.Device := aDevice;
  209. with result do begin
  210. {%DEVICE_COMMANDS.IMPLEMENTATION%}
  211. end;
  212. except
  213. FreeAndNil(result);
  214. raise;
  215. end;
  216. end;
  217. procedure FinalizeVulkan;
  218. begin
  219. vkFreeLibrary(vkLibHandle);
  220. end;
  221. initialization
  222. finalization
  223. FinalizeVulkan;
  224. end.