From ea689bc784d3cda28c2b1b558a294fe52236f7dd Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 25 Sep 2022 16:18:01 +0300 Subject: [PATCH] Print warnings if a required resource is not bound in PipelineState --- .../backends/opengl/pipelinestate_backend.cpp | 5 ++++ .../backends/vulkan/pipelinestate_backend.cpp | 4 ++++ source/core/pipelinestate.cpp | 24 +++++++++++++++++++ source/core/pipelinestate.h | 3 +++ 4 files changed, 36 insertions(+) diff --git a/source/backends/opengl/pipelinestate_backend.cpp b/source/backends/opengl/pipelinestate_backend.cpp index 204e8139..da5f4957 100644 --- a/source/backends/opengl/pipelinestate_backend.cpp +++ b/source/backends/opengl/pipelinestate_backend.cpp @@ -252,6 +252,11 @@ void OpenGLPipelineState::apply() const glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); } +#ifdef DEBUG + if(changes&(PipelineState::SHPROG|PipelineState::RESOURCES)) + self.check_bound_resources(); +#endif + applied_to = &device; dev_state.last_pipeline = this; changes = 0; diff --git a/source/backends/vulkan/pipelinestate_backend.cpp b/source/backends/vulkan/pipelinestate_backend.cpp index f06e2d32..5d1139b8 100644 --- a/source/backends/vulkan/pipelinestate_backend.cpp +++ b/source/backends/vulkan/pipelinestate_backend.cpp @@ -448,6 +448,10 @@ unsigned VulkanPipelineState::fill_descriptor_writes(unsigned index, unsigned fr ++write_ptr; } +#ifdef DEBUG + self.check_bound_resources(); +#endif + return n_writes; } diff --git a/source/core/pipelinestate.cpp b/source/core/pipelinestate.cpp index 0769d441..6078db5d 100644 --- a/source/core/pipelinestate.cpp +++ b/source/core/pipelinestate.cpp @@ -1,7 +1,9 @@ #include #include +#include #include "error.h" #include "pipelinestate.h" +#include "program.h" #include "uniformblock.h" using namespace std; @@ -137,5 +139,27 @@ void PipelineState::set_blend(const Blend &b) set(blend, b, BLEND); } +void PipelineState::check_bound_resources() const +{ + if(!shprog) + return; + + for(const ReflectData::UniformBlockInfo &b: shprog->get_uniform_blocks()) + if(b.bind_point!=ReflectData::DEFAULT_BLOCK) + { + auto i = lower_bound_member(resources, b.bind_point, &PipelineState::BoundResource::binding); + if(i==resources.end() || i->binding!=b.bind_point) + IO::print(IO::cerr, "Warning: No resource present for uniform block binding %d:%d (%s)\n", b.bind_point>>20, b.bind_point&0xFFFFF, b.name); + } + + for(const ReflectData::UniformInfo &u: shprog->get_uniforms()) + if(u.binding>=0 && is_image(u.type)) + { + auto i = lower_bound_member(resources, u.binding, &PipelineState::BoundResource::binding); + if(i==resources.end() || i->binding!=u.binding) + IO::print(IO::cerr, "Warning: No resource present for texture binding %d:%d (%s)\n", u.binding>>20, u.binding&0xFFFFF, u.name); + } +} + } // namespace GL } // namespace Msp diff --git a/source/core/pipelinestate.h b/source/core/pipelinestate.h index 5156e0b5..a836c407 100644 --- a/source/core/pipelinestate.h +++ b/source/core/pipelinestate.h @@ -120,6 +120,9 @@ public: const VertexSetup *get_vertex_setup() const { return vertex_setup; } FaceWinding get_front_face() const { return front_face; } CullMode get_face_cull() const { return face_cull; } + +private: + void check_bound_resources() const; }; } // namespace GL -- 2.45.2