diff --git a/include/inexor/vulkan-renderer/render-graph/graphics_pass.hpp b/include/inexor/vulkan-renderer/render-graph/graphics_pass.hpp index c827c8ebb..cc971a43d 100644 --- a/include/inexor/vulkan-renderer/render-graph/graphics_pass.hpp +++ b/include/inexor/vulkan-renderer/render-graph/graphics_pass.hpp @@ -5,6 +5,7 @@ #include "inexor/vulkan-renderer/render-graph/buffer.hpp" #include "inexor/vulkan-renderer/render-graph/texture.hpp" #include "inexor/vulkan-renderer/wrapper/descriptors/descriptor_set_layout.hpp" +#include "inexor/vulkan-renderer/wrapper/device.hpp" #include "inexor/vulkan-renderer/wrapper/swapchain.hpp" #include @@ -27,34 +28,6 @@ class RenderGraph; using wrapper::Swapchain; using wrapper::descriptors::DescriptorSetLayout; -// TODO: Move this to device wrapper(?) - -/// The debug label colors for vkCmdBeginDebugUtilsLabelEXT -enum class DebugLabelColor { - RED, - BLUE, - GREEN, - YELLOW, - PURPLE, - ORANGE, - MAGENTA, - CYAN, - BROWN, - PINK, - LIME, - TURQUOISE, - BEIGE, - MAROON, - OLIVE, - NAVY, - TEAL, -}; - -/// Convert a DebugLabelColor to an array of RGBA float values to pass to vkCmdBeginDebugUtilsLabelEXT -/// @param color The DebugLabelColor -/// @return An array of RGBA float values to be passed into vkCmdBeginDebugUtilsLabelEXT -[[nodiscard]] std::array get_debug_label_color(const DebugLabelColor color); - /// Using declaration using OnRecordCommandBufferForPass = std::function; @@ -120,7 +93,7 @@ class GraphicsPass { std::vector> graphics_pass_reads, std::vector, std::optional>> write_attachments, std::vector, std::optional>> write_swapchains, - DebugLabelColor pass_debug_label_color); + wrapper::DebugLabelColor pass_debug_label_color); GraphicsPass(const GraphicsPass &) = delete; GraphicsPass(GraphicsPass &&other) noexcept; diff --git a/include/inexor/vulkan-renderer/render-graph/graphics_pass_builder.hpp b/include/inexor/vulkan-renderer/render-graph/graphics_pass_builder.hpp index 7a3938084..9110f5bb9 100644 --- a/include/inexor/vulkan-renderer/render-graph/graphics_pass_builder.hpp +++ b/include/inexor/vulkan-renderer/render-graph/graphics_pass_builder.hpp @@ -18,6 +18,7 @@ class CommandBuffer; namespace inexor::vulkan_renderer::render_graph { // Using declaration +using wrapper::DebugLabelColor; using wrapper::Swapchain; using wrapper::commands::CommandBuffer; diff --git a/include/inexor/vulkan-renderer/renderers/imgui.hpp b/include/inexor/vulkan-renderer/renderers/imgui.hpp index 71d8a48ae..c5b15869e 100644 --- a/include/inexor/vulkan-renderer/renderers/imgui.hpp +++ b/include/inexor/vulkan-renderer/renderers/imgui.hpp @@ -16,29 +16,42 @@ class Shader; class Swapchain; } // namespace inexor::vulkan_renderer::wrapper -namespace inexor::vulkan_renderer::render_graph { +namespace inexor::vulkan_renderer::pipelines { // Forward declaration +class GraphicsPipeline; +} // namespace inexor::vulkan_renderer::pipelines + +namespace inexor::vulkan_renderer::render_graph { +// Forward declarations +class Buffer; class RenderGraph; +class GraphicsPass; } // namespace inexor::vulkan_renderer::render_graph namespace inexor::vulkan_renderer::renderers { // Using declarations +using render_graph::Buffer; +using render_graph::GraphicsPass; +using render_graph::RenderGraph; +using render_graph::Texture; using wrapper::Device; using wrapper::Shader; using wrapper::Swapchain; +using wrapper::pipelines::GraphicsPipeline; /// A wrapper for an ImGui implementation class ImGuiRenderer { - std::weak_ptr m_index_buffer; - std::weak_ptr m_vertex_buffer; - std::weak_ptr m_imgui_texture; + std::weak_ptr m_index_buffer; + std::weak_ptr m_vertex_buffer; + std::weak_ptr m_imgui_texture; std::shared_ptr m_imgui_pipeline; // This is the color attachment we will write to std::weak_ptr m_swapchain; + std::weak_ptr m_color_attachment; // This is the previous pass we read from - std::weak_ptr m_previous_pass; + std::weak_ptr m_previous_pass; std::shared_ptr m_vertex_shader; std::shared_ptr m_fragment_shader; @@ -81,9 +94,9 @@ class ImGuiRenderer { /// @param on_update_user_data The user-specified ImGui update function ImGuiRenderer(const Device &device, std::weak_ptr swapchain, - std::weak_ptr render_graph, - std::weak_ptr previous_pass, - std::weak_ptr color_attachment, + std::weak_ptr render_graph, + std::weak_ptr previous_pass, + //std::weak_ptr color_attachment, std::function on_update_user_data); ImGuiRenderer(const ImGuiRenderer &) = delete; diff --git a/include/inexor/vulkan-renderer/wrapper/device.hpp b/include/inexor/vulkan-renderer/wrapper/device.hpp index 39caac7f8..ca2974194 100644 --- a/include/inexor/vulkan-renderer/wrapper/device.hpp +++ b/include/inexor/vulkan-renderer/wrapper/device.hpp @@ -16,6 +16,32 @@ class CommandPool; namespace inexor::vulkan_renderer::wrapper { +/// The debug label colors for vkCmdBeginDebugUtilsLabelEXT +enum class DebugLabelColor { + RED, + BLUE, + GREEN, + YELLOW, + PURPLE, + ORANGE, + MAGENTA, + CYAN, + BROWN, + PINK, + LIME, + TURQUOISE, + BEIGE, + MAROON, + OLIVE, + NAVY, + TEAL, +}; + +/// Convert a DebugLabelColor to an array of RGBA float values to pass to vkCmdBeginDebugUtilsLabelEXT +/// @param color The DebugLabelColor +/// @return An array of RGBA float values to be passed into vkCmdBeginDebugUtilsLabelEXT +[[nodiscard]] std::array get_debug_label_color(const DebugLabelColor color); + // Forward declaration class Instance; @@ -150,10 +176,12 @@ class Device { /// the given command pool, begins the command buffer, executes the lambda, ends recording the command buffer, /// submits it and waits for it. /// @param name The internal debug name of the command buffer (must not be empty) - /// @param cmd_lambda The command buffer recording function to execute + /// @param dbg_label_color The debug label color to use for calling ``begin_debug_label_region`` + /// @param cmd_buf_recording_func The command buffer recording function to execute /// @param wait_semaphores /// @param signal_semaphores void execute(const std::string &name, + DebugLabelColor dbg_label_color, const std::function &cmd_buf_recording_func, std::span wait_semaphores = {}, std::span signal_semaphores = {}) const; diff --git a/include/inexor/vulkan-renderer/wrapper/pipelines/pipeline_builder.hpp b/include/inexor/vulkan-renderer/wrapper/pipelines/pipeline_builder.hpp index 4ade8ff70..4d2379637 100644 --- a/include/inexor/vulkan-renderer/wrapper/pipelines/pipeline_builder.hpp +++ b/include/inexor/vulkan-renderer/wrapper/pipelines/pipeline_builder.hpp @@ -125,7 +125,7 @@ class GraphicsPipelineBuilder { /// Adds a color attachment /// @param format The format of the color attachment /// @return A reference to the dereferenced this pointer (allows method calls to be chained) - [[nodiscard]] GraphicsPipelineBuilder &add_color_attachment(VkFormat format); + [[nodiscard]] GraphicsPipelineBuilder &add_color_attachment_format(VkFormat format); /// Add a color blend attachment /// @param attachment The color blend attachment diff --git a/src/vulkan-renderer/application.cpp b/src/vulkan-renderer/application.cpp index 89a7a0a40..bb05b6f5f 100644 --- a/src/vulkan-renderer/application.cpp +++ b/src/vulkan-renderer/application.cpp @@ -492,8 +492,14 @@ void Application::setup_render_graph() { // TODO: Fix me! //.set_multisampling(m_device->get_max_usable_sample_count(), 0.25f) .add_default_color_blend_attachment() - .add_color_attachment(m_swapchain->image_format()) + .add_color_attachment_format(m_swapchain->image_format()) .set_depth_attachment_format(VK_FORMAT_D32_SFLOAT_S8_UINT) + .set_depth_stencil({.depthTestEnable = VK_TRUE, + .depthWriteEnable = VK_TRUE, + .depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL, + .back{ + .compareOp = VK_COMPARE_OP_ALWAYS, + }}) .set_vertex_input_attributes({ { .location = 0, @@ -520,11 +526,19 @@ void Application::setup_render_graph() { m_render_graph->add_graphics_pass([&](render_graph::GraphicsPassBuilder &builder) { // NOTE: Octree pass is the first pass, so it does not declare any reads_from() m_octree_pass = builder - .writes_to(m_color_attachment, + // TODO: Helper function for clear values + .writes_to(m_swapchain, VkClearValue{ .color = {1.0f, 1.0f, 1.0f, 1.0f}, }) - .writes_to(m_depth_attachment) + // TODO: Helper function for clear values + .writes_to(m_depth_attachment, + VkClearValue{ + .depthStencil = + VkClearDepthStencilValue{ + .depth = 1.0f, + }, + }) .set_on_record([&](const wrapper::commands::CommandBuffer &cmd_buf) { cmd_buf.bind_pipeline(m_octree_pipeline) .bind_descriptor_set(m_descriptor_set, m_octree_pipeline) @@ -538,8 +552,9 @@ void Application::setup_render_graph() { // TODO: We don't need to recreate the imgui overlay when swapchain is recreated, use a .recreate() method instead? // TODO: Decouple ImGuiRenderer form ImGuiLoader - m_imgui_overlay = std::make_unique(*m_device, m_swapchain, m_render_graph, m_octree_pass, - m_color_attachment, [&]() { update_imgui_overlay(); }); + // m_imgui_overlay = std::make_unique(*m_device, m_swapchain, m_render_graph, + // m_octree_pass, + // [&]() { update_imgui_overlay(); }); m_render_graph->compile(); } diff --git a/src/vulkan-renderer/render-graph/graphics_pass.cpp b/src/vulkan-renderer/render-graph/graphics_pass.cpp index 08b929972..9b779d128 100644 --- a/src/vulkan-renderer/render-graph/graphics_pass.cpp +++ b/src/vulkan-renderer/render-graph/graphics_pass.cpp @@ -6,55 +6,13 @@ namespace inexor::vulkan_renderer::render_graph { -// TODO: Move to device wrapper? -std::array get_debug_label_color(const DebugLabelColor color) { - switch (color) { - case DebugLabelColor::RED: - return {0.98f, 0.60f, 0.60f, 1.0f}; - case DebugLabelColor::BLUE: - return {0.68f, 0.85f, 0.90f, 1.0f}; - case DebugLabelColor::GREEN: - return {0.73f, 0.88f, 0.73f, 1.0f}; - case DebugLabelColor::YELLOW: - return {0.98f, 0.98f, 0.70f, 1.0f}; - case DebugLabelColor::PURPLE: - return {0.80f, 0.70f, 0.90f, 1.0f}; - case DebugLabelColor::ORANGE: - return {0.98f, 0.75f, 0.53f, 1.0f}; - case DebugLabelColor::MAGENTA: - return {0.96f, 0.60f, 0.76f, 1.0f}; - case DebugLabelColor::CYAN: - return {0.70f, 0.98f, 0.98f, 1.0f}; - case DebugLabelColor::BROWN: - return {0.82f, 0.70f, 0.55f, 1.0f}; - case DebugLabelColor::PINK: - return {0.98f, 0.75f, 0.85f, 1.0f}; - case DebugLabelColor::LIME: - return {0.80f, 0.98f, 0.60f, 1.0f}; - case DebugLabelColor::TURQUOISE: - return {0.70f, 0.93f, 0.93f, 1.0f}; - case DebugLabelColor::BEIGE: - return {0.96f, 0.96f, 0.86f, 1.0f}; - case DebugLabelColor::MAROON: - return {0.76f, 0.50f, 0.50f, 1.0f}; - case DebugLabelColor::OLIVE: - return {0.74f, 0.75f, 0.50f, 1.0f}; - case DebugLabelColor::NAVY: - return {0.53f, 0.70f, 0.82f, 1.0f}; - case DebugLabelColor::TEAL: - return {0.53f, 0.80f, 0.75f, 1.0f}; - default: - return {0.0f, 0.0f, 0.0f, 1.0f}; // Default to opaque black if the color is not recognized - } -} - GraphicsPass::GraphicsPass( std::string name, OnRecordCommandBufferForPass on_record_cmd_buffer, std::vector> graphics_pass_reads, std::vector, std::optional>> write_attachments, std::vector, std::optional>> write_swapchains, - const DebugLabelColor pass_debug_label_color) { + const wrapper::DebugLabelColor pass_debug_label_color) { // If an extent has already been specified, all attachments must match this! if (m_extent.width != 0 && m_extent.height != 0) { for (const auto &write_attachment : write_attachments) { @@ -112,7 +70,7 @@ GraphicsPass::GraphicsPass( // Store the other data m_name = std::move(name); m_on_record_cmd_buffer = std::move(on_record_cmd_buffer); - m_debug_label_color = get_debug_label_color(pass_debug_label_color); + m_debug_label_color = wrapper::get_debug_label_color(pass_debug_label_color); m_graphics_pass_reads = std::move(graphics_pass_reads); m_write_attachments = std::move(write_attachments); m_write_swapchains = std::move(write_swapchains); diff --git a/src/vulkan-renderer/render-graph/graphics_pass_builder.cpp b/src/vulkan-renderer/render-graph/graphics_pass_builder.cpp index 0c9188a77..6d7136daa 100644 --- a/src/vulkan-renderer/render-graph/graphics_pass_builder.cpp +++ b/src/vulkan-renderer/render-graph/graphics_pass_builder.cpp @@ -32,7 +32,7 @@ GraphicsPassBuilder &GraphicsPassBuilder::conditionally_reads_from(std::weak_ptr return *this; } -GraphicsPassBuilder &GraphicsPassBuilder::reads_from(const std::weak_ptr graphics_pass) { +GraphicsPassBuilder &GraphicsPassBuilder::reads_from(std::weak_ptr graphics_pass) { if (graphics_pass.expired()) { throw std::invalid_argument("[GraphicsPassBuilder::reads_from] Error: 'graphics_pass' is an invalid pointer!"); } @@ -51,8 +51,8 @@ GraphicsPassBuilder &GraphicsPassBuilder::set_on_record(OnRecordCommandBufferFor return *this; } -GraphicsPassBuilder &GraphicsPassBuilder::writes_to(const std::weak_ptr attachment, - const std::optional clear_value) { +GraphicsPassBuilder &GraphicsPassBuilder::writes_to(std::weak_ptr attachment, + std::optional clear_value) { if (attachment.expired()) { throw std::invalid_argument("[GraphicsPassBuilder::writes_to] Error: 'attachment' is an invalid pointer!"); } @@ -60,8 +60,8 @@ GraphicsPassBuilder &GraphicsPassBuilder::writes_to(const std::weak_ptr return *this; } -GraphicsPassBuilder &GraphicsPassBuilder::writes_to(const std::weak_ptr swapchain, - const std::optional clear_value) { +GraphicsPassBuilder &GraphicsPassBuilder::writes_to(std::weak_ptr swapchain, + std::optional clear_value) { if (swapchain.expired()) { throw std::invalid_argument("[GraphicsPassBuilder::writes_to] Error: 'swapchain' is an invalid pointer!"); } diff --git a/src/vulkan-renderer/render-graph/render_graph.cpp b/src/vulkan-renderer/render-graph/render_graph.cpp index f1b20939b..2f4099d77 100644 --- a/src/vulkan-renderer/render-graph/render_graph.cpp +++ b/src/vulkan-renderer/render-graph/render_graph.cpp @@ -134,7 +134,7 @@ void RenderGraph::create_graphics_pipelines() { } void RenderGraph::create_textures() { - m_device.execute("[RenderGraph::create_textures]", [&](const CommandBuffer &cmd_buf) { + m_device.execute("[RenderGraph::create_textures]", DebugLabelColor::BLUE, [&](const CommandBuffer &cmd_buf) { for (const auto &texture : m_textures) { if (texture->m_on_init) { cmd_buf.set_suboperation_debug_name("[Texture|Initialize]:" + texture->m_name + "]"); @@ -186,7 +186,7 @@ void RenderGraph::fill_graphics_pass_rendering_info(GraphicsPass &pass) { .imageLayout = get_image_layout(), .resolveMode = VK_RESOLVE_MODE_NONE, .resolveImageView = nullptr, - .loadOp = clear_value ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .loadOp = clear_value ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD, .storeOp = VK_ATTACHMENT_STORE_OP_STORE, .clearValue = clear_value ? clear_value.value() : VkClearValue{}, }); @@ -230,7 +230,7 @@ void RenderGraph::fill_graphics_pass_rendering_info(GraphicsPass &pass) { .imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, .resolveMode = VK_RESOLVE_MODE_NONE, .resolveImageView = nullptr, - .loadOp = clear_value ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .loadOp = clear_value ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD, .storeOp = VK_ATTACHMENT_STORE_OP_STORE, .clearValue = clear_value ? clear_value.value() : VkClearValue{}, }); @@ -268,6 +268,8 @@ void RenderGraph::record_command_buffer_for_pass(const CommandBuffer &cmd_buf, G // Fill the VKRenderingInfo of the graphics pass fill_graphics_pass_rendering_info(pass); + // TODO: Only change image layout of swapchain if previous pass did not already do this! + // If there are writes to swapchains, the image layout of the swapchain must be changed because it comes back in // undefined layout after presenting for (const auto &swapchain : pass.m_write_swapchains) { @@ -290,12 +292,15 @@ void RenderGraph::record_command_buffer_for_pass(const CommandBuffer &cmd_buf, G cmd_buf.end_rendering(); // ---------------------------------------------------------------------------------------------------------------- + // TODO: Only change image layout of swapchain if previous pass did not already do this! + // Change the swapchain image layouts to prepare the swapchains for presenting for (const auto &swapchain : pass.m_write_swapchains) { cmd_buf.insert_debug_label("Changing Swapchain image layout", get_debug_label_color(DebugLabelColor::GREEN)); cmd_buf.change_image_layout(swapchain.first.lock()->m_current_img, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); } + // End the debug label for this graphics pass cmd_buf.end_debug_label_region(); } @@ -309,7 +314,7 @@ void RenderGraph::render() { // So if we are writing to multiple swapchains in this pass, we must wait for every swapchains // semaphore! m_device.execute( - "[RenderGraph::render]", + "[RenderGraph::render]", DebugLabelColor::CYAN, [&](const CommandBuffer &cmd_buf) { // Call the command buffer recording function of every graphics pass for (auto &pass : m_graphics_passes) { @@ -324,24 +329,46 @@ void RenderGraph::reset() { } void RenderGraph::update_buffers() { - m_device.execute("[RenderGraph::update_buffers]", [&](const CommandBuffer &cmd_buf) { - for (const auto &buffer : m_buffers) { - std::invoke(buffer->m_on_check_for_update); - if (buffer->m_update_requested) { - cmd_buf.set_suboperation_debug_name("[Buffer|Destroy:" + buffer->m_name + "]"); - buffer->destroy_all(); - cmd_buf.set_suboperation_debug_name("[Buffer|Update:" + buffer->m_name + "]"); - buffer->create(cmd_buf); - } + // Check if there is any update required + bool any_update_required = false; + for (const auto &buffer : m_buffers) { + std::invoke(buffer->m_on_check_for_update); + if (buffer->m_update_requested) { + any_update_required = true; } - }); + } + // Only start recording and submitting a command buffer if any update is required + if (any_update_required) { + m_device.execute("[RenderGraph::update_buffers]", DebugLabelColor::MAGENTA, [&](const CommandBuffer &cmd_buf) { + for (const auto &buffer : m_buffers) { + if (buffer->m_update_requested) { + cmd_buf.set_suboperation_debug_name("[Buffer|Destroy:" + buffer->m_name + "]"); + buffer->destroy_all(); + cmd_buf.set_suboperation_debug_name("[Buffer|Update:" + buffer->m_name + "]"); + buffer->create(cmd_buf); + } + } + }); + } } void RenderGraph::update_textures() { - m_device.execute("[RenderGraph::update_textures]", [&](const CommandBuffer &cmd_buf) { - for (const auto &texture : m_textures) { - // Only for dynamic textures m_on_lambda which is not std::nullopt - if (texture->m_on_check_for_updates) { + // Check if there is any update required + bool any_update_required = false; + for (const auto &texture : m_textures) { + // Only for dynamic textures m_on_lambda which is not std::nullopt + if (texture->m_on_check_for_updates) { + std::invoke(texture->m_on_check_for_updates.value()); + if (texture->m_update_requested) { + any_update_required = true; + } + } + } + // Only start recording and submitting a command buffer if any update is required + if (any_update_required) { + m_device.execute("[RenderGraph::update_textures]", DebugLabelColor::LIME, [&](const CommandBuffer &cmd_buf) { + for (const auto &texture : m_textures) { + // Only for dynamic textures m_on_lambda which is not std::nullopt if (texture->m_update_requested) { cmd_buf.set_suboperation_debug_name("[Texture|Destroy:" + texture->m_name + "]"); texture->destroy(); @@ -351,8 +378,8 @@ void RenderGraph::update_textures() { texture->create(); } } - } - }); + }); + } } void RenderGraph::update_write_descriptor_sets() { diff --git a/src/vulkan-renderer/render-graph/texture.cpp b/src/vulkan-renderer/render-graph/texture.cpp index e086e6985..ae6d79d4f 100644 --- a/src/vulkan-renderer/render-graph/texture.cpp +++ b/src/vulkan-renderer/render-graph/texture.cpp @@ -163,15 +163,13 @@ void Texture::update(const CommandBuffer &cmd_buf) { }) .pipeline_image_memory_barrier_after_copy_buffer_to_image(m_img->m_img); - // This is necessary for external textures only, not depth or back buffers used internally in rendergraph - if (m_usage == TextureUsage::NORMAL) { - // Update the descriptor image info - m_descriptor_img_info = VkDescriptorImageInfo{ - .sampler = m_img->m_sampler->m_sampler, - .imageView = m_img->m_img_view, - .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - }; - } + // Update the descriptor image info + m_descriptor_img_info = VkDescriptorImageInfo{ + .sampler = m_img->m_sampler->m_sampler, + .imageView = m_img->m_img_view, + .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + }; + // The update is finished m_update_requested = false; diff --git a/src/vulkan-renderer/renderers/imgui.cpp b/src/vulkan-renderer/renderers/imgui.cpp index 7a294569c..1458e80fa 100644 --- a/src/vulkan-renderer/renderers/imgui.cpp +++ b/src/vulkan-renderer/renderers/imgui.cpp @@ -14,12 +14,12 @@ namespace inexor::vulkan_renderer::renderers { ImGuiRenderer::ImGuiRenderer(const Device &device, std::weak_ptr swapchain, - std::weak_ptr render_graph, - std::weak_ptr previous_pass, - std::weak_ptr color_attachment, + std::weak_ptr render_graph, + std::weak_ptr previous_pass, + // std::weak_ptr color_attachment, std::function on_update_user_data) : m_on_update_user_data(std::move(on_update_user_data)), m_previous_pass(std::move(previous_pass)), - m_swapchain(std::move(swapchain)) { + m_swapchain(std::move(swapchain)) /*, m_color_attachment(std::move(color_attachment))*/ { if (render_graph.expired()) { throw std::invalid_argument( @@ -124,8 +124,7 @@ ImGuiRenderer::ImGuiRenderer(const Device &device, }, }) .add_default_color_blend_attachment() - .add_color_attachment(m_swapchain.lock()->image_format()) - .set_depth_attachment_format(VK_FORMAT_D32_SFLOAT_S8_UINT) + .add_color_attachment_format(m_swapchain.lock()->image_format()) .set_viewport(m_swapchain.lock()->extent()) .set_scissor(m_swapchain.lock()->extent()) .add_shader(m_vertex_shader) @@ -140,8 +139,12 @@ ImGuiRenderer::ImGuiRenderer(const Device &device, // NOTE: ImGui does not write to depth buffer and it reads from octree pass (previous pass) // NOTE: We directly return the ImGui graphics pass and do not store it in here because it's the last pass (for // now) and there is no reads_from function which would need it. - return builder.writes_to(m_swapchain) - .conditionally_reads_from(m_previous_pass, !m_previous_pass.expired()) + return builder + .writes_to(m_swapchain, + VkClearValue{ + .color = {1.0f, 1.0f, 1.0f, 1.0f}, + }) + //.conditionally_reads_from(m_previous_pass, !m_previous_pass.expired()) .set_on_record([&](const wrapper::commands::CommandBuffer &cmd_buf) { ImDrawData *draw_data = ImGui::GetDrawData(); if (draw_data == nullptr || draw_data->TotalIdxCount == 0 || draw_data->TotalVtxCount == 0) { diff --git a/src/vulkan-renderer/wrapper/device.cpp b/src/vulkan-renderer/wrapper/device.cpp index 54172bcfa..0a0eff778 100644 --- a/src/vulkan-renderer/wrapper/device.cpp +++ b/src/vulkan-renderer/wrapper/device.cpp @@ -29,6 +29,48 @@ constexpr float DEFAULT_QUEUE_PRIORITY = 1.0f; } // namespace namespace inexor::vulkan_renderer::wrapper { + +std::array get_debug_label_color(const DebugLabelColor color) { + switch (color) { + case DebugLabelColor::RED: + return {0.98f, 0.60f, 0.60f, 1.0f}; + case DebugLabelColor::BLUE: + return {0.68f, 0.85f, 0.90f, 1.0f}; + case DebugLabelColor::GREEN: + return {0.73f, 0.88f, 0.73f, 1.0f}; + case DebugLabelColor::YELLOW: + return {0.98f, 0.98f, 0.70f, 1.0f}; + case DebugLabelColor::PURPLE: + return {0.80f, 0.70f, 0.90f, 1.0f}; + case DebugLabelColor::ORANGE: + return {0.98f, 0.75f, 0.53f, 1.0f}; + case DebugLabelColor::MAGENTA: + return {0.96f, 0.60f, 0.76f, 1.0f}; + case DebugLabelColor::CYAN: + return {0.70f, 0.98f, 0.98f, 1.0f}; + case DebugLabelColor::BROWN: + return {0.82f, 0.70f, 0.55f, 1.0f}; + case DebugLabelColor::PINK: + return {0.98f, 0.75f, 0.85f, 1.0f}; + case DebugLabelColor::LIME: + return {0.80f, 0.98f, 0.60f, 1.0f}; + case DebugLabelColor::TURQUOISE: + return {0.70f, 0.93f, 0.93f, 1.0f}; + case DebugLabelColor::BEIGE: + return {0.96f, 0.96f, 0.86f, 1.0f}; + case DebugLabelColor::MAROON: + return {0.76f, 0.50f, 0.50f, 1.0f}; + case DebugLabelColor::OLIVE: + return {0.74f, 0.75f, 0.50f, 1.0f}; + case DebugLabelColor::NAVY: + return {0.53f, 0.70f, 0.82f, 1.0f}; + case DebugLabelColor::TEAL: + return {0.53f, 0.80f, 0.75f, 1.0f}; + default: + return {0.0f, 0.0f, 0.0f, 1.0f}; // Default to opaque black if the color is not recognized + } +} + namespace { /// A function for rating physical devices by type @@ -464,12 +506,15 @@ bool Device::surface_supports_usage(const VkSurfaceKHR surface, const VkImageUsa } void Device::execute(const std::string &name, + const DebugLabelColor dbg_label_color, const std::function &cmd_buf_recording_func, const std::span wait_semaphores, const std::span signal_semaphores) const { // TODO: Support other queues, not just graphics queue const auto &cmd_buf = thread_graphics_pool().request_command_buffer(name); + cmd_buf.begin_debug_label_region(name, get_debug_label_color(dbg_label_color)); std::invoke(cmd_buf_recording_func, cmd_buf); + cmd_buf.end_debug_label_region(); cmd_buf.submit_and_wait(wait_semaphores, signal_semaphores); } diff --git a/src/vulkan-renderer/wrapper/pipelines/pipeline_builder.cpp b/src/vulkan-renderer/wrapper/pipelines/pipeline_builder.cpp index e56f39077..cc40d4c84 100644 --- a/src/vulkan-renderer/wrapper/pipelines/pipeline_builder.cpp +++ b/src/vulkan-renderer/wrapper/pipelines/pipeline_builder.cpp @@ -150,7 +150,7 @@ void GraphicsPipelineBuilder::reset() { m_color_blend_attachment_states.clear(); } -GraphicsPipelineBuilder &GraphicsPipelineBuilder::add_color_attachment(const VkFormat format) { +GraphicsPipelineBuilder &GraphicsPipelineBuilder::add_color_attachment_format(const VkFormat format) { m_color_attachments.push_back(format); return *this; }