GPUShader: Add name for debugging & identifying shaders.

This commit is contained in:
Clément Foucault 2018-08-02 18:31:38 +02:00
parent 3578212e46
commit 8f6ff3adfa
9 changed files with 55 additions and 21 deletions

View File

@ -257,7 +257,7 @@ void DRW_deferred_shader_remove(GPUMaterial *mat)
GPUShader *DRW_shader_create(const char *vert, const char *geom, const char *frag, const char *defines)
{
return GPU_shader_create(vert, frag, geom, NULL, defines);
return GPU_shader_create(vert, frag, geom, NULL, defines, __func__);
}
GPUShader *DRW_shader_create_with_lib(
@ -274,7 +274,7 @@ GPUShader *DRW_shader_create_with_lib(
geom_with_lib = BLI_string_joinN(lib, geom);
}
sh = GPU_shader_create(vert_with_lib, frag_with_lib, geom_with_lib, NULL, defines);
sh = GPU_shader_create(vert_with_lib, frag_with_lib, geom_with_lib, NULL, defines, __func__);
MEM_freeN(vert_with_lib);
MEM_freeN(frag_with_lib);
@ -290,22 +290,22 @@ GPUShader *DRW_shader_create_with_transform_feedback(
const GPUShaderTFBType prim_type, const char **varying_names, const int varying_count)
{
return GPU_shader_create_ex(vert, NULL, geom, NULL, defines, GPU_SHADER_FLAGS_NONE,
prim_type, varying_names, varying_count);
prim_type, varying_names, varying_count, __func__);
}
GPUShader *DRW_shader_create_2D(const char *frag, const char *defines)
{
return GPU_shader_create(datatoc_gpu_shader_2D_vert_glsl, frag, NULL, NULL, defines);
return GPU_shader_create(datatoc_gpu_shader_2D_vert_glsl, frag, NULL, NULL, defines, __func__);
}
GPUShader *DRW_shader_create_3D(const char *frag, const char *defines)
{
return GPU_shader_create(datatoc_gpu_shader_3D_vert_glsl, frag, NULL, NULL, defines);
return GPU_shader_create(datatoc_gpu_shader_3D_vert_glsl, frag, NULL, NULL, defines, __func__);
}
GPUShader *DRW_shader_create_fullscreen(const char *frag, const char *defines)
{
return GPU_shader_create(datatoc_common_fullscreen_vert_glsl, frag, NULL, NULL, defines);
return GPU_shader_create(datatoc_common_fullscreen_vert_glsl, frag, NULL, NULL, defines, __func__);
}
GPUShader *DRW_shader_create_3D_depth_only(void)
@ -351,7 +351,7 @@ GPUMaterial *DRW_shader_create_from_world(
if (mat == NULL) {
mat = GPU_material_from_nodetree(
scene, wo->nodetree, &wo->gpumaterial, engine_type, options,
vert, geom, frag_lib, defines);
vert, geom, frag_lib, defines, wo->id.name);
}
if (GPU_material_status(mat) == GPU_MAT_QUEUED) {
@ -373,7 +373,7 @@ GPUMaterial *DRW_shader_create_from_material(
if (mat == NULL) {
mat = GPU_material_from_nodetree(
scene, ma->nodetree, &ma->gpumaterial, engine_type, options,
vert, geom, frag_lib, defines);
vert, geom, frag_lib, defines, ma->id.name);
}
if (GPU_material_status(mat) == GPU_MAT_QUEUED) {

View File

@ -247,7 +247,7 @@ GPUMaterial *GPU_material_from_nodetree_find(
struct ListBase *gpumaterials, const void *engine_type, int options);
GPUMaterial *GPU_material_from_nodetree(
struct Scene *scene, struct bNodeTree *ntree, struct 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);
void GPU_material_compile(GPUMaterial *mat);
void GPU_material_free(struct ListBase *gpumaterial);

View File

@ -62,7 +62,8 @@ GPUShader *GPU_shader_create(
const char *fragcode,
const char *geocode,
const char *libcode,
const char *defines);
const char *defines,
const char *shader_name);
GPUShader *GPU_shader_create_ex(
const char *vertexcode,
const char *fragcode,
@ -72,7 +73,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 *shader_name);
void GPU_shader_free(GPUShader *shader);
void GPU_shader_bind(GPUShader *shader);

View File

@ -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 */

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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];

View File

@ -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__ */