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 19, 2024
1 parent 25fdabf commit 0db8fa3
Show file tree
Hide file tree
Showing 25 changed files with 713 additions and 600 deletions.
31 changes: 21 additions & 10 deletions include/inexor/vulkan-renderer/render-graph/graphics_pass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace inexor::vulkan_renderer::render_graph {
// Forward declaration
class RenderGraph;

// Using declaration
// Using declarations
using wrapper::Swapchain;
using wrapper::descriptors::DescriptorSetLayout;

Expand Down Expand Up @@ -55,17 +55,18 @@ enum class 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 &)>;

/// A wrapper for graphics passes inside of rendergraph
class GraphicsPass {
//
friend class RenderGraph;

private:
/// The name of the graphics pass
std::string m_name;

/// The command buffer recording function of the graphics pass
using OnRecordCommandBufferForPass = std::function<void(const CommandBuffer &)>;
OnRecordCommandBufferForPass m_on_record_cmd_buffer{[](auto &) {}};

/// The descriptor set layout of the pass (this will be created by rendergraph)
Expand All @@ -76,12 +77,15 @@ class GraphicsPass {
/// The color of the debug label region (visible in graphics debuggers like RenderDoc)
std::array<float, 4> m_debug_label_color;

/// The extent
VkExtent2D m_extent{0, 0};
/// The graphics passes this pass reads from
std::vector<std::weak_ptr<GraphicsPass>> m_graphics_pass_reads;

/// The texture attachments of this pass (unified means color, depth, stencil attachment or a swapchain)
std::vector<std::weak_ptr<Texture>> m_write_attachments{};
std::vector<std::pair<std::weak_ptr<Texture>, std::optional<VkClearValue>>> m_write_attachments{};
/// The swapchains this graphics pass writes to
std::vector<std::weak_ptr<Swapchain>> m_write_swapchains{};
std::vector<std::pair<std::weak_ptr<Swapchain>, std::optional<VkClearValue>>> m_write_swapchains{};

// All the data below will be filled and used by rendergraph only

Expand All @@ -90,11 +94,18 @@ class GraphicsPass {
/// which is why we store them as members here.
VkRenderingInfo m_rendering_info{};
/// The color attachments inside of m_rendering_info
std::vector<VkRenderingAttachmentInfo> m_color_attachment_infos{};
std::vector<VkRenderingAttachmentInfo> m_color_attachments{};
/// Does this graphics pass have any depth attachment?
bool m_has_depth_attachment{false};
/// The depth attachment inside of m_rendering_info
VkRenderingAttachmentInfo m_depth_attachment_info{};
VkRenderingAttachmentInfo m_depth_attachment{};
/// Does this graphics pass have any stencil attachment?
bool m_has_stencil_attachment{false};
/// The stencil attachment inside of m_rendering_info
VkRenderingAttachmentInfo m_stencil_attachment_info{};
VkRenderingAttachmentInfo m_stencil_attachment{};

/// Reset the rendering info
void reset_rendering_info();

public:
/// Default constructor
Expand All @@ -107,8 +118,8 @@ class GraphicsPass {
GraphicsPass(std::string name,
OnRecordCommandBufferForPass on_record_cmd_buffer,
std::vector<std::weak_ptr<GraphicsPass>> graphics_pass_reads,
std::vector<std::weak_ptr<Texture>> write_attachments,
std::vector<std::weak_ptr<Swapchain>> write_swapchains,
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);

GraphicsPass(const GraphicsPass &) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ using wrapper::commands::CommandBuffer;
class GraphicsPassBuilder {
private:
/// Add members which describe data related to graphics passes here
std::function<void(const CommandBuffer &)> m_on_record_cmd_buffer{};
OnRecordCommandBufferForPass m_on_record_cmd_buffer{};
/// The graphics passes which are read by this graphics pass
std::vector<std::weak_ptr<GraphicsPass>> m_graphics_pass_reads{};
/// The texture resources this graphics pass writes to
std::vector<std::weak_ptr<Texture>> m_write_attachments{};
std::vector<std::pair<std::weak_ptr<Texture>, std::optional<VkClearValue>>> m_write_attachments{};
/// The swapchain this graphics pass writes to
std::vector<std::weak_ptr<Swapchain>> m_write_swapchains{};
std::vector<std::pair<std::weak_ptr<Swapchain>, std::optional<VkClearValue>>> m_write_swapchains{};

/// Reset the data of the graphics pass builder
void reset();
Expand Down Expand Up @@ -68,7 +68,7 @@ class GraphicsPassBuilder {
/// Set the function which will be called when the command buffer for rendering of the pass is being recorded
/// @param on_record_cmd_buffer The command buffer recording function
/// @return A const reference to the this pointer (allowing method calls to be chained)
[[nodiscard]] GraphicsPassBuilder &set_on_record(std::function<void(const CommandBuffer &)> on_record_cmd_buffer);
[[nodiscard]] GraphicsPassBuilder &set_on_record(OnRecordCommandBufferForPass on_record_cmd_buffer);

/// Specify that this graphics pass writes to an attachment
/// @param attachment The attachment
Expand All @@ -81,8 +81,10 @@ class GraphicsPassBuilder {

/// Specify that this graphics pass writes to a swapchain
/// @param swapchain The swapchain this pass writes to
/// @param clear_value The optional clear value of the swapchain (``std::nullopt`` by default)
/// @return A const reference to the this pointer (allowing method calls to be chained)
[[nodiscard]] GraphicsPassBuilder &writes_to(std::weak_ptr<Swapchain> swapchain);
[[nodiscard]] GraphicsPassBuilder &writes_to(std::weak_ptr<Swapchain> swapchain,
std::optional<VkClearValue> clear_value = std::nullopt);
};

} // namespace inexor::vulkan_renderer::render_graph
12 changes: 6 additions & 6 deletions include/inexor/vulkan-renderer/render-graph/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class RenderGraph {
/// -----------------------------------------------------------------------------------------------------------------

// TODO
std::vector<std::weak_ptr<Swapchain>> m_swapchains;
std::vector<VkSemaphore> m_swapchains_imgs_available;

/// -----------------------------------------------------------------------------------------------------------------
/// GRAPHICS PIPELINES
Expand Down Expand Up @@ -239,9 +239,8 @@ class RenderGraph {
/// @exception std::logic_error The rendergraph is not acyclic!
void check_for_cycles();

/// Create the buffers of every buffer resource in the rendergraph
/// @param cmd_buf The command buffer to record into
void create_buffers();
/// Collect all image available semaphores of all swapchains which are used into one std::vector<VkSemaphore>
void collect_swapchain_image_available_semaphores();

/// Create the descriptor set layouts
void create_descriptor_set_layouts();
Expand Down Expand Up @@ -281,8 +280,9 @@ class RenderGraph {
/// @note If a uniform buffer has been updated, an update of the associated descriptor set will be performed
void update_buffers();

/// Update the descriptor sets
void update_descriptor_sets();
/// Update the write descriptor sets
/// @note This function must only be called once during rendergraph compilation, not for every frame!
void update_write_descriptor_sets();

/// Update dynamic textures
void update_textures();
Expand Down
5 changes: 3 additions & 2 deletions include/inexor/vulkan-renderer/render-graph/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ namespace inexor::vulkan_renderer::render_graph {
/// NOTE: All usages which are not TextureUsage::NORMAL are for internal usage inside of rendergraph only
enum class TextureUsage {
NORMAL,
BACK_BUFFER,
DEPTH_STENCIL_BUFFER,
COLOR_ATTACHMENT,
DEPTH_ATTACHMENT,
STENCIL_ATTACHMENT,
};

// Forward declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class CommandBuffer {
const CommandBuffer &end_command_buffer() const; // NOLINT

/// Call vkQueueSubmit
void submit_and_wait() const;
/// @param wait_semaphores The semaphores to wait for
/// @param signal_semaphores The semaphores to signal
void submit_and_wait(std::span<const VkSemaphore> wait_semaphores = {},
std::span<const VkSemaphore> signal_semaphores = {}) const;

public:
/// Default constructor
Expand Down Expand Up @@ -405,7 +408,8 @@ class CommandBuffer {
const T &data, // NOLINT
const VkShaderStageFlags stage,
const VkDeviceSize offset = 0) const {
return push_constants(pipeline.lock()->m_pipeline_layout, stage, sizeof(data), &data, offset);
return push_constants(pipeline.lock()->m_pipeline_layout->m_pipeline_layout, stage, sizeof(data), &data,
offset);
}

/// Set the name of a command buffer during recording of a specific command in the current command buffer
Expand Down
8 changes: 6 additions & 2 deletions include/inexor/vulkan-renderer/wrapper/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ 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 lambda to execute
/// @param cmd_lambda The command buffer recording function to execute
/// @param wait_semaphores
/// @param signal_semaphores
void execute(const std::string &name,
const std::function<void(const commands::CommandBuffer &cmd_buf)> &cmd_lambda) const;
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;

/// Find a queue family index that suits a specific criteria
/// @param criteria_lambda The lambda to sort out unsuitable queue families
Expand Down
6 changes: 3 additions & 3 deletions include/inexor/vulkan-renderer/wrapper/pipelines/pipeline.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "inexor/vulkan-renderer/wrapper/pipelines/pipeline_layout.hpp"

#include <volk.h>

#include <string>
Expand Down Expand Up @@ -31,10 +33,8 @@ class GraphicsPipeline {

private:
const Device &m_device;
std::vector<VkDescriptorSetLayout> m_descriptor_set_layouts;
std::vector<VkPushConstantRange> m_push_constant_ranges;
std::unique_ptr<PipelineLayout> m_pipeline_layout{nullptr};
VkPipeline m_pipeline{VK_NULL_HANDLE};
VkPipelineLayout m_pipeline_layout{VK_NULL_HANDLE};
std::string m_name;

public:
Expand Down
Loading

0 comments on commit 0db8fa3

Please sign in to comment.