]> git.tdb.fi Git - libs/gl.git/commitdiff
Set debug names for shader modules on Vulkan
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 22:31:27 +0000 (00:31 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 22:38:07 +0000 (00:38 +0200)
source/backends/opengl/module_backend.h
source/backends/vulkan/module_backend.cpp
source/backends/vulkan/module_backend.h
source/backends/vulkan/program_backend.cpp
source/backends/vulkan/program_backend.h
source/core/module.h
source/resources/resources.cpp

index bb56c55ca15a5caae881fbc5af850a8c3e73b2c9..656b2025be3c870e4c9e4c4780bee07f5812c594 100644 (file)
@@ -14,6 +14,8 @@ protected:
        ~OpenGLSpirVModule() = default;
 
        void create() { }
+
+       void set_debug_name(const std::string &) { }
 };
 
 using SpirVModuleBackend = OpenGLSpirVModule;
index 759497ab6ed1fb9252a21abfe8c30c7ce271cf25..7ec198e0ec3f52de1696523e83a92eddeb129cb1 100644 (file)
@@ -39,6 +39,34 @@ void VulkanSpirVModule::create()
        module_info.pCode = code.data();
 
        vk.CreateShaderModule(module_info, handle);
+
+       if(!debug_name.empty())
+               set_vulkan_object_name();
+}
+
+void VulkanSpirVModule::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       debug_name = name;
+       if(handle)
+               set_vulkan_object_name();
+#else
+       (void)name;
+#endif
+}
+
+void VulkanSpirVModule::set_vulkan_object_name() const
+{
+#ifdef DEBUG
+       const VulkanFunctions &vk = device.get_functions();
+
+       VkDebugUtilsObjectNameInfoEXT name_info = { };
+       name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
+       name_info.objectType = VK_OBJECT_TYPE_SHADER_MODULE;
+       name_info.objectHandle = reinterpret_cast<uint64_t>(handle);
+       name_info.pObjectName = debug_name.c_str();
+       vk.SetDebugUtilsObjectName(name_info);
+#endif
 }
 
 
index 12cbe45f4cad7bb0b1d606453f486d194316da70..c472997607807223be41f3f11992ba8191ec663e 100644 (file)
@@ -15,12 +15,16 @@ class VulkanSpirVModule
 protected:
        Device &device;
        VkShaderModule handle = 0;
+       std::string debug_name;
 
        VulkanSpirVModule();
        VulkanSpirVModule(VulkanSpirVModule &&);
        ~VulkanSpirVModule();
 
        void create();
+
+       void set_debug_name(const std::string &);
+       void set_vulkan_object_name() const;
 };
 
 using SpirVModuleBackend = VulkanSpirVModule;
index 68ade90c7f2ef8e15f1f14298877c6d47d59b3f4..5af7d67aca0ba314884e2fb831de68e011c791e8 100644 (file)
@@ -22,7 +22,8 @@ VulkanProgram::VulkanProgram(VulkanProgram &&other):
        stage_flags(other.stage_flags),
        creation_info(move(other.creation_info)),
        desc_set_layout_handles(move(other.desc_set_layout_handles)),
-       layout_handle(other.layout_handle)
+       layout_handle(other.layout_handle),
+       debug_name(move(other.debug_name))
 {
        other.desc_set_layout_handles.clear();
        other.layout_handle = 0;
@@ -99,6 +100,12 @@ void VulkanProgram::add_spirv_stages(const SpirVModule &mod, const map<string, i
                stage_infos[i].pSpecializationInfo = spec_info;
                ++i;
        }
+
+#if DEBUG
+       if(!debug_name.empty())
+               if(SpirVModule *spirv = static_cast<Program *>(this)->specialized_spirv)
+                       spirv->set_debug_name(debug_name);
+#endif
 }
 
 void VulkanProgram::finalize_uniforms()
@@ -160,5 +167,16 @@ void VulkanProgram::finalize_uniforms()
        vk.CreatePipelineLayout(layout_info, layout_handle);
 }
 
+void VulkanProgram::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       debug_name = name;
+       if(SpirVModule *spirv = static_cast<Program *>(this)->specialized_spirv)
+               spirv->set_debug_name(debug_name);
+#else
+       (void)name;
+#endif
+}
+
 } // namespace GL
 } // namespace Msp
index 1454b40bdedf6b881e84450e4aca8ecf45bf573f..ff39aa4e46857858b804d983a0bf2d38f5b387cc 100644 (file)
@@ -26,6 +26,7 @@ protected:
        std::vector<char> creation_info;
        std::vector<VkDescriptorSetLayout> desc_set_layout_handles;
        VkPipelineLayout layout_handle = 0;
+       std::string debug_name;
 
        VulkanProgram();
        VulkanProgram(VulkanProgram &&);
@@ -37,7 +38,7 @@ protected:
 
        void finalize_uniforms();
 
-       void set_debug_name(const std::string &) { }
+       void set_debug_name(const std::string &);
 };
 
 using ProgramBackend = VulkanProgram;
index 51924d606668db500e7b871f72f7677ae538190d..26895ee0ba2fe9355e397026b5a068c3f7985fe4 100644 (file)
@@ -61,6 +61,9 @@ private:
        virtual void compile(SL::Compiler &) = 0;
 
        SL::Features create_features() const;
+
+public:
+       virtual void set_debug_name(const std::string &) { }
 };
 
 /**
@@ -278,6 +281,9 @@ public:
 private:
        std::vector<const InstructionBlock *> collect_visited_blocks(const std::map<unsigned, int> &) const;
        void collect_visited_blocks(unsigned, std::vector<std::uint8_t> &) const;
+
+public:
+       void set_debug_name(const std::string &n) { SpirVModuleBackend::set_debug_name(n); }
 };
 
 } // namespace GL
index 6a9c4f89d3b1f650910690b8ff4fa35bffc307da..ab4b0a8dd52d560282ef7ca11d1afcd41c1c6cda 100644 (file)
@@ -63,7 +63,8 @@ Resources::Resources(bool set_as_global):
                .creator([this](const string &n){ return create_mesh(n); })
                .notify(&set_debug_name<Mesh>);
        add_type<Module>().suffix(".glsl").suffix(".spv")
-               .creator([this](const string &n){ return create_module(n); });
+               .creator([this](const string &n){ return create_module(n); })
+               .notify(&set_debug_name<Module>);
        add_type<Object>().base<Renderable>().keyword("object");
        add_type<OccludedScene>().base<Scene>().base<Renderable>().suffix(".scene")
                .creator([this](const string &n) -> OccludedScene * { create_generic<Scene>(n); return 0; });