1 #include <gmath/gmath.h>
2 #include <vulkan/vulkan.h>
10 #include "allocator.h"
13 /* global variables */
14 VkPhysicalDevice vk_physical;
16 VkInstance vk_instance;
19 VkCommandPool vk_pool;
20 VkSurfaceKHR vk_surface;
21 VkSwapchainKHR vk_swapchain;
22 VkRenderPass vk_renderpass;
23 VkDescriptorPool vk_dpool;
25 /* static functions */
26 static const char *get_device_name_str(VkPhysicalDeviceType type);
27 static const char *get_memtype_flags_str(VkMemoryPropertyFlags flags);
28 static const char *get_queue_flags_str(VkQueueFlags flags);
29 static const char *get_mem_size_str(long sz);
30 static int ver_major(uint32_t ver);
31 static int ver_minor(uint32_t ver);
32 static int ver_patch(uint32_t ver);
34 /* static variables */
35 static VkPhysicalDevice *phys_devices;
38 static int sel_qfamily;
40 static VkExtensionProperties *vkext, *vkdevext;
41 static uint32_t vkext_count, vkdevext_count;
43 bool vku_have_extension(const char *name)
47 vkEnumerateInstanceExtensionProperties(0, &vkext_count, 0);
49 vkext = new VkExtensionProperties[vkext_count];
50 vkEnumerateInstanceExtensionProperties(0, &vkext_count, vkext);
52 printf("instance extensions:\n");
53 for(int i=0; i<(int)vkext_count; i++) {
54 printf(" %s (ver: %u)\n", vkext[i].extensionName, (unsigned int)vkext[i].specVersion);
59 for(int i=0; i<(int)vkext_count; i++) {
60 if(strcmp(vkext[i].extensionName, name) == 0) {
67 bool vku_have_device_extension(const char *name)
69 if(sel_dev < 0) return false;
73 vkEnumerateDeviceExtensionProperties(phys_devices[sel_dev], 0, &vkdevext_count, 0);
75 vkdevext = new VkExtensionProperties[vkdevext_count];
76 vkEnumerateDeviceExtensionProperties(phys_devices[sel_dev], 0, &vkdevext_count, vkdevext);
78 printf("selected device extensions:\n");
79 for(int i=0; i<(int)vkdevext_count; i++) {
80 printf(" %s (ver: %u)\n", vkdevext[i].extensionName, (unsigned int)vkdevext[i].specVersion);
85 for(int i=0; i<(int)vkdevext_count; i++) {
86 if(strcmp(vkdevext[i].extensionName, name) == 0) {
93 bool vku_create_device()
95 VkInstanceCreateInfo inst_info;
96 VkDeviceCreateInfo dev_info;
97 VkDeviceQueueCreateInfo queue_info;
98 VkCommandPoolCreateInfo cmdpool_info;
102 static const char *ext_names[] = {
103 "VK_KHR_xcb_surface",
107 static const char *devext_names[] = {
114 for(unsigned int i=0; i<sizeof ext_names / sizeof *ext_names; i++) {
115 if(!vku_have_extension(ext_names[i])) {
116 fprintf(stderr, "required extension (%s) not found\n", ext_names[i]);
120 memset(&inst_info, 0, sizeof inst_info);
121 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
122 inst_info.ppEnabledExtensionNames = ext_names;
123 inst_info.enabledExtensionCount = sizeof ext_names / sizeof *ext_names;
125 if(vkCreateInstance(&inst_info, 0, &vk_instance) != 0) {
126 fprintf(stderr, "failed to create vulkan instance\n");
129 printf("created vulkan instance\n");
130 if(vkEnumeratePhysicalDevices(vk_instance, &num_devices, 0) != 0) {
131 fprintf(stderr, "failed to enumerate vulkan physical devices\n");
134 phys_devices = new VkPhysicalDevice[num_devices];
135 if(vkEnumeratePhysicalDevices(vk_instance, &num_devices, phys_devices) != 0) {
136 fprintf(stderr, "failed to enumerate vulkan physical devices\n");
139 printf("found %u physical device(s)\n", (unsigned int)num_devices);
141 for(int i=0; i<(int)num_devices; i++) {
142 VkPhysicalDeviceProperties dev_prop;
143 VkPhysicalDeviceMemoryProperties mem_prop;
144 VkQueueFamilyProperties *qprop;
145 uint32_t qprop_count;
147 vkGetPhysicalDeviceProperties(phys_devices[i], &dev_prop);
149 printf("Device %d: %s\n", i, dev_prop.deviceName);
150 printf(" type: %s\n", get_device_name_str(dev_prop.deviceType));
151 printf(" API version: %d.%d.%d\n", ver_major(dev_prop.apiVersion), ver_minor(dev_prop.apiVersion),
152 ver_patch(dev_prop.apiVersion));
153 printf(" driver version: %d.%d.%d\n", ver_major(dev_prop.driverVersion), ver_minor(dev_prop.driverVersion),
154 ver_patch(dev_prop.driverVersion));
155 printf(" vendor id: %x device id: %x\n", dev_prop.vendorID, dev_prop.deviceID);
158 vkGetPhysicalDeviceMemoryProperties(phys_devices[i], &mem_prop);
159 printf(" %d memory heaps:\n", mem_prop.memoryHeapCount);
160 for(unsigned int j=0; j<mem_prop.memoryHeapCount; j++) {
161 VkMemoryHeap heap = mem_prop.memoryHeaps[j];
162 printf(" Heap %d - size: %s, flags: %s\n", j, get_mem_size_str(heap.size),
163 heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT ? "device-local" : "-");
165 printf(" %d memory types:\n", mem_prop.memoryTypeCount);
166 for(unsigned int j=0; j<mem_prop.memoryTypeCount; j++) {
167 VkMemoryType type = mem_prop.memoryTypes[j];
168 printf(" Type %d - heap: %d, flags: %s\n", j, type.heapIndex,
169 get_memtype_flags_str(type.propertyFlags));
172 vkGetPhysicalDeviceQueueFamilyProperties(phys_devices[i], &qprop_count, 0);
173 if(qprop_count <= 0) {
176 qprop = new VkQueueFamilyProperties[qprop_count];
177 vkGetPhysicalDeviceQueueFamilyProperties(phys_devices[i], &qprop_count, qprop);
179 for(unsigned int j=0; j<qprop_count; j++) {
180 printf(" Queue family %d:\n", j);
181 printf(" flags: %s\n", get_queue_flags_str(qprop[j].queueFlags));
182 printf(" num queues: %u\n", qprop[j].queueCount);
184 if(qprop[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
192 if(sel_dev < 0 || sel_qfamily < 0) {
193 fprintf(stderr, "failed to find any device with a graphics-capable command queue\n");
194 vkDestroyDevice(vk_device, 0);
198 for(unsigned int i=0; i<sizeof devext_names / sizeof *devext_names; i++) {
199 if(!vku_have_device_extension(devext_names[i])) {
200 fprintf(stderr, "required extension (%s) not found on the selected device (%d)\n",
201 ext_names[i], sel_dev);
206 /* create device & command queue */
207 memset(&queue_info, 0, sizeof queue_info);
208 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
209 queue_info.queueFamilyIndex = sel_qfamily;
210 queue_info.queueCount = 1;
211 queue_info.pQueuePriorities = &qprio;
213 memset(&dev_info, 0, sizeof dev_info);
214 dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
215 dev_info.queueCreateInfoCount = 1;
216 dev_info.pQueueCreateInfos = &queue_info;
217 dev_info.enabledExtensionCount = sizeof devext_names / sizeof *devext_names;
218 dev_info.ppEnabledExtensionNames = devext_names;
220 if(vkCreateDevice(phys_devices[sel_dev], &dev_info, 0, &vk_device) != 0) {
221 fprintf(stderr, "failed to create device %d\n", sel_dev);
224 printf("created device %d\n", sel_dev);
226 vk_physical = phys_devices[sel_dev];
227 vk_qfamily = sel_qfamily;
229 vkGetDeviceQueue(vk_device, sel_qfamily, 0, &vk_queue);
231 /* create command buffer pool */
232 memset(&cmdpool_info, 0, sizeof cmdpool_info);
233 cmdpool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
234 cmdpool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
235 cmdpool_info.queueFamilyIndex = sel_qfamily;
237 if(vkCreateCommandPool(vk_device, &cmdpool_info, 0, &vk_pool) != 0) {
238 fprintf(stderr, "failed to get command queue!\n");
242 /* if(!(vkcmdbuf = vku_alloc_cmdbuf(vk_pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY))) {
243 fprintf(stderr, "failed to create primary command buffer\n");
253 vkDeviceWaitIdle(vk_device);
254 vkDestroyCommandPool(vk_device, vk_pool, 0);
256 vkDestroyDevice(vk_device, 0);
257 vkDestroyInstance(vk_instance, 0);
261 delete [] phys_devices;
265 VkCommandBuffer vku_alloc_cmdbuf(VkCommandPool pool, VkCommandBufferLevel level)
267 VkCommandBuffer cmdbuf;
268 VkCommandBufferAllocateInfo inf;
270 memset(&inf, 0, sizeof inf);
271 inf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
272 inf.commandPool = pool;
274 inf.commandBufferCount = 1;
276 if(vkAllocateCommandBuffers(vk_device, &inf, &cmdbuf) != 0) {
282 bool vku_alloc_cmdbufs(VkCommandPool pool, VkCommandBufferLevel level, unsigned int count, VkCommandBuffer *buf_array)
284 VkCommandBufferAllocateInfo cinf;
285 memset(&cinf, 0, sizeof cinf);
287 cinf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
288 cinf.commandPool = vk_pool;
290 cinf.commandBufferCount = count;
292 if(vkAllocateCommandBuffers(vk_device, &cinf, buf_array) != VK_SUCCESS) {
293 fprintf(stderr, "Failed to allocate command buffer\n");
300 void vku_free_cmdbuf(VkCommandPool pool, VkCommandBuffer buf)
302 vkFreeCommandBuffers(vk_device, pool, 1, &buf);
305 void vku_begin_cmdbuf(VkCommandBuffer buf, unsigned int flags)
307 VkCommandBufferBeginInfo inf;
309 memset(&inf, 0, sizeof inf);
310 inf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
313 vkBeginCommandBuffer(buf, &inf);
317 void vku_end_cmdbuf(VkCommandBuffer buf)
319 vkEndCommandBuffer(buf);
322 void vku_reset_cmdbuf(VkCommandBuffer buf)
324 vkResetCommandBuffer(buf, 0);
327 void vku_submit_cmdbuf(VkQueue q, VkCommandBuffer buf, VkFence done_fence)
331 memset(&info, 0, sizeof info);
332 info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
333 info.commandBufferCount = 1;
334 info.pCommandBuffers = &buf;
336 vkQueueSubmit(q, 1, &info, done_fence);
339 bool vku_get_surface_format(VkPhysicalDevice gpu, VkSurfaceKHR surface, VkSurfaceFormatKHR *sformat)
343 if(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical,
344 vk_surface, &fcount, 0) != VK_SUCCESS) {
345 fprintf(stderr, "Failed to get format count for physical device.\n");
349 fprintf(stderr, "No color formats were found.\n");
353 VkSurfaceFormatKHR *formats = new VkSurfaceFormatKHR[fcount];
354 if(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical, vk_surface,
355 &fcount, formats) != VK_SUCCESS) {
357 fprintf(stderr, "Failed to get surface formats.\n");
361 *sformat = formats[0];
363 if((fcount == 1) && (formats[0].format == VK_FORMAT_UNDEFINED)) {
364 sformat->format = VK_FORMAT_B8G8R8_UNORM;
372 int vku_get_next_image(VkSwapchainKHR sc)
376 if(vkAcquireNextImageKHR(vk_device, sc, UINT64_MAX, 0, 0, &next) != 0) {
382 void vku_present(VkSwapchainKHR sc, int img_idx)
384 VkPresentInfoKHR inf;
386 uint32_t index = img_idx;
388 memset(&inf, 0, sizeof inf);
389 inf.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
390 inf.swapchainCount = 1;
391 inf.pSwapchains = ≻
392 inf.pImageIndices = &index;
395 vkQueuePresentKHR(vk_queue, &inf);
398 struct vku_buffer *vku_create_buffer(int sz, unsigned int usage)
400 struct vku_buffer *buf;
401 VkBufferCreateInfo binfo;
403 buf = new vku_buffer;
405 memset(&binfo, 0, sizeof binfo);
406 binfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
409 binfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
411 if(vkCreateBuffer(vk_device, &binfo, 0, &buf->buf) != 0) {
412 fprintf(stderr, "failed to create %d byte buffer (usage: %x)\n", sz, usage);
416 VkMemoryRequirements mr;
417 vkGetBufferMemoryRequirements(vk_device, buf->buf, &mr);
420 if(!vku_allocate(mr.size, &block))
423 buf->mem_pool = block.dev_mem;
428 void vku_destroy_buffer(struct vku_buffer *buf)
431 //TODO change when the allocator changes
432 vku_free(buf->mem_pool);
434 vkDestroyBuffer(vk_device, buf->buf, 0);
439 bool vku_update_buffer(vku_buffer *buf, int size, void *data)
442 if(vkMapMemory(vk_device, buf->mem_pool, 0, size, 0, (void**)&pdata) != VK_SUCCESS) {
443 fprintf(stderr, "Failed to map memory.\n");
446 memcpy(pdata, data, size);
447 vkUnmapMemory(vk_device, buf->mem_pool);
452 void vku_cmd_copybuf(VkCommandBuffer cmdbuf, VkBuffer dest, int doffs,
453 VkBuffer src, int soffs, int size)
457 copy.srcOffset = soffs;
458 copy.dstOffset = doffs;
460 vkCmdCopyBuffer(cmdbuf, src, dest, 1, ©);
463 const char *vku_get_vulkan_error_str(VkResult error)
468 errmsg = std::string("VK_SUCCESS");
471 errmsg = std::string("VK_NOT_READY");
474 errmsg = std::string("VK_TIMEOUT");
477 errmsg = std::string("VK_EVENT_SET");
480 errmsg = std::string("VK_EVENT_RESET");
483 errmsg = std::string("VK_EVENT");
485 case VK_ERROR_OUT_OF_HOST_MEMORY:
486 errmsg = std::string("VK_ERROR_OUT_OF_HOST_MEMORY");
488 case VK_ERROR_OUT_OF_DEVICE_MEMORY:
489 errmsg = std::string("VK_ERROR_OUT_OF_DEVICE_MEMORY");
491 case VK_ERROR_INITIALIZATION_FAILED:
492 errmsg = std::string("VK_ERROR_INITIALIZATION_FAILED");
494 case VK_ERROR_DEVICE_LOST:
495 errmsg = std::string("VK_ERROR_DEVICE_LOST");
497 case VK_ERROR_MEMORY_MAP_FAILED:
498 errmsg = std::string("VK_ERROR_MEMORY_MAP_FAILED");
500 case VK_ERROR_LAYER_NOT_PRESENT:
501 errmsg = std::string("VK_ERROR_LAYER_NOT_PRESENT");
503 case VK_ERROR_EXTENSION_NOT_PRESENT:
504 errmsg = std::string("VK_ERROR_EXTENSION_NOT_PRESENT");
506 case VK_ERROR_FEATURE_NOT_PRESENT:
507 errmsg = std::string("VK_ERROR_FEATURE_NOT_PRESENT");
508 case VK_ERROR_INCOMPATIBLE_DRIVER:
509 errmsg = std::string("VK_ERROR_INCOMPATIBLE_DRIVER");
511 case VK_ERROR_TOO_MANY_OBJECTS:
512 errmsg = std::string("VK_ERROR_TOO_MANY_OBJECTS");
514 case VK_ERROR_FORMAT_NOT_SUPPORTED:
515 errmsg = std::string("VK_ERROR_FORMAT_NOT_SUPPORTED");
517 case VK_ERROR_FRAGMENTED_POOL:
518 errmsg = std::string("VK_ERROR_FRAGMENTED_POOL");
521 errmsg = std::string("UNKNOWN");
525 return errmsg.c_str();
529 static const char *get_device_name_str(VkPhysicalDeviceType type)
532 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
533 return "integrated GPU";
534 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
535 return "discrete GPU";
536 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
537 return "virtual GPU";
538 case VK_PHYSICAL_DEVICE_TYPE_CPU:
546 static const char *get_memtype_flags_str(VkMemoryPropertyFlags flags)
548 static char str[128];
551 if(flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
552 strcat(str, "device-local ");
554 if(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
555 strcat(str, "host-visible ");
557 if(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
558 strcat(str, "host-coherent ");
560 if(flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) {
561 strcat(str, "host-cached ");
563 if(flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) {
564 strcat(str, "lazily-allocated ");
573 static const char *get_queue_flags_str(VkQueueFlags flags)
575 static char str[128];
578 if(flags & VK_QUEUE_GRAPHICS_BIT) {
579 strcat(str, "graphics ");
581 if(flags & VK_QUEUE_COMPUTE_BIT) {
582 strcat(str, "compute ");
584 if(flags & VK_QUEUE_TRANSFER_BIT) {
585 strcat(str, "transfer ");
587 if(flags & VK_QUEUE_SPARSE_BINDING_BIT) {
588 strcat(str, "sparse-binding ");
596 static int ver_major(uint32_t ver)
598 return (ver >> 22) & 0x3ff;
601 static int ver_minor(uint32_t ver)
603 return (ver >> 12) & 0x3ff;
606 static int ver_patch(uint32_t ver)
611 static const char *get_mem_size_str(long sz)
614 static const char *unitstr[] = { "bytes", "KB", "MB", "GB", "TB", "PB", 0 };
618 while(sz >= 10240 && unitstr[uidx + 1]) {
622 sprintf(str, "%ld.%ld %s", sz / 10, sz % 10, unitstr[uidx]);
626 vku_descriptor *vku_create_descriptor(VkDescriptorType type,
627 VkFlags stage, int binding_point,
628 int size, int num_desc)
630 vku_descriptor *desc = new vku_descriptor;
634 desc->stage_flags = stage;
635 desc->binding_point = binding_point;
637 VkDescriptorSetLayoutBinding dslb;
638 memset(&dslb, 0, sizeof dslb);
640 dslb.binding = binding_point;
641 dslb.descriptorType = type;
642 dslb.descriptorCount = num_desc;
643 dslb.stageFlags = stage;
645 VkDescriptorSetLayoutCreateInfo dslinf;
646 memset(&dslinf, 0, sizeof dslinf);
648 dslinf.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
649 dslinf.bindingCount = 1;
650 dslinf.pBindings = &dslb;
652 if(vkCreateDescriptorSetLayout(vk_device, &dslinf, 0, &desc->layout) != VK_SUCCESS) {
653 fprintf(stderr, "Failed to create vku_descriptor.\n");
660 void vku_destroy_descriptor(vku_descriptor *desc)
662 vkDestroyDescriptorSetLayout(vk_device, desc->layout, 0);
666 bool vku_create_descriptor_pool(vku_descriptor **descriptors, int num_desc)
669 vkDestroyDescriptorPool(vk_device, vk_dpool, 0);
671 VkDescriptorPoolCreateInfo dpinf;
672 memset(&dpinf, 0, sizeof dpinf);
673 dpinf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
676 dpinf.poolSizeCount = num_desc;
678 std::vector<VkDescriptorPoolSize> sizes;
679 for(int i=0; i<num_desc; i++) {
680 VkDescriptorPoolSize psz;
681 psz.type = descriptors[i]->type;
682 psz.descriptorCount = 1;
683 sizes.push_back(psz);
686 dpinf.pPoolSizes = sizes.data();
688 if(vkCreateDescriptorPool(vk_device, &dpinf, 0, &vk_dpool) != VK_SUCCESS) {
689 fprintf(stderr, "Failed to create descriptor pool.\n");
696 void vku_destroy_descriptor_pool()
698 vkDestroyDescriptorPool(vk_device, vk_dpool, 0);
701 bool vku_allocate_descriptor_sets(vku_descriptor **desc, int num_desc, VkDescriptorSet set)
703 VkDescriptorSetAllocateInfo dainf;
704 memset(&dainf, 0, sizeof dainf);
706 dainf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
707 dainf.descriptorPool = vk_dpool;
708 dainf.descriptorSetCount = num_desc;
710 std::vector<VkDescriptorSetLayout> layouts;
711 for(int i=0; i<num_desc; i++) {
712 layouts.push_back(desc[i]->layout);
715 dainf.pSetLayouts = layouts.data();
717 if(vkAllocateDescriptorSets(vk_device, &dainf, &set) != VK_SUCCESS) {
718 fprintf(stderr, "Failed to allocate descriptor sets.\n");
724 void vku_free_descriptor_sets(VkDescriptorSet *sets, int num)
726 vkFreeDescriptorSets(vk_device, vk_dpool, num, sets);
729 bool vku_update_descriptor_sets(VkDescriptorSet *sets, int num_sets)
735 VkPipelineCache vku_create_pipeline_cache()
737 VkPipelineCacheCreateInfo cinf;
738 memset(&cinf, 0, sizeof cinf);
739 cinf.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
741 VkPipelineCache cache;
742 if(vkCreatePipelineCache(vk_device, &cinf, 0, &cache) != VK_SUCCESS) {
743 fprintf(stderr, "Failed to create pipeline cache.\n");
749 void vku_destroy_pipeline_cache(VkPipelineCache cache)
751 vkDestroyPipelineCache(vk_device, cache, 0);
754 void vku_pl_init_shader_stage_state_info(VkPipelineShaderStageCreateInfo *ssinf,
755 VkShaderStageFlagBits stage, VkShaderModule sm)
757 memset(ssinf, 0, sizeof *ssinf);
758 ssinf->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
759 ssinf->stage = stage;
761 ssinf->pName = "main";
764 void vku_pl_init_input_asm_state_info(VkPipelineInputAssemblyStateCreateInfo *iasinf)
766 memset(iasinf, 0, sizeof *iasinf);
767 iasinf->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
768 iasinf->topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
771 void vku_pl_init_viewport_state_info(VkPipelineViewportStateCreateInfo *vsinf,
772 VkViewport *viewports, int num_viewports, VkRect2D *scissors,
775 memset(vsinf, 0, sizeof *vsinf);
776 vsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
777 vsinf->viewportCount = num_viewports;
778 vsinf->scissorCount = num_scissors;
779 vsinf->pViewports = viewports;
780 vsinf->pScissors = scissors;
783 void vku_pl_init_rasterization_state_info(VkPipelineRasterizationStateCreateInfo *rsinf)
785 memset(rsinf, 0, sizeof *rsinf);
786 rsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
787 rsinf->polygonMode = VK_POLYGON_MODE_FILL;
788 rsinf->cullMode = VK_CULL_MODE_FRONT_BIT;
789 rsinf->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
792 void vku_pl_init_multisample_state_info(VkPipelineMultisampleStateCreateInfo *msinf)
794 memset(msinf, 0, sizeof *msinf);
795 msinf->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
796 msinf->rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
799 void vku_pl_init_depth_stencil_state_info(VkPipelineDepthStencilStateCreateInfo *dsinf,
802 memset(dsinf, 0, sizeof *dsinf);
803 dsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
804 dsinf->depthTestEnable = enable ? VK_TRUE : VK_FALSE;
807 void vku_pl_init_color_blend_state_info(VkPipelineColorBlendStateCreateInfo *cbsinf,
810 memset(cbsinf, 0, sizeof *cbsinf);
811 cbsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;