Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

275 рядки
15 KiB

  1. unit uvkuPhysicalDevice;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuInstance;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TVkQueueFamilyPropertiesArr = array of TVkQueueFamilyProperties;
  10. TVkSparseImageFormatPropertiesArr = array of TVkSparseImageFormatProperties;
  11. TVkSurfaceFormatArr = array of TVkSurfaceFormatKHR;
  12. TVkPresentModeArr = array of TVkPresentModeKHR;
  13. TVkDisplayPropertiesArr = array of TVkDisplayPropertiesKHR;
  14. TVkDisplayPlanePropertiesArr = array of TVkDisplayPlanePropertiesKHR;
  15. TVkDisplayArr = array of VkDisplayKHR;
  16. TVkDisplayModePropertiesArr = array of TVkDisplayModePropertiesKHR;
  17. TvkuPhysicalDevice = class(TObject)
  18. private
  19. fHandle: VkPhysicalDevice;
  20. fInstanceCommands: TVkInstanceCommands;
  21. public { VK_VERSION_1_0 }
  22. function GetFeatures: TVkPhysicalDeviceFeatures;
  23. function GetProperties: TVkPhysicalDeviceProperties;
  24. function GetMemoryProperties: TVkPhysicalDeviceMemoryProperties;
  25. function GetQueueFamilyProperties: TVkQueueFamilyPropertiesArr;
  26. function GetFormatProperties(const aFormat: TVkFormat): TVkFormatProperties;
  27. function GetImageFormatProperties(
  28. const aFormat: TVkFormat;
  29. const aImageType: TVkImageType;
  30. const aTiling: TVkImageTiling;
  31. const aUsage: VkImageUsageFlags;
  32. const aFlags: VkImageCreateFlags): TVkImageFormatProperties;
  33. function GetSparseImageFormatProperties(
  34. const aFormat: TVkFormat;
  35. const aImageType: TVkImageType;
  36. const aSamples: TVkSampleCountFlagBits;
  37. const aUsage: VkImageUsageFlags;
  38. const aTiling: TVkImageTiling): TVkSparseImageFormatPropertiesArr;
  39. public { VK_KHR_surface }
  40. function GetSurfaceSupport(const aQueueFamilyIndex: VkUint32; const aSurface: VkSurfaceKHR): Boolean;
  41. function GetSurfaceCapabilities(const aSurface: VkSurfaceKHR): TVkSurfaceCapabilitiesKHR;
  42. function GetSurfaceFormats(const aSurface: VkSurfaceKHR): TVkSurfaceFormatArr;
  43. function GetSurfacePresentModes(const aSurface: VkSurfaceKHR): TVkPresentModeArr;
  44. public { VK_KHR_display }
  45. function GetDisplayProperties: TVkDisplayPropertiesArr;
  46. function GetDisplayPlaneProperties: TVkDisplayPlanePropertiesArr;
  47. function GetDisplayPlaneSupportedDisplays(const aPlaneIndex: VkUint32): TVkDisplayArr;
  48. function GetDisplayModeProperties(const aDisplay: VkDisplayKHR): TVkDisplayModePropertiesArr;
  49. public
  50. property Handle: VkPhysicalDevice read fHandle;
  51. property InstanceCommands: TVkInstanceCommands read fInstanceCommands;
  52. constructor Create(const aHandle: VkPhysicalDevice; const aInstanceCommands: TVkInstanceCommands);
  53. end;
  54. implementation
  55. uses
  56. uvkuUtils;
  57. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58. //TvkuPhysicalDevice/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60. function TvkuPhysicalDevice.GetFeatures: TVkPhysicalDeviceFeatures;
  61. begin
  62. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFeatures) then
  63. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceFeatures; did you load the vulkan core commands?');
  64. fInstanceCommands.vkGetPhysicalDeviceFeatures(fHandle, @result);
  65. end;
  66. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67. function TvkuPhysicalDevice.GetProperties: TVkPhysicalDeviceProperties;
  68. begin
  69. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceProperties) then
  70. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceProperties; did you load the vulkan core commands?');
  71. fInstanceCommands.vkGetPhysicalDeviceProperties(fHandle, @result);
  72. end;
  73. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. function TvkuPhysicalDevice.GetMemoryProperties: TVkPhysicalDeviceMemoryProperties;
  75. begin
  76. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceMemoryProperties) then
  77. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceMemoryProperties; did you load the vulkan core commands?');
  78. fInstanceCommands.vkGetPhysicalDeviceMemoryProperties(fHandle, @result);
  79. end;
  80. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81. function TvkuPhysicalDevice.GetQueueFamilyProperties: TVkQueueFamilyPropertiesArr;
  82. var c: VkUint32;
  83. begin
  84. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties) then
  85. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceQueueFamilyProperties; did you load the vulkan core commands?');
  86. fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, nil);
  87. SetLength(result, c);
  88. fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, @result[0]);
  89. end;
  90. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  91. function TvkuPhysicalDevice.GetFormatProperties(const aFormat: TVkFormat): TVkFormatProperties;
  92. begin
  93. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFormatProperties) then
  94. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceFormatProperties; did you load the vulkan core commands?');
  95. fInstanceCommands.vkGetPhysicalDeviceFormatProperties(fHandle, aFormat, @result);
  96. end;
  97. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  98. function TvkuPhysicalDevice.GetImageFormatProperties(const aFormat: TVkFormat; const aImageType: TVkImageType;
  99. const aTiling: TVkImageTiling; const aUsage: VkImageUsageFlags; const aFlags: VkImageCreateFlags): TVkImageFormatProperties;
  100. var err: TVkResult;
  101. begin
  102. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties) then
  103. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceImageFormatProperties; did you load the vulkan core commands?');
  104. err := fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties(fHandle, aFormat, aImageType, aTiling, aUsage, aFlags, @result);
  105. if (err < VK_SUCCESS) then
  106. raise TvkuErrorException.Create('unable to get physical device image format properties', err);
  107. end;
  108. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  109. function TvkuPhysicalDevice.GetSparseImageFormatProperties(const aFormat: TVkFormat; const aImageType: TVkImageType;
  110. const aSamples: TVkSampleCountFlagBits; const aUsage: VkImageUsageFlags; const aTiling: TVkImageTiling): TVkSparseImageFormatPropertiesArr;
  111. var c: VkUint32;
  112. begin
  113. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties) then
  114. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSparseImageFormatProperties; did you load the vulkan core commands?');
  115. fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, nil);
  116. SetLength(result, c);
  117. fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, @result[0]);
  118. end;
  119. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  120. function TvkuPhysicalDevice.GetSurfaceSupport(const aQueueFamilyIndex: VkUint32; const aSurface: VkSurfaceKHR): Boolean;
  121. var
  122. b: VkBool32;
  123. err: TVkResult;
  124. begin
  125. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR) then
  126. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceSupportKHR; did you enabled the VK_KHR_surface extension?');
  127. err := fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR(fHandle, aQueueFamilyIndex, aSurface, @b);
  128. if (err < VK_SUCCESS) then
  129. raise TvkuErrorException.Create('unable to get physical device surface support', err);
  130. result := (b <> 0);
  131. end;
  132. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  133. function TvkuPhysicalDevice.GetSurfaceCapabilities(const aSurface: VkSurfaceKHR): TVkSurfaceCapabilitiesKHR;
  134. var
  135. err: TVkResult;
  136. begin
  137. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR) then
  138. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceCapabilitiesKHR; did you enabled the VK_KHR_surface extension?');
  139. err := fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(fHandle, aSurface, @result);
  140. if (err < VK_SUCCESS) then
  141. raise TvkuErrorException.Create('unable to get physical device surface capabilities', err);
  142. end;
  143. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  144. function TvkuPhysicalDevice.GetSurfaceFormats(const aSurface: VkSurfaceKHR): TVkSurfaceFormatArr;
  145. var c: VkUint32;
  146. begin
  147. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR) then
  148. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceFormatsKHR; did you enabled the VK_KHR_surface extension?');
  149. fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, nil);
  150. SetLength(result, c);
  151. fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, @result[0]);
  152. end;
  153. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  154. function TvkuPhysicalDevice.GetSurfacePresentModes(const aSurface: VkSurfaceKHR): TVkPresentModeArr;
  155. var
  156. c: VkUint32;
  157. err: TVkResult;
  158. begin
  159. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR) then
  160. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfacePresentModesKHR; did you enabled the VK_KHR_surface extension?');
  161. err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, nil);
  162. if (err < VK_SUCCESS) then
  163. raise TvkuErrorException.Create('unable to get physical device surface present mode count', err);
  164. SetLength(result, c);
  165. err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, @result[0]);
  166. if (err < VK_SUCCESS) then
  167. raise TvkuErrorException.Create('unable to get physical device surface present modes', err);
  168. end;
  169. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  170. function TvkuPhysicalDevice.GetDisplayProperties: TVkDisplayPropertiesArr;
  171. var
  172. err: TVkResult;
  173. c: VkUint32;
  174. begin
  175. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR) then
  176. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPropertiesKHR; did you enabled the VK_KHR_display extension?');
  177. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, nil);
  178. if (err < VK_SUCCESS) then
  179. raise TvkuErrorException.Create('unable to get physical device display property count', err);
  180. SetLength(result, c);
  181. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, @result[0]);
  182. if (err < VK_SUCCESS) then
  183. raise TvkuErrorException.Create('unable to get physical device display properties', err);
  184. end;
  185. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  186. function TvkuPhysicalDevice.GetDisplayPlaneProperties: TVkDisplayPlanePropertiesArr;
  187. var
  188. err: TVkResult;
  189. c: VkUint32;
  190. begin
  191. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR) then
  192. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPlanePropertiesKHR; did you enabled the VK_KHR_display extension?');
  193. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, nil);
  194. if (err < VK_SUCCESS) then
  195. raise TvkuErrorException.Create('unable to get physical device display plane property count', err);
  196. SetLength(result, c);
  197. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, @result[0]);
  198. if (err < VK_SUCCESS) then
  199. raise TvkuErrorException.Create('unable to get physical device display plane properties', err);
  200. end;
  201. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  202. function TvkuPhysicalDevice.GetDisplayPlaneSupportedDisplays(const aPlaneIndex: VkUint32): TVkDisplayArr;
  203. var
  204. err: TVkResult;
  205. c: VkUint32;
  206. begin
  207. if not Assigned(fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR) then
  208. raise TvkuException.Create('invalid function pointer: vkGetDisplayPlaneSupportedDisplaysKHR; did you enabled the VK_KHR_display extension?');
  209. err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, nil);
  210. if (err < VK_SUCCESS) then
  211. raise TvkuErrorException.Create('unable to get supported display plane count', err);
  212. SetLength(result, c);
  213. err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, @result[0]);
  214. if (err < VK_SUCCESS) then
  215. raise TvkuErrorException.Create('unable to get supported display planes', err);
  216. end;
  217. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  218. function TvkuPhysicalDevice.GetDisplayModeProperties(const aDisplay: VkDisplayKHR): TVkDisplayModePropertiesArr;
  219. var
  220. err: TVkResult;
  221. c: VkUint32;
  222. begin
  223. if not Assigned(fInstanceCommands.vkGetDisplayModePropertiesKHR) then
  224. raise TvkuException.Create('invalid function pointer: vkGetDisplayModePropertiesKHR; did you enabled the VK_KHR_display extension?');
  225. err := fInstanceCommands.vkGetDisplayModePropertiesKHR(fHandle, aDisplay, @c, nil);
  226. if (err < VK_SUCCESS) then
  227. raise TvkuErrorException.Create('unable to get display mode property count', err);
  228. SetLength(result, c);
  229. err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aDisplay, @c, @result[0]);
  230. if (err < VK_SUCCESS) then
  231. raise TvkuErrorException.Create('unable to get display mode properties', err);
  232. end;
  233. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  234. constructor TvkuPhysicalDevice.Create(const aHandle: VkPhysicalDevice; const aInstanceCommands: TVkInstanceCommands);
  235. begin
  236. if (aHandle = VK_INVALID_HANDLE) then
  237. raise TvkuException.Create('invalid physical device handle');
  238. if not Assigned(aInstanceCommands) then
  239. raise TvkuException.Create('invalid instance commands');
  240. inherited Create;
  241. fHandle := aHandle;
  242. fInstanceCommands := aInstanceCommands;
  243. end;
  244. end.