| 143 | } |
| 144 | |
| 145 | VulkanObject VulkanObjectManager::CreateImage(VkImageUsageFlags usageFlags, VkFormat format, VkImageTiling tiling, |
| 146 | VkImageAspectFlags aspectFlags, uint32_t width, uint32_t height) |
| 147 | { |
| 148 | VulkanObject result; |
| 149 | VkImageCreateInfo imageCreateInfo = {}; |
| 150 | imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 151 | imageCreateInfo.pNext = nullptr; |
| 152 | imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; |
| 153 | imageCreateInfo.format = format; |
| 154 | imageCreateInfo.mipLevels = 1; |
| 155 | imageCreateInfo.arrayLayers = 1; |
| 156 | imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
| 157 | imageCreateInfo.tiling = tiling; |
| 158 | imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 159 | imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 160 | imageCreateInfo.extent = {width, height, 1}; |
| 161 | imageCreateInfo.usage = usageFlags | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 162 | CHECK_VK_CALL(vkCreateImage(m_device, &imageCreateInfo, nullptr, &result.m_image)); |
| 163 | |
| 164 | VkMemoryRequirements memReqs = {}; |
| 165 | vkGetImageMemoryRequirements(m_device, result.m_image, &memReqs); |
| 166 | |
| 167 | { |
| 168 | std::lock_guard<std::mutex> lock(m_mutex); |
| 169 | result.m_allocation = |
| 170 | m_memoryManager.Allocate(VulkanMemoryManager::ResourceType::Image, memReqs, 0 /* blockHash */); |
| 171 | CHECK_VK_CALL(vkBindImageMemory(m_device, result.m_image, result.GetMemory(), result.GetAlignedOffset())); |
| 172 | } |
| 173 | |
| 174 | VkImageViewCreateInfo viewCreateInfo = {}; |
| 175 | viewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 176 | viewCreateInfo.pNext = nullptr; |
| 177 | viewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 178 | viewCreateInfo.format = format; |
| 179 | if (usageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) |
| 180 | { |
| 181 | viewCreateInfo.components = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, |
| 182 | VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}; |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | viewCreateInfo.components = {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, |
| 187 | VK_COMPONENT_SWIZZLE_A}; |
| 188 | } |
| 189 | viewCreateInfo.subresourceRange.aspectMask = aspectFlags; |
| 190 | viewCreateInfo.subresourceRange.baseMipLevel = 0; |
| 191 | viewCreateInfo.subresourceRange.levelCount = 1; |
| 192 | viewCreateInfo.subresourceRange.baseArrayLayer = 0; |
| 193 | viewCreateInfo.subresourceRange.layerCount = 1; |
| 194 | viewCreateInfo.image = result.m_image; |
| 195 | CHECK_VK_CALL(vkCreateImageView(m_device, &viewCreateInfo, nullptr, &result.m_imageView)); |
| 196 | |
| 197 | #ifdef ENABLE_TRACE |
| 198 | m_imagesCount++; |
| 199 | TRACE_COUNTER("[drape][vulkan] Images", m_imagesCount); |
| 200 | #endif |
| 201 | |
| 202 | return result; |
no test coverage detected