wsi.c 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526
  1. /*
  2. * Copyright (c) 2015-2016, 2019 The Khronos Group Inc.
  3. * Copyright (c) 2015-2016, 2019 Valve Corporation
  4. * Copyright (c) 2015-2016, 2019 LunarG, Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Author: Ian Elliott <[email protected]>
  19. * Author: Jon Ashburn <[email protected]>
  20. * Author: Ian Elliott <[email protected]>
  21. * Author: Mark Lobodzinski <[email protected]>
  22. * Author: Lenny Komow <[email protected]>
  23. */
  24. #ifndef _GNU_SOURCE
  25. #define _GNU_SOURCE
  26. #endif
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "vk_loader_platform.h"
  31. #include "loader.h"
  32. #include "wsi.h"
  33. #include <vulkan/vk_icd.h>
  34. // The first ICD/Loader interface that support querying the SurfaceKHR from
  35. // the ICDs.
  36. #define ICD_VER_SUPPORTS_ICD_SURFACE_KHR 3
  37. void wsi_create_instance(struct loader_instance *ptr_instance, const VkInstanceCreateInfo *pCreateInfo) {
  38. ptr_instance->wsi_surface_enabled = false;
  39. #ifdef VK_USE_PLATFORM_WIN32_KHR
  40. ptr_instance->wsi_win32_surface_enabled = false;
  41. #endif // VK_USE_PLATFORM_WIN32_KHR
  42. #ifdef VK_USE_PLATFORM_WAYLAND_KHR
  43. ptr_instance->wsi_wayland_surface_enabled = false;
  44. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  45. #ifdef VK_USE_PLATFORM_XCB_KHR
  46. ptr_instance->wsi_xcb_surface_enabled = false;
  47. #endif // VK_USE_PLATFORM_XCB_KHR
  48. #ifdef VK_USE_PLATFORM_XLIB_KHR
  49. ptr_instance->wsi_xlib_surface_enabled = false;
  50. #endif // VK_USE_PLATFORM_XLIB_KHR
  51. #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
  52. ptr_instance->wsi_directfb_surface_enabled = false;
  53. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  54. #ifdef VK_USE_PLATFORM_ANDROID_KHR
  55. ptr_instance->wsi_android_surface_enabled = false;
  56. #endif // VK_USE_PLATFORM_ANDROID_KHR
  57. #ifdef VK_USE_PLATFORM_MACOS_MVK
  58. ptr_instance->wsi_macos_surface_enabled = false;
  59. #endif // VK_USE_PLATFORM_MACOS_MVK
  60. #ifdef VK_USE_PLATFORM_IOS_MVK
  61. ptr_instance->wsi_ios_surface_enabled = false;
  62. #endif // VK_USE_PLATFORM_IOS_MVK
  63. #ifdef VK_USE_PLATFORM_GGP
  64. ptr_instance->wsi_ggp_surface_enabled = false;
  65. #endif // VK_USE_PLATFORM_GGP
  66. #ifdef VK_USE_PLATFORM_FUCHSIA
  67. ptr_instance->wsi_imagepipe_surface_enabled = false;
  68. #endif // VK_USE_PLATFORM_FUCHSIA
  69. ptr_instance->wsi_display_enabled = false;
  70. ptr_instance->wsi_display_props2_enabled = false;
  71. #ifdef VK_USE_PLATFORM_METAL_EXT
  72. ptr_instance->wsi_metal_surface_enabled = false;
  73. #endif // VK_USE_PLATFORM_METAL_EXT
  74. for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
  75. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
  76. ptr_instance->wsi_surface_enabled = true;
  77. continue;
  78. }
  79. #ifdef VK_USE_PLATFORM_WIN32_KHR
  80. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
  81. ptr_instance->wsi_win32_surface_enabled = true;
  82. continue;
  83. }
  84. #endif // VK_USE_PLATFORM_WIN32_KHR
  85. #ifdef VK_USE_PLATFORM_WAYLAND_KHR
  86. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
  87. ptr_instance->wsi_wayland_surface_enabled = true;
  88. continue;
  89. }
  90. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  91. #ifdef VK_USE_PLATFORM_XCB_KHR
  92. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
  93. ptr_instance->wsi_xcb_surface_enabled = true;
  94. continue;
  95. }
  96. #endif // VK_USE_PLATFORM_XCB_KHR
  97. #ifdef VK_USE_PLATFORM_XLIB_KHR
  98. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
  99. ptr_instance->wsi_xlib_surface_enabled = true;
  100. continue;
  101. }
  102. #endif // VK_USE_PLATFORM_XLIB_KHR
  103. #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
  104. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME) == 0) {
  105. ptr_instance->wsi_directfb_surface_enabled = true;
  106. continue;
  107. }
  108. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  109. #ifdef VK_USE_PLATFORM_ANDROID_KHR
  110. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
  111. ptr_instance->wsi_android_surface_enabled = true;
  112. continue;
  113. }
  114. #endif // VK_USE_PLATFORM_ANDROID_KHR
  115. #ifdef VK_USE_PLATFORM_MACOS_MVK
  116. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_MVK_MACOS_SURFACE_EXTENSION_NAME) == 0) {
  117. ptr_instance->wsi_macos_surface_enabled = true;
  118. continue;
  119. }
  120. #endif // VK_USE_PLATFORM_MACOS_MVK
  121. #ifdef VK_USE_PLATFORM_IOS_MVK
  122. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_MVK_IOS_SURFACE_EXTENSION_NAME) == 0) {
  123. ptr_instance->wsi_ios_surface_enabled = true;
  124. continue;
  125. }
  126. #endif // VK_USE_PLATFORM_IOS_MVK
  127. #ifdef VK_USE_PLATFORM_GGP
  128. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME) == 0) {
  129. ptr_instance->wsi_ggp_surface_enabled = true;
  130. continue;
  131. }
  132. #endif // VK_USE_PLATFORM_GGP
  133. #ifdef VK_USE_PLATFORM_FUCHSIA
  134. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_FUCHSIA_IMAGEPIPE_SURFACE_EXTENSION_NAME) == 0) {
  135. ptr_instance->wsi_imagepipe_surface_enabled = true;
  136. continue;
  137. }
  138. #endif // VK_USE_PLATFORM_FUCHSIA
  139. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME) == 0) {
  140. ptr_instance->wsi_headless_surface_enabled = true;
  141. continue;
  142. }
  143. #if defined(VK_USE_PLATFORM_METAL_EXT)
  144. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_METAL_SURFACE_EXTENSION_NAME) == 0) {
  145. ptr_instance->wsi_metal_surface_enabled = true;
  146. continue;
  147. }
  148. #endif
  149. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
  150. ptr_instance->wsi_display_enabled = true;
  151. continue;
  152. }
  153. if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME) == 0) {
  154. ptr_instance->wsi_display_props2_enabled = true;
  155. continue;
  156. }
  157. }
  158. }
  159. // Linux WSI surface extensions are not always compiled into the loader. (Assume
  160. // for Windows the KHR_win32_surface is always compiled into loader). A given
  161. // Linux build environment might not have the headers required for building one
  162. // of the three extensions (Xlib, Xcb, Wayland). Thus, need to check if
  163. // the built loader actually supports the particular Linux surface extension.
  164. // If not supported by the built loader it will not be included in the list of
  165. // enumerated instance extensions. This solves the issue where an ICD or layer
  166. // advertises support for a given Linux surface extension but the loader was not
  167. // built to support the extension.
  168. bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
  169. #ifndef VK_USE_PLATFORM_WAYLAND_KHR
  170. if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface")) return true;
  171. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  172. #ifndef VK_USE_PLATFORM_XCB_KHR
  173. if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface")) return true;
  174. #endif // VK_USE_PLATFORM_XCB_KHR
  175. #ifndef VK_USE_PLATFORM_XLIB_KHR
  176. if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface")) return true;
  177. #endif // VK_USE_PLATFORM_XLIB_KHR
  178. #ifndef VK_USE_PLATFORM_DIRECTFB_EXT
  179. if (!strcmp(ext_prop->extensionName, "VK_EXT_directfb_surface")) return true;
  180. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  181. return false;
  182. }
  183. // Functions for the VK_KHR_surface extension:
  184. // This is the trampoline entrypoint for DestroySurfaceKHR
  185. LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
  186. const VkAllocationCallbacks *pAllocator) {
  187. const VkLayerInstanceDispatchTable *disp;
  188. disp = loader_get_instance_layer_dispatch(instance);
  189. disp->DestroySurfaceKHR(instance, surface, pAllocator);
  190. }
  191. // TODO probably need to lock around all the loader_get_instance() calls.
  192. // This is the instance chain terminator function for DestroySurfaceKHR
  193. VKAPI_ATTR void VKAPI_CALL terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
  194. const VkAllocationCallbacks *pAllocator) {
  195. struct loader_instance *ptr_instance = loader_get_instance(instance);
  196. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
  197. if (NULL != icd_surface) {
  198. if (NULL != icd_surface->real_icd_surfaces) {
  199. uint32_t i = 0;
  200. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  201. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  202. if (NULL != icd_term->dispatch.DestroySurfaceKHR && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[i]) {
  203. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, icd_surface->real_icd_surfaces[i], pAllocator);
  204. icd_surface->real_icd_surfaces[i] = (VkSurfaceKHR)NULL;
  205. }
  206. } else {
  207. // The real_icd_surface for any ICD not supporting the
  208. // proper interface version should be NULL. If not, then
  209. // we have a problem.
  210. assert((VkSurfaceKHR)NULL == icd_surface->real_icd_surfaces[i]);
  211. }
  212. }
  213. loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
  214. }
  215. loader_instance_heap_free(ptr_instance, (void *)(uintptr_t)surface);
  216. }
  217. }
  218. // This is the trampoline entrypoint for GetPhysicalDeviceSurfaceSupportKHR
  219. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
  220. uint32_t queueFamilyIndex, VkSurfaceKHR surface,
  221. VkBool32 *pSupported) {
  222. const VkLayerInstanceDispatchTable *disp;
  223. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  224. disp = loader_get_instance_layer_dispatch(physicalDevice);
  225. VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
  226. return res;
  227. }
  228. // This is the instance chain terminator function for
  229. // GetPhysicalDeviceSurfaceSupportKHR
  230. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
  231. uint32_t queueFamilyIndex, VkSurfaceKHR surface,
  232. VkBool32 *pSupported) {
  233. // First, check to ensure the appropriate extension was enabled:
  234. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  235. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  236. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  237. if (!ptr_instance->wsi_surface_enabled) {
  238. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  239. "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceSupportKHR not executed!\n");
  240. return VK_SUCCESS;
  241. }
  242. if (NULL == pSupported) {
  243. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  244. "NULL pointer passed into vkGetPhysicalDeviceSurfaceSupportKHR for pSupported!\n");
  245. assert(false && "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
  246. }
  247. *pSupported = false;
  248. if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR) {
  249. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  250. "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceSupportKHR!\n");
  251. assert(false && "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
  252. }
  253. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
  254. if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
  255. return icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR(
  256. phys_dev_term->phys_dev, queueFamilyIndex, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSupported);
  257. }
  258. return icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, surface, pSupported);
  259. }
  260. // This is the trampoline entrypoint for GetPhysicalDeviceSurfaceCapabilitiesKHR
  261. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
  262. VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
  263. const VkLayerInstanceDispatchTable *disp;
  264. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  265. disp = loader_get_instance_layer_dispatch(physicalDevice);
  266. VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(unwrapped_phys_dev, surface, pSurfaceCapabilities);
  267. return res;
  268. }
  269. // This is the instance chain terminator function for
  270. // GetPhysicalDeviceSurfaceCapabilitiesKHR
  271. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
  272. VkSurfaceKHR surface,
  273. VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
  274. // First, check to ensure the appropriate extension was enabled:
  275. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  276. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  277. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  278. if (!ptr_instance->wsi_surface_enabled) {
  279. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  280. "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed!\n");
  281. return VK_SUCCESS;
  282. }
  283. if (NULL == pSurfaceCapabilities) {
  284. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  285. "NULL pointer passed into vkGetPhysicalDeviceSurfaceCapabilitiesKHR for pSurfaceCapabilities!\n");
  286. assert(false && "GetPhysicalDeviceSurfaceCapabilitiesKHR: Error, null pSurfaceCapabilities");
  287. }
  288. if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR) {
  289. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  290. "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceCapabilitiesKHR!\n");
  291. assert(false && "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
  292. }
  293. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
  294. if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
  295. return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(
  296. phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSurfaceCapabilities);
  297. }
  298. return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, surface, pSurfaceCapabilities);
  299. }
  300. // This is the trampoline entrypoint for GetPhysicalDeviceSurfaceFormatsKHR
  301. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
  302. VkSurfaceKHR surface,
  303. uint32_t *pSurfaceFormatCount,
  304. VkSurfaceFormatKHR *pSurfaceFormats) {
  305. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  306. const VkLayerInstanceDispatchTable *disp;
  307. disp = loader_get_instance_layer_dispatch(physicalDevice);
  308. VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
  309. return res;
  310. }
  311. // This is the instance chain terminator function for
  312. // GetPhysicalDeviceSurfaceFormatsKHR
  313. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
  314. uint32_t *pSurfaceFormatCount,
  315. VkSurfaceFormatKHR *pSurfaceFormats) {
  316. // First, check to ensure the appropriate extension was enabled:
  317. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  318. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  319. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  320. if (!ptr_instance->wsi_surface_enabled) {
  321. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  322. "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceFormatsKHR not executed!\n");
  323. return VK_SUCCESS;
  324. }
  325. if (NULL == pSurfaceFormatCount) {
  326. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  327. "NULL pointer passed into vkGetPhysicalDeviceSurfaceFormatsKHR for pSurfaceFormatCount!\n");
  328. assert(false && "GetPhysicalDeviceSurfaceFormatsKHR(: Error, null pSurfaceFormatCount");
  329. }
  330. if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR) {
  331. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  332. "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceCapabilitiesKHR!\n");
  333. assert(false && "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
  334. }
  335. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
  336. if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
  337. return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev,
  338. icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
  339. pSurfaceFormatCount, pSurfaceFormats);
  340. }
  341. return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface, pSurfaceFormatCount,
  342. pSurfaceFormats);
  343. }
  344. // This is the trampoline entrypoint for GetPhysicalDeviceSurfacePresentModesKHR
  345. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
  346. VkSurfaceKHR surface,
  347. uint32_t *pPresentModeCount,
  348. VkPresentModeKHR *pPresentModes) {
  349. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  350. const VkLayerInstanceDispatchTable *disp;
  351. disp = loader_get_instance_layer_dispatch(physicalDevice);
  352. VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
  353. return res;
  354. }
  355. // This is the instance chain terminator function for
  356. // GetPhysicalDeviceSurfacePresentModesKHR
  357. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
  358. VkSurfaceKHR surface, uint32_t *pPresentModeCount,
  359. VkPresentModeKHR *pPresentModes) {
  360. // First, check to ensure the appropriate extension was enabled:
  361. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  362. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  363. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  364. if (!ptr_instance->wsi_surface_enabled) {
  365. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  366. "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfacePresentModesKHR not executed!\n");
  367. return VK_SUCCESS;
  368. }
  369. if (NULL == pPresentModeCount) {
  370. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  371. "NULL pointer passed into vkGetPhysicalDeviceSurfacePresentModesKHR for pPresentModeCount!\n");
  372. assert(false && "GetPhysicalDeviceSurfacePresentModesKHR(: Error, null pPresentModeCount");
  373. }
  374. if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR) {
  375. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  376. "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfacePresentModesKHR!\n");
  377. assert(false && "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
  378. }
  379. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
  380. if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
  381. return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR(
  382. phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pPresentModeCount, pPresentModes);
  383. }
  384. return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR(phys_dev_term->phys_dev, surface, pPresentModeCount,
  385. pPresentModes);
  386. }
  387. // Functions for the VK_KHR_swapchain extension:
  388. // This is the trampoline entrypoint for CreateSwapchainKHR
  389. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
  390. const VkAllocationCallbacks *pAllocator,
  391. VkSwapchainKHR *pSwapchain) {
  392. const VkLayerDispatchTable *disp;
  393. disp = loader_get_dispatch(device);
  394. return disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
  395. }
  396. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
  397. const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
  398. uint32_t icd_index = 0;
  399. struct loader_device *dev;
  400. struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
  401. if (NULL != icd_term && NULL != icd_term->dispatch.CreateSwapchainKHR) {
  402. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfo->surface;
  403. if (NULL != icd_surface->real_icd_surfaces) {
  404. if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
  405. // We found the ICD, and there is an ICD KHR surface
  406. // associated with it, so copy the CreateInfo struct
  407. // and point it at the ICD's surface.
  408. VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR));
  409. if (NULL == pCreateCopy) {
  410. return VK_ERROR_OUT_OF_HOST_MEMORY;
  411. }
  412. memcpy(pCreateCopy, pCreateInfo, sizeof(VkSwapchainCreateInfoKHR));
  413. pCreateCopy->surface = icd_surface->real_icd_surfaces[icd_index];
  414. return icd_term->dispatch.CreateSwapchainKHR(device, pCreateCopy, pAllocator, pSwapchain);
  415. }
  416. }
  417. return icd_term->dispatch.CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
  418. }
  419. return VK_SUCCESS;
  420. }
  421. // This is the trampoline entrypoint for DestroySwapchainKHR
  422. LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
  423. const VkAllocationCallbacks *pAllocator) {
  424. const VkLayerDispatchTable *disp;
  425. disp = loader_get_dispatch(device);
  426. disp->DestroySwapchainKHR(device, swapchain, pAllocator);
  427. }
  428. // This is the trampoline entrypoint for GetSwapchainImagesKHR
  429. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
  430. uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) {
  431. const VkLayerDispatchTable *disp;
  432. disp = loader_get_dispatch(device);
  433. return disp->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
  434. }
  435. // This is the trampoline entrypoint for AcquireNextImageKHR
  436. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
  437. VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
  438. const VkLayerDispatchTable *disp;
  439. disp = loader_get_dispatch(device);
  440. return disp->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
  441. }
  442. // This is the trampoline entrypoint for QueuePresentKHR
  443. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
  444. const VkLayerDispatchTable *disp;
  445. disp = loader_get_dispatch(queue);
  446. return disp->QueuePresentKHR(queue, pPresentInfo);
  447. }
  448. static VkIcdSurface *AllocateIcdSurfaceStruct(struct loader_instance *instance, size_t base_size, size_t platform_size) {
  449. // Next, if so, proceed with the implementation of this function:
  450. VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
  451. if (pIcdSurface != NULL) {
  452. // Setup the new sizes and offsets so we can grow the structures in the
  453. // future without having problems
  454. pIcdSurface->base_size = (uint32_t)base_size;
  455. pIcdSurface->platform_size = (uint32_t)platform_size;
  456. pIcdSurface->non_platform_offset = (uint32_t)((uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
  457. pIcdSurface->entire_size = sizeof(VkIcdSurface);
  458. pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
  459. VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
  460. if (pIcdSurface->real_icd_surfaces == NULL) {
  461. loader_instance_heap_free(instance, pIcdSurface);
  462. pIcdSurface = NULL;
  463. } else {
  464. memset(pIcdSurface->real_icd_surfaces, 0, sizeof(VkSurfaceKHR) * instance->total_icd_count);
  465. }
  466. }
  467. return pIcdSurface;
  468. }
  469. #ifdef VK_USE_PLATFORM_WIN32_KHR
  470. // Functions for the VK_KHR_win32_surface extension:
  471. // This is the trampoline entrypoint for CreateWin32SurfaceKHR
  472. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance,
  473. const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
  474. const VkAllocationCallbacks *pAllocator,
  475. VkSurfaceKHR *pSurface) {
  476. const VkLayerInstanceDispatchTable *disp;
  477. disp = loader_get_instance_layer_dispatch(instance);
  478. VkResult res;
  479. res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
  480. return res;
  481. }
  482. // This is the instance chain terminator function for CreateWin32SurfaceKHR
  483. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
  484. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  485. VkResult vkRes = VK_SUCCESS;
  486. VkIcdSurface *pIcdSurface = NULL;
  487. uint32_t i = 0;
  488. // Initialize pSurface to NULL just to be safe.
  489. *pSurface = VK_NULL_HANDLE;
  490. // First, check to ensure the appropriate extension was enabled:
  491. struct loader_instance *ptr_instance = loader_get_instance(instance);
  492. if (!ptr_instance->wsi_win32_surface_enabled) {
  493. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  494. "VK_KHR_win32_surface extension not enabled. vkCreateWin32SurfaceKHR not executed!\n");
  495. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  496. goto out;
  497. }
  498. // Next, if so, proceed with the implementation of this function:
  499. pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->win_surf.base), sizeof(pIcdSurface->win_surf));
  500. if (pIcdSurface == NULL) {
  501. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  502. goto out;
  503. }
  504. pIcdSurface->win_surf.base.platform = VK_ICD_WSI_PLATFORM_WIN32;
  505. pIcdSurface->win_surf.hinstance = pCreateInfo->hinstance;
  506. pIcdSurface->win_surf.hwnd = pCreateInfo->hwnd;
  507. // Loop through each ICD and determine if they need to create a surface
  508. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  509. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  510. if (NULL != icd_term->dispatch.CreateWin32SurfaceKHR) {
  511. vkRes = icd_term->dispatch.CreateWin32SurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
  512. &pIcdSurface->real_icd_surfaces[i]);
  513. if (VK_SUCCESS != vkRes) {
  514. goto out;
  515. }
  516. }
  517. }
  518. }
  519. *pSurface = (VkSurfaceKHR)(pIcdSurface);
  520. out:
  521. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  522. if (NULL != pIcdSurface->real_icd_surfaces) {
  523. i = 0;
  524. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  525. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  526. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  527. }
  528. }
  529. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  530. }
  531. loader_instance_heap_free(ptr_instance, pIcdSurface);
  532. }
  533. return vkRes;
  534. }
  535. // This is the trampoline entrypoint for
  536. // GetPhysicalDeviceWin32PresentationSupportKHR
  537. LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
  538. uint32_t queueFamilyIndex) {
  539. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  540. const VkLayerInstanceDispatchTable *disp;
  541. disp = loader_get_instance_layer_dispatch(physicalDevice);
  542. VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex);
  543. return res;
  544. }
  545. // This is the instance chain terminator function for
  546. // GetPhysicalDeviceWin32PresentationSupportKHR
  547. VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
  548. uint32_t queueFamilyIndex) {
  549. // First, check to ensure the appropriate extension was enabled:
  550. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  551. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  552. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  553. if (!ptr_instance->wsi_win32_surface_enabled) {
  554. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  555. "VK_KHR_win32_surface extension not enabled. vkGetPhysicalDeviceWin32PresentationSupportKHR not executed!\n");
  556. return VK_SUCCESS;
  557. }
  558. if (NULL == icd_term->dispatch.GetPhysicalDeviceWin32PresentationSupportKHR) {
  559. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  560. "ICD for selected physical device is not exporting vkGetPhysicalDeviceWin32PresentationSupportKHR!\n");
  561. assert(false && "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD pointer");
  562. }
  563. return icd_term->dispatch.GetPhysicalDeviceWin32PresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex);
  564. }
  565. #endif // VK_USE_PLATFORM_WIN32_KHR
  566. #ifdef VK_USE_PLATFORM_WAYLAND_KHR
  567. // This is the trampoline entrypoint for CreateWaylandSurfaceKHR
  568. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance,
  569. const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
  570. const VkAllocationCallbacks *pAllocator,
  571. VkSurfaceKHR *pSurface) {
  572. const VkLayerInstanceDispatchTable *disp;
  573. disp = loader_get_instance_layer_dispatch(instance);
  574. VkResult res;
  575. res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
  576. return res;
  577. }
  578. // This is the instance chain terminator function for CreateWaylandSurfaceKHR
  579. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(VkInstance instance,
  580. const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
  581. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  582. VkResult vkRes = VK_SUCCESS;
  583. VkIcdSurface *pIcdSurface = NULL;
  584. uint32_t i = 0;
  585. // First, check to ensure the appropriate extension was enabled:
  586. struct loader_instance *ptr_instance = loader_get_instance(instance);
  587. if (!ptr_instance->wsi_wayland_surface_enabled) {
  588. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  589. "VK_KHR_wayland_surface extension not enabled. vkCreateWaylandSurfaceKHR not executed!\n");
  590. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  591. goto out;
  592. }
  593. // Next, if so, proceed with the implementation of this function:
  594. pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->wayland_surf.base), sizeof(pIcdSurface->wayland_surf));
  595. if (pIcdSurface == NULL) {
  596. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  597. goto out;
  598. }
  599. pIcdSurface->wayland_surf.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
  600. pIcdSurface->wayland_surf.display = pCreateInfo->display;
  601. pIcdSurface->wayland_surf.surface = pCreateInfo->surface;
  602. // Loop through each ICD and determine if they need to create a surface
  603. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  604. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  605. if (NULL != icd_term->dispatch.CreateWaylandSurfaceKHR) {
  606. vkRes = icd_term->dispatch.CreateWaylandSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
  607. &pIcdSurface->real_icd_surfaces[i]);
  608. if (VK_SUCCESS != vkRes) {
  609. goto out;
  610. }
  611. }
  612. }
  613. }
  614. *pSurface = (VkSurfaceKHR)pIcdSurface;
  615. out:
  616. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  617. if (NULL != pIcdSurface->real_icd_surfaces) {
  618. i = 0;
  619. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  620. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  621. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  622. }
  623. }
  624. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  625. }
  626. loader_instance_heap_free(ptr_instance, pIcdSurface);
  627. }
  628. return vkRes;
  629. }
  630. // This is the trampoline entrypoint for
  631. // GetPhysicalDeviceWaylandPresentationSupportKHR
  632. LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
  633. uint32_t queueFamilyIndex,
  634. struct wl_display *display) {
  635. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  636. const VkLayerInstanceDispatchTable *disp;
  637. disp = loader_get_instance_layer_dispatch(physicalDevice);
  638. VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, display);
  639. return res;
  640. }
  641. // This is the instance chain terminator function for
  642. // GetPhysicalDeviceWaylandPresentationSupportKHR
  643. VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
  644. uint32_t queueFamilyIndex,
  645. struct wl_display *display) {
  646. // First, check to ensure the appropriate extension was enabled:
  647. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  648. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  649. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  650. if (!ptr_instance->wsi_wayland_surface_enabled) {
  651. loader_log(
  652. ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  653. "VK_KHR_wayland_surface extension not enabled. vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
  654. return VK_SUCCESS;
  655. }
  656. if (NULL == icd_term->dispatch.GetPhysicalDeviceWaylandPresentationSupportKHR) {
  657. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  658. "ICD for selected physical device is not exporting vkGetPhysicalDeviceWaylandPresentationSupportKHR!\n");
  659. assert(false && "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD pointer");
  660. }
  661. return icd_term->dispatch.GetPhysicalDeviceWaylandPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, display);
  662. }
  663. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  664. #ifdef VK_USE_PLATFORM_XCB_KHR
  665. // Functions for the VK_KHR_xcb_surface extension:
  666. // This is the trampoline entrypoint for CreateXcbSurfaceKHR
  667. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(VkInstance instance,
  668. const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
  669. const VkAllocationCallbacks *pAllocator,
  670. VkSurfaceKHR *pSurface) {
  671. const VkLayerInstanceDispatchTable *disp;
  672. disp = loader_get_instance_layer_dispatch(instance);
  673. VkResult res;
  674. res = disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
  675. return res;
  676. }
  677. // This is the instance chain terminator function for CreateXcbSurfaceKHR
  678. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
  679. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  680. VkResult vkRes = VK_SUCCESS;
  681. VkIcdSurface *pIcdSurface = NULL;
  682. uint32_t i = 0;
  683. // First, check to ensure the appropriate extension was enabled:
  684. struct loader_instance *ptr_instance = loader_get_instance(instance);
  685. if (!ptr_instance->wsi_xcb_surface_enabled) {
  686. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  687. "VK_KHR_xcb_surface extension not enabled. vkCreateXcbSurfaceKHR not executed!\n");
  688. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  689. goto out;
  690. }
  691. // Next, if so, proceed with the implementation of this function:
  692. pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xcb_surf.base), sizeof(pIcdSurface->xcb_surf));
  693. if (pIcdSurface == NULL) {
  694. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  695. goto out;
  696. }
  697. pIcdSurface->xcb_surf.base.platform = VK_ICD_WSI_PLATFORM_XCB;
  698. pIcdSurface->xcb_surf.connection = pCreateInfo->connection;
  699. pIcdSurface->xcb_surf.window = pCreateInfo->window;
  700. // Loop through each ICD and determine if they need to create a surface
  701. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  702. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  703. if (NULL != icd_term->dispatch.CreateXcbSurfaceKHR) {
  704. vkRes = icd_term->dispatch.CreateXcbSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
  705. &pIcdSurface->real_icd_surfaces[i]);
  706. if (VK_SUCCESS != vkRes) {
  707. goto out;
  708. }
  709. }
  710. }
  711. }
  712. *pSurface = (VkSurfaceKHR)pIcdSurface;
  713. out:
  714. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  715. if (NULL != pIcdSurface->real_icd_surfaces) {
  716. i = 0;
  717. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  718. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  719. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  720. }
  721. }
  722. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  723. }
  724. loader_instance_heap_free(ptr_instance, pIcdSurface);
  725. }
  726. return vkRes;
  727. }
  728. // This is the trampoline entrypoint for
  729. // GetPhysicalDeviceXcbPresentationSupportKHR
  730. LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
  731. uint32_t queueFamilyIndex,
  732. xcb_connection_t *connection,
  733. xcb_visualid_t visual_id) {
  734. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  735. const VkLayerInstanceDispatchTable *disp;
  736. disp = loader_get_instance_layer_dispatch(physicalDevice);
  737. VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
  738. return res;
  739. }
  740. // This is the instance chain terminator function for
  741. // GetPhysicalDeviceXcbPresentationSupportKHR
  742. VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
  743. uint32_t queueFamilyIndex,
  744. xcb_connection_t *connection,
  745. xcb_visualid_t visual_id) {
  746. // First, check to ensure the appropriate extension was enabled:
  747. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  748. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  749. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  750. if (!ptr_instance->wsi_xcb_surface_enabled) {
  751. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  752. "VK_KHR_xcb_surface extension not enabled. vkGetPhysicalDeviceXcbPresentationSupportKHR not executed!\n");
  753. return VK_SUCCESS;
  754. }
  755. if (NULL == icd_term->dispatch.GetPhysicalDeviceXcbPresentationSupportKHR) {
  756. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  757. "ICD for selected physical device is not exporting vkGetPhysicalDeviceXcbPresentationSupportKHR!\n");
  758. assert(false && "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
  759. }
  760. return icd_term->dispatch.GetPhysicalDeviceXcbPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, connection,
  761. visual_id);
  762. }
  763. #endif // VK_USE_PLATFORM_XCB_KHR
  764. #ifdef VK_USE_PLATFORM_XLIB_KHR
  765. // Functions for the VK_KHR_xlib_surface extension:
  766. // This is the trampoline entrypoint for CreateXlibSurfaceKHR
  767. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance,
  768. const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
  769. const VkAllocationCallbacks *pAllocator,
  770. VkSurfaceKHR *pSurface) {
  771. const VkLayerInstanceDispatchTable *disp;
  772. disp = loader_get_instance_layer_dispatch(instance);
  773. VkResult res;
  774. res = disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
  775. return res;
  776. }
  777. // This is the instance chain terminator function for CreateXlibSurfaceKHR
  778. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
  779. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  780. VkResult vkRes = VK_SUCCESS;
  781. VkIcdSurface *pIcdSurface = NULL;
  782. uint32_t i = 0;
  783. // First, check to ensure the appropriate extension was enabled:
  784. struct loader_instance *ptr_instance = loader_get_instance(instance);
  785. if (!ptr_instance->wsi_xlib_surface_enabled) {
  786. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  787. "VK_KHR_xlib_surface extension not enabled. vkCreateXlibSurfaceKHR not executed!\n");
  788. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  789. goto out;
  790. }
  791. // Next, if so, proceed with the implementation of this function:
  792. pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xlib_surf.base), sizeof(pIcdSurface->xlib_surf));
  793. if (pIcdSurface == NULL) {
  794. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  795. goto out;
  796. }
  797. pIcdSurface->xlib_surf.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
  798. pIcdSurface->xlib_surf.dpy = pCreateInfo->dpy;
  799. pIcdSurface->xlib_surf.window = pCreateInfo->window;
  800. // Loop through each ICD and determine if they need to create a surface
  801. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  802. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  803. if (NULL != icd_term->dispatch.CreateXlibSurfaceKHR) {
  804. vkRes = icd_term->dispatch.CreateXlibSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
  805. &pIcdSurface->real_icd_surfaces[i]);
  806. if (VK_SUCCESS != vkRes) {
  807. goto out;
  808. }
  809. }
  810. }
  811. }
  812. *pSurface = (VkSurfaceKHR)pIcdSurface;
  813. out:
  814. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  815. if (NULL != pIcdSurface->real_icd_surfaces) {
  816. i = 0;
  817. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  818. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  819. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  820. }
  821. }
  822. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  823. }
  824. loader_instance_heap_free(ptr_instance, pIcdSurface);
  825. }
  826. return vkRes;
  827. }
  828. // This is the trampoline entrypoint for
  829. // GetPhysicalDeviceXlibPresentationSupportKHR
  830. LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
  831. uint32_t queueFamilyIndex, Display *dpy,
  832. VisualID visualID) {
  833. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  834. const VkLayerInstanceDispatchTable *disp;
  835. disp = loader_get_instance_layer_dispatch(physicalDevice);
  836. VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
  837. return res;
  838. }
  839. // This is the instance chain terminator function for
  840. // GetPhysicalDeviceXlibPresentationSupportKHR
  841. VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
  842. uint32_t queueFamilyIndex, Display *dpy,
  843. VisualID visualID) {
  844. // First, check to ensure the appropriate extension was enabled:
  845. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  846. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  847. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  848. if (!ptr_instance->wsi_xlib_surface_enabled) {
  849. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  850. "VK_KHR_xlib_surface extension not enabled. vkGetPhysicalDeviceXlibPresentationSupportKHR not executed!\n");
  851. return VK_SUCCESS;
  852. }
  853. if (NULL == icd_term->dispatch.GetPhysicalDeviceXlibPresentationSupportKHR) {
  854. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  855. "ICD for selected physical device is not exporting vkGetPhysicalDeviceXlibPresentationSupportKHR!\n");
  856. assert(false && "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
  857. }
  858. return icd_term->dispatch.GetPhysicalDeviceXlibPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, dpy, visualID);
  859. }
  860. #endif // VK_USE_PLATFORM_XLIB_KHR
  861. #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
  862. // Functions for the VK_EXT_directfb_surface extension:
  863. // This is the trampoline entrypoint for CreateDirectFBSurfaceEXT
  864. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT(VkInstance instance,
  865. const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
  866. const VkAllocationCallbacks *pAllocator,
  867. VkSurfaceKHR *pSurface) {
  868. const VkLayerInstanceDispatchTable *disp;
  869. disp = loader_get_instance_layer_dispatch(instance);
  870. VkResult res;
  871. res = disp->CreateDirectFBSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
  872. return res;
  873. }
  874. // This is the instance chain terminator function for CreateDirectFBSurfaceEXT
  875. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDirectFBSurfaceEXT(VkInstance instance,
  876. const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
  877. const VkAllocationCallbacks *pAllocator,
  878. VkSurfaceKHR *pSurface) {
  879. VkResult vkRes = VK_SUCCESS;
  880. VkIcdSurface *pIcdSurface = NULL;
  881. uint32_t i = 0;
  882. // First, check to ensure the appropriate extension was enabled:
  883. struct loader_instance *ptr_instance = loader_get_instance(instance);
  884. if (!ptr_instance->wsi_directfb_surface_enabled) {
  885. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  886. "VK_EXT_directfb_surface extension not enabled. vkCreateDirectFBSurfaceEXT not executed!\n");
  887. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  888. goto out;
  889. }
  890. // Next, if so, proceed with the implementation of this function:
  891. pIcdSurface =
  892. AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->directfb_surf.base), sizeof(pIcdSurface->directfb_surf));
  893. if (pIcdSurface == NULL) {
  894. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  895. goto out;
  896. }
  897. pIcdSurface->directfb_surf.base.platform = VK_ICD_WSI_PLATFORM_DIRECTFB;
  898. pIcdSurface->directfb_surf.dfb = pCreateInfo->dfb;
  899. pIcdSurface->directfb_surf.surface = pCreateInfo->surface;
  900. // Loop through each ICD and determine if they need to create a surface
  901. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  902. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  903. if (NULL != icd_term->dispatch.CreateDirectFBSurfaceEXT) {
  904. vkRes = icd_term->dispatch.CreateDirectFBSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
  905. &pIcdSurface->real_icd_surfaces[i]);
  906. if (VK_SUCCESS != vkRes) {
  907. goto out;
  908. }
  909. }
  910. }
  911. }
  912. *pSurface = (VkSurfaceKHR)pIcdSurface;
  913. out:
  914. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  915. if (NULL != pIcdSurface->real_icd_surfaces) {
  916. i = 0;
  917. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  918. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  919. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  920. }
  921. }
  922. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  923. }
  924. loader_instance_heap_free(ptr_instance, pIcdSurface);
  925. }
  926. return vkRes;
  927. }
  928. // This is the trampoline entrypoint for
  929. // GetPhysicalDeviceDirectFBPresentationSupportEXT
  930. LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
  931. uint32_t queueFamilyIndex,
  932. IDirectFB *dfb) {
  933. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  934. const VkLayerInstanceDispatchTable *disp;
  935. disp = loader_get_instance_layer_dispatch(physicalDevice);
  936. VkBool32 res = disp->GetPhysicalDeviceDirectFBPresentationSupportEXT(unwrapped_phys_dev, queueFamilyIndex, dfb);
  937. return res;
  938. }
  939. // This is the instance chain terminator function for
  940. // GetPhysicalDeviceDirectFBPresentationSupportEXT
  941. VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
  942. uint32_t queueFamilyIndex,
  943. IDirectFB *dfb) {
  944. // First, check to ensure the appropriate extension was enabled:
  945. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  946. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  947. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  948. if (!ptr_instance->wsi_directfb_surface_enabled) {
  949. loader_log(
  950. ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  951. "VK_EXT_directfb_surface extension not enabled. vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
  952. return VK_SUCCESS;
  953. }
  954. if (NULL == icd_term->dispatch.GetPhysicalDeviceDirectFBPresentationSupportEXT) {
  955. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  956. "ICD for selected physical device is not exporting vkGetPhysicalDeviceDirectFBPresentationSupportEXT!\n");
  957. assert(false && "loader: null GetPhysicalDeviceDirectFBPresentationSupportEXT ICD pointer");
  958. }
  959. return icd_term->dispatch.GetPhysicalDeviceDirectFBPresentationSupportEXT(phys_dev_term->phys_dev, queueFamilyIndex, dfb);
  960. }
  961. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  962. #ifdef VK_USE_PLATFORM_ANDROID_KHR
  963. // Functions for the VK_KHR_android_surface extension:
  964. // This is the trampoline entrypoint for CreateAndroidSurfaceKHR
  965. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(VkInstance instance, ANativeWindow *window,
  966. const VkAllocationCallbacks *pAllocator,
  967. VkSurfaceKHR *pSurface) {
  968. const VkLayerInstanceDispatchTable *disp;
  969. disp = loader_get_instance_layer_dispatch(instance);
  970. VkResult res;
  971. res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
  972. return res;
  973. }
  974. // This is the instance chain terminator function for CreateAndroidSurfaceKHR
  975. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(VkInstance instance, Window window,
  976. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  977. // First, check to ensure the appropriate extension was enabled:
  978. struct loader_instance *ptr_instance = loader_get_instance(instance);
  979. if (!ptr_instance->wsi_display_enabled) {
  980. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  981. "VK_KHR_display extension not enabled. vkCreateAndroidSurfaceKHR not executed!\n");
  982. return VK_ERROR_EXTENSION_NOT_PRESENT;
  983. }
  984. // Next, if so, proceed with the implementation of this function:
  985. VkIcdSurfaceAndroid *pIcdSurface =
  986. loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
  987. if (pIcdSurface == NULL) {
  988. return VK_ERROR_OUT_OF_HOST_MEMORY;
  989. }
  990. pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
  991. pIcdSurface->window = window;
  992. *pSurface = (VkSurfaceKHR)pIcdSurface;
  993. return VK_SUCCESS;
  994. }
  995. #endif // VK_USE_PLATFORM_ANDROID_KHR
  996. // Functions for the VK_EXT_headless_surface extension:
  997. VKAPI_ATTR VkResult VKAPI_CALL vkCreateHeadlessSurfaceEXT(VkInstance instance, const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
  998. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  999. const VkLayerInstanceDispatchTable *disp;
  1000. disp = loader_get_instance_layer_dispatch(instance);
  1001. VkResult res;
  1002. res = disp->CreateHeadlessSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
  1003. return res;
  1004. }
  1005. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateHeadlessSurfaceEXT(VkInstance instance,
  1006. const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
  1007. const VkAllocationCallbacks *pAllocator,
  1008. VkSurfaceKHR *pSurface) {
  1009. struct loader_instance *inst = loader_get_instance(instance);
  1010. VkIcdSurface *pIcdSurface = NULL;
  1011. VkResult vkRes = VK_SUCCESS;
  1012. uint32_t i = 0;
  1013. if (!inst->wsi_headless_surface_enabled) {
  1014. loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1015. "VK_EXT_headless_surface extension not enabled. "
  1016. "vkCreateHeadlessSurfaceEXT not executed!\n");
  1017. return VK_SUCCESS;
  1018. }
  1019. // Next, if so, proceed with the implementation of this function:
  1020. pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->headless_surf.base), sizeof(pIcdSurface->headless_surf));
  1021. if (pIcdSurface == NULL) {
  1022. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  1023. goto out;
  1024. }
  1025. pIcdSurface->headless_surf.base.platform = VK_ICD_WSI_PLATFORM_HEADLESS;
  1026. // Loop through each ICD and determine if they need to create a surface
  1027. for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1028. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  1029. if (NULL != icd_term->dispatch.CreateHeadlessSurfaceEXT) {
  1030. vkRes = icd_term->dispatch.CreateHeadlessSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
  1031. &pIcdSurface->real_icd_surfaces[i]);
  1032. if (VK_SUCCESS != vkRes) {
  1033. goto out;
  1034. }
  1035. }
  1036. }
  1037. }
  1038. *pSurface = (VkSurfaceKHR)pIcdSurface;
  1039. out:
  1040. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  1041. if (NULL != pIcdSurface->real_icd_surfaces) {
  1042. i = 0;
  1043. for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1044. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  1045. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  1046. }
  1047. }
  1048. loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
  1049. }
  1050. loader_instance_heap_free(inst, pIcdSurface);
  1051. }
  1052. return vkRes;
  1053. }
  1054. #ifdef VK_USE_PLATFORM_MACOS_MVK
  1055. // Functions for the VK_MVK_macos_surface extension:
  1056. // This is the trampoline entrypoint for CreateMacOSSurfaceMVK
  1057. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(VkInstance instance,
  1058. const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
  1059. const VkAllocationCallbacks *pAllocator,
  1060. VkSurfaceKHR *pSurface) {
  1061. const VkLayerInstanceDispatchTable *disp;
  1062. disp = loader_get_instance_layer_dispatch(instance);
  1063. VkResult res;
  1064. res = disp->CreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
  1065. return res;
  1066. }
  1067. // This is the instance chain terminator function for CreateMacOSSurfaceKHR
  1068. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
  1069. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  1070. VkResult vkRes = VK_SUCCESS;
  1071. VkIcdSurface *pIcdSurface = NULL;
  1072. uint32_t i = 0;
  1073. // First, check to ensure the appropriate extension was enabled:
  1074. struct loader_instance *ptr_instance = loader_get_instance(instance);
  1075. if (!ptr_instance->wsi_macos_surface_enabled) {
  1076. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1077. "VK_MVK_macos_surface extension not enabled. vkCreateMacOSSurfaceMVK not executed!\n");
  1078. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  1079. goto out;
  1080. }
  1081. // Next, if so, proceed with the implementation of this function:
  1082. pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->macos_surf.base), sizeof(pIcdSurface->macos_surf));
  1083. if (pIcdSurface == NULL) {
  1084. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  1085. goto out;
  1086. }
  1087. pIcdSurface->macos_surf.base.platform = VK_ICD_WSI_PLATFORM_MACOS;
  1088. pIcdSurface->macos_surf.pView = pCreateInfo->pView;
  1089. // Loop through each ICD and determine if they need to create a surface
  1090. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1091. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  1092. if (NULL != icd_term->dispatch.CreateMacOSSurfaceMVK) {
  1093. vkRes = icd_term->dispatch.CreateMacOSSurfaceMVK(icd_term->instance, pCreateInfo, pAllocator,
  1094. &pIcdSurface->real_icd_surfaces[i]);
  1095. if (VK_SUCCESS != vkRes) {
  1096. goto out;
  1097. }
  1098. }
  1099. }
  1100. }
  1101. *pSurface = (VkSurfaceKHR)pIcdSurface;
  1102. out:
  1103. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  1104. if (NULL != pIcdSurface->real_icd_surfaces) {
  1105. i = 0;
  1106. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1107. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  1108. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  1109. }
  1110. }
  1111. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  1112. }
  1113. loader_instance_heap_free(ptr_instance, pIcdSurface);
  1114. }
  1115. return vkRes;
  1116. }
  1117. #endif // VK_USE_PLATFORM_MACOS_MVK
  1118. #ifdef VK_USE_PLATFORM_IOS_MVK
  1119. // Functions for the VK_MVK_ios_surface extension:
  1120. // This is the trampoline entrypoint for CreateIOSSurfaceMVK
  1121. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(VkInstance instance,
  1122. const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
  1123. const VkAllocationCallbacks *pAllocator,
  1124. VkSurfaceKHR *pSurface) {
  1125. const VkLayerInstanceDispatchTable *disp;
  1126. disp = loader_get_instance_layer_dispatch(instance);
  1127. VkResult res;
  1128. res = disp->CreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
  1129. return res;
  1130. }
  1131. // This is the instance chain terminator function for CreateIOSSurfaceKHR
  1132. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
  1133. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  1134. // First, check to ensure the appropriate extension was enabled:
  1135. struct loader_instance *ptr_instance = loader_get_instance(instance);
  1136. if (!ptr_instance->wsi_ios_surface_enabled) {
  1137. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1138. "VK_MVK_ios_surface extension not enabled. vkCreateIOSSurfaceMVK not executed!\n");
  1139. return VK_ERROR_EXTENSION_NOT_PRESENT;
  1140. }
  1141. // Next, if so, proceed with the implementation of this function:
  1142. VkIcdSurfaceIOS *pIcdSurface =
  1143. loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceIOS), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
  1144. if (pIcdSurface == NULL) {
  1145. return VK_ERROR_OUT_OF_HOST_MEMORY;
  1146. }
  1147. pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_IOS;
  1148. pIcdSurface->pView = pCreateInfo->pView;
  1149. *pSurface = (VkSurfaceKHR)pIcdSurface;
  1150. return VK_SUCCESS;
  1151. }
  1152. #endif // VK_USE_PLATFORM_IOS_MVK
  1153. #ifdef VK_USE_PLATFORM_GGP
  1154. // Functions for the VK_GGP_stream_descriptor_surface extension:
  1155. // This is the trampoline entrypoint for CreateStreamDescriptorSurfaceGGP
  1156. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
  1157. vkCreateStreamDescriptorSurfaceGGP(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo,
  1158. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  1159. const VkLayerInstanceDispatchTable *disp;
  1160. disp = loader_get_instance_layer_dispatch(instance);
  1161. VkResult res;
  1162. res = disp->CreateStreamDescriptorSurfaceGGP(instance, pCreateInfo, pAllocator, pSurface);
  1163. return res;
  1164. }
  1165. // This is the instance chain terminator function for CreateStreamDescriptorSurfaceGGP
  1166. VKAPI_ATTR VkResult VKAPI_CALL
  1167. terminator_CreateStreamDescriptorSurfaceGGP(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo,
  1168. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  1169. VkResult vkRes = VK_SUCCESS;
  1170. VkIcdSurface *pIcdSurface = NULL;
  1171. uint32_t i = 0;
  1172. // First, check to ensure the appropriate extension was enabled:
  1173. struct loader_instance *ptr_instance = loader_get_instance(instance);
  1174. if (!ptr_instance->wsi_ggp_surface_enabled) {
  1175. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1176. "VK_GGP_stream_descriptor_surface extension not enabled. vkCreateStreamDescriptorSurfaceGGP not executed!\n");
  1177. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  1178. goto out;
  1179. }
  1180. // Next, if so, proceed with the implementation of this function:
  1181. pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->ggp_surf.base), sizeof(pIcdSurface->ggp_surf));
  1182. if (pIcdSurface == NULL) {
  1183. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  1184. goto out;
  1185. }
  1186. pIcdSurface->ggp_surf.base.platform = VK_ICD_WSI_PLATFORM_GGP;
  1187. pIcdSurface->ggp_surf.streamDescriptor = pCreateInfo->streamDescriptor;
  1188. // Loop through each ICD and determine if they need to create a surface
  1189. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1190. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  1191. if (NULL != icd_term->dispatch.CreateStreamDescriptorSurfaceGGP) {
  1192. vkRes = icd_term->dispatch.CreateStreamDescriptorSurfaceGGP(icd_term->instance, pCreateInfo, pAllocator,
  1193. &pIcdSurface->real_icd_surfaces[i]);
  1194. if (VK_SUCCESS != vkRes) {
  1195. goto out;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. *pSurface = (VkSurfaceKHR)pIcdSurface;
  1201. out:
  1202. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  1203. if (NULL != pIcdSurface->real_icd_surfaces) {
  1204. i = 0;
  1205. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1206. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  1207. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  1208. }
  1209. }
  1210. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  1211. }
  1212. loader_instance_heap_free(ptr_instance, pIcdSurface);
  1213. }
  1214. return vkRes;
  1215. }
  1216. #endif // VK_USE_PLATFORM_GGP
  1217. #if defined(VK_USE_PLATFORM_METAL_EXT)
  1218. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT(VkInstance instance,
  1219. const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
  1220. const VkAllocationCallbacks *pAllocator,
  1221. VkSurfaceKHR *pSurface) {
  1222. const VkLayerInstanceDispatchTable *disp = loader_get_instance_layer_dispatch(instance);
  1223. return disp->CreateMetalSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
  1224. }
  1225. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
  1226. const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
  1227. VkResult result = VK_SUCCESS;
  1228. VkIcdSurface *icd_surface = NULL;
  1229. uint32_t i;
  1230. // First, check to ensure the appropriate extension was enabled:
  1231. struct loader_instance *ptr_instance = loader_get_instance(instance);
  1232. if (!ptr_instance->wsi_metal_surface_enabled) {
  1233. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1234. "VK_EXT_metal_surface extension not enabled. vkCreateMetalSurfaceEXT will not be executed.\n");
  1235. }
  1236. // Next, if so, proceed with the implementation of this function:
  1237. icd_surface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(icd_surface->metal_surf.base), sizeof(icd_surface->metal_surf));
  1238. if (icd_surface == NULL) {
  1239. result = VK_ERROR_OUT_OF_HOST_MEMORY;
  1240. goto out;
  1241. }
  1242. icd_surface->metal_surf.base.platform = VK_ICD_WSI_PLATFORM_METAL;
  1243. icd_surface->metal_surf.pLayer = pCreateInfo->pLayer;
  1244. // Loop through each ICD and determine if they need to create a surface
  1245. i = 0;
  1246. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, ++i) {
  1247. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  1248. if (icd_term->dispatch.CreateMetalSurfaceEXT != NULL) {
  1249. result = icd_term->dispatch.CreateMetalSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
  1250. &icd_surface->real_icd_surfaces[i]);
  1251. if (result != VK_SUCCESS) {
  1252. goto out;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. *pSurface = (VkSurfaceKHR)icd_surface;
  1258. out:
  1259. if (result != VK_SUCCESS && icd_surface != NULL) {
  1260. if (icd_surface->real_icd_surfaces != NULL) {
  1261. i = 0;
  1262. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, ++i) {
  1263. if (icd_surface->real_icd_surfaces[i] == VK_NULL_HANDLE && icd_term->dispatch.DestroySurfaceKHR != NULL) {
  1264. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, icd_surface->real_icd_surfaces[i], pAllocator);
  1265. }
  1266. }
  1267. loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
  1268. }
  1269. loader_instance_heap_free(ptr_instance, icd_surface);
  1270. }
  1271. return result;
  1272. }
  1273. #endif
  1274. // Functions for the VK_KHR_display instance extension:
  1275. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
  1276. uint32_t *pPropertyCount,
  1277. VkDisplayPropertiesKHR *pProperties) {
  1278. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1279. const VkLayerInstanceDispatchTable *disp;
  1280. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1281. VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
  1282. return res;
  1283. }
  1284. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
  1285. uint32_t *pPropertyCount,
  1286. VkDisplayPropertiesKHR *pProperties) {
  1287. // First, check to ensure the appropriate extension was enabled:
  1288. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1289. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1290. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1291. if (!ptr_instance->wsi_display_enabled) {
  1292. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1293. "VK_KHR_display extension not enabled. vkGetPhysicalDeviceDisplayPropertiesKHR not executed!\n");
  1294. return VK_SUCCESS;
  1295. }
  1296. if (NULL == icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR) {
  1297. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1298. "ICD for selected physical device is not exporting vkGetPhysicalDeviceDisplayPropertiesKHR!\n");
  1299. assert(false && "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
  1300. }
  1301. return icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
  1302. }
  1303. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
  1304. VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlanePropertiesKHR *pProperties) {
  1305. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1306. const VkLayerInstanceDispatchTable *disp;
  1307. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1308. VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
  1309. return res;
  1310. }
  1311. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
  1312. uint32_t *pPropertyCount,
  1313. VkDisplayPlanePropertiesKHR *pProperties) {
  1314. // First, check to ensure the appropriate extension was enabled:
  1315. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1316. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1317. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1318. if (!ptr_instance->wsi_display_enabled) {
  1319. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1320. "VK_KHR_display extension not enabled. vkGetPhysicalDeviceDisplayPlanePropertiesKHR not executed!\n");
  1321. return VK_SUCCESS;
  1322. }
  1323. if (NULL == icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR) {
  1324. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1325. "ICD for selected physical device is not exporting vkGetPhysicalDeviceDisplayPlanePropertiesKHR!\n");
  1326. assert(false && "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
  1327. }
  1328. return icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
  1329. }
  1330. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
  1331. uint32_t planeIndex, uint32_t *pDisplayCount,
  1332. VkDisplayKHR *pDisplays) {
  1333. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1334. const VkLayerInstanceDispatchTable *disp;
  1335. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1336. VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
  1337. return res;
  1338. }
  1339. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
  1340. uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
  1341. // First, check to ensure the appropriate extension was enabled:
  1342. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1343. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1344. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1345. if (!ptr_instance->wsi_display_enabled) {
  1346. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1347. "VK_KHR_display extension not enabled. vkGetDisplayPlaneSupportedDisplaysKHR not executed!\n");
  1348. return VK_SUCCESS;
  1349. }
  1350. if (NULL == icd_term->dispatch.GetDisplayPlaneSupportedDisplaysKHR) {
  1351. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1352. "ICD for selected physical device is not exporting vkGetDisplayPlaneSupportedDisplaysKHR!\n");
  1353. assert(false && "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
  1354. }
  1355. return icd_term->dispatch.GetDisplayPlaneSupportedDisplaysKHR(phys_dev_term->phys_dev, planeIndex, pDisplayCount, pDisplays);
  1356. }
  1357. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
  1358. uint32_t *pPropertyCount,
  1359. VkDisplayModePropertiesKHR *pProperties) {
  1360. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1361. const VkLayerInstanceDispatchTable *disp;
  1362. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1363. VkResult res = disp->GetDisplayModePropertiesKHR(unwrapped_phys_dev, display, pPropertyCount, pProperties);
  1364. return res;
  1365. }
  1366. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
  1367. uint32_t *pPropertyCount,
  1368. VkDisplayModePropertiesKHR *pProperties) {
  1369. // First, check to ensure the appropriate extension was enabled:
  1370. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1371. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1372. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1373. if (!ptr_instance->wsi_display_enabled) {
  1374. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1375. "VK_KHR_display extension not enabled. vkGetDisplayModePropertiesKHR not executed!\n");
  1376. return VK_SUCCESS;
  1377. }
  1378. if (NULL == icd_term->dispatch.GetDisplayModePropertiesKHR) {
  1379. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1380. "ICD for selected physical device is not exporting vkGetDisplayModePropertiesKHR!\n");
  1381. assert(false && "loader: null GetDisplayModePropertiesKHR ICD pointer");
  1382. }
  1383. return icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
  1384. }
  1385. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
  1386. const VkDisplayModeCreateInfoKHR *pCreateInfo,
  1387. const VkAllocationCallbacks *pAllocator,
  1388. VkDisplayModeKHR *pMode) {
  1389. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1390. const VkLayerInstanceDispatchTable *disp;
  1391. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1392. VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display, pCreateInfo, pAllocator, pMode);
  1393. return res;
  1394. }
  1395. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
  1396. const VkDisplayModeCreateInfoKHR *pCreateInfo,
  1397. const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
  1398. // First, check to ensure the appropriate extension was enabled:
  1399. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1400. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1401. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1402. if (!ptr_instance->wsi_display_enabled) {
  1403. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1404. "VK_KHR_display extension not enabled. vkCreateDisplayModeKHR not executed!\n");
  1405. return VK_ERROR_EXTENSION_NOT_PRESENT;
  1406. }
  1407. if (NULL == icd_term->dispatch.CreateDisplayModeKHR) {
  1408. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1409. "ICD for selected physical device is not exporting vkCreateDisplayModeKHR!\n");
  1410. assert(false && "loader: null CreateDisplayModeKHR ICD pointer");
  1411. }
  1412. return icd_term->dispatch.CreateDisplayModeKHR(phys_dev_term->phys_dev, display, pCreateInfo, pAllocator, pMode);
  1413. }
  1414. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,
  1415. VkDisplayModeKHR mode, uint32_t planeIndex,
  1416. VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
  1417. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1418. const VkLayerInstanceDispatchTable *disp;
  1419. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1420. VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(unwrapped_phys_dev, mode, planeIndex, pCapabilities);
  1421. return res;
  1422. }
  1423. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode,
  1424. uint32_t planeIndex,
  1425. VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
  1426. // First, check to ensure the appropriate extension was enabled:
  1427. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1428. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1429. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1430. if (!ptr_instance->wsi_display_enabled) {
  1431. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1432. "VK_KHR_display extension not enabled. vkGetDisplayPlaneCapabilitiesKHR not executed!\n");
  1433. return VK_SUCCESS;
  1434. }
  1435. if (NULL == icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR) {
  1436. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1437. "ICD for selected physical device is not exporting vkGetDisplayPlaneCapabilitiesKHR!\n");
  1438. assert(false && "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
  1439. }
  1440. return icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR(phys_dev_term->phys_dev, mode, planeIndex, pCapabilities);
  1441. }
  1442. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,
  1443. const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
  1444. const VkAllocationCallbacks *pAllocator,
  1445. VkSurfaceKHR *pSurface) {
  1446. const VkLayerInstanceDispatchTable *disp;
  1447. disp = loader_get_instance_layer_dispatch(instance);
  1448. VkResult res;
  1449. res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
  1450. return res;
  1451. }
  1452. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(VkInstance instance,
  1453. const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
  1454. const VkAllocationCallbacks *pAllocator,
  1455. VkSurfaceKHR *pSurface) {
  1456. struct loader_instance *inst = loader_get_instance(instance);
  1457. VkIcdSurface *pIcdSurface = NULL;
  1458. VkResult vkRes = VK_SUCCESS;
  1459. uint32_t i = 0;
  1460. if (!inst->wsi_display_enabled) {
  1461. loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1462. "VK_KHR_surface extension not enabled. vkCreateDisplayPlaneSurfaceKHR not executed!\n");
  1463. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  1464. goto out;
  1465. }
  1466. // Next, if so, proceed with the implementation of this function:
  1467. pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->display_surf.base), sizeof(pIcdSurface->display_surf));
  1468. if (pIcdSurface == NULL) {
  1469. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  1470. goto out;
  1471. }
  1472. pIcdSurface->display_surf.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
  1473. pIcdSurface->display_surf.displayMode = pCreateInfo->displayMode;
  1474. pIcdSurface->display_surf.planeIndex = pCreateInfo->planeIndex;
  1475. pIcdSurface->display_surf.planeStackIndex = pCreateInfo->planeStackIndex;
  1476. pIcdSurface->display_surf.transform = pCreateInfo->transform;
  1477. pIcdSurface->display_surf.globalAlpha = pCreateInfo->globalAlpha;
  1478. pIcdSurface->display_surf.alphaMode = pCreateInfo->alphaMode;
  1479. pIcdSurface->display_surf.imageExtent = pCreateInfo->imageExtent;
  1480. // Loop through each ICD and determine if they need to create a surface
  1481. for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1482. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  1483. if (NULL != icd_term->dispatch.CreateDisplayPlaneSurfaceKHR) {
  1484. vkRes = icd_term->dispatch.CreateDisplayPlaneSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
  1485. &pIcdSurface->real_icd_surfaces[i]);
  1486. if (VK_SUCCESS != vkRes) {
  1487. goto out;
  1488. }
  1489. }
  1490. }
  1491. }
  1492. *pSurface = (VkSurfaceKHR)pIcdSurface;
  1493. out:
  1494. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  1495. if (NULL != pIcdSurface->real_icd_surfaces) {
  1496. i = 0;
  1497. for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1498. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  1499. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  1500. }
  1501. }
  1502. loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
  1503. }
  1504. loader_instance_heap_free(inst, pIcdSurface);
  1505. }
  1506. return vkRes;
  1507. }
  1508. // EXT_display_swapchain Extension command
  1509. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
  1510. const VkSwapchainCreateInfoKHR *pCreateInfos,
  1511. const VkAllocationCallbacks *pAllocator,
  1512. VkSwapchainKHR *pSwapchains) {
  1513. const VkLayerDispatchTable *disp;
  1514. disp = loader_get_dispatch(device);
  1515. return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
  1516. }
  1517. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
  1518. const VkSwapchainCreateInfoKHR *pCreateInfos,
  1519. const VkAllocationCallbacks *pAllocator,
  1520. VkSwapchainKHR *pSwapchains) {
  1521. uint32_t icd_index = 0;
  1522. struct loader_device *dev;
  1523. struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
  1524. if (NULL != icd_term && NULL != icd_term->dispatch.CreateSharedSwapchainsKHR) {
  1525. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfos->surface;
  1526. if (NULL != icd_surface->real_icd_surfaces) {
  1527. if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
  1528. // We found the ICD, and there is an ICD KHR surface
  1529. // associated with it, so copy the CreateInfo struct
  1530. // and point it at the ICD's surface.
  1531. VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
  1532. if (NULL == pCreateCopy) {
  1533. return VK_ERROR_OUT_OF_HOST_MEMORY;
  1534. }
  1535. memcpy(pCreateCopy, pCreateInfos, sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
  1536. for (uint32_t sc = 0; sc < swapchainCount; sc++) {
  1537. pCreateCopy[sc].surface = icd_surface->real_icd_surfaces[icd_index];
  1538. }
  1539. return icd_term->dispatch.CreateSharedSwapchainsKHR(device, swapchainCount, pCreateCopy, pAllocator, pSwapchains);
  1540. }
  1541. }
  1542. return icd_term->dispatch.CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
  1543. }
  1544. return VK_SUCCESS;
  1545. }
  1546. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupPresentCapabilitiesKHR(
  1547. VkDevice device,
  1548. VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) {
  1549. const VkLayerDispatchTable *disp = loader_get_dispatch(device);
  1550. return disp->GetDeviceGroupPresentCapabilitiesKHR(device, pDeviceGroupPresentCapabilities);
  1551. }
  1552. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR(
  1553. VkDevice device,
  1554. VkSurfaceKHR surface,
  1555. VkDeviceGroupPresentModeFlagsKHR* pModes) {
  1556. const VkLayerDispatchTable *disp = loader_get_dispatch(device);
  1557. return disp->GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
  1558. }
  1559. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDeviceGroupSurfacePresentModesKHR(
  1560. VkDevice device,
  1561. VkSurfaceKHR surface,
  1562. VkDeviceGroupPresentModeFlagsKHR* pModes) {
  1563. uint32_t icd_index = 0;
  1564. struct loader_device *dev;
  1565. struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
  1566. if (NULL != icd_term && NULL != icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR) {
  1567. VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
  1568. if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
  1569. return icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR(device, icd_surface->real_icd_surfaces[icd_index], pModes);
  1570. }
  1571. return icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
  1572. }
  1573. return VK_SUCCESS;
  1574. }
  1575. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR(
  1576. VkPhysicalDevice physicalDevice,
  1577. VkSurfaceKHR surface,
  1578. uint32_t* pRectCount,
  1579. VkRect2D* pRects) {
  1580. const VkLayerInstanceDispatchTable *disp;
  1581. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1582. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1583. return disp->GetPhysicalDevicePresentRectanglesKHR(unwrapped_phys_dev, surface, pRectCount, pRects);
  1584. }
  1585. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDevicePresentRectanglesKHR(
  1586. VkPhysicalDevice physicalDevice,
  1587. VkSurfaceKHR surface,
  1588. uint32_t* pRectCount,
  1589. VkRect2D* pRects) {
  1590. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1591. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1592. if (NULL == icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR) {
  1593. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1594. "ICD associated with VkPhysicalDevice does not support GetPhysicalDevicePresentRectanglesKHX");
  1595. }
  1596. VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
  1597. uint8_t icd_index = phys_dev_term->icd_index;
  1598. if (NULL != icd_surface->real_icd_surfaces && NULL != (void *)icd_surface->real_icd_surfaces[icd_index]) {
  1599. return icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR(phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[icd_index], pRectCount, pRects);
  1600. }
  1601. return icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR(phys_dev_term->phys_dev, surface, pRectCount, pRects);
  1602. }
  1603. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImage2KHR(
  1604. VkDevice device,
  1605. const VkAcquireNextImageInfoKHR* pAcquireInfo,
  1606. uint32_t* pImageIndex) {
  1607. const VkLayerDispatchTable *disp = loader_get_dispatch(device);
  1608. return disp->AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
  1609. }
  1610. // ---- VK_KHR_get_display_properties2 extension trampoline/terminators
  1611. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
  1612. uint32_t *pPropertyCount,
  1613. VkDisplayProperties2KHR *pProperties) {
  1614. const VkLayerInstanceDispatchTable *disp;
  1615. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1616. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1617. return disp->GetPhysicalDeviceDisplayProperties2KHR(unwrapped_phys_dev, pPropertyCount, pProperties);
  1618. }
  1619. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
  1620. uint32_t *pPropertyCount,
  1621. VkDisplayProperties2KHR *pProperties) {
  1622. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1623. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1624. // If the function is available in the driver, just call into it
  1625. if (icd_term->dispatch.GetPhysicalDeviceDisplayProperties2KHR != NULL) {
  1626. return icd_term->dispatch.GetPhysicalDeviceDisplayProperties2KHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
  1627. }
  1628. // We have to emulate the function.
  1629. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
  1630. "vkGetPhysicalDeviceDisplayProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
  1631. // If the icd doesn't support VK_KHR_display, then no properties are available
  1632. if (icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR == NULL) {
  1633. *pPropertyCount = 0;
  1634. return VK_SUCCESS;
  1635. }
  1636. // If we aren't writing to pProperties, then emulation is straightforward
  1637. if (pProperties == NULL || *pPropertyCount == 0) {
  1638. return icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, NULL);
  1639. }
  1640. // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayPropertiesKHR and copy it
  1641. VkDisplayPropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayPropertiesKHR));
  1642. if (properties == NULL) {
  1643. return VK_ERROR_OUT_OF_HOST_MEMORY;
  1644. }
  1645. VkResult res = icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, properties);
  1646. if (res < 0) {
  1647. return res;
  1648. }
  1649. for (uint32_t i = 0; i < *pPropertyCount; ++i) {
  1650. memcpy(&pProperties[i].displayProperties, &properties[i], sizeof(VkDisplayPropertiesKHR));
  1651. }
  1652. return res;
  1653. }
  1654. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlaneProperties2KHR(
  1655. VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlaneProperties2KHR *pProperties) {
  1656. const VkLayerInstanceDispatchTable *disp;
  1657. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1658. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1659. return disp->GetPhysicalDeviceDisplayPlaneProperties2KHR(unwrapped_phys_dev, pPropertyCount, pProperties);
  1660. }
  1661. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
  1662. uint32_t *pPropertyCount,
  1663. VkDisplayPlaneProperties2KHR *pProperties) {
  1664. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1665. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1666. // If the function is available in the driver, just call into it
  1667. if (icd_term->dispatch.GetPhysicalDeviceDisplayPlaneProperties2KHR != NULL) {
  1668. return icd_term->dispatch.GetPhysicalDeviceDisplayPlaneProperties2KHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
  1669. }
  1670. // We have to emulate the function.
  1671. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
  1672. "vkGetPhysicalDeviceDisplayPlaneProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
  1673. // If the icd doesn't support VK_KHR_display, then no properties are available
  1674. if (icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR == NULL) {
  1675. *pPropertyCount = 0;
  1676. return VK_SUCCESS;
  1677. }
  1678. // If we aren't writing to pProperties, then emulation is straightforward
  1679. if (pProperties == NULL || *pPropertyCount == 0) {
  1680. return icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, NULL);
  1681. }
  1682. // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayPlanePropertiesKHR and copy it
  1683. VkDisplayPlanePropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayPlanePropertiesKHR));
  1684. if (properties == NULL) {
  1685. return VK_ERROR_OUT_OF_HOST_MEMORY;
  1686. }
  1687. VkResult res =
  1688. icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, properties);
  1689. if (res < 0) {
  1690. return res;
  1691. }
  1692. for (uint32_t i = 0; i < *pPropertyCount; ++i) {
  1693. memcpy(&pProperties[i].displayPlaneProperties, &properties[i], sizeof(VkDisplayPlanePropertiesKHR));
  1694. }
  1695. return res;
  1696. }
  1697. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
  1698. uint32_t *pPropertyCount,
  1699. VkDisplayModeProperties2KHR *pProperties) {
  1700. const VkLayerInstanceDispatchTable *disp;
  1701. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1702. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1703. return disp->GetDisplayModeProperties2KHR(unwrapped_phys_dev, display, pPropertyCount, pProperties);
  1704. }
  1705. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
  1706. uint32_t *pPropertyCount,
  1707. VkDisplayModeProperties2KHR *pProperties) {
  1708. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1709. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1710. // If the function is available in the driver, just call into it
  1711. if (icd_term->dispatch.GetDisplayModeProperties2KHR != NULL) {
  1712. return icd_term->dispatch.GetDisplayModeProperties2KHR(phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
  1713. }
  1714. // We have to emulate the function.
  1715. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
  1716. "vkGetDisplayModeProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
  1717. // If the icd doesn't support VK_KHR_display, then no properties are available
  1718. if (icd_term->dispatch.GetDisplayModePropertiesKHR == NULL) {
  1719. *pPropertyCount = 0;
  1720. return VK_SUCCESS;
  1721. }
  1722. // If we aren't writing to pProperties, then emulation is straightforward
  1723. if (pProperties == NULL || *pPropertyCount == 0) {
  1724. return icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, NULL);
  1725. }
  1726. // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayModePropertiesKHR and copy it
  1727. VkDisplayModePropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayModePropertiesKHR));
  1728. if (properties == NULL) {
  1729. return VK_ERROR_OUT_OF_HOST_MEMORY;
  1730. }
  1731. VkResult res = icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, properties);
  1732. if (res < 0) {
  1733. return res;
  1734. }
  1735. for (uint32_t i = 0; i < *pPropertyCount; ++i) {
  1736. memcpy(&pProperties[i].displayModeProperties, &properties[i], sizeof(VkDisplayModePropertiesKHR));
  1737. }
  1738. return res;
  1739. }
  1740. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice,
  1741. const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
  1742. VkDisplayPlaneCapabilities2KHR *pCapabilities) {
  1743. const VkLayerInstanceDispatchTable *disp;
  1744. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1745. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1746. return disp->GetDisplayPlaneCapabilities2KHR(unwrapped_phys_dev, pDisplayPlaneInfo, pCapabilities);
  1747. }
  1748. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice,
  1749. const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
  1750. VkDisplayPlaneCapabilities2KHR *pCapabilities) {
  1751. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1752. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1753. // If the function is abailable in the driver, just call into it
  1754. if (icd_term->dispatch.GetDisplayPlaneCapabilities2KHR != NULL) {
  1755. return icd_term->dispatch.GetDisplayPlaneCapabilities2KHR(phys_dev_term->phys_dev, pDisplayPlaneInfo, pCapabilities);
  1756. }
  1757. // We have to emulate the function.
  1758. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
  1759. "vkGetDisplayPlaneCapabilities2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
  1760. // Just call into the old version of the function.
  1761. // If the icd doesn't support VK_KHR_display, there are zero planes and this call is invalid (and will crash)
  1762. return icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR(phys_dev_term->phys_dev, pDisplayPlaneInfo->mode,
  1763. pDisplayPlaneInfo->planeIndex, &pCapabilities->capabilities);
  1764. }
  1765. #ifdef VK_USE_PLATFORM_FUCHSIA
  1766. // This is the trampoline entrypoint for CreateImagePipeSurfaceFUCHSIA
  1767. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImagePipeSurfaceFUCHSIA(VkInstance instance,
  1768. const VkImagePipeSurfaceCreateInfoFUCHSIA *pCreateInfo,
  1769. const VkAllocationCallbacks *pAllocator,
  1770. VkSurfaceKHR *pSurface) {
  1771. const VkLayerInstanceDispatchTable *disp;
  1772. disp = loader_get_instance_layer_dispatch(instance);
  1773. VkResult res;
  1774. res = disp->CreateImagePipeSurfaceFUCHSIA(instance, pCreateInfo, pAllocator, pSurface);
  1775. return res;
  1776. }
  1777. // This is the instance chain terminator function for CreateImagePipeSurfaceFUCHSIA
  1778. VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateImagePipeSurfaceFUCHSIA(VkInstance instance,
  1779. const VkImagePipeSurfaceCreateInfoFUCHSIA *pCreateInfo,
  1780. const VkAllocationCallbacks *pAllocator,
  1781. VkSurfaceKHR *pSurface) {
  1782. VkResult vkRes = VK_SUCCESS;
  1783. VkIcdSurface *pIcdSurface = NULL;
  1784. uint32_t i = 0;
  1785. // Initialize pSurface to NULL just to be safe.
  1786. *pSurface = VK_NULL_HANDLE;
  1787. // First, check to ensure the appropriate extension was enabled:
  1788. struct loader_instance *ptr_instance = loader_get_instance(instance);
  1789. if (!ptr_instance->wsi_imagepipe_surface_enabled) {
  1790. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1791. "VK_FUCHSIA_imagepipe_surface extension not enabled. "
  1792. "vkCreateImagePipeSurfaceFUCHSIA not executed!\n");
  1793. vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
  1794. goto out;
  1795. }
  1796. // Next, if so, proceed with the implementation of this function:
  1797. pIcdSurface =
  1798. AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->imagepipe_surf.base), sizeof(pIcdSurface->imagepipe_surf));
  1799. if (pIcdSurface == NULL) {
  1800. vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
  1801. goto out;
  1802. }
  1803. pIcdSurface->imagepipe_surf.base.platform = VK_ICD_WSI_PLATFORM_FUCHSIA;
  1804. // Loop through each ICD and determine if they need to create a surface
  1805. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1806. if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
  1807. if (NULL != icd_term->dispatch.CreateImagePipeSurfaceFUCHSIA) {
  1808. vkRes = icd_term->dispatch.CreateImagePipeSurfaceFUCHSIA(icd_term->instance, pCreateInfo, pAllocator,
  1809. &pIcdSurface->real_icd_surfaces[i]);
  1810. if (VK_SUCCESS != vkRes) {
  1811. goto out;
  1812. }
  1813. }
  1814. }
  1815. }
  1816. *pSurface = (VkSurfaceKHR)(pIcdSurface);
  1817. out:
  1818. if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
  1819. if (NULL != pIcdSurface->real_icd_surfaces) {
  1820. i = 0;
  1821. for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
  1822. if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
  1823. icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
  1824. }
  1825. }
  1826. loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
  1827. }
  1828. loader_instance_heap_free(ptr_instance, pIcdSurface);
  1829. }
  1830. return vkRes;
  1831. }
  1832. #endif // VK_USE_PLATFORM_FUCHSIA
  1833. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
  1834. vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  1835. VkSurfaceCapabilities2KHR *pSurfaceCapabilities) {
  1836. const VkLayerInstanceDispatchTable *disp;
  1837. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1838. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1839. return disp->GetPhysicalDeviceSurfaceCapabilities2KHR(unwrapped_phys_dev, pSurfaceInfo, pSurfaceCapabilities);
  1840. }
  1841. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilities2KHR(
  1842. VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  1843. VkSurfaceCapabilities2KHR *pSurfaceCapabilities) {
  1844. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1845. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1846. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1847. if (!ptr_instance->wsi_surface_enabled) {
  1848. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1849. "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceCapabilities2KHR not executed!\n");
  1850. return VK_SUCCESS;
  1851. }
  1852. VkIcdSurface *icd_surface = (VkIcdSurface *)(pSurfaceInfo->surface);
  1853. uint8_t icd_index = phys_dev_term->icd_index;
  1854. if (icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR != NULL) {
  1855. VkBaseOutStructure *pNext = (VkBaseOutStructure *)pSurfaceCapabilities->pNext;
  1856. while (pNext != NULL) {
  1857. if ((int)pNext->sType == VK_STRUCTURE_TYPE_SURFACE_PROTECTED_CAPABILITIES_KHR) {
  1858. // Not all ICDs may be supporting VK_KHR_surface_protected_capabilities
  1859. // Initialize VkSurfaceProtectedCapabilitiesKHR.supportsProtected to false and
  1860. // if an ICD supports protected surfaces, it will reset it to true accordingly.
  1861. ((VkSurfaceProtectedCapabilitiesKHR *)pNext)->supportsProtected = VK_FALSE;
  1862. }
  1863. pNext = (VkBaseOutStructure *)pNext->pNext;
  1864. }
  1865. // Pass the call to the driver, possibly unwrapping the ICD surface
  1866. if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
  1867. VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;
  1868. info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
  1869. return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev_term->phys_dev, &info_copy,
  1870. pSurfaceCapabilities);
  1871. } else {
  1872. return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev_term->phys_dev, pSurfaceInfo,
  1873. pSurfaceCapabilities);
  1874. }
  1875. } else {
  1876. // Emulate the call
  1877. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
  1878. "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulating call in ICD \"%s\" using "
  1879. "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
  1880. icd_term->scanned_icd->lib_name);
  1881. if (pSurfaceInfo->pNext != NULL) {
  1882. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
  1883. "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulation found unrecognized structure type in "
  1884. "pSurfaceInfo->pNext - this struct will be ignored");
  1885. }
  1886. // Write to the VkSurfaceCapabilities2KHR struct
  1887. VkSurfaceKHR surface = pSurfaceInfo->surface;
  1888. if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
  1889. surface = icd_surface->real_icd_surfaces[icd_index];
  1890. }
  1891. VkResult res = icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, surface,
  1892. &pSurfaceCapabilities->surfaceCapabilities);
  1893. if (pSurfaceCapabilities->pNext != NULL) {
  1894. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
  1895. "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulation found unrecognized structure type in "
  1896. "pSurfaceCapabilities->pNext - this struct will be ignored");
  1897. }
  1898. return res;
  1899. }
  1900. }
  1901. LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
  1902. vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  1903. uint32_t *pSurfaceFormatCount, VkSurfaceFormat2KHR *pSurfaceFormats) {
  1904. const VkLayerInstanceDispatchTable *disp;
  1905. VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
  1906. disp = loader_get_instance_layer_dispatch(physicalDevice);
  1907. return disp->GetPhysicalDeviceSurfaceFormats2KHR(unwrapped_phys_dev, pSurfaceInfo, pSurfaceFormatCount, pSurfaceFormats);
  1908. }
  1909. VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
  1910. const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
  1911. uint32_t *pSurfaceFormatCount,
  1912. VkSurfaceFormat2KHR *pSurfaceFormats) {
  1913. struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
  1914. struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
  1915. struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
  1916. if (!ptr_instance->wsi_surface_enabled) {
  1917. loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
  1918. "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceFormats2KHR not executed!\n");
  1919. return VK_SUCCESS;
  1920. }
  1921. VkIcdSurface *icd_surface = (VkIcdSurface *)(pSurfaceInfo->surface);
  1922. uint8_t icd_index = phys_dev_term->icd_index;
  1923. if (icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR != NULL) {
  1924. // Pass the call to the driver, possibly unwrapping the ICD surface
  1925. if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
  1926. VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;
  1927. info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
  1928. return icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR(phys_dev_term->phys_dev, &info_copy, pSurfaceFormatCount,
  1929. pSurfaceFormats);
  1930. } else {
  1931. return icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR(phys_dev_term->phys_dev, pSurfaceInfo,
  1932. pSurfaceFormatCount, pSurfaceFormats);
  1933. }
  1934. } else {
  1935. // Emulate the call
  1936. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
  1937. "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceSurfaceFormatsKHR",
  1938. icd_term->scanned_icd->lib_name);
  1939. if (pSurfaceInfo->pNext != NULL) {
  1940. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
  1941. "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulation found unrecognized structure type in pSurfaceInfo->pNext "
  1942. "- this struct will be ignored");
  1943. }
  1944. VkSurfaceKHR surface = pSurfaceInfo->surface;
  1945. if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
  1946. surface = icd_surface->real_icd_surfaces[icd_index];
  1947. }
  1948. if (*pSurfaceFormatCount == 0 || pSurfaceFormats == NULL) {
  1949. // Write to pSurfaceFormatCount
  1950. return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface, pSurfaceFormatCount,
  1951. NULL);
  1952. } else {
  1953. // Allocate a temporary array for the output of the old function
  1954. VkSurfaceFormatKHR *formats = loader_stack_alloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR));
  1955. if (formats == NULL) {
  1956. return VK_ERROR_OUT_OF_HOST_MEMORY;
  1957. }
  1958. VkResult res = icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface,
  1959. pSurfaceFormatCount, formats);
  1960. for (uint32_t i = 0; i < *pSurfaceFormatCount; ++i) {
  1961. pSurfaceFormats[i].surfaceFormat = formats[i];
  1962. if (pSurfaceFormats[i].pNext != NULL) {
  1963. loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
  1964. "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulation found unrecognized structure type in "
  1965. "pSurfaceFormats[%d].pNext - this struct will be ignored",
  1966. i);
  1967. }
  1968. }
  1969. return res;
  1970. }
  1971. }
  1972. }
  1973. bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, const char *name, void **addr) {
  1974. *addr = NULL;
  1975. // Functions for the VK_KHR_surface extension:
  1976. if (!strcmp("vkDestroySurfaceKHR", name)) {
  1977. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR : NULL;
  1978. return true;
  1979. }
  1980. if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
  1981. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR : NULL;
  1982. return true;
  1983. }
  1984. if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
  1985. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR : NULL;
  1986. return true;
  1987. }
  1988. if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
  1989. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR : NULL;
  1990. return true;
  1991. }
  1992. if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
  1993. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR : NULL;
  1994. return true;
  1995. }
  1996. if (!strcmp("vkGetDeviceGroupPresentCapabilitiesKHR", name)) {
  1997. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetDeviceGroupPresentCapabilitiesKHR : NULL;
  1998. return true;
  1999. }
  2000. if (!strcmp("vkGetDeviceGroupSurfacePresentModesKHR", name)) {
  2001. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetDeviceGroupSurfacePresentModesKHR : NULL;
  2002. return true;
  2003. }
  2004. if (!strcmp("vkGetPhysicalDevicePresentRectanglesKHR", name)) {
  2005. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDevicePresentRectanglesKHR : NULL;
  2006. return true;
  2007. }
  2008. // Functions for VK_KHR_get_surface_capabilities2 extension:
  2009. if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilities2KHR", name)) {
  2010. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceCapabilities2KHR : NULL;
  2011. return true;
  2012. }
  2013. if (!strcmp("vkGetPhysicalDeviceSurfaceFormats2KHR", name)) {
  2014. *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceFormats2KHR : NULL;
  2015. return true;
  2016. }
  2017. // Functions for the VK_KHR_swapchain extension:
  2018. // Note: This is a device extension, and its functions are statically
  2019. // exported from the loader. Per Khronos decisions, the loader's GIPA
  2020. // function will return the trampoline function for such device-extension
  2021. // functions, regardless of whether the extension has been enabled.
  2022. if (!strcmp("vkCreateSwapchainKHR", name)) {
  2023. *addr = (void *)vkCreateSwapchainKHR;
  2024. return true;
  2025. }
  2026. if (!strcmp("vkDestroySwapchainKHR", name)) {
  2027. *addr = (void *)vkDestroySwapchainKHR;
  2028. return true;
  2029. }
  2030. if (!strcmp("vkGetSwapchainImagesKHR", name)) {
  2031. *addr = (void *)vkGetSwapchainImagesKHR;
  2032. return true;
  2033. }
  2034. if (!strcmp("vkAcquireNextImageKHR", name)) {
  2035. *addr = (void *)vkAcquireNextImageKHR;
  2036. return true;
  2037. }
  2038. if (!strcmp("vkQueuePresentKHR", name)) {
  2039. *addr = (void *)vkQueuePresentKHR;
  2040. return true;
  2041. }
  2042. if (!strcmp("vkAcquireNextImage2KHR", name)) {
  2043. *addr = (void *)vkAcquireNextImage2KHR;
  2044. return true;
  2045. }
  2046. #ifdef VK_USE_PLATFORM_WIN32_KHR
  2047. // Functions for the VK_KHR_win32_surface extension:
  2048. if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
  2049. *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkCreateWin32SurfaceKHR : NULL;
  2050. return true;
  2051. }
  2052. if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
  2053. *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR : NULL;
  2054. return true;
  2055. }
  2056. #endif // VK_USE_PLATFORM_WIN32_KHR
  2057. #ifdef VK_USE_PLATFORM_WAYLAND_KHR
  2058. // Functions for the VK_KHR_wayland_surface extension:
  2059. if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
  2060. *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkCreateWaylandSurfaceKHR : NULL;
  2061. return true;
  2062. }
  2063. if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
  2064. *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR : NULL;
  2065. return true;
  2066. }
  2067. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  2068. #ifdef VK_USE_PLATFORM_XCB_KHR
  2069. // Functions for the VK_KHR_xcb_surface extension:
  2070. if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
  2071. *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkCreateXcbSurfaceKHR : NULL;
  2072. return true;
  2073. }
  2074. if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
  2075. *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR : NULL;
  2076. return true;
  2077. }
  2078. #endif // VK_USE_PLATFORM_XCB_KHR
  2079. #ifdef VK_USE_PLATFORM_XLIB_KHR
  2080. // Functions for the VK_KHR_xlib_surface extension:
  2081. if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
  2082. *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkCreateXlibSurfaceKHR : NULL;
  2083. return true;
  2084. }
  2085. if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
  2086. *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR : NULL;
  2087. return true;
  2088. }
  2089. #endif // VK_USE_PLATFORM_XLIB_KHR
  2090. #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
  2091. // Functions for the VK_EXT_directfb_surface extension:
  2092. if (!strcmp("vkCreateDirectFBSurfaceEXT", name)) {
  2093. *addr = ptr_instance->wsi_directfb_surface_enabled ? (void *)vkCreateDirectFBSurfaceEXT : NULL;
  2094. return true;
  2095. }
  2096. if (!strcmp("vkGetPhysicalDeviceDirectFBPresentationSupportEXT", name)) {
  2097. *addr = ptr_instance->wsi_directfb_surface_enabled ? (void *)vkGetPhysicalDeviceDirectFBPresentationSupportEXT : NULL;
  2098. return true;
  2099. }
  2100. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  2101. #ifdef VK_USE_PLATFORM_ANDROID_KHR
  2102. // Functions for the VK_KHR_android_surface extension:
  2103. if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
  2104. *addr = ptr_instance->wsi_android_surface_enabled ? (void *)vkCreateAndroidSurfaceKHR : NULL;
  2105. return true;
  2106. }
  2107. #endif // VK_USE_PLATFORM_ANDROID_KHR
  2108. #ifdef VK_USE_PLATFORM_MACOS_MVK
  2109. // Functions for the VK_MVK_macos_surface extension:
  2110. if (!strcmp("vkCreateMacOSSurfaceMVK", name)) {
  2111. *addr = ptr_instance->wsi_macos_surface_enabled ? (void *)vkCreateMacOSSurfaceMVK : NULL;
  2112. return true;
  2113. }
  2114. #endif // VK_USE_PLATFORM_MACOS_MVK
  2115. #ifdef VK_USE_PLATFORM_IOS_MVK
  2116. // Functions for the VK_MVK_ios_surface extension:
  2117. if (!strcmp("vkCreateIOSSurfaceMVK", name)) {
  2118. *addr = ptr_instance->wsi_ios_surface_enabled ? (void *)vkCreateIOSSurfaceMVK : NULL;
  2119. return true;
  2120. }
  2121. #endif // VK_USE_PLATFORM_IOS_MVK
  2122. #ifdef VK_USE_PLATFORM_GGP
  2123. // Functions for the VK_GGP_stream_descriptor_surface extension:
  2124. if (!strcmp("vkCreateStreamDescriptorSurfaceGGP", name)) {
  2125. *addr = ptr_instance->wsi_ggp_surface_enabled ? (void *)vkCreateStreamDescriptorSurfaceGGP : NULL;
  2126. return true;
  2127. }
  2128. #endif // VK_USE_PLATFORM_GGP
  2129. #ifdef VK_USE_PLATFORM_FUCHSIA
  2130. // Functions for the VK_FUCHSIA_imagepipe_surface extension:
  2131. if (!strcmp("vkCreateImagePipeSurfaceFUCHSIA", name)) {
  2132. *addr = ptr_instance->wsi_imagepipe_surface_enabled ? (void *)vkCreateImagePipeSurfaceFUCHSIA : NULL;
  2133. return true;
  2134. }
  2135. #endif // VK_USE_PLATFORM_FUCHSIA
  2136. // Functions for the VK_EXT_headless_surface extension:
  2137. if (!strcmp("vkCreateHeadlessSurfaceEXT", name)) {
  2138. *addr = ptr_instance->wsi_headless_surface_enabled ? (void *)vkCreateHeadlessSurfaceEXT : NULL;
  2139. return true;
  2140. }
  2141. #if defined(VK_USE_PLATFORM_METAL_EXT)
  2142. // Functions for the VK_MVK_macos_surface extension:
  2143. if (!strcmp("vkCreateMetalSurfaceEXT", name)) {
  2144. *addr = ptr_instance->wsi_metal_surface_enabled ? (void *)vkCreateMetalSurfaceEXT : NULL;
  2145. return true;
  2146. }
  2147. #endif // VK_USE_PLATFORM_METAL_EXT
  2148. // Functions for VK_KHR_display extension:
  2149. if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
  2150. *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR : NULL;
  2151. return true;
  2152. }
  2153. if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
  2154. *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR : NULL;
  2155. return true;
  2156. }
  2157. if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
  2158. *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR : NULL;
  2159. return true;
  2160. }
  2161. if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
  2162. *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayModePropertiesKHR : NULL;
  2163. return true;
  2164. }
  2165. if (!strcmp("vkCreateDisplayModeKHR", name)) {
  2166. *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayModeKHR : NULL;
  2167. return true;
  2168. }
  2169. if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
  2170. *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneCapabilitiesKHR : NULL;
  2171. return true;
  2172. }
  2173. if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
  2174. *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayPlaneSurfaceKHR : NULL;
  2175. return true;
  2176. }
  2177. // Functions for KHR_display_swapchain extension:
  2178. if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
  2179. *addr = (void *)vkCreateSharedSwapchainsKHR;
  2180. return true;
  2181. }
  2182. // Functions for KHR_get_display_properties2
  2183. if (!strcmp("vkGetPhysicalDeviceDisplayProperties2KHR", name)) {
  2184. *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetPhysicalDeviceDisplayProperties2KHR : NULL;
  2185. return true;
  2186. }
  2187. if (!strcmp("vkGetPhysicalDeviceDisplayPlaneProperties2KHR", name)) {
  2188. *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetPhysicalDeviceDisplayPlaneProperties2KHR : NULL;
  2189. return true;
  2190. }
  2191. if (!strcmp("vkGetDisplayModeProperties2KHR", name)) {
  2192. *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetDisplayModeProperties2KHR : NULL;
  2193. return true;
  2194. }
  2195. if (!strcmp("vkGetDisplayPlaneCapabilities2KHR", name)) {
  2196. *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetDisplayPlaneCapabilities2KHR : NULL;
  2197. return true;
  2198. }
  2199. return false;
  2200. }