Corentin Wallez | f2adf6d | 2017-11-17 17:52:04 -0500 | [diff] [blame] | 1 | // Copyright 2017 The NXT Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "backend/vulkan/VulkanFunctions.h" |
| 16 | |
Corentin Wallez | 6d9a3b8 | 2017-11-20 10:51:23 -0500 | [diff] [blame^] | 17 | #include "backend/vulkan/VulkanInfo.h" |
Corentin Wallez | f2adf6d | 2017-11-17 17:52:04 -0500 | [diff] [blame] | 18 | #include "common/DynamicLib.h" |
| 19 | |
| 20 | namespace backend { |
| 21 | namespace vulkan { |
| 22 | |
| 23 | #define GET_GLOBAL_PROC(name) \ |
| 24 | name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \ |
| 25 | if (name == nullptr) { \ |
| 26 | return false; \ |
| 27 | } |
| 28 | |
| 29 | bool VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) { |
| 30 | if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | GET_GLOBAL_PROC(CreateInstance); |
| 35 | GET_GLOBAL_PROC(DestroyInstance); |
| 36 | GET_GLOBAL_PROC(EnumerateInstanceExtensionProperties); |
| 37 | GET_GLOBAL_PROC(EnumerateInstanceLayerProperties); |
| 38 | |
| 39 | return true; |
| 40 | } |
| 41 | |
Corentin Wallez | 6d9a3b8 | 2017-11-20 10:51:23 -0500 | [diff] [blame^] | 42 | #define GET_INSTANCE_PROC(name) \ |
| 43 | name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #name)); \ |
| 44 | if (name == nullptr) { \ |
| 45 | return false; \ |
| 46 | } |
| 47 | |
| 48 | bool VulkanFunctions::LoadInstanceProcs(VkInstance instance, const KnownGlobalVulkanExtensions& usedGlobals) { |
| 49 | GET_INSTANCE_PROC(CreateDevice); |
| 50 | GET_INSTANCE_PROC(DestroyDevice); |
| 51 | GET_INSTANCE_PROC(EnumerateDeviceExtensionProperties); |
| 52 | GET_INSTANCE_PROC(EnumerateDeviceLayerProperties); |
| 53 | GET_INSTANCE_PROC(EnumeratePhysicalDevices); |
| 54 | GET_INSTANCE_PROC(GetPhysicalDeviceFeatures); |
| 55 | GET_INSTANCE_PROC(GetPhysicalDeviceFormatProperties); |
| 56 | GET_INSTANCE_PROC(GetPhysicalDeviceImageFormatProperties); |
| 57 | GET_INSTANCE_PROC(GetPhysicalDeviceMemoryProperties); |
| 58 | GET_INSTANCE_PROC(GetPhysicalDeviceProperties); |
| 59 | GET_INSTANCE_PROC(GetPhysicalDeviceQueueFamilyProperties); |
| 60 | GET_INSTANCE_PROC(GetPhysicalDeviceSparseImageFormatProperties); |
| 61 | |
| 62 | if (usedGlobals.debugReport) { |
| 63 | GET_INSTANCE_PROC(CreateDebugReportCallbackEXT); |
| 64 | GET_INSTANCE_PROC(DebugReportMessageEXT); |
| 65 | GET_INSTANCE_PROC(DestroyDebugReportCallbackEXT); |
| 66 | } |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | |
Corentin Wallez | f2adf6d | 2017-11-17 17:52:04 -0500 | [diff] [blame] | 71 | } |
| 72 | } |