Browse Source

libobs: Enable fast clear on Windows always

NVIDIA driver 527.37 fixes flickering when multiple GPUs are installed.
jpark37 3 years ago
parent
commit
c2afa58125
2 changed files with 21 additions and 25 deletions
  1. 21 24
      libobs/obs-display.c
  2. 0 1
      libobs/obs-internal.h

+ 21 - 24
libobs/obs-display.c

@@ -19,22 +19,19 @@
 #include "obs.h"
 #include "obs.h"
 #include "obs-internal.h"
 #include "obs-internal.h"
 
 
+#if defined(__APPLE__)
+/* Apple Silicon GL driver doesn't seem to track SRGB clears correctly */
+#define OBS_USE_CLEAR_WORKAROUND 1
+#else
+#define OBS_USE_CLEAR_WORKAROUND 0
+#endif
+
 bool obs_display_init(struct obs_display *display,
 bool obs_display_init(struct obs_display *display,
 		      const struct gs_init_data *graphics_data)
 		      const struct gs_init_data *graphics_data)
 {
 {
 	pthread_mutex_init_value(&display->draw_callbacks_mutex);
 	pthread_mutex_init_value(&display->draw_callbacks_mutex);
 	pthread_mutex_init_value(&display->draw_info_mutex);
 	pthread_mutex_init_value(&display->draw_info_mutex);
 
 
-#if defined(_WIN32)
-	/* Conservative test for NVIDIA flickering in multi-GPU setups */
-	display->use_clear_workaround = gs_get_adapter_count() > 1;
-#elif defined(__APPLE__)
-	/* Apple Silicon GL driver doesn't seem to track SRGB clears correctly */
-	display->use_clear_workaround = true;
-#else
-	display->use_clear_workaround = false;
-#endif
-
 	if (graphics_data) {
 	if (graphics_data) {
 		display->swap = gs_swapchain_create(graphics_data);
 		display->swap = gs_swapchain_create(graphics_data);
 		if (!display->swap) {
 		if (!display->swap) {
@@ -203,11 +200,12 @@ static inline bool render_display_begin(struct obs_display *display,
 					    display->background_color);
 					    display->background_color);
 		clear_color.w = 1.0f;
 		clear_color.w = 1.0f;
 
 
-		const bool use_clear_workaround = display->use_clear_workaround;
-
-		uint32_t clear_flags = GS_CLEAR_DEPTH | GS_CLEAR_STENCIL;
-		if (!use_clear_workaround)
-			clear_flags |= GS_CLEAR_COLOR;
+#if OBS_USE_CLEAR_WORKAROUND
+		const uint32_t clear_flags = GS_CLEAR_DEPTH | GS_CLEAR_STENCIL;
+#else
+		const uint32_t clear_flags = GS_CLEAR_COLOR | GS_CLEAR_DEPTH |
+					     GS_CLEAR_STENCIL;
+#endif
 		gs_clear(clear_flags, &clear_color, 1.0f, 0);
 		gs_clear(clear_flags, &clear_color, 1.0f, 0);
 
 
 		gs_enable_depth_test(false);
 		gs_enable_depth_test(false);
@@ -217,15 +215,14 @@ static inline bool render_display_begin(struct obs_display *display,
 		gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
 		gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
 		gs_set_viewport(0, 0, cx, cy);
 		gs_set_viewport(0, 0, cx, cy);
 
 
-		if (use_clear_workaround) {
-			gs_effect_t *const solid_effect =
-				obs->video.solid_effect;
-			gs_effect_set_vec4(gs_effect_get_param_by_name(
-						   solid_effect, "color"),
-					   &clear_color);
-			while (gs_effect_loop(solid_effect, "Solid"))
-				gs_draw_sprite(NULL, 0, cx, cy);
-		}
+#if OBS_USE_CLEAR_WORKAROUND
+		gs_effect_t *const solid_effect = obs->video.solid_effect;
+		gs_effect_set_vec4(gs_effect_get_param_by_name(solid_effect,
+							       "color"),
+				   &clear_color);
+		while (gs_effect_loop(solid_effect, "Solid"))
+			gs_draw_sprite(NULL, 0, cx, cy);
+#endif
 	}
 	}
 
 
 	return success;
 	return success;

+ 0 - 1
libobs/obs-internal.h

@@ -224,7 +224,6 @@ struct obs_display {
 	pthread_mutex_t draw_callbacks_mutex;
 	pthread_mutex_t draw_callbacks_mutex;
 	pthread_mutex_t draw_info_mutex;
 	pthread_mutex_t draw_info_mutex;
 	DARRAY(struct draw_callback) draw_callbacks;
 	DARRAY(struct draw_callback) draw_callbacks;
-	bool use_clear_workaround;
 
 
 	struct obs_display *next;
 	struct obs_display *next;
 	struct obs_display **prev_next;
 	struct obs_display **prev_next;