2 * Copyright © 2019 Raspberry Pi
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include <sys/sysinfo.h>
31 #include "libresoc_private.h"
35 libresoc_EnumerateInstanceExtensionProperties(const char *pLayerName
,
36 uint32_t *pPropertyCount
,
37 VkExtensionProperties
*pProperties
)
39 if (getenv("LIBRESOC_TRACE")) {
40 fprintf(stderr
, "EnumerateInstanceExtensionProperties called for: %s \n", pLayerName
);
42 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
44 for (int i
= 0; i
< LIBRESOC_INSTANCE_EXTENSION_COUNT
; i
++) {
45 if (libresoc_instance_extensions_supported
.extensions
[i
]) {
46 vk_outarray_append(&out
, prop
) {
47 *prop
= libresoc_instance_extensions
[i
];
52 return vk_outarray_status(&out
);
56 libresoc_CreateInstance(const VkInstanceCreateInfo
*pCreateInfo
,
57 const VkAllocationCallbacks
*pAllocator
,
58 VkInstance
*pInstance
)
60 if (getenv("LIBRESOC_TRACE")) {
61 fprintf(stderr
, "CreateInstance called. \n");
68 libresoc_DestroyInstance(VkInstance _instance
,
69 const VkAllocationCallbacks
*pAllocator
)
71 if (getenv("LIBRESOC_TRACE")) {
72 fprintf(stderr
, "DestroyInstance called. \n");
78 libresoc_EnumeratePhysicalDevices(VkInstance _instance
,
79 uint32_t *pPhysicalDeviceCount
,
80 VkPhysicalDevice
*pPhysicalDevices
)
82 if (getenv("LIBRESOC_TRACE")) {
83 fprintf(stderr
, "EnumeratePhysicalDevices called\n");
90 libresoc_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice
,
91 VkPhysicalDeviceFeatures
*pFeatures
)
93 if (getenv("LIBRESOC_TRACE")) {
94 fprintf(stderr
, "GetPhysicalDeviceFeatures called. \n");
100 libresoc_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice
,
101 VkPhysicalDeviceProperties
*pProperties
)
103 if (getenv("LIBRESOC_TRACE")) {
104 fprintf(stderr
, "GetPhysicalDeviceProperties called. \n");
110 libresoc_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice
,
112 VkQueueFamilyProperties
*pQueueFamilyProperties
)
114 if (getenv("LIBRESOC_TRACE")) {
115 fprintf(stderr
, "GetPhysicalDeviceQueueFamilyProperites called. \n");
121 libresoc_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice
,
122 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
124 if (getenv("LIBRESOC_TRACE")) {
125 fprintf(stderr
, "GetPhysicalDEviceMemoryProperties called. \n");
131 libresoc_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice
, VkFormat format
, VkFormatProperties
*pFormatProperties
) {
133 if (getenv("LIBRESOC_TRACE")) {
134 fprintf(stderr
, "GetPhysicalDeviceFormatProperties called. \n");
140 libresoc_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice
, VkFormat format
, VkImageType type
, VkImageTiling tiling
, VkImageUsageFlags usage
, VkImageCreateFlags flags
, VkImageFormatProperties
* pImageFormatProperties
)
142 if (getenv("LIBRESOC_TRACE")) {
143 fprintf(stderr
, "GetPhysicalDEviceImageFormatProperties called. \n");
150 libresoc_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice
, VkFormat format
, VkImageType type
, VkSampleCountFlagBits samples
, VkImageUsageFlags usage
, VkImageTiling tiling
, uint32_t* pPropertyCount
, VkSparseImageFormatProperties
* pProperties
)
152 if (getenv("LIBRESOC_TRACE")) {
153 fprintf(stderr
, "GetPhysicalDeviceSparseImageFormatProperties called. \n");
158 libresoc_GetInstanceProcAddr(VkInstance _instance
,
161 if (getenv("LIBRESOC_TRACE")) {
162 fprintf(stderr
, "GetInstanceProcAddr called for: %s \n", pName
);
164 LIBRESOC_FROM_HANDLE(libresoc_instance
, instance
, _instance
);
166 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
167 * when we have to return valid function pointers, NULL, or it's left
168 * undefined. See the table for exact details.
173 #define LOOKUP_LIBRESOC_ENTRYPOINT(entrypoint) \
174 if (strcmp(pName, "vk" #entrypoint) == 0) \
175 return (PFN_vkVoidFunction)libresoc_##entrypoint
177 LOOKUP_LIBRESOC_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
178 LOOKUP_LIBRESOC_ENTRYPOINT(CreateInstance
);
179 LOOKUP_LIBRESOC_ENTRYPOINT(DestroyInstance
);
180 LOOKUP_LIBRESOC_ENTRYPOINT(EnumeratePhysicalDevices
);
181 LOOKUP_LIBRESOC_ENTRYPOINT(GetPhysicalDeviceFeatures
);
182 LOOKUP_LIBRESOC_ENTRYPOINT(GetPhysicalDeviceFormatProperties
);
183 LOOKUP_LIBRESOC_ENTRYPOINT(GetPhysicalDeviceImageFormatProperties
);
184 LOOKUP_LIBRESOC_ENTRYPOINT(GetPhysicalDeviceProperties
);
185 LOOKUP_LIBRESOC_ENTRYPOINT(GetPhysicalDeviceQueueFamilyProperties
);
186 LOOKUP_LIBRESOC_ENTRYPOINT(GetPhysicalDeviceMemoryProperties
);
187 LOOKUP_LIBRESOC_ENTRYPOINT(GetDeviceProcAddr
);
188 LOOKUP_LIBRESOC_ENTRYPOINT(CreateDevice
);
189 LOOKUP_LIBRESOC_ENTRYPOINT(EnumerateDeviceExtensionProperties
);
190 LOOKUP_LIBRESOC_ENTRYPOINT(GetPhysicalDeviceSparseImageFormatProperties
);
193 #undef LOOKUP_LIBRESOC_ENTRYPOINT
195 if (instance
== NULL
)
198 int idx
= libresoc_get_instance_entrypoint_index(pName
);
200 return instance
->dispatch
.entrypoints
[idx
];
202 idx
= libresoc_get_physical_device_entrypoint_index(pName
);
204 return instance
->physicalDevice
.dispatch
.entrypoints
[idx
];
206 idx
= libresoc_get_device_entrypoint_index(pName
);
208 return instance
->device_dispatch
.entrypoints
[idx
];
213 /* With version 1+ of the loader interface the ICD should expose
214 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
217 VKAPI_ATTR PFN_vkVoidFunction
218 VKAPI_CALL
vk_icdGetInstanceProcAddr(VkInstance instance
,
222 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
223 vk_icdGetInstanceProcAddr(VkInstance instance
,
226 if (getenv("LIBRESOC_TRACE")) {
227 fprintf(stderr
, "vk_icdGetInstanceProcAddr called for: %s \n", pName
);
229 return libresoc_GetInstanceProcAddr(instance
, pName
);
233 libresoc_GetDeviceProcAddr(VkDevice _device
,
236 if (getenv("LIBRESOC_TRACE")) {
237 fprintf(stderr
, "GetDeviceProcAddr called for: %s \n", pName
);
239 LIBRESOC_FROM_HANDLE(libresoc_device
, device
, _device
);
241 if (!device
|| !pName
)
244 int idx
= libresoc_get_device_entrypoint_index(pName
);
248 return device
->dispatch
.entrypoints
[idx
];
251 /* With version 4+ of the loader interface the ICD should expose
252 * vk_icdGetPhysicalDeviceProcAddr()
255 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
256 vk_icdGetPhysicalDeviceProcAddr(VkInstance _instance
,
260 vk_icdGetPhysicalDeviceProcAddr(VkInstance _instance
,
263 if (getenv("LIBRESOC_TRACE")) {
264 fprintf(stderr
, "vk_icdGetPhysicalDeviceProcAddr called for: %s \n", pName
);
266 LIBRESOC_FROM_HANDLE(libresoc_instance
, instance
, _instance
);
268 if (!pName
|| !instance
)
271 int idx
= libresoc_get_physical_device_entrypoint_index(pName
);
275 return instance
->physicalDevice
.dispatch
.entrypoints
[idx
];
279 libresoc_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice
,
280 const char *pLayerName
,
281 uint32_t *pPropertyCount
,
282 VkExtensionProperties
*pProperties
)
284 if (getenv("LIBRESOC_TRACE")) {
285 fprintf(stderr
, "EnumerateDeviceExtensionProperties called for layer: %s \n", pLayerName
);
292 libresoc_CreateDevice(VkPhysicalDevice physicalDevice
,
293 const VkDeviceCreateInfo
*pCreateInfo
,
294 const VkAllocationCallbacks
*pAllocator
,
297 if (getenv("LIBRESOC_TRACE")) {
298 fprintf(stderr
, "CreateDevice called \n");
305 libresoc_DestroyDevice(VkDevice _device
,
306 const VkAllocationCallbacks
*pAllocator
)
308 if (getenv("LIBRESOC_TRACE")) {
309 fprintf(stderr
, "DestroyDevice called. \n");
315 libresoc_GetDeviceQueue(VkDevice _device
,
316 uint32_t queueNodeIndex
,
320 if (getenv("LIBRESOC_TRACE")) {
321 fprintf(stderr
, "GetDeviceQueue called. \n");