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 #ifndef GrVkInterface_DEFINED 9 #define GrVkInterface_DEFINED 10 11 #include "SkRefCnt.h" 12 13 #include "vk/GrVkDefines.h" 14 15 //////////////////////////////////////////////////////////////////////////////// 16 17 /** 18 * GrContext uses the following interface to make all calls into Vulkan. When a 19 * GrContext is created it is given a GrVkInterface. All functions that should be 20 * available based on the Vulkan's version must be non-NULL or GrContext creation 21 * will fail. This can be tested with the validate() method. 22 */ 23 struct SK_API GrVkInterface : public SkRefCnt { 24 private: 25 // simple wrapper class that exists only to initialize a pointer to NULL 26 template <typename FNPTR_TYPE> class VkPtr { 27 public: VkPtrGrVkInterface28 VkPtr() : fPtr(NULL) {} 29 VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } FNPTR_TYPEGrVkInterface30 operator FNPTR_TYPE() const { return fPtr; } 31 private: 32 FNPTR_TYPE fPtr; 33 }; 34 35 typedef SkRefCnt INHERITED; 36 37 public: 38 using GetProc = std::function<PFN_vkVoidFunction( 39 const char*, // function name 40 VkInstance, // instance or VK_NULL_HANDLE 41 VkDevice // device or VK_NULL_HANDLE 42 )>; 43 44 // This is typically vkGetInstanceProcAddr. 45 using GetInstanceProc = std::function<PFN_vkVoidFunction(VkInstance, const char*)>; 46 47 // This is typically vkGetDeviceProcAddr. 48 using GetDeviceProc = std::function<PFN_vkVoidFunction(VkDevice, const char*)>; 49 50 GrVkInterface(GetProc getProc, 51 VkInstance instance, 52 VkDevice device, 53 uint32_t extensionFlags); 54 55 GrVkInterface(const GetInstanceProc&, 56 const GetDeviceProc&, 57 VkInstance instance, 58 VkDevice device, 59 uint32_t extensionFlags); 60 61 // Validates that the GrVkInterface supports its advertised standard. This means the necessary 62 // function pointers have been initialized for Vulkan version. 63 bool validate(uint32_t extensionFlags) const; 64 65 /** 66 * The function pointers are in a struct so that we can have a compiler generated assignment 67 * operator. 68 */ 69 struct Functions { 70 VkPtr<PFN_vkCreateInstance> fCreateInstance; 71 VkPtr<PFN_vkDestroyInstance> fDestroyInstance; 72 VkPtr<PFN_vkEnumeratePhysicalDevices> fEnumeratePhysicalDevices; 73 VkPtr<PFN_vkGetPhysicalDeviceFeatures> fGetPhysicalDeviceFeatures; 74 VkPtr<PFN_vkGetPhysicalDeviceFormatProperties> fGetPhysicalDeviceFormatProperties; 75 VkPtr<PFN_vkGetPhysicalDeviceImageFormatProperties> fGetPhysicalDeviceImageFormatProperties; 76 VkPtr<PFN_vkGetPhysicalDeviceProperties> fGetPhysicalDeviceProperties; 77 VkPtr<PFN_vkGetPhysicalDeviceQueueFamilyProperties> fGetPhysicalDeviceQueueFamilyProperties; 78 VkPtr<PFN_vkGetPhysicalDeviceMemoryProperties> fGetPhysicalDeviceMemoryProperties; 79 VkPtr<PFN_vkCreateDevice> fCreateDevice; 80 VkPtr<PFN_vkDestroyDevice> fDestroyDevice; 81 VkPtr<PFN_vkEnumerateInstanceExtensionProperties> fEnumerateInstanceExtensionProperties; 82 VkPtr<PFN_vkEnumerateDeviceExtensionProperties> fEnumerateDeviceExtensionProperties; 83 VkPtr<PFN_vkEnumerateInstanceLayerProperties> fEnumerateInstanceLayerProperties; 84 VkPtr<PFN_vkEnumerateDeviceLayerProperties> fEnumerateDeviceLayerProperties; 85 VkPtr<PFN_vkGetDeviceQueue> fGetDeviceQueue; 86 VkPtr<PFN_vkQueueSubmit> fQueueSubmit; 87 VkPtr<PFN_vkQueueWaitIdle> fQueueWaitIdle; 88 VkPtr<PFN_vkDeviceWaitIdle> fDeviceWaitIdle; 89 VkPtr<PFN_vkAllocateMemory> fAllocateMemory; 90 VkPtr<PFN_vkFreeMemory> fFreeMemory; 91 VkPtr<PFN_vkMapMemory> fMapMemory; 92 VkPtr<PFN_vkUnmapMemory> fUnmapMemory; 93 VkPtr<PFN_vkFlushMappedMemoryRanges> fFlushMappedMemoryRanges; 94 VkPtr<PFN_vkInvalidateMappedMemoryRanges> fInvalidateMappedMemoryRanges; 95 VkPtr<PFN_vkGetDeviceMemoryCommitment> fGetDeviceMemoryCommitment; 96 VkPtr<PFN_vkBindBufferMemory> fBindBufferMemory; 97 VkPtr<PFN_vkBindImageMemory> fBindImageMemory; 98 VkPtr<PFN_vkGetBufferMemoryRequirements> fGetBufferMemoryRequirements; 99 VkPtr<PFN_vkGetImageMemoryRequirements> fGetImageMemoryRequirements; 100 VkPtr<PFN_vkGetImageSparseMemoryRequirements> fGetImageSparseMemoryRequirements; 101 VkPtr<PFN_vkGetPhysicalDeviceSparseImageFormatProperties> fGetPhysicalDeviceSparseImageFormatProperties; 102 VkPtr<PFN_vkQueueBindSparse> fQueueBindSparse; 103 VkPtr<PFN_vkCreateFence> fCreateFence; 104 VkPtr<PFN_vkDestroyFence> fDestroyFence; 105 VkPtr<PFN_vkResetFences> fResetFences; 106 VkPtr<PFN_vkGetFenceStatus> fGetFenceStatus; 107 VkPtr<PFN_vkWaitForFences> fWaitForFences; 108 VkPtr<PFN_vkCreateSemaphore> fCreateSemaphore; 109 VkPtr<PFN_vkDestroySemaphore> fDestroySemaphore; 110 VkPtr<PFN_vkCreateEvent> fCreateEvent; 111 VkPtr<PFN_vkDestroyEvent> fDestroyEvent; 112 VkPtr<PFN_vkGetEventStatus> fGetEventStatus; 113 VkPtr<PFN_vkSetEvent> fSetEvent; 114 VkPtr<PFN_vkResetEvent> fResetEvent; 115 VkPtr<PFN_vkCreateQueryPool> fCreateQueryPool; 116 VkPtr<PFN_vkDestroyQueryPool> fDestroyQueryPool; 117 VkPtr<PFN_vkGetQueryPoolResults> fGetQueryPoolResults; 118 VkPtr<PFN_vkCreateBuffer> fCreateBuffer; 119 VkPtr<PFN_vkDestroyBuffer> fDestroyBuffer; 120 VkPtr<PFN_vkCreateBufferView> fCreateBufferView; 121 VkPtr<PFN_vkDestroyBufferView> fDestroyBufferView; 122 VkPtr<PFN_vkCreateImage> fCreateImage; 123 VkPtr<PFN_vkDestroyImage> fDestroyImage; 124 VkPtr<PFN_vkGetImageSubresourceLayout> fGetImageSubresourceLayout; 125 VkPtr<PFN_vkCreateImageView> fCreateImageView; 126 VkPtr<PFN_vkDestroyImageView> fDestroyImageView; 127 VkPtr<PFN_vkCreateShaderModule> fCreateShaderModule; 128 VkPtr<PFN_vkDestroyShaderModule> fDestroyShaderModule; 129 VkPtr<PFN_vkCreatePipelineCache> fCreatePipelineCache; 130 VkPtr<PFN_vkDestroyPipelineCache> fDestroyPipelineCache; 131 VkPtr<PFN_vkGetPipelineCacheData> fGetPipelineCacheData; 132 VkPtr<PFN_vkMergePipelineCaches> fMergePipelineCaches; 133 VkPtr<PFN_vkCreateGraphicsPipelines> fCreateGraphicsPipelines; 134 VkPtr<PFN_vkCreateComputePipelines> fCreateComputePipelines; 135 VkPtr<PFN_vkDestroyPipeline> fDestroyPipeline; 136 VkPtr<PFN_vkCreatePipelineLayout> fCreatePipelineLayout; 137 VkPtr<PFN_vkDestroyPipelineLayout> fDestroyPipelineLayout; 138 VkPtr<PFN_vkCreateSampler> fCreateSampler; 139 VkPtr<PFN_vkDestroySampler> fDestroySampler; 140 VkPtr<PFN_vkCreateDescriptorSetLayout> fCreateDescriptorSetLayout; 141 VkPtr<PFN_vkDestroyDescriptorSetLayout> fDestroyDescriptorSetLayout; 142 VkPtr<PFN_vkCreateDescriptorPool> fCreateDescriptorPool; 143 VkPtr<PFN_vkDestroyDescriptorPool> fDestroyDescriptorPool; 144 VkPtr<PFN_vkResetDescriptorPool> fResetDescriptorPool; 145 VkPtr<PFN_vkAllocateDescriptorSets> fAllocateDescriptorSets; 146 VkPtr<PFN_vkFreeDescriptorSets> fFreeDescriptorSets; 147 VkPtr<PFN_vkUpdateDescriptorSets> fUpdateDescriptorSets; 148 VkPtr<PFN_vkCreateFramebuffer> fCreateFramebuffer; 149 VkPtr<PFN_vkDestroyFramebuffer> fDestroyFramebuffer; 150 VkPtr<PFN_vkCreateRenderPass> fCreateRenderPass; 151 VkPtr<PFN_vkDestroyRenderPass> fDestroyRenderPass; 152 VkPtr<PFN_vkGetRenderAreaGranularity> fGetRenderAreaGranularity; 153 VkPtr<PFN_vkCreateCommandPool> fCreateCommandPool; 154 VkPtr<PFN_vkDestroyCommandPool> fDestroyCommandPool; 155 VkPtr<PFN_vkResetCommandPool> fResetCommandPool; 156 VkPtr<PFN_vkAllocateCommandBuffers> fAllocateCommandBuffers; 157 VkPtr<PFN_vkFreeCommandBuffers> fFreeCommandBuffers; 158 VkPtr<PFN_vkBeginCommandBuffer> fBeginCommandBuffer; 159 VkPtr<PFN_vkEndCommandBuffer> fEndCommandBuffer; 160 VkPtr<PFN_vkResetCommandBuffer> fResetCommandBuffer; 161 VkPtr<PFN_vkCmdBindPipeline> fCmdBindPipeline; 162 VkPtr<PFN_vkCmdSetViewport> fCmdSetViewport; 163 VkPtr<PFN_vkCmdSetScissor> fCmdSetScissor; 164 VkPtr<PFN_vkCmdSetLineWidth> fCmdSetLineWidth; 165 VkPtr<PFN_vkCmdSetDepthBias> fCmdSetDepthBias; 166 VkPtr<PFN_vkCmdSetBlendConstants> fCmdSetBlendConstants; 167 VkPtr<PFN_vkCmdSetDepthBounds> fCmdSetDepthBounds; 168 VkPtr<PFN_vkCmdSetStencilCompareMask> fCmdSetStencilCompareMask; 169 VkPtr<PFN_vkCmdSetStencilWriteMask> fCmdSetStencilWriteMask; 170 VkPtr<PFN_vkCmdSetStencilReference> fCmdSetStencilReference; 171 VkPtr<PFN_vkCmdBindDescriptorSets> fCmdBindDescriptorSets; 172 VkPtr<PFN_vkCmdBindIndexBuffer> fCmdBindIndexBuffer; 173 VkPtr<PFN_vkCmdBindVertexBuffers> fCmdBindVertexBuffers; 174 VkPtr<PFN_vkCmdDraw> fCmdDraw; 175 VkPtr<PFN_vkCmdDrawIndexed> fCmdDrawIndexed; 176 VkPtr<PFN_vkCmdDrawIndirect> fCmdDrawIndirect; 177 VkPtr<PFN_vkCmdDrawIndexedIndirect> fCmdDrawIndexedIndirect; 178 VkPtr<PFN_vkCmdDispatch> fCmdDispatch; 179 VkPtr<PFN_vkCmdDispatchIndirect> fCmdDispatchIndirect; 180 VkPtr<PFN_vkCmdCopyBuffer> fCmdCopyBuffer; 181 VkPtr<PFN_vkCmdCopyImage> fCmdCopyImage; 182 VkPtr<PFN_vkCmdBlitImage> fCmdBlitImage; 183 VkPtr<PFN_vkCmdCopyBufferToImage> fCmdCopyBufferToImage; 184 VkPtr<PFN_vkCmdCopyImageToBuffer> fCmdCopyImageToBuffer; 185 VkPtr<PFN_vkCmdUpdateBuffer> fCmdUpdateBuffer; 186 VkPtr<PFN_vkCmdFillBuffer> fCmdFillBuffer; 187 VkPtr<PFN_vkCmdClearColorImage> fCmdClearColorImage; 188 VkPtr<PFN_vkCmdClearDepthStencilImage> fCmdClearDepthStencilImage; 189 VkPtr<PFN_vkCmdClearAttachments> fCmdClearAttachments; 190 VkPtr<PFN_vkCmdResolveImage> fCmdResolveImage; 191 VkPtr<PFN_vkCmdSetEvent> fCmdSetEvent; 192 VkPtr<PFN_vkCmdResetEvent> fCmdResetEvent; 193 VkPtr<PFN_vkCmdWaitEvents> fCmdWaitEvents; 194 VkPtr<PFN_vkCmdPipelineBarrier> fCmdPipelineBarrier; 195 VkPtr<PFN_vkCmdBeginQuery> fCmdBeginQuery; 196 VkPtr<PFN_vkCmdEndQuery> fCmdEndQuery; 197 VkPtr<PFN_vkCmdResetQueryPool> fCmdResetQueryPool; 198 VkPtr<PFN_vkCmdWriteTimestamp> fCmdWriteTimestamp; 199 VkPtr<PFN_vkCmdCopyQueryPoolResults> fCmdCopyQueryPoolResults; 200 VkPtr<PFN_vkCmdPushConstants> fCmdPushConstants; 201 VkPtr<PFN_vkCmdBeginRenderPass> fCmdBeginRenderPass; 202 VkPtr<PFN_vkCmdNextSubpass> fCmdNextSubpass; 203 VkPtr<PFN_vkCmdEndRenderPass> fCmdEndRenderPass; 204 VkPtr<PFN_vkCmdExecuteCommands> fCmdExecuteCommands; 205 206 VkPtr<PFN_vkCreateDebugReportCallbackEXT> fCreateDebugReportCallbackEXT; 207 VkPtr<PFN_vkDebugReportMessageEXT> fDebugReportMessageEXT; 208 VkPtr<PFN_vkDestroyDebugReportCallbackEXT> fDestroyDebugReportCallbackEXT; 209 } fFunctions; 210 211 }; 212 213 #endif 214