選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

283 行
15 KiB

  1. unit uvkuPhysicalDevice;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuInstance;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuQueueFamilyPropertiesArr = array of TVkQueueFamilyProperties;
  10. TvkuSparseImageFormatPropertiesArr = array of TVkSparseImageFormatProperties;
  11. TvkuSurfaceFormatArr = array of TVkSurfaceFormatKHR;
  12. TvkuPresentModeArr = array of TVkPresentModeKHR;
  13. TvkuDisplayPropertiesArr = array of TVkDisplayPropertiesKHR;
  14. TvkuDisplayPlanePropertiesArr = array of TVkDisplayPlanePropertiesKHR;
  15. TvkuDisplayArr = array of VkDisplayKHR;
  16. TvkuDisplayModePropertiesArr = 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: TvkuQueueFamilyPropertiesArr;
  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): TvkuSparseImageFormatPropertiesArr;
  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): TvkuSurfaceFormatArr;
  43. function GetSurfacePresentModes(const aSurface: VkSurfaceKHR): TvkuPresentModeArr;
  44. public { VK_KHR_display }
  45. function GetDisplayProperties: TvkuDisplayPropertiesArr;
  46. function GetDisplayPlaneProperties: TvkuDisplayPlanePropertiesArr;
  47. function GetDisplayPlaneSupportedDisplays(const aPlaneIndex: VkUint32): TvkuDisplayArr;
  48. function GetDisplayModeProperties(const aDisplay: VkDisplayKHR): TvkuDisplayModePropertiesArr;
  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: TvkuQueueFamilyPropertiesArr;
  82. var c: VkUint32;
  83. begin
  84. result := nil;
  85. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties) then
  86. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceQueueFamilyProperties; did you load the vulkan core commands?');
  87. fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, nil);
  88. SetLength(result, c);
  89. fInstanceCommands.vkGetPhysicalDeviceQueueFamilyProperties(fHandle, @c, @result[0]);
  90. end;
  91. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92. function TvkuPhysicalDevice.GetFormatProperties(const aFormat: TVkFormat): TVkFormatProperties;
  93. begin
  94. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceFormatProperties) then
  95. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceFormatProperties; did you load the vulkan core commands?');
  96. fInstanceCommands.vkGetPhysicalDeviceFormatProperties(fHandle, aFormat, @result);
  97. end;
  98. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  99. function TvkuPhysicalDevice.GetImageFormatProperties(const aFormat: TVkFormat; const aImageType: TVkImageType;
  100. const aTiling: TVkImageTiling; const aUsage: VkImageUsageFlags; const aFlags: VkImageCreateFlags): TVkImageFormatProperties;
  101. var err: TVkResult;
  102. begin
  103. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties) then
  104. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceImageFormatProperties; did you load the vulkan core commands?');
  105. err := fInstanceCommands.vkGetPhysicalDeviceImageFormatProperties(fHandle, aFormat, aImageType, aTiling, aUsage, aFlags, @result);
  106. if (err < VK_SUCCESS) then
  107. raise TvkuErrorException.Create('unable to get physical device image format properties', err);
  108. end;
  109. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  110. function TvkuPhysicalDevice.GetSparseImageFormatProperties(const aFormat: TVkFormat; const aImageType: TVkImageType;
  111. const aSamples: TVkSampleCountFlagBits; const aUsage: VkImageUsageFlags; const aTiling: TVkImageTiling): TvkuSparseImageFormatPropertiesArr;
  112. var c: VkUint32;
  113. begin
  114. result := nil;
  115. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties) then
  116. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSparseImageFormatProperties; did you load the vulkan core commands?');
  117. fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, nil);
  118. SetLength(result, c);
  119. fInstanceCommands.vkGetPhysicalDeviceSparseImageFormatProperties(fHandle, aFormat, aImageType, aSamples, aUsage, aTiling, @c, @result[0]);
  120. end;
  121. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. function TvkuPhysicalDevice.GetSurfaceSupport(const aQueueFamilyIndex: VkUint32; const aSurface: VkSurfaceKHR): Boolean;
  123. var
  124. b: VkBool32;
  125. err: TVkResult;
  126. begin
  127. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR) then
  128. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceSupportKHR; did you enabled the VK_KHR_surface extension?');
  129. err := fInstanceCommands.vkGetPhysicalDeviceSurfaceSupportKHR(fHandle, aQueueFamilyIndex, aSurface, @b);
  130. if (err < VK_SUCCESS) then
  131. raise TvkuErrorException.Create('unable to get physical device surface support', err);
  132. result := (b <> 0);
  133. end;
  134. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  135. function TvkuPhysicalDevice.GetSurfaceCapabilities(const aSurface: VkSurfaceKHR): TVkSurfaceCapabilitiesKHR;
  136. var
  137. err: TVkResult;
  138. begin
  139. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR) then
  140. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceCapabilitiesKHR; did you enabled the VK_KHR_surface extension?');
  141. err := fInstanceCommands.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(fHandle, aSurface, @result);
  142. if (err < VK_SUCCESS) then
  143. raise TvkuErrorException.Create('unable to get physical device surface capabilities', err);
  144. end;
  145. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  146. function TvkuPhysicalDevice.GetSurfaceFormats(const aSurface: VkSurfaceKHR): TvkuSurfaceFormatArr;
  147. var c: VkUint32;
  148. begin
  149. result := nil;
  150. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR) then
  151. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfaceFormatsKHR; did you enabled the VK_KHR_surface extension?');
  152. fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, nil);
  153. SetLength(result, c);
  154. fInstanceCommands.vkGetPhysicalDeviceSurfaceFormatsKHR(fHandle, aSurface, @c, @result[0]);
  155. end;
  156. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. function TvkuPhysicalDevice.GetSurfacePresentModes(const aSurface: VkSurfaceKHR): TvkuPresentModeArr;
  158. var
  159. c: VkUint32;
  160. err: TVkResult;
  161. begin
  162. result := nil;
  163. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR) then
  164. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceSurfacePresentModesKHR; did you enabled the VK_KHR_surface extension?');
  165. err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, nil);
  166. if (err < VK_SUCCESS) then
  167. raise TvkuErrorException.Create('unable to get physical device surface present mode count', err);
  168. SetLength(result, c);
  169. err := fInstanceCommands.vkGetPhysicalDeviceSurfacePresentModesKHR(fHandle, aSurface, @c, @result[0]);
  170. if (err < VK_SUCCESS) then
  171. raise TvkuErrorException.Create('unable to get physical device surface present modes', err);
  172. end;
  173. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  174. function TvkuPhysicalDevice.GetDisplayProperties: TvkuDisplayPropertiesArr;
  175. var
  176. err: TVkResult;
  177. c: VkUint32;
  178. begin
  179. result := nil;
  180. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR) then
  181. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPropertiesKHR; did you enabled the VK_KHR_display extension?');
  182. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, nil);
  183. if (err < VK_SUCCESS) then
  184. raise TvkuErrorException.Create('unable to get physical device display property count', err);
  185. SetLength(result, c);
  186. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPropertiesKHR(fHandle, @c, @result[0]);
  187. if (err < VK_SUCCESS) then
  188. raise TvkuErrorException.Create('unable to get physical device display properties', err);
  189. end;
  190. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  191. function TvkuPhysicalDevice.GetDisplayPlaneProperties: TvkuDisplayPlanePropertiesArr;
  192. var
  193. err: TVkResult;
  194. c: VkUint32;
  195. begin
  196. result := nil;
  197. if not Assigned(fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR) then
  198. raise TvkuException.Create('invalid function pointer: vkGetPhysicalDeviceDisplayPlanePropertiesKHR; did you enabled the VK_KHR_display extension?');
  199. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, nil);
  200. if (err < VK_SUCCESS) then
  201. raise TvkuErrorException.Create('unable to get physical device display plane property count', err);
  202. SetLength(result, c);
  203. err := fInstanceCommands.vkGetPhysicalDeviceDisplayPlanePropertiesKHR(fHandle, @c, @result[0]);
  204. if (err < VK_SUCCESS) then
  205. raise TvkuErrorException.Create('unable to get physical device display plane properties', err);
  206. end;
  207. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  208. function TvkuPhysicalDevice.GetDisplayPlaneSupportedDisplays(const aPlaneIndex: VkUint32): TvkuDisplayArr;
  209. var
  210. err: TVkResult;
  211. c: VkUint32;
  212. begin
  213. result := nil;
  214. if not Assigned(fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR) then
  215. raise TvkuException.Create('invalid function pointer: vkGetDisplayPlaneSupportedDisplaysKHR; did you enabled the VK_KHR_display extension?');
  216. err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, nil);
  217. if (err < VK_SUCCESS) then
  218. raise TvkuErrorException.Create('unable to get supported display plane count', err);
  219. SetLength(result, c);
  220. err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aPlaneIndex, @c, @result[0]);
  221. if (err < VK_SUCCESS) then
  222. raise TvkuErrorException.Create('unable to get supported display planes', err);
  223. end;
  224. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225. function TvkuPhysicalDevice.GetDisplayModeProperties(const aDisplay: VkDisplayKHR): TvkuDisplayModePropertiesArr;
  226. var
  227. err: TVkResult;
  228. c: VkUint32;
  229. begin
  230. result := nil;
  231. if not Assigned(fInstanceCommands.vkGetDisplayModePropertiesKHR) then
  232. raise TvkuException.Create('invalid function pointer: vkGetDisplayModePropertiesKHR; did you enabled the VK_KHR_display extension?');
  233. err := fInstanceCommands.vkGetDisplayModePropertiesKHR(fHandle, aDisplay, @c, nil);
  234. if (err < VK_SUCCESS) then
  235. raise TvkuErrorException.Create('unable to get display mode property count', err);
  236. SetLength(result, c);
  237. err := fInstanceCommands.vkGetDisplayPlaneSupportedDisplaysKHR(fHandle, aDisplay, @c, @result[0]);
  238. if (err < VK_SUCCESS) then
  239. raise TvkuErrorException.Create('unable to get display mode properties', err);
  240. end;
  241. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  242. constructor TvkuPhysicalDevice.Create(const aHandle: VkPhysicalDevice; const aInstanceCommands: TVkInstanceCommands);
  243. begin
  244. if (aHandle = VK_INVALID_HANDLE) then
  245. raise TvkuException.Create('invalid physical device handle');
  246. if not Assigned(aInstanceCommands) then
  247. raise TvkuException.Create('invalid instance commands');
  248. inherited Create;
  249. fHandle := aHandle;
  250. fInstanceCommands := aInstanceCommands;
  251. end;
  252. end.