您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

276 行
14 KiB

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