Skip to content

Commit 1e20a19

Browse files
yeetariIAmNotHanni
authored andcommitted
[gltf]render-graph] Fix gltf rendering setup in rendergraph
1 parent 1832278 commit 1e20a19

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/vulkan-renderer/render_graph.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ void RenderGraph::build_render_pass(const GraphicsStage *stage, PhysicalGraphics
243243
colour_refs.push_back({static_cast<std::uint32_t>(i), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL});
244244
break;
245245
case TextureUsage::DEPTH_STENCIL_BUFFER:
246+
// TODO: Proper image layout tracking.
247+
if (!stage->m_clears_screen) {
248+
attachment.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
249+
attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
250+
}
246251
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
247252
depth_refs.push_back({static_cast<std::uint32_t>(i), attachment.finalLayout});
248253
break;

src/vulkan-renderer/renderer.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,42 @@ void VulkanRenderer::setup_render_graph() {
4141
offsetof(gltf::ModelVertex, color)); // NOLINT
4242
m_gltf_vertex_buffer->upload_data(m_gltf_vertices);
4343

44+
auto *gltf_stage = m_render_graph->add<GraphicsStage>("gltf stage");
45+
gltf_stage->writes_to(m_back_buffer);
46+
gltf_stage->writes_to(depth_buffer);
47+
gltf_stage->reads_from(m_gltf_index_buffer);
48+
gltf_stage->reads_from(m_gltf_vertex_buffer);
49+
gltf_stage->bind_buffer(m_gltf_vertex_buffer, 0);
50+
gltf_stage->set_clears_screen(true);
51+
gltf_stage->set_depth_options(true, true);
52+
gltf_stage->set_on_record([&](const PhysicalStage &physical, const wrapper::CommandBuffer &cmd_buf) {
53+
// Render glTF2 models
54+
cmd_buf.bind_descriptor(m_descriptors[1], physical.pipeline_layout());
55+
cmd_buf.draw_indexed(m_gltf_indices.size());
56+
});
57+
4458
auto *main_stage = m_render_graph->add<GraphicsStage>("main stage");
4559
main_stage->writes_to(m_back_buffer);
4660
main_stage->writes_to(depth_buffer);
4761
main_stage->reads_from(m_octree_index_buffer);
4862
main_stage->reads_from(m_octree_vertex_buffer);
4963
main_stage->bind_buffer(m_octree_vertex_buffer, 0);
50-
main_stage->reads_from(m_gltf_index_buffer);
51-
main_stage->reads_from(m_gltf_vertex_buffer);
52-
main_stage->bind_buffer(m_gltf_vertex_buffer, 1);
53-
main_stage->set_clears_screen(true);
5464
main_stage->set_depth_options(true, true);
5565
main_stage->set_on_record([&](const PhysicalStage &physical, const wrapper::CommandBuffer &cmd_buf) {
5666
// Render octrees
5767
cmd_buf.bind_descriptor(m_descriptors[0], physical.pipeline_layout());
5868
cmd_buf.draw_indexed(m_octree_indices.size());
59-
60-
// Render glTF2 models
61-
cmd_buf.bind_descriptor(m_descriptors[1], physical.pipeline_layout());
62-
cmd_buf.draw_indexed(m_gltf_indices.size());
6369
});
6470

71+
for (const auto &shader : m_shaders) {
72+
gltf_stage->uses_shader(shader);
73+
}
6574
for (const auto &shader : m_shaders) {
6675
main_stage->uses_shader(shader);
6776
}
6877

6978
main_stage->add_descriptor_layout(m_descriptors[0].descriptor_set_layout());
70-
main_stage->add_descriptor_layout(m_descriptors[1].descriptor_set_layout());
79+
gltf_stage->add_descriptor_layout(m_descriptors[1].descriptor_set_layout());
7180
}
7281

7382
void VulkanRenderer::generate_octree_indices() {

0 commit comments

Comments
 (0)