5 #define LOC QString("VulkanTex: ")
8 VkSampler Sampler, VkCommandBuffer CommandBuffer)
23 QImage *Image, VkSampler Sampler,
24 VkCommandBuffer CommandBuffer)
32 auto datasize =
static_cast<VkDeviceSize
>((Image->width() * Image->height() * Image->depth()) >> 3);
33 auto datasize2 = Image->sizeInBytes();
34 if (datasize !=
static_cast<VkDeviceSize
>(datasize2))
35 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Inconsistent image data size");
37 const auto *data = Image->constBits();
41 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
44 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create staging buffer");
49 void* memory =
nullptr;
51 memcpy(memory, data,
static_cast<size_t>(datasize));
56 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
63 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, commandbuffer);
65 static_cast<uint32_t
>(Image->height()), commandbuffer);
67 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, commandbuffer);
81 VkImageViewCreateInfo viewinfo { };
82 viewinfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
84 viewinfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
85 viewinfo.format = VK_FORMAT_B8G8R8A8_UNORM;
86 viewinfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
87 viewinfo.subresourceRange.baseMipLevel = 0;
88 viewinfo.subresourceRange.levelCount = 1;
89 viewinfo.subresourceRange.baseArrayLayer = 0;
90 viewinfo.subresourceRange.layerCount = 1;
92 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create image view");
102 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create texture image");
114 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Texture has not returned descriptor");
137 return {
m_sampler,
m_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL };