vulkan_test2

diff src/vku.c @ 13:d34f84bede17

pipeline madness
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 25 Jun 2018 08:00:57 +0300
parents e17abe477616
children 9fb6c24691ea
line diff
     1.1 --- a/src/vku.c	Sat Jun 23 07:47:49 2018 +0300
     1.2 +++ b/src/vku.c	Mon Jun 25 08:00:57 2018 +0300
     1.3 @@ -426,8 +426,70 @@
     1.4  }
     1.5  
     1.6  
     1.7 +VkRenderPass vku_create_renderpass(VkFormat cfmt, VkFormat dsfmt)
     1.8 +{
     1.9 +	int count = 1;	/* always assume we have a color attachment for now */
    1.10 +	VkAttachmentDescription at[2];
    1.11 +	VkAttachmentReference colref, dsref;
    1.12 +	VkSubpassDescription subpass;
    1.13 +	VkRenderPass pass;
    1.14 +	VkRenderPassCreateInfo rpinf;
    1.15 +
    1.16 +	colref.attachment = 0;
    1.17 +	colref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
    1.18 +	dsref.attachment = 1;
    1.19 +	dsref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
    1.20 +
    1.21 +	memset(&subpass, 0, sizeof subpass);
    1.22 +	subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
    1.23 +	subpass.colorAttachmentCount = 1;
    1.24 +	subpass.pColorAttachments = &colref;
    1.25 +
    1.26 +	at[0].format = cfmt;
    1.27 +	at[0].samples = VK_SAMPLE_COUNT_1_BIT;	/* TODO multisampling */
    1.28 +	at[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
    1.29 +	at[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
    1.30 +	at[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
    1.31 +	at[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
    1.32 +	at[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
    1.33 +	at[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
    1.34 +
    1.35 +	if(dsfmt != VK_FORMAT_UNDEFINED) {
    1.36 +		at[1].format = dsfmt;
    1.37 +		at[1].samples = VK_SAMPLE_COUNT_1_BIT;
    1.38 +		at[1].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
    1.39 +		at[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
    1.40 +		at[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
    1.41 +		at[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
    1.42 +		at[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
    1.43 +		at[1].finalLayout = VK_IMAGE_LAYOUT_UNDEFINED;
    1.44 +
    1.45 +		subpass.pDepthStencilAttachment = &dsref;
    1.46 +		count++;
    1.47 +	}
    1.48 +
    1.49 +	memset(&rpinf, 0, sizeof rpinf);
    1.50 +	rpinf.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
    1.51 +	rpinf.attachmentCount = count;
    1.52 +	rpinf.pAttachments = at;
    1.53 +	rpinf.subpassCount = 1;
    1.54 +	rpinf.pSubpasses = &subpass;
    1.55 +
    1.56 +	if(vkCreateRenderPass(vkdev, &rpinf, 0, &pass) != 0) {
    1.57 +		fprintf(stderr, "vku_create_renderpass: failed to create renderpass\n");
    1.58 +		return 0;
    1.59 +	}
    1.60 +
    1.61 +	return pass;
    1.62 +}
    1.63 +
    1.64 +void vku_destroy_renderpass(VkRenderPass rpass)
    1.65 +{
    1.66 +	vkDestroyRenderPass(vkdev, rpass, 0);
    1.67 +}
    1.68 +
    1.69 +
    1.70  #ifdef VK_USE_PLATFORM_XLIB_KHR
    1.71 -
    1.72  int vku_xlib_usable_visual(Display *dpy, VisualID vid)
    1.73  {
    1.74  	return vkGetPhysicalDeviceXlibPresentationSupportKHR(phys_devices[sel_dev],