From 01649b68b98b990383cbcb52e79d21b7774290f4 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Tue, 8 Feb 2022 08:32:33 +0000 Subject: [PATCH] backend: don't trust device_status after a reset Signed-off-by: Yuxuan Shui --- src/backend/backend.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/backend/backend.c b/src/backend/backend.c index 6ea9446..293a86b 100644 --- a/src/backend/backend.c +++ b/src/backend/backend.c @@ -56,10 +56,22 @@ region_t get_damage(session_t *ps, bool all_damage) { void handle_device_reset(session_t *ps) { log_error("Device reset detected"); // Wait for reset to complete - while (ps->backend_data->ops->device_status(ps->backend_data) != DEVICE_STATUS_NORMAL) { - log_error("Device is resetting..."); - sleep(1); - } + // Although ideally the backend should return DEVICE_STATUS_NORMAL after a reset + // is completed, it's not always possible. + // + // According to ARB_robustness (emphasis mine): + // + // "If a reset status other than NO_ERROR is returned and subsequent + // calls return NO_ERROR, the context reset was encountered and + // completed. If a reset status is repeatedly returned, the context **may** + // be in the process of resetting." + // + // Which means it may also not be in the process of resetting. For example on + // AMDGPU devices, Mesa OpenGL always return CONTEXT_RESET after a reset has + // started, completed or not. + // + // So here we blindly wait 5 seconds and hope ourselves best of the luck. + sleep(5); // Reset picom log_info("Resetting picom after device reset");