25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
6.9 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. {$ENDIF}
  26. {$I Vulkan.inc}
  27. interface
  28. type
  29. VkUint8 = Byte;
  30. VkUint16 = Word;
  31. VkUint32 = Cardinal;
  32. VkUint64 = QWord;
  33. VkInt16 = SmallInt;
  34. VkInt32 = Integer;
  35. VkInt64 = Int64;
  36. VkFloat = Single;
  37. VkDouble = Double;
  38. VkChar = AnsiChar;
  39. VkSize = SizeUInt;
  40. VkHandle = Pointer;
  41. VkNonDispatchableHandle = {$IFDEF VK_CPU64}Pointer{$ELSE}VkUint64{$ENDIF};
  42. const
  43. VK_INVALID_HANDLE: VkHandle = nil;
  44. VK_INVALID_NDP_HANDLE: VkNonDispatchableHandle = {$IFDEF VK_CPU64}nil{$ELSE}0{$ENDIF};
  45. type
  46. {$IFDEF VK_USE_PLATFORM_WIN32_KHR}
  47. HINSTANCE = VkHandle;
  48. HWND = VkHandle;
  49. {$ENDIF}
  50. PVkVoid = Pointer;
  51. PVkHandle = ^VkHandle;
  52. PVkUint8 = ^VkUint8;
  53. PVkUint16 = ^VkUint16;
  54. PVkUint32 = ^VkUint32;
  55. PVkUint64 = ^VkUint64;
  56. PVkInt16 = ^VkInt16;
  57. PVkInt32 = ^VkInt32;
  58. PVkInt64 = ^VkInt64;
  59. PVkFloat = ^VkFloat;
  60. PVkDouble = ^VkDouble;
  61. PVkChar = ^VkChar;
  62. PVkSize = ^VkSize;
  63. PPVkVoid = ^PVkVoid;
  64. PPVkHandle = ^PVkHandle;
  65. PPVkUint8 = ^PVkUint8;
  66. PPVkUint16 = ^PVkUint16;
  67. PPVkUint32 = ^PVkUint32;
  68. PPVkUint64 = ^PVkUint64;
  69. PPVkInt16 = ^PVkInt16;
  70. PPVkInt32 = ^PVkInt32;
  71. PPVkInt64 = ^PVkInt64;
  72. PPVkFloat = ^PVkFloat;
  73. PPVkDouble = ^PVkDouble;
  74. PPVkChar = ^PVkChar;
  75. PPVkSize = ^PVkSize;
  76. {%INTERFACE%}
  77. type
  78. TVkInstanceCommands = packed record
  79. Instance: VkInstance;
  80. {%INSTANCE_COMMANDS.INTERFACE%}
  81. end;
  82. TVkDeviceCommands = packed record
  83. Device: VkDevice;
  84. {%DEVICE_COMMANDS.INTERFACE%}
  85. end;
  86. const
  87. VULKAN_LIBNAME = 'vulkan-1.dll';
  88. type
  89. VkVersion = VkInt32;
  90. function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion; inline;
  91. function vkGetVersionMajor(const aVersion: VkVersion): Integer; inline;
  92. function vkGetVersionMinor(const aVersion: VkVersion): Integer; inline;
  93. function vkGetVersionPatch(const aVersion: VkVersion): Integer; inline;
  94. function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
  95. function LoadInstanceCommands(const aInstance: VkInstance; out aCommands: TVkInstanceCommands): Boolean;
  96. function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice; out aCommands: TVkDeviceCommands): Boolean;
  97. procedure FinalizeVulkan;
  98. implementation
  99. type
  100. {$IF DEFINED(VK_WIN)}
  101. TvkLibHandle = TLibHandle;
  102. {$ELSE}
  103. TvkLibHandle = Pointer;
  104. {$ENDIF}
  105. const
  106. {$IF DEFINED(VK_WIN)}
  107. InvalidLibHandle = 0;
  108. {$ELSE}
  109. InvalidLibHandle = nil;
  110. {$ENDIF}
  111. var
  112. vkLibHandle: TvkLibHandle = InvalidLibHandle;
  113. { ===================================== Library Handling ============================================= }
  114. function vkLoadLibrary(const aLibName: String): TvkLibHandle;
  115. begin
  116. {$IF DEFINED(VK_WIN)}
  117. result := LoadLibrary(aLibName);
  118. {$ELSE}
  119. result := InvalidLibHandle;
  120. {$ENDIF}
  121. end;
  122. function vkGetProcAddress(const aProcName: String; aLibHandle: TvkLibHandle = InvalidLibHandle): TvkVoidFunction;
  123. begin
  124. result := nil;
  125. if (aLibHandle = InvalidLibHandle) then
  126. aLibHandle := vkLibHandle;
  127. {$IF DEFINED(VK_WIN)}
  128. result := TvkVoidFunction(GetProcAddress(aLibHandle, AnsiString(aProcName)));
  129. {$ELSE}
  130. result := nil;
  131. {$ENDIF}
  132. end;
  133. procedure vkFreeLibrary(var aLibHandle: TvkLibHandle);
  134. begin
  135. if (aLibHandle <> InvalidLibHandle) then begin
  136. {$IF DEFINED(VK_WIN)}
  137. FreeLibrary(aLibHandle);
  138. {$ENDIF}
  139. aLibHandle := InvalidLibHandle;
  140. end;
  141. end;
  142. { ===================================== Vulkan Version Helpers ======================================= }
  143. function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion;
  144. begin
  145. result := (aMajor shl 22) or (aMinor shl 12) or aPatch;
  146. end;
  147. function vkGetVersionMajor(const aVersion: VkVersion): Integer;
  148. begin
  149. result := (aVersion shr 22);
  150. end;
  151. function vkGetVersionMinor(const aVersion: VkVersion): Integer;
  152. begin
  153. result := (aVersion shr 12) and $3FF;
  154. end;
  155. function vkGetVersionPatch(const aVersion: VkVersion): Integer;
  156. begin
  157. result := (aVersion and $FFF);
  158. end;
  159. { ===================================== Initialize Routines ========================================== }
  160. function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
  161. var success: Boolean;
  162. function GetProcAddress(const aName: String): TvkVoidFunction;
  163. begin
  164. result := vkGetProcAddress(aName);
  165. if not Assigned(result) then
  166. success := false;
  167. end;
  168. begin
  169. FinalizeVulkan;
  170. vkLibHandle := vkLoadLibrary(aLibName);
  171. success := (vkLibHandle <> InvalidLibHandle);
  172. if not success then
  173. exit;
  174. {%IMPLEMENTATION%}
  175. result := success;
  176. end;
  177. function LoadInstanceCommands(const aInstance: VkInstance; out aCommands: TVkInstanceCommands): Boolean;
  178. var
  179. success: Boolean;
  180. function GetProcAddress(const aName: String): TvkVoidFunction;
  181. begin
  182. result := vkGetInstanceProcAddr(aInstance, PVkChar(aName));
  183. if not Assigned(result) then
  184. success := false;
  185. end;
  186. begin
  187. FillByte(aCommands, SizeOf(aCommands), 0);
  188. success := true;
  189. with aCommands do begin
  190. {%INSTANCE_COMMANDS.IMPLEMENTATION%}
  191. end;
  192. result := success;
  193. end;
  194. function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice; out aCommands: TVkDeviceCommands): Boolean;
  195. var
  196. vkGetDeviceProcAddr: TvkGetDeviceProcAddr;
  197. success: Boolean;
  198. function GetProcAddress(const aName: String): TvkVoidFunction;
  199. begin
  200. result := vkGetDeviceProcAddr(aDevice, PVkChar(aName));
  201. if not Assigned(result) then
  202. success := false;
  203. end;
  204. begin
  205. FillByte(aCommands, SizeOf(aCommands), 0);
  206. vkGetDeviceProcAddr := TvkGetDeviceProcAddr(vkGetInstanceProcAddr(aInstance, 'vkGetDeviceProcAddr'));
  207. success := true;
  208. with aCommands do begin
  209. {%DEVICE_COMMANDS.IMPLEMENTATION%}
  210. end;
  211. result := success;
  212. end;
  213. procedure FinalizeVulkan;
  214. begin
  215. vkFreeLibrary(vkLibHandle);
  216. end;
  217. initialization
  218. finalization
  219. FinalizeVulkan;
  220. end.