@@ -57,9 +57,7 @@ PhysicalStage::~PhysicalStage() {
5757 vkDestroyPipeline (m_device.device (), m_pipeline, nullptr );
5858}
5959
60- PhysicalGraphicsStage::~PhysicalGraphicsStage () {
61- vkDestroyRenderPass (m_device.device (), m_render_pass, nullptr );
62- }
60+ PhysicalGraphicsStage::~PhysicalGraphicsStage () {}
6361
6462void RenderGraph::build_buffer (const BufferResource &buffer_resource, PhysicalBuffer &physical) const {
6563 // TODO: Don't always create mapped.
@@ -159,7 +157,7 @@ void RenderGraph::record_command_buffer(const RenderStage *stage, const wrapper:
159157 }
160158
161159 cmd_buf.begin_render_pass (wrapper::make_info<VkRenderPassBeginInfo>({
162- .renderPass = phys_graphics_stage->m_render_pass ,
160+ .renderPass = phys_graphics_stage->m_render_pass -> render_pass () ,
163161 .framebuffer = phys_graphics_stage->m_framebuffers .at (image_index).get (),
164162 .renderArea {
165163 .extent = m_swapchain.extent (),
@@ -249,35 +247,27 @@ void RenderGraph::build_render_pass(const GraphicsStage *stage, PhysicalGraphics
249247 attachments.push_back (attachment);
250248 }
251249
252- // Build a simple subpass that just waits for the output colour vector to be written by the fragment shader. In the
253- // future, we may want to make use of subpasses more.
254- const VkSubpassDependency subpass_dependency{
255- . srcSubpass = VK_SUBPASS_EXTERNAL ,
256- . srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ,
257- . dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ,
258- . dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ,
250+ const std:: vector<VkSubpassDescription> subpasses{
251+ {
252+ . pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
253+ . colorAttachmentCount = static_cast <std:: uint32_t >(colour_refs. size ()) ,
254+ . pColorAttachments = colour_refs. data () ,
255+ . pDepthStencilAttachment = !depth_refs. empty () ? depth_refs. data () : nullptr ,
256+ } ,
259257 };
260258
261- const VkSubpassDescription subpass_description{
262- .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
263- .colorAttachmentCount = static_cast <std::uint32_t >(colour_refs.size ()),
264- .pColorAttachments = colour_refs.data (),
265- .pDepthStencilAttachment = !depth_refs.empty () ? depth_refs.data () : nullptr ,
259+ // Build a simple subpass that just waits for the output colour vector to be written by the fragment shader
260+ const std::vector<VkSubpassDependency> dependencies{
261+ {
262+ .srcSubpass = VK_SUBPASS_EXTERNAL,
263+ .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
264+ .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
265+ .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
266+ },
266267 };
267268
268- const auto render_pass_ci = wrapper::make_info<VkRenderPassCreateInfo>({
269- .attachmentCount = static_cast <std::uint32_t >(attachments.size ()),
270- .pAttachments = attachments.data (),
271- .subpassCount = 1 ,
272- .pSubpasses = &subpass_description,
273- .dependencyCount = 1 ,
274- .pDependencies = &subpass_dependency,
275- });
276-
277- if (const auto result = vkCreateRenderPass (m_device.device (), &render_pass_ci, nullptr , &physical.m_render_pass );
278- result != VK_SUCCESS) {
279- throw VulkanException (" Error: vkCreateRenderPass failed for renderpass " + stage->name () + " !" , result);
280- }
269+ physical.m_render_pass =
270+ std::make_unique<wrapper::RenderPass>(m_device, attachments, subpasses, dependencies, " renderpass" );
281271}
282272
283273void RenderGraph::build_graphics_pipeline (const GraphicsStage *stage, PhysicalGraphicsStage &physical) const {
@@ -383,7 +373,7 @@ void RenderGraph::build_graphics_pipeline(const GraphicsStage *stage, PhysicalGr
383373 .pDepthStencilState = &depth_stencil,
384374 .pColorBlendState = &blend_state,
385375 .layout = physical.pipeline_layout (),
386- .renderPass = physical.m_render_pass ,
376+ .renderPass = physical.m_render_pass -> render_pass () ,
387377 });
388378
389379 // TODO: Pipeline caching (basically load the render graph from a file)
@@ -489,8 +479,8 @@ void RenderGraph::compile(const RenderResource *target) {
489479 for (const auto *image : images) {
490480 image_views.push_back (image->image_view ());
491481 }
492- physical.m_framebuffers .emplace_back (m_device, physical.m_render_pass , image_views, m_swapchain ,
493- " Framebuffer" );
482+ physical.m_framebuffers .emplace_back (m_device, physical.m_render_pass -> render_pass () , image_views,
483+ m_swapchain, " Framebuffer" );
494484 image_views.clear ();
495485 }
496486 }
0 commit comments