| 789 | } |
| 790 | |
| 791 | void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) { |
| 792 | VkImageCreateInfo imageInfo{}; |
| 793 | imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 794 | imageInfo.imageType = VK_IMAGE_TYPE_2D; |
| 795 | imageInfo.extent.width = width; |
| 796 | imageInfo.extent.height = height; |
| 797 | imageInfo.extent.depth = 1; |
| 798 | imageInfo.mipLevels = 1; |
| 799 | imageInfo.arrayLayers = 1; |
| 800 | imageInfo.format = format; |
| 801 | imageInfo.tiling = tiling; |
| 802 | imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 803 | imageInfo.usage = usage; |
| 804 | imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
| 805 | imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 806 | |
| 807 | if (vkCreateImage(device, &imageInfo, nullptr, &image) != VK_SUCCESS) { |
| 808 | throw std::runtime_error("failed to create image!"); |
| 809 | } |
| 810 | |
| 811 | VkMemoryRequirements memRequirements; |
| 812 | vkGetImageMemoryRequirements(device, image, &memRequirements); |
| 813 | |
| 814 | VkMemoryAllocateInfo allocInfo{}; |
| 815 | allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 816 | allocInfo.allocationSize = memRequirements.size; |
| 817 | allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties); |
| 818 | |
| 819 | if (vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) { |
| 820 | throw std::runtime_error("failed to allocate image memory!"); |
| 821 | } |
| 822 | |
| 823 | vkBindImageMemory(device, image, imageMemory, 0); |
| 824 | } |
| 825 | |
| 826 | void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout) { |
| 827 | VkCommandBuffer commandBuffer = beginSingleTimeCommands(); |
nothing calls this directly
no outgoing calls
no test coverage detected