diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-08-02 19:31:38 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-08-02 19:33:49 +0300 |
commit | 8f6ff3adfae7b7f14e0bab293efd0c8231982c89 (patch) | |
tree | d37d2abd17a8b324cc5bbc6a1c73cb5c81a4aa3d /source/blender/gpu/intern | |
parent | 3578212e462d2a67f49d64ce5fb64df43200654f (diff) |
GPUShader: Add name for debugging & identifying shaders.
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_basic_shader.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 5 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 19 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.c | 20 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_private.h | 3 |
6 files changed, 42 insertions, 10 deletions
diff --git a/source/blender/gpu/intern/gpu_basic_shader.c b/source/blender/gpu/intern/gpu_basic_shader.c index 61e8cf87038..1b7b1ecf85a 100644 --- a/source/blender/gpu/intern/gpu_basic_shader.c +++ b/source/blender/gpu/intern/gpu_basic_shader.c @@ -243,7 +243,8 @@ static GPUShader *gpu_basic_shader(int options) datatoc_gpu_shader_basic_frag_glsl, geom_glsl, NULL, - defines); + defines, + __func__); if (shader) { /* set texture map to first texture unit */ diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 3b9d2e08769..c6cf0c55594 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -1993,7 +1993,7 @@ GPUPass *GPU_generate_pass_new( return pass; } -void GPU_pass_compile(GPUPass *pass) +void GPU_pass_compile(GPUPass *pass, const char *shname) { if (!pass->compiled) { pass->shader = GPU_shader_create( @@ -2001,7 +2001,8 @@ void GPU_pass_compile(GPUPass *pass) pass->fragmentcode, pass->geometrycode, NULL, - pass->defines); + pass->defines, + shname); pass->compiled = true; } } diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h index 278843fc948..4af87c6a226 100644 --- a/source/blender/gpu/intern/gpu_codegen.h +++ b/source/blender/gpu/intern/gpu_codegen.h @@ -184,7 +184,7 @@ void GPU_nodes_extract_dynamic_inputs(struct GPUShader *shader, ListBase *inputs void GPU_nodes_get_vertex_attributes(ListBase *nodes, struct GPUVertexAttribs *attribs); void GPU_nodes_prune(ListBase *nodes, struct GPUNodeLink *outlink); -void GPU_pass_compile(GPUPass *pass); +void GPU_pass_compile(GPUPass *pass, const char *shname); void GPU_pass_release(GPUPass *pass); void GPU_pass_free_nodes(ListBase *nodes); diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 5e0d9275aa2..9859f56c1db 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -43,6 +43,7 @@ #include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_main.h" #include "BKE_node.h" @@ -120,6 +121,10 @@ struct GPUMaterial { short int sss_falloff; float sss_sharpness; bool sss_dirty; + +#ifndef NDEBUG + char name[64]; +#endif }; enum { @@ -581,7 +586,7 @@ GPUMaterial *GPU_material_from_nodetree_find( */ GPUMaterial *GPU_material_from_nodetree( Scene *scene, struct bNodeTree *ntree, ListBase *gpumaterials, const void *engine_type, int options, - const char *vert_code, const char *geom_code, const char *frag_lib, const char *defines) + const char *vert_code, const char *geom_code, const char *frag_lib, const char *defines, const char *name) { LinkData *link; bool has_volume_output, has_surface_output; @@ -594,6 +599,11 @@ GPUMaterial *GPU_material_from_nodetree( mat->scene = scene; mat->engine_type = engine_type; mat->options = options; +#ifndef NDEBUG + BLI_snprintf(mat->name, sizeof(mat->name), "%s", name); +#else + UNUSED_VARS(name); +#endif /* localize tree to create links for reroute and mute */ bNodeTree *localtree = ntreeLocalize(ntree); @@ -666,7 +676,12 @@ void GPU_material_compile(GPUMaterial *mat) /* NOTE: The shader may have already been compiled here since we are * sharing GPUShader across GPUMaterials. In this case it's a no-op. */ - GPU_pass_compile(mat->pass); +#ifndef NDEBUG + GPU_pass_compile(mat->pass, mat->name); +#else + GPU_pass_compile(mat->pass, __func__); +#endif + GPUShader *sh = GPU_pass_shader_get(mat->pass); if (sh != NULL) { diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c index 5346d3f1aee..3a6ad04b69a 100644 --- a/source/blender/gpu/intern/gpu_shader.c +++ b/source/blender/gpu/intern/gpu_shader.c @@ -31,6 +31,7 @@ #include "BLI_math_base.h" #include "BLI_math_vector.h" #include "BLI_path_util.h" +#include "BLI_string.h" #include "BKE_appdir.h" #include "BKE_global.h" @@ -172,6 +173,8 @@ extern char datatoc_gpu_shader_gpencil_fill_frag_glsl[]; /* cache of built-in shaders (each is created on first use) */ static GPUShader *builtin_shaders[GPU_NUM_BUILTIN_SHADERS] = { NULL }; +static uint g_shaderid = 0; + typedef struct { const char *vert; const char *frag; @@ -272,7 +275,8 @@ GPUShader *GPU_shader_create( const char *fragcode, const char *geocode, const char *libcode, - const char *defines) + const char *defines, + const char *shname) { return GPU_shader_create_ex( vertexcode, @@ -283,7 +287,8 @@ GPUShader *GPU_shader_create( GPU_SHADER_FLAGS_NONE, GPU_SHADER_TFB_NONE, NULL, - 0); + 0, + shname); } #define DEBUG_SHADER_NONE "" @@ -342,7 +347,8 @@ GPUShader *GPU_shader_create_ex( const int flags, const GPUShaderTFBType tf_type, const char **tf_names, - const int tf_count) + const int tf_count, + const char *shname) { #ifdef WITH_OPENSUBDIV bool use_opensubdiv = (flags & GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV) != 0; @@ -360,6 +366,12 @@ GPUShader *GPU_shader_create_ex( shader = MEM_callocN(sizeof(GPUShader), "GPUShader"); gpu_dump_shaders(NULL, 0, DEBUG_SHADER_NONE); +#ifndef NDEBUG + BLI_snprintf(shader->name, sizeof(shader->name), "%s_%u", shname, g_shaderid++); +#else + UNUSED_VARS(shname); +#endif + if (vertexcode) shader->vertex = glCreateShader(GL_VERTEX_SHADER); if (fragcode) @@ -969,7 +981,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader) } /* common case */ - builtin_shaders[shader] = GPU_shader_create(stages->vert, stages->frag, stages->geom, NULL, defines); + builtin_shaders[shader] = GPU_shader_create(stages->vert, stages->frag, stages->geom, NULL, defines, __func__); } return builtin_shaders[shader]; diff --git a/source/blender/gpu/intern/gpu_shader_private.h b/source/blender/gpu/intern/gpu_shader_private.h index d16aae79aae..69c0c41cef4 100644 --- a/source/blender/gpu/intern/gpu_shader_private.h +++ b/source/blender/gpu/intern/gpu_shader_private.h @@ -38,6 +38,9 @@ struct GPUShader { GPUShaderInterface *interface; /* cached uniform & attrib interface for shader */ int feedback_transform_type; +#ifndef NDEBUG + char name[64]; +#endif }; #endif /* __GPU_SHADER_PRIVATE_H__ */ |