Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_manager_shader.c
| Show All 28 Lines | |||||
| #include "BLI_string_utils.h" | #include "BLI_string_utils.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "GPU_extensions.h" | |||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "draw_manager.h" | #include "draw_manager.h" | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| DRWShaderCompiler *comp = (DRWShaderCompiler *)custom_data; | DRWShaderCompiler *comp = (DRWShaderCompiler *)custom_data; | ||||
| void *gl_context = comp->gl_context; | void *gl_context = comp->gl_context; | ||||
| #if TRUST_NO_ONE | #if TRUST_NO_ONE | ||||
| BLI_assert(gl_context != NULL); | BLI_assert(gl_context != NULL); | ||||
| #endif | #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); | WM_opengl_context_activate(gl_context); | ||||
| while (true) { | while (true) { | ||||
| BLI_spin_lock(&comp->list_lock); | BLI_spin_lock(&comp->list_lock); | ||||
| if (*stop != 0) { | if (*stop != 0) { | ||||
| /* We don't want user to be able to cancel the compilation | /* We don't want user to be able to cancel the compilation | ||||
| * but wm can kill the task if we are closing blender. */ | * but wm can kill the task if we are closing blender. */ | ||||
| Show All 32 Lines | while (true) { | ||||
| else { | else { | ||||
| drw_deferred_shader_free(comp->mat_compiling); | drw_deferred_shader_free(comp->mat_compiling); | ||||
| } | } | ||||
| comp->mat_compiling = NULL; | comp->mat_compiling = NULL; | ||||
| BLI_spin_unlock(&comp->list_lock); | BLI_spin_unlock(&comp->list_lock); | ||||
| } | } | ||||
| WM_opengl_context_release(gl_context); | 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) | static void drw_deferred_shader_compilation_free(void *custom_data) | ||||
| { | { | ||||
| DRWShaderCompiler *comp = (DRWShaderCompiler *)custom_data; | DRWShaderCompiler *comp = (DRWShaderCompiler *)custom_data; | ||||
| drw_deferred_shader_queue_free(&comp->queue); | drw_deferred_shader_queue_free(&comp->queue); | ||||
| Show All 26 Lines | static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) | ||||
| if (DST.draw_ctx.evil_C == NULL || DRW_state_is_image_render() || !USE_DEFERRED_COMPILATION || | if (DST.draw_ctx.evil_C == NULL || DRW_state_is_image_render() || !USE_DEFERRED_COMPILATION || | ||||
| !deferred) { | !deferred) { | ||||
| /* Double checking that this GPUMaterial is not going to be | /* Double checking that this GPUMaterial is not going to be | ||||
| * compiled by another thread. */ | * compiled by another thread. */ | ||||
| DRW_deferred_shader_remove(mat); | DRW_deferred_shader_remove(mat); | ||||
| GPU_material_compile(mat); | GPU_material_compile(mat); | ||||
| return; | 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"); | DRWDeferredShader *dsh = MEM_callocN(sizeof(DRWDeferredShader), "Deferred Shader"); | ||||
| dsh->mat = mat; | dsh->mat = mat; | ||||
| BLI_assert(DST.draw_ctx.evil_C); | BLI_assert(DST.draw_ctx.evil_C); | ||||
| wmWindowManager *wm = CTX_wm_manager(DST.draw_ctx.evil_C); | wmWindowManager *wm = CTX_wm_manager(DST.draw_ctx.evil_C); | ||||
| wmWindow *win = CTX_wm_window(DST.draw_ctx.evil_C); | wmWindow *win = CTX_wm_window(DST.draw_ctx.evil_C); | ||||
| Show All 15 Lines | static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) | ||||
| if (old_comp) { | if (old_comp) { | ||||
| BLI_spin_lock(&old_comp->list_lock); | BLI_spin_lock(&old_comp->list_lock); | ||||
| BLI_movelisttolist(&comp->queue, &old_comp->queue); | BLI_movelisttolist(&comp->queue, &old_comp->queue); | ||||
| BLI_spin_unlock(&old_comp->list_lock); | BLI_spin_unlock(&old_comp->list_lock); | ||||
| /* Do not recreate context, just pass ownership. */ | /* Do not recreate context, just pass ownership. */ | ||||
| if (old_comp->gl_context) { | if (old_comp->gl_context) { | ||||
| comp->gl_context = old_comp->gl_context; | comp->gl_context = old_comp->gl_context; | ||||
| old_comp->own_context = false; | old_comp->own_context = false; | ||||
| comp->own_context = true; | comp->own_context = job_own_context; | ||||
| } | } | ||||
| } | } | ||||
| BLI_addtail(&comp->queue, dsh); | BLI_addtail(&comp->queue, dsh); | ||||
| /* Create only one context. */ | /* Create only one context. */ | ||||
| if (comp->gl_context == NULL) { | if (comp->gl_context == NULL) { | ||||
| if (use_main_context) { | |||||
| comp->gl_context = DST.gl_context; | |||||
| } | |||||
| else { | |||||
| comp->gl_context = WM_opengl_context_create(); | comp->gl_context = WM_opengl_context_create(); | ||||
| WM_opengl_context_activate(DST.gl_context); | WM_opengl_context_activate(DST.gl_context); | ||||
| comp->own_context = true; | } | ||||
| comp->own_context = job_own_context; | |||||
| } | } | ||||
| WM_jobs_customdata_set(wm_job, comp, drw_deferred_shader_compilation_free); | WM_jobs_customdata_set(wm_job, comp, drw_deferred_shader_compilation_free); | ||||
| WM_jobs_timer(wm_job, 0.1, NC_MATERIAL | ND_SHADING_DRAW, 0); | WM_jobs_timer(wm_job, 0.1, NC_MATERIAL | ND_SHADING_DRAW, 0); | ||||
| WM_jobs_delay_start(wm_job, 0.1); | WM_jobs_delay_start(wm_job, 0.1); | ||||
| WM_jobs_callbacks(wm_job, drw_deferred_shader_compilation_exec, NULL, NULL, NULL); | WM_jobs_callbacks(wm_job, drw_deferred_shader_compilation_exec, NULL, NULL, NULL); | ||||
| G.is_break = false; | G.is_break = false; | ||||
| ▲ Show 20 Lines • Show All 393 Lines • Show Last 20 Lines | |||||