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 2, 2024
1 parent fa45441 commit 8365d87
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class GraphicsPipelineBuilder {
std::vector<VkPipelineColorBlendAttachmentState> m_color_blend_attachment_states;

/// The push constant ranges of the graphics pass
std::vector<std::pair<VkPushConstantRange, std::function<void()>>> m_push_constant_ranges;
std::vector<VkPushConstantRange> m_push_constant_ranges;

/// Reset all data in this class so the builder can be re-used
/// @note This is called by the constructor
Expand Down Expand Up @@ -155,22 +155,17 @@ class GraphicsPipelineBuilder {

/// Add a push constant range to the graphics pass
/// @param shader_stage The shader stage for the push constant range
/// @param push_constant The push constant data
/// @param on_update The update function
/// @param size The size of the push constant
/// @param offset The offset in the push constant range
/// @return A const reference to the this pointer (allowing method calls to be chained)
template <typename PushConstantDataType>
[[nodiscard]] auto &add_push_constant_range(const VkShaderStageFlags shader_stage,
const PushConstantDataType &push_constant,
std::function<void()> on_update,
const std::uint32_t size,
const std::uint32_t offset = 0) {
m_push_constant_ranges.emplace_back(
VkPushConstantRange{
.stageFlags = shader_stage,
.offset = offset,
.size = sizeof(push_constant),
},
std::move(on_update));
m_push_constant_ranges.emplace_back(VkPushConstantRange{
.stageFlags = shader_stage,
.offset = offset,
.size = size,
});
return *this;
}

Expand Down
2 changes: 2 additions & 0 deletions src/vulkan-renderer/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ void Application::setup_render_graph() {
})
// TOOD: Even simpler API like .reads_from() and .writes_to() without templates (just overloading)?
// TODO: Since we don't bind vertex or index buffers, do we even need these calls to reads_from_buffer?
// TODO: We could imagine some API where we have vertex_buffer.bind_me() in on_record and then check
// which ones were not bound
.reads_from_buffer(m_index_buffer)
.reads_from_buffer(m_vertex_buffer)
// This is essential to know for descriptor setup in rendergraph
Expand Down
12 changes: 3 additions & 9 deletions src/vulkan-renderer/render-graph/render_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ void RenderGraph::compile() {

void RenderGraph::create_buffers() {
for (const auto &buffer : m_buffers) {
// Call the update lambda of the buffer
// Call the update lambda of the buffer (if specified)
if (buffer->m_on_update) {
std::invoke(buffer->m_on_update.value());
}
// Create the buffer
buffer->create_buffer();
}
// TODO: Batch all updates which require staging buffer into one pipeline barrier call
Expand Down Expand Up @@ -173,6 +172,7 @@ void RenderGraph::record_command_buffer_for_pass(const CommandBuffer &cmd_buf,
const std::uint32_t img_index) {

// TODO: Remove img_index and implement swapchain.get_current_image()
// TODO: Or do we need the image index for buffers? (We want to automatically double or triple buffer them)

// Start a new debug label for this graphics pass (debug labels are visible in graphics debuggers like RenderDoc)
// TODO: Generate color gradient depending on the number of passes? (Interpolate e.g. in 12 steps for 12 passes)
Expand Down Expand Up @@ -244,15 +244,9 @@ void RenderGraph::record_command_buffer_for_pass(const CommandBuffer &cmd_buf,
cmd_buf.bind_index_buffer(pass.m_index_buffer);
}

// TODO: bind descriptor set(s)

// TODO: push constants
if (!pass.m_push_constant_ranges.empty()) {
cmd_buf.push_constants();
}
#endif

// Call the user-defined command buffer recording function of the graphics pass
// Call the custom command buffer recording function of the graphics pass
std::invoke(pass.m_on_record, cmd_buf);

// End dynamic rendering
Expand Down
16 changes: 8 additions & 8 deletions src/vulkan-renderer/renderers/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ ImGuiRenderer::ImGuiRenderer(const wrapper::Device &device,
.uses_shader(m_vertex_shader)
.uses_shader(m_fragment_shader)
.set_descriptor_set_layout(descriptor_set_layout_builder.add_combined_image_sampler().build("ImGui"))
.add_push_constant_range(VK_SHADER_STAGE_VERTEX_BIT, &m_push_const_block,
[&]() {
const ImGuiIO &io = ImGui::GetIO();
m_push_const_block.scale =
glm::vec2(2.0f / io.DisplaySize.x, 2.0f / io.DisplaySize.y);
})
.add_push_constant_range(VK_SHADER_STAGE_VERTEX_BIT, sizeof(m_push_const_block))
.build("ImGui");
return m_imgui_pipeline;
});
Expand All @@ -129,16 +124,21 @@ ImGuiRenderer::ImGuiRenderer(const wrapper::Device &device,
.writes_to_texture(back_buffer)
.writes_to_texture(depth_buffer)
.set_on_record([&](const CommandBuffer &cmd_buf) {
// TODO: Bind pipelines through rendergraph automatically or not?
const ImGuiIO &io = ImGui::GetIO();
m_push_const_block.scale = glm::vec2(2.0f / io.DisplaySize.x, 2.0f / io.DisplaySize.y);

cmd_buf.bind_pipeline(m_imgui_pipeline);
// TODO: Bind descriptor set!
// TODO: Bind push constant!

ImDrawData *draw_data = ImGui::GetDrawData();
if (draw_data == nullptr) {
return;
}
std::uint32_t index_offset = 0;
std::int32_t vertex_offset = 0;
for (std::size_t i = 0; i < draw_data->CmdListsCount; i++) {
const ImDrawList *cmd_list = draw_data->CmdLists[i]; // NOLINT
const ImDrawList *cmd_list = draw_data->CmdLists[i];
for (std::int32_t j = 0; j < cmd_list->CmdBuffer.Size; j++) {
const ImDrawCmd &draw_cmd = cmd_list->CmdBuffer[j];
cmd_buf.draw_indexed(draw_cmd.ElemCount, 1, index_offset, vertex_offset);
Expand Down

0 comments on commit 8365d87

Please sign in to comment.