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