| 750 | } |
| 751 | |
| 752 | void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) { |
| 753 | VkImageCreateInfo imageInfo{}; |
| 754 | imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 755 | imageInfo.imageType = VK_IMAGE_TYPE_2D; |
| 756 | imageInfo.extent.width = width; |
| 757 | imageInfo.extent.height = height; |
| 758 | imageInfo.extent.depth = 1; |
| 759 | imageInfo.mipLevels = 1; |
| 760 | imageInfo.arrayLayers = 1; |
| 761 | imageInfo.format = format; |
| 762 | imageInfo.tiling = tiling; |
| 763 | imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 764 | imageInfo.usage = usage; |
| 765 | imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
| 766 | imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 767 | |
| 768 | if (vkCreateImage(device, &imageInfo, nullptr, &image) != VK_SUCCESS) { |
| 769 | throw std::runtime_error("failed to create image!"); |
| 770 | } |
| 771 | |
| 772 | VkMemoryRequirements memRequirements; |
| 773 | vkGetImageMemoryRequirements(device, image, &memRequirements); |
| 774 | |
| 775 | VkMemoryAllocateInfo allocInfo{}; |
| 776 | allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 777 | allocInfo.allocationSize = memRequirements.size; |
| 778 | allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties); |
| 779 | |
| 780 | if (vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) { |
| 781 | throw std::runtime_error("failed to allocate image memory!"); |
| 782 | } |
| 783 | |
| 784 | vkBindImageMemory(device, image, imageMemory, 0); |
| 785 | } |
| 786 | |
| 787 | void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout) { |
| 788 | VkCommandBuffer commandBuffer = beginSingleTimeCommands(); |
nothing calls this directly
no outgoing calls
no test coverage detected