aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gpu/vk/GrVkGpu.cpp52
-rw-r--r--src/gpu/vk/GrVkGpu.h8
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;
};