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 23, 2024
1 parent 9392044 commit c9cc646
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
19 changes: 6 additions & 13 deletions include/inexor/vulkan-renderer/render-graph/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ class RenderGraph {
/// Create the descriptor set layouts
void create_descriptor_set_layouts();

/// Create the graphics passes
void create_graphics_passes();

/// Create the graphics pipelines
void create_graphics_pipelines();

Expand Down Expand Up @@ -301,9 +298,6 @@ class RenderGraph {
/// @note This function must only be called once during rendergraph compilation, not for every frame!
void update_write_descriptor_sets();

/// Make sure all required resources are specified so rendergraph is ready to be compiled
void validate_render_graph();

public:
/// Default constructor
/// @note device and swapchain are not taken as a const reference because rendergraph needs to modify both
Expand All @@ -319,9 +313,9 @@ class RenderGraph {
RenderGraph &operator=(RenderGraph &&) = delete;

/// Add a new graphics pass to the rendergraph
/// @aram graphics_pass The graphics pass that was created
/// @aram pass The graphics pass that was created
/// @return A std::weak_ptr to the graphics pass that was added
[[nodiscard]] std::weak_ptr<GraphicsPass> add_graphics_pass(std::shared_ptr<GraphicsPass> graphics_pass);
[[nodiscard]] std::weak_ptr<GraphicsPass> add_graphics_pass(std::shared_ptr<GraphicsPass> pass);

/// Add a new graphics pipeline to the rendergraph
/// @param on_pipeline_create A function to create the graphics pipeline using GraphicsPipelineBuilder
Expand All @@ -330,11 +324,10 @@ class RenderGraph {

/// Add an buffer to rendergraph
/// @param name The name of the buffer
/// @param buffer_type The type of the buffer
/// @param type The type of the buffer
/// @param on_update The update function of the index buffer
/// @return A weak pointer to the buffer resource that was created
[[nodiscard]] std::weak_ptr<Buffer>
add_buffer(std::string buffer_name, BufferType buffer_type, std::function<void()> on_update);
[[nodiscard]] std::weak_ptr<Buffer> add_buffer(std::string name, BufferType type, std::function<void()> on_update);

/// Add a descriptor to rendergraph
/// @note This function is of type void because it does not store anything that is created in those callback
Expand All @@ -350,7 +343,7 @@ class RenderGraph {
OnBuildWriteDescriptorSets on_update_descriptor_set);

/// Add a texture which will be initialized externally (not inside of rendergraph)
/// @param texture_name The name of the texture
/// @param name The name of the texture
/// @param usage The usage of the texture inside of rendergraph
/// @param format The format of the texture
/// @param width The width of the texture
Expand All @@ -360,7 +353,7 @@ class RenderGraph {
/// @param m_on_check_for_updates The texture update function (an empty lambda by default)
/// @return A weak pointer to the texture that was created
[[nodiscard]] std::weak_ptr<Texture> add_texture(
std::string texture_name,
std::string name,
TextureUsage usage,
VkFormat format,
std::uint32_t width,
Expand Down
36 changes: 12 additions & 24 deletions src/vulkan-renderer/render-graph/render_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ RenderGraph::RenderGraph(Device &device)
: m_device(device), m_graphics_pipeline_builder(device), m_descriptor_set_layout_builder(device),
m_descriptor_set_allocator(m_device), m_write_descriptor_set_builder(m_device) {}

std::weak_ptr<GraphicsPass> RenderGraph::add_graphics_pass(std::shared_ptr<GraphicsPass> graphics_pass) {
m_graphics_passes.emplace_back(std::move(graphics_pass));
std::weak_ptr<GraphicsPass> RenderGraph::add_graphics_pass(std::shared_ptr<GraphicsPass> pass) {
m_graphics_passes.emplace_back(std::move(pass));
return m_graphics_passes.back();
}

Expand All @@ -24,9 +24,8 @@ void RenderGraph::add_graphics_pipeline(OnCreateGraphicsPipeline on_pipeline_cre
}

std::weak_ptr<Buffer>
RenderGraph::add_buffer(std::string buffer_name, const BufferType buffer_type, std::function<void()> on_update) {
m_buffers.emplace_back(
std::make_shared<Buffer>(m_device, std::move(buffer_name), buffer_type, std::move(on_update)));
RenderGraph::add_buffer(std::string name, const BufferType type, std::function<void()> on_update) {
m_buffers.emplace_back(std::make_shared<Buffer>(m_device, std::move(name), type, std::move(on_update)));
return m_buffers.back();
}

Expand All @@ -44,16 +43,16 @@ void RenderGraph::add_resource_descriptor(OnBuildDescriptorSetLayout on_build_de
std::move(on_allocate_descriptor_set), std::move(on_update_descriptor_set));
}

std::weak_ptr<Texture> RenderGraph::add_texture(std::string texture_name,
std::weak_ptr<Texture> RenderGraph::add_texture(std::string name,
const TextureUsage usage,
const VkFormat format,
const std::uint32_t width,
const std::uint32_t height,
const std::uint32_t channels,
const VkSampleCountFlagBits sample_count,
std::function<void()> m_on_check_for_updates) {
m_textures.emplace_back(std::make_shared<Texture>(m_device, std::move(texture_name), usage, format, width, height,
channels, sample_count, std::move(m_on_check_for_updates)));
m_textures.emplace_back(std::make_shared<Texture>(m_device, std::move(name), usage, format, width, height, channels,
sample_count, std::move(m_on_check_for_updates)));
return m_textures.back();
}

Expand Down Expand Up @@ -104,16 +103,14 @@ void RenderGraph::collect_swapchain_image_available_semaphores() {

void RenderGraph::compile() {
// TODO: What needs to be re-done when swapchain is recreated?
validate_render_graph();
check_for_cycles();
determine_pass_order();
update_buffers();
update_textures();
create_descriptor_set_layouts();
allocate_descriptor_sets();
create_graphics_passes();
create_graphics_pipelines();
collect_swapchain_image_available_semaphores();
check_for_cycles();
determine_pass_order();
}

void RenderGraph::create_descriptor_set_layouts() {
Expand All @@ -123,10 +120,6 @@ void RenderGraph::create_descriptor_set_layouts() {
}
}

void RenderGraph::create_graphics_passes() {
// TODO: Implement me
}

void RenderGraph::create_graphics_pipelines() {
for (const auto &create_func : m_pipeline_create_functions) {
// Call the graphics pipeline create function
Expand All @@ -139,13 +132,15 @@ void RenderGraph::determine_pass_order() {
std::vector<std::shared_ptr<GraphicsPass>> ordered_passes;
std::unordered_map<std::shared_ptr<GraphicsPass>, bool> visited;

// Reserve memory for the sorted graphics passes
ordered_passes.reserve(m_graphics_passes.size());

// Lambda function for DFS
std::function<void(const std::shared_ptr<GraphicsPass> &)> dfs = [&](const std::shared_ptr<GraphicsPass> &pass) {
// If the pass has already been visited, return
if (visited[pass]) {
return;
}

// Mark the pass as visited
visited[pass] = true;

Expand All @@ -155,7 +150,6 @@ void RenderGraph::determine_pass_order() {
dfs(read_pass);
}
}

// All dependencies of this pass have been visited, now push this pass onto the stack
ordered_passes.push_back(pass);
};
Expand Down Expand Up @@ -438,10 +432,4 @@ void RenderGraph::update_write_descriptor_sets() {
m_write_descriptor_sets.data(), 0, nullptr);
}

void RenderGraph::validate_render_graph() {
if (m_pipeline_create_functions.empty()) {
throw std::runtime_error("[RenderGraph::validate_render_graph] Error: No graphics pipelines in rendergraph!");
}
}

} // namespace inexor::vulkan_renderer::render_graph

0 comments on commit c9cc646

Please sign in to comment.