Blender
V3.3
|
#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "DNA_world_types.h"
#include "PIL_time.h"
#include "BLI_dynstr.h"
#include "BLI_listbase.h"
#include "BLI_string_utils.h"
#include "BLI_threads.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "DEG_depsgraph_query.h"
#include "GPU_capabilities.h"
#include "GPU_material.h"
#include "GPU_shader.h"
#include "WM_api.h"
#include "WM_types.h"
#include "wm_window.h"
#include "draw_manager.h"
#include "CLG_log.h"
Go to the source code of this file.
Classes | |
struct | DRWShaderCompiler |
struct | DRWShaderLibrary |
Macros | |
#define | USE_DEFERRED_COMPILATION 1 |
Variables | |
static CLG_LogRef | LOG = {"draw.manager.shader"} |
char | datatoc_gpu_shader_depth_only_frag_glsl [] |
char | datatoc_common_fullscreen_vert_glsl [] |
Shader Library | |
Simple include system for glsl files. Usage: Create a DRWShaderLibrary and add the library in the right order. You can have nested dependencies but each new library needs to have all its dependencies already added to the DRWShaderLibrary. Finally you can use DRW_shader_library_create_shader_string to get a shader string that also contains the needed libraries for this shader. | |
#define | MAX_LIB 64 |
#define | MAX_LIB_NAME 64 |
#define | MAX_LIB_DEPS 8 |
DRWShaderLibrary * | DRW_shader_library_create (void) |
void | DRW_shader_library_free (DRWShaderLibrary *lib) |
static int | drw_shader_library_search (const DRWShaderLibrary *lib, const char *name) |
static uint64_t | drw_shader_dependencies_get (const DRWShaderLibrary *lib, const char *pragma_str, const char *lib_code, const char *UNUSED(lib_name)) |
void | DRW_shader_library_add_file (DRWShaderLibrary *lib, const char *lib_code, const char *lib_name) |
char * | DRW_shader_library_create_shader_string (const DRWShaderLibrary *lib, const char *shader_code) |
Deferred Compilation (DRW_deferred) | |
typedef struct DRWShaderCompiler | DRWShaderCompiler |
static void | drw_deferred_shader_compilation_exec (void *custom_data, short *stop, short *UNUSED(do_update), float *UNUSED(progress)) |
static void | drw_deferred_shader_compilation_free (void *custom_data) |
static void | drw_deferred_shader_add (GPUMaterial *mat, bool deferred) |
void | DRW_deferred_shader_remove (GPUMaterial *mat) |
GPUShader * | DRW_shader_create_ex (const char *vert, const char *geom, const char *frag, const char *defines, const char *name) |
GPUShader * | DRW_shader_create_with_lib_ex (const char *vert, const char *geom, const char *frag, const char *lib, const char *defines, const char *name) |
GPUShader * | DRW_shader_create_with_shaderlib_ex (const char *vert, const char *geom, const char *frag, const DRWShaderLibrary *lib, const char *defines, const char *name) |
GPUShader * | DRW_shader_create_with_transform_feedback (const char *vert, const char *geom, const char *defines, const eGPUShaderTFBType prim_type, const char **varying_names, const int varying_count) |
GPUShader * | DRW_shader_create_fullscreen_ex (const char *frag, const char *defines, const char *name) |
GPUShader * | DRW_shader_create_fullscreen_with_shaderlib_ex (const char *frag, const DRWShaderLibrary *lib, const char *defines, const char *name) |
GPUMaterial * | DRW_shader_from_world (World *wo, struct bNodeTree *ntree, const uint64_t shader_id, const bool is_volume_shader, bool deferred, GPUCodegenCallbackFn callback, void *thunk) |
GPUMaterial * | DRW_shader_from_material (Material *ma, struct bNodeTree *ntree, const uint64_t shader_id, const bool is_volume_shader, bool deferred, GPUCodegenCallbackFn callback, void *thunk) |
void | DRW_shader_free (GPUShader *shader) |
#define MAX_LIB 64 |
Definition at line 439 of file draw_manager_shader.c.
#define MAX_LIB_DEPS 8 |
Definition at line 441 of file draw_manager_shader.c.
#define MAX_LIB_NAME 64 |
Definition at line 440 of file draw_manager_shader.c.
#define USE_DEFERRED_COMPILATION 1 |
Definition at line 43 of file draw_manager_shader.c.
typedef struct DRWShaderCompiler DRWShaderCompiler |
|
static |
Definition at line 149 of file draw_manager_shader.c.
References BLI_addtail(), BLI_assert, BLI_genericNodeN(), BLI_movelisttolist(), BLI_spin_init(), BLI_spin_lock(), BLI_spin_unlock(), CTX_wm_manager(), CTX_wm_window(), DRWManager::draw_ctx, drw_deferred_shader_compilation_exec(), drw_deferred_shader_compilation_free(), DRW_deferred_shader_remove(), DRW_state_is_image_render(), DST, ELEM, DRWContextState::evil_C, G, DRWManager::gl_context, DRWShaderCompiler::gl_context, DRWManager::gpu_context, DRWShaderCompiler::gpu_context, GPU_context_active_set(), GPU_context_create(), GPU_MAT_CREATED, GPU_MAT_FAILED, GPU_MAT_QUEUED, GPU_MAT_SUCCESS, GPU_material_compile(), GPU_material_status(), GPU_material_status_set(), GPU_use_main_context_workaround(), DRWShaderCompiler::list_lock, MEM_callocN, NC_MATERIAL, ND_SHADING_DRAW, node, NULL, DRWShaderCompiler::own_context, PIL_sleep_ms(), DRWShaderCompiler::queue, USE_DEFERRED_COMPILATION, WM_JOB_TYPE_SHADER_COMPILATION, WM_jobs_callbacks(), WM_jobs_customdata_get(), WM_jobs_customdata_set(), WM_jobs_delay_start(), WM_jobs_get(), WM_jobs_start(), WM_jobs_timer(), WM_opengl_context_activate(), and WM_opengl_context_create().
Referenced by DRW_shader_from_material(), and DRW_shader_from_world().
|
static |
Definition at line 62 of file draw_manager_shader.c.
References BLI_assert, BLI_poptail(), BLI_spin_lock(), BLI_spin_unlock(), LinkData::data, DST, DRWManager::gl_context, DRWShaderCompiler::gl_context, GPU_BACKEND_OPENGL, DRWShaderCompiler::gpu_context, GPU_context_active_set(), GPU_context_main_lock(), GPU_context_main_unlock(), GPU_DEVICE_ANY, GPU_DRIVER_ANY, GPU_flush(), GPU_material_acquire(), GPU_material_compile(), GPU_material_release(), GPU_OS_ANY, GPU_render_begin(), GPU_render_end(), GPU_type_matches_ex(), GPU_use_main_context_workaround(), if(), DRWShaderCompiler::list_lock, MEM_freeN, NULL, DRWShaderCompiler::queue, WM_opengl_context_activate(), and WM_opengl_context_release().
Referenced by drw_deferred_shader_add().
Definition at line 128 of file draw_manager_shader.c.
References BLI_freelistN(), BLI_spin_lock(), BLI_spin_unlock(), DRWShaderCompiler::gl_context, DRWShaderCompiler::gpu_context, GPU_context_active_set(), GPU_context_discard(), DRWShaderCompiler::list_lock, MEM_freeN, DRWShaderCompiler::own_context, DRWShaderCompiler::queue, WM_opengl_context_activate(), WM_opengl_context_dispose(), and wm_window_reset_drawable().
Referenced by drw_deferred_shader_add().
void DRW_deferred_shader_remove | ( | GPUMaterial * | mat | ) |
Definition at line 238 of file draw_manager_shader.c.
References BLI_findptr(), BLI_remlink(), BLI_spin_lock(), BLI_spin_unlock(), data, LinkData::data, G_MAIN, GPU_MAT_CREATED, GPU_material_status_set(), DRWShaderCompiler::list_lock, LISTBASE_FOREACH, MEM_SAFE_FREE, NULL, DRWShaderCompiler::queue, WM_JOB_TYPE_SHADER_COMPILATION, and WM_jobs_customdata_from_type().
Referenced by drw_deferred_shader_add().
GPUShader* DRW_shader_create_ex | ( | const char * | vert, |
const char * | geom, | ||
const char * | frag, | ||
const char * | defines, | ||
const char * | name | ||
) |
Definition at line 265 of file draw_manager_shader.c.
References GPU_shader_create(), and NULL.
GPUShader* DRW_shader_create_fullscreen_ex | ( | const char * | frag, |
const char * | defines, | ||
const char * | name | ||
) |
Definition at line 340 of file draw_manager_shader.c.
References datatoc_common_fullscreen_vert_glsl, GPU_shader_create(), and NULL.
GPUShader* DRW_shader_create_fullscreen_with_shaderlib_ex | ( | const char * | frag, |
const DRWShaderLibrary * | lib, | ||
const char * | defines, | ||
const char * | name | ||
) |
Definition at line 345 of file draw_manager_shader.c.
References datatoc_common_fullscreen_vert_glsl, DRW_shader_library_create_shader_string(), GPU_shader_create(), lib, MEM_SAFE_FREE, NULL, and sh.
GPUShader* DRW_shader_create_with_lib_ex | ( | const char * | vert, |
const char * | geom, | ||
const char * | frag, | ||
const char * | lib, | ||
const char * | defines, | ||
const char * | name | ||
) |
Definition at line 271 of file draw_manager_shader.c.
References BLI_string_joinN, GPU_shader_create(), lib, MEM_freeN, NULL, and sh.
GPUShader* DRW_shader_create_with_shaderlib_ex | ( | const char * | vert, |
const char * | geom, | ||
const char * | frag, | ||
const DRWShaderLibrary * | lib, | ||
const char * | defines, | ||
const char * | name | ||
) |
Definition at line 300 of file draw_manager_shader.c.
References DRW_shader_library_create_shader_string(), GPU_shader_create(), lib, MEM_SAFE_FREE, NULL, and sh.
GPUShader* DRW_shader_create_with_transform_feedback | ( | const char * | vert, |
const char * | geom, | ||
const char * | defines, | ||
const eGPUShaderTFBType | prim_type, | ||
const char ** | varying_names, | ||
const int | varying_count | ||
) |
Definition at line 321 of file draw_manager_shader.c.
References datatoc_gpu_shader_depth_only_frag_glsl, GPU_shader_create_ex(), and NULL.
Referenced by hair_refine_shader_transform_feedback_create().
|
static |
Definition at line 475 of file draw_manager_shader.c.
References CLOG_INFO, drw_shader_library_search(), lib, LOG, and MAX_NAME.
Referenced by DRW_shader_library_add_file(), and DRW_shader_library_create_shader_string().
Definition at line 419 of file draw_manager_shader.c.
References GPU_shader_free().
GPUMaterial* DRW_shader_from_material | ( | Material * | ma, |
struct bNodeTree * | ntree, | ||
const uint64_t | shader_id, | ||
const bool | is_volume_shader, | ||
bool | deferred, | ||
GPUCodegenCallbackFn | callback, | ||
void * | thunk | ||
) |
Definition at line 390 of file draw_manager_shader.c.
References callback, DEG_get_original_id(), DRWManager::draw_ctx, drw_deferred_shader_add(), DRW_state_is_image_render(), DST, GPU_material_from_nodetree(), Material::gpumaterial, Material::id, Scene::id, ID::name, ntree, scene, and DRWContextState::scene.
Referenced by eevee_material_get_ex(), and blender::eevee::ShaderModule::material_shader_get().
GPUMaterial* DRW_shader_from_world | ( | World * | wo, |
struct bNodeTree * | ntree, | ||
const uint64_t | shader_id, | ||
const bool | is_volume_shader, | ||
bool | deferred, | ||
GPUCodegenCallbackFn | callback, | ||
void * | thunk | ||
) |
Definition at line 362 of file draw_manager_shader.c.
References callback, DEG_get_original_id(), DRWManager::draw_ctx, drw_deferred_shader_add(), DRW_state_is_image_render(), DST, GPU_material_from_nodetree(), World::gpumaterial, Scene::id, World::id, ID::name, ntree, NULL, scene, and DRWContextState::scene.
Referenced by eevee_material_get_ex(), and blender::eevee::ShaderModule::world_shader_get().
void DRW_shader_library_add_file | ( | DRWShaderLibrary * | lib, |
const char * | lib_code, | ||
const char * | lib_name | ||
) |
Definition at line 510 of file draw_manager_shader.c.
References BLI_assert, BLI_strncpy(), drw_shader_dependencies_get(), lib, DRWShaderLibrary::libs, DRWShaderLibrary::libs_deps, DRWShaderLibrary::libs_name, MAX_LIB, MAX_LIB_NAME, and NULL.
DRWShaderLibrary* DRW_shader_library_create | ( | void | ) |
Definition at line 449 of file draw_manager_shader.c.
References MEM_callocN.
Referenced by eevee_shader_library_ensure().
char* DRW_shader_library_create_shader_string | ( | const DRWShaderLibrary * | lib, |
const char * | shader_code | ||
) |
Definition at line 532 of file draw_manager_shader.c.
References BLI_dynstr_append(), BLI_dynstr_free(), BLI_dynstr_get_cstring(), BLI_dynstr_new(), drw_shader_dependencies_get(), lib, DRWShaderLibrary::libs, DRWShaderLibrary::libs_deps, MAX_LIB, and str.
Referenced by DRW_shader_create_fullscreen_with_shaderlib_ex(), DRW_shader_create_with_shaderlib_ex(), eevee_get_frag(), eevee_get_geom(), eevee_get_vert(), and eevee_shader_library_ensure().
void DRW_shader_library_free | ( | DRWShaderLibrary * | lib | ) |
Definition at line 454 of file draw_manager_shader.c.
References lib, and MEM_SAFE_FREE.
|
static |
Definition at line 459 of file draw_manager_shader.c.
References lib, DRWShaderLibrary::libs, DRWShaderLibrary::libs_name, and MAX_LIB.
Referenced by drw_shader_dependencies_get().
|
extern |
Referenced by DRW_shader_create_fullscreen_ex(), and DRW_shader_create_fullscreen_with_shaderlib_ex().
|
extern |
Referenced by DRW_shader_create_with_transform_feedback().
|
static |
Definition at line 38 of file draw_manager_shader.c.
Referenced by drw_shader_dependencies_get().