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 16, 2024
1 parent a3c9543 commit f48bcba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
4 changes: 0 additions & 4 deletions include/inexor/vulkan-renderer/render-graph/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,6 @@ class RenderGraph {
/// @param pass The graphics pass to record the command buffer for
void record_command_buffer_for_pass(const CommandBuffer &cmd_buf, const GraphicsPass &pass);

/// Record all command buffers required for the passes
/// @param cmd_buf The command buffer to record all passes with
void record_command_buffers(const CommandBuffer &cmd_buf);

/// Update the vertex-, index-, and uniform-buffers
/// @note If a uniform buffer has been updated, an update of the associated descriptor set will be performed
void update_buffers();
Expand Down
60 changes: 30 additions & 30 deletions src/vulkan-renderer/render-graph/render_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ void RenderGraph::create_rendering_infos() {
.resolveMode = msaa_enabled ? (!is_integer_format(attach_ptr->m_format) ? VK_RESOLVE_MODE_AVERAGE_BIT
: VK_RESOLVE_MODE_MIN_BIT)
: VK_RESOLVE_MODE_NONE, // No resolve if MSAA is disabled
.resolveImageView = msaa_enabled ? attach_ptr->m_img->m_img_view : VK_NULL_HANDLE,
// This will be filled during rendering!
.resolveImageView = VK_NULL_HANDLE,
// TODO: Is this correct layout?
.resolveImageLayout = msaa_enabled ? img_layout : VK_IMAGE_LAYOUT_UNDEFINED,
// Does this pass require clearing this attachment?
Expand All @@ -216,27 +217,14 @@ void RenderGraph::create_rendering_infos() {
const bool has_depth_attachment = !pass->m_depth_attachment.first.expired();
if (has_depth_attachment) {
pass->m_depth_attachment_info = fill_rendering_info(pass->m_depth_attachment);
pass->m_depth_attachment_info.resolveMode = VK_RESOLVE_MODE_NONE;
}

// Fill the stencil attachment (if specified)
const bool has_stencil_attachment = !pass->m_stencil_attachment.first.expired();
if (has_stencil_attachment) {
pass->m_stencil_attachment_info = fill_rendering_info(pass->m_stencil_attachment);
}

// We store all this data in the rendering info in the graphics pass itself
// The advantage of this is that we don't have to fill this during the actual rendering
pass->m_rendering_info = std::move(wrapper::make_info<VkRenderingInfo>({
.renderArea =
{
.extent = m_swapchain.extent(),
},
.layerCount = 1,
.colorAttachmentCount = static_cast<std::uint32_t>(pass->m_color_attachment_infos.size()),
.pColorAttachments = pass->m_color_attachment_infos.data(),
.pDepthAttachment = has_depth_attachment ? &pass->m_depth_attachment_info : nullptr,
.pStencilAttachment = has_stencil_attachment ? &pass->m_stencil_attachment_info : nullptr,
}));
}
}

Expand All @@ -248,11 +236,11 @@ void RenderGraph::create_textures() {
std::invoke(texture->m_on_init.value());
}
// Rename the command buffer before creating every texture for fine-grained debugging
cmd_buf.set_suboperation_debug_name("Texture-Create:" + texture->m_name + "]");
cmd_buf.set_suboperation_debug_name("Texture|Create:" + texture->m_name + "]");
texture->create();
if (texture->m_usage == TextureUsage::NORMAL) {
// Rename the command buffer before creating every texture for fine-grained debugging
cmd_buf.set_suboperation_debug_name("Texture-Update:" + texture->m_name + "]");
cmd_buf.set_suboperation_debug_name("Texture|Update:" + texture->m_name + "]");
// Only external textures are updated, not back or depth buffers used internally in rendergraph
texture->update(cmd_buf);
}
Expand All @@ -272,8 +260,23 @@ void RenderGraph::record_command_buffer_for_pass(const CommandBuffer &cmd_buf, c
// TODO: Define default color values for debug labels!
// Start a new debug label for this graphics pass (visible in graphics debuggers like RenderDoc)
cmd_buf.begin_debug_label_region(pass.m_name, {1.0f, 0.0f, 0.0f, 1.0f});

// TODO: Support multi-target rendering!
auto color_attachment_info = pass.m_color_attachment_infos;
color_attachment_info[0].resolveImageView = m_swapchain.m_current_img_view;

// Start dynamic rendering with the compiled rendering info
cmd_buf.begin_rendering(pass.m_rendering_info);
cmd_buf.begin_rendering(wrapper::make_info<VkRenderingInfo>({
.renderArea =
{
.extent = m_swapchain.extent(),
},
.layerCount = 1,
.colorAttachmentCount = 1,
.pColorAttachments = &color_attachment_info[0],
.pDepthAttachment = (!pass.m_depth_attachment.first.expired()) ? &pass.m_depth_attachment_info : nullptr,
.pStencilAttachment = (!pass.m_stencil_attachment.first.expired()) ? &pass.m_stencil_attachment_info : nullptr,
}));

// Call the command buffer recording function of this graphics pass. In this function, the actual rendering takes
// place: the programmer binds pipelines, descriptor sets, buffers, and calls Vulkan commands. Note that rendergraph
Expand All @@ -286,27 +289,24 @@ void RenderGraph::record_command_buffer_for_pass(const CommandBuffer &cmd_buf, c
cmd_buf.end_debug_label_region();
}

void RenderGraph::record_command_buffers(const CommandBuffer &cmd_buf) {
void RenderGraph::render() {
// Acquire the next swapchain image index
m_swapchain.acquire_next_image_index();

// TODO: Refactor this into .exec();
const auto &cmd_buf = m_device.request_command_buffer("[RenderGraph::render|");

// Transform the image layout of the swapchain (it comes in undefined layout after presenting)
cmd_buf.change_image_layout(m_swapchain.m_current_img, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);

for (const auto &pass : m_graphics_passes) {
// TODO: Name command buffer on a per-pass basis like [RenderGraph::record_command_buffer|Pass:ImGui]
for (auto &pass : m_graphics_passes) {
record_command_buffer_for_pass(cmd_buf, *pass);
}

// Change the layout of the swapchain image to make it ready for presenting
cmd_buf.change_image_layout(m_swapchain.m_current_img, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
}

void RenderGraph::render() {
// Acquire the next swapchain image index
m_swapchain.acquire_next_image_index();

const auto &cmd_buf = m_device.request_command_buffer("[RenderGraph::render|");
// TODO: Record command buffers for passes in parallel!
record_command_buffers(cmd_buf);

// TODO: Further abstract this away?
const std::array<VkPipelineStageFlags, 1> stage_mask{VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
Expand Down

0 comments on commit f48bcba

Please sign in to comment.