SpiecsEngine
 
Loading...
Searching...
No Matches

◆ CreateImage()

void Spices::VulkanImage::CreateImage ( VulkanState & vulkanState,
const std::string & name,
VkImageType type,
uint32_t width,
uint32_t height,
uint32_t layers,
VkSampleCountFlagBits numSamples,
VkFormat format,
VkImageTiling tiling,
VkImageUsageFlags usage,
VkImageCreateFlags flags,
VkMemoryPropertyFlags properties,
uint32_t mipLevels )

@breif Create a VkImage.

Parameters
[in]vulkanStateThe VulkanObject in used this frame.
[in]nameImage's name.
[in]typeImage's type.
[in]widthImage's width.
[in]heightImage's height.
[in]layersImage's layers(texture cube).
[in]numSamplesImage's MSAA sample num.(8 if enable MSAA).
[in]formatImage's format.
[in]tilingImage's tilling.
[in]usageImage's used stage.
[in]flagsImage's used flags.
[in]propertiesImage's data memory requirement.
[in]mipLevelsImage's mip num, if need.

Instance a VkImageCreateInfo.

Instance a VmaAllocationCreateInfo.

Create Image.

Instance a VkImageCreateInfo.

Instance a VmaAllocationCreateInfo.

Create Image.

Definition at line 798 of file VulkanImage.cpp.

813 {
815
816 m_Width = static_cast<int>(width);
817 m_Height = static_cast<int>(height);
818 m_Layers = layers;
819 m_ImageType = type;
820 m_Format = format;
821 m_MipLevels = mipLevels;
822
826 VkImageCreateInfo imageInfo{};
827 imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
828 imageInfo.imageType = type;
829 imageInfo.extent.width = width;
830 imageInfo.extent.height = height;
831 imageInfo.extent.depth = 1;
832 imageInfo.mipLevels = mipLevels;
833 imageInfo.arrayLayers = layers;
834 imageInfo.format = format;
835 imageInfo.tiling = tiling;
836 imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
837 imageInfo.usage = usage;
838 imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
839 imageInfo.samples = numSamples;
840 imageInfo.flags = flags;
841
842#if VMA_ALLOCATOR
843
847 VmaAllocationCreateInfo createInfo{};
848 createInfo.usage = VMA_MEMORY_USAGE_AUTO;
849
853 VK_CHECK(vmaCreateImage(vulkanState.m_VmaAllocator, &imageInfo, &createInfo, &m_Image, &m_Alloc, nullptr))
854 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_IMAGE, reinterpret_cast<uint64_t>(m_Image), m_VulkanState.m_Device, name)
855
856#else
857
861 VK_CHECK(vkCreateImage(vulkanState.m_Device, &imageInfo, nullptr, &m_Image));
862 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_IMAGE, (uint64_t)m_Image, m_VulkanState.m_Device, name)
863
864
867 VkMemoryRequirements memRequirements;
868 vkGetImageMemoryRequirements(vulkanState.m_Device, m_Image, &memRequirements);
869
873 VkMemoryAllocateInfo allocInfo{};
874 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
875 allocInfo.allocationSize = memRequirements.size;
876
880 VkPhysicalDeviceMemoryProperties memProperties;
881 vkGetPhysicalDeviceMemoryProperties(vulkanState.m_PhysicalDevice, &memProperties);
882
886 allocInfo.memoryTypeIndex = 0;
887 for (uint32_t i = 0; i < memProperties.memoryTypeCount; i++)
888 {
889 if (memRequirements.memoryTypeBits & (1 << i) && (memProperties.memoryTypes[i].propertyFlags & properties) == properties)
890 {
891 allocInfo.memoryTypeIndex = i;
892 }
893 }
894
898 VK_CHECK(vkAllocateMemory(vulkanState.m_Device, &allocInfo, nullptr, &m_ImageMemory))
899
900
903 vkBindImageMemory(vulkanState.m_Device, m_Image, m_ImageMemory, 0);
904
905#endif
906
907 }
#define SPICES_PROFILE_ZONE
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
Definition VulkanUtils.h:68
VkImageType m_ImageType
Image Type.
int m_Width
Image width.
VkFormat m_Format
The image format.
VmaAllocation m_Alloc
VMA allocation.
VkDeviceMemory m_ImageMemory
The image video memory.
uint32_t m_MipLevels
Image mipmaps num.
int m_Height
Image height.
VkImage m_Image
The VkImage this Class Wrapped.
uint32_t m_Layers
Image layer(texture cube: 6).
VulkanState & m_VulkanState
The global VulkanState Referenced from VulkanRenderBackend.

References m_Height, m_Layers, m_MipLevels, and m_Width.