0059-pvr-wsi-add-PowerVR-Vulkan-WSI-library.patch 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. From 65c47424e2dd558d2c79ef5f1b9008fe38b3b0bf Mon Sep 17 00:00:00 2001
  2. From: Brendan King <Brendan.King@imgtec.com>
  3. Date: Thu, 18 Mar 2021 13:44:57 +0000
  4. Subject: [PATCH] pvr/wsi: add PowerVR Vulkan WSI library
  5. PowerVR Vulkan will load the WSI library, libpvr_mesa_wsi.so,
  6. and lookup the symbol pvr_mesa_wsi_sym_addr, which is a used to
  7. lookup all other symbols required by Vulkan from the library.
  8. The function is used by Vulkan to lookup the library initialisation
  9. function, pvr_mesa_wsi_init. That function is passed the address
  10. of another lookup function, pvr_vk_mesa_wsi_sym_addr, which is used
  11. by the WSI library to lookup symbols in Vulkan.
  12. The interface between PVR Vulkan and the WSI library is defined in
  13. pvr_mesa_wsi_interface.h. Most of the functions defined on the WSI
  14. side are wrappers around Mesa WSI functions.
  15. ---
  16. meson.build | 1 +
  17. meson_options.txt | 2 +-
  18. src/meson.build | 3 +
  19. src/pvr/meson.build | 23 ++
  20. src/pvr/wsi/meson.build | 75 ++++++
  21. src/pvr/wsi/pvr_mesa_wsi_interface.h | 306 ++++++++++++++++++++++++
  22. src/pvr/wsi/pvr_wsi.c | 333 +++++++++++++++++++++++++++
  23. src/pvr/wsi/pvr_wsi.h | 78 +++++++
  24. src/pvr/wsi/pvr_wsi_display.c | 293 +++++++++++++++++++++++
  25. src/pvr/wsi/pvr_wsi_wayland.c | 45 ++++
  26. src/pvr/wsi/pvr_wsi_x11.c | 62 +++++
  27. 11 files changed, 1220 insertions(+), 1 deletion(-)
  28. create mode 100644 src/pvr/meson.build
  29. create mode 100644 src/pvr/wsi/meson.build
  30. create mode 100644 src/pvr/wsi/pvr_mesa_wsi_interface.h
  31. create mode 100644 src/pvr/wsi/pvr_wsi.c
  32. create mode 100644 src/pvr/wsi/pvr_wsi.h
  33. create mode 100644 src/pvr/wsi/pvr_wsi_display.c
  34. create mode 100644 src/pvr/wsi/pvr_wsi_wayland.c
  35. create mode 100644 src/pvr/wsi/pvr_wsi_x11.c
  36. diff --git a/meson.build b/meson.build
  37. index c0b6264..3f6ddb6 100644
  38. --- a/meson.build
  39. +++ b/meson.build
  40. @@ -296,6 +296,7 @@ with_swrast_vk = _vulkan_drivers.contains('swrast')
  41. with_virtio_vk = _vulkan_drivers.contains('virtio-experimental')
  42. with_freedreno_kgsl = get_option('freedreno-kgsl')
  43. with_broadcom_vk = _vulkan_drivers.contains('broadcom')
  44. +with_pvr_vk = _vulkan_drivers.contains('pvr')
  45. with_any_vk = _vulkan_drivers.length() != 0
  46. with_any_broadcom = with_gallium_vc4 or with_gallium_v3d or with_broadcom_vk
  47. diff --git a/meson_options.txt b/meson_options.txt
  48. index d36e714..e0c25a5 100644
  49. --- a/meson_options.txt
  50. +++ b/meson_options.txt
  51. @@ -194,7 +194,7 @@ option(
  52. 'vulkan-drivers',
  53. type : 'array',
  54. value : ['auto'],
  55. - choices : ['auto', 'amd', 'broadcom', 'freedreno', 'intel', 'panfrost', 'swrast', 'virtio-experimental'],
  56. + choices : ['auto', 'amd', 'broadcom', 'freedreno', 'intel', 'panfrost', 'swrast', 'virtio-experimental', 'pvr'],
  57. description : 'List of vulkan drivers to build. If this is set to auto all drivers applicable to the target OS/architecture will be built'
  58. )
  59. option(
  60. diff --git a/src/meson.build b/src/meson.build
  61. index f6eede5..36fec26 100644
  62. --- a/src/meson.build
  63. +++ b/src/meson.build
  64. @@ -90,6 +90,9 @@ endif
  65. if with_gallium_panfrost or with_gallium_lima or with_panfrost_vk
  66. subdir('panfrost')
  67. endif
  68. +if with_pvr_vk
  69. + subdir('pvr')
  70. +endif
  71. if with_gallium_virgl or with_virtio_vk
  72. subdir('virtio')
  73. endif
  74. diff --git a/src/pvr/meson.build b/src/pvr/meson.build
  75. new file mode 100644
  76. index 0000000..09a6986
  77. --- /dev/null
  78. +++ b/src/pvr/meson.build
  79. @@ -0,0 +1,23 @@
  80. +# Copyright (c) Imagination Technologies Ltd.
  81. +
  82. +# Permission is hereby granted, free of charge, to any person obtaining a copy
  83. +# of this software and associated documentation files (the "Software"), to deal
  84. +# in the Software without restriction, including without limitation the rights
  85. +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  86. +# copies of the Software, and to permit persons to whom the Software is
  87. +# furnished to do so, subject to the following conditions:
  88. +
  89. +# The above copyright notice and this permission notice shall be included in
  90. +# all copies or substantial portions of the Software.
  91. +
  92. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  93. +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  94. +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  95. +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  96. +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  97. +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  98. +# SOFTWARE.
  99. +
  100. +if with_pvr_vk
  101. + subdir('wsi')
  102. +endif
  103. diff --git a/src/pvr/wsi/meson.build b/src/pvr/wsi/meson.build
  104. new file mode 100644
  105. index 0000000..57c7623
  106. --- /dev/null
  107. +++ b/src/pvr/wsi/meson.build
  108. @@ -0,0 +1,75 @@
  109. +# Copyright (c) Imagination Technologies Ltd.
  110. +
  111. +# Permission is hereby granted, free of charge, to any person obtaining a copy
  112. +# of this software and associated documentation files (the "Software"), to deal
  113. +# in the Software without restriction, including without limitation the rights
  114. +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  115. +# copies of the Software, and to permit persons to whom the Software is
  116. +# furnished to do so, subject to the following conditions:
  117. +
  118. +# The above copyright notice and this permission notice shall be included in
  119. +# all copies or substantial portions of the Software.
  120. +
  121. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  122. +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  123. +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  124. +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  125. +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  126. +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  127. +# SOFTWARE.
  128. +
  129. +pvr_wsi_args = vulkan_wsi_args
  130. +
  131. +pvr_wsi_depends = [ dep_libdrm, idep_vulkan_util, idep_xmlconfig ]
  132. +
  133. +pvr_wsi_includes = [
  134. + inc_include,
  135. + inc_src,
  136. + inc_vulkan_util,
  137. + inc_vulkan_wsi
  138. +]
  139. +
  140. +pvr_wsi_src = [ 'pvr_wsi.c' ]
  141. +
  142. +if with_platform_wayland
  143. + pvr_wsi_args += '-DVK_USE_PLATFORM_WAYLAND_KHR'
  144. +
  145. + pvr_wsi_depends += dep_wayland_client
  146. +
  147. + pvr_wsi_src += 'pvr_wsi_wayland.c'
  148. +endif
  149. +
  150. +if with_platform_x11
  151. + pvr_wsi_args += [
  152. + '-DVK_USE_PLATFORM_XCB_KHR',
  153. + '-DVK_USE_PLATFORM_XLIB_KHR',
  154. + ]
  155. +
  156. + pvr_wsi_depends += dep_xcb_dri2
  157. +
  158. + pvr_wsi_src += 'pvr_wsi_x11.c'
  159. +endif
  160. +
  161. +if system_has_kms_drm and not with_platform_android
  162. + pvr_wsi_args += '-DVK_USE_PLATFORM_DISPLAY_KHR'
  163. +
  164. + pvr_wsi_src += 'pvr_wsi_display.c'
  165. +endif
  166. +
  167. +if with_xlib_lease
  168. + pvr_wsi_args += '-DVK_USE_PLATFORM_XLIB_XRANDR_EXT'
  169. +
  170. + pvr_wsi_depends += dep_xlib_xrandr
  171. +endif
  172. +
  173. +libvulkan_wsi = shared_library(
  174. + 'pvr_mesa_wsi',
  175. + pvr_wsi_src,
  176. + include_directories : pvr_wsi_includes,
  177. + dependencies : pvr_wsi_depends,
  178. + c_args : pvr_wsi_args,
  179. + link_with: libvulkan_wsi,
  180. + gnu_symbol_visibility : 'hidden',
  181. + build_by_default : true,
  182. + install : true
  183. +)
  184. diff --git a/src/pvr/wsi/pvr_mesa_wsi_interface.h b/src/pvr/wsi/pvr_mesa_wsi_interface.h
  185. new file mode 100644
  186. index 0000000..b4b1bcb
  187. --- /dev/null
  188. +++ b/src/pvr/wsi/pvr_mesa_wsi_interface.h
  189. @@ -0,0 +1,306 @@
  190. +/*************************************************************************/ /*!
  191. +@File
  192. +@Title PVR interface to the Vulkan WSI layer in Mesa
  193. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
  194. +@License MIT
  195. +
  196. +The contents of this file are subject to the MIT license as set out below.
  197. +
  198. +Permission is hereby granted, free of charge, to any person obtaining a copy
  199. +of this software and associated documentation files (the "Software"), to deal
  200. +in the Software without restriction, including without limitation the rights
  201. +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  202. +copies of the Software, and to permit persons to whom the Software is
  203. +furnished to do so, subject to the following conditions:
  204. +
  205. +The above copyright notice and this permission notice shall be included in
  206. +all copies or substantial portions of the Software.
  207. +
  208. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  209. +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  210. +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  211. +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  212. +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  213. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  214. +THE SOFTWARE.
  215. +*/ /**************************************************************************/
  216. +
  217. +#ifndef PVR_MESA_WSI_INTERFACE_H
  218. +#define PVR_MESA_WSI_INTERFACE_H
  219. +
  220. +#include <stdbool.h>
  221. +#include <stdint.h>
  222. +
  223. +#include <vulkan/vulkan.h>
  224. +
  225. +/*
  226. + * The pvr_mesa_wsi structure holds the Mesa WSI state, and is opaque to
  227. + * the PowerVK DDK.
  228. + */
  229. +struct pvr_mesa_wsi;
  230. +
  231. +/*
  232. + * Functions defined in Mesa for use by the PowerVR DDK.
  233. + * All functions have a "pvr_mesa_wsi" prefix.
  234. + */
  235. +
  236. +void *
  237. +pvr_mesa_wsi_sym_addr(struct pvr_mesa_wsi *mwsi,
  238. + const char *name);
  239. +
  240. +VkResult
  241. +pvr_mesa_wsi_init(struct pvr_mesa_wsi **mwsi,
  242. + VkPhysicalDevice physicalDevice,
  243. + PFN_vkVoidFunction (VKAPI_PTR *pvr_vk_mesa_wsi_sym_addr)
  244. + (VkPhysicalDevice physicalDevice, const char *),
  245. + const VkAllocationCallbacks *alloc,
  246. + int fd,
  247. + bool sw);
  248. +
  249. +void
  250. +pvr_mesa_wsi_finish(struct pvr_mesa_wsi *mwsi,
  251. + const VkAllocationCallbacks *alloc);
  252. +
  253. +VkResult
  254. +pvr_mesa_wsi_common_get_surface_support(struct pvr_mesa_wsi *mwsi,
  255. + uint32_t queueFamilyIndex,
  256. + VkSurfaceKHR surface,
  257. + VkBool32 *pSupported);
  258. +
  259. +VkResult
  260. +pvr_mesa_wsi_common_get_surface_capabilities(struct pvr_mesa_wsi *mwsi,
  261. + VkSurfaceKHR surface,
  262. + VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
  263. +
  264. +VkResult
  265. +pvr_mesa_wsi_common_get_surface_capabilities2(struct pvr_mesa_wsi *mwsi,
  266. + const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  267. + VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
  268. +
  269. +VkResult
  270. +pvr_mesa_wsi_common_get_surface_capabilities2ext(struct pvr_mesa_wsi *mwsi,
  271. + VkSurfaceKHR surface,
  272. + VkSurfaceCapabilities2EXT *pSurfaceCapabilities);
  273. +
  274. +VkResult
  275. +pvr_mesa_wsi_common_get_surface_formats(struct pvr_mesa_wsi *mwsi,
  276. + VkSurfaceKHR surface,
  277. + uint32_t *pSurfaceFormatCount,
  278. + VkSurfaceFormatKHR *pSurfaceFormats);
  279. +
  280. +VkResult
  281. +pvr_mesa_wsi_common_get_surface_formats2(struct pvr_mesa_wsi *mwsi,
  282. + const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  283. + uint32_t *pSurfaceFormatCount,
  284. + VkSurfaceFormat2KHR *pSurfaceFormats);
  285. +
  286. +VkResult
  287. +pvr_mesa_wsi_common_get_surface_present_modes(struct pvr_mesa_wsi *mwsi,
  288. + VkSurfaceKHR surface,
  289. + uint32_t *pPresentModeCount,
  290. + VkPresentModeKHR *pPresentModes);
  291. +
  292. +VkResult
  293. +pvr_mesa_wsi_common_create_swapchain(struct pvr_mesa_wsi *mwsi,
  294. + VkDevice device,
  295. + const VkSwapchainCreateInfoKHR *pCreateInfo,
  296. + const VkAllocationCallbacks *pAllocator,
  297. + VkSwapchainKHR *pSwapchain);
  298. +void
  299. +pvr_mesa_wsi_common_destroy_swapchain(struct pvr_mesa_wsi *mwsi,
  300. + VkDevice device,
  301. + VkSwapchainKHR swapchain,
  302. + const VkAllocationCallbacks *pAllocator);
  303. +
  304. +VkResult
  305. +pvr_mesa_wsi_common_get_images(struct pvr_mesa_wsi *mwsi,
  306. + VkSwapchainKHR swapchain,
  307. + uint32_t *pSwapchainImageCount,
  308. + VkImage *pSwapchainImages);
  309. +
  310. +VkResult
  311. +pvr_mesa_wsi_common_acquire_next_image2(struct pvr_mesa_wsi *mwsi,
  312. + VkDevice device,
  313. + const VkAcquireNextImageInfoKHR *pAcquireInfo,
  314. + uint32_t *pImageIndex);
  315. +
  316. +VkResult
  317. +pvr_mesa_wsi_common_queue_present(struct pvr_mesa_wsi *mwsi,
  318. + VkDevice device,
  319. + VkQueue queue,
  320. + int queue_family_index,
  321. + const VkPresentInfoKHR *pPresentInfo);
  322. +
  323. +VkResult
  324. +pvr_mesa_wsi_common_get_present_rectangles(struct pvr_mesa_wsi *mwsi,
  325. + VkSurfaceKHR surface,
  326. + uint32_t* pRectCount,
  327. + VkRect2D* pRects);
  328. +
  329. +#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
  330. +VkBool32
  331. +pvr_mesa_wsi_get_physical_device_wayland_presentation_support(struct pvr_mesa_wsi *mwsi,
  332. + uint32_t queueFamilyIndex,
  333. + void *display);
  334. +
  335. +VkResult
  336. +pvr_mesa_wsi_create_wayland_surface(struct pvr_mesa_wsi *mwsi,
  337. + const VkAllocationCallbacks *pAllocator,
  338. + const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
  339. + VkSurfaceKHR *pSurface);
  340. +#endif
  341. +
  342. +#if defined(VK_USE_PLATFORM_XCB_KHR)
  343. +VkBool32
  344. +pvr_mesa_wsi_get_physical_device_xcb_presentation_support(struct pvr_mesa_wsi *mwsi,
  345. + uint32_t queueFamilyIndex,
  346. + void *connection,
  347. + uint32_t visualId);
  348. +VkResult
  349. +pvr_mesa_wsi_create_xcb_surface(struct pvr_mesa_wsi *mwsi,
  350. + const VkAllocationCallbacks *pAllocator,
  351. + const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
  352. + VkSurfaceKHR *pSurface);
  353. +#endif
  354. +
  355. +#if defined(VK_USE_PLATFORM_XLIB_KHR)
  356. +VkResult
  357. +pvr_mesa_wsi_create_xlib_surface(struct pvr_mesa_wsi *mwsi,
  358. + const VkAllocationCallbacks *pAllocator,
  359. + const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
  360. + VkSurfaceKHR *pSurface);
  361. +#endif
  362. +
  363. +VkResult
  364. +pvr_mesa_wsi_display_get_physical_device_display_properties(struct pvr_mesa_wsi *mwsi,
  365. + VkPhysicalDevice physicalDevice,
  366. + uint32_t *pPropertyCount,
  367. + VkDisplayPropertiesKHR *pProperties);
  368. +
  369. +VkResult
  370. +pvr_mesa_wsi_display_get_physical_device_display_properties2(struct pvr_mesa_wsi *mwsi,
  371. + VkPhysicalDevice physicalDevice,
  372. + uint32_t *pPropertyCount,
  373. + VkDisplayProperties2KHR *pProperties);
  374. +
  375. +VkResult
  376. +pvr_mesa_wsi_display_get_physical_device_display_plane_properties(struct pvr_mesa_wsi *mwsi,
  377. + VkPhysicalDevice physicalDevice,
  378. + uint32_t *pPropertyCount,
  379. + VkDisplayPlanePropertiesKHR *pProperties);
  380. +
  381. +VkResult
  382. +pvr_mesa_wsi_display_get_physical_device_display_plane_properties2(struct pvr_mesa_wsi *mwsi,
  383. + VkPhysicalDevice physicalDevice,
  384. + uint32_t *pPropertyCount,
  385. + VkDisplayPlaneProperties2KHR *pProperties);
  386. +
  387. +VkResult
  388. +pvr_mesa_wsi_display_get_display_plane_supported_displays(struct pvr_mesa_wsi *mwsi,
  389. + VkPhysicalDevice physicalDevice,
  390. + uint32_t planeIndex,
  391. + uint32_t *pDisplayCount,
  392. + VkDisplayKHR *pDisplays);
  393. +
  394. +VkResult
  395. +pvr_mesa_wsi_display_get_display_mode_properties(struct pvr_mesa_wsi *mwsi,
  396. + VkPhysicalDevice physicalDevice,
  397. + VkDisplayKHR display,
  398. + uint32_t *pPropertyCount,
  399. + VkDisplayModePropertiesKHR *pProperties);
  400. +
  401. +VkResult
  402. +pvr_mesa_wsi_display_get_display_mode_properties2(struct pvr_mesa_wsi *mwsi,
  403. + VkPhysicalDevice physicalDevice,
  404. + VkDisplayKHR display,
  405. + uint32_t *pPropertyCount,
  406. + VkDisplayModeProperties2KHR *pProperties);
  407. +
  408. +VkResult
  409. +pvr_mesa_wsi_display_create_display_mode(struct pvr_mesa_wsi *mwsi,
  410. + VkPhysicalDevice physicalDevice,
  411. + VkDisplayKHR display,
  412. + const VkDisplayModeCreateInfoKHR *pCreateInfo,
  413. + const VkAllocationCallbacks *pAllocator,
  414. + VkDisplayModeKHR *pMode);
  415. +
  416. +VkResult
  417. +pvr_mesa_wsi_get_display_plane_capabilities(struct pvr_mesa_wsi *mwsi,
  418. + VkPhysicalDevice physicalDevice,
  419. + VkDisplayModeKHR modeKhr,
  420. + uint32_t planeIndex,
  421. + VkDisplayPlaneCapabilitiesKHR *pCapabilities);
  422. +
  423. +VkResult
  424. +pvr_mesa_wsi_get_display_plane_capabilities2(struct pvr_mesa_wsi *mwsi,
  425. + VkPhysicalDevice physicalDevice,
  426. + const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
  427. + VkDisplayPlaneCapabilities2KHR *pCapabilities);
  428. +
  429. +VkResult
  430. +pvr_mesa_wsi_create_display_surface(struct pvr_mesa_wsi *mwsi,
  431. + VkInstance instance,
  432. + const VkAllocationCallbacks *pAllocator,
  433. + const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
  434. + VkSurfaceKHR *pSurface);
  435. +
  436. +VkResult
  437. +pvr_mesa_wsi_release_display(struct pvr_mesa_wsi *mwsi,
  438. + VkPhysicalDevice physicalDevice,
  439. + VkDisplayKHR display);
  440. +
  441. +#if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
  442. +VkResult
  443. +pvr_mesa_wsi_acquire_xlib_display(struct pvr_mesa_wsi *mwsi,
  444. + VkPhysicalDevice physicalDevice,
  445. + void *dpy,
  446. + VkDisplayKHR display);
  447. +
  448. +VkResult
  449. +pvr_mesa_wsi_get_randr_output_display(struct pvr_mesa_wsi *mwsi,
  450. + VkPhysicalDevice physicalDevice,
  451. + void *dpy,
  452. + uint32_t output,
  453. + VkDisplayKHR *pDisplay);
  454. +
  455. +#endif
  456. +
  457. +VkResult
  458. +pvr_mesa_wsi_display_power_control(struct pvr_mesa_wsi *mwsi,
  459. + VkDevice device,
  460. + VkDisplayKHR display,
  461. + const VkDisplayPowerInfoEXT *pDisplayPowerInfo);
  462. +
  463. +VkResult
  464. +pvr_mesa_wsi_register_device_event(struct pvr_mesa_wsi *mwsi,
  465. + VkDevice device,
  466. + const VkDeviceEventInfoEXT *pDeviceEventInfo,
  467. + const VkAllocationCallbacks *pAllocator,
  468. + void **pFence,
  469. + int syncFd);
  470. +
  471. +VkResult
  472. +pvr_mesa_wsi_register_display_event(struct pvr_mesa_wsi *mwsi,
  473. + VkDevice device,
  474. + VkDisplayKHR display,
  475. + const VkDisplayEventInfoEXT *pDisplayEventInfo,
  476. + const VkAllocationCallbacks *pAllocator,
  477. + void **pFence,
  478. + int syncFd);
  479. +
  480. +VkResult
  481. +pvr_mesa_wsi_get_swapchain_counter(struct pvr_mesa_wsi *mwsi,
  482. + VkDevice device,
  483. + VkSwapchainKHR swapchain,
  484. + VkSurfaceCounterFlagBitsEXT flagBits,
  485. + uint64_t *pValue);
  486. +
  487. +/*
  488. + * Functions defined in the PowerVR DDK for use by Mesa.
  489. + * All functions have a "pvr_vk_mesa_wsi" prefix.
  490. + */
  491. +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
  492. +pvr_vk_mesa_wsi_sym_addr(VkPhysicalDevice physicalDevice,
  493. + const char *name);
  494. +
  495. +#endif /* PVR_MESA_WSI_INTERFACE_H */
  496. diff --git a/src/pvr/wsi/pvr_wsi.c b/src/pvr/wsi/pvr_wsi.c
  497. new file mode 100644
  498. index 0000000..a1fcdfd
  499. --- /dev/null
  500. +++ b/src/pvr/wsi/pvr_wsi.c
  501. @@ -0,0 +1,333 @@
  502. +/*
  503. + * Copyright © Imagination Technologies Ltd.
  504. + *
  505. + * The contents of this file are subject to the MIT license as set out below.
  506. + *
  507. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  508. + * of this software and associated documentation files (the "Software"), to deal
  509. + * in the Software without restriction, including without limitation the rights
  510. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  511. + * copies of the Software, and to permit persons to whom the Software is
  512. + * furnished to do so, subject to the following conditions:
  513. + *
  514. + * The above copyright notice and this permission notice shall be included in
  515. + * all copies or substantial portions of the Software.
  516. + *
  517. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  518. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  519. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  520. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  521. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  522. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  523. + * THE SOFTWARE.
  524. + */
  525. +
  526. +#include <string.h>
  527. +
  528. +#include "pvr_wsi.h"
  529. +#include "pvr_mesa_wsi_interface.h"
  530. +
  531. +VkResult
  532. +pvr_mesa_wsi_init(struct pvr_mesa_wsi **pmwsi,
  533. + VkPhysicalDevice physicalDevice,
  534. + PFN_vkVoidFunction (VKAPI_PTR *pvr_vk_mesa_wsi_sym_addr)
  535. + (VkPhysicalDevice physicalDevice, const char *),
  536. + const VkAllocationCallbacks *alloc,
  537. + int fd,
  538. + bool sw)
  539. +{
  540. + struct pvr_mesa_wsi *mwsi;
  541. + VkResult result;
  542. +
  543. + mwsi = vk_zalloc(alloc, sizeof(*mwsi), 8,
  544. + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  545. + if (!mwsi)
  546. + return VK_ERROR_OUT_OF_HOST_MEMORY;
  547. +
  548. + mwsi->symtab.pvr_vk_mesa_wsi_sym_addr = pvr_vk_mesa_wsi_sym_addr;
  549. + mwsi->physicalDevice = physicalDevice;
  550. +
  551. + result = wsi_device_init(&mwsi->wsi,
  552. + physicalDevice,
  553. + pvr_vk_mesa_wsi_sym_addr,
  554. + alloc,
  555. + fd, NULL, sw);
  556. + if (result != VK_SUCCESS) {
  557. + vk_free(alloc, mwsi);
  558. + return result;
  559. + }
  560. +
  561. + if (!sw)
  562. + mwsi->wsi.supports_modifiers = true;
  563. +
  564. + *pmwsi = mwsi;
  565. +
  566. + return VK_SUCCESS;
  567. +}
  568. +
  569. +void
  570. +pvr_mesa_wsi_finish(struct pvr_mesa_wsi *mwsi,
  571. + const VkAllocationCallbacks *alloc)
  572. +{
  573. + wsi_device_finish(&mwsi->wsi, alloc);
  574. +
  575. + vk_free(alloc, mwsi);
  576. +}
  577. +
  578. +VkResult
  579. +pvr_mesa_wsi_common_get_surface_support(struct pvr_mesa_wsi *mwsi,
  580. + uint32_t queueFamilyIndex,
  581. + VkSurfaceKHR surface,
  582. + VkBool32 *pSupported)
  583. +{
  584. + return wsi_common_get_surface_support(&mwsi->wsi,
  585. + queueFamilyIndex,
  586. + surface,
  587. + pSupported);
  588. +}
  589. +
  590. +VkResult
  591. +pvr_mesa_wsi_common_get_surface_capabilities(struct pvr_mesa_wsi *mwsi,
  592. + VkSurfaceKHR surface,
  593. + VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
  594. +{
  595. + return wsi_common_get_surface_capabilities(&mwsi->wsi,
  596. + surface,
  597. + pSurfaceCapabilities);
  598. +}
  599. +
  600. +VkResult
  601. +pvr_mesa_wsi_common_get_surface_capabilities2(struct pvr_mesa_wsi *mwsi,
  602. + const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  603. + VkSurfaceCapabilities2KHR *pSurfaceCapabilities)
  604. +{
  605. + return wsi_common_get_surface_capabilities2(&mwsi->wsi,
  606. + pSurfaceInfo,
  607. + pSurfaceCapabilities);
  608. +}
  609. +
  610. +VkResult
  611. +pvr_mesa_wsi_common_get_surface_capabilities2ext(struct pvr_mesa_wsi *mwsi,
  612. + VkSurfaceKHR surface,
  613. + VkSurfaceCapabilities2EXT *pSurfaceCapabilities)
  614. +{
  615. + return wsi_common_get_surface_capabilities2ext(&mwsi->wsi,
  616. + surface,
  617. + pSurfaceCapabilities);
  618. +}
  619. +
  620. +VkResult
  621. +pvr_mesa_wsi_common_get_surface_formats(struct pvr_mesa_wsi *mwsi,
  622. + VkSurfaceKHR surface,
  623. + uint32_t *pSurfaceFormatCount,
  624. + VkSurfaceFormatKHR *pSurfaceFormats)
  625. +{
  626. + return wsi_common_get_surface_formats(&mwsi->wsi,
  627. + surface,
  628. + pSurfaceFormatCount,
  629. + pSurfaceFormats);
  630. +}
  631. +
  632. +VkResult
  633. +pvr_mesa_wsi_common_get_surface_formats2(struct pvr_mesa_wsi *mwsi,
  634. + const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  635. + uint32_t *pSurfaceFormatCount,
  636. + VkSurfaceFormat2KHR *pSurfaceFormats)
  637. +{
  638. + return wsi_common_get_surface_formats2(&mwsi->wsi,
  639. + pSurfaceInfo,
  640. + pSurfaceFormatCount,
  641. + pSurfaceFormats);
  642. +}
  643. +
  644. +VkResult
  645. +pvr_mesa_wsi_common_get_surface_present_modes(struct pvr_mesa_wsi *mwsi,
  646. + VkSurfaceKHR surface,
  647. + uint32_t *pPresentModeCount,
  648. + VkPresentModeKHR *pPresentModes)
  649. +{
  650. + return wsi_common_get_surface_present_modes(&mwsi->wsi,
  651. + surface,
  652. + pPresentModeCount,
  653. + pPresentModes);
  654. +}
  655. +
  656. +VkResult
  657. +pvr_mesa_wsi_common_create_swapchain(struct pvr_mesa_wsi *mwsi,
  658. + VkDevice device,
  659. + const VkSwapchainCreateInfoKHR *pCreateInfo,
  660. + const VkAllocationCallbacks *pAllocator,
  661. + VkSwapchainKHR *pSwapchain)
  662. +{
  663. + return wsi_common_create_swapchain(&mwsi->wsi,
  664. + device,
  665. + pCreateInfo,
  666. + pAllocator,
  667. + pSwapchain);
  668. +}
  669. +
  670. +void
  671. +pvr_mesa_wsi_common_destroy_swapchain(UNUSED struct pvr_mesa_wsi *mwsi,
  672. + VkDevice device,
  673. + VkSwapchainKHR swapchain,
  674. + const VkAllocationCallbacks *pAllocator)
  675. +{
  676. + return wsi_common_destroy_swapchain(device,
  677. + swapchain,
  678. + pAllocator);
  679. +}
  680. +
  681. +VkResult
  682. +pvr_mesa_wsi_common_get_images(UNUSED struct pvr_mesa_wsi *mwsi,
  683. + VkSwapchainKHR swapchain,
  684. + uint32_t *pSwapchainImageCount,
  685. + VkImage *pSwapchainImages)
  686. +{
  687. + return wsi_common_get_images(swapchain,
  688. + pSwapchainImageCount,
  689. + pSwapchainImages);
  690. +}
  691. +
  692. +VkResult
  693. +pvr_mesa_wsi_common_acquire_next_image2(struct pvr_mesa_wsi *mwsi,
  694. + VkDevice device,
  695. + const VkAcquireNextImageInfoKHR *pAcquireInfo,
  696. + uint32_t *pImageIndex)
  697. +{
  698. + return wsi_common_acquire_next_image2(&mwsi->wsi,
  699. + device,
  700. + pAcquireInfo,
  701. + pImageIndex);
  702. +}
  703. +
  704. +VkResult
  705. +pvr_mesa_wsi_common_queue_present(struct pvr_mesa_wsi *mwsi,
  706. + VkDevice device,
  707. + VkQueue queue,
  708. + int queue_family_index,
  709. + const VkPresentInfoKHR *pPresentInfo)
  710. +{
  711. + return wsi_common_queue_present(&mwsi->wsi,
  712. + device,
  713. + queue,
  714. + queue_family_index,
  715. + pPresentInfo);
  716. +}
  717. +
  718. +VkResult
  719. +pvr_mesa_wsi_common_get_present_rectangles(struct pvr_mesa_wsi *mwsi,
  720. + VkSurfaceKHR surface,
  721. + uint32_t* pRectCount,
  722. + VkRect2D* pRects)
  723. +{
  724. + return wsi_common_get_present_rectangles(&mwsi->wsi,
  725. + surface,
  726. + pRectCount,
  727. + pRects);
  728. +}
  729. +
  730. +/*
  731. + * The mwsi parameter is currently unused. Note that it is invalid for
  732. + * pvr_mesa_wsi_init, which is responsible for allocating it.
  733. +*/
  734. +PUBLIC void *
  735. +pvr_mesa_wsi_sym_addr(UNUSED struct pvr_mesa_wsi *mwsi, const char *name)
  736. +{
  737. + static const struct {
  738. + char *name;
  739. + void *addr;
  740. + } lookup[] = {
  741. + { "pvr_mesa_wsi_init",
  742. + pvr_mesa_wsi_init },
  743. + { "pvr_mesa_wsi_finish",
  744. + pvr_mesa_wsi_finish },
  745. + { "pvr_mesa_wsi_common_get_surface_support",
  746. + pvr_mesa_wsi_common_get_surface_support },
  747. + { "pvr_mesa_wsi_common_get_surface_capabilities",
  748. + pvr_mesa_wsi_common_get_surface_capabilities },
  749. + { "pvr_mesa_wsi_common_get_surface_capabilities2",
  750. + pvr_mesa_wsi_common_get_surface_capabilities2 },
  751. + { "pvr_mesa_wsi_common_get_surface_capabilities2ext",
  752. + pvr_mesa_wsi_common_get_surface_capabilities2ext },
  753. + { "pvr_mesa_wsi_common_get_surface_formats",
  754. + pvr_mesa_wsi_common_get_surface_formats },
  755. + { "pvr_mesa_wsi_common_get_surface_formats2",
  756. + pvr_mesa_wsi_common_get_surface_formats2 },
  757. + { "pvr_mesa_wsi_common_get_surface_present_modes",
  758. + pvr_mesa_wsi_common_get_surface_present_modes },
  759. + { "pvr_mesa_wsi_common_create_swapchain",
  760. + pvr_mesa_wsi_common_create_swapchain },
  761. + { "pvr_mesa_wsi_common_destroy_swapchain",
  762. + pvr_mesa_wsi_common_destroy_swapchain },
  763. + { "pvr_mesa_wsi_common_get_images",
  764. + pvr_mesa_wsi_common_get_images },
  765. + { "pvr_mesa_wsi_common_acquire_next_image2",
  766. + pvr_mesa_wsi_common_acquire_next_image2 },
  767. + { "pvr_mesa_wsi_common_queue_present",
  768. + pvr_mesa_wsi_common_queue_present },
  769. + { "pvr_mesa_wsi_common_get_present_rectangles",
  770. + pvr_mesa_wsi_common_get_present_rectangles },
  771. +#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
  772. + { "pvr_mesa_wsi_get_physical_device_wayland_presentation_support",
  773. + pvr_mesa_wsi_get_physical_device_wayland_presentation_support },
  774. + { "pvr_mesa_wsi_create_wayland_surface",
  775. + pvr_mesa_wsi_create_wayland_surface },
  776. +#endif
  777. +#if defined(VK_USE_PLATFORM_XCB_KHR)
  778. + { "pvr_mesa_wsi_get_physical_device_xcb_presentation_support",
  779. + pvr_mesa_wsi_get_physical_device_xcb_presentation_support },
  780. + { "pvr_mesa_wsi_create_xcb_surface",
  781. + pvr_mesa_wsi_create_xcb_surface },
  782. +#endif
  783. +#if defined(VK_USE_PLATFORM_XLIB_KHR)
  784. + { "pvr_mesa_wsi_create_xlib_surface",
  785. + pvr_mesa_wsi_create_xlib_surface },
  786. +#endif
  787. + { "pvr_mesa_wsi_display_get_physical_device_display_properties",
  788. + pvr_mesa_wsi_display_get_physical_device_display_properties },
  789. + { "pvr_mesa_wsi_display_get_physical_device_display_properties2",
  790. + pvr_mesa_wsi_display_get_physical_device_display_properties2 },
  791. + { "pvr_mesa_wsi_display_get_physical_device_display_plane_properties",
  792. + pvr_mesa_wsi_display_get_physical_device_display_plane_properties },
  793. + { "pvr_mesa_wsi_display_get_physical_device_display_plane_properties2",
  794. + pvr_mesa_wsi_display_get_physical_device_display_plane_properties2 },
  795. + { "pvr_mesa_wsi_display_get_display_plane_supported_displays",
  796. + pvr_mesa_wsi_display_get_display_plane_supported_displays },
  797. + { "pvr_mesa_wsi_display_get_display_mode_properties",
  798. + pvr_mesa_wsi_display_get_display_mode_properties },
  799. + { "pvr_mesa_wsi_display_get_display_mode_properties2",
  800. + pvr_mesa_wsi_display_get_display_mode_properties2 },
  801. + { "pvr_mesa_wsi_display_create_display_mode",
  802. + pvr_mesa_wsi_display_create_display_mode },
  803. + { "pvr_mesa_wsi_get_display_plane_capabilities",
  804. + pvr_mesa_wsi_get_display_plane_capabilities },
  805. + { "pvr_mesa_wsi_get_display_plane_capabilities2",
  806. + pvr_mesa_wsi_get_display_plane_capabilities2 },
  807. + { "pvr_mesa_wsi_create_display_surface",
  808. + pvr_mesa_wsi_create_display_surface },
  809. + { "pvr_mesa_wsi_release_display",
  810. + pvr_mesa_wsi_release_display },
  811. +#if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
  812. + { "pvr_mesa_wsi_acquire_xlib_display",
  813. + pvr_mesa_wsi_acquire_xlib_display },
  814. + { "pvr_mesa_wsi_get_randr_output_display",
  815. + pvr_mesa_wsi_get_randr_output_display },
  816. +#endif
  817. + { "pvr_mesa_wsi_display_power_control",
  818. + pvr_mesa_wsi_display_power_control },
  819. + { "pvr_mesa_wsi_register_device_event",
  820. + pvr_mesa_wsi_register_device_event },
  821. + { "pvr_mesa_wsi_register_display_event",
  822. + pvr_mesa_wsi_register_display_event },
  823. + { "pvr_mesa_wsi_get_swapchain_counter",
  824. + pvr_mesa_wsi_get_swapchain_counter },
  825. + };
  826. + unsigned i;
  827. +
  828. + for (i = 0; i < ARRAY_SIZE(lookup); i++) {
  829. + if (!strcmp(name, lookup[i].name))
  830. + return lookup[i].addr;
  831. + }
  832. +
  833. + return NULL;
  834. +}
  835. diff --git a/src/pvr/wsi/pvr_wsi.h b/src/pvr/wsi/pvr_wsi.h
  836. new file mode 100644
  837. index 0000000..142358d
  838. --- /dev/null
  839. +++ b/src/pvr/wsi/pvr_wsi.h
  840. @@ -0,0 +1,78 @@
  841. +/*
  842. + * Copyright © Imagination Technologies Ltd.
  843. + *
  844. + * The contents of this file are subject to the MIT license as set out below.
  845. + *
  846. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  847. + * of this software and associated documentation files (the "Software"), to deal
  848. + * in the Software without restriction, including without limitation the rights
  849. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  850. + * copies of the Software, and to permit persons to whom the Software is
  851. + * furnished to do so, subject to the following conditions:
  852. + *
  853. + * The above copyright notice and this permission notice shall be included in
  854. + * all copies or substantial portions of the Software.
  855. + *
  856. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  857. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  858. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  859. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  860. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  861. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  862. + * THE SOFTWARE.
  863. + */
  864. +
  865. +#if !defined PVR_WSI_H
  866. +#define PVR_WSI_H
  867. +
  868. +#include "util/macros.h"
  869. +#include "util/u_memory.h"
  870. +#include "util/u_atomic.h"
  871. +
  872. +#include "wsi_common.h"
  873. +
  874. +#define Container(p, s, m) ((s *) ((uintptr_t)(p) - Offset(s, m)))
  875. +
  876. +#define _MAKE_STRING(x) # x
  877. +#define MAKE_STRING(x) _MAKE_STRING(x)
  878. +
  879. +#define LOOKUP_DDK(mwsi, sym) \
  880. + mwsi->symtab.pvr_vk_mesa_wsi_sym_addr(MAKE_STRING(sym))
  881. +
  882. +#define JUMP_DDK(mwsi, sym, ...) \
  883. + do { \
  884. + void *_entry = p_atomic_read(&mwsi->symtab.sym); \
  885. + \
  886. + if (!_entry) { \
  887. + _entry = LOOKUP_DDK(mwsi, sym); \
  888. + \
  889. + if (_entry) \
  890. + p_atomic_set(&mwsi->symtab.sym, _entry); \
  891. + } \
  892. + \
  893. + if (_entry) { \
  894. + __typeof__(mwsi->symtab.sym) _func = _entry; \
  895. + \
  896. + return _func(__VA_ARGS__); \
  897. + } \
  898. + } while(0)
  899. +
  900. +struct pvr_vk_mesa_wsi_sym_tab
  901. +{
  902. + PFN_vkVoidFunction (VKAPI_PTR *pvr_vk_mesa_wsi_sym_addr)
  903. + (VkPhysicalDevice physicalDevice, const char *);
  904. +};
  905. +
  906. +struct pvr_mesa_wsi
  907. +{
  908. + struct wsi_device wsi;
  909. + struct pvr_vk_mesa_wsi_sym_tab symtab;
  910. + VkPhysicalDevice physicalDevice;
  911. +};
  912. +
  913. +static inline struct pvr_mesa_wsi *pvr_mesa_wsi(struct wsi_device *wsi_ptr)
  914. +{
  915. + return Container(wsi_ptr, struct pvr_mesa_wsi, wsi);
  916. +}
  917. +
  918. +#endif
  919. diff --git a/src/pvr/wsi/pvr_wsi_display.c b/src/pvr/wsi/pvr_wsi_display.c
  920. new file mode 100644
  921. index 0000000..65a1c99
  922. --- /dev/null
  923. +++ b/src/pvr/wsi/pvr_wsi_display.c
  924. @@ -0,0 +1,293 @@
  925. +/*
  926. + * Copyright © Imagination Technologies Ltd.
  927. + *
  928. + * The contents of this file are subject to the MIT license as set out below.
  929. + *
  930. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  931. + * of this software and associated documentation files (the "Software"), to deal
  932. + * in the Software without restriction, including without limitation the rights
  933. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  934. + * copies of the Software, and to permit persons to whom the Software is
  935. + * furnished to do so, subject to the following conditions:
  936. + *
  937. + * The above copyright notice and this permission notice shall be included in
  938. + * all copies or substantial portions of the Software.
  939. + *
  940. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  941. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  942. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  943. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  944. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  945. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  946. + * THE SOFTWARE.
  947. + */
  948. +
  949. +#include "wsi_common_display.h"
  950. +
  951. +#if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
  952. +#include "wsi_common_x11.h"
  953. +#endif
  954. +
  955. +#include "pvr_wsi.h"
  956. +#include "pvr_mesa_wsi_interface.h"
  957. +
  958. +VkResult
  959. +pvr_mesa_wsi_display_get_physical_device_display_properties(struct pvr_mesa_wsi *mwsi,
  960. + VkPhysicalDevice physicalDevice,
  961. + uint32_t *pPropertyCount,
  962. + VkDisplayPropertiesKHR *pProperties)
  963. +{
  964. + return wsi_display_get_physical_device_display_properties(physicalDevice,
  965. + &mwsi->wsi,
  966. + pPropertyCount,
  967. + pProperties);
  968. +}
  969. +
  970. +VkResult
  971. +pvr_mesa_wsi_display_get_physical_device_display_properties2(struct pvr_mesa_wsi *mwsi,
  972. + VkPhysicalDevice physicalDevice,
  973. + uint32_t *pPropertyCount,
  974. + VkDisplayProperties2KHR *pProperties)
  975. +{
  976. + return wsi_display_get_physical_device_display_properties2(physicalDevice,
  977. + &mwsi->wsi,
  978. + pPropertyCount,
  979. + pProperties);
  980. +}
  981. +
  982. +VkResult
  983. +pvr_mesa_wsi_display_get_physical_device_display_plane_properties(struct pvr_mesa_wsi *mwsi,
  984. + VkPhysicalDevice physicalDevice,
  985. + uint32_t *pPropertyCount,
  986. + VkDisplayPlanePropertiesKHR *pProperties)
  987. +{
  988. + return wsi_display_get_physical_device_display_plane_properties(physicalDevice,
  989. + &mwsi->wsi,
  990. + pPropertyCount,
  991. + pProperties);
  992. +}
  993. +
  994. +VkResult
  995. +pvr_mesa_wsi_display_get_physical_device_display_plane_properties2(struct pvr_mesa_wsi *mwsi,
  996. + VkPhysicalDevice physicalDevice,
  997. + uint32_t *pPropertyCount,
  998. + VkDisplayPlaneProperties2KHR *pProperties)
  999. +{
  1000. + return wsi_display_get_physical_device_display_plane_properties2(physicalDevice,
  1001. + &mwsi->wsi,
  1002. + pPropertyCount,
  1003. + pProperties);
  1004. +}
  1005. +
  1006. +VkResult
  1007. +pvr_mesa_wsi_display_get_display_plane_supported_displays(struct pvr_mesa_wsi *mwsi,
  1008. + VkPhysicalDevice physicalDevice,
  1009. + uint32_t planeIndex,
  1010. + uint32_t *pDisplayCount,
  1011. + VkDisplayKHR *pDisplays)
  1012. +{
  1013. + return wsi_display_get_display_plane_supported_displays(physicalDevice,
  1014. + &mwsi->wsi,
  1015. + planeIndex,
  1016. + pDisplayCount,
  1017. + pDisplays);
  1018. +
  1019. +}
  1020. +
  1021. +VkResult
  1022. +pvr_mesa_wsi_display_get_display_mode_properties(struct pvr_mesa_wsi *mwsi,
  1023. + VkPhysicalDevice physicalDevice,
  1024. + VkDisplayKHR display,
  1025. + uint32_t *pPropertyCount,
  1026. + VkDisplayModePropertiesKHR *pProperties)
  1027. +{
  1028. + return wsi_display_get_display_mode_properties(physicalDevice,
  1029. + &mwsi->wsi,
  1030. + display,
  1031. + pPropertyCount,
  1032. + pProperties);
  1033. +}
  1034. +
  1035. +VkResult
  1036. +pvr_mesa_wsi_display_get_display_mode_properties2(struct pvr_mesa_wsi *mwsi,
  1037. + VkPhysicalDevice physicalDevice,
  1038. + VkDisplayKHR display,
  1039. + uint32_t *pPropertyCount,
  1040. + VkDisplayModeProperties2KHR *pProperties)
  1041. +{
  1042. + return wsi_display_get_display_mode_properties2(physicalDevice,
  1043. + &mwsi->wsi,
  1044. + display,
  1045. + pPropertyCount,
  1046. + pProperties);
  1047. +}
  1048. +
  1049. +VkResult
  1050. +pvr_mesa_wsi_display_create_display_mode(struct pvr_mesa_wsi *mwsi,
  1051. + VkPhysicalDevice physicalDevice,
  1052. + VkDisplayKHR display,
  1053. + const VkDisplayModeCreateInfoKHR *pCreateInfo,
  1054. + const VkAllocationCallbacks *pAllocator,
  1055. + VkDisplayModeKHR *pMode)
  1056. +{
  1057. + return wsi_display_create_display_mode(physicalDevice,
  1058. + &mwsi->wsi,
  1059. + display,
  1060. + pCreateInfo,
  1061. + pAllocator,
  1062. + pMode);
  1063. +}
  1064. +
  1065. +VkResult
  1066. +pvr_mesa_wsi_get_display_plane_capabilities(struct pvr_mesa_wsi *mwsi,
  1067. + VkPhysicalDevice physicalDevice,
  1068. + VkDisplayModeKHR modeKhr,
  1069. + uint32_t planeIndex,
  1070. + VkDisplayPlaneCapabilitiesKHR *pCapabilities)
  1071. +{
  1072. + return wsi_get_display_plane_capabilities(physicalDevice,
  1073. + &mwsi->wsi,
  1074. + modeKhr,
  1075. + planeIndex,
  1076. + pCapabilities);
  1077. +}
  1078. +
  1079. +VkResult
  1080. +pvr_mesa_wsi_get_display_plane_capabilities2(struct pvr_mesa_wsi *mwsi,
  1081. + VkPhysicalDevice physicalDevice,
  1082. + const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
  1083. + VkDisplayPlaneCapabilities2KHR *pCapabilities)
  1084. +{
  1085. + return wsi_get_display_plane_capabilities2(physicalDevice,
  1086. + &mwsi->wsi,
  1087. + pDisplayPlaneInfo,
  1088. + pCapabilities);
  1089. +}
  1090. +
  1091. +VkResult
  1092. +pvr_mesa_wsi_create_display_surface(UNUSED struct pvr_mesa_wsi *mwsi,
  1093. + VkInstance instance,
  1094. + const VkAllocationCallbacks *pAllocator,
  1095. + const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
  1096. + VkSurfaceKHR *pSurface)
  1097. +{
  1098. + return wsi_create_display_surface(instance,
  1099. + pAllocator,
  1100. + pCreateInfo,
  1101. + pSurface);
  1102. +}
  1103. +
  1104. +VkResult
  1105. +pvr_mesa_wsi_release_display(struct pvr_mesa_wsi *mwsi,
  1106. + VkPhysicalDevice physicalDevice,
  1107. + VkDisplayKHR display)
  1108. +{
  1109. + return wsi_release_display(physicalDevice,
  1110. + &mwsi->wsi,
  1111. + display);
  1112. +}
  1113. +
  1114. +#if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
  1115. +VkResult
  1116. +pvr_mesa_wsi_acquire_xlib_display(struct pvr_mesa_wsi *mwsi,
  1117. + VkPhysicalDevice physicalDevice,
  1118. + void *dpy,
  1119. + VkDisplayKHR display)
  1120. +{
  1121. + return wsi_acquire_xlib_display(physicalDevice,
  1122. + &mwsi->wsi,
  1123. + dpy,
  1124. + display);
  1125. +}
  1126. +
  1127. +VkResult
  1128. +pvr_mesa_wsi_get_randr_output_display(struct pvr_mesa_wsi *mwsi,
  1129. + VkPhysicalDevice physicalDevice,
  1130. + void *dpy,
  1131. + uint32_t output,
  1132. + VkDisplayKHR *pDisplay)
  1133. +{
  1134. + return wsi_get_randr_output_display(physicalDevice,
  1135. + &mwsi->wsi,
  1136. + dpy,
  1137. + output,
  1138. + pDisplay);
  1139. +}
  1140. +#endif
  1141. +
  1142. +VkResult
  1143. +pvr_mesa_wsi_display_power_control(struct pvr_mesa_wsi *mwsi,
  1144. + VkDevice device,
  1145. + VkDisplayKHR display,
  1146. + const VkDisplayPowerInfoEXT *pDisplayPowerInfo)
  1147. +{
  1148. + return wsi_display_power_control(device,
  1149. + &mwsi->wsi,
  1150. + display,
  1151. + pDisplayPowerInfo);
  1152. +}
  1153. +
  1154. +VkResult
  1155. +pvr_mesa_wsi_register_device_event(struct pvr_mesa_wsi *mwsi,
  1156. + VkDevice device,
  1157. + const VkDeviceEventInfoEXT *pDeviceEventInfo,
  1158. + const VkAllocationCallbacks *pAllocator,
  1159. + void **pFence,
  1160. + int syncFd)
  1161. +{
  1162. + struct wsi_fence *fence;
  1163. + VkResult ret;
  1164. +
  1165. + ret = wsi_register_device_event(device,
  1166. + &mwsi->wsi,
  1167. + pDeviceEventInfo,
  1168. + pAllocator,
  1169. + pFence ? &fence : NULL,
  1170. + syncFd);
  1171. +
  1172. + if (ret == VK_SUCCESS && pFence != NULL)
  1173. + *pFence = fence;
  1174. +
  1175. + return ret;
  1176. +}
  1177. +
  1178. +VkResult
  1179. +pvr_mesa_wsi_register_display_event(struct pvr_mesa_wsi *mwsi,
  1180. + VkDevice device,
  1181. + VkDisplayKHR display,
  1182. + const VkDisplayEventInfoEXT *pDisplayEventInfo,
  1183. + const VkAllocationCallbacks *pAllocator,
  1184. + void **pFence,
  1185. + int syncFd)
  1186. +{
  1187. + struct wsi_fence *fence;
  1188. + VkResult ret;
  1189. +
  1190. + ret = wsi_register_display_event(device,
  1191. + &mwsi->wsi,
  1192. + display,
  1193. + pDisplayEventInfo,
  1194. + pAllocator,
  1195. + pFence ? &fence : NULL,
  1196. + syncFd);
  1197. +
  1198. + if (ret == VK_SUCCESS && pFence != NULL)
  1199. + *pFence = fence;
  1200. +
  1201. + return ret;
  1202. +}
  1203. +
  1204. +VkResult
  1205. +pvr_mesa_wsi_get_swapchain_counter(struct pvr_mesa_wsi *mwsi,
  1206. + VkDevice device,
  1207. + VkSwapchainKHR swapchain,
  1208. + VkSurfaceCounterFlagBitsEXT flagBits,
  1209. + uint64_t *pValue)
  1210. +{
  1211. + return wsi_get_swapchain_counter(device,
  1212. + &mwsi->wsi,
  1213. + swapchain,
  1214. + flagBits,
  1215. + pValue);
  1216. +}
  1217. +
  1218. diff --git a/src/pvr/wsi/pvr_wsi_wayland.c b/src/pvr/wsi/pvr_wsi_wayland.c
  1219. new file mode 100644
  1220. index 0000000..5b05266
  1221. --- /dev/null
  1222. +++ b/src/pvr/wsi/pvr_wsi_wayland.c
  1223. @@ -0,0 +1,45 @@
  1224. +/*
  1225. + * Copyright © Imagination Technologies Ltd.
  1226. + *
  1227. + * The contents of this file are subject to the MIT license as set out below.
  1228. + *
  1229. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  1230. + * of this software and associated documentation files (the "Software"), to deal
  1231. + * in the Software without restriction, including without limitation the rights
  1232. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1233. + * copies of the Software, and to permit persons to whom the Software is
  1234. + * furnished to do so, subject to the following conditions:
  1235. + *
  1236. + * The above copyright notice and this permission notice shall be included in
  1237. + * all copies or substantial portions of the Software.
  1238. + *
  1239. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1240. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1241. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1242. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1243. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1244. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1245. + * THE SOFTWARE.
  1246. + */
  1247. +
  1248. +#include "wsi_common_wayland.h"
  1249. +
  1250. +#include "pvr_wsi.h"
  1251. +#include "pvr_mesa_wsi_interface.h"
  1252. +
  1253. +VkBool32
  1254. +pvr_mesa_wsi_get_physical_device_wayland_presentation_support(struct pvr_mesa_wsi *mwsi,
  1255. + uint32_t queueFamilyIndex,
  1256. + void *display)
  1257. +{
  1258. + return wsi_wl_get_presentation_support(&mwsi->wsi, display);
  1259. +}
  1260. +
  1261. +VkResult
  1262. +pvr_mesa_wsi_create_wayland_surface(UNUSED struct pvr_mesa_wsi *mwsi,
  1263. + const VkAllocationCallbacks *pAllocator,
  1264. + const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
  1265. + VkSurfaceKHR *pSurface)
  1266. +{
  1267. + return wsi_create_wl_surface(pAllocator, pCreateInfo, pSurface);
  1268. +}
  1269. diff --git a/src/pvr/wsi/pvr_wsi_x11.c b/src/pvr/wsi/pvr_wsi_x11.c
  1270. new file mode 100644
  1271. index 0000000..0a69e92
  1272. --- /dev/null
  1273. +++ b/src/pvr/wsi/pvr_wsi_x11.c
  1274. @@ -0,0 +1,62 @@
  1275. +/*
  1276. + * Copyright © Imagination Technologies Ltd.
  1277. + *
  1278. + * The contents of this file are subject to the MIT license as set out below.
  1279. + *
  1280. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  1281. + * of this software and associated documentation files (the "Software"), to deal
  1282. + * in the Software without restriction, including without limitation the rights
  1283. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1284. + * copies of the Software, and to permit persons to whom the Software is
  1285. + * furnished to do so, subject to the following conditions:
  1286. + *
  1287. + * The above copyright notice and this permission notice shall be included in
  1288. + * all copies or substantial portions of the Software.
  1289. + *
  1290. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1291. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1292. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1293. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1294. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1295. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1296. + * THE SOFTWARE.
  1297. + */
  1298. +
  1299. +#include "wsi_common_x11.h"
  1300. +
  1301. +#include "pvr_wsi.h"
  1302. +#include "pvr_mesa_wsi_interface.h"
  1303. +
  1304. +VkBool32
  1305. +pvr_mesa_wsi_get_physical_device_xcb_presentation_support(struct pvr_mesa_wsi *mwsi,
  1306. + uint32_t queueFamilyIndex,
  1307. + void *connection,
  1308. + uint32_t visual_id)
  1309. +{
  1310. + return wsi_get_physical_device_xcb_presentation_support(&mwsi->wsi,
  1311. + queueFamilyIndex,
  1312. + connection,
  1313. + visual_id);
  1314. +}
  1315. +
  1316. +VkResult
  1317. +pvr_mesa_wsi_create_xcb_surface(UNUSED struct pvr_mesa_wsi *mwsi,
  1318. + const VkAllocationCallbacks *pAllocator,
  1319. + const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
  1320. + VkSurfaceKHR *pSurface)
  1321. +{
  1322. + return wsi_create_xcb_surface(pAllocator,
  1323. + pCreateInfo,
  1324. + pSurface);
  1325. +}
  1326. +
  1327. +VkResult
  1328. +pvr_mesa_wsi_create_xlib_surface(UNUSED struct pvr_mesa_wsi *mwsi,
  1329. + const VkAllocationCallbacks *pAllocator,
  1330. + const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
  1331. + VkSurfaceKHR *pSurface)
  1332. +{
  1333. + return wsi_create_xlib_surface(pAllocator,
  1334. + pCreateInfo,
  1335. + pSurface);
  1336. +}