diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-02-04 20:52:15 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-02-04 20:54:32 +0300 |
commit | 7b88a206b25225a291a7f972478602bf0b2e2d6a (patch) | |
tree | 5877bd35645abd0eb3227a2191cd9e41f50e23be /source/blender/draw | |
parent | 9aa25ff53d9aa5a1ff7a7dd562b4ed95632e45bb (diff) |
DRW: Add DRW_UNUSED_RESOURCE_TRACKING for ubo and ssbo
When uncommented, this option will make any call binding a resource that is
not present in the shader produce a warning message with its origin.
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 53 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 60 |
2 files changed, 91 insertions, 22 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 29a321df556..d531d8ad9f8 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -66,6 +66,15 @@ extern "C" { #endif +/* Uncomment to track unused resource bindings. */ +// #define DRW_UNUSED_RESOURCE_TRACKING + +#ifdef DRW_UNUSED_RESOURCE_TRACKING +# define DRW_DEBUG_FILE_LINE_ARGS , const char *file, int line +#else +# define DRW_DEBUG_FILE_LINE_ARGS +#endif + struct GPUBatch; struct GPUMaterial; struct GPUShader; @@ -568,12 +577,12 @@ void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, struct GPUTexture **tex); -void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, - const char *name, - const struct GPUUniformBuf *ubo); -void DRW_shgroup_uniform_block_ref(DRWShadingGroup *shgroup, - const char *name, - struct GPUUniformBuf **ubo); +void DRW_shgroup_uniform_block_ex(DRWShadingGroup *shgroup, + const char *name, + const struct GPUUniformBuf *ubo DRW_DEBUG_FILE_LINE_ARGS); +void DRW_shgroup_uniform_block_ref_ex(DRWShadingGroup *shgroup, + const char *name, + struct GPUUniformBuf **ubo DRW_DEBUG_FILE_LINE_ARGS); void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, @@ -633,12 +642,32 @@ void DRW_shgroup_uniform_vec4_array_copy(DRWShadingGroup *shgroup, const char *name, const float (*value)[4], int arraysize); -void DRW_shgroup_vertex_buffer(DRWShadingGroup *shgroup, - const char *name, - struct GPUVertBuf *vertex_buffer); -void DRW_shgroup_vertex_buffer_ref(DRWShadingGroup *shgroup, - const char *name, - struct GPUVertBuf **vertex_buffer); +void DRW_shgroup_vertex_buffer_ex(DRWShadingGroup *shgroup, + const char *name, + struct GPUVertBuf *vertex_buffer DRW_DEBUG_FILE_LINE_ARGS); +void DRW_shgroup_vertex_buffer_ref_ex(DRWShadingGroup *shgroup, + const char *name, + struct GPUVertBuf **vertex_buffer DRW_DEBUG_FILE_LINE_ARGS); + +#ifdef DRW_UNUSED_RESOURCE_TRACKING +# define DRW_shgroup_vertex_buffer(shgroup, name, vert) \ + DRW_shgroup_vertex_buffer_ex(shgroup, name, vert, __FILE__, __LINE__) +# define DRW_shgroup_vertex_buffer_ref(shgroup, name, vert) \ + DRW_shgroup_vertex_buffer_ref_ex(shgroup, name, vert, __FILE__, __LINE__) +# define DRW_shgroup_uniform_block(shgroup, name, ubo) \ + DRW_shgroup_uniform_block_ex(shgroup, name, ubo, __FILE__, __LINE__) +# define DRW_shgroup_uniform_block_ref(shgroup, name, ubo) \ + DRW_shgroup_uniform_block_ref_ex(shgroup, name, ubo, __FILE__, __LINE__) +#else +# define DRW_shgroup_vertex_buffer(shgroup, name, vert) \ + DRW_shgroup_vertex_buffer_ex(shgroup, name, vert) +# define DRW_shgroup_vertex_buffer_ref(shgroup, name, vert) \ + DRW_shgroup_vertex_buffer_ref_ex(shgroup, name, vert) +# define DRW_shgroup_uniform_block(shgroup, name, ubo) \ + DRW_shgroup_uniform_block_ex(shgroup, name, ubo) +# define DRW_shgroup_uniform_block_ref(shgroup, name, ubo) \ + DRW_shgroup_uniform_block_ref_ex(shgroup, name, ubo) +#endif bool DRW_shgroup_is_empty(DRWShadingGroup *shgroup); diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index 9091ae632d0..3f299e878c4 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -283,19 +283,45 @@ void DRW_shgroup_uniform_image_ref(DRWShadingGroup *shgroup, const char *name, G drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_IMAGE_REF, tex, 0, 0, 1); } -void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, - const char *name, - const GPUUniformBuf *ubo) +void DRW_shgroup_uniform_block_ex(DRWShadingGroup *shgroup, + const char *name, + const GPUUniformBuf *ubo DRW_DEBUG_FILE_LINE_ARGS) { BLI_assert(ubo != NULL); int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name); + if (loc == -1) { +#ifdef DRW_UNUSED_RESOURCE_TRACKING + printf("%s:%d: Unable to locate binding of shader uniform buffer object: %s.\n", + file, + line, + name); +#else + /* TODO(@fclem): Would be good to have, but eevee has too much of this for the moment. */ + // BLI_assert_msg(0, "Unable to locate binding of shader uniform buffer objects."); +#endif + return; + } drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_BLOCK, ubo, 0, 0, 1); } -void DRW_shgroup_uniform_block_ref(DRWShadingGroup *shgroup, const char *name, GPUUniformBuf **ubo) +void DRW_shgroup_uniform_block_ref_ex(DRWShadingGroup *shgroup, + const char *name, + GPUUniformBuf **ubo DRW_DEBUG_FILE_LINE_ARGS) { BLI_assert(ubo != NULL); int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name); + if (loc == -1) { +#ifdef DRW_UNUSED_RESOURCE_TRACKING + printf("%s:%d: Unable to locate binding of shader uniform buffer object: %s.\n", + file, + line, + name); +#else + /* TODO(@fclem): Would be good to have, but eevee has too much of this for the moment. */ + // BLI_assert_msg(0, "Unable to locate binding of shader uniform buffer objects."); +#endif + return; + } drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_BLOCK_REF, ubo, 0, 0, 1); } @@ -447,26 +473,40 @@ void DRW_shgroup_uniform_vec4_array_copy(DRWShadingGroup *shgroup, } } -void DRW_shgroup_vertex_buffer(DRWShadingGroup *shgroup, - const char *name, - GPUVertBuf *vertex_buffer) +void DRW_shgroup_vertex_buffer_ex(DRWShadingGroup *shgroup, + const char *name, + GPUVertBuf *vertex_buffer DRW_DEBUG_FILE_LINE_ARGS) { int location = GPU_shader_get_ssbo(shgroup->shader, name); if (location == -1) { +#ifdef DRW_UNUSED_RESOURCE_TRACKING + printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", + file, + line, + name); +#else BLI_assert_msg(0, "Unable to locate binding of shader storage buffer objects."); +#endif return; } drw_shgroup_uniform_create_ex( shgroup, location, DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE, vertex_buffer, 0, 0, 1); } -void DRW_shgroup_vertex_buffer_ref(DRWShadingGroup *shgroup, - const char *name, - GPUVertBuf **vertex_buffer) +void DRW_shgroup_vertex_buffer_ref_ex(DRWShadingGroup *shgroup, + const char *name, + GPUVertBuf **vertex_buffer DRW_DEBUG_FILE_LINE_ARGS) { int location = GPU_shader_get_ssbo(shgroup->shader, name); if (location == -1) { +#ifdef DRW_UNUSED_RESOURCE_TRACKING + printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", + file, + line, + name); +#else BLI_assert_msg(0, "Unable to locate binding of shader storage buffer objects."); +#endif return; } drw_shgroup_uniform_create_ex( |