···101101 int32_t fenced_buffer;
102102103103 /*!
104104+ * The render pass used to render to the target, it depends on the
105105+ * target's format so will be recreated each time the target changes.
106106+ */
107107+ struct render_gfx_render_pass target_render_pass;
108108+109109+ /*!
104110 * Array of "rendering" target resources equal in size to the number of
105111 * comp_target images. Each target resources holds all of the resources
106112 * needed to render to that target and its views.
···212218213219 struct comp_compositor *c = r->c;
214220215215- struct render_gfx_target_data data;
216216- data.format = r->c->target->format;
217217- data.is_external = true;
218218- data.width = r->c->target->width;
219219- data.height = r->c->target->height;
221221+ VkImageView image_view = r->c->target->images[index].view;
222222+ VkExtent2D extent = {r->c->target->width, r->c->target->height};
220223221221- render_gfx_target_resources_init(rtr, &c->nr, r->c->target->images[index].view, &data);
224224+ render_gfx_target_resources_init( //
225225+ rtr, //
226226+ &c->nr, //
227227+ &r->target_render_pass, //
228228+ image_view, //
229229+ extent); //
222230}
223231224232/*!
···376384 if (!use_compute) {
377385 r->rtr_array = U_TYPED_ARRAY_CALLOC(struct render_gfx_target_resources, r->buffer_count);
378386387387+ render_gfx_render_pass_init( //
388388+ &r->target_render_pass, // rgrp
389389+ &r->c->nr, // r
390390+ r->c->target->format, // format
391391+ VK_ATTACHMENT_LOAD_OP_CLEAR, // load_op
392392+ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); // final_layout
393393+379394 for (uint32_t i = 0; i < r->buffer_count; ++i) {
380395 renderer_build_rendering_target_resources(r, &r->rtr_array[i], i);
381396 }
···413428 for (uint32_t i = 0; i < r->buffer_count; i++) {
414429 render_gfx_target_resources_close(&r->rtr_array[i]);
415430 }
431431+432432+ // Close the render pass used for rendering to the target.
433433+ render_gfx_render_pass_close(&r->target_render_pass);
416434417435 free(r->rtr_array);
418436 r->rtr_array = NULL;
···526526527527/*
528528 *
529529- * Rendering target
529529+ * Render pass
530530 *
531531 */
532532533533/*!
534534- * Each rendering (@ref render_gfx) render to one or more targets
535535- * (@ref render_gfx_target_resources), each target can have one or more
536536- * views (@ref render_gfx_view), this struct holds all the data that is
537537- * specific to the target.
534534+ * A render pass while not depending on a @p VkFramebuffer does depend on the
535535+ * format of the target image(s), and other options for the render pass. These
536536+ * are used to create a @p VkRenderPass, all @p VkFramebuffer(s) and
537537+ * @p VkPipeline depends on the @p VkRenderPass so hang off this struct.
538538 */
539539-struct render_gfx_target_data
539539+struct render_gfx_render_pass
540540{
541541- // The format that should be used to read from the target.
541541+ struct render_resources *r;
542542+543543+ //! The format of the image(s) we are rendering to.
542544 VkFormat format;
543545544544- // Is this target a external target.
545545- bool is_external;
546546+ //! Sample count for this render pass.
547547+ VkSampleCountFlagBits sample_count;
548548+549549+ //! Load op used on the attachment(s).
550550+ VkAttachmentLoadOp load_op;
546551547547- //! Total height and width of the target.
548548- uint32_t width, height;
552552+ //! Final layout of the target image(s).
553553+ VkImageLayout final_layout;
554554+555555+ //! Render pass used for rendering.
556556+ VkRenderPass render_pass;
557557+558558+ struct
559559+ {
560560+ //! Pipeline layout used for mesh, does not depend on framebuffer.
561561+ VkPipeline pipeline;
562562+ } mesh;
549563};
550564551565/*!
566566+ * Creates all resources held by the render pass, does not free the struct itself.
567567+ *
568568+ * @public @memberof render_gfx_render_pass
569569+ */
570570+bool
571571+render_gfx_render_pass_init(struct render_gfx_render_pass *rgrp,
572572+ struct render_resources *r,
573573+ VkFormat format,
574574+ VkAttachmentLoadOp load_op,
575575+ VkImageLayout final_layout);
576576+577577+/*!
578578+ * Frees all resources held by the render pass, does not free the struct itself.
579579+ *
580580+ * @public @memberof render_gfx_render_pass
581581+ */
582582+void
583583+render_gfx_render_pass_close(struct render_gfx_render_pass *rgrp);
584584+585585+586586+/*
587587+ *
588588+ * Rendering target
589589+ *
590590+ */
591591+592592+/*!
552593 * Each rendering (@ref render_gfx) render to one or more targets
553594 * (@ref render_gfx_target_resources), each target can have one or more
554595 * views (@ref render_gfx_view), this struct holds all the vulkan resources
···564605 //! Collections of static resources.
565606 struct render_resources *r;
566607567567- //! The data for this target.
568568- struct render_gfx_target_data data;
569569-570570- //! Render pass used for rendering, does not depend on framebuffer.
571571- VkRenderPass render_pass;
608608+ //! Render pass.
609609+ struct render_gfx_render_pass *rgrp;
572610573573- struct
574574- {
575575- //! Pipeline layout used for mesh, does not depend on framebuffer.
576576- VkPipeline pipeline;
577577- } mesh;
611611+ // The extent of the framebuffer.
612612+ VkExtent2D extent;
578613579614 //! Framebuffer for this target, depends on given VkImageView.
580615 VkFramebuffer framebuffer;
581616};
582582-583617584618/*!
585619 * Init a target resource struct, caller has to keep target alive until closed.
···589623bool
590624render_gfx_target_resources_init(struct render_gfx_target_resources *rtr,
591625 struct render_resources *r,
626626+ struct render_gfx_render_pass *rgrp,
592627 VkImageView target,
593593- struct render_gfx_target_data *data);
628628+ VkExtent2D extent);
594629595630/*!
596631 * Frees all resources held by the target, does not free the struct itself.