Commit fca8fd62 by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Refix cleanup race condition on Context destroy

This partially reverts commit 905ee082 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/1333969Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 092481ad
...@@ -545,10 +545,6 @@ void Context::initialize() ...@@ -545,10 +545,6 @@ void Context::initialize()
egl::Error Context::onDestroy(const egl::Display *display) 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) if (mGLES1Renderer)
{ {
mGLES1Renderer->onDestroy(this, &mGLState); mGLES1Renderer->onDestroy(this, &mGLState);
......
...@@ -1203,12 +1203,6 @@ angle::Result Renderer11::flush(Context11 *context11) ...@@ -1203,12 +1203,6 @@ angle::Result Renderer11::flush(Context11 *context11)
angle::Result Renderer11::finish(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()) if (!mSyncQuery.valid())
{ {
D3D11_QUERY_DESC queryDesc; D3D11_QUERY_DESC queryDesc;
......
...@@ -648,20 +648,9 @@ angle::Result Renderer9::finish(const gl::Context *context) ...@@ -648,20 +648,9 @@ angle::Result Renderer9::finish(const gl::Context *context)
} }
ANGLE_TRY_HR(context9, result, "Failed to get event query data"); 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 // Loop until the query completes
// false, so we loop for a maximum of 100ms.
unsigned int attempt = 0; unsigned int attempt = 0;
while (result == S_FALSE)
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)
{ {
// Keep polling, but allow other threads to do something useful first // Keep polling, but allow other threads to do something useful first
ScheduleYield(); ScheduleYield();
...@@ -686,8 +675,6 @@ angle::Result Renderer9::finish(const gl::Context *context) ...@@ -686,8 +675,6 @@ angle::Result Renderer9::finish(const gl::Context *context)
freeEventQuery(query); freeEventQuery(query);
} }
ANGLE_TRY_HR(context9, result, "Failed to get event query data"); ANGLE_TRY_HR(context9, result, "Failed to get event query data");
QueryPerformanceCounter(&currentTime);
} }
freeEventQuery(query); freeEventQuery(query);
......
...@@ -138,8 +138,8 @@ void FramebufferVk::destroy(const gl::Context *context) ...@@ -138,8 +138,8 @@ void FramebufferVk::destroy(const gl::Context *context)
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
mFramebuffer.release(renderer); mFramebuffer.release(renderer);
mReadPixelBuffer.destroy(contextVk->getDevice()); mReadPixelBuffer.release(renderer);
mBlitPixelBuffer.destroy(contextVk->getDevice()); mBlitPixelBuffer.release(renderer);
} }
angle::Result FramebufferVk::discard(const gl::Context *context, angle::Result FramebufferVk::discard(const gl::Context *context,
......
...@@ -105,15 +105,16 @@ VertexArrayVk::~VertexArrayVk() ...@@ -105,15 +105,16 @@ VertexArrayVk::~VertexArrayVk()
void VertexArrayVk::destroy(const gl::Context *context) 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) for (vk::DynamicBuffer &buffer : mCurrentArrayBufferConversion)
{ {
buffer.destroy(device); buffer.release(renderer);
} }
mDynamicVertexData.destroy(device); mDynamicVertexData.release(renderer);
mDynamicIndexData.destroy(device); mDynamicIndexData.release(renderer);
mTranslatedByteIndexData.destroy(device); mTranslatedByteIndexData.release(renderer);
mLineLoopHelper.destroy(device); mLineLoopHelper.release(renderer);
} }
angle::Result VertexArrayVk::streamIndexData(ContextVk *contextVk, angle::Result VertexArrayVk::streamIndexData(ContextVk *contextVk,
......
...@@ -875,6 +875,11 @@ angle::Result LineLoopHelper::streamIndices(ContextVk *contextVk, ...@@ -875,6 +875,11 @@ angle::Result LineLoopHelper::streamIndices(ContextVk *contextVk,
return angle::Result::Continue(); return angle::Result::Continue();
} }
void LineLoopHelper::release(RendererVk *renderer)
{
mDynamicIndexBuffer.release(renderer);
}
void LineLoopHelper::destroy(VkDevice device) void LineLoopHelper::destroy(VkDevice device)
{ {
mDynamicIndexBuffer.destroy(device); mDynamicIndexBuffer.destroy(device);
......
...@@ -361,6 +361,7 @@ class LineLoopHelper final : angle::NonCopyable ...@@ -361,6 +361,7 @@ class LineLoopHelper final : angle::NonCopyable
VkBuffer *bufferHandleOut, VkBuffer *bufferHandleOut,
VkDeviceSize *bufferOffsetOut); VkDeviceSize *bufferOffsetOut);
void release(RendererVk *renderer);
void destroy(VkDevice device); void destroy(VkDevice device);
static void Draw(uint32_t count, CommandBuffer *commandBuffer); static void Draw(uint32_t count, CommandBuffer *commandBuffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment