diff options
author | Greg Daniel <egdaniel@google.com> | 2017-05-08 16:17:53 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-09 03:41:52 +0000 |
commit | 8606cf836e2cdbabe7fd917b7cba88b6673c9175 (patch) | |
tree | 19b58dc8d3d062cd6f3198abf6f2057e0b0c2c38 | |
parent | 0c9d13b97a1990ee5fea2608150d3d2c1f6b8948 (diff) |
Implement disconnect function for GrVkGpu
Apparently this was not added to Vk when it was added to GL. It may be
the cause of a flutter error they are seeing.
Bug: skia:
Change-Id: I4d4e9d1817b308b6c4f01e83f712eb3437e2ad71
Reviewed-on: https://skia-review.googlesource.com/15887
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 52 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.h | 8 |
2 files changed, 52 insertions, 8 deletions
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index c271133918..23c7094bb3 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -97,7 +97,8 @@ GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options, : INHERITED(context) , fDevice(backendCtx->fDevice) , fQueue(backendCtx->fQueue) - , fResourceProvider(this) { + , fResourceProvider(this) + , fDisconnected(false) { fBackendContext.reset(backendCtx); #ifdef SK_ENABLE_VK_LAYERS @@ -157,9 +158,11 @@ GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options, fHeaps[kCopyWriteBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Strategy, 16*1024*1024)); } -GrVkGpu::~GrVkGpu() { - fCurrentCmdBuffer->end(this); - fCurrentCmdBuffer->unref(this); +void GrVkGpu::destroyResources() { + if (fCurrentCmdBuffer) { + fCurrentCmdBuffer->end(this); + fCurrentCmdBuffer->unref(this); + } // wait for all commands to finish fResourceProvider.checkCommandBuffers(); @@ -193,16 +196,49 @@ GrVkGpu::~GrVkGpu() { // must call this just before we destroy the command pool and VkDevice fResourceProvider.destroyResources(VK_ERROR_DEVICE_LOST == res); - VK_CALL(DestroyCommandPool(fDevice, fCmdPool, nullptr)); - - delete fCompiler; + if (fCmdPool != VK_NULL_HANDLE) { + VK_CALL(DestroyCommandPool(fDevice, fCmdPool, nullptr)); + } #ifdef SK_ENABLE_VK_LAYERS if (fCallback) { VK_CALL(DestroyDebugReportCallbackEXT(fBackendContext->fInstance, fCallback, nullptr)); - fCallback = VK_NULL_HANDLE; } #endif + +} + +GrVkGpu::~GrVkGpu() { + if (!fDisconnected) { + this->destroyResources(); + } + delete fCompiler; +} + + +void GrVkGpu::disconnect(DisconnectType type) { + INHERITED::disconnect(type); + if (!fDisconnected) { + if (DisconnectType::kCleanup == type) { + this->destroyResources(); + } else { + fCurrentCmdBuffer->unrefAndAbandon(); + for (int i = 0; i < fSemaphoresToWaitOn.count(); ++i) { + fSemaphoresToWaitOn[i]->unrefAndAbandon(); + } + fCopyManager.abandonResources(); + + // must call this just before we destroy the command pool and VkDevice + fResourceProvider.abandonResources(); + } + fSemaphoresToWaitOn.reset(); +#ifdef SK_ENABLE_VK_LAYERS + fCallback = VK_NULL_HANDLE; +#endif + fCurrentCmdBuffer = nullptr; + fCmdPool = VK_NULL_HANDLE; + fDisconnected = true; + } } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index b47d428836..605c7af965 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -43,6 +43,8 @@ public: ~GrVkGpu() override; + void disconnect(DisconnectType) override; + const GrVkInterface* vkInterface() const { return fBackendContext->fInterface.get(); } const GrVkCaps& vkCaps() const { return *fVkCaps; } @@ -167,6 +169,8 @@ private: void onResetContext(uint32_t resetBits) override {} + void destroyResources(); + GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const SkTArray<GrMipLevel>&) override; @@ -282,6 +286,10 @@ private: // there is significant overhead to the first compile of any compiler. SkSL::Compiler* fCompiler; + // We need a bool to track whether or not we've already disconnected all the gpu resources from + // vulkan context. + bool fDisconnected; + typedef GrGpu INHERITED; }; |