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