From fca8fd6201901e372ef544a847284b0ea02cd1b1 Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Tue, 13 Nov 2018 13:55:48 -0500 Subject: [PATCH] Vulkan: Refix cleanup race condition on Context destroy This partially reverts commit 905ee08219faed8ea50e194be0d76ad69faf1026 due to regression caused on startup time. Instead of calling finish before destroying the context, the objects in the Vulkan backend are `release()`ed instead of `destroy()`ed, so they will be kept alive for the duration of current work. Bug: 904846 Change-Id: Ia774470666c4c0d4c1ddc348f685d621243de204 Reviewed-on: https://chromium-review.googlesource.com/c/1333969 Reviewed-by: Jamie Madill Reviewed-by: Geoff Lang Commit-Queue: Shahbaz Youssefi --- src/libANGLE/Context.cpp | 4 ---- src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp | 6 ------ src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp | 17 ++--------------- src/libANGLE/renderer/vulkan/FramebufferVk.cpp | 4 ++-- src/libANGLE/renderer/vulkan/VertexArrayVk.cpp | 13 +++++++------ src/libANGLE/renderer/vulkan/vk_helpers.cpp | 5 +++++ src/libANGLE/renderer/vulkan/vk_helpers.h | 1 + 7 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp index 8cc877424..58a9c8a6f 100644 --- a/src/libANGLE/Context.cpp +++ b/src/libANGLE/Context.cpp @@ -545,10 +545,6 @@ void Context::initialize() egl::Error Context::onDestroy(const egl::Display *display) { - // Trigger a finish() to make sure resources are not in use upon destruction. Particularly - // necessary for Vulkan. - finish(); - if (mGLES1Renderer) { mGLES1Renderer->onDestroy(this, &mGLState); diff --git a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp index 2277489a7..bc72881ff 100644 --- a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp +++ b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp @@ -1203,12 +1203,6 @@ angle::Result Renderer11::flush(Context11 *context11) angle::Result Renderer11::finish(Context11 *context11) { - // If device is lost, there is nothing to finish. This is called on context destroy. - if (!mDevice) - { - return angle::Result::Continue(); - } - if (!mSyncQuery.valid()) { D3D11_QUERY_DESC queryDesc; diff --git a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp index 0546a5654..bbd403622 100644 --- a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp +++ b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp @@ -648,20 +648,9 @@ angle::Result Renderer9::finish(const gl::Context *context) } ANGLE_TRY_HR(context9, result, "Failed to get event query data"); - // Loop until the query completes. A bug has been observed where the query result is always - // false, so we loop for a maximum of 100ms. + // Loop until the query completes unsigned int attempt = 0; - - LARGE_INTEGER timerFrequency; - QueryPerformanceFrequency(&timerFrequency); - - LARGE_INTEGER startTime; - QueryPerformanceCounter(&startTime); - LARGE_INTEGER currentTime = startTime; - - // Note: timerFrequency is ticks in one second - const LONGLONG kMaxWaitTicks = timerFrequency.QuadPart / 10; - while (result == S_FALSE && (currentTime.QuadPart - startTime.QuadPart) < kMaxWaitTicks) + while (result == S_FALSE) { // Keep polling, but allow other threads to do something useful first ScheduleYield(); @@ -686,8 +675,6 @@ angle::Result Renderer9::finish(const gl::Context *context) freeEventQuery(query); } ANGLE_TRY_HR(context9, result, "Failed to get event query data"); - - QueryPerformanceCounter(¤tTime); } freeEventQuery(query); diff --git a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp index b7d373a93..e230ad296 100644 --- a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp +++ b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp @@ -138,8 +138,8 @@ void FramebufferVk::destroy(const gl::Context *context) RendererVk *renderer = contextVk->getRenderer(); mFramebuffer.release(renderer); - mReadPixelBuffer.destroy(contextVk->getDevice()); - mBlitPixelBuffer.destroy(contextVk->getDevice()); + mReadPixelBuffer.release(renderer); + mBlitPixelBuffer.release(renderer); } angle::Result FramebufferVk::discard(const gl::Context *context, diff --git a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp index e39b3410c..3748816f4 100644 --- a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp +++ b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp @@ -105,15 +105,16 @@ VertexArrayVk::~VertexArrayVk() void VertexArrayVk::destroy(const gl::Context *context) { - VkDevice device = vk::GetImpl(context)->getRenderer()->getDevice(); + RendererVk *renderer = vk::GetImpl(context)->getRenderer(); + for (vk::DynamicBuffer &buffer : mCurrentArrayBufferConversion) { - buffer.destroy(device); + buffer.release(renderer); } - mDynamicVertexData.destroy(device); - mDynamicIndexData.destroy(device); - mTranslatedByteIndexData.destroy(device); - mLineLoopHelper.destroy(device); + mDynamicVertexData.release(renderer); + mDynamicIndexData.release(renderer); + mTranslatedByteIndexData.release(renderer); + mLineLoopHelper.release(renderer); } angle::Result VertexArrayVk::streamIndexData(ContextVk *contextVk, diff --git a/src/libANGLE/renderer/vulkan/vk_helpers.cpp b/src/libANGLE/renderer/vulkan/vk_helpers.cpp index 0866cede0..fce2f6489 100644 --- a/src/libANGLE/renderer/vulkan/vk_helpers.cpp +++ b/src/libANGLE/renderer/vulkan/vk_helpers.cpp @@ -875,6 +875,11 @@ angle::Result LineLoopHelper::streamIndices(ContextVk *contextVk, return angle::Result::Continue(); } +void LineLoopHelper::release(RendererVk *renderer) +{ + mDynamicIndexBuffer.release(renderer); +} + void LineLoopHelper::destroy(VkDevice device) { mDynamicIndexBuffer.destroy(device); diff --git a/src/libANGLE/renderer/vulkan/vk_helpers.h b/src/libANGLE/renderer/vulkan/vk_helpers.h index 5e2f6c0fb..2950f3bb5 100644 --- a/src/libANGLE/renderer/vulkan/vk_helpers.h +++ b/src/libANGLE/renderer/vulkan/vk_helpers.h @@ -361,6 +361,7 @@ class LineLoopHelper final : angle::NonCopyable VkBuffer *bufferHandleOut, VkDeviceSize *bufferOffsetOut); + void release(RendererVk *renderer); void destroy(VkDevice device); static void Draw(uint32_t count, CommandBuffer *commandBuffer);