std::vector<image::image_type> get_images(swapchain_type &swapchain) { uint32_t count; VKCHECK(vkGetSwapchainImagesKHR( internal::get_instance(*internal::get_parent(swapchain)), internal::get_instance(swapchain), &count, NULL)); std::vector<VkImage> images(count); VKCHECK(vkGetSwapchainImagesKHR(internal::get_instance(*internal::get_parent(swapchain)), internal::get_instance(swapchain), &count, &images.front())); std::vector<image::image_type> converted_images; converted_images.reserve(images.size()); for (VkImage image : images) { converted_images.push_back(image::image_type(image, internal::get_parent(swapchain), false, VK_IMAGE_TYPE_2D, get_format(swapchain), 1, 1)); } return std::move(converted_images); }
buffer_type create(const type::supplier<device::device_type> &device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, VkSharingMode sharingMode, const std::vector<uint32_t> &queueFamilyIndices) { VkBufferCreateInfo create = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, NULL}; create.flags = flags; create.size = size; create.usage = usage; create.sharingMode = sharingMode; create.queueFamilyIndexCount = (uint32_t) queueFamilyIndices.size(); create.pQueueFamilyIndices = queueFamilyIndices.empty() ? NULL : &queueFamilyIndices.front(); VkBuffer buffer; VKCHECK(vkCreateBuffer(internal::get_instance(*device), &create, NULL, &buffer)); return buffer_type(buffer, device); }
swapchain_type create(const type::supplier<device::device_type> &device, const create_info_type &create_info) { VkSwapchainCreateInfoKHR create = { VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, NULL, 0 }; create.minImageCount = create_info.minImageCount; create.imageFormat = create_info.imageFormat; create.imageColorSpace = create_info.imageColorSpace; create.imageExtent = create_info.imageExtent; create.imageArrayLayers = create_info.imageArrayLayers; create.imageUsage = create_info.imageUsage; create.imageSharingMode = create_info.imageSharingMode; create.pQueueFamilyIndices = create_info.queueFamilyIndices.data(); create.preTransform = create_info.preTransform; create.compositeAlpha = (VkCompositeAlphaFlagBitsKHR) create_info.compositeAlpha; create.presentMode = create_info.presentMode; create.clipped = create_info.clipped; create.oldSwapchain = create_info.oldSwapchain ? internal::get_instance(*create_info.oldSwapchain) : VK_NULL_HANDLE; VkSwapchainKHR swapchain; { if (create_info.oldSwapchain) { std::lock(internal::get_mutex(*create_info.surface), internal::get_mutex(*create_info.oldSwapchain)); std::lock_guard<std::mutex> surface_lock( internal::get_mutex(*create_info.surface), std::adopt_lock); std::lock_guard<std::mutex> old_swapchain_lock( internal::get_mutex(*create_info.oldSwapchain), std::adopt_lock); create.surface = internal::get_instance(*create_info.surface); VKCHECK(vkCreateSwapchainKHR(internal::get_instance(*device), &create, NULL, &swapchain)); } else { std::lock_guard<std::mutex> surface_lock( internal::get_mutex(*create_info.surface)); create.surface = internal::get_instance(*create_info.surface); VKCHECK(vkCreateSwapchainKHR(internal::get_instance(*device), &create, NULL, &swapchain)); } } return swapchain_type(swapchain, device, create_info.imageFormat); }
render_pass_type create(const type::supplier<const device::device_type> &device, const std::vector<VkAttachmentDescription> &attachment_descriptions, const std::vector<subpass_description_type> &subpass_descriptions, const std::vector<VkSubpassDependency> &subpass_dependency) { VkRenderPassCreateInfo create = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, NULL, 0}; create.attachmentCount = (uint32_t)attachment_descriptions.size(); create.pAttachments = attachment_descriptions.empty() ? NULL : &attachment_descriptions.front(); create.subpassCount = (uint32_t)subpass_descriptions.size(); const std::vector<VkSubpassDescription> subpass_descriptions_converted( subpass_descriptions_convert(subpass_descriptions)); create.pSubpasses = subpass_descriptions_converted.empty() ? NULL : &subpass_descriptions_converted.front(); create.dependencyCount = (uint32_t)subpass_dependency.size(); create.pDependencies = subpass_dependency.empty() ? NULL : &subpass_dependency.front(); VkRenderPass render_pass; VKCHECK(vkCreateRenderPass(internal::get_instance(*device), &create, NULL, &render_pass)); return render_pass_type(render_pass, device); }
pipeline_layout_type create(const type::supplier<device::device_type> &device, const std::vector<type::supplier<vcc::descriptor_set_layout::descriptor_set_layout_type>> &set_layouts, const std::vector<VkPushConstantRange> &push_constant_ranges) { VkPipelineLayoutCreateInfo create = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, NULL, 0}; create.setLayoutCount = (uint32_t) set_layouts.size(); std::vector<VkDescriptorSetLayout> converted_set_layouts; converted_set_layouts.reserve(set_layouts.size()); std::transform(set_layouts.begin(), set_layouts.end(), std::back_inserter(converted_set_layouts), [](const type::supplier<vcc::descriptor_set_layout::descriptor_set_layout_type> &set_layout){ return vcc::internal::get_instance(*set_layout); }); create.pSetLayouts = set_layouts.empty() ? NULL : &converted_set_layouts.front(); create.pushConstantRangeCount = (uint32_t) push_constant_ranges.size(); create.pPushConstantRanges = push_constant_ranges.empty() ? NULL : &push_constant_ranges.front(); VkPipelineLayout pipeline_layout; VKCHECK(vkCreatePipelineLayout(vcc::internal::get_instance(*device), &create, NULL, &pipeline_layout)); return pipeline_layout_type(pipeline_layout, device); }