1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "vk/GrVkInterface.h" 9 10 GrVkInterface::GrVkInterface() { 11 } 12 13 #define GET_PROC(F) functions->f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk" #F) 14 15 const GrVkInterface* GrVkCreateInterface(VkInstance instance) { 16 17 GrVkInterface* interface = new GrVkInterface(); 18 GrVkInterface::Functions* functions = &interface->fFunctions; 19 20 GET_PROC(CreateInstance); 21 GET_PROC(DestroyInstance); 22 GET_PROC(EnumeratePhysicalDevices); 23 GET_PROC(GetPhysicalDeviceFeatures); 24 GET_PROC(GetPhysicalDeviceFormatProperties); 25 GET_PROC(GetPhysicalDeviceImageFormatProperties); 26 GET_PROC(GetPhysicalDeviceProperties); 27 GET_PROC(GetPhysicalDeviceQueueFamilyProperties); 28 GET_PROC(GetPhysicalDeviceMemoryProperties); 29 GET_PROC(CreateDevice); 30 GET_PROC(DestroyDevice); 31 GET_PROC(EnumerateInstanceExtensionProperties); 32 GET_PROC(EnumerateDeviceExtensionProperties); 33 GET_PROC(EnumerateInstanceLayerProperties); 34 GET_PROC(EnumerateDeviceLayerProperties); 35 GET_PROC(GetDeviceQueue); 36 GET_PROC(QueueSubmit); 37 GET_PROC(QueueWaitIdle); 38 GET_PROC(DeviceWaitIdle); 39 GET_PROC(AllocateMemory); 40 GET_PROC(FreeMemory); 41 GET_PROC(MapMemory); 42 GET_PROC(UnmapMemory); 43 GET_PROC(FlushMappedMemoryRanges); 44 GET_PROC(InvalidateMappedMemoryRanges); 45 GET_PROC(GetDeviceMemoryCommitment); 46 GET_PROC(BindBufferMemory); 47 GET_PROC(BindImageMemory); 48 GET_PROC(GetBufferMemoryRequirements); 49 GET_PROC(GetImageMemoryRequirements); 50 GET_PROC(GetImageSparseMemoryRequirements); 51 GET_PROC(GetPhysicalDeviceSparseImageFormatProperties); 52 GET_PROC(QueueBindSparse); 53 GET_PROC(CreateFence); 54 GET_PROC(DestroyFence); 55 GET_PROC(ResetFences); 56 GET_PROC(GetFenceStatus); 57 GET_PROC(WaitForFences); 58 GET_PROC(CreateSemaphore); 59 GET_PROC(DestroySemaphore); 60 GET_PROC(CreateEvent); 61 GET_PROC(DestroyEvent); 62 GET_PROC(GetEventStatus); 63 GET_PROC(SetEvent); 64 GET_PROC(ResetEvent); 65 GET_PROC(CreateQueryPool); 66 GET_PROC(DestroyQueryPool); 67 GET_PROC(GetQueryPoolResults); 68 GET_PROC(CreateBuffer); 69 GET_PROC(DestroyBuffer); 70 GET_PROC(CreateBufferView); 71 GET_PROC(DestroyBufferView); 72 GET_PROC(CreateImage); 73 GET_PROC(DestroyImage); 74 GET_PROC(GetImageSubresourceLayout); 75 GET_PROC(CreateImageView); 76 GET_PROC(DestroyImageView); 77 GET_PROC(CreateShaderModule); 78 GET_PROC(DestroyShaderModule); 79 GET_PROC(CreatePipelineCache); 80 GET_PROC(DestroyPipelineCache); 81 GET_PROC(GetPipelineCacheData); 82 GET_PROC(MergePipelineCaches); 83 GET_PROC(CreateGraphicsPipelines); 84 GET_PROC(CreateComputePipelines); 85 GET_PROC(DestroyPipeline); 86 GET_PROC(CreatePipelineLayout); 87 GET_PROC(DestroyPipelineLayout); 88 GET_PROC(CreateSampler); 89 GET_PROC(DestroySampler); 90 GET_PROC(CreateDescriptorSetLayout); 91 GET_PROC(DestroyDescriptorSetLayout); 92 GET_PROC(CreateDescriptorPool); 93 GET_PROC(DestroyDescriptorPool); 94 GET_PROC(ResetDescriptorPool); 95 GET_PROC(AllocateDescriptorSets); 96 GET_PROC(FreeDescriptorSets); 97 GET_PROC(UpdateDescriptorSets); 98 GET_PROC(CreateFramebuffer); 99 GET_PROC(DestroyFramebuffer); 100 GET_PROC(CreateRenderPass); 101 GET_PROC(DestroyRenderPass); 102 GET_PROC(GetRenderAreaGranularity); 103 GET_PROC(CreateCommandPool); 104 GET_PROC(DestroyCommandPool); 105 GET_PROC(ResetCommandPool); 106 GET_PROC(AllocateCommandBuffers); 107 GET_PROC(FreeCommandBuffers); 108 GET_PROC(BeginCommandBuffer); 109 GET_PROC(EndCommandBuffer); 110 GET_PROC(ResetCommandBuffer); 111 GET_PROC(CmdBindPipeline); 112 GET_PROC(CmdSetViewport); 113 GET_PROC(CmdSetScissor); 114 GET_PROC(CmdSetLineWidth); 115 GET_PROC(CmdSetDepthBias); 116 GET_PROC(CmdSetBlendConstants); 117 GET_PROC(CmdSetDepthBounds); 118 GET_PROC(CmdSetStencilCompareMask); 119 GET_PROC(CmdSetStencilWriteMask); 120 GET_PROC(CmdSetStencilReference); 121 GET_PROC(CmdBindDescriptorSets); 122 GET_PROC(CmdBindIndexBuffer); 123 GET_PROC(CmdBindVertexBuffers); 124 GET_PROC(CmdDraw); 125 GET_PROC(CmdDrawIndexed); 126 GET_PROC(CmdDrawIndirect); 127 GET_PROC(CmdDrawIndexedIndirect); 128 GET_PROC(CmdDispatch); 129 GET_PROC(CmdDispatchIndirect); 130 GET_PROC(CmdCopyBuffer); 131 GET_PROC(CmdCopyImage); 132 GET_PROC(CmdBlitImage); 133 GET_PROC(CmdCopyBufferToImage); 134 GET_PROC(CmdCopyImageToBuffer); 135 GET_PROC(CmdUpdateBuffer); 136 GET_PROC(CmdFillBuffer); 137 GET_PROC(CmdClearColorImage); 138 GET_PROC(CmdClearDepthStencilImage); 139 GET_PROC(CmdClearAttachments); 140 GET_PROC(CmdResolveImage); 141 GET_PROC(CmdSetEvent); 142 GET_PROC(CmdResetEvent); 143 GET_PROC(CmdWaitEvents); 144 GET_PROC(CmdPipelineBarrier); 145 GET_PROC(CmdBeginQuery); 146 GET_PROC(CmdEndQuery); 147 GET_PROC(CmdResetQueryPool); 148 GET_PROC(CmdWriteTimestamp); 149 GET_PROC(CmdCopyQueryPoolResults); 150 GET_PROC(CmdPushConstants); 151 GET_PROC(CmdBeginRenderPass); 152 GET_PROC(CmdNextSubpass); 153 GET_PROC(CmdEndRenderPass); 154 GET_PROC(CmdExecuteCommands); 155 GET_PROC(DestroySurfaceKHR); 156 GET_PROC(GetPhysicalDeviceSurfaceSupportKHR); 157 GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); 158 GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR); 159 GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR); 160 GET_PROC(CreateSwapchainKHR); 161 GET_PROC(DestroySwapchainKHR); 162 GET_PROC(GetSwapchainImagesKHR); 163 GET_PROC(AcquireNextImageKHR); 164 GET_PROC(QueuePresentKHR); 165 GET_PROC(GetPhysicalDeviceDisplayPropertiesKHR); 166 GET_PROC(GetPhysicalDeviceDisplayPlanePropertiesKHR); 167 GET_PROC(GetDisplayPlaneSupportedDisplaysKHR); 168 GET_PROC(GetDisplayModePropertiesKHR); 169 GET_PROC(CreateDisplayModeKHR); 170 GET_PROC(GetDisplayPlaneCapabilitiesKHR); 171 GET_PROC(CreateDisplayPlaneSurfaceKHR); 172 GET_PROC(CreateSharedSwapchainsKHR); 173 174 return interface; 175 } 176 177 #define RETURN_FALSE_INTERFACE \ 178 if (kIsDebug) { SkDebugf("%s:%d GrVkInterface::validate() failed.\n", __FILE__, __LINE__); } \ 179 return false; 180 181 bool GrVkInterface::validate() const { 182 // functions that are always required 183 if (NULL == fFunctions.fCreateInstance || 184 NULL == fFunctions.fDestroyInstance || 185 NULL == fFunctions.fEnumeratePhysicalDevices || 186 NULL == fFunctions.fGetPhysicalDeviceFeatures || 187 NULL == fFunctions.fGetPhysicalDeviceFormatProperties || 188 NULL == fFunctions.fGetPhysicalDeviceImageFormatProperties || 189 NULL == fFunctions.fGetPhysicalDeviceProperties || 190 NULL == fFunctions.fGetPhysicalDeviceQueueFamilyProperties || 191 NULL == fFunctions.fGetPhysicalDeviceMemoryProperties || 192 NULL == fFunctions.fCreateDevice || 193 NULL == fFunctions.fDestroyDevice || 194 NULL == fFunctions.fEnumerateInstanceExtensionProperties || 195 NULL == fFunctions.fEnumerateDeviceExtensionProperties || 196 NULL == fFunctions.fEnumerateInstanceLayerProperties || 197 NULL == fFunctions.fEnumerateDeviceLayerProperties || 198 NULL == fFunctions.fGetDeviceQueue || 199 NULL == fFunctions.fQueueSubmit || 200 NULL == fFunctions.fQueueWaitIdle || 201 NULL == fFunctions.fDeviceWaitIdle || 202 NULL == fFunctions.fAllocateMemory || 203 NULL == fFunctions.fFreeMemory || 204 NULL == fFunctions.fMapMemory || 205 NULL == fFunctions.fUnmapMemory || 206 NULL == fFunctions.fFlushMappedMemoryRanges || 207 NULL == fFunctions.fInvalidateMappedMemoryRanges || 208 NULL == fFunctions.fGetDeviceMemoryCommitment || 209 NULL == fFunctions.fBindBufferMemory || 210 NULL == fFunctions.fBindImageMemory || 211 NULL == fFunctions.fGetBufferMemoryRequirements || 212 NULL == fFunctions.fGetImageMemoryRequirements || 213 NULL == fFunctions.fGetImageSparseMemoryRequirements || 214 NULL == fFunctions.fGetPhysicalDeviceSparseImageFormatProperties || 215 NULL == fFunctions.fQueueBindSparse || 216 NULL == fFunctions.fCreateFence || 217 NULL == fFunctions.fDestroyFence || 218 NULL == fFunctions.fResetFences || 219 NULL == fFunctions.fGetFenceStatus || 220 NULL == fFunctions.fWaitForFences || 221 NULL == fFunctions.fCreateSemaphore || 222 NULL == fFunctions.fDestroySemaphore || 223 NULL == fFunctions.fCreateEvent || 224 NULL == fFunctions.fDestroyEvent || 225 NULL == fFunctions.fGetEventStatus || 226 NULL == fFunctions.fSetEvent || 227 NULL == fFunctions.fResetEvent || 228 NULL == fFunctions.fCreateQueryPool || 229 NULL == fFunctions.fDestroyQueryPool || 230 NULL == fFunctions.fGetQueryPoolResults || 231 NULL == fFunctions.fCreateBuffer || 232 NULL == fFunctions.fDestroyBuffer || 233 NULL == fFunctions.fCreateBufferView || 234 NULL == fFunctions.fDestroyBufferView || 235 NULL == fFunctions.fCreateImage || 236 NULL == fFunctions.fDestroyImage || 237 NULL == fFunctions.fGetImageSubresourceLayout || 238 NULL == fFunctions.fCreateImageView || 239 NULL == fFunctions.fDestroyImageView || 240 NULL == fFunctions.fCreateShaderModule || 241 NULL == fFunctions.fDestroyShaderModule || 242 NULL == fFunctions.fCreatePipelineCache || 243 NULL == fFunctions.fDestroyPipelineCache || 244 NULL == fFunctions.fGetPipelineCacheData || 245 NULL == fFunctions.fMergePipelineCaches || 246 NULL == fFunctions.fCreateGraphicsPipelines || 247 NULL == fFunctions.fCreateComputePipelines || 248 NULL == fFunctions.fDestroyPipeline || 249 NULL == fFunctions.fCreatePipelineLayout || 250 NULL == fFunctions.fDestroyPipelineLayout || 251 NULL == fFunctions.fCreateSampler || 252 NULL == fFunctions.fDestroySampler || 253 NULL == fFunctions.fCreateDescriptorSetLayout || 254 NULL == fFunctions.fDestroyDescriptorSetLayout || 255 NULL == fFunctions.fCreateDescriptorPool || 256 NULL == fFunctions.fDestroyDescriptorPool || 257 NULL == fFunctions.fResetDescriptorPool || 258 NULL == fFunctions.fAllocateDescriptorSets || 259 NULL == fFunctions.fFreeDescriptorSets || 260 NULL == fFunctions.fUpdateDescriptorSets || 261 NULL == fFunctions.fCreateFramebuffer || 262 NULL == fFunctions.fDestroyFramebuffer || 263 NULL == fFunctions.fCreateRenderPass || 264 NULL == fFunctions.fDestroyRenderPass || 265 NULL == fFunctions.fGetRenderAreaGranularity || 266 NULL == fFunctions.fCreateCommandPool || 267 NULL == fFunctions.fDestroyCommandPool || 268 NULL == fFunctions.fResetCommandPool || 269 NULL == fFunctions.fAllocateCommandBuffers || 270 NULL == fFunctions.fFreeCommandBuffers || 271 NULL == fFunctions.fBeginCommandBuffer || 272 NULL == fFunctions.fEndCommandBuffer || 273 NULL == fFunctions.fResetCommandBuffer || 274 NULL == fFunctions.fCmdBindPipeline || 275 NULL == fFunctions.fCmdSetViewport || 276 NULL == fFunctions.fCmdSetScissor || 277 NULL == fFunctions.fCmdSetLineWidth || 278 NULL == fFunctions.fCmdSetDepthBias || 279 NULL == fFunctions.fCmdSetBlendConstants || 280 NULL == fFunctions.fCmdSetDepthBounds || 281 NULL == fFunctions.fCmdSetStencilCompareMask || 282 NULL == fFunctions.fCmdSetStencilWriteMask || 283 NULL == fFunctions.fCmdSetStencilReference || 284 NULL == fFunctions.fCmdBindDescriptorSets || 285 NULL == fFunctions.fCmdBindIndexBuffer || 286 NULL == fFunctions.fCmdBindVertexBuffers || 287 NULL == fFunctions.fCmdDraw || 288 NULL == fFunctions.fCmdDrawIndexed || 289 NULL == fFunctions.fCmdDrawIndirect || 290 NULL == fFunctions.fCmdDrawIndexedIndirect || 291 NULL == fFunctions.fCmdDispatch || 292 NULL == fFunctions.fCmdDispatchIndirect || 293 NULL == fFunctions.fCmdCopyBuffer || 294 NULL == fFunctions.fCmdCopyImage || 295 NULL == fFunctions.fCmdBlitImage || 296 NULL == fFunctions.fCmdCopyBufferToImage || 297 NULL == fFunctions.fCmdCopyImageToBuffer || 298 NULL == fFunctions.fCmdUpdateBuffer || 299 NULL == fFunctions.fCmdFillBuffer || 300 NULL == fFunctions.fCmdClearColorImage || 301 NULL == fFunctions.fCmdClearDepthStencilImage || 302 NULL == fFunctions.fCmdClearAttachments || 303 NULL == fFunctions.fCmdResolveImage || 304 NULL == fFunctions.fCmdSetEvent || 305 NULL == fFunctions.fCmdResetEvent || 306 NULL == fFunctions.fCmdWaitEvents || 307 NULL == fFunctions.fCmdPipelineBarrier || 308 NULL == fFunctions.fCmdBeginQuery || 309 NULL == fFunctions.fCmdEndQuery || 310 NULL == fFunctions.fCmdResetQueryPool || 311 NULL == fFunctions.fCmdWriteTimestamp || 312 NULL == fFunctions.fCmdCopyQueryPoolResults || 313 NULL == fFunctions.fCmdPushConstants || 314 NULL == fFunctions.fCmdBeginRenderPass || 315 NULL == fFunctions.fCmdNextSubpass || 316 NULL == fFunctions.fCmdEndRenderPass || 317 NULL == fFunctions.fCmdExecuteCommands || 318 NULL == fFunctions.fDestroySurfaceKHR || 319 NULL == fFunctions.fGetPhysicalDeviceSurfaceSupportKHR || 320 NULL == fFunctions.fGetPhysicalDeviceSurfaceCapabilitiesKHR || 321 NULL == fFunctions.fGetPhysicalDeviceSurfaceFormatsKHR || 322 NULL == fFunctions.fGetPhysicalDeviceSurfacePresentModesKHR || 323 NULL == fFunctions.fCreateSwapchainKHR || 324 NULL == fFunctions.fDestroySwapchainKHR || 325 NULL == fFunctions.fGetSwapchainImagesKHR || 326 NULL == fFunctions.fAcquireNextImageKHR || 327 NULL == fFunctions.fQueuePresentKHR || 328 NULL == fFunctions.fGetPhysicalDeviceDisplayPropertiesKHR || 329 NULL == fFunctions.fGetPhysicalDeviceDisplayPlanePropertiesKHR || 330 NULL == fFunctions.fGetDisplayPlaneSupportedDisplaysKHR || 331 NULL == fFunctions.fGetDisplayModePropertiesKHR || 332 NULL == fFunctions.fCreateDisplayModeKHR || 333 NULL == fFunctions.fGetDisplayPlaneCapabilitiesKHR || 334 NULL == fFunctions.fCreateDisplayPlaneSurfaceKHR || 335 NULL == fFunctions.fCreateSharedSwapchainsKHR) { 336 return false; 337 } 338 return true; 339 } 340 341