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