Skip to content

Commit

Permalink
[WIP] Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmNotHanni committed Jul 20, 2024
1 parent 0db8fa3 commit d9f7fc6
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 131 deletions.
31 changes: 2 additions & 29 deletions include/inexor/vulkan-renderer/render-graph/graphics_pass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <array>
Expand All @@ -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<float, 4> get_debug_label_color(const DebugLabelColor color);

/// Using declaration
using OnRecordCommandBufferForPass = std::function<void(const CommandBuffer &)>;

Expand Down Expand Up @@ -120,7 +93,7 @@ class GraphicsPass {
std::vector<std::weak_ptr<GraphicsPass>> graphics_pass_reads,
std::vector<std::pair<std::weak_ptr<Texture>, std::optional<VkClearValue>>> write_attachments,
std::vector<std::pair<std::weak_ptr<Swapchain>, std::optional<VkClearValue>>> write_swapchains,
DebugLabelColor pass_debug_label_color);
wrapper::DebugLabelColor pass_debug_label_color);

GraphicsPass(const GraphicsPass &) = delete;
GraphicsPass(GraphicsPass &&other) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CommandBuffer;
namespace inexor::vulkan_renderer::render_graph {

// Using declaration
using wrapper::DebugLabelColor;
using wrapper::Swapchain;
using wrapper::commands::CommandBuffer;

Expand Down
29 changes: 21 additions & 8 deletions include/inexor/vulkan-renderer/renderers/imgui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<render_graph::Buffer> m_index_buffer;
std::weak_ptr<render_graph::Buffer> m_vertex_buffer;
std::weak_ptr<render_graph::Texture> m_imgui_texture;
std::weak_ptr<Buffer> m_index_buffer;
std::weak_ptr<Buffer> m_vertex_buffer;
std::weak_ptr<Texture> m_imgui_texture;
std::shared_ptr<wrapper::pipelines::GraphicsPipeline> m_imgui_pipeline;

// This is the color attachment we will write to
std::weak_ptr<Swapchain> m_swapchain;
std::weak_ptr<Texture> m_color_attachment;
// This is the previous pass we read from
std::weak_ptr<render_graph::GraphicsPass> m_previous_pass;
std::weak_ptr<GraphicsPass> m_previous_pass;

std::shared_ptr<Shader> m_vertex_shader;
std::shared_ptr<Shader> m_fragment_shader;
Expand Down Expand Up @@ -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> swapchain,
std::weak_ptr<render_graph::RenderGraph> render_graph,
std::weak_ptr<render_graph::GraphicsPass> previous_pass,
std::weak_ptr<render_graph::Texture> color_attachment,
std::weak_ptr<RenderGraph> render_graph,
std::weak_ptr<GraphicsPass> previous_pass,
//std::weak_ptr<Texture> color_attachment,
std::function<void()> on_update_user_data);

ImGuiRenderer(const ImGuiRenderer &) = delete;
Expand Down
30 changes: 29 additions & 1 deletion include/inexor/vulkan-renderer/wrapper/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, 4> get_debug_label_color(const DebugLabelColor color);

// Forward declaration
class Instance;

Expand Down Expand Up @@ -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<void(const commands::CommandBuffer &cmd_buf)> &cmd_buf_recording_func,
std::span<const VkSemaphore> wait_semaphores = {},
std::span<const VkSemaphore> signal_semaphores = {}) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 20 additions & 5 deletions src/vulkan-renderer/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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<renderers::ImGuiRenderer>(*m_device, m_swapchain, m_render_graph, m_octree_pass,
m_color_attachment, [&]() { update_imgui_overlay(); });
// m_imgui_overlay = std::make_unique<renderers::ImGuiRenderer>(*m_device, m_swapchain, m_render_graph,
// m_octree_pass,
// [&]() { update_imgui_overlay(); });

m_render_graph->compile();
}
Expand Down
46 changes: 2 additions & 44 deletions src/vulkan-renderer/render-graph/graphics_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,13 @@

namespace inexor::vulkan_renderer::render_graph {

// TODO: Move to device wrapper?
std::array<float, 4> 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<std::weak_ptr<GraphicsPass>> graphics_pass_reads,
std::vector<std::pair<std::weak_ptr<Texture>, std::optional<VkClearValue>>> write_attachments,
std::vector<std::pair<std::weak_ptr<Swapchain>, std::optional<VkClearValue>>> 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) {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/vulkan-renderer/render-graph/graphics_pass_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GraphicsPassBuilder &GraphicsPassBuilder::conditionally_reads_from(std::weak_ptr
return *this;
}

GraphicsPassBuilder &GraphicsPassBuilder::reads_from(const std::weak_ptr<GraphicsPass> graphics_pass) {
GraphicsPassBuilder &GraphicsPassBuilder::reads_from(std::weak_ptr<GraphicsPass> graphics_pass) {
if (graphics_pass.expired()) {
throw std::invalid_argument("[GraphicsPassBuilder::reads_from] Error: 'graphics_pass' is an invalid pointer!");
}
Expand All @@ -51,17 +51,17 @@ GraphicsPassBuilder &GraphicsPassBuilder::set_on_record(OnRecordCommandBufferFor
return *this;
}

GraphicsPassBuilder &GraphicsPassBuilder::writes_to(const std::weak_ptr<Texture> attachment,
const std::optional<VkClearValue> clear_value) {
GraphicsPassBuilder &GraphicsPassBuilder::writes_to(std::weak_ptr<Texture> attachment,
std::optional<VkClearValue> clear_value) {
if (attachment.expired()) {
throw std::invalid_argument("[GraphicsPassBuilder::writes_to] Error: 'attachment' is an invalid pointer!");
}
m_write_attachments.emplace_back(std::make_pair(std::move(attachment), std::move(clear_value)));
return *this;
}

GraphicsPassBuilder &GraphicsPassBuilder::writes_to(const std::weak_ptr<Swapchain> swapchain,
const std::optional<VkClearValue> clear_value) {
GraphicsPassBuilder &GraphicsPassBuilder::writes_to(std::weak_ptr<Swapchain> swapchain,
std::optional<VkClearValue> clear_value) {
if (swapchain.expired()) {
throw std::invalid_argument("[GraphicsPassBuilder::writes_to] Error: 'swapchain' is an invalid pointer!");
}
Expand Down
Loading

0 comments on commit d9f7fc6

Please sign in to comment.