58 lines
1.7 KiB
C
58 lines
1.7 KiB
C
/* SPDX-License-Identifier:BSD-3-Clause */
|
|
#include "renderpass.h"
|
|
#include "../../core/log.h"
|
|
|
|
void vk_renderpass_init(struct renderer_context *context)
|
|
{
|
|
VkAttachmentDescription color_attachment = {
|
|
.format = context->swapchain.format,
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
|
|
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
|
|
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
|
|
};
|
|
|
|
VkAttachmentReference color_ref = {
|
|
.attachment = 0,
|
|
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
|
|
};
|
|
|
|
VkSubpassDescription subpass = {
|
|
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
.colorAttachmentCount = 1,
|
|
.pColorAttachments = &color_ref
|
|
};
|
|
|
|
VkSubpassDependency dependency = {
|
|
.srcSubpass = VK_SUBPASS_EXTERNAL,
|
|
.dstSubpass = 0,
|
|
.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
|
.srcAccessMask = 0,
|
|
.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
|
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
|
|
};
|
|
|
|
VkRenderPassCreateInfo create_info = {
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
|
.attachmentCount = 1,
|
|
.pAttachments = &color_attachment,
|
|
.subpassCount = 1,
|
|
.pSubpasses = &subpass,
|
|
.dependencyCount = 1,
|
|
.pDependencies = &dependency
|
|
};
|
|
|
|
if (vkCreateRenderPass(context->device, &create_info, NULL, &context->render_pass) != VK_SUCCESS) {
|
|
fatal("Can't create render pass.\n");
|
|
}
|
|
|
|
log_info("Render pass created.\n");
|
|
}
|
|
|
|
void vk_renderpass_deinit(struct renderer_context *context)
|
|
{
|
|
vkDestroyRenderPass(context->device, context->render_pass, NULL);
|
|
}
|