diff --git a/include/gpu/vk/GrVkBackendContext.h b/include/gpu/vk/GrVkBackendContext.h index 5ae7b31656..5838caa323 100644 --- a/include/gpu/vk/GrVkBackendContext.h +++ b/include/gpu/vk/GrVkBackendContext.h @@ -58,6 +58,20 @@ struct GrVkBackendContext : public SkRefCnt { CanPresentFn = CanPresentFn(), GrVkInterface::GetProc getProc = nullptr); + static const GrVkBackendContext* Create(const GrVkInterface::GetInstanceProc& getInstanceProc, + const GrVkInterface::GetDeviceProc& getDeviceProc, + uint32_t* presentQueueIndex = nullptr, + CanPresentFn canPresent = CanPresentFn()) { + auto getProc = [&getInstanceProc, &getDeviceProc](const char* proc_name, + VkInstance instance, VkDevice device) { + if (device != VK_NULL_HANDLE) { + return getDeviceProc(device, proc_name); + } + return getInstanceProc(instance, proc_name); + }; + return Create(presentQueueIndex, canPresent, getProc); + } + ~GrVkBackendContext() override; }; diff --git a/include/gpu/vk/GrVkInterface.h b/include/gpu/vk/GrVkInterface.h index dca47ffc4c..1a381bdbe7 100644 --- a/include/gpu/vk/GrVkInterface.h +++ b/include/gpu/vk/GrVkInterface.h @@ -40,6 +40,13 @@ public: VkInstance, // instance or VK_NULL_HANDLE VkDevice // device or VK_NULL_HANDLE )>; + + // This is typically vkGetInstanceProcAddr. + using GetInstanceProc = std::function; + + // This is typically vkGetDeviceProcAddr. + using GetDeviceProc = std::function; + GrVkInterface(GetProc getProc, VkInstance instance, VkDevice device, diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 3d30e3585b..d8f1037f07 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -77,10 +77,7 @@ GrGpu* GrVkGpu::Create(GrBackendContext backendContext, const GrContextOptions& const GrVkBackendContext* vkBackendContext = reinterpret_cast(backendContext); if (!vkBackendContext) { - vkBackendContext = GrVkBackendContext::Create(); - if (!vkBackendContext) { - return nullptr; - } + return nullptr; } else { vkBackendContext->ref(); } diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp index b1e7ad450f..3e76d87830 100644 --- a/tools/gpu/vk/VkTestContext.cpp +++ b/tools/gpu/vk/VkTestContext.cpp @@ -109,7 +109,8 @@ GR_STATIC_ASSERT(sizeof(VkFence) <= sizeof(sk_gpu_test::PlatformFence)); class VkTestContextImpl : public sk_gpu_test::VkTestContext { public: static VkTestContext* Create() { - sk_sp backendContext(GrVkBackendContext::Create()); + sk_sp backendContext( + GrVkBackendContext::Create(vkGetInstanceProcAddr, vkGetDeviceProcAddr)); if (!backendContext) { return nullptr; } diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp index 831c7ae0c2..f483c27163 100644 --- a/tools/viewer/sk_app/VulkanWindowContext.cpp +++ b/tools/viewer/sk_app/VulkanWindowContext.cpp @@ -41,7 +41,8 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params, , fBackbuffers(nullptr) { // any config code here (particularly for msaa)? - fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPresent)); + fBackendContext.reset(GrVkBackendContext::Create(vkGetInstanceProcAddr, vkGetDeviceProcAddr, + &fPresentQueueIndex, canPresent)); if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) {