From 54449966dd2eaa9a04449855f67af4bb29d52239 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Fri, 15 Jan 2021 16:35:49 +0000 Subject: [PATCH] Workaround ANGLE hang with a glFlush(). Change-Id: Idce1b71bdb132a1b96836d270eb2ab53fd0086f8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/36700 Commit-Queue: Stephen White Reviewed-by: Austin Eng --- src/dawn_native/Toggles.cpp | 4 ++++ src/dawn_native/Toggles.h | 1 + src/dawn_native/opengl/DeviceGL.cpp | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp index bc4d55b047..034eabf128 100644 --- a/src/dawn_native/Toggles.cpp +++ b/src/dawn_native/Toggles.cpp @@ -152,6 +152,10 @@ namespace dawn_native { {Toggle::UseTintInspector, {"use_tint_inspector", "Use Tint instead of SPRIV-cross for shader reflection.", "https://crbug.com/dawn/578"}}, + {Toggle::FlushBeforeClientWaitSync, + {"flush_before_client_wait_sync", + "Call glFlush before glClientWaitSync to work around bugs in the latter", + "https://crbug.com/dawn/633"}}, // Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle. }}; diff --git a/src/dawn_native/Toggles.h b/src/dawn_native/Toggles.h index d2f70608e3..2ecf5e0785 100644 --- a/src/dawn_native/Toggles.h +++ b/src/dawn_native/Toggles.h @@ -47,6 +47,7 @@ namespace dawn_native { DisallowUnsafeAPIs, UseTintGenerator, UseTintInspector, + FlushBeforeClientWaitSync, EnumCount, InvalidEnum = EnumCount, diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp index 1d81932bda..bc64d4549f 100644 --- a/src/dawn_native/opengl/DeviceGL.cpp +++ b/src/dawn_native/opengl/DeviceGL.cpp @@ -86,6 +86,7 @@ namespace dawn_native { namespace opengl { SetToggle(Toggle::DisableBaseVertex, !supportsBaseVertex); SetToggle(Toggle::DisableBaseInstance, !supportsBaseInstance); SetToggle(Toggle::DisableIndexedDrawBuffers, !supportsIndexedDrawBuffers); + SetToggle(Toggle::FlushBeforeClientWaitSync, gl.GetVersion().IsES()); } const GLFormat& Device::GetGLFormat(const Format& format) { @@ -173,6 +174,11 @@ namespace dawn_native { namespace opengl { // Fence are added in order, so we can stop searching as soon // as we see one that's not ready. + + // TODO(crbug.com/dawn/633): Remove this workaround after the deadlock issue is fixed. + if (IsToggleEnabled(Toggle::FlushBeforeClientWaitSync)) { + gl.Flush(); + } GLenum result = gl.ClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 0); if (result == GL_TIMEOUT_EXPIRED) { return fenceSerial;