diff options
Diffstat (limited to 'src/gpu/vk/GrVkGpu.cpp')
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index ba1f7caf2d..0b160a6ade 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -73,33 +73,38 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback( } #endif -sk_sp<GrGpu> GrVkGpu::Make(sk_sp<const GrVkBackendContext> backendContext, +sk_sp<GrGpu> GrVkGpu::Make(const GrVkBackendContext& backendContext, const GrContextOptions& options, GrContext* context) { - if (!backendContext) { + if (backendContext.fInstance == VK_NULL_HANDLE || + backendContext.fPhysicalDevice == VK_NULL_HANDLE || + backendContext.fDevice == VK_NULL_HANDLE || + backendContext.fQueue == VK_NULL_HANDLE) { return nullptr; } - - if (!backendContext->fInterface->validate(backendContext->fExtensions)) { + if (!backendContext.fInterface || + !backendContext.fInterface->validate(backendContext.fExtensions)) { return nullptr; } - return sk_sp<GrGpu>(new GrVkGpu(context, options, std::move(backendContext))); + return sk_sp<GrGpu>(new GrVkGpu(context, options, backendContext)); } //////////////////////////////////////////////////////////////////////////////// GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options, - sk_sp<const GrVkBackendContext> backendCtx) + const GrVkBackendContext& backendContext) : INHERITED(context) - , fBackendContext(std::move(backendCtx)) - , fMemoryAllocator(fBackendContext->fMemoryAllocator) - , fDevice(fBackendContext->fDevice) - , fQueue(fBackendContext->fQueue) + , fInterface(std::move(backendContext.fInterface)) + , fMemoryAllocator(backendContext.fMemoryAllocator) + , fInstance(backendContext.fInstance) + , fDevice(backendContext.fDevice) + , fQueue(backendContext.fQueue) , fResourceProvider(this) , fDisconnected(false) { + SkASSERT(!backendContext.fOwnsInstanceAndDevice); #ifdef SK_ENABLE_VK_LAYERS fCallback = VK_NULL_HANDLE; - if (fBackendContext->fExtensions & kEXT_debug_report_GrVkExtensionFlag) { + if (backendContext.fExtensions & kEXT_debug_report_GrVkExtensionFlag) { // Setup callback creation information VkDebugReportCallbackCreateInfoEXT callbackCreateInfo; callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; @@ -114,32 +119,32 @@ GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options, // Register the callback GR_VK_CALL_ERRCHECK(this->vkInterface(), - CreateDebugReportCallbackEXT(fBackendContext->fInstance, + CreateDebugReportCallbackEXT(backendContext.fInstance, &callbackCreateInfo, nullptr, &fCallback)); } #endif if (!fMemoryAllocator) { // We were not given a memory allocator at creation - fMemoryAllocator.reset(new GrVkAMDMemoryAllocator(fBackendContext->fPhysicalDevice, - fDevice, fBackendContext->fInterface)); + fMemoryAllocator.reset(new GrVkAMDMemoryAllocator(backendContext.fPhysicalDevice, + fDevice, backendContext.fInterface)); } fCompiler = new SkSL::Compiler(); - fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), fBackendContext->fPhysicalDevice, - fBackendContext->fFeatures, fBackendContext->fExtensions)); + fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), backendContext.fPhysicalDevice, + backendContext.fFeatures, backendContext.fExtensions)); fCaps.reset(SkRef(fVkCaps.get())); - VK_CALL(GetPhysicalDeviceProperties(fBackendContext->fPhysicalDevice, &fPhysDevProps)); - VK_CALL(GetPhysicalDeviceMemoryProperties(fBackendContext->fPhysicalDevice, &fPhysDevMemProps)); + VK_CALL(GetPhysicalDeviceProperties(backendContext.fPhysicalDevice, &fPhysDevProps)); + VK_CALL(GetPhysicalDeviceMemoryProperties(backendContext.fPhysicalDevice, &fPhysDevMemProps)); const VkCommandPoolCreateInfo cmdPoolInfo = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType nullptr, // pNext VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // CmdPoolCreateFlags - fBackendContext->fGraphicsQueueIndex, // queueFamilyIndex + backendContext.fGraphicsQueueIndex, // queueFamilyIndex }; GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateCommandPool(fDevice, &cmdPoolInfo, nullptr, &fCmdPool)); @@ -201,10 +206,15 @@ void GrVkGpu::destroyResources() { #ifdef SK_ENABLE_VK_LAYERS if (fCallback) { - VK_CALL(DestroyDebugReportCallbackEXT(fBackendContext->fInstance, fCallback, nullptr)); + VK_CALL(DestroyDebugReportCallbackEXT(fInstance, fCallback, nullptr)); } #endif + fMemoryAllocator.reset(); + + fQueue = VK_NULL_HANDLE; + fDevice = VK_NULL_HANDLE; + fInstance = VK_NULL_HANDLE; } GrVkGpu::~GrVkGpu() { |