From: Mikko Rasa Date: Sun, 9 May 2021 12:31:32 +0000 (+0300) Subject: Add debug name capability to more classes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1863f17c5c5563be8492d7f01e5c613a740ea1e9;p=libs%2Fgl.git Add debug name capability to more classes --- diff --git a/source/builders/sequencebuilder.cpp b/source/builders/sequencebuilder.cpp index 317b6884..6cf34c0e 100644 --- a/source/builders/sequencebuilder.cpp +++ b/source/builders/sequencebuilder.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "error.h" #include "renderbuffer.h" #include "sequence.h" @@ -33,8 +34,22 @@ void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc get_item(postprocessors, name) = &pproc; } +void SequenceBuilder::set_debug_name(const string &name) +{ +#ifdef DEBUG + debug_name = name; +#else + (void)name; +#endif +} + void SequenceBuilder::build(Sequence &sequence) const { +#ifdef DEBUG + if(!debug_name.empty()) + sequence.set_debug_name(debug_name); +#endif + sequence.set_hdr(tmpl.get_hdr()); sequence.set_alpha(tmpl.get_alpha()); unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples()); @@ -68,7 +83,13 @@ void SequenceBuilder::build(Sequence &sequence) const { proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height()); if(proc) + { +#ifdef DEBUG + if(!debug_name.empty()) + proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin())); +#endif sequence.add_postprocessor_owned(proc); + } } } } diff --git a/source/builders/sequencebuilder.h b/source/builders/sequencebuilder.h index 739cc5ed..d696dbf8 100644 --- a/source/builders/sequencebuilder.h +++ b/source/builders/sequencebuilder.h @@ -20,6 +20,7 @@ private: const SequenceTemplate &tmpl; std::map renderables; std::map postprocessors; + std::string debug_name; public: SequenceBuilder(const SequenceTemplate &); @@ -27,6 +28,8 @@ public: void set_renderable(const std::string &, Renderable &); void set_postprocessor(const std::string &, PostProcessor &); + void set_debug_name(const std::string &); + void build(Sequence &) const; Sequence *build(unsigned, unsigned) const; Sequence *build(const View &) const; diff --git a/source/core/framebuffer.cpp b/source/core/framebuffer.cpp index 810f0cf1..23b39f2d 100644 --- a/source/core/framebuffer.cpp +++ b/source/core/framebuffer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "error.h" #include "framebuffer.h" #include "misc.h" @@ -393,6 +394,16 @@ void Framebuffer::unbind() system().bind(); } +void Framebuffer::set_debug_name(const string &name) +{ +#ifdef DEBUG + if(KHR_debug) + glObjectLabel(GL_FRAMEBUFFER, id, name.size(), name.c_str()); +#else + (void)name; +#endif +} + Framebuffer &Framebuffer::system() { static Framebuffer sys_framebuf(0); diff --git a/source/core/framebuffer.h b/source/core/framebuffer.h index 88ab465a..ca97ed17 100644 --- a/source/core/framebuffer.h +++ b/source/core/framebuffer.h @@ -164,6 +164,8 @@ public: static const Framebuffer *current(); static void unbind(); + void set_debug_name(const std::string &); + static Framebuffer &system(); }; diff --git a/source/core/renderbuffer.cpp b/source/core/renderbuffer.cpp index e86a97a5..9af18dae 100644 --- a/source/core/renderbuffer.cpp +++ b/source/core/renderbuffer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "misc.h" #include "renderbuffer.h" @@ -78,5 +79,15 @@ void Renderbuffer::unbind() glBindRenderbuffer(GL_RENDERBUFFER, 0); } +void Renderbuffer::set_debug_name(const string &name) +{ +#ifdef DEBUG + if(KHR_debug) + glObjectLabel(GL_RENDERBUFFER, id, name.size(), name.c_str()); +#else + (void)name; +#endif +} + } // namespace GL } // namespace Msp diff --git a/source/core/renderbuffer.h b/source/core/renderbuffer.h index afc6ed20..aea23080 100644 --- a/source/core/renderbuffer.h +++ b/source/core/renderbuffer.h @@ -47,6 +47,8 @@ public: void bind() const; static void unbind(); + + void set_debug_name(const std::string &); }; } // namespace GL diff --git a/source/effects/ambientocclusion.cpp b/source/effects/ambientocclusion.cpp index c35e5771..21271acf 100644 --- a/source/effects/ambientocclusion.cpp +++ b/source/effects/ambientocclusion.cpp @@ -116,6 +116,16 @@ void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const quad.draw(renderer); } +void AmbientOcclusion::set_debug_name(const string &name) +{ +#ifdef DEBUG + occlude_target.set_debug_name(name+" [RT]"); + shdata.set_debug_name(name+" [UBO]"); +#else + (void)name; +#endif +} + AmbientOcclusion::Template::Template(): n_samples(16), diff --git a/source/effects/ambientocclusion.h b/source/effects/ambientocclusion.h index f186db3d..0171d89e 100644 --- a/source/effects/ambientocclusion.h +++ b/source/effects/ambientocclusion.h @@ -64,6 +64,8 @@ public: void set_darkness(float); virtual void render(Renderer &, const Texture2D &, const Texture2D &); + + virtual void set_debug_name(const std::string &); }; } // namespace GL diff --git a/source/effects/bloom.cpp b/source/effects/bloom.cpp index af2057d9..8612ec06 100644 --- a/source/effects/bloom.cpp +++ b/source/effects/bloom.cpp @@ -82,6 +82,19 @@ void Bloom::render(Renderer &renderer, const Texture2D &src, const Texture2D &) quad.draw(renderer); } +void Bloom::set_debug_name(const string &name) +{ +#ifdef DEBUG + for(unsigned i=0; i<2; ++i) + target[i]->set_debug_name(format("%s [RT:%d]", name, i)); + common_shdata.set_debug_name(name+" [UBO:common]"); + blur_shdata[0].set_debug_name(name+" [UBO:blur_x]"); + blur_shdata[1].set_debug_name(name+" [UBO:blur_y]"); +#else + (void)name; +#endif +} + Bloom::Template::Template(): radius(2.0f), diff --git a/source/effects/bloom.h b/source/effects/bloom.h index 7315075b..b80388d6 100644 --- a/source/effects/bloom.h +++ b/source/effects/bloom.h @@ -62,6 +62,8 @@ public: void set_strength(float); virtual void render(Renderer &, const Texture2D &, const Texture2D &); + + virtual void set_debug_name(const std::string &); }; } // namespace GL diff --git a/source/effects/colorcurve.cpp b/source/effects/colorcurve.cpp index d35b7928..697a0583 100644 --- a/source/effects/colorcurve.cpp +++ b/source/effects/colorcurve.cpp @@ -76,6 +76,16 @@ void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Te quad.draw(renderer); } +void ColorCurve::set_debug_name(const string &name) +{ +#ifdef DEBUG + shdata.set_debug_name(name+" [UBO]"); + curve.set_debug_name(name+"/curve.tex1d"); +#else + (void)name; +#endif +} + ColorCurve::Template::Template(): exposure_adjust(0.0f), diff --git a/source/effects/colorcurve.h b/source/effects/colorcurve.h index f274bf06..3ccfbf76 100644 --- a/source/effects/colorcurve.h +++ b/source/effects/colorcurve.h @@ -75,6 +75,8 @@ public: void set_linear(); virtual void render(Renderer &, const Texture2D &, const Texture2D &); + + virtual void set_debug_name(const std::string &); }; } // namespace GL diff --git a/source/effects/effect.h b/source/effects/effect.h index c43cda3a..a4f108fb 100644 --- a/source/effects/effect.h +++ b/source/effects/effect.h @@ -34,6 +34,8 @@ public: virtual void setup_frame(Renderer &r) { renderable.setup_frame(r); } virtual void finish_frame() { renderable.finish_frame(); } + + virtual void set_debug_name(const std::string &) = 0; }; } // namespace GL diff --git a/source/effects/environmentmap.cpp b/source/effects/environmentmap.cpp index a82731e1..e33295da 100644 --- a/source/effects/environmentmap.cpp +++ b/source/effects/environmentmap.cpp @@ -191,5 +191,28 @@ void EnvironmentMap::render(Renderer &renderer, Tag tag) const renderer.render(renderable, tag); } +void EnvironmentMap::set_debug_name(const string &name) +{ +#ifdef DEBUG + env_tex.set_debug_name(name+"/environment.texcb"); + depth_buf.set_debug_name(name+"/environment_depth.rbuf"); + static const char *face_names[] = { "X+", "X-", "Y+", "Y-", "Z+", "Z-" }; + for(unsigned i=0; i<6; ++i) + { + faces[i].fbo.set_debug_name(format("%s [FBO:%s]", name, face_names[i])); + faces[i].camera.set_debug_name(format("%s/%s.camera", name, face_names[i])); + } + + irradiance.set_debug_name(name+"/irradiance.texcb"); + irradiance_fbo.set_debug_name(name+" [FBO:irradiance]"); + for(unsigned i=0; i +#include #include "error.h" #include "renderbuffer.h" #include "rendertarget.h" @@ -202,5 +203,30 @@ void RenderTarget::blit_from(const RenderTarget &other) fbo.blit_from(other.fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false); } +void RenderTarget::set_debug_name(const string &name) +{ +#ifdef DEBUG + fbo.set_debug_name(name+" [FBO]"); + unsigned i = 0; + for(const unsigned char *j=format.begin(); j!=format.end(); ++i, ++j) + { + unsigned type = get_output_type(*j); + + string buf_name; + if(type>=get_output_type(RENDER_DEPTH)) + buf_name = name+"/depth"; + else + buf_name = Msp::format("%s/color%d", name, type); + + if(samples) + buffers[i].buffer->set_debug_name(buf_name+".tex2d"); + else + buffers[i].texture->set_debug_name(buf_name+".rbuf"); + } +#else + (void)name; +#endif +} + } // namespace GL } // namespace Msp diff --git a/source/render/rendertarget.h b/source/render/rendertarget.h index 7d796a3c..cb6d6b97 100644 --- a/source/render/rendertarget.h +++ b/source/render/rendertarget.h @@ -81,6 +81,8 @@ public: const Texture2D &get_target_texture(unsigned) const; const Texture2D &get_target_texture(RenderOutput) const; void blit_from(const RenderTarget &); + + void set_debug_name(const std::string &); }; } // namespace GL diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 06b1403b..05cbafff 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -241,6 +241,33 @@ void Sequence::create_targets(unsigned recreate) if(!target_ms && samples) target_ms = new RenderTarget(width, height, samples, fmt); + +#ifdef DEBUG + if(!debug_name.empty()) + set_target_debug_names(); +#endif +} + +void Sequence::set_debug_name(const string &name) +{ +#ifdef DEBUG + debug_name = name; + if(!name.empty()) + set_target_debug_names(); +#else + (void)name; +#endif +} + +void Sequence::set_target_debug_names() +{ +#ifdef DEBUG + for(unsigned i=0; i<2; ++i) + if(target[i]) + target[i]->set_debug_name(format("%s [RT:%d]", debug_name, i)); + if(target_ms) + target_ms->set_debug_name(debug_name+" [RT:ms]"); +#endif } diff --git a/source/render/sequence.h b/source/render/sequence.h index 8a480add..b1d2c7ca 100644 --- a/source/render/sequence.h +++ b/source/render/sequence.h @@ -84,6 +84,7 @@ private: unsigned samples; RenderTarget *target[2]; RenderTarget *target_ms; + std::string debug_name; public: Sequence(unsigned, unsigned, bool = false); @@ -134,6 +135,11 @@ public: private: void create_targets(unsigned); + +public: + void set_debug_name(const std::string &); +private: + void set_target_debug_names(); }; } // namespace GL