1 // Copyright 2017 The Dawn 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 "dawn_native/vulkan/VulkanFunctions.h" 16 17 #include "common/DynamicLib.h" 18 #include "dawn_native/vulkan/VulkanInfo.h" 19 20 namespace dawn_native { namespace vulkan { 21 22 #define GET_GLOBAL_PROC(name) \ 23 name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \ 24 if (name == nullptr) { \ 25 return DAWN_CONTEXT_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \ 26 } 27 LoadGlobalProcs(const DynamicLib & vulkanLib)28 MaybeError VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) { 29 if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) { 30 return DAWN_CONTEXT_LOST_ERROR("Couldn't get vkGetInstanceProcAddr"); 31 } 32 33 GET_GLOBAL_PROC(CreateInstance); 34 GET_GLOBAL_PROC(EnumerateInstanceExtensionProperties); 35 GET_GLOBAL_PROC(EnumerateInstanceLayerProperties); 36 37 return {}; 38 } 39 40 #define GET_INSTANCE_PROC(name) \ 41 name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #name)); \ 42 if (name == nullptr) { \ 43 return DAWN_CONTEXT_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \ 44 } 45 LoadInstanceProcs(VkInstance instance,const VulkanGlobalKnobs & usedKnobs)46 MaybeError VulkanFunctions::LoadInstanceProcs(VkInstance instance, 47 const VulkanGlobalKnobs& usedKnobs) { 48 // Load this proc first so that we can destroy the instance even if some other 49 // GET_INSTANCE_PROC fails 50 GET_INSTANCE_PROC(DestroyInstance); 51 52 GET_INSTANCE_PROC(CreateDevice); 53 GET_INSTANCE_PROC(DestroyDevice); 54 GET_INSTANCE_PROC(EnumerateDeviceExtensionProperties); 55 GET_INSTANCE_PROC(EnumerateDeviceLayerProperties); 56 GET_INSTANCE_PROC(EnumeratePhysicalDevices); 57 GET_INSTANCE_PROC(GetDeviceProcAddr); 58 GET_INSTANCE_PROC(GetPhysicalDeviceFeatures); 59 GET_INSTANCE_PROC(GetPhysicalDeviceFormatProperties); 60 GET_INSTANCE_PROC(GetPhysicalDeviceImageFormatProperties); 61 GET_INSTANCE_PROC(GetPhysicalDeviceMemoryProperties); 62 GET_INSTANCE_PROC(GetPhysicalDeviceProperties); 63 GET_INSTANCE_PROC(GetPhysicalDeviceQueueFamilyProperties); 64 GET_INSTANCE_PROC(GetPhysicalDeviceSparseImageFormatProperties); 65 66 if (usedKnobs.debugReport) { 67 GET_INSTANCE_PROC(CreateDebugReportCallbackEXT); 68 GET_INSTANCE_PROC(DebugReportMessageEXT); 69 GET_INSTANCE_PROC(DestroyDebugReportCallbackEXT); 70 } 71 72 if (usedKnobs.surface) { 73 GET_INSTANCE_PROC(DestroySurfaceKHR); 74 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceSupportKHR); 75 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); 76 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceFormatsKHR); 77 GET_INSTANCE_PROC(GetPhysicalDeviceSurfacePresentModesKHR); 78 } 79 80 return {}; 81 } 82 83 #define GET_DEVICE_PROC(name) \ 84 name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \ 85 if (name == nullptr) { \ 86 return DAWN_CONTEXT_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \ 87 } 88 LoadDeviceProcs(VkDevice device,const VulkanDeviceKnobs & usedKnobs)89 MaybeError VulkanFunctions::LoadDeviceProcs(VkDevice device, 90 const VulkanDeviceKnobs& usedKnobs) { 91 GET_DEVICE_PROC(AllocateCommandBuffers); 92 GET_DEVICE_PROC(AllocateDescriptorSets); 93 GET_DEVICE_PROC(AllocateMemory); 94 GET_DEVICE_PROC(BeginCommandBuffer); 95 GET_DEVICE_PROC(BindBufferMemory); 96 GET_DEVICE_PROC(BindImageMemory); 97 GET_DEVICE_PROC(CmdBeginQuery); 98 GET_DEVICE_PROC(CmdBeginRenderPass); 99 GET_DEVICE_PROC(CmdBindDescriptorSets); 100 GET_DEVICE_PROC(CmdBindIndexBuffer); 101 GET_DEVICE_PROC(CmdBindPipeline); 102 GET_DEVICE_PROC(CmdBindVertexBuffers); 103 GET_DEVICE_PROC(CmdBlitImage); 104 GET_DEVICE_PROC(CmdClearAttachments); 105 GET_DEVICE_PROC(CmdClearColorImage); 106 GET_DEVICE_PROC(CmdClearDepthStencilImage); 107 GET_DEVICE_PROC(CmdCopyBuffer); 108 GET_DEVICE_PROC(CmdCopyBufferToImage); 109 GET_DEVICE_PROC(CmdCopyImage); 110 GET_DEVICE_PROC(CmdCopyImageToBuffer); 111 GET_DEVICE_PROC(CmdCopyQueryPoolResults); 112 GET_DEVICE_PROC(CmdDispatch); 113 GET_DEVICE_PROC(CmdDispatchIndirect); 114 GET_DEVICE_PROC(CmdDraw); 115 GET_DEVICE_PROC(CmdDrawIndexed); 116 GET_DEVICE_PROC(CmdDrawIndexedIndirect); 117 GET_DEVICE_PROC(CmdDrawIndirect); 118 GET_DEVICE_PROC(CmdEndQuery); 119 GET_DEVICE_PROC(CmdEndRenderPass); 120 GET_DEVICE_PROC(CmdExecuteCommands); 121 GET_DEVICE_PROC(CmdFillBuffer); 122 GET_DEVICE_PROC(CmdNextSubpass); 123 GET_DEVICE_PROC(CmdPipelineBarrier); 124 GET_DEVICE_PROC(CmdPushConstants); 125 GET_DEVICE_PROC(CmdResetEvent); 126 GET_DEVICE_PROC(CmdResetQueryPool); 127 GET_DEVICE_PROC(CmdResolveImage); 128 GET_DEVICE_PROC(CmdSetBlendConstants); 129 GET_DEVICE_PROC(CmdSetDepthBias); 130 GET_DEVICE_PROC(CmdSetDepthBounds); 131 GET_DEVICE_PROC(CmdSetEvent); 132 GET_DEVICE_PROC(CmdSetLineWidth); 133 GET_DEVICE_PROC(CmdSetScissor); 134 GET_DEVICE_PROC(CmdSetStencilCompareMask); 135 GET_DEVICE_PROC(CmdSetStencilReference); 136 GET_DEVICE_PROC(CmdSetStencilWriteMask); 137 GET_DEVICE_PROC(CmdSetViewport); 138 GET_DEVICE_PROC(CmdUpdateBuffer); 139 GET_DEVICE_PROC(CmdWaitEvents); 140 GET_DEVICE_PROC(CmdWriteTimestamp); 141 GET_DEVICE_PROC(CreateBuffer); 142 GET_DEVICE_PROC(CreateBufferView); 143 GET_DEVICE_PROC(CreateCommandPool); 144 GET_DEVICE_PROC(CreateComputePipelines); 145 GET_DEVICE_PROC(CreateDescriptorPool); 146 GET_DEVICE_PROC(CreateDescriptorSetLayout); 147 GET_DEVICE_PROC(CreateEvent); 148 GET_DEVICE_PROC(CreateFence); 149 GET_DEVICE_PROC(CreateFramebuffer); 150 GET_DEVICE_PROC(CreateGraphicsPipelines); 151 GET_DEVICE_PROC(CreateImage); 152 GET_DEVICE_PROC(CreateImageView); 153 GET_DEVICE_PROC(CreatePipelineCache); 154 GET_DEVICE_PROC(CreatePipelineLayout); 155 GET_DEVICE_PROC(CreateQueryPool); 156 GET_DEVICE_PROC(CreateRenderPass); 157 GET_DEVICE_PROC(CreateSampler); 158 GET_DEVICE_PROC(CreateSemaphore); 159 GET_DEVICE_PROC(CreateShaderModule); 160 GET_DEVICE_PROC(DestroyBuffer); 161 GET_DEVICE_PROC(DestroyBufferView); 162 GET_DEVICE_PROC(DestroyCommandPool); 163 GET_DEVICE_PROC(DestroyDescriptorPool); 164 GET_DEVICE_PROC(DestroyDescriptorSetLayout); 165 GET_DEVICE_PROC(DestroyEvent); 166 GET_DEVICE_PROC(DestroyFence); 167 GET_DEVICE_PROC(DestroyFramebuffer); 168 GET_DEVICE_PROC(DestroyImage); 169 GET_DEVICE_PROC(DestroyImageView); 170 GET_DEVICE_PROC(DestroyPipeline); 171 GET_DEVICE_PROC(DestroyPipelineCache); 172 GET_DEVICE_PROC(DestroyPipelineLayout); 173 GET_DEVICE_PROC(DestroyQueryPool); 174 GET_DEVICE_PROC(DestroyRenderPass); 175 GET_DEVICE_PROC(DestroySampler); 176 GET_DEVICE_PROC(DestroySemaphore); 177 GET_DEVICE_PROC(DestroyShaderModule); 178 GET_DEVICE_PROC(DeviceWaitIdle); 179 GET_DEVICE_PROC(EndCommandBuffer); 180 GET_DEVICE_PROC(FlushMappedMemoryRanges); 181 GET_DEVICE_PROC(FreeCommandBuffers); 182 GET_DEVICE_PROC(FreeDescriptorSets); 183 GET_DEVICE_PROC(FreeMemory); 184 GET_DEVICE_PROC(GetBufferMemoryRequirements); 185 GET_DEVICE_PROC(GetDeviceMemoryCommitment); 186 GET_DEVICE_PROC(GetDeviceQueue); 187 GET_DEVICE_PROC(GetEventStatus); 188 GET_DEVICE_PROC(GetFenceStatus); 189 GET_DEVICE_PROC(GetImageMemoryRequirements); 190 GET_DEVICE_PROC(GetImageSparseMemoryRequirements); 191 GET_DEVICE_PROC(GetImageSubresourceLayout); 192 GET_DEVICE_PROC(GetPipelineCacheData); 193 GET_DEVICE_PROC(GetQueryPoolResults); 194 GET_DEVICE_PROC(GetRenderAreaGranularity); 195 GET_DEVICE_PROC(InvalidateMappedMemoryRanges); 196 GET_DEVICE_PROC(MapMemory); 197 GET_DEVICE_PROC(MergePipelineCaches); 198 GET_DEVICE_PROC(QueueBindSparse); 199 GET_DEVICE_PROC(QueueSubmit); 200 GET_DEVICE_PROC(QueueWaitIdle); 201 GET_DEVICE_PROC(ResetCommandBuffer); 202 GET_DEVICE_PROC(ResetCommandPool); 203 GET_DEVICE_PROC(ResetDescriptorPool); 204 GET_DEVICE_PROC(ResetEvent); 205 GET_DEVICE_PROC(ResetFences); 206 GET_DEVICE_PROC(SetEvent); 207 GET_DEVICE_PROC(UnmapMemory); 208 GET_DEVICE_PROC(UpdateDescriptorSets); 209 GET_DEVICE_PROC(WaitForFences); 210 211 if (usedKnobs.debugMarker) { 212 GET_DEVICE_PROC(CmdDebugMarkerBeginEXT); 213 GET_DEVICE_PROC(CmdDebugMarkerEndEXT); 214 GET_DEVICE_PROC(CmdDebugMarkerInsertEXT); 215 } 216 217 if (usedKnobs.swapchain) { 218 GET_DEVICE_PROC(CreateSwapchainKHR); 219 GET_DEVICE_PROC(DestroySwapchainKHR); 220 GET_DEVICE_PROC(GetSwapchainImagesKHR); 221 GET_DEVICE_PROC(AcquireNextImageKHR); 222 GET_DEVICE_PROC(QueuePresentKHR); 223 } 224 225 return {}; 226 } 227 228 }} // namespace dawn_native::vulkan 229