/* * Copyright 2015 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrVkInterface_DEFINED #define GrVkInterface_DEFINED #include "SkRefCnt.h" #include "vk/GrVkDefines.h" //////////////////////////////////////////////////////////////////////////////// /** * GrContext uses the following interface to make all calls into Vulkan. When a * GrContext is created it is given a GrVkInterface. All functions that should be * available based on the Vulkan's version must be non-NULL or GrContext creation * will fail. This can be tested with the validate() method. */ struct SK_API GrVkInterface : public SkRefCnt { private: // simple wrapper class that exists only to initialize a pointer to NULL template class VkPtr { public: VkPtr() : fPtr(NULL) {} VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } operator FNPTR_TYPE() const { return fPtr; } private: FNPTR_TYPE fPtr; }; typedef SkRefCnt INHERITED; public: // TODO: This matches the definition of GrVkGetProc in GrVkTypes. Once we switch clients to // using that and make GrVkInterface private, we can remove this GetProc. using GetProc = std::function; // This is typically vkGetInstanceProcAddr. using GetInstanceProc = std::function; // This is typically vkGetDeviceProcAddr. using GetDeviceProc = std::function; GrVkInterface(GetProc getProc, VkInstance instance, VkDevice device, uint32_t extensionFlags); GrVkInterface(const GetInstanceProc&, const GetDeviceProc&, VkInstance instance, VkDevice device, uint32_t extensionFlags); // Validates that the GrVkInterface supports its advertised standard. This means the necessary // function pointers have been initialized for Vulkan version. bool validate(uint32_t extensionFlags) const; /** * The function pointers are in a struct so that we can have a compiler generated assignment * operator. */ struct Functions { VkPtr fCreateInstance; VkPtr fDestroyInstance; VkPtr fEnumeratePhysicalDevices; VkPtr fGetPhysicalDeviceFeatures; VkPtr fGetPhysicalDeviceFormatProperties; VkPtr fGetPhysicalDeviceImageFormatProperties; VkPtr fGetPhysicalDeviceProperties; VkPtr fGetPhysicalDeviceQueueFamilyProperties; VkPtr fGetPhysicalDeviceMemoryProperties; VkPtr fCreateDevice; VkPtr fDestroyDevice; VkPtr fEnumerateInstanceExtensionProperties; VkPtr fEnumerateDeviceExtensionProperties; VkPtr fEnumerateInstanceLayerProperties; VkPtr fEnumerateDeviceLayerProperties; VkPtr fGetDeviceQueue; VkPtr fQueueSubmit; VkPtr fQueueWaitIdle; VkPtr fDeviceWaitIdle; VkPtr fAllocateMemory; VkPtr fFreeMemory; VkPtr fMapMemory; VkPtr fUnmapMemory; VkPtr fFlushMappedMemoryRanges; VkPtr fInvalidateMappedMemoryRanges; VkPtr fGetDeviceMemoryCommitment; VkPtr fBindBufferMemory; VkPtr fBindImageMemory; VkPtr fGetBufferMemoryRequirements; VkPtr fGetImageMemoryRequirements; VkPtr fGetImageSparseMemoryRequirements; VkPtr fGetPhysicalDeviceSparseImageFormatProperties; VkPtr fQueueBindSparse; VkPtr fCreateFence; VkPtr fDestroyFence; VkPtr fResetFences; VkPtr fGetFenceStatus; VkPtr fWaitForFences; VkPtr fCreateSemaphore; VkPtr fDestroySemaphore; VkPtr fCreateEvent; VkPtr fDestroyEvent; VkPtr fGetEventStatus; VkPtr fSetEvent; VkPtr fResetEvent; VkPtr fCreateQueryPool; VkPtr fDestroyQueryPool; VkPtr fGetQueryPoolResults; VkPtr fCreateBuffer; VkPtr fDestroyBuffer; VkPtr fCreateBufferView; VkPtr fDestroyBufferView; VkPtr fCreateImage; VkPtr fDestroyImage; VkPtr fGetImageSubresourceLayout; VkPtr fCreateImageView; VkPtr fDestroyImageView; VkPtr fCreateShaderModule; VkPtr fDestroyShaderModule; VkPtr fCreatePipelineCache; VkPtr fDestroyPipelineCache; VkPtr fGetPipelineCacheData; VkPtr fMergePipelineCaches; VkPtr fCreateGraphicsPipelines; VkPtr fCreateComputePipelines; VkPtr fDestroyPipeline; VkPtr fCreatePipelineLayout; VkPtr fDestroyPipelineLayout; VkPtr fCreateSampler; VkPtr fDestroySampler; VkPtr fCreateDescriptorSetLayout; VkPtr fDestroyDescriptorSetLayout; VkPtr fCreateDescriptorPool; VkPtr fDestroyDescriptorPool; VkPtr fResetDescriptorPool; VkPtr fAllocateDescriptorSets; VkPtr fFreeDescriptorSets; VkPtr fUpdateDescriptorSets; VkPtr fCreateFramebuffer; VkPtr fDestroyFramebuffer; VkPtr fCreateRenderPass; VkPtr fDestroyRenderPass; VkPtr fGetRenderAreaGranularity; VkPtr fCreateCommandPool; VkPtr fDestroyCommandPool; VkPtr fResetCommandPool; VkPtr fAllocateCommandBuffers; VkPtr fFreeCommandBuffers; VkPtr fBeginCommandBuffer; VkPtr fEndCommandBuffer; VkPtr fResetCommandBuffer; VkPtr fCmdBindPipeline; VkPtr fCmdSetViewport; VkPtr fCmdSetScissor; VkPtr fCmdSetLineWidth; VkPtr fCmdSetDepthBias; VkPtr fCmdSetBlendConstants; VkPtr fCmdSetDepthBounds; VkPtr fCmdSetStencilCompareMask; VkPtr fCmdSetStencilWriteMask; VkPtr fCmdSetStencilReference; VkPtr fCmdBindDescriptorSets; VkPtr fCmdBindIndexBuffer; VkPtr fCmdBindVertexBuffers; VkPtr fCmdDraw; VkPtr fCmdDrawIndexed; VkPtr fCmdDrawIndirect; VkPtr fCmdDrawIndexedIndirect; VkPtr fCmdDispatch; VkPtr fCmdDispatchIndirect; VkPtr fCmdCopyBuffer; VkPtr fCmdCopyImage; VkPtr fCmdBlitImage; VkPtr fCmdCopyBufferToImage; VkPtr fCmdCopyImageToBuffer; VkPtr fCmdUpdateBuffer; VkPtr fCmdFillBuffer; VkPtr fCmdClearColorImage; VkPtr fCmdClearDepthStencilImage; VkPtr fCmdClearAttachments; VkPtr fCmdResolveImage; VkPtr fCmdSetEvent; VkPtr fCmdResetEvent; VkPtr fCmdWaitEvents; VkPtr fCmdPipelineBarrier; VkPtr fCmdBeginQuery; VkPtr fCmdEndQuery; VkPtr fCmdResetQueryPool; VkPtr fCmdWriteTimestamp; VkPtr fCmdCopyQueryPoolResults; VkPtr fCmdPushConstants; VkPtr fCmdBeginRenderPass; VkPtr fCmdNextSubpass; VkPtr fCmdEndRenderPass; VkPtr fCmdExecuteCommands; VkPtr fCreateDebugReportCallbackEXT; VkPtr fDebugReportMessageEXT; VkPtr fDestroyDebugReportCallbackEXT; } fFunctions; }; #endif