#include "iwa/render_pass.hpp" #include "iwa/device.hpp" #include "iwa/image.hpp" namespace iwa { RenderPass::RenderPass(ObjectPtr owner, const RenderPassCreationArgs& args) : super_t(std::move(owner)) { std::vector vkSubpasses; vkSubpasses.reserve(args.subpasses.size()); for (const SubpassDescription& subpass : args.subpasses) { MIJIN_ASSERT(subpass.resolveAttachments.empty() || subpass.resolveAttachments.size() == subpass.colorAttachments.size(), "Number of resolve attachments must be either 0 or the same as color attachments."); vkSubpasses.push_back({ .flags = subpass.flags, .pipelineBindPoint = subpass.pipelineBindPoint, .inputAttachmentCount = static_cast(subpass.inputAttachments.size()), .pInputAttachments = subpass.inputAttachments.data(), .colorAttachmentCount = static_cast(subpass.colorAttachments.size()), .pColorAttachments = subpass.colorAttachments.data(), .pResolveAttachments = subpass.resolveAttachments.data(), .pDepthStencilAttachment = subpass.depthStencilAttachment.has_value() ? &subpass.depthStencilAttachment.value() : nullptr, .preserveAttachmentCount = static_cast(subpass.preserveAttachments.size()), .pPreserveAttachments = subpass.preserveAttachments.data() }); } mHandle = getOwner()->getVkHandle().createRenderPass(vk::RenderPassCreateInfo{ .flags = args.flags, .attachmentCount = static_cast(args.attachments.size()), .pAttachments = args.attachments.data(), .subpassCount = static_cast(vkSubpasses.size()), .pSubpasses = vkSubpasses.data(), .dependencyCount = static_cast(args.dependencies.size()), .pDependencies = args.dependencies.data() }); } RenderPass::~RenderPass() noexcept { IWA_DELETE_DEVICE_OBJECT(getOwner(), mHandle, destroyRenderPass); } Framebuffer::Framebuffer(ObjectPtr owner, const FramebufferCreationArgs& args) : super_t(std::move(owner)), mImageViews(args.attachments) { std::vector vkImageViews; vkImageViews.reserve(mImageViews.size()); for (const ObjectPtr& imageView : mImageViews) { vkImageViews.push_back(*imageView); } mHandle = getOwner()->getVkHandle().createFramebuffer(vk::FramebufferCreateInfo{ .flags = args.flags, .renderPass = *args.renderPass, .attachmentCount = static_cast(vkImageViews.size()), .pAttachments = vkImageViews.data(), .width = args.width, .height = args.height, .layers = args.layers }); } Framebuffer::~Framebuffer() noexcept { IWA_DELETE_DEVICE_OBJECT(getOwner(), mHandle, destroyFramebuffer); } } // namespace iwa