X-Git-Url: https://eleni.mutantstargoat.com/git/?p=demo;a=blobdiff_plain;f=src%2Fvulkan%2Fvkutil.cc;h=698e6f8d17e2bfa2f964ca0e320cc3679506198f;hp=051ee4dc7174b101c6301ba2924046ec7a55f34e;hb=72995482b98ff2a014ddd737131a0935ead89977;hpb=9148ff7614b1dc22fd5d1dcf6d74e2fb4ff13706 diff --git a/src/vulkan/vkutil.cc b/src/vulkan/vkutil.cc index 051ee4d..698e6f8 100644 --- a/src/vulkan/vkutil.cc +++ b/src/vulkan/vkutil.cc @@ -10,8 +10,13 @@ /* global variables */ +VkPipeline *vkgraphics_pipeline; +VkFramebuffer *vkfbufs; +VkRenderPass vkrpass; VkSwapchainKHR vkswapchain; VkImage *vkswapchain_images; +VkImageView *vkswapchain_views; +int vknum_swapchain_images; int vknext_swapchain_image; VkSurfaceKHR vksurface; VkInstance vkinst; @@ -46,10 +51,7 @@ bool vku_have_extension(const char *name) vkext_count = 0; vkEnumerateInstanceExtensionProperties(0, &vkext_count, 0); if(vkext_count) { - if(!(vkext = (VkExtensionProperties *)malloc(vkext_count * sizeof *vkext))) { - perror("failed to allocate instance extension list"); - return false; - } + vkext = new VkExtensionProperties[vkext_count]; vkEnumerateInstanceExtensionProperties(0, &vkext_count, vkext); printf("instance extensions:\n"); @@ -75,10 +77,7 @@ bool vku_have_device_extension(const char *name) vkdevext_count = 0; vkEnumerateDeviceExtensionProperties(phys_devices[sel_dev], 0, &vkdevext_count, 0); if(vkdevext_count) { - if(!(vkdevext = (VkExtensionProperties *)malloc(vkdevext_count * sizeof *vkdevext))) { - perror("failed to allocate device extension list"); - return false; - } + vkdevext = new VkExtensionProperties[vkdevext_count]; vkEnumerateDeviceExtensionProperties(phys_devices[sel_dev], 0, &vkdevext_count, vkdevext); printf("selected device extensions:\n"); @@ -137,7 +136,7 @@ bool vku_create_device() fprintf(stderr, "failed to enumerate vulkan physical devices\n"); return false; } - phys_devices = (VkPhysicalDevice *)malloc(num_devices * sizeof *phys_devices); + phys_devices = new VkPhysicalDevice[num_devices]; if(vkEnumeratePhysicalDevices(vkinst, &num_devices, phys_devices) != 0) { fprintf(stderr, "failed to enumerate vulkan physical devices\n"); return false; @@ -179,7 +178,7 @@ bool vku_create_device() if(qprop_count <= 0) { continue; } - qprop = (VkQueueFamilyProperties *)malloc(qprop_count * sizeof *qprop); + qprop = new VkQueueFamilyProperties[qprop_count]; vkGetPhysicalDeviceQueueFamilyProperties(phys_devices[i], &qprop_count, qprop); for(unsigned int j=0; jbuf, 0); - free(buf); + delete buf; } } @@ -754,6 +860,80 @@ const char *vku_get_vulkan_error_str(VkResult error) return errmsg.c_str(); } +bool vku_create_graphics_pipeline(VkPipelineLayout *layout) +{ + VkGraphicsPipelineCreateInfo inf; + memset(&inf, 0, sizeof inf); + + inf.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + inf.layout = *layout; + inf.renderPass = vkrpass; + + /* states */ + + /* how primitives are assembled */ + VkPipelineInputAssemblyStateCreateInfo ias; + memset(&ias, 0, sizeof ias); + ias.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + ias.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + /* rasterisation */ + VkPipelineRasterizationStateCreateInfo rsi; + memset(&rsi, 0, sizeof rsi); + rsi.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rsi.polygonMode = VK_POLYGON_MODE_FILL; + rsi.cullMode = VK_CULL_MODE_BACK_BIT; + rsi.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + rsi.lineWidth = 1.0f; + + /* blend factors */ + VkPipelineColorBlendAttachmentState bas[1]; + memset(&bas[0], 0, sizeof bas[0]); + + VkPipelineColorBlendStateCreateInfo cbs; + memset(&cbs, 0, sizeof cbs); + cbs.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + cbs.attachmentCount = 1; + cbs.pAttachments = bas; + + /* number of viewport and scissors in this pipeline */ + VkPipelineViewportStateCreateInfo vs; + memset(&vs, 0, sizeof vs); + vs.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + vs.viewportCount = 1; + vs.scissorCount = 1; + + /* dynamic states: that can be changed later */ + std::vector ds_enabled; + ds_enabled.push_back(VK_DYNAMIC_STATE_VIEWPORT); + //ds_enabled.push_back(VK_DYNAMIC_STATE_SCISSOR); + VkPipelineDynamicStateCreateInfo ds; + ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + ds.pDynamicStates = ds_enabled.data(); + ds.dynamicStateCount = static_cast(ds_enabled.size()); + + /* depth tests */ + VkPipelineDepthStencilStateCreateInfo dsi; + memset(&dsi, 0, sizeof dsi); + dsi.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + dsi.depthTestEnable = VK_TRUE; + dsi.depthWriteEnable = VK_TRUE; + dsi.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; + dsi.back.failOp = VK_STENCIL_OP_KEEP; + dsi.back.passOp = VK_STENCIL_OP_KEEP; + dsi.back.compareOp = VK_COMPARE_OP_ALWAYS; + dsi.front = dsi.back; + + /* multisampling - must be set even if not used */ + VkPipelineMultisampleStateCreateInfo msi; + memset(&msi, 0, sizeof msi); + msi.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + msi.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + //TODO in progress + return true; +} + static const char *get_device_name_str(VkPhysicalDeviceType type) { switch(type) {