From f7d38e2e6426a21f4b91bedc0fe635aba4692ff2 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 5 Aug 2020 15:26:49 +0200 Subject: Fix T77346: GPU Workaround Always Render Using Main Context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Blender 2.90 EEVEE materials were refactored that introduced crashes on Intel GPUs on Windows. The crash happened in the `local_context_workaround` that temporary stored compiled materials in a binary form to reload it in the main GL context. It has been tested that the workaround isn't needed anymore for HD6xx GPUs, but it is still needed for HD4000. After several unsuccesfull fixes we came to the conclusion that we could not support the local context workaround and needed to come with a different workaround. The idea of this patch is that in these cases there is only a single context that is used for rendering. Threads that uses these contextes are guarded by a mutex and will block. Impact on User Level: * Due to main mutex lock the UI freezes when rendering or baking or feel less snappy Reviewed By: Clément Foucault, Brecht van Lommel Differential Revision: https://developer.blender.org/D8410 --- source/blender/draw/intern/draw_manager.c | 12 ++++++++++++ source/blender/draw/intern/draw_manager_shader.c | 25 ++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'source/blender/draw/intern') diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index cea5dea6029..70c117d55b4 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2719,6 +2719,12 @@ void DRW_render_context_enable(Render *render) WM_init_opengl(G_MAIN); } + if (GPU_use_main_context_workaround()) { + GPU_context_main_lock(); + DRW_opengl_context_enable(); + return; + } + void *re_gl_context = RE_gl_context_get(render); /* Changing Context */ @@ -2736,6 +2742,12 @@ void DRW_render_context_enable(Render *render) void DRW_render_context_disable(Render *render) { + if (GPU_use_main_context_workaround()) { + DRW_opengl_context_disable(); + GPU_context_main_unlock(); + return; + } + void *re_gl_context = RE_gl_context_get(render); if (re_gl_context != NULL) { diff --git a/source/blender/draw/intern/draw_manager_shader.c b/source/blender/draw/intern/draw_manager_shader.c index 0bb20631537..34069438e47 100644 --- a/source/blender/draw/intern/draw_manager_shader.c +++ b/source/blender/draw/intern/draw_manager_shader.c @@ -34,6 +34,7 @@ #include "DEG_depsgraph_query.h" +#include "GPU_extensions.h" #include "GPU_material.h" #include "GPU_shader.h" @@ -106,6 +107,12 @@ static void drw_deferred_shader_compilation_exec( BLI_assert(gl_context != NULL); #endif + const bool use_main_context_workaround = GPU_use_main_context_workaround(); + if (use_main_context_workaround) { + BLI_assert(gl_context == DST.gl_context); + GPU_context_main_lock(); + } + WM_opengl_context_activate(gl_context); while (true) { @@ -154,6 +161,9 @@ static void drw_deferred_shader_compilation_exec( } WM_opengl_context_release(gl_context); + if (use_main_context_workaround) { + GPU_context_main_unlock(); + } } static void drw_deferred_shader_compilation_free(void *custom_data) @@ -196,6 +206,8 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) GPU_material_compile(mat); return; } + const bool use_main_context = GPU_use_main_context_workaround(); + const bool job_own_context = !use_main_context; DRWDeferredShader *dsh = MEM_callocN(sizeof(DRWDeferredShader), "Deferred Shader"); @@ -227,7 +239,7 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) if (old_comp->gl_context) { comp->gl_context = old_comp->gl_context; old_comp->own_context = false; - comp->own_context = true; + comp->own_context = job_own_context; } } @@ -235,9 +247,14 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) /* Create only one context. */ if (comp->gl_context == NULL) { - comp->gl_context = WM_opengl_context_create(); - WM_opengl_context_activate(DST.gl_context); - comp->own_context = true; + if (use_main_context) { + comp->gl_context = DST.gl_context; + } + else { + comp->gl_context = WM_opengl_context_create(); + WM_opengl_context_activate(DST.gl_context); + } + comp->own_context = job_own_context; } WM_jobs_customdata_set(wm_job, comp, drw_deferred_shader_compilation_free); -- cgit v1.2.3