#include <vulkan/vulkan.h>
#include "vk.h"
#include "util.h"
+#include "darray.h"
#ifdef __WIN32__
#include <vulkan/vulkan_win32.h>
struct rpass {
int used;
int fmt;
+ int zfmt;
int num_colbuf;
int num_samples;
/* TODO: stuff about depth-stencil */
/* init renderpass defaults */
rp->used = 1;
rp->fmt = vksurf_fmt[vksurf_selfmt].format;
+ rp->zfmt = VK_FORMAT_D24_UNORM_S8_UINT;
rp->num_colbuf = 1;
rp->num_samples = 1;
rp->clear = 1;
rpasses[rp].num_samples = nsamp;
}
-void vk_rpass_clear(int clear)
+void vk_rpass_clear(int rp, int clear)
{
rpasses[rp].clear = clear;
}
VkRenderPass vk_rpass(int rp)
{
+ int i, zidx;
struct rpass *r;
- VkAttachmentDescription cat;
- VkAttachmentReference catref[16];
+ VkAttachmentDescription att[17];
+ VkAttachmentReference catref[16], zatref;
VkSubpassDescription subpass;
VkRenderPassCreateInfo pinf;
- VkSubpassDependency dep;
r = rpasses + rp;
if(!r->vkobj_valid) {
- memset(&cat, 0, sizeof cat);
- cat.format = r->fmt;
- cat.samples = r->num_samples;
- cat.loadOp = r->clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
- cat.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
- cat.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
- cat.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
- cat.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
- cat.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ zidx = r->num_colbuf;
+ memset(att, 0, sizeof att);
+ for(i=0; i<r->num_colbuf; i++) {
+ att[i].format = r->fmt;
+ att[i].samples = r->num_samples;
+ att[i].loadOp = r->clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ att[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ att[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ att[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ att[i].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ att[i].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ }
+ att[zidx].format = r->zfmt;
+ att[zidx].samples = 1;
+ att[zidx].loadOp = r->clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ att[zidx].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ att[zidx].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ att[zidx].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ att[zidx].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ att[zidx].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
for(i=0; i<r->num_colbuf; i++) {
- memset(&catref[i], 0, sizeof catref);
+ catref[i].attachment = i;
catref[i].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
}
+ zatref.attachment = zidx;
+ zatref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
memset(&subpass, 0, sizeof subpass);
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = r->num_colbuf;
subpass.pColorAttachments = catref;
-
- memset(&dep, 0, sizeof dep);
- dep.srcSubpass =
+ subpass.pDepthStencilAttachment = &zatref;
+
+ memset(&pinf, 0, sizeof pinf);
+ pinf.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
+ pinf.attachmentCount = r->num_colbuf + 1;
+ pinf.pAttachments = att;
+ pinf.subpassCount = 1;
+ pinf.pSubpasses = &subpass;
+
+ if(vkCreateRenderPass(vkdev, &pinf, 0, &r->vkobj) != 0) {
+ fprintf(stderr, "failed to create render pass!\n");
+ return 0;
+ }
+ r->vkobj_valid = 1;
}
- return rpasses[rp].vkobj;
+ return r->vkobj;
}
#define ARRSZ(arr) (sizeof arr / sizeof *arr)