diff options
author | Jeroen Bakker <jbakker> | 2020-08-05 16:26:49 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-08-05 16:45:42 +0300 |
commit | f7d38e2e6426a21f4b91bedc0fe635aba4692ff2 (patch) | |
tree | c3d240bcb10b992b41826d876dc1a3016dabe632 /source/blender/draw/intern/draw_manager_shader.c | |
parent | 56d7e39b92997768b3db8ce2dbc262f869994145 (diff) |
Fix T77346: GPU Workaround Always Render Using Main Context
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
Diffstat (limited to 'source/blender/draw/intern/draw_manager_shader.c')
-rw-r--r-- | source/blender/draw/intern/draw_manager_shader.c | 25 |
1 files changed, 21 insertions, 4 deletions
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); |